Skip to content

Commit 97a84f8

Browse files
sanzoghenzoeldruin
andauthored
chore: upgrade to embedded-hal v1.0.0 (#2)
* chore: upgrade to embedded-hal v1.0.0 * ci: upgrade actions - upgrade checkout action - use maintained rust toolchain - remove old rust verion from matrix - run cargo directly - switch coverage action to llvm-cov * Update CHANGELOG.md --------- Co-authored-by: Diego Barrios Romero <[email protected]>
1 parent 4328b27 commit 97a84f8

File tree

14 files changed

+72
-92
lines changed

14 files changed

+72
-92
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
rust: [stable, 1.31.0]
16+
rust: [stable]
1717
TARGET:
1818
- x86_64-unknown-linux-gnu
1919
- x86_64-unknown-linux-musl
@@ -26,16 +26,14 @@ jobs:
2626
- thumbv7m-none-eabi
2727

2828
steps:
29-
- uses: actions/checkout@v2
30-
- uses: actions-rs/toolchain@v1
29+
- uses: actions/checkout@v4
30+
- uses: dtolnay/rust-toolchain@master
3131
with:
32-
profile: minimal
3332
toolchain: ${{ matrix.rust }}
3433
target: ${{ matrix.TARGET }}
35-
override: true
3634

3735
- name: Checkout CI scripts
38-
uses: actions/checkout@v2
36+
uses: actions/checkout@v4
3937
with:
4038
repository: 'eldruin/rust-driver-ci-scripts'
4139
ref: 'master'
@@ -45,10 +43,7 @@ jobs:
4543
if: ${{ ! contains(matrix.TARGET, 'x86_64') }}
4644

4745
- name: Build
48-
uses: actions-rs/cargo@v1
49-
with:
50-
command: build
51-
args: --target=${{ matrix.TARGET }}
46+
run: cargo build --target=${{ matrix.TARGET }}
5247

5348
checks:
5449
name: Checks
@@ -60,89 +55,72 @@ jobs:
6055
- x86_64-unknown-linux-gnu
6156

6257
steps:
63-
- uses: actions/checkout@v2
64-
- uses: actions-rs/toolchain@v1
58+
- uses: actions/checkout@v4
59+
- uses: dtolnay/rust-toolchain@master
6560
with:
66-
profile: minimal
6761
toolchain: ${{ matrix.rust }}
6862
target: ${{ matrix.TARGET }}
69-
override: true
7063
components: rustfmt
7164

7265
- name: Doc
73-
uses: actions-rs/cargo@v1
74-
with:
75-
command: doc
66+
run: cargo doc
7667

7768
- name: Formatting
78-
uses: actions-rs/cargo@v1
79-
with:
80-
command: fmt
81-
args: --all -- --check
69+
run: cargo fmt --all -- --check
8270

8371
clippy:
8472
name: Clippy
8573
runs-on: ubuntu-latest
8674
strategy:
8775
matrix:
88-
rust: [1.54.0]
76+
rust: [stable]
8977
TARGET:
9078
- x86_64-unknown-linux-gnu
9179

9280
steps:
93-
- uses: actions/checkout@v2
94-
- uses: actions-rs/toolchain@v1
81+
- uses: actions/checkout@v4
82+
- uses: dtolnay/rust-toolchain@master
9583
with:
96-
profile: minimal
9784
toolchain: ${{ matrix.rust }}
9885
target: ${{ matrix.TARGET }}
99-
override: true
10086
components: clippy
10187

102-
- name: Clippy
103-
uses: actions-rs/clippy-check@v1
104-
with:
105-
token: ${{ secrets.GITHUB_TOKEN }}
88+
- run: cargo clippy --message-format=json --all-features
10689

10790
test:
10891
name: Tests
10992
runs-on: ubuntu-latest
11093
strategy:
11194
matrix:
112-
rust: [stable, beta]
95+
rust: [stable]
11396
TARGET: [x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl]
11497
steps:
115-
- uses: actions/checkout@v2
116-
- uses: actions-rs/toolchain@v1
98+
- uses: actions/checkout@v4
99+
- uses: dtolnay/rust-toolchain@master
117100
with:
118-
profile: minimal
119101
toolchain: ${{ matrix.rust }}
120102
target: ${{ matrix.TARGET }}
121-
override: true
122103

123104
- name: Test
124-
uses: actions-rs/cargo@v1
125-
with:
126-
command: test
127-
args: --target=${{ matrix.TARGET }}
105+
run: cargo test --target=${{ matrix.TARGET }}
128106

129107
coverage:
130108
name: Coverage
131109
runs-on: ubuntu-latest
132110
steps:
133111
- name: Checkout repository
134-
uses: actions/checkout@v2
112+
uses: actions/checkout@v4
135113

136114
- name: Install stable toolchain
137-
uses: actions-rs/toolchain@v1
115+
uses: dtolnay/rust-toolchain@master
138116
with:
139117
toolchain: stable
140-
override: true
141118

142-
- name: Run cargo-tarpaulin
143-
uses: actions-rs/[email protected]
144-
with:
145-
args: '--out Lcov -- --test-threads 1'
119+
- name: Install cargo-llvm-cov
120+
uses: taiki-e/install-action@cargo-llvm-cov
121+
122+
- name: Generate code coverage
123+
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
146124

147125
- name: upload to Coveralls
148126
uses: coverallsapp/github-action@master

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Changed
1111
- Updated dependencies
12+
- [breaking-change] upgrade project to support embedded-hal v1.0.0
1213

1314
## [0.2.0] - 2020-09-10
1415

@@ -23,4 +24,4 @@ Initial release to crates.io.
2324

2425
[Unreleased]: https://github.com/eldruin/embedded-ccs811-rs/compare/v0.2.0...HEAD
2526
[0.2.0]: https://github.com/eldruin/embedded-ccs811-rs/compare/v0.1.0...v0.2.0
26-
[0.1.0]: https://github.com/eldruin/embedded-ccs811-rs/releases/tag/v0.1.0
27+
[0.1.0]: https://github.com/eldruin/embedded-ccs811-rs/releases/tag/v0.1.0

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ include = [
2121
edition = "2018"
2222

2323
[dependencies]
24-
embedded-hal = "0.2.6"
24+
embedded-hal = "1.0.0"
2525
nb = "1"
2626

2727
[dev-dependencies]
28-
linux-embedded-hal = "0.3"
29-
embedded-hal-mock = "0.8"
28+
embedded-hal-mock = { version = "0.11.1", features = ["eh1"] }
29+
linux-embedded-hal = { version = "0.4", features = ["gpio_cdev"] }
3030

3131
[profile.release]
3232
lto = true

src/app_mode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::hal::{blocking::delay::DelayUs, digital::v2::OutputPin};
1+
use crate::hal::{delay::DelayNs, digital::OutputPin};
22
use crate::{
33
hal, mode, register_access::get_errors, AlgorithmResult, BitFlags, Ccs811, Ccs811AppMode,
44
Ccs811Awake, Error, ErrorAwake, InterruptMode, MeasurementMode, ModeChangeError, Register,
55
};
66

77
impl<I2C, E> Ccs811AppMode for Ccs811Awake<I2C, mode::App>
88
where
9-
I2C: hal::blocking::i2c::Write<Error = E> + hal::blocking::i2c::WriteRead<Error = E>,
9+
I2C: hal::i2c::I2c<Error = E>,
1010
{
1111
type Error = ErrorAwake<E>;
1212
type ModeChangeError = ModeChangeError<ErrorAwake<E>, Self>;
@@ -164,9 +164,9 @@ fn handle_raw_data(data0: u8, data1: u8) -> (u8, u16) {
164164

165165
impl<I2C, CommE, PinE, NWAKE, WAKEDELAY> Ccs811AppMode for Ccs811<I2C, NWAKE, WAKEDELAY, mode::App>
166166
where
167-
I2C: hal::blocking::i2c::Write<Error = CommE> + hal::blocking::i2c::WriteRead<Error = CommE>,
167+
I2C: hal::i2c::I2c<Error = CommE>,
168168
NWAKE: OutputPin<Error = PinE>,
169-
WAKEDELAY: DelayUs<u8>,
169+
WAKEDELAY: DelayNs,
170170
{
171171
type Error = Error<CommE, PinE>;
172172
type ModeChangeError = ModeChangeError<Error<CommE, PinE>, Self>;

src/boot_mode.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
use crate::hal::{
2-
blocking::delay::{DelayMs, DelayUs},
3-
digital::v2::OutputPin,
4-
};
1+
use crate::hal::{delay::DelayNs, digital::OutputPin};
52
use crate::{
63
hal, mode, ActionInProgress, BitFlags, Ccs811, Ccs811Awake, Ccs811BootMode, Ccs811Device,
74
Error, ErrorAwake, ModeChangeError, Register,
85
};
96

107
impl<I2C, E> Ccs811BootMode for Ccs811Awake<I2C, mode::Boot>
118
where
12-
I2C: hal::blocking::i2c::Write<Error = E> + hal::blocking::i2c::WriteRead<Error = E>,
9+
I2C: hal::i2c::I2c<Error = E>,
1310
{
1411
type Error = ErrorAwake<E>;
1512
type ModeChangeError = ModeChangeError<Self::Error, Self>;
@@ -81,7 +78,7 @@ where
8178
}
8279
}
8380

84-
fn download_application<D: DelayMs<u16>>(
81+
fn download_application<D: DelayNs>(
8582
&mut self,
8683
bin: &[u8],
8784
delay: &mut D,
@@ -101,7 +98,7 @@ where
10198
self.check_status_error()
10299
}
103100

104-
fn update_application<D: DelayMs<u16>>(
101+
fn update_application<D: DelayNs>(
105102
&mut self,
106103
bin: &[u8],
107104
delay: &mut D,
@@ -135,9 +132,9 @@ where
135132
impl<I2C, CommE, PinE, NWAKE, WAKEDELAY> Ccs811BootMode
136133
for Ccs811<I2C, NWAKE, WAKEDELAY, mode::Boot>
137134
where
138-
I2C: hal::blocking::i2c::Write<Error = CommE> + hal::blocking::i2c::WriteRead<Error = CommE>,
135+
I2C: hal::i2c::I2c<Error = CommE>,
139136
NWAKE: OutputPin<Error = PinE>,
140-
WAKEDELAY: DelayUs<u8>,
137+
WAKEDELAY: DelayNs,
141138
{
142139
type Error = Error<CommE, PinE>;
143140
type ModeChangeError = ModeChangeError<Self::Error, Self>;
@@ -155,15 +152,15 @@ where
155152
self.on_awaken_nb(|s| s.dev.erase_application())
156153
}
157154

158-
fn download_application<D: DelayMs<u16>>(
155+
fn download_application<D: DelayNs>(
159156
&mut self,
160157
bin: &[u8],
161158
delay: &mut D,
162159
) -> Result<(), Self::Error> {
163160
self.on_awaken(|s| s.dev.download_application(bin, delay))
164161
}
165162

166-
fn update_application<D: DelayMs<u16>>(
163+
fn update_application<D: DelayNs>(
167164
&mut self,
168165
bin: &[u8],
169166
delay: &mut D,

src/common_impl.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::hal::{blocking::delay::DelayUs, digital::v2::OutputPin};
1+
use crate::hal::{delay::DelayNs, digital::OutputPin};
22
use crate::{
33
hal, mode, ActionInProgress, BitFlags, Ccs811, Ccs811Awake, Ccs811Device, Error, ErrorAwake,
44
FirmwareMode, ModeChangeError, Register, SlaveAddr,
@@ -54,7 +54,7 @@ impl<I2C, MODE> Ccs811Awake<I2C, MODE> {
5454

5555
impl<I2C, E, MODE> Ccs811Awake<I2C, MODE>
5656
where
57-
I2C: hal::blocking::i2c::Write<Error = E>,
57+
I2C: hal::i2c::I2c<Error = E>,
5858
{
5959
/// Destroy driver instance, return I²C bus instance.
6060
pub fn destroy(self) -> I2C {
@@ -63,7 +63,7 @@ where
6363
}
6464
impl<I2C, E, MODE> Ccs811Awake<I2C, MODE>
6565
where
66-
I2C: hal::blocking::i2c::Write<Error = E> + hal::blocking::i2c::WriteRead<Error = E>,
66+
I2C: hal::i2c::I2c<Error = E>,
6767
{
6868
pub(crate) fn write_sw_reset(&mut self) -> Result<(), ErrorAwake<E>> {
6969
self.i2c
@@ -74,9 +74,9 @@ where
7474

7575
impl<I2C, CommE, PinE, NWAKE, WAKEDELAY, MODE> Ccs811<I2C, NWAKE, WAKEDELAY, MODE>
7676
where
77-
I2C: hal::blocking::i2c::Write<Error = CommE>,
77+
I2C: hal::i2c::I2c<Error = CommE>,
7878
NWAKE: OutputPin<Error = PinE>,
79-
WAKEDELAY: DelayUs<u8>,
79+
WAKEDELAY: DelayNs,
8080
{
8181
/// Destroy driver instance, return I²C bus, nWAKE pin
8282
/// and wake delay instances.
@@ -173,7 +173,7 @@ where
173173

174174
impl<I2C, E, MODE> Ccs811Device for Ccs811Awake<I2C, MODE>
175175
where
176-
I2C: hal::blocking::i2c::Write<Error = E> + hal::blocking::i2c::WriteRead<Error = E>,
176+
I2C: hal::i2c::I2c<Error = E>,
177177
{
178178
type Error = ErrorAwake<E>;
179179

@@ -214,9 +214,9 @@ where
214214

215215
impl<I2C, CommE, PinE, NWAKE, WAKEDELAY, MODE> Ccs811Device for Ccs811<I2C, NWAKE, WAKEDELAY, MODE>
216216
where
217-
I2C: hal::blocking::i2c::Write<Error = CommE> + hal::blocking::i2c::WriteRead<Error = CommE>,
217+
I2C: hal::i2c::I2c<Error = CommE>,
218218
NWAKE: OutputPin<Error = PinE>,
219-
WAKEDELAY: DelayUs<u8>,
219+
WAKEDELAY: DelayNs,
220220
{
221221
type Error = Error<CommE, PinE>;
222222

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,16 @@
104104
//! ### Start the application and take measurements
105105
//!
106106
//! ```no_run
107-
//! use linux_embedded_hal::{I2cdev, Pin, Delay};
107+
//! use linux_embedded_hal::{I2cdev, CdevPin, Delay};
108+
//! use linux_embedded_hal::gpio_cdev::{Chip, LineRequestFlags};
108109
//! use embedded_ccs811::{prelude::*, Ccs811, SlaveAddr, MeasurementMode};
109110
//! use nb::block;
110111
//!
111112
//! let dev = I2cdev::new("/dev/i2c-1").unwrap();
112-
//! let nwake = Pin::new(17);
113+
//! let mut chip = Chip::new("/dev/gpiochip0").unwrap();
114+
//! let handle = chip.get_line(17).unwrap()
115+
//! .request(LineRequestFlags::OUTPUT, 0, "output").unwrap();
116+
//! let nwake = CdevPin::new(handle).unwrap();
113117
//! let delay = Delay {};
114118
//! let address = SlaveAddr::default();
115119
//! let sensor = Ccs811::new(dev, address, nwake, delay);

src/register_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl BitFlags {
4141

4242
impl<I2C, E, MODE> Ccs811Awake<I2C, MODE>
4343
where
44-
I2C: hal::blocking::i2c::Write<Error = E> + hal::blocking::i2c::WriteRead<Error = E>,
44+
I2C: hal::i2c::I2c<Error = E>,
4545
{
4646
pub(crate) fn check_status_error(&mut self) -> Result<(), ErrorAwake<E>> {
4747
self.read_status().map(drop)

src/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{private, AlgorithmResult, FirmwareMode, InterruptMode, MeasurementMode};
2-
use embedded_hal::blocking::delay::DelayMs;
2+
use embedded_hal::delay::DelayNs;
33

44
/// General CCS811 methods available in either mode
55
pub trait Ccs811Device: private::Sealed {
@@ -114,7 +114,7 @@ pub trait Ccs811BootMode: private::Sealed {
114114
/// This resets the device via a software reset, erases the current application,
115115
/// flashes the new binary and verifies it. This takes at least 572ms + 50ms * (bin_size/8).
116116
/// Returns `Error::InvalidInputData` if the input binary lengh is not multiple of 8.
117-
fn update_application<D: DelayMs<u16>>(
117+
fn update_application<D: DelayNs>(
118118
&mut self,
119119
bin: &[u8],
120120
delay: &mut D,
@@ -136,7 +136,7 @@ pub trait Ccs811BootMode: private::Sealed {
136136
///
137137
/// Returns `Error::InvalidInputData` if the input binary lengh is not multiple of 8.
138138
/// This takes at least 50ms * (bin_size/8).
139-
fn download_application<D: DelayMs<u16>>(
139+
fn download_application<D: DelayNs>(
140140
&mut self,
141141
bin: &[u8],
142142
delay: &mut D,

tests/app_mode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use embedded_ccs811::{
22
mode, prelude::*, AlgorithmResult, Ccs811, Error, InterruptMode, MeasurementMode,
33
};
4-
use embedded_hal_mock::{
5-
delay::MockNoop as NoDelay,
4+
use embedded_hal_mock::eh1::{
5+
delay::NoopDelay as NoDelay,
6+
digital::{Mock as PinMock, State as PinState, Transaction as PinTrans},
67
i2c::{Mock as I2cMock, Transaction as I2cTrans},
7-
pin::{Mock as PinMock, State as PinState, Transaction as PinTrans},
88
};
99
mod common;
1010
use crate::common::{destroy, new, BitFlags as BF, Register, DEV_ADDR};

0 commit comments

Comments
 (0)