diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..3024413f --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @rust-embedded/embedded-linux diff --git a/.github/bors.toml b/.github/bors.toml new file mode 100644 index 00000000..92c7183d --- /dev/null +++ b/.github/bors.toml @@ -0,0 +1,10 @@ +block_labels = ["needs-decision"] +delete_merged_branches = true +required_approvals = 1 +status = [ + "CI (stable, x86_64-unknown-linux-gnu)", + "CI (stable, armv7-unknown-linux-gnueabihf)", + "CI (1.46.0, x86_64-unknown-linux-gnu)", + "CI-macOS (stable, x86_64-apple-darwin)", + "CI-macOS (1.46.0, x86_64-apple-darwin)", +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..85f41199 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Continuous integration + +jobs: + ci-linux: + name: CI + runs-on: ubuntu-latest + + strategy: + matrix: + # All generated code should be running on stable now + rust: [stable] + + # The default target we're compiling on and for + TARGET: [x86_64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf] + + include: + # Test MSRV + - rust: 1.46.0 + TARGET: x86_64-unknown-linux-gnu + + # Test nightly but don't fail + - rust: nightly + experimental: true + TARGET: x86_64-unknown-linux-gnu + + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.TARGET }} + override: true + + - name: Install armv7 libraries + if: ${{ matrix.TARGET == 'armv7-unknown-linux-gnueabihf' }} + run: sudo apt-get install -y libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf + + - uses: actions-rs/cargo@v1 + if: ${{ matrix.TARGET != 'armv7-unknown-linux-gnueabihf' }} + with: + command: test + args: --target=${{ matrix.TARGET }} + + + - uses: actions-rs/cargo@v1 + if: ${{ matrix.TARGET == 'armv7-unknown-linux-gnueabihf' }} + with: + command: build + args: --target=${{ matrix.TARGET }} + + ci-macos: + name: CI-macOS + runs-on: macos-11 + + strategy: + matrix: + rust: [stable, 1.46.0] + TARGET: [x86_64-apple-darwin] + + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.TARGET }} + override: true + + - uses: actions-rs/cargo@v1 + with: + command: build + args: --target=${{ matrix.TARGET }} diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 00000000..72d9a109 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,20 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Clippy check +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.55.0 + override: true + components: clippy + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100644 index 00000000..9a55c002 --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -0,0 +1,23 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Code formatting check + +jobs: + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d963eb2f..00000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: rust -sudo: false - -os: - - linux - - osx - -rust: - - nightly - - stable - # MSRV - - 1.32.0 - -script: - - rustup component add rustfmt - - cargo build --verbose - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cargo test --verbose; fi - - cargo fmt -- --check diff --git a/Cargo.toml b/Cargo.toml index 6c16f7b5..8a987b3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,18 +6,19 @@ authors = ["Paul Osborne "] license = "MIT/Apache-2.0" repository = "https://github.com/rust-embedded/rust-i2cdev" homepage = "https://github.com/rust-embedded/rust-i2cdev" -documentation = "http://rust-embedded.github.io/rust-i2cdev" +documentation = "https://docs.rs/i2cdev" +readme = "README.md" +keywords = ["linux"] +categories = ["embedded", "hardware-support"] description = """ Provides API for safe access to Linux i2c device interface. - -https://www.kernel.org/doc/Documentation/i2c/dev-interface """ [dependencies] libc = "0.2" bitflags = "1" byteorder = "1" -nix = "0.14" +nix = "0.22" [dev-dependencies] docopt = "1" diff --git a/README.md b/README.md index 6d2b80e6..9ca65c3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rust I2cdev -[![Build Status](https://travis-ci.org/rust-embedded/rust-i2cdev.svg?branch=master)](https://travis-ci.org/rust-embedded/rust-i2cdev) +[![Build Status](https://github.com/rust-embedded/rust-i2cdev/workflows/CI/badge.svg)](https://github.com/rust-embedded/rust-i2cdev/actions) [![Version](https://img.shields.io/crates/v/i2cdev.svg)](https://crates.io/crates/i2cdev) [![License](https://img.shields.io/crates/l/i2cdev.svg)](https://github.com/rust-embedded/rust-i2cdev/blob/master/README.md#license) @@ -53,7 +53,7 @@ cross-compile. See https://github.com/japaric/rust-cross for pointers. ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.32.0 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might* compile with older versions but that may change in any new patch release. ## License diff --git a/examples/nunchuck.rs b/examples/nunchuck.rs index 2e7d03e8..fc2b67df 100644 --- a/examples/nunchuck.rs +++ b/examples/nunchuck.rs @@ -40,19 +40,12 @@ mod nunchuck { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { NunchuckError::Error(ref e) => fmt::Display::fmt(e, f), - NunchuckError::ParseError => fmt::Display::fmt(self.description(), f), + NunchuckError::ParseError => write!(f, "Could not parse data"), } } } impl Error for NunchuckError { - fn description(&self) -> &str { - match *self { - NunchuckError::Error(ref e) => e.description(), - NunchuckError::ParseError => "Unable to Parse Data", - } - } - fn cause(&self) -> Option<&dyn Error> { match *self { NunchuckError::Error(ref e) => Some(e), @@ -129,10 +122,9 @@ mod nunchuck { let mut buf: [u8; 6] = [0; 6]; // tell the nunchuck to prepare a sample - try!(self - .i2cdev + self.i2cdev .smbus_write_byte(0x00) - .map_err(NunchuckError::Error)); + .map_err(NunchuckError::Error)?; // now, read it! thread::sleep(Duration::from_millis(10)); diff --git a/examples/sensors.rs b/examples/sensors.rs index 189c6b7e..a9f3f7ba 100644 --- a/examples/sensors.rs +++ b/examples/sensors.rs @@ -173,8 +173,8 @@ mod sensors { i2cdev.smbus_write_byte_data(REGISTER_POWER_CTL, 0x00)?; // configure some defaults - try!(i2cdev - .smbus_write_byte_data(REGISTER_BW_RATE, ADXL345DataRate::RATE_1600HZ as u8)); + i2cdev + .smbus_write_byte_data(REGISTER_BW_RATE, ADXL345DataRate::RATE_1600HZ as u8)?; i2cdev.smbus_write_byte_data(REGISTER_DATA_FORMAT, 0x08)?; i2cdev.smbus_write_byte_data(REGISTER_OFSX, 0xFD)?; i2cdev.smbus_write_byte_data(REGISTER_OFSY, 0x03)?; diff --git a/src/ffi.rs b/src/ffi.rs index 1236c579..472ecb13 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -174,7 +174,7 @@ unsafe fn i2c_smbus_access( size: I2CSMBusSize, data: *mut i2c_smbus_data, ) -> Result<(), I2CError> { - let mut args = i2c_smbus_ioctl_data { + let args = i2c_smbus_ioctl_data { read_write: read_write as u8, command, size: size as u32, @@ -182,7 +182,7 @@ unsafe fn i2c_smbus_access( }; // remove type information - ioctl::i2c_smbus(fd, &mut args).map(drop) + ioctl::i2c_smbus(fd, &args).map(drop) } #[inline] @@ -375,7 +375,7 @@ fn copy_to_i2c_block_data(values: &[u8], max_size: usize) -> i2c_smbus_data { #[inline] pub fn i2c_smbus_write_block_data(fd: RawFd, register: u8, values: &[u8]) -> Result<(), I2CError> { - let mut data = copy_to_i2c_block_data(&values, 32); + let mut data = copy_to_i2c_block_data(values, 32); unsafe { i2c_smbus_access( fd, @@ -393,7 +393,7 @@ pub fn i2c_smbus_write_i2c_block_data( register: u8, values: &[u8], ) -> Result<(), I2CError> { - let mut data = copy_to_i2c_block_data(&values, 32); + let mut data = copy_to_i2c_block_data(values, 32); unsafe { i2c_smbus_access( fd, @@ -411,7 +411,7 @@ pub fn i2c_smbus_process_call_block( register: u8, values: &[u8], ) -> Result, I2CError> { - let mut data = copy_to_i2c_block_data(&values, 31); + let mut data = copy_to_i2c_block_data(values, 31); unsafe { i2c_smbus_access( fd, diff --git a/src/linux.rs b/src/linux.rs index 915887ad..53968382 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -57,10 +57,7 @@ impl From for io::Error { fn from(e: LinuxI2CError) -> io::Error { match e { LinuxI2CError::Io(e) => e, - LinuxI2CError::Nix(e) => match e { - nix::Error::Sys(e) => io::Error::from_raw_os_error(e as i32), - e => io::Error::new(io::ErrorKind::InvalidInput, format!("{:?}", e)), - }, + LinuxI2CError::Nix(e) => e.into(), } } } @@ -75,13 +72,6 @@ impl fmt::Display for LinuxI2CError { } impl Error for LinuxI2CError { - fn description(&self) -> &str { - match *self { - LinuxI2CError::Io(ref e) => e.description(), - LinuxI2CError::Nix(ref e) => e.description(), - } - } - fn cause(&self) -> Option<&dyn Error> { match *self { LinuxI2CError::Io(ref e) => Some(e), diff --git a/src/mock.rs b/src/mock.rs index bc292e88..058708a9 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -35,7 +35,7 @@ impl I2CRegisterMap { /// Set several registers starting at the given offset pub fn write_regs(&mut self, offset: usize, data: &[u8]) { println!("WRITE | 0x{:X} : {:?}", offset, data); - self.registers[offset..(data.len() + offset)].clone_from_slice(&data); + self.registers[offset..(data.len() + offset)].clone_from_slice(data); } }