diff --git a/Cargo.lock b/Cargo.lock index a68b25b1..3bff2fee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -646,8 +646,8 @@ dependencies = [ [[package]] name = "embedded-cfu-protocol" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#ffb9041a2ec9ca7a411f3439f45eec3bc01b975b" +version = "0.2.0" +source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#a4cc8707842b878048447abbf2af4efa79fed368" dependencies = [ "defmt 0.3.100", "embedded-io-async", diff --git a/Cargo.toml b/Cargo.toml index bd073d7a..661c4e8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ embassy-sync = { git = "https://github.com/embassy-rs/embassy" } embassy-time = { git = "https://github.com/embassy-rs/embassy" } embassy-time-driver = { git = "https://github.com/embassy-rs/embassy" } embedded-batteries-async = "0.1.0" -embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.1.0" } +embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu" } embedded-hal = "1.0" embedded-hal-async = "1.0" embedded-hal-nb = "1.0" diff --git a/battery-service/src/device.rs b/battery-service/src/device.rs index 011f288d..423da6c4 100644 --- a/battery-service/src/device.rs +++ b/battery-service/src/device.rs @@ -1,8 +1,6 @@ -use core::cell::Cell; - -use embassy_sync::channel::Channel; +use embassy_sync::{channel::Channel, mutex::Mutex}; use embassy_time::Duration; -use embedded_services::{GlobalRawMutex, Node, NodeContainer}; +use embedded_services::{GlobalRawMutex, Node, NodeContainer, SyncCell}; #[derive(Debug, Clone, Copy)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -116,9 +114,9 @@ pub struct Device { id: DeviceId, command: Channel, response: Channel, - dynamic_battery_cache: Cell, - static_battery_cache: Cell, - timeout: Cell, + dynamic_battery_cache: Mutex, + static_battery_cache: Mutex, + timeout: SyncCell, } impl Device { @@ -128,9 +126,9 @@ impl Device { id, command: Channel::new(), response: Channel::new(), - dynamic_battery_cache: Cell::default(), - static_battery_cache: Cell::default(), - timeout: Cell::new(Duration::from_secs(60)), + dynamic_battery_cache: Mutex::default(), + static_battery_cache: Mutex::default(), + timeout: SyncCell::new(Duration::from_secs(60)), } } @@ -166,23 +164,23 @@ impl Device { } /// Set dynamic battery cache with updated values. - pub fn set_dynamic_battery_cache(&self, new_values: DynamicBatteryMsgs) { - self.dynamic_battery_cache.set(new_values); + pub async fn set_dynamic_battery_cache(&self, new_values: DynamicBatteryMsgs) { + *self.dynamic_battery_cache.lock().await = new_values; } /// Set static battery cache with updated values. - pub fn set_static_battery_cache(&self, new_values: StaticBatteryMsgs) { - self.static_battery_cache.set(new_values); + pub async fn set_static_battery_cache(&self, new_values: StaticBatteryMsgs) { + *self.static_battery_cache.lock().await = new_values; } /// Get dynamic battery cache. - pub fn get_dynamic_battery_cache(&self) -> DynamicBatteryMsgs { - self.dynamic_battery_cache.get() + pub async fn get_dynamic_battery_cache(&self) -> DynamicBatteryMsgs { + *self.dynamic_battery_cache.lock().await } /// Get static battery cache. - pub fn get_static_battery_cache(&self) -> StaticBatteryMsgs { - self.static_battery_cache.get() + pub async fn get_static_battery_cache(&self) -> StaticBatteryMsgs { + *self.static_battery_cache.lock().await } /// Set device timeout. diff --git a/battery-service/src/wrapper.rs b/battery-service/src/wrapper.rs index ff8297a8..11a7a9e8 100644 --- a/battery-service/src/wrapper.rs +++ b/battery-service/src/wrapper.rs @@ -76,7 +76,7 @@ impl<'a, C: Controller> Wrapper<'a, C> { }, Command::UpdateStaticCache => match controller.get_static_data().await { Ok(static_data) => { - device.set_static_battery_cache(static_data); + device.set_static_battery_cache(static_data).await; device .send_response(Ok(crate::device::InternalResponse::Complete)) .await; @@ -88,7 +88,7 @@ impl<'a, C: Controller> Wrapper<'a, C> { }, Command::UpdateDynamicCache => match controller.get_dynamic_data().await { Ok(dynamic_data) => { - device.set_dynamic_battery_cache(dynamic_data); + device.set_dynamic_battery_cache(dynamic_data).await; device .send_response(Ok(crate::device::InternalResponse::Complete)) .await; diff --git a/cfu-service/src/buffer.rs b/cfu-service/src/buffer.rs index 46368f19..119fc473 100644 --- a/cfu-service/src/buffer.rs +++ b/cfu-service/src/buffer.rs @@ -5,7 +5,7 @@ use core::future::pending; use embassy_futures::select::{Either3, select3}; use embassy_sync::{ - channel::{DynamicReceiver, DynamicSender}, + channel::{SendDynamicReceiver, SendDynamicSender}, mutex::Mutex, }; use embassy_time::{Duration, TimeoutError, with_timeout}; @@ -57,10 +57,10 @@ pub struct Buffer<'a> { state: Mutex, /// Component ID to buffer requests for buffered_id: ComponentId, - /// Sender for the buffer - buffer_sender: DynamicSender<'a, FwUpdateContentCommand>, - /// Receiver for the buffer - buffer_receiver: DynamicReceiver<'a, FwUpdateContentCommand>, + /// Sender for the buffer. Must be used with a channel with an underlying Mutex that is Send and Sync. + buffer_sender: SendDynamicSender<'a, FwUpdateContentCommand>, + /// Receiver for the buffer. Must be used with a channel with an underlying Mutex that is Send and Sync. + buffer_receiver: SendDynamicReceiver<'a, FwUpdateContentCommand>, /// Configuration for the buffer config: Config, } @@ -81,8 +81,8 @@ impl<'a> Buffer<'a> { pub fn new( external_id: ComponentId, buffered_id: ComponentId, - buffer_sender: DynamicSender<'a, FwUpdateContentCommand>, - buffer_receiver: DynamicReceiver<'a, FwUpdateContentCommand>, + buffer_sender: SendDynamicSender<'a, FwUpdateContentCommand>, + buffer_receiver: SendDynamicReceiver<'a, FwUpdateContentCommand>, config: Config, ) -> Self { Self { diff --git a/cfu-service/src/host.rs b/cfu-service/src/host.rs index de9b1564..c86e215e 100644 --- a/cfu-service/src/host.rs +++ b/cfu-service/src/host.rs @@ -3,30 +3,31 @@ use core::future::Future; use embedded_cfu_protocol::components::CfuComponentTraits; use embedded_cfu_protocol::host::{CfuHostStates, CfuUpdater}; use embedded_cfu_protocol::protocol_definitions::*; -use embedded_cfu_protocol::{CfuImage, CfuWriter, CfuWriterDefault, CfuWriterError}; +use embedded_cfu_protocol::{ + CfuImage, + writer::{CfuWriterAsync, CfuWriterError, CfuWriterNop}, +}; use heapless::Vec; use crate::CfuError; /// All host side Cfu traits, in some cases this will originate from a OS driver for CFU -pub trait CfuHost: CfuHostStates { +pub trait CfuHost: CfuHostStates { /// Get all images fn get_cfu_images(&self) -> impl Future, CfuError>>; /// Gets the firmware version of all components - fn get_all_fw_versions( + fn get_all_fw_versions( self, - writer: &mut T, + writer: &mut W, primary_cmpt: ComponentId, ) -> impl Future>; /// Goes through the offer list and returns a slice of offer responses - fn process_cfu_offers<'a, T: CfuWriter>( + fn process_cfu_offers<'a>( offer_commands: &'a [FwUpdateOffer], - writer: &mut T, + writer: &mut W, ) -> impl Future>; /// For a specific component, update its content - fn update_cfu_content( - writer: &mut T, - ) -> impl Future>; + fn update_cfu_content(writer: &mut W) -> impl Future>; /// For a specific image that was updated, validate its content fn is_cfu_image_valid(image: I) -> impl Future>; } @@ -34,7 +35,7 @@ pub trait CfuHost: CfuHostStates { pub struct CfuHostInstance { pub updater: CfuUpdater, pub images: heapless::Vec, - pub writer: CfuWriterDefault, + pub writer: CfuWriterNop, pub primary_cmpt: C, pub host_token: HostToken, } @@ -45,15 +46,15 @@ impl CfuHostInstance { Self { updater: CfuUpdater {}, images: Vec::new(), - writer: CfuWriterDefault::default(), + writer: CfuWriterNop, primary_cmpt, host_token: HostToken::Driver, } } } -impl CfuHostStates for CfuHostInstance { - async fn start_transaction(self, _writer: &mut T) -> Result { +impl CfuHostStates for CfuHostInstance { + async fn start_transaction(self, _writer: &mut W) -> Result { let _mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, SpecialComponentIds::Info, @@ -62,10 +63,7 @@ impl CfuHostStates for CfuHostInstance let mockresponse = FwUpdateOfferResponse::default(); Ok(mockresponse) } - async fn notify_start_offer_list( - self, - writer: &mut T, - ) -> Result { + async fn notify_start_offer_list(self, writer: &mut W) -> Result { // Serialize FwUpdateOfferInformation to bytes let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, @@ -89,10 +87,7 @@ impl CfuHostStates for CfuHostInstance } } - async fn notify_end_offer_list( - self, - writer: &mut T, - ) -> Result { + async fn notify_end_offer_list(self, writer: &mut W) -> Result { let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, SpecialComponentIds::Info, @@ -128,14 +123,14 @@ impl CfuHostStates for CfuHostInstance } } -impl CfuHost for CfuHostInstance { +impl CfuHost for CfuHostInstance { async fn get_cfu_images(&self) -> Result, CfuError> { Err(CfuError::BadImage) } - async fn get_all_fw_versions( + async fn get_all_fw_versions( self, - _writer: &mut T, + _writer: &mut W, primary_cmpt: ComponentId, ) -> Result { let mut component_count: u8 = 0; @@ -172,15 +167,15 @@ impl CfuHost for CfuHostInstance { } } - async fn process_cfu_offers<'a, T: CfuWriter>( + async fn process_cfu_offers<'a>( _offer_commands: &'a [FwUpdateOffer], - _writer: &mut T, + _writer: &mut W, ) -> Result<&'a [FwUpdateOfferResponse], CfuError> { // TODO Err(CfuError::BadImage) } - async fn update_cfu_content(_writer: &mut T) -> Result { + async fn update_cfu_content(_writer: &mut W) -> Result { Err(CfuError::ProtocolError(CfuProtocolError::WriterError( CfuWriterError::Other, ))) diff --git a/cfu-service/src/lib.rs b/cfu-service/src/lib.rs index f3995bd5..21f69362 100644 --- a/cfu-service/src/lib.rs +++ b/cfu-service/src/lib.rs @@ -1,10 +1,12 @@ #![no_std] + use embassy_sync::once_lock::OnceLock; use embedded_cfu_protocol::client::CfuReceiveContent; +use embedded_cfu_protocol::components::CfuComponentTraits; use embedded_cfu_protocol::protocol_definitions::*; use embedded_services::cfu::component::*; use embedded_services::cfu::{CfuError, ContextToken}; -use embedded_services::{comms, error, info}; +use embedded_services::{comms, error, info, trace}; pub mod buffer; pub mod host; @@ -17,8 +19,21 @@ pub struct CfuClient { tp: comms::Endpoint, } -/// use default "do-nothing" implementations -impl CfuReceiveContent for CfuClient {} +impl CfuReceiveContent for CfuClient { + async fn process_command(&self, _args: Option, _cmd: C) -> Result<(), ()> { + trace!("CfuClient CfuReceiveContent::process_command do nothing implementation."); + Ok(()) + } + + async fn prepare_components( + &self, + _args: Option, + _primary_component: impl CfuComponentTraits, + ) -> Result<(), ()> { + trace!("CfuClient CfuReceiveContent::prepare_components do nothing implementation."); + Ok(()) + } +} impl CfuClient { /// Create a new Cfu Client diff --git a/embedded-service/src/cfu/component.rs b/embedded-service/src/cfu/component.rs index 0b5e3ff2..e7633a27 100644 --- a/embedded-service/src/cfu/component.rs +++ b/embedded-service/src/cfu/component.rs @@ -5,7 +5,7 @@ use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; use embedded_cfu_protocol::components::{CfuComponentInfo, CfuComponentStorage, CfuComponentTraits}; use embedded_cfu_protocol::protocol_definitions::*; -use embedded_cfu_protocol::{CfuWriter, CfuWriterError}; +use embedded_cfu_protocol::writer::{CfuWriterAsync, CfuWriterError}; use heapless::Vec; use super::CfuError; @@ -173,7 +173,7 @@ impl CfuDevice { } /// Example for CFU Component -pub struct CfuComponentDefault { +pub struct CfuComponentDefault { device: CfuDevice, is_dual_bank: bool, is_primary: bool, @@ -182,19 +182,19 @@ pub struct CfuComponentDefault { writer: Mutex, } -impl Default for CfuComponentDefault { +impl Default for CfuComponentDefault { fn default() -> Self { Self::new(1, false, [None; MAX_SUBCMPT_COUNT], W::default()) } } -impl CfuDeviceContainer for CfuComponentDefault { +impl CfuDeviceContainer for CfuComponentDefault { fn get_cfu_component_device(&self) -> &CfuDevice { &self.device } } -impl CfuComponentDefault { +impl CfuComponentDefault { /// Constructor pub fn new( id: ComponentId, @@ -283,7 +283,7 @@ impl CfuComponentDefault { } } -impl CfuComponentInfo for CfuComponentDefault { +impl CfuComponentInfo for CfuComponentDefault { fn get_component_id(&self) -> ComponentId { self.device.component_id() } @@ -304,12 +304,12 @@ impl CfuComponentInfo for CfuComponentDefault { } } -impl CfuWriter for CfuComponentDefault { - async fn cfu_write(&self, mem_offset: Option, data: &[u8]) -> Result<(), CfuWriterError> { +impl CfuWriterAsync for CfuComponentDefault { + async fn cfu_write(&mut self, mem_offset: Option, data: &[u8]) -> Result<(), CfuWriterError> { self.writer.lock().await.cfu_write(mem_offset, data).await } async fn cfu_write_read( - &self, + &mut self, mem_offset: Option, data: &[u8], read: &mut [u8], @@ -317,12 +317,16 @@ impl CfuWriter for CfuComponentDefault { self.writer.lock().await.cfu_write_read(mem_offset, data, read).await } - async fn cfu_read(&self, mem_offset: Option, read: &mut [u8]) -> Result<(), CfuWriterError> { + async fn cfu_read(&mut self, mem_offset: Option, read: &mut [u8]) -> Result<(), CfuWriterError> { self.writer.lock().await.cfu_read(mem_offset, read).await } + + async fn cfu_storage(&mut self, mem_offset: usize, read: &[u8]) -> Result<(), CfuWriterError> { + self.writer.lock().await.cfu_storage(mem_offset, read).await + } } -impl CfuComponentStorage for CfuComponentDefault { +impl CfuComponentStorage for CfuComponentDefault { fn get_storage_offset(&self) -> usize { self.storage_offset } @@ -344,7 +348,7 @@ async fn default_get_fw_version() -> Result { Ok(FwVersion::default()) } -impl CfuComponentTraits for CfuComponentDefault {} +impl CfuComponentTraits for CfuComponentDefault {} /// Example Wrapper for CFU Component /// Takes type which implements `CFUComponentTraits` and `CfuDeviceContainer` diff --git a/examples/rt633/Cargo.lock b/examples/rt633/Cargo.lock index eaab3fc1..3ae963fc 100644 --- a/examples/rt633/Cargo.lock +++ b/examples/rt633/Cargo.lock @@ -65,10 +65,10 @@ dependencies = [ "embassy-futures", "embassy-sync", "embassy-time", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-batteries-async", "embedded-hal 1.0.0", "embedded-hal-async", - "embedded-services 0.1.0", + "embedded-services", ] [[package]] @@ -150,7 +150,7 @@ version = "0.1.0" source = "git+https://github.com/OpenDevicePartnership/bq25773#025db35ca05fe870cac4bfb7e4e5413ca9326eef" dependencies = [ "device-driver", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-batteries-async", "embedded-hal 1.0.0", "embedded-hal-async", ] @@ -162,7 +162,7 @@ source = "git+https://github.com/OpenDevicePartnership/bq40z50#9850c086fe1e3ef25 dependencies = [ "defmt 0.3.100", "device-driver", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-batteries-async", "embedded-hal 1.0.0", "embedded-hal-async", ] @@ -546,15 +546,6 @@ dependencies = [ "embedded-hal 1.0.0", ] -[[package]] -name = "embedded-batteries" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-batteries#410e2482d54b58c205a425c70d2ccf062e3ee3f3" -dependencies = [ - "bitfield-struct", - "embedded-hal 1.0.0", -] - [[package]] name = "embedded-batteries-async" version = "0.1.0" @@ -563,24 +554,14 @@ checksum = "02b35cd3052eaffa4d2914d07adda1b8631f9cb14300b62ce6b082b68ef926dd" dependencies = [ "bitfield-struct", "defmt 0.3.100", - "embedded-batteries 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 1.0.0", -] - -[[package]] -name = "embedded-batteries-async" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-batteries#410e2482d54b58c205a425c70d2ccf062e3ee3f3" -dependencies = [ - "bitfield-struct", - "embedded-batteries 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-batteries)", + "embedded-batteries", "embedded-hal 1.0.0", ] [[package]] name = "embedded-cfu-protocol" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#e2734a2bf953d584b11bbaa5931919345df9bf7c" +version = "0.2.0" +source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#a4cc8707842b878048447abbf2af4efa79fed368" dependencies = [ "defmt 0.3.100", "embedded-io-async", @@ -656,40 +637,7 @@ dependencies = [ "embassy-futures", "embassy-sync", "embassy-time", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-cfu-protocol", - "embedded-hal-async", - "embedded-hal-nb", - "embedded-io", - "embedded-io-async", - "embedded-storage", - "embedded-storage-async", - "embedded-usb-pd", - "fixed", - "heapless 0.8.0", - "postcard", - "rand_core", - "serde", -] - -[[package]] -name = "embedded-services" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-services#f63384357768f9301318bc40030b1058598f6bef" -dependencies = [ - "bitfield 0.17.0", - "bitflags 2.9.0", - "bitvec", - "cfg-if", - "cortex-m", - "cortex-m-rt", - "critical-section", - "document-features", - "embassy-executor", - "embassy-futures", - "embassy-sync", - "embassy-time", - "embedded-batteries-async 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-batteries)", + "embedded-batteries-async", "embedded-cfu-protocol", "embedded-hal-async", "embedded-hal-nb", @@ -750,7 +698,7 @@ dependencies = [ "embassy-imxrt", "embassy-sync", "embassy-time", - "embedded-services 0.1.0", + "embedded-services", ] [[package]] @@ -1148,9 +1096,9 @@ dependencies = [ "embassy-imxrt", "embassy-sync", "embassy-time", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "embedded-batteries-async", "embedded-hal-async", - "embedded-services 0.1.0", + "embedded-services", "espi-service", "futures", "mimxrt600-fcb", @@ -1256,7 +1204,7 @@ dependencies = [ "embassy-executor", "embassy-sync", "embassy-time", - "embedded-services 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-services)", + "embedded-services", ] [[package]] diff --git a/examples/rt633/Cargo.toml b/examples/rt633/Cargo.toml index 264bcb79..de87dd8f 100644 --- a/examples/rt633/Cargo.toml +++ b/examples/rt633/Cargo.toml @@ -54,3 +54,7 @@ bq40z50 = { git = "https://github.com/OpenDevicePartnership/bq40z50", features = ] } static_cell = "2.1.0" embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", default-features = false } + +# Needed otherwise cargo will pull from git +[patch."https://github.com/OpenDevicePartnership/embedded-services"] +embedded-services = { path = "../../embedded-service" } diff --git a/examples/rt633/src/bin/espi_battery.rs b/examples/rt633/src/bin/espi_battery.rs index 7cbc6d63..6854569c 100644 --- a/examples/rt633/src/bin/espi_battery.rs +++ b/examples/rt633/src/bin/espi_battery.rs @@ -217,7 +217,7 @@ async fn battery_publish_task(fg_device: &'static Device) { loop { Timer::after_secs(1).await; // Get dynamic cache - let cache = fg_device.get_dynamic_battery_cache(); + let cache = fg_device.get_dynamic_battery_cache().await; // Send cache data to eSpi service battery_service::comms_send( diff --git a/examples/rt685s-evk/Cargo.lock b/examples/rt685s-evk/Cargo.lock index 5a60d62c..1fa5ac3a 100644 --- a/examples/rt685s-evk/Cargo.lock +++ b/examples/rt685s-evk/Cargo.lock @@ -542,15 +542,6 @@ dependencies = [ "embedded-hal 1.0.0", ] -[[package]] -name = "embedded-batteries" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-batteries#410e2482d54b58c205a425c70d2ccf062e3ee3f3" -dependencies = [ - "bitfield-struct", - "embedded-hal 1.0.0", -] - [[package]] name = "embedded-batteries-async" version = "0.1.0" @@ -558,24 +549,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02b35cd3052eaffa4d2914d07adda1b8631f9cb14300b62ce6b082b68ef926dd" dependencies = [ "bitfield-struct", - "embedded-batteries 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-hal 1.0.0", -] - -[[package]] -name = "embedded-batteries-async" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-batteries#410e2482d54b58c205a425c70d2ccf062e3ee3f3" -dependencies = [ - "bitfield-struct", - "embedded-batteries 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-batteries)", + "embedded-batteries", "embedded-hal 1.0.0", ] [[package]] name = "embedded-cfu-protocol" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#e2734a2bf953d584b11bbaa5931919345df9bf7c" +version = "0.2.0" +source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#a4cc8707842b878048447abbf2af4efa79fed368" dependencies = [ "defmt 0.3.100", "embedded-io-async", @@ -651,40 +632,7 @@ dependencies = [ "embassy-futures", "embassy-sync", "embassy-time", - "embedded-batteries-async 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "embedded-cfu-protocol", - "embedded-hal-async", - "embedded-hal-nb", - "embedded-io", - "embedded-io-async", - "embedded-storage", - "embedded-storage-async", - "embedded-usb-pd", - "fixed", - "heapless 0.8.0", - "postcard", - "rand_core", - "serde", -] - -[[package]] -name = "embedded-services" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-services#f63384357768f9301318bc40030b1058598f6bef" -dependencies = [ - "bitfield 0.17.0", - "bitflags 2.9.0", - "bitvec", - "cfg-if", - "cortex-m", - "cortex-m-rt", - "critical-section", - "document-features", - "embassy-executor", - "embassy-futures", - "embassy-sync", - "embassy-time", - "embedded-batteries-async 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-batteries)", + "embedded-batteries-async", "embedded-cfu-protocol", "embedded-hal-async", "embedded-hal-nb", @@ -1055,7 +1003,7 @@ dependencies = [ "embassy-sync", "embassy-time", "embedded-cfu-protocol", - "embedded-services 0.1.0", + "embedded-services", "heapless 0.8.0", ] @@ -1095,7 +1043,7 @@ dependencies = [ "embassy-futures", "embassy-sync", "embassy-time", - "embedded-services 0.1.0", + "embedded-services", ] [[package]] @@ -1168,7 +1116,7 @@ dependencies = [ "embedded-cfu-protocol", "embedded-hal 1.0.0", "embedded-hal-async", - "embedded-services 0.1.0", + "embedded-services", "embedded-usb-pd", "futures", "mimxrt600-fcb 0.1.0", @@ -1279,7 +1227,7 @@ dependencies = [ "embassy-executor", "embassy-sync", "embassy-time", - "embedded-services 0.1.0 (git+https://github.com/OpenDevicePartnership/embedded-services)", + "embedded-services", ] [[package]] @@ -1356,7 +1304,7 @@ dependencies = [ "embedded-hal 1.0.0", "embedded-hal-async", "embedded-io-async", - "embedded-services 0.1.0", + "embedded-services", "embedded-usb-pd", "tps6699x", ] diff --git a/examples/rt685s-evk/Cargo.toml b/examples/rt685s-evk/Cargo.toml index 2eca9c32..126b58aa 100644 --- a/examples/rt685s-evk/Cargo.toml +++ b/examples/rt685s-evk/Cargo.toml @@ -72,3 +72,7 @@ platform-service = { path = "../../platform-service", features = [ "defmt", "imxrt685", ] } + +# Needed otherwise cargo will pull from git +[patch."https://github.com/OpenDevicePartnership/embedded-services"] +embedded-services = { path = "../../embedded-service" } diff --git a/examples/std/Cargo.lock b/examples/std/Cargo.lock index b0d6828c..29ba28c6 100644 --- a/examples/std/Cargo.lock +++ b/examples/std/Cargo.lock @@ -362,7 +362,7 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "embassy-executor" version = "0.7.0" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "critical-section", "document-features", @@ -373,7 +373,7 @@ dependencies = [ [[package]] name = "embassy-executor-macros" version = "0.6.2" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "darling", "proc-macro2", @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "embassy-futures" version = "0.1.1" -source = "git+https://github.com/embassy-rs/embassy#b024d5e892618947f81efd72f2c4224ae830d891" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "log", ] @@ -392,13 +392,13 @@ dependencies = [ [[package]] name = "embassy-sync" version = "0.7.0" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "cfg-if", "critical-section", "embedded-io-async", + "futures-core", "futures-sink", - "futures-util", "heapless 0.8.0", "log", ] @@ -406,7 +406,7 @@ dependencies = [ [[package]] name = "embassy-time" version = "0.4.0" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "cfg-if", "critical-section", @@ -416,14 +416,14 @@ dependencies = [ "embedded-hal 0.2.7", "embedded-hal 1.0.0", "embedded-hal-async", - "futures-util", + "futures-core", "log", ] [[package]] name = "embassy-time-driver" version = "0.2.0" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "document-features", ] @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "embassy-time-queue-utils" version = "0.1.0" -source = "git+https://github.com/embassy-rs/embassy#141c170db426404444a454c063c2eec07c74a1c3" +source = "git+https://github.com/embassy-rs/embassy#504261a8d0bc58fcfa8b73245eaf859f88d62a94" dependencies = [ "embassy-executor", "heapless 0.8.0", @@ -460,8 +460,8 @@ dependencies = [ [[package]] name = "embedded-cfu-protocol" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#e2734a2bf953d584b11bbaa5931919345df9bf7c" +version = "0.2.0" +source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#a4cc8707842b878048447abbf2af4efa79fed368" dependencies = [ "embedded-io-async", "log", @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "embedded-usb-pd" version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#b8948c96b8c8e920c837307d30653cfd74cf80cd" +source = "git+https://github.com/OpenDevicePartnership/embedded-usb-pd#99232ecdfdd9f5aa93b1dedbfc22f11c8d12632c" dependencies = [ "bitfield 0.19.1", "embedded-hal-async", @@ -656,24 +656,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "half" version = "2.6.0" @@ -891,18 +873,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "portable-atomic" version = "1.11.0" diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 86fe1b9e..b2c2ab58 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -54,3 +54,7 @@ path = "src/bin/type_c/service.rs" [[bin]] name = "type-c-external" path = "src/bin/type_c/external.rs" + +# Needed otherwise cargo will pull from git +[patch."https://github.com/OpenDevicePartnership/embedded-services"] +embedded-services = { path = "../../embedded-service" } diff --git a/examples/std/src/bin/battery.rs b/examples/std/src/bin/battery.rs index f3906754..1f20abf0 100644 --- a/examples/std/src/bin/battery.rs +++ b/examples/std/src/bin/battery.rs @@ -18,18 +18,17 @@ use static_cell::StaticCell; mod espi_service { use battery_service::context::{BatteryEvent, BatteryEventInner}; use battery_service::device::DeviceId; - use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::once_lock::OnceLock; use embassy_sync::signal::Signal; use embassy_time::Timer; use embedded_services::comms::{self, EndpointID, External}; use embedded_services::ec_type::message::BatteryMessage; - use embedded_services::error; + use embedded_services::{GlobalRawMutex, error}; use log::info; pub struct Service { endpoint: comms::Endpoint, - _signal: Signal, + _signal: Signal, } impl Service { diff --git a/examples/std/src/bin/cfu_buffer.rs b/examples/std/src/bin/cfu_buffer.rs index 3052bd1d..b2ce7f73 100644 --- a/examples/std/src/bin/cfu_buffer.rs +++ b/examples/std/src/bin/cfu_buffer.rs @@ -1,11 +1,14 @@ use embassy_executor::{Executor, Spawner}; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, once_lock::OnceLock}; +use embassy_sync::once_lock::OnceLock; use embassy_time::{Duration, Timer}; use log::*; use static_cell::StaticCell; use embedded_cfu_protocol::protocol_definitions::*; -use embedded_services::cfu::{self, component::InternalResponseData, route_request}; +use embedded_services::{ + GlobalRawMutex, + cfu::{self, component::InternalResponseData, route_request}, +}; use cfu_service::buffer; @@ -18,7 +21,7 @@ const CFU_BUFFER_ID: ComponentId = 0x06; const CFU_COMPONENT0_ID: ComponentId = 0x20; mod mock { - use std::cell::Cell; + use std::sync::atomic::AtomicBool; use embedded_services::cfu::component::{CfuDevice, CfuDeviceContainer, InternalResponseData}; @@ -28,7 +31,7 @@ mod mock { pub struct Device { cfu_device: CfuDevice, version: FwVersion, - init: Cell, + init: AtomicBool, } impl Device { @@ -37,7 +40,7 @@ mod mock { Self { cfu_device: CfuDevice::new(component_id), version, - init: Cell::new(false), + init: AtomicBool::new(false), } } @@ -71,7 +74,7 @@ mod mock { } } RequestData::GiveContent(content) => { - if self.init.get() { + if self.init.load(std::sync::atomic::Ordering::Acquire) { trace!("Got GiveContent: {content:#?}"); // If the device is already initialized, accept the content InternalResponseData::ContentResponse(FwUpdateContentResponse::new( @@ -80,7 +83,7 @@ mod mock { )) } else { // Take 500 ms to init the device - self.init.set(true); + self.init.store(true, std::sync::atomic::Ordering::Release); info!("Initializing device, taking 500 ms"); embassy_time::Timer::after_millis(500).await; info!("Device initialized"); @@ -154,15 +157,15 @@ async fn run(spawner: Spawner) { info!("Creating buffer"); static BUFFER: OnceLock> = OnceLock::new(); - static BUFFER_CHANNEL: OnceLock> = + static BUFFER_CHANNEL: OnceLock> = OnceLock::new(); let channel = BUFFER_CHANNEL.get_or_init(embassy_sync::channel::Channel::new); let buffer = BUFFER.get_or_init(|| { buffer::Buffer::new( CFU_BUFFER_ID, CFU_COMPONENT0_ID, - channel.dyn_sender(), - channel.dyn_receiver(), + From::from(channel.sender()), + From::from(channel.receiver()), buffer::Config::with_timeout(Duration::from_millis(75)), ) }); diff --git a/examples/std/src/bin/cfu_client.rs b/examples/std/src/bin/cfu_client.rs index 53792efe..ae7409cb 100644 --- a/examples/std/src/bin/cfu_client.rs +++ b/examples/std/src/bin/cfu_client.rs @@ -1,6 +1,6 @@ use embassy_executor::{Executor, Spawner}; use embassy_sync::once_lock::OnceLock; -use embedded_cfu_protocol::CfuWriterDefault; +use embedded_cfu_protocol::writer::CfuWriterNop; use log::*; use static_cell::StaticCell; @@ -13,7 +13,7 @@ use embedded_services::cfu::component::CfuComponentDefault; use crate::cfu::component::RequestData; #[embassy_executor::task] -async fn device_task0(component: &'static CfuComponentDefault) { +async fn device_task0(component: &'static CfuComponentDefault) { loop { if let Err(e) = component.process_request().await { error!("Error processing request: {e:?}"); @@ -22,7 +22,7 @@ async fn device_task0(component: &'static CfuComponentDefault) } #[embassy_executor::task] -async fn device_task1(component: &'static CfuComponentDefault) { +async fn device_task1(component: &'static CfuComponentDefault) { loop { if let Err(e) = component.process_request().await { error!("Error processing request: {e:?}"); @@ -35,17 +35,17 @@ async fn run(spawner: Spawner) { embedded_services::init().await; info!("Creating device 0"); - static DEVICE0: OnceLock> = OnceLock::new(); + static DEVICE0: OnceLock> = OnceLock::new(); let mut subs: [Option; MAX_SUBCMPT_COUNT] = [None; MAX_SUBCMPT_COUNT]; subs[0] = Some(2); - let device0 = DEVICE0.get_or_init(|| CfuComponentDefault::new(1, true, subs, CfuWriterDefault::new())); + let device0 = DEVICE0.get_or_init(|| CfuComponentDefault::new(1, true, subs, CfuWriterNop {})); cfu::register_device(device0).await.unwrap(); spawner.must_spawn(device_task0(device0)); info!("Creating device 1"); - static DEVICE1: OnceLock> = OnceLock::new(); + static DEVICE1: OnceLock> = OnceLock::new(); let device1 = - DEVICE1.get_or_init(|| CfuComponentDefault::new(2, false, [None; MAX_SUBCMPT_COUNT], CfuWriterDefault::new())); + DEVICE1.get_or_init(|| CfuComponentDefault::new(2, false, [None; MAX_SUBCMPT_COUNT], CfuWriterNop {})); cfu::register_device(device1).await.unwrap(); spawner.must_spawn(device_task1(device1)); diff --git a/examples/std/src/bin/type_c/service.rs b/examples/std/src/bin/type_c/service.rs index 81437cab..0bd31c12 100644 --- a/examples/std/src/bin/type_c/service.rs +++ b/examples/std/src/bin/type_c/service.rs @@ -4,11 +4,11 @@ use embassy_time::Timer; use embedded_cfu_protocol::protocol_definitions::{FwUpdateOfferResponse, HostToken}; use embedded_services::comms; use embedded_services::power::{self, policy}; -use embedded_services::type_c::{controller, ControllerId}; -use embedded_usb_pd::type_c::Current; +use embedded_services::type_c::{ControllerId, controller}; use embedded_usb_pd::Error; use embedded_usb_pd::GlobalPortId; use embedded_usb_pd::PortId as LocalPortId; +use embedded_usb_pd::type_c::Current; use log::*; use static_cell::StaticCell; @@ -19,30 +19,33 @@ const POWER0: power::policy::DeviceId = power::policy::DeviceId(0); mod test_controller { use std::cell::Cell; - use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; - use embedded_services::type_c::{ - controller::{Contract, ControllerStatus, PortStatus, RetimerFwUpdateState}, - event::PortEventKind, + use embassy_sync::{mutex::Mutex, signal::Signal}; + use embedded_services::{ + GlobalRawMutex, + type_c::{ + controller::{Contract, ControllerStatus, PortStatus, RetimerFwUpdateState}, + event::PortEventKind, + }, }; use super::*; pub struct ControllerState { - events: Signal, - status: Cell, + events: Signal, + status: Mutex, } impl ControllerState { pub fn new() -> Self { Self { events: Signal::new(), - status: Cell::new(PortStatus::default()), + status: Mutex::new(PortStatus::default()), } } /// Simulate a connection - pub fn connect(&self, _contract: Contract) { - self.status.set(PortStatus::new()); + pub async fn connect(&self, _contract: Contract) { + *self.status.lock().await = PortStatus::new(); let mut events = PortEventKind::none(); events.set_plug_inserted_or_removed(true); @@ -51,13 +54,13 @@ mod test_controller { } /// Simulate a sink connecting - pub fn connect_sink(&self, current: Current) { - self.connect(Contract::Sink(current.into())); + pub async fn connect_sink(&self, current: Current) { + self.connect(Contract::Sink(current.into())).await; } /// Simulate a disconnection - pub fn disconnect(&self) { - self.status.set(PortStatus::default()); + pub async fn disconnect(&self) { + *self.status.lock().await = PortStatus::default(); let mut events = PortEventKind::none(); events.set_plug_inserted_or_removed(true); @@ -65,8 +68,8 @@ mod test_controller { } /// Simulate a debug accessory source connecting - pub fn connect_debug_accessory_source(&self, _current: Current) { - self.status.set(PortStatus::new()); + pub async fn connect_debug_accessory_source(&self, _current: Current) { + *self.status.lock().await = PortStatus::new(); let mut events = PortEventKind::none(); events.set_plug_inserted_or_removed(true); @@ -112,8 +115,8 @@ mod test_controller { } async fn get_port_status(&mut self, _port: LocalPortId) -> Result> { - debug!("Get port status: {:#?}", self.state.status.get()); - Ok(self.state.status.get()) + debug!("Get port status: {:#?}", *self.state.status.lock().await); + Ok(*self.state.status.lock().await) } async fn enable_sink_path(&mut self, _port: LocalPortId, enable: bool) -> Result<(), Error> { @@ -267,19 +270,19 @@ async fn task(spawner: Spawner) { Timer::after_secs(1).await; info!("Simulating connection"); - state.connect_sink(Current::UsbDefault); + state.connect_sink(Current::UsbDefault).await; Timer::after_millis(250).await; info!("Simulating disconnection"); - state.disconnect(); + state.disconnect().await; Timer::after_millis(250).await; info!("Simulating debug accessory connection"); - state.connect_debug_accessory_source(Current::UsbDefault); + state.connect_debug_accessory_source(Current::UsbDefault).await; Timer::after_millis(250).await; info!("Simulating debug accessory disconnection"); - state.disconnect(); + state.disconnect().await; Timer::after_millis(250).await; }