From ca4c57366009558b06f1064a5e2636581e1bbe29 Mon Sep 17 00:00:00 2001 From: Juraj Sadel Date: Wed, 14 Dec 2022 13:55:48 +0100 Subject: [PATCH] PeripheralRef: I2S --- esp-hal-common/src/i2s.rs | 26 ++++++++++++----------- esp-hal-common/src/peripherals/esp32.rs | 2 ++ esp-hal-common/src/peripherals/esp32c3.rs | 1 + esp-hal-common/src/peripherals/esp32s2.rs | 1 + esp-hal-common/src/peripherals/esp32s3.rs | 2 ++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/esp-hal-common/src/i2s.rs b/esp-hal-common/src/i2s.rs index 29ac9a7a415..999931ed42d 100644 --- a/esp-hal-common/src/i2s.rs +++ b/esp-hal-common/src/i2s.rs @@ -13,6 +13,7 @@ use crate::{ DmaError, DmaTransfer, }, + peripheral::{Peripheral, PeripheralRef}, system::PeripheralClockControl, InputPin, OutputPin, @@ -440,7 +441,7 @@ where } /// Instance of the I2S peripheral driver -pub struct I2s +pub struct I2s<'d, I, T, P, TX, RX> where I: Instance, T: RegisterAccess + Clone, @@ -448,14 +449,14 @@ where TX: Tx, RX: Rx, { - _peripheral: I, + _peripheral: PeripheralRef<'d, I>, _register_access: T, _pins: P, pub i2s_tx: TxCreator, pub i2s_rx: RxCreator, } -impl I2s +impl<'d, I, T, P, TX, RX> I2s<'d, I, T, P, TX, RX> where I: Instance, T: RegisterAccess + Clone, @@ -464,7 +465,7 @@ where RX: Rx, { fn new_internal( - i2s: I, + i2s: impl Peripheral

+ 'd, mut pins: P, standard: Standard, data_format: DataFormat, @@ -480,6 +481,7 @@ where // 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(); @@ -512,7 +514,7 @@ where } /// Construct a new I2S peripheral driver instance for the first I2S peripheral -pub trait I2s0New +pub trait I2s0New<'d, I, T, P, TX, RX, IP> where I: Instance, T: RegisterAccess + Clone, @@ -523,7 +525,7 @@ where RX: Rx, { fn new( - i2s: I, + i2s: impl Peripheral

+ 'd, pins: P, standard: Standard, data_format: DataFormat, @@ -534,7 +536,7 @@ where ) -> Self; } -impl I2s0New for I2s +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 + I2s0Instance, T: RegisterAccess + Clone, @@ -544,7 +546,7 @@ where IP: I2sPeripheral + I2s0Peripheral, { fn new( - i2s: I, + i2s: impl Peripheral

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

+ 'd, pins: P, standard: Standard, data_format: DataFormat, @@ -591,7 +593,7 @@ where } #[cfg(any(esp32s3))] -impl I2s1New for I2s +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 + I2s1Instance, T: RegisterAccess + Clone, @@ -601,7 +603,7 @@ where IP: I2sPeripheral + I2s1Peripheral, { fn new( - i2s: I, + i2s: impl Peripheral

+ 'd, pins: P, standard: Standard, data_format: DataFormat, diff --git a/esp-hal-common/src/peripherals/esp32.rs b/esp-hal-common/src/peripherals/esp32.rs index 5bc81d8f598..4b3c0179523 100644 --- a/esp-hal-common/src/peripherals/esp32.rs +++ b/esp-hal-common/src/peripherals/esp32.rs @@ -69,5 +69,7 @@ mod peripherals { DPORT, LEDC, RMT, + I2S0, + I2S1, } } diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs index 82f9514afe6..bdf078c42ee 100644 --- a/esp-hal-common/src/peripherals/esp32c3.rs +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -61,5 +61,6 @@ mod peripherals { SYSTEM, LEDC, RMT, + I2S, } } diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs index d5658e63d90..d422e120dd5 100644 --- a/esp-hal-common/src/peripherals/esp32s2.rs +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -68,5 +68,6 @@ mod peripherals { SYSTEM, LEDC, RMT, + I2S, } } diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs index 521e4d05789..5da9e6f3d9e 100644 --- a/esp-hal-common/src/peripherals/esp32s3.rs +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -80,5 +80,7 @@ mod peripherals { SYSTEM, LEDC, RMT, + I2S0, + I2S1, } }