Skip to content

Commit 0d39f26

Browse files
committed
Document the init module
1 parent 7c7aee3 commit 0d39f26

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/init/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Provides various hardware initialization functions.
2+
13
use crate::i2c::{self, I2C};
24
use crate::lcd::{self, Lcd};
35
use crate::system_clock;
@@ -7,6 +9,9 @@ pub use self::pins::init as pins;
79

810
mod pins;
911

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.
1015
pub fn init_system_clock_216mhz(rcc: &mut RCC, pwr: &mut PWR, flash: &mut FLASH) {
1116
// enable power control clock
1217
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)
8994
rcc.cfgr.modify(|_, w| w.ppre2().div2());
9095
}
9196

97+
/// Initialize the system clock to the specified frequency.
98+
///
99+
/// Equivalent to [`system_clock::init`](crate::system_clock::init).
92100
pub fn init_systick(frequency: system_clock::Hz, systick: &mut SYST, rcc: &RCC) {
93101
system_clock::init(frequency, systick, rcc)
94102
}
95103

104+
/// Enable all GPIO ports in the RCC register.
96105
pub fn enable_gpio_ports(rcc: &mut RCC) {
97106
rcc.ahb1enr.modify(|_, w| {
98107
w.gpioaen().enabled();
@@ -128,13 +137,17 @@ pub fn enable_gpio_ports(rcc: &mut RCC) {
128137
}
129138
}
130139

140+
/// Enable the syscfg clock.
131141
pub fn enable_syscfg(rcc: &mut RCC) {
132142
// enable syscfg clock
133143
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
134144
// delay
135145
let _unused = rcc.apb2enr.read();
136146
}
137147

148+
/// Initializes the SDRAM, which makes more memory accessible.
149+
///
150+
/// This is a prerequisite for using the LCD.
138151
pub fn init_sdram(rcc: &mut RCC, fmc: &mut FMC) {
139152
#[allow(dead_code)]
140153
#[derive(Debug, Clone, Copy)]
@@ -275,14 +288,23 @@ pub fn init_sdram(rcc: &mut RCC, fmc: &mut FMC) {
275288
}
276289
}
277290

291+
/// Initializes the LCD.
292+
///
293+
/// This function is equivalent to [`lcd::init`](crate::lcd::init::init).
278294
pub fn init_lcd<'a>(ltdc: &'a mut LTDC, rcc: &mut RCC) -> Lcd<'a> {
279295
lcd::init(ltdc, rcc)
280296
}
281297

298+
/// Initializes the I2C3 bus.
299+
///
300+
/// This function is equivalent to [`i2c::init`](crate::i2c::init).
282301
pub fn init_i2c_3<'a>(i2c: &'a i2c1::RegisterBlock, rcc: &mut RCC) -> I2C<'a> {
283302
i2c::init(i2c, rcc)
284303
}
285304

305+
/// Initializes the SAI2 controller.
306+
///
307+
/// Required for audio input.
286308
pub fn init_sai_2(sai: &mut SAI2, rcc: &mut RCC) {
287309
let audio_frequency = 16000;
288310

@@ -500,6 +522,9 @@ pub fn init_sai_2(sai: &mut SAI2, rcc: &mut RCC) {
500522

501523
const WM8994_ADDRESS: i2c::Address = i2c::Address::bits_7(0b0011010);
502524

525+
/// Initializes the WM8994 audio controller.
526+
///
527+
/// Required for audio input.
503528
pub fn init_wm8994(i2c_3: &mut i2c::I2C) -> Result<(), i2c::Error> {
504529
i2c_3.connect::<u16, _>(WM8994_ADDRESS, |mut conn| {
505530
// read and check device family ID

src/init/pins.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::gpio::{
44
RegisterBlockB, RegisterBlockD, Resistor,
55
};
66

7+
/// This struct contains special PIO pins.
78
pub struct Pins<
89
Led: OutputPin,
910
Button: InputPin,
@@ -12,14 +13,26 @@ pub struct Pins<
1213
SdcardPresent: InputPin,
1314
AudioIn: InputPin,
1415
> {
16+
/// This pin enables or disables the debug LED.
1517
pub led: Led,
18+
/// This pin reports whether the user button is pressed.
1619
pub button: Button,
20+
/// This pin controls whether the LCD is enabled.
1721
pub display_enable: DisplayEnable,
22+
/// This pin controls the LCD backlight.
1823
pub backlight: Backlight,
24+
/// This pin reports whether there is a card in the SD card slot.
1925
pub sdcard_present: SdcardPresent,
26+
/// This pin reports whether there is new audio data from the microphone.
27+
///
28+
/// **Does not work currently**
2029
pub audio_in: AudioIn,
2130
}
2231

32+
/// Initializes the pin mapping for all the peripherals.
33+
///
34+
/// This function uses Rust's ownership mechanism internally to report duplicate mappings
35+
/// at compile time.
2336
pub fn init<'a>(
2437
mut gpio_a: GpioPort<RegisterBlockA<'a>>,
2538
mut gpio_b: GpioPort<RegisterBlockB<'a>>,

0 commit comments

Comments
 (0)