use avr_oxide::hal::generic::port::{Pin, PinMode, InterruptMode};
use avr_oxide::util::OwnOrBorrowMut;
use avr_oxide::devices::UsesPin;
use avr_oxide::devices::internal::StaticShareable;
pub struct Led<P>
where
P: 'static + Pin
{
pin: OwnOrBorrowMut<'static,P>
}
impl<P> StaticShareable for Led<P>
where
P: 'static + Pin
{}
impl<P> UsesPin<P> for Led<P>
where
P: Pin
{
fn using<OP: Into<OwnOrBorrowMut<'static, P>>>(pin: OP) -> Self {
let pin : OwnOrBorrowMut<P> = pin.into();
pin.set_mode(PinMode::Output);
pin.set_interrupt_mode(InterruptMode::Disabled);
Led { pin }
}
}
impl<P> Led<P>
where
P: Pin
{
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()
}
}