Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions nrf52840-hal-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cortex-m-rt = { version = "0.7.1", features = ["device"] }
defmt = "0.3.0"
defmt-rtt = "0.3.0"
defmt-test = "0.3.0"
embedded-hal = "1.0.0"
embedded-storage = "0.3.0"
nrf52840-hal = { path = "../nrf52840-hal" }
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
3 changes: 2 additions & 1 deletion nrf52840-hal-tests/tests/gpio-input-floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct State {
#[defmt_test::tests]
mod tests {
use defmt::{assert, unwrap};
use nrf52840_hal::{gpio::p0, pac, prelude::*};
use embedded_hal::digital::InputPin;
use nrf52840_hal::{gpio::p0, pac};

use super::State;

Expand Down
10 changes: 5 additions & 5 deletions nrf52840-hal-tests/tests/gpio-input-pulled.rs
Copy link
Copy Markdown

@adamhott adamhott Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 46: Can you please comment on the change to make pulldown_pin mutuable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embedded_hal::digital::InputPin::is_low takes &mut self, so it needs to be mutable for the call on line 49.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

use defmt_rtt as _;
use nrf52840_hal as _;
use panic_probe as _;

use nrf52840_hal::gpio::{Floating, Input, Pin};
use panic_probe as _;

struct State {
input_pin: Pin<Input<Floating>>,
Expand All @@ -21,7 +20,8 @@ struct State {
mod tests {
use cortex_m::asm;
use defmt::{assert, unwrap};
use nrf52840_hal::{gpio::p0, pac, prelude::*};
use embedded_hal::digital::InputPin;
use nrf52840_hal::{gpio::p0, pac};

use super::State;

Expand All @@ -43,7 +43,7 @@ mod tests {
fn pulldown_is_low(state: &mut State) {
let puller_pin = unwrap!(state.puller_pin.take());

let pulldown_pin = puller_pin.into_pulldown_input();
let mut pulldown_pin = puller_pin.into_pulldown_input();
// GPIO re-configuration is not instantaneous so a delay is needed
asm::delay(100);
assert!(pulldown_pin.is_low().unwrap());
Expand All @@ -65,7 +65,7 @@ mod tests {
fn pullup_is_high(state: &mut State) {
let puller_pin = unwrap!(state.puller_pin.take());

let pullup_pin = puller_pin.into_pullup_input();
let mut pullup_pin = puller_pin.into_pullup_input();
// GPIO re-configuration is not instantaneous so a delay is needed
asm::delay(100);
assert!(pullup_pin.is_high().unwrap());
Expand Down
13 changes: 6 additions & 7 deletions nrf52840-hal-tests/tests/gpio-output-open-drain-io.rs
Copy link
Copy Markdown

@adamhott adamhott Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 53-54: Can you please comment on the change made from:

(state.input_pin.as_ref().unwrap().is_low().unwrap());

to:

(state.input_pin.as_mut().unwrap().is_low().unwrap());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, embedded_hal::digital::InputPin::is_low takes &mut self, so we need a mutable reference.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

use defmt_rtt as _;
use nrf52840_hal as _;
use panic_probe as _;

use nrf52840_hal::gpio::{Input, OpenDrainIO, Output, Pin, PullUp};
use panic_probe as _;

struct State {
input_pin: Option<Pin<Input<PullUp>>>,
Expand All @@ -21,10 +20,10 @@ struct State {
mod tests {
use cortex_m::asm;
use defmt::{assert, unwrap};
use embedded_hal::digital::{InputPin, OutputPin};
use nrf52840_hal::{
gpio::{p0, Level, OpenDrainConfig},
pac,
prelude::*,
};

use super::State;
Expand All @@ -51,17 +50,17 @@ mod tests {
state.output_pin.set_low().unwrap();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(state.input_pin.as_ref().unwrap().is_low().unwrap());
assert!(state.input_pin.as_mut().unwrap().is_low().unwrap());
}

#[test]
fn set_high_is_open(state: &mut State) {
state.output_pin.set_high().unwrap();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(state.input_pin.as_ref().unwrap().is_high().unwrap());
assert!(state.input_pin.as_mut().unwrap().is_high().unwrap());

let pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
let mut pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(pulled_down_input_pin.is_low().unwrap());
Expand All @@ -82,7 +81,7 @@ mod tests {
fn open_pulldown_reads_low(state: &mut State) {
state.output_pin.set_high().unwrap();

let pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
let mut pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(pulled_down_input_pin.is_low().unwrap());
Expand Down
11 changes: 5 additions & 6 deletions nrf52840-hal-tests/tests/gpio-output-open-drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

use defmt_rtt as _;
use nrf52840_hal as _;
use panic_probe as _;

use nrf52840_hal::gpio::{Input, OpenDrain, Output, Pin, PullUp};
use panic_probe as _;

struct State {
input_pin: Option<Pin<Input<PullUp>>>,
Expand All @@ -21,10 +20,10 @@ struct State {
mod tests {
use cortex_m::asm;
use defmt::{assert, unwrap};
use embedded_hal::digital::{InputPin, OutputPin};
use nrf52840_hal::{
gpio::{p0, Level, OpenDrainConfig},
pac,
prelude::*,
};

use super::State;
Expand All @@ -51,17 +50,17 @@ mod tests {
state.output_pin.set_low().unwrap();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(state.input_pin.as_ref().unwrap().is_low().unwrap());
assert!(state.input_pin.as_mut().unwrap().is_low().unwrap());
}

#[test]
fn set_high_is_open(state: &mut State) {
state.output_pin.set_high().unwrap();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(state.input_pin.as_ref().unwrap().is_high().unwrap());
assert!(state.input_pin.as_mut().unwrap().is_high().unwrap());

let pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
let mut pulled_down_input_pin = state.input_pin.take().unwrap().into_pulldown_input();
// GPIO operations are not instantaneous so a delay is needed
asm::delay(100);
assert!(pulled_down_input_pin.is_low().unwrap());
Expand Down
5 changes: 2 additions & 3 deletions nrf52840-hal-tests/tests/gpio-output-push-pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

use defmt_rtt as _;
use nrf52840_hal as _;
use panic_probe as _;

use nrf52840_hal::gpio::{Floating, Input, Output, Pin, PushPull};
use panic_probe as _;

struct State {
input_pin: Pin<Input<Floating>>,
Expand All @@ -21,10 +20,10 @@ struct State {
mod tests {
use cortex_m::asm;
use defmt::{assert, unwrap};
use embedded_hal::digital::{InputPin, OutputPin};
use nrf52840_hal::{
gpio::{p0, Level},
pac,
prelude::*,
};

use super::State;
Expand Down