Skip to content

Commit 46f7918

Browse files
authored
Merge pull request #233 from braun-embedded/documentation
Update some documentation
2 parents 6e22cfb + 06d96f8 commit 46f7918

17 files changed

+180
-62
lines changed

src/gpio.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
//! peripheral, and is required to convert instances of [`Pin`] to a
55
//! [`GpioPin`], which provides the core GPIO API.
66
//!
7-
//! The GPIO peripheral is described in the user manual, chapter 9.
7+
//! The GPIO peripheral is described in the following user manuals:
8+
//! - LPC82x user manual, chapter 9
9+
//! - LPC84x user manual, chapter 12
810
//!
911
//! # Examples
1012
//!
@@ -177,6 +179,23 @@ impl GPIO<init_state::Enabled> {
177179
}
178180

179181
/// A pin used for general purpose I/O (GPIO)
182+
///
183+
/// You can get access to an instance of this struct by switching a pin to the
184+
/// GPIO state, using [`Pin::into_input_pin`] or [`Pin::into_output_pin`].
185+
///
186+
/// While in input mode, this struct implements the [`InputPin`] trait.
187+
///
188+
/// While in output mode, this struct implements the following traits:
189+
/// - [`OutputPin`]
190+
/// - [`StatefulOutputPin`]
191+
/// - [`ToggleableOutputPin`]
192+
///
193+
/// [`Pin::into_input_pin`]: ../pins/struct.Pin.html#method.into_input_pin
194+
/// [`Pin::into_output_pin`]: ../pins/struct.Pin.html#method.into_output_pin
195+
/// [`InputPin`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/digital/v2/trait.InputPin.html
196+
/// [`OutputPin`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/digital/v2/trait.OutputPin.html
197+
/// [`StatefulOutputPin`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/digital/v2/trait.StatefulOutputPin.html
198+
/// [`ToggleableOutputPin`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/digital/v2/trait.ToggleableOutputPin.html
180199
pub struct GpioPin<T, D> {
181200
token: pins::Token<T, init_state::Enabled>,
182201
_direction: D,

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
//! [`Peripherals`], which is the entry point to the whole API.
6161
//!
6262
//! [`Cargo.toml`]: https://github.com/lpc-rs/lpc8xx-hal/blob/master/Cargo.toml
63+
//! [`Peripherals`]: struct.Peripherals.html
6364
//!
6465
//!
6566
//! ## Examples
@@ -201,6 +202,9 @@ use embedded_hal as hal;
201202
/// make sure you know what you're doing. In specific terms, this means you
202203
/// should be fully aware of what your code does, and whether that is a valid
203204
/// use of the hardware.
205+
///
206+
/// [`Peripherals::take`]: #method.take
207+
/// [`Peripherals::steal`]: #method.steal
204208
#[allow(non_snake_case)]
205209
pub struct Peripherals {
206210
/// Pins that can be used for GPIO or other functions

src/pins.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! API to control pins
2+
//!
3+
//! The most important part of this API is [`Pin`]. Please refer to its
4+
//! documentation, to learn how to use this module.
5+
//!
6+
//! [`Pin`]: struct.Pin.html
27
38
mod gen;
49
mod pin;

src/pins/gen.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ macro_rules! pins {
1414
)*) => {
1515
/// Provides access to all pins
1616
///
17+
/// You can get access to an instance of this struct through
18+
///[`Peripherals`].
19+
///
1720
/// # Limitations
1821
///
1922
/// This struct currently provides access to all pins that can be
2023
/// available on an LPC8xx part. Please make sure that you are aware of
2124
/// which pins are actually available on your specific part, and only
2225
/// use those.
26+
///
27+
/// [`Peripherals`]: ../struct.Peripherals.html
2328
#[allow(missing_docs)]
2429
pub struct Pins {
2530
$(pub $field: Pin<$type, $default_state_ty>,)*
@@ -42,9 +47,10 @@ macro_rules! pins {
4247
$(
4348
/// Identifies a specific pin
4449
///
45-
/// Pins can be accessed via the field `pins` of [`swm::Parts`].
50+
/// This type is used as a type parameter on [`Pin`]. Check out
51+
/// [`Pin`]'s documentation for more information.
4652
///
47-
/// [`swm::Parts`]: ../swm/struct.Parts.html
53+
/// [`Pin`]: struct.Pin.html
4854
#[allow(non_camel_case_types)]
4955
pub struct $type(());
5056

src/pins/pin.rs

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,26 @@ use super::{
1212
/// Main API for controlling pins
1313
///
1414
/// `Pin` has two type parameters:
15-
/// - `T`, to indicate which specific pin this instance of `Pin` represents (so,
16-
/// [`PIO0_0`], [`PIO0_1`], and so on)
17-
/// - `S`, to indicate which state the represented pin is currently in
15+
/// - `T`, to indicate which specific pin this instance of `Pin` represents
16+
/// ([`PIO0_0`], [`PIO0_1`], and so on).
17+
/// - `S`, to indicate which state the represented pin is currently in.
1818
///
1919
/// A pin instance can be in one of the following states:
20-
/// - [`state::Unused`], to indicate that the pin is currently not used
21-
/// - [`state::Gpio`], to indicate that the pin is being used for
22-
/// general-purpose I/O
20+
/// - [`state::Unused`], to indicate that the pin is currently not used.
2321
/// - [`state::Swm`], to indicate that the pin is available for switch
24-
/// matrix function assignment
22+
/// matrix function assignment.
2523
/// - [`state::Analog`], to indicate that the pin is being used for analog
26-
/// input
24+
/// input.
25+
///
26+
/// A pin that is in the GPIO state is represented by its own struct,
27+
/// [`GpioPin`].
2728
///
2829
/// # State Management
2930
///
3031
/// All pins start out in their initial state, as defined in the user manual. To
31-
/// prevent us from making mistakes, only the methods that induce a valid state
32-
/// transition are available. Code that tries to call a method that would cause
33-
/// an invalid state transition will simply not compile:
32+
/// prevent the user from making a mistake, only the methods that induce a valid
33+
/// state transition are available. Code that tries to call a method that would
34+
/// cause an invalid state transition will simply not compile:
3435
///
3536
/// ``` no_run
3637
/// # use lpc8xx_hal::Peripherals;
@@ -51,10 +52,10 @@ use super::{
5152
/// &mut swm_handle,
5253
/// );
5354
///
54-
/// // As long as the function is assigned, we can't use the pin for
55-
/// // general-purpose I/O. Therefore the following method call would cause a
56-
/// // compile-time error.
57-
/// // let pio0_12 = pio0_12.into_gpio_pin(&p.GPIO);
55+
/// // As long as a function is assigned, we can't use the pin for general-
56+
/// // purpose I/O. Therefore the following method call would cause a compile-
57+
/// // time error.
58+
/// // let pio0_12 = pio0_12.into_input_pin(&p.GPIO);
5859
/// ```
5960
///
6061
/// To use the pin in the above example for GPIO, we first have to unassign the
@@ -78,10 +79,10 @@ use super::{
7879
/// # &mut swm_handle,
7980
/// # );
8081
/// #
81-
/// #[cfg(feature = "82x")]
82-
/// let gpio = p.GPIO;
83-
/// #[cfg(feature = "845")]
84-
/// let gpio = p.GPIO.enable(&mut syscon.handle);
82+
/// # #[cfg(feature = "82x")]
83+
/// # let gpio = p.GPIO;
84+
/// # #[cfg(feature = "845")]
85+
/// # let gpio = p.GPIO.enable(&mut syscon.handle);
8586
///
8687
/// let (clkout, pio0_12) = clkout.unassign(pio0_12, &mut swm_handle);
8788
/// let pio0_12 = pio0_12.into_unused_pin();
@@ -116,7 +117,7 @@ use super::{
116117
/// let pin = p.pins.pio0_12
117118
/// .into_swm_pin();
118119
///
119-
/// // Functions can be assigned now using the methods on `Function`
120+
/// // Functions can be assigned now using the SWM API
120121
/// ```
121122
///
122123
/// As mentioned above, a function can be fixed or movable. But there is also
@@ -132,7 +133,7 @@ use super::{
132133
/// topic, [please help us figure this out](https://github.com/lpc-rs/lpc8xx-hal/issues/44).
133134
///
134135
/// Once a pin is in the SWM state, you can assign functions to it. Please refer
135-
/// to [`Function`] for more information on how to do that.
136+
/// to the [SWM API] for more information on how to do that.
136137
///
137138
/// # Analog Input
138139
///
@@ -151,7 +152,7 @@ use super::{
151152
/// #[cfg(feature = "845")]
152153
/// let mut swm_handle = swm.handle.enable(&mut syscon.handle);
153154
///
154-
/// // Transition pin into ADC state
155+
/// // Transition pin to ADC state
155156
/// let (adc_2, pio0_14) = swm.fixed_functions.adc_2.assign(
156157
/// p.pins.pio0_14.into_swm_pin(),
157158
/// &mut swm_handle,
@@ -168,8 +169,7 @@ use super::{
168169
/// [`Pin::into_output_pin`]: struct.Pin.html#method.into_output_pin
169170
/// [`GpioPin`]: ../gpio/struct.GpioPin.html
170171
/// [`Pin::into_swm_pin`]: struct.Pin.html#method.into_swm_pin
171-
/// [`lpc82x::IOCON`]: https://docs.rs/lpc82x-pac/0.7.*/lpc82x_pac/struct.IOCON.html
172-
/// [`lpc82x::ADC`]: https://docs.rs/lpc82x-pac/0.7.*/lpc82x_pac/struct.ADC.html
172+
/// [SWM API]: ../swm/index.html
173173
pub struct Pin<T: Trait, S: State> {
174174
pub(crate) ty: T,
175175
pub(crate) _state: S,
@@ -180,6 +180,22 @@ where
180180
T: Trait,
181181
{
182182
/// Transition pin to GPIO input mode
183+
///
184+
/// This method is only available while the pin is in the unused state. Code
185+
/// that attempts to call this method while the pin is in any other state
186+
/// will not compile. See [State Management] for more information on
187+
/// managing pin states.
188+
///
189+
/// Consumes this `Pin` instance and returns an instance of [`GpioPin`],
190+
/// which provides access to all GPIO functions.
191+
///
192+
/// This method requires a GPIO token from the [`GPIO`] struct, to ensure
193+
/// that the GPIO peripheral is enabled, and stays enabled while the pin is
194+
/// in the GPIO mode.
195+
///
196+
/// [State Management]: #state-management
197+
/// [`GpioPin`]: ../gpio/struct.GpioPin.html
198+
/// [`GPIO`]: ../gpio/struct.GPIO.html
183199
pub fn into_input_pin(
184200
self,
185201
token: Token<T, init_state::Enabled>,
@@ -188,6 +204,22 @@ where
188204
}
189205

190206
/// Transition pin to GPIO output mode
207+
///
208+
/// This method is only available while the pin is in the unused state. Code
209+
/// that attempts to call this method while the pin is in any other state
210+
/// will not compile. See [State Management] for more information on
211+
/// managing pin states.
212+
///
213+
/// Consumes this `Pin` instance and returns an instance of [`GpioPin`],
214+
/// which provides access to all GPIO functions.
215+
///
216+
/// This method requires a GPIO token from the [`GPIO`] struct, to ensure
217+
/// that the GPIO peripheral is enabled, and stays enabled while the pin is
218+
/// in the GPIO mode.
219+
///
220+
/// [State Management]: #state-management
221+
/// [`GpioPin`]: ../gpio/struct.GpioPin.html
222+
/// [`GPIO`]: ../gpio/struct.GPIO.html
191223
pub fn into_output_pin(
192224
self,
193225
token: Token<T, init_state::Enabled>,
@@ -196,7 +228,7 @@ where
196228
GpioPin::new(token, initial)
197229
}
198230

199-
/// Transition pin to SWM state
231+
/// Transition pin to SWM mode
200232
///
201233
/// This method is only available while the pin is in the unused state. Code
202234
/// that attempts to call this method while the pin is in any other state
@@ -206,7 +238,8 @@ where
206238
/// Consumes this pin instance and returns a new instance that is in the SWM
207239
/// state, making this pin available for switch matrix function assignment.
208240
///
209-
/// Please refer [`Function`] to learn more about SWM function assignment.
241+
/// Please refer to the [SWM API] to learn more about SWM function
242+
/// assignment.
210243
///
211244
/// # Example
212245
///
@@ -222,6 +255,7 @@ where
222255
/// ```
223256
///
224257
/// [State Management]: #state-management
258+
/// [SWM API]: ../swm/index.html
225259
pub fn into_swm_pin(self) -> Pin<T, state::Swm<(), ()>> {
226260
Pin {
227261
ty: self.ty,

src/pins/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ impl State for Analog {}
4242
/// functions have been assigned to a pin:
4343
///
4444
/// - `Output` tracks whether an output function has been assigned. Zero or
45-
/// one output functions can be assigned to a pin.
45+
/// one output functions can be assigned to a pin at a time.
4646
/// - `Inputs` tracks the number of assigned input functions. Any number of
4747
/// input functions can be assigned to a pin at the same time.
4848
///
4949
/// Both type parameters use nested tuples to count the number of assigned
50-
/// functions. The empty tuple (`()`) represents zero assigned functions,
51-
/// the empty tuple nested in another tuple (`((),)`) represents one
50+
/// functions. The empty tuple, `()`, represents zero assigned functions,
51+
/// the empty tuple nested in another tuple, `((),)`, represents one
5252
/// function being assigned, `(((),))` represents two assigned functions,
5353
/// and so forth. This is a bit of a hack, of course, but it should do until
5454
/// [const generics] become available.

src/swm.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
//! The entry point to this API is [`SWM`]. Please refer to [`SWM`]'s
44
//! documentation for additional information.
55
//!
6-
//! The switch matrix is described in the user manual, chapter 7.
6+
//! The switch matrix is described in the following user manuals:
7+
//! - LPC82x user manual, chapter 7
8+
//! - LPC84x user manual, chapter 10
9+
//!
10+
//! [`SWM`]: struct.SWM.html
711
812
pub mod state;
913

@@ -17,8 +21,9 @@ mod peripheral;
1721

1822
pub use self::{
1923
fixed_functions::*,
24+
function_kind::{Analog, FunctionKind, Input, Output},
2025
functions::{Function, FunctionTrait},
2126
handle::Handle,
2227
movable_functions::*,
23-
peripheral::SWM,
28+
peripheral::{Parts, SWM},
2429
};

src/swm/fixed_functions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ macro_rules! fixed_functions {
3838
$(
3939
/// Represents a fixed function
4040
///
41-
/// Fixed functions can be accessed via the field `fixed_functions`
42-
/// of [`swm::Parts`].
41+
/// Fixed functions can be accessed through [`FixedFunctions`].
4342
///
44-
/// [`swm::Parts`]: struct.Parts.html
43+
/// [`FixedFunctions`]: struct.FixedFunctions.html
4544
#[allow(non_camel_case_types)]
4645
pub struct $type(());
4746

src/swm/functions.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ use super::{
1414
/// The type parameter `T` identifies the fixed or movable function that an
1515
/// instance of `Function` controls. The other type paramter, `State`, tracks
1616
/// whether this function is assigned to a pin, and which pin it is assigned to.
17+
///
18+
/// You can gain access to the instances of this struct that represent fixed
19+
/// functions through [`FixedFunctions`], to those that represent movable
20+
/// functions through [`MovableFunctions`].
21+
///
22+
/// [`FixedFunctions`]: struct.FixedFunctions.html
23+
/// [`MovableFunctions`]: struct.MovableFunctions.html
1724
pub struct Function<T, S> {
1825
ty: T,
1926
_state: S,
@@ -41,7 +48,7 @@ impl<T> Function<T, Unassigned> {
4148
/// documentation on [`Pin`] for information on pin state management.
4249
/// - The function must be assignable to the pin. Movable functions can be
4350
/// assigned to any pin, but fixed functions can be assigned to only one
44-
/// pin.
51+
/// specific pin.
4552
/// - The state of the pin must allow another function of this type to be
4653
/// assigned. Input functions can always be assigned, but only one output
4754
/// or bidirectional function can be assigned to a given pin at any time.
@@ -86,6 +93,8 @@ impl<T> Function<T, Unassigned> {
8693
/// ```
8794
///
8895
/// [`Unassigned`]: state/struct.Unassigned.html
96+
/// [`Pin`]: ../pins/struct.Pin.html
97+
/// [`pins::state::Swm`]: ../pins/state/struct.Swm.html
8998
pub fn assign<P, S>(
9099
mut self,
91100
mut pin: Pin<P, S>,
@@ -164,6 +173,8 @@ impl<T, P> Function<T, Assigned<P>> {
164173
/// ```
165174
///
166175
/// [`Assigned`]: state/struct.Assigned.html
176+
/// [`Pin`]: ../pins/struct.Pin.html
177+
/// [`pins::state::Swm`]: ../pins/state/struct.Swm.html
167178
pub fn unassign<S>(
168179
mut self,
169180
mut pin: Pin<P, S>,
@@ -197,6 +208,9 @@ impl<T, P> Function<T, Assigned<P>> {
197208
///
198209
/// Please refer [`Function::assign`] and [`Function::unassign`] for the public
199210
/// API that uses this trait.
211+
///
212+
/// [`Function::assign`]: struct.Function.html#method.assign
213+
/// [`Function::unassign`]: struct.Function.html#method.unassign
200214
pub trait FunctionTrait<P: pins::Trait> {
201215
/// Whether this is an input or output function
202216
///

0 commit comments

Comments
 (0)