From bd0203203338baa862105859d461081e445c1d5e Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Sat, 10 Aug 2024 21:17:02 +0300 Subject: [PATCH] gpio: Make AnyPin, AnyInputOnlyPin, DummyPin available from gpio module Making these available straight from `gpio` aligns it with other Embassy implementations (mainly nrf and stm32). Signed-off-by: Priit Laes --- esp-hal/CHANGELOG.md | 1 + esp-hal/src/gpio/any_pin.rs | 6 ------ esp-hal/src/gpio/mod.rs | 15 +++++++++------ esp-hal/src/uart.rs | 4 ++-- examples/src/bin/spi_loopback.rs | 2 +- hil-test/tests/gpio.rs | 2 +- hil-test/tests/lcd_cam_i8080.rs | 2 +- hil-test/tests/lcd_cam_i8080_async.rs | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 61c074ebf64..31223cb0802 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - DMA buffers now don't require a static lifetime. Make sure to never `mem::forget` an in-progress DMA transfer (consider using `#[deny(clippy::mem_forget)]`) (#1837) - SHA driver now use specific structs for the hashing algorithm instead of a parameter. (#1908) - Remove `fn free(self)` in HMAC which goes against esp-hal API guidelines (#1972) +- `AnyPin`, `AnyInputOnyPin` and `DummyPin` are now accessible from `gpio` module (#1918) ### Fixed diff --git a/esp-hal/src/gpio/any_pin.rs b/esp-hal/src/gpio/any_pin.rs index d5d58e95b4a..640ce8dafa7 100644 --- a/esp-hal/src/gpio/any_pin.rs +++ b/esp-hal/src/gpio/any_pin.rs @@ -1,9 +1,3 @@ -//! Type-erased wrappers for GPIO pins. -//! These are useful to pass them into peripheral drivers. -//! -//! If you want a generic pin for GPIO input/output look into -//! [Output],[OutputOpenDrain], [Input] and [Flex]. - use super::*; #[derive(Clone, Copy)] diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 11a363b65dc..4e9c49296b8 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -21,10 +21,10 @@ //! - [Input] pins can be used as digital inputs. //! - [Output] and [OutputOpenDrain] pins can be used as digital outputs. //! - [Flex] pin is a pin that can be used as an input and output pin. -//! - [any_pin::AnyPin] pin is type-erased that can be used for peripherals -//! signals. -//! - It supports inverting the pin, so the peripheral signal can be -//! inverted. +//! - [AnyPin] and [AnyInputOnlyPin] are type-erased GPIO pins with support +//! for inverted signalling. +//! - [DummyPin] is a useful for cases where peripheral driver requires a pin, +//! but real pin cannot be used. //! //! ## Examples //! ### Set up a GPIO as an Output @@ -67,8 +67,11 @@ use crate::{ #[cfg(touch)] pub(crate) use crate::{touch_common, touch_into}; -pub mod any_pin; -pub mod dummy_pin; +mod any_pin; +mod dummy_pin; + +pub use any_pin::{AnyInputOnlyPin, AnyPin}; +pub use dummy_pin::DummyPin; #[cfg(soc_etm)] pub mod etm; diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index 8965db86e21..c0c05fd3fb5 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -90,7 +90,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::uart::{config::Config, Uart}; -//! use esp_hal::gpio::{Io, any_pin::AnyPin}; +//! use esp_hal::gpio::{AnyPin, Io}; //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! let tx = AnyPin::new_inverted(io.pins.gpio1); @@ -103,7 +103,7 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::uart::{config::Config, UartTx, UartRx}; -//! use esp_hal::gpio::{Io, any_pin::AnyPin}; +//! use esp_hal::gpio::{AnyPin, Io}; //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! let tx = UartTx::new(peripherals.UART0, &clocks, diff --git a/examples/src/bin/spi_loopback.rs b/examples/src/bin/spi_loopback.rs index 735321644a1..6c8432592b2 100644 --- a/examples/src/bin/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -22,7 +22,7 @@ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, delay::Delay, - gpio::{any_pin::AnyPin, Io}, + gpio::{AnyPin, Io}, peripherals::Peripherals, prelude::*, spi::{master::Spi, SpiMode}, diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index a9acca00f6f..a27ab177b0a 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -15,7 +15,7 @@ use critical_section::Mutex; use esp_hal::{ clock::ClockControl, delay::Delay, - gpio::{any_pin::AnyPin, Gpio2, Gpio3, GpioPin, Input, Io, Level, Output, Pull}, + gpio::{AnyPin, Gpio2, Gpio3, GpioPin, Input, Io, Level, Output, Pull}, macros::handler, peripherals::Peripherals, system::SystemControl, diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index 1189bbaab69..42563ad107e 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -9,7 +9,7 @@ use esp_hal::{ clock::{ClockControl, Clocks}, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, - gpio::dummy_pin::DummyPin, + gpio::DummyPin, lcd_cam::{ lcd::{ i8080, diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index cc57f291ab7..11506498a56 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -9,7 +9,7 @@ use esp_hal::{ clock::{ClockControl, Clocks}, dma::{Dma, DmaDescriptor, DmaPriority}, dma_buffers, - gpio::dummy_pin::DummyPin, + gpio::DummyPin, lcd_cam::{ lcd::{ i8080,