@@ -113,18 +113,18 @@ impl<I2C, PINS> I2c<I2C, PINS> {
113
113
}
114
114
115
115
macro_rules! wait_for_flag {
116
- ( $i2c: expr, $flag: ident) => { {
116
+ ( $i2c: expr, $flag: ident, $nack : ident ) => { {
117
117
let sr1 = $i2c. sr1. read( ) ;
118
118
119
119
if sr1. berr( ) . bit_is_set( ) {
120
120
$i2c. sr1. write( |w| w. berr( ) . clear_bit( ) ) ;
121
121
Err ( Error :: Bus . into( ) )
122
122
} else if sr1. arlo( ) . bit_is_set( ) {
123
123
$i2c. sr1. write( |w| w. arlo( ) . clear_bit( ) ) ;
124
- Err ( Error :: Arbitration . into( ) )
124
+ Err ( Error :: ArbitrationLoss . into( ) )
125
125
} else if sr1. af( ) . bit_is_set( ) {
126
126
$i2c. sr1. write( |w| w. af( ) . clear_bit( ) ) ;
127
- Err ( Error :: Acknowledge . into( ) )
127
+ Err ( Error :: NoAcknowledge ( NoAcknowledgeSource :: $nack ) . into( ) )
128
128
} else if sr1. ovr( ) . bit_is_set( ) {
129
129
$i2c. sr1. write( |w| w. ovr( ) . clear_bit( ) ) ;
130
130
Err ( Error :: Overrun . into( ) )
@@ -190,7 +190,7 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
190
190
/// method returns `WouldBlock` so the program can act accordingly
191
191
/// (busy wait, async, ...)
192
192
fn wait_after_sent_start ( & mut self ) -> nb:: Result < ( ) , Error > {
193
- wait_for_flag ! ( self . nb. i2c, sb)
193
+ wait_for_flag ! ( self . nb. i2c, sb, Unknown )
194
194
}
195
195
196
196
/// Check if STOP condition is generated. If the condition is not generated, this
@@ -225,8 +225,11 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
225
225
fn send_addr_and_wait ( & mut self , addr : u8 , read : bool ) -> Result < ( ) , Error > {
226
226
self . nb . i2c . sr1 . read ( ) ;
227
227
self . nb . send_addr ( addr, read) ;
228
- let ret = busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, addr) , self . timeouts. addr) ;
229
- if ret == Err ( Error :: Acknowledge ) {
228
+ let ret = busy_wait_cycles ! (
229
+ wait_for_flag!( self . nb. i2c, addr, Address ) ,
230
+ self . timeouts. addr
231
+ ) ;
232
+ if let Err ( Error :: NoAcknowledge ( _) ) = ret {
230
233
self . nb . send_stop ( ) ;
231
234
}
232
235
ret
@@ -239,10 +242,10 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
239
242
self . nb . i2c . dr . write ( |w| w. dr ( ) . bits ( bytes[ 0 ] ) ) ;
240
243
241
244
for byte in & bytes[ 1 ..] {
242
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, tx_e) , self . timeouts. data) ?;
245
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, tx_e, Data ) , self . timeouts. data) ?;
243
246
self . nb . i2c . dr . write ( |w| w. dr ( ) . bits ( * byte) ) ;
244
247
}
245
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf) , self . timeouts. data) ?;
248
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf, Data ) , self . timeouts. data) ?;
246
249
247
250
Ok ( ( ) )
248
251
}
@@ -252,7 +255,7 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
252
255
self . send_addr_and_wait ( addr, false ) ?;
253
256
254
257
let ret = self . write_bytes_and_wait ( bytes) ;
255
- if ret == Err ( Error :: Acknowledge ) {
258
+ if let Err ( Error :: NoAcknowledge ( _ ) ) = ret {
256
259
self . nb . send_stop ( ) ;
257
260
}
258
261
ret
@@ -277,7 +280,7 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
277
280
self . nb . i2c . sr2 . read ( ) ;
278
281
self . nb . send_stop ( ) ;
279
282
280
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, rx_ne) , self . timeouts. data) ?;
283
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, rx_ne, Data ) , self . timeouts. data) ?;
281
284
buffer[ 0 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
282
285
283
286
busy_wait_cycles ! ( self . wait_for_stop( ) , self . timeouts. data) ?;
@@ -292,7 +295,7 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
292
295
self . nb . i2c . sr2 . read ( ) ;
293
296
self . nb . i2c . cr1 . modify ( |_, w| w. ack ( ) . clear_bit ( ) ) ;
294
297
295
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf) , self . timeouts. data) ?;
298
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf, Data ) , self . timeouts. data) ?;
296
299
self . nb . send_stop ( ) ;
297
300
buffer[ 0 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
298
301
buffer[ 1 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
@@ -311,16 +314,19 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
311
314
312
315
let ( first_bytes, last_two_bytes) = buffer. split_at_mut ( buffer_len - 3 ) ;
313
316
for byte in first_bytes {
314
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, rx_ne) , self . timeouts. data) ?;
317
+ busy_wait_cycles ! (
318
+ wait_for_flag!( self . nb. i2c, rx_ne, Data ) ,
319
+ self . timeouts. data
320
+ ) ?;
315
321
* byte = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
316
322
}
317
323
318
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf) , self . timeouts. data) ?;
324
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, btf, Data ) , self . timeouts. data) ?;
319
325
self . nb . i2c . cr1 . modify ( |_, w| w. ack ( ) . clear_bit ( ) ) ;
320
326
last_two_bytes[ 0 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
321
327
self . nb . send_stop ( ) ;
322
328
last_two_bytes[ 1 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
323
- busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, rx_ne) , self . timeouts. data) ?;
329
+ busy_wait_cycles ! ( wait_for_flag!( self . nb. i2c, rx_ne, Data ) , self . timeouts. data) ?;
324
330
last_two_bytes[ 2 ] = self . nb . i2c . dr . read ( ) . dr ( ) . bits ( ) ;
325
331
326
332
busy_wait_cycles ! ( self . wait_for_stop( ) , self . timeouts. data) ?;
@@ -345,4 +351,20 @@ impl<I2C: Instance, PINS> BlockingI2c<I2C, PINS> {
345
351
346
352
Ok ( ( ) )
347
353
}
354
+
355
+ pub fn transaction_slice (
356
+ & mut self ,
357
+ _addr : u8 ,
358
+ _ops_slice : & mut [ embedded_hal:: i2c:: Operation < ' _ > ] ,
359
+ ) -> Result < ( ) , Error > {
360
+ todo ! ( ) ;
361
+ }
362
+
363
+ pub ( crate ) fn transaction_slice_hal_02 (
364
+ & mut self ,
365
+ _addr : u8 ,
366
+ _ops_slice : & mut [ embedded_hal_02:: blocking:: i2c:: Operation < ' _ > ] ,
367
+ ) -> Result < ( ) , Error > {
368
+ todo ! ( ) ;
369
+ }
348
370
}
0 commit comments