@@ -190,20 +190,18 @@ impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)> {
190
190
191
191
// Configure for "fast mode" (400 KHz)
192
192
// 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
+ } ) ;
207
205
208
206
// Enable the peripheral
209
207
i2c. cr1 ( ) . modify ( |_, w| w. pe ( ) . set_bit ( ) ) ;
@@ -252,16 +250,11 @@ where
252
250
self . i2c . cr2 ( ) . modify ( |_, w| {
253
251
if i == 0 {
254
252
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 ) ) ) ) ;
259
254
w. rd_wrn ( ) . read ( ) ;
260
255
w. start ( ) . start ( ) ;
261
256
}
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( ) ) ) ) ;
265
258
if i == end {
266
259
w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
267
260
} else {
@@ -308,14 +301,9 @@ where
308
301
// 0 byte write
309
302
self . i2c . cr2 ( ) . modify ( |_, w| {
310
303
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 ) ) ) ) ;
315
305
w. rd_wrn ( ) . write ( ) ;
316
- unsafe {
317
- w. nbytes ( ) . bits ( 0 ) ;
318
- }
306
+ w. nbytes ( ) . set ( 0 ) ;
319
307
w. reload ( ) . completed ( ) ;
320
308
w. autoend ( ) . automatic ( ) ;
321
309
w. start ( ) . start ( )
@@ -329,16 +317,11 @@ where
329
317
self . i2c . cr2 ( ) . modify ( |_, w| {
330
318
if i == 0 {
331
319
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 ) ) ) ) ;
336
321
w. rd_wrn ( ) . write ( ) ;
337
322
w. start ( ) . start ( ) ;
338
323
}
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( ) ) ) ) ;
342
325
if i == end {
343
326
w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
344
327
} else {
@@ -353,9 +336,7 @@ where
353
336
354
337
// Put byte on the wire
355
338
// 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) ) ;
359
340
}
360
341
361
342
if i != end {
@@ -397,16 +378,12 @@ where
397
378
self . i2c . cr2 ( ) . modify ( |_, w| {
398
379
if i == 0 {
399
380
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 ) ) ) ) ;
404
383
w. rd_wrn ( ) . write ( ) ;
405
384
w. start ( ) . start ( ) ;
406
385
}
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( ) ) ) ) ;
410
387
if i == end {
411
388
w. reload ( ) . completed ( ) . autoend ( ) . software ( )
412
389
} else {
@@ -421,9 +398,7 @@ where
421
398
422
399
// Put byte on the wire
423
400
// 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) ) ;
427
402
}
428
403
429
404
if i != end {
@@ -445,16 +420,12 @@ where
445
420
self . i2c . cr2 ( ) . modify ( |_, w| {
446
421
if i == 0 {
447
422
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 ) ) ) ) ;
452
425
w. rd_wrn ( ) . read ( ) ;
453
426
w. start ( ) . start ( ) ;
454
427
}
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( ) ) ) ) ;
458
429
if i == end {
459
430
w. reload ( ) . completed ( ) . autoend ( ) . automatic ( )
460
431
} else {
0 commit comments