diff --git a/embassy-nxp/Cargo.toml b/embassy-nxp/Cargo.toml index 1df672bfe4..ab51f4e7e9 100644 --- a/embassy-nxp/Cargo.toml +++ b/embassy-nxp/Cargo.toml @@ -40,13 +40,13 @@ embassy-time-queue-utils = { version = "0.3.2", path = "../embassy-time-queue-ut embedded-io = { version = "0.7.1" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } ## Chip dependencies -nxp-pac = { version = "0.1.0", optional = true, git = "https://github.com/embassy-rs/nxp-pac", rev = "c54814bbb514495a7a5aebad7d17b987b7b70c0f" } +nxp-pac = { version = "0.1.0", optional = true, git = "https://github.com/embassy-rs/nxp-pac", rev = "59cc45767cc48a4285270c95fecccd447f143030" } imxrt-rt = { version = "0.1.7", optional = true, features = ["device"] } [build-dependencies] cfg_aliases = "0.2.1" -nxp-pac = { version = "0.1.0", git = "https://github.com/embassy-rs/nxp-pac", rev = "c54814bbb514495a7a5aebad7d17b987b7b70c0f", default-features = false, features = ["metadata"] } +nxp-pac = { version = "0.1.0", git = "https://github.com/embassy-rs/nxp-pac", rev = "59cc45767cc48a4285270c95fecccd447f143030", default-features = false, features = ["metadata"] } proc-macro2 = "1.0.95" quote = "1.0.15" diff --git a/embassy-nxp/build.rs b/embassy-nxp/build.rs index a90d834116..bdd3dacaf2 100644 --- a/embassy-nxp/build.rs +++ b/embassy-nxp/build.rs @@ -268,6 +268,26 @@ fn peripherals(singletons: &[Singleton]) -> TokenStream { } } +fn impl_adc(impls: &mut Vec, peripheral: &Peripheral) { + for signal in peripheral.signals.iter() { + let (ch_num, ch_side) = signal.name.rsplit_once("_").unwrap(); + let ch_num = ch_num.strip_prefix("CH").unwrap().parse::().unwrap(); + let ch_side = match ch_side { + "A" => format_ident!("SideA"), + "B" => format_ident!("SideB"), + side => panic!("Invalid ADC channel side: {}", side), + }; + + assert_eq!(signal.pins.len(), 1); + let pin = format_ident!("{}", signal.pins[0].pin); + let ch_num = Literal::u8_unsuffixed(ch_num); + + impls.push(quote! { + impl_adc_pin!(#pin, #ch_num, crate::adc::ChannelSide::#ch_side); + }) + } +} + fn impl_gpio_pin(impls: &mut Vec, peripheral: &Peripheral) { let instance = peripheral.name.strip_prefix("GPIO").unwrap(); let bank = format_ident!("Gpio{}", instance); @@ -445,6 +465,10 @@ fn impl_peripherals(cfgs: &mut common::CfgSet, _singletons: &[Singleton]) -> Tok let mut impls = Vec::new(); for peripheral in metadata::METADATA.peripherals.iter() { + if peripheral.name.starts_with("ADC") { + impl_adc(&mut impls, peripheral); + } + if peripheral.name.starts_with("GPIO") { impl_gpio_pin(&mut impls, peripheral); } diff --git a/embassy-nxp/src/adc/lpc55.rs b/embassy-nxp/src/adc/lpc55.rs index 7cdc63303b..74820c8b45 100644 --- a/embassy-nxp/src/adc/lpc55.rs +++ b/embassy-nxp/src/adc/lpc55.rs @@ -242,7 +242,6 @@ pub trait AdcPin: crate::gpio::Pin { w.set_func(0.into()); w.set_mode(0.into()); w.set_digimode(0.into()); - #[cfg(feature = "lpc55-core0")] w.set_asw(1.into()) }); } @@ -251,7 +250,6 @@ pub trait AdcPin: crate::gpio::Pin { w.set_func(0.into()); w.set_mode(0.into()); w.set_digimode(0.into()); - #[cfg(feature = "lpc55-core0")] w.set_asw(1.into()) }); } @@ -262,6 +260,7 @@ pub trait AdcPin: crate::gpio::Pin { /// Channel side /// There are 2 ADC sides on each channels /// Each channel supports either single ended mode (just one channel) or differential (difference between two channels) +/// Differential mode is not supported by this driver yet #[repr(u8)] pub enum ChannelSide { SideA = 0, @@ -279,22 +278,9 @@ macro_rules! impl_adc_pin { $adc_channel } - fn channel_side(&self) -> ChannelSide { + fn channel_side(&self) -> crate::adc::ChannelSide { $channel_side } } }; } - -// https://www.nxp.com/docs/en/data-sheet/LPC55S6x.pdf -// Table 3 (starts at page 8) -impl_adc_pin!(PIO0_23, 0, ChannelSide::SideA); -impl_adc_pin!(PIO0_16, 0, ChannelSide::SideB); -impl_adc_pin!(PIO0_10, 1, ChannelSide::SideA); -impl_adc_pin!(PIO0_11, 1, ChannelSide::SideB); -impl_adc_pin!(PIO0_15, 2, ChannelSide::SideA); -impl_adc_pin!(PIO0_12, 2, ChannelSide::SideB); -impl_adc_pin!(PIO0_31, 3, ChannelSide::SideA); -impl_adc_pin!(PIO1_0, 3, ChannelSide::SideB); -impl_adc_pin!(PIO1_8, 4, ChannelSide::SideA); -impl_adc_pin!(PIO1_9, 4, ChannelSide::SideB);