Skip to content

Commit 9775f61

Browse files
bors[bot]burrbull
andauthored
Merge #340
340: NoPin & no Pins r=thalesfragoso a=burrbull One `NoPin` type and `NoTx`, `NoSck etc. are aliases for it. Use `(TX, RX)` directly in constructors instead of `Pins`. Better for docs: ![изображение](https://user-images.githubusercontent.com/3072754/125181418-3bc2b380-e20d-11eb-8b71-176e9f8d6d31.png) vs ![изображение](https://user-images.githubusercontent.com/3072754/125181423-4715df00-e20d-11eb-86d0-bfdcb51eec35.png) Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents 578921a + 1f98180 commit 9775f61

File tree

6 files changed

+71
-98
lines changed

6 files changed

+71
-98
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12+
- Filler `NoPin` type
1213
- Add inherent impl of `PwmPin` methods on `PwmChannel`s.
1314
- `Serial:tx` and `Serial::rx` that take only 1 pin
1415
- Instead of `Alternate<AF1>` you can just use `Alternate<1>`.

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/i2c.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,12 @@ impl private::Sealed for I2C3 {}
267267
impl Instance for I2C3 {}
268268

269269
#[cfg(feature = "fmpi2c1")]
270-
impl<PINS> FMPI2c<FMPI2C1, PINS>
270+
impl<SCL, SDA> FMPI2c<FMPI2C1, (SCL, SDA)>
271271
where
272-
PINS: Pins<FMPI2C1>,
272+
SCL: PinScl<FMPI2C1>,
273+
SDA: PinSda<FMPI2C1>,
273274
{
274-
pub fn new(i2c: FMPI2C1, pins: PINS, speed: KiloHertz) -> Self {
275+
pub fn new(i2c: FMPI2C1, pins: (SCL, SDA), speed: KiloHertz) -> Self {
275276
unsafe {
276277
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
277278
let rcc = &(*RCC::ptr());
@@ -289,12 +290,13 @@ where
289290
}
290291
}
291292

292-
impl<I2C, PINS> I2c<I2C, PINS>
293+
impl<I2C, SCL, SDA> I2c<I2C, (SCL, SDA)>
293294
where
294295
I2C: Instance,
295-
PINS: Pins<I2C>,
296+
SCL: PinScl<I2C>,
297+
SDA: PinSda<I2C>,
296298
{
297-
pub fn new(i2c: I2C, pins: PINS, speed: KiloHertz, clocks: Clocks) -> Self {
299+
pub fn new(i2c: I2C, pins: (SCL, SDA), speed: KiloHertz, clocks: Clocks) -> Self {
298300
unsafe {
299301
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
300302
let rcc = &(*RCC::ptr());

src/i2s.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,15 @@ macro_rules! i2s {
293293
}
294294
}
295295

296-
impl<PINS> I2s<$SPIX, PINS>
296+
impl<PWS, PCK, PMCLK, PSD> I2s<$SPIX, (PWS, PCK, PMCLK, PSD)>
297297
where
298-
PINS: Pins<$SPIX>,
298+
PWS: PinWs<$SPIX>,
299+
PCK: PinCk<$SPIX>,
300+
PMCLK: PinMck<$SPIX>,
301+
PSD: PinSd<$SPIX>,
299302
{
300303
#[deprecated(since = "0.10.0", note = "Please use new instead")]
301-
pub fn $i2sx(spi: $SPIX, pins: PINS, clocks: Clocks) -> Self {
304+
pub fn $i2sx(spi: $SPIX, pins: (PWS, PCK, PMCLK, PSD), clocks: Clocks) -> Self {
302305
Self::new(spi, pins, clocks)
303306
}
304307
}
@@ -309,10 +312,13 @@ macro_rules! i2s {
309312
};
310313
}
311314

312-
impl<SPI, PINS> I2s<SPI, PINS>
315+
impl<SPI, PWS, PCK, PMCLK, PSD> I2s<SPI, (PWS, PCK, PMCLK, PSD)>
313316
where
314317
SPI: I2sFreq + rcc::Enable + rcc::Reset,
315-
PINS: Pins<SPI>,
318+
PWS: PinWs<SPI>,
319+
PCK: PinCk<SPI>,
320+
PMCLK: PinMck<SPI>,
321+
PSD: PinSd<SPI>,
316322
{
317323
/// Creates an I2s object around an SPI peripheral and pins
318324
///
@@ -325,7 +331,7 @@ where
325331
///
326332
/// This function panics if the I2S clock input (from the I2S PLL or similar)
327333
/// is not configured.
328-
pub fn new(spi: SPI, pins: PINS, clocks: Clocks) -> Self {
334+
pub fn new(spi: SPI, pins: (PWS, PCK, PMCLK, PSD), clocks: Clocks) -> Self {
329335
let input_clock = SPI::i2s_freq(&clocks);
330336
unsafe {
331337
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.

src/serial.rs

Lines changed: 23 additions & 55 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> {
@@ -1275,15 +1242,16 @@ macro_rules! halUart {
12751242
}
12761243
}
12771244

1278-
impl<USART, PINS> Serial<USART, PINS>
1245+
impl<USART, TX, RX> Serial<USART, (TX, RX)>
12791246
where
1280-
PINS: Pins<USART>,
1247+
TX: PinTx<USART>,
1248+
RX: PinRx<USART>,
12811249
USART: Instance,
12821250
{
12831251
#[deprecated(since = "0.10.0")]
12841252
pub fn $usartX(
12851253
usart: USART,
1286-
pins: PINS,
1254+
pins: (TX, RX),
12871255
config: config::Config,
12881256
clocks: Clocks,
12891257
) -> Result<Self, config::InvalidConfig> {

0 commit comments

Comments
 (0)