Skip to content

Commit d2fd284

Browse files
committed
pass complementary pins
1 parent bb41956 commit d2fd284

File tree

3 files changed

+52
-57
lines changed

3 files changed

+52
-57
lines changed

src/gpio/alt.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -766,22 +766,7 @@ pin! {
766766
<serial::RxPin, USART6> for [PA12<8>]
767767
}
768768

769-
#[cfg(any(
770-
feature = "stm32f405",
771-
feature = "stm32f407",
772-
feature = "stm32f412",
773-
feature = "stm32f413",
774-
feature = "stm32f415",
775-
feature = "stm32f417",
776-
feature = "stm32f423",
777-
feature = "stm32f427",
778-
feature = "stm32f429",
779-
feature = "stm32f437",
780-
feature = "stm32f439",
781-
feature = "stm32f446",
782-
feature = "stm32f469",
783-
feature = "stm32f479"
784-
))]
769+
#[cfg(feature = "gpiog")]
785770
pin! {
786771
<serial::TxPin, USART6> for [PG14<8>],
787772
<serial::RxPin, USART6> for [PG9<8>]

src/timer/pins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait EtrPin<TIM> {}
1010
pub trait BkinPin<TIM> {}
1111

1212
/// Channel wrapper
13-
pub struct Ch<const C: u8>;
13+
pub struct Ch<const C: u8, const COMP: bool>;
1414
pub const C1: u8 = 0;
1515
pub const C2: u8 = 1;
1616
pub const C3: u8 = 2;

src/timer/pwm.rs

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{compute_arr_presc, Channel, FTimer, Instance, Ocm, Timer, WithPwm};
1+
use super::{compute_arr_presc, Channel, FTimer, Instance, Ocm, Timer, WithPwm, NCPin};
22
use crate::rcc::Clocks;
33
use core::marker::PhantomData;
44
use core::ops::{Deref, DerefMut};
@@ -9,6 +9,10 @@ pub trait Pins<TIM, P> {
99
const C2: bool = false;
1010
const C3: bool = false;
1111
const C4: bool = false;
12+
const NC1: bool = false;
13+
const NC2: bool = false;
14+
const NC3: bool = false;
15+
const NC4: bool = false;
1216
type Channels;
1317

1418
fn check_used(c: Channel) -> Channel {
@@ -27,20 +31,21 @@ pub trait Pins<TIM, P> {
2731
}
2832
pub use super::{CPin, Ch, C1, C2, C3, C4};
2933

30-
pub struct PwmChannel<TIM, const C: u8> {
34+
pub struct PwmChannel<TIM, const C: u8, const COMP: bool = false> {
3135
pub(super) _tim: PhantomData<TIM>,
3236
}
3337

3438
macro_rules! pins_impl {
35-
( $( ( $($PINX:ident),+ ), ( $($ENCHX:ident),+ ); )+ ) => {
39+
( $( ( $($PINX:ident),+ ), ( $($ENCHX:ident),+ ), ( $($COMP:ident),+ ); )+ ) => {
3640
$(
3741
#[allow(unused_parens)]
38-
impl<TIM, $($PINX,)+> Pins<TIM, ($(Ch<$ENCHX>),+)> for ($($PINX),+)
42+
impl<TIM, $($PINX,)+ $(const $COMP: bool,)+> Pins<TIM, ($(Ch<$ENCHX, $COMP>),+)> for ($($PINX),+)
3943
where
4044
TIM: Instance + WithPwm,
41-
$($PINX: CPin<TIM, $ENCHX>,)+
45+
$($PINX: PwmPin<TIM, $ENCHX, $COMP>,)+
4246
{
4347
$(const $ENCHX: bool = true;)+
48+
$(const $COMP: bool = true;)+
4449
type Channels = ($(PwmChannel<TIM, $ENCHX>),+);
4550
fn split() -> Self::Channels {
4651
($(PwmChannel::<TIM, $ENCHX>::new()),+)
@@ -51,46 +56,51 @@ macro_rules! pins_impl {
5156
}
5257

5358
pins_impl!(
54-
(P1, P2, P3, P4), (C1, C2, C3, C4);
55-
(P2, P3, P4), (C2, C3, C4);
56-
(P1, P3, P4), (C1, C3, C4);
57-
(P1, P2, P4), (C1, C2, C4);
58-
(P1, P2, P3), (C1, C2, C3);
59-
(P3, P4), (C3, C4);
60-
(P2, P4), (C2, C4);
61-
(P2, P3), (C2, C3);
62-
(P1, P4), (C1, C4);
63-
(P1, P3), (C1, C3);
64-
(P1, P2), (C1, C2);
65-
(P1), (C1);
66-
(P2), (C2);
67-
(P3), (C3);
68-
(P4), (C4);
59+
(P1, P2, P3, P4), (C1, C2, C3, C4), (NC1, NC2, NC3, NC4);
60+
(P2, P3, P4), (C2, C3, C4), (NC2, NC3, NC4);
61+
(P1, P3, P4), (C1, C3, C4), (NC1, NC3, NC4);
62+
(P1, P2, P4), (C1, C2, C4), (NC1, NC2, NC4);
63+
(P1, P2, P3), (C1, C2, C3), (NC1, NC2, NC3);
64+
(P3, P4), (C3, C4), (NC3, NC4);
65+
(P2, P4), (C2, C4), (NC2, NC4);
66+
(P2, P3), (C2, C3), (NC2, NC3);
67+
(P1, P4), (C1, C4), (NC1, NC4);
68+
(P1, P3), (C1, C3), (NC1, NC3);
69+
(P1, P2), (C1, C2), (NC1, NC2);
70+
(P1), (C1), (NC1);
71+
(P2), (C2), (NC2);
72+
(P3), (C3), (NC3);
73+
(P4), (C4), (NC4);
6974
);
7075

71-
impl<TIM, P1, P2, const C: u8> CPin<TIM, C> for (P1, P2)
72-
where
73-
P1: CPin<TIM, C>,
74-
P2: CPin<TIM, C>,
75-
{
76-
}
77-
impl<TIM, P1, P2, P3, const C: u8> CPin<TIM, C> for (P1, P2, P3)
78-
where
79-
P1: CPin<TIM, C>,
80-
P2: CPin<TIM, C>,
81-
P3: CPin<TIM, C>,
82-
{
76+
macro_rules! tuples {
77+
( $( $trait:ident, ( $($PX:ident),+ ); )+ ) => {
78+
$(
79+
impl<TIM, $($PX,)+ const C: u8> $trait<TIM, C> for ($($PX),+)
80+
where
81+
$($PX: CPin<TIM, C>,)+
82+
{
83+
}
84+
)+
85+
};
8386
}
84-
impl<TIM, P1, P2, P3, P4, const C: u8> CPin<TIM, C> for (P1, P2, P3, P4)
85-
where
86-
P1: CPin<TIM, C>,
87-
P2: CPin<TIM, C>,
88-
P3: CPin<TIM, C>,
89-
P4: CPin<TIM, C>,
90-
{
87+
88+
tuples! {
89+
CPin, (P1, P2);
90+
CPin, (P1, P2, P3);
91+
CPin, (P1, P2, P3, P4);
92+
NCPin, (P1, P2);
93+
NCPin, (P1, P2, P3);
94+
NCPin, (P1, P2, P3, P4);
9195
}
9296

93-
pub trait PwmExt
97+
pub trait PwmPin<TIM, const C: u8, const COMP: bool = false> { }
98+
99+
impl<P, TIM, const C: u8> PwmPin<TIM, C> for P where P: CPin<TIM, C> { }
100+
impl<P, NP, TIM, const C: u8> PwmPin<TIM, C, true> for (P, NP) where P: CPin<TIM, C>, NP: NCPin<TIM, C> { }
101+
102+
103+
pub trait PwmExt
94104
where
95105
Self: Sized + Instance + WithPwm,
96106
{

0 commit comments

Comments
 (0)