Skip to content

Commit

Permalink
i2c/uart: Fix macros for latest avr-device
Browse files Browse the repository at this point in the history
By updating to svd2rust v1.16.1, a few previously safe function have
unfortunately become unsafe.  Wrap calls to them in unsafe blocks to
make avr-hal compile again.

Signed-off-by: Rahix <rahix@rahix.de>
  • Loading branch information
Rahix committed Oct 21, 2019
1 parent d6daf71 commit 0aef1a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions avr-hal-generic/src/i2c.rs
Expand Up @@ -227,7 +227,7 @@ macro_rules! impl_twi_i2c {
) -> $I2c<CLOCK, $crate::i2c::I2cPullUp> {
// Calculate TWBR
let twbr = ((CLOCK::FREQ / speed) - 16) / 2;
p.$twbr.write(|w| w.bits(twbr as u8));
p.$twbr.write(|w| unsafe { w.bits(twbr as u8) });
// Disable prescaler
p.$twsr.modify(|_, w| w.$twps().prescaler_1());

Expand Down Expand Up @@ -257,7 +257,7 @@ macro_rules! impl_twi_i2c {
) -> $I2c<CLOCK, $crate::i2c::I2cFloating> {
// Calculate TWBR
let twbr = ((CLOCK::FREQ / speed) - 16) / 2;
p.$twbr.write(|w| w.bits(twbr as u8));
p.$twbr.write(|w| unsafe { w.bits(twbr as u8) });
// Disable prescaler
p.$twsr.modify(|_, w| w.$twps().prescaler_1());

Expand Down Expand Up @@ -325,7 +325,7 @@ macro_rules! impl_twi_i2c {
// Send slave address
let dirbit = if dir == $crate::i2c::Direction::Read { 1 } else { 0 };
let rawaddr = (addr << 1) | dirbit;
self.p.$twdr.write(|w| w.bits(rawaddr));
self.p.$twdr.write(|w| unsafe { w.bits(rawaddr) });
self.transact();

// Check if the slave responded
Expand Down Expand Up @@ -364,7 +364,7 @@ macro_rules! impl_twi_i2c {

fn write_data(&mut self, bytes: &[u8]) -> Result<(), $crate::i2c::Error> {
for byte in bytes {
self.p.$twdr.write(|w| w.bits(*byte));
self.p.$twdr.write(|w| unsafe { w.bits(*byte) });
self.transact();

match self.p.$twsr.read().$tws().bits() {
Expand Down
4 changes: 2 additions & 2 deletions avr-hal-generic/src/serial.rs
Expand Up @@ -66,7 +66,7 @@ macro_rules! impl_usart {
// Calculate BRR value
let brr = CLOCK::FREQ / (16 * baud) - 1;
// Set baudrate
p.$baud.write(|w| w.bits(brr as u16));
p.$baud.write(|w| unsafe { w.bits(brr as u16) });
// Enable receiver and transmitter
p.$control_b
.write(|w| w.$txen().set_bit().$rxen().set_bit());
Expand Down Expand Up @@ -102,7 +102,7 @@ macro_rules! impl_usart {
// Call flush to make sure the data-register is empty
self.flush()?;

self.p.$data.write(|w| w.bits(byte));
self.p.$data.write(|w| unsafe { w.bits(byte) });
Ok(())
}

Expand Down

0 comments on commit 0aef1a6

Please sign in to comment.