From dcab721dc12400bf94984beee73e219501dfde27 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Sun, 17 Dec 2017 15:02:23 +1300 Subject: [PATCH] Use the correct timer thing --- core_generator/gen.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core_generator/gen.rs b/core_generator/gen.rs index 331b021..a4b23cf 100644 --- a/core_generator/gen.rs +++ b/core_generator/gen.rs @@ -168,6 +168,8 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> { tc.registers().find(|r| r.name.starts_with(name) && r.name.ends_with(suffix)) .expect(&format!("could not find '{}' register", name)) }; + let timer_number = find_reg("TIMSK").name.chars().last().unwrap() + .to_digit(10).unwrap(); writeln!(w, "/// 8-bit timer.")?; writeln!(w, "pub struct {};", TYPE_NAME)?; @@ -186,7 +188,7 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> { writeln!(w, " const WGM0: Mask = Self::ControlA::WGM00;")?; writeln!(w, " const WGM1: Mask = Self::ControlA::WGM01;")?; writeln!(w, " const WGM2: Mask = Self::ControlB::WGM020;")?; - writeln!(w, " const OCIEA: Mask = Self::InterruptMask::OCIE0A;")?; + writeln!(w, " const OCIEA: Mask = Self::InterruptMask::OCIE{}A;", timer_number)?; writeln!(w, "}}")?; } @@ -201,6 +203,8 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> { tc.registers().find(|r| r.name.starts_with(name) && r.name.ends_with(suffix)) .expect(&format!("could not find '{}' register", name)) }; + let timer_number = find_reg("TIMSK").name.chars().last().unwrap() + .to_digit(10).unwrap(); writeln!(w, "/// 16-bit timer.")?; writeln!(w, "pub struct {};", TYPE_NAME)?; @@ -221,7 +225,7 @@ pub fn write_timers(mcu: &Mcu, w: &mut Write) -> Result<(), io::Error> { writeln!(w, " const WGM1: Mask = Self::ControlA::WGM11;")?; writeln!(w, " const WGM2: Mask = Self::ControlB::WGM10;")?; writeln!(w, " const WGM3: Mask = Self::ControlB::WGM11;")?; - writeln!(w, " const OCIEA: Mask = Self::InterruptMask::OCIE1A;")?; + writeln!(w, " const OCIEA: Mask = Self::InterruptMask::OCIE{}A;", timer_number)?; writeln!(w, "}}")?; }