From 76885042895d1aaad611672b5d55c99c575ba762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Wed, 4 Sep 2024 15:37:56 +0200 Subject: [PATCH] Remove Gpio type aliasses (#2073) * Remove Gpio type aliasses * Clean up examples --- esp-hal/CHANGELOG.md | 1 + esp-hal/MIGRATING-0.20.md | 4 +++ esp-hal/src/analog/adc/esp32.rs | 36 +++++++++++------------ esp-hal/src/analog/adc/mod.rs | 6 ++-- esp-hal/src/analog/adc/riscv.rs | 46 +++++++++++++++--------------- esp-hal/src/analog/adc/xtensa.rs | 40 +++++++++++++------------- esp-hal/src/analog/dac.rs | 8 +++--- esp-hal/src/gpio/mod.rs | 7 +---- esp-hal/src/soc/esp32s2/gpio.rs | 4 +-- esp-hal/src/soc/esp32s3/gpio.rs | 4 +-- esp-hal/src/uart.rs | 28 +++++++++--------- examples/src/bin/embassy_rmt_rx.rs | 4 +-- examples/src/bin/gpio_interrupt.rs | 8 ++++-- examples/src/bin/spi_slave_dma.rs | 10 +++---- examples/src/bin/touch.rs | 5 ++-- 15 files changed, 106 insertions(+), 105 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 8a9f8a01f82..5935c60c46c 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed `NoPinType` in favour of `DummyPin`. (#2068) - Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070) +- Removed the `GpioN` type aliasses. Use `GpioPin` instead. (#2073) ## [0.20.1] - 2024-08-30 diff --git a/esp-hal/MIGRATING-0.20.md b/esp-hal/MIGRATING-0.20.md index c7a836fcdd8..7a42dd6fb9e 100644 --- a/esp-hal/MIGRATING-0.20.md +++ b/esp-hal/MIGRATING-0.20.md @@ -35,3 +35,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c // ... } ``` + +## GPIO changes + +The `GpioN` type aliasses are no longer available. You can use `GpioPin` instead. diff --git a/esp-hal/src/analog/adc/esp32.rs b/esp-hal/src/analog/adc/esp32.rs index 585e27f75c7..4bacea253d0 100644 --- a/esp-hal/src/analog/adc/esp32.rs +++ b/esp-hal/src/analog/adc/esp32.rs @@ -359,29 +359,29 @@ where mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio36, 0), // Alt. name: SENSOR_VP - (Gpio37, 1), // Alt. name: SENSOR_CAPP - (Gpio38, 2), // Alt. name: SENSOR_CAPN - (Gpio39, 3), // Alt. name: SENSOR_VN - (Gpio33, 4), // Alt. name: 32K_XP - (Gpio32, 5), // Alt. name: 32K_XN - (Gpio34, 6), // Alt. name: VDET_1 - (Gpio35, 7), // Alt. name: VDET_2 + (GpioPin<36>, 0), // Alt. name: SENSOR_VP + (GpioPin<37>, 1), // Alt. name: SENSOR_CAPP + (GpioPin<38>, 2), // Alt. name: SENSOR_CAPN + (GpioPin<39>, 3), // Alt. name: SENSOR_VN + (GpioPin<33>, 4), // Alt. name: 32K_XP + (GpioPin<32>, 5), // Alt. name: 32K_XN + (GpioPin<34>, 6), // Alt. name: VDET_1 + (GpioPin<35>, 7), // Alt. name: VDET_2 ] } crate::analog::adc::impl_adc_interface! { ADC2 [ - (Gpio4, 0), - (Gpio0, 1), - (Gpio2, 2), - (Gpio15, 3), // Alt. name: MTDO - (Gpio13, 4), // Alt. name: MTCK - (Gpio12, 5), // Alt. name: MTDI - (Gpio14, 6), // Alt. name: MTMS - (Gpio27, 7), - (Gpio25, 8), - (Gpio26, 9), + (GpioPin<4>, 0), + (GpioPin<0>, 1), + (GpioPin<2>, 2), + (GpioPin<15>, 3), // Alt. name: MTDO + (GpioPin<13>, 4), // Alt. name: MTCK + (GpioPin<12>, 5), // Alt. name: MTDI + (GpioPin<14>, 6), // Alt. name: MTMS + (GpioPin<27>, 7), + (GpioPin<25>, 8), + (GpioPin<26>, 9), ] } } diff --git a/esp-hal/src/analog/adc/mod.rs b/esp-hal/src/analog/adc/mod.rs index 417f0f70077..f9a53fce2a4 100644 --- a/esp-hal/src/analog/adc/mod.rs +++ b/esp-hal/src/analog/adc/mod.rs @@ -252,14 +252,14 @@ trait AdcCalEfuse { macro_rules! impl_adc_interface { ($adc:ident [ - $( ($pin:ident, $channel:expr) ,)+ + $( (GpioPin<$pin:literal>, $channel:expr) ,)+ ]) => { $( - impl $crate::analog::adc::AdcChannel for crate::gpio::$pin { + impl $crate::analog::adc::AdcChannel for crate::gpio::GpioPin<$pin> { const CHANNEL: u8 = $channel; } - impl embedded_hal_02::adc::Channel for crate::gpio::$pin { + impl embedded_hal_02::adc::Channel for crate::gpio::GpioPin<$pin> { type ID = u8; fn channel() -> u8 { $channel } diff --git a/esp-hal/src/analog/adc/riscv.rs b/esp-hal/src/analog/adc/riscv.rs index 1f91eef0265..b25eaa2fc86 100644 --- a/esp-hal/src/analog/adc/riscv.rs +++ b/esp-hal/src/analog/adc/riscv.rs @@ -548,11 +548,11 @@ where mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio0, 0), - (Gpio1, 1), - (Gpio2, 2), - (Gpio3, 3), - (Gpio4, 4), + (GpioPin<0>, 0), + (GpioPin<1>, 1), + (GpioPin<2>, 2), + (GpioPin<3>, 3), + (GpioPin<4>, 4), ] } } @@ -561,17 +561,17 @@ mod adc_implementation { mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio0, 0), - (Gpio1, 1), - (Gpio2, 2), - (Gpio3, 3), - (Gpio4, 4), + (GpioPin<0>, 0), + (GpioPin<1>, 1), + (GpioPin<2>, 2), + (GpioPin<3>, 3), + (GpioPin<4>, 4), ] } crate::analog::adc::impl_adc_interface! { ADC2 [ - (Gpio5, 0), + (GpioPin<5>, 0), ] } } @@ -580,13 +580,13 @@ mod adc_implementation { mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio0, 0), - (Gpio1, 1), - (Gpio2, 2), - (Gpio3, 3), - (Gpio4, 4), - (Gpio5, 5), - (Gpio6, 6), + (GpioPin<0>, 0), + (GpioPin<1>, 1), + (GpioPin<2>, 2), + (GpioPin<3>, 3), + (GpioPin<4>, 4), + (GpioPin<5>, 5), + (GpioPin<6>, 6), ] } } @@ -595,11 +595,11 @@ mod adc_implementation { mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio1, 0), - (Gpio2, 1), - (Gpio3, 2), - (Gpio4, 3), - (Gpio5, 4), + (GpioPin<1>, 0), + (GpioPin<2>, 1), + (GpioPin<3>, 2), + (GpioPin<4>, 3), + (GpioPin<5>, 4), ] } } diff --git a/esp-hal/src/analog/adc/xtensa.rs b/esp-hal/src/analog/adc/xtensa.rs index 215d0815ba5..bc9d6ef3202 100644 --- a/esp-hal/src/analog/adc/xtensa.rs +++ b/esp-hal/src/analog/adc/xtensa.rs @@ -607,31 +607,31 @@ where mod adc_implementation { crate::analog::adc::impl_adc_interface! { ADC1 [ - (Gpio1, 0), - (Gpio2, 1), - (Gpio3, 2), - (Gpio4, 3), - (Gpio5, 4), - (Gpio6, 5), - (Gpio7, 6), - (Gpio8, 7), - (Gpio9, 8), - (Gpio10, 9), + (GpioPin<1>, 0), + (GpioPin<2>, 1), + (GpioPin<3>, 2), + (GpioPin<4>, 3), + (GpioPin<5>, 4), + (GpioPin<6>, 5), + (GpioPin<7>, 6), + (GpioPin<8>, 7), + (GpioPin<9>, 8), + (GpioPin<10>, 9), ] } crate::analog::adc::impl_adc_interface! { ADC2 [ - (Gpio11, 0), - (Gpio12, 1), - (Gpio13, 2), - (Gpio14, 3), - (Gpio15, 4), - (Gpio16, 5), - (Gpio17, 6), - (Gpio18, 7), - (Gpio19, 8), - (Gpio20, 9), + (GpioPin<11>, 0), + (GpioPin<12>, 1), + (GpioPin<13>, 2), + (GpioPin<14>, 3), + (GpioPin<15>, 4), + (GpioPin<16>, 5), + (GpioPin<17>, 6), + (GpioPin<18>, 7), + (GpioPin<19>, 8), + (GpioPin<20>, 9), ] } } diff --git a/esp-hal/src/analog/dac.rs b/esp-hal/src/analog/dac.rs index d0244c4ba9a..9b5f64e7caa 100644 --- a/esp-hal/src/analog/dac.rs +++ b/esp-hal/src/analog/dac.rs @@ -51,11 +51,11 @@ use crate::{ // reason, we will type alias the pins for ease of use later in this module: cfg_if::cfg_if! { if #[cfg(esp32)] { - type Dac1Gpio = gpio::Gpio25; - type Dac2Gpio = gpio::Gpio26; + type Dac1Gpio = gpio::GpioPin<25>; + type Dac2Gpio = gpio::GpioPin<26>; } else if #[cfg(esp32s2)] { - type Dac1Gpio = gpio::Gpio17; - type Dac2Gpio = gpio::Gpio18; + type Dac1Gpio = gpio::GpioPin<17>; + type Dac2Gpio = gpio::GpioPin<18>; } } diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index fef1fe145f6..4db777a39d0 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -1418,15 +1418,10 @@ macro_rules! gpio { )+ } - $( - #[doc = concat!("Alias for GpioPin")] - pub type [] = GpioPin<$gpionum>; - )+ - #[doc(hidden)] pub enum ErasedPin { $( - []([]), + [](GpioPin<$gpionum>), )+ } diff --git a/esp-hal/src/soc/esp32s2/gpio.rs b/esp-hal/src/soc/esp32s2/gpio.rs index 70e02fc2d8b..3b5d3daac12 100644 --- a/esp-hal/src/soc/esp32s2/gpio.rs +++ b/esp-hal/src/soc/esp32s2/gpio.rs @@ -443,5 +443,5 @@ impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank1 { } // implement marker traits on USB pins -impl crate::otg_fs::UsbDm for Gpio19 {} -impl crate::otg_fs::UsbDp for Gpio20 {} +impl crate::otg_fs::UsbDm for GpioPin<19> {} +impl crate::otg_fs::UsbDp for GpioPin<20> {} diff --git a/esp-hal/src/soc/esp32s3/gpio.rs b/esp-hal/src/soc/esp32s3/gpio.rs index 0810f29c71d..9cf339f1bd6 100644 --- a/esp-hal/src/soc/esp32s3/gpio.rs +++ b/esp-hal/src/soc/esp32s3/gpio.rs @@ -493,5 +493,5 @@ impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank1 { } // implement marker traits on USB pins -impl crate::otg_fs::UsbDm for Gpio19 {} -impl crate::otg_fs::UsbDp for Gpio20 {} +impl crate::otg_fs::UsbDm for GpioPin<19> {} +impl crate::otg_fs::UsbDp for GpioPin<20> {} diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index f1cb5425138..5427a2f8668 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -161,59 +161,59 @@ cfg_if::cfg_if! { if #[cfg(esp32)] { /// Default TX pin for UART0 on ESP32. /// Corresponds to GPIO1. - pub type DefaultTxPin = crate::gpio::Gpio1; + pub type DefaultTxPin = crate::gpio::GpioPin<1>; /// Default RX pin for UART0 on ESP32. /// Corresponds to GPIO3. - pub type DefaultRxPin = crate::gpio::Gpio3; + pub type DefaultRxPin = crate::gpio::GpioPin<3>; } else if #[cfg(esp32c2)] { /// Default TX pin for UART0 on ESP32-C2. /// Corresponds to GPIO20. - pub type DefaultTxPin = crate::gpio::Gpio20; + pub type DefaultTxPin = crate::gpio::GpioPin<20>; /// Default RX pin for UART0 on ESP32-C2. /// Corresponds to GPIO19. - pub type DefaultRxPin = crate::gpio::Gpio19; + pub type DefaultRxPin = crate::gpio::GpioPin<19>; } else if #[cfg(esp32c3)] { /// Default TX pin for UART0 on ESP32-C3. /// Corresponds to GPIO21. - pub type DefaultTxPin = crate::gpio::Gpio21; + pub type DefaultTxPin = crate::gpio::GpioPin<21>; /// Default RX pin for UART0 on ESP32-C3. /// Corresponds to GPIO20. - pub type DefaultRxPin = crate::gpio::Gpio20; + pub type DefaultRxPin = crate::gpio::GpioPin<20>; } else if #[cfg(esp32c6)] { /// Default TX pin for UART0 on ESP32-C6. /// Corresponds to GPIO16. - pub type DefaultTxPin = crate::gpio::Gpio16; + pub type DefaultTxPin = crate::gpio::GpioPin<16>; /// Default RX pin for UART0 on ESP32-C6. /// Corresponds to GPIO17. - pub type DefaultRxPin = crate::gpio::Gpio17; + pub type DefaultRxPin = crate::gpio::GpioPin<17>; } else if #[cfg(esp32h2)] { /// Default TX pin for UART0 on ESP32-H2. /// Corresponds to GPIO24. - pub type DefaultTxPin = crate::gpio::Gpio24; + pub type DefaultTxPin = crate::gpio::GpioPin<24>; /// Default RX pin for UART0 on ESP32-H2. /// Corresponds to GPIO23. - pub type DefaultRxPin = crate::gpio::Gpio23; + pub type DefaultRxPin = crate::gpio::GpioPin<23>; } else if #[cfg(esp32s2)] { /// Default TX pin for UART0 on ESP32-S2. /// Corresponds to GPIO43. - pub type DefaultTxPin = crate::gpio::Gpio43; + pub type DefaultTxPin = crate::gpio::GpioPin<43>; /// Default RX pin for UART0 on ESP32-S2. /// Corresponds to GPIO44. - pub type DefaultRxPin = crate::gpio::Gpio44; + pub type DefaultRxPin = crate::gpio::GpioPin<44>; } else if #[cfg(esp32s3)] { /// Default TX pin for UART0 on ESP32-S3. /// Corresponds to GPIO43. - pub type DefaultTxPin = crate::gpio::Gpio43; + pub type DefaultTxPin = crate::gpio::GpioPin<43>; /// Default RX pin for UART0 on ESP32-S3. /// Corresponds to GPIO44. - pub type DefaultRxPin = crate::gpio::Gpio44; + pub type DefaultRxPin = crate::gpio::GpioPin<44>; } } diff --git a/examples/src/bin/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs index 86d299a9e35..ef42cd4c108 100644 --- a/examples/src/bin/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -13,7 +13,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - gpio::{Gpio5, Io, Level, Output}, + gpio::{GpioPin, Io, Level, Output}, prelude::*, rmt::{asynch::RxChannelAsync, PulseCode, Rmt, RxChannelConfig, RxChannelCreatorAsync}, timer::timg::TimerGroup, @@ -26,7 +26,7 @@ const WIDTH: usize = 80; compile_error!("Run this example in release mode"); #[embassy_executor::task] -async fn signal_task(mut pin: Output<'static, Gpio5>) { +async fn signal_task(mut pin: Output<'static, GpioPin<5>>) { loop { for _ in 0..10 { pin.toggle(); diff --git a/examples/src/bin/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs index 2e7a60fe36c..b7675744a5c 100644 --- a/examples/src/bin/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -17,19 +17,21 @@ use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ delay::Delay, - gpio::{self, Event, Input, Io, Level, Output, Pull}, + gpio::{Event, GpioPin, Input, Io, Level, Output, Pull}, macros::ram, prelude::*, }; cfg_if::cfg_if! { if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] { - static BUTTON: Mutex>>> = Mutex::new(RefCell::new(None)); + const BUTTON_PIN: u8 = 0; } else { - static BUTTON: Mutex>>> = Mutex::new(RefCell::new(None)); + const BUTTON_PIN: u8 = 9; } } +static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); + #[entry] fn main() -> ! { let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index f821c49f168..8bc10a458fa 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -34,7 +34,7 @@ use esp_hal::{ delay::Delay, dma::{Dma, DmaPriority}, dma_buffers, - gpio::{Gpio4, Gpio5, Gpio8, Gpio9, Input, Io, Level, Output, Pull}, + gpio::{GpioPin, Input, Io, Level, Output, Pull}, prelude::*, spi::{ slave::{prelude::*, Spi}, @@ -189,10 +189,10 @@ fn main() -> ! { fn bitbang_master( master_send: &[u8], master_receive: &mut [u8], - master_cs: &mut Output, - master_mosi: &mut Output, - master_sclk: &mut Output, - master_miso: &Input, + master_cs: &mut Output>, + master_mosi: &mut Output>, + master_sclk: &mut Output>, + master_miso: &Input>, ) { // 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 diff --git a/examples/src/bin/touch.rs b/examples/src/bin/touch.rs index eef73f705d0..0e7b6ae8db3 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -17,8 +17,7 @@ use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ delay::Delay, - gpio, - gpio::Io, + gpio::{GpioPin, Io}, macros::ram, prelude::*, rtc_cntl::Rtc, @@ -27,7 +26,7 @@ use esp_hal::{ }; use esp_println::println; -static TOUCH1: Mutex>>> = +static TOUCH1: Mutex, Continous, Blocking>>>> = Mutex::new(RefCell::new(None)); #[handler]