Skip to content

Add github actions CI #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/bors.toml
Original file line number Diff line number Diff line change
@@ -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)",
]
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
20 changes: 20 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
23 changes: 23 additions & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 0 additions & 78 deletions .travis.yml

This file was deleted.

49 changes: 25 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -202,19 +201,19 @@ 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)
}
}

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()
Expand Down Expand Up @@ -280,30 +279,32 @@ impl embedded_hal::blocking::spi::Write<u8> 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<u8> 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)
Expand Down