Skip to content

Commit 77557ad

Browse files
committed
ADC takes impl Into<DynPclk>
1 parent b1c04c9 commit 77557ad

3 files changed

Lines changed: 10 additions & 18 deletions

File tree

boards/examples/m4-adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> ! {
4444
let apb_adc0 = buses.apb.enable(tokens.apbs.adc0);
4545
// ...and enable the ADC0 PCLK. Both of these are required for the
4646
// ADC to run.
47-
let (pclk_adc0, _gclk0) = Pclk::enable_dyn(tokens.pclks.adc0, clocks.gclk0);
47+
let (pclk_adc0, _gclk0) = Pclk::enable(tokens.pclks.adc0, clocks.gclk0);
4848

4949
let mut adc = AdcBuilder::new(Accumulation::single(atsamd_hal::adc::AdcResolution::_12))
5050
.with_clock_cycles_per_sample(5)

hal/src/peripherals/adc/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,19 @@ impl AdcBuilder {
244244
Ok(adc_clk_freq / clocks_per_sample)
245245
}
246246

247-
/// Turn the builder into an ADC
247+
/// Turn the builder into an ADC.
248+
///
249+
/// This function will convert the provided [`Pclk`](crate::clock::v2::pclk::Pclk) into a [`DynPclk`].
248250
#[hal_cfg("adc-d5x")]
249251
#[inline]
250252
pub fn enable<I: AdcInstance>(
251253
self,
252254
adc: I::Instance,
253255
clk: crate::clock::v2::apb::ApbClk<I::ClockId>,
254-
pclk: crate::clock::v2::pclk::Pclk<I::ClockId, crate::clock::v2::pclk::DynPclkSourceId>,
256+
pclk: impl Into<crate::clock::v2::pclk::DynPclk<I::ClockId>>,
255257
) -> Result<Adc<I>, BuilderError> {
256258
let settings = self.to_settings()?;
257-
Adc::new(adc, settings, clk, pclk).map_err(|e| e.into())
259+
Adc::new(adc, settings, clk, pclk.into()).map_err(|e| e.into())
258260
}
259261

260262
#[hal_cfg(any("adc-d11", "adc-d21"))]

hal/src/peripherals/adc/mod.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ pub use builder::*;
4949
use crate::pac::adc as adc0;
5050
#[hal_cfg("adc-d5x")]
5151
use crate::{
52-
clock::v2::{
53-
apb::ApbClk,
54-
pclk::{DynPclkSourceId, Pclk},
55-
},
52+
clock::v2::{apb::ApbClk, pclk::DynPclk},
5653
pac::adc0,
5754
};
5855

@@ -181,7 +178,7 @@ pub struct Adc<I: AdcInstance> {
181178
pub struct Adc<I: AdcInstance> {
182179
adc: I::Instance,
183180
_apbclk: ApbClk<I::ClockId>,
184-
_pclk: Pclk<I::ClockId, DynPclkSourceId>,
181+
_pclk: DynPclk<I::ClockId>,
185182
cfg: AdcSettings,
186183
discard: bool,
187184
}
@@ -214,7 +211,7 @@ impl<I: AdcInstance> Adc<I> {
214211
adc: I::Instance,
215212
settings: AdcSettings,
216213
clk: ApbClk<I::ClockId>,
217-
pclk: Pclk<I::ClockId, DynPclkSourceId>,
214+
pclk: DynPclk<I::ClockId>,
218215
) -> Result<Self, Error> {
219216
// TODO: Ideally, the ADC struct would take ownership of the Pclk type here.
220217
// However, since clock::v2 is not implemented for all chips yet, the
@@ -430,15 +427,8 @@ impl<I: AdcInstance> Adc<I> {
430427

431428
/// Return the underlying ADC PAC object and the enabled APB ADC clock.
432429
#[hal_cfg("adc-d5x")]
433-
#[allow(clippy::type_complexity)]
434430
#[inline]
435-
pub fn free(
436-
mut self,
437-
) -> (
438-
I::Instance,
439-
ApbClk<I::ClockId>,
440-
Pclk<I::ClockId, DynPclkSourceId>,
441-
) {
431+
pub fn free(mut self) -> (I::Instance, ApbClk<I::ClockId>, DynPclk<I::ClockId>) {
442432
self.software_reset();
443433
(self.adc, self._apbclk, self._pclk)
444434
}

0 commit comments

Comments
 (0)