Skip to content

Commit 18d704d

Browse files
committed
Update to embedded-hal-1.0.0-alpha.5
1 parent 4c331ec commit 18d704d

File tree

9 files changed

+53
-57
lines changed

9 files changed

+53
-57
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async-tokio = ["gpio-cdev/async-tokio"]
2020
default = [ "gpio_cdev", "gpio_sysfs" ]
2121

2222
[dependencies]
23-
embedded-hal = "=1.0.0-alpha.4"
23+
embedded-hal = "=1.0.0-alpha.5"
2424
gpio-cdev = { version = "0.4", optional = true }
2525
sysfs_gpio = { version = "0.5", optional = true }
2626

examples/transactional-i2c.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use embedded_hal::blocking::i2c::{Operation as I2cOperation, Transactional};
1+
use embedded_hal::i2c::blocking::{Operation as I2cOperation, Transactional};
22
use linux_embedded_hal::I2cdev;
33

44
const ADDR: u8 = 0x12;
@@ -21,7 +21,7 @@ where
2121
I2cOperation::Write(&[0xAB]),
2222
I2cOperation::Read(&mut read_buffer),
2323
];
24-
self.i2c.try_exec(ADDR, &mut ops).and(Ok(read_buffer[0]))
24+
self.i2c.exec(ADDR, &mut ops).and(Ok(read_buffer[0]))
2525
}
2626
}
2727

src/cdev_pin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ impl CdevPin {
1717
}
1818
}
1919

