Skip to content

Commit

Permalink
[opentitantool] Support gpio analog-write via proxy
Browse files Browse the repository at this point in the history
Add a few method needed to propagate calls to `Gpio::analog_write()` and
`Gpio::analog_read()` via the proxy protocol.  This appears to have been
an oversight at the time when the analog functionality was added, which
has gone undetected the feature was needed by Google now.

Change-Id: I89b66c86a79ce4686fd3259373f7c057cffb4783
Signed-off-by: Jes B. Klinke <jbk@chromium.org>
  • Loading branch information
jesultra committed Oct 23, 2024
1 parent 1eefb5c commit 3df1d4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sw/host/opentitanlib/src/proxy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ impl<'a> TransportCommandHandler<'a> {
instance.set_pull_mode(*pull)?;
Ok(Response::Gpio(GpioResponse::SetPullMode))
}
GpioRequest::AnalogRead => {
let value = instance.analog_read()?;
Ok(Response::Gpio(GpioResponse::AnalogRead { value }))
}
GpioRequest::AnalogWrite { value } => {
instance.analog_write(*value)?;
Ok(Response::Gpio(GpioResponse::AnalogWrite))
}
GpioRequest::MultiSet {
mode,
value,
Expand Down
6 changes: 6 additions & 0 deletions sw/host/opentitanlib/src/proxy/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub enum GpioRequest {
SetPullMode {
pull: PullMode,
},
AnalogWrite {
value: f32,
},
AnalogRead,
MultiSet {
mode: Option<PinMode>,
value: Option<bool>,
Expand All @@ -89,6 +93,8 @@ pub enum GpioResponse {
Read { value: bool },
SetMode,
SetPullMode,
AnalogWrite,
AnalogRead { value: f32 },
MultiSet,
}

Expand Down
14 changes: 14 additions & 0 deletions sw/host/opentitanlib/src/transport/proxy/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ impl GpioPin for ProxyGpioPin {
}
}

fn analog_read(&self) -> Result<f32> {
match self.execute_command(GpioRequest::AnalogRead)? {
GpioResponse::AnalogRead { value } => Ok(value),
_ => bail!(ProxyError::UnexpectedReply()),
}
}

fn analog_write(&self, volts: f32) -> Result<()> {
match self.execute_command(GpioRequest::AnalogWrite { value: volts })? {
GpioResponse::AnalogWrite => Ok(()),
_ => bail!(ProxyError::UnexpectedReply()),
}
}

fn set(
&self,
mode: Option<PinMode>,
Expand Down

0 comments on commit 3df1d4e

Please sign in to comment.