added second pin test

This commit is contained in:
Robin Müller 2025-02-11 18:19:53 +01:00
parent 0c4b04b53e
commit 1cbadeffb9
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -8,7 +8,7 @@ use embedded_hal::digital::{InputPin, OutputPin, StatefulOutputPin};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_embassy::embassy; use va108xx_embassy::embassy;
use va108xx_hal::gpio::{handle_interrupt_for_async_gpio, InputPinAsync}; use va108xx_hal::gpio::{handle_interrupt_for_async_gpio, InputDynPinAsync, InputPinAsync, PinsB};
use va108xx_hal::{ use va108xx_hal::{
gpio::{DynPin, PinsA}, gpio::{DynPin, PinsA},
pac::{self, interrupt}, pac::{self, interrupt},
@ -41,7 +41,11 @@ pub enum GpioCmdType {
} }
// Declare a bounded channel of 3 u32s. // Declare a bounded channel of 3 u32s.
static CHANNEL: Channel<ThreadModeRawMutex, GpioCmd, 3> = Channel::new(); static CHANNEL_PA0_PA1: Channel<ThreadModeRawMutex, GpioCmd, 3> = Channel::new();
static CHANNEL_PB22_TO_PB23: Channel<ThreadModeRawMutex, GpioCmd, 3> = Channel::new();
const CHECK_PA0_TO_PA1: bool = true;
const CHECK_PB22_TO_PB23: bool = true;
#[embassy_executor::main] #[embassy_executor::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
@ -62,24 +66,52 @@ async fn main(spawner: Spawner) {
}; };
let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta); let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta);
let portb = PinsB::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.portb);
let led0 = porta.pa10.into_readable_push_pull_output(); let led0 = porta.pa10.into_readable_push_pull_output();
let out = porta.pa0.into_readable_push_pull_output(); let out_pa0 = porta.pa0.into_readable_push_pull_output();
let input = porta.pa1.into_floating_input(); let in_pa1 = porta.pa1.into_floating_input();
let mut async_input = InputPinAsync::new(input, pac::Interrupt::OC10); let out_pb22 = portb.pb22.into_readable_push_pull_output();
let out_dyn = out.downgrade(); let in_pb23 = portb.pb23.into_floating_input();
let mut led_0_dyn = led0.downgrade();
spawner.spawn(output_task(out_dyn)).unwrap(); let mut in_pa1_async = InputPinAsync::new(in_pa1, pac::Interrupt::OC10);
let out_pa0_dyn = out_pa0.downgrade();
let mut in_pb23_async = InputPinAsync::new(in_pb23, pac::Interrupt::OC10);
let out_pb22_dyn = out_pb22.downgrade();
spawner.spawn(output_task(out_pa0_dyn)).unwrap();
if CHECK_PA0_TO_PA1 {
check_pin_to_pin_async_ops(&CHANNEL_PA0_PA1, in_pa1_async);
}
if CHECK_PB22_TO_PB23 {
check_pin_to_pin_async_ops(&CHANNEL_PB22_TO_PB23, in_pb23_async);
}
rprintln!("Example done, toggling LED0");
loop {
led0.toggle().unwrap();
Timer::after(Duration::from_millis(500)).await;
}
}
async fn check_pin_to_pin_async_ops(
ch: &'static Channel<ThreadModeRawMutex, GpioCmd, 3>,
async_input: InputDynPinAsync,
) {
rprintln!( rprintln!(
"sending SetHigh command ({} ms)", "sending SetHigh command ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
CHANNEL.send(GpioCmd::new(GpioCmdType::SetHigh, 20)).await; CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::SetHigh, 20))
.await;
async_input.wait_for_high().await; async_input.wait_for_high().await;
rprintln!("Input pin is high now ({} ms)", Instant::now().as_millis()); rprintln!("Input pin is high now ({} ms)", Instant::now().as_millis());
rprintln!("sending SetLow command ({} ms)", Instant::now().as_millis()); rprintln!("sending SetLow command ({} ms)", Instant::now().as_millis());
CHANNEL.send(GpioCmd::new(GpioCmdType::SetLow, 20)).await; CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::SetLow, 20))
.await;
async_input.wait_for_low().await; async_input.wait_for_low().await;
rprintln!("Input pin is low now ({} ms)", Instant::now().as_millis()); rprintln!("Input pin is low now ({} ms)", Instant::now().as_millis());
@ -87,7 +119,7 @@ async fn main(spawner: Spawner) {
"sending RisingEdge command ({} ms)", "sending RisingEdge command ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
CHANNEL CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::RisingEdge, 20)) .send(GpioCmd::new(GpioCmdType::RisingEdge, 20))
.await; .await;
async_input.wait_for_rising_edge().await; async_input.wait_for_rising_edge().await;
@ -100,7 +132,7 @@ async fn main(spawner: Spawner) {
"sending Falling command ({} ms)", "sending Falling command ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
CHANNEL CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::FallingEdge, 20)) .send(GpioCmd::new(GpioCmdType::FallingEdge, 20))
.await; .await;
async_input.wait_for_falling_edge().await; async_input.wait_for_falling_edge().await;
@ -113,7 +145,7 @@ async fn main(spawner: Spawner) {
"sending Falling command ({} ms)", "sending Falling command ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
CHANNEL CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::FallingEdge, 20)) .send(GpioCmd::new(GpioCmdType::FallingEdge, 20))
.await; .await;
async_input.wait_for_any_edge().await; async_input.wait_for_any_edge().await;
@ -126,7 +158,7 @@ async fn main(spawner: Spawner) {
"sending Falling command ({} ms)", "sending Falling command ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
CHANNEL CHANNEL_PA0_PA1
.send(GpioCmd::new(GpioCmdType::RisingEdge, 20)) .send(GpioCmd::new(GpioCmdType::RisingEdge, 20))
.await; .await;
async_input.wait_for_any_edge().await; async_input.wait_for_any_edge().await;
@ -134,18 +166,12 @@ async fn main(spawner: Spawner) {
"input pin had a rising (any) edge ({} ms)", "input pin had a rising (any) edge ({} ms)",
Instant::now().as_millis() Instant::now().as_millis()
); );
rprintln!("Example done, toggling LED0");
loop {
led_0_dyn.toggle().unwrap();
Timer::after(Duration::from_millis(500)).await;
}
} }
#[embassy_executor::task] #[embassy_executor::task]
async fn output_task(mut out: DynPin) { async fn output_task(mut out: DynPin) {
loop { loop {
let next_cmd = CHANNEL.receive().await; let next_cmd = CHANNEL_PA0_PA1.receive().await;
Timer::after(Duration::from_millis(next_cmd.after_delay.into())).await; Timer::after(Duration::from_millis(next_cmd.after_delay.into())).await;
match next_cmd.cmd_type { match next_cmd.cmd_type {
GpioCmdType::SetHigh => { GpioCmdType::SetHigh => {