diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 24f0b800884..0851a1bdeac 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Inherent implementions of GPIO pin `set_low`, `is_low`, etc. + ### Fixed - Fixing `esp-wifi` + `TRNG` issue on `ESP32-S2` (#1272) diff --git a/esp-hal/src/gpio.rs b/esp-hal/src/gpio.rs index 04ee1e6b346..e189559d758 100644 --- a/esp-hal/src/gpio.rs +++ b/esp-hal/src/gpio.rs @@ -35,6 +35,10 @@ use crate::peripherals::{GPIO, IO_MUX}; pub(crate) use crate::rtc_pins; pub use crate::soc::gpio::*; +mod eh02; +#[cfg(feature = "eh1")] +mod eh1; + /// Convenience type-alias for a no-pin / don't care - pin pub type NoPinType = Gpio0; @@ -541,64 +545,31 @@ pub struct GpioPin { _mode: PhantomData, } -impl embedded_hal::digital::v2::InputPin for GpioPin, GPIONUM> -where - Self: GpioProperties, -{ - type Error = Infallible; - fn is_high(&self) -> Result { - Ok(::Bank::read_input() & (1 << (GPIONUM % 32)) != 0) - } - fn is_low(&self) -> Result { - Ok(!self.is_high()?) - } -} - -impl embedded_hal::digital::v2::InputPin for GpioPin, GPIONUM> +impl GpioPin, GPIONUM> where Self: GpioProperties, { - type Error = Infallible; - fn is_high(&self) -> Result { - Ok(::Bank::read_input() & (1 << (GPIONUM % 32)) != 0) - } - fn is_low(&self) -> Result { - Ok(!self.is_high()?) - } -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::ErrorType for GpioPin, GPIONUM> -where - Self: GpioProperties, -{ - type Error = Infallible; -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::InputPin for GpioPin, GPIONUM> -where - Self: GpioProperties, -{ - fn is_high(&mut self) -> Result { - Ok(::Bank::read_input() & (1 << (GPIONUM % 32)) != 0) + #[inline] + pub fn is_high(&self) -> bool { + ::Bank::read_input() & (1 << (GPIONUM % 32)) != 0 } - fn is_low(&mut self) -> Result { - Ok(!self.is_high()?) + #[inline] + pub fn is_low(&self) -> bool { + !self.is_high() } } -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::InputPin for GpioPin, GPIONUM> +impl GpioPin, GPIONUM> where Self: GpioProperties, - ::PinType: IsOutputPin, { - fn is_high(&mut self) -> Result { - Ok(::Bank::read_input() & (1 << (GPIONUM % 32)) != 0) + #[inline] + pub fn is_high(&self) -> bool { + ::Bank::read_input() & (1 << (GPIONUM % 32)) != 0 } - fn is_low(&mut self) -> Result { - Ok(!self.is_high()?) + #[inline] + pub fn is_low(&self) -> bool { + !self.is_high() } } @@ -865,94 +836,37 @@ where } } -impl embedded_hal::digital::v2::OutputPin - for GpioPin, GPIONUM> +impl GpioPin, GPIONUM> where Self: GpioProperties, ::PinType: IsOutputPin, { - type Error = Infallible; - fn set_high(&mut self) -> Result<(), Self::Error> { + #[inline] + pub fn set_high(&mut self) { ::Bank::write_output_set(1 << (GPIONUM % 32)); - Ok(()) } - fn set_low(&mut self) -> Result<(), Self::Error> { + #[inline] + pub fn set_low(&mut self) { ::Bank::write_output_clear(1 << (GPIONUM % 32)); - Ok(()) } -} - -impl embedded_hal::digital::v2::StatefulOutputPin - for GpioPin, GPIONUM> -where - Self: GpioProperties, - ::PinType: IsOutputPin, -{ - fn is_set_high(&self) -> Result { - Ok(::Bank::read_output() & (1 << (GPIONUM % 32)) != 0) + #[inline] + pub fn is_set_high(&self) -> bool { + ::Bank::read_output() & (1 << (GPIONUM % 32)) != 0 } - fn is_set_low(&self) -> Result { - Ok(!self.is_set_high()?) + #[inline] + pub fn is_set_low(&self) -> bool { + !self.is_set_high() } -} - -impl embedded_hal::digital::v2::ToggleableOutputPin - for GpioPin, GPIONUM> -where - Self: GpioProperties, - ::PinType: IsOutputPin, -{ - type Error = Infallible; - fn toggle(&mut self) -> Result<(), Self::Error> { - use embedded_hal::digital::v2::{OutputPin as _, StatefulOutputPin as _}; - if self.is_set_high()? { - Ok(self.set_low()?) + #[inline] + pub fn toggle(&mut self) { + if self.is_set_high() { + self.set_low(); } else { - Ok(self.set_high()?) + self.set_high(); } } } -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::ErrorType for GpioPin, GPIONUM> -where - Self: GpioProperties, - ::PinType: IsOutputPin, -{ - type Error = Infallible; -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::OutputPin for GpioPin, GPIONUM> -where - Self: GpioProperties, - ::PinType: IsOutputPin, -{ - fn set_low(&mut self) -> Result<(), Self::Error> { - ::Bank::write_output_clear(1 << (GPIONUM % 32)); - Ok(()) - } - fn set_high(&mut self) -> Result<(), Self::Error> { - ::Bank::write_output_set(1 << (GPIONUM % 32)); - Ok(()) - } -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::StatefulOutputPin - for GpioPin, GPIONUM> -where - Self: GpioProperties, - ::PinType: IsOutputPin, -{ - fn is_set_high(&mut self) -> Result { - Ok(::Bank::read_output() & (1 << (GPIONUM % 32)) != 0) - } - fn is_set_low(&mut self) -> Result { - Ok(!self.is_set_high()?) - } -} - impl crate::peripheral::Peripheral for GpioPin where Self: GpioProperties, @@ -1719,127 +1633,75 @@ where } } -impl embedded_hal::digital::v2::InputPin for AnyPin, TYPE> { - type Error = core::convert::Infallible; - - fn is_high(&self) -> Result { +impl AnyPin, TYPE> { + #[inline] + pub fn is_high(&self) -> bool { let inner = &self.inner; handle_gpio_input!(inner, target, { target.is_high() }) } - fn is_low(&self) -> Result { + #[inline] + pub fn is_low(&self) -> bool { let inner = &self.inner; handle_gpio_input!(inner, target, { target.is_low() }) } } -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::ErrorType for AnyPin, TYPE> { - type Error = Infallible; -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::InputPin for AnyPin, TYPE> { - fn is_high(&mut self) -> Result { - let inner = &mut self.inner; - handle_gpio_input!(inner, target, { target.is_high() }) - } - - fn is_low(&mut self) -> Result { - let inner = &mut self.inner; - handle_gpio_input!(inner, target, { target.is_low() }) - } -} - -impl embedded_hal::digital::v2::OutputPin for AnyPin, TYPE> { - type Error = Infallible; - - fn set_low(&mut self) -> Result<(), Self::Error> { +impl AnyPin, TYPE> { + #[inline] + pub fn set_low(&mut self) { let inner = &mut self.inner; handle_gpio_output!(inner, target, { target.set_low() }) } - fn set_high(&mut self) -> Result<(), Self::Error> { + #[inline] + pub fn set_high(&mut self) { let inner = &mut self.inner; handle_gpio_output!(inner, target, { target.set_high() }) } -} -impl embedded_hal::digital::v2::StatefulOutputPin for AnyPin, TYPE> { - fn is_set_high(&self) -> Result { + #[inline] + pub fn is_set_high(&self) -> bool { let inner = &self.inner; handle_gpio_output!(inner, target, { target.is_set_high() }) } - fn is_set_low(&self) -> Result { + #[inline] + pub fn is_set_low(&self) -> bool { let inner = &self.inner; handle_gpio_output!(inner, target, { target.is_set_low() }) } -} -impl embedded_hal::digital::v2::ToggleableOutputPin for AnyPin, TYPE> { - type Error = Infallible; - - fn toggle(&mut self) -> Result<(), Self::Error> { + #[inline] + pub fn toggle(&mut self) { let inner = &mut self.inner; handle_gpio_output!(inner, target, { target.toggle() }) } } -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::ErrorType for AnyPin, TYPE> { - type Error = Infallible; -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::OutputPin for AnyPin, TYPE> { - fn set_low(&mut self) -> Result<(), Self::Error> { - let inner = &mut self.inner; - handle_gpio_output!(inner, target, { target.set_low() }) - } - - fn set_high(&mut self) -> Result<(), Self::Error> { - let inner = &mut self.inner; - handle_gpio_output!(inner, target, { target.set_high() }) - } -} - -#[cfg(feature = "eh1")] -impl embedded_hal_1::digital::StatefulOutputPin for AnyPin, TYPE> { - fn is_set_high(&mut self) -> Result { - let inner = &mut self.inner; - handle_gpio_output!(inner, target, { target.is_set_high() }) - } - - fn is_set_low(&mut self) -> Result { - let inner = &mut self.inner; - handle_gpio_output!(inner, target, { target.is_set_low() }) - } -} - #[cfg(feature = "async")] -impl embedded_hal_async::digital::Wait for AnyPin, TYPE> { - async fn wait_for_high(&mut self) -> Result<(), Self::Error> { +impl AnyPin, TYPE> { + pub async fn wait_for_high(&mut self) { let inner = &mut self.inner; handle_gpio_input!(inner, target, { target.wait_for_high().await }) } - async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_low(&mut self) { let inner = &mut self.inner; handle_gpio_input!(inner, target, { target.wait_for_low().await }) } - async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_rising_edge(&mut self) { let inner = &mut self.inner; handle_gpio_input!(inner, target, { target.wait_for_rising_edge().await }) } - async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_falling_edge(&mut self) { let inner = &mut self.inner; handle_gpio_input!(inner, target, { target.wait_for_falling_edge().await }) } - async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_any_edge(&mut self) { let inner = &mut self.inner; handle_gpio_input!(inner, target, { target.wait_for_any_edge().await }) } @@ -3072,63 +2934,61 @@ mod asynch { use core::task::{Context, Poll}; use embassy_sync::waitqueue::AtomicWaker; - use embedded_hal_async::digital::Wait; use super::*; - use crate::prelude::*; #[allow(clippy::declare_interior_mutable_const)] const NEW_AW: AtomicWaker = AtomicWaker::new(); static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [NEW_AW; NUM_PINS]; - impl Wait for GpioPin, GPIONUM> + impl GpioPin, GPIONUM> where Self: GpioProperties, ::PinType: IsInputPin, { - async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_high(&mut self) { PinFuture::new(self, Event::HighLevel).await } - async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_low(&mut self) { PinFuture::new(self, Event::LowLevel).await } - async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_rising_edge(&mut self) { PinFuture::new(self, Event::RisingEdge).await } - async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_falling_edge(&mut self) { PinFuture::new(self, Event::FallingEdge).await } - async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_any_edge(&mut self) { PinFuture::new(self, Event::AnyEdge).await } } - impl Wait for GpioPin, GPIONUM> + impl GpioPin, GPIONUM> where Self: GpioProperties, ::PinType: IsInputPin + IsOutputPin, { - async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_high(&mut self) { PinFuture::new(self, Event::HighLevel).await } - async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_low(&mut self) { PinFuture::new(self, Event::LowLevel).await } - async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_rising_edge(&mut self) { PinFuture::new(self, Event::RisingEdge).await } - async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_falling_edge(&mut self) { PinFuture::new(self, Event::FallingEdge).await } - async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + pub async fn wait_for_any_edge(&mut self) { PinFuture::new(self, Event::AnyEdge).await } } @@ -3139,7 +2999,7 @@ mod asynch { impl<'a, P> PinFuture<'a, P> where - P: crate::gpio::Pin + embedded_hal_1::digital::ErrorType, + P: crate::gpio::Pin, { pub fn new(pin: &'a mut P, event: Event) -> Self { pin.listen(event); @@ -3149,9 +3009,9 @@ mod asynch { impl<'a, P> core::future::Future for PinFuture<'a, P> where - P: crate::gpio::Pin + embedded_hal_1::digital::ErrorType, + P: crate::gpio::Pin, { - type Output = Result<(), P::Error>; + type Output = (); fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { PIN_WAKERS[self.pin.number() as usize].register(cx.waker()); @@ -3159,7 +3019,7 @@ mod asynch { // if pin is no longer listening its been triggered // therefore the future has resolved if !self.pin.is_listening() { - Poll::Ready(Ok(())) + Poll::Ready(()) } else { Poll::Pending } diff --git a/esp-hal/src/gpio/eh02.rs b/esp-hal/src/gpio/eh02.rs new file mode 100644 index 00000000000..529abf5da72 --- /dev/null +++ b/esp-hal/src/gpio/eh02.rs @@ -0,0 +1,123 @@ +use super::{ + AnyPin, + BankGpioRegisterAccess, + GpioPin, GpioProperties, + Infallible, + Input, + IsOutputPin, + OpenDrain, + Output, +}; +use embedded_hal::digital::v2 as digital; + +impl digital::InputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, +{ + type Error = Infallible; + fn is_high(&self) -> Result { + Ok(self.is_high()) + } + fn is_low(&self) -> Result { + Ok(self.is_low()) + } +} + +impl digital::InputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, +{ + type Error = Infallible; + fn is_high(&self) -> Result { + Ok(::Bank::read_input() & (1 << (GPIONUM % 32)) != 0) + } + fn is_low(&self) -> Result { + Ok(self.is_low()) + } +} + +impl digital::OutputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + type Error = Infallible; + fn set_high(&mut self) -> Result<(), Self::Error> { + self.set_high(); + Ok(()) + } + fn set_low(&mut self) -> Result<(), Self::Error> { + self.set_low(); + Ok(()) + } +} + +impl digital::StatefulOutputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + fn is_set_high(&self) -> Result { + Ok(self.is_set_high()) + } + fn is_set_low(&self) -> Result { + Ok(self.is_set_low()) + } +} + +impl digital::ToggleableOutputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + type Error = Infallible; + fn toggle(&mut self) -> Result<(), Self::Error> { + self.toggle(); + Ok(()) + } +} + +impl digital::InputPin for AnyPin, TYPE> { + type Error = core::convert::Infallible; + + fn is_high(&self) -> Result { + Ok(self.is_high()) + } + + fn is_low(&self) -> Result { + Ok(self.is_low()) + } +} + +impl digital::OutputPin for AnyPin, TYPE> { + type Error = Infallible; + + fn set_low(&mut self) -> Result<(), Self::Error> { + self.set_low(); + Ok(()) + } + + fn set_high(&mut self) -> Result<(), Self::Error> { + self.set_high(); + Ok(()) + } +} + +impl digital::StatefulOutputPin for AnyPin, TYPE> { + fn is_set_high(&self) -> Result { + Ok(self.is_set_high()) + } + + fn is_set_low(&self) -> Result { + Ok(self.is_set_low()) + } +} + +impl digital::ToggleableOutputPin for AnyPin, TYPE> { + type Error = Infallible; + + fn toggle(&mut self) -> Result<(), Self::Error> { + self.toggle(); + Ok(()) + } +} diff --git a/esp-hal/src/gpio/eh1.rs b/esp-hal/src/gpio/eh1.rs new file mode 100644 index 00000000000..df16d9556a6 --- /dev/null +++ b/esp-hal/src/gpio/eh1.rs @@ -0,0 +1,209 @@ +use embedded_hal_1::digital; + +use super::{AnyPin, GpioPin, GpioProperties, Infallible, Input, IsOutputPin, OpenDrain, Output}; + +impl digital::ErrorType for GpioPin, GPIONUM> +where + Self: GpioProperties, +{ + type Error = Infallible; +} + +impl digital::InputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, +{ + fn is_high(&mut self) -> Result { + Ok(Self::is_high(self)) + } + fn is_low(&mut self) -> Result { + Ok(Self::is_low(self)) + } +} + +impl digital::InputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + fn is_high(&mut self) -> Result { + Ok(Self::is_high(self)) + } + fn is_low(&mut self) -> Result { + Ok(Self::is_low(self)) + } +} + +impl digital::ErrorType for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + type Error = Infallible; +} + +impl digital::OutputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + fn set_low(&mut self) -> Result<(), Self::Error> { + self.set_low(); + Ok(()) + } + fn set_high(&mut self) -> Result<(), Self::Error> { + self.set_high(); + Ok(()) + } +} + +impl digital::StatefulOutputPin for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsOutputPin, +{ + fn is_set_high(&mut self) -> Result { + Ok(Self::is_set_high(self)) + } + fn is_set_low(&mut self) -> Result { + Ok(Self::is_set_low(self)) + } +} + +impl digital::ErrorType for AnyPin, TYPE> { + type Error = Infallible; +} + +impl digital::InputPin for AnyPin, TYPE> { + fn is_high(&mut self) -> Result { + Ok(Self::is_high(self)) + } + + fn is_low(&mut self) -> Result { + Ok(Self::is_low(self)) + } +} + +impl digital::ErrorType for AnyPin, TYPE> { + type Error = Infallible; +} + +impl digital::OutputPin for AnyPin, TYPE> { + fn set_low(&mut self) -> Result<(), Self::Error> { + self.set_low(); + Ok(()) + } + + fn set_high(&mut self) -> Result<(), Self::Error> { + self.set_high(); + Ok(()) + } +} + +impl digital::StatefulOutputPin for AnyPin, TYPE> { + fn is_set_high(&mut self) -> Result { + Ok(Self::is_set_high(self)) + } + + fn is_set_low(&mut self) -> Result { + Ok(Self::is_set_low(self)) + } +} + +#[cfg(feature = "async")] +use embedded_hal_async::digital::Wait; + +#[cfg(feature = "async")] +use super::IsInputPin; + +#[cfg(feature = "async")] +impl Wait for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsInputPin, +{ + async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + self.wait_for_high().await; + Ok(()) + } + + async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + self.wait_for_low().await; + Ok(()) + } + + async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_rising_edge().await; + Ok(()) + } + + async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_falling_edge().await; + Ok(()) + } + + async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_any_edge().await; + Ok(()) + } +} + +#[cfg(feature = "async")] +impl Wait for GpioPin, GPIONUM> +where + Self: GpioProperties, + ::PinType: IsInputPin + IsOutputPin, +{ + async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + self.wait_for_high().await; + Ok(()) + } + + async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + self.wait_for_low().await; + Ok(()) + } + + async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_rising_edge().await; + Ok(()) + } + + async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_falling_edge().await; + Ok(()) + } + + async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_any_edge().await; + Ok(()) + } +} + +#[cfg(feature = "async")] +impl embedded_hal_async::digital::Wait for AnyPin, TYPE> { + async fn wait_for_high(&mut self) -> Result<(), Self::Error> { + self.wait_for_high().await; + Ok(()) + } + + async fn wait_for_low(&mut self) -> Result<(), Self::Error> { + self.wait_for_low().await; + Ok(()) + } + + async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_rising_edge().await; + Ok(()) + } + + async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_falling_edge().await; + Ok(()) + } + + async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { + self.wait_for_any_edge().await; + Ok(()) + } +} diff --git a/examples/src/bin/blinky.rs b/examples/src/bin/blinky.rs index 072267b9bad..1f471f25552 100644 --- a/examples/src/bin/blinky.rs +++ b/examples/src/bin/blinky.rs @@ -20,14 +20,14 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = io.pins.gpio0.into_push_pull_output(); - led.set_high().unwrap(); + led.set_high(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. let mut delay = Delay::new(&clocks); loop { - led.toggle().unwrap(); + led.toggle(); delay.delay_ms(500u32); } } diff --git a/examples/src/bin/blinky_erased_pins.rs b/examples/src/bin/blinky_erased_pins.rs index 0a58e2f285c..0b7a7700638 100644 --- a/examples/src/bin/blinky_erased_pins.rs +++ b/examples/src/bin/blinky_erased_pins.rs @@ -50,10 +50,10 @@ fn main() -> ! { fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { for pin in leds.iter_mut() { - pin.toggle().unwrap(); + pin.toggle(); } - if button.is_low().unwrap() { + if button.is_low() { esp_println::println!("Button pressed"); } } diff --git a/examples/src/bin/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs index 45354e7f123..63d1cfecd06 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -40,10 +40,10 @@ async fn control_led( loop { if control.wait().await { esp_println::println!("LED on"); - led.set_low().unwrap(); + led.set_low(); } else { esp_println::println!("LED off"); - led.set_high().unwrap(); + led.set_high(); } } } diff --git a/examples/src/bin/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs index c139e6ef9af..e2c30985ef3 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -56,10 +56,10 @@ async fn control_led( loop { if control.wait().await { esp_println::println!("LED on"); - led.set_low().unwrap(); + led.set_low(); } else { esp_println::println!("LED off"); - led.set_high().unwrap(); + led.set_high(); } } } diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index 3b22c1ea1ec..8d3693221f2 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -30,7 +30,7 @@ compile_error!("Run this example in release mode"); async fn signal_task(mut pin: Gpio5>) { loop { for _ in 0..10 { - pin.toggle().unwrap(); + pin.toggle(); Timer::after(Duration::from_micros(10)).await; } Timer::after(Duration::from_millis(1000)).await; diff --git a/examples/src/bin/embassy_wait.rs b/examples/src/bin/embassy_wait.rs index 56a8c4c1151..77bcffd8df2 100644 --- a/examples/src/bin/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) { loop { esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); + input.wait_for_rising_edge().await; esp_println::println!("Ping!"); Timer::after(Duration::from_millis(100)).await; } diff --git a/examples/src/bin/etm_gpio.rs b/examples/src/bin/etm_gpio.rs index 900ad1c3239..8cc0caa1697 100644 --- a/examples/src/bin/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -21,7 +21,7 @@ fn main() -> ! { let mut led = io.pins.gpio1.into_push_pull_output(); let button = io.pins.gpio9.into_pull_down_input(); - led.set_high().unwrap(); + led.set_high(); // setup ETM let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); diff --git a/examples/src/bin/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs index e2555e2528f..3fcb4a36752 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -50,14 +50,14 @@ fn main() -> ! { interrupt::enable(Interrupt::GPIO, Priority::Priority2).unwrap(); - led.set_high().unwrap(); + led.set_high(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. let mut delay = Delay::new(&clocks); loop { - led.toggle().unwrap(); + led.toggle(); delay.delay_ms(500u32); } } diff --git a/examples/src/bin/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs index a93d7f8d0c1..6a6c893f5c7 100644 --- a/examples/src/bin/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -95,9 +95,9 @@ fn main() -> ! { // https://gist.github.com/sukesh-ak/610508bc84779a26efdcf969bf51a2d1 // https://github.com/lovyan03/LovyanGFX/blob/302169a6f23e9a2a6451f03311c366d182193831/src/lgfx/v1/panel/Panel_ST7796.hpp#L28 - reset.set_low().unwrap(); + reset.set_low(); delay.delay_us(8_000u32); - reset.set_high().unwrap(); + reset.set_high(); delay.delay_us(64_000u32); // const CMD_FRMCTR1: u8 = 0xB1; @@ -208,7 +208,7 @@ fn main() -> ! { const RED: u16 = 0b00000_000000_11111; const BLUE: u16 = 0b11111_000000_00000; - backlight.set_high().unwrap(); + backlight.set_high(); let total_pixels = width as usize * height as usize; let total_bytes = total_pixels * 2; diff --git a/examples/src/bin/rmt_rx.rs b/examples/src/bin/rmt_rx.rs index 6dc47e92a8d..60d0fc59791 100644 --- a/examples/src/bin/rmt_rx.rs +++ b/examples/src/bin/rmt_rx.rs @@ -73,9 +73,9 @@ fn main() -> ! { // simulate input for i in 0u32..5u32 { - out.set_high().unwrap(); + out.set_high(); delay.delay_us(i * 10 + 20); - out.set_low().unwrap(); + out.set_low(); delay.delay_us(i * 20 + 20); } diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index 1100db9edc4..887724b0b99 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -59,9 +59,9 @@ fn main() -> ! { let mut master_mosi = io.pins.gpio8.into_push_pull_output(); let slave_cs = io.pins.gpio3; let mut master_cs = io.pins.gpio9.into_push_pull_output(); - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - master_mosi.set_low().unwrap(); + master_cs.set_high(); + master_sclk.set_low(); + master_mosi.set_low(); let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -113,31 +113,31 @@ fn main() -> ! { // Bit-bang out the contents of master_send and read into master_receive // as quickly as manageable. MSB first. Mode 0, so sampled on the rising // edge and set on the falling edge. - master_cs.set_low().unwrap(); + master_cs.set_low(); for (j, v) in master_send.iter().enumerate() { let mut b = *v; let mut rb = 0u8; for _ in 0..8 { if b & 128 != 0 { - master_mosi.set_high().unwrap(); + master_mosi.set_high(); } else { - master_mosi.set_low().unwrap(); + master_mosi.set_low(); } - master_sclk.set_low().unwrap(); + master_sclk.set_low(); b <<= 1; rb <<= 1; // NB: adding about 24 NOPs here makes the clock's duty cycle // run at about 50% ... but we don't strictly need the delay, // either. - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { + master_sclk.set_high(); + if master_miso.is_high() { rb |= 1; } } master_receive[j] = rb; } - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); + master_cs.set_high(); + master_sclk.set_low(); // the buffers and spi is moved into the transfer and we can get it back via // `wait` transfer.wait().unwrap(); @@ -153,23 +153,23 @@ fn main() -> ! { slave_receive.fill(0xff); let transfer = spi.dma_read(&mut slave_receive).unwrap(); - master_cs.set_high().unwrap(); + master_cs.set_high(); - master_cs.set_low().unwrap(); + master_cs.set_low(); for v in master_send.iter() { let mut b = *v; for _ in 0..8 { if b & 128 != 0 { - master_mosi.set_high().unwrap(); + master_mosi.set_high(); } else { - master_mosi.set_low().unwrap(); + master_mosi.set_low(); } b <<= 1; - master_sclk.set_low().unwrap(); - master_sclk.set_high().unwrap(); + master_sclk.set_low(); + master_sclk.set_high(); } } - master_cs.set_high().unwrap(); + master_cs.set_high(); transfer.wait().unwrap(); println!( "slave got {:x?} .. {:x?}", @@ -182,20 +182,20 @@ fn main() -> ! { master_receive.fill(0); - master_cs.set_low().unwrap(); + master_cs.set_low(); for (j, _) in master_send.iter().enumerate() { let mut rb = 0u8; for _ in 0..8 { - master_sclk.set_low().unwrap(); + master_sclk.set_low(); rb <<= 1; - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { + master_sclk.set_high(); + if master_miso.is_high() { rb |= 1; } } master_receive[j] = rb; } - master_cs.set_high().unwrap(); + master_cs.set_high(); transfer.wait().unwrap(); println!(