@@ -16,19 +16,18 @@ extern crate cast;
1616extern crate core;
1717extern crate embedded_hal as hal;
1818pub extern crate i2cdev;
19- pub extern crate spidev;
20- pub extern crate serial_unix;
21- pub extern crate serial_core;
2219pub extern crate nb;
23-
20+ pub extern crate serial_core;
21+ pub extern crate serial_unix;
22+ pub extern crate spidev;
2423
2524#[ cfg( feature = "gpio_sysfs" ) ]
2625pub extern crate sysfs_gpio;
2726
2827#[ cfg( feature = "gpio_cdev" ) ]
2928pub extern crate gpio_cdev;
3029
31-
30+ use core :: convert :: Infallible ;
3231use std:: io:: { self , Write } ;
3332use std:: path:: { Path , PathBuf } ;
3433use std:: time:: Duration ;
@@ -60,65 +59,87 @@ pub use cdev_pin::CdevPin;
6059/// Sysfs pin re-export
6160pub use sysfs_pin:: SysfsPin ;
6261
63-
6462/// Empty struct that provides delay functionality on top of `thread::sleep`
6563pub struct Delay ;
6664
6765impl hal:: blocking:: delay:: DelayUs < u8 > for Delay {
68- fn delay_us ( & mut self , n : u8 ) {
69- thread:: sleep ( Duration :: new ( 0 , u32 ( n) * 1000 ) )
66+ type Error = Infallible ;
67+
68+ fn try_delay_us ( & mut self , n : u8 ) -> Result < ( ) , Self :: Error > {
69+ thread:: sleep ( Duration :: new ( 0 , u32 ( n) * 1000 ) ) ;
70+ Ok ( ( ) )
7071 }
7172}
7273
7374impl hal:: blocking:: delay:: DelayUs < u16 > for Delay {
74- fn delay_us ( & mut self , n : u16 ) {
75- thread:: sleep ( Duration :: new ( 0 , u32 ( n) * 1000 ) )
75+ type Error = Infallible ;
76+
77+ fn try_delay_us ( & mut self , n : u16 ) -> Result < ( ) , Self :: Error > {
78+ thread:: sleep ( Duration :: new ( 0 , u32 ( n) * 1000 ) ) ;
79+ Ok ( ( ) )
7680 }
7781}
7882
7983impl hal:: blocking:: delay:: DelayUs < u32 > for Delay {
80- fn delay_us ( & mut self , n : u32 ) {
84+ type Error = Infallible ;
85+
86+ fn try_delay_us ( & mut self , n : u32 ) -> Result < ( ) , Self :: Error > {
8187 let secs = n / 1_000_000 ;
8288 let nsecs = ( n % 1_000_000 ) * 1_000 ;
8389
84- thread:: sleep ( Duration :: new ( u64 ( secs) , nsecs) )
90+ thread:: sleep ( Duration :: new ( u64 ( secs) , nsecs) ) ;
91+ Ok ( ( ) )
8592 }
8693}
8794
8895impl hal:: blocking:: delay:: DelayUs < u64 > for Delay {
89- fn delay_us ( & mut self , n : u64 ) {
96+ type Error = Infallible ;
97+
98+ fn try_delay_us ( & mut self , n : u64 ) -> Result < ( ) , Self :: Error > {
9099 let secs = n / 1_000_000 ;
91100 let nsecs = ( ( n % 1_000_000 ) * 1_000 ) as u32 ;
92101
93- thread:: sleep ( Duration :: new ( secs, nsecs) )
102+ thread:: sleep ( Duration :: new ( secs, nsecs) ) ;
103+ Ok ( ( ) )
94104 }
95105}
96106
97107impl hal:: blocking:: delay:: DelayMs < u8 > for Delay {
98- fn delay_ms ( & mut self , n : u8 ) {
99- thread:: sleep ( Duration :: from_millis ( u64 ( n) ) )
108+ type Error = Infallible ;
109+
110+ fn try_delay_ms ( & mut self , n : u8 ) -> Result < ( ) , Self :: Error > {
111+ thread:: sleep ( Duration :: from_millis ( u64 ( n) ) ) ;
112+ Ok ( ( ) )
100113 }
101114}
102115
103116impl hal:: blocking:: delay:: DelayMs < u16 > for Delay {
104- fn delay_ms ( & mut self , n : u16 ) {
105- thread:: sleep ( Duration :: from_millis ( u64 ( n) ) )
117+ type Error = Infallible ;
118+
119+ fn try_delay_ms ( & mut self , n : u16 ) -> Result < ( ) , Self :: Error > {
120+ thread:: sleep ( Duration :: from_millis ( u64 ( n) ) ) ;
121+ Ok ( ( ) )
106122 }
107123}
108124
109125impl hal:: blocking:: delay:: DelayMs < u32 > for Delay {
110- fn delay_ms ( & mut self , n : u32 ) {
111- thread:: sleep ( Duration :: from_millis ( u64 ( n) ) )
126+ type Error = Infallible ;
127+
128+ fn try_delay_ms ( & mut self , n : u32 ) -> Result < ( ) , Self :: Error > {
129+ thread:: sleep ( Duration :: from_millis ( u64 ( n) ) ) ;
130+ Ok ( ( ) )
112131 }
113132}
114133
115134impl hal:: blocking:: delay:: DelayMs < u64 > for Delay {
116- fn delay_ms ( & mut self , n : u64 ) {
117- thread:: sleep ( Duration :: from_millis ( n) )
135+ type Error = Infallible ;
136+
137+ fn try_delay_ms ( & mut self , n : u64 ) -> Result < ( ) , Self :: Error > {
138+ thread:: sleep ( Duration :: from_millis ( n) ) ;
139+ Ok ( ( ) )
118140 }
119141}
120142
121-
122143/// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
123144///
124145/// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html
@@ -156,7 +177,7 @@ impl I2cdev {
156177impl hal:: blocking:: i2c:: Read for I2cdev {
157178 type Error = i2cdev:: linux:: LinuxI2CError ;
158179
159- fn read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
180+ fn try_read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
160181 self . set_address ( address) ?;
161182 self . inner . read ( buffer)
162183 }
@@ -165,7 +186,7 @@ impl hal::blocking::i2c::Read for I2cdev {
165186impl hal:: blocking:: i2c:: Write for I2cdev {
166187 type Error = i2cdev:: linux:: LinuxI2CError ;
167188
168- fn write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
189+ fn try_write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
169190 self . set_address ( address) ?;
170191 self . inner . write ( bytes)
171192 }
@@ -174,7 +195,7 @@ impl hal::blocking::i2c::Write for I2cdev {
174195impl hal:: blocking:: i2c:: WriteRead for I2cdev {
175196 type Error = i2cdev:: linux:: LinuxI2CError ;
176197
177- fn write_read (
198+ fn try_write_read (
178199 & mut self ,
179200 address : u8 ,
180201 bytes : & [ u8 ] ,
@@ -220,7 +241,7 @@ impl Spidev {
220241impl hal:: blocking:: spi:: Transfer < u8 > for Spidev {
221242 type Error = io:: Error ;
222243
223- fn transfer < ' b > ( & mut self , buffer : & ' b mut [ u8 ] ) -> io:: Result < & ' b [ u8 ] > {
244+ fn try_transfer < ' b > ( & mut self , buffer : & ' b mut [ u8 ] ) -> io:: Result < & ' b [ u8 ] > {
224245 let tx = buffer. to_owned ( ) ;
225246 self . 0
226247 . transfer ( & mut SpidevTransfer :: read_write ( & tx, buffer) ) ?;
@@ -231,7 +252,7 @@ impl hal::blocking::spi::Transfer<u8> for Spidev {
231252impl hal:: blocking:: spi:: Write < u8 > for Spidev {
232253 type Error = io:: Error ;
233254
234- fn write ( & mut self , buffer : & [ u8 ] ) -> io:: Result < ( ) > {
255+ fn try_write ( & mut self , buffer : & [ u8 ] ) -> io:: Result < ( ) > {
235256 self . 0 . write_all ( buffer)
236257 }
237258}
0 commit comments