1use crate::hil::gpio;
12
13pub trait Led {
18 fn init(&self);
20
21 fn on(&self);
23
24 fn off(&self);
26
27 fn toggle(&self);
29
30 fn read(&self) -> bool;
33}
34
35pub struct LedHigh<'a, P: gpio::Pin> {
37 pub pin: &'a P,
38}
39
40pub struct LedLow<'a, P: gpio::Pin> {
42 pub pin: &'a P,
43}
44
45impl<'a, P: gpio::Pin> LedHigh<'a, P> {
46 pub fn new(p: &'a P) -> Self {
47 Self { pin: p }
48 }
49}
50
51impl<'a, P: gpio::Pin> LedLow<'a, P> {
52 pub fn new(p: &'a P) -> Self {
53 Self { pin: p }
54 }
55}
56
57impl<P: gpio::Pin> Led for LedHigh<'_, P> {
58 fn init(&self) {
59 self.pin.make_output();
60 }
61
62 fn on(&self) {
63 self.pin.set();
64 }
65
66 fn off(&self) {
67 self.pin.clear();
68 }
69
70 fn toggle(&self) {
71 self.pin.toggle();
72 }
73
74 fn read(&self) -> bool {
75 self.pin.read()
76 }
77}
78
79impl<P: gpio::Pin> Led for LedLow<'_, P> {
80 fn init(&self) {
81 self.pin.make_output();
82 }
83
84 fn on(&self) {
85 self.pin.clear();
86 }
87
88 fn off(&self) {
89 self.pin.set();
90 }
91
92 fn toggle(&self) {
93 self.pin.toggle();
94 }
95
96 fn read(&self) -> bool {
97 !self.pin.read()
98 }
99}