sel4_pl031_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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

use rtcc::{DateTime, DateTimeAccess, NaiveDateTime};

mod device;

use device::Device;

pub struct Driver {
    device: Device,
}

impl Driver {
    #[allow(clippy::missing_safety_doc)]
    pub const unsafe fn new_uninit(ptr: *mut ()) -> Self {
        Self {
            device: Device::new(ptr),
        }
    }

    #[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) {}
}

impl DateTimeAccess for Driver {
    type Error = Error;

    fn datetime(&mut self) -> Result<NaiveDateTime, Self::Error> {
        Ok(DateTime::from_timestamp(self.device.get_data().into(), 0)
            .unwrap()
            .naive_utc())
    }

    fn set_datetime(&mut self, _datetime: &NaiveDateTime) -> Result<(), Self::Error> {
        Err(Error::UnsupportedOperation)
    }
}

#[derive(Debug, Clone)]
pub enum Error {
    UnsupportedOperation,
}