20-
impl embedded_hal::digital::OutputPin for CdevPin {
20+
impl embedded_hal::digital::blocking::OutputPin for CdevPin {
2121
type Error = gpio_cdev::errors::Error;
2222

23-
fn try_set_low(&mut self) -> Result<(), Self::Error> {
23+
fn set_low(&mut self) -> Result<(), Self::Error> {
2424
if self.1 {
2525
self.0.set_value(1)
2626
} else {
2727
self.0.set_value(0)
2828
}
2929
}
3030

31-
fn try_set_high(&mut self) -> Result<(), Self::Error> {
31+
fn set_high(&mut self) -> Result<(), Self::Error> {
3232
if self.1 {
3333
self.0.set_value(0)
3434
} else {
@@ -37,19 +37,19 @@ impl embedded_hal::digital::OutputPin for CdevPin {
3737
}
3838
}
3939

40-
impl embedded_hal::digital::InputPin for CdevPin {
40+
impl embedded_hal::digital::blocking::InputPin for CdevPin {
4141
type Error = gpio_cdev::errors::Error;
4242

43-
fn try_is_high(&self) -> Result<bool, Self::Error> {
43+
fn is_high(&self) -> Result<bool, Self::Error> {
4444
if !self.1 {
4545
self.0.get_value().map(|val| val != 0)
4646
} else {
4747
self.0.get_value().map(|val| val == 0)
4848
}
4949
}
5050

51-
fn try_is_low(&self) -> Result<bool, Self::Error> {
52-
self.try_is_high().map(|val| !val)
51+
fn is_low(&self) -> Result<bool, Self::Error> {
52+
self.is_high().map(|val| !val)
5353
}
5454
}
5555

src/delay.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use cast::{u32, u64};
66
use core::convert::Infallible;
7-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
7+
use embedded_hal::delay::blocking::{DelayMs, DelayUs};
88
use std::thread;
99
use std::time::Duration;
1010

@@ -14,7 +14,7 @@ pub struct Delay;
1414
impl DelayUs<u8> for Delay {
1515
type Error = Infallible;
1616

17-
fn try_delay_us(&mut self, n: u8) -> Result<(), Self::Error> {
17+
fn delay_us(&mut self, n: u8) -> Result<(), Self::Error> {
1818
thread::sleep(Duration::new(0, u32(n) * 1000));
1919
Ok(())
2020
}
@@ -23,7 +23,7 @@ impl DelayUs<u8> for Delay {
2323
impl DelayUs<u16> for Delay {
2424
type Error = Infallible;
2525

26-
fn try_delay_us(&mut self, n: u16) -> Result<(), Self::Error> {
26+
fn delay_us(&mut self, n: u16) -> Result<(), Self::Error> {
2727
thread::sleep(Duration::new(0, u32(n) * 1000));
2828
Ok(())
2929
}
@@ -32,7 +32,7 @@ impl DelayUs<u16> for Delay {
3232
impl DelayUs<u32> for Delay {
3333
type Error = Infallible;
3434

35-
fn try_delay_us(&mut self, n: u32) -> Result<(), Self::Error> {
35+
fn delay_us(&mut self, n: u32) -> Result<(), Self::Error> {
3636
let secs = n / 1_000_000;
3737
let nsecs = (n % 1_000_000) * 1_000;
3838

@@ -44,7 +44,7 @@ impl DelayUs<u32> for Delay {
4444
impl DelayUs<u64> for Delay {
4545
type Error = Infallible;
4646

47-
fn try_delay_us(&mut self, n: u64) -> Result<(), Self::Error> {
47+
fn delay_us(&mut self, n: u64) -> Result<(), Self::Error> {
4848
let secs = n / 1_000_000;
4949
let nsecs = ((n % 1_000_000) * 1_000) as u32;
5050

@@ -56,7 +56,7 @@ impl DelayUs<u64> for Delay {
5656
impl DelayMs<u8> for Delay {
5757
type Error = Infallible;
5858

59-
fn try_delay_ms(&mut self, n: u8) -> Result<(), Self::Error> {
59+
fn delay_ms(&mut self, n: u8) -> Result<(), Self::Error> {
6060
thread::sleep(Duration::from_millis(u64(n)));
6161
Ok(())
6262
}
@@ -65,7 +65,7 @@ impl DelayMs<u8> for Delay {
6565
impl DelayMs<u16> for Delay {
6666
type Error = Infallible;
6767

68-
fn try_delay_ms(&mut self, n: u16) -> Result<(), Self::Error> {
68+
fn delay_ms(&mut self, n: u16) -> Result<(), Self::Error> {
6969
thread::sleep(Duration::from_millis(u64(n)));
7070
Ok(())
7171
}
@@ -74,7 +74,7 @@ impl DelayMs<u16> for Delay {
7474
impl DelayMs<u32> for Delay {
7575
type Error = Infallible;
7676

77-
fn try_delay_ms(&mut self, n: u32) -> Result<(), Self::Error> {
77+
fn delay_ms(&mut self, n: u32) -> Result<(), Self::Error> {
7878
thread::sleep(Duration::from_millis(u64(n)));
7979
Ok(())
8080
}
@@ -83,7 +83,7 @@ impl DelayMs<u32> for Delay {
8383
impl DelayMs<u64> for Delay {
8484
type Error = Infallible;
8585

86-
fn try_delay_ms(&mut self, n: u64) -> Result<(), Self::Error> {
86+
fn delay_ms(&mut self, n: u64) -> Result<(), Self::Error> {
8787
thread::sleep(Duration::from_millis(n));
8888
Ok(())
8989
}

src/i2c.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl ops::DerefMut for I2cdev {
5555

5656
mod embedded_hal_impl {
5757
use super::*;
58-
use embedded_hal::blocking::i2c::{
58+
use embedded_hal::i2c::blocking::{
5959
Operation as I2cOperation, Read, Transactional, Write, WriteRead,
6060
};
6161
use i2cdev::core::{I2CDevice, I2CMessage, I2CTransfer};
@@ -64,7 +64,7 @@ mod embedded_hal_impl {
6464
impl Read for I2cdev {
6565
type Error = i2cdev::linux::LinuxI2CError;
6666

67-
fn try_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
67+
fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
6868
self.set_address(address)?;
6969
self.inner.read(buffer)
7070
}
@@ -73,7 +73,7 @@ mod embedded_hal_impl {
7373
impl Write for I2cdev {
7474
type Error = i2cdev::linux::LinuxI2CError;
7575

76-
fn try_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
76+
fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
7777
self.set_address(address)?;
7878
self.inner.write(bytes)
7979
}
@@ -82,7 +82,7 @@ mod embedded_hal_impl {
8282
impl WriteRead for I2cdev {
8383
type Error = i2cdev::linux::LinuxI2CError;
8484

85-
fn try_write_read(
85+
fn write_read(
8686
&mut self,
8787
address: u8,
8888
bytes: &[u8],
@@ -97,7 +97,7 @@ mod embedded_hal_impl {
9797
impl Transactional for I2cdev {
9898
type Error = i2cdev::linux::LinuxI2CError;
9999

100-
fn try_exec(
100+
fn exec(
101101
&mut self,
102102
address: u8,
103103
operations: &mut [I2cOperation],

src/serial.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ fn translate_io_errors(err: std::io::Error) -> nb::Error<IoErrorKind> {
2929
}
3030
}
3131

32-
impl embedded_hal::serial::Read<u8> for Serial {
32+
impl embedded_hal::serial::nb::Read<u8> for Serial {
3333
type Error = IoErrorKind;
3434

35-
fn try_read(&mut self) -> nb::Result<u8, Self::Error> {
35+
fn read(&mut self) -> nb::Result<u8, Self::Error> {
3636
let mut buffer = [0; 1];
3737
let bytes_read = self.0.read(&mut buffer).map_err(translate_io_errors)?;
3838
if bytes_read == 1 {
@@ -43,15 +43,15 @@ impl embedded_hal::serial::Read<u8> for Serial {
4343
}
4444
}
4545

46-
impl embedded_hal::serial::Write<u8> for Serial {
46+
impl embedded_hal::serial::nb::Write<u8> for Serial {
4747
type Error = IoErrorKind;
4848

49-
fn try_write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
49+
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
5050
self.0.write(&[word]).map_err(translate_io_errors)?;
5151
Ok(())
5252
}
5353

54-
fn try_flush(&mut self) -> nb::Result<(), Self::Error> {
54+
fn flush(&mut self) -> nb::Result<(), Self::Error> {
5555
self.0.flush().map_err(translate_io_errors)
5656
}
5757
}
@@ -60,7 +60,7 @@ impl embedded_hal::serial::Write<u8> for Serial {
6060
mod test {
6161
use std::path::Path;
6262

63-
use embedded_hal::serial::{Read, Write};
63+
use embedded_hal::serial::nb::{Read, Write};
6464
use std::io::{Read as IoRead, Write as IoWrite};
6565

6666
use super::*;
@@ -75,20 +75,20 @@ mod test {
7575
#[test]
7676
fn test_empty_read() {
7777
let (mut _master, mut serial) = create_pty_and_serial();
78-
assert_eq!(Err(nb::Error::WouldBlock), serial.try_read());
78+
assert_eq!(Err(nb::Error::WouldBlock), serial.read());
7979
}
8080

8181
#[test]
8282
fn test_read() {
8383
let (mut master, mut serial) = create_pty_and_serial();
8484
master.write(&[1]).expect("Write failed");
85-
assert_eq!(Ok(1), serial.try_read());
85+
assert_eq!(Ok(1), serial.read());
8686
}
8787

8888
#[test]
8989
fn test_write() {
9090
let (mut master, mut serial) = create_pty_and_serial();
91-
serial.try_write(2).expect("Write failed");
91+
serial.write(2).expect("Write failed");
9292
let mut buf = [0; 2];
9393
assert_eq!(1, master.read(&mut buf).unwrap());
9494
assert_eq!(buf, [2, 0]);

src/spi.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,24 @@ impl ops::DerefMut for Spidev {
4040

4141
mod embedded_hal_impl {
4242
use super::*;
43-
use embedded_hal::blocking::spi::{Operation as SpiOperation, Transactional, Transfer, Write};
43+
use embedded_hal::spi::blocking::{Operation as SpiOperation, Transactional, Transfer, Write};
4444
use spidev::SpidevTransfer;
4545
use std::io::Write as _;
4646

4747
impl Transfer<u8> for Spidev {
4848
type Error = io::Error;
4949

50-
fn try_transfer<'b>(&mut self, buffer: &'b mut [u8]) -> io::Result<&'b [u8]> {
50+
fn transfer<'b>(&mut self, buffer: &'b mut [u8]) -> io::Result<()> {
5151
let tx = buffer.to_owned();
5252
self.0
53-
.transfer(&mut SpidevTransfer::read_write(&tx, buffer))?;
54-
Ok(buffer)
53+
.transfer(&mut SpidevTransfer::read_write(&tx, buffer))
5554
}
5655
}
5756

5857
impl Write<u8> for Spidev {
5958
type Error = io::Error;
6059

61-
fn try_write(&mut self, buffer: &[u8]) -> io::Result<()> {
60+
fn write(&mut self, buffer: &[u8]) -> io::Result<()> {
6261
self.0.write_all(buffer)
6362
}
6463
}
@@ -67,10 +66,7 @@ mod embedded_hal_impl {
6766
impl Transactional<u8> for Spidev {
6867
type Error = io::Error;
6968

70-
fn try_exec<'a>(
71-
&mut self,
72-
operations: &mut [SpiOperation<'a, u8>],
73-
) -> Result<(), Self::Error> {
69+
fn exec<'a>(&mut self, operations: &mut [SpiOperation<'a, u8>]) -> Result<(), Self::Error> {
7470
// Map types from generic to linux objects
7571
let mut messages: Vec<_> = operations
7672
.iter_mut()

src/sysfs_pin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ impl SysfsPin {
2828
}
2929
}
3030

31-
impl embedded_hal::digital::OutputPin for SysfsPin {
31+
impl embedded_hal::digital::blocking::OutputPin for SysfsPin {
3232
type Error = sysfs_gpio::Error;
3333

34-
fn try_set_low(&mut self) -> Result<(), Self::Error> {
34+
fn set_low(&mut self) -> Result<(), Self::Error> {
3535
if self.0.get_active_low()? {
3636
self.0.set_value(1)
3737
} else {
3838
self.0.set_value(0)
3939
}
4040
}
4141

42-
fn try_set_high(&mut self) -> Result<(), Self::Error> {
42+
fn set_high(&mut self) -> Result<(), Self::Error> {
4343
if self.0.get_active_low()? {
4444
self.0.set_value(0)
4545
} else {
@@ -48,19 +48,19 @@ impl embedded_hal::digital::OutputPin for SysfsPin {
4848
}
4949
}
5050

51-
impl embedded_hal::digital::InputPin for SysfsPin {
51+
impl embedded_hal::digital::blocking::InputPin for SysfsPin {
5252
type Error = sysfs_gpio::Error;
5353

54-
fn try_is_high(&self) -> Result<bool, Self::Error> {
54+
fn is_high(&self) -> Result<bool, Self::Error> {
5555
if !self.0.get_active_low()? {
5656
self.0.get_value().map(|val| val != 0)
5757
} else {
5858
self.0.get_value().map(|val| val == 0)
5959
}
6060
}
6161

62-
fn try_is_low(&self) -> Result<bool, Self::Error> {
63-
self.try_is_high().map(|val| !val)
62+
fn is_low(&self) -> Result<bool, Self::Error> {
63+
self.is_high().map(|val| !val)
6464
}
6565
}
6666

0 commit comments

Comments
 (0)