@@ -3,7 +3,7 @@ use crate::gpio::*;
33use crate :: i2c:: config:: Config ;
44use crate :: i2c:: { self , Error , I2c , I2cDirection , I2cExt , SCLPin , SDAPin } ;
55use crate :: rcc:: * ;
6- use crate :: stm32:: I2C ;
6+ use crate :: stm32:: I2C1 ;
77use hal:: blocking:: i2c:: { Read , Write , WriteRead } ;
88
99pub trait I2cSlave {
@@ -42,7 +42,7 @@ macro_rules! flush_txdr {
4242
4343 // If TXDR is not flagged as empty, write 1 to flush it
4444 if $i2c. isr( ) . read( ) . txe( ) . bit_is_set( ) {
45- $i2c. isr( ) . write( |w| w. txe( ) . set_bit ( ) ) ;
45+ $i2c. isr( ) . write( |w| w. txe( ) . bit ( true ) ) ;
4646 }
4747 } ;
4848}
@@ -67,19 +67,19 @@ macro_rules! busy_wait {
6767 if isr. $flag( ) . $variant( ) {
6868 break
6969 } else if isr. berr( ) . bit_is_set( ) {
70- $i2c. icr( ) . write( |w| w. berrcf( ) . set_bit ( ) ) ;
70+ $i2c. icr( ) . write( |w| w. berrcf( ) . bit ( true ) ) ;
7171 return Err ( Error :: BusError ) ;
7272 } else if isr. arlo( ) . bit_is_set( ) {
73- $i2c. icr( ) . write( |w| w. arlocf( ) . set_bit ( ) ) ;
73+ $i2c. icr( ) . write( |w| w. arlocf( ) . bit ( true ) ) ;
7474 return Err ( Error :: ArbitrationLost ) ;
7575 } else if isr. nackf( ) . bit_is_set( ) {
76- $i2c. icr( ) . write( |w| w. nackcf( ) . set_bit ( ) ) ;
76+ $i2c. icr( ) . write( |w| w. nackcf( ) . bit ( true ) ) ;
7777 // Make one extra loop to wait on the stop condition
7878 } else if isr. tcr( ) . bit_is_set( ) {
7979 // This condition Will only happen when reload == 1 and sbr == 1 (slave) and nbytes was written.
8080 // Send a NACK, set nbytes to clear tcr flag
8181 $i2c. cr2( ) . modify( |_, w| unsafe {
82- w. nack( ) . set_bit ( ) . nbytes( ) . bits( 1 as u8 )
82+ w. nack( ) . bit ( true ) . nbytes( ) . bits( 1 as u8 )
8383 } ) ;
8484 // Make one extra loop here to wait on the stop condition
8585 } else if isr. addr( ) . bit_is_set( ) {
@@ -93,7 +93,7 @@ macro_rules! busy_wait {
9393 } else if isr. stopf( ) . bit_is_set( ) {
9494 flush_txdr!( $i2c) ;
9595 // Clear the stop condition flag
96- $i2c. icr( ) . write( |w| w. stopcf( ) . set_bit ( ) ) ;
96+ $i2c. icr( ) . write( |w| w. stopcf( ) . bit ( true ) ) ;
9797 if $idx == $buflen {
9898 return Ok ( ( ) )
9999 } else
@@ -178,7 +178,7 @@ macro_rules! i2c {
178178 // Enable the I2C processing
179179 i2c. cr1( ) . modify( |_, w| unsafe {
180180 w. pe( )
181- . set_bit ( )
181+ . bit ( true )
182182 . dnf( )
183183 . bits( config. digital_filter)
184184 . anfoff( )
@@ -189,20 +189,20 @@ macro_rules! i2c {
189189 i2c. oar1( ) . write( |w| unsafe {
190190 w. oa1( ) . bits( config. slave_address_1)
191191 . oa1mode( ) . bit( config. address_11bits)
192- . oa1en( ) . set_bit ( )
192+ . oa1en( ) . bit ( true )
193193 } ) ;
194194 // Enable acknowlidge control
195- i2c. cr1( ) . modify( |_, w| w. sbc( ) . set_bit ( ) ) ;
195+ i2c. cr1( ) . modify( |_, w| w. sbc( ) . bit ( true ) ) ;
196196 }
197197
198198 if config. slave_address_2 > 0 {
199199 i2c. oar2( ) . write( |w| unsafe {
200200 w. oa2msk( ) . bits( config. slave_address_mask as u8 )
201201 . oa2( ) . bits( config. slave_address_2)
202- . oa2en( ) . set_bit ( )
202+ . oa2en( ) . bit ( true )
203203 } ) ;
204204 // Enable acknowlidge control
205- i2c. cr1( ) . modify( |_, w| w. sbc( ) . set_bit ( ) ) ;
205+ i2c. cr1( ) . modify( |_, w| w. sbc( ) . bit ( true ) ) ;
206206 }
207207
208208 // Enable pins
@@ -214,21 +214,21 @@ macro_rules! i2c {
214214
215215 pub fn listen( & mut self , ev: i2c:: Event ) {
216216 match ev {
217- i2c:: Event :: AddressMatch => self . i2c. cr1( ) . modify( |_, w| w. addrie( ) . set_bit ( ) ) ,
218- i2c:: Event :: Rxne => self . i2c. cr1( ) . modify( |_, w| w. rxie( ) . set_bit ( ) ) ,
219- }
217+ i2c:: Event :: AddressMatch => self . i2c. cr1( ) . modify( |_, w| w. addrie( ) . bit ( true ) ) ,
218+ i2c:: Event :: Rxne => self . i2c. cr1( ) . modify( |_, w| w. rxie( ) . bit ( true ) ) ,
219+ } ;
220220 }
221221
222222 pub fn unlisten( & mut self , ev: i2c:: Event ) {
223223 match ev {
224224 i2c:: Event :: AddressMatch => self . i2c. cr1( ) . modify( |_, w| w. addrie( ) . clear_bit( ) ) ,
225225 i2c:: Event :: Rxne => self . i2c. cr1( ) . modify( |_, w| w. rxie( ) . clear_bit( ) ) ,
226- }
226+ } ;
227227 }
228228
229229 pub fn clear_irq( & mut self , ev: i2c:: Event ) {
230230 match ev {
231- i2c:: Event :: AddressMatch => self . i2c. icr( ) . write( |w| w. addrcf( ) . set_bit ( ) ) ,
231+ i2c:: Event :: AddressMatch => _ = self . i2c. icr( ) . write( |w| w. addrcf( ) . bit ( true ) ) ,
232232 _ => { } ,
233233 }
234234 }
@@ -257,7 +257,7 @@ macro_rules! i2c {
257257 while self . i2c. cr2( ) . read( ) . start( ) . bit_is_set( ) { } ;
258258
259259 // flush i2c tx register
260- self . i2c. isr( ) . write( |w| w. txe( ) . set_bit ( ) ) ;
260+ self . i2c. isr( ) . write( |w| w. txe( ) . bit ( true ) ) ;
261261
262262 // Set START and prepare to send `bytes`.
263263 // The START bit can be set even if the bus is BUSY or
@@ -276,7 +276,7 @@ macro_rules! i2c {
276276 . autoend( ) . clear_bit( )
277277 . reload( ) . clear_bit( )
278278 // Start transfer
279- . start( ) . set_bit ( )
279+ . start( ) . bit ( true )
280280 } ) ;
281281 let mut idx = 0 ;
282282 // Wait until we are allowed to send data
@@ -302,12 +302,12 @@ macro_rules! i2c {
302302 // 7-bit addressing mode
303303 . add10( ) . clear_bit( )
304304 // Set transfer direction to read
305- . rd_wrn( ) . set_bit ( )
305+ . rd_wrn( ) . bit ( true )
306306 // Automatic end mode
307- . autoend( ) . set_bit ( )
307+ . autoend( ) . bit ( true )
308308 . reload( ) . clear_bit( )
309309 // Start transfer
310- . start( ) . set_bit ( )
310+ . start( ) . bit ( true )
311311 } ) ;
312312
313313 idx = 0 ;
@@ -336,15 +336,15 @@ macro_rules! i2c {
336336 self . i2c. cr2( ) . modify( |_, w| unsafe {
337337 w
338338 // Start transfer
339- . start( ) . set_bit ( )
339+ . start( ) . bit ( true )
340340 // Set number of bytes to transfer
341341 . nbytes( ) . bits( buflen as u8 )
342342 // Set address to transfer to/from
343343 . sadd( ) . bits( ( addr << 1 ) as u16 )
344344 // Set transfer direction to write
345345 . rd_wrn( ) . clear_bit( )
346346 // Automatic end mode
347- . autoend( ) . set_bit ( )
347+ . autoend( ) . bit ( true )
348348 . reload( ) . clear_bit( )
349349 } ) ;
350350
@@ -381,15 +381,15 @@ macro_rules! i2c {
381381 self . i2c. cr2( ) . modify( |_, w| unsafe {
382382 w
383383 // Start transfer
384- . start( ) . set_bit ( )
384+ . start( ) . bit ( true )
385385 // Set number of bytes to transfer
386386 . nbytes( ) . bits( buflen as u8 )
387387 // Set address to transfer to/from
388388 . sadd( ) . bits( ( addr << 1 ) as u16 )
389389 // Set transfer direction to read
390- . rd_wrn( ) . set_bit ( )
390+ . rd_wrn( ) . bit ( true )
391391 // automatic end mode
392- . autoend( ) . set_bit ( )
392+ . autoend( ) . bit ( true )
393393 . reload( ) . clear_bit( )
394394 } ) ;
395395 let mut idx = 0 ;
@@ -449,9 +449,9 @@ macro_rules! i2c {
449449 . reload( ) . clear_bit( )
450450 } ) ;
451451 // flush i2c tx register
452- self . i2c. isr( ) . write( |w| w. txe( ) . set_bit ( ) ) ;
452+ self . i2c. isr( ) . write( |w| w. txe( ) . bit ( true ) ) ;
453453 // end address phase, release clock stretching
454- self . i2c. icr( ) . write( |w| w. addrcf( ) . set_bit ( ) ) ;
454+ self . i2c. icr( ) . write( |w| w. addrcf( ) . bit ( true ) ) ;
455455
456456 let mut idx = 0 ;
457457 loop {
@@ -481,11 +481,11 @@ macro_rules! i2c {
481481 // Set number of bytes to transfer: maximum as all incoming bytes will be ACK'ed
482482 . nbytes( ) . bits( buflen as u8 )
483483 // during sending nbytes automatically send a ACK, stretch clock after last byte
484- . reload( ) . set_bit ( )
484+ . reload( ) . bit ( true )
485485 } ) ;
486486 // end address phase, release clock stretching
487487 self . i2c. icr( ) . write( |w|
488- w. addrcf( ) . set_bit ( )
488+ w. addrcf( ) . bit ( true )
489489 ) ;
490490 flush_rxdr!( self . i2c) ;
491491
@@ -506,7 +506,7 @@ macro_rules! i2c {
506506}
507507
508508i2c ! (
509- I2C ,
509+ I2C1 ,
510510 i2c1,
511511 sda: [
512512 ( PA10 <Output <OpenDrain >>, AltFunction :: AF6 ) ,
0 commit comments