Skip to content

Commit 4259e42

Browse files
authored
Merge pull request #117 from TheZoq2/doc_improvements
improve rcc and gpio docs
2 parents 20c51f1 + 93f9206 commit 4259e42

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/gpio.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
//! General Purpose Input / Output
2+
//!
3+
//! To use the GPIO pins, you first need to configure the GPIO bank (GPIOA, GPIOB, ...) that you
4+
//! are interested in. This is done using the [GpioExt::split](trait.GpioExt.html#tymethod.split) function.
5+
//!
6+
//! ```
7+
//! let dp = pac::Peripherals::take().unwrap();
8+
//! let rcc = dp.RCC.constrain();
9+
//!
10+
//! let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
11+
//! ```
12+
//!
13+
//! The resulting [Parts](gpioa/struct.Parts.html) struct contains one field for each
14+
//! pin, as well as some shared registers.
15+
//!
16+
//! To use a pin, first use the relevant `into_...` method of the [pin](gpioa/struct.PA0.html).
17+
//!
18+
//! ```rust
19+
//! let pa0 = gpioa.pa0.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
20+
//! ```
21+
//!
22+
//! And finally, you can use the functions from the [InputPin] or [OutputPin] traits in
23+
//! `embedded_hal`
24+
//!
25+
//! For a complete example, see [examples/toggle.rs]
26+
//!
27+
//! [InputPin]: ../prelude/trait._embedded_hal_digital_InputPin.html
28+
//! [OutputPin]: ../prelude/trait._embedded_hal_digital_OutputPin.html
29+
//! [examples/toggle.rs]: https://github.com/stm32-rs/stm32f3xx-hal/blob/v0.4.3/examples/toggle.rs
230
331
use core::convert::Infallible;
432
use core::marker::PhantomData;

src/rcc.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ impl RccExt for RCC {
3232
}
3333

3434
/// Constrained RCC peripheral
35+
///
36+
/// An instance of this struct is aquired by calling the
37+
/// [constrain](trait.RccExt.html#tymethod.constrain) function on the
38+
/// [pac::RCC](../pac/struct.RCC.html) struct.
39+
///
40+
/// ```
41+
/// let dp = pac::Peripherals::take().unwrap();
42+
/// let rcc = dp.RCC.constrain();
43+
/// ```
3544
pub struct Rcc {
3645
/// AMBA High-performance Bus (AHB) registers
3746
pub ahb: AHB,
@@ -44,6 +53,14 @@ pub struct Rcc {
4453
}
4554

4655
/// AMBA High-performance Bus (AHB) registers
56+
///
57+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
58+
///
59+
/// ```
60+
/// let dp = pac::Peripherals::take().unwrap();
61+
/// let rcc = dp.RCC.constrain();
62+
/// use_ahb(&mut rcc.ahb)
63+
/// ```
4764
pub struct AHB {
4865
_0: (),
4966
}
@@ -61,6 +78,14 @@ impl AHB {
6178
}
6279

6380
/// Advanced Peripheral Bus 1 (APB1) registers
81+
///
82+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
83+
///
84+
/// ```
85+
/// let dp = pac::Peripherals::take().unwrap();
86+
/// let rcc = dp.RCC.constrain();
87+
/// use_ahb(&mut rcc.apb1)
88+
/// ```
6489
pub struct APB1 {
6590
_0: (),
6691
}
@@ -78,6 +103,14 @@ impl APB1 {
78103
}
79104

80105
/// Advanced Peripheral Bus 2 (APB2) registers
106+
///
107+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
108+
///
109+
/// ```
110+
/// let dp = pac::Peripherals::take().unwrap();
111+
/// let rcc = dp.RCC.constrain();
112+
/// use_ahb(&mut rcc.apb2)
113+
/// ```
81114
pub struct APB2 {
82115
_0: (),
83116
}
@@ -158,6 +191,14 @@ mod usb_clocking {
158191
}
159192

160193
/// Clock configuration
194+
///
195+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
196+
///
197+
/// ```
198+
/// let dp = pac::Peripherals::take().unwrap();
199+
/// let rcc = dp.RCC.constrain();
200+
/// use_ahb(&mut rcc.cfgr)
201+
/// ```
161202
pub struct CFGR {
162203
hse: Option<u32>,
163204
hclk: Option<u32>,

0 commit comments

Comments
 (0)