Skip to content

Commit 25f75f5

Browse files
committed
NoPin
1 parent 01e8155 commit 25f75f5

File tree

2 files changed

+22
-52
lines changed

2 files changed

+22
-52
lines changed

src/gpio.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub use partially_erased::PEPin;
1414
mod erased;
1515
pub use erased::EPin;
1616

17+
/// A filler pin type
18+
pub struct NoPin;
19+
1720
/// Extension trait to split a GPIO peripheral in independent pins and registers
1821
pub trait GpioExt {
1922
/// The parts to split the GPIO into

src/serial.rs

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::pac::UART8;
5656
#[cfg(feature = "uart9")]
5757
use crate::pac::UART9;
5858

59-
use crate::gpio::Alternate;
59+
use crate::gpio::{Alternate, NoPin};
6060
use crate::rcc::Clocks;
6161

6262
use crate::dma::traits::PeriAddress;
@@ -192,13 +192,13 @@ where
192192
}
193193

194194
/// A filler type for when the Tx pin is unnecessary
195-
pub struct NoTx;
195+
pub type NoTx = NoPin;
196196
/// A filler type for when the Rx pin is unnecessary
197-
pub struct NoRx;
197+
pub type NoRx = NoPin;
198198

199-
impl PinTx<USART1> for NoTx {}
199+
impl<USART> PinTx<USART> for NoPin where USART: Instance {}
200200

201-
impl PinRx<USART1> for NoRx {}
201+
impl<USART> PinRx<USART> for NoPin where USART: Instance {}
202202

203203
impl PinTx<USART1> for gpioa::PA9<Alternate<7>> {}
204204

@@ -224,10 +224,6 @@ impl PinTx<USART1> for gpiob::PB6<Alternate<7>> {}
224224

225225
impl PinRx<USART1> for gpiob::PB7<Alternate<7>> {}
226226

227-
impl PinTx<USART2> for NoTx {}
228-
229-
impl PinRx<USART2> for NoRx {}
230-
231227
impl PinTx<USART2> for gpioa::PA2<Alternate<7>> {}
232228

233229
impl PinRx<USART2> for gpioa::PA3<Alternate<7>> {}
@@ -270,10 +266,6 @@ impl PinTx<USART2> for gpiod::PD5<Alternate<7>> {}
270266
))]
271267
impl PinRx<USART2> for gpiod::PD6<Alternate<7>> {}
272268

273-
#[cfg(feature = "usart3")]
274-
impl PinTx<USART3> for NoTx {}
275-
#[cfg(feature = "usart3")]
276-
impl PinRx<USART3> for NoRx {}
277269
#[cfg(feature = "usart3")]
278270
impl PinTx<USART3> for gpiob::PB10<Alternate<7>> {}
279271
#[cfg(feature = "usart3")]
@@ -354,10 +346,6 @@ impl PinTx<USART3> for gpiod::PD8<Alternate<7>> {}
354346
))]
355347
impl PinRx<USART3> for gpiod::PD9<Alternate<7>> {}
356348

357-
#[cfg(feature = "uart4")]
358-
impl PinTx<UART4> for NoTx {}
359-
#[cfg(feature = "uart4")]
360-
impl PinRx<UART4> for NoRx {}
361349
#[cfg(feature = "uart4")]
362350
impl PinTx<UART4> for gpioa::PA0<Alternate<8>> {}
363351
#[cfg(feature = "uart4")]
@@ -403,10 +391,6 @@ impl PinTx<UART4> for gpiod::PD10<Alternate<8>> {}
403391
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
404392
impl PinRx<UART4> for gpioc::PC11<Alternate<8>> {}
405393

406-
#[cfg(feature = "uart5")]
407-
impl PinTx<UART5> for NoTx {}
408-
#[cfg(feature = "uart5")]
409-
impl PinRx<UART5> for NoRx {}
410394
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
411395
impl PinTx<UART5> for gpiob::PB6<Alternate<11>> {}
412396
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
@@ -428,9 +412,6 @@ impl PinTx<UART5> for gpioe::PE8<Alternate<8>> {}
428412
#[cfg(any(feature = "stm32f446"))]
429413
impl PinRx<UART5> for gpioe::PE7<Alternate<8>> {}
430414

431-
impl PinTx<USART6> for NoTx {}
432-
433-
impl PinRx<USART6> for NoRx {}
434415
#[cfg(any(
435416
feature = "stm32f401",
436417
feature = "stm32f410",
@@ -488,10 +469,6 @@ impl PinTx<USART6> for gpiog::PG14<Alternate<8>> {}
488469
))]
489470
impl PinRx<USART6> for gpiog::PG9<Alternate<8>> {}
490471

491-
#[cfg(feature = "uart7")]
492-
impl PinTx<UART7> for NoTx {}
493-
#[cfg(feature = "uart7")]
494-
impl PinRx<UART7> for NoRx {}
495472
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
496473
impl PinTx<UART7> for gpioa::PA15<Alternate<8>> {}
497474
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
@@ -509,10 +486,6 @@ impl PinTx<UART7> for gpiof::PF7<Alternate<8>> {}
509486
#[cfg(all(feature = "uart7", feature = "gpiof"))]
510487
impl PinRx<UART7> for gpiof::PF6<Alternate<8>> {}
511488

