Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO interconnect #2128

Merged
merged 21 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Previously unavailable memory is available via `.dram2_uninit` section (#2079)
- You can now use `Input`, `Output`, `OutputOpenDrain` and `Flex` pins as EXTI and RTCIO wakeup sources (#2095)
- Added `Rtc::set_current_time` to allow setting RTC time, and `Rtc::current_time` to getting RTC time while taking into account boot time (#1883)
- Added APIs to allow connecting signals through the GPIO matrix. (#2128)

### Changed

Expand All @@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The (previously undocumented) `ErasedPin` enum has been replaced with the `ErasedPin` struct. (#2094)
- Renamed and merged `Rtc::get_time_us` and `Rtc::get_time_ms` into `Rtc::time_since_boot` (#1883)
- ESP32: Added support for touch sensing on GPIO32 and 33 (#2109)
- Replaced `AnyPin` with `InputSignal` and `OutputSignal` and renamed `ErasedPin` to `AnyPin` (#2128)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion esp-hal/MIGRATING-0.20.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ You no longer have to spell out the GPIO pin type for `Input`, `Output`, `Output
However, if you want to, you can keep using their typed form!

```rust
let pin = Input::new(io.gpio0); // pin will have the type `Input<'some>` (or `Input<'some, ErasedPin>` if you want to be explicit about it)
let pin = Input::new(io.gpio0); // pin will have the type `Input<'some>` (or `Input<'some, AnyPin>` if you want to be explicit about it)
let pin = Input::new_typed(io.gpio0); // pin will have the type `Input<'some, GpioPin<0>>`
```

Expand Down
169 changes: 0 additions & 169 deletions esp-hal/src/gpio/any_pin.rs

This file was deleted.

132 changes: 63 additions & 69 deletions esp-hal/src/gpio/dummy_pin.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! "Dummy" pins".
//! Placeholder pins.
//!
//! These are useful to pass them into peripheral drivers where you don't want
//! an actual pin but one is required.

use super::*;

/// DummyPin, not useful everywhere as it panics if number() is called
#[derive(Default)]
#[derive(Default, Clone)]
pub struct DummyPin {
value: bool,
}
Expand All @@ -27,43 +28,72 @@ impl crate::peripheral::Peripheral for DummyPin {

impl private::Sealed for DummyPin {}

impl Pin for DummyPin {
fn number(&self, _: private::Internal) -> u8 {
panic!("DummyPin not supported here!");
impl PeripheralInput for DummyPin {
fn input_signals(&self, _: private::Internal) -> [Option<InputSignal>; 6] {
[None; 6]
}

fn degrade_internal(&self, _: private::Internal) -> ErasedPin {
panic!("Can not type erase the DummyPin!");
}
fn init_input(&self, _pull: Pull, _: private::Internal) {}

fn sleep_mode(&mut self, _on: bool, _: private::Internal) {}
fn enable_input(&mut self, _on: bool, _: private::Internal) {}

fn set_alternate_function(&mut self, _alternate: AlternateFunction, _: private::Internal) {}
fn enable_input_in_sleep_mode(&mut self, _on: bool, _: private::Internal) {}

fn is_listening(&self, _: private::Internal) -> bool {
false
fn is_input_high(&self, _: private::Internal) -> bool {
self.value
}

fn listen_with_options(
&mut self,
_event: Event,
_int_enable: bool,
_nmi_enable: bool,
_wake_up_from_light_sleep: bool,
_: private::Internal,
) {
fn connect_input_to_peripheral(&mut self, signal: InputSignal, _: private::Internal) {
let value = if self.value { ONE_INPUT } else { ZERO_INPUT };

unsafe { &*GPIO::PTR }
.func_in_sel_cfg(signal as usize - FUNC_IN_SEL_OFFSET)
.modify(|_, w| unsafe {
w.sel()
.set_bit()
.in_inv_sel()
.bit(false)
.in_sel()
.bits(value)
});
}

fn unlisten(&mut self, _: private::Internal) {}
fn disconnect_input_from_peripheral(&mut self, _signal: InputSignal, _: private::Internal) {}
}

impl PeripheralSignal for Level {
delegate::delegate! {
to match self {
Level::High => DummyPin { value: true },
Level::Low => DummyPin { value: false },
} {
fn pull_direction(&self, pull: Pull, _internal: private::Internal);
}
}
}

fn is_interrupt_set(&self, _: private::Internal) -> bool {
false
impl PeripheralInput for Level {
delegate::delegate! {
to match self {
Level::High => DummyPin { value: true },
Level::Low => DummyPin { value: false },
} {
fn init_input(&self, _pull: Pull, _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;
fn connect_input_to_peripheral(&mut self, _signal: InputSignal, _internal: private::Internal);
fn disconnect_input_from_peripheral(&mut self, _signal: InputSignal, _internal: private::Internal);
fn input_signals(&self, _internal: private::Internal) -> [Option<InputSignal>; 6];
}
}
}

fn clear_interrupt(&mut self, _: private::Internal) {}
impl PeripheralSignal for DummyPin {
fn pull_direction(&self, _pull: Pull, _internal: private::Internal) {}
}

impl OutputPin for DummyPin {
impl PeripheralOutput for DummyPin {
fn set_to_open_drain_output(&mut self, _: private::Internal) {}

fn set_to_push_pull_output(&mut self, _: private::Internal) {}
Expand All @@ -84,53 +114,17 @@ impl OutputPin for DummyPin {

fn internal_pull_down_in_sleep_mode(&mut self, _on: bool, _: private::Internal) {}

fn internal_pull_up(&mut self, _on: bool, _: private::Internal) {}

fn internal_pull_down(&mut self, _on: bool, _: private::Internal) {}

fn connect_peripheral_to_output(&mut self, _signal: OutputSignal, _: private::Internal) {}

fn connect_peripheral_to_output_with_options(
&mut self,
_signal: OutputSignal,
_invert: bool,
_invert_enable: bool,
_enable_from_gpio: bool,
_force_via_gpio_mux: bool,
_: private::Internal,
) {
}

fn disconnect_peripheral_from_output(&mut self, _: private::Internal) {}

fn is_set_high(&self, _: private::Internal) -> bool {
self.value
}
}

impl InputPin for DummyPin {
fn init_input(&self, _pull_down: bool, _pull_up: bool, _: private::Internal) {}

fn enable_input(&mut self, _on: bool, _: private::Internal) {}

fn enable_input_in_sleep_mode(&mut self, _on: bool, _: private::Internal) {}

fn is_input_high(&self, _: private::Internal) -> bool {
self.value
fn output_signals(&self, _: private::Internal) -> [Option<OutputSignal>; 6] {
[None; 6]
}

fn connect_input_to_peripheral(&mut self, _signal: InputSignal, _: private::Internal) {}

fn connect_input_to_peripheral_with_options(
&mut self,
_signal: InputSignal,
_invert: bool,
_force_via_gpio_mux: bool,
_: private::Internal,
) {
}
fn connect_peripheral_to_output(&mut self, _signal: OutputSignal, _: private::Internal) {}

fn disconnect_input_from_peripheral(&mut self, _signal: InputSignal, _: private::Internal) {}
fn disconnect_from_peripheral_output(&mut self, _signal: OutputSignal, _: private::Internal) {}
}

impl embedded_hal_02::digital::v2::OutputPin for DummyPin {
Expand All @@ -147,10 +141,10 @@ impl embedded_hal_02::digital::v2::OutputPin for DummyPin {
}
impl embedded_hal_02::digital::v2::StatefulOutputPin for DummyPin {
fn is_set_high(&self) -> Result<bool, Self::Error> {
Ok(OutputPin::is_set_high(self, private::Internal))
Ok(PeripheralOutput::is_set_high(self, private::Internal))
}
fn is_set_low(&self) -> Result<bool, Self::Error> {
Ok(!OutputPin::is_set_high(self, private::Internal))
Ok(!PeripheralOutput::is_set_high(self, private::Internal))
}
}

Expand All @@ -172,10 +166,10 @@ impl embedded_hal::digital::OutputPin for DummyPin {

impl embedded_hal::digital::StatefulOutputPin for DummyPin {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
Ok(OutputPin::is_set_high(self, private::Internal))
Ok(PeripheralOutput::is_set_high(self, private::Internal))
}

fn is_set_low(&mut self) -> Result<bool, Self::Error> {
Ok(!OutputPin::is_set_high(self, private::Internal))
Ok(!PeripheralOutput::is_set_high(self, private::Internal))
}
}
Loading