Skip to content

Commit

Permalink
Remove the GPIO peripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 9, 2024
1 parent e811152 commit da53932
Show file tree
Hide file tree
Showing 120 changed files with 127 additions and 347 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SPI transactions are now cancelled if the transfer object (or async Future) is dropped. (#2216)
- The DMA channel types have been removed from peripherals (#2261)
- `I2C` driver renamed to `I2c` (#2320)
- The GPIO pins are now accessible via `Peripherals` and are no longer part of the `Io` struct (#2508)

### Fixed

Expand Down Expand Up @@ -215,6 +216,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `esp_hal::spi::slave::WithDmaSpiN` traits (#2260)
- The `WithDmaAes` trait has been removed (#2261)
- The `I2s::new_i2s1` constructor has been removed (#2261)
- `Peripherals.GPIO` has been removed (#2508)

## [0.20.1] - 2024-08-30

Expand Down
18 changes: 18 additions & 0 deletions esp-hal/MIGRATING-0.21.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Migration Guide from 0.21.x to v0.22.x

## IO changes

### GPIO pins are now accessible via `Peripherals`

```diff
let peripherals = esp_hal::init(Default::default());
-let io = Io::new(peripherals.GPIO, peripherals.IOMUX);
-let pin = io.pins.gpio5;
+let pin = peripherals.pins.gpio5;
```

### `Io` constructor changes

- `new_with_priority` and `new_no_bind_interrupts` have been removed.
Use `set_priority` to configure the GPIO interrupt priority.
We no longer overwrite interrupt handlers set by user code during initialization.
- `new` no longer takes `peripherals.GPIO`

## Removed `async`-specific constructors

The following async-specific constuctors have been removed:
Expand Down
7 changes: 4 additions & 3 deletions esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
//! # use esp_hal::analog::adc::Attenuation;
//! # use esp_hal::analog::adc::Adc;
//! # use esp_hal::delay::Delay;
//! # use esp_hal::gpio::Io;
//! # let io = Io::new(peripherals.IO_MUX);
#![cfg_attr(esp32, doc = "let analog_pin = peripherals.pins.gpio32;")]
#![cfg_attr(any(esp32s2, esp32s3), doc = "let analog_pin = peripherals.pins.gpio3;")]
#![cfg_attr(
any(esp32s2, esp32s3),
doc = "let analog_pin = peripherals.pins.gpio3;"
)]
#![cfg_attr(
not(any(esp32, esp32s2, esp32s3)),
doc = "let analog_pin = peripherals.pins.gpio2;"
Expand Down
3 changes: 0 additions & 3 deletions esp-hal/src/analog/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
//! ### Write a value to a DAC channel
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::Io;
//! # use esp_hal::analog::dac::Dac;
//! # use esp_hal::delay::Delay;
//! # use embedded_hal::delay::DelayNs;
//!
//! let io = Io::new(peripherals.IO_MUX);
#![cfg_attr(esp32, doc = "let dac1_pin = peripherals.pins.gpio25;")]
#![cfg_attr(esp32s2, doc = "let dac1_pin = peripherals.pins.gpio17;")]
//! let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin);
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::dma_buffers;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::spi::{master::{Config, Spi}, SpiMode};
//! # use esp_hal::dma::{Dma, DmaPriority};
//! let dma = Dma::new(peripherals.DMA);
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")]
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
//! let io = Io::new(peripherals.IO_MUX);
//! let sclk = peripherals.pins.gpio0;
//! let miso = peripherals.pins.gpio2;
//! let mosi = peripherals.pins.gpio4;
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/etm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
//! ## Examples
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::Io;
//! # use esp_hal::gpio::etm::{Channels, InputConfig, OutputConfig};
//! # use esp_hal::etm::Etm;
//! # use esp_hal::gpio::Pull;
//! # use esp_hal::gpio::Level;
//!
//! let io = Io::new(peripherals.IO_MUX);
//! let mut led = peripherals.pins.gpio1;
//! let button = peripherals.pins.gpio9;
//!
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/gpio/etm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
//! ### Toggle an LED When a Button is Pressed
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::Io;
//! # use esp_hal::gpio::etm::Channels;
//! # use esp_hal::etm::Etm;
//! # use esp_hal::gpio::etm::InputConfig;
//! # use esp_hal::gpio::etm::OutputConfig;
//! # use esp_hal::gpio::Pull;
//! # use esp_hal::gpio::Level;
//! #
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut led = peripherals.pins.gpio1;
//! # let button = peripherals.pins.gpio9;
//!
Expand Down
7 changes: 4 additions & 3 deletions esp-hal/src/gpio/lp_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
//! chip from Deep-sleep.
//!
//! # Example
//!
//! ## Configure a LP Pin as Output
//!
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! use esp_hal::gpio::Io;
//! use esp_hal::gpio::lp_io::LowPowerOutput;
//! let io = Io::new(peripherals.IO_MUX);
//! // configure GPIO 1 as LP output pin
//! let lp_pin: LowPowerOutput<'_, 1> =
//! LowPowerOutput::new(peripherals.pins.gpio1); # }
//! LowPowerOutput::new(peripherals.pins.gpio1);
//! # }
//! ```
use core::marker::PhantomData;
Expand Down
7 changes: 3 additions & 4 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! GPIO interrupts. For more information, see the
//! [`Io::set_interrupt_handler`].
//!
//! The pins are accessible via [`Io::pins`]. These pins can then be passed to
//! peripherals (such as SPI, UART, I2C, etc.), to pin drivers or can be
//! [`GpioPin::split`] into peripheral signals.
//! The pins are accessible via [`crate::Peripherals::pins`]. These pins can
//! then be passed to peripherals (such as SPI, UART, I2C, etc.), to pin drivers
//! or can be [`GpioPin::split`] into peripheral signals.
//!
//! Each pin is a different type initially. Internally, `esp-hal` will often
//! erase their types automatically, but they can also be converted into
Expand Down Expand Up @@ -52,7 +52,6 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::{Io, Level, Output};
//! let io = Io::new(peripherals.IO_MUX);
//! let mut led = Output::new(peripherals.pins.gpio5, Level::High);
//! # }
//! ```
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/gpio/rtc_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::rtc_io::LowPowerOutput;
//! # use esp_hal::gpio::Io;
//! let io = Io::new(peripherals.IO_MUX);
//! // configure GPIO 1 as ULP output pin
//! let lp_pin = LowPowerOutput::<'static, 1>::new(peripherals.pins.gpio1);
//! # }
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::i2c::master::{Config, I2c};
//! # use esp_hal::gpio::Io;
//!
//! // Create a new peripheral object with the described wiring
//! // and standard I2C clock speed.
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/i2s/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::i2s::master::{I2s, Standard, DataFormat};
//! # use esp_hal::gpio::Io;
//! # use esp_hal::dma_buffers;
//! # use esp_hal::dma::{Dma, DmaPriority};
//! # let io = Io::new(peripherals.IO_MUX);
//! let dma = Dma::new(peripherals.DMA);
#![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")]
#![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")]
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/lcd_cam/cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
//! master mode.
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::Io;
//! # use esp_hal::lcd_cam::{cam::{Camera, RxEightBits}, LcdCam};
//! # use fugit::RateExtU32;
//! # use esp_hal::dma_rx_stream_buffer;
//! # use esp_hal::dma::{Dma, DmaPriority};
//! # let io = Io::new(peripherals.IO_MUX);
//!
//! # let dma = Dma::new(peripherals.DMA);
//! # let channel = dma.channel0;
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/lcd_cam/lcd/i8080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
//!
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::Io;
//! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}};
//! # use esp_hal::dma_tx_buffer;
//! # use esp_hal::dma::{Dma, DmaPriority, DmaTxBuf};
//! # let io = Io::new(peripherals.IO_MUX);
//!
//! # let dma = Dma::new(peripherals.DMA);
//! # let channel = dma.channel0;
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
//! # use esp_hal::ledc::timer;
//! # use esp_hal::ledc::LowSpeed;
//! # use esp_hal::ledc::channel;
//! # use esp_hal::gpio::Io;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let led = peripherals.pins.gpio0;
//!
//! let mut ledc = Ledc::new(peripherals.LEDC);
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
//! });
//!
//! // Set GPIO0 as an output, and set its state high initially.
//! let io = Io::new(peripherals.IO_MUX);
//! let mut led = Output::new(peripherals.pins.gpio0, Level::High);
//!
//! let delay = Delay::new();
Expand Down
3 changes: 0 additions & 3 deletions esp-hal/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::mcpwm::{operator::{DeadTimeCfg, PWMStream, PwmPinConfig}, timer::PwmWorkingMode, McPwm, PeripheralClockConfig};
//! # use esp_hal::gpio::Io;
//!
//! # let io = Io::new(peripherals.IO_MUX);
//! # let pin = peripherals.pins.gpio0;
//!
//! // initialize peripheral
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/mcpwm/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ impl<PWM: PwmPeripheral, const OP: u8, const IS_A: bool> embedded_hal::pwm::SetD
/// # use esp_hal::{mcpwm, prelude::*};
/// # use esp_hal::mcpwm::{McPwm, PeripheralClockConfig};
/// # use esp_hal::mcpwm::operator::{DeadTimeCfg, PwmPinConfig, PWMStream};
/// # use esp_hal::gpio::Io;
/// # let io = Io::new(peripherals.IO_MUX);
/// // active high complementary using PWMA input
/// let bridge_active = DeadTimeCfg::new_ahc();
/// // use PWMB as input for both outputs
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
//! # use esp_hal::peripherals::Peripherals;
//! # use esp_hal::rmt::TxChannelConfig;
//! # use esp_hal::rmt::Rmt;
//! # use esp_hal::gpio::Io;
//! # use crate::esp_hal::rmt::TxChannelCreator;
//! # let io = Io::new(peripherals.IO_MUX);
#![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")]
#![cfg_attr(not(esp32h2), doc = "let freq = 80.MHz();")]
//! let rmt = Rmt::new(peripherals.RMT, freq).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ impl rand_core::RngCore for Rng {
/// # use esp_hal::peripherals::Peripherals;
/// # use esp_hal::peripherals::ADC1;
/// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc};
/// # use esp_hal::gpio::Io;
///
/// let io = Io::new(peripherals.IO_MUX);
/// let mut buf = [0u8; 16];
///
/// // ADC is not available from now
Expand All @@ -152,10 +150,12 @@ impl rand_core::RngCore for Rng {
#[cfg_attr(esp32, doc = "let analog_pin = peripherals.pins.gpio32;")]
#[cfg_attr(not(esp32), doc = "let analog_pin = peripherals.pins.gpio3;")]
/// let mut adc1_config = AdcConfig::new();
/// let mut adc1_pin = adc1_config.enable_pin(analog_pin,
/// Attenuation::Attenuation11dB); let mut adc1 =
/// Adc::<ADC1>::new(peripherals.ADC1, adc1_config); let pin_value: u16 =
/// nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
/// let mut adc1_pin = adc1_config.enable_pin(
/// analog_pin,
/// Attenuation::Attenuation11dB
/// );
/// let mut adc1 = Adc::<ADC1>::new(peripherals.ADC1, adc1_config);
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
/// rng.read(&mut buf);
/// true_rand = rng.random();
/// let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
Expand Down
4 changes: 0 additions & 4 deletions esp-hal/src/rom/md5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
#![doc = crate::before_snippet!()]
//! # use esp_hal::rom::md5;
//! # use esp_hal::uart::Uart;
//! # use esp_hal::gpio::Io;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, peripherals.pins.gpio1, peripherals.pins.gpio2).unwrap();
//! # let data = "Dummy";
//! let d: md5::Digest = md5::compute(&data);
Expand All @@ -48,10 +46,8 @@
#![doc = crate::before_snippet!()]
//! # use esp_hal::rom::md5;
//! # use esp_hal::uart::Uart;
//! # use esp_hal::gpio::Io;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, peripherals.pins.gpio1, peripherals.pins.gpio2).unwrap();
//! # let data0 = "Dummy";
//! # let data1 = "Dummy";
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::uart::Uart;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, peripherals.pins.gpio4, peripherals.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address();
//! writeln!(
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/soc/esp32/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ crate::peripherals! {
EFUSE <= EFUSE,
FLASH_ENCRYPTION <= FLASH_ENCRYPTION,
FRC_TIMER <= FRC_TIMER,
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HINF <= HINF,
I2C0 <= I2C0,
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32c2/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::uart::Uart;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, peripherals.pins.gpio4, peripherals.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address();
//! writeln!(
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/soc/esp32c2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ crate::peripherals! {
ECC <= ECC,
EFUSE <= EFUSE,
EXTMEM <= EXTMEM,
GPIO <= GPIO (GPIO,GPIO_NMI),
I2C0 <= I2C0,
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32c3/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::uart::Uart;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, peripherals.pins.gpio4, peripherals.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address();
//! writeln!(
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/soc/esp32c3/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ crate::peripherals! {
DS <= DS,
EFUSE <= EFUSE,
EXTMEM <= EXTMEM,
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HMAC <= HMAC,
I2C0 <= I2C0,
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32c6/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::uart::Uart;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, peripherals.pins.gpio4, peripherals.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address();
//! writeln!(
Expand Down
1 change: 0 additions & 1 deletion esp-hal/src/soc/esp32c6/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ crate::peripherals! {
ECC <= ECC,
EFUSE <= EFUSE,
EXTMEM <= EXTMEM,
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HINF <= HINF,
HMAC <= HMAC,
Expand Down
2 changes: 0 additions & 2 deletions esp-hal/src/soc/esp32h2/efuse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
//! ```rust, no_run
#![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse;
//! # use esp_hal::gpio::Io;
//! # use esp_hal::uart::Uart;
//! # use core::writeln;
//! # use core::fmt::Write;
//! # let io = Io::new(peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, peripherals.pins.gpio4, peripherals.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address();
//! writeln!(
Expand Down
Loading

0 comments on commit da53932

Please sign in to comment.