Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend tests in gpio::check_pin_groups() #817

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions on-target-tests/tests/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ mod tests {
fn check_pin_groups() {
// Safety: Test cases do not run in parallel
let mut pac = unsafe { pac::Peripherals::steal() };
let pingroup = PinGroup::new();
let sio = hal::Sio::new(pac.SIO);
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
Expand All @@ -115,18 +114,39 @@ mod tests {
&mut pac.RESETS,
);

let pingroup = pingroup.add_pin(pins.gpio0.into_push_pull_output_in_state(PinState::Low));
let pingroup = pingroup.add_pin(pins.gpio1.into_push_pull_output_in_state(PinState::Low));
let pingroup = pingroup.add_pin(pins.gpio2.into_bus_keep_input());
let mut pingroup = pingroup.add_pin(pins.gpio3.into_bus_keep_input());
// GPIO (0 <=> 2) and (1 <=> 3) connected together
let mut group = PinGroup::new()
.add_pin(pins.gpio0.into_push_pull_output())
.add_pin(pins.gpio1.into_push_pull_output())
.add_pin(pins.gpio2.into_bus_keep_input())
.add_pin(pins.gpio3.into_bus_keep_input());

group.set(PinState::Low);
cortex_m::asm::delay(10);
assert!(pingroup.read() == 0);
pingroup.toggle();
assert_eq!(group.read(), 0b0000);
group.set(PinState::High);
cortex_m::asm::delay(10);
assert!(pingroup.read() == 0xf);
pingroup.toggle();
assert_eq!(group.read(), 0b1111);
group.set(PinState::Low);
cortex_m::asm::delay(10);
assert!(pingroup.read() == 0);
assert_eq!(group.read(), 0b0000);

group.set(PinState::Low);
group.toggle();
cortex_m::asm::delay(10);
assert_eq!(group.read(), 0b1111);
group.toggle();
cortex_m::asm::delay(10);
assert_eq!(group.read(), 0b0000);
group.toggle();
cortex_m::asm::delay(10);
assert_eq!(group.read(), 0b1111);

group.set_u32(0b0001);
cortex_m::asm::delay(10);
assert_eq!(group.read(), 0b0101);
group.set_u32(0b0010);
cortex_m::asm::delay(10);
assert_eq!(group.read(), 0b1010);
}
}
Loading