sel4_bcm2835_aux_uart_driver/
lib.rs

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