From 6d4a49bca86415b88f282d084cfa4045c171e63a Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 11 May 2022 16:23:31 +0200 Subject: [PATCH 1/2] Implement Output::is_set_low for embassy-rp This commit implements a suggestion for the method is_set_low which is currently a 'todo', by reading last value written to GPIO_OUT. --- embassy-rp/src/gpio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 598759036..9cdba8bf3 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -127,8 +127,8 @@ impl<'d, T: Pin> Output<'d, T> { /// Is the output pin set as low? pub fn is_set_low(&self) -> bool { - // todo - true + // Reading from SIO: GPIO_OUT gives the last value written. + unsafe { self.pin.sio_out().value().read() == 0 } } } From 0bb428dcc01a01f15459acb9ebed4e045448bf5d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 11 May 2022 18:26:25 +0200 Subject: [PATCH 2/2] squash! Implement Output::is_set_low for embassy-rp Add check for the bit of the current pin. --- embassy-rp/src/gpio.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 9cdba8bf3..28dfce476 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -128,7 +128,8 @@ impl<'d, T: Pin> Output<'d, T> { /// Is the output pin set as low? pub fn is_set_low(&self) -> bool { // Reading from SIO: GPIO_OUT gives the last value written. - unsafe { self.pin.sio_out().value().read() == 0 } + let val = 1 << self.pin.pin(); + unsafe { (self.pin.sio_out().value().read() & val) == 0 } } }