1
1
use crate :: pac:: rcc:: cfgr:: { HPRE , SW } ;
2
- use crate :: pac:: { self , rcc , RCC } ;
2
+ use crate :: pac:: RCC ;
3
3
4
- use super :: { BusClock , BusTimerClock , RccBus } ;
4
+ use super :: * ;
5
5
6
6
use fugit:: HertzU32 as Hertz ;
7
7
use fugit:: RateExtU32 ;
8
8
9
9
mod pll;
10
10
11
11
mod enable;
12
- use crate :: pac:: rcc:: RegisterBlock as RccRB ;
13
-
14
- //github.com/ Enable/disable peripheral
15
- #[ allow( clippy:: missing_safety_doc) ]
16
- pub trait Enable : RccBus {
17
- //github.com/ Enables peripheral
18
- fn enable ( rcc : & RccRB ) ;
19
-
20
- //github.com/ Disables peripheral
21
- fn disable ( rcc : & RccRB ) ;
22
-
23
- //github.com/ Check if peripheral enabled
24
- fn is_enabled ( ) -> bool ;
25
-
26
- //github.com/ Check if peripheral disabled
27
- #[ inline]
28
- fn is_disabled ( ) -> bool {
29
- !Self :: is_enabled ( )
30
- }
31
-
32
- //github.com/ # Safety
33
- //github.com/
34
- //github.com/ Enables peripheral. Takes access to RCC internally
35
- unsafe fn enable_unchecked ( ) {
36
- let rcc = & * pac:: RCC :: ptr ( ) ;
37
- Self :: enable ( rcc) ;
38
- }
39
-
40
- //github.com/ # Safety
41
- //github.com/
42
- //github.com/ Disables peripheral. Takes access to RCC internally
43
- unsafe fn disable_unchecked ( ) {
44
- let rcc = pac:: RCC :: ptr ( ) ;
45
- Self :: disable ( & * rcc) ;
46
- }
47
- }
48
-
49
- //github.com/ Low power enable/disable peripheral
50
- #[ allow( clippy:: missing_safety_doc) ]
51
- pub trait LPEnable : RccBus {
52
- //github.com/ Enables peripheral in low power mode
53
- fn enable_in_low_power ( rcc : & RccRB ) ;
54
-
55
- //github.com/ Disables peripheral in low power mode
56
- fn disable_in_low_power ( rcc : & RccRB ) ;
57
-
58
- //github.com/ Check if peripheral enabled in low power mode
59
- fn is_enabled_in_low_power ( ) -> bool ;
60
-
61
- //github.com/ Check if peripheral disabled in low power mode
62
- #[ inline]
63
- fn is_disabled_in_low_power ( ) -> bool {
64
- !Self :: is_enabled_in_low_power ( )
65
- }
66
-
67
- //github.com/ # Safety
68
- //github.com/
69
- //github.com/ Enables peripheral in low power mode. Takes access to RCC internally
70
- unsafe fn enable_in_low_power_unchecked ( ) {
71
- let rcc = pac:: RCC :: ptr ( ) ;
72
- Self :: enable_in_low_power ( & * rcc) ;
73
- }
74
-
75
- //github.com/ # Safety
76
- //github.com/
77
- //github.com/ Disables peripheral in low power mode. Takes access to RCC internally
78
- unsafe fn disable_in_low_power_unchecked ( ) {
79
- let rcc = pac:: RCC :: ptr ( ) ;
80
- Self :: disable_in_low_power ( & * rcc) ;
81
- }
82
- }
83
-
84
- //github.com/ Reset peripheral
85
- #[ allow( clippy:: missing_safety_doc) ]
86
- pub trait Reset : RccBus {
87
- //github.com/ Resets peripheral
88
- fn reset ( rcc : & RccRB ) ;
89
-
90
- //github.com/ # Safety
91
- //github.com/
92
- //github.com/ Resets peripheral. Takes access to RCC internally
93
- unsafe fn reset_unchecked ( ) {
94
- let rcc = pac:: RCC :: ptr ( ) ;
95
- Self :: reset ( & * rcc) ;
96
- }
97
- }
98
-
99
- //github.com/ Extension trait that constrains the `RCC` peripheral
100
- pub trait RccExt {
101
- //github.com/ Constrains the `RCC` peripheral so it plays nicely with the other abstractions
102
- fn constrain ( self ) -> Rcc ;
103
- }
104
-
105
- macro_rules! bus_struct {
106
- ( $( $( #[ $attr: meta] ) * $busX: ident => ( $EN: ident, $en: ident, $LPEN: ident, $lpen: ident, $RST: ident, $rst: ident, $doc: literal) , ) +) => {
107
- $(
108
- $( #[ $attr] ) *
109
- #[ doc = $doc]
110
- #[ non_exhaustive]
111
- pub struct $busX;
112
-
113
- $( #[ $attr] ) *
114
- impl $busX {
115
- pub ( crate ) fn enr( rcc: & RccRB ) -> & rcc:: $EN {
116
- rcc. $en( )
117
- }
118
-
119
- pub ( crate ) fn lpenr( rcc: & RccRB ) -> & rcc:: $LPEN {
120
- rcc. $lpen( )
121
- }
122
-
123
- pub ( crate ) fn rstr( rcc: & RccRB ) -> & rcc:: $RST {
124
- rcc. $rst( )
125
- }
126
- }
127
- ) +
128
- } ;
129
- }
130
-
131
- bus_struct ! {
132
- APB1 => ( APB1ENR , apb1enr, APB1LPENR , apb1lpenr, APB1RSTR , apb1rstr, "Advanced Peripheral Bus 1 (APB1) registers" ) ,
133
- APB2 => ( APB2ENR , apb2enr, APB2LPENR , apb2lpenr, APB2RSTR , apb2rstr, "Advanced Peripheral Bus 2 (APB2) registers" ) ,
134
- AHB1 => ( AHB1ENR , ahb1enr, AHB1LPENR , ahb1lpenr, AHB1RSTR , ahb1rstr, "Advanced High-performance Bus 1 (AHB1) registers" ) ,
135
- #[ cfg( not( feature = "gpio-f410" ) ) ]
136
- AHB2 => ( AHB2ENR , ahb2enr, AHB2LPENR , ahb2lpenr, AHB2RSTR , ahb2rstr, "Advanced High-performance Bus 2 (AHB2) registers" ) ,
137
- //#[cfg(any(feature = "fsmc", feature = "fmc"))]
138
- //AHB3 => (AHB3ENR, ahb3enr, AHB3LPENR, ahb3lpenr, AHB3RSTR, ahb3rstr, "Advanced High-performance Bus 3 (AHB3) registers"),
139
- }
140
-
141
- //github.com/ AMBA High-performance Bus 3 (AHB3) registers
142
- #[ cfg( any( feature = "fsmc" , feature = "fmc" ) ) ]
143
- #[ non_exhaustive]
144
- pub struct AHB3 ;
145
-
146
- #[ cfg( any( feature = "fsmc" , feature = "fmc" ) ) ]
147
- impl AHB3 {
148
- #[ inline( always) ]
149
- fn enr ( rcc : & RccRB ) -> & rcc:: AHB3ENR {
150
- rcc. ahb3enr ( )
151
- }
152
- #[ cfg( feature = "fmc" ) ]
153
- #[ inline( always) ]
154
- fn lpenr ( rcc : & RccRB ) -> & rcc:: AHB3LPENR {
155
- rcc. ahb3lpenr ( )
156
- }
157
- #[ inline( always) ]
158
- fn rstr ( rcc : & RccRB ) -> & rcc:: AHB3RSTR {
159
- rcc. ahb3rstr ( )
160
- }
161
- }
162
-
163
- impl BusClock for AHB1 {
164
- fn clock ( clocks : & Clocks ) -> Hertz {
165
- clocks. hclk
166
- }
167
- }
168
-
169
- #[ cfg( not( feature = "gpio-f410" ) ) ]
170
- impl BusClock for AHB2 {
171
- fn clock ( clocks : & Clocks ) -> Hertz {
172
- clocks. hclk
173
- }
174
- }
175
-
176
- #[ cfg( any( feature = "fsmc" , feature = "fmc" ) ) ]
177
- impl BusClock for AHB3 {
178
- fn clock ( clocks : & Clocks ) -> Hertz {
179
- clocks. hclk
180
- }
181
- }
182
-
183
- impl BusClock for APB1 {
184
- fn clock ( clocks : & Clocks ) -> Hertz {
185
- clocks. pclk1
186
- }
187
- }
188
-
189
- impl BusClock for APB2 {
190
- fn clock ( clocks : & Clocks ) -> Hertz {
191
- clocks. pclk2
192
- }
193
- }
194
-
195
- impl BusTimerClock for APB1 {
196
- fn timer_clock ( clocks : & Clocks ) -> Hertz {
197
- clocks. timclk1
198
- }
199
- }
200
-
201
- impl BusTimerClock for APB2 {
202
- fn timer_clock ( clocks : & Clocks ) -> Hertz {
203
- clocks. timclk2
204
- }
205
- }
206
12
207
13
impl RccExt for RCC {
208
14
fn constrain ( self ) -> Rcc {
209
15
Rcc {
16
+ rb : self ,
210
17
cfgr : CFGR {
211
18
hse : None ,
212
19
hse_bypass : false ,
@@ -233,11 +40,6 @@ impl RccExt for RCC {
233
40
}
234
41
}
235
42
236
- //github.com/ Constrained RCC peripheral
237
- pub struct Rcc {
238
- pub cfgr : CFGR ,
239
- }
240
-
241
43
//github.com/ Built-in high speed clock frequency
242
44
pub const HSI : u32 = 16_000_000 ; // Hz
243
45
@@ -917,31 +719,31 @@ impl RealSaiClocks {
917
719
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
918
720
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
919
721
pub struct Clocks {
920
- hclk : Hertz ,
921
- pclk1 : Hertz ,
922
- pclk2 : Hertz ,
923
- timclk1 : Hertz ,
924
- timclk2 : Hertz ,
925
- sysclk : Hertz ,
926
- pll48clk : Option < Hertz > ,
722
+ pub ( super ) hclk : Hertz ,
723
+ pub ( super ) pclk1 : Hertz ,
724
+ pub ( super ) pclk2 : Hertz ,
725
+ pub ( super ) timclk1 : Hertz ,
726
+ pub ( super ) timclk2 : Hertz ,
727
+ pub ( super ) sysclk : Hertz ,
728
+ pub ( super ) pll48clk : Option < Hertz > ,
927
729
928
730
#[ cfg( not( feature = "rcc_i2s_apb" ) ) ]
929
- i2s_clk : Option < Hertz > ,
731
+ pub ( super ) i2s_clk : Option < Hertz > ,
930
732
#[ cfg( feature = "rcc_i2s_apb" ) ]
931
- i2s_apb1_clk : Option < Hertz > ,
733
+ pub ( super ) i2s_apb1_clk : Option < Hertz > ,
932
734
#[ cfg( feature = "rcc_i2s_apb" ) ]
933
- i2s_apb2_clk : Option < Hertz > ,
735
+ pub ( super ) i2s_apb2_clk : Option < Hertz > ,
934
736
935
737
#[ cfg( feature = "sai" ) ]
936
738
#[ cfg( not( feature = "sai2" ) ) ]
937
- saia_clk : Option < Hertz > ,
739
+ pub ( super ) saia_clk : Option < Hertz > ,
938
740
#[ cfg( feature = "sai" ) ]
939
741
#[ cfg( not( feature = "sai2" ) ) ]
940
- saib_clk : Option < Hertz > ,
742
+ pub ( super ) saib_clk : Option < Hertz > ,
941
743
#[ cfg( feature = "sai2" ) ]
942
- sai1_clk : Option < Hertz > ,
744
+ pub ( super ) sai1_clk : Option < Hertz > ,
943
745
#[ cfg( feature = "sai2" ) ]
944
- sai2_clk : Option < Hertz > ,
746
+ pub ( super ) sai2_clk : Option < Hertz > ,
945
747
}
946
748
947
749
impl Clocks {
0 commit comments