diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-07-10 21:22:46 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-07-10 21:22:46 +0000 |
| commit | 93e7d53e393a8f79be1c4a5c0e1fd8497305fc50 (patch) | |
| tree | 11d9be878c0eb04e7b9b9e7deb766ca4489c8935 /tests | |
| parent | 5f43c1d37e9db847c7861fe0bd821db62edba9f6 (diff) | |
| parent | 323b0d1a5c430bfcec3288e229179a5b7c86038a (diff) | |
Merge #851
851: Gpio dynamic flex r=Dirbaio a=AntoineMugnier
Add Flex GPIO type for embassy-stm32 as it is the case for embassy-nrf.
Co-authored-by: [email protected] <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stm32/src/bin/gpio.rs | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index c7991953f..37cfe7cf4 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use defmt::assert; | 7 | use defmt::assert; |
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 9 | use embassy_stm32::gpio::{Flex, Input, Level, Output, OutputOpenDrain, Pull, Speed}; |
| 10 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 11 | use example_common::*; | 11 | use example_common::*; |
| 12 | 12 | ||
| @@ -88,6 +88,110 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 88 | assert!(b.is_high()); | 88 | assert!(b.is_high()); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | // Test output open drain | ||
| 92 | { | ||
| 93 | let b = Input::new(&mut b, Pull::Down); | ||
| 94 | // no pull, the status is undefined | ||
| 95 | |||
| 96 | let mut a = OutputOpenDrain::new(&mut a, Level::Low, Speed::Low, Pull::None); | ||
| 97 | delay(); | ||
| 98 | assert!(b.is_low()); | ||
| 99 | a.set_high(); // High-Z output | ||
| 100 | delay(); | ||
| 101 | assert!(b.is_low()); | ||
| 102 | } | ||
| 103 | |||
| 104 | // FLEX | ||
| 105 | // Test initial output | ||
| 106 | { | ||
| 107 | //Flex pin configured as input | ||
| 108 | let mut b = Flex::new(&mut b); | ||
| 109 | b.set_as_input(Pull::None); | ||
| 110 | |||
| 111 | { | ||
| 112 | //Flex pin configured as output | ||
| 113 | let mut a = Flex::new(&mut a); //Flex pin configured as output | ||
| 114 | a.set_low(); // Pin state must be set before configuring the pin, thus we avoid unknown state | ||
| 115 | a.set_as_output(Speed::Low); | ||
| 116 | delay(); | ||
| 117 | assert!(b.is_low()); | ||
| 118 | } | ||
| 119 | { | ||
| 120 | //Flex pin configured as output | ||
| 121 | let mut a = Flex::new(&mut a); | ||
| 122 | a.set_high(); | ||
| 123 | a.set_as_output(Speed::Low); | ||
| 124 | |||
| 125 | delay(); | ||
| 126 | assert!(b.is_high()); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | // Test input no pull | ||
| 131 | { | ||
| 132 | let mut b = Flex::new(&mut b); | ||
| 133 | b.set_as_input(Pull::None); // no pull, the status is undefined | ||
| 134 | |||
| 135 | let mut a = Flex::new(&mut a); | ||
| 136 | a.set_low(); | ||
| 137 | a.set_as_output(Speed::Low); | ||
| 138 | |||
| 139 | delay(); | ||
| 140 | assert!(b.is_low()); | ||
| 141 | a.set_high(); | ||
| 142 | delay(); | ||
| 143 | assert!(b.is_high()); | ||
| 144 | } | ||
| 145 | |||
| 146 | // Test input pulldown | ||
| 147 | { | ||
| 148 | let mut b = Flex::new(&mut b); | ||
| 149 | b.set_as_input(Pull::Down); | ||
| 150 | delay(); | ||
| 151 | assert!(b.is_low()); | ||
| 152 | |||
| 153 | let mut a = Flex::new(&mut a); | ||
| 154 | a.set_low(); | ||
| 155 | a.set_as_output(Speed::Low); | ||
| 156 | delay(); | ||
| 157 | assert!(b.is_low()); | ||
| 158 | a.set_high(); | ||
| 159 | delay(); | ||
| 160 | assert!(b.is_high()); | ||
| 161 | } | ||
| 162 | |||
| 163 | // Test input pullup | ||
| 164 | { | ||
| 165 | let mut b = Flex::new(&mut b); | ||
| 166 | b.set_as_input(Pull::Up); | ||
| 167 | delay(); | ||
| 168 | assert!(b.is_high()); | ||
| 169 | |||
| 170 | let mut a = Flex::new(&mut a); | ||
| 171 | a.set_high(); | ||
| 172 | a.set_as_output(Speed::Low); | ||
| 173 | delay(); | ||
| 174 | assert!(b.is_high()); | ||
| 175 | a.set_low(); | ||
| 176 | delay(); | ||
| 177 | assert!(b.is_low()); | ||
| 178 | } | ||
| 179 | |||
| 180 | // Test output open drain | ||
| 181 | { | ||
| 182 | let mut b = Flex::new(&mut b); | ||
| 183 | b.set_as_input(Pull::Down); | ||
| 184 | |||
| 185 | let mut a = Flex::new(&mut a); | ||
| 186 | a.set_low(); | ||
| 187 | a.set_as_input_output(Speed::Low, Pull::None); | ||
| 188 | delay(); | ||
| 189 | assert!(b.is_low()); | ||
| 190 | a.set_high(); // High-Z output | ||
| 191 | delay(); | ||
| 192 | assert!(b.is_low()); | ||
| 193 | } | ||
| 194 | |||
| 91 | info!("Test OK"); | 195 | info!("Test OK"); |
| 92 | cortex_m::asm::bkpt(); | 196 | cortex_m::asm::bkpt(); |
| 93 | } | 197 | } |
