diff options
| author | Dion Dokter <[email protected]> | 2025-11-22 00:37:19 +0100 |
|---|---|---|
| committer | Dion Dokter <[email protected]> | 2025-11-22 00:37:19 +0100 |
| commit | 1479fbbee76b52e04bf658244fc535e462e17637 (patch) | |
| tree | db3f79c3c3516b28253a1f2c966eca1c9e6a2f07 /embassy-stm32/src | |
| parent | c972b81a737e43e5580a76d6538caa625a39f829 (diff) | |
Restructure build script and pin traits a little bit
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/lcd.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/embassy-stm32/src/lcd.rs b/embassy-stm32/src/lcd.rs index 3a890e529..66a9386b7 100644 --- a/embassy-stm32/src/lcd.rs +++ b/embassy-stm32/src/lcd.rs | |||
| @@ -168,6 +168,12 @@ impl<'d, T: Instance> Lcd<'d, T> { | |||
| 168 | AfType::output(crate::gpio::OutputType::PushPull, crate::gpio::Speed::VeryHigh), | 168 | AfType::output(crate::gpio::OutputType::PushPull, crate::gpio::Speed::VeryHigh), |
| 169 | ); | 169 | ); |
| 170 | 170 | ||
| 171 | assert_eq!( | ||
| 172 | pins.iter().filter(|pin| !pin.is_seg).count(), | ||
| 173 | config.duty.num_com_pins() as usize, | ||
| 174 | "The number of provided COM pins is not the same as the duty configures" | ||
| 175 | ); | ||
| 176 | |||
| 171 | // Set the pins | 177 | // Set the pins |
| 172 | for pin in pins { | 178 | for pin in pins { |
| 173 | pin.pin.set_as_af( | 179 | pin.pin.set_as_af( |
| @@ -375,23 +381,31 @@ impl<'d, T: Instance> Drop for Lcd<'d, T> { | |||
| 375 | pub struct LcdPin<'d, T: Instance> { | 381 | pub struct LcdPin<'d, T: Instance> { |
| 376 | pin: Peri<'d, AnyPin>, | 382 | pin: Peri<'d, AnyPin>, |
| 377 | af_num: u8, | 383 | af_num: u8, |
| 384 | is_seg: bool, | ||
| 378 | _phantom: PhantomData<T>, | 385 | _phantom: PhantomData<T>, |
| 379 | } | 386 | } |
| 380 | 387 | ||
| 381 | impl<'d, T: Instance, Pin: SegComPin<T>> From<Peri<'d, Pin>> for LcdPin<'d, T> { | 388 | impl<'d, T: Instance> LcdPin<'d, T> { |
| 382 | fn from(value: Peri<'d, Pin>) -> Self { | 389 | /// Construct an LCD pin from any pin that supports it |
| 383 | Self::new(value) | 390 | pub fn new_seg(pin: Peri<'d, impl SegPin<T>>) -> Self { |
| 391 | let af = pin.af_num(); | ||
| 392 | |||
| 393 | Self { | ||
| 394 | pin: pin.into(), | ||
| 395 | af_num: af, | ||
| 396 | is_seg: true, | ||
| 397 | _phantom: PhantomData, | ||
| 398 | } | ||
| 384 | } | 399 | } |
| 385 | } | ||
| 386 | 400 | ||
| 387 | impl<'d, T: Instance> LcdPin<'d, T> { | ||
| 388 | /// Construct an LCD pin from any pin that supports it | 401 | /// Construct an LCD pin from any pin that supports it |
| 389 | pub fn new(pin: Peri<'d, impl SegComPin<T>>) -> Self { | 402 | pub fn new_com(pin: Peri<'d, impl ComPin<T>>) -> Self { |
| 390 | let af = pin.af_num(); | 403 | let af = pin.af_num(); |
| 391 | 404 | ||
| 392 | Self { | 405 | Self { |
| 393 | pin: pin.into(), | 406 | pin: pin.into(), |
| 394 | af_num: af, | 407 | af_num: af, |
| 408 | is_seg: false, | ||
| 395 | _phantom: PhantomData, | 409 | _phantom: PhantomData, |
| 396 | } | 410 | } |
| 397 | } | 411 | } |
| @@ -405,13 +419,10 @@ trait SealedInstance: crate::rcc::SealedRccPeripheral + PeripheralType { | |||
| 405 | #[allow(private_bounds)] | 419 | #[allow(private_bounds)] |
| 406 | pub trait Instance: SealedInstance + RccPeripheral + 'static {} | 420 | pub trait Instance: SealedInstance + RccPeripheral + 'static {} |
| 407 | 421 | ||
| 408 | pin_trait!(SegComPin, Instance); | 422 | pin_trait!(SegPin, Instance); |
| 423 | pin_trait!(ComPin, Instance); | ||
| 409 | pin_trait!(VlcdPin, Instance); | 424 | pin_trait!(VlcdPin, Instance); |
| 410 | 425 | ||
| 411 | // TODO: pull into build.rs, but the metapack doesn't have this info | ||
| 412 | pin_trait_impl!(crate::lcd::VlcdPin, LCD, PC3, 11); | ||
| 413 | pin_trait_impl!(crate::lcd::VlcdPin, LCD, PB2, 11); | ||
| 414 | |||
| 415 | foreach_peripheral!( | 426 | foreach_peripheral!( |
| 416 | (lcd, $inst:ident) => { | 427 | (lcd, $inst:ident) => { |
| 417 | impl crate::lcd::SealedInstance for peripherals::$inst { | 428 | impl crate::lcd::SealedInstance for peripherals::$inst { |
