working data catch

This commit is contained in:
Priec
2025-11-19 14:51:42 +01:00
parent 89ee552da3
commit 46486a6e74

View File

@@ -37,7 +37,7 @@ use core::cell::RefCell;
use embassy_sync::channel::Channel; use embassy_sync::channel::Channel;
static RX_PIN_GLOBAL: Mutex<RefCell<Option<&'static Input<'static>>>> = Mutex::new(RefCell::new(None)); static RX_PIN_GLOBAL: Mutex<RefCell<Option<&'static Input<'static>>>> = Mutex::new(RefCell::new(None));
static PD6_BITS: Channel<CriticalSectionRawMutex, u8, 512> = Channel::new(); static PD6_BITS: Channel<CriticalSectionRawMutex, u8, 4096> = Channel::new();
bind_interrupts!(struct Irqs { bind_interrupts!(struct Irqs {
USART1 => BufferedInterruptHandler<peripherals::USART1>; USART1 => BufferedInterruptHandler<peripherals::USART1>;
@@ -120,10 +120,14 @@ async fn main(spawner: Spawner) {
// EDN OF SOFTWARE UART // EDN OF SOFTWARE UART
unsafe { cortex_m::peripheral::NVIC::unmask(pac::Interrupt::TIM7); } unsafe { cortex_m::peripheral::NVIC::unmask(pac::Interrupt::TIM7); }
let mut last_bit: Option<u8> = None;
loop { loop {
if let Ok(bit) = PD6_BITS.try_receive() { while let Ok(bit) = PD6_BITS.try_receive() {
// only called when ISR pushed something if Some(bit) != last_bit {
info!("c"); // PD6 level changed since the last sample → print one 'c'
info!("c");
last_bit = Some(bit);
}
} }
yield_now().await; yield_now().await;
} }
@@ -133,11 +137,9 @@ async fn main(spawner: Spawner) {
fn TIM7() { fn TIM7() {
let tim = unsafe { pac::TIM7 }; let tim = unsafe { pac::TIM7 };
// acknowledge update
if tim.sr().read().uif() { if tim.sr().read().uif() {
tim.sr().modify(|w| w.set_uif(false)); tim.sr().modify(|w| w.set_uif(false));
// quick PD6 read
let bit = cortex_m::interrupt::free(|cs| { let bit = cortex_m::interrupt::free(|cs| {
RX_PIN_GLOBAL RX_PIN_GLOBAL
.borrow(cs) .borrow(cs)
@@ -145,14 +147,9 @@ fn TIM7() {
.as_ref() .as_ref()
.map(|pin| pin.is_high()) .map(|pin| pin.is_high())
.unwrap_or(false) .unwrap_or(false)
}); }) as u8;
// track state change; push if different let _ = PD6_BITS.try_send(bit);
static mut LAST: bool = false;
if bit != unsafe { LAST } {
unsafe { LAST = bit; }
let _ = PD6_BITS.try_send(bit as u8);
}
} }
} }