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

73
2sem_sem2/src/send.rs Normal file
View File

@@ -0,0 +1,73 @@
// src/send.rs
use core::sync::atomic::{AtomicBool, Ordering};
use defmt::info;
use embassy_stm32::gpio::Output;
use embassy_sync::{
blocking_mutex::raw::CriticalSectionRawMutex,
channel::{Receiver, Sender},
};
use embassy_time::{Duration, Ticker};
use heapless::Vec;
static SEND_ALLOWED: AtomicBool = AtomicBool::new(true);
pub fn encode(word: &str, v: &mut Vec<u8, 38, u8>) {
v.clear();
for byte in word.bytes() {
for bit in 0..8 {
let bit_value = (byte >> (7 - bit)) & 1;
if v.push(bit_value).is_err() {
info!("we panick boyz");
return;
}
}
}
}
pub async fn nrz(
enkodovany: &Vec<u8, 38, u8>,
sender: &Sender<'_, CriticalSectionRawMutex, u8, 64>,
) {
if !SEND_ALLOWED.load(Ordering::Relaxed) {
return;
}
let sync_hod: u8 = 0xAA;
let start_bits: u8 = 0xAB;
let sequence = [sync_hod, start_bits];
for byte in sequence {
for i in (0..8).rev() {
sender.send((byte >> i) & 1).await;
}
}
for &bit in enkodovany {
sender.send(bit).await;
}
for i in (0..8).rev() {
sender.send((sync_hod >> i) & 1).await;
}
// idle
sender.send(1).await;
}
#[embassy_executor::task]
pub async fn bit_send(
mut pin: Output<'static>,
receiver: Receiver<'static, CriticalSectionRawMutex, u8, 64>,
) {
let mut ticker = Ticker::every(Duration::from_millis(10));
loop {
let bit = receiver.receive().await;
if bit == 1 {
pin.set_high();
} else {
pin.set_low();
}
// bitrate
ticker.next().await;
}
}