Skip to content

Commit

Permalink
Remove PeripheralMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 6, 2024
1 parent 34a2b19 commit 41c0436
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 138 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
21 changes: 12 additions & 9 deletions esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -1305,7 +1307,7 @@ pub struct State {

/// I2C Peripheral Instance
#[doc(hidden)]
pub trait Instance: Peripheral<P = Self> + PeripheralMarker + Into<AnyI2c> + 'static {
pub trait Instance: Peripheral<P = Self> + Into<AnyI2c> + 'static {
/// Returns the peripheral data and state describing this instance.
fn parts(&self) -> (&Info, &State);

Expand All @@ -1323,7 +1325,7 @@ pub trait Instance: Peripheral<P = Self> + PeripheralMarker + Into<AnyI2c> + '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]
Expand All @@ -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,
Expand All @@ -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.
Expand Down
23 changes: 12 additions & 11 deletions esp-hal/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -913,10 +906,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 @@ -1611,6 +1603,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 @@ -1715,6 +1711,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 @@ -1788,6 +1788,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
20 changes: 10 additions & 10 deletions esp-hal/src/soc/esp32/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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
8 changes: 4 additions & 4 deletions esp-hal/src/soc/esp32c2/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
12 changes: 6 additions & 6 deletions esp-hal/src/soc/esp32c3/peripherals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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
Loading

0 comments on commit 41c0436

Please sign in to comment.