diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index e09fd05882..9eace1da82 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `gpio::{GpioPin, AnyPin, Flex, Output, OutputOpenDrain}::split()` to obtain peripheral interconnect signals. (#2418) - `gpio::Input::{split(), into_peripheral_output()}` when used with output pins. (#2418) - `gpio::Output::peripheral_input()` (#2418) +- GPIO ETM tasks and events now accept `InputSignal` and `OutputSignal` (#2427) ### Changed @@ -67,11 +68,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed the pin type parameters from `lcd_cam::lcd::i8080::{TxEightBits, TxSixteenBits}` (#2388) - Removed the pin type parameters from `lcd_cam::cam::{RxEightBits, RxSixteenBits}` (#2388) - `gpio::{Input, Output, OutputOpenDrain, Flex, GpioPin}::{peripheral_input, into_peripheral_output}` have been removed. (#2418) -- The `GpioEtm` prefix has been removed from `gpio::etm` types (#?) -- The `TimerEtm` prefix has been removed from `timer::timg::etm` types (#?) -- The `SysTimerEtm` prefix has been removed from `timer::systimer::etm` types (#?) -- The `GpioEtmEventRising`, `GpioEtmEventFalling`, `GpioEtmEventAny` types have been replaced with `Event` (#?) -- The `TaskSet`, `TaskClear`, `TaskToggle` types have been replaced with `Event` (#?) +- The `GpioEtm` prefix has been removed from `gpio::etm` types (#2427) +- The `TimerEtm` prefix has been removed from `timer::timg::etm` types (#2427) +- The `SysTimerEtm` prefix has been removed from `timer::systimer::etm` types (#2427) +- The `GpioEtmEventRising`, `GpioEtmEventFalling`, `GpioEtmEventAny` types have been replaced with `Event` (#2427) +- The `TaskSet`, `TaskClear`, `TaskToggle` types have been replaced with `Task` (#2427) ## [0.21.1] diff --git a/esp-hal/MIGRATING-0.21.md b/esp-hal/MIGRATING-0.21.md index d11bfe8f79..88bdb73827 100644 --- a/esp-hal/MIGRATING-0.21.md +++ b/esp-hal/MIGRATING-0.21.md @@ -193,7 +193,7 @@ The previous signal function have been replaced by `split`. This change affects +let (input_signal, output_signal) = gpioN.split(); ``` -# ETM simplifications +## ETM changes - The types are no longer prefixed with `GpioEtm`, `TimerEtm` or `SysTimerEtm`. You can still use import aliasses in case you need to differentiate due to name collisions diff --git a/esp-hal/src/etm.rs b/esp-hal/src/etm.rs index 1e8322c185..8f6c9c47ef 100644 --- a/esp-hal/src/etm.rs +++ b/esp-hal/src/etm.rs @@ -24,10 +24,8 @@ //! ```rust, no_run #![doc = crate::before_snippet!()] //! # use esp_hal::gpio::Io; -//! # use esp_hal::gpio::etm::GpioEtmChannels; +//! # use esp_hal::gpio::etm::{Channels, InputConfig, OutputConfig}; //! # use esp_hal::etm::Etm; -//! # use esp_hal::gpio::etm::GpioEtmInputConfig; -//! # use esp_hal::gpio::etm::GpioEtmOutputConfig; //! # use esp_hal::gpio::Pull; //! # use esp_hal::gpio::Level; //! @@ -36,18 +34,18 @@ //! let button = io.pins.gpio9; //! //! // setup ETM -//! let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); +//! let gpio_ext = Channels::new(peripherals.GPIO_SD); //! let led_task = gpio_ext.channel0_task.toggle( -//! &mut led, -//! GpioEtmOutputConfig { -//! open_drain: false, -//! pull: Pull::None, -//! initial_state: Level::Low, -//! }, +//! &mut led, +//! OutputConfig { +//! open_drain: false, +//! pull: Pull::None, +//! initial_state: Level::Low, +//! }, //! ); //! let button_event = gpio_ext //! .channel0_event -//! .falling_edge(button, GpioEtmInputConfig { pull: Pull::Down }); +//! .falling_edge(button, InputConfig { pull: Pull::Down }); //! //! let etm = Etm::new(peripherals.SOC_ETM); //! let channel0 = etm.channel0; diff --git a/esp-hal/src/gpio/etm.rs b/esp-hal/src/gpio/etm.rs index 20ccf6c89e..c92a2c5286 100644 --- a/esp-hal/src/gpio/etm.rs +++ b/esp-hal/src/gpio/etm.rs @@ -32,7 +32,7 @@ //! # use esp_hal::gpio::etm::OutputConfig; //! # use esp_hal::gpio::Pull; //! # use esp_hal::gpio::Level; -//! +//! # //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let mut led = io.pins.gpio1; //! # let button = io.pins.gpio9; @@ -55,7 +55,11 @@ use core::marker::PhantomData; use crate::{ - gpio::{Level, Pull}, + gpio::{ + interconnect::{InputSignal, OutputSignal}, + Level, + Pull, + }, peripheral::{Peripheral, PeripheralRef}, peripherals::GPIO_SD, private, @@ -147,7 +151,7 @@ impl EventChannel { /// Trigger at rising edge pub fn rising_edge<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: InputConfig, ) -> Event<'d> { self.into_event(pin, pin_config, EventKind::Rising) @@ -156,7 +160,7 @@ impl EventChannel { /// Trigger at falling edge pub fn falling_edge<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: InputConfig, ) -> Event<'d> { self.into_event(pin, pin_config, EventKind::Falling) @@ -165,7 +169,7 @@ impl EventChannel { /// Trigger at any edge pub fn any_edge<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: InputConfig, ) -> Event<'d> { self.into_event(pin, pin_config, EventKind::Any) @@ -173,11 +177,11 @@ impl EventChannel { fn into_event<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: InputConfig, kind: EventKind, ) -> Event<'d> { - crate::into_ref!(pin); + crate::into_mapped_ref!(pin); pin.init_input(pin_config.pull, private::Internal); @@ -255,7 +259,7 @@ impl TaskChannel { /// Task to set a high level pub fn set<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: OutputConfig, ) -> Task<'d> { self.into_task(pin, pin_config, TaskKind::Set) @@ -264,7 +268,7 @@ impl TaskChannel { /// Task to set a low level pub fn clear<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: OutputConfig, ) -> Task<'d> { self.into_task(pin, pin_config, TaskKind::Clear) @@ -273,7 +277,7 @@ impl TaskChannel { /// Task to toggle the level pub fn toggle<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: OutputConfig, ) -> Task<'d> { self.into_task(pin, pin_config, TaskKind::Toggle) @@ -281,11 +285,11 @@ impl TaskChannel { fn into_task<'d>( self, - pin: impl Peripheral

+ 'd, + pin: impl Peripheral

> + 'd, pin_config: OutputConfig, kind: TaskKind, ) -> Task<'d> { - crate::into_ref!(pin); + crate::into_mapped_ref!(pin); pin.set_output_high(pin_config.initial_state.into(), private::Internal); if pin_config.open_drain { diff --git a/esp-hal/src/gpio/interconnect.rs b/esp-hal/src/gpio/interconnect.rs index 4f95a927cc..b86b76c2ae 100644 --- a/esp-hal/src/gpio/interconnect.rs +++ b/esp-hal/src/gpio/interconnect.rs @@ -60,6 +60,15 @@ pub struct InputSignal { is_inverted: bool, } +impl

From

for InputSignal +where + P: InputPin, +{ + fn from(input: P) -> Self { + Self::new(input.degrade()) + } +} + impl Clone for InputSignal { fn clone(&self) -> Self { Self { @@ -87,6 +96,11 @@ impl InputSignal { } } + /// Returns the GPIO number of the underlying pin. + pub fn number(&self) -> u8 { + self.pin.number() + } + /// Returns the current signal level. pub fn get_level(&self) -> Level { self.is_input_high(private::Internal).into() @@ -120,9 +134,7 @@ impl InputSignal { w.in_sel().bits(input) }); } -} -impl InputSignal { /// Connect the pin to a peripheral input signal. /// /// Since there can only be one input signal connected to a peripheral at a @@ -191,6 +203,15 @@ pub struct OutputSignal { is_inverted: bool, } +impl

From

for OutputSignal +where + P: OutputPin, +{ + fn from(input: P) -> Self { + Self::new(input.degrade()) + } +} + impl Peripheral for OutputSignal { type P = Self; @@ -212,6 +233,11 @@ impl OutputSignal { } } + /// Returns the GPIO number of the underlying pin. + pub fn number(&self) -> u8 { + self.pin.number() + } + /// Inverts the peripheral's output signal. /// /// Calling this function multiple times toggles the setting. @@ -268,9 +294,7 @@ impl OutputSignal { w.oen_inv_sel().bit(invert_enable) }); } -} -impl OutputSignal { /// Connect the pin to a peripheral input signal. /// /// Since there can only be one signal connected to a peripheral input at a @@ -434,9 +458,7 @@ where P: InputPin, { fn from(input: P) -> Self { - Self(InputConnectionInner::Input(InputSignal::new( - input.degrade(), - ))) + Self(InputConnectionInner::Input(InputSignal::from(input))) } } @@ -527,9 +549,7 @@ where P: OutputPin, { fn from(input: P) -> Self { - Self(OutputConnectionInner::Output(OutputSignal::new( - input.degrade(), - ))) + Self(OutputConnectionInner::Output(OutputSignal::from(input))) } } diff --git a/examples/src/bin/etm_blinky_systimer.rs b/examples/src/bin/etm_blinky_systimer.rs index afe20d18f4..65b141bfb5 100644 --- a/examples/src/bin/etm_blinky_systimer.rs +++ b/examples/src/bin/etm_blinky_systimer.rs @@ -12,7 +12,7 @@ use esp_backtrace as _; use esp_hal::{ etm::Etm, gpio::{ - etm::{GpioEtmChannels, GpioEtmOutputConfig}, + etm::{Channels, OutputConfig}, Io, Level, Pull, @@ -35,10 +35,10 @@ fn main() -> ! { let mut led = io.pins.gpio1; // setup ETM - let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); + let gpio_ext = Channels::new(peripherals.GPIO_SD); let led_task = gpio_ext.channel0_task.toggle( &mut led, - GpioEtmOutputConfig { + OutputConfig { open_drain: false, pull: Pull::None, initial_state: Level::High, diff --git a/examples/src/bin/etm_gpio.rs b/examples/src/bin/etm_gpio.rs index 112fa2db78..83cf726c4a 100644 --- a/examples/src/bin/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -12,7 +12,7 @@ use esp_backtrace as _; use esp_hal::{ etm::Etm, gpio::{ - etm::{GpioEtmChannels, GpioEtmInputConfig, GpioEtmOutputConfig}, + etm::{Channels, InputConfig, OutputConfig}, Io, Level, Output, @@ -26,16 +26,17 @@ fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); + let mut led = Output::new(io.pins.gpio1, Level::Low); let button = io.pins.gpio9; led.set_high(); // setup ETM - let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); + let gpio_ext = Channels::new(peripherals.GPIO_SD); let led_task = gpio_ext.channel0_task.toggle( - &mut led, - GpioEtmOutputConfig { + led, + OutputConfig { open_drain: false, pull: Pull::None, initial_state: Level::Low, @@ -43,7 +44,7 @@ fn main() -> ! { ); let button_event = gpio_ext .channel0_event - .falling_edge(button, GpioEtmInputConfig { pull: Pull::Down }); + .falling_edge(button, InputConfig { pull: Pull::Down }); let etm = Etm::new(peripherals.SOC_ETM); let channel0 = etm.channel0;