fix serial

This commit is contained in:
Alex Janka 2023-02-22 10:09:32 +11:00
parent 8e910cfec8
commit 788afa49d4

View file

@ -32,7 +32,8 @@ impl Default for SerialControl {
pub struct Serial {
byte: u8,
bits_transferred: u8,
output_byte: u8,
bits_remaining: u8,
control: SerialControl,
}
@ -41,11 +42,13 @@ impl Serial {
let mut will_interrupt = false;
for _ in 0..steps {
if self.control.transfer_in_progress {
let (remainder, finished) = self.bits_transferred.overflowing_sub(1);
self.bits_transferred = if finished {
self.output_byte = self.output_byte << 1 | self.byte >> 7;
self.byte = (self.byte << 1) | 0b1;
let (remainder, finished) = self.bits_remaining.overflowing_sub(1);
self.bits_remaining = if finished {
self.control.transfer_in_progress = false;
will_interrupt = true;
print!("{}", self.byte as char);
print!("{}", self.output_byte as char);
stdout().flush().unwrap();
7
} else {
@ -91,8 +94,9 @@ impl Serial {
impl Default for Serial {
fn default() -> Self {
Self {
byte: 0,
bits_transferred: 7,
byte: 0xFF,
output_byte: 0,
bits_remaining: 7,
control: SerialControl::default(),
}
}