stm32f1xx_hal/gpio/
erased.rs1use super::*;
2
3pub type AnyPin<MODE> = ErasedPin<MODE>;
4
5macro_rules! impl_pxx {
6 ($(($port_id:literal :: $pin:ident)),*) => {
7 pub enum ErasedPin<MODE> {
11 $(
12 $pin(PartiallyErasedPin<$port_id, MODE>)
13 ),*
14 }
15
16 impl<MODE> PinExt for ErasedPin<MODE> {
17 type Mode = MODE;
18
19 #[inline(always)]
20 fn pin_id(&self) -> u8 {
21 match self {
22 $(Self::$pin(pin) => pin.pin_id()),*
23 }
24 }
25
26 #[inline(always)]
27 fn port_id(&self) -> u8 {
28 match self {
29 $(Self::$pin(pin) => pin.port_id()),*
30 }
31 }
32 }
33
34 impl<MODE> ErasedPin<Output<MODE>> {
35 pub fn set_high(&mut self) {
36 match self {
37 $(Self::$pin(pin) => pin.set_high()),*
38 }
39 }
40
41 pub fn set_low(&mut self) {
42 match self {
43 $(Self::$pin(pin) => pin.set_low()),*
44 }
45 }
46
47 pub fn is_set_high(&self) -> bool {
48 match self {
49 $(Self::$pin(pin) => pin.is_set_high()),*
50 }
51 }
52
53 pub fn is_set_low(&self) -> bool {
54 match self {
55 $(Self::$pin(pin) => pin.is_set_low()),*
56 }
57 }
58 }
59
60 impl<MODE> ErasedPin<Input<MODE>> {
61 pub fn is_high(&self) -> bool {
62 match self {
63 $(Self::$pin(pin) => pin.is_high()),*
64 }
65 }
66
67 pub fn is_low(&self) -> bool {
68 match self {
69 $(Self::$pin(pin) => pin.is_low()),*
70 }
71 }
72 }
73
74 impl ErasedPin<Output<OpenDrain>> {
75 pub fn is_high(&self) -> bool {
76 match self {
77 $(Self::$pin(pin) => pin.is_high()),*
78 }
79 }
80
81 pub fn is_low(&self) -> bool {
82 match self {
83 $(Self::$pin(pin) => pin.is_low()),*
84 }
85 }
86 }
87 }
88}
89
90impl<MODE> ErasedPin<Output<MODE>> {
91 #[inline(always)]
92 pub fn get_state(&self) -> PinState {
93 if self.is_set_low() {
94 PinState::Low
95 } else {
96 PinState::High
97 }
98 }
99
100 #[inline(always)]
101 pub fn set_state(&mut self, state: PinState) {
102 match state {
103 PinState::Low => self.set_low(),
104 PinState::High => self.set_high(),
105 }
106 }
107
108 #[inline(always)]
109 pub fn toggle(&mut self) {
110 if self.is_set_low() {
111 self.set_high()
112 } else {
113 self.set_low()
114 }
115 }
116}
117
118#[cfg(not(any(feature = "xl", feature = "high")))]
119impl_pxx! {
120 ('A'::PAx),
121 ('B'::PBx),
122 ('C'::PCx),
123 ('D'::PDx),
124 ('E'::PEx)
125}
126
127#[cfg(any(feature = "xl", feature = "high"))]
128impl_pxx! {
129 ('A'::PAx),
130 ('B'::PBx),
131 ('C'::PCx),
132 ('D'::PDx),
133 ('E'::PEx),
134 ('F'::PFx),
135 ('G'::PGx)
136}