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
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ concurrency:
name: check
env:
# Crates that require std and won't build on embedded-targets
STD_CRATES: "fw-update-interface-mocks"
STD_EXCLUDED_CRATES: "--exclude fw-update-interface-mocks --exclude type-c-interface-mocks"
jobs:

fmt:
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
run: cargo hack $COMMON_HACK_ARGS clippy --locked --target ${{ matrix.target }}
- name: cargo hack
if: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }}
run: cargo hack $COMMON_HACK_ARGS clippy --exclude $STD_CRATES --locked --target ${{ matrix.target }}
run: cargo hack $COMMON_HACK_ARGS clippy $STD_EXCLUDED_CRATES --locked --target ${{ matrix.target }}

deny:
# cargo-deny checks licenses, advisories, sources, and bans for
Expand Down Expand Up @@ -219,8 +219,8 @@ jobs:
- name: cargo +${{ matrix.msrv }} check
if: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }}
run: |
cargo check -F log --locked --workspace --exclude $STD_CRATES --target ${{ matrix.target }}
cargo check -F defmt --locked --workspace --exclude $STD_CRATES --target ${{ matrix.target }}
cargo check -F log --locked --workspace $STD_EXCLUDED_CRATES --target ${{ matrix.target }}
cargo check -F defmt --locked --workspace $STD_EXCLUDED_CRATES --target ${{ matrix.target }}

check-arm-examples:
runs-on: ubuntu-latest
Expand Down
16 changes: 15 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"fw-update-interface",
"fw-update-interface-mocks",
"mctp-rs",
"type-c-interface-mocks",
]
exclude = ["examples/*"]

Expand Down Expand Up @@ -114,6 +115,7 @@ thermal-service-relay = { path = "./thermal-service-relay" }
time-alarm-service-interface = { path = "./time-alarm-service-interface" }
time-alarm-service-relay = { path = "./time-alarm-service-relay" }
type-c-interface = { path = "./type-c-interface" }
type-c-interface-mocks = { path = "./type-c-interface-mocks" }
syn = "2.0"
tps6699x = { git = "https://github.com/OpenDevicePartnership/tps6699x", branch = "v0.2.0" }
tokio = { version = "1.42.0" }
Expand Down
2 changes: 1 addition & 1 deletion examples/rt685s-evk/Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/rt685s-evk/src/bin/type_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async fn main(spawner: Spawner) {
)));

static TYPE_C_SERVICE: StaticCell<Mutex<GlobalRawMutex, TypeCServiceType>> = StaticCell::new();
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::create(
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::new(
Default::default(),
TypeCRegistrationType {
ports: [port0, port1],
Expand Down
2 changes: 1 addition & 1 deletion examples/rt685s-evk/src/bin/type_c_cfu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ async fn main(spawner: Spawner) {
)));

static TYPE_C_SERVICE: StaticCell<Mutex<GlobalRawMutex, TypeCServiceType>> = StaticCell::new();
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::create(
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::new(
Default::default(),
TypeCRegistrationType {
ports: [port0, port1],
Expand Down
8 changes: 4 additions & 4 deletions examples/std/Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/std/src/bin/type_c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async fn task(spawner: Spawner) {
)));

static TYPE_C_SERVICE: StaticCell<Mutex<GlobalRawMutex, ServiceType>> = StaticCell::new();
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::create(
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::new(
Config::default(),
type_c_service::service::registration::ArrayRegistration {
ports: [port],
Expand Down
2 changes: 1 addition & 1 deletion examples/std/src/bin/type_c/ucsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ async fn task(spawner: Spawner) {

// Create type-c service
static TYPE_C_SERVICE: StaticCell<Mutex<GlobalRawMutex, TypeCServiceType>> = StaticCell::new();
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::create(
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::new(
Config {
ucsi_capabilities: UcsiCapabilities {
num_connectors: 2,
Expand Down
2 changes: 1 addition & 1 deletion examples/std/src/bin/type_c/unconstrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async fn task(spawner: Spawner) {

// Create type-c service
static TYPE_C_SERVICE: StaticCell<Mutex<GlobalRawMutex, TypeCServiceType>> = StaticCell::new();
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::create(
let type_c_service = TYPE_C_SERVICE.init(Mutex::new(Service::new(
Default::default(),
TypeCRegistrationType {
ports: [port0, port1, port2],
Expand Down
15 changes: 15 additions & 0 deletions type-c-interface-mocks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "type-c-interface-mocks"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
embedded-services = { workspace = true }
embedded-usb-pd = { workspace = true }
type-c-interface = { workspace = true }

[lints]
workspace = true
85 changes: 85 additions & 0 deletions type-c-interface-mocks/src/controller/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Mock controller implementations for testing

use std::collections::VecDeque;

use embedded_services::named::Named;
use embedded_usb_pd::{PdError, ado::Ado};
use type_c_interface::control::{
dp::DpStatus,
pd::PortStatus,
vdm::{AttnVdm, OtherVdm},
};

pub mod pd;
pub mod ucsi;

/// Contains a controller function call and its arguments
pub enum FnCall {
Pd(pd::FnCall),
Ucsi(ucsi::FnCall),
}

/// Mock PD controller for use in tests
pub struct Mock {
name: &'static str,
/// Recorded function calls
pub fn_calls: VecDeque<FnCall>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::get_port_status`]
pub next_result_get_port_status: VecDeque<Result<PortStatus, PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::clear_dead_battery_flag`]
pub next_result_clear_dead_battery_flag: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::enable_sink_path`]
pub next_result_enable_sink_path: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::get_pd_alert`]
pub next_result_get_pd_alert: VecDeque<Result<Option<Ado>, PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::set_unconstrained_power`]
pub next_result_set_unconstrained_power: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::get_other_vdm`]
pub next_result_get_other_vdm: VecDeque<Result<OtherVdm, PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::get_attn_vdm`]
pub next_result_get_attn_vdm: VecDeque<Result<AttnVdm, PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::send_vdm`]
pub next_result_send_vdm: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::execute_drst`]
pub next_result_execute_drst: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::get_dp_status`]
pub next_result_get_dp_status: VecDeque<Result<DpStatus, PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::set_dp_config`]
pub next_result_set_dp_config: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::set_tbt_config`]
pub next_result_set_tbt_config: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::controller::pd::Pd::set_usb_control`]
pub next_result_set_usb_control: VecDeque<Result<(), PdError>>,
/// Next results to return for [`type_c_interface::ucsi::Lpm::execute_lpm_command`]
pub next_result_execute_lpm_command: VecDeque<Result<Option<embedded_usb_pd::ucsi::lpm::ResponseData>, PdError>>,
}

impl Mock {
/// Create a new mock with the given name
pub fn new(name: &'static str) -> Self {
Self {
fn_calls: VecDeque::new(),
name,
next_result_get_port_status: VecDeque::new(),
next_result_clear_dead_battery_flag: VecDeque::new(),
next_result_enable_sink_path: VecDeque::new(),
next_result_get_pd_alert: VecDeque::new(),
next_result_set_unconstrained_power: VecDeque::new(),
next_result_get_other_vdm: VecDeque::new(),
next_result_get_attn_vdm: VecDeque::new(),
next_result_send_vdm: VecDeque::new(),
next_result_execute_drst: VecDeque::new(),
next_result_get_dp_status: VecDeque::new(),
next_result_set_dp_config: VecDeque::new(),
next_result_set_tbt_config: VecDeque::new(),
next_result_set_usb_control: VecDeque::new(),
next_result_execute_lpm_command: VecDeque::new(),
}
}
}

impl Named for Mock {
fn name(&self) -> &'static str {
self.name
}
}
Loading
Loading