Skip to content

Commit

Permalink
PeripheralRef: I2S
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajSadel committed Dec 14, 2022
1 parent 220f812 commit 9c918b5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
37 changes: 20 additions & 17 deletions esp-hal-common/src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
DmaError,
DmaTransfer,
},
peripheral::{Peripheral, PeripheralRef},
system::PeripheralClockControl,
InputPin,
OutputPin,
Expand Down Expand Up @@ -440,22 +441,22 @@ where
}

/// Instance of the I2S peripheral driver
pub struct I2s<I, T, P, TX, RX>
pub struct I2s<'d, I, T, P, TX, RX>
where
I: Instance<T>,
T: RegisterAccess + Clone,
P: I2sMclkPin,
TX: Tx,
RX: Rx,
{
_peripheral: I,
_peripheral: PeripheralRef<'d, I>,
_register_access: T,
_pins: P,
pub i2s_tx: TxCreator<T, TX>,
pub i2s_rx: RxCreator<T, RX>,
}

impl<I, T, P, TX, RX> I2s<I, T, P, TX, RX>
impl<'d, I, T, P, TX, RX> I2s<'d, I, T, P, TX, RX>
where
I: Instance<T>,
T: RegisterAccess + Clone,
Expand All @@ -464,7 +465,7 @@ where
RX: Rx,
{
fn new_internal<IP>(
i2s: I,
i2s: impl Peripheral<P = I> + 'd,
mut pins: P,
standard: Standard,
data_format: DataFormat,
Expand All @@ -475,11 +476,13 @@ where
) -> Self
where
IP: I2sPeripheral,
I: Instance<T>,
{
// on ESP32-C3 / ESP32-S3 and later RX and TX are independent and
// could be configured totally independently but for now handle all
// the targets the same and force same configuration for both, TX and RX

crate::into_ref!(i2s);
let mut register_access = i2s.register_access();

channel.tx.init_channel();
Expand Down Expand Up @@ -512,7 +515,7 @@ where
}

/// Construct a new I2S peripheral driver instance for the first I2S peripheral
pub trait I2s0New<I, T, P, TX, RX, IP>
pub trait I2s0New<'d, I, T, P, TX, RX, IP>
where
I: Instance<T>,
T: RegisterAccess + Clone,
Expand All @@ -523,7 +526,7 @@ where
RX: Rx,
{
fn new(
i2s: I,
i2s: impl Peripheral<P = I> + 'd,
pins: P,
standard: Standard,
data_format: DataFormat,
Expand All @@ -534,7 +537,7 @@ where
) -> Self;
}

impl<I, T, P, TX, RX, IP> I2s0New<I, T, P, TX, RX, IP> for I2s<I, T, P, TX, RX>
impl<'d, I, T, P, TX, RX, IP> I2s0New<'d, I, T, P, TX, RX, IP> for I2s<'d, I, T, P, TX, RX>
where
I: Instance<T> + I2s0Instance,
T: RegisterAccess + Clone,
Expand All @@ -544,7 +547,7 @@ where
IP: I2sPeripheral + I2s0Peripheral,
{
fn new(
i2s: I,
i2s: impl Peripheral<P = I> + 'd,
pins: P,
standard: Standard,
data_format: DataFormat,
Expand All @@ -568,7 +571,7 @@ where

/// Construct a new I2S peripheral driver instance for the second I2S peripheral
#[cfg(any(esp32s3))]
pub trait I2s1New<I, T, P, TX, RX, IP>
pub trait I2s1New<'d, I, T, P, TX, RX, IP>
where
I: Instance<T>,
T: RegisterAccess + Clone,
Expand All @@ -579,7 +582,7 @@ where
RX: Rx,
{
fn new(
i2s: I,
i2s: impl Peripheral<P = I> + 'd,
pins: P,
standard: Standard,
data_format: DataFormat,
Expand All @@ -591,7 +594,7 @@ where
}

#[cfg(any(esp32s3))]
impl<I, T, P, TX, RX, IP> I2s1New<I, T, P, TX, RX, IP> for I2s<I, T, P, TX, RX>
impl<'d, I, T, P, TX, RX, IP> I2s1New<'d, I, T, P, TX, RX, IP> for I2s<'d, I, T, P, TX, RX>
where
I: Instance<T> + I2s1Instance,
T: RegisterAccess + Clone,
Expand All @@ -601,7 +604,7 @@ where
IP: I2sPeripheral + I2s1Peripheral,
{
fn new(
i2s: I,
i2s: impl Peripheral<P = I> + 'd,
pins: P,
standard: Standard,
data_format: DataFormat,
Expand Down Expand Up @@ -915,9 +918,9 @@ mod private {
#[cfg(any(esp32s3, esp32))]
use crate::pac::i2s1::RegisterBlock;
#[cfg(any(esp32c3, esp32s2))]
use crate::pac::I2S;
use crate::peripherals::I2S;
#[cfg(any(esp32s3, esp32))]
use crate::pac::I2S0 as I2S;
use crate::peripherals::I2S0 as I2S;
use crate::{
clock::Clocks,
dma::{
Expand Down Expand Up @@ -1016,14 +1019,14 @@ mod private {
impl I2s0Instance for I2S {}

#[cfg(esp32s3)]
impl Instance<I2sPeripheral1> for crate::pac::I2S1 {
impl Instance<I2sPeripheral1> for crate::peripherals::I2S1 {
fn register_access(&self) -> I2sPeripheral1 {
I2sPeripheral1 {}
}
}

#[cfg(esp32s3)]
impl I2s1Instance for crate::pac::I2S1 {}
impl I2s1Instance for crate::peripherals::I2S1 {}

pub trait Signals {
fn get_peripheral(&self) -> Peripheral;
Expand Down Expand Up @@ -1797,7 +1800,7 @@ mod private {
#[cfg(any(esp32s3, esp32))]
impl RegBlock for I2sPeripheral1 {
fn register_block(&self) -> &'static RegisterBlock {
unsafe { core::mem::transmute(crate::pac::I2S1::PTR) }
unsafe { core::mem::transmute(crate::peripherals::I2S1::PTR) }
}
}

Expand Down
2 changes: 2 additions & 0 deletions esp-hal-common/src/peripherals/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ mod peripherals {
DPORT,
LEDC,
RMT,
I2S0,
I2S1,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ mod peripherals {
SYSTEM,
LEDC,
RMT,
I2S,
}
}
1 change: 1 addition & 0 deletions esp-hal-common/src/peripherals/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ mod peripherals {
SYSTEM,
LEDC,
RMT,
I2S,
}
}
2 changes: 2 additions & 0 deletions esp-hal-common/src/peripherals/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ mod peripherals {
SYSTEM,
LEDC,
RMT,
I2S0,
I2S1,
}
}

0 comments on commit 9c918b5

Please sign in to comment.