Skip to content

Commit 194aecc

Browse files
committed
cleanups
1 parent 0605447 commit 194aecc

File tree

4 files changed

+167
-274
lines changed

4 files changed

+167
-274
lines changed

CHANGELOG.md

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

4040
### Changed
4141

42+
- Add `Spi::new` and deprecate `Spi:spix`, deprecate `Serial::usartx`, remove deprecated `I2c::i2cx`
4243
- Deprecate `free` in favour of `release`
4344
- Clean features in `serial`
4445
- Internal implementation of GPIO Pin API changed to use Const Generics

src/i2c.rs

Lines changed: 36 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl PinScl<I2C3> for PH7<AlternateOD<4>> {}
293293
))]
294294
impl PinSda<I2C3> for PH8<AlternateOD<4>> {}
295295

296-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
296+
#[cfg(feature = "fmpi2c1")]
297297
use crate::{
298298
gpio::{
299299
gpiob::{PB13, PB14, PB15},
@@ -305,40 +305,40 @@ use crate::{
305305
pac::FMPI2C1,
306306
};
307307

308-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
308+
#[cfg(feature = "fmpi2c1")]
309309
impl PinScl<FMPI2C1> for PC6<AlternateOD<4>> {}
310310

311-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
311+
#[cfg(feature = "fmpi2c1")]
312312
impl PinSda<FMPI2C1> for PC7<AlternateOD<4>> {}
313313

314-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
314+
#[cfg(feature = "fmpi2c1")]
315315
impl PinSda<FMPI2C1> for PB3<AlternateOD<4>> {}
316316

317-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
317+
#[cfg(feature = "fmpi2c1")]
318318
impl PinScl<FMPI2C1> for PB10<AlternateOD<9>> {}
319319

320-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
320+
#[cfg(feature = "fmpi2c1")]
321321
impl PinSda<FMPI2C1> for PB14<AlternateOD<4>> {}
322322

323-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
323+
#[cfg(feature = "fmpi2c1")]
324324
impl PinScl<FMPI2C1> for PB15<AlternateOD<4>> {}
325325

326-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
326+
#[cfg(feature = "fmpi2c1")]
327327
impl PinScl<FMPI2C1> for PD12<AlternateOD<4>> {}
328328

329-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
329+
#[cfg(feature = "fmpi2c1")]
330330
impl PinScl<FMPI2C1> for PB13<AlternateOD<4>> {}
331331

332-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
332+
#[cfg(feature = "fmpi2c1")]
333333
impl PinScl<FMPI2C1> for PD14<AlternateOD<4>> {}
334334

335-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
335+
#[cfg(feature = "fmpi2c1")]
336336
impl PinScl<FMPI2C1> for PD15<AlternateOD<4>> {}
337337

338-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
338+
#[cfg(feature = "fmpi2c1")]
339339
impl PinScl<FMPI2C1> for PF14<AlternateOD<4>> {}
340340

341-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
341+
#[cfg(feature = "fmpi2c1")]
342342
impl PinScl<FMPI2C1> for PF15<AlternateOD<4>> {}
343343

344344
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
@@ -359,52 +359,22 @@ mod private {
359359

360360
pub trait Instance: private::Sealed + Deref<Target = i2c1::RegisterBlock> + Enable + Reset {}
361361

362-
// Implemented by all I2C instances
363-
macro_rules! i2c {
364-
($(
365-
$I2C:ident: ($i2c:ident, $apbXenr:ident, $en_bit:expr, $apbxrstr:ident, $reset_bit:expr),
366-
)+) => {
367-
$(
368-
impl private::Sealed for $I2C {}
369-
impl Instance for $I2C {}
370-
371-
impl<PINS> I2c<$I2C, PINS>
372-
where
373-
PINS: Pins<$I2C>,
374-
{
375-
#[deprecated(
376-
since = "0.9.0",
377-
note = "Please use new instead"
378-
)]
379-
pub fn $i2c(
380-
i2c: $I2C,
381-
pins: PINS,
382-
speed: KiloHertz,
383-
clocks: Clocks,
384-
) -> Self {
385-
Self::new(i2c, pins, speed, clocks)
386-
}
387-
}
388-
)+
389-
}
390-
}
391-
392-
i2c! {
393-
I2C1: (i2c1, apb1enr, 21, apb1rstr, 21),
394-
I2C2: (i2c2, apb1enr, 22, apb1rstr, 22),
395-
}
362+
impl private::Sealed for I2C1 {}
363+
impl Instance for I2C1 {}
364+
impl private::Sealed for I2C2 {}
365+
impl Instance for I2C2 {}
396366

397367
#[cfg(feature = "i2c3")]
398-
i2c! {
399-
I2C3: (i2c3, apb1enr, 23, apb1rstr, 23),
400-
}
368+
impl private::Sealed for I2C3 {}
369+
#[cfg(feature = "i2c3")]
370+
impl Instance for I2C3 {}
401371

402372
#[cfg(feature = "fmpi2c1")]
403-
impl<PINS> FMPI2c<FMPI2C1, PINS> {
404-
pub fn fmpi2c(i2c: FMPI2C1, pins: PINS, speed: KiloHertz) -> Self
405-
where
406-
PINS: Pins<FMPI2C1>,
407-
{
373+
impl<PINS> FMPI2c<FMPI2C1, PINS>
374+
where
375+
PINS: Pins<FMPI2C1>,
376+
{
377+
pub fn new(i2c: FMPI2C1, pins: PINS, speed: KiloHertz) -> Self {
408378
unsafe {
409379
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
410380
let rcc = &(*RCC::ptr());
@@ -425,11 +395,9 @@ impl<PINS> FMPI2c<FMPI2C1, PINS> {
425395
impl<I2C, PINS> I2c<I2C, PINS>
426396
where
427397
I2C: Instance,
398+
PINS: Pins<I2C>,
428399
{
429-
pub fn new(i2c: I2C, pins: PINS, speed: KiloHertz, clocks: Clocks) -> Self
430-
where
431-
PINS: Pins<I2C>,
432-
{
400+
pub fn new(i2c: I2C, pins: PINS, speed: KiloHertz, clocks: Clocks) -> Self {
433401
unsafe {
434402
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
435403
let rcc = &(*RCC::ptr());
@@ -443,7 +411,12 @@ where
443411
i2c.i2c_init(speed, clocks.pclk1());
444412
i2c
445413
}
414+
}
446415

416+
impl<I2C, PINS> I2c<I2C, PINS>
417+
where
418+
I2C: Instance,
419+
{
447420
fn i2c_init(&self, speed: KiloHertz, pclk: Hertz) {
448421
let speed: Hertz = speed.into();
449422

@@ -735,7 +708,7 @@ where
735708
}
736709
}
737710

738-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
711+
#[cfg(feature = "fmpi2c1")]
739712
impl<I2C, PINS> FMPI2c<I2C, PINS>
740713
where
741714
I2C: Deref<Target = fmpi2c1::RegisterBlock>,
@@ -839,7 +812,7 @@ where
839812
}
840813
}
841814

842-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
815+
#[cfg(feature = "fmpi2c1")]
843816
impl<I2C, PINS> WriteRead for FMPI2c<I2C, PINS>
844817
where
845818
I2C: Deref<Target = fmpi2c1::RegisterBlock>,
@@ -909,7 +882,7 @@ where
909882
}
910883
}
911884

912-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
885+
#[cfg(feature = "fmpi2c1")]
913886
impl<I2C, PINS> Read for FMPI2c<I2C, PINS>
914887
where
915888
I2C: Deref<Target = fmpi2c1::RegisterBlock>,
@@ -945,7 +918,7 @@ where
945918
}
946919
}
947920

948-
#[cfg(any(feature = "stm32f413", feature = "stm32f423",))]
921+
#[cfg(feature = "fmpi2c1")]
949922
impl<I2C, PINS> Write for FMPI2c<I2C, PINS>
950923
where
951924
I2C: Deref<Target = fmpi2c1::RegisterBlock>,

0 commit comments

Comments
 (0)