diff --git a/app/lpc55xpresso/app-sprot.toml b/app/lpc55xpresso/app-sprot.toml index 097e9a810..7a98140df 100644 --- a/app/lpc55xpresso/app-sprot.toml +++ b/app/lpc55xpresso/app-sprot.toml @@ -157,12 +157,12 @@ interrupts = {"flexcomm5.irq" = "spi-irq"} # Out = MOSI on, MISO off out_cfg = [ { pin = { port = 0, pin = 8 }, alt = 3 }, - { pin = { port = 0, pin = 9 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 9 }, alt = 0, mode = "pulldown" }, ] # In = MISO on, MOSI off in_cfg = [ { pin = { port = 0, pin = 9 }, alt = 3 }, - { pin = { port = 0, pin = 8 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 8 }, alt = 0, mode = "pulldown" }, ] pins = [ # SCK diff --git a/app/oxide-rot-1/app-dev.toml b/app/oxide-rot-1/app-dev.toml index 1d0097b86..563230c2a 100644 --- a/app/oxide-rot-1/app-dev.toml +++ b/app/oxide-rot-1/app-dev.toml @@ -121,12 +121,12 @@ interrupts = {"flexcomm5.irq" = "spi-irq"} # Out = MOSI on, MISO off out_cfg = [ { pin = { port = 0, pin = 8 }, alt = 3 }, - { pin = { port = 0, pin = 9 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 9 }, alt = 0, mode = "pulldown" }, ] # In = MISO on, MOSI off in_cfg = [ { pin = { port = 0, pin = 9 }, alt = 3 }, - { pin = { port = 0, pin = 8 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 8 }, alt = 0, mode = "pulldown" }, ] pins = [ # SCK diff --git a/app/oxide-rot-1/app.toml b/app/oxide-rot-1/app.toml index cf17974ad..bb7db15e7 100644 --- a/app/oxide-rot-1/app.toml +++ b/app/oxide-rot-1/app.toml @@ -111,12 +111,12 @@ interrupts = {"flexcomm5.irq" = "spi-irq"} # Out = MOSI on, MISO off out_cfg = [ { pin = { port = 0, pin = 8 }, alt = 3 }, - { pin = { port = 0, pin = 9 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 9 }, alt = 0, mode = "pulldown" }, ] # In = MISO on, MOSI off in_cfg = [ { pin = { port = 0, pin = 9 }, alt = 3 }, - { pin = { port = 0, pin = 8 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 8 }, alt = 0, mode = "pulldown" }, ] pins = [ # SCK diff --git a/app/rot-carrier/app.toml b/app/rot-carrier/app.toml index b5a92d3d2..a42dfac9d 100644 --- a/app/rot-carrier/app.toml +++ b/app/rot-carrier/app.toml @@ -151,12 +151,12 @@ interrupts = {"flexcomm3.irq" = "spi-irq"} # Out = MOSI on, MISO off out_cfg = [ { pin = { port = 0, pin = 3 }, alt = 1 }, - { pin = { port = 0, pin = 2 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 2 }, alt = 0, mode = "pulldown" }, ] # In = MISO on, MOSI off in_cfg = [ { pin = { port = 0, pin = 2 }, alt = 1 }, - { pin = { port = 0, pin = 3 }, alt = 0, mode = "PullDown" }, + { pin = { port = 0, pin = 3 }, alt = 0, mode = "pulldown" }, ] pins = [ # SCK diff --git a/build/lpc55pins/src/lib.rs b/build/lpc55pins/src/lib.rs index d0e6e8d70..8f7e1949b 100644 --- a/build/lpc55pins/src/lib.rs +++ b/build/lpc55pins/src/lib.rs @@ -9,7 +9,7 @@ use serde::Deserialize; use std::io::{BufWriter, Write}; #[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "kebab-case", deny_unknown_fields)] +#[serde(rename_all = "lowercase", deny_unknown_fields)] struct Pin { port: usize, pin: usize, @@ -36,55 +36,74 @@ impl ToTokens for Pin { } #[derive(Clone, Debug, Deserialize)] -#[serde(rename_all = "kebab-case", deny_unknown_fields)] +#[serde(rename_all = "lowercase", deny_unknown_fields)] pub struct PinConfig { pin: Pin, alt: usize, - mode: Option, - slew: Option, - invert: Option, - digimode: Option, - opendrain: Option, - direction: Option, + #[serde(default)] + mode: Mode, + #[serde(default)] + slew: Slew, + #[serde(default)] + invert: Invert, + #[serde(default)] + digimode: Digimode, + #[serde(default)] + opendrain: Opendrain, + direction: Option, name: Option, } -impl PinConfig { - fn get_mode(&self) -> String { - match &self.mode { - None => "NoPull".to_string(), - Some(s) => s.to_string(), - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "lowercase")] +enum Mode { + #[default] + NoPull, + PullDown, + PullUp, + Repeater, +} - fn get_slew(&self) -> String { - match &self.slew { - None => "Standard".to_string(), - Some(s) => s.to_string(), - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "lowercase")] +enum Slew { + #[default] + Standard, + Fast, +} - fn get_invert(&self) -> String { - match &self.invert { - None => "Disable".to_string(), - Some(s) => s.to_string(), - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Invert { + #[default] + Disable, + Enabled, +} - fn get_digimode(&self) -> String { - match &self.digimode { - None => "Digital".to_string(), - Some(s) => s.to_string(), - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Digimode { + #[default] + Digital, + Analog, +} - fn get_opendrain(&self) -> String { - match &self.opendrain { - None => "Normal".to_string(), - Some(s) => s.to_string(), - } - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Opendrain { + #[default] + Normal, + Opendrain, +} + +#[derive(Copy, Clone, Debug, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Direction { + Input, + Output, +} +impl PinConfig { fn get_alt(&self) -> usize { if self.alt > 9 { panic!("Invalid alt setting {}", self.alt); @@ -98,12 +117,12 @@ impl ToTokens for PinConfig { fn to_tokens(&self, tokens: &mut TokenStream) { let final_pin = self.pin.to_token_stream(); let alt_num = format_ident!("Alt{}", self.get_alt()); - let mode = format_ident!("{}", self.get_mode()); - let slew = format_ident!("{}", self.get_slew()); - let invert = format_ident!("{}", self.get_invert()); - let digimode = format_ident!("{}", self.get_digimode()); - let od = format_ident!("{}", self.get_opendrain()); + let mode = format_ident!("{}", format!("{:?}", self.mode)); + let slew = format_ident!("{}", format!("{:?}", self.slew)); + let invert = format_ident!("{}", format!("{:?}", self.invert)); + let digimode = format_ident!("{}", format!("{:?}", self.digimode)); + let od = format_ident!("{}", format!("{:?}", self.opendrain)); tokens.append_all(final_pin); tokens.append_all(quote::quote! { AltFn::#alt_num, @@ -135,16 +154,13 @@ pub fn codegen(pins: Vec) -> Result<()> { writeln!(&mut file, "iocon.iocon_configure(")?; writeln!(&mut file, "{}", p.to_token_stream())?; writeln!(&mut file, ");")?; + match p.direction { None => (), Some(d) => { writeln!(&mut file, "iocon.set_dir(")?; writeln!(&mut file, "{}", p.pin.to_token_stream())?; - if d == "output" { - writeln!(&mut file, "Direction::Output")?; - } else { - writeln!(&mut file, "Direction::Input")?; - } + writeln!(&mut file, "Direction::{d:?}")?; writeln!(&mut file, ");")?; } }