Open Rahix opened 2 months ago
Full diff (very large!): svd2rust-0.33.1-changes.diff.txt.zip
"Manageable" diff of just ATmega328P: svd2rust-0.33.1-changes-atmega328p.diff.txt
The most major change seems to be from 0.31.0 where registers are now accessed using methods instead of fields. This will require rather large downstream changes.
This can be fixed rather easily for avr-hal
: Rustc already makes some good suggestions for where the parentheses are missing to convert field accesses into method calls. So with a bit of jq and sed magic, we can apply those fixes automatically. Simply run the following command from inside examples/arduino-uno
:
cargo build --message-format json 2>/dev/null | jq '.message.children[].spans[] | {file: .file_name, line: .line_start, col: (.text[0].highlight_start - 1), insert: .suggested_replacement}' 2>/dev/null | jq -r '"sed -ri '"'"'" + (.line | tostring) + "s/^(.{" + (.col | tostring) + "})/\\1" + .insert + "/'"'"' $(cd ../..; realpath " + .file + ")"' | sort | uniq | bash
(Definitely not cursed......)
For reference, the diff it produces is here:
avr-hal
diff]().set_bit()
})
}
#[inline]
unsafe fn out_clear(&mut self) {
- (*<$port>::ptr()).[ ]().clear_bit()
})
}
#[inline]
unsafe fn out_toggle(&mut self) {
- (*<$port>::ptr()).[ ]().set_bit()
})
}
#[inline]
unsafe fn out_get(&self) -> bool {
- (*<$port>::ptr()).[ ]().bit()
+ (*<$port>::ptr()).[ ]().bit()
}
#[inline]
unsafe fn in_get(&self) -> bool {
- (*<$port>::ptr()).[ ]().bit()
+ (*<$port>::ptr()).[ ]().bit()
}
#[inline]
unsafe fn make_output(&mut self) {
- (*<$port>::ptr()).[ ]().set_bit()
})
}
#[inline]
unsafe fn make_input(&mut self, pull_up: bool) {
- (*<$port>::ptr()).[ ]().clear_bit()
});
if pull_up {
diff --git a/avr-hal-generic/src/simple_pwm.rs b/avr-hal-generic/src/simple_pwm.rs
index 93b4081bf5..b0330927c6 100644
--- a/avr-hal-generic/src/simple_pwm.rs
+++ b/avr-hal-generic/src/simple_pwm.rs
@@ -175,7 +175,7 @@ macro_rules! impl_simple_pwm {
}
fn get_duty(&self) -> Self::Duty {
- unsafe { (&*<$TIMER>::ptr()) }.$ocr.read().bits() as Self::Duty
+ unsafe { (&*<$TIMER>::ptr()) }.$ocr().read().bits() as Self::Duty
}
fn get_max_duty(&self) -> Self::Duty {
@@ -185,7 +185,7 @@ macro_rules! impl_simple_pwm {
fn set_duty(&mut self, duty: Self::Duty) {
// SAFETY: This register is exclusively used here so there are no concurrency
// issues.
- unsafe { (&*<$TIMER>::ptr()).$ocr.write(|w| w.bits(duty.into())); };
+ unsafe { (&*<$TIMER>::ptr()).$ocr().write(|w| w.bits(duty.into())); };
}
}
)+
diff --git a/avr-hal-generic/src/spi.rs b/avr-hal-generic/src/spi.rs
index d12563235c..73d2d2a30e 100644
--- a/avr-hal-generic/src/spi.rs
+++ b/avr-hal-generic/src/spi.rs
@@ -454,7 +454,7 @@ macro_rules! impl_spi {
use $crate::hal::spi;
// set up control register
- self.spcr.write(|w| {
+ self.spcr().write(|w| {
// enable SPI
w.spe().set_bit();
// Set to primary mode
@@ -486,7 +486,7 @@ macro_rules! impl_spi {
}
});
// set up 2x clock rate status bit
- self.spsr.write(|w| match settings.clock {
+ self.spsr().write(|w| match settings.clock {
SerialClockRate::OscfOver2 => w.spi2x().set_bit(),
SerialClockRate::OscfOver4 => w.spi2x().clear_bit(),
SerialClockRate::OscfOver8 => w.spi2x().set_bit(),
@@ -498,19 +498,19 @@ macro_rules! impl_spi {
}
fn raw_release(&mut self) {
- self.spcr.write(|w| w.spe().clear_bit());
+ self.spcr().write(|w| w.spe().clear_bit());
}
fn raw_check_iflag(&self) -> bool {
- self.spsr.read().spif().bit_is_set()
+ self.spsr().read().spif().bit_is_set()
}
fn raw_read(&self) -> u8 {
- self.spdr.read().bits()
+ self.spdr().read().bits()
}
fn raw_write(&mut self, byte: u8) {
- self.spdr.write(|w| unsafe { w.bits(byte) });
+ self.spdr().write(|w| unsafe { w.bits(byte) });
}
fn raw_transaction(&mut self, byte: u8) -> u8 {
diff --git a/avr-hal-generic/src/usart.rs b/avr-hal-generic/src/usart.rs
index d929cf553b..ed670014c5 100644
--- a/avr-hal-generic/src/usart.rs
+++ b/avr-hal-generic/src/usart.rs
@@ -484,18 +484,18 @@ macro_rules! impl_usart_traditional {
$crate::port::Pin<$crate::port::mode::Output, $txpin>,
> for $USART {
fn raw_init
This improves the generated API in various ways.
The most major change seems to be from 0.31.0 where registers are now accessed using methods instead of fields. This will require rather large downstream changes.
Upstream svd2rust also switched to a different case style for identifiers in 0.32.0. For now, this is disabled using
--ident-formats legacy
but we should consider following their suggestion at some point in the future.