Skip to content

Commit

Permalink
Fix up I2sParallel
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 21, 2024
1 parent dad3e9a commit c3ab143
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion esp-hal/src/i2s/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ where
)
}

/// Converts the SPI instance into async mode.
/// Converts the I2S instance into async mode.
pub fn into_async(self) -> I2s<'d, Async, T> {
I2s {
i2s_rx: RxCreator {
Expand Down
42 changes: 34 additions & 8 deletions esp-hal/src/i2s/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use crate::{
private::Internal,
system::PeripheralGuard,
Async,
Blocking,
Mode,
};

Expand Down Expand Up @@ -180,14 +181,11 @@ where
_guard: PeripheralGuard,
}

impl<'d, DM> I2sParallel<'d, DM>
where
DM: Mode,
{
impl<'d> I2sParallel<'d, Blocking> {
/// Create a new I2S Parallel Interface
pub fn new<CH>(
i2s: impl Peripheral<P = impl Instance> + 'd,
channel: Channel<'d, DM, CH>,
channel: Channel<'d, Blocking, CH>,
frequency: impl Into<fugit::HertzU32>,
pins: impl TxPins<'d>,
clock_pin: impl Peripheral<P = impl PeripheralOutput> + 'd,
Expand All @@ -199,15 +197,14 @@ where
}
}

impl<'d, I, DM> I2sParallel<'d, DM, I>
impl<'d, I> I2sParallel<'d, Blocking, I>
where
I: Instance,
DM: Mode,
{
/// Create a new I2S Parallel Interface
pub fn new_typed<CH>(
i2s: impl Peripheral<P = I> + 'd,
channel: Channel<'d, DM, CH>,
channel: Channel<'d, Blocking, CH>,
frequency: impl Into<fugit::HertzU32>,
mut pins: impl TxPins<'d>,
clock_pin: impl Peripheral<P = impl PeripheralOutput> + 'd,
Expand Down Expand Up @@ -237,6 +234,35 @@ where
}
}

/// Converts the I2S instance into async mode.
pub fn into_async(self) -> I2sParallel<'d, Async, I> {
I2sParallel {
instance: self.instance,
tx_channel: self.tx_channel.into_async(),
_guard: self._guard,
}
}
}

impl<'d, I> I2sParallel<'d, Async, I>
where
I: Instance,
{
/// Converts the I2S instance into async mode.
pub fn into_blocking(self) -> I2sParallel<'d, Blocking, I> {
I2sParallel {
instance: self.instance,
tx_channel: self.tx_channel.into_blocking(),
_guard: self._guard,
}
}
}

impl<'d, I, DM> I2sParallel<'d, DM, I>
where
I: Instance,
DM: Mode,
{
/// Write data to the I2S peripheral
pub fn send<BUF: DmaTxBuffer>(
mut self,
Expand Down
12 changes: 2 additions & 10 deletions examples/src/bin/embassy_i2s_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use embassy_executor::Spawner;
use embassy_time::Timer;
use esp_backtrace as _;
use esp_hal::{
dma::{Dma, DmaPriority, DmaTxBuf},
dma::{Dma, DmaTxBuf},
dma_buffers,
i2s::parallel::{I2sParallel, TxEightBits},
prelude::*,
Expand Down Expand Up @@ -56,15 +56,7 @@ async fn main(_spawner: Spawner) {
);

let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, BUFFER_SIZE);
let mut parallel = I2sParallel::new(
i2s,
dma_channel
.configure(false, DmaPriority::Priority0)
.into_async(),
1.MHz(),
pins,
clock,
);
let mut parallel = I2sParallel::new(i2s, dma_channel, 1.MHz(), pins, clock).into_async();

for (i, data) in tx_buffer.chunks_mut(4).enumerate() {
let offset = i * 4;
Expand Down
10 changes: 2 additions & 8 deletions examples/src/bin/i2s_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use esp_backtrace as _;
use esp_hal::{
delay::Delay,
dma::{Dma, DmaPriority, DmaTxBuf},
dma::{Dma, DmaTxBuf},
dma_buffers,
i2s::parallel::{I2sParallel, TxEightBits},
prelude::*,
Expand Down Expand Up @@ -50,13 +50,7 @@ fn main() -> ! {
);

let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, BUFFER_SIZE);
let mut parallel = I2sParallel::new(
i2s,
dma_channel.configure(false, DmaPriority::Priority0),
1.MHz(),
pins,
clock,
);
let mut parallel = I2sParallel::new(i2s, dma_channel, 1.MHz(), pins, clock);

for (i, data) in tx_buffer.chunks_mut(4).enumerate() {
let offset = i * 4;
Expand Down

0 comments on commit c3ab143

Please sign in to comment.