Skip to content

Commit f511312

Browse files
authored
Merge pull request #177 from korken89/more_adc
ADC available on all supported MCUs
2 parents db6cb3f + fce9695 commit f511312

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/adc.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ use crate::{
1212
rcc::{AHB2, CCIPR},
1313
};
1414

15+
#[cfg(any(feature = "stm32l4x1", feature = "stm32l4x2", feature = "stm32l4x3",))]
16+
use pac::ADC as ADC1;
17+
18+
#[cfg(any(feature = "stm32l4x5", feature = "stm32l4x6"))]
19+
use pac::ADC1;
20+
1521
/// Analog to Digital converter interface
1622
pub struct ADC {
17-
inner: pac::ADC,
23+
inner: ADC1,
1824
resolution: Resolution,
1925
sample_time: SampleTime,
2026
}
2127

2228
impl ADC {
2329
/// Initialize the ADC
2430
pub fn new(
25-
inner: pac::ADC,
31+
inner: ADC1,
2632
ahb: &mut AHB2,
2733
ccipr: &mut CCIPR,
2834
delay: &mut impl DelayUs<u32>,
@@ -88,7 +94,7 @@ impl ADC {
8894
///
8995
/// Drops `ADC` and returns the `pac::ADC` that is was wrapping, giving the
9096
/// user full access to the peripheral.
91-
pub fn release(self) -> pac::ADC {
97+
pub fn release(self) -> ADC1 {
9298
self.inner
9399
}
94100
}
@@ -202,7 +208,7 @@ impl Default for SampleTime {
202208

203209
/// Implemented for all types that represent ADC channels
204210
pub trait Channel: EmbeddedHalChannel<ADC, ID = u8> {
205-
fn set_sample_time(&mut self, adc: &pac::ADC, sample_time: SampleTime);
211+
fn set_sample_time(&mut self, adc: &ADC1, sample_time: SampleTime);
206212
}
207213

208214
macro_rules! external_channels {
@@ -225,7 +231,7 @@ macro_rules! external_channels {
225231

226232
impl Channel for crate::gpio::$pin<Analog> {
227233
fn set_sample_time(&mut self,
228-
adc: &pac::ADC,
234+
adc: &ADC1,
229235
sample_time: SampleTime,
230236
) {
231237
adc.$smpr.modify(|_, w| {

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ pub use crate::pac as stm32;
6060

6161
pub mod traits;
6262

63-
#[cfg(feature = "stm32l4x3")]
63+
#[cfg(any(
64+
feature = "stm32l4x1",
65+
feature = "stm32l4x2",
66+
feature = "stm32l4x3",
67+
feature = "stm32l4x5",
68+
feature = "stm32l4x6"
69+
))]
6470
pub mod adc;
6571
#[cfg(any(
6672
feature = "stm32l4x1",

0 commit comments

Comments
 (0)