Skip to content

Commit 4891053

Browse files
committed
tim clean
1 parent e8c72e1 commit 4891053

File tree

6 files changed

+39
-207
lines changed

6 files changed

+39
-207
lines changed

CHANGELOG.md

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

4242
- Add `Spi::new` and deprecate `Spi:spix`, deprecate `Serial::usartx`, remove deprecated `I2c::i2cx`
4343
- Deprecate `free` in favour of `release`
44-
- Clean features in `serial`
44+
- Clean features in `serial`, `spi`, `i2c`, `timer`
4545
- Internal implementation of GPIO Pin API changed to use Const Generics
4646
- Update the sdio driver to match the changes in the PAC
4747
- Update README.md with current information

src/adc.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,34 +1042,10 @@ macro_rules! adc {
10421042

10431043
adc!(ADC1 => (adc1, ADC_COMMON, 8));
10441044

1045-
#[cfg(any(
1046-
feature = "stm32f405",
1047-
feature = "stm32f415",
1048-
feature = "stm32f407",
1049-
feature = "stm32f417",
1050-
feature = "stm32f427",
1051-
feature = "stm32f437",
1052-
feature = "stm32f429",
1053-
feature = "stm32f439",
1054-
feature = "stm32f446",
1055-
feature = "stm32f469",
1056-
feature = "stm32f479",
1057-
))]
1045+
#[cfg(feature = "adc2")]
10581046
adc!(ADC2 => (adc2, ADC_COMMON, 9));
10591047

1060-
#[cfg(any(
1061-
feature = "stm32f405",
1062-
feature = "stm32f415",
1063-
feature = "stm32f407",
1064-
feature = "stm32f417",
1065-
feature = "stm32f427",
1066-
feature = "stm32f437",
1067-
feature = "stm32f429",
1068-
feature = "stm32f439",
1069-
feature = "stm32f446",
1070-
feature = "stm32f469",
1071-
feature = "stm32f479",
1072-
))]
1048+
#[cfg(feature = "adc3")]
10731049
adc!(ADC3 => (adc3, ADC_COMMON, 10));
10741050

10751051
#[cfg(feature = "stm32f401")]

src/qei.rs

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,6 @@ use crate::{
55
rcc::{Enable, Reset},
66
};
77

8-
#[cfg(any(
9-
feature = "stm32f401",
10-
feature = "stm32f405",
11-
feature = "stm32f407",
12-
feature = "stm32f410",
13-
feature = "stm32f411",
14-
feature = "stm32f412",
15-
feature = "stm32f413",
16-
feature = "stm32f415",
17-
feature = "stm32f417",
18-
feature = "stm32f423",
19-
feature = "stm32f427",
20-
feature = "stm32f429",
21-
feature = "stm32f437",
22-
feature = "stm32f439",
23-
feature = "stm32f446",
24-
feature = "stm32f469",
25-
feature = "stm32f479"
26-
))]
27-
use crate::pac::{TIM1, TIM5};
28-
29-
#[cfg(any(
30-
feature = "stm32f401",
31-
feature = "stm32f405",
32-
feature = "stm32f407",
33-
feature = "stm32f411",
34-
feature = "stm32f412",
35-
feature = "stm32f413",
36-
feature = "stm32f415",
37-
feature = "stm32f417",
38-
feature = "stm32f423",
39-
feature = "stm32f427",
40-
feature = "stm32f429",
41-
feature = "stm32f437",
42-
feature = "stm32f439",
43-
feature = "stm32f446",
44-
feature = "stm32f469",
45-
feature = "stm32f479"
46-
))]
47-
use crate::pac::{TIM2, TIM3, TIM4};
48-
49-
#[cfg(any(
50-
feature = "stm32f405",
51-
feature = "stm32f407",
52-
feature = "stm32f412",
53-
feature = "stm32f413",
54-
feature = "stm32f415",
55-
feature = "stm32f417",
56-
feature = "stm32f423",
57-
feature = "stm32f427",
58-
feature = "stm32f429",
59-
feature = "stm32f437",
60-
feature = "stm32f439",
61-
feature = "stm32f446",
62-
feature = "stm32f469",
63-
feature = "stm32f479"
64-
))]
65-
use crate::pac::TIM8;
66-
678
pub trait Pins<TIM> {}
689
use crate::timer::PinC1;
6910
use crate::timer::PinC2;
@@ -130,7 +71,7 @@ pub trait Instance: sealed::Sealed {
13071
}
13172

