Skip to content

Commit c03b4a5

Browse files
committed
Add adc::Channel
This makes it possible to add channel-specific code to this trait, which is required for some features, like setting the sampling time, or internal channels.
1 parent 38dc9f4 commit c03b4a5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/adc.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::convert::Infallible;
55
use crate::{
66
gpio::Analog,
77
hal::{
8-
adc::{Channel, OneShot},
8+
adc::{Channel as EmbeddedHalChannel, OneShot},
99
blocking::delay::DelayUs,
1010
},
1111
pac,
@@ -88,7 +88,7 @@ impl ADC {
8888

8989
impl<C> OneShot<ADC, u16, C> for ADC
9090
where
91-
C: Channel<ADC, ID = u8>,
91+
C: Channel,
9292
{
9393
type Error = Infallible;
9494

@@ -154,6 +154,9 @@ impl Default for Resolution {
154154
}
155155
}
156156

157+
/// Implemented for all types that represent ADC channels
158+
pub trait Channel: EmbeddedHalChannel<ADC, ID = u8> {}
159+
157160
macro_rules! external_channels {
158161
(
159162
$(
@@ -162,13 +165,15 @@ macro_rules! external_channels {
162165
)*
163166
) => {
164167
$(
165-
impl Channel<ADC> for crate::gpio::$pin<Analog> {
168+
impl EmbeddedHalChannel<ADC> for crate::gpio::$pin<Analog> {
166169
type ID = u8;
167170

168171
fn channel() -> Self::ID {
169172
$id
170173
}
171174
}
175+
176+
impl Channel for crate::gpio::$pin<Analog> {}
172177
)*
173178
};
174179
}

0 commit comments

Comments
 (0)