Skip to content

Commit

Permalink
Merge #372
Browse files Browse the repository at this point in the history
372: Unified how pins are return in `free` calls r=jonas-schievink a=korken89

Hi,

I unified so pins are returned the same for all peripherals.

Co-authored-by: Emil Fresk <[email protected]>
Co-authored-by: Jonas Schievink <[email protected]>
  • Loading branch information
3 people authored Jan 12, 2022
2 parents 28d3bba + 5b43511 commit 577a9f3
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 194 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Unreleased

(no changes)
### Changed

- Unified how pins are are returned in `free` calls ([#372]).

[#372]: https://github.com/nrf-rs/nrf-hal/pull/372

## [0.14.1]

Expand Down
25 changes: 11 additions & 14 deletions examples/i2s-controller-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use {
hal::{
gpio::{Input, Level, Output, Pin, PullUp, PushPull},
gpiote::*,
i2s::*,
i2s::{self, *},
pac::{TIMER0, UARTE0},
timer::Timer,
uarte::*,
uarte::{self, *},
},
nrf52840_hal as hal,
rtic::cyccnt::U32Ext,
Expand Down Expand Up @@ -74,18 +74,15 @@ const APP: () = {
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);

// Configure I2S controller
let mck_pin = p0.p0_28.into_push_pull_output(Level::Low).degrade();
let sck_pin = p0.p0_29.into_push_pull_output(Level::Low).degrade();
let sdout_pin = p0.p0_30.into_push_pull_output(Level::Low).degrade();
let lrck_pin = p0.p0_31.into_push_pull_output(Level::Low).degrade();

let i2s = I2S::new_controller(
let i2s = I2S::new(
ctx.device.I2S,
Some(&mck_pin),
&sck_pin,
&lrck_pin,
None,
Some(&sdout_pin),
i2s::Pins::Controller {
mck: Some(p0.p0_28.into_push_pull_output(Level::Low).degrade()),
sck: p0.p0_29.into_push_pull_output(Level::Low).degrade(),
lrck: p0.p0_31.into_push_pull_output(Level::Low).degrade(),
sdin: None,
sdout: Some(p0.p0_30.into_push_pull_output(Level::Low).degrade()),
},
);
i2s.start();

Expand All @@ -100,7 +97,7 @@ const APP: () = {
// Configure the onboard USB CDC UARTE
let uarte = Uarte::new(
ctx.device.UARTE0,
Pins {
uarte::Pins {
txd: p0.p0_06.into_push_pull_output(Level::High).degrade(),
rxd: p0.p0_08.into_floating_input().degrade(),
cts: None,
Expand Down
24 changes: 11 additions & 13 deletions examples/i2s-peripheral-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use {
},
hal::{
gpio::Level,
i2s::*,
i2s::{self, *},
pac::SPIM0,
spim::{Frequency, Mode as SPIMode, Phase, Pins, Polarity, Spim},
spim::{self, Frequency, Mode as SPIMode, Phase, Polarity, Spim},
},
nrf52840_hal as hal,
rtt_target::{rprintln, rtt_init_print},
Expand Down Expand Up @@ -45,19 +45,17 @@ const APP: () = {
rprintln!("Play me some audio...");

let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
let mck_pin = p0.p0_25.into_floating_input().degrade();
let sck_pin = p0.p0_24.into_floating_input().degrade();
let lrck_pin = p0.p0_16.into_floating_input().degrade();
let sdin_pin = p0.p0_14.into_floating_input().degrade();

// Configure I2S reception
let i2s = I2S::new_peripheral(
let i2s = I2S::new(
ctx.device.I2S,
Some(&mck_pin),
&sck_pin,
&lrck_pin,
Some(&sdin_pin),
None,
i2s::Pins::Peripheral {
mck: Some(p0.p0_25.into_floating_input().degrade()),
sck: p0.p0_24.into_floating_input().degrade(),
lrck: p0.p0_16.into_floating_input().degrade(),
sdin: Some(p0.p0_14.into_floating_input().degrade()),
sdout: None,
},
);
i2s.enable_interrupt(I2SEvent::RxPtrUpdated).start();

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

let rgb = Spim::new(
ctx.device.SPIM0,
Pins {
spim::Pins {
miso: None,
mosi: Some(rgb_data_pin),
sck: rgb_clk_pin,
Expand Down
9 changes: 6 additions & 3 deletions examples/qdec-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ const APP: () = {
rtt_init_print!();

let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
let pin_a = p0.p0_31.into_pullup_input().degrade();
let pin_b = p0.p0_30.into_pullup_input().degrade();
let pins = Pins {
a: p0.p0_31.into_pullup_input().degrade(),
b: p0.p0_30.into_pullup_input().degrade(),
led: None,
};

let qdec = Qdec::new(ctx.device.QDEC, pin_a, pin_b, None, SamplePeriod::_128us);
let qdec = Qdec::new(ctx.device.QDEC, pins, SamplePeriod::_128us);
qdec.debounce(true)
.enable_interrupt(NumSamples::_1smpl)
.enable();
Expand Down
Loading

0 comments on commit 577a9f3

Please sign in to comment.