Skip to content

Commit 2e8a7d6

Browse files
authored
Extend tests in gpio::check_pin_groups() (rp-rs#817)
* Extend tests in `gpio::check_pin_groups()` Replaced the uses of `assert!(x == y)` with `assert_eq!()`, so it was more clear which pin was wrong when tests failed. Also added checks for `group.set(...)`, `group.set_u32(...)`, on top of the existing `group.toggle()` Switch hex numbers to binary to make it easier to read the bits Signed-off-by: hfly0 <[email protected]> * Format files --------- Signed-off-by: hfly0 <[email protected]>
1 parent fc72c25 commit 2e8a7d6

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

on-target-tests/tests/gpio.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mod tests {
106106
fn check_pin_groups() {
107107
// Safety: Test cases do not run in parallel
108108
let mut pac = unsafe { pac::Peripherals::steal() };
109-
let pingroup = PinGroup::new();
110109
let sio = hal::Sio::new(pac.SIO);
111110
let pins = hal::gpio::Pins::new(
112111
pac.IO_BANK0,
@@ -115,18 +114,39 @@ mod tests {
115114
&mut pac.RESETS,
116115
);
117116

118-
let pingroup = pingroup.add_pin(pins.gpio0.into_push_pull_output_in_state(PinState::Low));
119-
let pingroup = pingroup.add_pin(pins.gpio1.into_push_pull_output_in_state(PinState::Low));
120-
let pingroup = pingroup.add_pin(pins.gpio2.into_bus_keep_input());
121-
let mut pingroup = pingroup.add_pin(pins.gpio3.into_bus_keep_input());
117+
// GPIO (0 <=> 2) and (1 <=> 3) connected together
118+
let mut group = PinGroup::new()
119+
.add_pin(pins.gpio0.into_push_pull_output())
120+
.add_pin(pins.gpio1.into_push_pull_output())
121+
.add_pin(pins.gpio2.into_bus_keep_input())
122+
.add_pin(pins.gpio3.into_bus_keep_input());
122123

124+
group.set(PinState::Low);
123125
cortex_m::asm::delay(10);
124-
assert!(pingroup.read() == 0);
125-
pingroup.toggle();
126+
assert_eq!(group.read(), 0b0000);
127+
group.set(PinState::High);
126128
cortex_m::asm::delay(10);
127-
assert!(pingroup.read() == 0xf);
128-
pingroup.toggle();
129+
assert_eq!(group.read(), 0b1111);
130+
group.set(PinState::Low);
129131
cortex_m::asm::delay(10);
130-
assert!(pingroup.read() == 0);
132+
assert_eq!(group.read(), 0b0000);
133+
134+
group.set(PinState::Low);
135+
group.toggle();
136+
cortex_m::asm::delay(10);
137+
assert_eq!(group.read(), 0b1111);
138+
group.toggle();
139+
cortex_m::asm::delay(10);
140+
assert_eq!(group.read(), 0b0000);
141+
group.toggle();
142+
cortex_m::asm::delay(10);
143+
assert_eq!(group.read(), 0b1111);
144+
145+
group.set_u32(0b0001);
146+
cortex_m::asm::delay(10);
147+
assert_eq!(group.read(), 0b0101);
148+
group.set_u32(0b0010);
149+
cortex_m::asm::delay(10);
150+
assert_eq!(group.read(), 0b1010);
131151
}
132152
}

0 commit comments

Comments
 (0)