Skip to content

Commit

Permalink
Adjust for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
playfulFence committed Jan 9, 2025
1 parent ce49ee6 commit 07aa760
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions hil-test/tests/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,41 @@
#![no_std]
#![no_main]

#[cfg(feature = "unstable")] // unused in stable build
use core::cell::RefCell;

#[cfg(feature = "unstable")] // unused in stable build
use critical_section::Mutex;
#[cfg(feature = "unstable")]
use embassy_time::{Duration, Timer};
use esp_hal::gpio::{AnyPin, Input, Level, Output, Pin, Pull};
#[cfg(feature = "unstable")]
use esp_hal::{
// OutputOpenDrain is here because will be unused otherwise
delay::Delay,
gpio::{AnyPin, Input, Level, Output, OutputOpenDrain, Pin, Pull},
gpio::{Event, Flex, Io, OutputOpenDrain},
handler,
};
#[cfg(feature = "unstable")]
use esp_hal::{
gpio::{Event, Flex, Io},
interrupt::InterruptConfigurable,
timer::timg::TimerGroup,
};
use hil_test as _;
#[cfg(feature = "unstable")]
use portable_atomic::{AtomicUsize, Ordering};

#[cfg(feature = "unstable")] // unused in stable build
static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0));
#[cfg(feature = "unstable")] // unused in stable build
static INPUT_PIN: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));

struct Context {
test_gpio1: AnyPin,
test_gpio2: AnyPin,
#[cfg(feature = "unstable")]
delay: Delay,
}

#[handler]
#[cfg_attr(feature = "unstable", handler)]
#[cfg(feature = "unstable")]
pub fn interrupt_handler() {
critical_section::with(|cs| {
*COUNTER.borrow_ref_mut(cs) += 1;
Expand All @@ -56,6 +61,7 @@ mod tests {
fn init() -> Context {
let peripherals = esp_hal::init(esp_hal::Config::default());

#[cfg(feature = "unstable")]
let delay = Delay::new();

let (gpio1, gpio2) = hil_test::common_test_pins!(peripherals);
Expand All @@ -74,6 +80,7 @@ mod tests {
Context {
test_gpio1: gpio1.degrade(),
test_gpio2: gpio2.degrade(),
#[cfg(feature = "unstable")]
delay,
}
}
Expand Down Expand Up @@ -244,6 +251,7 @@ mod tests {
}

#[test]
#[cfg(feature = "unstable")] // delay is unstable
fn gpio_od(ctx: Context) {
let mut test_gpio1 = OutputOpenDrain::new(ctx.test_gpio1, Level::High, Pull::Up);
let mut test_gpio2 = OutputOpenDrain::new(ctx.test_gpio2, Level::High, Pull::Up);
Expand Down

0 comments on commit 07aa760

Please sign in to comment.