Skip to content

Commit 703f8b8

Browse files
zhuyi2024zhuyi
andauthored
Add Retimer FW status get/set command (#298)
Add Retimer FW status get/set command --------- Co-authored-by: zhuyi <zhuyi@microsoft.com>
1 parent 437a932 commit 703f8b8

File tree

10 files changed

+245
-14
lines changed

10 files changed

+245
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

embedded-service/src/type_c/controller.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ pub enum PortCommandData {
9292
PortStatus,
9393
/// Get and clear events
9494
ClearEvents,
95+
/// Get retimer fw update state
96+
RetimerFwUpdateGetState,
97+
/// Set retimer fw update state
98+
RetimerFwUpdateSetState,
99+
/// Clear retimer fw update state
100+
RetimerFwUpdateClearState,
95101
}
96102

97103
/// Port-specific commands
@@ -104,6 +110,16 @@ pub struct PortCommand {
104110
pub data: PortCommandData,
105111
}
106112

113+
/// PD controller command-specific data
114+
#[derive(Copy, Clone, Debug, PartialEq)]
115+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
116+
pub enum RetimerFwUpdateState {
117+
/// Retimer FW Update Inactive
118+
Inactive,
119+
/// Revimer FW Update Active
120+
Active,
121+
}
122+
107123
/// Port-specific response data
108124
#[derive(Copy, Clone, Debug)]
109125
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -114,6 +130,8 @@ pub enum PortResponseData {
114130
PortStatus(PortStatus),
115131
/// ClearEvents
116132
ClearEvents(PortEventKind),
133+
/// Retimer Fw Update status
134+
RtFwUpdateStatus(RetimerFwUpdateState),
117135
}
118136

119137
impl PortResponseData {
@@ -311,6 +329,18 @@ pub trait Controller {
311329
/// Returns the port status
312330
fn get_port_status(&mut self, port: LocalPortId)
313331
-> impl Future<Output = Result<PortStatus, Error<Self::BusError>>>;
332+
/// Returns the retimer fw update state
333+
fn get_rt_fw_update_status(
334+
&mut self,
335+
port: LocalPortId,
336+
) -> impl Future<Output = Result<RetimerFwUpdateState, Error<Self::BusError>>>;
337+
/// Set retimer fw update state
338+
fn set_rt_fw_update_state(&mut self, port: LocalPortId) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
339+
/// Clear retimer fw update state
340+
fn clear_rt_fw_update_state(
341+
&mut self,
342+
port: LocalPortId,
343+
) -> impl Future<Output = Result<(), Error<Self::BusError>>>;
314344
/// Enable or disable sink path
315345
fn enable_sink_path(
316346
&mut self,
@@ -596,6 +626,39 @@ impl ContextToken {
596626
}
597627
}
598628

629+
/// Get the retimer fw update status
630+
pub async fn get_rt_fw_update_status(&self, port: GlobalPortId) -> Result<RetimerFwUpdateState, PdError> {
631+
match self
632+
.send_port_command(port, PortCommandData::RetimerFwUpdateGetState)
633+
.await?
634+
{
635+
PortResponseData::RtFwUpdateStatus(status) => Ok(status),
636+
_ => Err(PdError::InvalidResponse),
637+
}
638+
}
639+
640+
/// Set the retimer fw update state
641+
pub async fn set_rt_fw_update_state(&self, port: GlobalPortId) -> Result<(), PdError> {
642+
match self
643+
.send_port_command(port, PortCommandData::RetimerFwUpdateSetState)
644+
.await?
645+
{
646+
PortResponseData::Complete => Ok(()),
647+
_ => Err(PdError::InvalidResponse),
648+
}
649+
}
650+
651+
/// Clear the retimer fw update state
652+
pub async fn clear_rt_fw_update_state(&self, port: GlobalPortId) -> Result<(), PdError> {
653+
match self
654+
.send_port_command(port, PortCommandData::RetimerFwUpdateClearState)
655+
.await?
656+
{
657+
PortResponseData::Complete => Ok(()),
658+
_ => Err(PdError::InvalidResponse),
659+
}
660+
}
661+
599662
/// Get current controller status
600663
pub async fn get_controller_status(
601664
&self,

embedded-service/src/type_c/external.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use embedded_usb_pd::{GlobalPortId, PdError, PortId as LocalPortId};
44
use super::{
55
controller::{
66
execute_external_controller_command, execute_external_port_command, lookup_controller, ControllerStatus,
7-
PortStatus,
7+
PortStatus, RetimerFwUpdateState,
88
},
99
ControllerId,
1010
};
@@ -44,6 +44,12 @@ pub type ControllerResponse<'a> = Result<ControllerResponseData<'a>, PdError>;
4444
pub enum PortCommandData {
4545
/// Get port status
4646
PortStatus,
47+
/// Get retimer fw update status
48+
RetimerFwUpdateGetState,
49+
/// Set retimer fw update status
50+
RetimerFwUpdateSetState,
51+
/// Clear retimer fw update status
52+
RetimerFwUpdateClearState,
4753
}
4854

4955
/// Port-specific commands
@@ -60,8 +66,12 @@ pub struct PortCommand {
6066
#[derive(Copy, Clone, Debug)]
6167
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6268
pub enum PortResponseData {
69+
/// Command completed with no error
70+
Complete,
6371
/// Get port status
6472
PortStatus(PortStatus),
73+
/// Get retimer fw update status
74+
RetimerFwUpdateGetState(RetimerFwUpdateState),
6575
}
6676

6777
/// Port-specific command response
@@ -88,7 +98,6 @@ pub enum Response<'a> {
8898
}
8999

90100
/// Get the status of the given port
91-
#[allow(unreachable_patterns)]
92101
pub async fn get_port_status(port: GlobalPortId) -> Result<PortStatus, PdError> {
93102
match execute_external_port_command(Command::Port(PortCommand {
94103
port,
@@ -133,3 +142,42 @@ pub async fn controller_port_to_global_id(
133142
) -> Result<GlobalPortId, PdError> {
134143
lookup_controller(controller_id).await?.lookup_global_port(port_id)
135144
}
145+
146+
/// Get the retimer fw update status of the given port
147+
pub async fn port_get_rt_fw_update_status(port: GlobalPortId) -> Result<RetimerFwUpdateState, PdError> {
148+
match execute_external_port_command(Command::Port(PortCommand {
149+
port,
150+
data: PortCommandData::RetimerFwUpdateGetState,
151+
}))
152+
.await?
153+
{
154+
PortResponseData::RetimerFwUpdateGetState(status) => Ok(status),
155+
_ => Err(PdError::InvalidResponse),
156+
}
157+
}
158+
159+
/// Set the retimer fw update state of the given port
160+
pub async fn port_set_rt_fw_update_state(port: GlobalPortId) -> Result<(), PdError> {
161+
match execute_external_port_command(Command::Port(PortCommand {
162+
port,
163+
data: PortCommandData::RetimerFwUpdateSetState,
164+
}))
165+
.await?
166+
{
167+
PortResponseData::Complete => Ok(()),
168+
_ => Err(PdError::InvalidResponse),
169+
}
170+
}
171+
172+
/// Clear the retimer fw update state of the given port
173+
pub async fn port_clear_rt_fw_update_state(port: GlobalPortId) -> Result<(), PdError> {
174+
match execute_external_port_command(Command::Port(PortCommand {
175+
port,
176+
data: PortCommandData::RetimerFwUpdateClearState,
177+
}))
178+
.await?
179+
{
180+
PortResponseData::Complete => Ok(()),
181+
_ => Err(PdError::InvalidResponse),
182+
}
183+
}

examples/rt685s-evk/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/std/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/std/src/bin/type_c/external.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ async fn task(_spawner: Spawner) {
1717
info!("Getting port status");
1818
let port_status = external::get_port_status(GlobalPortId(0)).await.unwrap();
1919
info!("Port status: {:?}", port_status);
20+
21+
info!("Getting retimer fw update status");
22+
let rt_fw_update_status = external::port_get_rt_fw_update_status(GlobalPortId(0)).await.unwrap();
23+
info!("Port status: {:?}", rt_fw_update_status);
24+
25+
info!("Setting retimer fw update state");
26+
let cmd_state = external::port_set_rt_fw_update_state(GlobalPortId(0)).await.unwrap();
27+
info!("Set retimer fw update state: {:?}", cmd_state);
28+
29+
info!("Clearing retimer fw update state");
30+
let cmd_state = external::get_port_status(GlobalPortId(0)).await.unwrap();
31+
info!("Clear retimer fw update state: {:?}", cmd_state);
2032
}
2133

2234
fn main() {

examples/std/src/bin/type_c/service.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod test_controller {
2525

2626
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal};
2727
use embedded_services::type_c::{
28-
controller::{Contract, ControllerStatus, PortStatus},
28+
controller::{Contract, ControllerStatus, PortStatus, RetimerFwUpdateState},
2929
event::PortEventKind,
3030
};
3131

@@ -168,8 +168,25 @@ mod test_controller {
168168
fw_version1: 0xdeadbeef,
169169
})
170170
}
171-
}
172171

172+
async fn get_rt_fw_update_status(
173+
&mut self,
174+
_port: LocalPortId,
175+
) -> Result<RetimerFwUpdateState, Error<Self::BusError>> {
176+
debug!("Get retimer fw update status");
177+
Ok(RetimerFwUpdateState::Inactive)
178+
}
179+
180+
async fn set_rt_fw_update_state(&mut self, _port: LocalPortId) -> Result<(), Error<Self::BusError>> {
181+
debug!("Get set fw update status");
182+
Ok(())
183+
}
184+
185+
async fn clear_rt_fw_update_state(&mut self, _port: LocalPortId) -> Result<(), Error<Self::BusError>> {
186+
debug!("Get clear fw update status");
187+
Ok(())
188+
}
189+
}
173190
pub type Wrapper<'a> = type_c_service::wrapper::ControllerWrapper<'a, 1, Controller<'a>>;
174191
}
175192

type-c-service/src/driver/tps6699x.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,31 @@ impl<const N: usize, M: RawMutex, B: I2c> Controller for Tps6699x<'_, N, M, B> {
259259
Ok(self.port_status[port.0 as usize].get())
260260
}
261261

262+
#[allow(clippy::await_holding_refcell_ref)]
263+
async fn get_rt_fw_update_status(
264+
&mut self,
265+
port: LocalPortId,
266+
) -> Result<type_c::controller::RetimerFwUpdateState, Error<Self::BusError>> {
267+
let mut tps6699x = self.tps6699x.borrow_mut();
268+
match tps6699x.get_rt_fw_update_status(port).await {
269+
Ok(true) => Ok(type_c::controller::RetimerFwUpdateState::Active),
270+
Ok(false) => Ok(type_c::controller::RetimerFwUpdateState::Inactive),
271+
Err(e) => Err(e),
272+
}
273+
}
274+
275+
#[allow(clippy::await_holding_refcell_ref)]
276+
async fn set_rt_fw_update_state(&mut self, port: LocalPortId) -> Result<(), Error<Self::BusError>> {
277+
let mut tps6699x = self.tps6699x.borrow_mut();
278+
tps6699x.set_rt_fw_update_state(port).await
279+
}
280+
281+
#[allow(clippy::await_holding_refcell_ref)]
282+
async fn clear_rt_fw_update_state(&mut self, port: LocalPortId) -> Result<(), Error<Self::BusError>> {
283+
let mut tps6699x = self.tps6699x.borrow_mut();
284+
tps6699x.clear_rt_fw_update_state(port).await
285+
}
286+
262287
#[allow(clippy::await_holding_refcell_ref)]
263288
async fn enable_sink_path(&mut self, port: LocalPortId, enable: bool) -> Result<(), Error<Self::BusError>> {
264289
debug!("Port{} enable sink path: {}", port.0, enable);

0 commit comments

Comments
 (0)