rktk_drivers_rp/split/
uart_full_duplex.rs1use embassy_rp::uart::BufferedUart;
2use embedded_io_async::{Read as _, Write as _};
3use rktk::drivers::interface::split::SplitDriver;
4
5#[derive(Debug)]
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7pub enum UartFullDuplexSplitDriverError {
8 GeneralError(&'static str),
9}
10
11impl rktk::drivers::interface::Error for UartFullDuplexSplitDriverError {}
12
13pub struct UartFullDuplexSplitDriver {
14 uart: BufferedUart,
15}
16
17impl UartFullDuplexSplitDriver {
18 pub fn new(uart: BufferedUart) -> Self {
19 Self { uart }
20 }
21}
22
23impl SplitDriver for UartFullDuplexSplitDriver {
24 type Error = UartFullDuplexSplitDriverError;
25
26 async fn recv(&mut self, buf: &mut [u8], _is_master: bool) -> Result<usize, Self::Error> {
27 let size = self
28 .uart
29 .read(buf)
30 .await
31 .map_err(|_| UartFullDuplexSplitDriverError::GeneralError("Read error"))?;
32 Ok(size)
33 }
34
35 async fn send_all(&mut self, buf: &[u8], _is_master: bool) -> Result<(), Self::Error> {
36 self.uart
37 .write_all(buf)
38 .await
39 .map_err(|_| UartFullDuplexSplitDriverError::GeneralError("Write error"))
40 }
41}