Skip to content

Commit

Permalink
Remove PeripheralMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 7, 2024
1 parent 7222a66 commit 4fd2f1b
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 129 deletions.
6 changes: 0 additions & 6 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 6 additions & 9 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ use procmacros::handler;

use crate::{
clock::Clocks,
dma::PeripheralMarker,
gpio::{interconnect::PeripheralOutput, InputSignal, OutputSignal, Pull},
interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef},
Expand Down Expand Up @@ -1176,7 +1175,9 @@ pub(super) fn i2c1_handler() {

/// I2C Peripheral Instance
#[doc(hidden)]
pub trait Instance: Peripheral<P = Self> + PeripheralMarker + Into<AnyI2c> + 'static {
pub trait Instance: Peripheral<P = Self> + Into<AnyI2c> + 'static {
fn peripheral(&self) -> crate::system::Peripheral;

/// Returns the interrupt associated with this I2C peripheral.
fn interrupt(&self) -> crate::peripherals::Interrupt;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions esp-hal/src/i2s/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -911,10 +904,9 @@ mod private {
}
}

pub trait RegBlock:
Peripheral<P = Self> + PeripheralMarker + DmaEligible + Into<super::AnyI2s> + 'static
{
pub trait RegBlock: Peripheral<P = Self> + DmaEligible + Into<super::AnyI2s> + 'static {
fn register_block(&self) -> &RegisterBlock;
fn peripheral(&self) -> crate::system::Peripheral;
}

pub trait Signals: RegBlock {
Expand Down Expand Up @@ -1609,6 +1601,10 @@ mod private {
fn register_block(&self) -> &RegisterBlock {
unsafe { &*I2S0::PTR.cast::<RegisterBlock>() }
}

fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2s0
}
}

impl RegisterAccessPrivate for I2S0 {
Expand Down Expand Up @@ -1713,6 +1709,10 @@ mod private {
fn register_block(&self) -> &RegisterBlock {
unsafe { &*I2S1::PTR.cast::<RegisterBlock>() }
}

fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2s1
}
}

#[cfg(i2s1)]
Expand Down Expand Up @@ -1786,6 +1786,7 @@ mod private {
super::AnyI2sInner::I2s1(i2s) => i2s,
} {
fn register_block(&self) -> &RegisterBlock;
fn peripheral(&self) -> crate::system::Peripheral;
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions esp-hal/src/i2s/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ use crate::{
DmaError,
DmaPeripheral,
DmaTxBuffer,
PeripheralMarker,
Tx,
},
gpio::{
Expand Down Expand Up @@ -424,10 +423,9 @@ fn calculate_clock(sample_rate: impl Into<fugit::HertzU32>, data_bits: u8) -> I2
}

#[doc(hidden)]
pub trait Instance:
Peripheral<P = Self> + PeripheralMarker + DmaEligible + Into<AnyI2s> + 'static
{
pub trait Instance: Peripheral<P = Self> + DmaEligible + Into<AnyI2s> + '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;

Expand Down Expand Up @@ -614,6 +612,10 @@ impl Instance for I2S0 {
unsafe { &*I2S0::PTR.cast::<RegisterBlock>() }
}

fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2s0
}

fn ws_signal(&self) -> OutputSignal {
OutputSignal::I2S0O_WS
}
Expand Down Expand Up @@ -661,6 +663,10 @@ impl Instance for I2S1 {
unsafe { &*I2S1::PTR.cast::<RegisterBlock>() }
}

fn peripheral(&self) -> crate::system::Peripheral {
crate::system::Peripheral::I2s1
}

fn ws_signal(&self) -> OutputSignal {
OutputSignal::I2S1O_WS
}
Expand Down Expand Up @@ -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 ;
}
Expand Down
12 changes: 0 additions & 12 deletions esp-hal/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 4 additions & 16 deletions esp-hal/src/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -226,15 +223,15 @@ mod peripheral_macros {
macro_rules! peripherals {
(
$(
$([$enum_variant:ident])? $name:ident <= $from_pac:tt $(($($interrupt:ident),*))?
$name:ident <= $from_pac:tt $(($($interrupt:ident),*))?
), *$(,)?
) => {

/// Contains the generated peripherals which implement [`Peripheral`]
mod peripherals {
pub use super::pac::*;
$(
$crate::create_peripheral!($([$enum_variant])? $name <= $from_pac);
$crate::create_peripheral!($name <= $from_pac);
)*
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) => {
Expand Down
16 changes: 8 additions & 8 deletions esp-hal/src/soc/esp32/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/soc/esp32c2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/soc/esp32c3/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/soc/esp32c6/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -73,18 +73,18 @@ crate::peripherals! {
SOC_ETM <= SOC_ETM,
SPI0 <= SPI0,
SPI1 <= SPI1,
[Spi2] SPI2 <= SPI2 (SPI2),
SPI2 <= SPI2 (SPI2),
SYSTEM <= PCR,
SYSTIMER <= SYSTIMER,
SW_INTERRUPT <= virtual,
TEE <= TEE,
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,
Expand Down
Loading

0 comments on commit 4fd2f1b

Please sign in to comment.