From 42bbdaeb4f1b606876e1267dbec4a10827480972 Mon Sep 17 00:00:00 2001 From: Juraj Sadel Date: Mon, 19 Aug 2024 13:43:59 +0200 Subject: [PATCH] Add basic HIL test for GPIO that can be configured as pin for (#1963) --- hil-test/tests/gpio.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index 9c257ab27..d1a8350da 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -17,7 +17,7 @@ use esp_backtrace as _; use esp_hal::{ clock::ClockControl, delay::Delay, - gpio::{Gpio2, Gpio3, GpioPin, Input, Io, Level, Output, Pull}, + gpio::{any_pin::AnyPin, Gpio2, Gpio3, GpioPin, Input, Io, Level, Output, Pull}, macros::handler, peripherals::Peripherals, system::SystemControl, @@ -276,4 +276,32 @@ mod tests { assert_eq!(io2.is_low(), true); assert_eq!(io3.is_set_low(), true); } + + // Tests touch pin (GPIO2) as AnyPin and Output + // https://github.com/esp-rs/esp-hal/issues/1943 + #[test] + fn test_gpio_touch_anypin_output() { + let any_pin2 = AnyPin::new(unsafe { GpioPin::<2>::steal() }); + let any_pin3 = AnyPin::new(unsafe { GpioPin::<3>::steal() }); + + let out_pin = Output::new(any_pin2, Level::High); + let in_pin = Input::new(any_pin3, Pull::Down); + + assert_eq!(out_pin.is_set_high(), true); + assert_eq!(in_pin.is_high(), true); + } + + // Tests touch pin (GPIO2) as AnyPin and Input + // https://github.com/esp-rs/esp-hal/issues/1943 + #[test] + fn test_gpio_touch_anypin_input() { + let any_pin2 = AnyPin::new(unsafe { GpioPin::<2>::steal() }); + let any_pin3 = AnyPin::new(unsafe { GpioPin::<3>::steal() }); + + let out_pin = Output::new(any_pin3, Level::Low); + let in_pin = Input::new(any_pin2, Pull::Down); + + assert_eq!(out_pin.is_set_high(), false); + assert_eq!(in_pin.is_high(), false); + } }