Skip to content

Commit

Permalink
Remove RtcPin trait impls from Flex
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jan 13, 2025
1 parent e13c09e commit a625262
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 72 deletions.
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Removed all peripheral instance type parameters and `new_typed` constructors (#2907)

- Removed `Pin`, `RtcPin` and `RtcPinWithResistors` implementations from `Flex` (#2938)

## [0.22.0] - 2024-11-20

### Added
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/gpio/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ where

impl From<Flex<'static>> for InputSignal {
fn from(input: Flex<'static>) -> Self {
Self::new(input.degrade())
Self::new(unsafe { AnyPin::steal(input.pin.number()) })
}
}

Expand Down Expand Up @@ -359,14 +359,14 @@ impl<P> From<P> for OutputSignal
where
P: OutputPin,
{
fn from(input: P) -> Self {
Self::new(input.degrade())
fn from(output: P) -> Self {
Self::new(output.degrade())
}
}

impl From<Flex<'static>> for OutputSignal {
fn from(input: Flex<'static>) -> Self {
Self::new(input.degrade())
fn from(output: Flex<'static>) -> Self {
Self::new(unsafe { AnyPin::steal(output.pin.number()) })
}
}

Expand Down
40 changes: 4 additions & 36 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ impl<'d> Flex<'d> {
Self { pin }
}

fn number(&self) -> u8 {
self.pin.number()
}

/// Returns a peripheral [input][interconnect::InputSignal] connected to
/// this pin.
///
Expand Down Expand Up @@ -1865,42 +1869,6 @@ impl<'d> Flex<'d> {
}
}

// Unfortunate implementation details responsible for:
// - making pin drivers work with the peripheral signal system
// - making the pin drivers work with the sleep API
impl Pin for Flex<'_> {
delegate::delegate! {
to self.pin {
fn number(&self) -> u8;
fn output_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, OutputSignal)];
fn input_signals(&self, _internal: private::Internal) -> &'static [(AlternateFunction, InputSignal)];
}
}
}
#[cfg(any(lp_io, rtc_cntl))]
impl RtcPin for Flex<'_> {
delegate::delegate! {
to self.pin {
#[cfg(xtensa)]
fn rtc_number(&self) -> u8;
#[cfg(any(xtensa, esp32c6))]
fn rtc_set_config(&mut self, input_enable: bool, mux: bool, func: RtcFunction);
fn rtcio_pad_hold(&mut self, enable: bool);
#[cfg(any(esp32c3, esp32c2, esp32c6))]
unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8);
}
}
}
#[cfg(any(lp_io, rtc_cntl))]
impl RtcPinWithResistors for Flex<'_> {
delegate::delegate! {
to self.pin {
fn rtcio_pullup(&mut self, enable: bool);
fn rtcio_pulldown(&mut self, enable: bool);
}
}
}

impl private::Sealed for AnyPin {}

