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,