#![no_implicit_prelude]
extern crate core;
use core::convert::{From, Into};
use core::ops::{Deref, DerefMut};
use crate::Board;
use crate::pin::gpio::Output;
use crate::pin::pwm::PwmPin;
use crate::pin::{Pin, PinID};
pub struct Led(Pin<Output>);
pub struct LedPwm(PwmPin<Output>);
impl Led {
#[inline]
pub fn get(p: &Board, i: PinID) -> Led {
Pin::get(p, i).into()
}
#[inline]
pub fn on(&self) {
self.0.high()
}
#[inline]
pub fn off(&self) {
self.0.low()
}
}
impl LedPwm {
#[inline]
pub fn get(p: &Board, i: PinID) -> LedPwm {
Pin::get(p, i).into_pwm().into()
}
#[inline]
pub fn on(&self) {
self.0.high()
}
#[inline]
pub fn off(&self) {
self.0.low()
}
#[inline]
pub fn brightness(&self, p: u8) {
self.0.set_duty((self.0.get_max_duty() / 100) * (p as u16))
}
}
impl Deref for Led {
type Target = Pin<Output>;
#[inline]
fn deref(&self) -> &Pin<Output> {
&self.0
}
}
impl DerefMut for Led {
#[inline]
fn deref_mut(&mut self) -> &mut Pin<Output> {
&mut self.0
}
}
impl From<Pin<Output>> for Led {
#[inline]
fn from(v: Pin<Output>) -> Led {
Led(v)
}
}
impl Deref for LedPwm {
type Target = PwmPin<Output>;
#[inline]
fn deref(&self) -> &PwmPin<Output> {
&self.0
}
}
impl DerefMut for LedPwm {
#[inline]
fn deref_mut(&mut self) -> &mut PwmPin<Output> {
&mut self.0
}
}
impl From<PwmPin<Output>> for LedPwm {
#[inline]
fn from(v: PwmPin<Output>) -> LedPwm {
LedPwm(v)
}
}