diff --git a/Cargo.toml b/Cargo.toml index 1f0494c8..9b816bc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,14 @@ repository = "https://github.com/stm32-rs/stm32g4xx-hal" version = "0.0.2" [dependencies] -nb = "0.1.1" +nb = "1" stm32g4 = "0.15.1" paste = "1.0" bitflags = "1.2" vcell = "0.1" static_assertions = "1.1" fugit = "0.3.5" +embedded-io = "0.6" [dependencies.cortex-m] version = "0.7.7" @@ -36,9 +37,13 @@ default-features = false features = ["const-fn"] version = "0.2.5" -[dependencies.embedded-hal] +[dependencies.embedded-hal-old] +package = "embedded-hal" features = ["unproven"] -version = "0.2.4" +version = "0.2.7" + +[dependencies.embedded-hal] +version = "1.0.0" [dependencies.embedded-dma] version = "0.1.2" @@ -88,7 +93,7 @@ stm32g4a1 = ["stm32g4/stm32g4a1"] log-itm = ["cortex-m-log/itm"] log-rtt = [] log-semihost = ["cortex-m-log/semihosting"] -defmt-logging = ["defmt"] +defmt-logging = ["defmt", "nb/defmt-0-3", "embedded-hal/defmt-03", "embedded-io/defmt-03"] [profile.dev] codegen-units = 1 diff --git a/examples/adc-continious-dma.rs b/examples/adc-continious-dma.rs index e7ceb824..e53224d5 100644 --- a/examples/adc-continious-dma.rs +++ b/examples/adc-continious-dma.rs @@ -2,6 +2,7 @@ #![no_main] mod utils; +use utils::logger::info; use crate::hal::{ adc::{ @@ -9,18 +10,19 @@ use crate::hal::{ config::{Continuous, Dma as AdcDma, SampleTime, Sequence}, AdcClaim, ClockSource, Temperature, Vref, }, - delay::SYSTDelayExt, + delay::DelayFromCountDownTimer, dma::{config::DmaConfig, stream::DMAExt, TransferExt}, gpio::GpioExt, pwr::PwrExt, rcc::{Config, RccExt}, signature::{VrefCal, VDDA_CALIB}, stm32::Peripherals, + time::ExtU32, + timer::Timer, }; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use utils::logger::info; #[entry] fn main() -> ! { @@ -29,7 +31,7 @@ fn main() -> ! { info!("start"); let dp = Peripherals::take().unwrap(); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); info!("rcc"); let rcc = dp.RCC.constrain(); @@ -47,7 +49,10 @@ fn main() -> ! { let pa0 = gpioa.pa0.into_analog(); info!("Setup Adc1"); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let mut adc = dp .ADC1 .claim(ClockSource::SystemClock, &rcc, &mut delay, true); diff --git a/examples/adc-continious.rs b/examples/adc-continious.rs index 53f12e1a..95e8c6e6 100644 --- a/examples/adc-continious.rs +++ b/examples/adc-continious.rs @@ -6,12 +6,14 @@ use crate::hal::{ config::{Continuous, Resolution, SampleTime, Sequence}, AdcClaim, ClockSource, Temperature, Vref, }, - delay::SYSTDelayExt, + delay::DelayFromCountDownTimer, gpio::GpioExt, pwr::PwrExt, rcc::{Config, RccExt}, signature::{VrefCal, VDDA_CALIB}, stm32::Peripherals, + time::ExtU32, + timer::Timer, }; use stm32g4xx_hal as hal; @@ -29,7 +31,7 @@ fn main() -> ! { info!("start"); let dp = Peripherals::take().unwrap(); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); info!("rcc"); @@ -42,7 +44,10 @@ fn main() -> ! { let pa0 = gpioa.pa0.into_analog(); info!("Setup Adc1"); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let mut adc = dp .ADC1 .claim(ClockSource::SystemClock, &rcc, &mut delay, true); diff --git a/examples/adc-one-shot-dma.rs b/examples/adc-one-shot-dma.rs index 898e7f02..53430d09 100644 --- a/examples/adc-one-shot-dma.rs +++ b/examples/adc-one-shot-dma.rs @@ -8,19 +8,20 @@ use crate::hal::{ config::{Continuous, Dma as AdcDma, Resolution, SampleTime, Sequence}, AdcClaim, ClockSource, Temperature, }, - delay::SYSTDelayExt, + delay::DelayFromCountDownTimer, dma::{config::DmaConfig, stream::DMAExt, TransferExt}, gpio::GpioExt, pwr::PwrExt, rcc::{Config, RccExt}, stm32::Peripherals, + time::ExtU32, + timer::Timer, }; use stm32g4xx_hal as hal; -use log::info; - #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { @@ -29,7 +30,7 @@ fn main() -> ! { info!("start"); let dp = Peripherals::take().unwrap(); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); info!("rcc"); @@ -48,7 +49,10 @@ fn main() -> ! { let pa0 = gpioa.pa0.into_analog(); info!("Setup Adc1"); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let mut adc = dp .ADC1 .claim(ClockSource::SystemClock, &rcc, &mut delay, true); diff --git a/examples/adc-one-shot.rs b/examples/adc-one-shot.rs index 7e727430..39a74cf2 100644 --- a/examples/adc-one-shot.rs +++ b/examples/adc-one-shot.rs @@ -3,20 +3,21 @@ use crate::hal::{ adc::{config::SampleTime, AdcClaim}, - delay::SYSTDelayExt, + delay::DelayFromCountDownTimer, pwr::PwrExt, rcc::Config, stm32::Peripherals, + time::ExtU32, + timer::Timer, }; use hal::prelude::*; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use log::info; - #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { @@ -25,7 +26,7 @@ fn main() -> ! { info!("start"); let dp = Peripherals::take().unwrap(); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); info!("rcc"); @@ -34,7 +35,10 @@ fn main() -> ! { let mut rcc = rcc.freeze(Config::hsi(), pwr); info!("Setup Adc1"); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let mut adc = dp.ADC2.claim_and_configure( stm32g4xx_hal::adc::ClockSource::SystemClock, &rcc, diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs index 7e815c4c..115c0ef9 100644 --- a/examples/blinky_delay.rs +++ b/examples/blinky_delay.rs @@ -3,6 +3,7 @@ #![no_main] #![no_std] +use embedded_hal::delay::DelayNs; use hal::delay::DelayFromCountDownTimer; use hal::prelude::*; use hal::pwr::PwrExt; @@ -47,6 +48,6 @@ fn main() -> ! { info!("Toggle"); led.toggle().unwrap(); info!("TIM2 delay"); - delay_tim2.delay_ms(1000_u16); + delay_tim2.delay_ms(1000); } } diff --git a/examples/button.rs b/examples/button.rs index f119b6a8..ef7990ec 100644 --- a/examples/button.rs +++ b/examples/button.rs @@ -14,7 +14,7 @@ use core::cell::RefCell; use core::sync::atomic::{AtomicBool, Ordering}; use cortex_m::{asm::wfi, interrupt::Mutex}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; type ButtonPin = gpioc::PC13>; diff --git a/examples/can-echo.rs b/examples/can-echo.rs index 53ba01bf..1bb6d0b2 100644 --- a/examples/can-echo.rs +++ b/examples/can-echo.rs @@ -22,10 +22,9 @@ use core::num::{NonZeroU16, NonZeroU8}; use cortex_m_rt::entry; -use log::info; - #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { @@ -116,7 +115,7 @@ fn main() -> ! { bit_rate_switching: false, marker: None, }; - info!("Initial Header: {:#X?}", &header); + info!("Initial Header: {:#?}", &header); info!("Transmit initial message"); block!(can.transmit(header, &buffer)).unwrap(); diff --git a/examples/comp_w_dac.rs b/examples/comp_w_dac.rs index 63b0f4ec..b5d1d605 100644 --- a/examples/comp_w_dac.rs +++ b/examples/comp_w_dac.rs @@ -18,20 +18,25 @@ fn main() -> ! { #[cfg(feature = "stm32g474")] #[entry] fn main() -> ! { - use embedded_hal::Direction; + use embedded_hal_old::Direction; use hal::comparator::{self, ComparatorExt, ComparatorSplit}; use hal::dac::{Dac1IntSig1, DacExt, DacOut}; - use hal::delay::SYSTDelayExt; + use hal::delay::DelayFromCountDownTimer; use hal::gpio::GpioExt; use hal::rcc::RccExt; use hal::stm32; + use hal::time::ExtU32; + use hal::timer::Timer; use stm32g4xx_hal as hal; let dp = stm32::Peripherals::take().expect("cannot take peripherals"); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); let mut rcc = dp.RCC.constrain(); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let gpioa = dp.GPIOA.split(&mut rcc); diff --git a/examples/dac.rs b/examples/dac.rs index 7348f703..d4c6923e 100644 --- a/examples/dac.rs +++ b/examples/dac.rs @@ -8,11 +8,13 @@ #![no_main] #![no_std] -use embedded_hal::Direction; +use embedded_hal_old::Direction; use hal::dac::{DacExt, DacOut, GeneratorConfig}; -use hal::delay::SYSTDelayExt; +use hal::delay::DelayFromCountDownTimer; use hal::gpio::GpioExt; use hal::rcc::RccExt; +use hal::time::ExtU32; +use hal::timer::Timer; use stm32g4xx_hal as hal; mod utils; extern crate cortex_m_rt as rt; @@ -23,10 +25,14 @@ use rt::entry; #[entry] fn main() -> ! { let dp = stm32::Peripherals::take().expect("cannot take peripherals"); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); let mut rcc = dp.RCC.constrain(); - let mut delay = cp.SYST.delay(&rcc.clocks); + // cortex-m doesn't yet support hal-1 DelayNs on systick (PR #504) + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let gpioa = dp.GPIOA.split(&mut rcc); let (dac1ch1, dac1ch2) = dp.DAC1.constrain((gpioa.pa4, gpioa.pa5), &mut rcc); diff --git a/examples/i2c-bme680.rs b/examples/i2c-bme680.rs index 2fa8a9c0..f3f18033 100644 --- a/examples/i2c-bme680.rs +++ b/examples/i2c-bme680.rs @@ -5,7 +5,7 @@ use bme680::*; use core::time::Duration; -use embedded_hal::blocking::delay::DelayMs; +use embedded_hal::delay::DelayNs; use hal::delay::DelayFromCountDownTimer; use hal::i2c::Config; use hal::prelude::*; @@ -15,10 +15,10 @@ use hal::timer::Timer; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use log::info; #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { diff --git a/examples/i2c-mpu6050.rs b/examples/i2c-mpu6050.rs index a0be9c10..a9bf69ad 100644 --- a/examples/i2c-mpu6050.rs +++ b/examples/i2c-mpu6050.rs @@ -10,11 +10,11 @@ use hal::time::{ExtU32, RateExtU32}; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use log::info; use mpu6050::*; #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { diff --git a/examples/i2c.rs b/examples/i2c.rs index 78104767..beea9ae2 100644 --- a/examples/i2c.rs +++ b/examples/i2c.rs @@ -10,10 +10,10 @@ use hal::time::RateExtU32; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use log::info; #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { @@ -35,7 +35,7 @@ fn main() -> ! { let buf: [u8; 1] = [0]; loop { - match i2c.write(0x3c, &buf) { + match i2c.write(0x3Cu8, &buf) { Ok(_) => info!("ok"), Err(err) => info!("error: {:?}", err), } diff --git a/examples/opamp.rs b/examples/opamp.rs index 00175a8e..cbd9742b 100644 --- a/examples/opamp.rs +++ b/examples/opamp.rs @@ -3,16 +3,21 @@ #![no_std] #![no_main] -use stm32g4xx_hal::adc::AdcClaim; -use stm32g4xx_hal::adc::ClockSource; -use stm32g4xx_hal::gpio::gpioa::*; -use stm32g4xx_hal::gpio::Analog; -use stm32g4xx_hal::opamp::opamp1::IntoPga as _; -use stm32g4xx_hal::opamp::opamp2::IntoPga as _; -use stm32g4xx_hal::opamp::NonInvertingGain; -use stm32g4xx_hal::opamp::PgaModeInternal; -use stm32g4xx_hal::prelude::*; -use stm32g4xx_hal::pwr::PwrExt; +use stm32g4xx_hal as hal; + +use hal::adc::AdcClaim; +use hal::adc::ClockSource; +use hal::delay::DelayFromCountDownTimer; +use hal::gpio::gpioa::*; +use hal::gpio::Analog; +use hal::opamp::opamp1::IntoPga as _; +use hal::opamp::opamp2::IntoPga as _; +use hal::opamp::NonInvertingGain; +use hal::opamp::PgaModeInternal; +use hal::prelude::*; +use hal::pwr::PwrExt; +use hal::time::ExtU32; +use hal::timer::Timer; use utils::logger::info; @@ -25,7 +30,7 @@ fn main() -> ! { // take peripherals let dp = stm32g4xx_hal::stm32::Peripherals::take().unwrap(); - let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); + // let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals"); // setup clock and power let pwr = dp.PWR.constrain().freeze(); @@ -66,7 +71,10 @@ fn main() -> ! { Option::>::None, // Do not route output to any external pin, use internal AD instead ); - let mut delay = cp.SYST.delay(&rcc.clocks); + // let mut delay = cp.SYST.delay(&rcc.clocks); + let mut delay = DelayFromCountDownTimer::new( + Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), + ); let mut adc = dp .ADC2 .claim(ClockSource::SystemClock, &rcc, &mut delay, true); diff --git a/examples/pwm.rs b/examples/pwm.rs index 9d2ca8e8..cee8f7d7 100644 --- a/examples/pwm.rs +++ b/examples/pwm.rs @@ -11,6 +11,7 @@ use hal::stm32; use hal::time::RateExtU32; use stm32g4xx_hal as hal; extern crate cortex_m_rt as rt; +use hal::prelude::SetDutyCycle; #[macro_use] mod utils; @@ -26,7 +27,7 @@ fn main() -> ! { let mut pwm = dp.TIM1.pwm(pin, 100.Hz(), &mut rcc); - pwm.set_duty(pwm.get_max_duty() / 2); + let _ = pwm.set_duty_cycle_percent(50); pwm.enable(); loop { diff --git a/examples/spi-dma.rs b/examples/spi-dma.rs index 04533e3f..dcfff763 100644 --- a/examples/spi-dma.rs +++ b/examples/spi-dma.rs @@ -28,6 +28,7 @@ use stm32g4xx_hal::dma::TransferExt; #[macro_use] mod utils; +// use utils::logger::info; const BUFFER_SIZE: usize = 254; @@ -68,6 +69,6 @@ fn main() -> ! { .into_memory_to_peripheral_transfer(spi.enable_tx_dma(), &mut dma_buf[..], config); transfer_dma.start(|_spi| {}); loop { - delay_tim2.delay_ms(1000_u16); + delay_tim2.delay_ms(1000); } } diff --git a/examples/spi-example.rs b/examples/spi-example.rs index 2543e3fc..a661e248 100644 --- a/examples/spi-example.rs +++ b/examples/spi-example.rs @@ -5,14 +5,14 @@ #![no_main] #![no_std] -use crate::hal::{ - block, +use hal::{ delay::DelayFromCountDownTimer, gpio::gpioa::PA5, gpio::gpioa::PA6, gpio::gpioa::PA7, gpio::Alternate, gpio::AF5, + hal_02::spi::FullDuplex, prelude::*, pwr::PwrExt, rcc::Config, @@ -59,11 +59,11 @@ fn main() -> ! { for byte in message.iter() { cs.set_low().unwrap(); spi.send(*byte as u8).unwrap(); - received_byte = block!(spi.read()).unwrap(); + received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap(); cs.set_high().unwrap(); info!("{}", received_byte as char); } - delay_tim2.delay_ms(1000_u16); + delay_tim2.delay_ms(1000); } } diff --git a/examples/uart-dma-tx.rs b/examples/uart-dma-tx.rs index 78abeb4f..bc92922a 100644 --- a/examples/uart-dma-tx.rs +++ b/examples/uart-dma-tx.rs @@ -16,10 +16,10 @@ use hal::{rcc, stm32}; use stm32g4xx_hal as hal; use cortex_m_rt::entry; -use log::info; #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { diff --git a/examples/uart-fifo.rs b/examples/uart-fifo.rs index eb6ddb88..74084b97 100644 --- a/examples/uart-fifo.rs +++ b/examples/uart-fifo.rs @@ -12,12 +12,14 @@ use hal::pwr::PwrExt; use hal::serial::*; use hal::{rcc, stm32}; use stm32g4xx_hal as hal; +// TODO: switch to embedded-hal-nb +use hal::hal_02::serial::Read; use cortex_m_rt::entry; -use log::info; #[macro_use] mod utils; +use utils::logger::info; #[entry] fn main() -> ! { diff --git a/examples/uart.rs b/examples/uart.rs index 883ef3b7..a7154f39 100644 --- a/examples/uart.rs +++ b/examples/uart.rs @@ -3,8 +3,7 @@ #![no_main] #![no_std] -use core::fmt::Write; - +use embedded_io::{Read, Write}; use hal::prelude::*; use hal::pwr::PwrExt; use hal::serial::FullConfig; @@ -54,10 +53,13 @@ fn main() -> ! { .unwrap(); writeln!(usart, "Hello USART3, yay!!\r\n").unwrap(); + let mut read_buf = [0u8; 8]; + usart.read_exact(&mut read_buf).unwrap(); + usart.write_all(&read_buf).unwrap(); let mut cnt = 0; loop { - match block!(usart.read()) { + match block!(embedded_hal_old::serial::Read::read(&mut usart)) { Ok(byte) => writeln!(usart, "{}: {}\r", cnt, byte).unwrap(), Err(e) => writeln!(usart, "E: {:?}\r", e).unwrap(), }; diff --git a/src/adc.rs b/src/adc.rs index 2a0b4310..07e0ba98 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -1,5 +1,5 @@ //! Analog to digital converter configuration. -//! https://github.com/stm32-rs/stm32l4xx-hal/blob/master/src/adc.rs +//! #![deny(missing_docs)] @@ -20,10 +20,8 @@ use crate::{ }; use core::fmt; use core::marker::PhantomData; -use embedded_hal::{ - adc::{Channel, OneShot}, - blocking::delay::DelayUs, -}; +use embedded_hal::delay::DelayNs; +use embedded_hal_old::adc::{Channel, OneShot}; use self::config::ExternalTrigger12; @@ -168,7 +166,7 @@ macro_rules! adc_op_follower { /// Contains types related to ADC configuration pub mod config { - use embedded_hal::adc::Channel; + use embedded_hal_old::adc::Channel; /// The place in the sequence a given channel should be captured #[derive(Debug, PartialEq, PartialOrd, Copy, Clone)] @@ -312,7 +310,8 @@ pub mod config { pub enum ClockMode { /// (Asynchronous clock mode), adc_ker_ck. generated at product level (refer to Section 6: Reset and clock control (RCC) Asynchronous, - /// (Synchronous clock mode). adc_hclk/1 This configuration must be enabled only if the AHB clock prescaler is set to 1 (HPRE[3:0] = 0xxx in RCC_CFGR register) and if the system clock has a 50% duty cycle. + /// (Synchronous clock mode). adc_hclk/1 + /// This configuration must be enabled only if the AHB clock prescaler is set to 1 (HPRE\[3:0\] = 0xxx in RCC_CFGR register) and if the system clock has a 50% duty cycle. Synchronous_Div_1, /// Synchronous clock mode. adc_hclk/2 Synchronous_Div_2, @@ -1168,9 +1167,9 @@ impl Conversion { !self.is_active() } - /// Converts from Conversion to Option. + /// Converts from `Conversion` to `Option`. /// - /// Converts self into an Option, consuming self, and discarding the adc, if it is stopped. + /// Converts self into an `Option`, consuming self, and discarding the adc, if it is stopped. #[inline(always)] pub fn active(self) -> Option> { match self { @@ -1179,9 +1178,9 @@ impl Conversion { } } - /// Converts from Conversion to Option. + /// Converts from `Conversion` to `Option`. /// - /// Converts self into an Option, consuming self, and discarding the adc, if it is still active. + /// Converts self into an `Option`, consuming self, and discarding the adc, if it is still active. #[inline(always)] pub fn stopped(self) -> Option> { match self { @@ -1381,7 +1380,7 @@ pub trait AdcClaim { self, cs: ClockSource, rcc: &Rcc, - delay: &mut impl DelayUs, + delay: &mut impl DelayNs, reset: bool, ) -> Adc; @@ -1391,7 +1390,7 @@ pub trait AdcClaim { cs: ClockSource, rcc: &Rcc, config: config::AdcConfig, - delay: &mut impl DelayUs, + delay: &mut impl DelayNs, reset: bool, ) -> Adc; } @@ -1583,7 +1582,7 @@ macro_rules! adc { /// Powers-up an powered-down Adc #[inline(always)] - pub fn power_up(&mut self, delay: &mut impl DelayUs) { + pub fn power_up(&mut self, delay: &mut impl DelayNs) { if self.is_deeppwd_enabled() { self.disable_deeppwd_down(); } @@ -1616,7 +1615,7 @@ macro_rules! adc { /// Enables the Voltage Regulator #[inline(always)] - pub fn enable_vreg(&mut self, delay: &mut impl DelayUs) { + pub fn enable_vreg(&mut self, delay: &mut impl DelayNs) { self.adc_reg.cr.modify(|_, w| w.advregen().set_bit()); while !self.adc_reg.cr.read().advregen().bit_is_set() {} @@ -2125,7 +2124,7 @@ macro_rules! adc { /// /// TODO: fix needing SYST #[inline(always)] - fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayUs, reset: bool) -> Adc { + fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayNs, reset: bool) -> Adc { unsafe { let rcc_ptr = &(*stm32::RCC::ptr()); stm32::$adc_type::enable(rcc_ptr); @@ -2149,7 +2148,7 @@ macro_rules! adc { /// claims and configures the Adc #[inline(always)] - fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig<$trigger_type>, delay: &mut impl DelayUs, reset :bool) -> Adc { + fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig<$trigger_type>, delay: &mut impl DelayNs, reset :bool) -> Adc { let mut adc = self.claim(cs, rcc, delay, reset); adc.adc.config = config; @@ -2173,7 +2172,7 @@ macro_rules! adc { impl Adc { /// Powers-up an powered-down Adc #[inline(always)] - pub fn power_up(mut self, delay: &mut impl DelayUs) -> Adc { + pub fn power_up(mut self, delay: &mut impl DelayNs) -> Adc { self.adc.power_up(delay); Adc { diff --git a/src/dac.rs b/src/dac.rs index 109374c0..5289da29 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -12,7 +12,7 @@ use crate::gpio::gpioa::{PA4, PA5, PA6}; use crate::gpio::DefaultMode; use crate::rcc::{self, *}; use crate::stm32::{DAC1, DAC2, DAC3, DAC4, RCC}; -use hal::blocking::delay::DelayUs; +use embedded_hal::delay::DelayNs; pub trait DacOut { fn set_value(&mut self, val: V); @@ -230,9 +230,9 @@ macro_rules! dac_helper { /// /// After the calibration operation, the DAC channel is /// disabled. - pub fn calibrate_buffer(self, delay: &mut T) -> $CX + pub fn calibrate_buffer(self, delay: &mut D) -> $CX where - T: DelayUs, + D: DelayNs { let dac = unsafe { &(*<$DAC>::ptr()) }; dac.dac_cr.modify(|_, w| w.$en().clear_bit()); diff --git a/src/delay.rs b/src/delay.rs index f40ffeae..417208b6 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -1,9 +1,9 @@ //! Delay providers //! //! There are currently two delay providers. In general you should prefer to use -//! [Delay](Delay), however if you do not have access to `SYST` you can use -//! [DelayFromCountDownTimer](DelayFromCountDownTimer) with any timer that -//! implements the [CountDown](embedded_hal::timer::CountDown) trait. This can be +//! [Delay], however if you do not have access to `SYST` you can use +//! [DelayFromCountDownTimer] with any timer that +//! implements the [CountDown](embedded_hal_old::timer::CountDown) trait. This can be //! useful if you're using [RTIC](https://rtic.rs)'s schedule API, which occupies //! the `SYST` peripheral. //! @@ -40,12 +40,14 @@ use crate::rcc::Clocks; use crate::time::MicroSecond; pub use cortex_m::delay::*; use cortex_m::peripheral::SYST; +use fugit::ExtU32Ceil; use crate::nb::block; use crate::time::ExtU32; -use embedded_hal::blocking::delay::{DelayMs, DelayUs}; +use embedded_hal::delay::DelayNs; +use embedded_hal_old::blocking::delay::{DelayMs, DelayUs}; -pub trait CountDown: embedded_hal::timer::CountDown { +pub trait CountDown: embedded_hal_old::timer::CountDown { fn max_period(&self) -> MicroSecond; } @@ -132,7 +134,7 @@ macro_rules! impl_delay_from_count_down_timer { T: CountDown