Skip to content

Commit 413a33e

Browse files
author
Brandon Matthews
committed
Rename Once to OneShot; add docs
1 parent 5421446 commit 413a33e

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

src/adc.rs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,62 @@
22
33
use nb;
44

5-
/// This trait denotes an object, e.g. a GPIO pin, that is configured for use as an ADC channel.
6-
/// Objects of this type are passed to ADC-mode-specific methods.
5+
/// A marker trait to identify MCU pins that can be used as inputs to an ADC channel.
6+
///
7+
/// This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the
8+
/// ADC. As ADCs channels can be supplied by multiple pins, this trait defines the relationship
9+
/// between the physical interface and the ADC sampling buffer.
710
pub trait AdcChannel {
811
/// Channel ID type
912
///
10-
/// e.g. u8 for ADC channels 1-n, or a (partid, pinid) tuple for something more complex.
13+
/// A type used to identify this ADC channel. For example, if the ADC has eight channels, this
14+
/// might be a `u8`. If the ADC has multiple banks of channels, it could be a tuple, like
15+
/// `(u8: bank_id, u8: channel_id)`.
1116
type ID;
1217

13-
/// ID of the channel associated with this pin
18+
/// The specific ID that identifies this channel, for example `0` for the first ADC channel.
1419
const CHANNEL: Self::ID;
1520
}
1621

1722
/// ADCs that sample on single channels per request, and do so at the time of the request.
18-
pub trait Once<Word, Pin: AdcChannel> {
23+
///
24+
/// This trait is the interface to an ADC that is configured to read a specific channel at the time
25+
/// of the request (in contrast to continuous asynchronous sampling).
26+
pub trait OneShot<Word, Pin: AdcChannel> {
1927
/// Error type returned by ADC methods
2028
type Error;
2129

22-
/// Take an analog reading from the specified pin
30+
/// Request that the ADC begin a conversion on the specified pin
31+
///
32+
/// This method takes a `Pin` reference, as it is expected that the ADC will be able to sample
33+
/// whatever channel underlies the pin.
2334
fn read_channel(&mut self, pin: &mut Pin) -> nb::Result<Word, Self::Error>;
2435
}
2536

26-
/// ADCs that sample continuously without requiring requests
37+
/// ADCs that sample continuously or asynchrounously
38+
///
39+
/// This trait is the interface to an ADC that is configured to sample one or more `Pin`s on a
40+
/// regular and recurring basis, without requiring that the channel be sampled at the time of the
41+
/// request.
2742
pub trait Continuous<Word, Pin: AdcChannel> {
2843
/// Error type returned by ADC methods
2944
type Error;
3045

31-
/// Take ownership of an ADC channel/pin
32-
fn add_channel(&mut self, pin: Pin) -> nb::Result<(), Self::Error>;
46+
/// Add a `Pin` (and its channel) to those that are to be sampled
47+
///
48+
/// This method moves the Pin, and configures the ADC to include this pin's channel in those
49+
/// that it will sample asynchronously.
50+
fn add_pin(&mut self, pin: Pin) -> nb::Result<(), Self::Error>;
3351

34-
/// Release the ADC channel/pin
35-
fn release_channel(&mut self, id: Pin::ID) -> nb::Result<Pin, Self::Error>;
52+
/// Remove the specified channel from those sampled, and release its pin.
53+
///
54+
/// This method removes the channel identified by `id` from the channels that the ADC
55+
/// asynchronously samples. It then releases the `Pin` and returns it to the user.
56+
fn release_pin(&mut self, id: Pin::ID) -> nb::Result<Pin, Self::Error>;
3657

3758
/// Start a continuous conversion cycle
59+
///
60+
/// This starts the ADC sampling its configured channels continuously.
3861
fn start(&mut self) -> nb::Result<(), Self::Error>;
3962

4063
/// Stop conversions.
@@ -43,8 +66,14 @@ pub trait Continuous<Word, Pin: AdcChannel> {
4366
fn stop(&mut self) -> nb::Result<(), Self::Error>;
4467

4568
/// Read the specified channel
69+
///
70+
/// Read the most recently sampled value for the specified channel.
4671
fn read(&mut self, chan: Pin::ID) -> nb::Result<Word, Self::Error>;
4772
}
4873

49-
/// Run conversions in a burst that does not automatically loop or repeat
74+
/// ADCs that sample a set of channels in a "burst" that does not loop or repeat
75+
///
76+
/// This trait is the interface to an ADC that is configured to read from multiple channels
77+
/// beginning at the time of the request. Unlike `Continuous`, the channels are only read once, and
78+
/// then the conversions stop.
5079
pub trait Burst<Word, Pin: AdcChannel> : Continuous<Word, Pin> {}

0 commit comments

Comments
 (0)