diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs
index f512ad05a24..0cfbb2e5269 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/master/mod.rs b/esp-hal/src/i2c/master/mod.rs
index 440851e5d31..314fd597659 100644
--- a/esp-hal/src/i2c/master/mod.rs
+++ b/esp-hal/src/i2c/master/mod.rs
@@ -64,7 +64,6 @@ use version::{I2C_CHUNK_SIZE, I2C_LL_INTR_MASK};
use crate::{
clock::Clocks,
- dma::PeripheralMarker,
gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull},
interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef},
@@ -269,8 +268,8 @@ where
}
fn internal_recover(&self) {
- PeripheralClockControl::reset(self.i2c.peripheral());
- PeripheralClockControl::enable(self.i2c.peripheral());
+ PeripheralClockControl::reset(self.i2c.info().peripheral);
+ PeripheralClockControl::enable(self.i2c.info().peripheral);
self.driver().setup(&self.config);
}
@@ -421,8 +420,8 @@ where
config,
};
- PeripheralClockControl::reset(i2c.i2c.peripheral());
- PeripheralClockControl::enable(i2c.i2c.peripheral());
+ PeripheralClockControl::reset(i2c.driver().info.peripheral);
+ PeripheralClockControl::enable(i2c.driver().info.peripheral);
i2c.driver().setup(&i2c.config);
i2c
@@ -831,6 +830,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 I2C instance.
pub async_handler: InterruptHandler,
@@ -1305,7 +1307,7 @@ pub struct State {
/// I2C Peripheral Instance
#[doc(hidden)]
-pub trait Instance: Peripheral
+ PeripheralMarker + Into + 'static {
+pub trait Instance: Peripheral + Into + 'static {
/// Returns the peripheral data and state describing this instance.
fn parts(&self) -> (&Info, &State);
@@ -1323,7 +1325,7 @@ pub trait Instance: Peripheral + PeripheralMarker + Into + 'st
}
macro_rules! instance {
- ($inst:ident, $scl:ident, $sda:ident, $interrupt:ident) => {
+ ($inst:ident, $peri:ident, $scl:ident, $sda:ident, $interrupt:ident) => {
impl Instance for crate::peripherals::$inst {
fn parts(&self) -> (&Info, &State) {
#[crate::macros::handler]
@@ -1337,6 +1339,7 @@ macro_rules! instance {
static PERIPHERAL: Info = Info {
register_block: crate::peripherals::$inst::ptr(),
+ peripheral: crate::system::Peripheral::$peri,
async_handler: irq_handler,
interrupt: Interrupt::$interrupt,
scl_output: OutputSignal::$scl,
@@ -1351,9 +1354,9 @@ macro_rules! instance {
}
#[cfg(i2c0)]
-instance!(I2C0, I2CEXT0_SCL, I2CEXT0_SDA, I2C_EXT0);
+instance!(I2C0, I2cExt0, I2CEXT0_SCL, I2CEXT0_SDA, I2C_EXT0);
#[cfg(i2c1)]
-instance!(I2C1, I2CEXT1_SCL, I2CEXT1_SDA, I2C_EXT1);
+instance!(I2C1, I2cExt1, I2CEXT1_SCL, I2CEXT1_SDA, I2C_EXT1);
crate::any_peripheral! {
/// Represents any I2C peripheral.
diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs
index 0a44a75fa6d..6f5f195de61 100644
--- a/esp-hal/src/i2s.rs
+++ b/esp-hal/src/i2s.rs
@@ -775,14 +775,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,
@@ -913,10 +906,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 {
@@ -1611,6 +1603,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 {
@@ -1715,6 +1711,10 @@ mod private {
fn register_block(&self) -> &RegisterBlock {
unsafe { &*I2S1::PTR.cast::() }
}
+
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::I2s1
+ }
}
#[cfg(i2s1)]
@@ -1788,6 +1788,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 37fd6585d43..d4f0a47fe6f 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 c22b5a44a6b..f4274d8033d 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 9b3c230e3a9..6883d2caecc 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 3d1fbadfd78..ab9b31ce6d1 100644
--- a/esp-hal/src/soc/esp32/peripherals.rs
+++ b/esp-hal/src/soc/esp32/peripherals.rs
@@ -36,10 +36,10 @@ crate::peripherals! {
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HINF <= HINF,
- [I2cExt0] I2C0 <= I2C0,
- [I2cExt1] I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
- [I2s1] I2S1 <= I2S1 (I2S1),
+ I2C0 <= I2C0,
+ I2C1 <= I2C1,
+ 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 68c00598bb9..3cd86959d96 100644
--- a/esp-hal/src/soc/esp32c2/peripherals.rs
+++ b/esp-hal/src/soc/esp32c2/peripherals.rs
@@ -29,7 +29,7 @@ crate::peripherals! {
EFUSE <= EFUSE,
EXTMEM <= EXTMEM,
GPIO <= GPIO (GPIO,GPIO_NMI),
- [I2cExt0] I2C0 <= I2C0,
+ I2C0 <= I2C0,
INTERRUPT_CORE0 <= INTERRUPT_CORE0,
IO_MUX <= IO_MUX,
LEDC <= LEDC,
@@ -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 5b762d4a2d5..dd5308df0c2 100644
--- a/esp-hal/src/soc/esp32c3/peripherals.rs
+++ b/esp-hal/src/soc/esp32c3/peripherals.rs
@@ -33,8 +33,8 @@ crate::peripherals! {
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HMAC <= HMAC,
- [I2cExt0] I2C0 <= I2C0,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2C0 <= I2C0,
+ 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 784f957e796..ef74459ed22 100644
--- a/esp-hal/src/soc/esp32c6/peripherals.rs
+++ b/esp-hal/src/soc/esp32c6/peripherals.rs
@@ -36,8 +36,8 @@ crate::peripherals! {
HMAC <= HMAC,
HP_APM <= HP_APM,
HP_SYS <= HP_SYS,
- [I2cExt0] I2C0 <= I2C0,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2C0 <= I2C0,
+ 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 ccc359decbf..7fbda39c981 100644
--- a/esp-hal/src/soc/esp32h2/peripherals.rs
+++ b/esp-hal/src/soc/esp32h2/peripherals.rs
@@ -33,9 +33,9 @@ crate::peripherals! {
HMAC <= HMAC,
HP_APM <= HP_APM,
HP_SYS <= HP_SYS,
- [I2cExt0] I2C0 <= I2C0,
- [I2cExt1] I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2C0 <= I2C0,
+ I2C1 <= I2C1,
+ 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 28e776daa62..c96d1c7b171 100644
--- a/esp-hal/src/soc/esp32s2/peripherals.rs
+++ b/esp-hal/src/soc/esp32s2/peripherals.rs
@@ -33,9 +33,9 @@ crate::peripherals! {
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HMAC <= HMAC,
- [I2cExt0] I2C0 <= I2C0,
- [I2cExt1] I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
+ I2C0 <= I2C0,
+ I2C1 <= I2C1,
+ 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 dc8bfe2b48d..9e0592abf52 100644
--- a/esp-hal/src/soc/esp32s3/peripherals.rs
+++ b/esp-hal/src/soc/esp32s3/peripherals.rs
@@ -34,14 +34,14 @@ crate::peripherals! {
GPIO <= GPIO (GPIO,GPIO_NMI),
GPIO_SD <= GPIO_SD,
HMAC <= HMAC,
- [I2cExt0] I2C0 <= I2C0,
- [I2cExt1] I2C1 <= I2C1,
- [I2s0] I2S0 <= I2S0 (I2S0),
- [I2s1] I2S1 <= I2S1 (I2S1),
+ I2C0 <= I2C0,
+ I2C1 <= I2C1,
+ 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 141a348a836..33dca46978a 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;
}
@@ -2171,6 +2160,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,
@@ -3004,6 +2996,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 675d66b2d36..90e94ac7dec 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::{DescriptorChain, DmaChannelConvert, DmaEligible, PeripheralMarker, Rx, Tx},
+ dma::{DescriptorChain, DmaChannelConvert, DmaEligible, Rx, Tx},
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
@@ -577,9 +577,10 @@ impl InstanceDma for crate::peripherals::SPI2 {}
impl InstanceDma for crate::peripherals::SPI3 {}
#[doc(hidden)]
-pub trait Instance: Peripheral + Into + PeripheralMarker + 'static {
+pub trait Instance: Peripheral + Into + 'static {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn sclk_signal(&self) -> InputSignal;
fn mosi_signal(&self) -> InputSignal;
fn miso_signal(&self) -> OutputSignal;
@@ -745,6 +746,10 @@ impl Instance for crate::peripherals::SPI2 {
self
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::Spi2
+ }
+
#[inline(always)]
fn sclk_signal(&self) -> InputSignal {
cfg_if::cfg_if! {
@@ -797,6 +802,10 @@ impl Instance for crate::peripherals::SPI3 {
self
}
+ fn peripheral(&self) -> crate::system::Peripheral {
+ crate::system::Peripheral::Spi3
+ }
+
#[inline(always)]
fn sclk_signal(&self) -> InputSignal {
cfg_if::cfg_if! {
@@ -850,6 +859,7 @@ impl Instance for super::AnySpi {
super::AnySpiInner::Spi3(spi) => spi,
} {
fn register_block(&self) -> &RegisterBlock;
+ fn peripheral(&self) -> crate::system::Peripheral;
fn sclk_signal(&self) -> InputSignal;
fn mosi_signal(&self) -> InputSignal;
fn miso_signal(&self) -> OutputSignal;
diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs
index 5739ffd6d85..946766e031c 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,
@@ -1452,10 +1451,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;
+ #[doc(hidden)]
+ fn peripheral(&self) -> crate::system::Peripheral;
+
/// Input signal.
fn input_signal(&self) -> InputSignal;
/// Output signal.
@@ -1640,6 +1642,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))] {
@@ -1685,6 +1691,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
}
@@ -1731,6 +1741,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 812b4abd134..dd36320393e 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);
@@ -2180,6 +2179,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,
@@ -2584,7 +2586,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]
@@ -2601,6 +2603,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,
@@ -2614,10 +2617,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.