Skip to content

Commit 0589cc9

Browse files
committed
I2S refactor and addition of Pins
1 parent e3a7b7c commit 0589cc9

File tree

3 files changed

+213
-136
lines changed

3 files changed

+213
-136
lines changed

examples/i2s-controller-demo/src/main.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use {
1919
hal::{
2020
gpio::{Input, Level, Output, Pin, PullUp, PushPull},
2121
gpiote::*,
22-
i2s::*,
22+
i2s::{self, *},
2323
pac::{TIMER0, UARTE0},
2424
timer::Timer,
25-
uarte::*,
25+
uarte::{self, *},
2626
},
2727
nrf52840_hal as hal,
2828
rtic::cyccnt::U32Ext,
@@ -74,18 +74,15 @@ const APP: () = {
7474
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
7575

7676
// Configure I2S controller
77-
let mck_pin = p0.p0_28.into_push_pull_output(Level::Low).degrade();
78-
let sck_pin = p0.p0_29.into_push_pull_output(Level::Low).degrade();
79-
let sdout_pin = p0.p0_30.into_push_pull_output(Level::Low).degrade();
80-
let lrck_pin = p0.p0_31.into_push_pull_output(Level::Low).degrade();
81-
82-
let i2s = I2S::new_controller(
77+
let i2s = I2S::new(
8378
ctx.device.I2S,
84-
Some(&mck_pin),
85-
&sck_pin,
86-
&lrck_pin,
87-
None,
88-
Some(&sdout_pin),
79+
i2s::Pins::Controller {
80+
mck: Some(p0.p0_28.into_push_pull_output(Level::Low).degrade()),
81+
sck: p0.p0_29.into_push_pull_output(Level::Low).degrade(),
82+
lrck: p0.p0_31.into_push_pull_output(Level::Low).degrade(),
83+
sdin: None,
84+
sdout: Some(p0.p0_30.into_push_pull_output(Level::Low).degrade()),
85+
},
8986
);
9087
i2s.start();
9188

@@ -100,7 +97,7 @@ const APP: () = {
10097
// Configure the onboard USB CDC UARTE
10198
let uarte = Uarte::new(
10299
ctx.device.UARTE0,
103-
Pins {
100+
uarte::Pins {
104101
txd: p0.p0_06.into_push_pull_output(Level::High).degrade(),
105102
rxd: p0.p0_08.into_floating_input().degrade(),
106103
cts: None,

examples/i2s-peripheral-demo/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use {
1212
},
1313
hal::{
1414
gpio::Level,
15-
i2s::*,
15+
i2s::{self, *},
1616
pac::SPIM0,
17-
spim::{Frequency, Mode as SPIMode, Phase, Pins, Polarity, Spim},
17+
spim::{self, Frequency, Mode as SPIMode, Phase, Polarity, Spim},
1818
},
1919
nrf52840_hal as hal,
2020
rtt_target::{rprintln, rtt_init_print},
@@ -45,19 +45,17 @@ const APP: () = {
4545
rprintln!("Play me some audio...");
4646

4747
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
48-
let mck_pin = p0.p0_25.into_floating_input().degrade();
49-
let sck_pin = p0.p0_24.into_floating_input().degrade();
50-
let lrck_pin = p0.p0_16.into_floating_input().degrade();
51-
let sdin_pin = p0.p0_14.into_floating_input().degrade();
5248

5349
// Configure I2S reception
54-
let i2s = I2S::new_peripheral(
50+
let i2s = I2S::new(
5551
ctx.device.I2S,
56-
Some(&mck_pin),
57-
&sck_pin,
58-
&lrck_pin,
59-
Some(&sdin_pin),
60-
None,
52+
i2s::Pins::Peripheral {
53+
mck: Some(p0.p0_25.into_floating_input().degrade()),
54+
sck: p0.p0_24.into_floating_input().degrade(),
55+
lrck: p0.p0_16.into_floating_input().degrade(),
56+
sdin: Some(p0.p0_14.into_floating_input().degrade()),
57+
sdout: None,
58+
},
6159
);
6260
i2s.enable_interrupt(I2SEvent::RxPtrUpdated).start();
6361

@@ -68,7 +66,7 @@ const APP: () = {
6866

6967
let rgb = Spim::new(
7068
ctx.device.SPIM0,
71-
Pins {
69+
spim::Pins {
7270
miso: None,
7371
mosi: Some(rgb_data_pin),
7472
sck: rgb_clk_pin,

0 commit comments

Comments
 (0)