use crate::units::time::Microsecond;
pub trait ClockDriver: 'static {
const USE_DEFAULT_DRIVER: bool;
const CAN_PAUSE: bool = false;
fn uptime() -> Microsecond;
unsafe fn pause(_should_pause: bool) {}
fn system_time_valid() -> bool;
}
#[allow(dead_code)]
pub(crate) fn initialize_time_callbacks<T: ClockDriver>(name: &'static str) {
assert!(
std::mem::size_of::<T>() == 0,
"Clock Driver must be zero sized"
);
if T::USE_DEFAULT_DRIVER {
return;
}
let r#impl = crate::time::__private::TimeImplementation {
implementation_name: name,
uptime: || T::uptime().value(),
pause: if T::CAN_PAUSE {
Some(|should_pause: bool| unsafe { T::pause(should_pause) })
} else {
None
},
system_time_valid: T::system_time_valid,
};
unsafe { crate::time::__private::set_time_implementation(r#impl) }
}