|
4 | 4 | pub fn init() {}
|
5 | 5 |
|
6 | 6 | use cortex_m_rt::entry;
|
7 |
| -use stm32h7xx_hal::gpio::{ |
8 |
| - erased::EPin, Floating, Input, Output, PushPull, |
9 |
| -}; |
| 7 | +use stm32h7xx_hal::gpio::{erased::EPin, Floating, Input, Output, PushPull}; |
10 | 8 | use stm32h7xx_hal::hal::digital::v2::{InputPin, OutputPin};
|
11 | 9 | use stm32h7xx_hal::{delay::Delay, pac, prelude::*};
|
12 | 10 |
|
@@ -39,155 +37,151 @@ fn main() -> ! {
|
39 | 37 | let gpiof = dp.GPIOF.split(ccdr.peripheral.GPIOF);
|
40 | 38 | let gpiog = dp.GPIOG.split(ccdr.peripheral.GPIOG);
|
41 | 39 |
|
42 |
| - let mut input_pin = gpioa.pa0.into_floating_input().erase(); |
43 |
| - |
44 |
| - let mut most_pins = [ |
45 |
| - //gpioa.pa0.into_push_pull_output().erase(), // Used as probe pin |
46 |
| - gpioa.pa1.into_push_pull_output().erase(), |
47 |
| - gpioa.pa2.into_push_pull_output().erase(), |
48 |
| - gpioa.pa3.into_push_pull_output().erase(), |
49 |
| - gpioa.pa4.into_push_pull_output().erase(), |
50 |
| - gpioa.pa5.into_push_pull_output().erase(), |
51 |
| - gpioa.pa6.into_push_pull_output().erase(), |
52 |
| - gpioa.pa7.into_push_pull_output().erase(), |
53 |
| - gpioa.pa8.into_push_pull_output().erase(), |
54 |
| - gpioa.pa9.into_push_pull_output().erase(), |
55 |
| - gpioa.pa10.into_push_pull_output().erase(), |
56 |
| - gpioa.pa11.into_push_pull_output().erase(), |
57 |
| - gpioa.pa12.into_push_pull_output().erase(), |
58 |
| - gpioa.pa13.into_push_pull_output().erase(), |
59 |
| - gpioa.pa14.into_push_pull_output().erase(), |
60 |
| - gpioa.pa15.into_push_pull_output().erase(), |
61 |
| - gpiob.pb0.into_push_pull_output().erase(), |
62 |
| - gpiob.pb1.into_push_pull_output().erase(), |
63 |
| - gpiob.pb2.into_push_pull_output().erase(), |
64 |
| - gpiob.pb3.into_push_pull_output().erase(), |
65 |
| - gpiob.pb4.into_push_pull_output().erase(), |
66 |
| - gpiob.pb5.into_push_pull_output().erase(), |
67 |
| - gpiob.pb6.into_push_pull_output().erase(), |
68 |
| - gpiob.pb7.into_push_pull_output().erase(), |
69 |
| - gpiob.pb8.into_push_pull_output().erase(), |
70 |
| - gpiob.pb9.into_push_pull_output().erase(), |
71 |
| - gpiob.pb10.into_push_pull_output().erase(), |
72 |
| - gpiob.pb11.into_push_pull_output().erase(), |
73 |
| - gpiob.pb12.into_push_pull_output().erase(), |
74 |
| - gpiob.pb13.into_push_pull_output().erase(), |
75 |
| - gpiob.pb14.into_push_pull_output().erase(), |
76 |
| - gpiob.pb15.into_push_pull_output().erase(), |
77 |
| - gpioc.pc0.into_push_pull_output().erase(), |
78 |
| - gpioc.pc1.into_push_pull_output().erase(), |
79 |
| - gpioc.pc2.into_push_pull_output().erase(), |
80 |
| - gpioc.pc3.into_push_pull_output().erase(), |
81 |
| - gpioc.pc4.into_push_pull_output().erase(), |
82 |
| - gpioc.pc5.into_push_pull_output().erase(), |
83 |
| - gpioc.pc6.into_push_pull_output().erase(), |
84 |
| - gpioc.pc7.into_push_pull_output().erase(), |
85 |
| - gpioc.pc8.into_push_pull_output().erase(), |
86 |
| - gpioc.pc9.into_push_pull_output().erase(), |
87 |
| - gpioc.pc10.into_push_pull_output().erase(), |
88 |
| - gpioc.pc11.into_push_pull_output().erase(), |
89 |
| - gpioc.pc12.into_push_pull_output().erase(), |
90 |
| - gpioc.pc13.into_push_pull_output().erase(), |
91 |
| - gpioc.pc14.into_push_pull_output().erase(), |
92 |
| - gpioc.pc15.into_push_pull_output().erase(), |
93 |
| - gpiod.pd0.into_push_pull_output().erase(), |
94 |
| - gpiod.pd1.into_push_pull_output().erase(), |
95 |
| - gpiod.pd2.into_push_pull_output().erase(), |
96 |
| - gpiod.pd3.into_push_pull_output().erase(), |
97 |
| - gpiod.pd4.into_push_pull_output().erase(), |
98 |
| - gpiod.pd5.into_push_pull_output().erase(), |
99 |
| - gpiod.pd6.into_push_pull_output().erase(), |
100 |
| - gpiod.pd7.into_push_pull_output().erase(), |
101 |
| - gpiod.pd8.into_push_pull_output().erase(), |
102 |
| - gpiod.pd9.into_push_pull_output().erase(), |
103 |
| - gpiod.pd10.into_push_pull_output().erase(), |
104 |
| - gpiod.pd11.into_push_pull_output().erase(), |
105 |
| - gpiod.pd12.into_push_pull_output().erase(), |
106 |
| - gpiod.pd13.into_push_pull_output().erase(), |
107 |
| - gpiod.pd14.into_push_pull_output().erase(), |
108 |
| - gpiod.pd15.into_push_pull_output().erase(), |
109 |
| - gpioe.pe0.into_push_pull_output().erase(), |
110 |
| - gpioe.pe1.into_push_pull_output().erase(), |
111 |
| - gpioe.pe2.into_push_pull_output().erase(), |
112 |
| - gpioe.pe3.into_push_pull_output().erase(), |
113 |
| - gpioe.pe4.into_push_pull_output().erase(), |
114 |
| - gpioe.pe5.into_push_pull_output().erase(), |
115 |
| - gpioe.pe6.into_push_pull_output().erase(), |
116 |
| - gpioe.pe7.into_push_pull_output().erase(), |
117 |
| - gpioe.pe8.into_push_pull_output().erase(), |
118 |
| - gpioe.pe9.into_push_pull_output().erase(), |
119 |
| - gpioe.pe10.into_push_pull_output().erase(), |
120 |
| - gpioe.pe11.into_push_pull_output().erase(), |
121 |
| - gpioe.pe12.into_push_pull_output().erase(), |
122 |
| - gpioe.pe13.into_push_pull_output().erase(), |
123 |
| - gpioe.pe14.into_push_pull_output().erase(), |
124 |
| - gpioe.pe15.into_push_pull_output().erase(), |
125 |
| - gpiof.pf0.into_push_pull_output().erase(), |
126 |
| - gpiof.pf1.into_push_pull_output().erase(), |
127 |
| - gpiof.pf2.into_push_pull_output().erase(), |
128 |
| - gpiof.pf3.into_push_pull_output().erase(), |
129 |
| - gpiof.pf4.into_push_pull_output().erase(), |
130 |
| - gpiof.pf5.into_push_pull_output().erase(), |
131 |
| - gpiof.pf6.into_push_pull_output().erase(), |
132 |
| - gpiof.pf7.into_push_pull_output().erase(), |
133 |
| - gpiof.pf8.into_push_pull_output().erase(), |
134 |
| - gpiof.pf9.into_push_pull_output().erase(), |
135 |
| - gpiof.pf10.into_push_pull_output().erase(), |
136 |
| - gpiof.pf11.into_push_pull_output().erase(), |
137 |
| - gpiof.pf12.into_push_pull_output().erase(), |
138 |
| - gpiof.pf13.into_push_pull_output().erase(), |
139 |
| - gpiof.pf14.into_push_pull_output().erase(), |
140 |
| - gpiof.pf15.into_push_pull_output().erase(), |
141 |
| - gpiog.pg0.into_push_pull_output().erase(), |
142 |
| - gpiog.pg1.into_push_pull_output().erase(), |
143 |
| - gpiog.pg2.into_push_pull_output().erase(), |
144 |
| - gpiog.pg3.into_push_pull_output().erase(), |
145 |
| - gpiog.pg4.into_push_pull_output().erase(), |
146 |
| - gpiog.pg5.into_push_pull_output().erase(), |
147 |
| - gpiog.pg6.into_push_pull_output().erase(), |
148 |
| - gpiog.pg7.into_push_pull_output().erase(), |
149 |
| - gpiog.pg8.into_push_pull_output().erase(), |
150 |
| - gpiog.pg9.into_push_pull_output().erase(), |
151 |
| - gpiog.pg10.into_push_pull_output().erase(), |
152 |
| - gpiog.pg11.into_push_pull_output().erase(), |
153 |
| - gpiog.pg12.into_push_pull_output().erase(), |
154 |
| - gpiog.pg13.into_push_pull_output().erase(), |
155 |
| - gpiog.pg14.into_push_pull_output().erase(), |
156 |
| - gpiog.pg15.into_push_pull_output().erase(), |
157 |
| - ]; |
158 |
| - |
159 |
| - |
160 |
| - loop { |
161 |
| - let found_index = probe_pins(&mut input_pin, &mut most_pins, &mut delay); |
162 |
| - info!("Pin: {:?}", found_index.map(|index| &most_pins[index])); |
163 |
| - delay.delay_ms(1_u16); |
164 |
| - } |
165 |
| - |
| 40 | + let mut input_pin = gpioa.pa0.into_floating_input().erase(); |
| 41 | + |
| 42 | + let mut most_pins = [ |
| 43 | + //gpioa.pa0.into_push_pull_output().erase(), // Used as probe pin |
| 44 | + gpioa.pa1.into_push_pull_output().erase(), |
| 45 | + gpioa.pa2.into_push_pull_output().erase(), |
| 46 | + gpioa.pa3.into_push_pull_output().erase(), |
| 47 | + gpioa.pa4.into_push_pull_output().erase(), |
| 48 | + gpioa.pa5.into_push_pull_output().erase(), |
| 49 | + gpioa.pa6.into_push_pull_output().erase(), |
| 50 | + gpioa.pa7.into_push_pull_output().erase(), |
| 51 | + gpioa.pa8.into_push_pull_output().erase(), |
| 52 | + gpioa.pa9.into_push_pull_output().erase(), |
| 53 | + gpioa.pa10.into_push_pull_output().erase(), |
| 54 | + gpioa.pa11.into_push_pull_output().erase(), |
| 55 | + gpioa.pa12.into_push_pull_output().erase(), |
| 56 | + gpioa.pa13.into_push_pull_output().erase(), |
| 57 | + gpioa.pa14.into_push_pull_output().erase(), |
| 58 | + gpioa.pa15.into_push_pull_output().erase(), |
| 59 | + gpiob.pb0.into_push_pull_output().erase(), |
| 60 | + gpiob.pb1.into_push_pull_output().erase(), |
| 61 | + gpiob.pb2.into_push_pull_output().erase(), |
| 62 | + gpiob.pb3.into_push_pull_output().erase(), |
| 63 | + gpiob.pb4.into_push_pull_output().erase(), |
| 64 | + gpiob.pb5.into_push_pull_output().erase(), |
| 65 | + gpiob.pb6.into_push_pull_output().erase(), |
| 66 | + gpiob.pb7.into_push_pull_output().erase(), |
| 67 | + gpiob.pb8.into_push_pull_output().erase(), |
| 68 | + gpiob.pb9.into_push_pull_output().erase(), |
| 69 | + gpiob.pb10.into_push_pull_output().erase(), |
| 70 | + gpiob.pb11.into_push_pull_output().erase(), |
| 71 | + gpiob.pb12.into_push_pull_output().erase(), |
| 72 | + gpiob.pb13.into_push_pull_output().erase(), |
| 73 | + gpiob.pb14.into_push_pull_output().erase(), |
| 74 | + gpiob.pb15.into_push_pull_output().erase(), |
| 75 | + gpioc.pc0.into_push_pull_output().erase(), |
| 76 | + gpioc.pc1.into_push_pull_output().erase(), |
| 77 | + gpioc.pc2.into_push_pull_output().erase(), |
| 78 | + gpioc.pc3.into_push_pull_output().erase(), |
| 79 | + gpioc.pc4.into_push_pull_output().erase(), |
| 80 | + gpioc.pc5.into_push_pull_output().erase(), |
| 81 | + gpioc.pc6.into_push_pull_output().erase(), |
| 82 | + gpioc.pc7.into_push_pull_output().erase(), |
| 83 | + gpioc.pc8.into_push_pull_output().erase(), |
| 84 | + gpioc.pc9.into_push_pull_output().erase(), |
| 85 | + gpioc.pc10.into_push_pull_output().erase(), |
| 86 | + gpioc.pc11.into_push_pull_output().erase(), |
| 87 | + gpioc.pc12.into_push_pull_output().erase(), |
| 88 | + gpioc.pc13.into_push_pull_output().erase(), |
| 89 | + gpioc.pc14.into_push_pull_output().erase(), |
| 90 | + gpioc.pc15.into_push_pull_output().erase(), |
| 91 | + gpiod.pd0.into_push_pull_output().erase(), |
| 92 | + gpiod.pd1.into_push_pull_output().erase(), |
| 93 | + gpiod.pd2.into_push_pull_output().erase(), |
| 94 | + gpiod.pd3.into_push_pull_output().erase(), |
| 95 | + gpiod.pd4.into_push_pull_output().erase(), |
| 96 | + gpiod.pd5.into_push_pull_output().erase(), |
| 97 | + gpiod.pd6.into_push_pull_output().erase(), |
| 98 | + gpiod.pd7.into_push_pull_output().erase(), |
| 99 | + gpiod.pd8.into_push_pull_output().erase(), |
| 100 | + gpiod.pd9.into_push_pull_output().erase(), |
| 101 | + gpiod.pd10.into_push_pull_output().erase(), |
| 102 | + gpiod.pd11.into_push_pull_output().erase(), |
| 103 | + gpiod.pd12.into_push_pull_output().erase(), |
| 104 | + gpiod.pd13.into_push_pull_output().erase(), |
| 105 | + gpiod.pd14.into_push_pull_output().erase(), |
| 106 | + gpiod.pd15.into_push_pull_output().erase(), |
| 107 | + gpioe.pe0.into_push_pull_output().erase(), |
| 108 | + gpioe.pe1.into_push_pull_output().erase(), |
| 109 | + gpioe.pe2.into_push_pull_output().erase(), |
| 110 | + gpioe.pe3.into_push_pull_output().erase(), |
| 111 | + gpioe.pe4.into_push_pull_output().erase(), |
| 112 | + gpioe.pe5.into_push_pull_output().erase(), |
| 113 | + gpioe.pe6.into_push_pull_output().erase(), |
| 114 | + gpioe.pe7.into_push_pull_output().erase(), |
| 115 | + gpioe.pe8.into_push_pull_output().erase(), |
| 116 | + gpioe.pe9.into_push_pull_output().erase(), |
| 117 | + gpioe.pe10.into_push_pull_output().erase(), |
| 118 | + gpioe.pe11.into_push_pull_output().erase(), |
| 119 | + gpioe.pe12.into_push_pull_output().erase(), |
| 120 | + gpioe.pe13.into_push_pull_output().erase(), |
| 121 | + gpioe.pe14.into_push_pull_output().erase(), |
| 122 | + gpioe.pe15.into_push_pull_output().erase(), |
| 123 | + gpiof.pf0.into_push_pull_output().erase(), |
| 124 | + gpiof.pf1.into_push_pull_output().erase(), |
| 125 | + gpiof.pf2.into_push_pull_output().erase(), |
| 126 | + gpiof.pf3.into_push_pull_output().erase(), |
| 127 | + gpiof.pf4.into_push_pull_output().erase(), |
| 128 | + gpiof.pf5.into_push_pull_output().erase(), |
| 129 | + gpiof.pf6.into_push_pull_output().erase(), |
| 130 | + gpiof.pf7.into_push_pull_output().erase(), |
| 131 | + gpiof.pf8.into_push_pull_output().erase(), |
| 132 | + gpiof.pf9.into_push_pull_output().erase(), |
| 133 | + gpiof.pf10.into_push_pull_output().erase(), |
| 134 | + gpiof.pf11.into_push_pull_output().erase(), |
| 135 | + gpiof.pf12.into_push_pull_output().erase(), |
| 136 | + gpiof.pf13.into_push_pull_output().erase(), |
| 137 | + gpiof.pf14.into_push_pull_output().erase(), |
| 138 | + gpiof.pf15.into_push_pull_output().erase(), |
| 139 | + gpiog.pg0.into_push_pull_output().erase(), |
| 140 | + gpiog.pg1.into_push_pull_output().erase(), |
| 141 | + gpiog.pg2.into_push_pull_output().erase(), |
| 142 | + gpiog.pg3.into_push_pull_output().erase(), |
| 143 | + gpiog.pg4.into_push_pull_output().erase(), |
| 144 | + gpiog.pg5.into_push_pull_output().erase(), |
| 145 | + gpiog.pg6.into_push_pull_output().erase(), |
| 146 | + gpiog.pg7.into_push_pull_output().erase(), |
| 147 | + gpiog.pg8.into_push_pull_output().erase(), |
| 148 | + gpiog.pg9.into_push_pull_output().erase(), |
| 149 | + gpiog.pg10.into_push_pull_output().erase(), |
| 150 | + gpiog.pg11.into_push_pull_output().erase(), |
| 151 | + gpiog.pg12.into_push_pull_output().erase(), |
| 152 | + gpiog.pg13.into_push_pull_output().erase(), |
| 153 | + gpiog.pg14.into_push_pull_output().erase(), |
| 154 | + gpiog.pg15.into_push_pull_output().erase(), |
| 155 | + ]; |
| 156 | + |
| 157 | + loop { |
| 158 | + let found_index = |
| 159 | + probe_pins(&mut input_pin, &mut most_pins, &mut delay); |
| 160 | + info!("Pin: {:?}", found_index.map(|index| &most_pins[index])); |
| 161 | + delay.delay_ms(1_u16); |
| 162 | + } |
166 | 163 | }
|
167 | 164 |
|
168 |
| - |
169 | 165 | fn probe_pins<'a>(
|
170 |
| - input: &mut EPin<Input<Floating>>, |
171 |
| - pins: &'a mut [EPin<Output<PushPull>>], |
172 |
| - delay: &mut Delay, |
173 |
| -) |
174 |
| - -> Option<usize> { |
175 |
| - |
176 |
| - if input.is_high().unwrap() { |
177 |
| - return None; |
178 |
| - } |
179 |
| - |
180 |
| - for (i,pin) in pins.iter_mut().enumerate() { |
181 |
| - pin.set_high().unwrap(); |
182 |
| - delay.delay_ms(1_u16); |
183 |
| - |
184 |
| - if input.is_high().unwrap() { |
185 |
| - pin.set_low().unwrap(); |
186 |
| - return Some(i); |
187 |
| - } |
188 |
| - |
189 |
| - pin.set_low().unwrap(); |
190 |
| - } |
191 |
| - |
192 |
| - None |
| 166 | + input: &mut EPin<Input<Floating>>, |
| 167 | + pins: &'a mut [EPin<Output<PushPull>>], |
| 168 | + delay: &mut Delay, |
| 169 | +) -> Option<usize> { |
| 170 | + if input.is_high().unwrap() { |
| 171 | + return None; |
| 172 | + } |
| 173 | + |
| 174 | + for (i, pin) in pins.iter_mut().enumerate() { |
| 175 | + pin.set_high().unwrap(); |
| 176 | + delay.delay_ms(1_u16); |
| 177 | + |
| 178 | + if input.is_high().unwrap() { |
| 179 | + pin.set_low().unwrap(); |
| 180 | + return Some(i); |
| 181 | + } |
| 182 | + |
| 183 | + pin.set_low().unwrap(); |
| 184 | + } |
| 185 | + |
| 186 | + None |
193 | 187 | }
|
0 commit comments