From d6813a4bf0b643c58fc9e195be1dadde4b52d361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Fri, 6 Sep 2024 12:26:23 +0200 Subject: [PATCH] Random additional GPIO cleanups, implement Peripheral for drivers (#2094) * Reuse enable_iomux_clk_gate * Remove public functions * Remove set_to_input * Deduplicate constructor * Deduplicate is_listening * Hide PinFuture better * Deduplicate set_int_enable * Align macro indentation * Typo * Slightly simplify the touch_into macro * Implement the AnalogPin trait directly * Provide default impls for simple forwarding methods * Newtype ErasedPin * Merge rtc_pin macros * Fmt * Changelog * Fix migration guide * Fix example * Fix ETM --- esp-hal/CHANGELOG.md | 11 +- esp-hal/src/gpio/any_pin.rs | 22 - esp-hal/src/gpio/dummy_pin.rs | 2 - esp-hal/src/gpio/mod.rs | 698 ++++++++++++-------------------- esp-hal/src/i2s.rs | 2 +- esp-hal/src/lcd_cam/cam.rs | 60 +-- esp-hal/src/parl_io.rs | 9 +- esp-hal/src/peripheral.rs | 6 +- esp-hal/src/rmt.rs | 4 +- esp-hal/src/soc/esp32/gpio.rs | 114 +++--- esp-hal/src/soc/esp32s3/gpio.rs | 44 +- esp-hal/src/spi/master.rs | 4 +- esp-hal/src/spi/slave.rs | 6 +- esp-hal/src/touch.rs | 32 +- esp-hal/src/twai/mod.rs | 2 +- esp-hal/src/uart.rs | 16 +- examples/src/bin/etm_gpio.rs | 3 +- examples/src/bin/i2s_read.rs | 2 +- examples/src/bin/rmt_rx.rs | 4 +- examples/src/bin/touch.rs | 6 +- 20 files changed, 436 insertions(+), 611 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index abaab00a3..ed8c4f754 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -15,31 +15,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added missing functions to `Flex`: `unlisten`, `is_interrupt_set`, `wakeup_enable`, `wait_for_high`, `wait_for_low`, `wait_for_rising_edge`, `wait_for_falling_edge`, `wait_for_any_edge`. (#2075) - `Flex` now implements `Wait`. (#2075) - Added sleep and wakeup support for esp32c2 (#1922) +- `Input`, `Output`, `OutputOpenDrain` and `Flex` now implement `Peripheral`. (#2094) ### Changed + - Make saving and restoring SHA digest state an explicit operation (#2049) - Reordered RX-TX pairs in all APIs to be consistent (#2074) - +- Make saving and restoring SHA digest state an explicit operation (#2049) - `Delay::new()` is now a `const` function (#1999) - You can now create an `AnyPin` out of an `ErasedPin`. (#2072) - `Input`, `Output`, `OutputOpenDrain` and `Flex` are now type-erased by default. Use the new `new_typed` constructor to keep using the ZST pin types. (#2075) - To avoid confusion with the `Rtc::current_time` wall clock time APIs, we've renamed `esp_hal::time::current_time` to `esp_hal::time::now`. (#2091) +- Renamed `touch::Continous` to `touch::Continuous`. (#2094) +- The (previously undocumented) `ErasedPin` enum has been replaced with the `ErasedPin` struct. (#2094) ### Fixed -- SHA driver can now be safely used in multiple contexts concurrently (#2049) +- SHA driver can now be safely used in multiple contexts concurrently (#2049) - Fixed an issue with DMA transfers potentially not waking up the correct async task (#2065) - Fixed an issue with LCD_CAM i8080 where it would send double the clocks in 16bit mode (#2085) - Fix i2c embedded-hal transaction (#2028) ### Removed -- Removed `digest::Digest` implementation from SHA (#2049) +- Removed `digest::Digest` implementation from SHA (#2049) - 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) - Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999) - Removed `AnyInputOnlyPin` in favour of `AnyPin`. (#2071) +- Removed the following functions from `GpioPin`: `is_high`, `is_low`, `set_high`, `set_low`, `set_state`, `is_set_high`, `is_set_low`, `toggle`. (#2094) ## [0.20.1] - 2024-08-30 diff --git a/esp-hal/src/gpio/any_pin.rs b/esp-hal/src/gpio/any_pin.rs index f22203914..93c59da4d 100644 --- a/esp-hal/src/gpio/any_pin.rs +++ b/esp-hal/src/gpio/any_pin.rs @@ -78,7 +78,6 @@ impl<'d> Pin for AnyPin<'d> { fn unlisten(&mut self, _internal: private::Internal); fn is_interrupt_set(&self, _internal: private::Internal) -> bool; fn clear_interrupt(&mut self, _internal: private::Internal); - fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _internal: private::Internal); } } } @@ -102,17 +101,6 @@ impl<'d> OutputPin for AnyPin<'d> { } } - fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _internal: private::Internal) { - self.pin.connect_peripheral_to_output_with_options( - signal, - self.is_inverted, - false, - false, - self.is_inverted, - private::Internal, - ); - } - fn connect_peripheral_to_output_with_options( &mut self, signal: OutputSignal, @@ -148,7 +136,6 @@ impl<'d> InputPin for AnyPin<'d> { delegate::delegate! { to self.pin { fn init_input(&self, pull_down: bool, pull_up: bool, _internal: private::Internal); - fn set_to_input(&mut self, _internal: private::Internal); fn enable_input(&mut self, on: bool, _internal: private::Internal); fn enable_input_in_sleep_mode(&mut self, on: bool, _internal: private::Internal); fn is_input_high(&self, _internal: private::Internal) -> bool; @@ -156,15 +143,6 @@ impl<'d> InputPin for AnyPin<'d> { } } - fn connect_input_to_peripheral(&mut self, signal: InputSignal, _internal: private::Internal) { - self.pin.connect_input_to_peripheral_with_options( - signal, - self.is_inverted, - self.is_inverted, - private::Internal, - ); - } - fn connect_input_to_peripheral_with_options( &mut self, signal: InputSignal, diff --git a/esp-hal/src/gpio/dummy_pin.rs b/esp-hal/src/gpio/dummy_pin.rs index 5d319808a..0b79017aa 100644 --- a/esp-hal/src/gpio/dummy_pin.rs +++ b/esp-hal/src/gpio/dummy_pin.rs @@ -113,8 +113,6 @@ impl OutputPin for DummyPin { impl InputPin for DummyPin { fn init_input(&self, _pull_down: bool, _pull_up: bool, _: private::Internal) {} - fn set_to_input(&mut self, _: private::Internal) {} - fn enable_input(&mut self, _on: bool, _: private::Internal) {} fn enable_input_in_sleep_mode(&mut self, _on: bool, _: private::Internal) {} diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 210b827fd..f4db13a64 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -65,7 +65,7 @@ pub(crate) use crate::rtc_pins; pub use crate::soc::gpio::*; use crate::{ interrupt::InterruptHandler, - peripheral::PeripheralRef, + peripheral::{Peripheral, PeripheralRef}, peripherals::{GPIO, IO_MUX}, private, InterruptConfigurable, @@ -297,7 +297,9 @@ pub trait Pin: private::Sealed { } /// Checks if listening for interrupts is enabled for this Pin - fn is_listening(&self, _: private::Internal) -> bool; + fn is_listening(&self, _: private::Internal) -> bool { + is_listening(self.number(private::Internal)) + } /// Listen for interrupts fn listen_with_options( @@ -319,7 +321,9 @@ pub trait Pin: private::Sealed { fn clear_interrupt(&mut self, _: private::Internal); /// Enable this pin as a wake up source - fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _: private::Internal); + fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _: private::Internal) { + self.listen_with_options(event.into(), false, false, enable, private::Internal); + } } /// Trait implemented by pins which can be used as inputs @@ -327,9 +331,6 @@ pub trait InputPin: Pin { /// Init as input with the given pull-up/pull-down fn init_input(&self, pull_down: bool, pull_up: bool, _: private::Internal); - /// Set the pin to input mode without internal pull-up / pull-down resistors - fn set_to_input(&mut self, _: private::Internal); - /// Enable input for the pin fn enable_input(&mut self, on: bool, _: private::Internal); @@ -340,7 +341,9 @@ pub trait InputPin: Pin { fn is_input_high(&self, _: private::Internal) -> bool; /// Connect the pin to a peripheral input signal - fn connect_input_to_peripheral(&mut self, signal: InputSignal, _: private::Internal); + fn connect_input_to_peripheral(&mut self, signal: InputSignal, _: private::Internal) { + self.connect_input_to_peripheral_with_options(signal, false, false, private::Internal); + } /// Connect the pin to a peripheral input signal. /// @@ -398,7 +401,16 @@ pub trait OutputPin: Pin { fn internal_pull_down(&mut self, on: bool, _: private::Internal); /// Connect the pin to a peripheral output signal - fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _: private::Internal); + fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _: private::Internal) { + self.connect_peripheral_to_output_with_options( + signal, + false, + false, + false, + false, + private::Internal, + ) + } /// Connect the pin to a peripheral output signal. /// @@ -695,18 +707,6 @@ where Self::new() } - /// Is the input pin high? - #[inline] - pub fn is_high(&self) -> bool { - ::Bank::read_input() & (1 << (GPIONUM % 32)) != 0 - } - - /// Is the input pin low? - #[inline] - pub fn is_low(&self) -> bool { - !self.is_high() - } - fn write_out_en(&self, enable: bool) { if enable { ::Bank::write_out_en_set(1 << (GPIONUM % 32)); @@ -778,10 +778,6 @@ where }); } - fn set_to_input(&mut self, _: private::Internal) { - self.init_input(false, false, private::Internal); - } - fn enable_input(&mut self, on: bool, _: private::Internal) { get_io_mux_reg(GPIONUM).modify(|_, w| w.fun_ie().bit(on)); } @@ -791,11 +787,7 @@ where } fn is_input_high(&self, _: private::Internal) -> bool { - self.is_high() - } - - fn connect_input_to_peripheral(&mut self, signal: InputSignal, _: private::Internal) { - self.connect_input_to_peripheral_with_options(signal, false, false, private::Internal); + ::Bank::read_input() & (1 << (GPIONUM % 32)) != 0 } fn connect_input_to_peripheral_with_options( @@ -894,25 +886,12 @@ where } } - unsafe { - (*GPIO::PTR).pin(GPIONUM as usize).modify(|_, w| { - w.int_ena() - .bits(gpio_intr_enable(int_enable, nmi_enable)) - .int_type() - .bits(event as u8) - .wakeup_enable() - .bit(wake_up_from_light_sleep) - }); - } - } - - fn is_listening(&self, _: private::Internal) -> bool { - let bits = unsafe { &*GPIO::PTR } - .pin(GPIONUM as usize) - .read() - .int_ena() - .bits(); - bits != 0 + set_int_enable( + GPIONUM, + gpio_intr_enable(int_enable, nmi_enable), + event as u8, + wake_up_from_light_sleep, + ) } fn unlisten(&mut self, _: private::Internal) { @@ -930,13 +909,9 @@ where fn clear_interrupt(&mut self, _: private::Internal) { ::Bank::write_interrupt_status_clear(1 << (GPIONUM % 32)); } - - fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _: private::Internal) { - self.listen_with_options(event.into(), false, false, enable, private::Internal); - } } -impl crate::peripheral::Peripheral for GpioPin +impl Peripheral for GpioPin where Self: GpioProperties, { @@ -985,49 +960,6 @@ where .clear_bit() }); } - - /// Drives the pin high. - #[inline] - pub fn set_high(&mut self) { - ::Bank::write_output_set(1 << (GPIONUM % 32)); - } - - /// Drives the pin low. - #[inline] - pub fn set_low(&mut self) { - ::Bank::write_output_clear(1 << (GPIONUM % 32)); - } - - /// Drives the pin high or low depending on the provided value. - #[inline] - pub fn set_state(&mut self, state: bool) { - match state { - true => self.set_high(), - false => self.set_low(), - } - } - - /// Is the pin in drive high mode? - #[inline] - pub fn is_set_high(&self) -> bool { - ::Bank::read_output() & (1 << (GPIONUM % 32)) != 0 - } - - /// Is the pin in drive low mode? - #[inline] - pub fn is_set_low(&self) -> bool { - !self.is_set_high() - } - - /// Toggle pin output. - #[inline] - pub fn toggle(&mut self) { - if self.is_set_high() { - self.set_low(); - } else { - self.set_high(); - } - } } impl OutputPin for GpioPin @@ -1048,9 +980,9 @@ where fn set_output_high(&mut self, high: bool, _: private::Internal) { if high { - self.set_high() + ::Bank::write_output_set(1 << (GPIONUM % 32)); } else { - self.set_low() + ::Bank::write_output_clear(1 << (GPIONUM % 32)); } } @@ -1067,9 +999,11 @@ where fn internal_pull_up_in_sleep_mode(&mut self, on: bool, _: private::Internal) { get_io_mux_reg(GPIONUM).modify(|_, w| w.mcu_wpu().bit(on)); } + fn internal_pull_down_in_sleep_mode(&mut self, on: bool, _: private::Internal) { get_io_mux_reg(GPIONUM).modify(|_, w| w.mcu_wpd().bit(on)); } + fn enable_output_in_sleep_mode(&mut self, on: bool, _: private::Internal) { get_io_mux_reg(GPIONUM).modify(|_, w| w.mcu_oe().bit(on)); } @@ -1080,6 +1014,7 @@ where get_io_mux_reg(GPIONUM).modify(|_, w| w.fun_wpu().bit(on)); } + fn internal_pull_down(&mut self, on: bool, _: private::Internal) { #[cfg(esp32)] crate::soc::gpio::errata36(GPIONUM, None, Some(on)); @@ -1087,17 +1022,6 @@ where get_io_mux_reg(GPIONUM).modify(|_, w| w.fun_wpd().bit(on)); } - fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _: private::Internal) { - self.connect_peripheral_to_output_with_options( - signal, - false, - false, - false, - false, - private::Internal, - ) - } - fn connect_peripheral_to_output_with_options( &mut self, signal: OutputSignal, @@ -1167,17 +1091,6 @@ where } } -#[cfg(any(adc, dac))] -impl AnalogPin for GpioPin -where - Self: GpioProperties, -{ - /// Configures the pin for analog mode. - fn set_analog(&self, _: private::Internal) { - crate::soc::gpio::internal_into_analog(GPIONUM); - } -} - #[cfg(touch)] impl TouchPin for GpioPin where @@ -1224,12 +1137,7 @@ impl Io { gpio.bind_gpio_interrupt(gpio_interrupt_handler); crate::interrupt::enable(crate::peripherals::Interrupt::GPIO, prio).unwrap(); - let pins = gpio.pins(); - - Io { - _io_mux: io_mux, - pins, - } + Self::new_no_bind_interrupt(gpio, io_mux) } /// Initialize the I/O driver without enabling the GPIO interrupt or @@ -1238,12 +1146,10 @@ impl Io { /// *Note:* You probably don't want to use this, it is intended to be used /// in very specific use cases. Async GPIO functionality will not work /// when instantiating `Io` using this constructor. - pub fn new_no_bind_interrupt(gpio: GPIO, io_mux: IO_MUX) -> Self { - let pins = gpio.pins(); - + pub fn new_no_bind_interrupt(gpio: GPIO, _io_mux: IO_MUX) -> Self { Io { - _io_mux: io_mux, - pins, + _io_mux, + pins: gpio.pins(), } } } @@ -1364,7 +1270,7 @@ macro_rules! gpio { $crate::pin_types!($type); fn degrade_pin(&self, _: $crate::private::Internal) -> ErasedPin { - $crate::gpio::ErasedPin::[< Gpio $gpionum >](unsafe { Self::steal() }) + ErasedPin($crate::gpio::ErasedPinInner::[< Gpio $gpionum >](unsafe { Self::steal() })) } } @@ -1407,21 +1313,21 @@ macro_rules! gpio { )+ } - #[doc(hidden)] - pub enum ErasedPin { + pub(crate) enum ErasedPinInner { $( [](GpioPin<$gpionum>), )+ } + /// Type-erased GPIO pin + pub struct ErasedPin(pub(crate) ErasedPinInner); + impl ErasedPin { pub(crate) unsafe fn clone_unchecked(&self) -> Self { - match self { - $( - ErasedPin::[](_) => { - ErasedPin::[< Gpio $gpionum >](unsafe { GpioPin::steal() }) - } - )+ + match self.0 { + $(ErasedPinInner::[](_) => { + Self(ErasedPinInner::[< Gpio $gpionum >](unsafe { GpioPin::steal() })) + })+ } } } @@ -1438,10 +1344,10 @@ macro_rules! gpio { #[doc(hidden)] #[macro_export] macro_rules! handle_gpio_output { - ($this:ident, $inner:ident, $code:tt) => { + ($this:expr, $inner:ident, $code:tt) => { match $this { $( - ErasedPin::[]($inner) => if_output_pin!($type, { + ErasedPinInner::[]($inner) => if_output_pin!($type, { $code } else {{ let _ = $inner; @@ -1455,10 +1361,10 @@ macro_rules! gpio { #[doc(hidden)] #[macro_export] macro_rules! handle_gpio_input { - ($this:ident, $inner:ident, $code:tt) => { + ($this:expr, $inner:ident, $code:tt) => { match $this { $( - ErasedPin::[]($inner) => $code + ErasedPinInner::[]($inner) => $code )+ } } @@ -1490,10 +1396,7 @@ macro_rules! rtc_pins { let rtcio = unsafe{ &*RTC_IO::ptr() }; - #[cfg(esp32s3)] - unsafe { $crate::peripherals::SENS::steal() }.sar_peri_clk_gate_conf().modify(|_,w| w.iomux_clk_en().set_bit()); - #[cfg(esp32s2)] - unsafe { $crate::peripherals::SENS::steal() }.sar_io_mux_conf().modify(|_,w| w.iomux_clk_gate_en().set_bit()); + $crate::gpio::enable_iomux_clk_gate(); // disable input paste::paste!{ @@ -1547,7 +1450,7 @@ macro_rules! rtc_pins { }; } -#[cfg(esp32c3)] +#[cfg(any(esp32c2, esp32c3))] #[doc(hidden)] #[macro_export] macro_rules! rtc_pins { @@ -1557,10 +1460,19 @@ macro_rules! rtc_pins { impl $crate::gpio::RtcPin for GpioPin<$pin_num> { unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8) { let rtc_cntl = unsafe { &*$crate::peripherals::RTC_CNTL::ptr() }; - paste::paste! { - rtc_cntl.gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); - rtc_cntl.gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); - } + cfg_if::cfg_if! { + if #[cfg(esp32c2)] { + paste::paste! { + rtc_cntl.cntl_gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); + rtc_cntl.cntl_gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + } + } else { + paste::paste! { + rtc_cntl.gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); + rtc_cntl.gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + } + } + }; } fn rtcio_pad_hold(&mut self, enable: bool) { @@ -1588,58 +1500,20 @@ macro_rules! rtc_pins { ( $( $pin_num:expr )+ ) => { $( $crate::gpio::rtc_pins!($pin_num); )+ }; } -#[cfg(esp32c2)] -#[doc(hidden)] -#[macro_export] -macro_rules! rtc_pins { - ( - $pin_num:expr - ) => { - impl $crate::gpio::RtcPin for GpioPin<$pin_num> { - unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8) { - let rtc_cntl = unsafe { &*$crate::peripherals::RTC_CNTL::ptr() }; - paste::paste! { - rtc_cntl.cntl_gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); - rtc_cntl.cntl_gpio_wakeup().modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); - } - } - - fn rtcio_pad_hold(&mut self, enable: bool) { - let rtc_cntl = unsafe { &*$crate::peripherals::RTC_CNTL::ptr() }; - paste::paste! { - rtc_cntl.pad_hold().modify(|_, w| w.[< gpio_pin $pin_num _hold >]().bit(enable)); - } - } - } - - impl $crate::gpio::RtcPinWithResistors for GpioPin<$pin_num> { - fn rtcio_pullup(&mut self, enable: bool) { - let io_mux = unsafe { &*$crate::peripherals::IO_MUX::ptr() }; - io_mux.gpio($pin_num).modify(|_, w| w.fun_wpu().bit(enable)); - } - - fn rtcio_pulldown(&mut self, enable: bool) { - let io_mux = unsafe { &*$crate::peripherals::IO_MUX::ptr() }; - io_mux.gpio($pin_num).modify(|_, w| w.fun_wpd().bit(enable)); - } - } - - }; - - ( $( $pin_num:expr )+ ) => { $( $crate::gpio::rtc_pins!($pin_num); )+ }; -} - -// Following code enables `into_analog` - #[doc(hidden)] pub fn enable_iomux_clk_gate() { - #[cfg(esp32s2)] - { - use crate::peripherals::SENS; - let sensors = unsafe { &*SENS::ptr() }; - sensors - .sar_io_mux_conf() - .modify(|_, w| w.iomux_clk_gate_en().set_bit()); + cfg_if::cfg_if! { + if #[cfg(esp32s2)] { + let sensors = unsafe { &*crate::peripherals::SENS::ptr() }; + sensors + .sar_io_mux_conf() + .modify(|_, w| w.iomux_clk_gate_en().set_bit()); + } else if #[cfg(esp32s3)] { + let sensors = unsafe { &*crate::peripherals::SENS::ptr() }; + sensors + .sar_peri_clk_gate_conf() + .modify(|_,w| w.iomux_clk_en().set_bit()); + } } } @@ -1655,51 +1529,52 @@ macro_rules! analog { ) )+ ) => { - pub(crate) fn internal_into_analog(pin: u8) { - use $crate::peripherals::RTC_IO; + $( + #[cfg(any(adc, dac))] + impl $crate::gpio::AnalogPin for GpioPin<$pin_num> + where + Self: $crate::gpio::GpioProperties, + { + /// Configures the pin for analog mode. + fn set_analog(&self, _: $crate::private::Internal) { + let rtcio = unsafe{ &*$crate::peripherals::RTC_IO::ptr() }; - let rtcio = unsafe{ &*RTC_IO::ptr() }; - $crate::gpio::enable_iomux_clk_gate(); + #[cfg(esp32s2)] + $crate::gpio::enable_iomux_clk_gate(); - match pin { - $( - $pin_num => { - // We need `paste` (and a [< >] in it) to rewrite the token stream to - // handle indexed pins. - paste::paste! { - // disable input - rtcio.$pin_reg.modify(|_,w| w.$fun_ie().bit([< false >])); + // We need `paste` (and a [< >] in it) to rewrite the token stream to + // handle indexed pins. + paste::paste! { + // disable input + rtcio.$pin_reg.modify(|_,w| w.$fun_ie().bit([< false >])); - // disable output - rtcio.enable_w1tc().write(|w| unsafe { w.enable_w1tc().bits(1 << $rtc_pin) }); + // disable output + rtcio.enable_w1tc().write(|w| unsafe { w.enable_w1tc().bits(1 << $rtc_pin) }); - // disable open drain - rtcio.pin($rtc_pin).modify(|_,w| w.pad_driver().bit(false)); + // disable open drain + rtcio.pin($rtc_pin).modify(|_,w| w.pad_driver().bit(false)); - rtcio.$pin_reg.modify(|_,w| { - w.$fun_ie().clear_bit(); + rtcio.$pin_reg.modify(|_,w| { + w.$fun_ie().clear_bit(); - // Connect pin to analog / RTC module instead of standard GPIO - w.$mux_sel().set_bit(); + // Connect pin to analog / RTC module instead of standard GPIO + w.$mux_sel().set_bit(); - // Select function "RTC function 1" (GPIO) for analog use - unsafe { w.$fun_sel().bits(0b00) } - }); + // Select function "RTC function 1" (GPIO) for analog use + unsafe { w.$fun_sel().bits(0b00) }; // Disable pull-up and pull-down resistors on the pin, if it has them $( - rtcio.$pin_reg.modify(|_,w| { - w - .$rue().bit(false) - .$rde().bit(false) - }); + w.$rue().bit(false); + w.$rde().bit(false); )? - } + + w + }); } - )+ - _ => unreachable!(), + } } - } + )+ } } @@ -1710,30 +1585,27 @@ macro_rules! analog { ( $($pin_num:literal)+ ) => { - pub(crate) fn internal_into_analog(pin: u8) { - use $crate::peripherals::IO_MUX; - use $crate::peripherals::GPIO; + $( + #[cfg(any(adc, dac))] + impl $crate::gpio::AnalogPin for GpioPin<$pin_num> + where + Self: $crate::gpio::GpioProperties, + { + /// Configures the pin for analog mode. + fn set_analog(&self, _: $crate::private::Internal) { + use $crate::peripherals::{GPIO}; - let io_mux = unsafe{ &*IO_MUX::PTR }; - let gpio = unsafe{ &*GPIO::PTR }; + get_io_mux_reg($pin_num).modify(|_,w| unsafe { + w.mcu_sel().bits(1) + .fun_ie().clear_bit() + .fun_wpu().clear_bit() + .fun_wpd().clear_bit() + }); - match pin { - $( - $pin_num => { - io_mux.gpio($pin_num).modify(|_,w| unsafe { - w.mcu_sel().bits(1) - .fun_ie().clear_bit() - .fun_wpu().clear_bit() - .fun_wpd().clear_bit() - }); - - gpio.enable_w1tc().write(|w| unsafe { w.bits(1 << $pin_num) }); - } - )+ - _ => unreachable!() + unsafe{ &*GPIO::PTR }.enable_w1tc().write(|w| unsafe { w.bits(1 << $pin_num) }); + } } - - } + )+ } } @@ -1742,93 +1614,73 @@ macro_rules! analog { #[doc(hidden)] #[macro_export] macro_rules! touch_into { + (@pin_specific $touch_num:expr, true) => { + paste::paste! { + unsafe { &*RTC_IO::ptr() }.[< touch_pad $touch_num >]().write(|w| unsafe { + w + .xpd().set_bit() + // clear input_enable + .fun_ie().clear_bit() + // Connect pin to analog / RTC module instead of standard GPIO + .mux_sel().set_bit() + // Disable pull-up and pull-down resistors on the pin + .rue().clear_bit() + .rde().clear_bit() + .tie_opt().clear_bit() + // Select function "RTC function 1" (GPIO) for analog use + .fun_sel().bits(0b00) + }); + } + }; + + (@pin_specific $touch_num:expr, false) => { + paste::paste! { + unsafe { &*RTC_IO::ptr() }.[< touch_pad $touch_num >]().write(|w| + w + .xpd().set_bit() + .tie_opt().clear_bit() + ); + } + }; + ( - $( ( $touch_num:expr, $pin_num:expr, $rtc_pin:expr, $touch_thres_reg:expr, $touch_thres_field:expr , true ) )+ - --- - $( ( $touch_numx:expr, $pin_numx:expr, $rtc_pinx:expr, $touch_thres_regx:expr , $touch_thres_fieldx:expr , false ) )* + $( ( $touch_num:expr, $pin_num:expr, $rtc_pin:expr, $touch_thres_reg:expr, $touch_thres_field:expr , $needs_extra_setup:tt ))+ ) => { pub(crate) fn internal_into_touch(pin: u8) { - use $crate::peripherals::{GPIO, RTC_IO, SENS}; - - let rtcio = unsafe { &*RTC_IO::ptr() }; - let sens = unsafe { &*SENS::ptr() }; - let gpio = unsafe { &*GPIO::ptr() }; - match pin { $( $pin_num => { - paste::paste! { - // Pad to normal mode (not open-drain) - gpio.pin($rtc_pin).write(|w| w.pad_driver().clear_bit()); + use $crate::peripherals::{GPIO, RTC_IO, SENS}; - // clear output - rtcio.enable_w1tc().write(|w| unsafe { w.enable_w1tc().bits(1 << $rtc_pin) }); - sens - . $touch_thres_reg () + let gpio = unsafe { &*GPIO::ptr() }; + let rtcio = unsafe { &*RTC_IO::ptr() }; + let sens = unsafe { &*SENS::ptr() }; + + // Pad to normal mode (not open-drain) + gpio.pin($rtc_pin).write(|w| w.pad_driver().clear_bit()); + + // clear output + rtcio.enable_w1tc().write(|w| unsafe { w.enable_w1tc().bits(1 << $rtc_pin) }); + paste::paste! { + sens . $touch_thres_reg () .write(|w| unsafe { w. $touch_thres_field ().bits( 0b0 // Default: 0 for esp32 gets overridden later anyway. ) }); - rtcio.[< touch_pad $touch_num >]().write(|w| unsafe { - w - .xpd().set_bit() - // clear input_enable - .fun_ie().clear_bit() - // Connect pin to analog / RTC module instead of standard GPIO - .mux_sel().set_bit() - // Disable pull-up and pull-down resistors on the pin - .rue().clear_bit() - .rde().clear_bit() - .tie_opt().clear_bit() - // Select function "RTC function 1" (GPIO) for analog use - .fun_sel().bits(0b00) - }); + $crate::touch_into!( @pin_specific $touch_num, $needs_extra_setup ); + // enable the pin sens.sar_touch_enable().modify(|r, w| unsafe { - w - // enable the pin - .touch_pad_worken().bits( - r.touch_pad_worken().bits() | ( 1 << [< $touch_num >] ) + w.touch_pad_worken().bits( + r.touch_pad_worken().bits() | ( 1 << [< $touch_num >] ) ) }); } } )+ - $( - $pin_numx => { - paste::paste! { - // Pad to normal mode (not open-drain) - gpio.pin($rtc_pinx).write(|w| w.pad_driver().clear_bit()); - - // clear output - rtcio.enable_w1tc().write(|w| unsafe { w.enable_w1tc().bits(1 << $rtc_pinx) }); - sens - . $touch_thres_regx () - .write(|w| unsafe { - w. $touch_thres_fieldx ().bits( - 0b0 // Default: 0 for esp32 gets overridden later anyway. - ) - }); - - rtcio.[< touch_pad $touch_numx >]().write(|w| - w - .xpd().set_bit() - .tie_opt().clear_bit() - ); - - sens.sar_touch_enable().modify(|r, w| unsafe { - w - // enable the pin - .touch_pad_worken().bits( - r.touch_pad_worken().bits() | ( 1 << [< $touch_numx >] ) - ) - }); - } - } - )* _ => unreachable!(), } } @@ -1892,13 +1744,19 @@ pub struct Output<'d, P = ErasedPin> { pin: Flex<'d, P>, } +impl

private::Sealed for Output<'_, P> {} + +impl<'d, P> Peripheral for Output<'d, P> { + type P = P; + unsafe fn clone_unchecked(&mut self) -> P { + self.pin.clone_unchecked() + } +} + impl<'d> Output<'d> { /// Create GPIO output driver for a [GpioPin] with the provided level #[inline] - pub fn new( - pin: impl crate::peripheral::Peripheral

+ 'd, - initial_output: Level, - ) -> Self { + pub fn new(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { let pin = Flex::new(pin); Self::new_inner(pin, initial_output) @@ -1911,10 +1769,7 @@ where { /// Create GPIO output driver for a [GpioPin] with the provided level #[inline] - pub fn new_typed( - pin: impl crate::peripheral::Peripheral

+ 'd, - initial_output: Level, - ) -> Self { + pub fn new_typed(pin: impl Peripheral

+ 'd, initial_output: Level) -> Self { let pin = Flex::new_typed(pin); Self::new_inner(pin, initial_output) @@ -1982,14 +1837,20 @@ pub struct Input<'d, P = ErasedPin> { pin: Flex<'d, P>, } +impl

private::Sealed for Input<'_, P> {} + +impl<'d, P> Peripheral for Input<'d, P> { + type P = P; + unsafe fn clone_unchecked(&mut self) -> P { + self.pin.clone_unchecked() + } +} + impl<'d> Input<'d> { /// Create GPIO input driver for a [Pin] with the provided [Pull] /// configuration. #[inline] - pub fn new( - pin: impl crate::peripheral::Peripheral

+ 'd, - pull: Pull, - ) -> Self { + pub fn new(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { let pin = Flex::new(pin); Self::new_inner(pin, pull) @@ -2003,7 +1864,7 @@ where /// Create GPIO input driver for a [Pin] with the provided [Pull] /// configuration. #[inline] - pub fn new_typed(pin: impl crate::peripheral::Peripheral

+ 'd, pull: Pull) -> Self { + pub fn new_typed(pin: impl Peripheral

+ 'd, pull: Pull) -> Self { let pin = Flex::new_typed(pin); Self::new_inner(pin, pull) @@ -2070,12 +1931,21 @@ pub struct OutputOpenDrain<'d, P = ErasedPin> { pin: Flex<'d, P>, } +impl

private::Sealed for OutputOpenDrain<'_, P> {} + +impl<'d, P> Peripheral for OutputOpenDrain<'d, P> { + type P = P; + unsafe fn clone_unchecked(&mut self) -> P { + self.pin.clone_unchecked() + } +} + impl<'d> OutputOpenDrain<'d> { /// Create GPIO open-drain output driver for a [Pin] with the provided /// initial output-level and [Pull] configuration. #[inline] pub fn new( - pin: impl crate::peripheral::Peripheral

+ 'd, + pin: impl Peripheral

+ 'd, initial_output: Level, pull: Pull, ) -> Self { @@ -2092,11 +1962,7 @@ where /// Create GPIO open-drain output driver for a [Pin] with the provided /// initial output-level and [Pull] configuration. #[inline] - pub fn new_typed( - pin: impl crate::peripheral::Peripheral

+ 'd, - initial_output: Level, - pull: Pull, - ) -> Self { + pub fn new_typed(pin: impl Peripheral

+ 'd, initial_output: Level, pull: Pull) -> Self { let pin = Flex::new_typed(pin); Self::new_inner(pin, initial_output, pull) @@ -2194,11 +2060,20 @@ pub struct Flex<'d, P = ErasedPin> { pin: PeripheralRef<'d, P>, } +impl

private::Sealed for Flex<'_, P> {} + +impl<'d, P> Peripheral for Flex<'d, P> { + type P = P; + unsafe fn clone_unchecked(&mut self) -> P { + core::ptr::read(&*self.pin as *const _) + } +} + impl<'d> Flex<'d> { /// Create flexible pin driver for a [Pin]. /// No mode change happens. #[inline] - pub fn new(pin: impl crate::peripheral::Peripheral

+ 'd) -> Self { + pub fn new(pin: impl Peripheral

+ 'd) -> Self { crate::into_ref!(pin); let pin = pin.degrade_internal(private::Internal); Self::new_typed(pin) @@ -2212,7 +2087,7 @@ where /// Create flexible pin driver for a [Pin]. /// No mode change happens. #[inline] - pub fn new_typed(pin: impl crate::peripheral::Peripheral

+ 'd) -> Self { + pub fn new_typed(pin: impl Peripheral

+ 'd) -> Self { crate::into_ref!(pin); Self { pin } } @@ -2357,7 +2232,7 @@ pub(crate) mod internal { impl Pin for ErasedPin { fn number(&self, _: private::Internal) -> u8 { - handle_gpio_input!(self, target, { Pin::number(target, private::Internal) }) + handle_gpio_input!(&self.0, target, { Pin::number(target, private::Internal) }) } fn degrade_internal(&self, _: private::Internal) -> ErasedPin { @@ -2365,23 +2240,17 @@ pub(crate) mod internal { } fn sleep_mode(&mut self, on: bool, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { Pin::sleep_mode(target, on, private::Internal) }) } fn set_alternate_function(&mut self, alternate: AlternateFunction, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { Pin::set_alternate_function(target, alternate, private::Internal) }) } - fn is_listening(&self, _: private::Internal) -> bool { - handle_gpio_input!(self, target, { - Pin::is_listening(target, private::Internal) - }) - } - fn listen_with_options( &mut self, event: Event, @@ -2390,7 +2259,7 @@ pub(crate) mod internal { wake_up_from_light_sleep: bool, _: private::Internal, ) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { Pin::listen_with_options( target, event, @@ -2403,65 +2272,49 @@ pub(crate) mod internal { } fn unlisten(&mut self, _: private::Internal) { - handle_gpio_input!(self, target, { Pin::unlisten(target, private::Internal) }) + handle_gpio_input!(&mut self.0, target, { + Pin::unlisten(target, private::Internal) + }) } fn is_interrupt_set(&self, _: private::Internal) -> bool { - handle_gpio_input!(self, target, { + handle_gpio_input!(&self.0, target, { Pin::is_interrupt_set(target, private::Internal) }) } fn clear_interrupt(&mut self, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { Pin::clear_interrupt(target, private::Internal) }) } - - fn wakeup_enable(&mut self, enable: bool, event: WakeEvent, _: private::Internal) { - handle_gpio_input!(self, target, { - Pin::wakeup_enable(target, enable, event, private::Internal) - }) - } } impl InputPin for ErasedPin { fn init_input(&self, pull_down: bool, pull_up: bool, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&self.0, target, { InputPin::init_input(target, pull_down, pull_up, private::Internal) }) } - fn set_to_input(&mut self, _: private::Internal) { - handle_gpio_input!(self, target, { - InputPin::set_to_input(target, private::Internal); - }); - } - fn enable_input(&mut self, on: bool, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { InputPin::enable_input(target, on, private::Internal) }); } fn enable_input_in_sleep_mode(&mut self, on: bool, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { InputPin::enable_input_in_sleep_mode(target, on, private::Internal) }); } fn is_input_high(&self, _: private::Internal) -> bool { - handle_gpio_input!(self, target, { + handle_gpio_input!(&self.0, target, { InputPin::is_input_high(target, private::Internal) }) } - fn connect_input_to_peripheral(&mut self, signal: InputSignal, _: private::Internal) { - handle_gpio_input!(self, target, { - InputPin::connect_input_to_peripheral(target, signal, private::Internal) - }); - } - fn connect_input_to_peripheral_with_options( &mut self, signal: InputSignal, @@ -2469,7 +2322,7 @@ pub(crate) mod internal { force_via_gpio_mux: bool, _: private::Internal, ) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { InputPin::connect_input_to_peripheral_with_options( target, signal, @@ -2481,7 +2334,7 @@ pub(crate) mod internal { } fn disconnect_input_from_peripheral(&mut self, signal: InputSignal, _: private::Internal) { - handle_gpio_input!(self, target, { + handle_gpio_input!(&mut self.0, target, { InputPin::disconnect_input_from_peripheral(target, signal, private::Internal) }); } @@ -2489,77 +2342,71 @@ pub(crate) mod internal { impl OutputPin for ErasedPin { fn set_to_open_drain_output(&mut self, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::set_to_open_drain_output(target, private::Internal) }); } fn set_to_push_pull_output(&mut self, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::set_to_push_pull_output(target, private::Internal) }); } fn enable_output(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::enable_output(target, on, private::Internal) }); } fn set_output_high(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::set_output_high(target, on, private::Internal) }); } fn set_drive_strength(&mut self, strength: DriveStrength, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::set_drive_strength(target, strength, private::Internal) }); } fn enable_open_drain(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::enable_open_drain(target, on, private::Internal) }); } fn enable_output_in_sleep_mode(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::enable_output_in_sleep_mode(target, on, private::Internal) }); } fn internal_pull_up_in_sleep_mode(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::internal_pull_up_in_sleep_mode(target, on, private::Internal) }); } fn internal_pull_down_in_sleep_mode(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::internal_pull_down_in_sleep_mode(target, on, private::Internal) }); } fn internal_pull_up(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::internal_pull_up(target, on, private::Internal) }); } fn internal_pull_down(&mut self, on: bool, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::internal_pull_down(target, on, private::Internal) }); } - fn connect_peripheral_to_output(&mut self, signal: OutputSignal, _: private::Internal) { - handle_gpio_output!(self, target, { - OutputPin::connect_peripheral_to_output(target, signal, private::Internal) - }); - } - fn connect_peripheral_to_output_with_options( &mut self, signal: OutputSignal, @@ -2569,7 +2416,7 @@ pub(crate) mod internal { force_via_gpio_mux: bool, _: private::Internal, ) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::connect_peripheral_to_output_with_options( target, signal, @@ -2583,19 +2430,40 @@ pub(crate) mod internal { } fn disconnect_peripheral_from_output(&mut self, _: private::Internal) { - handle_gpio_output!(self, target, { + handle_gpio_output!(&mut self.0, target, { OutputPin::disconnect_peripheral_from_output(target, private::Internal) }); } fn is_set_high(&self, _: private::Internal) -> bool { - handle_gpio_output!(self, target, { + handle_gpio_output!(&self.0, target, { OutputPin::is_set_high(target, private::Internal) }) } } } +fn is_listening(pin_num: u8) -> bool { + let bits = unsafe { &*GPIO::PTR } + .pin(pin_num as usize) + .read() + .int_ena() + .bits(); + bits != 0 +} + +fn set_int_enable(gpio_num: u8, int_ena: u8, int_type: u8, wake_up_from_light_sleep: bool) { + let gpio = unsafe { &*crate::peripherals::GPIO::PTR }; + gpio.pin(gpio_num as usize).modify(|_, w| unsafe { + w.int_ena() + .bits(int_ena) + .int_type() + .bits(int_type) + .wakeup_enable() + .bit(wake_up_from_light_sleep) + }); +} + mod asynch { use core::task::{Context, Poll}; @@ -2677,12 +2545,12 @@ mod asynch { } #[must_use = "futures do nothing unless you `.await` or poll them"] - pub struct PinFuture { + struct PinFuture { pin_num: u8, } impl PinFuture { - pub fn new(pin_num: u8) -> Self { + fn new(pin_num: u8) -> Self { Self { pin_num } } } @@ -2703,32 +2571,6 @@ mod asynch { } } - pub(crate) fn is_listening(gpio_num: u8) -> bool { - let bits = unsafe { &*GPIO::PTR } - .pin(gpio_num as usize) - .read() - .int_ena() - .bits(); - bits != 0 - } - - pub(crate) fn set_int_enable( - gpio_num: u8, - int_ena: u8, - int_type: u8, - wake_up_from_light_sleep: bool, - ) { - let gpio = unsafe { &*crate::peripherals::GPIO::PTR }; - gpio.pin(gpio_num as usize).modify(|_, w| unsafe { - w.int_ena() - .bits(int_ena) - .int_type() - .bits(int_type) - .wakeup_enable() - .bit(wake_up_from_light_sleep) - }); - } - #[ram] pub(super) fn handle_gpio_interrupt() { let intrs_bank0 = InterruptStatusRegisterAccessBank0::interrupt_status_read(); diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs index d3cd847e6..3767a1431 100644 --- a/esp-hal/src/i2s.rs +++ b/esp-hal/src/i2s.rs @@ -999,7 +999,7 @@ mod private { P: InputPin, { into_ref!(pin); - pin.set_to_input(crate::private::Internal); + pin.init_input(false, false, crate::private::Internal); pin.connect_input_to_peripheral(T::din_signal(), crate::private::Internal); self } diff --git a/esp-hal/src/lcd_cam/cam.rs b/esp-hal/src/lcd_cam/cam.rs index c83734249..41e30c1b6 100644 --- a/esp-hal/src/lcd_cam/cam.rs +++ b/esp-hal/src/lcd_cam/cam.rs @@ -311,7 +311,7 @@ impl<'d, CH: DmaChannel> Camera<'d, CH> { pub fn with_pixel_clock(self, pclk: impl Peripheral

+ 'd) -> Self { crate::into_ref!(pclk); - pclk.set_to_input(crate::private::Internal); + pclk.init_input(false, false, crate::private::Internal); pclk.connect_input_to_peripheral(InputSignal::CAM_PCLK, crate::private::Internal); self @@ -327,9 +327,9 @@ impl<'d, CH: DmaChannel> Camera<'d, CH> { crate::into_ref!(vsync); crate::into_ref!(h_enable); - vsync.set_to_input(crate::private::Internal); + vsync.init_input(false, false, crate::private::Internal); vsync.connect_input_to_peripheral(InputSignal::CAM_V_SYNC, crate::private::Internal); - h_enable.set_to_input(crate::private::Internal); + h_enable.init_input(false, false, crate::private::Internal); h_enable.connect_input_to_peripheral(InputSignal::CAM_H_ENABLE, crate::private::Internal); self.lcd_cam @@ -351,11 +351,11 @@ impl<'d, CH: DmaChannel> Camera<'d, CH> { crate::into_ref!(hsync); crate::into_ref!(h_enable); - vsync.set_to_input(crate::private::Internal); + vsync.init_input(false, false, crate::private::Internal); vsync.connect_input_to_peripheral(InputSignal::CAM_V_SYNC, crate::private::Internal); - hsync.set_to_input(crate::private::Internal); + hsync.init_input(false, false, crate::private::Internal); hsync.connect_input_to_peripheral(InputSignal::CAM_H_SYNC, crate::private::Internal); - h_enable.set_to_input(crate::private::Internal); + h_enable.init_input(false, false, crate::private::Internal); h_enable.connect_input_to_peripheral(InputSignal::CAM_H_ENABLE, crate::private::Internal); self.lcd_cam @@ -475,21 +475,21 @@ impl RxEightBits { crate::into_ref!(pin_6); crate::into_ref!(pin_7); - pin_0.set_to_input(crate::private::Internal); + pin_0.init_input(false, false, crate::private::Internal); pin_0.connect_input_to_peripheral(InputSignal::CAM_DATA_0, crate::private::Internal); - pin_1.set_to_input(crate::private::Internal); + pin_1.init_input(false, false, crate::private::Internal); pin_1.connect_input_to_peripheral(InputSignal::CAM_DATA_1, crate::private::Internal); - pin_2.set_to_input(crate::private::Internal); + pin_2.init_input(false, false, crate::private::Internal); pin_2.connect_input_to_peripheral(InputSignal::CAM_DATA_2, crate::private::Internal); - pin_3.set_to_input(crate::private::Internal); + pin_3.init_input(false, false, crate::private::Internal); pin_3.connect_input_to_peripheral(InputSignal::CAM_DATA_3, crate::private::Internal); - pin_4.set_to_input(crate::private::Internal); + pin_4.init_input(false, false, crate::private::Internal); pin_4.connect_input_to_peripheral(InputSignal::CAM_DATA_4, crate::private::Internal); - pin_5.set_to_input(crate::private::Internal); + pin_5.init_input(false, false, crate::private::Internal); pin_5.connect_input_to_peripheral(InputSignal::CAM_DATA_5, crate::private::Internal); - pin_6.set_to_input(crate::private::Internal); + pin_6.init_input(false, false, crate::private::Internal); pin_6.connect_input_to_peripheral(InputSignal::CAM_DATA_6, crate::private::Internal); - pin_7.set_to_input(crate::private::Internal); + pin_7.init_input(false, false, crate::private::Internal); pin_7.connect_input_to_peripheral(InputSignal::CAM_DATA_7, crate::private::Internal); Self { _pins: () } @@ -563,37 +563,37 @@ impl RxSixteenBits { crate::into_ref!(pin_14); crate::into_ref!(pin_15); - pin_0.set_to_input(crate::private::Internal); + pin_0.init_input(false, false, crate::private::Internal); pin_0.connect_input_to_peripheral(InputSignal::CAM_DATA_0, crate::private::Internal); - pin_1.set_to_input(crate::private::Internal); + pin_1.init_input(false, false, crate::private::Internal); pin_1.connect_input_to_peripheral(InputSignal::CAM_DATA_1, crate::private::Internal); - pin_2.set_to_input(crate::private::Internal); + pin_2.init_input(false, false, crate::private::Internal); pin_2.connect_input_to_peripheral(InputSignal::CAM_DATA_2, crate::private::Internal); - pin_3.set_to_input(crate::private::Internal); + pin_3.init_input(false, false, crate::private::Internal); pin_3.connect_input_to_peripheral(InputSignal::CAM_DATA_3, crate::private::Internal); - pin_4.set_to_input(crate::private::Internal); + pin_4.init_input(false, false, crate::private::Internal); pin_4.connect_input_to_peripheral(InputSignal::CAM_DATA_4, crate::private::Internal); - pin_5.set_to_input(crate::private::Internal); + pin_5.init_input(false, false, crate::private::Internal); pin_5.connect_input_to_peripheral(InputSignal::CAM_DATA_5, crate::private::Internal); - pin_6.set_to_input(crate::private::Internal); + pin_6.init_input(false, false, crate::private::Internal); pin_6.connect_input_to_peripheral(InputSignal::CAM_DATA_6, crate::private::Internal); - pin_7.set_to_input(crate::private::Internal); + pin_7.init_input(false, false, crate::private::Internal); pin_7.connect_input_to_peripheral(InputSignal::CAM_DATA_7, crate::private::Internal); - pin_8.set_to_input(crate::private::Internal); + pin_8.init_input(false, false, crate::private::Internal); pin_8.connect_input_to_peripheral(InputSignal::CAM_DATA_8, crate::private::Internal); - pin_9.set_to_input(crate::private::Internal); + pin_9.init_input(false, false, crate::private::Internal); pin_9.connect_input_to_peripheral(InputSignal::CAM_DATA_9, crate::private::Internal); - pin_10.set_to_input(crate::private::Internal); + pin_10.init_input(false, false, crate::private::Internal); pin_10.connect_input_to_peripheral(InputSignal::CAM_DATA_10, crate::private::Internal); - pin_11.set_to_input(crate::private::Internal); + pin_11.init_input(false, false, crate::private::Internal); pin_11.connect_input_to_peripheral(InputSignal::CAM_DATA_11, crate::private::Internal); - pin_12.set_to_input(crate::private::Internal); + pin_12.init_input(false, false, crate::private::Internal); pin_12.connect_input_to_peripheral(InputSignal::CAM_DATA_12, crate::private::Internal); - pin_13.set_to_input(crate::private::Internal); + pin_13.init_input(false, false, crate::private::Internal); pin_13.connect_input_to_peripheral(InputSignal::CAM_DATA_13, crate::private::Internal); - pin_14.set_to_input(crate::private::Internal); + pin_14.init_input(false, false, crate::private::Internal); pin_14.connect_input_to_peripheral(InputSignal::CAM_DATA_14, crate::private::Internal); - pin_15.set_to_input(crate::private::Internal); + pin_15.init_input(false, false, crate::private::Internal); pin_15.connect_input_to_peripheral(InputSignal::CAM_DATA_15, crate::private::Internal); Self { _pins: () } diff --git a/esp-hal/src/parl_io.rs b/esp-hal/src/parl_io.rs index af576ca38..4105acb19 100644 --- a/esp-hal/src/parl_io.rs +++ b/esp-hal/src/parl_io.rs @@ -332,7 +332,7 @@ where pcr.parl_clk_tx_conf() .modify(|_, w| unsafe { w.parl_clk_tx_sel().bits(3).parl_clk_tx_div_num().bits(0) }); // PAD_CLK_TX, no divider - self.pin.set_to_input(crate::private::Internal); + self.pin.init_input(false, false, crate::private::Internal); self.pin.connect_input_to_peripheral( crate::gpio::InputSignal::PARL_TX_CLK, crate::private::Internal, @@ -367,7 +367,7 @@ where pcr.parl_clk_rx_conf() .modify(|_, w| unsafe { w.parl_clk_rx_sel().bits(3).parl_clk_rx_div_num().bits(0) }); // PAD_CLK_TX, no divider - self.pin.set_to_input(crate::private::Internal); + self.pin.init_input(false, false, crate::private::Internal); self.pin.connect_input_to_peripheral( crate::gpio::InputSignal::PARL_RX_CLK, crate::private::Internal, @@ -634,7 +634,8 @@ where { fn configure(&mut self) -> Result<(), Error> { self.rx_pins.configure()?; - self.valid_pin.set_to_input(crate::private::Internal); + self.valid_pin + .init_input(false, false, crate::private::Internal); self.valid_pin .connect_input_to_peripheral(Instance::rx_valid_pin_signal(), crate::private::Internal); Instance::set_rx_sw_en(false); @@ -738,7 +739,7 @@ macro_rules! rx_pins { { fn configure(&mut self) -> Result<(), Error> { $( - self.[< pin_ $pin:lower >].set_to_input($crate::private::Internal); + self.[< pin_ $pin:lower >].init_input(false, false, $crate::private::Internal); self.[< pin_ $pin:lower >].connect_input_to_peripheral(crate::gpio::InputSignal::$signal, $crate::private::Internal); )+ diff --git a/esp-hal/src/peripheral.rs b/esp-hal/src/peripheral.rs index bdba4866b..3f56ab9a3 100644 --- a/esp-hal/src/peripheral.rs +++ b/esp-hal/src/peripheral.rs @@ -194,11 +194,11 @@ pub trait Peripheral: Sized + crate::private::Sealed { } } -impl Peripheral for &mut T +impl Peripheral for &mut T where - T: Peripheral

, + T: Peripheral

, { - type P = T; + type P = P; unsafe fn clone_unchecked(&mut self) -> Self::P { T::clone_unchecked(self) diff --git a/esp-hal/src/rmt.rs b/esp-hal/src/rmt.rs index e505d7d16..7ea901626 100644 --- a/esp-hal/src/rmt.rs +++ b/esp-hal/src/rmt.rs @@ -387,7 +387,7 @@ where } crate::into_ref!(pin); - pin.set_to_input(crate::private::Internal); + pin.init_input(false, false, crate::private::Internal); pin.connect_input_to_peripheral(T::input_signal(), crate::private::Internal); T::set_divider(config.clk_divider); T::set_carrier( @@ -433,7 +433,7 @@ where } crate::into_ref!(pin); - pin.set_to_input(crate::private::Internal); + pin.init_input(false, false, crate::private::Internal); pin.connect_input_to_peripheral(T::input_signal(), crate::private::Internal); T::set_divider(config.clk_divider); T::set_carrier( diff --git a/esp-hal/src/soc/esp32/gpio.rs b/esp-hal/src/soc/esp32/gpio.rs index d2fa84b3b..8b62dba18 100644 --- a/esp-hal/src/soc/esp32/gpio.rs +++ b/esp-hal/src/soc/esp32/gpio.rs @@ -804,74 +804,74 @@ crate::gpio::gpio! { } crate::gpio::analog! { - (36, 0, sensor_pads(), sense1_mux_sel, sense1_fun_sel, sense1_fun_ie) - (37, 1, sensor_pads(), sense2_mux_sel, sense2_fun_sel, sense2_fun_ie) - (38, 2, sensor_pads(), sense3_mux_sel, sense3_fun_sel, sense3_fun_ie) - (39, 3, sensor_pads(), sense4_mux_sel, sense4_fun_sel, sense4_fun_ie) - (34, 4, adc_pad(), adc1_mux_sel, adc1_fun_sel, adc1_fun_ie) - (35, 5, adc_pad(), adc2_mux_sel, adc2_fun_sel, adc1_fun_ie) - (25, 6, pad_dac1(), mux_sel, fun_sel, fun_ie, rue, rde) - (26, 7, pad_dac2(), mux_sel, fun_sel, fun_ie, rue, rde) - (33, 8, xtal_32k_pad(), x32n_mux_sel, x32n_fun_sel, x32n_fun_ie, x32n_rue, x32n_rde ) - (32, 9, xtal_32k_pad(), x32p_mux_sel, x32p_fun_sel, x32p_fun_ie, x32p_rue, x32p_rde ) - (4, 10, touch_pad0(), mux_sel, fun_sel, fun_ie, rue, rde ) - (0, 11, touch_pad1(), mux_sel, fun_sel, fun_ie, rue, rde ) - (2, 12, touch_pad2(), mux_sel, fun_sel, fun_ie, rue, rde ) - (15, 13, touch_pad3(), mux_sel, fun_sel, fun_ie, rue, rde ) - (13, 14, touch_pad4(), mux_sel, fun_sel, fun_ie, rue, rde ) - (12, 15, touch_pad5(), mux_sel, fun_sel, fun_ie, rue, rde ) - (14, 16, touch_pad6(), mux_sel, fun_sel, fun_ie, rue, rde ) - (27, 17, touch_pad7(), mux_sel, fun_sel, fun_ie, rue, rde ) + (36, 0, sensor_pads(), sense1_mux_sel, sense1_fun_sel, sense1_fun_ie) + (37, 1, sensor_pads(), sense2_mux_sel, sense2_fun_sel, sense2_fun_ie) + (38, 2, sensor_pads(), sense3_mux_sel, sense3_fun_sel, sense3_fun_ie) + (39, 3, sensor_pads(), sense4_mux_sel, sense4_fun_sel, sense4_fun_ie) + (34, 4, adc_pad(), adc1_mux_sel, adc1_fun_sel, adc1_fun_ie) + (35, 5, adc_pad(), adc2_mux_sel, adc2_fun_sel, adc1_fun_ie) + (25, 6, pad_dac1(), mux_sel, fun_sel, fun_ie, rue, rde) + (26, 7, pad_dac2(), mux_sel, fun_sel, fun_ie, rue, rde) + (33, 8, xtal_32k_pad(), x32n_mux_sel, x32n_fun_sel, x32n_fun_ie, x32n_rue, x32n_rde ) + (32, 9, xtal_32k_pad(), x32p_mux_sel, x32p_fun_sel, x32p_fun_ie, x32p_rue, x32p_rde ) + (4, 10, touch_pad0(), mux_sel, fun_sel, fun_ie, rue, rde ) + (0, 11, touch_pad1(), mux_sel, fun_sel, fun_ie, rue, rde ) + (2, 12, touch_pad2(), mux_sel, fun_sel, fun_ie, rue, rde ) + (15, 13, touch_pad3(), mux_sel, fun_sel, fun_ie, rue, rde ) + (13, 14, touch_pad4(), mux_sel, fun_sel, fun_ie, rue, rde ) + (12, 15, touch_pad5(), mux_sel, fun_sel, fun_ie, rue, rde ) + (14, 16, touch_pad6(), mux_sel, fun_sel, fun_ie, rue, rde ) + (27, 17, touch_pad7(), mux_sel, fun_sel, fun_ie, rue, rde ) } crate::gpio::rtc_pins! { - (36, 0, sensor_pads(), sense1_, sense1_hold_force ) - (37, 1, sensor_pads(), sense2_, sense2_hold_force ) - (38, 2, sensor_pads(), sense3_, sense3_hold_force ) - (39, 3, sensor_pads(), sense4_, sense4_hold_force ) - (34, 4, adc_pad(), adc1_, adc1_hold_force ) - (35, 5, adc_pad(), adc2_, adc2_hold_force ) - (25, 6, pad_dac1(), "", pdac1_hold_force, rue, rde ) - (26, 7, pad_dac2(), "", pdac2_hold_force, rue, rde ) - (33, 8, xtal_32k_pad(), x32n_, x32n_hold_force, x32n_rue, x32n_rde ) - (32, 9, xtal_32k_pad(), x32p_, x32p_hold_force, x32p_rue, x32p_rde ) - (4, 10, touch_pad0(), "", touch_pad0_hold_force, rue, rde ) - (0, 11, touch_pad1(), "", touch_pad1_hold_force, rue, rde ) - (2, 12, touch_pad2(), "", touch_pad2_hold_force, rue, rde ) - (15, 13, touch_pad3(), "", touch_pad3_hold_force, rue, rde ) - (13, 14, touch_pad4(), "", touch_pad4_hold_force, rue, rde ) - (12, 15, touch_pad5(), "", touch_pad5_hold_force, rue, rde ) - (14, 16, touch_pad6(), "", touch_pad6_hold_force, rue, rde ) - (27, 17, touch_pad7(), "", touch_pad7_hold_force, rue, rde ) + (36, 0, sensor_pads(), sense1_, sense1_hold_force ) + (37, 1, sensor_pads(), sense2_, sense2_hold_force ) + (38, 2, sensor_pads(), sense3_, sense3_hold_force ) + (39, 3, sensor_pads(), sense4_, sense4_hold_force ) + (34, 4, adc_pad(), adc1_, adc1_hold_force ) + (35, 5, adc_pad(), adc2_, adc2_hold_force ) + (25, 6, pad_dac1(), "", pdac1_hold_force, rue, rde ) + (26, 7, pad_dac2(), "", pdac2_hold_force, rue, rde ) + (33, 8, xtal_32k_pad(), x32n_, x32n_hold_force, x32n_rue, x32n_rde ) + (32, 9, xtal_32k_pad(), x32p_, x32p_hold_force, x32p_rue, x32p_rde ) + (4, 10, touch_pad0(), "", touch_pad0_hold_force, rue, rde ) + (0, 11, touch_pad1(), "", touch_pad1_hold_force, rue, rde ) + (2, 12, touch_pad2(), "", touch_pad2_hold_force, rue, rde ) + (15, 13, touch_pad3(), "", touch_pad3_hold_force, rue, rde ) + (13, 14, touch_pad4(), "", touch_pad4_hold_force, rue, rde ) + (12, 15, touch_pad5(), "", touch_pad5_hold_force, rue, rde ) + (14, 16, touch_pad6(), "", touch_pad6_hold_force, rue, rde ) + (27, 17, touch_pad7(), "", touch_pad7_hold_force, rue, rde ) } crate::gpio::touch_into! { // (touch_nr, pin_nr, rtc_pin, touch_comb_reg_nr, normal_pin) - (0, 4, 10, sar_touch_thres1, touch_out_th0, true ) - (1, 0, 11, sar_touch_thres1, touch_out_th1, true ) - (2, 2, 12, sar_touch_thres2, touch_out_th2, true ) - (3, 15, 13, sar_touch_thres2, touch_out_th3, true ) - (4, 13, 14, sar_touch_thres3, touch_out_th4, true ) - (5, 12, 15, sar_touch_thres3, touch_out_th5, true ) - (6, 14, 16, sar_touch_thres4, touch_out_th6, true ) - (7, 27, 17, sar_touch_thres4, touch_out_th7, true ) - --- - (8, 33, 8, sar_touch_thres5, touch_out_th8, false ) - (9, 32, 9, sar_touch_thres5, touch_out_th9, false ) + (0, 4, 10, sar_touch_thres1, touch_out_th0, true ) + (1, 0, 11, sar_touch_thres1, touch_out_th1, true ) + (2, 2, 12, sar_touch_thres2, touch_out_th2, true ) + (3, 15, 13, sar_touch_thres2, touch_out_th3, true ) + (4, 13, 14, sar_touch_thres3, touch_out_th4, true ) + (5, 12, 15, sar_touch_thres3, touch_out_th5, true ) + (6, 14, 16, sar_touch_thres4, touch_out_th6, true ) + (7, 27, 17, sar_touch_thres4, touch_out_th7, true ) + // --- + (8, 33, 8, sar_touch_thres5, touch_out_th8, false ) + (9, 32, 9, sar_touch_thres5, touch_out_th9, false ) } crate::gpio::touch_common! { // (touch_nr, pin_nr, touch_out_reg, touch_thres_reg ) - (0, 4, sar_touch_out1, touch_meas_out0, sar_touch_thres1, touch_out_th0) - (1, 0, sar_touch_out1, touch_meas_out1, sar_touch_thres1, touch_out_th1) - (2, 2, sar_touch_out2, touch_meas_out2, sar_touch_thres2, touch_out_th2) - (3, 15, sar_touch_out2, touch_meas_out3, sar_touch_thres2, touch_out_th3) - (4, 13, sar_touch_out3, touch_meas_out4, sar_touch_thres3, touch_out_th4) - (5, 12, sar_touch_out3, touch_meas_out5, sar_touch_thres3, touch_out_th5) - (6, 14, sar_touch_out4, touch_meas_out6, sar_touch_thres4, touch_out_th6) - (7, 27, sar_touch_out4, touch_meas_out7, sar_touch_thres4, touch_out_th7) - (8, 33, sar_touch_out5, touch_meas_out8, sar_touch_thres5, touch_out_th8) - (9, 32, sar_touch_out5, touch_meas_out9, sar_touch_thres5, touch_out_th9) + (0, 4, sar_touch_out1, touch_meas_out0, sar_touch_thres1, touch_out_th0) + (1, 0, sar_touch_out1, touch_meas_out1, sar_touch_thres1, touch_out_th1) + (2, 2, sar_touch_out2, touch_meas_out2, sar_touch_thres2, touch_out_th2) + (3, 15, sar_touch_out2, touch_meas_out3, sar_touch_thres2, touch_out_th3) + (4, 13, sar_touch_out3, touch_meas_out4, sar_touch_thres3, touch_out_th4) + (5, 12, sar_touch_out3, touch_meas_out5, sar_touch_thres3, touch_out_th5) + (6, 14, sar_touch_out4, touch_meas_out6, sar_touch_thres4, touch_out_th6) + (7, 27, sar_touch_out4, touch_meas_out7, sar_touch_thres4, touch_out_th7) + (8, 33, sar_touch_out5, touch_meas_out8, sar_touch_thres5, touch_out_th8) + (9, 32, sar_touch_out5, touch_meas_out9, sar_touch_thres5, touch_out_th9) } impl InterruptStatusRegisterAccess for InterruptStatusRegisterAccessBank0 { diff --git a/esp-hal/src/soc/esp32s3/gpio.rs b/esp-hal/src/soc/esp32s3/gpio.rs index 9cf339f1b..9c4598bfe 100644 --- a/esp-hal/src/soc/esp32s3/gpio.rs +++ b/esp-hal/src/soc/esp32s3/gpio.rs @@ -405,28 +405,28 @@ crate::gpio::gpio! { } crate::gpio::analog! { - ( 0, 0, touch_pad(0), mux_sel, fun_sel, fun_ie, rue, rde) - ( 1, 1, touch_pad(1), mux_sel, fun_sel, fun_ie, rue, rde) - ( 2, 2, touch_pad(2), mux_sel, fun_sel, fun_ie, rue, rde) - ( 3, 3, touch_pad(3), mux_sel, fun_sel, fun_ie, rue, rde) - ( 4, 4, touch_pad(4), mux_sel, fun_sel, fun_ie, rue, rde) - ( 5, 5, touch_pad(5), mux_sel, fun_sel, fun_ie, rue, rde) - ( 6, 6, touch_pad(6), mux_sel, fun_sel, fun_ie, rue, rde) - ( 7, 7, touch_pad(7), mux_sel, fun_sel, fun_ie, rue, rde) - ( 8, 8, touch_pad(8), mux_sel, fun_sel, fun_ie, rue, rde) - ( 9, 9, touch_pad(9), mux_sel, fun_sel, fun_ie, rue, rde) - (10, 10, touch_pad(10), mux_sel, fun_sel, fun_ie, rue, rde) - (11, 11, touch_pad(11), mux_sel, fun_sel, fun_ie, rue, rde) - (12, 12, touch_pad(12), mux_sel, fun_sel, fun_ie, rue, rde) - (13, 13, touch_pad(13), mux_sel, fun_sel, fun_ie, rue, rde) - (14, 14, touch_pad(14), mux_sel, fun_sel, fun_ie, rue, rde) - (15, 15, xtal_32p_pad(), x32p_mux_sel, x32p_fun_sel, x32p_fun_ie, x32p_rue, x32p_rde) - (16, 16, xtal_32n_pad(), x32n_mux_sel, x32n_fun_sel, x32n_fun_ie, x32n_rue, x32n_rde) - (17, 17, pad_dac1(), pdac1_mux_sel,pdac1_fun_sel,pdac1_fun_ie, pdac1_rue, pdac1_rde) - (18, 18, pad_dac2(), pdac2_mux_sel,pdac2_fun_sel,pdac2_fun_ie, pdac2_rue, pdac2_rde) - (19, 19, rtc_pad19(), mux_sel, fun_sel, fun_ie, rue, rde) - (20, 20, rtc_pad20(), mux_sel, fun_sel, fun_ie, rue, rde) - (21, 21, rtc_pad21(), mux_sel, fun_sel, fun_ie, rue, rde) + ( 0, 0, touch_pad(0), mux_sel, fun_sel, fun_ie, rue, rde) + ( 1, 1, touch_pad(1), mux_sel, fun_sel, fun_ie, rue, rde) + ( 2, 2, touch_pad(2), mux_sel, fun_sel, fun_ie, rue, rde) + ( 3, 3, touch_pad(3), mux_sel, fun_sel, fun_ie, rue, rde) + ( 4, 4, touch_pad(4), mux_sel, fun_sel, fun_ie, rue, rde) + ( 5, 5, touch_pad(5), mux_sel, fun_sel, fun_ie, rue, rde) + ( 6, 6, touch_pad(6), mux_sel, fun_sel, fun_ie, rue, rde) + ( 7, 7, touch_pad(7), mux_sel, fun_sel, fun_ie, rue, rde) + ( 8, 8, touch_pad(8), mux_sel, fun_sel, fun_ie, rue, rde) + ( 9, 9, touch_pad(9), mux_sel, fun_sel, fun_ie, rue, rde) + (10, 10, touch_pad(10), mux_sel, fun_sel, fun_ie, rue, rde) + (11, 11, touch_pad(11), mux_sel, fun_sel, fun_ie, rue, rde) + (12, 12, touch_pad(12), mux_sel, fun_sel, fun_ie, rue, rde) + (13, 13, touch_pad(13), mux_sel, fun_sel, fun_ie, rue, rde) + (14, 14, touch_pad(14), mux_sel, fun_sel, fun_ie, rue, rde) + (15, 15, xtal_32p_pad(), x32p_mux_sel, x32p_fun_sel, x32p_fun_ie, x32p_rue, x32p_rde) + (16, 16, xtal_32n_pad(), x32n_mux_sel, x32n_fun_sel, x32n_fun_ie, x32n_rue, x32n_rde) + (17, 17, pad_dac1(), pdac1_mux_sel,pdac1_fun_sel,pdac1_fun_ie, pdac1_rue, pdac1_rde) + (18, 18, pad_dac2(), pdac2_mux_sel,pdac2_fun_sel,pdac2_fun_ie, pdac2_rue, pdac2_rde) + (19, 19, rtc_pad19(), mux_sel, fun_sel, fun_ie, rue, rde) + (20, 20, rtc_pad20(), mux_sel, fun_sel, fun_ie, rue, rde) + (21, 21, rtc_pad21(), mux_sel, fun_sel, fun_ie, rue, rde) } crate::gpio::rtc_pins! { diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index a5650d10f..237ef8e54 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -542,7 +542,7 @@ where /// Sets the specified pin to input and connects it to the SPI MISO signal. pub fn with_miso(self, miso: impl Peripheral

+ 'd) -> Self { crate::into_ref!(miso); - miso.set_to_input(private::Internal); + miso.init_input(false, false, private::Internal); miso.connect_input_to_peripheral(self.spi.miso_signal(), private::Internal); self @@ -593,7 +593,7 @@ where if let Some(miso) = miso { crate::into_ref!(miso); - miso.set_to_input(private::Internal); + miso.init_input(false, false, private::Internal); miso.connect_input_to_peripheral(self.spi.miso_signal(), private::Internal); } diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index a7af7ab2f..3a915d7f4 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -115,16 +115,16 @@ where mode: SpiMode, ) -> Spi<'d, T, FullDuplexMode> { crate::into_ref!(spi, sck, mosi, miso, cs); - sck.set_to_input(private::Internal); + sck.init_input(false, false, private::Internal); sck.connect_input_to_peripheral(spi.sclk_signal(), private::Internal); - mosi.set_to_input(private::Internal); + mosi.init_input(false, false, private::Internal); mosi.connect_input_to_peripheral(spi.mosi_signal(), private::Internal); miso.set_to_push_pull_output(private::Internal); miso.connect_peripheral_to_output(spi.miso_signal(), private::Internal); - cs.set_to_input(private::Internal); + cs.init_input(false, false, private::Internal); cs.connect_input_to_peripheral(spi.cs_signal(), private::Internal); Self::new_internal(spi, mode) diff --git a/esp-hal/src/touch.rs b/esp-hal/src/touch.rs index e81034c5e..3005d2e29 100644 --- a/esp-hal/src/touch.rs +++ b/esp-hal/src/touch.rs @@ -13,7 +13,7 @@ //! # use esp_hal::gpio::Io; //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let touch_pin0 = io.pins.gpio2; -//! let touch = Touch::continous_mode(peripherals.TOUCH, None); +//! let touch = Touch::continuous_mode(peripherals.TOUCH, None); //! let mut touchpad = TouchPad::new(touch_pin0, &touch); //! // ... give the peripheral some time for the measurement //! let touch_val = touchpad.read(); @@ -50,16 +50,16 @@ pub trait TouchMode: Sealed {} #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct OneShot; -/// Marker struct for the touch peripherals continous reading mode. In the +/// Marker struct for the touch peripherals continuous reading mode. In the /// technical reference manual, this is referred to as "start FSM via timer". #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct Continous; +pub struct Continuous; impl TouchMode for OneShot {} -impl TouchMode for Continous {} +impl TouchMode for Continuous {} impl Sealed for OneShot {} -impl Sealed for Continous {} +impl Sealed for Continuous {} /// Touchpad threshold type. #[derive(Debug, Copy, Clone)] @@ -81,7 +81,7 @@ pub struct TouchConfig { /// Duration of a single measurement (in cycles of the 8 MHz touch clock). /// Defaults to `0x7fff` pub measurement_duration: Option, - /// Sleep cycles for the touch timer in [`Continous`]-mode. Defaults to + /// Sleep cycles for the touch timer in [`Continuous`]-mode. Defaults to /// `0x100` pub sleep_cycles: Option, } @@ -147,8 +147,8 @@ impl<'d, TOUCHMODE: TouchMode, MODE: Mode> Touch<'d, TOUCHMODE, MODE> { }); } - /// Common parts of the continous mode initialization. - fn initialize_common_continoous(config: Option) { + /// Common parts of the continuous mode initialization. + fn initialize_common_continuous(config: Option) { let rtccntl = unsafe { &*RTC_CNTL::ptr() }; let sens = unsafe { &*SENS::ptr() }; @@ -241,8 +241,8 @@ impl<'d> Touch<'d, OneShot, Blocking> { } } } -impl<'d> Touch<'d, Continous, Blocking> { - /// Initializes the touch peripheral in continous mode and returns this +impl<'d> Touch<'d, Continuous, Blocking> { + /// Initializes the touch peripheral in continuous mode and returns this /// marker struct. Optionally accepts configuration options. /// /// ## Example @@ -254,16 +254,16 @@ impl<'d> Touch<'d, Continous, Blocking> { /// measurement_duration: Some(0x3000), /// ..Default::default() /// }); - /// let touch = Touch::continous_mode(peripherals.TOUCH, touch_cfg); + /// let touch = Touch::continuous_mode(peripherals.TOUCH, touch_cfg); /// # } /// ``` - pub fn continous_mode( + pub fn continuous_mode( touch_peripheral: impl Peripheral

+ 'd, config: Option, ) -> Self { crate::into_ref!(touch_peripheral); - Self::initialize_common_continoous(config); + Self::initialize_common_continuous(config); Self { _inner: touch_peripheral, @@ -272,8 +272,8 @@ impl<'d> Touch<'d, Continous, Blocking> { } } } -impl<'d> Touch<'d, Continous, Async> { - /// Initializes the touch peripheral in continous async mode and returns +impl<'d> Touch<'d, Continuous, Async> { + /// Initializes the touch peripheral in continuous async mode and returns /// this marker struct. /// /// ## Warning: @@ -307,7 +307,7 @@ impl<'d> Touch<'d, Continous, Async> { ) -> Self { crate::into_ref!(touch_peripheral); - Self::initialize_common_continoous(config); + Self::initialize_common_continuous(config); rtc.set_interrupt_handler(asynch::handle_touch_interrupt); diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index 5a5cb1d8e..c8e3d943c 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -741,7 +741,7 @@ where } tx_pin.set_to_push_pull_output(crate::private::Internal); tx_pin.connect_peripheral_to_output(T::OUTPUT_SIGNAL, crate::private::Internal); - rx_pin.set_to_input(crate::private::Internal); + rx_pin.init_input(false, false, crate::private::Internal); rx_pin.connect_input_to_peripheral(T::INPUT_SIGNAL, crate::private::Internal); // Set the operating mode based on provided option diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index fa8c631a7..a3e7d75de 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -613,7 +613,7 @@ where /// Configure CTS pin pub fn with_cts(self, cts: impl Peripheral

+ 'd) -> Self { crate::into_ref!(cts); - cts.set_to_input(Internal); + cts.init_input(false, false, Internal); cts.connect_input_to_peripheral(T::cts_signal(), Internal); self @@ -791,7 +791,7 @@ where rx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(rx); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); let (uart_rx, _) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split(); @@ -817,7 +817,7 @@ where tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); Self::new_with_config_inner(uart, config) } @@ -833,7 +833,7 @@ where tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); Self::new_inner(uart) } @@ -848,7 +848,7 @@ where tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); Self::new_inner(uart) } @@ -916,7 +916,7 @@ where /// Configure CTS pin pub fn with_cts(self, cts: impl Peripheral

+ 'd) -> Self { crate::into_ref!(cts); - cts.set_to_input(Internal); + cts.init_input(false, false, Internal); cts.connect_input_to_peripheral(T::cts_signal(), Internal); self @@ -2141,7 +2141,7 @@ mod asynch { tx.set_to_push_pull_output(Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); let mut this = Self::new_with_config_inner(uart, config)?; @@ -2303,7 +2303,7 @@ mod asynch { rx: impl Peripheral

+ 'd, ) -> Result { crate::into_ref!(rx); - rx.set_to_input(Internal); + rx.init_input(false, false, Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal); let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config)?; diff --git a/examples/src/bin/etm_gpio.rs b/examples/src/bin/etm_gpio.rs index 25bcf9b9a..112fa2db7 100644 --- a/examples/src/bin/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -15,6 +15,7 @@ use esp_hal::{ etm::{GpioEtmChannels, GpioEtmInputConfig, GpioEtmOutputConfig}, Io, Level, + Output, Pull, }, prelude::*, @@ -25,7 +26,7 @@ fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio1; + let mut led = Output::new(io.pins.gpio1, Level::Low); let button = io.pins.gpio9; led.set_high(); diff --git a/examples/src/bin/i2s_read.rs b/examples/src/bin/i2s_read.rs index 1098b0ed3..ecfa92218 100644 --- a/examples/src/bin/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -1,4 +1,4 @@ -//! This shows how to continously receive data via I2S. +//! This shows how to continuously receive data via I2S. //! //! Without an additional I2S source device you can connect 3V3 or GND to DIN //! to read 0 or 0xFF or connect DIN to WS to read two different values. diff --git a/examples/src/bin/rmt_rx.rs b/examples/src/bin/rmt_rx.rs index 16fffe80b..948b6c8c6 100644 --- a/examples/src/bin/rmt_rx.rs +++ b/examples/src/bin/rmt_rx.rs @@ -14,7 +14,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - gpio::Io, + gpio::{Io, Level, Output}, prelude::*, rmt::{PulseCode, Rmt, RxChannel, RxChannelConfig, RxChannelCreator}, }; @@ -27,7 +27,7 @@ fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut out = io.pins.gpio5; + let mut out = Output::new(io.pins.gpio5, Level::Low); cfg_if::cfg_if! { if #[cfg(feature = "esp32h2")] { diff --git a/examples/src/bin/touch.rs b/examples/src/bin/touch.rs index 0f34e6d74..22a324c28 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -21,12 +21,12 @@ use esp_hal::{ macros::ram, prelude::*, rtc_cntl::Rtc, - touch::{Continous, Touch, TouchConfig, TouchPad}, + touch::{Continuous, Touch, TouchConfig, TouchPad}, Blocking, }; use esp_println::println; -static TOUCH1: Mutex, Continous, Blocking>>>> = +static TOUCH1: Mutex, Continuous, Blocking>>>> = Mutex::new(RefCell::new(None)); #[handler] @@ -62,7 +62,7 @@ fn main() -> ! { ..Default::default() }); - let touch = Touch::continous_mode(peripherals.TOUCH, touch_cfg); + let touch = Touch::continuous_mode(peripherals.TOUCH, touch_cfg); let mut touch0 = TouchPad::new(touch_pin0, &touch); let mut touch1 = TouchPad::new(touch_pin1, &touch);