@@ -37,7 +37,7 @@ macro_rules! flush_txdr {
37
37
($i2c:expr) => {
38
38
// If a pending TXIS flag is set, write dummy data to TXDR
39
39
if $i2c.isr.read().txis().bit_is_set() {
40
- $i2c.txdr.write(|w| unsafe { w.txdata().bits(0) } );
40
+ $i2c.txdr.write(|w| w.txdata().bits(0));
41
41
}
42
42
43
43
// If TXDR is not flagged as empty, write 1 to flush it
@@ -78,9 +78,9 @@ macro_rules! busy_wait {
78
78
} else if isr.tcr().bit_is_set() {
79
79
// This condition Will only happen when reload == 1 and sbr == 1 (slave) and nbytes was written.
80
80
// Send a NACK, set nbytes to clear tcr flag
81
- $i2c.cr2.modify(|_, w| unsafe {
81
+ $i2c.cr2.modify(|_, w|
82
82
w.nack().set_bit().nbytes().bits(1 as u8)
83
- } );
83
+ );
84
84
// Make one extra loop here to wait on the stop condition
85
85
} else if isr.addr().bit_is_set() {
86
86
// in case of a master write_read operation, this flag is the only exit for the function.
@@ -176,31 +176,31 @@ macro_rules! i2c {
176
176
i2c.timingr.write(|w| unsafe { w.bits(timing_bits) });
177
177
178
178
// Enable the I2C processing
179
- i2c.cr1.modify(|_, w| unsafe {
179
+ i2c.cr1.modify(|_, w|
180
180
w.pe()
181
181
.set_bit()
182
182
.dnf()
183
183
.bits(config.digital_filter)
184
184
.anfoff()
185
185
.bit(!config.analog_filter)
186
- } );
186
+ );
187
187
188
188
if config.slave_address_1 > 0 {
189
- i2c.oar1.write(|w| unsafe {
189
+ i2c.oar1.write(|w|
190
190
w.oa1().bits(config.slave_address_1)
191
191
.oa1mode().bit(config.address_11bits)
192
192
.oa1en().set_bit()
193
- } );
193
+ );
194
194
// Enable acknowlidge control
195
195
i2c.cr1.modify(|_, w| w.sbc().set_bit() );
196
196
}
197
197
198
198
if config.slave_address_2 > 0 {
199
- i2c.oar2.write( |w| unsafe {
199
+ i2c.oar2.write( |w|
200
200
w.oa2msk().bits( config.slave_address_mask as u8)
201
201
.oa2().bits(config.slave_address_2)
202
202
.oa2en().set_bit()
203
- } );
203
+ );
204
204
// Enable acknowlidge control
205
205
i2c.cr1.modify(|_, w| w.sbc().set_bit() );
206
206
}
@@ -263,7 +263,7 @@ macro_rules! i2c {
263
263
// Set START and prepare to send `bytes`.
264
264
// The START bit can be set even if the bus is BUSY or
265
265
// I2C is in slave mode.
266
- self.i2c.cr2.write(|w| unsafe {
266
+ self.i2c.cr2.write(|w|
267
267
w
268
268
// Set number of bytes to transfer
269
269
.nbytes().bits(sndlen as u8)
@@ -278,23 +278,23 @@ macro_rules! i2c {
278
278
.reload().clear_bit()
279
279
// Start transfer
280
280
.start().set_bit()
281
- } );
281
+ );
282
282
let mut idx = 0;
283
283
// Wait until we are allowed to send data
284
284
// (START has been ACKed or last byte went through)
285
285
// macro will return false when the tc bit is set
286
286
for byte in snd_buffer {
287
287
busy_wait!(self.i2c, txis, bit_is_set, idx, sndlen);
288
288
// Put byte on the wire
289
- self.i2c.txdr.write(|w| unsafe { w.txdata().bits(*byte) } );
289
+ self.i2c.txdr.write(|w| w.txdata().bits(*byte) );
290
290
idx += 1;
291
291
}
292
292
// Wait until the write finishes before beginning to read.
293
293
let dummy = 0xFE;
294
294
busy_wait!(self.i2c, tc, bit_is_set, idx, dummy );
295
295
296
296
// reSTART and prepare to receive bytes into `rcv_buffer`
297
- self.i2c.cr2.write(|w| unsafe {
297
+ self.i2c.cr2.write(|w|
298
298
w
299
299
// Set number of bytes to transfer
300
300
.nbytes().bits(rcvlen as u8)
@@ -309,7 +309,7 @@ macro_rules! i2c {
309
309
.reload().clear_bit()
310
310
// Start transfer
311
311
.start().set_bit()
312
- } );
312
+ );
313
313
314
314
idx = 0;
315
315
loop {
@@ -334,7 +334,7 @@ macro_rules! i2c {
334
334
// This could be up to 50% of a bus cycle (ie. up to 0.5/freq)
335
335
while self.i2c.cr2.read().start().bit_is_set() {};
336
336
337
- self.i2c.cr2.modify(|_, w| unsafe {
337
+ self.i2c.cr2.modify(|_, w|
338
338
w
339
339
// Start transfer
340
340
.start().set_bit()
@@ -347,7 +347,7 @@ macro_rules! i2c {
347
347
// Automatic end mode
348
348
.autoend().set_bit()
349
349
.reload().clear_bit()
350
- } );
350
+ );
351
351
352
352
let mut idx = 0;
353
353
loop {
@@ -356,7 +356,7 @@ macro_rules! i2c {
356
356
357
357
// Put byte on the wire
358
358
if idx < buflen {
359
- self.i2c.txdr.write(|w| unsafe { w.txdata().bits(bytes[idx]) } );
359
+ self.i2c.txdr.write(|w| w.txdata().bits(bytes[idx]) );
360
360
idx += 1;
361
361
}
362
362
}
@@ -380,7 +380,7 @@ macro_rules! i2c {
380
380
// Set START and prepare to receive bytes into `buffer`.
381
381
// The START bit can be set even if the bus
382
382
// is BUSY or I2C is in slave mode.
383
- self.i2c.cr2.modify(|_, w| unsafe {
383
+ self.i2c.cr2.modify(|_, w|
384
384
w
385
385
// Start transfer
386
386
.start().set_bit()
@@ -393,7 +393,7 @@ macro_rules! i2c {
393
393
// automatic end mode
394
394
.autoend().set_bit()
395
395
.reload().clear_bit()
396
- } );
396
+ );
397
397
let mut idx = 0;
398
398
loop {
399
399
// Wait until we have received something
@@ -447,10 +447,10 @@ macro_rules! i2c {
447
447
assert!(buflen < 256 && buflen > 0);
448
448
449
449
// Set the nbytes and prepare to send bytes into `buffer`.
450
- self.i2c.cr2.modify(|_, w| unsafe {
450
+ self.i2c.cr2.modify(|_, w|
451
451
w.nbytes().bits( buflen as u8)
452
452
.reload().clear_bit()
453
- } );
453
+ );
454
454
// flush i2c tx register
455
455
self.i2c.isr.write(|w| w.txe().set_bit());
456
456
// end address phase, release clock stretching
@@ -463,13 +463,13 @@ macro_rules! i2c {
463
463
464
464
// Put byte on the wire
465
465
if idx < buflen {
466
- self.i2c.txdr.write(|w| unsafe { w.txdata().bits(bytes[idx]) } );
466
+ self.i2c.txdr.write(|w| w.txdata().bits(bytes[idx]) );
467
467
idx += 1;
468
468
} else {
469
469
// we will never reach here. In case the master wants to read more than buflen
470
470
// the hardware will send 0xFF
471
471
// Also means that on slave side we cannot detect this error case
472
- self.i2c.txdr.write(|w| unsafe { w.txdata().bits(0x21) } );
472
+ self.i2c.txdr.write(|w| w.txdata().bits(0x21) );
473
473
}
474
474
}
475
475
}
@@ -480,13 +480,13 @@ macro_rules! i2c {
480
480
assert!(buflen < 256 && buflen > 0);
481
481
482
482
// Set the nbytes START and prepare to receive bytes into `buffer`.
483
- self.i2c.cr2.modify(|_, w| unsafe {
483
+ self.i2c.cr2.modify(|_, w|
484
484
w
485
485
// Set number of bytes to transfer: maximum as all incoming bytes will be ACK'ed
486
486
.nbytes().bits(buflen as u8)
487
487
// during sending nbytes automatically send a ACK, stretch clock after last byte
488
488
.reload().set_bit()
489
- } );
489
+ );
490
490
// end address phase, release clock stretching
491
491
self.i2c.icr.write(|w|
492
492
w.addrcf().set_bit()
0 commit comments