@@ -8,6 +8,7 @@ use embassy_imxrt::gpio::{Input, Inverter, Pull};
88use embassy_imxrt:: i2c:: Async ;
99use embassy_imxrt:: i2c:: master:: { Config , I2cMaster } ;
1010use embassy_imxrt:: { bind_interrupts, peripherals} ;
11+ use embassy_sync:: channel:: { Channel , DynamicReceiver , DynamicSender } ;
1112use embassy_sync:: mutex:: Mutex ;
1213use embassy_sync:: pubsub:: PubSubChannel ;
1314use embassy_time:: Timer ;
@@ -16,18 +17,20 @@ use embedded_cfu_protocol::protocol_definitions::*;
1617use embedded_cfu_protocol:: protocol_definitions:: { FwUpdateOffer , FwUpdateOfferResponse , FwVersion } ;
1718use embedded_services:: cfu:: component:: InternalResponseData ;
1819use embedded_services:: cfu:: component:: RequestData ;
19- use embedded_services:: power:: policy:: { CommsMessage , DeviceId as PowerId } ;
20+ use embedded_services:: power:: policy:: { CommsMessage , DeviceId as PowerId , policy } ;
2021use embedded_services:: type_c:: ControllerId ;
2122use embedded_services:: type_c:: controller:: Context ;
2223use embedded_services:: { GlobalRawMutex , IntrusiveList , cfu} ;
2324use embedded_services:: { error, info} ;
2425use embedded_usb_pd:: GlobalPortId ;
26+ use power_policy_service:: PowerPolicy ;
2527use static_cell:: StaticCell ;
2628use tps6699x:: asynchronous:: embassy as tps6699x;
2729use type_c_service:: driver:: tps6699x:: { self as tps6699x_drv} ;
2830use type_c_service:: service:: Service ;
2931use type_c_service:: wrapper:: ControllerWrapper ;
30- use type_c_service:: wrapper:: backing:: { ReferencedStorage , Storage } ;
32+ use type_c_service:: wrapper:: backing:: { IntermediateStorage , ReferencedStorage , Storage } ;
33+ use type_c_service:: wrapper:: proxy:: PowerProxyDevice ;
3134
3235extern crate rt685s_evk_example;
3336
@@ -47,7 +50,14 @@ impl type_c_service::wrapper::FwOfferValidator for Validator {
4750type BusMaster < ' a > = I2cMaster < ' a , Async > ;
4851type BusDevice < ' a > = I2cDevice < ' a , GlobalRawMutex , BusMaster < ' a > > ;
4952type Tps6699xMutex < ' a > = Mutex < GlobalRawMutex , tps6699x_drv:: Tps6699x < ' a , GlobalRawMutex , BusDevice < ' a > > > ;
50- type Wrapper < ' a > = ControllerWrapper < ' a , GlobalRawMutex , Tps6699xMutex < ' a > , Validator > ;
53+ type Wrapper < ' a > = ControllerWrapper <
54+ ' a ,
55+ GlobalRawMutex ,
56+ Tps6699xMutex < ' a > ,
57+ DynamicSender < ' a , policy:: RequestData > ,
58+ DynamicReceiver < ' a , policy:: RequestData > ,
59+ Validator ,
60+ > ;
5161type Controller < ' a > = tps6699x:: controller:: Controller < GlobalRawMutex , BusDevice < ' a > > ;
5262type Interrupt < ' a > = tps6699x:: Interrupt < ' a , GlobalRawMutex , BusDevice < ' a > > ;
5363
@@ -155,7 +165,15 @@ async fn fw_update_task() {
155165
156166#[ embassy_executor:: task]
157167async fn power_policy_service_task ( ) {
158- power_policy_service:: task:: task ( Default :: default ( ) )
168+ static POWER_POLICY : static_cell:: StaticCell <
169+ PowerPolicy < Mutex < GlobalRawMutex , PowerProxyDevice < ' static > > , DynamicReceiver < ' static , policy:: RequestData > > ,
170+ > = static_cell:: StaticCell :: new ( ) ;
171+ let power_policy =
172+ POWER_POLICY . init ( PowerPolicy :: create ( Default :: default ( ) ) . expect ( "Failed to create power policy" ) ) ;
173+
174+ // TODO: remove once power policy task accepts context
175+ Timer :: after_millis ( 100 ) . await ;
176+ power_policy_service:: task:: task ( power_policy)
159177 . await
160178 . expect ( "Failed to start power policy service task" ) ;
161179}
@@ -242,14 +260,41 @@ async fn main(spawner: Spawner) {
242260 let storage = STORAGE . init ( Storage :: new (
243261 controller_context,
244262 CONTROLLER0_ID ,
245- CONTROLLER0_CFU_ID ,
246- [ ( PORT0_ID , PORT0_PWR_ID ) , ( PORT1_ID , PORT1_PWR_ID ) ] ,
263+ 0 , // CFU component ID
264+ [ PORT0_ID , PORT1_ID ] ,
247265 ) ) ;
248266
249- static REFERENCED : StaticCell < ReferencedStorage < TPS66994_NUM_PORTS , GlobalRawMutex > > = StaticCell :: new ( ) ;
250- let referenced = REFERENCED . init (
267+ static INTERMEDIATE : StaticCell < IntermediateStorage < TPS66994_NUM_PORTS , GlobalRawMutex > > = StaticCell :: new ( ) ;
268+ let intermediate = INTERMEDIATE . init (
251269 storage
252- . create_referenced ( )
270+ . try_create_intermediate ( )
271+ . expect ( "Failed to create intermediate storage" ) ,
272+ ) ;
273+
274+ static POLICY_CHANNEL0 : StaticCell < Channel < GlobalRawMutex , policy:: RequestData , 1 > > = StaticCell :: new ( ) ;
275+ let policy_channel0 = POLICY_CHANNEL0 . init ( Channel :: new ( ) ) ;
276+ let policy_sender0 = policy_channel0. dyn_sender ( ) ;
277+ let policy_receiver0 = policy_channel0. dyn_receiver ( ) ;
278+
279+ static POLICY_CHANNEL1 : StaticCell < Channel < GlobalRawMutex , policy:: RequestData , 1 > > = StaticCell :: new ( ) ;
280+ let policy_channel1 = POLICY_CHANNEL1 . init ( Channel :: new ( ) ) ;
281+ let policy_sender1 = policy_channel1. dyn_sender ( ) ;
282+ let policy_receiver1 = policy_channel1. dyn_receiver ( ) ;
283+
284+ static REFERENCED : StaticCell <
285+ ReferencedStorage <
286+ TPS66994_NUM_PORTS ,
287+ GlobalRawMutex ,
288+ DynamicSender < ' _ , policy:: RequestData > ,
289+ DynamicReceiver < ' _ , policy:: RequestData > ,
290+ > ,
291+ > = StaticCell :: new ( ) ;
292+ let referenced = REFERENCED . init (
293+ intermediate
294+ . try_create_referenced ( [
295+ ( PORT0_PWR_ID , policy_sender0, policy_receiver0) ,
296+ ( PORT1_PWR_ID , policy_sender1, policy_receiver1) ,
297+ ] )
253298 . expect ( "Failed to create referenced storage" ) ,
254299 ) ;
255300
0 commit comments