@@ -12,25 +12,26 @@ use super::{
12
12
/// Main API for controlling pins
13
13
///
14
14
/// `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.
18
18
///
19
19
/// 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.
23
21
/// - [`state::Swm`], to indicate that the pin is available for switch
24
- /// matrix function assignment
22
+ /// matrix function assignment.
25
23
/// - [`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`].
27
28
///
28
29
/// # State Management
29
30
///
30
31
/// 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:
34
35
///
35
36
/// ``` no_run
36
37
/// # use lpc8xx_hal::Peripherals;
@@ -51,10 +52,10 @@ use super::{
51
52
/// &mut swm_handle,
52
53
/// );
53
54
///
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);
58
59
/// ```
59
60
///
60
61
/// To use the pin in the above example for GPIO, we first have to unassign the
@@ -78,10 +79,10 @@ use super::{
78
79
/// # &mut swm_handle,
79
80
/// # );
80
81
/// #
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);
85
86
///
86
87
/// let (clkout, pio0_12) = clkout.unassign(pio0_12, &mut swm_handle);
87
88
/// let pio0_12 = pio0_12.into_unused_pin();
@@ -116,7 +117,7 @@ use super::{
116
117
/// let pin = p.pins.pio0_12
117
118
/// .into_swm_pin();
118
119
///
119
- /// // Functions can be assigned now using the methods on `Function`
120
+ /// // Functions can be assigned now using the SWM API
120
121
/// ```
121
122
///
122
123
/// As mentioned above, a function can be fixed or movable. But there is also
@@ -132,7 +133,7 @@ use super::{
132
133
/// topic, [please help us figure this out](https://github.com/lpc-rs/lpc8xx-hal/issues/44).
133
134
///
134
135
/// 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.
136
137
///
137
138
/// # Analog Input
138
139
///
@@ -151,7 +152,7 @@ use super::{
151
152
/// #[cfg(feature = "845")]
152
153
/// let mut swm_handle = swm.handle.enable(&mut syscon.handle);
153
154
///
154
- /// // Transition pin into ADC state
155
+ /// // Transition pin to ADC state
155
156
/// let (adc_2, pio0_14) = swm.fixed_functions.adc_2.assign(
156
157
/// p.pins.pio0_14.into_swm_pin(),
157
158
/// &mut swm_handle,
@@ -168,8 +169,7 @@ use super::{
168
169
/// [`Pin::into_output_pin`]: struct.Pin.html#method.into_output_pin
169
170
/// [`GpioPin`]: ../gpio/struct.GpioPin.html
170
171
/// [`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
173
173
pub struct Pin < T : Trait , S : State > {
174
174
pub ( crate ) ty : T ,
175
175
pub ( crate ) _state : S ,
@@ -180,6 +180,22 @@ where
180
180
T : Trait ,
181
181
{
182
182
/// 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
183
199
pub fn into_input_pin (
184
200
self ,
185
201
token : Token < T , init_state:: Enabled > ,
@@ -188,6 +204,22 @@ where
188
204
}
189
205
190
206
/// 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
191
223
pub fn into_output_pin (
192
224
self ,
193
225
token : Token < T , init_state:: Enabled > ,
@@ -196,7 +228,7 @@ where
196
228
GpioPin :: new ( token, initial)
197
229
}
198
230
199
- /// Transition pin to SWM state
231
+ /// Transition pin to SWM mode
200
232
///
201
233
/// This method is only available while the pin is in the unused state. Code
202
234
/// that attempts to call this method while the pin is in any other state
@@ -206,7 +238,8 @@ where
206
238
/// Consumes this pin instance and returns a new instance that is in the SWM
207
239
/// state, making this pin available for switch matrix function assignment.
208
240
///
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.
210
243
///
211
244
/// # Example
212
245
///
@@ -222,6 +255,7 @@ where
222
255
/// ```
223
256
///
224
257
/// [State Management]: #state-management
258
+ /// [SWM API]: ../swm/index.html
225
259
pub fn into_swm_pin ( self ) -> Pin < T , state:: Swm < ( ) , ( ) > > {
226
260
Pin {
227
261
ty : self . ty ,
0 commit comments