From f911ad25c3cb1155dc47cf9bd7de31628562c6a9 Mon Sep 17 00:00:00 2001 From: "amugniere@gmail.com" Date: Fri, 8 Jul 2022 21:59:09 +0200 Subject: [PATCH] Flex/ Test initial output test done --- tests/stm32/src/bin/gpio.rs | 92 ++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index c7991953..2692f25f 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs @@ -6,7 +6,7 @@ mod example_common; use defmt::assert; use embassy::executor::Spawner; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::gpio::{Input, Level, Output, OutputOpenDrain, Flex, Pull, Speed}; use embassy_stm32::Peripherals; use example_common::*; @@ -88,6 +88,96 @@ async fn main(_spawner: Spawner, p: Peripherals) { assert!(b.is_high()); } + // Test output open drain + { + let b = Input::new(&mut b, Pull::Down); + // no pull, the status is undefined + + let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low, Pull::None); + delay(); + assert!(b.is_low()); + a.set_high(); // High-Z output + delay(); + assert!(b.is_low()); + } + + // FLEX + // Test initial output + { + let mut b = Flex::new(&mut b); + b.set_as_input(Pull::None); + + { + let mut a = Flex::new(&mut a); + a.set_low(); + a.set_as_output(Speed::Low); + delay(); + assert!(b.is_low()); + } + { + let mut a = Flex::new(&mut a); + a.set_as_output(Speed::Low); + a.set_high(); + delay(); + assert!(b.is_high()); + } + } + /* + // Test input no pull + { + let b = Input::new(&mut b, Pull::None); + // no pull, the status is undefined + + let mut a = Output::new(&mut a, Level::Low, Speed::Low); + delay(); + assert!(b.is_low()); + a.set_high(); + delay(); + assert!(b.is_high()); + } + + // Test input pulldown + { + let b = Input::new(&mut b, Pull::Down); + delay(); + assert!(b.is_low()); + + let mut a = Output::new(&mut a, Level::Low, Speed::Low); + delay(); + assert!(b.is_low()); + a.set_high(); + delay(); + assert!(b.is_high()); + } + + // Test input pullup + { + let b = Input::new(&mut b, Pull::Up); + delay(); + assert!(b.is_high()); + + let mut a = Output::new(&mut a, Level::Low, Speed::Low); + delay(); + assert!(b.is_low()); + a.set_high(); + delay(); + assert!(b.is_high()); + } + + // Test output open drain + { + let b = Input::new(&mut b, Pull::Down); + // no pull, the status is undefined + + let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low, Pull::None); + delay(); + assert!(b.is_low()); + a.set_high(); // High-Z output + delay(); + assert!(b.is_low()); + } +*/ + info!("Test OK"); cortex_m::asm::bkpt(); }