13273
macro_rules! hal {
133-
($($TIM:ident: ($tim:ident, $bits:ident),)+) => {
74+
($($TIM:ty: ($tim:ident, $bits:ident),)+) => {
13475
$(
13576
impl sealed::Sealed for $TIM {}
13677
impl Instance for $TIM {
@@ -141,8 +82,8 @@ macro_rules! hal {
14182
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
14283
let rcc = &(*RCC::ptr());
14384
// Enable and reset clock.
144-
$TIM::enable(rcc);
145-
$TIM::reset(rcc);
85+
<$TIM>::enable(rcc);
86+
<$TIM>::reset(rcc);
14687
}
14788
}
14889

@@ -196,8 +137,8 @@ macro_rules! hal {
196137
}
197138

198139
hal! {
199-
TIM1: (tim1, u16),
200-
TIM5: (tim5, u32),
140+
crate::pac::TIM1: (tim1, u16),
141+
crate::pac::TIM5: (tim5, u32),
201142
}
202143

203144
#[cfg(any(
@@ -219,9 +160,9 @@ hal! {
219160
feature = "stm32f479"
220161
))]
221162
hal! {
222-
TIM2: (tim2, u32),
223-
TIM3: (tim3, u16),
224-
TIM4: (tim4, u16),
163+
crate::pac::TIM2: (tim2, u32),
164+
crate::pac::TIM3: (tim3, u16),
165+
crate::pac::TIM4: (tim4, u16),
225166
}
226167

227168
#[cfg(any(
@@ -241,5 +182,5 @@ hal! {
241182
feature = "stm32f479"
242183
))]
243184
hal! {
244-
TIM8: (tim8, u16),
185+
crate::pac::TIM8: (tim8, u16),
245186
}

src/serial.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ where
590590
let rcc = &(*RCC::ptr());
591591

592592
// Enable clock.
593-
USART::enable_clock(rcc);
593+
USART::enable(rcc);
594594
}
595595

596596
let pclk_freq = USART::pclk_freq(&clocks);
@@ -1183,33 +1183,27 @@ mod private {
11831183
}
11841184

11851185
// Implemented by all USART instances
1186-
pub trait Instance: private::Sealed {
1186+
pub trait Instance: private::Sealed + Enable {
11871187
#[doc(hidden)]
11881188
fn ptr() -> *const uart_base::RegisterBlock;
11891189
#[doc(hidden)]
11901190
fn pclk_freq(clocks: &Clocks) -> u32;
11911191
#[doc(hidden)]
1192-
unsafe fn enable_clock(rcc: &crate::pac::rcc::RegisterBlock);
1193-
#[doc(hidden)]
11941192
fn set_stopbits(&self, bits: config::StopBits);
11951193
}
11961194

11971195
macro_rules! halUsart {
1198-
($USARTX:ident: ($usartX:ident, $pclkX:ident)) => {
1196+
($USARTX:ty: ($usartX:ident, $pclkX:ident)) => {
11991197
impl private::Sealed for $USARTX {}
12001198
impl Instance for $USARTX {
12011199
fn ptr() -> *const uart_base::RegisterBlock {
1202-
$USARTX::ptr() as *const _
1200+
<$USARTX>::ptr() as *const _
12031201
}
12041202

12051203
fn pclk_freq(clocks: &Clocks) -> u32 {
12061204
clocks.$pclkX().0
12071205
}
12081206

1209-
unsafe fn enable_clock(rcc: &crate::pac::rcc::RegisterBlock) {
1210-
$USARTX::enable(rcc);
1211-
}
1212-
12131207
fn set_stopbits(&self, bits: config::StopBits) {
12141208
use crate::pac::usart1::cr2::STOP_A;
12151209
use config::StopBits;
@@ -1254,21 +1248,17 @@ macro_rules! halUsart {
12541248
))]
12551249
#[cfg(not(any(feature = "stm32f413", feature = "stm32f423",)))]
12561250
macro_rules! halUart {
1257-
($USARTX:ident: ($usartX:ident, $pclkX:ident)) => {
1251+
($USARTX:ty: ($usartX:ident, $pclkX:ident)) => {
12581252
impl private::Sealed for $USARTX {}
12591253
impl Instance for $USARTX {
12601254
fn ptr() -> *const uart_base::RegisterBlock {
1261-
$USARTX::ptr() as *const _
1255+
<$USARTX>::ptr() as *const _
12621256
}
12631257

12641258
fn pclk_freq(clocks: &Clocks) -> u32 {
12651259
clocks.$pclkX().0
12661260
}
12671261

1268-
unsafe fn enable_clock(rcc: &crate::pac::rcc::RegisterBlock) {
1269-
$USARTX::enable(rcc);
1270-
}
1271-
12721262
fn set_stopbits(&self, bits: config::StopBits) {
12731263
use crate::pac::uart4::cr2::STOP_A;
12741264
use config::StopBits;

src/spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub struct Spi<SPI, PINS> {
376376

377377
// Implemented by all I2C instances
378378
macro_rules! spi {
379-
($SPI:ident: ($spi:ident, $pclk:ident)) => {
379+
($SPI:ty: ($spi:ident, $pclk:ident)) => {
380380
impl<PINS> Spi<$SPI, PINS>
381381
where
382382
PINS: Pins<$SPI>,
@@ -388,7 +388,7 @@ macro_rules! spi {
388388
unsafe {
389389
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
390390
let rcc = &(*RCC::ptr());
391-
$SPI::enable(rcc);
391+
<$SPI>::enable(rcc);
392392
}
393393

394394
Spi { spi, pins }.init(mode, freq, clocks.$pclk())

0 commit comments

Comments
 (0)