Skip to content

Commit 9606227

Browse files
committed
crate::Sealed
1 parent b623399 commit 9606227

File tree

8 files changed

+26
-47
lines changed

8 files changed

+26
-47
lines changed

src/i2c.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,11 @@ pub enum Error {
250250
ARBITRATION,
251251
}
252252

253-
mod private {
254-
pub trait Sealed {}
255-
}
256-
257-
pub trait Instance: private::Sealed + Deref<Target = i2c1::RegisterBlock> + Enable + Reset {}
253+
pub trait Instance: crate::Sealed + Deref<Target = i2c1::RegisterBlock> + Enable + Reset {}
258254

259-
impl private::Sealed for I2C1 {}
260255
impl Instance for I2C1 {}
261-
impl private::Sealed for I2C2 {}
262256
impl Instance for I2C2 {}
263257

264-
#[cfg(feature = "i2c3")]
265-
impl private::Sealed for I2C3 {}
266258
#[cfg(feature = "i2c3")]
267259
impl Instance for I2C3 {}
268260

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,8 @@ pub mod time;
175175
pub mod timer;
176176
#[cfg(feature = "device-selected")]
177177
pub mod watchdog;
178+
179+
mod sealed {
180+
pub trait Sealed {}
181+
}
182+
pub(crate) use sealed::Sealed;

src/qei.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ impl<TIM: Instance, PINS> hal::Qei for Qei<TIM, PINS> {
5757
}
5858
}
5959

