diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-03-05 20:40:13 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-03-06 00:17:51 +0100 |
| commit | 34563b74aa48c53622344541153266b0227fc9bf (patch) | |
| tree | 795533be5cbdf74f62a170c72a9c30a3eb588327 /examples | |
| parent | 63b75eaf644eee2da2c16f72dbd46bb404f5fdbd (diff) | |
nrf/i2s: switch to new interrupt binding.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf52840/src/bin/i2s_effect.rs | 15 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/i2s_monitor.rs | 9 | ||||
| -rw-r--r-- | examples/nrf52840/src/bin/i2s_waveform.rs | 9 |
3 files changed, 19 insertions, 14 deletions
diff --git a/examples/nrf52840/src/bin/i2s_effect.rs b/examples/nrf52840/src/bin/i2s_effect.rs index 52d46e4f9..391514d93 100644 --- a/examples/nrf52840/src/bin/i2s_effect.rs +++ b/examples/nrf52840/src/bin/i2s_effect.rs | |||
| @@ -7,7 +7,7 @@ use core::f32::consts::PI; | |||
| 7 | use defmt::{error, info}; | 7 | use defmt::{error, info}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::i2s::{self, Channels, Config, MasterClock, MultiBuffering, Sample as _, SampleWidth, I2S}; | 9 | use embassy_nrf::i2s::{self, Channels, Config, MasterClock, MultiBuffering, Sample as _, SampleWidth, I2S}; |
| 10 | use embassy_nrf::interrupt; | 10 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | type Sample = i16; | 13 | type Sample = i16; |
| @@ -15,6 +15,10 @@ type Sample = i16; | |||
| 15 | const NUM_BUFFERS: usize = 2; | 15 | const NUM_BUFFERS: usize = 2; |
| 16 | const NUM_SAMPLES: usize = 4; | 16 | const NUM_SAMPLES: usize = 4; |
| 17 | 17 | ||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 20 | }); | ||
| 21 | |||
| 18 | #[embassy_executor::main] | 22 | #[embassy_executor::main] |
| 19 | async fn main(_spawner: Spawner) { | 23 | async fn main(_spawner: Spawner) { |
| 20 | let p = embassy_nrf::init(Default::default()); | 24 | let p = embassy_nrf::init(Default::default()); |
| @@ -28,15 +32,10 @@ async fn main(_spawner: Spawner) { | |||
| 28 | config.sample_width = SampleWidth::_16bit; | 32 | config.sample_width = SampleWidth::_16bit; |
| 29 | config.channels = Channels::MonoLeft; | 33 | config.channels = Channels::MonoLeft; |
| 30 | 34 | ||
| 31 | let irq = interrupt::take!(I2S); | ||
| 32 | let buffers_out = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); | 35 | let buffers_out = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); |
| 33 | let buffers_in = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); | 36 | let buffers_in = MultiBuffering::<Sample, NUM_BUFFERS, NUM_SAMPLES>::new(); |
| 34 | let mut full_duplex_stream = I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).full_duplex( | 37 | let mut full_duplex_stream = I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config) |
| 35 | p.P0_29, | 38 | .full_duplex(p.P0_29, p.P0_28, buffers_out, buffers_in); |
| 36 | p.P0_28, | ||
| 37 | buffers_out, | ||
| 38 | buffers_in, | ||
| 39 | ); | ||
| 40 | 39 | ||
| 41 | let mut modulator = SineOsc::new(); | 40 | let mut modulator = SineOsc::new(); |
| 42 | modulator.set_frequency(8.0, 1.0 / sample_rate as f32); | 41 | modulator.set_frequency(8.0, 1.0 / sample_rate as f32); |
diff --git a/examples/nrf52840/src/bin/i2s_monitor.rs b/examples/nrf52840/src/bin/i2s_monitor.rs index 5ebfd9542..4ed597c0d 100644 --- a/examples/nrf52840/src/bin/i2s_monitor.rs +++ b/examples/nrf52840/src/bin/i2s_monitor.rs | |||
| @@ -5,14 +5,18 @@ | |||
| 5 | use defmt::{debug, error, info}; | 5 | use defmt::{debug, error, info}; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 7 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; |
| 8 | use embassy_nrf::interrupt; | ||
| 9 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; | 8 | use embassy_nrf::pwm::{Prescaler, SimplePwm}; |
| 9 | use embassy_nrf::{bind_interrupts, peripherals}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | type Sample = i16; | 12 | type Sample = i16; |
| 13 | 13 | ||
| 14 | const NUM_SAMPLES: usize = 500; | 14 | const NUM_SAMPLES: usize = 500; |
| 15 | 15 | ||
| 16 | bind_interrupts!(struct Irqs { | ||
| 17 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 18 | }); | ||
| 19 | |||
| 16 | #[embassy_executor::main] | 20 | #[embassy_executor::main] |
| 17 | async fn main(_spawner: Spawner) { | 21 | async fn main(_spawner: Spawner) { |
| 18 | let p = embassy_nrf::init(Default::default()); | 22 | let p = embassy_nrf::init(Default::default()); |
| @@ -26,10 +30,9 @@ async fn main(_spawner: Spawner) { | |||
| 26 | config.sample_width = SampleWidth::_16bit; | 30 | config.sample_width = SampleWidth::_16bit; |
| 27 | config.channels = Channels::MonoLeft; | 31 | config.channels = Channels::MonoLeft; |
| 28 | 32 | ||
| 29 | let irq = interrupt::take!(I2S); | ||
| 30 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); | 33 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); |
| 31 | let mut input_stream = | 34 | let mut input_stream = |
| 32 | I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); | 35 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).input(p.P0_29, buffers); |
| 33 | 36 | ||
| 34 | // Configure the PWM to use the pins corresponding to the RGB leds | 37 | // Configure the PWM to use the pins corresponding to the RGB leds |
| 35 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24); | 38 | let mut pwm = SimplePwm::new_3ch(p.PWM0, p.P0_23, p.P0_22, p.P0_24); |
diff --git a/examples/nrf52840/src/bin/i2s_waveform.rs b/examples/nrf52840/src/bin/i2s_waveform.rs index eda930677..f2c1166b1 100644 --- a/examples/nrf52840/src/bin/i2s_waveform.rs +++ b/examples/nrf52840/src/bin/i2s_waveform.rs | |||
| @@ -7,13 +7,17 @@ use core::f32::consts::PI; | |||
| 7 | use defmt::{error, info}; | 7 | use defmt::{error, info}; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; | 9 | use embassy_nrf::i2s::{self, Channels, Config, DoubleBuffering, MasterClock, Sample as _, SampleWidth, I2S}; |
| 10 | use embassy_nrf::interrupt; | 10 | use embassy_nrf::{bind_interrupts, peripherals}; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | type Sample = i16; | 13 | type Sample = i16; |
| 14 | 14 | ||
| 15 | const NUM_SAMPLES: usize = 50; | 15 | const NUM_SAMPLES: usize = 50; |
| 16 | 16 | ||
| 17 | bind_interrupts!(struct Irqs { | ||
| 18 | I2S => i2s::InterruptHandler<peripherals::I2S>; | ||
| 19 | }); | ||
| 20 | |||
| 17 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 19 | let p = embassy_nrf::init(Default::default()); | 23 | let p = embassy_nrf::init(Default::default()); |
| @@ -27,10 +31,9 @@ async fn main(_spawner: Spawner) { | |||
| 27 | config.sample_width = SampleWidth::_16bit; | 31 | config.sample_width = SampleWidth::_16bit; |
| 28 | config.channels = Channels::MonoLeft; | 32 | config.channels = Channels::MonoLeft; |
| 29 | 33 | ||
| 30 | let irq = interrupt::take!(I2S); | ||
| 31 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); | 34 | let buffers = DoubleBuffering::<Sample, NUM_SAMPLES>::new(); |
| 32 | let mut output_stream = | 35 | let mut output_stream = |
| 33 | I2S::master(p.I2S, irq, p.P0_25, p.P0_26, p.P0_27, master_clock, config).output(p.P0_28, buffers); | 36 | I2S::new_master(p.I2S, Irqs, p.P0_25, p.P0_26, p.P0_27, master_clock, config).output(p.P0_28, buffers); |
| 34 | 37 | ||
| 35 | let mut waveform = Waveform::new(1.0 / sample_rate as f32); | 38 | let mut waveform = Waveform::new(1.0 / sample_rate as f32); |
| 36 | 39 | ||
