Skip to content

Commit 5e9c863

Browse files
authored
Add support for embedded-hal version 1.0.0-alpha.8
1 parent 8ea3d00 commit 5e9c863

14 files changed

+818
-353
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Added re-exports for `libftd2xx` and `ftdi` when the respective feature is used.
10+
- Added `embedded-hal` version `1.0.0-alpha.8` trait implementations for:
11+
- GPIOs
12+
- Delay
13+
- SPI
14+
15+
### Changed
16+
- Changed the `embedded-hal` version `0.2` re-export name from `embedded-hal` to
17+
`eh0` to differentiate from `embedded-hal` version `1.0.0-alpha.8`.
1018

1119
## [0.11.0] - 2022-01-18
1220
### Added

Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ libftd2xx-static = ["libftd2xx/static"]
1616
default = []
1717

1818
[dependencies]
19-
nb = "^1"
20-
embedded-hal = { version = "~0.2.4", features = ["unproven"] }
21-
ftdi-mpsse = "^0.1"
22-
libftd2xx = { version = "0.32.0", optional = true }
19+
eh0 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"] }
20+
eh1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
2321
ftdi = { version = "0.1.3", optional = true }
22+
ftdi-mpsse = "0.1"
23+
libftd2xx = { version = "0.32", optional = true }
24+
nb = "1"
2425

2526
[dev-dependencies]
26-
version-sync = "~0.9.2"
27-
spi-memory = "0.2.0"
27+
cfg-if = "1"
2828
eeprom24x = "0.5.0"
2929
lm75 = "0.2.0"
30+
spi-memory = "0.2.0"
31+
version-sync = "0.9.2"
3032

3133
[badges]
3234
maintenance = { status = "experimental" }

examples/at24c04.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ use ftdi_embedded_hal as hal;
44
use std::thread::sleep;
55
use std::time::Duration;
66

7-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
8-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
9-
10-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
11-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
12-
137
fn main() {
14-
#[cfg(feature = "ftdi")]
15-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
16-
.interface(ftdi::Interface::A)
17-
.open()
18-
.unwrap();
19-
20-
#[cfg(feature = "libftd2xx")]
21-
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
8+
cfg_if::cfg_if! {
9+
if #[cfg(feature = "ftdi")] {
10+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
11+
.interface(ftdi::Interface::A)
12+
.open()
13+
.unwrap();
14+
} else if #[cfg(feature = "libftd2xx")] {
15+
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
16+
} else {
17+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
18+
}
19+
}
2220

2321
let hal = hal::FtHal::init_freq(device, 400_000).unwrap();
2422
let i2c = hal.i2c().unwrap();

examples/blink.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
use embedded_hal::digital::v2::OutputPin;
1+
use eh0::digital::v2::OutputPin;
22
use ftdi_embedded_hal as hal;
33
use std::{thread::sleep, time::Duration};
44

55
const NUM_BLINK: usize = 10;
66
const SLEEP_DURATION: Duration = Duration::from_millis(500);
77

8-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
9-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
10-
11-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
12-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
13-
148
fn main() {
15-
#[cfg(feature = "libftd2xx")]
16-
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
17-
18-
#[cfg(feature = "ftdi")]
19-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
20-
.interface(ftdi::Interface::A)
21-
.open()
22-
.unwrap();
9+
cfg_if::cfg_if! {
10+
if #[cfg(feature = "ftdi")] {
11+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
12+
.interface(ftdi::Interface::A)
13+
.open()
14+
.unwrap();
15+
} else if #[cfg(feature = "libftd2xx")] {
16+
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
17+
} else {
18+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
19+
}
20+
}
2321

2422
let hal = hal::FtHal::init_default(device).unwrap();
2523
let mut output_pin = hal.ad3().unwrap();

examples/bme280.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77
//! * https://www.adafruit.com/product/4399
88
//! * https://www.adafruit.com/product/4472
99
10-
use embedded_hal::prelude::*;
10+
use eh0::prelude::*;
1111
use ftdi_embedded_hal as hal;
1212

