From 1632cfdc71fb988464479e4c9a0aaad84c651b45 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Tue, 6 Aug 2024 12:39:23 +0200 Subject: [PATCH 1/2] Refactoring e-h 0.2 traits --- Cargo.toml | 3 +- src/adc.rs | 13 ++++----- src/dac.rs | 2 +- src/delay.rs | 31 ++++++++++---------- src/gpio.rs | 2 +- src/gpio/hal_02.rs | 56 +++++++++++++++++++++++-------------- src/i2c.rs | 7 ++--- src/independent_watchdog.rs | 4 --- src/lib.rs | 2 +- src/prelude.rs | 2 +- src/pwm.rs | 5 ++-- src/qei.rs | 9 +++--- src/rng.rs | 3 +- src/sai/i2s.rs | 1 - src/serial.rs | 18 ++++++------ src/spi.rs | 20 ++++++------- src/system_watchdog.rs | 5 ++-- src/timer.rs | 15 ++++++---- 18 files changed, 99 insertions(+), 99 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dcef60b5..6a4a2f4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] fugit = "0.3.5" -embedded-hal = { version = "0.2.6", features = ["unproven"] } +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } +embedded-hal-1 = { package = "embedded-hal", version = "1" } embedded-dma = "0.2.0" cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] } defmt = { version = ">=0.2.0,<0.4", optional = true } diff --git a/src/adc.rs b/src/adc.rs index 2acb56f1..efa74d87 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -11,8 +11,7 @@ //! - [Using ADC1 and ADC2 in parallel](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/adc12_parallel.rs) //! - [Using ADC1 through DMA](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/adc_dma.rs) -use crate::hal::adc::{Channel, OneShot}; -use crate::hal::blocking::delay::DelayUs; +use embedded_hal_02::blocking::delay::DelayUs; use core::convert::Infallible; use core::marker::PhantomData; @@ -189,7 +188,7 @@ impl AdcCalLinear { macro_rules! adc_pins { ($ADC:ident, $($input:ty => $chan:expr),+ $(,)*) => { $( - impl Channel<$ADC> for $input { + impl embedded_hal_02::adc::Channel<$ADC> for $input { type ID = u8; fn channel() -> u8 { @@ -823,7 +822,7 @@ macro_rules! adc_hal { /// The value can be then read through the `read_sample` method. // Refer to RM0433 Rev 7 - Chapter 25.4.16 pub fn start_conversion(&mut self, _pin: &mut PIN) - where PIN: Channel<$ADC, ID = u8>, + where PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>, { let chan = PIN::channel(); assert!(chan <= 19); @@ -841,7 +840,7 @@ macro_rules! adc_hal { /// This method starts a conversion sequence with DMA /// enabled. The DMA mode selected depends on the [`AdcDmaMode`] specified. pub fn start_conversion_dma(&mut self, _pin: &mut PIN, mode: AdcDmaMode) - where PIN: Channel<$ADC, ID = u8>, + where PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>, { let chan = PIN::channel(); assert!(chan <= 19); @@ -1112,10 +1111,10 @@ macro_rules! adc_hal { } } - impl OneShot<$ADC, WORD, PIN> for Adc<$ADC, Enabled> + impl embedded_hal_02::adc::OneShot<$ADC, WORD, PIN> for Adc<$ADC, Enabled> where WORD: From, - PIN: Channel<$ADC, ID = u8>, + PIN: embedded_hal_02::adc::Channel<$ADC, ID = u8>, { type Error = (); diff --git a/src/dac.rs b/src/dac.rs index 0617739b..1f16be95 100644 --- a/src/dac.rs +++ b/src/dac.rs @@ -9,7 +9,7 @@ use core::marker::PhantomData; use core::mem::MaybeUninit; use crate::gpio::{self, Analog}; -use crate::hal::blocking::delay::DelayUs; +use crate::hal_02::blocking::delay::DelayUs; use crate::rcc::{rec, ResetEnable}; #[cfg(not(feature = "rm0455"))] use crate::stm32::DAC as DAC1; diff --git a/src/delay.rs b/src/delay.rs index 31478806..c7a8d3bd 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -40,10 +40,6 @@ use cast::u32; use cortex_m::peripheral::syst::SystClkSource; use cortex_m::peripheral::SYST; -use embedded_hal::{ - blocking::delay::{DelayMs, DelayUs}, - timer::CountDown, -}; use void::Void; use crate::nb::block; @@ -110,7 +106,7 @@ impl<'a> Countdown<'a> { } } -impl<'a> CountDown for Countdown<'a> { +impl<'a> embedded_hal_02::timer::CountDown for Countdown<'a> { type Time = fugit::MicrosDurationU32; fn start(&mut self, count: T) @@ -163,25 +159,26 @@ impl Delay { } } -impl DelayMs for Delay { +impl embedded_hal_02::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u32) { + use embedded_hal_02::blocking::delay::DelayUs; self.delay_us(ms * 1_000); } } -impl DelayMs for Delay { +impl embedded_hal_02::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u16) { self.delay_ms(u32(ms)); } } -impl DelayMs for Delay { +impl embedded_hal_02::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u8) { self.delay_ms(u32(ms)); } } -impl DelayUs for Delay { +impl embedded_hal_02::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u32) { // The SysTick Reload Value register supports values between 1 and 0x00FFFFFF. const MAX_RVR: u32 = 0x00FF_FFFF; @@ -220,13 +217,13 @@ impl DelayUs for Delay { } } -impl DelayUs for Delay { +impl embedded_hal_02::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u16) { self.delay_us(u32(us)) } } -impl DelayUs for Delay { +impl embedded_hal_02::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u8) { self.delay_us(u32(us)) } @@ -251,9 +248,9 @@ macro_rules! impl_delay_from_count_down_timer { ($(($Delay:ident, $delay:ident, $num:expr)),+) => { $( - impl $Delay for DelayFromCountDownTimer + impl embedded_hal_02::blocking::delay::$Delay for DelayFromCountDownTimer where - T: CountDown