1
+ //! Provides various hardware initialization functions.
2
+
1
3
use crate :: i2c:: { self , I2C } ;
2
4
use crate :: lcd:: { self , Lcd } ;
3
5
use crate :: system_clock;
@@ -7,6 +9,9 @@ pub use self::pins::init as pins;
7
9
8
10
mod pins;
9
11
12
+ /// Initialize the system clock to the maximum speed of 216MHz.
13
+ ///
14
+ /// This function should be called right at the beginning of the main function.
10
15
pub fn init_system_clock_216mhz ( rcc : & mut RCC , pwr : & mut PWR , flash : & mut FLASH ) {
11
16
// enable power control clock
12
17
rcc. apb1enr . modify ( |_, w| w. pwren ( ) . enabled ( ) ) ;
@@ -89,10 +94,14 @@ pub fn init_system_clock_216mhz(rcc: &mut RCC, pwr: &mut PWR, flash: &mut FLASH)
89
94
rcc. cfgr . modify ( |_, w| w. ppre2 ( ) . div2 ( ) ) ;
90
95
}
91
96
97
+ /// Initialize the system clock to the specified frequency.
98
+ ///
99
+ /// Equivalent to [`system_clock::init`](crate::system_clock::init).
92
100
pub fn init_systick ( frequency : system_clock:: Hz , systick : & mut SYST , rcc : & RCC ) {
93
101
system_clock:: init ( frequency, systick, rcc)
94
102
}
95
103
104
+ /// Enable all GPIO ports in the RCC register.
96
105
pub fn enable_gpio_ports ( rcc : & mut RCC ) {
97
106
rcc. ahb1enr . modify ( |_, w| {
98
107
w. gpioaen ( ) . enabled ( ) ;
@@ -128,13 +137,17 @@ pub fn enable_gpio_ports(rcc: &mut RCC) {
128
137
}
129
138
}
130
139
140
+ /// Enable the syscfg clock.
131
141
pub fn enable_syscfg ( rcc : & mut RCC ) {
132
142
// enable syscfg clock
133
143
rcc. apb2enr . modify ( |_, w| w. syscfgen ( ) . set_bit ( ) ) ;
134
144
// delay
135
145
let _unused = rcc. apb2enr . read ( ) ;
136
146
}
137
147
148
+ /// Initializes the SDRAM, which makes more memory accessible.
149
+ ///
150
+ /// This is a prerequisite for using the LCD.
138
151
pub fn init_sdram ( rcc : & mut RCC , fmc : & mut FMC ) {
139
152
#[ allow( dead_code) ]
140
153
#[ derive( Debug , Clone , Copy ) ]
@@ -275,14 +288,23 @@ pub fn init_sdram(rcc: &mut RCC, fmc: &mut FMC) {
275
288
}
276
289
}
277
290
291
+ /// Initializes the LCD.
292
+ ///
293
+ /// This function is equivalent to [`lcd::init`](crate::lcd::init::init).
278
294
pub fn init_lcd < ' a > ( ltdc : & ' a mut LTDC , rcc : & mut RCC ) -> Lcd < ' a > {
279
295
lcd:: init ( ltdc, rcc)
280
296
}
281
297
298
+ /// Initializes the I2C3 bus.
299
+ ///
300
+ /// This function is equivalent to [`i2c::init`](crate::i2c::init).
282
301
pub fn init_i2c_3 < ' a > ( i2c : & ' a i2c1:: RegisterBlock , rcc : & mut RCC ) -> I2C < ' a > {
283
302
i2c:: init ( i2c, rcc)
284
303
}
285
304
305
+ /// Initializes the SAI2 controller.
306
+ ///
307
+ /// Required for audio input.
286
308
pub fn init_sai_2 ( sai : & mut SAI2 , rcc : & mut RCC ) {
287
309
let audio_frequency = 16000 ;
288
310
@@ -500,6 +522,9 @@ pub fn init_sai_2(sai: &mut SAI2, rcc: &mut RCC) {
500
522
501
523
const WM8994_ADDRESS : i2c:: Address = i2c:: Address :: bits_7 ( 0b0011010 ) ;
502
524
525
+ /// Initializes the WM8994 audio controller.
526
+ ///
527
+ /// Required for audio input.
503
528
pub fn init_wm8994 ( i2c_3 : & mut i2c:: I2C ) -> Result < ( ) , i2c:: Error > {
504
529
i2c_3. connect :: < u16 , _ > ( WM8994_ADDRESS , |mut conn| {
505
530
// read and check device family ID
0 commit comments