1use core::ops;
4
5use hal::prelude::*;
6
7use hal::gpio::gpioe::{self, PE10, PE11, PE12, PE13, PE14, PE15, PE8, PE9, PEx};
8use hal::gpio::{Output, PushPull};
9
10pub type LD3 = PE9<Output<PushPull>>;
12
13pub type LD5 = PE10<Output<PushPull>>;
15
16pub type LD7 = PE11<Output<PushPull>>;
18
19pub type LD9 = PE12<Output<PushPull>>;
21
22pub type LD10 = PE13<Output<PushPull>>;
24
25pub type LD8 = PE14<Output<PushPull>>;
27
28pub type LD6 = PE15<Output<PushPull>>;
30
31pub type LD4 = PE8<Output<PushPull>>;
33
34pub enum Direction {
36 North,
38 Northeast,
40 East,
42 Southeast,
44 South,
46 Southwest,
48 West,
50 Northwest,
52}
53
54pub struct Leds {
56 leds: [Led; 8],
57}
58
59impl Leds {
60 pub fn new(mut gpioe: gpioe::Parts) -> Self {
62 let n = gpioe
63 .pe9
64 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
65 let ne = gpioe
66 .pe10
67 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
68 let e = gpioe
69 .pe11
70 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
71 let se = gpioe
72 .pe12
73 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
74 let s = gpioe
75 .pe13
76 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
77 let sw = gpioe
78 .pe14
79 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
80 let w = gpioe
81 .pe15
82 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
83 let nw = gpioe
84 .pe8
85 .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
86
87 Leds {
88 leds: [
89 n.into(),
90 ne.into(),
91 e.into(),
92 se.into(),
93 s.into(),
94 sw.into(),
95 w.into(),
96 nw.into(),
97 ],
98 }
99 }
100}
101
102impl ops::Deref for Leds {
103 type Target = [Led];
104
105 fn deref(&self) -> &[Led] {
106 &self.leds
107 }
108}
109
110impl ops::DerefMut for Leds {
111 fn deref_mut(&mut self) -> &mut [Led] {
112 &mut self.leds
113 }
114}
115
116impl ops::Index<usize> for Leds {
117 type Output = Led;
118
119 fn index(&self, i: usize) -> &Led {
120 &self.leds[i]
121 }
122}
123
124impl ops::Index<Direction> for Leds {
125 type Output = Led;
126
127 fn index(&self, d: Direction) -> &Led {
128 &self.leds[d as usize]
129 }
130}
131
132impl ops::IndexMut<usize> for Leds {
133 fn index_mut(&mut self, i: usize) -> &mut Led {
134 &mut self.leds[i]
135 }
136}
137
138impl ops::IndexMut<Direction> for Leds {
139 fn index_mut(&mut self, d: Direction) -> &mut Led {
140 &mut self.leds[d as usize]
141 }
142}
143
144pub struct Led {
146 pex: PEx<Output<PushPull>>,
147}
148
149macro_rules! ctor {
150 ($($ldx:ident),+) => {
151 $(
152 impl Into<Led> for $ldx {
153 fn into(self) -> Led {
154 Led {
155 pex: self.downgrade(),
156 }
157 }
158 }
159 )+
160 }
161}
162
163ctor!(LD3, LD4, LD5, LD6, LD7, LD8, LD9, LD10);
164
165impl Led {
166 pub fn off(&mut self) {
168 self.pex.set_low()
169 }
170
171 pub fn on(&mut self) {
173 self.pex.set_high()
174 }
175}