Skip to content

Commit 001adeb

Browse files
Improve & unify documentation for implemented embededd-hal traits
As proposed in lpc-rs#233 (comment)
1 parent 46f7918 commit 001adeb

File tree

11 files changed

+86
-25
lines changed

11 files changed

+86
-25
lines changed

src/adc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ use crate::{
4949
///
5050
/// Please refer to the [module documentation] for more information.
5151
///
52+
/// # `embedded-hal` traits
53+
/// - [`embedded_hal::adc::OneShot`] for measuring the voltage on a pin
54+
///
5255
/// [`Peripherals`]: ../struct.Peripherals.html
5356
/// [module documentation]: index.html
57+
/// [`embedded_hal::adc::OneShot`]: #impl-OneShot%3CADC%3CEnabled%3C()%3E%3E%2C%20u16%2C%20PIN%3E
5458
pub struct ADC<State = init_state::Enabled> {
5559
adc: pac::ADC0,
5660
_state: State,
@@ -153,6 +157,7 @@ where
153157
{
154158
type Error = ();
155159

160+
/// Request that the ADC begin a conversion on the specified pin
156161
fn read(&mut self, _: &mut PIN) -> nb::Result<u16, Self::Error> {
157162
// Start the measurement of the given channel
158163
// Follows the description in the um

src/ctimer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ pub struct DetachedPwmPin<CTOutput> {
8181
}
8282

8383
/// Represents a pwm channel assigned to an output pin
84+
///
85+
/// # `embedded-hal` traits
86+
/// - [`embedded_hal::PwmPin`]
87+
///
88+
/// [`embedded_hal::PwmPin`]: #impl-PwmPin
8489
pub struct CTimerPwmPin {
8590
mr: RegProxy<MR>,
8691
msr: RegProxy<MSR>,
@@ -195,14 +200,17 @@ impl PwmPin for CTimerPwmPin {
195200
// and would involve a hidden `CriticalSection`
196201
fn disable(&mut self) {}
197202

203+
/// Returns the current duty cycle
198204
fn get_duty(&self) -> Self::Duty {
199205
self.msr[self.number as usize].read().match_shadow().bits()
200206
}
201207

208+
/// Returns the maximum duty cycle value
202209
fn get_max_duty(&self) -> Self::Duty {
203210
self.mr[3].read().match_().bits()
204211
}
205212

213+
/// Sets a new duty cycle
206214
fn set_duty(&mut self, duty: Self::Duty) {
207215
unsafe {
208216
self.msr[self.number as usize]

src/delay.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ const SYSTICK_RANGE: u32 = 0x0100_0000;
2929
const SYSTEM_CLOCK: u32 = 12_000_000;
3030

3131
/// System timer (SysTick) as a delay provider
32+
///
33+
/// # `embedded-hal` traits
34+
/// - [`embedded_hal::blocking::delay::DelayUs`]
35+
/// - [`embedded_hal::blocking::delay::DelayMs`]
36+
///
37+
/// [`embedded_hal::blocking::delay::DelayUs`]: #impl-DelayUs%3Cu32%3E
38+
/// [`embedded_hal::blocking::delay::DelayMs`]: #impl-DelayMs%3Cu32%3E
3239
#[derive(Clone)]
3340
pub struct Delay {
3441
scale: u32,
@@ -52,6 +59,7 @@ impl Delay {
5259
}
5360

5461
impl DelayMs<u32> for Delay {
62+
/// Pauses execution for `ms` milliseconds
5563
// At 30 MHz (the maximum frequency), calling delay_us with ms * 1_000 directly overflows at 0x418937 (over the max u16 value)
5664
// So we implement a separate, higher level, delay loop
5765
fn delay_ms(&mut self, mut ms: u32) {
@@ -65,6 +73,7 @@ impl DelayMs<u32> for Delay {
6573
}
6674

6775
impl DelayMs<u16> for Delay {
76+
/// Pauses execution for `ms` milliseconds
6877
fn delay_ms(&mut self, ms: u16) {
6978
// Call delay_us directly, since we don't have to use the additional
7079
// delay loop the u32 variant uses
@@ -73,13 +82,15 @@ impl DelayMs<u16> for Delay {
7382
}
7483

7584
impl DelayMs<u8> for Delay {
85+
/// Pauses execution for `ms` milliseconds
7686
fn delay_ms(&mut self, ms: u8) {
7787
self.delay_ms(ms as u16);
7888
}
7989
}
8090

8191
// At 30MHz (the maximum frequency), this overflows at approx. 2^32 / 30 = 146 seconds
8292
impl DelayUs<u32> for Delay {
93+
/// Pauses execution for `us` milliseconds
8394
fn delay_us(&mut self, us: u32) {
8495
// The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
8596
// Here half the maximum is used so we have some play if there's a long running interrupt.
@@ -108,12 +119,14 @@ impl DelayUs<u32> for Delay {
108119
}
109120

110121
impl DelayUs<u16> for Delay {
122+
/// Pauses execution for `us` milliseconds
111123
fn delay_us(&mut self, us: u16) {
112124
self.delay_us(us as u32)
113125
}
114126
}
115127

116128
impl DelayUs<u8> for Delay {
129+
/// Pauses execution for `us` milliseconds
117130
fn delay_us(&mut self, us: u8) {
118131
self.delay_us(us as u32)
119132
}

src/gpio.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,20 @@ impl GPIO<init_state::Enabled> {
183183
/// You can get access to an instance of this struct by switching a pin to the
184184
/// GPIO state, using [`Pin::into_input_pin`] or [`Pin::into_output_pin`].
185185
///
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`]
186+
/// # `embedded-hal` traits
187+
/// - While in input mode
188+
/// - [`embedded_hal::digital::v2::InputPin`] for reading the pin state
189+
/// - While in output mode
190+
/// - [`embedded_hal::digital::v2::OutputPin`] for setting the pin state
191+
/// - [`embedded_hal::digital::v2::StatefulOutputPin`] for reading the pin output state
192+
/// - [`embedded_hal::digital::v2::ToggleableOutputPin`] for toggling the pin state
192193
///
193194
/// [`Pin::into_input_pin`]: ../pins/struct.Pin.html#method.into_input_pin
194195
/// [`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
196+
/// [`embedded_hal::digital::v2::InputPin`]: #impl-InputPin
197+
/// [`embedded_hal::digital::v2::OutputPin`]: #impl-OutputPin
198+
/// [`embedded_hal::digital::v2::StatefulOutputPin`]: #impl-StatefulOutputPin
199+
/// [`embedded_hal::digital::v2::ToggleableOutputPin`]: #impl-ToggleableOutputPin
199200
pub struct GpioPin<T, D> {
200201
token: pins::Token<T, init_state::Enabled>,
201202
_direction: D,

src/i2c.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ use crate::{
8181
/// Additional limitations are documented on the specific methods that they
8282
/// apply to.
8383
///
84+
/// # `embedded-hal` traits
85+
/// - [`embedded_hal::blocking::i2c::Read`] for synchronous reading
86+
/// - [`embedded_hal::blocking::i2c::Write`] for synchronous writing
87+
///
88+
/// [`embedded_hal::blocking::i2c::Read`]: #impl-Read
89+
/// [`embedded_hal::blocking::i2c::Write`]: #impl-Write
8490
/// [module documentation]: index.html
8591
pub struct I2C<I, State = init_state::Enabled> {
8692
i2c: I,

src/mrt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ impl MRT {
5959
pub const MAX_VALUE: u32 = 0x7fff_ffff - 1;
6060

6161
/// Represents a MRT0 channel
62+
///
63+
/// # `embedded-hal` traits
64+
/// - [`embedded_hal::timer::CountDown`]
65+
///
66+
/// [`embedded_hal::timer::CountDown`]: #impl-CountDown
6267
pub struct Channel<T: Reg>(RegProxy<T>);
6368

6469
impl<T> Channel<T>
@@ -109,6 +114,7 @@ where
109114
.write(|w| unsafe { w.ivalue().bits(reload + 1) });
110115
}
111116

117+
/// Non-blockingly "waits" until the count down finishes
112118
fn wait(&mut self) -> Result<(), Void> {
113119
if self.0.stat.read().intflag().is_pending_interrupt() {
114120
// Reset the interrupt flag

src/spi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,17 @@ use crate::{
7575
///
7676
/// Please refer to the [module documentation] for more information.
7777
///
78+
/// # `embedded-hal` traits
79+
///
80+
/// - [`embedded_hal::spi::FullDuplex`] for asynchronous transfers
81+
/// - [`embedded_hal::blocking::spi::Transfer`] for synchronous transfers
82+
/// - [`embedded_hal::blocking::spi::Write`] for synchronous writes
83+
///
7884
/// [`Peripherals`]: ../struct.Peripherals.html
7985
/// [module documentation]: index.html
86+
/// [`embedded_hal::spi::FullDuplex`]: #impl-FullDuplex%3Cu8%3E
87+
/// [`embedded_hal::blocking::spi::Transfer`]: #impl-Transfer%3CW%3E
88+
/// [`embedded_hal::blocking::spi::Write`]: #impl-Write%3CW%3E
8089
pub struct SPI<I, State = init_state::Enabled> {
8190
spi: I,
8291
_state: State,

src/usart/peripheral.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ use super::{
3030
/// same place, or you can move the `rx` and `tx` fields out of this struct, to
3131
/// use the sender and receiver from different contexts.
3232
///
33-
/// This struct implement the following traits:
34-
/// - [`embedded_hal::serial::Read`]
35-
/// - [`embedded_hal::serial::Write`]
36-
/// - [`embedded_hal::blocking::serial::Write`]
37-
///
3833
/// Please refer to the [module documentation] for more information.
3934
///
35+
/// # `embedded-hal` traits
36+
/// - [`embedded_hal::serial::Read`] for asynchronous receiving
37+
/// - [`embedded_hal::serial::Write`] for asynchronous sending
38+
/// - [`embedded_hal::blocking::serial::Write`] for synchronous sending
39+
///
40+
///
4041
/// [`Peripherals`]: ../struct.Peripherals.html
41-
/// [`embedded_hal::serial::Read`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/serial/trait.Read.html
42-
/// [`embedded_hal::serial::Write`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/serial/trait.Write.html
43-
/// [`embedded_hal::blocking::serial::Write`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/blocking/serial/trait.Write.html
4442
/// [module documentation]: index.html
43+
/// [`embedded_hal::serial::Read`]: #impl-Read%3Cu8%3E
44+
/// [`embedded_hal::serial::Write`]: #impl-Write%3Cu8%3E
45+
/// [`embedded_hal::blocking::serial::Write`]: #impl-Write
4546
pub struct USART<I, State = init_state::Enabled> {
4647
/// The USART Receiver
4748
pub rx: Rx<I, State>,
@@ -267,6 +268,7 @@ where
267268
{
268269
type Error = Error;
269270

271+
/// Reads a single word from the serial interface
270272
fn read(&mut self) -> nb::Result<u8, Self::Error> {
271273
self.rx.read()
272274
}
@@ -278,10 +280,12 @@ where
278280
{
279281
type Error = Void;
280282

283+
/// Writes a single word to the serial interface
281284
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
282285
self.tx.write(word)
283286
}
284287

288+
/// Ensures that none of the previously written words are still buffered
285289
fn flush(&mut self) -> nb::Result<(), Self::Error> {
286290
self.tx.flush()
287291
}
@@ -297,6 +301,7 @@ where
297301
Self: BlockingWriteDefault<u8>,
298302
I: Instance,
299303
{
304+
/// Writes a string slice into this writer, returning whether the write succeeded.
300305
fn write_str(&mut self, s: &str) -> fmt::Result {
301306
self.tx.write_str(s)
302307
}

src/usart/rx.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use super::instances::Instance;
66

77
/// USART receiver
88
///
9-
/// This struct implements the [`embedded_hal::serial::Read`] trait.
9+
/// # `embedded-hal` traits
10+
/// - [`embedded_hal::serial::Read`] for asynchronous receiving
1011
///
11-
/// [`embedded_hal::serial::Read`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/serial/trait.Read.html
12+
///
13+
/// [`embedded_hal::serial::Read`]: #impl-Read%3Cu8%3E
1214
pub struct Rx<I, State = init_state::Enabled> {
1315
_instance: PhantomData<I>,
1416
_state: PhantomData<State>,

src/usart/tx.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use super::instances::Instance;
1212

1313
/// USART transmitter
1414
///
15-
/// This struct implements the following traits:
16-
/// - [`embedded_hal::serial::Write`]
17-
/// - [`embedded_hal::blocking::serial::Write`]
15+
/// # `embedded-hal` traits
16+
/// - [`embedded_hal::serial::Write`] for asynchronous sending
17+
/// - [`embedded_hal::blocking::serial::Write`] for synchronous receiving
1818
///
19-
/// [`embedded_hal::serial::Write`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/serial/trait.Write.html
20-
/// [`embedded_hal::blocking::serial::Write`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/blocking/serial/trait.Write.html
19+
/// [`embedded_hal::serial::Write`]: #impl-Write%3Cu8%3E
20+
/// [`embedded_hal::blocking::serial::Write`]: #impl-Write
2121
pub struct Tx<I, State = init_state::Enabled> {
2222
_instance: PhantomData<I>,
2323
_state: PhantomData<State>,

0 commit comments

Comments
 (0)