diff options
| author | Roman Valls Guimera <[email protected]> | 2022-11-09 21:58:56 +0100 |
|---|---|---|
| committer | Roman Valls Guimera <[email protected]> | 2022-11-09 22:31:19 +0100 |
| commit | 3760b60db382c8c4f8d7067a8d472affa6db928b (patch) | |
| tree | b728d220cf2b4b584515b1d3bd8940d6bd3828c4 /examples | |
| parent | cecd77938c694ff2bad2a259ff64f2f468dcb04a (diff) | |
Make bors grin ;)
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/i2s.rs | 17 |
1 files changed, 9 insertions, 8 deletions
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 | ||
| 7 | use defmt::*; | 7 | //use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::{i2s}; | 9 | use embassy_nrf::i2s; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {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 | ||
| 40 | fn triangle_wave(x: i32, length: usize, amplitude: i32, phase: i32, periods: i32) -> i32 { | 43 | fn 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 | } |
