larger GPIO refactoring and Async UART update
This commit is contained in:
@ -6,10 +6,7 @@
|
||||
#![no_std]
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use embedded_hal::{
|
||||
delay::DelayNs,
|
||||
digital::{InputPin, OutputPin, StatefulOutputPin},
|
||||
};
|
||||
use embedded_hal::delay::DelayNs;
|
||||
use panic_rtt_target as _;
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use va108xx_hal::{
|
||||
@ -67,35 +64,35 @@ fn main() -> ! {
|
||||
TestCase::TestBasic => {
|
||||
// Tie PORTA[0] to PORTA[1] for these tests!
|
||||
let mut out = pinsa.pa0.into_readable_push_pull_output();
|
||||
let mut input = pinsa.pa1.into_floating_input();
|
||||
out.set_high().unwrap();
|
||||
assert!(input.is_high().unwrap());
|
||||
out.set_low().unwrap();
|
||||
assert!(input.is_low().unwrap());
|
||||
let input = pinsa.pa1.into_floating_input();
|
||||
out.set_high();
|
||||
assert!(input.is_high());
|
||||
out.set_low();
|
||||
assert!(input.is_low());
|
||||
}
|
||||
TestCase::TestPullup => {
|
||||
// Tie PORTA[0] to PORTA[1] for these tests!
|
||||
let mut input = pinsa.pa1.into_pull_up_input();
|
||||
assert!(input.is_high().unwrap());
|
||||
let input = pinsa.pa1.into_pull_up_input();
|
||||
assert!(input.is_high());
|
||||
let mut out = pinsa.pa0.into_readable_push_pull_output();
|
||||
out.set_low().unwrap();
|
||||
assert!(input.is_low().unwrap());
|
||||
out.set_high().unwrap();
|
||||
assert!(input.is_high().unwrap());
|
||||
out.set_low();
|
||||
assert!(input.is_low());
|
||||
out.set_high();
|
||||
assert!(input.is_high());
|
||||
out.into_floating_input();
|
||||
assert!(input.is_high().unwrap());
|
||||
assert!(input.is_high());
|
||||
}
|
||||
TestCase::TestPulldown => {
|
||||
// Tie PORTA[0] to PORTA[1] for these tests!
|
||||
let mut input = pinsa.pa1.into_pull_down_input();
|
||||
assert!(input.is_low().unwrap());
|
||||
let input = pinsa.pa1.into_pull_down_input();
|
||||
assert!(input.is_low());
|
||||
let mut out = pinsa.pa0.into_push_pull_output();
|
||||
out.set_low().unwrap();
|
||||
assert!(input.is_low().unwrap());
|
||||
out.set_high().unwrap();
|
||||
assert!(input.is_high().unwrap());
|
||||
out.set_low();
|
||||
assert!(input.is_low());
|
||||
out.set_high();
|
||||
assert!(input.is_high());
|
||||
out.into_floating_input();
|
||||
assert!(input.is_low().unwrap());
|
||||
assert!(input.is_low());
|
||||
}
|
||||
TestCase::TestMask => {
|
||||
// Tie PORTA[0] to PORTA[1] for these tests!
|
||||
@ -110,11 +107,11 @@ fn main() -> ! {
|
||||
TestCase::PortB => {
|
||||
// Tie PORTB[22] to PORTB[23] for these tests!
|
||||
let mut out = pinsb.pb22.into_readable_push_pull_output();
|
||||
let mut input = pinsb.pb23.into_floating_input();
|
||||
out.set_high().unwrap();
|
||||
assert!(input.is_high().unwrap());
|
||||
out.set_low().unwrap();
|
||||
assert!(input.is_low().unwrap());
|
||||
let input = pinsb.pb23.into_floating_input();
|
||||
out.set_high();
|
||||
assert!(input.is_high());
|
||||
out.set_low();
|
||||
assert!(input.is_low());
|
||||
}
|
||||
TestCase::Perid => {
|
||||
assert_eq!(PinsA::get_perid(), 0x004007e1);
|
||||
@ -124,15 +121,15 @@ fn main() -> ! {
|
||||
let mut output_pulsed = pinsa.pa0.into_push_pull_output();
|
||||
output_pulsed.configure_pulse_mode(true, PinState::Low);
|
||||
rprintln!("Pulsing high 10 times..");
|
||||
output_pulsed.set_low().unwrap();
|
||||
output_pulsed.set_low();
|
||||
for _ in 0..10 {
|
||||
output_pulsed.set_high().unwrap();
|
||||
output_pulsed.set_high();
|
||||
cortex_m::asm::delay(25_000_000);
|
||||
}
|
||||
output_pulsed.configure_pulse_mode(true, PinState::High);
|
||||
rprintln!("Pulsing low 10 times..");
|
||||
for _ in 0..10 {
|
||||
output_pulsed.set_low().unwrap();
|
||||
output_pulsed.set_low();
|
||||
cortex_m::asm::delay(25_000_000);
|
||||
}
|
||||
}
|
||||
@ -144,9 +141,9 @@ fn main() -> ! {
|
||||
let mut out_2 = pinsa.pa3.into_readable_push_pull_output();
|
||||
out_2.configure_delay(true, true);
|
||||
for _ in 0..20 {
|
||||
out_0.toggle().unwrap();
|
||||
out_1.toggle().unwrap();
|
||||
out_2.toggle().unwrap();
|
||||
out_0.toggle();
|
||||
out_1.toggle();
|
||||
out_2.toggle();
|
||||
cortex_m::asm::delay(25_000_000);
|
||||
}
|
||||
}
|
||||
@ -159,18 +156,18 @@ fn main() -> ! {
|
||||
dp.tim0,
|
||||
);
|
||||
for _ in 0..5 {
|
||||
led1.toggle().ok();
|
||||
led1.toggle();
|
||||
ms_timer.delay_ms(500);
|
||||
led1.toggle().ok();
|
||||
led1.toggle();
|
||||
ms_timer.delay_ms(500);
|
||||
}
|
||||
|
||||
let mut delay_timer = CountdownTimer::new(&mut dp.sysconfig, 50.MHz(), dp.tim1);
|
||||
let mut pa0 = pinsa.pa0.into_readable_push_pull_output();
|
||||
for _ in 0..5 {
|
||||
led1.toggle().ok();
|
||||
led1.toggle();
|
||||
delay_timer.delay_ms(500);
|
||||
led1.toggle().ok();
|
||||
led1.toggle();
|
||||
delay_timer.delay_ms(500);
|
||||
}
|
||||
let ahb_freq: Hertz = 50.MHz();
|
||||
@ -178,13 +175,13 @@ fn main() -> ! {
|
||||
// Test usecond delay using both TIM peripheral and SYST. Use the release image if you
|
||||
// want to verify the timings!
|
||||
loop {
|
||||
pa0.toggle().ok();
|
||||
pa0.toggle();
|
||||
delay_timer.delay_us(50);
|
||||
pa0.toggle().ok();
|
||||
pa0.toggle();
|
||||
delay_timer.delay_us(50);
|
||||
pa0.toggle_with_toggle_reg();
|
||||
pa0.toggle();
|
||||
syst_delay.delay_us(50);
|
||||
pa0.toggle_with_toggle_reg();
|
||||
pa0.toggle();
|
||||
syst_delay.delay_us(50);
|
||||
}
|
||||
}
|
||||
@ -192,7 +189,7 @@ fn main() -> ! {
|
||||
|
||||
rprintln!("Test success");
|
||||
loop {
|
||||
led1.toggle().ok();
|
||||
led1.toggle();
|
||||
cortex_m::asm::delay(25_000_000);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user