From 6defd8963fce0a1638fbadac8229b27939aa549a Mon Sep 17 00:00:00 2001 From: doryan Date: Wed, 30 Apr 2025 18:05:09 +0400 Subject: [PATCH] feat(writer/reader): move write and read methods to SoftSerialWriter and SoftSerialReader traits + impl these traits a --- src/lib.rs | 56 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b44df18..1289fba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,21 +67,6 @@ where while P::is_low() {} } - fn write_bytes(&self, transmit_data: &[u8]) { - for byte in transmit_data { - self.write_byte(*byte); - self.sync_transmitter(); - } - } - - fn read_bytes(&self, recieve_buffer: &mut [u8]) { - for byte in recieve_buffer { - if let Ok(data) = self.read_byte() { - *byte = data; - } - self.sync_reciever(); - } - } } impl

SoftSerial

for HalfDuplexSerial

@@ -138,6 +123,11 @@ where while P::is_low() {} } + +pub trait SoftSerialWriter +where + P: PinOps + StaticPinOps, +{ #[inline(never)] fn write_byte(&self, data: u8) { let (mut data, mut parity_bit) = (data, 0); @@ -167,6 +157,25 @@ where delay_us(SERIAL_DELAY); } + fn write_bytes(&self, transmit_data: T); +} + +impl

SoftSerialWriter for HalfDuplexSerial

+where + P: PinOps + StaticPinOps, +{ + fn write_bytes(&self, transmit_data: &[u8]) { + for byte in transmit_data { + self.write_byte(*byte); + self.sync_transmitter(); + } + } +} + +pub trait SoftSerialReader +where + P: PinOps + StaticPinOps, +{ #[inline(never)] fn read_byte(&self) -> ReadByteResult { let (mut data, mut reciever_parity_bit) = (0, 0); @@ -202,4 +211,21 @@ where Ok(data) } + + fn read_bytes(&self, recieve_data: T); } + +impl

SoftSerialReader for HalfDuplexSerial

+where + P: PinOps + StaticPinOps, +{ + fn read_bytes(&self, recieve_data: &mut [u8]) { + for byte in recieve_data { + if let Ok(data) = self.read_byte() { + *byte = data; + } + self.sync_reciever(); + } + } +} +