13-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
14-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
15-
16-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
17-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
18-
1913
fn main() {
20-
#[cfg(feature = "libftd2xx")]
21-
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
22-
23-
#[cfg(feature = "ftdi")]
24-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
25-
.interface(ftdi::Interface::A)
26-
.open()
27-
.unwrap();
14+
cfg_if::cfg_if! {
15+
if #[cfg(feature = "ftdi")] {
16+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
17+
.interface(ftdi::Interface::A)
18+
.open()
19+
.unwrap();
20+
} else if #[cfg(feature = "libftd2xx")] {
21+
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
22+
} else {
23+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
24+
}
25+
}
2826

2927
let hal = hal::FtHal::init_default(device).unwrap();
3028
let mut i2c = hal.i2c().unwrap();

examples/input.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
use embedded_hal::digital::v2::InputPin;
1+
use eh0::digital::v2::InputPin;
22
use ftdi_embedded_hal as hal;
33
use std::{thread::sleep, time::Duration};
44

55
const SLEEP_DURATION: Duration = Duration::from_millis(500);
66

7-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
8-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
9-
10-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
11-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
12-
137
fn main() {
14-
#[cfg(feature = "libftd2xx")]
15-
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
16-
17-
#[cfg(feature = "ftdi")]
18-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
19-
.interface(ftdi::Interface::A)
20-
.open()
21-
.unwrap();
8+
cfg_if::cfg_if! {
9+
if #[cfg(feature = "ftdi")] {
10+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
11+
.interface(ftdi::Interface::A)
12+
.open()
13+
.unwrap();
14+
} else if #[cfg(feature = "libftd2xx")] {
15+
let device: libftd2xx::Ft232h = libftd2xx::Ftdi::new().unwrap().try_into().unwrap();
16+
} else {
17+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
18+
}
19+
}
2220

2321
let hal = hal::FtHal::init_default(device).unwrap();
2422

examples/lm75.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ use lm75::{Address, Lm75};
33
use std::thread::sleep;
44
use std::time::Duration;
55

6-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
7-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
8-
9-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
10-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
11-
126
fn main() {
13-
#[cfg(feature = "ftdi")]
14-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
15-
.interface(ftdi::Interface::A)
16-
.open()
17-
.unwrap();
18-
19-
#[cfg(feature = "libftd2xx")]
20-
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
7+
cfg_if::cfg_if! {
8+
if #[cfg(feature = "ftdi")] {
9+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
10+
.interface(ftdi::Interface::A)
11+
.open()
12+
.unwrap();
13+
} else if #[cfg(feature = "libftd2xx")] {
14+
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
15+
} else {
16+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
17+
}
18+
}
2119

2220
let hal = hal::FtHal::init_freq(device, 400_000).unwrap();
2321
let i2c = hal.i2c().unwrap();

examples/spi-flash.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ use spi_memory::series25::Flash;
44
use std::thread::sleep;
55
use std::time::Duration;
66

7-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
8-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
9-
10-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
11-
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
12-
137
const LINE: u32 = 0x10;
148

159
fn main() {
16-
#[cfg(feature = "ftdi")]
17-
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
18-
.interface(ftdi::Interface::A)
19-
.open()
20-
.unwrap();
21-
22-
#[cfg(feature = "libftd2xx")]
23-
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
10+
cfg_if::cfg_if! {
11+
if #[cfg(feature = "ftdi")] {
12+
let device = ftdi::find_by_vid_pid(0x0403, 0x6014)
13+
.interface(ftdi::Interface::A)
14+
.open()
15+
.unwrap();
16+
let data: [u8; 8] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07];
17+
} else if #[cfg(feature = "libftd2xx")] {
18+
let device = libftd2xx::Ft232h::with_description("Single RS232-HS").unwrap();
19+
let data: [u8; 8] = [0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70];
20+
} else {
21+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
22+
}
23+
}
2424

2525
let hal = hal::FtHal::init_freq(device, 1_000_000).unwrap();
2626
let spi = hal.spi().unwrap();
@@ -31,11 +31,6 @@ fn main() {
3131
let id = flash.read_jedec_id().unwrap();
3232
println!("JEDEC ID: {:?}", id);
3333

34-
#[cfg(feature = "libftd2xx")]
35-
let data: [u8; 8] = [0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70];
36-
#[cfg(feature = "ftdi")]
37-
let data: [u8; 8] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07];
38-
3934
let addrs: [u32; 5] = [0, LINE, 2 * LINE, 3 * LINE, 4 * LINE];
4035
let zero: [u8; 8] = [0; 8];
4136
let mut bytes_w: [u8; 8] = [0; 8];

examples/ws2812.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
use embedded_hal::blocking::spi::Write;
1+
use eh0::blocking::spi::Write;
22
use ftdi_embedded_hal as hal;
33
use std::thread::sleep;
44
use std::time::Duration;
55

6-
#[cfg(all(feature = "ftdi", feature = "libftd2xx"))]
7-
compile_error!("features 'ftdi' and 'libftd2xx' cannot be enabled at the same time");
8-
9-
#[cfg(not(any(feature = "ftdi", feature = "libftd2xx")))]
10-
compile_error!("one of features 'ftdi' and 'libftdi2xx' shall be enabled");
11-
126
fn main() {
13-
#[cfg(feature = "libftd2xx")]
14-
let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A").unwrap();
15-
16-
#[cfg(feature = "ftdi")]
17-
let device = ftdi::find_by_vid_pid(0x0403, 0x6010)
18-
.interface(ftdi::Interface::A)
19-
.open()
20-
.unwrap();
7+
cfg_if::cfg_if! {
8+
if #[cfg(feature = "ftdi")] {
9+
let device = ftdi::find_by_vid_pid(0x0403, 0x6010)
10+
.interface(ftdi::Interface::A)
11+
.open()
12+
.unwrap();
13+
} else if #[cfg(feature = "libftd2xx")] {
14+
let device = libftd2xx::Ft2232h::with_description("Dual RS232-HS A").unwrap();
15+
} else {
16+
compile_error!("one of features 'ftdi' and 'libftd2xx' shall be enabled");
17+
}
18+
}
2119

2220
let hal = hal::FtHal::init_freq(device, 3_000_000).unwrap();
2321
let mut spi = hal.spi().unwrap();

src/delay.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! Implementation of the [`embedded_hal::blocking::delay`] traits.
1+
//! Implementation of the [`eh0::blocking::delay`] and [`eh1::delay::blocking`]
2+
//! traits.
23
34
/// Delay structure.
45
///
@@ -31,23 +32,37 @@ impl Default for Delay {
3132
}
3233
}
3334

34-
macro_rules! impl_delay_for {
35+
impl eh1::delay::blocking::DelayUs for Delay {
36+
type Error = std::convert::Infallible;
37+
38+
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
39+
std::thread::sleep(std::time::Duration::from_micros(us.into()));
40+
Ok(())
41+
}
42+
43+
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
44+
std::thread::sleep(std::time::Duration::from_millis(ms.into()));
45+
Ok(())
46+
}
47+
}
48+
49+
macro_rules! impl_eh0_delay_for {
3550
($UXX:ty) => {
36-
impl embedded_hal::blocking::delay::DelayMs<$UXX> for Delay {
51+
impl eh0::blocking::delay::DelayMs<$UXX> for Delay {
3752
fn delay_ms(&mut self, ms: $UXX) {
3853
std::thread::sleep(std::time::Duration::from_millis(ms.into()))
3954
}
4055
}
4156

42-
impl embedded_hal::blocking::delay::DelayUs<$UXX> for Delay {
57+
impl eh0::blocking::delay::DelayUs<$UXX> for Delay {
4358
fn delay_us(&mut self, us: $UXX) {
4459
std::thread::sleep(std::time::Duration::from_micros(us.into()))
4560
}
4661
}
4762
};
4863
}
4964

50-
impl_delay_for!(u8);
51-
impl_delay_for!(u16);
52-
impl_delay_for!(u32);
53-
impl_delay_for!(u64);
65+
impl_eh0_delay_for!(u8);
66+
impl_eh0_delay_for!(u16);
67+
impl_eh0_delay_for!(u32);
68+
impl_eh0_delay_for!(u64);

0 commit comments

Comments
 (0)