aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/i2s.rs47
-rw-r--r--examples/nrf/src/bin/i2s.rs17
2 files changed, 36 insertions, 28 deletions
diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs
index 0199ac615..e0fe6a6eb 100644
--- a/embassy-nrf/src/i2s.rs
+++ b/embassy-nrf/src/i2s.rs
@@ -2,18 +2,19 @@
2 2
3//! I2S 3//! I2S
4 4
5use core::future::poll_fn; 5//use core::future::poll_fn;
6use core::sync::atomic::{compiler_fence, Ordering}; 6//use core::sync::atomic::{compiler_fence, Ordering};
7use core::task::Poll; 7//use core::task::Poll;
8 8
9use embassy_hal_common::drop::OnDrop; 9//use embassy_hal_common::drop::OnDrop;
10use embassy_hal_common::{into_ref, PeripheralRef}; 10use embassy_hal_common::{into_ref, PeripheralRef};
11use pac::i2s::config::mcken;
12 11
13use crate::{pac, Peripheral}; 12//use crate::pac::i2s::config::mcken;
14use crate::interrupt::{Interrupt, InterruptExt}; 13
15use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; 14//use crate::gpio::sealed::Pin as _;
16use crate::gpio::sealed::Pin as _; 15use crate::gpio::{AnyPin, Pin as GpioPin};
16use crate::interrupt::Interrupt;
17use crate::Peripheral;
17 18
18// TODO: Define those in lib.rs somewhere else 19// TODO: Define those in lib.rs somewhere else
19// 20//
@@ -161,13 +162,12 @@ pub enum Mode {
161// _32MDiv125 = 0x020C0000, 162// _32MDiv125 = 0x020C0000,
162// } 163// }
163 164
164
165/// Interface to the UARTE peripheral using EasyDMA to offload the transmission and reception workload. 165/// Interface to the UARTE peripheral using EasyDMA to offload the transmission and reception workload.
166/// 166///
167/// For more details about EasyDMA, consult the module documentation. 167/// For more details about EasyDMA, consult the module documentation.
168pub struct I2s<'d, T: Instance> { 168pub struct I2s<'d, T: Instance> {
169 output: I2sOutput<'d, T>, 169 output: I2sOutput<'d, T>,
170 input: I2sInput<'d, T>, 170 _input: I2sInput<'d, T>,
171} 171}
172 172
173/// Transmitter interface to the UARTE peripheral obtained 173/// Transmitter interface to the UARTE peripheral obtained
@@ -198,7 +198,13 @@ impl<'d, T: Instance> I2s<'d, T> {
198 Self::new_inner( 198 Self::new_inner(
199 i2s, 199 i2s,
200 // irq, 200 // irq,
201 mck.map_into(), sck.map_into(), lrck.map_into(), sdin.map_into(), sdout.map_into(), config) 201 mck.map_into(),
202 sck.map_into(),
203 lrck.map_into(),
204 sdin.map_into(),
205 sdout.map_into(),
206 config,
207 )
202 } 208 }
203 209
204 fn new_inner( 210 fn new_inner(
@@ -209,12 +215,12 @@ impl<'d, T: Instance> I2s<'d, T> {
209 lrck: PeripheralRef<'d, AnyPin>, 215 lrck: PeripheralRef<'d, AnyPin>,
210 sdin: PeripheralRef<'d, AnyPin>, 216 sdin: PeripheralRef<'d, AnyPin>,
211 sdout: PeripheralRef<'d, AnyPin>, 217 sdout: PeripheralRef<'d, AnyPin>,
212 config: Config, 218 _config: Config,
213 ) -> Self { 219 ) -> Self {
214 into_ref!( 220 into_ref!(
215 i2s, 221 i2s, // irq,
216 // irq, 222 mck, sck, lrck, sdin, sdout
217 mck, sck, lrck, sdin, sdout); 223 );
218 224
219 let r = T::regs(); 225 let r = T::regs();
220 226
@@ -260,7 +266,7 @@ impl<'d, T: Instance> I2s<'d, T> {
260 output: I2sOutput { 266 output: I2sOutput {
261 _p: unsafe { i2s.clone_unchecked() }, 267 _p: unsafe { i2s.clone_unchecked() },
262 }, 268 },
263 input: I2sInput { _p: i2s }, 269 _input: I2sInput { _p: i2s },
264 } 270 }
265 } 271 }
266 272
@@ -357,7 +363,7 @@ pub(crate) mod sealed {
357 363
358 use embassy_sync::waitqueue::AtomicWaker; 364 use embassy_sync::waitqueue::AtomicWaker;
359 365
360 use super::*; 366 //use super::*;
361 367
362 pub struct State { 368 pub struct State {
363 pub input_waker: AtomicWaker, 369 pub input_waker: AtomicWaker,
@@ -375,7 +381,7 @@ pub(crate) mod sealed {
375 } 381 }
376 382
377 pub trait Instance { 383 pub trait Instance {
378 fn regs() -> &'static pac::i2s::RegisterBlock; 384 fn regs() -> &'static crate::pac::i2s::RegisterBlock;
379 fn state() -> &'static State; 385 fn state() -> &'static State;
380 } 386 }
381} 387}
@@ -384,6 +390,8 @@ pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
384 type Interrupt: Interrupt; 390 type Interrupt: Interrupt;
385} 391}
386 392
393// TODO: Unsure why this macro is flagged as unused by CI when in fact it's used elsewhere?
394#[allow(unused_macros)]
387macro_rules! impl_i2s { 395macro_rules! impl_i2s {
388 ($type:ident, $pac_type:ident, $irq:ident) => { 396 ($type:ident, $pac_type:ident, $irq:ident) => {
389 impl crate::i2s::sealed::Instance for peripherals::$type { 397 impl crate::i2s::sealed::Instance for peripherals::$type {
@@ -400,4 +408,3 @@ macro_rules! impl_i2s {
400 } 408 }
401 }; 409 };
402} 410}
403
diff --git a/examples/nrf/src/bin/i2s.rs b/examples/nrf/src/bin/i2s.rs
index 556f6b2e2..60cde3b65 100644
--- a/examples/nrf/src/bin/i2s.rs
+++ b/examples/nrf/src/bin/i2s.rs
@@ -4,9 +4,9 @@
4#![no_main] 4#![no_main]
5#![feature(type_alias_impl_trait)] 5#![feature(type_alias_impl_trait)]
6 6
7use defmt::*; 7//use defmt::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_nrf::{i2s}; 9use embassy_nrf::i2s;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12#[repr(align(4))] 12#[repr(align(4))]
@@ -18,7 +18,7 @@ async fn main(_spawner: Spawner) {
18 let config = i2s::Config::default(); 18 let config = i2s::Config::default();
19 19
20 let mut i2s = i2s::I2s::new(p.I2S, p.P0_28, p.P0_29, p.P0_31, p.P0_11, p.P0_30, config); 20 let mut i2s = i2s::I2s::new(p.I2S, p.P0_28, p.P0_29, p.P0_31, p.P0_11, p.P0_30, config);
21 21
22 let mut signal_buf: Aligned<[i16; 32]> = Aligned([0i16; 32]); 22 let mut signal_buf: Aligned<[i16; 32]> = Aligned([0i16; 32]);
23 let len = signal_buf.0.len() / 2; 23 let len = signal_buf.0.len() / 2;
24 for x in 0..len { 24 for x in 0..len {
@@ -31,18 +31,19 @@ async fn main(_spawner: Spawner) {
31 31
32 i2s.start(); 32 i2s.start();
33 i2s.set_tx_enabled(true); 33 i2s.set_tx_enabled(true);
34 34
35 loop { 35 loop {
36 i2s.tx(ptr, len).await; 36 match i2s.tx(ptr, len).await {
37 Ok(_) => todo!(),
38 Err(_) => todo!(),
39 };
37 } 40 }
38} 41}
39 42
40fn triangle_wave(x: i32, length: usize, amplitude: i32, phase: i32, periods: i32) -> i32 { 43fn triangle_wave(x: i32, length: usize, amplitude: i32, phase: i32, periods: i32) -> i32 {
41 let length = length as i32; 44 let length = length as i32;
42 amplitude 45 amplitude
43 - ((2 * periods * (x + phase + length / (4 * periods)) * amplitude / length) 46 - ((2 * periods * (x + phase + length / (4 * periods)) * amplitude / length) % (2 * amplitude) - amplitude)
44 % (2 * amplitude)
45 - amplitude)
46 .abs() 47 .abs()
47 - amplitude / 2 48 - amplitude / 2
48} 49}