Skip to content
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @rust-embedded/embedded-linux
10 changes: 10 additions & 0 deletions .github/bors.toml
Original file line number Diff line number Diff line change
@@ -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)",
]
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
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: 1.55.0
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
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ authors = ["Paul Osborne <[email protected]>"]
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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions examples/nunchuck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E: Error> Error for NunchuckError<E> {
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),
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions examples/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
10 changes: 5 additions & 5 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ 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,
data,
};

// remove type information
ioctl::i2c_smbus(fd, &mut args).map(drop)
ioctl::i2c_smbus(fd, &args).map(drop)
}

#[inline]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -411,7 +411,7 @@ pub fn i2c_smbus_process_call_block(
register: u8,
values: &[u8],
) -> Result<Vec<u8>, 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,
Expand Down
12 changes: 1 addition & 11 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ impl From<LinuxI2CError> 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(),
}
}
}
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down