Skip to content

Commit

Permalink
Skip unsupported UART control registers avr-rust#48
Browse files Browse the repository at this point in the history
  • Loading branch information
gergoerdi committed Dec 22, 2022
1 parent 6e83cf0 commit 7bd3dea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core_generator/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,22 @@ pub fn write_usarts(mcu: &Mcu, w: &mut dyn Write) -> Result<(), io::Error> {
writeln!(w, "impl modules::HardwareUsart for {} {{", usart.name)?;
for register in usart.registers.iter() {
let reg_ty = if register.name.starts_with("UDR") { // the data register.
"DataRegister".to_owned()
Some("DataRegister".to_owned())
} else if register.name.starts_with("UCSR") { // one of the three control/status registers.
let suffix = register.name.chars().rev().next().unwrap();
format!("ControlRegister{}", suffix)
if suffix == 'A' || suffix == 'B' || suffix == 'C' {
Some(format!("ControlRegister{}", suffix))
} else {
None
}
} else if register.name.starts_with("UBRR") { // the baud rate register.
"BaudRateRegister".to_owned()
Some("BaudRateRegister".to_owned())
} else {
panic!("unknown usart register '{}'", register.name);
};
writeln!(w, " type {} = {};", reg_ty, register.name)?;
if let Some(reg_ty) = reg_ty {
writeln!(w, " type {} = {};", reg_ty, register.name)?;
}
}
writeln!(w, "}}")?;
writeln!(w)?;
Expand Down

0 comments on commit 7bd3dea

Please sign in to comment.