use avr_oxide::hal::generic::port::{Pin, PinMode, InterruptMode};
use avr_oxide::util::OwnOrBorrow;
use avr_oxide::devices::UsesPin;
use avr_oxide::devices::internal::StaticShareable;
pub struct Led {
pin: OwnOrBorrow<'static,dyn Pin>
}
impl StaticShareable for Led {}
impl UsesPin for Led {
fn using<OP: Into<OwnOrBorrow<'static, dyn Pin>>>(pin: OP) -> Self {
let pin : OwnOrBorrow<dyn Pin> = pin.into();
pin.set_mode(PinMode::Output);
pin.set_interrupt_mode(InterruptMode::Disabled);
Led { pin }
}
}
impl Led {
pub fn set_on(&self) {
self.pin.set_high();
}
pub fn set_off(&self) {
self.pin.set_low();
}
pub fn set(&self, on: bool) {
match on {
true => self.set_on(),
false => self.set_off()
}
}
pub fn toggle(&self) {
self.pin.toggle()
}
}
unsafe impl Send for Led {}
unsafe impl Sync for Led {}