60-
mod sealed {
61-
pub trait Sealed {}
62-
}
63-
64-
pub trait Instance: sealed::Sealed {
60+
pub trait Instance: crate::Sealed {
6561
type Count;
6662

6763
fn setup_clocks();
@@ -73,7 +69,6 @@ pub trait Instance: sealed::Sealed {
7369
macro_rules! hal {
7470
($($TIM:ty: ($tim:ident, $bits:ident),)+) => {
7571
$(
76-
impl sealed::Sealed for $TIM {}
7772
impl Instance for $TIM {
7873
type Count = $bits;
7974

src/rcc/enable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! bus_reset {
5858
macro_rules! bus {
5959
($($PER:ident => ($busX:ty, $bit:literal),)+) => {
6060
$(
61-
impl Sealed for crate::pac::$PER {}
61+
impl crate::Sealed for crate::pac::$PER {}
6262
impl RccBus for crate::pac::$PER {
6363
type Bus = $busX;
6464
}
@@ -126,7 +126,7 @@ bus! {
126126

127127
// TODO: fix absent ahb3lpenr
128128
#[cfg(feature = "fsmc")]
129-
impl Sealed for crate::pac::FSMC {}
129+
impl crate::Sealed for crate::pac::FSMC {}
130130
#[cfg(feature = "fsmc")]
131131
impl RccBus for crate::pac::FSMC {
132132
type Bus = AHB3;
@@ -231,7 +231,7 @@ bus! {
231231
}
232232

233233
#[cfg(feature = "adc2")]
234-
impl Sealed for crate::pac::ADC2 {}
234+
impl crate::Sealed for crate::pac::ADC2 {}
235235
#[cfg(feature = "adc2")]
236236
impl RccBus for crate::pac::ADC2 {
237237
type Bus = APB2;
@@ -244,7 +244,7 @@ bus_lpenable!(ADC2 => (APB2, 9));
244244
bus_reset!(ADC2 => (APB2, 8));
245245

246246
#[cfg(feature = "adc3")]
247-
impl Sealed for crate::pac::ADC3 {}
247+
impl crate::Sealed for crate::pac::ADC3 {}
248248
#[cfg(feature = "adc3")]
249249
impl RccBus for crate::pac::ADC3 {
250250
type Bus = APB2;

src/rcc/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,8 @@ mod pll;
6363
mod enable;
6464
use crate::pac::rcc::RegisterBlock as RccRB;
6565

66-
pub mod sealed {
67-
pub trait Sealed {}
68-
}
69-
pub(crate) use sealed::Sealed;
70-
7166
/// Bus associated to peripheral
72-
pub trait RccBus {
67+
pub trait RccBus: crate::Sealed {
7368
/// Bus type;
7469
type Bus;
7570
}
@@ -138,10 +133,12 @@ impl AHB1 {
138133
}
139134

140135
/// AMBA High-performance Bus 2 (AHB2) registers
136+
#[cfg(not(feature = "stm32f410"))]
141137
pub struct AHB2 {
142138
_0: (),
143139
}
144140

141+
#[cfg(not(feature = "stm32f410"))]
145142
impl AHB2 {
146143
#[inline(always)]
147144
fn enr(rcc: &RccRB) -> &rcc::AHB2ENR {
@@ -158,17 +155,22 @@ impl AHB2 {
158155
}
159156

160157
/// AMBA High-performance Bus 3 (AHB3) registers
161-
#[cfg(feature = "fsmc")]
158+
#[cfg(any(feature = "fsmc", feature = "fmc"))]
162159
pub struct AHB3 {
163160
_0: (),
164161
}
165162

166-
#[cfg(feature = "fsmc")]
163+
#[cfg(any(feature = "fsmc", feature = "fmc"))]
167164
impl AHB3 {
168165
#[inline(always)]
169166
fn enr(rcc: &RccRB) -> &rcc::AHB3ENR {
170167
&rcc.ahb3enr
171168
}
169+
#[cfg(feature = "fmc")]
170+
#[inline(always)]
171+
fn lpenr(rcc: &RccRB) -> &rcc::AHB3LPENR {
172+
&rcc.ahb3lpenr
173+
}
172174
#[inline(always)]
173175
fn rstr(rcc: &RccRB) -> &rcc::AHB3RSTR {
174176
&rcc.ahb3rstr
@@ -221,13 +223,14 @@ impl GetBusFreq for AHB1 {
221223
}
222224
}
223225

226+
#[cfg(not(feature = "stm32f410"))]
224227
impl GetBusFreq for AHB2 {
225228
fn get_frequency(clocks: &Clocks) -> Hertz {
226229
clocks.hclk
227230
}
228231
}
229232

230-
#[cfg(feature = "fsmc")]
233+
#[cfg(any(feature = "fsmc", feature = "fmc"))]
231234
impl GetBusFreq for AHB3 {
232235
fn get_frequency(clocks: &Clocks) -> Hertz {
233236
clocks.hclk

src/serial.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,12 +1145,8 @@ use crate::pac::uart4 as uart_base;
11451145
)))]
11461146
use crate::pac::usart1 as uart_base;
11471147

1148-
mod private {
1149-
pub trait Sealed {}
1150-
}
1151-
11521148
// Implemented by all USART instances
1153-
pub trait Instance: private::Sealed + rcc::Enable + rcc::Reset + rcc::GetBusFreq {
1149+
pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset + rcc::GetBusFreq {
11541150
#[doc(hidden)]
11551151
fn ptr() -> *const uart_base::RegisterBlock;
11561152
#[doc(hidden)]
@@ -1159,7 +1155,6 @@ pub trait Instance: private::Sealed + rcc::Enable + rcc::Reset + rcc::GetBusFreq
11591155

11601156
macro_rules! halUsart {
11611157
($USARTX:ty: ($usartX:ident)) => {
1162-
impl private::Sealed for $USARTX {}
11631158
impl Instance for $USARTX {
11641159
fn ptr() -> *const uart_base::RegisterBlock {
11651160
<$USARTX>::ptr() as *const _
@@ -1211,7 +1206,6 @@ macro_rules! halUsart {
12111206
#[cfg(not(any(feature = "stm32f413", feature = "stm32f423",)))]
12121207
macro_rules! halUart {
12131208
($USARTX:ty: ($usartX:ident)) => {
1214-
impl private::Sealed for $USARTX {}
12151209
impl Instance for $USARTX {
12161210
fn ptr() -> *const uart_base::RegisterBlock {
12171211
<$USARTX>::ptr() as *const _

src/spi.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,9 @@ pub struct Spi<SPI, PINS> {
357357
pins: PINS,
358358
}
359359

360-
mod private {
361-
pub trait Sealed {}
362-
}
363-
364360
// Implemented by all SPI instances
365361
pub trait Instance:
366-
private::Sealed + Deref<Target = spi1::RegisterBlock> + rcc::Enable + rcc::Reset
362+
crate::Sealed + Deref<Target = spi1::RegisterBlock> + rcc::Enable + rcc::Reset
367363
{
368364
#[doc(hidden)]
369365
fn pclk_freq(clocks: &Clocks) -> Hertz;
@@ -372,7 +368,6 @@ pub trait Instance:
372368
// Implemented by all SPI instances
373369
macro_rules! spi {
374370
($SPI:ident: ($spi:ident, $pclk:ident)) => {
375-
impl private::Sealed for $SPI {}
376371
impl Instance for $SPI {
377372
fn pclk_freq(clocks: &Clocks) -> Hertz {
378373
clocks.$pclk()

src/timer.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ impl Instant {
176176
}
177177
}
178178

179-
mod private {
180-
pub trait Sealed {}
181-
}
182-
183-
pub trait Instance: private::Sealed + rcc::Enable + rcc::Reset + rcc::GetBusFreq {}
179+
pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset + rcc::GetBusFreq {}
184180

185181
impl<TIM> Timer<TIM>
186182
where
@@ -206,7 +202,6 @@ where
206202
macro_rules! hal {
207203
($($TIM:ty: ($tim:ident),)+) => {
208204
$(
209-
impl private::Sealed for $TIM {}
210205
impl Instance for $TIM { }
211206

212207
impl CountDownTimer<$TIM> {

0 commit comments

Comments
 (0)