Skip to content

Commit 1f98180

Browse files
committed
no Pins
1 parent 25f75f5 commit 1f98180

File tree

5 files changed

+49
-46
lines changed

5 files changed

+49
-46
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/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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,15 +1242,16 @@ macro_rules! halUart {
12421242
}
12431243
}
12441244

1245-
impl<USART, PINS> Serial<USART, PINS>
1245+
impl<USART, TX, RX> Serial<USART, (TX, RX)>
12461246
where
1247-
PINS: Pins<USART>,
1247+
TX: PinTx<USART>,
1248+
RX: PinRx<USART>,
12481249
USART: Instance,
12491250
{
12501251
#[deprecated(since = "0.10.0")]
12511252
pub fn $usartX(
12521253
usart: USART,
1253-
pins: PINS,
1254+
pins: (TX, RX),
12541255
config: config::Config,
12551256
clocks: Clocks,
12561257
) -> Result<Self, config::InvalidConfig> {

src/spi.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::pac::SPI5;
3838
#[cfg(feature = "spi6")]
3939
use crate::pac::SPI6;
4040

41-
use crate::gpio::Alternate;
41+
use crate::gpio::{Alternate, NoPin};
4242

4343
use crate::rcc::Clocks;
4444
use crate::time::Hertz;
@@ -69,11 +69,15 @@ where
6969
}
7070

7171
/// A filler type for when the SCK pin is unnecessary
72-
pub struct NoSck;
72+
pub type NoSck = NoPin;
7373
/// A filler type for when the Miso pin is unnecessary
74-
pub struct NoMiso;
74+
pub type NoMiso = NoPin;
7575
/// A filler type for when the Mosi pin is unnecessary
76-
pub struct NoMosi;
76+
pub type NoMosi = NoPin;
77+
78+
impl<SPI> PinSck<SPI> for NoPin where SPI: Instance {}
79+
impl<SPI> PinMiso<SPI> for NoPin where SPI: Instance {}
80+
impl<SPI> PinMosi<SPI> for NoPin where SPI: Instance {}
7781

7882
macro_rules! pins {
7983
($($SPIX:ty: SCK: [$($SCK:ty),*] MISO: [$($MISO:ty),*] MOSI: [$($MOSI:ty),*])+) => {
@@ -94,34 +98,28 @@ macro_rules! pins {
9498
pins! {
9599
SPI1:
96100
SCK: [
97-
NoSck,
98101
gpioa::PA5<Alternate<5>>,
99102
gpiob::PB3<Alternate<5>>
100103
]
101104
MISO: [
102-
NoMiso,
103105
gpioa::PA6<Alternate<5>>,
104106
gpiob::PB4<Alternate<5>>
105107
]
106108
MOSI: [
107-
NoMosi,
108109
gpioa::PA7<Alternate<5>>,
109110
gpiob::PB5<Alternate<5>>
110111
]
111112

112113
SPI2:
113114
SCK: [
114-
NoSck,
115115
gpiob::PB10<Alternate<5>>,
116116
gpiob::PB13<Alternate<5>>
117117
]
118118
MISO: [
119-
NoMiso,
120119
gpiob::PB14<Alternate<5>>,
121120
gpioc::PC2<Alternate<5>>
122121
]
123122
MOSI: [
124-
NoMosi,
125123
gpiob::PB15<Alternate<5>>,
126124
gpioc::PC3<Alternate<5>>
127125
]
@@ -131,17 +129,14 @@ pins! {
131129
pins! {
132130
SPI3:
133131
SCK: [
134-
NoSck,
135132
gpiob::PB3<Alternate<6>>,
136133
gpioc::PC10<Alternate<6>>
137134
]
138135
MISO: [
139-
NoMiso,
140136
gpiob::PB4<Alternate<6>>,
141137
gpioc::PC11<Alternate<6>>
142138
]
143139
MOSI: [
144-
NoMosi,
145140
gpiob::PB5<Alternate<6>>,
146141
gpioc::PC12<Alternate<6>>
147142
]
@@ -172,17 +167,14 @@ pins! {
172167
MOSI: [gpiod::PD6<Alternate<5>>]
173168
SPI4:
174169
SCK: [
175-
NoSck,
176170
gpioe::PE2<Alternate<5>>,
177171
gpioe::PE12<Alternate<5>>
178172
]
179173
MISO: [
180-
NoMiso,
181174
gpioe::PE5<Alternate<5>>,
182175
gpioe::PE13<Alternate<5>>
183176
]
184177
MOSI: [
185-
NoMosi,
186178
gpioe::PE6<Alternate<5>>,
187179
gpioe::PE14<Alternate<5>>
188180
]
@@ -232,15 +224,12 @@ pins! {
232224
pins! {
233225
SPI5:
234226
SCK: [
235-
NoSck,
236227
gpiob::PB0<Alternate<6>>
237228
]
238229
MISO: [
239-
NoMiso,
240230
gpioa::PA12<Alternate<6>>
241231
]
242232
MOSI: [
243-
NoMosi,
244233
gpioa::PA10<Alternate<6>>,
245234
gpiob::PB8<Alternate<6>>
246235
]
@@ -295,32 +284,26 @@ pins! {
295284
pins! {
296285
SPI5:
297286
SCK: [
298-
NoSck,
299287
gpiof::PF7<Alternate<5>>,
300288
gpioh::PH6<Alternate<5>>
301289
]
302290
MISO: [
303-
NoMiso,
304291
gpiof::PF8<Alternate<5>>,
305292
gpioh::PH7<Alternate<5>>
306293
]
307294
MOSI: [
308-
NoMosi,
309295
gpiof::PF9<Alternate<5>>,
310296
gpiof::PF11<Alternate<5>>
311297
]
312298

313299
SPI6:
314300
SCK: [
315-
NoSck,
316301
gpiog::PG13<Alternate<5>>
317302
]
318303
MISO: [
319-
NoMiso,
320304
gpiog::PG12<Alternate<5>>
321305
]
322306
MOSI: [
323-
NoMosi,
324307
gpiog::PG14<Alternate<5>>
325308
]
326309
}
@@ -396,12 +379,20 @@ macro_rules! spi {
396379
}
397380
}
398381

399-
impl<PINS> Spi<$SPI, PINS>
382+
impl<SCK, MISO, MOSI> Spi<$SPI, (SCK, MISO, MOSI)>
400383
where
401-
PINS: Pins<$SPI>,
384+
SCK: PinSck<$SPI>,
385+
MISO: PinMiso<$SPI>,
386+
MOSI: PinMosi<$SPI>,
402387
{
403388
#[deprecated(since = "0.10.0", note = "Please use new instead")]
404-
pub fn $spi(spi: $SPI, pins: PINS, mode: Mode, freq: Hertz, clocks: Clocks) -> Self {
389+
pub fn $spi(
390+
spi: $SPI,
391+
pins: (SCK, MISO, MOSI),
392+
mode: Mode,
393+
freq: Hertz,
394+
clocks: Clocks,
395+
) -> Self {
405396
Self::new(spi, pins, mode, freq, clocks)
406397
}
407398
}
@@ -423,12 +414,14 @@ spi! { SPI5: (spi5, pclk2) }
423414
#[cfg(feature = "spi6")]
424415
spi! { SPI6: (spi6, pclk2) }
425416

426-
impl<SPI, PINS> Spi<SPI, PINS>
417+
impl<SPI, SCK, MISO, MOSI> Spi<SPI, (SCK, MISO, MOSI)>
427418
where
428419
SPI: Instance,
429-
PINS: Pins<SPI>,
420+
SCK: PinSck<SPI>,
421+
MISO: PinMiso<SPI>,
422+
MOSI: PinMosi<SPI>,
430423
{
431-
pub fn new(spi: SPI, pins: PINS, mode: Mode, freq: Hertz, clocks: Clocks) -> Self {
424+
pub fn new(spi: SPI, pins: (SCK, MISO, MOSI), mode: Mode, freq: Hertz, clocks: Clocks) -> Self {
432425
unsafe {
433426
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
434427
let rcc = &(*RCC::ptr());

0 commit comments

Comments
 (0)