Skip to content

Commit 8b9e273

Browse files
committed
improve rcc and gpio docs
1 parent 2ea16b4 commit 8b9e273

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/gpio.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
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 register.
15+
//!
16+
//! To use a pin, first use the relevant `into_...` function in 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](../prelude/trait._embedded_hal_digital_InputPin.html) or [OutputPin](../prelude/trait._embedded_hal_digital_OutputPin.html) traits in
23+
//! `embedded_hal`
224
325
use core::convert::Infallible;
426
use core::marker::PhantomData;

src/rcc.rs

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

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

4653
/// AMBA High-performance Bus (AHB) registers
54+
///
55+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
56+
///
57+
/// ```
58+
/// let dp = pac::Peripherals::take().unwrap();
59+
/// let rcc = dp.RCC.constrain();
60+
/// use_ahb(&mut rcc.ahb)
61+
/// ```
4762
pub struct AHB {
4863
_0: (),
4964
}
@@ -61,6 +76,14 @@ impl AHB {
6176
}
6277

6378
/// Advanced Peripheral Bus 1 (APB1) registers
79+
///
80+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
81+
///
82+
/// ```
83+
/// let dp = pac::Peripherals::take().unwrap();
84+
/// let rcc = dp.RCC.constrain();
85+
/// use_ahb(&mut rcc.apb1)
86+
/// ```
6487
pub struct APB1 {
6588
_0: (),
6689
}
@@ -78,6 +101,14 @@ impl APB1 {
78101
}
79102

80103
/// Advanced Peripheral Bus 2 (APB2) registers
104+
///
105+
/// An instance of this struct is aquired from the [Rcc](../struct.Rcc.html) struct.
106+
///
107+
/// ```
108+
/// let dp = pac::Peripherals::take().unwrap();
109+
/// let rcc = dp.RCC.constrain();
110+
/// use_ahb(&mut rcc.apb2)
111+
/// ```
81112
pub struct APB2 {
82113
_0: (),
83114
}
@@ -159,6 +190,14 @@ mod usb_clocking {
159190
}
160191

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

0 commit comments

Comments
 (0)