stm32: use embedded_hal_1::delay::DelayNs

This makes delay compatible with https://lib.rs/crates/rtic-monotonics.
This commit is contained in:
Andres Vahter 2024-04-09 22:32:09 +03:00
parent c575c7dc6c
commit fd802ffdfd
6 changed files with 19 additions and 19 deletions

View File

@ -3,7 +3,7 @@ use core::marker::PhantomData;
use core::task::Poll;
use embassy_hal_internal::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
use crate::adc::{Adc, AdcPin, Instance, SampleTime};
use crate::time::Hertz;
@ -48,7 +48,7 @@ impl<T: Instance> super::SealedAdcPin<T> for Temperature {
}
impl<'d, T: Instance> Adc<'d, T> {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayNs) -> Self {
into_ref!(adc);
T::enable_and_reset();
T::regs().cr2().modify(|reg| reg.set_adon(true));
@ -95,7 +95,7 @@ impl<'d, T: Instance> Adc<'d, T> {
}
}
pub fn enable_vref(&self, _delay: &mut impl DelayUs<u32>) -> Vref {
pub fn enable_vref(&self, _delay: &mut impl DelayNs) -> Vref {
T::regs().cr2().modify(|reg| {
reg.set_tsvrefe(true);
});

View File

@ -3,7 +3,7 @@ use core::marker::PhantomData;
use core::task::Poll;
use embassy_hal_internal::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
use crate::adc::{Adc, AdcPin, Instance, SampleTime};
use crate::interrupt::typelevel::Interrupt;
@ -58,7 +58,7 @@ impl<'d, T: Instance> Adc<'d, T> {
pub fn new(
adc: impl Peripheral<P = T> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
delay: &mut impl DelayUs<u32>,
delay: &mut impl DelayNs,
) -> Self {
use crate::pac::adc::vals;
@ -117,7 +117,7 @@ impl<'d, T: Instance> Adc<'d, T> {
}
}
pub fn enable_vref(&self, _delay: &mut impl DelayUs<u32>) -> Vref {
pub fn enable_vref(&self, _delay: &mut impl DelayNs) -> Vref {
T::common_regs().ccr().modify(|w| w.set_vrefen(true));
Vref {}

View File

@ -3,7 +3,7 @@ use core::marker::PhantomData;
use core::task::Poll;
use embassy_hal_internal::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
#[cfg(adc_l0)]
use stm32_metapac::adc::vals::Ckmode;
@ -65,7 +65,7 @@ impl<'d, T: Instance> Adc<'d, T> {
pub fn new(
adc: impl Peripheral<P = T> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
delay: &mut impl DelayUs<u32>,
delay: &mut impl DelayNs,
) -> Self {
into_ref!(adc);
T::enable_and_reset();
@ -114,7 +114,7 @@ impl<'d, T: Instance> Adc<'d, T> {
}
#[cfg(not(adc_l0))]
pub fn enable_vbat(&self, _delay: &mut impl DelayUs<u32>) -> Vbat {
pub fn enable_vbat(&self, _delay: &mut impl DelayNs) -> Vbat {
// SMP must be ≥ 56 ADC clock cycles when using HSI14.
//
// 6.3.20 Vbat monitoring characteristics
@ -123,7 +123,7 @@ impl<'d, T: Instance> Adc<'d, T> {
Vbat
}
pub fn enable_vref(&self, delay: &mut impl DelayUs<u32>) -> Vref {
pub fn enable_vref(&self, delay: &mut impl DelayNs) -> Vref {
// Table 28. Embedded internal reference voltage
// tstart = 10μs
T::regs().ccr().modify(|reg| reg.set_vrefen(true));
@ -131,7 +131,7 @@ impl<'d, T: Instance> Adc<'d, T> {
Vref
}
pub fn enable_temperature(&self, delay: &mut impl DelayUs<u32>) -> Temperature {
pub fn enable_temperature(&self, delay: &mut impl DelayNs) -> Temperature {
// SMP must be ≥ 56 ADC clock cycles when using HSI14.
//
// 6.3.19 Temperature sensor characteristics

View File

@ -1,5 +1,5 @@
use embassy_hal_internal::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
use crate::adc::{Adc, AdcPin, Instance, Resolution, SampleTime};
use crate::peripherals::ADC1;
@ -97,7 +97,7 @@ impl<'d, T> Adc<'d, T>
where
T: Instance,
{
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayNs) -> Self {
into_ref!(adc);
T::enable_and_reset();

View File

@ -1,6 +1,6 @@
use cfg_if::cfg_if;
use embassy_hal_internal::into_ref;
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
use crate::adc::{Adc, AdcPin, Instance, Resolution, SampleTime};
use crate::Peripheral;
@ -74,7 +74,7 @@ cfg_if! {
}
impl<'d, T: Instance> Adc<'d, T> {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayNs) -> Self {
into_ref!(adc);
T::enable_and_reset();
T::regs().cr().modify(|reg| {
@ -106,7 +106,7 @@ impl<'d, T: Instance> Adc<'d, T> {
}
}
pub fn enable_vrefint(&self, delay: &mut impl DelayUs<u32>) -> VrefInt {
pub fn enable_vrefint(&self, delay: &mut impl DelayNs) -> VrefInt {
#[cfg(not(adc_g0))]
T::common_regs().ccr().modify(|reg| {
reg.set_vrefen(true);

View File

@ -1,4 +1,4 @@
use embedded_hal_02::blocking::delay::DelayUs;
use embedded_hal_1::delay::DelayNs;
#[allow(unused)]
use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel};
use pac::adccommon::vals::Presc;
@ -129,7 +129,7 @@ impl Prescaler {
impl<'d, T: Instance> Adc<'d, T> {
/// Create a new ADC driver.
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayUs<u16>) -> Self {
pub fn new(adc: impl Peripheral<P = T> + 'd, delay: &mut impl DelayNs) -> Self {
embassy_hal_internal::into_ref!(adc);
T::enable_and_reset();
@ -173,7 +173,7 @@ impl<'d, T: Instance> Adc<'d, T> {
s
}
fn power_up(&mut self, delay: &mut impl DelayUs<u16>) {
fn power_up(&mut self, delay: &mut impl DelayNs) {
T::regs().cr().modify(|reg| {
reg.set_deeppwd(false);
reg.set_advregen(true);