rktk_drivers_nrf/split/
uart_full_duplex.rs1use embassy_nrf::buffered_uarte::BufferedUarte;
2use embedded_io_async::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 uarte: BufferedUarte<'static>,
15}
16
17impl UartFullDuplexSplitDriver {
18 pub fn new(uarte: BufferedUarte<'static>) -> Self {
19 Self { uarte }
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 .uarte
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.uarte
37 .write_all(buf)
38 .await
39 .map_err(|_| UartFullDuplexSplitDriverError::GeneralError("Write error"))
40 }
41}