1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use stm32f3xx_hal::gpio::gpioe;
use stm32f3xx_hal::gpio::{Output, PushPull};
use switch_hal::{ActiveHigh, IntoSwitch, OutputSwitch, Switch};
pub struct Leds {
pub ld3: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld4: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld5: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld6: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld7: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld8: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld9: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
pub ld10: Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>,
}
impl Leds {
pub fn new<PE8Mode, PE9Mode, PE10Mode, PE11Mode, PE12Mode, PE13Mode, PE14Mode, PE15Mode>(
pe8: gpioe::PE8<PE8Mode>,
pe9: gpioe::PE9<PE9Mode>,
pe10: gpioe::PE10<PE10Mode>,
pe11: gpioe::PE11<PE11Mode>,
pe12: gpioe::PE12<PE12Mode>,
pe13: gpioe::PE13<PE13Mode>,
pe14: gpioe::PE14<PE14Mode>,
pe15: gpioe::PE15<PE15Mode>,
moder: &mut gpioe::MODER,
otyper: &mut gpioe::OTYPER,
) -> Self {
let mut leds = Leds {
ld3: pe9
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld4: pe8
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld5: pe10
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld6: pe15
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld7: pe11
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld8: pe14
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld9: pe12
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
ld10: pe13
.into_push_pull_output(moder, otyper)
.downgrade()
.into_active_high_switch(),
};
leds.ld3.off().ok();
leds.ld4.off().ok();
leds.ld5.off().ok();
leds.ld6.off().ok();
leds.ld7.off().ok();
leds.ld8.off().ok();
leds.ld9.off().ok();
leds.ld10.off().ok();
leds
}
pub fn into_array(self) -> [Switch<gpioe::PEx<Output<PushPull>>, ActiveHigh>; 8] {
[
self.ld3,
self.ld5,
self.ld7,
self.ld9,
self.ld10,
self.ld8,
self.ld6,
self.ld4,
]
}
}