@@ -190,20 +190,18 @@ impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)> {
190190
191191 // Configure for "fast mode" (400 KHz)
192192 // NOTE(write): writes all non-reserved bits.
193- unsafe {
194- i2c. timingr ( ) . write ( |w| {
195- w. presc ( )
196- . bits ( crate :: unwrap!( u8 :: try_from( presc) ) )
197- . sdadel ( )
198- . bits ( crate :: unwrap!( u8 :: try_from( sdadel) ) )
199- . scldel ( )
200- . bits ( crate :: unwrap!( u8 :: try_from( scldel) ) )
201- . scll ( )
202- . bits ( scl_low)
203- . sclh ( )
204- . bits ( scl_high)
205- } ) ;
206- }
193+ i2c. timingr ( ) . write ( |w| {
194+ w. presc ( )
195+ . set ( crate :: unwrap!( u8 :: try_from( presc) ) )
196+ . sdadel ( )
197+ . set ( crate :: unwrap!( u8 :: try_from( sdadel) ) )
198+ . scldel ( )
199+ . set ( crate :: unwrap!( u8 :: try_from( scldel) ) )
200+ . scll ( )
201+ . set ( scl_low)
202+ . sclh ( )
203+ . set ( scl_high)
204+ } ) ;
207205
208206 // Enable the peripheral
209207 i2c. cr1 ( ) . modify ( |_, w| w. pe ( ) . set_bit ( ) ) ;
@@ -252,16 +250,11 @@ where
252250 self . i2c . cr2 ( ) . modify ( |_, w| {
253251 if i == 0 {
254252 w. add10 ( ) . bit7 ( ) ;
255- unsafe {
256- w. sadd ( )
257- . bits ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
258- }
253+ w. sadd ( ) . set ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
259254 w. rd_wrn ( ) . read ( ) ;
260255 w. start ( ) . start ( ) ;
261256 }
262- unsafe {
263- w. nbytes ( ) . bits ( crate :: unwrap!( u8 :: try_from( buffer. len( ) ) ) ) ;
264- }
257+ w. nbytes ( ) . set ( crate :: unwrap!( u8 :: try_from( buffer. len( ) ) ) ) ;
265258 if i == end {
266259 w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
267260 } else {
@@ -308,14 +301,9 @@ where
308301 // 0 byte write
309302 self . i2c . cr2 ( ) . modify ( |_, w| {
310303 w. add10 ( ) . bit7 ( ) ;
311- unsafe {
312- w. sadd ( )
313- . bits ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
314- }
304+ w. sadd ( ) . set ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
315305 w. rd_wrn ( ) . write ( ) ;
316- unsafe {
317- w. nbytes ( ) . bits ( 0 ) ;
318- }
306+ w. nbytes ( ) . set ( 0 ) ;
319307 w. reload ( ) . completed ( ) ;
320308 w. autoend ( ) . automatic ( ) ;
321309 w. start ( ) . start ( )
@@ -329,16 +317,11 @@ where
329317 self . i2c . cr2 ( ) . modify ( |_, w| {
330318 if i == 0 {
331319 w. add10 ( ) . bit7 ( ) ;
332- unsafe {
333- w. sadd ( )
334- . bits ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
335- }
320+ w. sadd ( ) . set ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
336321 w. rd_wrn ( ) . write ( ) ;
337322 w. start ( ) . start ( ) ;
338323 }
339- unsafe {
340- w. nbytes ( ) . bits ( crate :: unwrap!( u8 :: try_from( bytes. len( ) ) ) ) ;
341- }
324+ w. nbytes ( ) . set ( crate :: unwrap!( u8 :: try_from( bytes. len( ) ) ) ) ;
342325 if i == end {
343326 w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
344327 } else {
@@ -353,9 +336,7 @@ where
353336
354337 // Put byte on the wire
355338 // NOTE(write): Writes all non-reserved bits.
356- unsafe {
357- self . i2c . txdr ( ) . write ( |w| w. txdata ( ) . bits ( * byte) ) ;
358- }
339+ self . i2c . txdr ( ) . write ( |w| w. txdata ( ) . set ( * byte) ) ;
359340 }
360341
361342 if i != end {
@@ -397,16 +378,12 @@ where
397378 self . i2c . cr2 ( ) . modify ( |_, w| {
398379 if i == 0 {
399380 w. add10 ( ) . bit7 ( ) ;
400- unsafe {
401- w. sadd ( )
402- . bits ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
403- }
381+ w. sadd ( )
382+ . set ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
404383 w. rd_wrn ( ) . write ( ) ;
405384 w. start ( ) . start ( ) ;
406385 }
407- unsafe {
408- w. nbytes ( ) . bits ( crate :: unwrap!( u8 :: try_from( bytes. len( ) ) ) ) ;
409- }
386+ w. nbytes ( ) . set ( crate :: unwrap!( u8 :: try_from( bytes. len( ) ) ) ) ;
410387 if i == end {
411388 w. reload ( ) . completed ( ) . autoend ( ) . software ( )
412389 } else {
@@ -421,9 +398,7 @@ where
421398
422399 // Put byte on the wire
423400 // NOTE(write): Writes all non-reserved bits.
424- unsafe {
425- self . i2c . txdr ( ) . write ( |w| w. txdata ( ) . bits ( * byte) ) ;
426- }
401+ self . i2c . txdr ( ) . write ( |w| w. txdata ( ) . set ( * byte) ) ;
427402 }
428403
429404 if i != end {
@@ -445,16 +420,12 @@ where
445420 self . i2c . cr2 ( ) . modify ( |_, w| {
446421 if i == 0 {
447422 w. add10 ( ) . bit7 ( ) ;
448- unsafe {
449- w. sadd ( )
450- . bits ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
451- }
423+ w. sadd ( )
424+ . set ( u16:: from ( crate :: unwrap!( addr. checked_shl( 1 ) ) ) ) ;
452425 w. rd_wrn ( ) . read ( ) ;
453426 w. start ( ) . start ( ) ;
454427 }
455- unsafe {
456- w. nbytes ( ) . bits ( crate :: unwrap!( u8 :: try_from( buffer. len( ) ) ) ) ;
457- }
428+ w. nbytes ( ) . set ( crate :: unwrap!( u8 :: try_from( buffer. len( ) ) ) ) ;
458429 if i == end {
459430 w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
460431 } else {
0 commit comments