diff --git a/macros/node-poll-variants/src/lib.rs b/macros/node-poll-variants/src/lib.rs index c6d8b99..53f2597 100644 --- a/macros/node-poll-variants/src/lib.rs +++ b/macros/node-poll-variants/src/lib.rs @@ -63,7 +63,7 @@ pub fn poll_variant_macro(input: TokenStream) -> TokenStream { // ----- Add publisher generics ---------------------------------- // MutexT - const MUTEX_T_NAME: &str = "MutexT"; + const MUTEX_T_NAME: &str = "PublishMutexT"; let mutex_t_ident = Ident::new(MUTEX_T_NAME, Span::call_site()); const CAPACITY_NAME: &str = "CAPACITY"; let capacity_ident = Ident::new(CAPACITY_NAME, Span::call_site()); diff --git a/peripheral-components/ads1256/node/Cargo.toml b/peripheral-components/ads1256/node/Cargo.toml index 32df4a4..b4f8d3d 100644 --- a/peripheral-components/ads1256/node/Cargo.toml +++ b/peripheral-components/ads1256/node/Cargo.toml @@ -8,7 +8,8 @@ readme.workspace = true license.workspace = true [features] -poll = ["node-poll-variants"] +embassy-sync = ["dep:embassy-sync", "ads1256/embassy-sync"] +poll = ["standard-multiplexer", "embassy-sync"] config = ["physical-ads1256-types/config"] standard-input = ["physical-ads1256-types/standard-input"] standard-multiplexer = ["standard-input"] @@ -17,7 +18,6 @@ standard-multiplexer = ["standard-input"] path = "../../../node" [dependencies.node-poll-variants] path = "../../../macros/node-poll-variants" -optional = true [dependencies.physical-ads1256-types] path = "../types" features = ["defmt"] @@ -30,4 +30,7 @@ workspace = true [dependencies.defmt] workspace = true [dependencies.uom] -workspace = true \ No newline at end of file +workspace = true +[dependencies.embassy-sync] +workspace = true +optional = true \ No newline at end of file diff --git a/peripheral-components/ads1256/node/src/lib.rs b/peripheral-components/ads1256/node/src/lib.rs index 72729a0..646b486 100644 --- a/peripheral-components/ads1256/node/src/lib.rs +++ b/peripheral-components/ads1256/node/src/lib.rs @@ -1,7 +1,9 @@ #![no_std] +#![feature(async_fn_in_trait, impl_trait_projections)] #[cfg(feature = "standard-multiplexer")] mod standard_multiplexer; +#[cfg(feature = "poll")] mod poll; pub use physical_ads1256_types::*; \ No newline at end of file diff --git a/peripheral-components/ads1256/node/src/poll.rs b/peripheral-components/ads1256/node/src/poll.rs deleted file mode 100644 index e69de29..0000000 diff --git a/peripheral-components/ads1256/node/src/standard_multiplexer.rs b/peripheral-components/ads1256/node/src/standard_multiplexer.rs deleted file mode 100644 index e69de29..0000000 diff --git a/peripheral-components/ads1256/node/src/standard_multiplexer/mod.rs b/peripheral-components/ads1256/node/src/standard_multiplexer/mod.rs new file mode 100644 index 0000000..2c842b4 --- /dev/null +++ b/peripheral-components/ads1256/node/src/standard_multiplexer/mod.rs @@ -0,0 +1,4 @@ +mod sync; + +#[cfg(feature = "embassy-sync")] +pub use sync::*; \ No newline at end of file diff --git a/peripheral-components/ads1256/node/src/standard_multiplexer/sync/mod.rs b/peripheral-components/ads1256/node/src/standard_multiplexer/sync/mod.rs new file mode 100644 index 0000000..5e18f2b --- /dev/null +++ b/peripheral-components/ads1256/node/src/standard_multiplexer/sync/mod.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "poll")] +pub mod poll; \ No newline at end of file diff --git a/peripheral-components/ads1256/node/src/standard_multiplexer/sync/poll.rs b/peripheral-components/ads1256/node/src/standard_multiplexer/sync/poll.rs new file mode 100644 index 0000000..8eaddaa --- /dev/null +++ b/peripheral-components/ads1256/node/src/standard_multiplexer/sync/poll.rs @@ -0,0 +1,249 @@ +use core::ops::DerefMut; +use ads1256::{ + AdControl, Ads1256, BlockingDelay, DataRate, Multiplexer, OutputPin, SpiBus, Status, Wait, +}; +use embassy_sync::blocking_mutex::raw::RawMutex; +use embassy_sync::mutex::Mutex; +use physical_node::transducer::input::Poll; + +pub struct AutocalPoll<'a, DeviceMutexT, ModInT, DelayerT, SST, DrdyT, SpiT> +where + DeviceMutexT: RawMutex, + ModInT: ModInput, + DelayerT: BlockingDelay, + SST: OutputPin, + DrdyT: Wait, + SpiT: SpiBus, +{ + input_mod: ModInT, + ads1256: &'a Mutex>, + spi: &'a Mutex, +} + +impl<'a, DeviceMutexT, ModInT, DelayerT, SST, DrdyT, SpiT> Poll + for AutocalPoll<'a, DeviceMutexT, ModInT, DelayerT, SST, DrdyT, SpiT> +where + DeviceMutexT: RawMutex, + ModInT: ModInput, + DelayerT: BlockingDelay, + SST: OutputPin, + DrdyT: Wait, + SpiT: SpiBus, +{ + type Value = (); + + async fn poll(&self) -> Self::Value { + todo!() + } +} + +pub trait ModInput { + fn multiplexer(self) -> Multiplexer; + + fn status(self) -> Option; + + fn ad_control(self) -> Option; + + fn data_rate(self) -> Option; +} + +/// buffer +pub struct ModInStatus { + pub multiplexer: Multiplexer, + pub status: Status, +} + +impl ModInput for ModInStatus { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + Some(self.status) + } + + #[inline(always)] + fn ad_control(self) -> Option { + None + } + + #[inline(always)] + fn data_rate(self) -> Option { + None + } +} + +/// gain +pub struct ModInAdControl { + pub multiplexer: Multiplexer, + pub ad_control: AdControl, +} + +impl ModInput for ModInAdControl { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + None + } + + #[inline(always)] + fn ad_control(self) -> Option { + Some(self.ad_control) + } + + #[inline(always)] + fn data_rate(self) -> Option { + None + } +} + +/// data rate +pub struct ModInDataRate { + pub multiplexer: Multiplexer, + pub data_rate: DataRate, +} + +impl ModInput for ModInDataRate { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + None + } + + #[inline(always)] + fn ad_control(self) -> Option { + None + } + + #[inline(always)] + fn data_rate(self) -> Option { + Some(self.data_rate) + } +} + +/// buffer, gain +pub struct ModInStatAdc { + pub multiplexer: Multiplexer, + pub status: Status, + pub ad_control: AdControl, +} + +impl ModInput for ModInStatAdc { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + Some(self.status) + } + + #[inline(always)] + fn ad_control(self) -> Option { + Some(self.ad_control) + } + + #[inline(always)] + fn data_rate(self) -> Option { + None + } +} + +/// buffer, data rate +pub struct ModInStatDrate { + pub multiplexer: Multiplexer, + pub status: Status, + pub data_rate: DataRate, +} + +impl ModInput for ModInStatDrate { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + Some(self.status) + } + + #[inline(always)] + fn ad_control(self) -> Option { + None + } + + #[inline(always)] + fn data_rate(self) -> Option { + Some(self.data_rate) + } +} + +// gain, data rate +pub struct ModInAdcDrate { + pub multiplexer: Multiplexer, + pub ad_control: AdControl, + pub data_rate: DataRate, +} + +impl ModInput for ModInAdcDrate { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + None + } + + #[inline(always)] + fn ad_control(self) -> Option { + Some(self.ad_control) + } + + #[inline(always)] + fn data_rate(self) -> Option { + Some(self.data_rate) + } +} + +/// buffer, gain, data rate +pub struct ModInAll { + pub multiplexer: Multiplexer, + pub status: Status, + pub ad_control: AdControl, + pub data_rate: DataRate, +} + +impl ModInput for ModInAll { + #[inline(always)] + fn multiplexer(self) -> Multiplexer { + self.multiplexer + } + + #[inline(always)] + fn status(self) -> Option { + Some(self.status) + } + + #[inline(always)] + fn ad_control(self) -> Option { + Some(self.ad_control) + } + + #[inline(always)] + fn data_rate(self) -> Option { + Some(self.data_rate) + } +}