From 3df1d4ea470fe1619387eec20fba9e19d3980c2f Mon Sep 17 00:00:00 2001 From: "Jes B. Klinke" Date: Wed, 23 Oct 2024 15:11:19 -0700 Subject: [PATCH] [opentitantool] Support gpio analog-write via proxy 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 --- sw/host/opentitanlib/src/proxy/handler.rs | 8 ++++++++ sw/host/opentitanlib/src/proxy/protocol.rs | 6 ++++++ sw/host/opentitanlib/src/transport/proxy/gpio.rs | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/sw/host/opentitanlib/src/proxy/handler.rs b/sw/host/opentitanlib/src/proxy/handler.rs index 167ace72fb5b2..cebe18f20aa3a 100644 --- a/sw/host/opentitanlib/src/proxy/handler.rs +++ b/sw/host/opentitanlib/src/proxy/handler.rs @@ -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, diff --git a/sw/host/opentitanlib/src/proxy/protocol.rs b/sw/host/opentitanlib/src/proxy/protocol.rs index d1eb75d451114..483a4e107253e 100644 --- a/sw/host/opentitanlib/src/proxy/protocol.rs +++ b/sw/host/opentitanlib/src/proxy/protocol.rs @@ -75,6 +75,10 @@ pub enum GpioRequest { SetPullMode { pull: PullMode, }, + AnalogWrite { + value: f32, + }, + AnalogRead, MultiSet { mode: Option, value: Option, @@ -89,6 +93,8 @@ pub enum GpioResponse { Read { value: bool }, SetMode, SetPullMode, + AnalogWrite, + AnalogRead { value: f32 }, MultiSet, } diff --git a/sw/host/opentitanlib/src/transport/proxy/gpio.rs b/sw/host/opentitanlib/src/transport/proxy/gpio.rs index 0a533b55ecc19..f68baa2b040de 100644 --- a/sw/host/opentitanlib/src/transport/proxy/gpio.rs +++ b/sw/host/opentitanlib/src/transport/proxy/gpio.rs @@ -76,6 +76,20 @@ impl GpioPin for ProxyGpioPin { } } + fn analog_read(&self) -> Result { + 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,