@@ -16,19 +16,18 @@ extern crate cast;
16
16
extern crate core;
17
17
extern crate embedded_hal as hal;
18
18
pub extern crate i2cdev;
19
- pub extern crate spidev;
20
- pub extern crate serial_unix;
21
- pub extern crate serial_core;
22
19
pub extern crate nb;
23
-
20
+ pub extern crate serial_core;
21
+ pub extern crate serial_unix;
22
+ pub extern crate spidev;
24
23
25
24
#[ cfg( feature = "gpio_sysfs" ) ]
26
25
pub extern crate sysfs_gpio;
27
26
28
27
#[ cfg( feature = "gpio_cdev" ) ]
29
28
pub extern crate gpio_cdev;
30
29
31
-
30
+ use core :: convert :: Infallible ;
32
31
use std:: io:: { self , Write } ;
33
32
use std:: path:: { Path , PathBuf } ;
34
33
use std:: time:: Duration ;
@@ -60,65 +59,87 @@ pub use cdev_pin::CdevPin;
60
59
/// Sysfs pin re-export
61
60
pub use sysfs_pin:: SysfsPin ;
62
61
63
-
64
62
/// Empty struct that provides delay functionality on top of `thread::sleep`
65
63
pub struct Delay ;
66
64
67
65
impl 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 ( ( ) )
70
71
}
71
72
}
72
73
73
74
impl 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 ( ( ) )
76
80
}
77
81
}
78
82
79
83
impl 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 > {
81
87
let secs = n / 1_000_000 ;
82
88
let nsecs = ( n % 1_000_000 ) * 1_000 ;
83
89
84
- thread:: sleep ( Duration :: new ( u64 ( secs) , nsecs) )
90
+ thread:: sleep ( Duration :: new ( u64 ( secs) , nsecs) ) ;
91
+ Ok ( ( ) )
85
92
}
86
93
}
87
94
88
95
impl 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 > {
90
99
let secs = n / 1_000_000 ;
91
100
let nsecs = ( ( n % 1_000_000 ) * 1_000 ) as u32 ;
92
101
93
- thread:: sleep ( Duration :: new ( secs, nsecs) )
102
+ thread:: sleep ( Duration :: new ( secs, nsecs) ) ;
103
+ Ok ( ( ) )
94
104
}
95
105
}
96
106
97
107
impl 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 ( ( ) )
100
113
}
101
114
}
102
115
103
116
impl 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 ( ( ) )
106
122
}
107
123
}
108
124
109
125
impl 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 ( ( ) )
112
131
}
113
132
}
114
133
115
134
impl 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 ( ( ) )
118
140
}
119
141
}
120
142
121
-
122
143
/// Newtype around [`i2cdev::linux::LinuxI2CDevice`] that implements the `embedded-hal` traits
123
144
///
124
145
/// [`i2cdev::linux::LinuxI2CDevice`]: https://docs.rs/i2cdev/0.3.1/i2cdev/linux/struct.LinuxI2CDevice.html
@@ -156,7 +177,7 @@ impl I2cdev {
156
177
impl hal:: blocking:: i2c:: Read for I2cdev {
157
178
type Error = i2cdev:: linux:: LinuxI2CError ;
158
179
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 > {
160
181
self . set_address ( address) ?;
161
182
self . inner . read ( buffer)
162
183
}
@@ -165,7 +186,7 @@ impl hal::blocking::i2c::Read for I2cdev {
165
186
impl hal:: blocking:: i2c:: Write for I2cdev {
166
187
type Error = i2cdev:: linux:: LinuxI2CError ;
167
188
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 > {
169
190
self . set_address ( address) ?;
170
191
self . inner . write ( bytes)
171
192
}
@@ -174,7 +195,7 @@ impl hal::blocking::i2c::Write for I2cdev {
174
195
impl hal:: blocking:: i2c:: WriteRead for I2cdev {
175
196
type Error = i2cdev:: linux:: LinuxI2CError ;
176
197
177
- fn write_read (
198
+ fn try_write_read (
178
199
& mut self ,
179
200
address : u8 ,
180
201
bytes : & [ u8 ] ,
@@ -220,7 +241,7 @@ impl Spidev {
220
241
impl hal:: blocking:: spi:: Transfer < u8 > for Spidev {
221
242
type Error = io:: Error ;
222
243
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 ] > {
224
245
let tx = buffer. to_owned ( ) ;
225
246
self . 0
226
247
. transfer ( & mut SpidevTransfer :: read_write ( & tx, buffer) ) ?;
@@ -231,7 +252,7 @@ impl hal::blocking::spi::Transfer<u8> for Spidev {
231
252
impl hal:: blocking:: spi:: Write < u8 > for Spidev {
232
253
type Error = io:: Error ;
233
254
234
- fn write ( & mut self , buffer : & [ u8 ] ) -> io:: Result < ( ) > {
255
+ fn try_write ( & mut self , buffer : & [ u8 ] ) -> io:: Result < ( ) > {
235
256
self . 0 . write_all ( buffer)
236
257
}
237
258
}
0 commit comments