fix serial
This commit is contained in:
parent
8e910cfec8
commit
788afa49d4
|
@ -32,7 +32,8 @@ impl Default for SerialControl {
|
||||||
|
|
||||||
pub struct Serial {
|
pub struct Serial {
|
||||||
byte: u8,
|
byte: u8,
|
||||||
bits_transferred: u8,
|
output_byte: u8,
|
||||||
|
bits_remaining: u8,
|
||||||
control: SerialControl,
|
control: SerialControl,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +42,13 @@ impl Serial {
|
||||||
let mut will_interrupt = false;
|
let mut will_interrupt = false;
|
||||||
for _ in 0..steps {
|
for _ in 0..steps {
|
||||||
if self.control.transfer_in_progress {
|
if self.control.transfer_in_progress {
|
||||||
let (remainder, finished) = self.bits_transferred.overflowing_sub(1);
|
self.output_byte = self.output_byte << 1 | self.byte >> 7;
|
||||||
self.bits_transferred = if finished {
|
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;
|
self.control.transfer_in_progress = false;
|
||||||
will_interrupt = true;
|
will_interrupt = true;
|
||||||
print!("{}", self.byte as char);
|
print!("{}", self.output_byte as char);
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
7
|
7
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,8 +94,9 @@ impl Serial {
|
||||||
impl Default for Serial {
|
impl Default for Serial {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
byte: 0,
|
byte: 0xFF,
|
||||||
bits_transferred: 7,
|
output_byte: 0,
|
||||||
|
bits_remaining: 7,
|
||||||
control: SerialControl::default(),
|
control: SerialControl::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue