aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/tsc
diff options
context:
space:
mode:
authorKarun <[email protected]>2024-04-19 18:43:00 -0400
committerKarun <[email protected]>2024-05-02 17:17:39 -0400
commitfd69247d702d01a8e3c976a48bba4e44422d2cae (patch)
tree25b914b2e3901e217cb4033ab893fbb75317e509 /embassy-stm32/src/tsc
parentaf357d2ad08c82b35811bb603eae4e3fa3df87a0 (diff)
hyperspecific constructor
Diffstat (limited to 'embassy-stm32/src/tsc')
-rw-r--r--embassy-stm32/src/tsc/mod.rs139
1 files changed, 119 insertions, 20 deletions
diff --git a/embassy-stm32/src/tsc/mod.rs b/embassy-stm32/src/tsc/mod.rs
index 8da0e87ab..301d6f900 100644
--- a/embassy-stm32/src/tsc/mod.rs
+++ b/embassy-stm32/src/tsc/mod.rs
@@ -5,7 +5,7 @@
5/// Enums defined for peripheral parameters 5/// Enums defined for peripheral parameters
6pub mod enums; 6pub mod enums;
7 7
8use crate::gpio::AnyPin; 8use crate::gpio::{low_level::AFType, AnyPin, Pull};
9use crate::{pac::tsc::Tsc as Regs, rcc::RccPeripheral}; 9use crate::{pac::tsc::Tsc as Regs, rcc::RccPeripheral};
10use crate::{peripherals, Peripheral}; 10use crate::{peripherals, Peripheral};
11use embassy_hal_internal::{into_ref, PeripheralRef}; 11use embassy_hal_internal::{into_ref, PeripheralRef};
@@ -186,22 +186,21 @@ impl<'d, T: Instance> Tsc<'d, T> {
186 pub fn new( 186 pub fn new(
187 peri: impl Peripheral<P = T> + 'd, 187 peri: impl Peripheral<P = T> + 'd,
188 // g1_d1: Option<PeriPin<impl Peripheral<P = impl G1IO1Pin<T>> + 'd>>, 188 // g1_d1: Option<PeriPin<impl Peripheral<P = impl G1IO1Pin<T>> + 'd>>,
189 // g1_d2: Option<PeriPin<impl Peripheral<P = impl G1IO2Pin<T>> + 'd>>, 189 g1_d2: Option<PeriPin<impl Peripheral<P = impl G1IO2Pin<T>> + 'd>>,
190 // g1_d3: Option<PeriPin<impl Peripheral<P = impl G1IO3Pin<T>> + 'd>>, 190 g1_d3: Option<PeriPin<impl Peripheral<P = impl G1IO3Pin<T>> + 'd>>,
191 // g1_d4: Option<PeriPin<impl Peripheral<P = impl G1IO4Pin<T>> + 'd>>, 191 // g1_d4: Option<PeriPin<impl Peripheral<P = impl G1IO4Pin<T>> + 'd>>,
192 192
193 // g2_d1: Option<impl Peripheral<P = impl G2IO1Pin<T>> + 'd>, 193 // g2_d1: Option<impl Peripheral<P = impl G2IO1Pin<T>> + 'd>,
194 // g2_d2: Option<impl Peripheral<P = impl G2IO2Pin<T>> + 'd>, 194 // g2_d2: Option<impl Peripheral<P = impl G2IO2Pin<T>> + 'd>,
195 // g2_d3: Option<impl Peripheral<P = impl G2IO3Pin<T>> + 'd>, 195 g2_d3: Option<PeriPin<impl Peripheral<P = impl G2IO3Pin<T>> + 'd>>,
196 // g2_d4: Option<impl Peripheral<P = impl G2IO4Pin<T>> + 'd>, 196 g2_d4: Option<PeriPin<impl Peripheral<P = impl G2IO4Pin<T>> + 'd>>,
197 197
198 // g3_d1: Option<impl Peripheral<P = impl G3IO1Pin<T>> + 'd>, 198 // g3_d1: Option<impl Peripheral<P = impl G3IO1Pin<T>> + 'd>,
199 // g3_d2: Option<impl Peripheral<P = impl G3IO2Pin<T>> + 'd>, 199 // g3_d2: Option<impl Peripheral<P = impl G3IO2Pin<T>> + 'd>,
200 // g3_d3: Option<impl Peripheral<P = impl G3IO3Pin<T>> + 'd>, 200 // g3_d3: Option<impl Peripheral<P = impl G3IO3Pin<T>> + 'd>,
201 // g3_d4: Option<impl Peripheral<P = impl G3IO4Pin<T>> + 'd>, 201 // g3_d4: Option<impl Peripheral<P = impl G3IO4Pin<T>> + 'd>,
202 202 g4_d1: Option<PeriPin<impl Peripheral<P = impl G4IO1Pin<T>> + 'd>>,
203 // g4_d1: Option<impl Peripheral<P = impl G4IO1Pin<T>> + 'd>, 203 g4_d2: Option<PeriPin<impl Peripheral<P = impl G4IO2Pin<T>> + 'd>>,
204 // g4_d2: Option<impl Peripheral<P = impl G4IO2Pin<T>> + 'd>,
205 // g4_d3: Option<impl Peripheral<P = impl G4IO3Pin<T>> + 'd>, 204 // g4_d3: Option<impl Peripheral<P = impl G4IO3Pin<T>> + 'd>,
206 // g4_d4: Option<impl Peripheral<P = impl G4IO4Pin<T>> + 'd>, 205 // g4_d4: Option<impl Peripheral<P = impl G4IO4Pin<T>> + 'd>,
207 206
@@ -226,13 +225,102 @@ impl<'d, T: Instance> Tsc<'d, T> {
226 // g8_d4: Option<impl Peripheral<P = impl G8IO4Pin<T>> + 'd>, 225 // g8_d4: Option<impl Peripheral<P = impl G8IO4Pin<T>> + 'd>,
227 config: Config, 226 config: Config,
228 ) -> Self { 227 ) -> Self {
229 into_ref!(peri); 228 let g1_d2 = g1_d2.unwrap();
229 let g1_d2_pin = g1_d2.pin;
230 let g1_d3 = g1_d3.unwrap();
231 let g1_d3_pin = g1_d3.pin;
232 let g2_d3 = g2_d3.unwrap();
233 let g2_d3_pin = g2_d3.pin;
234 let g2_d4 = g2_d4.unwrap();
235 let g2_d4_pin = g2_d4.pin;
236 let g4_d1 = g4_d1.unwrap();
237 let g4_d1_pin = g4_d1.pin;
238 let g4_d2 = g4_d2.unwrap();
239 let g4_d2_pin = g4_d2.pin;
240 into_ref!(peri, g1_d2_pin, g1_d3_pin, g2_d3_pin, g2_d4_pin, g4_d1_pin, g4_d2_pin);
241
242 // Configure pins
243 match g1_d2.role {
244 PinType::Channel => g1_d2_pin.set_as_af_pull(g1_d2_pin.af_num(), AFType::OutputPushPull, Pull::None),
245 PinType::Sample => g1_d2_pin.set_as_af_pull(g1_d2_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
246 PinType::Shield => g1_d2_pin.set_as_af_pull(g1_d2_pin.af_num(), AFType::OutputPushPull, Pull::None),
247 }
248 match g1_d3.role {
249 PinType::Channel => g1_d3_pin.set_as_af_pull(g1_d3_pin.af_num(), AFType::OutputPushPull, Pull::None),
250 PinType::Sample => g1_d3_pin.set_as_af_pull(g1_d3_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
251 PinType::Shield => g1_d3_pin.set_as_af_pull(g1_d3_pin.af_num(), AFType::OutputPushPull, Pull::None),
252 }
253 let g1 = PinGroup {
254 d1: None,
255 d2: Some(TscPin {
256 pin: g1_d2_pin.map_into(),
257 role: g1_d2.role,
258 }),
259 d3: Some(TscPin {
260 pin: g1_d3_pin.map_into(),
261 role: g1_d3.role,
262 }),
263 d4: None,
264 };
265
266 match g2_d3.role {
267 PinType::Channel => g2_d3_pin.set_as_af_pull(g2_d3_pin.af_num(), AFType::OutputPushPull, Pull::None),
268 PinType::Sample => g2_d3_pin.set_as_af_pull(g2_d3_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
269 PinType::Shield => g2_d3_pin.set_as_af_pull(g2_d3_pin.af_num(), AFType::OutputPushPull, Pull::None),
270 }
271 match g2_d4.role {
272 PinType::Channel => g2_d4_pin.set_as_af_pull(g2_d4_pin.af_num(), AFType::OutputPushPull, Pull::None),
273 PinType::Sample => g2_d4_pin.set_as_af_pull(g2_d4_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
274 PinType::Shield => g2_d4_pin.set_as_af_pull(g2_d4_pin.af_num(), AFType::OutputPushPull, Pull::None),
275 }
276 let g2 = PinGroup {
277 d1: None,
278 d2: None,
279 d3: Some(TscPin {
280 pin: g2_d3_pin.map_into(),
281 role: g2_d3.role,
282 }),
283 d4: Some(TscPin {
284 pin: g2_d4_pin.map_into(),
285 role: g2_d4.role,
286 }),
287 };
288
289 match g4_d1.role {
290 PinType::Channel => g4_d1_pin.set_as_af_pull(g4_d1_pin.af_num(), AFType::OutputPushPull, Pull::None),
291 PinType::Sample => g4_d1_pin.set_as_af_pull(g4_d1_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
292 PinType::Shield => g4_d1_pin.set_as_af_pull(g4_d1_pin.af_num(), AFType::OutputPushPull, Pull::None),
293 }
294 match g4_d2.role {
295 PinType::Channel => g4_d2_pin.set_as_af_pull(g4_d2_pin.af_num(), AFType::OutputPushPull, Pull::None),
296 PinType::Sample => g4_d2_pin.set_as_af_pull(g4_d2_pin.af_num(), AFType::OutputOpenDrain, Pull::None),
297 PinType::Shield => g4_d2_pin.set_as_af_pull(g4_d2_pin.af_num(), AFType::OutputPushPull, Pull::None),
298 }
299 let g4 = PinGroup {
300 d1: Some(TscPin {
301 pin: g4_d1_pin.map_into(),
302 role: g4_d1.role,
303 }),
304 d2: Some(TscPin {
305 pin: g4_d2_pin.map_into(),
306 role: g4_d2.role,
307 }),
308 d3: None,
309 d4: None,
310 };
230 311
231 // Need to check valid pin configuration input 312 // Need to check valid pin configuration input
232 // Need to configure pin 313 Self::new_inner(peri, Some(g1), Some(g2), None, Some(g4), None, None, None, None, config)
233 Self::new_inner(peri, config)
234 } 314 }
235 315
316 // fn configure_pin<'b, G: Pin>(pin: PeripheralRef<'b, G>, role: PinType) {
317 // match role {
318 // PinType::Channel => pin.set_as_af_pull(pin.af_num(), AFType::OutputPushPull, Pull::None),
319 // PinType::Sample => {}
320 // PinType::Shield => {}
321 // }
322 // }
323
236 // fn filter_group() -> Option<PinGroup<'d>> {} 324 // fn filter_group() -> Option<PinGroup<'d>> {}
237 fn extract_groups(io_mask: u32) -> u32 { 325 fn extract_groups(io_mask: u32) -> u32 {
238 let mut groups: u32 = 0; 326 let mut groups: u32 = 0;
@@ -244,7 +332,18 @@ impl<'d, T: Instance> Tsc<'d, T> {
244 groups 332 groups
245 } 333 }
246 334
247 fn new_inner(peri: impl Peripheral<P = T> + 'd, config: Config) -> Self { 335 fn new_inner(
336 peri: impl Peripheral<P = T> + 'd,
337 g1: Option<PinGroup<'d, AnyPin>>,
338 g2: Option<PinGroup<'d, AnyPin>>,
339 g3: Option<PinGroup<'d, AnyPin>>,
340 g4: Option<PinGroup<'d, AnyPin>>,
341 g5: Option<PinGroup<'d, AnyPin>>,
342 g6: Option<PinGroup<'d, AnyPin>>,
343 g7: Option<PinGroup<'d, AnyPin>>,
344 g8: Option<PinGroup<'d, AnyPin>>,
345 config: Config,
346 ) -> Self {
248 into_ref!(peri); 347 into_ref!(peri);
249 348
250 T::enable_and_reset(); 349 T::enable_and_reset();
@@ -306,14 +405,14 @@ impl<'d, T: Instance> Tsc<'d, T> {
306 405
307 Self { 406 Self {
308 _peri: peri, 407 _peri: peri,
309 g1: None, 408 g1,
310 g2: None, 409 g2,
311 g3: None, 410 g3,
312 g4: None, 411 g4,
313 g5: None, 412 g5,
314 g6: None, 413 g6,
315 g7: None, 414 g7,
316 g8: None, 415 g8,
317 state: State::Ready, 416 state: State::Ready,
318 config, 417 config,
319 } 418 }