diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs
index f512ad05a2..0cfbb2e526 100644
--- a/esp-hal/src/dma/mod.rs
+++ b/esp-hal/src/dma/mod.rs
@@ -949,12 +949,6 @@ macro_rules! impl_dma_eligible {
};
}
-/// Marker trait
-#[doc(hidden)]
-pub trait PeripheralMarker {
- fn peripheral(&self) -> crate::system::Peripheral;
-}
-
#[doc(hidden)]
#[derive(Debug)]
pub struct DescriptorChain {
diff --git a/esp-hal/src/i2c.rs b/esp-hal/src/i2c.rs
index 0e636efe22..62f342d6ea 100644
--- a/esp-hal/src/i2c.rs
+++ b/esp-hal/src/i2c.rs
@@ -66,7 +66,6 @@ use procmacros::handler;
use crate::{
clock::Clocks,
- dma::PeripheralMarker,
gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull},
interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef},
@@ -1176,7 +1175,9 @@ pub(super) fn i2c1_handler() {
/// I2C Peripheral Instance
#[doc(hidden)]
-pub trait Instance: Peripheral
+ PeripheralMarker + Into + 'static {
+pub trait Instance: Peripheral + Into + 'static {
+ fn peripheral(&self) -> crate::system::Peripheral;
+
/// Returns the interrupt associated with this I2C peripheral.
fn interrupt(&self) -> crate::peripherals::Interrupt;
@@ -2204,14 +2205,12 @@ fn write_fifo(register_block: &RegisterBlock, data: u8) {
}
}
-impl PeripheralMarker for crate::peripherals::I2C0 {
+impl Instance for crate::peripherals::I2C0 {
#[inline(always)]
fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2cExt0
}
-}
-impl Instance for crate::peripherals::I2C0 {
#[inline(always)]
fn async_handler(&self) -> InterruptHandler {
i2c0_handler
@@ -2254,15 +2253,12 @@ impl Instance for crate::peripherals::I2C0 {
}
#[cfg(i2c1)]
-impl PeripheralMarker for crate::peripherals::I2C1 {
+impl Instance for crate::peripherals::I2C1 {
#[inline(always)]
fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2cExt1
}
-}
-#[cfg(i2c1)]
-impl Instance for crate::peripherals::I2C1 {
#[inline(always)]
fn async_handler(&self) -> InterruptHandler {
i2c1_handler
@@ -2322,6 +2318,7 @@ impl Instance for AnyI2c {
AnyI2cInner::I2c1(i2c) => i2c,
} {
fn interrupt(&self) -> crate::peripherals::Interrupt;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn async_handler(&self) -> InterruptHandler;
fn scl_output_signal(&self) -> OutputSignal;
fn scl_input_signal(&self) -> InputSignal;
diff --git a/esp-hal/src/i2s/master.rs b/esp-hal/src/i2s/master.rs
index 78728ac36a..6a418b966e 100644
--- a/esp-hal/src/i2s/master.rs
+++ b/esp-hal/src/i2s/master.rs
@@ -773,14 +773,7 @@ mod private {
#[cfg(i2s1)]
use crate::peripherals::{i2s1::RegisterBlock, I2S1};
use crate::{
- dma::{
- ChannelRx,
- ChannelTx,
- DescriptorChain,
- DmaDescriptor,
- DmaEligible,
- PeripheralMarker,
- },
+ dma::{ChannelRx, ChannelTx, DescriptorChain, DmaDescriptor, DmaEligible},
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
@@ -911,10 +904,9 @@ mod private {
}
}
- pub trait RegBlock:
- Peripheral + PeripheralMarker + DmaEligible + Into + 'static
- {
+ pub trait RegBlock: Peripheral + DmaEligible + Into + 'static {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
}
pub trait Signals: RegBlock {
@@ -1609,6 +1601,10 @@ mod private {
fn register_block(&self) -> &RegisterBlock {
unsafe { &*I2S0::PTR.cast::() }
}
+
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::I2s0
+ }
}
impl RegisterAccessPrivate for I2S0 {
@@ -1713,6 +1709,10 @@ mod private {
fn register_block(&self) -> &RegisterBlock {
unsafe { &*I2S1::PTR.cast::() }
}
+
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::I2s1
+ }
}
#[cfg(i2s1)]
@@ -1786,6 +1786,7 @@ mod private {
super::AnyI2sInner::I2s1(i2s) => i2s,
} {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
}
}
}
diff --git a/esp-hal/src/i2s/parallel.rs b/esp-hal/src/i2s/parallel.rs
index d8888f2537..865346fb64 100644
--- a/esp-hal/src/i2s/parallel.rs
+++ b/esp-hal/src/i2s/parallel.rs
@@ -52,7 +52,6 @@ use crate::{
DmaError,
DmaPeripheral,
DmaTxBuffer,
- PeripheralMarker,
Tx,
},
gpio::{
@@ -424,10 +423,9 @@ fn calculate_clock(sample_rate: impl Into, data_bits: u8) -> I2
}
#[doc(hidden)]
-pub trait Instance:
- Peripheral + PeripheralMarker + DmaEligible + Into + 'static
-{
+pub trait Instance: Peripheral + DmaEligible + Into + 'static {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn ws_signal(&self) -> OutputSignal;
fn data_out_signal(&self, i: usize, bits: u8) -> OutputSignal;
@@ -614,6 +612,10 @@ impl Instance for I2S0 {
unsafe { &*I2S0::PTR.cast::() }
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::I2s0
+ }
+
fn ws_signal(&self) -> OutputSignal {
OutputSignal::I2S0O_WS
}
@@ -661,6 +663,10 @@ impl Instance for I2S1 {
unsafe { &*I2S1::PTR.cast::() }
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::I2s1
+ }
+
fn ws_signal(&self) -> OutputSignal {
OutputSignal::I2S1O_WS
}
@@ -729,6 +735,7 @@ impl Instance for AnyI2s {
AnyI2sInner::I2s1(i2s) => i2s,
} {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn ws_signal(&self) -> OutputSignal;
fn data_out_signal(&self, i: usize, bits: u8) -> OutputSignal ;
}
diff --git a/esp-hal/src/macros.rs b/esp-hal/src/macros.rs
index c22b5a44a6..f4274d8033 100644
--- a/esp-hal/src/macros.rs
+++ b/esp-hal/src/macros.rs
@@ -87,18 +87,6 @@ macro_rules! any_peripheral {
$vis struct $name([< $name Inner >]);
impl $crate::private::Sealed for $name {}
- impl $crate::dma::PeripheralMarker for $name {
- #[inline(always)]
- fn peripheral(&self) -> $crate::system::Peripheral {
- match &self.0 {
- $(
- $(#[cfg($variant_meta)])*
- [<$name Inner>]::$variant(inner) => inner.peripheral(),
- )*
- }
- }
- }
-
impl $crate::peripheral::Peripheral for $name {
type P = $name;
diff --git a/esp-hal/src/peripheral.rs b/esp-hal/src/peripheral.rs
index 9b3c230e3a..6883d2caec 100644
--- a/esp-hal/src/peripheral.rs
+++ b/esp-hal/src/peripheral.rs
@@ -210,10 +210,7 @@ mod peripheral_macros {
/// Creates a new `Peripherals` struct and its associated methods.
///
/// The macro has a few fields doing different things, in the form of
- /// `[first] second <= third (fourth)`.
- /// - The first field is the name of the `Peripherals` enum variant. This is
- /// optional and used to create `PeripheralMarker` implementations for
- /// DMA-eligible peripherals.
+ /// `second <= third (fourth)`.
/// - The second field is the name of the peripheral, as it appears in the
/// `Peripherals` struct.
/// - The third field is the name of the peripheral as it appears in the
@@ -226,7 +223,7 @@ mod peripheral_macros {
macro_rules! peripherals {
(
$(
- $([$enum_variant:ident])? $name:ident <= $from_pac:tt $(($($interrupt:ident),*))?
+ $name:ident <= $from_pac:tt $(($($interrupt:ident),*))?
), *$(,)?
) => {
@@ -234,7 +231,7 @@ mod peripheral_macros {
mod peripherals {
pub use super::pac::*;
$(
- $crate::create_peripheral!($([$enum_variant])? $name <= $from_pac);
+ $crate::create_peripheral!($name <= $from_pac);
)*
}
@@ -327,7 +324,7 @@ mod peripheral_macros {
#[macro_export]
/// Macro to create a peripheral structure.
macro_rules! create_peripheral {
- ($([$enum_variant:ident])? $name:ident <= virtual) => {
+ ($name:ident <= virtual) => {
#[derive(Debug)]
#[allow(non_camel_case_types)]
/// Represents a virtual peripheral with no associated hardware.
@@ -358,15 +355,6 @@ mod peripheral_macros {
}
impl $crate::private::Sealed for $name {}
-
- $(
- impl $crate::dma::PeripheralMarker for $crate::peripherals::$name {
- #[inline(always)]
- fn peripheral(&self) -> $crate::system::Peripheral {
- $crate::system::Peripheral::$enum_variant
- }
- }
- )?
};
($([$enum_variant:ident])? $name:ident <= $base:ident) => {
diff --git a/esp-hal/src/soc/esp32/peripherals.rs b/esp-hal/src/soc/esp32/peripherals.rs
index c0bd6f2732..ab9b31ce6d 100644
--- a/esp-hal/src/soc/esp32/peripherals.rs
+++ b/esp-hal/src/soc/esp32/peripherals.rs
@@ -38,8 +38,8 @@ crate::peripherals! {
HINF <= HINF,
I2C0 <= I2C0,
I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
- [I2s1] I2S1 <= I2S1 (I2S1),
+ I2S0 <= I2S0 (I2S0),
+ I2S1 <= I2S1 (I2S1),
IO_MUX <= IO_MUX,
LEDC <= LEDC,
MCPWM0 <= MCPWM0,
@@ -60,17 +60,17 @@ crate::peripherals! {
SLCHOST <= SLCHOST,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2_DMA, SPI2),
- [Spi3] SPI3 <= SPI3 (SPI3_DMA, SPI3),
+ SPI2 <= SPI2 (SPI2_DMA, SPI2),
+ SPI3 <= SPI3 (SPI3_DMA, SPI3),
SYSTEM <= DPORT,
SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
TOUCH <= virtual,
- [Twai0] TWAI0 <= TWAI0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
- [Uart2] UART2 <= UART2,
+ TWAI0 <= TWAI0,
+ UART0 <= UART0,
+ UART1 <= UART1,
+ UART2 <= UART2,
UHCI0 <= UHCI0,
UHCI1 <= UHCI1,
WIFI <= virtual,
diff --git a/esp-hal/src/soc/esp32c2/peripherals.rs b/esp-hal/src/soc/esp32c2/peripherals.rs
index 310c62416d..3cd86959d9 100644
--- a/esp-hal/src/soc/esp32c2/peripherals.rs
+++ b/esp-hal/src/soc/esp32c2/peripherals.rs
@@ -40,13 +40,13 @@ crate::peripherals! {
SHA <= SHA,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2),
+ SPI2 <= SPI2 (SPI2),
SYSTEM <= SYSTEM,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
+ UART0 <= UART0,
+ UART1 <= UART1,
WIFI <= virtual,
XTS_AES <= XTS_AES,
MEM2MEM1 <= virtual,
diff --git a/esp-hal/src/soc/esp32c3/peripherals.rs b/esp-hal/src/soc/esp32c3/peripherals.rs
index 12296386d6..dd5308df0c 100644
--- a/esp-hal/src/soc/esp32c3/peripherals.rs
+++ b/esp-hal/src/soc/esp32c3/peripherals.rs
@@ -34,7 +34,7 @@ crate::peripherals! {
GPIO_SD <= GPIO_SD,
HMAC <= HMAC,
I2C0 <= I2C0,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2S0 <= I2S0 (I2S0),
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
@@ -47,15 +47,15 @@ crate::peripherals! {
SHA <= SHA,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2),
+ SPI2 <= SPI2 (SPI2),
SYSTEM <= SYSTEM,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
- [Twai0] TWAI0 <= TWAI0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
+ TWAI0 <= TWAI0,
+ UART0 <= UART0,
+ UART1 <= UART1,
UHCI0 <= UHCI0,
UHCI1 <= UHCI1,
USB_DEVICE <= USB_DEVICE,
diff --git a/esp-hal/src/soc/esp32c6/peripherals.rs b/esp-hal/src/soc/esp32c6/peripherals.rs
index 8c5e2de92c..ef74459ed2 100644
--- a/esp-hal/src/soc/esp32c6/peripherals.rs
+++ b/esp-hal/src/soc/esp32c6/peripherals.rs
@@ -37,7 +37,7 @@ crate::peripherals! {
HP_APM <= HP_APM,
HP_SYS <= HP_SYS,
I2C0 <= I2C0,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2S0 <= I2S0 (I2S0),
IEEE802154 <= IEEE802154,
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
INTPRI <= INTPRI,
@@ -73,7 +73,7 @@ crate::peripherals! {
SOC_ETM <= SOC_ETM,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2),
+ SPI2 <= SPI2 (SPI2),
SYSTEM <= PCR,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
@@ -81,10 +81,10 @@ crate::peripherals! {
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
TRACE0 <= TRACE,
- [Twai0] TWAI0 <= TWAI0,
- [Twai1] TWAI1 <= TWAI1,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
+ TWAI0 <= TWAI0,
+ TWAI1 <= TWAI1,
+ UART0 <= UART0,
+ UART1 <= UART1,
UHCI0 <= UHCI0,
USB_DEVICE <= USB_DEVICE,
WIFI <= virtual,
diff --git a/esp-hal/src/soc/esp32h2/peripherals.rs b/esp-hal/src/soc/esp32h2/peripherals.rs
index 37eb1285f6..7fbda39c98 100644
--- a/esp-hal/src/soc/esp32h2/peripherals.rs
+++ b/esp-hal/src/soc/esp32h2/peripherals.rs
@@ -35,7 +35,7 @@ crate::peripherals! {
HP_SYS <= HP_SYS,
I2C0 <= I2C0,
I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2S0 <= I2S0 (I2S0),
IEEE802154 <= IEEE802154,
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
INTPRI <= INTPRI,
@@ -65,7 +65,7 @@ crate::peripherals! {
SOC_ETM <= SOC_ETM,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2),
+ SPI2 <= SPI2 (SPI2),
SYSTEM <= PCR,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
@@ -73,9 +73,9 @@ crate::peripherals! {
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
TRACE0 <= TRACE,
- [Twai0] TWAI0 <= TWAI0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
+ TWAI0 <= TWAI0,
+ UART0 <= UART0,
+ UART1 <= UART1,
UHCI0 <= UHCI0,
USB_DEVICE <= USB_DEVICE,
MEM2MEM1 <= virtual,
diff --git a/esp-hal/src/soc/esp32s2/peripherals.rs b/esp-hal/src/soc/esp32s2/peripherals.rs
index d6bfb5b831..c96d1c7b17 100644
--- a/esp-hal/src/soc/esp32s2/peripherals.rs
+++ b/esp-hal/src/soc/esp32s2/peripherals.rs
@@ -35,7 +35,7 @@ crate::peripherals! {
HMAC <= HMAC,
I2C0 <= I2C0,
I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2S0 <= I2S0 (I2S0),
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
@@ -52,17 +52,17 @@ crate::peripherals! {
SHA <= SHA,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2_DMA, SPI2),
- [Spi3] SPI3 <= SPI3 (SPI3_DMA, SPI3),
+ SPI2 <= SPI2 (SPI2_DMA, SPI2),
+ SPI3 <= SPI3 (SPI3_DMA, SPI3),
SYSCON <= SYSCON,
SYSTEM <= SYSTEM,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
- [Twai0] TWAI0 <= TWAI0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
+ TWAI0 <= TWAI0,
+ UART0 <= UART0,
+ UART1 <= UART1,
UHCI0 <= UHCI0,
ULP_RISCV_CORE <= virtual,
USB0 <= USB0,
diff --git a/esp-hal/src/soc/esp32s3/peripherals.rs b/esp-hal/src/soc/esp32s3/peripherals.rs
index 30159a6536..9e0592abf5 100644
--- a/esp-hal/src/soc/esp32s3/peripherals.rs
+++ b/esp-hal/src/soc/esp32s3/peripherals.rs
@@ -36,12 +36,12 @@ crate::peripherals! {
HMAC <= HMAC,
I2C0 <= I2C0,
I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
- [I2s1] I2S1 <= I2S1 (I2S1),
+ I2S0 <= I2S0 (I2S0),
+ I2S1 <= I2S1 (I2S1),
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
INTERRUPT_CORE1 <= INTERRUPT_CORE1,
IO_MUX <= IO_MUX,
- [LcdCam] LCD_CAM <= LCD_CAM,
+ LCD_CAM <= LCD_CAM,
LEDC <= LEDC,
LPWR <= RTC_CNTL,
PCNT <= PCNT,
@@ -59,17 +59,17 @@ crate::peripherals! {
SHA <= SHA,
SPI0 <= SPI0,
SPI1 <= SPI1,
- [Spi2] SPI2 <= SPI2 (SPI2),
- [Spi3] SPI3 <= SPI3 (SPI3),
+ SPI2 <= SPI2 (SPI2),
+ SPI3 <= SPI3 (SPI3),
SYSTEM <= SYSTEM,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
TIMG0 <= TIMG0,
TIMG1 <= TIMG1,
- [Twai0] TWAI0 <= TWAI0,
- [Uart0] UART0 <= UART0,
- [Uart1] UART1 <= UART1,
- [Uart2] UART2 <= UART2,
+ TWAI0 <= TWAI0,
+ UART0 <= UART0,
+ UART1 <= UART1,
+ UART2 <= UART2,
UHCI0 <= UHCI0,
UHCI1 <= UHCI1,
ULP_RISCV_CORE <= virtual,
diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs
index 6720f6d908..1609c7c290 100644
--- a/esp-hal/src/spi/master.rs
+++ b/esp-hal/src/spi/master.rs
@@ -80,16 +80,7 @@ use procmacros::ram;
use super::{DmaError, Error, SpiBitOrder, SpiDataMode, SpiMode};
use crate::{
clock::Clocks,
- dma::{
- Channel,
- DmaChannelConvert,
- DmaEligible,
- DmaRxBuffer,
- DmaTxBuffer,
- PeripheralMarker,
- Rx,
- Tx,
- },
+ dma::{Channel, DmaChannelConvert, DmaEligible, DmaRxBuffer, DmaTxBuffer, Rx, Tx},
gpio::{interconnect::PeripheralOutput, InputSignal, NoPin, OutputSignal},
interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef},
@@ -589,8 +580,8 @@ where
_mode: PhantomData,
};
- PeripheralClockControl::enable(this.spi.peripheral());
- PeripheralClockControl::reset(this.spi.peripheral());
+ PeripheralClockControl::enable(this.driver().peripheral);
+ PeripheralClockControl::reset(this.driver().peripheral);
this.driver().init();
unwrap!(this.apply_config(&config)); // FIXME: update based on the resolution of https://github.com/esp-rs/esp-hal/issues/2416
@@ -2154,9 +2145,7 @@ mod ehal1 {
}
/// SPI peripheral instance.
-pub trait Instance:
- private::Sealed + PeripheralMarker + Into + DmaEligible + 'static
-{
+pub trait Instance: private::Sealed + Into + DmaEligible + 'static {
/// Returns the peripheral data describing this SPI instance.
fn info(&self) -> &'static Info;
}
@@ -2172,6 +2161,9 @@ pub struct Info {
/// Use [Self::register_block] to access the register block.
pub register_block: *const RegisterBlock,
+ /// The system peripheral marker.
+ pub peripheral: crate::system::Peripheral,
+
/// Interrupt for this SPI instance.
pub interrupt: crate::peripherals::Interrupt,
@@ -3005,6 +2997,7 @@ macro_rules! spi_instance {
fn info(&self) -> &'static Info {
static INFO: Info = Info {
register_block: crate::peripherals::[]::PTR,
+ peripheral: crate::system::Peripheral::[],
interrupt: crate::peripherals::Interrupt::[],
sclk: OutputSignal::$sclk,
mosi: OutputSignal::$mosi,
diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs
index 3921532456..0ffad8f7c9 100644
--- a/esp-hal/src/spi/slave.rs
+++ b/esp-hal/src/spi/slave.rs
@@ -75,7 +75,7 @@ use core::marker::PhantomData;
use super::{Error, SpiMode};
use crate::{
- dma::{DmaChannelConvert, DmaEligible, PeripheralMarker},
+ dma::{DmaChannelConvert, DmaEligible},
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
@@ -167,8 +167,8 @@ where
_mode: PhantomData,
};
- PeripheralClockControl::reset(spi.spi.peripheral());
- PeripheralClockControl::enable(spi.spi.peripheral());
+ PeripheralClockControl::reset(spi.spi.info().peripheral);
+ PeripheralClockControl::enable(spi.spi.info().peripheral);
spi.spi.info().init();
spi.spi.info().set_data_mode(mode, false);
@@ -572,7 +572,7 @@ pub mod dma {
}
/// SPI peripheral instance.
-pub trait Instance: Peripheral + Into + PeripheralMarker + 'static {
+pub trait Instance: Peripheral + Into + 'static {
/// Returns the peripheral data describing this SPI instance.
fn info(&self) -> &'static Info;
}
@@ -592,6 +592,9 @@ pub struct Info {
/// Use [Self::register_block] to access the register block.
pub register_block: *const RegisterBlock,
+ /// System peripheral marker.
+ pub peripheral: crate::system::Peripheral,
+
/// SCLK signal.
pub sclk: InputSignal,
@@ -794,6 +797,7 @@ macro_rules! spi_instance {
fn info(&self) -> &'static Info {
static INFO: Info = Info {
register_block: crate::peripherals::[]::PTR,
+ peripheral: crate::system::Peripheral::[],
sclk: InputSignal::$sclk,
mosi: InputSignal::$mosi,
miso: OutputSignal::$miso,
diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs
index 7d6b25c21b..a89d5cfda3 100644
--- a/esp-hal/src/twai/mod.rs
+++ b/esp-hal/src/twai/mod.rs
@@ -129,7 +129,6 @@ use core::marker::PhantomData;
use self::filter::{Filter, FilterType};
use crate::{
- dma::PeripheralMarker,
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
@@ -1472,10 +1471,13 @@ where
}
/// TWAI peripheral instance.
-pub trait Instance: Peripheral + PeripheralMarker + Into + 'static {
+pub trait Instance: Peripheral + Into + 'static {
/// The identifier number for this TWAI instance.
fn number(&self) -> usize;
+ /// Returns the system peripheral marker for this instance.
+ fn peripheral(&self) -> crate::system::Peripheral;
+
/// Input signal.
fn input_signal(&self) -> InputSignal;
/// Output signal.
@@ -1660,6 +1662,10 @@ impl Instance for crate::peripherals::TWAI0 {
0
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::Twai0
+ }
+
fn input_signal(&self) -> InputSignal {
cfg_if::cfg_if! {
if #[cfg(any(esp32, esp32c3, esp32s2, esp32s3))] {
@@ -1705,6 +1711,10 @@ impl Instance for crate::peripherals::TWAI1 {
1
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::Twai1
+ }
+
fn input_signal(&self) -> InputSignal {
InputSignal::TWAI1_RX
}
@@ -1751,6 +1761,7 @@ impl Instance for AnyTwai {
AnyTwaiInner::Twai1(twai) => twai,
} {
fn number(&self) -> usize;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn input_signal(&self) -> InputSignal;
fn output_signal(&self) -> OutputSignal;
fn interrupt(&self) -> crate::peripherals::Interrupt;
diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs
index 142c2f8c9b..ef1ccb9e3b 100644
--- a/esp-hal/src/uart.rs
+++ b/esp-hal/src/uart.rs
@@ -135,7 +135,6 @@ use portable_atomic::AtomicBool;
use crate::{
clock::Clocks,
- dma::PeripheralMarker,
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
@@ -1211,7 +1210,7 @@ where
}
};
- PeripheralClockControl::enable(self.tx.uart.peripheral());
+ PeripheralClockControl::enable(self.tx.uart.info().peripheral);
self.uart_peripheral_reset();
self.rx.disable_rx_interrupts();
self.tx.disable_tx_interrupts();
@@ -1263,7 +1262,7 @@ where
}
rst_core(self.register_block(), true);
- PeripheralClockControl::reset(self.tx.uart.peripheral());
+ PeripheralClockControl::reset(self.tx.uart.info().peripheral);
rst_core(self.register_block(), false);
}
}
@@ -2156,7 +2155,7 @@ pub mod lp_uart {
}
/// UART Peripheral Instance
-pub trait Instance: Peripheral + PeripheralMarker + Into + 'static {
+pub trait Instance: Peripheral + Into + 'static {
/// Returns the peripheral data and state describing this UART instance.
fn parts(&self) -> (&'static Info, &'static State);
@@ -2181,6 +2180,9 @@ pub struct Info {
/// Use [Self::register_block] to access the register block.
pub register_block: *const RegisterBlock,
+ /// The system peripheral marker.
+ pub peripheral: crate::system::Peripheral,
+
/// Interrupt handler for the asynchronous operations of this UART instance.
pub async_handler: InterruptHandler,
@@ -2586,7 +2588,7 @@ impl PartialEq for Info {
unsafe impl Sync for Info {}
macro_rules! impl_instance {
- ($inst:ident, $txd:ident, $rxd:ident, $cts:ident, $rts:ident) => {
+ ($inst:ident, $peri:ident, $txd:ident, $rxd:ident, $cts:ident, $rts:ident) => {
impl Instance for crate::peripherals::$inst {
fn parts(&self) -> (&'static Info, &'static State) {
#[crate::macros::handler]
@@ -2603,6 +2605,7 @@ macro_rules! impl_instance {
static PERIPHERAL: Info = Info {
register_block: crate::peripherals::$inst::ptr(),
+ peripheral: crate::system::Peripheral::$peri,
async_handler: irq_handler,
interrupt: Interrupt::$inst,
tx_signal: OutputSignal::$txd,
@@ -2616,10 +2619,10 @@ macro_rules! impl_instance {
};
}
-impl_instance!(UART0, U0TXD, U0RXD, U0CTS, U0RTS);
-impl_instance!(UART1, U1TXD, U1RXD, U1CTS, U1RTS);
+impl_instance!(UART0, Uart0, U0TXD, U0RXD, U0CTS, U0RTS);
+impl_instance!(UART1, Uart1, U1TXD, U1RXD, U1CTS, U1RTS);
#[cfg(uart2)]
-impl_instance!(UART2, U2TXD, U2RXD, U2CTS, U2RTS);
+impl_instance!(UART2, Uart2, U2TXD, U2RXD, U2CTS, U2RTS);
crate::any_peripheral! {
/// Any UART peripheral.