@@ -66,12 +66,32 @@ pub trait RccBus: crate::Sealed {
66
66
/// Enable/disable peripheral
67
67
#[ allow( clippy:: missing_safety_doc) ]
68
68
pub trait Enable : RccBus {
69
+ /// Enables peripheral
69
70
fn enable ( rcc : & RccRB ) ;
71
+
72
+ /// Disables peripheral
70
73
fn disable ( rcc : & RccRB ) ;
74
+
75
+ /// Check if peripheral enabled
76
+ fn is_enabled ( ) -> bool ;
77
+
78
+ /// Check if peripheral disabled
79
+ #[ inline]
80
+ fn is_disabled ( ) -> bool {
81
+ !Self :: is_enabled ( )
82
+ }
83
+
84
+ /// # Safety
85
+ ///
86
+ /// Enables peripheral. Takes access to RCC internally
71
87
unsafe fn enable_unchecked ( ) {
72
88
let rcc = & * pac:: RCC :: ptr ( ) ;
73
89
Self :: enable ( rcc) ;
74
90
}
91
+
92
+ /// # Safety
93
+ ///
94
+ /// Disables peripheral. Takes access to RCC internally
75
95
unsafe fn disable_unchecked ( ) {
76
96
let rcc = pac:: RCC :: ptr ( ) ;
77
97
Self :: disable ( & * rcc) ;
@@ -81,22 +101,47 @@ pub trait Enable: RccBus {
81
101
/// Low power enable/disable peripheral
82
102
#[ allow( clippy:: missing_safety_doc) ]
83
103
pub trait LPEnable : RccBus {
84
- fn low_power_enable ( rcc : & RccRB ) ;
85
- fn low_power_disable ( rcc : & RccRB ) ;
86
- unsafe fn low_power_enable_unchecked ( ) {
104
+ /// Enables peripheral in low power mode
105
+ fn enable_in_low_power ( rcc : & RccRB ) ;
106
+
107
+ /// Disables peripheral in low power mode
108
+ fn disable_in_low_power ( rcc : & RccRB ) ;
109
+
110
+ /// Check if peripheral enabled in low power mode
111
+ fn is_enabled_in_low_power ( ) -> bool ;
112
+
113
+ /// Check if peripheral disabled in low power mode
114
+ #[ inline]
115
+ fn is_disabled_in_low_power ( ) -> bool {
116
+ !Self :: is_enabled_in_low_power ( )
117
+ }
118
+
119
+ /// # Safety
120
+ ///
121
+ /// Enables peripheral in low power mode. Takes access to RCC internally
122
+ unsafe fn enable_in_low_power_unchecked ( ) {
87
123
let rcc = pac:: RCC :: ptr ( ) ;
88
- Self :: low_power_enable ( & * rcc) ;
124
+ Self :: enable_in_low_power ( & * rcc) ;
89
125
}
90
- unsafe fn low_power_disable_unchecked ( ) {
126
+
127
+ /// # Safety
128
+ ///
129
+ /// Disables peripheral in low power mode. Takes access to RCC internally
130
+ unsafe fn disable_in_low_power_unchecked ( ) {
91
131
let rcc = pac:: RCC :: ptr ( ) ;
92
- Self :: low_power_disable ( & * rcc) ;
132
+ Self :: disable_in_low_power ( & * rcc) ;
93
133
}
94
134
}
95
135
96
136
/// Reset peripheral
97
137
#[ allow( clippy:: missing_safety_doc) ]
98
138
pub trait Reset : RccBus {
139
+ /// Resets peripheral
99
140
fn reset ( rcc : & RccRB ) ;
141
+
142
+ /// # Safety
143
+ ///
144
+ /// Resets peripheral. Takes access to RCC internally
100
145
unsafe fn reset_unchecked ( ) {
101
146
let rcc = pac:: RCC :: ptr ( ) ;
102
147
Self :: reset ( & * rcc) ;
@@ -141,46 +186,41 @@ where
141
186
}
142
187
}
143
188
144
- /// AMBA High-performance Bus 1 (AHB1) registers
145
- pub struct AHB1 {
146
- _0 : ( ) ,
147
- }
189
+ macro_rules! bus_struct {
190
+ ( $( $( #[ $attr: meta] ) * $busX: ident => ( $EN: ident, $en: ident, $LPEN: ident, $lpen: ident, $RST: ident, $rst: ident, $doc: literal) , ) +) => {
191
+ $(
192
+ $( #[ $attr] ) *
193
+ #[ doc = $doc]
194
+ pub struct $busX {
195
+ _0: ( ) ,
196
+ }
148
197
149
- impl AHB1 {
150
- #[ inline( always) ]
151
- fn enr ( rcc : & RccRB ) -> & rcc:: AHB1ENR {
152
- & rcc. ahb1enr
153
- }
154
- #[ inline( always) ]
155
- fn lpenr ( rcc : & RccRB ) -> & rcc:: AHB1LPENR {
156
- & rcc. ahb1lpenr
157
- }
158
- #[ inline( always) ]
159
- fn rstr ( rcc : & RccRB ) -> & rcc:: AHB1RSTR {
160
- & rcc. ahb1rstr
161
- }
162
- }
198
+ $( #[ $attr] ) *
199
+ impl $busX {
200
+ pub ( crate ) fn enr( rcc: & RccRB ) -> & rcc:: $EN {
201
+ & rcc. $en
202
+ }
163
203
164
- /// AMBA High-performance Bus 2 (AHB2) registers
165
- #[ cfg( not( feature = "gpio-f410" ) ) ]
166
- pub struct AHB2 {
167
- _0 : ( ) ,
204
+ pub ( crate ) fn lpenr( rcc: & RccRB ) -> & rcc:: $LPEN {
205
+ & rcc. $lpen
206
+ }
207
+
208
+ pub ( crate ) fn rstr( rcc: & RccRB ) -> & rcc:: $RST {
209
+ & rcc. $rst
210
+ }
211
+ }
212
+ ) +
213
+ } ;
168
214
}
169
215
170
- #[ cfg( not( feature = "gpio-f410" ) ) ]
171
- impl AHB2 {
172
- #[ inline( always) ]
173
- fn enr ( rcc : & RccRB ) -> & rcc:: AHB2ENR {
174
- & rcc. ahb2enr
175
- }
176
- #[ inline( always) ]
177
- fn lpenr ( rcc : & RccRB ) -> & rcc:: AHB2LPENR {
178
- & rcc. ahb2lpenr
179
- }
180
- #[ inline( always) ]
181
- fn rstr ( rcc : & RccRB ) -> & rcc:: AHB2RSTR {
182
- & rcc. ahb2rstr
183
- }
216
+ bus_struct ! {
217
+ APB1 => ( APB1ENR , apb1enr, APB1LPENR , apb1lpenr, APB1RSTR , apb1rstr, "Advanced Peripheral Bus 1 (APB1) registers" ) ,
218
+ APB2 => ( APB2ENR , apb2enr, APB2LPENR , apb2lpenr, APB2RSTR , apb2rstr, "Advanced Peripheral Bus 2 (APB2) registers" ) ,
219
+ AHB1 => ( AHB1ENR , ahb1enr, AHB1LPENR , ahb1lpenr, AHB1RSTR , ahb1rstr, "Advanced High-performance Bus 1 (AHB1) registers" ) ,
220
+ #[ cfg( not( feature = "gpio-f410" ) ) ]
221
+ AHB2 => ( AHB2ENR , ahb2enr, AHB2LPENR , ahb2lpenr, AHB2RSTR , ahb2rstr, "Advanced High-performance Bus 2 (AHB2) registers" ) ,
222
+ //#[cfg(any(feature = "fsmc", feature = "fmc"))]
223
+ //AHB3 => (AHB3ENR, ahb3enr, AHB3LPENR, ahb3lpenr, AHB3RSTR, ahb3rstr, "Advanced High-performance Bus 3 (AHB3) registers"),
184
224
}
185
225
186
226
/// AMBA High-performance Bus 3 (AHB3) registers
@@ -206,46 +246,6 @@ impl AHB3 {
206
246
}
207
247
}
208
248
209
- /// Advanced Peripheral Bus 1 (APB1) registers
210
- pub struct APB1 {
211
- _0 : ( ) ,
212
- }
213
-
214
- impl APB1 {
215
- #[ inline( always) ]
216
- fn enr ( rcc : & RccRB ) -> & rcc:: APB1ENR {
217
- & rcc. apb1enr
218
- }
219
- #[ inline( always) ]
220
- fn lpenr ( rcc : & RccRB ) -> & rcc:: APB1LPENR {
221
- & rcc. apb1lpenr
222
- }
223
- #[ inline( always) ]
224
- fn rstr ( rcc : & RccRB ) -> & rcc:: APB1RSTR {
225
- & rcc. apb1rstr
226
- }
227
- }
228
-
229
- /// Advanced Peripheral Bus 2 (APB2) registers
230
- pub struct APB2 {
231
- _0 : ( ) ,
232
- }
233
-
234
- impl APB2 {
235
- #[ inline( always) ]
236
- fn enr ( rcc : & RccRB ) -> & rcc:: APB2ENR {
237
- & rcc. apb2enr
238
- }
239
- #[ inline( always) ]
240
- fn lpenr ( rcc : & RccRB ) -> & rcc:: APB2LPENR {
241
- & rcc. apb2lpenr
242
- }
243
- #[ inline( always) ]
244
- fn rstr ( rcc : & RccRB ) -> & rcc:: APB2RSTR {
245
- & rcc. apb2rstr
246
- }
247
- }
248
-
249
249
impl BusClock for AHB1 {
250
250
fn clock ( clocks : & Clocks ) -> Hertz {
251
251
clocks. hclk
0 commit comments