jsut minor changes, UNTESTED DMA TIMER CHANGE
This commit is contained in:
@@ -115,7 +115,7 @@ pub fn decode_uart_samples(
|
||||
let frame_bits = 1 + nbits + parity_bits + stop_bits_count;
|
||||
let frame_len = frame_bits * ovs;
|
||||
|
||||
// Helper: Majority vote over 3 samples centered at `i`
|
||||
// Majority vote over 3 samples centered at `i`
|
||||
let get_bit = |i: usize| -> u8 {
|
||||
let mut votes = 0;
|
||||
// Check i-1, i, i+1. Saturating sub/add handles boundaries roughly.
|
||||
@@ -136,7 +136,7 @@ pub fn decode_uart_samples(
|
||||
}
|
||||
};
|
||||
|
||||
// We loop while we have enough remaining samples for a full frame
|
||||
// Loop while we have enough remaining samples for a full frame
|
||||
while idx + frame_len <= samples.len() {
|
||||
// Wait for falling edge (High -> Low)
|
||||
// samples[idx] == 1 (Idle/Stop) && samples[idx+1] == 0 (Start)
|
||||
@@ -146,7 +146,7 @@ pub fn decode_uart_samples(
|
||||
let center_offset = 1 + (ovs / 2);
|
||||
let mut scan_idx = idx + center_offset;
|
||||
|
||||
// 1. Validate Start Bit (Must be 0)
|
||||
// Validate Start Bit
|
||||
if get_bit(scan_idx) != 0 {
|
||||
idx += 1; // False start (noise), move on
|
||||
continue;
|
||||
@@ -155,7 +155,7 @@ pub fn decode_uart_samples(
|
||||
// Move to center of first data bit
|
||||
scan_idx += ovs;
|
||||
|
||||
// 2. Read Data Bits
|
||||
// Read Data Bits
|
||||
let mut data: u8 = 0;
|
||||
for bit in 0..nbits {
|
||||
if get_bit(scan_idx) == 1 {
|
||||
@@ -164,22 +164,22 @@ pub fn decode_uart_samples(
|
||||
scan_idx += ovs;
|
||||
}
|
||||
|
||||
// 3. Skip Parity (if any)
|
||||
// Skip Parity
|
||||
if cfg.parity != Parity::None {
|
||||
scan_idx += ovs;
|
||||
}
|
||||
|
||||
// 4. Validate Stop Bit (Must be 1)
|
||||
// Validate Stop Bit (Must be 1)
|
||||
// If stop bit is 0, it's a framing error. We reject the whole byte.
|
||||
if get_bit(scan_idx) == 0 {
|
||||
idx += 1; // Try to find a real start bit on the next sample
|
||||
idx += 1; // Next sample
|
||||
continue;
|
||||
}
|
||||
|
||||
// 5. Byte is valid
|
||||
// Byte is valid
|
||||
let _ = out.push(data);
|
||||
|
||||
// 6. Active Resync: Fast-forward through the stop bit(s) and idle time
|
||||
// Active Resync: Fast-forward through the stop bit(s) and idle time
|
||||
// scan_idx is currently at the center of the Stop bit.
|
||||
idx = scan_idx;
|
||||
// Advance while we are reading High (1).
|
||||
|
||||
Reference in New Issue
Block a user