Merge #1487
1487: rp: Implement embedded_hal::serial::Write for Uart/UartTx r=Dirbaio a=Alpha-3 Uart/UartTx currently implements `embedded_hal_02::serial::Read<u8>` and `embedded_hal_02::blocking::serial::Write<u8>` but not `embedded_hal_02::serial::Write<u8>`. This implements the missing `embedded_hal_02::serial::Write<u8>` to allow use of Uart with crates that expect this interface, such as [defmt_serial](https://docs.rs/defmt-serial/latest/defmt_serial/). Co-authored-by: Alpha3__0 <Alpha3.0gmail.com>
This commit is contained in:
commit
524a89cc72
@ -755,6 +755,32 @@ mod eh02 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, M: Mode> embedded_hal_02::serial::Write<u8> for UartTx<'d, T, M> {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, word: u8) -> Result<(), nb::Error<Self::Error>> {
|
||||
let r = T::regs();
|
||||
unsafe {
|
||||
if r.uartfr().read().txff() {
|
||||
return Err(nb::Error::WouldBlock);
|
||||
}
|
||||
|
||||
r.uartdr().write(|w| w.set_data(word));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), nb::Error<Self::Error>> {
|
||||
let r = T::regs();
|
||||
unsafe {
|
||||
if !r.uartfr().read().txfe() {
|
||||
return Err(nb::Error::WouldBlock);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, M: Mode> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T, M> {
|
||||
type Error = Error;
|
||||
|
||||
@ -775,6 +801,18 @@ mod eh02 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, M: Mode> embedded_hal_02::serial::Write<u8> for Uart<'d, T, M> {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, word: u8) -> Result<(), nb::Error<Self::Error>> {
|
||||
embedded_hal_02::serial::Write::write(&mut self.tx, word)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), nb::Error<Self::Error>> {
|
||||
embedded_hal_02::serial::Write::flush(&mut self.tx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, M: Mode> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, M> {
|
||||
type Error = Error;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user