diff --git a/.github/bors.toml b/.github/bors.toml index ca42be0..b47d1a9 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -1,4 +1,8 @@ block_labels = ["needs-decision"] delete_merged_branches = true required_approvals = 1 -status = ["continuous-integration/travis-ci/push"] +status = [ + "CI (stable, x86_64-unknown-linux-gnu)", + "CI (stable, armv7-unknown-linux-gnueabihf)", + "CI (1.35.0, x86_64-unknown-linux-gnu)", +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..68596fd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Continuous integration + +jobs: + ci-linux: + name: CI + runs-on: ubuntu-latest + + strategy: + fail-fast: false + 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.35.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 + with: + command: check + args: --target=${{ matrix.TARGET }} diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..adc3a6e --- /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: stable + 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 0000000..9a55c00 --- /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 062bb3a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,78 +0,0 @@ -language: rust - - - -matrix: - include: - - env: TARGET=armv7-unknown-linux-gnueabihf - rust: nightly - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - addons: - apt: - packages: - - libc6-armhf-cross - - libc6-dev-armhf-cross - - gcc-arm-linux-gnueabihf - - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - - env: TARGET=armv7-unknown-linux-gnueabihf - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - addons: - apt: - packages: - - libc6-armhf-cross - - libc6-dev-armhf-cross - - gcc-arm-linux-gnueabihf - - - - env: TARGET=x86_64-unknown-linux-gnu - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - # MSRV - - env: TARGET=armv7-unknown-linux-gnueabihf - rust: 1.36.0 - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - addons: - apt: - packages: - - libc6-armhf-cross - - libc6-dev-armhf-cross - - gcc-arm-linux-gnueabihf - - # MSRV - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.36.0 - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - -before_install: - - set -e - - rustup self update - -install: - - bash ci/install.sh - -script: - - bash ci/script.sh - -after_script: set +e - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -branches: - only: - - master - - trying - - staging - -notifications: - email: - on_success: never diff --git a/src/lib.rs b/src/lib.rs index 32ee25d..f03c925 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,6 @@ pub use sysfs_gpio; #[cfg(feature = "gpio_cdev")] pub use gpio_cdev; - use core::convert::Infallible; use std::io::{self, Write}; use std::path::{Path, PathBuf}; @@ -202,10 +201,7 @@ impl embedded_hal::blocking::i2c::WriteRead for I2cdev { buffer: &mut [u8], ) -> Result<(), Self::Error> { self.set_address(address)?; - let mut messages = [ - LinuxI2CMessage::write(bytes), - LinuxI2CMessage::read(buffer), - ]; + let mut messages = [LinuxI2CMessage::write(bytes), LinuxI2CMessage::read(buffer)]; self.inner.transfer(&mut messages).map(drop) } } @@ -213,8 +209,11 @@ impl embedded_hal::blocking::i2c::WriteRead for I2cdev { impl embedded_hal::blocking::i2c::Transactional for I2cdev { type Error = i2cdev::linux::LinuxI2CError; - fn try_exec(&mut self, address: u8, operations: &mut [I2cOperation]) -> Result<(), Self::Error> - { + fn try_exec( + &mut self, + address: u8, + operations: &mut [I2cOperation], + ) -> Result<(), Self::Error> { // Map operations from generic to linux objects let mut messages: Vec<_> = operations .as_mut() @@ -280,30 +279,32 @@ impl embedded_hal::blocking::spi::Write for Spidev { } } -pub use embedded_hal::blocking::spi::{Operation as SpiOperation}; +pub use embedded_hal::blocking::spi::Operation as SpiOperation; /// Transactional implementation batches SPI operations into a single transaction impl embedded_hal::blocking::spi::Transactional for Spidev { type Error = io::Error; fn try_exec<'a>(&mut self, operations: &mut [SpiOperation<'a, u8>]) -> Result<(), Self::Error> { - // Map types from generic to linux objects - let mut messages: Vec<_> = operations.iter_mut().map(|a| { - match a { - SpiOperation::Write(w) => SpidevTransfer::write(w), - SpiOperation::Transfer(r) => { - // Clone read to write pointer - // SPIdev is okay with having w == r but this is tricky to achieve in safe rust - let w = unsafe { - let p = r.as_ptr(); - std::slice::from_raw_parts(p, r.len()) - }; - - SpidevTransfer::read_write(w, r) - }, - } - }).collect(); + let mut messages: Vec<_> = operations + .iter_mut() + .map(|a| { + match a { + SpiOperation::Write(w) => SpidevTransfer::write(w), + SpiOperation::Transfer(r) => { + // Clone read to write pointer + // SPIdev is okay with having w == r but this is tricky to achieve in safe rust + let w = unsafe { + let p = r.as_ptr(); + std::slice::from_raw_parts(p, r.len()) + }; + + SpidevTransfer::read_write(w, r) + } + } + }) + .collect(); // Execute transfer self.0.transfer_multiple(&mut messages)