msrt-uart 0.1.0

UART adapters for MSRT.
Documentation
  • Coverage
  • 100%
    29 out of 29 items documented0 out of 0 items with examples
  • Size
  • Source code size: 24.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.19 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • atlas-orien/msrt-adapters
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • atlas-orien

msrt-uart

UART adapters for MSRT.

This crate has two sides:

  • TokioUartFrontend<T> for the host/frontend side
  • UartBackend<T> for MCU/no-std passive backend side

The frontend requires Tokio and is enabled by default. The backend can be built without default features for MCU firmware.

Host Frontend

use msrt_uart::{TokioUartFrontend, UartFrontendEvent};

# async fn run<T>(io: T) -> msrt_uart::TokioResult<()>
# where
#     T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin,
# {
let mut frontend = TokioUartFrontend::new(io);
frontend.connect()?;
frontend.send(b"hello")?;

loop {
    match frontend.tick().await? {
        UartFrontendEvent::Message(message) => {
            println!("{:?}", message.as_bytes());
        }
        UartFrontendEvent::SendFailed(_) | UartFrontendEvent::TransportUnavailable => {
            frontend.disconnect();
            frontend.connect()?;
        }
        UartFrontendEvent::Idle => {}
    }
}
# }

MCU Backend

Build without Tokio/std:

cargo build -p msrt-uart --no-default-features --target thumbv7em-none-eabihf

Implement UartIo for your UART driver:

use msrt_uart::{UartBackend, UartIo, UartIoError, UartIoResult};

struct BoardUart;

impl UartIo for BoardUart {
    type Error = ();

    fn read(&mut self, buf: &mut [u8]) -> UartIoResult<usize, Self::Error> {
        let _ = buf;
        Err(UartIoError::WouldBlock)
    }

    fn write_all(&mut self, bytes: &[u8]) -> UartIoResult<(), Self::Error> {
        let _ = bytes;
        Ok(())
    }
}

let mut backend = UartBackend::new(BoardUart);
let now_ms = 0;
let _event = backend.tick(now_ms);