diff --git a/node/src/lib.rs b/node/src/lib.rs index 66ffc1f..7a6c8c9 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -1,4 +1,7 @@ #![feature(async_fn_in_trait)] -pub mod cell; -mod transducer; \ No newline at end of file +mod transducer; + +pub mod cell { + pub use physical::cell::*; +} diff --git a/node/src/transducer/input.rs b/node/src/transducer/input.rs index 839acc6..f36bec2 100644 --- a/node/src/transducer/input.rs +++ b/node/src/transducer/input.rs @@ -1,2 +1,30 @@ +use crate::cell::CellView; +#[cfg(feature = "embassy-sync")] +use embassy_sync::blocking_mutex::raw::RawMutex; +#[cfg(feature = "embassy-sync")] +use embassy_sync::pubsub::PubSubChannel; pub use physical::transducer::input::*; +#[cfg(feature = "embassy-sync")] +pub struct ChannelInput< + T: Copy, + MutexT: RawMutex, + const CAPACITY: usize, + const NUM_SUBS: usize, + const NUM_PUBS: usize, +> { + channel: PubSubChannel, +} + +#[cfg(feature = "embassy-sync")] +pub struct StatefulChannelInput< + 'a, + T: Copy, + MutexT: RawMutex, + const CAPACITY: usize, + const NUM_SUBS: usize, + const NUM_PUBS: usize, +> { + pub state_cell: CellView<'a, T>, + channel: PubSubChannel, +} diff --git a/node/src/cell.rs b/src/cell.rs similarity index 100% rename from node/src/cell.rs rename to src/cell.rs diff --git a/src/lib.rs b/src/lib.rs index 4ef2a82..6437a0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ #![no_std] -pub mod transducer; \ No newline at end of file +pub mod transducer; +pub mod cell; diff --git a/src/transducer/input.rs b/src/transducer/input.rs index e69de29..7f8cc1d 100644 --- a/src/transducer/input.rs +++ b/src/transducer/input.rs @@ -0,0 +1,20 @@ +use crate::cell::CellView; +use crate::transducer::Stateful; + +pub struct StatefulInput<'a, T: Copy> { + pub state_cell: CellView<'a, T>, +} + +impl<'a, T: Copy> Stateful for StatefulInput<'a, T> { + type Value = T; + + #[inline(always)] + fn state_cell(&self) -> CellView<'a, Self::Value> { + self.state_cell + } + + #[inline] + fn state(&self) -> Self::Value { + self.state_cell.get() + } +} diff --git a/src/transducer/mod.rs b/src/transducer/mod.rs index d3986f6..2d69172 100644 --- a/src/transducer/mod.rs +++ b/src/transducer/mod.rs @@ -1,3 +1,5 @@ +use crate::cell::CellView; + pub mod input; pub mod output; @@ -6,5 +8,7 @@ pub mod output; pub trait Stateful { type Value: Copy; + fn state_cell(&self) -> CellView; + fn state(&self) -> Self::Value; }