split the codebase

This commit is contained in:
Priec
2026-05-17 16:26:33 +02:00
parent 34b10426c2
commit 5399983dfb
6 changed files with 184 additions and 127 deletions

71
2sem_sem2/src/receive.rs Normal file
View File

@@ -0,0 +1,71 @@
use defmt::info;
use embassy_stm32::exti::ExtiInput;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Receiver};
use embassy_time::Timer;
#[embassy_executor::task]
pub async fn bit_receive_and_decode(mut pin: ExtiInput<'static>) {
loop {
pin.wait_for_falling_edge().await;
let t1 = embassy_time::Instant::now();
pin.wait_for_rising_edge().await;
let bit_time = embassy_time::Instant::now().duration_since(t1);
let _ = Timer::after(bit_time).await;
let mut message_buffer = [0u8; 8]; // sprava
let mut byte_idx = 0;
let mut frame_active = true;
while frame_active && byte_idx < message_buffer.len() {
let mut current_byte = 0u8;
for _ in 0..8 {
let bit = if pin.is_high() { 1 } else { 0 };
current_byte = (current_byte << 1) | bit;
Timer::after(bit_time).await;
}
if current_byte == 0xAA {
frame_active = false;
} else {
message_buffer[byte_idx] = current_byte;
byte_idx += 1;
}
}
if let Ok(s) = core::str::from_utf8(&message_buffer[..byte_idx]) {
info!("sprava: {}", s);
}
}
}
#[embassy_executor::task]
pub async fn bit_decode(receiver: Receiver<'static, CriticalSectionRawMutex, u8, 64>) {
let mut buffer = 0u64;
loop {
let bit = receiver.receive().await;
buffer = (buffer << 1) | (bit as u64);
// sync 0xAA + start 0xAB
if (buffer & 0xFFFF) == 0xAAAB {
info!("frame");
let mut message = [0u8; 4];
for byte in message.iter_mut() {
for _ in 0..8 {
let b = receiver.receive().await;
*byte = (*byte << 1) | b;
}
}
if let Ok(s) = core::str::from_utf8(&message) {
info!("Received: {}", s);
}
buffer = 0;
}
}
}