Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions embassy-nxp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "e93605d8e8686f1853726921d5349ef3ecdea693" }
nxp-pac = { version = "0.1.0", optional = true, git = "https://github.com/embassy-rs/nxp-pac", rev = "277270550eb614113e05aa61fed170974976d977" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to change this hash after your nxp-pac commit is merged


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 = "e93605d8e8686f1853726921d5349ef3ecdea693", default-features = false, features = ["metadata"] }
nxp-pac = { version = "0.1.0", git = "https://github.com/embassy-rs/nxp-pac", rev = "277270550eb614113e05aa61fed170974976d977", default-features = false, features = ["metadata"] }
proc-macro2 = "1.0.95"
quote = "1.0.15"

Expand Down
24 changes: 24 additions & 0 deletions embassy-nxp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ fn peripherals(singletons: &[Singleton]) -> TokenStream {
}
}

fn impl_adc(impls: &mut Vec<TokenStream>, 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::<u8>().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<TokenStream>, peripheral: &Peripheral) {
let instance = peripheral.name.strip_prefix("GPIO").unwrap();
let bank = format_ident!("Gpio{}", instance);
Expand Down Expand Up @@ -403,6 +423,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);
}
Expand Down
18 changes: 2 additions & 16 deletions embassy-nxp/src/adc/lpc55.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
});
}
Expand All @@ -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())
});
}
Expand All @@ -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,
Expand All @@ -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);