Skip to content
Merged
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
9 changes: 9 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Rust PR Review Instructions
CI overview:
* CI will build the project and run `cargo test` and `cargo clippy`.
* Feature combinations are checked with `cargo hack`.
* Do not comment on compile errors, compiler warnings, or clippy warnings.

Pay special attention to...
* code that uses async selection APIs such as `select`, `selectN`, `select_array`, `select_slice`, or is marked with a drop safety comment. These functions drop the futures that don't finish. Check that values are not lost when this happens.
* code that could possibly panic or is marked with a panic safety comment.
4 changes: 2 additions & 2 deletions .github/workflows/device-driver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: baptiste0928/cargo-install@v3
with:
crate: device-driver-cli
version: 1.0.3
version: 1.0.9
- name: Generate files
run: device-driver-cli --manifest device.yaml --device-name Registers -o ci_gen_registers.rs
- name: Check that the files are the exact same
Expand All @@ -31,4 +31,4 @@ jobs:
old: ci_gen_registers.rs
new: src/registers/generated.rs
mode: strict
tolerance: same
tolerance: same
6 changes: 3 additions & 3 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ embedded-hal = "1.0.0"
embedded-hal-async = "1.0.0"
embedded-usb-pd = { git = "https://github.com/OpenDevicePartnership/embedded-usb-pd", default-features = false }
# When updating `device-driver`, also update the version of device-driver-cli in the README and in the device-driver.yml workflow.
device-driver = { version = "1.0.3", default-features = false }
device-driver = { version = "1.0.9", default-features = false }
defmt = { version = "0.3.0", optional = true }
log = { version = "0.4.14", optional = true }
embassy-sync = { version = "0.8.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Driver for TPS6699x series PD controller
This driver uses the [device-driver](https://crates.io/crates/device-driver) crate to define the register mapping. If any changes are made to the register map manifest file `device.yaml`, `src/registers/generated.rs` must be regenerated by running the following commands:

```bash
$ cargo install device-driver-cli --version 1.0.3
$ cargo install device-driver-cli --version 1.0.9
$ device-driver-cli --manifest device.yaml --device-name Registers -o src/registers/generated.rs
```
6 changes: 3 additions & 3 deletions examples/rt685s-evk/Cargo.lock

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

29 changes: 29 additions & 0 deletions src/asynchronous/embassy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ impl<'a, M: RawMutex, B: I2c> Tps6699x<'a, M, B> {
inner.set_sx_app_config(port, state).await
}

/// Get the discovered SVIDs on a port returned from `Discover SVIDs REQ` messages.
pub async fn get_discovered_svids(
&mut self,
port: LocalPortId,
) -> Result<registers::discovered_svids::DiscoveredSvids, Error<B::Error>> {
self.lock_inner().await.get_discovered_svids(port).await
}

/// Get Rx ADO
pub async fn get_rx_ado(
&mut self,
Expand Down Expand Up @@ -702,6 +710,22 @@ impl<'a, M: RawMutex, B: I2c> Tps6699x<'a, M, B> {
self.lock_inner().await.modify_tx_identity(port, f).await
}

/// Get the latest received SOP identity data
pub async fn get_received_sop_identity_data(
&mut self,
port: LocalPortId,
) -> Result<registers::received_sop_identity_data::ReceivedSopIdentityData, Error<B::Error>> {
self.lock_inner().await.get_received_sop_identity_data(port).await
}

/// Get the latest received SOP Prime identity data
pub async fn get_received_sop_prime_identity_data(
&mut self,
port: LocalPortId,
) -> Result<registers::received_sop_prime_identity_data::ReceivedSopPrimeIdentityData, Error<B::Error>> {
self.lock_inner().await.get_received_sop_prime_identity_data(port).await
}

/// Get DP config
pub async fn get_dp_config(
&mut self,
Expand Down Expand Up @@ -736,6 +760,11 @@ impl<'a, M: RawMutex, B: I2c> Tps6699x<'a, M, B> {
self.execute_command(port, Command::Drst, None, None).await
}

/// Execute the [`Command::HRST`] command.
pub async fn execute_hrst(&mut self, port: LocalPortId) -> Result<ReturnValue, Error<B::Error>> {
self.execute_command(port, Command::HRST, None, None).await
}

/// Get Rx discovered custom modes
pub async fn execute_gcdm(
&mut self,
Expand Down
48 changes: 12 additions & 36 deletions src/asynchronous/embassy/rx_caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ mod tests {

fn make_src_caps() -> RxCaps<source::Pdo> {
let spr = source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 5000,
current_ma: 3000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
});
let epr0 = source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 28000,
current_ma: 3000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
});
let epr1 = source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 28000,
current_ma: 5000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
});
RxCaps {
spr: heapless::Vec::from_iter([spr]),
Expand All @@ -124,34 +124,22 @@ mod tests {

fn make_snk_caps() -> RxCaps<sink::Pdo> {
let spr0 = sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 5000,
operational_current_ma: 900,
..Default::default()
});
let spr1 = sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 5000,
operational_current_ma: 3000,
..Default::default()
});
let epr = sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 20000,
operational_current_ma: 3000,
..Default::default()
});
RxCaps {
spr: heapless::Vec::from_iter([spr0, spr1]),
Expand All @@ -169,28 +157,28 @@ mod tests {
assert_eq!(
generic.spr[0],
pdo::Pdo::Source(source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 5000,
current_ma: 3000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
}))
);
assert_eq!(
generic.epr[0],
pdo::Pdo::Source(source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 28000,
current_ma: 3000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
}))
);
assert_eq!(
generic.epr[1],
pdo::Pdo::Source(source::Pdo::Fixed(SrcFixedData {
flags: Default::default(),
voltage_mv: 28000,
current_ma: 5000,
peak_current: source::PeakCurrent::Pct100,
..Default::default()
}))
);
}
Expand All @@ -205,40 +193,28 @@ mod tests {
assert_eq!(
generic.spr[0],
pdo::Pdo::Sink(sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 5000,
operational_current_ma: 900,
..Default::default()
}))
);
assert_eq!(
generic.spr[1],
pdo::Pdo::Sink(sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 5000,
operational_current_ma: 3000,
..Default::default()
}))
);
assert_eq!(
generic.epr[0],
pdo::Pdo::Sink(sink::Pdo::Fixed(SnkFixedData {
dual_role_power: false,
higher_capability: false,
unconstrained_power: false,
usb_comms_capable: false,
dual_role_data: false,
frs_required_current: sink::FrsRequiredCurrent::None,
voltage_mv: 20000,
operational_current_ma: 3000,
..Default::default()
}))
);
}
Expand Down
55 changes: 55 additions & 0 deletions src/asynchronous/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,25 @@ impl<B: I2c> Tps6699x<B> {
.await
}

