sel4_bcm2835_aux_uart_driver/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//
#![no_std]
use core::convert::Infallible;
use embedded_hal_nb::nb;
use embedded_hal_nb::serial;
// use sel4_driver_interfaces::HandleInterrupt;
mod device;
use device::Device;
pub struct Driver {
device: Device,
}
unsafe impl Send for Driver {}
unsafe impl Sync for Driver {}
impl Driver {
#[allow(clippy::missing_safety_doc)]
pub const unsafe fn new_uninit(ptr: *mut ()) -> Self {
Self {
device: Device::new(ptr.cast()),
}
}
#[allow(clippy::missing_safety_doc)]
pub unsafe fn new(ptr: *mut ()) -> Self {
let mut this = Self::new_uninit(ptr);
this.init();
this
}
pub fn init(&mut self) {
self.device.init();
}
}
impl serial::ErrorType for Driver {
type Error = Infallible;
}
// TODO
// impl serial::Read for Driver {
// fn read(&mut self) -> nb::Result<u8, Self::Error> {
// self.device.get_char().ok_or(nb::Error::WouldBlock)
// }
// }
impl serial::Write for Driver {
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
self.device.put_char(word);
Ok(())
}
fn flush(&mut self) -> nb::Result<(), Self::Error> {
Ok(())
}
}
// TODO
// impl HandleInterrupt for Driver {
// fn handle_interrupt(&mut self) {
// self.device.clear_all_interrupts()
// }
// }