512-
#[cfg(feature = "uart8")]
513-
impl PinTx<UART8> for NoTx {}
514-
#[cfg(feature = "uart8")]
515-
impl PinRx<UART8> for NoRx {}
516489
#[cfg(all(feature = "uart8", feature = "gpioe"))]
517490
impl PinTx<UART8> for gpioe::PE1<Alternate<8>> {}
518491
#[cfg(all(feature = "uart8", feature = "gpioe"))]
@@ -522,10 +495,6 @@ impl PinTx<UART8> for gpiof::PF9<Alternate<8>> {}
522495
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
523496
impl PinRx<UART8> for gpiof::PF8<Alternate<8>> {}
524497

525-
#[cfg(feature = "uart9")]
526-
impl PinTx<UART9> for NoTx {}
527-
#[cfg(feature = "uart9")]
528-
impl PinRx<UART9> for NoRx {}
529498
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
530499
impl PinTx<UART9> for gpiod::PD15<Alternate<11>> {}
531500
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
@@ -535,10 +504,6 @@ impl PinTx<UART9> for gpiog::PG1<Alternate<11>> {}
535504
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
536505
impl PinRx<UART9> for gpiog::PG0<Alternate<11>> {}
537506

538-
#[cfg(feature = "uart10")]
539-
impl PinTx<UART10> for NoTx {}
540-
#[cfg(feature = "uart10")]
541-
impl PinRx<UART10> for NoRx {}
542507
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
543508
impl PinTx<UART10> for gpioe::PE3<Alternate<11>> {}
544509
#[cfg(any(feature = "stm32f413", feature = "stm32f423"))]
@@ -567,9 +532,10 @@ pub struct Tx<USART, WORD = u8> {
567532
_word: PhantomData<WORD>,
568533
}
569534

570-
impl<USART, PINS, WORD> Serial<USART, PINS, WORD>
535+
impl<USART, TX, RX, WORD> Serial<USART, (TX, RX), WORD>
571536
where
572-
PINS: Pins<USART>,
537+
TX: PinTx<USART>,
538+
RX: PinRx<USART>,
573539
USART: Instance,
574540
{
575541
/*
@@ -579,7 +545,7 @@ where
579545
*/
580546
pub fn new(
581547
usart: USART,
582-
pins: PINS,
548+
pins: (TX, RX),
583549
config: config::Config,
584550
clocks: Clocks,
585551
) -> Result<Self, config::InvalidConfig> {
@@ -696,9 +662,9 @@ where
696662
}
697663
}
698664

699-
impl<USART, TX, WORD> Serial<USART, (TX, NoRx), WORD>
665+
impl<USART, TX, WORD> Serial<USART, (TX, NoPin), WORD>
700666
where
701-
(TX, NoRx): Pins<USART>,
667+
TX: PinTx<USART>,
702668
USART: Instance,
703669
{
704670
pub fn tx(
@@ -707,13 +673,13 @@ where
707673
config: config::Config,
708674
clocks: Clocks,
709675
) -> Result<Tx<USART, WORD>, config::InvalidConfig> {
710-
Self::new(usart, (tx_pin, NoRx), config, clocks).map(|s| s.split().0)
676+
Self::new(usart, (tx_pin, NoPin), config, clocks).map(|s| s.split().0)
711677
}
712678
}
713679

714-
impl<USART, RX, WORD> Serial<USART, (NoTx, RX), WORD>
680+
impl<USART, RX, WORD> Serial<USART, (NoPin, RX), WORD>
715681
where
716-
(NoTx, RX): Pins<USART>,
682+
RX: PinRx<USART>,
717683
USART: Instance,
718684
{
719685
pub fn rx(
@@ -722,7 +688,7 @@ where
722688
config: config::Config,
723689
clocks: Clocks,
724690
) -> Result<Rx<USART, WORD>, config::InvalidConfig> {
725-
Self::new(usart, (NoTx, rx_pin), config, clocks).map(|s| s.split().1)
691+
Self::new(usart, (NoPin, rx_pin), config, clocks).map(|s| s.split().1)
726692
}
727693
}
728694

@@ -1220,15 +1186,16 @@ macro_rules! halUsart {
12201186
}
12211187
}
12221188

1223-
impl<USART, PINS> Serial<USART, PINS>
1189+
impl<USART, TX, RX> Serial<USART, (TX, RX)>
12241190
where
1225-
PINS: Pins<USART>,
1191+
TX: PinTx<USART>,
1192+
RX: PinRx<USART>,
12261193
USART: Instance,
12271194
{
12281195
#[deprecated(since = "0.10.0")]
12291196
pub fn $usartX(
12301197
usart: USART,
1231-
pins: PINS,
1198+
pins: (TX, RX),
12321199
config: config::Config,
12331200
clocks: Clocks,
12341201
) -> Result<Self, config::InvalidConfig> {

0 commit comments

Comments
 (0)