2
2
3
3
use nb;
4
4
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.
7
10
pub trait AdcChannel {
8
11
/// Channel ID type
9
12
///
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)`.
11
16
type ID ;
12
17
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.
14
19
const CHANNEL : Self :: ID ;
15
20
}
16
21
17
22
/// 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 > {
19
27
/// Error type returned by ADC methods
20
28
type Error ;
21
29
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.
23
34
fn read_channel ( & mut self , pin : & mut Pin ) -> nb:: Result < Word , Self :: Error > ;
24
35
}
25
36
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.
27
42
pub trait Continuous < Word , Pin : AdcChannel > {
28
43
/// Error type returned by ADC methods
29
44
type Error ;
30
45
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 > ;
33
51
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 > ;
36
57
37
58
/// Start a continuous conversion cycle
59
+ ///
60
+ /// This starts the ADC sampling its configured channels continuously.
38
61
fn start ( & mut self ) -> nb:: Result < ( ) , Self :: Error > ;
39
62
40
63
/// Stop conversions.
@@ -43,8 +66,14 @@ pub trait Continuous<Word, Pin: AdcChannel> {
43
66
fn stop ( & mut self ) -> nb:: Result < ( ) , Self :: Error > ;
44
67
45
68
/// Read the specified channel
69
+ ///
70
+ /// Read the most recently sampled value for the specified channel.
46
71
fn read ( & mut self , chan : Pin :: ID ) -> nb:: Result < Word , Self :: Error > ;
47
72
}
48
73
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.
50
79
pub trait Burst < Word , Pin : AdcChannel > : Continuous < Word , Pin > { }
0 commit comments