11use crate :: pac:: rcc:: cfgr:: { HPRE , SW } ;
2- use crate :: pac:: { self , rcc , RCC } ;
2+ use crate :: pac:: RCC ;
33
4- use super :: { BusClock , BusTimerClock , RccBus } ;
4+ use super :: * ;
55
66use fugit:: HertzU32 as Hertz ;
77use fugit:: RateExtU32 ;
88
99mod pll;
1010
1111mod enable;
12- use crate :: pac:: rcc:: RegisterBlock as RccRB ;
13-
14- /// Enable/disable peripheral
15- #[ allow( clippy:: missing_safety_doc) ]
16- pub trait Enable : RccBus {
17- /// Enables peripheral
18- fn enable ( rcc : & RccRB ) ;
19-
20- /// Disables peripheral
21- fn disable ( rcc : & RccRB ) ;
22-
23- /// Check if peripheral enabled
24- fn is_enabled ( ) -> bool ;
25-
26- /// Check if peripheral disabled
27- #[ inline]
28- fn is_disabled ( ) -> bool {
29- !Self :: is_enabled ( )
30- }
31-
32- /// # Safety
33- ///
34- /// 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- /// # Safety
41- ///
42- /// 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- /// Low power enable/disable peripheral
50- #[ allow( clippy:: missing_safety_doc) ]
51- pub trait LPEnable : RccBus {
52- /// Enables peripheral in low power mode
53- fn enable_in_low_power ( rcc : & RccRB ) ;
54-
55- /// Disables peripheral in low power mode
56- fn disable_in_low_power ( rcc : & RccRB ) ;
57-
58- /// Check if peripheral enabled in low power mode
59- fn is_enabled_in_low_power ( ) -> bool ;
60-
61- /// 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- /// # Safety
68- ///
69- /// 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- /// # Safety
76- ///
77- /// 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- /// Reset peripheral
85- #[ allow( clippy:: missing_safety_doc) ]
86- pub trait Reset : RccBus {
87- /// Resets peripheral
88- fn reset ( rcc : & RccRB ) ;
89-
90- /// # Safety
91- ///
92- /// 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- /// Extension trait that constrains the `RCC` peripheral
100- pub trait RccExt {
101- /// 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- /// 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- }
20612
20713impl RccExt for RCC {
20814 fn constrain ( self ) -> Rcc {
20915 Rcc {
16+ rb : self ,
21017 cfgr : CFGR {
21118 hse : None ,
21219 hse_bypass : false ,
@@ -233,11 +40,6 @@ impl RccExt for RCC {
23340 }
23441}
23542
236- /// Constrained RCC peripheral
237- pub struct Rcc {
238- pub cfgr : CFGR ,
239- }
240-
24143/// Built-in high speed clock frequency
24244pub const HSI : u32 = 16_000_000 ; // Hz
24345
@@ -917,31 +719,31 @@ impl RealSaiClocks {
917719#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
918720#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
919721pub 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 > ,
927729
928730 #[ cfg( not( feature = "rcc_i2s_apb" ) ) ]
929- i2s_clk : Option < Hertz > ,
731+ pub ( super ) i2s_clk : Option < Hertz > ,
930732 #[ cfg( feature = "rcc_i2s_apb" ) ]
931- i2s_apb1_clk : Option < Hertz > ,
733+ pub ( super ) i2s_apb1_clk : Option < Hertz > ,
932734 #[ cfg( feature = "rcc_i2s_apb" ) ]
933- i2s_apb2_clk : Option < Hertz > ,
735+ pub ( super ) i2s_apb2_clk : Option < Hertz > ,
934736
935737 #[ cfg( feature = "sai" ) ]
936738 #[ cfg( not( feature = "sai2" ) ) ]
937- saia_clk : Option < Hertz > ,
739+ pub ( super ) saia_clk : Option < Hertz > ,
938740 #[ cfg( feature = "sai" ) ]
939741 #[ cfg( not( feature = "sai2" ) ) ]
940- saib_clk : Option < Hertz > ,
742+ pub ( super ) saib_clk : Option < Hertz > ,
941743 #[ cfg( feature = "sai2" ) ]
942- sai1_clk : Option < Hertz > ,
744+ pub ( super ) sai1_clk : Option < Hertz > ,
943745 #[ cfg( feature = "sai2" ) ]
944- sai2_clk : Option < Hertz > ,
746+ pub ( super ) sai2_clk : Option < Hertz > ,
945747}
946748
947749impl Clocks {
0 commit comments