pub const MASTER_CLOCK_HZ: u32 = 20_000_000; pub const MAIN_CLOCK_PRESCALER: u8 = 6; pub const MASTER_TICK_PERIOD_CS: u16 = 5;
pub trait HardwareEventSource {
type Event : Clone;
fn enable_events(&mut self);
fn disable_events(&mut self);
fn wait_for_event(&mut self) -> Option<Self::Event>;
}
pub struct Supervisor<'s,H>
where
H: HardwareEventSource
{
hardware: &'s mut H
}
impl<'s,H> Supervisor<'s,H>
where
H: HardwareEventSource
{
pub fn for_hardware(hardware: &'s mut H) -> Self {
Self {
hardware
}
}
pub fn run<F: FnMut(H::Event)>(&mut self, mut handler: F) -> ! {
self.hardware.enable_events();
loop {
match self.hardware.wait_for_event() {
Some(event) => handler(event),
None => {}
}
}
}
}