impl AnyPin {
Expand Down
38 changes: 20 additions & 18 deletions esp-hal/src/rtc_cntl/sleep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ pub enum Error {
/// let delay = Delay::new();
/// let mut rtc = Rtc::new(peripherals.LPWR);
///
/// let pin_0 = Input::new(peripherals.GPIO4, Pull::None);
/// let mut pin_4 = peripherals.GPIO4;
/// let pin_4_input = Input::new(&mut pin_4, Pull::None);
///
/// let reason =
/// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
Expand All @@ -119,7 +120,8 @@ pub enum Error {
///
/// let timer = TimerWakeupSource::new(Duration::from_secs(30));
///
/// let ext0 = Ext0WakeupSource::new(pin_0, WakeupLevel::High);
/// core::mem::drop(pin_4_input);
/// let ext0 = Ext0WakeupSource::new(&mut pin_4, WakeupLevel::High);
///
/// delay.delay_millis(100);
/// rtc.sleep_deep(&[&timer, &ext0]);
Expand Down Expand Up @@ -161,19 +163,21 @@ impl<'a, P: RtcIoWakeupPinType> Ext0WakeupSource<'a, P> {
/// let delay = Delay::new();
/// let mut rtc = Rtc::new(peripherals.LPWR);
///
/// let pin_4 = Input::new(peripherals.GPIO4, Pull::None);
/// let mut pin_2 = peripherals.GPIO2;
/// let mut pin_4 = peripherals.GPIO4;
/// let pin_4_driver = Input::new(&mut pin_4, Pull::None);
///
/// let reason =
/// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
/// let reason = reset_reason(Cpu::ProCpu)
/// .unwrap_or(SocResetReason::ChipPowerOn);
///
/// let wake_reason = wakeup_cause();
///
/// let timer = TimerWakeupSource::new(Duration::from_secs(30));
///
/// // Drop the driver to access `pin_4`
/// core::mem::drop(pin_4_driver);
///
/// let mut wakeup_pins: [&mut dyn RtcPin; 2] =
/// [&mut *pin_4.into_ref(), &mut pin_2];
/// let mut wakeup_pins: [&mut dyn RtcPin; 2] = [&mut pin_4, &mut pin_2];
///
/// let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High);
///
Expand Down Expand Up @@ -215,8 +219,9 @@ impl<'a, 'b> Ext1WakeupSource<'a, 'b> {
/// let delay = Delay::new();
/// let mut rtc = Rtc::new(peripherals.LPWR);
///
/// let pin2 = Input::new(peripherals.GPIO2, Pull::None);
/// let mut pin2 = peripherals.GPIO2;
/// let mut pin3 = peripherals.GPIO3;
/// let mut pin2_input = Input::new(&mut pin2, Pull::None);
///
/// let reason =
/// reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
Expand All @@ -225,8 +230,11 @@ impl<'a, 'b> Ext1WakeupSource<'a, 'b> {
///
/// let timer = TimerWakeupSource::new(Duration::from_secs(30));
///
/// core::mem::drop(pin2_input);
///
/// let wakeup_pins: &mut [(&mut dyn RtcPinWithResistors, WakeupLevel)] =
/// &mut [(&mut *pin2.into_ref(), WakeupLevel::Low),
/// &mut [
/// (&mut pin2, WakeupLevel::Low),
/// (&mut pin3, WakeupLevel::High),
/// ];
///
Expand Down Expand Up @@ -277,15 +285,9 @@ impl<'a, 'b> Ext1WakeupSource<'a, 'b> {
///
/// let delay = Delay::new();
/// let timer = TimerWakeupSource::new(Duration::from_secs(10));
#[cfg_attr(
any(esp32c3, esp32c2),
doc = "let pin_0 = Input::new(peripherals.GPIO2, Pull::None);"
)]
#[cfg_attr(any(esp32c3, esp32c2), doc = "let mut pin_0 = peripherals.GPIO2;")]
#[cfg_attr(any(esp32c3, esp32c2), doc = "let mut pin_1 = peripherals.GPIO3;")]
#[cfg_attr(
esp32s3,
doc = "let pin_0 = Input::new(peripherals.GPIO17, Pull::None);"
)]
#[cfg_attr(esp32s3, doc = "let mut pin_0 = peripherals.GPIO17;")]
#[cfg_attr(esp32s3, doc = "let mut pin_1 = peripherals.GPIO18;")]
#[cfg_attr(
any(esp32c3, esp32c2),
Expand All @@ -295,7 +297,7 @@ impl<'a, 'b> Ext1WakeupSource<'a, 'b> {
esp32s3,
doc = "let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = &mut ["
)]
/// (&mut *pin_0.into_ref(), WakeupLevel::Low),
/// (&mut pin_0, WakeupLevel::Low),
/// (&mut pin_1, WakeupLevel::High),
/// ];
///
Expand Down
7 changes: 5 additions & 2 deletions qa-test/src/bin/sleep_timer_ext0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ fn main() -> ! {

let mut rtc = Rtc::new(peripherals.LPWR);

let ext0_pin = Input::new(peripherals.GPIO4, Pull::None);
let mut pin4 = peripherals.GPIO4;
let ext0_pin = Input::new(&mut pin4, Pull::None);

println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
Expand All @@ -42,8 +43,10 @@ fn main() -> ! {

let delay = Delay::new();

core::mem::drop(ext0_pin);

let timer = TimerWakeupSource::new(Duration::from_secs(30));
let ext0 = Ext0WakeupSource::new(ext0_pin, WakeupLevel::High);
let ext0 = Ext0WakeupSource::new(&mut pin4, WakeupLevel::High);
println!("sleeping!");
delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &ext0]);
Expand Down
7 changes: 4 additions & 3 deletions qa-test/src/bin/sleep_timer_ext1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use esp_hal::{
delay::Delay,
entry,
gpio::{Input, Pull, RtcPin},
peripheral::Peripheral,
rtc_cntl::{
reset_reason,
sleep::{Ext1WakeupSource, TimerWakeupSource, WakeupLevel},
Expand All @@ -33,8 +32,9 @@ fn main() -> ! {

let mut rtc = Rtc::new(peripherals.LPWR);

let pin_0 = Input::new(peripherals.GPIO4, Pull::None);
let mut pin_2 = peripherals.GPIO2;
let mut pin_4 = peripherals.GPIO4;
let input = Input::new(&mut pin_4, Pull::None);

println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
Expand All @@ -45,7 +45,8 @@ fn main() -> ! {
let delay = Delay::new();

let timer = TimerWakeupSource::new(Duration::from_secs(30));
let mut wakeup_pins: [&mut dyn RtcPin; 2] = [&mut *pin_0.into_ref(), &mut pin_2];
core::mem::drop(input);
let mut wakeup_pins: [&mut dyn RtcPin; 2] = [&mut pin_4, &mut pin_2];
let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High);
println!("sleeping!");
delay.delay_millis(100);
Expand Down
8 changes: 5 additions & 3 deletions qa-test/src/bin/sleep_timer_lpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use esp_hal::{
delay::Delay,
entry,
gpio::{Input, Pull, RtcPinWithResistors},
peripheral::Peripheral,
rtc_cntl::{
reset_reason,
sleep::{Ext1WakeupSource, TimerWakeupSource, WakeupLevel},
Expand All @@ -34,8 +33,9 @@ fn main() -> ! {

let mut rtc = Rtc::new(peripherals.LPWR);

let pin2 = Input::new(peripherals.GPIO2, Pull::None);
let mut pin2 = peripherals.GPIO2;
let mut pin3 = peripherals.GPIO3;
let input = Input::new(&mut pin2, Pull::None);

println!("up and runnning!");
let reason = reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn);
Expand All @@ -46,8 +46,10 @@ fn main() -> ! {
let delay = Delay::new();
let timer = TimerWakeupSource::new(Duration::from_secs(10));

core::mem::drop(input);

let wakeup_pins: &mut [(&mut dyn RtcPinWithResistors, WakeupLevel)] = &mut [
(&mut *pin2.into_ref(), WakeupLevel::Low),
(&mut pin2, WakeupLevel::Low),
(&mut pin3, WakeupLevel::High),
];

Expand Down
11 changes: 6 additions & 5 deletions qa-test/src/bin/sleep_timer_rtcio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use esp_hal::{
entry,
gpio,
gpio::{Input, Pull},
peripheral::Peripheral,
rtc_cntl::{
reset_reason,
sleep::{RtcioWakeupSource, TimerWakeupSource, WakeupLevel},
Expand Down Expand Up @@ -49,19 +48,21 @@ fn main() -> ! {

cfg_if::cfg_if! {
if #[cfg(any(feature = "esp32c3", feature = "esp32c2"))] {
let pin2 = Input::new(peripherals.GPIO2, Pull::None);
let mut pin2 = peripherals.GPIO2;
let mut pin3 = peripherals.GPIO3;
let _pin2_input = Input::new(&mut pin2, Pull::None);

let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [
(&mut *pin2.into_ref(), WakeupLevel::Low),
(&mut pin2, WakeupLevel::Low),
(&mut pin3, WakeupLevel::High),
];
} else if #[cfg(feature = "esp32s3")] {
let pin17 = Input::new(peripherals.GPIO17, Pull::None);
let mut pin17 = peripherals.GPIO17;
let mut pin18 = peripherals.GPIO18;
let _pin17_input = Input::new(&mut pin17, Pull::None);

let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = &mut [
(&mut *pin17.into_ref(), WakeupLevel::Low),
(&mut pin17, WakeupLevel::Low),
(&mut pin18, WakeupLevel::High),
];
}
Expand Down

0 comments on commit a625262

Please sign in to comment.