Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GPIOs start in a Disconnected state #220

Merged
merged 2 commits into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

- Remove `Spi::read` ([#190]).
- Seal the `timer::Instance` trait ([#214]).
- Make GPIOs start in a `Disconnected` state instead of `Input<Floating>` ([#220]).

[#185]: https://github.com/nrf-rs/nrf-hal/pull/185
[#188]: https://github.com/nrf-rs/nrf-hal/pull/188
Expand All @@ -36,6 +37,7 @@
[#206]: https://github.com/nrf-rs/nrf-hal/pull/206
[#217]: https://github.com/nrf-rs/nrf-hal/pull/217
[#214]: https://github.com/nrf-rs/nrf-hal/pull/214
[#220]: https://github.com/nrf-rs/nrf-hal/pull/220

## [0.11.1]

Expand Down
100 changes: 52 additions & 48 deletions nrf-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use core::marker::PhantomData;

/// Disconnected pin in input mode (type state, reset value).
pub struct Disconnected;

/// Input mode (type state).
pub struct Input<MODE> {
_mode: PhantomData<MODE>,
Expand Down Expand Up @@ -328,6 +331,7 @@ macro_rules! gpio {
Port,

Floating,
Disconnected,
Input,
Level,
OpenDrain,
Expand Down Expand Up @@ -548,58 +552,58 @@ macro_rules! gpio {
// 32-bit GPIO port (P0)
// ===========================================================================
gpio!(P0, p0, p0, Port::Port0, [
P0_00: (p0_00, 0, Input<Floating>),
P0_01: (p0_01, 1, Input<Floating>),
P0_02: (p0_02, 2, Input<Floating>),
P0_03: (p0_03, 3, Input<Floating>),
P0_04: (p0_04, 4, Input<Floating>),
P0_05: (p0_05, 5, Input<Floating>),
P0_06: (p0_06, 6, Input<Floating>),
P0_07: (p0_07, 7, Input<Floating>),
P0_08: (p0_08, 8, Input<Floating>),
P0_09: (p0_09, 9, Input<Floating>),
P0_10: (p0_10, 10, Input<Floating>),
P0_11: (p0_11, 11, Input<Floating>),
P0_12: (p0_12, 12, Input<Floating>),
P0_13: (p0_13, 13, Input<Floating>),
P0_14: (p0_14, 14, Input<Floating>),
P0_15: (p0_15, 15, Input<Floating>),
P0_16: (p0_16, 16, Input<Floating>),
P0_17: (p0_17, 17, Input<Floating>),
P0_18: (p0_18, 18, Input<Floating>),
P0_19: (p0_19, 19, Input<Floating>),
P0_20: (p0_20, 20, Input<Floating>),
P0_21: (p0_21, 21, Input<Floating>),
P0_22: (p0_22, 22, Input<Floating>),
P0_23: (p0_23, 23, Input<Floating>),
P0_24: (p0_24, 24, Input<Floating>),
P0_25: (p0_25, 25, Input<Floating>),
P0_26: (p0_26, 26, Input<Floating>),
P0_27: (p0_27, 27, Input<Floating>),
P0_28: (p0_28, 28, Input<Floating>),
P0_29: (p0_29, 29, Input<Floating>),
P0_30: (p0_30, 30, Input<Floating>),
P0_31: (p0_31, 31, Input<Floating>),
P0_00: (p0_00, 0, Input<Disconnected>),
P0_01: (p0_01, 1, Input<Disconnected>),
P0_02: (p0_02, 2, Input<Disconnected>),
P0_03: (p0_03, 3, Input<Disconnected>),
P0_04: (p0_04, 4, Input<Disconnected>),
P0_05: (p0_05, 5, Input<Disconnected>),
P0_06: (p0_06, 6, Input<Disconnected>),
P0_07: (p0_07, 7, Input<Disconnected>),
P0_08: (p0_08, 8, Input<Disconnected>),
P0_09: (p0_09, 9, Input<Disconnected>),
P0_10: (p0_10, 10, Input<Disconnected>),
P0_11: (p0_11, 11, Input<Disconnected>),
P0_12: (p0_12, 12, Input<Disconnected>),
P0_13: (p0_13, 13, Input<Disconnected>),
P0_14: (p0_14, 14, Input<Disconnected>),
P0_15: (p0_15, 15, Input<Disconnected>),
P0_16: (p0_16, 16, Input<Disconnected>),
P0_17: (p0_17, 17, Input<Disconnected>),
P0_18: (p0_18, 18, Input<Disconnected>),
P0_19: (p0_19, 19, Input<Disconnected>),
P0_20: (p0_20, 20, Input<Disconnected>),
P0_21: (p0_21, 21, Input<Disconnected>),
P0_22: (p0_22, 22, Input<Disconnected>),
P0_23: (p0_23, 23, Input<Disconnected>),
P0_24: (p0_24, 24, Input<Disconnected>),
P0_25: (p0_25, 25, Input<Disconnected>),
P0_26: (p0_26, 26, Input<Disconnected>),
P0_27: (p0_27, 27, Input<Disconnected>),
P0_28: (p0_28, 28, Input<Disconnected>),
P0_29: (p0_29, 29, Input<Disconnected>),
P0_30: (p0_30, 30, Input<Disconnected>),
P0_31: (p0_31, 31, Input<Disconnected>),
]);

// The p1 types are present in the p0 module generated from the
// svd, but we want to export them in a p1 module from this crate.
#[cfg(any(feature = "52833", feature = "52840"))]
gpio!(P1, p0, p1, Port::Port1, [
P1_00: (p1_00, 0, Input<Floating>),
P1_01: (p1_01, 1, Input<Floating>),
P1_02: (p1_02, 2, Input<Floating>),
P1_03: (p1_03, 3, Input<Floating>),
P1_04: (p1_04, 4, Input<Floating>),
P1_05: (p1_05, 5, Input<Floating>),
P1_06: (p1_06, 6, Input<Floating>),
P1_07: (p1_07, 7, Input<Floating>),
P1_08: (p1_08, 8, Input<Floating>),
P1_09: (p1_09, 9, Input<Floating>),
P1_10: (p1_10, 10, Input<Floating>),
P1_11: (p1_11, 11, Input<Floating>),
P1_12: (p1_12, 12, Input<Floating>),
P1_13: (p1_13, 13, Input<Floating>),
P1_14: (p1_14, 14, Input<Floating>),
P1_15: (p1_15, 15, Input<Floating>),
P1_00: (p1_00, 0, Input<Disconnected>),
P1_01: (p1_01, 1, Input<Disconnected>),
P1_02: (p1_02, 2, Input<Disconnected>),
P1_03: (p1_03, 3, Input<Disconnected>),
P1_04: (p1_04, 4, Input<Disconnected>),
P1_05: (p1_05, 5, Input<Disconnected>),
P1_06: (p1_06, 6, Input<Disconnected>),
P1_07: (p1_07, 7, Input<Disconnected>),
P1_08: (p1_08, 8, Input<Disconnected>),
P1_09: (p1_09, 9, Input<Disconnected>),
P1_10: (p1_10, 10, Input<Disconnected>),
P1_11: (p1_11, 11, Input<Disconnected>),
P1_12: (p1_12, 12, Input<Disconnected>),
P1_13: (p1_13, 13, Input<Disconnected>),
P1_14: (p1_14, 14, Input<Disconnected>),
P1_15: (p1_15, 15, Input<Disconnected>),
]);
47 changes: 27 additions & 20 deletions nrf-hal-common/src/saadc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::pac::{saadc_ns as saadc, SAADC_NS as SAADC};
#[cfg(not(feature = "9160"))]
use crate::pac::{saadc, SAADC};

use crate::gpio::{Floating, Input};
use core::{
hint::unreachable_unchecked,
sync::atomic::{compiler_fence, Ordering::SeqCst},
Expand Down Expand Up @@ -217,9 +216,9 @@ where
}

macro_rules! channel_mappings {
($($n:expr => $pin:path),*) => {
( $($n:expr => $pin:ident,)*) => {
$(
impl Channel<Saadc> for $pin {
impl<STATE> Channel<Saadc> for crate::gpio::p0::$pin<STATE> {
type ID = u8;

fn channel() -> <Self as embedded_hal::adc::Channel<Saadc>>::ID {
Expand All @@ -232,27 +231,35 @@ macro_rules! channel_mappings {

#[cfg(feature = "9160")]
channel_mappings! {
0 => crate::gpio::p0::P0_13<Input<Floating>>,
1 => crate::gpio::p0::P0_14<Input<Floating>>,
2 => crate::gpio::p0::P0_15<Input<Floating>>,
3 => crate::gpio::p0::P0_16<Input<Floating>>,
4 => crate::gpio::p0::P0_17<Input<Floating>>,
5 => crate::gpio::p0::P0_18<Input<Floating>>,
6 => crate::gpio::p0::P0_19<Input<Floating>>,
7 => crate::gpio::p0::P0_20<Input<Floating>>
0 => P0_13,
1 => P0_14,
2 => P0_15,
3 => P0_16,
4 => P0_17,
5 => P0_18,
6 => P0_19,
7 => P0_20,
}

#[cfg(not(feature = "9160"))]
channel_mappings! {
0 => crate::gpio::p0::P0_02<Input<Floating>>,
1 => crate::gpio::p0::P0_03<Input<Floating>>,
2 => crate::gpio::p0::P0_04<Input<Floating>>,
3 => crate::gpio::p0::P0_05<Input<Floating>>,
4 => crate::gpio::p0::P0_28<Input<Floating>>,
5 => crate::gpio::p0::P0_29<Input<Floating>>,
6 => crate::gpio::p0::P0_30<Input<Floating>>,
7 => crate::gpio::p0::P0_31<Input<Floating>>,
8 => InternalVdd
0 => P0_02,
1 => P0_03,
2 => P0_04,
3 => P0_05,
4 => P0_28,
5 => P0_29,
6 => P0_30,
7 => P0_31,
}

#[cfg(not(feature = "9160"))]
impl Channel<Saadc> for InternalVdd {
type ID = u8;

fn channel() -> <Self as embedded_hal::adc::Channel<Saadc>>::ID {
8
}
}

#[cfg(not(feature = "9160"))]
Expand Down