diff --git a/rp2040-hal/src/lib.rs b/rp2040-hal/src/lib.rs index 00be8ba..e8d96e2 100644 --- a/rp2040-hal/src/lib.rs +++ b/rp2040-hal/src/lib.rs @@ -23,5 +23,4 @@ pub mod ssi; pub mod timer; pub mod uart; pub mod usb; -pub mod serial; pub mod watchdog; diff --git a/rp2040-hal/src/serial.rs b/rp2040-hal/src/serial.rs deleted file mode 100644 index c7a3a2e..0000000 --- a/rp2040-hal/src/serial.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Implementation for the embedded_hal::serial traits for the UART. -// See [embedded-hal](https://docs.rs/embedded-hal/0.2.4/embedded_hal/serial/index.html) for more details - -use core::convert::Infallible; - -use crate::uart::{ - UARTPeripheral, - UARTDevice, - Enabled -}; - -use embedded_hal::serial::{ - Read, - Write -}; - -use nb::Error::WouldBlock; - -impl Read for UARTPeripheral { - type Error = Infallible; - - fn read(&mut self) -> nb::Result { - - let byte: &mut [u8] = &mut [0; 1]; - - if let Err(_) = self.read_raw(byte) { - Err(WouldBlock) - } - else { - Ok(byte[0]) - } - } -} - -impl Write for UARTPeripheral { - type Error = Infallible; - - fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { - if let Err(_) = self.write_raw(&[word]) { - Err(WouldBlock) - } - else { - Ok(()) - } - } - - fn flush(&mut self) -> nb::Result<(), Self::Error> { - self.transmit_flushed() - } -} diff --git a/rp2040-hal/src/uart.rs b/rp2040-hal/src/uart.rs index e161cd8..3f9f0ce 100644 --- a/rp2040-hal/src/uart.rs +++ b/rp2040-hal/src/uart.rs @@ -6,6 +6,12 @@ use core::ops::Deref; use embedded_time::rate::Baud; use embedded_time::rate::Hertz; use embedded_time::fixed_point::FixedPoint; + +use embedded_hal::serial::{ + Read, + Write +}; + use nb::Error::{ WouldBlock, Other @@ -435,3 +441,36 @@ fn set_format<'w>(w: &'w mut UART_LCR_H_Writer, data_bits: &DataBits, stop_bits: w } + +impl Read for UARTPeripheral { + type Error = Infallible; + + fn read(&mut self) -> nb::Result { + + let byte: &mut [u8] = &mut [0; 1]; + + if let Err(_) = self.read_raw(byte) { + Err(WouldBlock) + } + else { + Ok(byte[0]) + } + } +} + +impl Write for UARTPeripheral { + type Error = Infallible; + + fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { + if let Err(_) = self.write_raw(&[word]) { + Err(WouldBlock) + } + else { + Ok(()) + } + } + + fn flush(&mut self) -> nb::Result<(), Self::Error> { + self.transmit_flushed() + } +}