/// Get the discovered SVIDs on a port returned from `Discover SVIDs REQ` messages.
pub async fn get_discovered_svids(
&mut self,
port: LocalPortId,
) -> Result<registers::discovered_svids::DiscoveredSvids, Error<B::Error>> {
let mut buf = [0u8; registers::discovered_svids::LEN];
self.borrow_port(port)?
.into_registers()
.interface()
.read_register(
registers::discovered_svids::ADDR,
(registers::discovered_svids::LEN * 8) as u32,
&mut buf,
)
.await?;

Ok(buf.into())
}

/// Get Rx ADO
pub async fn get_rx_ado(&mut self, port: LocalPortId) -> Result<registers::field_sets::RxAdo, Error<B::Error>> {
self.borrow_port(port)?.into_registers().rx_ado().read_async().await
Expand Down Expand Up @@ -753,6 +772,42 @@ impl<B: I2c> Tps6699x<B> {
self.set_tx_identity(port, reg.clone()).await?;
Ok(reg)
}

/// Get the latest received SOP identity data
pub async fn get_received_sop_identity_data(
&mut self,
port: LocalPortId,
) -> Result<registers::received_sop_identity_data::ReceivedSopIdentityData, Error<B::Error>> {
let mut buf = [0u8; registers::received_sop_identity_data::LEN];
self.borrow_port(port)?
.into_registers()
.interface()
.read_register(
registers::received_sop_identity_data::ADDR,
(registers::received_sop_identity_data::LEN * 8) as u32,
&mut buf,
)
.await?;
Ok(buf.into())
}

/// Get the latest received SOP Prime identity data
pub async fn get_received_sop_prime_identity_data(
&mut self,
port: LocalPortId,
) -> Result<registers::received_sop_prime_identity_data::ReceivedSopPrimeIdentityData, Error<B::Error>> {
let mut buf = [0u8; registers::received_sop_prime_identity_data::LEN];
self.borrow_port(port)?
.into_registers()
.interface()
.read_register(
registers::received_sop_prime_identity_data::ADDR,
(registers::received_sop_prime_identity_data::LEN * 8) as u32,
&mut buf,
)
.await?;
Ok(buf.into())
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/command/gcdm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Get custom discovered modes command
use embedded_usb_pd::vdm::Svid;
use embedded_usb_pd::vdm::structured::Svid;

/// Input data length
pub const INPUT_LEN: usize = 3;
Expand Down
12 changes: 12 additions & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ pub enum Command {
/// [`ReturnValue`]
Drst = u32_from_str(*b"DRST"),

/// Hard Reset
///
/// # Input
/// None
///
/// # Output
/// [`ReturnValue`]
HRST = u32_from_str(*b"HRST"),

/// Send VDM.
///
/// # Input
Expand Down Expand Up @@ -170,6 +179,8 @@ impl TryFrom<u32> for Command {
Ok(Command::Muxr)
} else if Command::Drst == value {
Ok(Command::Drst)
} else if Command::HRST == value {
Ok(Command::HRST)
} else if Command::VDMs == value {
Ok(Command::VDMs)
} else if Command::Ucsi == value {
Expand Down Expand Up @@ -718,6 +729,7 @@ mod test {
assert_eq!(Command::try_from(Command::Dbfg as u32).unwrap(), Command::Dbfg);
assert_eq!(Command::try_from(Command::Muxr as u32).unwrap(), Command::Muxr);
assert_eq!(Command::try_from(Command::Drst as u32).unwrap(), Command::Drst);
assert_eq!(Command::try_from(Command::HRST as u32).unwrap(), Command::HRST);
assert_eq!(Command::try_from(Command::VDMs as u32).unwrap(), Command::VDMs);
assert_eq!(Command::try_from(Command::Ucsi as u32).unwrap(), Command::Ucsi);
assert_eq!(Command::try_from(0xFFFFFFFFu32), Err(PdError::InvalidParams));
Expand Down
Loading
Loading