Skip to content
Open
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/rt685s-evk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion examples/rt685s-evk/src/bin/type_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use power_policy_service::service::registration::ArrayRegistration;
use static_cell::StaticCell;
use tps6699x::asynchronous::embassy as tps6699x;
use type_c_interface::port::ControllerId;
use type_c_interface::port::PortRegistration;
use type_c_interface::service::event::PortEvent as ServicePortEvent;
use type_c_service::driver::tps6699x::{self as tps6699x_drv};
use type_c_service::service::{EventReceiver, Service};
use type_c_service::wrapper::ControllerWrapper;
Expand All @@ -33,6 +35,8 @@ use type_c_service::wrapper::proxy::PowerProxyDevice;

extern crate rt685s_evk_example;

const CHANNEL_CAPACITY: usize = 4;

const NUM_PD_CONTROLLERS: usize = 1;
const CONTROLLER0_ID: ControllerId = ControllerId(0);
const PORT0_ID: GlobalPortId = GlobalPortId(0);
Expand Down Expand Up @@ -163,12 +167,25 @@ async fn main(spawner: Spawner) {
static CONTROLLER_CONTEXT: StaticCell<type_c_interface::service::context::Context> = StaticCell::new();
let controller_context = CONTROLLER_CONTEXT.init(type_c_interface::service::context::Context::new());

static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static PORT1_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE: StaticCell<Storage<TPS66994_NUM_PORTS, GlobalRawMutex>> = StaticCell::new();
let storage = STORAGE.init(Storage::new(
controller_context,
CONTROLLER0_ID,
0, // CFU component ID
[PORT0_ID, PORT1_ID],
[
PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
},
PortRegistration {
id: PORT1_ID,
sender: Mutex::new(PORT1_CHANNEL.dyn_sender()),
receiver: PORT1_CHANNEL.dyn_receiver(),
},
],
));

static POLICY_CHANNEL0: StaticCell<Channel<GlobalRawMutex, psu::event::EventData, 2>> = StaticCell::new();
Expand Down
21 changes: 19 additions & 2 deletions examples/rt685s-evk/src/bin/type_c_cfu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use power_policy_service::service::registration::ArrayRegistration;
use static_cell::StaticCell;
use tps6699x::asynchronous::embassy as tps6699x;
use type_c_interface::port::ControllerId;
use type_c_interface::port::PortRegistration;
use type_c_interface::service::event::PortEvent as ServicePortEvent;
use type_c_service::driver::tps6699x::{self as tps6699x_drv};
use type_c_service::service::{EventReceiver, Service};
use type_c_service::wrapper::ControllerWrapper;
Expand All @@ -36,6 +38,8 @@ use type_c_service::wrapper::proxy::PowerProxyDevice;

extern crate rt685s_evk_example;

const CHANNEL_CAPACITY: usize = 4;

bind_interrupts!(struct Irqs {
FLEXCOMM2 => embassy_imxrt::i2c::InterruptHandler<peripherals::FLEXCOMM2>;
});
Expand Down Expand Up @@ -247,12 +251,25 @@ async fn main(spawner: Spawner) {
static CONTROLLER_CONTEXT: StaticCell<type_c_interface::service::context::Context> = StaticCell::new();
let controller_context = CONTROLLER_CONTEXT.init(type_c_interface::service::context::Context::new());

static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static PORT1_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE: StaticCell<Storage<TPS66994_NUM_PORTS, GlobalRawMutex>> = StaticCell::new();
let storage = STORAGE.init(Storage::new(
controller_context,
CONTROLLER0_ID,
CONTROLLER0_CFU_ID,
[PORT0_ID, PORT1_ID],
0, // CFU component ID
[
PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
},
PortRegistration {
id: PORT1_ID,
sender: Mutex::new(PORT1_CHANNEL.dyn_sender()),
receiver: PORT1_CHANNEL.dyn_receiver(),
},
],
));

