nrz and nrzi are working right now
This commit is contained in:
@@ -7,6 +7,8 @@ use embassy_sync::{
|
||||
};
|
||||
use embassy_time::{Duration, Ticker};
|
||||
|
||||
use crate::Encoding;
|
||||
|
||||
const START: u8 = 0x7E;
|
||||
const STOP: u8 = 0x81;
|
||||
const BIT_PERIOD: Duration = Duration::from_millis(10);
|
||||
@@ -66,15 +68,37 @@ fn crc8(crc: u8, byte: u8) -> u8 {
|
||||
pub async fn bit_send(
|
||||
mut pin: Output<'static>,
|
||||
rx: Receiver<'static, CriticalSectionRawMutex, u8, 128>,
|
||||
encoding: Encoding,
|
||||
) {
|
||||
let mut ticker = Ticker::every(BIT_PERIOD);
|
||||
let mut is_high = true;
|
||||
pin.set_high();
|
||||
|
||||
loop {
|
||||
let bit = rx.receive().await;
|
||||
if bit == 1 {
|
||||
pin.set_high();
|
||||
} else {
|
||||
pin.set_low();
|
||||
}
|
||||
match encoding {
|
||||
Encoding::Nrz => {
|
||||
if bit == 1 {
|
||||
is_high = true;
|
||||
pin.set_high();
|
||||
} else {
|
||||
is_high = false;
|
||||
pin.set_low();
|
||||
}
|
||||
}
|
||||
// toggle, ak sme v 1, inac sa nedeje nic
|
||||
Encoding::Nrzi => {
|
||||
if bit == 1 {
|
||||
is_high = !is_high;
|
||||
if is_high {
|
||||
pin.set_high();
|
||||
} else {
|
||||
pin.set_low();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// bitrate
|
||||
ticker.next().await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user