diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44635006..8af25e98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,31 +31,21 @@ jobs: TARGET: x86_64-unknown-linux-gnu steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master 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 + run: sudo apt-get update && sudo apt-get install -y libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf - - uses: actions-rs/cargo@v1 + - run: cargo test --target=${{ matrix.TARGET }} if: ${{ matrix.TARGET != 'armv7-unknown-linux-gnueabihf' }} - with: - command: test - args: --target=${{ matrix.TARGET }} - - - uses: actions-rs/cargo@v1 + - run: cargo build --target=${{ matrix.TARGET }} if: ${{ matrix.TARGET == 'armv7-unknown-linux-gnueabihf' }} - with: - command: build - args: --target=${{ matrix.TARGET }} ci-macos: name: CI-macOS @@ -67,16 +57,10 @@ jobs: TARGET: [x86_64-apple-darwin] steps: - - uses: actions/checkout@v2 - - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} target: ${{ matrix.TARGET }} - override: true - - uses: actions-rs/cargo@v1 - with: - command: build - args: --target=${{ matrix.TARGET }} + - run: cargo build --target=${{ matrix.TARGET }} diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index f2c654ac..e6bc5bf9 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -10,13 +10,9 @@ jobs: clippy_check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal - toolchain: 1.55.0 - override: true + toolchain: 1.71.0 components: clippy - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + - run: cargo clippy diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index de591564..9c597032 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -12,14 +12,9 @@ jobs: name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal - toolchain: stable - override: true + toolchain: 1.71.0 components: rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all -- --check diff --git a/CHANGELOG.md b/CHANGELOG.md index ac10d5a3..925fc4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v0.6.0] - 2023-08-03 + - Hide nix from the public api such that it can be updated without resulting in a breaking change. -- Updated nix to version `0.25`. -- Updated nix to version `0.24`; only use the `ioctl` feature. +- Updated nix to version `0.26`; only use the `ioctl` feature. +- Updated `bitflags` to version `2.3`. - Use `File.read_exact` instead of `File.read` in `LinuxI2CDevice.read` so that the buffer is filled. - Fix the lifetime parameter on `LinuxI2CMessage` to ensure that it does not outlive the buffer it points to. - Updated MSRV to 1.60.0. @@ -31,6 +33,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). The changelog for previous versions was not recorded. -[Unreleased]: https://github.com/rust-embedded/rust-i2cdev/compare/0.5.1...HEAD +[Unreleased]: https://github.com/rust-embedded/rust-i2cdev/compare/0.6.0...HEAD +[v0.6.0]: https://github.com/rust-embedded/rust-i2cdev/compare/0.5.1...0.6.0 [v0.5.1]: https://github.com/rust-embedded/rust-i2cdev/compare/0.5.0...0.5.1 [v0.5.0]: https://github.com/rust-embedded/rust-i2cdev/compare/0.4.0...0.5.0 diff --git a/Cargo.toml b/Cargo.toml index 8e681f3c..a3b1e3b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "i2cdev" -version = "0.5.1" -authors = ["Paul Osborne "] +version = "0.6.0" +authors = [ + "Paul Osborne ", + "The Embedded Linux Team " +] license = "MIT/Apache-2.0" repository = "https://github.com/rust-embedded/rust-i2cdev" homepage = "https://github.com/rust-embedded/rust-i2cdev" @@ -16,9 +19,9 @@ Provides API for safe access to Linux i2c device interface. [dependencies] libc = "0.2" -bitflags = "1.3" +bitflags = "2.3" byteorder = "1" -nix = { version = "0.25", default-features = false, features = ["ioctl"] } +nix = { version = "0.26.2", default-features = false, features = ["ioctl"] } [dev-dependencies] docopt = "1" diff --git a/LICENSE-MIT b/LICENSE-MIT index c70652f0..e320efc2 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015 Paul Osborne +Copyright (c) 2021-2023 The Rust Embedded Linux Team and contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.md b/README.md index 7bc280d7..642e92fa 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![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) +![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.60+-blue.svg) [Documentation](https://docs.rs/i2cdev) @@ -49,7 +50,7 @@ The following features are implemented and planned for the library: Most likely, the machine you are running on is not your development machine (although it could be). In those cases, you will need to -cross-compile. See https://github.com/japaric/rust-cross for pointers. +cross-compile. See for pointers. ## Minimum Supported Rust Version (MSRV) diff --git a/examples/nunchuck.rs b/examples/nunchuck.rs index 50f5e980..9af0242c 100644 --- a/examples/nunchuck.rs +++ b/examples/nunchuck.rs @@ -58,13 +58,13 @@ mod nunchuck { #[derive(Debug)] pub struct NunchuckReading { - joystick_x: u8, - joystick_y: u8, - accel_x: u16, // 10-bit - accel_y: u16, // 10-bit - accel_z: u16, // 10-bit - c_button_pressed: bool, - z_button_pressed: bool, + pub joystick_x: u8, + pub joystick_y: u8, + pub accel_x: u16, // 10-bit + pub accel_y: u16, // 10-bit + pub accel_z: u16, // 10-bit + pub c_button_pressed: bool, + pub z_button_pressed: bool, } impl NunchuckReading { diff --git a/examples/sensors.rs b/examples/sensors.rs index a9f3f7ba..4fc9c0cb 100644 --- a/examples/sensors.rs +++ b/examples/sensors.rs @@ -285,9 +285,8 @@ mod sensors { // If values are less than 16 bytes, need to adjust let extrabits = 16 - integer_bits - fractional_bits - 1; let rawval: i16 = BigEndian::read_i16(&[msb, lsb]); - let adj = (f32::from(rawval) / 2_f32.powi(fractional_bits + extrabits)) - / 10_f32.powi(dec_pt_zero_pad); - adj + (f32::from(rawval) / 2_f32.powi(fractional_bits + extrabits)) + / 10_f32.powi(dec_pt_zero_pad) } impl MPL115A2Coefficients { diff --git a/src/ffi.rs b/src/ffi.rs index fbe733d4..aaab92c2 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -55,24 +55,24 @@ bitflags! { const I2C_FUNC_SMBUS_READ_I2C_BLOCK = 0x0400_0000; /* I2C-like block xfer */ const I2C_FUNC_SMBUS_WRITE_I2C_BLOCK = 0x0800_0000; /* w/ 1-byte reg. addr. */ - const I2C_FUNC_SMBUS_BYTE = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE.bits); - const I2C_FUNC_SMBUS_BYTE_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE_DATA.bits); - const I2C_FUNC_SMBUS_WORD_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_WORD_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_WORD_DATA.bits); - const I2C_FUNC_SMBUS_BLOCK_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BLOCK_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits); - const I2C_FUNC_SMBUS_I2C_BLOCK = (I2CFunctions::I2C_FUNC_SMBUS_READ_I2C_BLOCK.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_I2C_BLOCK.bits); - const I2C_FUNC_SMBUS_EMUL = (I2CFunctions::I2C_FUNC_SMBUS_QUICK.bits | - I2CFunctions::I2C_FUNC_SMBUS_BYTE.bits | - I2CFunctions::I2C_FUNC_SMBUS_BYTE_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_WORD_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_PROC_CALL.bits | - I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits | - I2CFunctions::I2C_FUNC_SMBUS_I2C_BLOCK.bits | - I2CFunctions::I2C_FUNC_SMBUS_PEC.bits); + const I2C_FUNC_SMBUS_BYTE = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE.bits()); + const I2C_FUNC_SMBUS_BYTE_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE_DATA.bits()); + const I2C_FUNC_SMBUS_WORD_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_WORD_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_WORD_DATA.bits()); + const I2C_FUNC_SMBUS_BLOCK_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BLOCK_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits()); + const I2C_FUNC_SMBUS_I2C_BLOCK = (I2CFunctions::I2C_FUNC_SMBUS_READ_I2C_BLOCK.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_I2C_BLOCK.bits()); + const I2C_FUNC_SMBUS_EMUL = (I2CFunctions::I2C_FUNC_SMBUS_QUICK.bits() | + I2CFunctions::I2C_FUNC_SMBUS_BYTE.bits() | + I2CFunctions::I2C_FUNC_SMBUS_BYTE_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WORD_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_PROC_CALL.bits() | + I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits() | + I2CFunctions::I2C_FUNC_SMBUS_I2C_BLOCK.bits() | + I2CFunctions::I2C_FUNC_SMBUS_PEC.bits()); } } @@ -354,7 +354,7 @@ pub fn i2c_smbus_read_block_data(fd: RawFd, register: u8) -> Result, I2C // create a vector from the data in the block starting at byte // 1 and ending after count bytes after that let count = data.block[0]; - Ok((&data.block[1..(count + 1) as usize]).to_vec()) + Ok((data.block[1..(count + 1) as usize]).to_vec()) } pub fn i2c_smbus_read_i2c_block_data( @@ -377,7 +377,7 @@ pub fn i2c_smbus_read_i2c_block_data( // create a vector from the data in the block starting at byte // 1 and ending after count bytes after that let count = data.block[0]; - Ok((&data.block[1..(count + 1) as usize]).to_vec()) + Ok((data.block[1..(count + 1) as usize]).to_vec()) } #[inline] @@ -445,7 +445,7 @@ pub fn i2c_smbus_process_call_block( // create a vector from the data in the block starting at byte // 1 and ending after count bytes after that let count = data.block[0]; - Ok((&data.block[1..(count + 1) as usize]).to_vec()) + Ok((data.block[1..(count + 1) as usize]).to_vec()) } #[inline] diff --git a/src/linux.rs b/src/linux.rs index 18cbb180..4e855037 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -301,7 +301,7 @@ impl<'a> I2CTransfer<'a> for LinuxI2CDevice { /// Issue the provided sequence of I2C transactions fn transfer(&mut self, messages: &'a mut [Self::Message]) -> Result { for msg in messages.iter_mut() { - (*msg).addr = self.slave_address; + msg.addr = self.slave_address; } ffi::i2c_rdwr(self.as_raw_fd(), messages).map_err(From::from) }