From 8164340e066463ba2914387ad7743d1f1ec037a7 Mon Sep 17 00:00:00 2001 From: Martins Polakovs Date: Sun, 2 Jun 2024 00:01:14 +0300 Subject: [PATCH] Fix set_low() and set_high() implementation for OutputPin --- rp2040-hal/src/gpio/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index d8fb75e89..71a346682 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1465,8 +1465,8 @@ mod eh1 { use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; use super::{ - func, AnyPin, AsInputPin, Error, FunctionSio, InOutPin, Pin, PinId, PullType, SioConfig, - SioInput, SioOutput, + func, AnyPin, AsInputPin, Error, FunctionSio, InOutPin, OutputEnableOverride, Pin, PinId, + PullType, SioConfig, SioInput, SioOutput, }; impl ErrorType for Pin, P> @@ -1558,12 +1558,17 @@ mod eh1 { I: AnyPin, { fn set_low(&mut self) -> Result<(), Self::Error> { - self.inner._set_low(); + // The pin is already set to output low but this is inhibited by the override. + self.inner + .set_output_enable_override(OutputEnableOverride::Enable); Ok(()) } fn set_high(&mut self) -> Result<(), Self::Error> { - self.inner._set_high(); + // To set the open-drain pin to high, just disable the output driver by configuring the + // output override. That way, the DHT11 can still pull the data line down to send its response. + self.inner + .set_output_enable_override(OutputEnableOverride::Disable); Ok(()) } }