static POLICY_CHANNEL0: StaticCell<Channel<GlobalRawMutex, psu::event::EventData, 1>> = StaticCell::new();
Expand Down
1 change: 0 additions & 1 deletion examples/std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 29 additions & 31 deletions examples/std/src/bin/type_c/basic.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use embassy_executor::{Executor, Spawner};
use embassy_sync::once_lock::OnceLock;
use embassy_sync::channel::Channel;
use embassy_sync::mutex::Mutex;
use embassy_time::Timer;
use embedded_services::GlobalRawMutex;
use embedded_usb_pd::ucsi::lpm;
use embedded_usb_pd::{GlobalPortId, PdError as Error};
use log::*;
use static_cell::StaticCell;
use type_c_interface::port::{self, Cached, ControllerId};
use type_c_interface::port::{self, ControllerId, PortRegistration};
use type_c_interface::service::context::{Context, DeviceContainer};
use type_c_interface::service::event::PortEvent as ServicePortEvent;

const CONTROLLER0_ID: ControllerId = ControllerId(0);
const PORT0_ID: GlobalPortId = GlobalPortId(0);
const PORT1_ID: GlobalPortId = GlobalPortId(1);
const CHANNEL_CAPACITY: usize = 4;

mod test_controller {
use embedded_usb_pd::ucsi;
use type_c_interface::port::{ControllerStatus, PortStatus};
use type_c_interface::port::{ControllerStatus, PortRegistration};

use super::*;

Expand All @@ -29,7 +33,7 @@ mod test_controller {
}

impl<'a> Controller<'a> {
pub fn new(id: ControllerId, ports: &'a [GlobalPortId]) -> Self {
pub fn new(id: ControllerId, ports: &'a [PortRegistration]) -> Self {
Self {
controller: port::Device::new(id, ports),
}
Expand Down Expand Up @@ -80,16 +84,8 @@ mod test_controller {
}

async fn process_port_command(&self, command: port::PortCommand) -> Result<port::PortResponseData, Error> {
Ok(match command.data {
port::PortCommandData::PortStatus(Cached(true)) => {
info!("Port status for port {}", command.port.0);
port::PortResponseData::PortStatus(PortStatus::new())
}
_ => {
info!("Port command for port {}", command.port.0);
port::PortResponseData::Complete
}
})
info!("Port command for port {}", command.port.0);
Ok(port::PortResponseData::Complete)
}

pub async fn process(&self) {
Expand All @@ -109,11 +105,25 @@ mod test_controller {

#[embassy_executor::task]
async fn controller_task(controller_context: &'static Context) {
static CONTROLLER: OnceLock<test_controller::Controller> = OnceLock::new();

static PORTS: [GlobalPortId; 2] = [PORT0_ID, PORT1_ID];

let controller = CONTROLLER.get_or_init(|| test_controller::Controller::new(CONTROLLER0_ID, &PORTS));
static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static PORT1_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();

static PORTS: StaticCell<[PortRegistration; 2]> = StaticCell::new();
let ports = PORTS.init([
PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
},
PortRegistration {
id: PORT1_ID,
sender: Mutex::new(PORT1_CHANNEL.dyn_sender()),
receiver: PORT1_CHANNEL.dyn_receiver(),
},
]);

static CONTROLLER: StaticCell<test_controller::Controller> = StaticCell::new();
let controller = CONTROLLER.init(test_controller::Controller::new(CONTROLLER0_ID, ports.as_slice()));
controller_context.register_controller(controller).unwrap();

loop {
Expand All @@ -137,18 +147,6 @@ async fn task(spawner: Spawner) {

let status = controller_context.get_controller_status(CONTROLLER0_ID).await.unwrap();
info!("Controller 0 status: {status:#?}");

let status = controller_context
.get_port_status(PORT0_ID, Cached(true))
.await
.unwrap();
info!("Port 0 status: {status:#?}");

let status = controller_context
.get_port_status(PORT1_ID, Cached(true))
.await
.unwrap();
info!("Port 1 status: {status:#?}");
}

fn main() {
Expand Down
12 changes: 10 additions & 2 deletions examples/std/src/bin/type_c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use power_policy_service::service::registration::ArrayRegistration;
use static_cell::StaticCell;
use std_examples::type_c::mock_controller;
use std_examples::type_c::mock_controller::Wrapper;
use type_c_interface::port::ControllerId;
use type_c_interface::port::{ControllerId, PortRegistration};
use type_c_interface::service::context::Context;
use type_c_interface::service::event::PortEvent as ServicePortEvent;
use type_c_service::service::config::Config;
use type_c_service::service::{EventReceiver, Service};
use type_c_service::util::power_capability_from_current;
Expand All @@ -27,6 +28,7 @@ use type_c_service::wrapper::message::*;
use type_c_service::wrapper::proxy::PowerProxyDevice;

const NUM_PD_CONTROLLERS: usize = 1;
const CHANNEL_CAPACITY: usize = 4;
const CONTROLLER0_ID: ControllerId = ControllerId(0);
const PORT0_ID: GlobalPortId = GlobalPortId(0);
const DELAY_MS: u64 = 1000;
Expand Down Expand Up @@ -193,12 +195,18 @@ fn create_wrapper(
static STATE: StaticCell<mock_controller::ControllerState> = StaticCell::new();
let state = STATE.init(mock_controller::ControllerState::new());

static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();

static STORAGE: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage = STORAGE.init(Storage::new(
context,
CONTROLLER0_ID,
0, // CFU component ID (unused)
[PORT0_ID],
[PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
}],
));

static POLICY_CHANNEL: StaticCell<Channel<GlobalRawMutex, power_policy_interface::psu::event::EventData, 1>> =
Expand Down
28 changes: 25 additions & 3 deletions examples/std/src/bin/type_c/ucsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ use power_policy_service::psu::ArrayEventReceivers;
use power_policy_service::service::registration::ArrayRegistration;
use static_cell::StaticCell;
use std_examples::type_c::mock_controller;
use type_c_interface::port::ControllerId;
use type_c_interface::port::{ControllerId, PortRegistration};
use type_c_interface::service::context::Context;
use type_c_interface::service::event::PortEvent as ServicePortEvent;
use type_c_service::service::config::Config;
use type_c_service::service::{EventReceiver, Service};
use type_c_service::wrapper::backing::Storage;
use type_c_service::wrapper::proxy::PowerProxyDevice;

const CHANNEL_CAPACITY: usize = 4;
const NUM_PD_CONTROLLERS: usize = 2;
const CONTROLLER0_ID: ControllerId = ControllerId(0);
const CONTROLLER1_ID: ControllerId = ControllerId(1);
Expand Down Expand Up @@ -229,8 +231,18 @@ async fn task(spawner: Spawner) {
static CONTROLLER_CONTEXT: StaticCell<Context> = StaticCell::new();
let controller_context = CONTROLLER_CONTEXT.init(Context::new());

static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE0: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage0 = STORAGE0.init(Storage::new(controller_context, CONTROLLER0_ID, CFU0_ID, [PORT0_ID]));
let storage0 = STORAGE0.init(Storage::new(
controller_context,
CONTROLLER0_ID,
CFU0_ID,
[PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
}],
));

static POLICY_CHANNEL0: StaticCell<Channel<GlobalRawMutex, psu::event::EventData, 2>> = StaticCell::new();
let policy_channel0 = POLICY_CHANNEL0.init(Channel::new());
Expand Down Expand Up @@ -280,8 +292,18 @@ async fn task(spawner: Spawner) {
let policy_sender1 = policy_channel1.dyn_sender();
let policy_receiver1 = policy_channel1.dyn_receiver();

static PORT1_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE1: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage1 = STORAGE1.init(Storage::new(controller_context, CONTROLLER1_ID, CFU1_ID, [PORT1_ID]));
let storage1 = STORAGE1.init(Storage::new(
controller_context,
CONTROLLER1_ID,
CFU1_ID,
[PortRegistration {
id: PORT1_ID,
sender: Mutex::new(PORT1_CHANNEL.dyn_sender()),
receiver: PORT1_CHANNEL.dyn_receiver(),
}],
));
static INTERMEDIATE1: StaticCell<
type_c_service::wrapper::backing::IntermediateStorage<
1,
Expand Down
40 changes: 37 additions & 3 deletions examples/std/src/bin/type_c/unconstrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ use power_policy_service::service::registration::ArrayRegistration;
use static_cell::StaticCell;
use std_examples::type_c::mock_controller;
use type_c_interface::port::ControllerId;
use type_c_interface::port::PortRegistration;
use type_c_interface::service::event::PortEvent as ServicePortEvent;
use type_c_service::service::{EventReceiver, Service};
use type_c_service::wrapper::backing::{IntermediateStorage, ReferencedStorage, Storage};
use type_c_service::wrapper::proxy::PowerProxyDevice;

const CHANNEL_CAPACITY: usize = 4;

const NUM_PD_CONTROLLERS: usize = 3;

const CONTROLLER0_ID: ControllerId = ControllerId(0);
Expand Down Expand Up @@ -87,8 +91,18 @@ async fn task(spawner: Spawner) {
let policy_sender0 = policy_channel0.dyn_sender();
let policy_receiver0 = policy_channel0.dyn_receiver();

static PORT0_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE0: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage0 = STORAGE0.init(Storage::new(controller_context, CONTROLLER0_ID, CFU0_ID, [PORT0_ID]));
let storage0 = STORAGE0.init(Storage::new(
controller_context,
CONTROLLER0_ID,
CFU0_ID,
[PortRegistration {
id: PORT0_ID,
sender: Mutex::new(PORT0_CHANNEL.dyn_sender()),
receiver: PORT0_CHANNEL.dyn_receiver(),
}],
));
static INTERMEDIATE0: StaticCell<
IntermediateStorage<1, GlobalRawMutex, DynamicSender<'static, psu::event::EventData>>,
> = StaticCell::new();
Expand Down Expand Up @@ -123,8 +137,18 @@ async fn task(spawner: Spawner) {
let policy_sender1 = policy_channel1.dyn_sender();
let policy_receiver1 = policy_channel1.dyn_receiver();

static PORT1_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE1: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage1 = STORAGE1.init(Storage::new(controller_context, CONTROLLER1_ID, CFU1_ID, [PORT1_ID]));
let storage1 = STORAGE1.init(Storage::new(
controller_context,
CONTROLLER1_ID,
CFU1_ID,
[PortRegistration {
id: PORT1_ID,
sender: Mutex::new(PORT1_CHANNEL.dyn_sender()),
receiver: PORT1_CHANNEL.dyn_receiver(),
}],
));
static INTERMEDIATE1: StaticCell<
IntermediateStorage<1, GlobalRawMutex, DynamicSender<'static, psu::event::EventData>>,
> = StaticCell::new();
Expand Down Expand Up @@ -159,8 +183,18 @@ async fn task(spawner: Spawner) {
let policy_sender2 = policy_channel2.dyn_sender();
let policy_receiver2 = policy_channel2.dyn_receiver();

static PORT2_CHANNEL: Channel<GlobalRawMutex, ServicePortEvent, CHANNEL_CAPACITY> = Channel::new();
static STORAGE2: StaticCell<Storage<1, GlobalRawMutex>> = StaticCell::new();
let storage2 = STORAGE2.init(Storage::new(controller_context, CONTROLLER2_ID, CFU2_ID, [PORT2_ID]));
let storage2 = STORAGE2.init(Storage::new(
controller_context,
CONTROLLER2_ID,
CFU2_ID,
[PortRegistration {
id: PORT2_ID,
sender: Mutex::new(PORT2_CHANNEL.dyn_sender()),
receiver: PORT2_CHANNEL.dyn_receiver(),
}],
));
static INTERMEDIATE2: StaticCell<
IntermediateStorage<1, GlobalRawMutex, DynamicSender<'static, psu::event::EventData>>,
> = StaticCell::new();
Expand Down
Loading
Loading