From 7e7b4ea3ffb8178bfde8c4ed2a51ac0da191f8c2 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 08:07:52 +0000 Subject: [PATCH 01/16] Make embedded-hal 1.0.0 non-optional --- rp2040-hal/Cargo.toml | 9 ++--- .../examples/pwm_blink_embedded_hal_1.rs | 2 +- rp2040-hal/src/gpio/mod.rs | 11 +----- rp2040-hal/src/i2c.rs | 37 +++++++------------ rp2040-hal/src/i2c/controller.rs | 6 +-- rp2040-hal/src/lib.rs | 2 +- rp2040-hal/src/pwm/mod.rs | 6 +-- rp2040-hal/src/spi.rs | 32 +++++++--------- rp2040-hal/src/timer.rs | 3 +- rp2040-hal/src/uart/peripheral.rs | 6 +-- rp2040-hal/src/uart/reader.rs | 6 +-- rp2040-hal/src/uart/writer.rs | 5 +-- 12 files changed, 40 insertions(+), 85 deletions(-) diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 8322ec1a1..5da60f0f0 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -18,8 +18,8 @@ targets = ["thumbv6m-none-eabi"] [dependencies] cortex-m = "0.7.2" embedded-hal = { version = "0.2.5", features = ["unproven"] } -eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-rc.3", optional = true } -eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "=1.0.0-rc.3", optional = true } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0" } +embedded-hal-nb = "1.0.0" embedded-dma = "0.2.0" embedded-io = "0.6.1" fugit = "0.3.6" @@ -79,9 +79,6 @@ rp2040-e5 = [] # critical section that is safe for multicore use critical-section-impl = ["critical-section/restore-state-u8"] -# Support alpha release of embedded-hal -eh1_0_alpha = ["dep:eh1_0_alpha", "dep:eh_nb_1_0_alpha"] - # Add conversion functions between chrono types and the rp2040-hal specific DateTime type chrono = ["dep:chrono"] @@ -192,7 +189,7 @@ required-features = ["critical-section-impl"] [[example]] name = "pwm_blink_embedded_hal_1" -required-features = ["critical-section-impl", "eh1_0_alpha"] +required-features = ["critical-section-impl"] [[example]] name = "rom_funcs" diff --git a/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs b/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs index aec3697ed..77dcda14e 100644 --- a/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs +++ b/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs @@ -18,7 +18,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use eh1_0_alpha::pwm::SetDutyCycle; +use embedded_hal_1::pwm::SetDutyCycle; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index b54f71f67..4fedb5bd9 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1396,10 +1396,9 @@ impl embedded_hal::digital::v2::OutputPin for InOutPin { } } -#[cfg(feature = "eh1_0_alpha")] mod eh1 { - use eh1_0_alpha::digital::{ - ErrorType, InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, + use embedded_hal_1::digital::{ + ErrorType, InputPin, OutputPin, StatefulOutputPin, }; use super::{Error, FunctionSio, Pin, PinId, PullType, SioConfig, SioInput, SioOutput}; @@ -1441,13 +1440,7 @@ mod eh1 { fn is_set_low(&mut self) -> Result { Ok(self._is_set_low()) } - } - impl ToggleableOutputPin for Pin, P> - where - I: PinId, - P: PullType, - { fn toggle(&mut self) -> Result<(), Self::Error> { self._toggle(); Ok(()) diff --git a/rp2040-hal/src/i2c.rs b/rp2040-hal/src/i2c.rs index 01b90444a..c7191d65f 100644 --- a/rp2040-hal/src/i2c.rs +++ b/rp2040-hal/src/i2c.rs @@ -72,13 +72,6 @@ impl I2cDevice for pac::I2C1 { /// I2C error #[non_exhaustive] -// when eh1_0_alpha is set, Debug & defmt::Format are manually implemented -// to rely on eh1.0's ErrorKind. -#[cfg_attr(not(feature = "eh1_0_alpha"), derive(Debug))] -#[cfg_attr( - all(feature = "defmt", not(feature = "eh1_0_alpha")), - derive(defmt::Format) -)] pub enum Error { /// I2C abort with error Abort(u32), @@ -100,10 +93,9 @@ pub enum Error { AddressReserved(u16), } -#[cfg(feature = "eh1_0_alpha")] impl core::fmt::Debug for Error { fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - use eh1_0_alpha::i2c::Error as _; + use embedded_hal_1::i2c::Error as _; match self { Error::InvalidReadBufferLength => write!(fmt, "InvalidReadBufferLength"), Error::InvalidWriteBufferLength => write!(fmt, "InvalidWriteBufferLength"), @@ -116,10 +108,10 @@ impl core::fmt::Debug for Error { } } -#[cfg(all(feature = "defmt", feature = "eh1_0_alpha"))] +#[cfg(feature = "defmt")] impl defmt::Format for Error { fn format(&self, fmt: defmt::Formatter) { - use eh1_0_alpha::i2c::Error as _; + use embedded_hal_1::i2c::Error as _; match self { Error::InvalidReadBufferLength => defmt::write!(fmt, "InvalidReadBufferLength"), Error::InvalidWriteBufferLength => defmt::write!(fmt, "InvalidWriteBufferLength"), @@ -132,27 +124,26 @@ impl defmt::Format for Error { } } -#[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::i2c::Error for Error { - fn kind(&self) -> eh1_0_alpha::i2c::ErrorKind { +impl embedded_hal_1::i2c::Error for Error { + fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { match &self { Error::Abort(v) if v & 1<<12 != 0 // ARB_LOST - => eh1_0_alpha::i2c::ErrorKind::ArbitrationLoss, + => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, Error::Abort(v) if v & 1<<7 != 0 // ABRT_SBYTE_ACKDET - => eh1_0_alpha::i2c::ErrorKind::Bus, + => embedded_hal_1::i2c::ErrorKind::Bus, Error::Abort(v) if v & 1<<6 != 0 // ABRT_HS_ACKDET - => eh1_0_alpha::i2c::ErrorKind::Bus, + => embedded_hal_1::i2c::ErrorKind::Bus, Error::Abort(v) if v & 1<<4 != 0 // ABRT_GCALL_NOACK - => eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address), + => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<3 != 0 // ABRT_TXDATA_NOACK - => eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Data), + => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data), Error::Abort(v) if v & 1<<2 != 0 // ABRT_10ADDR2_NOACK - => eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address), + => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<1 != 0 // ABRT_10ADDR1_NOACK - => eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address), + => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<0 != 0 // ABRT_7B_ADDR_NOACK - => eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address), - _ => eh1_0_alpha::i2c::ErrorKind::Other, + => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), + _ => embedded_hal_1::i2c::ErrorKind::Other, } } } diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index cd084929c..ce960974a 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -2,8 +2,7 @@ use core::{marker::PhantomData, ops::Deref}; use embedded_hal::blocking::i2c::{Read, Write, WriteIter, WriteIterRead, WriteRead}; use fugit::HertzU32; -#[cfg(feature = "eh1_0_alpha")] -use eh1_0_alpha::i2c as eh1; +use embedded_hal_1::i2c as eh1; use super::{i2c_reserved_addr, Controller, Error, ValidPinScl, ValidPinSda, I2C}; use crate::{ @@ -291,7 +290,6 @@ impl, PINS> I2C { /// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing /// - `SR` = repeated start condition /// - `SP` = stop condition - #[cfg(feature = "eh1_0_alpha")] pub fn transaction_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Error> where O: IntoIterator>, @@ -375,12 +373,10 @@ impl, PINS> WriteIterRead for I2C } } -#[cfg(feature = "eh1_0_alpha")] impl, PINS> eh1::ErrorType for I2C { type Error = Error; } -#[cfg(feature = "eh1_0_alpha")] impl, PINS> eh1::I2c for I2C { fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> { Write::write(self, addr, bytes) diff --git a/rp2040-hal/src/lib.rs b/rp2040-hal/src/lib.rs index 35ba8e924..0deafdaed 100644 --- a/rp2040-hal/src/lib.rs +++ b/rp2040-hal/src/lib.rs @@ -15,7 +15,7 @@ //! Implement `defmt::Format` for several types. //! * **disable-intrinsics** - //! Disable automatic mapping of language features (like floating point math) to ROM functions -//! * **eh1_0_alpha** - +//! * **embedded_hal_1** - //! Support alpha release of embedded-hal //! * **rom-func-cache** - //! Memoize(cache) ROM function pointers on first use to improve performance diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index a1b2d51c1..06875f0e5 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -76,12 +76,10 @@ //! min_config() leaves those registers in the state they were before it was called (Careful, this can lead to unexpected behavior) //! It's recommended to only call min_config() after calling default_config() on a pin that shares a PWM block. -#[cfg(feature = "eh1_0_alpha")] use core::convert::Infallible; use core::marker::PhantomData; -#[cfg(feature = "eh1_0_alpha")] -use eh1_0_alpha::pwm::{ErrorType, SetDutyCycle}; +use embedded_hal_1::pwm::{ErrorType, SetDutyCycle}; use embedded_dma::Word; use embedded_hal::PwmPin; @@ -668,12 +666,10 @@ impl PwmPin for Channel { } } -#[cfg(feature = "eh1_0_alpha")] impl ErrorType for Channel { type Error = Infallible; } -#[cfg(feature = "eh1_0_alpha")] impl SetDutyCycle for Channel { fn max_duty_cycle(&self) -> u16 { self.get_max_duty() diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index f53173285..3ce0c14ab 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -28,10 +28,8 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; -#[cfg(feature = "eh1_0_alpha")] -use eh1_0_alpha::spi as eh1; -#[cfg(feature = "eh1_0_alpha")] -use eh_nb_1_0_alpha::spi as eh1nb; +use embedded_hal_1::spi as eh1; +use embedded_hal_nb::spi as eh1nb; use embedded_hal::{ blocking::spi, spi::{FullDuplex, Phase, Polarity}, @@ -71,26 +69,25 @@ pub enum FrameFormat { NationalSemiconductorMicrowire, } -#[cfg(feature = "eh1_0_alpha")] -impl From for FrameFormat { - fn from(f: eh1_0_alpha::spi::Mode) -> Self { - let eh1_0_alpha::spi::Mode { polarity, phase } = f; +impl From for FrameFormat { + fn from(f: embedded_hal_1::spi::Mode) -> Self { + let embedded_hal_1::spi::Mode { polarity, phase } = f; match (polarity, phase) { ( - eh1_0_alpha::spi::Polarity::IdleLow, - eh1_0_alpha::spi::Phase::CaptureOnFirstTransition, + embedded_hal_1::spi::Polarity::IdleLow, + embedded_hal_1::spi::Phase::CaptureOnFirstTransition, ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_0), ( - eh1_0_alpha::spi::Polarity::IdleLow, - eh1_0_alpha::spi::Phase::CaptureOnSecondTransition, + embedded_hal_1::spi::Polarity::IdleLow, + embedded_hal_1::spi::Phase::CaptureOnSecondTransition, ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_1), ( - eh1_0_alpha::spi::Polarity::IdleHigh, - eh1_0_alpha::spi::Phase::CaptureOnFirstTransition, + embedded_hal_1::spi::Polarity::IdleHigh, + embedded_hal_1::spi::Phase::CaptureOnFirstTransition, ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_2), ( - eh1_0_alpha::spi::Polarity::IdleHigh, - eh1_0_alpha::spi::Phase::CaptureOnSecondTransition, + embedded_hal_1::spi::Polarity::IdleHigh, + embedded_hal_1::spi::Phase::CaptureOnSecondTransition, ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_3), } } @@ -409,12 +406,10 @@ macro_rules! impl_write { impl> spi::transfer::Default<$type> for Spi {} impl> spi::write_iter::Default<$type> for Spi {} - #[cfg(feature = "eh1_0_alpha")] impl> eh1::ErrorType for Spi { type Error = Infallible; } - #[cfg(feature = "eh1_0_alpha")] impl> eh1::SpiBus<$type> for Spi { fn read(&mut self, words: &mut [$type]) -> Result<(), Self::Error> { for word in words.iter_mut() { @@ -489,7 +484,6 @@ macro_rules! impl_write { } } - #[cfg(feature = "eh1_0_alpha")] impl> eh1nb::FullDuplex<$type> for Spi { fn read(&mut self) -> Result<$type, nb::Error> { if !self.is_readable() { diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 4b897c6c9..72122544e 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -166,8 +166,7 @@ macro_rules! impl_delay_traits { // The implementation for i32 is a workaround to allow `delay_ms(42)` construction without specifying a type. impl_delay_traits!(u8, u16, u32, i32); -#[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::delay::DelayNs for Timer { +impl embedded_hal_1::delay::DelayNs for Timer { fn delay_ns(&mut self, ns: u32) { // For now, just use microsecond delay, internally. Of course, this // might cause a much longer delay than necessary. So a more advanced diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 61193347a..a32abc81a 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -14,8 +14,7 @@ use crate::{ uart::*, }; -#[cfg(feature = "eh1_0_alpha")] -use eh_nb_1_0_alpha::serial as eh1nb; +use embedded_hal_nb::serial as eh1nb; /// An UART Peripheral based on an underlying UART device. pub struct UartPeripheral> { @@ -360,12 +359,10 @@ impl> eh0::Read for UartPeripheral> eh1nb::ErrorType for UartPeripheral { type Error = ReadErrorType; } -#[cfg(feature = "eh1_0_alpha")] impl> eh1nb::Read for UartPeripheral { fn read(&mut self) -> nb::Result { let byte: &mut [u8] = &mut [0; 1]; @@ -396,7 +393,6 @@ impl> eh0::Write for UartPeripheral> eh1nb::Write for UartPeripheral { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { if self.write_raw(&[word]).is_err() { diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index 6e53a2fec..eae03d9c6 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -8,8 +8,7 @@ use crate::pac::uart0::RegisterBlock; use embedded_hal::serial::Read; use nb::Error::*; -#[cfg(feature = "eh1_0_alpha")] -use eh_nb_1_0_alpha::serial as eh1nb; +use embedded_hal_nb::serial as eh1nb; /// When there's a read error. #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -39,7 +38,6 @@ pub enum ReadErrorType { Framing, } -#[cfg(feature = "eh1_0_alpha")] impl eh1nb::Error for ReadErrorType { fn kind(&self) -> eh1nb::ErrorKind { match self { @@ -255,12 +253,10 @@ unsafe impl> ReadTarget for Reader { impl> EndlessReadTarget for Reader {} -#[cfg(feature = "eh1_0_alpha")] impl> eh1nb::ErrorType for Reader { type Error = ReadErrorType; } -#[cfg(feature = "eh1_0_alpha")] impl> eh1nb::Read for Reader { fn read(&mut self) -> nb::Result { let byte: &mut [u8] = &mut [0; 1]; diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index f474e9f7b..27342dd87 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -7,8 +7,7 @@ use crate::dma::{EndlessWriteTarget, WriteTarget}; use crate::pac::uart0::RegisterBlock; use core::fmt; use core::{convert::Infallible, marker::PhantomData}; -#[cfg(feature = "eh1_0_alpha")] -use eh_nb_1_0_alpha::serial as eh1nb; +use embedded_hal_nb::serial as eh1nb; use embedded_hal::serial::Write; use nb::Error::*; @@ -209,12 +208,10 @@ unsafe impl> WriteTarget for Writer { impl> EndlessWriteTarget for Writer {} -#[cfg(feature = "eh1_0_alpha")] impl> eh1nb::ErrorType for Writer { type Error = core::convert::Infallible; } -#[cfg(feature = "eh1_0_alpha")] impl> eh1nb::Write for Writer { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { if self.write_raw(&[word]).is_err() { From 1d91b0a10b1079cec094718b8f2223a0a946751d Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 10:31:25 +0000 Subject: [PATCH 02/16] cargo fmt --- rp2040-hal/src/gpio/mod.rs | 4 +--- rp2040-hal/src/pwm/mod.rs | 2 +- rp2040-hal/src/spi.rs | 4 ++-- rp2040-hal/src/uart/writer.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index 4fedb5bd9..d51574c71 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1397,9 +1397,7 @@ impl embedded_hal::digital::v2::OutputPin for InOutPin { } mod eh1 { - use embedded_hal_1::digital::{ - ErrorType, InputPin, OutputPin, StatefulOutputPin, - }; + use embedded_hal_1::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; use super::{Error, FunctionSio, Pin, PinId, PullType, SioConfig, SioInput, SioOutput}; diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index 06875f0e5..b8add9425 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -79,9 +79,9 @@ use core::convert::Infallible; use core::marker::PhantomData; -use embedded_hal_1::pwm::{ErrorType, SetDutyCycle}; use embedded_dma::Word; use embedded_hal::PwmPin; +use embedded_hal_1::pwm::{ErrorType, SetDutyCycle}; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 3ce0c14ab..76eecda2a 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -28,12 +28,12 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; -use embedded_hal_1::spi as eh1; -use embedded_hal_nb::spi as eh1nb; use embedded_hal::{ blocking::spi, spi::{FullDuplex, Phase, Polarity}, }; +use embedded_hal_1::spi as eh1; +use embedded_hal_nb::spi as eh1nb; use fugit::{HertzU32, RateExtU32}; use crate::{ diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index 27342dd87..d961b33ac 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -7,8 +7,8 @@ use crate::dma::{EndlessWriteTarget, WriteTarget}; use crate::pac::uart0::RegisterBlock; use core::fmt; use core::{convert::Infallible, marker::PhantomData}; -use embedded_hal_nb::serial as eh1nb; use embedded_hal::serial::Write; +use embedded_hal_nb::serial as eh1nb; use nb::Error::*; /// Set tx FIFO watermark From 61d6e7d352bcea818cc39ebca8d763ffdf248d86 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 19:02:37 +0000 Subject: [PATCH 03/16] Rename legacy embedded-hal to embedded_hal_0_2 --- rp2040-hal/Cargo.toml | 2 +- rp2040-hal/examples/adc.rs | 2 +- rp2040-hal/examples/blinky.rs | 4 ++-- rp2040-hal/examples/dht11.rs | 2 +- rp2040-hal/examples/gpio_dyn_pin_array.rs | 4 ++-- rp2040-hal/examples/gpio_in_out.rs | 4 ++-- rp2040-hal/examples/gpio_irq_example.rs | 2 +- rp2040-hal/examples/i2c.rs | 2 +- rp2040-hal/examples/mem_to_mem_dma.rs | 2 +- rp2040-hal/examples/multicore_fifo_blink.rs | 2 +- rp2040-hal/examples/multicore_polyblink.rs | 2 +- rp2040-hal/examples/pwm_blink.rs | 2 +- rp2040-hal/examples/pwm_irq_input.rs | 4 ++-- rp2040-hal/examples/rosc_as_system_clock.rs | 2 +- rp2040-hal/examples/rtc_irq_example.rs | 2 +- rp2040-hal/examples/rtc_sleep_example.rs | 2 +- rp2040-hal/examples/spi.rs | 2 +- rp2040-hal/examples/spi_dma.rs | 4 ++-- rp2040-hal/examples/vector_table.rs | 2 +- rp2040-hal/examples/watchdog.rs | 4 ++-- rp2040-hal/src/adc.rs | 8 ++++---- rp2040-hal/src/gpio/mod.rs | 20 +++++++++---------- rp2040-hal/src/gpio/pin_group.rs | 2 +- rp2040-hal/src/i2c.rs | 6 +++--- rp2040-hal/src/i2c/controller.rs | 2 +- rp2040-hal/src/pwm/mod.rs | 4 ++-- rp2040-hal/src/spi.rs | 22 ++++++++++----------- rp2040-hal/src/timer.rs | 14 ++++++------- rp2040-hal/src/uart/peripheral.rs | 2 +- rp2040-hal/src/uart/reader.rs | 2 +- rp2040-hal/src/uart/writer.rs | 2 +- rp2040-hal/src/watchdog.rs | 2 +- 32 files changed, 69 insertions(+), 69 deletions(-) diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 5da60f0f0..40551672b 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -17,7 +17,7 @@ targets = ["thumbv6m-none-eabi"] [dependencies] cortex-m = "0.7.2" -embedded-hal = { version = "0.2.5", features = ["unproven"] } +embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } embedded-hal-1 = { package = "embedded-hal", version = "1.0.0" } embedded-hal-nb = "1.0.0" embedded-dma = "0.2.0" diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index b66f189ac..32508146e 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -19,7 +19,7 @@ use rp2040_hal as hal; // Some traits we need use core::fmt::Write; -use embedded_hal::adc::OneShot; +use embedded_hal_0_2::adc::OneShot; use hal::fugit::RateExtU32; use rp2040_hal::Clock; diff --git a/rp2040-hal/examples/blinky.rs b/rp2040-hal/examples/blinky.rs index 86fead6af..ba877c08e 100644 --- a/rp2040-hal/examples/blinky.rs +++ b/rp2040-hal/examples/blinky.rs @@ -21,8 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::blocking::delay::DelayMs; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::blocking::delay::DelayMs; +use embedded_hal_0_2::digital::v2::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/dht11.rs b/rp2040-hal/examples/dht11.rs index f8af8b131..d0adfb547 100644 --- a/rp2040-hal/examples/dht11.rs +++ b/rp2040-hal/examples/dht11.rs @@ -24,7 +24,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::digital::v2::OutputPin; use hal::Clock; /// The linker will place this boot block at the start of our program image. We diff --git a/rp2040-hal/examples/gpio_dyn_pin_array.rs b/rp2040-hal/examples/gpio_dyn_pin_array.rs index 70ee44cab..81adb682e 100644 --- a/rp2040-hal/examples/gpio_dyn_pin_array.rs +++ b/rp2040-hal/examples/gpio_dyn_pin_array.rs @@ -28,8 +28,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::blocking::delay::DelayMs; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::blocking::delay::DelayMs; +use embedded_hal_0_2::digital::v2::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/gpio_in_out.rs b/rp2040-hal/examples/gpio_in_out.rs index fd7356660..7adec4489 100644 --- a/rp2040-hal/examples/gpio_in_out.rs +++ b/rp2040-hal/examples/gpio_in_out.rs @@ -21,8 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::InputPin; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::digital::v2::InputPin; +use embedded_hal_0_2::digital::v2::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/gpio_irq_example.rs b/rp2040-hal/examples/gpio_irq_example.rs index 9c20716f4..008c71eda 100644 --- a/rp2040-hal/examples/gpio_irq_example.rs +++ b/rp2040-hal/examples/gpio_irq_example.rs @@ -34,7 +34,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/i2c.rs b/rp2040-hal/examples/i2c.rs index 889748ff4..ef6480912 100644 --- a/rp2040-hal/examples/i2c.rs +++ b/rp2040-hal/examples/i2c.rs @@ -17,7 +17,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal::blocking::i2c::Write; +use embedded_hal_0_2::blocking::i2c::Write; use hal::fugit::RateExtU32; // A shorter alias for the Peripheral Access Crate, which provides low-level diff --git a/rp2040-hal/examples/mem_to_mem_dma.rs b/rp2040-hal/examples/mem_to_mem_dma.rs index 6dc0cf5a6..740e9b11c 100644 --- a/rp2040-hal/examples/mem_to_mem_dma.rs +++ b/rp2040-hal/examples/mem_to_mem_dma.rs @@ -8,7 +8,7 @@ use cortex_m::singleton; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::digital::v2::OutputPin; use hal::dma::{single_buffer, DMAExt}; use hal::pac; use panic_halt as _; diff --git a/rp2040-hal/examples/multicore_fifo_blink.rs b/rp2040-hal/examples/multicore_fifo_blink.rs index ae7d0851b..6380a49a4 100644 --- a/rp2040-hal/examples/multicore_fifo_blink.rs +++ b/rp2040-hal/examples/multicore_fifo_blink.rs @@ -27,7 +27,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/multicore_polyblink.rs b/rp2040-hal/examples/multicore_polyblink.rs index f61301f9e..8e6ad0f87 100644 --- a/rp2040-hal/examples/multicore_polyblink.rs +++ b/rp2040-hal/examples/multicore_polyblink.rs @@ -26,7 +26,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/pwm_blink.rs b/rp2040-hal/examples/pwm_blink.rs index 048fd4f81..4f3b6647d 100644 --- a/rp2040-hal/examples/pwm_blink.rs +++ b/rp2040-hal/examples/pwm_blink.rs @@ -18,7 +18,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal::PwmPin; +use embedded_hal_0_2::PwmPin; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level diff --git a/rp2040-hal/examples/pwm_irq_input.rs b/rp2040-hal/examples/pwm_irq_input.rs index 2de79a4ff..93f369f1e 100644 --- a/rp2040-hal/examples/pwm_irq_input.rs +++ b/rp2040-hal/examples/pwm_irq_input.rs @@ -20,8 +20,8 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal::digital::v2::OutputPin; -use embedded_hal::PwmPin; +use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal_0_2::PwmPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/rosc_as_system_clock.rs b/rp2040-hal/examples/rosc_as_system_clock.rs index 31238d539..d484f51d6 100644 --- a/rp2040-hal/examples/rosc_as_system_clock.rs +++ b/rp2040-hal/examples/rosc_as_system_clock.rs @@ -21,7 +21,7 @@ use rp2040_hal as hal; // register access use hal::pac; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::digital::v2::OutputPin; use fugit::{HertzU32, RateExtU32}; use hal::clocks::{Clock, ClockSource, ClocksManager, StoppableClock}; use hal::pac::rosc::ctrl::FREQ_RANGE_A; diff --git a/rp2040-hal/examples/rtc_irq_example.rs b/rp2040-hal/examples/rtc_irq_example.rs index e7d89b745..490d6f04b 100644 --- a/rp2040-hal/examples/rtc_irq_example.rs +++ b/rp2040-hal/examples/rtc_irq_example.rs @@ -21,7 +21,7 @@ use rp2040_hal as hal; use hal::{gpio, pac, rtc}; // Some traits we need -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/rtc_sleep_example.rs b/rp2040-hal/examples/rtc_sleep_example.rs index 18b8f07c1..a4b3b75ef 100644 --- a/rp2040-hal/examples/rtc_sleep_example.rs +++ b/rp2040-hal/examples/rtc_sleep_example.rs @@ -20,7 +20,7 @@ use rp2040_hal as hal; use hal::{clocks::ClockGate, gpio, pac, rtc}; // Some traits we need -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/spi.rs b/rp2040-hal/examples/spi.rs index 4f47823bb..32c20da23 100644 --- a/rp2040-hal/examples/spi.rs +++ b/rp2040-hal/examples/spi.rs @@ -89,7 +89,7 @@ fn main() -> ! { &mut pac.RESETS, clocks.peripheral_clock.freq(), 16.MHz(), - embedded_hal::spi::MODE_0, + embedded_hal_0_2::spi::MODE_0, ); // Write out 0, ignore return value diff --git a/rp2040-hal/examples/spi_dma.rs b/rp2040-hal/examples/spi_dma.rs index 5710de0b7..0522e8e35 100644 --- a/rp2040-hal/examples/spi_dma.rs +++ b/rp2040-hal/examples/spi_dma.rs @@ -11,7 +11,7 @@ use cortex_m::singleton; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal_0_2::digital::v2::OutputPin; use hal::dma::{bidirectional, DMAExt}; use hal::fugit::RateExtU32; use hal::pac; @@ -67,7 +67,7 @@ fn main() -> ! { &mut pac.RESETS, clocks.peripheral_clock.freq(), 16_000_000u32.Hz(), - embedded_hal::spi::MODE_0, + embedded_hal_0_2::spi::MODE_0, ); // Initialize DMA. diff --git a/rp2040-hal/examples/vector_table.rs b/rp2040-hal/examples/vector_table.rs index 27d2eeccc..43ce0150f 100644 --- a/rp2040-hal/examples/vector_table.rs +++ b/rp2040-hal/examples/vector_table.rs @@ -21,7 +21,7 @@ use hal::pac; // Some traits we need use core::cell::RefCell; use critical_section::Mutex; -use embedded_hal::digital::v2::ToggleableOutputPin; +use embedded_hal_0_2::digital::v2::ToggleableOutputPin; use hal::fugit::MicrosDurationU32; use pac::interrupt; use rp2040_hal::clocks::Clock; diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal/examples/watchdog.rs index de9fd0bd6..d4d9db685 100644 --- a/rp2040-hal/examples/watchdog.rs +++ b/rp2040-hal/examples/watchdog.rs @@ -21,8 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal::digital::v2::OutputPin; -use embedded_hal::watchdog::{Watchdog, WatchdogEnable}; +use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal_0_2::watchdog::{Watchdog, WatchdogEnable}; use hal::fugit::ExtU32; use rp2040_hal::clocks::Clock; diff --git a/rp2040-hal/src/adc.rs b/rp2040-hal/src/adc.rs index f47c4fefc..651256c94 100644 --- a/rp2040-hal/src/adc.rs +++ b/rp2040-hal/src/adc.rs @@ -6,7 +6,7 @@ //! //! Capture ADC reading from a pin //! ```no_run -//! use embedded_hal::adc::OneShot; +//! use embedded_hal_0_2::adc::OneShot; //! use rp2040_hal::{adc::Adc, adc::AdcPin, gpio::Pins, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); //! let sio = Sio::new(peripherals.SIO); @@ -21,7 +21,7 @@ //! //! Capture ADC reading from temperature sensor. Note that this needs conversion to be a real-world temperature. //! ```no_run -//! use embedded_hal::adc::OneShot; +//! use embedded_hal_0_2::adc::OneShot; //! use rp2040_hal::{adc::Adc, gpio::Pins, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); //! let sio = Sio::new(peripherals.SIO); @@ -118,7 +118,7 @@ use core::convert::Infallible; use core::marker::PhantomData; -use embedded_hal::adc::{Channel, OneShot}; +use embedded_hal_0_2::adc::{Channel, OneShot}; use crate::{ dma, @@ -223,7 +223,7 @@ impl Channel for TempSense { /// by calling [`Adc::take_temp_sensor()`]. Either way, the resulting objects can be /// passed to the [`OneShot::read()`][a] trait method to actually do the read. /// -/// [a]: embedded_hal::adc::OneShot::read +/// [a]: embedded_hal_0_2::adc::OneShot::read pub struct Adc { device: ADC, } diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index d51574c71..2dd48d09a 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -2,7 +2,7 @@ //! //! ## Basic usage //! ```no_run -//! use embedded_hal::digital::v2::{InputPin, OutputPin}; +//! use embedded_hal_0_2::digital::v2::{InputPin, OutputPin}; //! use rp2040_hal::{clocks::init_clocks_and_plls, gpio::Pins, watchdog::Watchdog, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); //! let mut watchdog = Watchdog::new(peripherals.WATCHDOG); @@ -39,7 +39,7 @@ // advanced usage of the pin (relative to reading/writing a gpio) and it is the responsibility of // the user to make sure these are in a correct state when converting and passing the pin around. -pub use embedded_hal::digital::v2::PinState; +pub use embedded_hal_0_2::digital::v2::PinState; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, @@ -863,7 +863,7 @@ pub struct AsInputPin<'a, I: PinId, F: func::Function, P: PullType>(&'a Pin embedded_hal::digital::v2::OutputPin for Pin, P> +impl embedded_hal_0_2::digital::v2::OutputPin for Pin, P> where I: PinId, P: PullType, @@ -883,7 +883,7 @@ where /// Deprecated: Instead of implicitly implementing InputPin for function SioOutput, /// use `pin.as_input()` to get access to input values indepentent of the selected function. -impl embedded_hal::digital::v2::InputPin for Pin, P> +impl embedded_hal_0_2::digital::v2::InputPin for Pin, P> where I: PinId, P: PullType, @@ -899,7 +899,7 @@ where } } -impl<'a, I: PinId, F: func::Function, P: PullType> embedded_hal::digital::v2::InputPin +impl<'a, I: PinId, F: func::Function, P: PullType> embedded_hal_0_2::digital::v2::InputPin for AsInputPin<'a, I, F, P> { type Error = core::convert::Infallible; @@ -913,7 +913,7 @@ impl<'a, I: PinId, F: func::Function, P: PullType> embedded_hal::digital::v2::In } } -impl embedded_hal::digital::v2::StatefulOutputPin for Pin, P> +impl embedded_hal_0_2::digital::v2::StatefulOutputPin for Pin, P> where I: PinId, P: PullType, @@ -927,7 +927,7 @@ where } } -impl embedded_hal::digital::v2::ToggleableOutputPin for Pin, P> +impl embedded_hal_0_2::digital::v2::ToggleableOutputPin for Pin, P> where I: PinId, P: PullType, @@ -939,7 +939,7 @@ where Ok(()) } } -impl embedded_hal::digital::v2::InputPin for Pin, P> +impl embedded_hal_0_2::digital::v2::InputPin for Pin, P> where I: PinId, P: PullType, @@ -1367,7 +1367,7 @@ where } } -impl embedded_hal::digital::v2::InputPin for InOutPin { +impl embedded_hal_0_2::digital::v2::InputPin for InOutPin { type Error = Error; fn is_high(&self) -> Result { self.inner.is_high() @@ -1378,7 +1378,7 @@ impl embedded_hal::digital::v2::InputPin for InOutPin { } } -impl embedded_hal::digital::v2::OutputPin for InOutPin { +impl embedded_hal_0_2::digital::v2::OutputPin for InOutPin { type Error = Error; fn set_low(&mut self) -> Result<(), Error> { // The pin is already set to output low but this is inhibited by the override. diff --git a/rp2040-hal/src/gpio/pin_group.rs b/rp2040-hal/src/gpio/pin_group.rs index 61657818a..bea6d09c0 100644 --- a/rp2040-hal/src/gpio/pin_group.rs +++ b/rp2040-hal/src/gpio/pin_group.rs @@ -1,4 +1,4 @@ -use embedded_hal::digital::v2::PinState; +use embedded_hal_0_2::digital::v2::PinState; use frunk::{hlist::Plucker, HCons, HNil}; use crate::typelevel::Sealed; diff --git a/rp2040-hal/src/i2c.rs b/rp2040-hal/src/i2c.rs index c7191d65f..a2a44b5c4 100644 --- a/rp2040-hal/src/i2c.rs +++ b/rp2040-hal/src/i2c.rs @@ -20,7 +20,7 @@ //! ); //! //! // Scan for devices on the bus by attempting to read from them -//! use embedded_hal::prelude::_embedded_hal_blocking_i2c_Read; +//! use embedded_hal_0_2::prelude::_embedded_hal_blocking_i2c_Read; //! for i in 0..=127 { //! let mut readbuf: [u8; 1] = [0; 1]; //! let result = i2c.read(i, &mut readbuf); @@ -31,11 +31,11 @@ //! } //! //! // Write some data to a device at 0x2c -//! use embedded_hal::prelude::_embedded_hal_blocking_i2c_Write; +//! use embedded_hal_0_2::prelude::_embedded_hal_blocking_i2c_Write; //! i2c.write(0x2c, &[1, 2, 3]).unwrap(); //! //! // Write and then read from a device at 0x3a -//! use embedded_hal::prelude::_embedded_hal_blocking_i2c_WriteRead; +//! use embedded_hal_0_2::prelude::_embedded_hal_blocking_i2c_WriteRead; //! let mut readbuf: [u8; 1] = [0; 1]; //! i2c.write_read(0x2c, &[1, 2, 3], &mut readbuf).unwrap(); //! ``` diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index ce960974a..25382c0a3 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -1,5 +1,5 @@ use core::{marker::PhantomData, ops::Deref}; -use embedded_hal::blocking::i2c::{Read, Write, WriteIter, WriteIterRead, WriteRead}; +use embedded_hal_0_2::blocking::i2c::{Read, Write, WriteIter, WriteIterRead, WriteRead}; use fugit::HertzU32; use embedded_hal_1::i2c as eh1; diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index b8add9425..a1ade3f3a 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -37,7 +37,7 @@ //! # &mut pac.RESETS, //! # ); //! # -//! use embedded_hal::PwmPin; +//! use embedded_hal_0_2::PwmPin; //! //! // Use B channel (which inputs from GPIO 25) //! let mut channel_b = pwm.channel_b; @@ -80,7 +80,7 @@ use core::convert::Infallible; use core::marker::PhantomData; use embedded_dma::Word; -use embedded_hal::PwmPin; +use embedded_hal_0_2::PwmPin; use embedded_hal_1::pwm::{ErrorType, SetDutyCycle}; use crate::{ diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 76eecda2a..0fcbf8c82 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -8,7 +8,7 @@ //! ## Usage //! //! ```no_run -//! use embedded_hal::spi::MODE_0; +//! use embedded_hal_0_2::spi::MODE_0; //! use fugit::RateExtU32; //! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio}; //! @@ -28,7 +28,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; -use embedded_hal::{ +use embedded_hal_0_2::{ blocking::spi, spi::{FullDuplex, Phase, Polarity}, }; @@ -46,14 +46,14 @@ use crate::{ mod pins; pub use pins::*; -impl From for FrameFormat { - fn from(f: embedded_hal::spi::Mode) -> Self { +impl From for FrameFormat { + fn from(f: embedded_hal_0_2::spi::Mode) -> Self { Self::MotorolaSpi(f) } } -impl From<&embedded_hal::spi::Mode> for FrameFormat { - fn from(f: &embedded_hal::spi::Mode) -> Self { +impl From<&embedded_hal_0_2::spi::Mode> for FrameFormat { + fn from(f: &embedded_hal_0_2::spi::Mode) -> Self { Self::MotorolaSpi(*f) } } @@ -62,7 +62,7 @@ impl From<&embedded_hal::spi::Mode> for FrameFormat { #[derive(Clone, Copy, PartialEq, Eq)] pub enum FrameFormat { /// Motorola SPI format. See section 4.4.3.9 of RP2040 datasheet. - MotorolaSpi(embedded_hal::spi::Mode), + MotorolaSpi(embedded_hal_0_2::spi::Mode), /// Texas Instruments synchronous serial frame format. See section 4.4.3.8 of RP2040 datasheet. TexasInstrumentsSynchronousSerial, /// National Semiconductor Microwire frame format. See section 4.4.3.14 of RP2040 datasheet. @@ -76,19 +76,19 @@ impl From for FrameFormat { ( embedded_hal_1::spi::Polarity::IdleLow, embedded_hal_1::spi::Phase::CaptureOnFirstTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_0), + ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_0), ( embedded_hal_1::spi::Polarity::IdleLow, embedded_hal_1::spi::Phase::CaptureOnSecondTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_1), + ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_1), ( embedded_hal_1::spi::Polarity::IdleHigh, embedded_hal_1::spi::Phase::CaptureOnFirstTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_2), + ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_2), ( embedded_hal_1::spi::Polarity::IdleHigh, embedded_hal_1::spi::Phase::CaptureOnSecondTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal::spi::MODE_3), + ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_3), } } } diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 72122544e..47a6e0c6d 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -143,14 +143,14 @@ impl Timer { macro_rules! impl_delay_traits { ($($t:ty),+) => { $( - impl embedded_hal::blocking::delay::DelayUs<$t> for Timer { + impl embedded_hal_0_2::blocking::delay::DelayUs<$t> for Timer { fn delay_us(&mut self, us: $t) { #![allow(unused_comparisons)] assert!(us >= 0); // Only meaningful for i32 self.delay_us_internal(us as u32) } } - impl embedded_hal::blocking::delay::DelayMs<$t> for Timer { + impl embedded_hal_0_2::blocking::delay::DelayMs<$t> for Timer { fn delay_ms(&mut self, ms: $t) { #![allow(unused_comparisons)] assert!(ms >= 0); // Only meaningful for i32 @@ -188,11 +188,11 @@ impl embedded_hal_1::delay::DelayNs for Timer { } } -/// Implementation of the embedded_hal::Timer traits using rp2040_hal::timer counter +/// Implementation of the embedded_hal_0_2::Timer traits using rp2040_hal::timer counter /// /// ## Usage /// ```no_run -/// use embedded_hal::timer::{CountDown, Cancel}; +/// use embedded_hal_0_2::timer::{CountDown, Cancel}; /// use fugit::ExtU32; /// use rp2040_hal; /// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap(); @@ -217,7 +217,7 @@ pub struct CountDown<'timer> { next_end: Option, } -impl embedded_hal::timer::CountDown for CountDown<'_> { +impl embedded_hal_0_2::timer::CountDown for CountDown<'_> { type Time = MicrosDurationU64; fn start(&mut self, count: T) @@ -248,9 +248,9 @@ impl embedded_hal::timer::CountDown for CountDown<'_> { } } -impl embedded_hal::timer::Periodic for CountDown<'_> {} +impl embedded_hal_0_2::timer::Periodic for CountDown<'_> {} -impl embedded_hal::timer::Cancel for CountDown<'_> { +impl embedded_hal_0_2::timer::Cancel for CountDown<'_> { type Error = &'static str; fn cancel(&mut self) -> Result<(), Self::Error> { diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index a32abc81a..1ebe25e38 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -4,7 +4,7 @@ //! UartPeripheral object that can both read and write. use core::{convert::Infallible, fmt}; -use embedded_hal::serial as eh0; +use embedded_hal_0_2::serial as eh0; use fugit::HertzU32; use nb::Error::{Other, WouldBlock}; diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index eae03d9c6..d26a04283 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -5,7 +5,7 @@ use super::{FifoWatermark, UartDevice, ValidUartPinout}; use crate::dma::{EndlessReadTarget, ReadTarget}; use crate::pac::uart0::RegisterBlock; -use embedded_hal::serial::Read; +use embedded_hal_0_2::serial::Read; use nb::Error::*; use embedded_hal_nb::serial as eh1nb; diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index d961b33ac..ca4736593 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -7,7 +7,7 @@ use crate::dma::{EndlessWriteTarget, WriteTarget}; use crate::pac::uart0::RegisterBlock; use core::fmt; use core::{convert::Infallible, marker::PhantomData}; -use embedded_hal::serial::Write; +use embedded_hal_0_2::serial::Write; use embedded_hal_nb::serial as eh1nb; use nb::Error::*; diff --git a/rp2040-hal/src/watchdog.rs b/rp2040-hal/src/watchdog.rs index 9133752aa..27b720b4e 100644 --- a/rp2040-hal/src/watchdog.rs +++ b/rp2040-hal/src/watchdog.rs @@ -34,7 +34,7 @@ //! ``` //! See [examples/watchdog.rs](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples/watchdog.rs) for a more complete example -use embedded_hal::watchdog; +use embedded_hal_0_2::watchdog; use fugit::MicrosDurationU32; use crate::pac::{self, WATCHDOG}; From 978299f613db23d45cadd4ada757ad39be40a25b Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 19:04:21 +0000 Subject: [PATCH 04/16] Rename embedded-hal-1 to embedded-hal --- rp2040-hal/Cargo.toml | 2 +- .../examples/pwm_blink_embedded_hal_1.rs | 2 +- rp2040-hal/src/gpio/mod.rs | 2 +- rp2040-hal/src/i2c.rs | 26 +++++++++---------- rp2040-hal/src/i2c/controller.rs | 2 +- rp2040-hal/src/pwm/mod.rs | 2 +- rp2040-hal/src/spi.rs | 24 ++++++++--------- rp2040-hal/src/timer.rs | 2 +- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 40551672b..d089f87da 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -18,7 +18,7 @@ targets = ["thumbv6m-none-eabi"] [dependencies] cortex-m = "0.7.2" embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0" } +embedded-hal = "1.0.0" embedded-hal-nb = "1.0.0" embedded-dma = "0.2.0" embedded-io = "0.6.1" diff --git a/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs b/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs index 77dcda14e..32bb24223 100644 --- a/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs +++ b/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs @@ -18,7 +18,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal_1::pwm::SetDutyCycle; +use embedded_hal::pwm::SetDutyCycle; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index 2dd48d09a..6bb20b707 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1397,7 +1397,7 @@ impl embedded_hal_0_2::digital::v2::OutputPin for InOutPin { } mod eh1 { - use embedded_hal_1::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; + use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; use super::{Error, FunctionSio, Pin, PinId, PullType, SioConfig, SioInput, SioOutput}; diff --git a/rp2040-hal/src/i2c.rs b/rp2040-hal/src/i2c.rs index a2a44b5c4..a01fccdbb 100644 --- a/rp2040-hal/src/i2c.rs +++ b/rp2040-hal/src/i2c.rs @@ -95,7 +95,7 @@ pub enum Error { impl core::fmt::Debug for Error { fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - use embedded_hal_1::i2c::Error as _; + use embedded_hal::i2c::Error as _; match self { Error::InvalidReadBufferLength => write!(fmt, "InvalidReadBufferLength"), Error::InvalidWriteBufferLength => write!(fmt, "InvalidWriteBufferLength"), @@ -111,7 +111,7 @@ impl core::fmt::Debug for Error { #[cfg(feature = "defmt")] impl defmt::Format for Error { fn format(&self, fmt: defmt::Formatter) { - use embedded_hal_1::i2c::Error as _; + use embedded_hal::i2c::Error as _; match self { Error::InvalidReadBufferLength => defmt::write!(fmt, "InvalidReadBufferLength"), Error::InvalidWriteBufferLength => defmt::write!(fmt, "InvalidWriteBufferLength"), @@ -124,26 +124,26 @@ impl defmt::Format for Error { } } -impl embedded_hal_1::i2c::Error for Error { - fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { +impl embedded_hal::i2c::Error for Error { + fn kind(&self) -> embedded_hal::i2c::ErrorKind { match &self { Error::Abort(v) if v & 1<<12 != 0 // ARB_LOST - => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, + => embedded_hal::i2c::ErrorKind::ArbitrationLoss, Error::Abort(v) if v & 1<<7 != 0 // ABRT_SBYTE_ACKDET - => embedded_hal_1::i2c::ErrorKind::Bus, + => embedded_hal::i2c::ErrorKind::Bus, Error::Abort(v) if v & 1<<6 != 0 // ABRT_HS_ACKDET - => embedded_hal_1::i2c::ErrorKind::Bus, + => embedded_hal::i2c::ErrorKind::Bus, Error::Abort(v) if v & 1<<4 != 0 // ABRT_GCALL_NOACK - => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), + => embedded_hal::i2c::ErrorKind::NoAcknowledge(embedded_hal::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<3 != 0 // ABRT_TXDATA_NOACK - => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data), + => embedded_hal::i2c::ErrorKind::NoAcknowledge(embedded_hal::i2c::NoAcknowledgeSource::Data), Error::Abort(v) if v & 1<<2 != 0 // ABRT_10ADDR2_NOACK - => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), + => embedded_hal::i2c::ErrorKind::NoAcknowledge(embedded_hal::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<1 != 0 // ABRT_10ADDR1_NOACK - => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), + => embedded_hal::i2c::ErrorKind::NoAcknowledge(embedded_hal::i2c::NoAcknowledgeSource::Address), Error::Abort(v) if v & 1<<0 != 0 // ABRT_7B_ADDR_NOACK - => embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address), - _ => embedded_hal_1::i2c::ErrorKind::Other, + => embedded_hal::i2c::ErrorKind::NoAcknowledge(embedded_hal::i2c::NoAcknowledgeSource::Address), + _ => embedded_hal::i2c::ErrorKind::Other, } } } diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index 25382c0a3..3fef2f609 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -2,7 +2,7 @@ use core::{marker::PhantomData, ops::Deref}; use embedded_hal_0_2::blocking::i2c::{Read, Write, WriteIter, WriteIterRead, WriteRead}; use fugit::HertzU32; -use embedded_hal_1::i2c as eh1; +use embedded_hal::i2c as eh1; use super::{i2c_reserved_addr, Controller, Error, ValidPinScl, ValidPinSda, I2C}; use crate::{ diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index a1ade3f3a..eda2d80c2 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -81,7 +81,7 @@ use core::marker::PhantomData; use embedded_dma::Word; use embedded_hal_0_2::PwmPin; -use embedded_hal_1::pwm::{ErrorType, SetDutyCycle}; +use embedded_hal::pwm::{ErrorType, SetDutyCycle}; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 0fcbf8c82..caccde2f8 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -32,7 +32,7 @@ use embedded_hal_0_2::{ blocking::spi, spi::{FullDuplex, Phase, Polarity}, }; -use embedded_hal_1::spi as eh1; +use embedded_hal::spi as eh1; use embedded_hal_nb::spi as eh1nb; use fugit::{HertzU32, RateExtU32}; @@ -69,25 +69,25 @@ pub enum FrameFormat { NationalSemiconductorMicrowire, } -impl From for FrameFormat { - fn from(f: embedded_hal_1::spi::Mode) -> Self { - let embedded_hal_1::spi::Mode { polarity, phase } = f; +impl From for FrameFormat { + fn from(f: embedded_hal::spi::Mode) -> Self { + let embedded_hal::spi::Mode { polarity, phase } = f; match (polarity, phase) { ( - embedded_hal_1::spi::Polarity::IdleLow, - embedded_hal_1::spi::Phase::CaptureOnFirstTransition, + embedded_hal::spi::Polarity::IdleLow, + embedded_hal::spi::Phase::CaptureOnFirstTransition, ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_0), ( - embedded_hal_1::spi::Polarity::IdleLow, - embedded_hal_1::spi::Phase::CaptureOnSecondTransition, + embedded_hal::spi::Polarity::IdleLow, + embedded_hal::spi::Phase::CaptureOnSecondTransition, ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_1), ( - embedded_hal_1::spi::Polarity::IdleHigh, - embedded_hal_1::spi::Phase::CaptureOnFirstTransition, + embedded_hal::spi::Polarity::IdleHigh, + embedded_hal::spi::Phase::CaptureOnFirstTransition, ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_2), ( - embedded_hal_1::spi::Polarity::IdleHigh, - embedded_hal_1::spi::Phase::CaptureOnSecondTransition, + embedded_hal::spi::Polarity::IdleHigh, + embedded_hal::spi::Phase::CaptureOnSecondTransition, ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_3), } } diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 47a6e0c6d..6e6d2dee6 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -166,7 +166,7 @@ macro_rules! impl_delay_traits { // The implementation for i32 is a workaround to allow `delay_ms(42)` construction without specifying a type. impl_delay_traits!(u8, u16, u32, i32); -impl embedded_hal_1::delay::DelayNs for Timer { +impl embedded_hal::delay::DelayNs for Timer { fn delay_ns(&mut self, ns: u32) { // For now, just use microsecond delay, internally. Of course, this // might cause a much longer delay than necessary. So a more advanced From 8e1fea96983d8fa12e7ff55ea5845fb17bf26871 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 19:22:19 +0000 Subject: [PATCH 05/16] Update readme --- rp2040-hal/README.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/rp2040-hal/README.md b/rp2040-hal/README.md index a15eadd25..8dae33f5b 100644 --- a/rp2040-hal/README.md +++ b/rp2040-hal/README.md @@ -92,18 +92,11 @@ volatile until a 1.0.0 release. See the [open issues](https://github.com/rp-rs/rp-hal/issues) for a list of proposed features (and known issues). -### Support for embedded-hal 1.0 +### Implemented traits -We plan to support embedded-hal 1.0 soon after it is released. - -For now, there is preliminary support for alpha/rc versions of embedded-hal, which can -be enabled with the feature `eh1_0_alpha`. Please note that this support does not -provide any semver compatibility guarantees: With that feature activated, there -will be breaking changes even in minor versions of rp2040-hal. - -Support for embedded-hal 1.0(-alpha/rc) exists in parallel to support for -embedded-hal 0.2: Traits of both versions are implemented and can be used -at the same time. +This crate aims to implement all traits from embedded-hal, both version +0.2 and 1.0. They can be used at the same time, so you can upgrade drivers +incrementally. ## Contributing From 0bdaacb976dda9de1a66fd3b0a1dbfac4e7cbee3 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 19:42:07 +0000 Subject: [PATCH 06/16] Update embedded-hal naming in spi.rs --- rp2040-hal/src/pwm/mod.rs | 2 +- rp2040-hal/src/spi.rs | 57 +++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index eda2d80c2..c17bf3232 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -80,8 +80,8 @@ use core::convert::Infallible; use core::marker::PhantomData; use embedded_dma::Word; -use embedded_hal_0_2::PwmPin; use embedded_hal::pwm::{ErrorType, SetDutyCycle}; +use embedded_hal_0_2::PwmPin; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index caccde2f8..d04f60a35 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -28,11 +28,8 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; -use embedded_hal_0_2::{ - blocking::spi, - spi::{FullDuplex, Phase, Polarity}, -}; -use embedded_hal::spi as eh1; +use embedded_hal::spi; +use embedded_hal_0_2::{blocking::spi as blocking_spi02, spi as spi02}; use embedded_hal_nb::spi as eh1nb; use fugit::{HertzU32, RateExtU32}; @@ -69,26 +66,22 @@ pub enum FrameFormat { NationalSemiconductorMicrowire, } -impl From for FrameFormat { - fn from(f: embedded_hal::spi::Mode) -> Self { - let embedded_hal::spi::Mode { polarity, phase } = f; +impl From for FrameFormat { + fn from(f: spi::Mode) -> Self { + let spi::Mode { polarity, phase } = f; match (polarity, phase) { - ( - embedded_hal::spi::Polarity::IdleLow, - embedded_hal::spi::Phase::CaptureOnFirstTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_0), - ( - embedded_hal::spi::Polarity::IdleLow, - embedded_hal::spi::Phase::CaptureOnSecondTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_1), - ( - embedded_hal::spi::Polarity::IdleHigh, - embedded_hal::spi::Phase::CaptureOnFirstTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_2), - ( - embedded_hal::spi::Polarity::IdleHigh, - embedded_hal::spi::Phase::CaptureOnSecondTransition, - ) => FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_3), + (spi::Polarity::IdleLow, spi::Phase::CaptureOnFirstTransition) => { + FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_0) + } + (spi::Polarity::IdleLow, spi::Phase::CaptureOnSecondTransition) => { + FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_1) + } + (spi::Polarity::IdleHigh, spi::Phase::CaptureOnFirstTransition) => { + FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_2) + } + (spi::Polarity::IdleHigh, spi::Phase::CaptureOnSecondTransition) => { + FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_3) + } } } } @@ -279,9 +272,9 @@ impl, const DS: u8> Spi { */ if let FrameFormat::MotorolaSpi(ref mode) = frame_format { w.spo() - .bit(mode.polarity == Polarity::IdleHigh) + .bit(mode.polarity == spi02::Polarity::IdleHigh) .sph() - .bit(mode.phase == Phase::CaptureOnSecondTransition); + .bit(mode.phase == spi02::Phase::CaptureOnSecondTransition); } w }); @@ -377,7 +370,7 @@ macro_rules! impl_write { ($type:ident, [$($nr:expr),+]) => { $( - impl> FullDuplex<$type> for Spi { + impl> spi02::FullDuplex<$type> for Spi { type Error = Infallible; fn read(&mut self) -> Result<$type, nb::Error> { @@ -402,15 +395,15 @@ macro_rules! impl_write { } } - impl> spi::write::Default<$type> for Spi {} - impl> spi::transfer::Default<$type> for Spi {} - impl> spi::write_iter::Default<$type> for Spi {} + impl> blocking_spi02::write::Default<$type> for Spi {} + impl> blocking_spi02::transfer::Default<$type> for Spi {} + impl> blocking_spi02::write_iter::Default<$type> for Spi {} - impl> eh1::ErrorType for Spi { + impl> spi::ErrorType for Spi { type Error = Infallible; } - impl> eh1::SpiBus<$type> for Spi { + impl> spi::SpiBus<$type> for Spi { fn read(&mut self, words: &mut [$type]) -> Result<(), Self::Error> { for word in words.iter_mut() { // write empty word From ab0bf515638f8b2e053aca75f0bf9d265ab7d532 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 19:55:12 +0000 Subject: [PATCH 07/16] Use Mode from eh1 in FrameFormat --- rp2040-hal/src/spi.rs | 44 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index d04f60a35..93b215036 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -28,7 +28,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; -use embedded_hal::spi; +use embedded_hal::spi::{self, Phase, Polarity}; use embedded_hal_0_2::{blocking::spi as blocking_spi02, spi as spi02}; use embedded_hal_nb::spi as eh1nb; use fugit::{HertzU32, RateExtU32}; @@ -43,14 +43,14 @@ use crate::{ mod pins; pub use pins::*; -impl From for FrameFormat { - fn from(f: embedded_hal_0_2::spi::Mode) -> Self { +impl From for FrameFormat { + fn from(f: spi::Mode) -> Self { Self::MotorolaSpi(f) } } -impl From<&embedded_hal_0_2::spi::Mode> for FrameFormat { - fn from(f: &embedded_hal_0_2::spi::Mode) -> Self { +impl From<&spi::Mode> for FrameFormat { + fn from(f: &spi::Mode) -> Self { Self::MotorolaSpi(*f) } } @@ -59,33 +59,39 @@ impl From<&embedded_hal_0_2::spi::Mode> for FrameFormat { #[derive(Clone, Copy, PartialEq, Eq)] pub enum FrameFormat { /// Motorola SPI format. See section 4.4.3.9 of RP2040 datasheet. - MotorolaSpi(embedded_hal_0_2::spi::Mode), + MotorolaSpi(spi::Mode), /// Texas Instruments synchronous serial frame format. See section 4.4.3.8 of RP2040 datasheet. TexasInstrumentsSynchronousSerial, /// National Semiconductor Microwire frame format. See section 4.4.3.14 of RP2040 datasheet. NationalSemiconductorMicrowire, } -impl From for FrameFormat { - fn from(f: spi::Mode) -> Self { - let spi::Mode { polarity, phase } = f; +impl From<&embedded_hal_0_2::spi::Mode> for FrameFormat { + fn from(f: &embedded_hal_0_2::spi::Mode) -> Self { + let embedded_hal_0_2::spi::Mode { polarity, phase } = f; match (polarity, phase) { - (spi::Polarity::IdleLow, spi::Phase::CaptureOnFirstTransition) => { - FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_0) + (spi02::Polarity::IdleLow, spi02::Phase::CaptureOnFirstTransition) => { + FrameFormat::MotorolaSpi(spi::MODE_0) } - (spi::Polarity::IdleLow, spi::Phase::CaptureOnSecondTransition) => { - FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_1) + (spi02::Polarity::IdleLow, spi02::Phase::CaptureOnSecondTransition) => { + FrameFormat::MotorolaSpi(spi::MODE_1) } - (spi::Polarity::IdleHigh, spi::Phase::CaptureOnFirstTransition) => { - FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_2) + (spi02::Polarity::IdleHigh, spi02::Phase::CaptureOnFirstTransition) => { + FrameFormat::MotorolaSpi(spi::MODE_2) } - (spi::Polarity::IdleHigh, spi::Phase::CaptureOnSecondTransition) => { - FrameFormat::MotorolaSpi(embedded_hal_0_2::spi::MODE_3) + (spi02::Polarity::IdleHigh, spi02::Phase::CaptureOnSecondTransition) => { + FrameFormat::MotorolaSpi(spi::MODE_3) } } } } +impl From for FrameFormat { + fn from(f: embedded_hal_0_2::spi::Mode) -> Self { + From::from(&f) + } +} + /// State of the SPI pub trait State: Sealed {} @@ -272,9 +278,9 @@ impl, const DS: u8> Spi { */ if let FrameFormat::MotorolaSpi(ref mode) = frame_format { w.spo() - .bit(mode.polarity == spi02::Polarity::IdleHigh) + .bit(mode.polarity == Polarity::IdleHigh) .sph() - .bit(mode.phase == spi02::Phase::CaptureOnSecondTransition); + .bit(mode.phase == Phase::CaptureOnSecondTransition); } w }); From d533dabfa709a27df9fcf1c34478361b01906400 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 21:27:43 +0000 Subject: [PATCH 08/16] Another tiny improvement in spi.rs --- rp2040-hal/src/spi.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 93b215036..3851e7f49 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -30,7 +30,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; use embedded_hal::spi::{self, Phase, Polarity}; use embedded_hal_0_2::{blocking::spi as blocking_spi02, spi as spi02}; -use embedded_hal_nb::spi as eh1nb; +use embedded_hal_nb::spi::FullDuplex; use fugit::{HertzU32, RateExtU32}; use crate::{ @@ -483,7 +483,7 @@ macro_rules! impl_write { } } - impl> eh1nb::FullDuplex<$type> for Spi { + impl> FullDuplex<$type> for Spi { fn read(&mut self) -> Result<$type, nb::Error> { if !self.is_readable() { return Err(nb::Error::WouldBlock); From 00e27a899144af1dbd534d8164a99a18e694d41b Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 21:31:34 +0000 Subject: [PATCH 09/16] Update embedded-hal naming in reader.rs --- rp2040-hal/src/uart/reader.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index d26a04283..18fbb36f6 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -5,10 +5,10 @@ use super::{FifoWatermark, UartDevice, ValidUartPinout}; use crate::dma::{EndlessReadTarget, ReadTarget}; use crate::pac::uart0::RegisterBlock; -use embedded_hal_0_2::serial::Read; +use embedded_hal_0_2::serial::Read as Read02; use nb::Error::*; -use embedded_hal_nb::serial as eh1nb; +use embedded_hal_nb::serial::{Error, ErrorKind, ErrorType, Read}; /// When there's a read error. #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -38,13 +38,13 @@ pub enum ReadErrorType { Framing, } -impl eh1nb::Error for ReadErrorType { - fn kind(&self) -> eh1nb::ErrorKind { +impl Error for ReadErrorType { + fn kind(&self) -> ErrorKind { match self { - ReadErrorType::Overrun => eh1nb::ErrorKind::Overrun, - ReadErrorType::Break => eh1nb::ErrorKind::Other, - ReadErrorType::Parity => eh1nb::ErrorKind::Parity, - ReadErrorType::Framing => eh1nb::ErrorKind::FrameFormat, + ReadErrorType::Overrun => ErrorKind::Overrun, + ReadErrorType::Break => ErrorKind::Other, + ReadErrorType::Parity => ErrorKind::Parity, + ReadErrorType::Framing => ErrorKind::FrameFormat, } } } @@ -217,7 +217,7 @@ impl> Reader { } } -impl> Read for Reader { +impl> Read02 for Reader { type Error = ReadErrorType; fn read(&mut self) -> nb::Result { @@ -253,11 +253,11 @@ unsafe impl> ReadTarget for Reader { impl> EndlessReadTarget for Reader {} -impl> eh1nb::ErrorType for Reader { +impl> ErrorType for Reader { type Error = ReadErrorType; } -impl> eh1nb::Read for Reader { +impl> Read for Reader { fn read(&mut self) -> nb::Result { let byte: &mut [u8] = &mut [0; 1]; From 64762e39c1bd50ebe3e21dd3870c76ad01cfeb92 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 21:40:31 +0000 Subject: [PATCH 10/16] Update embedded-hal naming in writer.rs --- rp2040-hal/src/uart/writer.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index ca4736593..326c2f610 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -7,8 +7,8 @@ use crate::dma::{EndlessWriteTarget, WriteTarget}; use crate::pac::uart0::RegisterBlock; use core::fmt; use core::{convert::Infallible, marker::PhantomData}; -use embedded_hal_0_2::serial::Write; -use embedded_hal_nb::serial as eh1nb; +use embedded_hal_0_2::serial::Write as Write02; +use embedded_hal_nb::serial::{ErrorType, Write}; use nb::Error::*; /// Set tx FIFO watermark @@ -172,7 +172,7 @@ impl> Writer { } } -impl> Write for Writer { +impl> Write02 for Writer { type Error = Infallible; fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { @@ -208,11 +208,11 @@ unsafe impl> WriteTarget for Writer { impl> EndlessWriteTarget for Writer {} -impl> eh1nb::ErrorType for Writer { - type Error = core::convert::Infallible; +impl> ErrorType for Writer { + type Error = Infallible; } -impl> eh1nb::Write for Writer { +impl> Write for Writer { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { if self.write_raw(&[word]).is_err() { Err(WouldBlock) @@ -232,7 +232,7 @@ impl> eh1nb::Write for Writer { impl> fmt::Write for Writer { fn write_str(&mut self, s: &str) -> fmt::Result { s.bytes() - .try_for_each(|c| nb::block!(self.write(c))) + .try_for_each(|c| nb::block!(Write::write(self, c))) .map_err(|_| fmt::Error) } } From e8bff0c627464ce1730f22274dc702907054fbed Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Wed, 10 Jan 2024 21:43:05 +0000 Subject: [PATCH 11/16] Update embedded-hal naming in peripheral.rs --- rp2040-hal/src/uart/peripheral.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 1ebe25e38..1d5f65291 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -14,7 +14,7 @@ use crate::{ uart::*, }; -use embedded_hal_nb::serial as eh1nb; +use embedded_hal_nb::serial::{ErrorType, Read, Write}; /// An UART Peripheral based on an underlying UART device. pub struct UartPeripheral> { @@ -359,11 +359,11 @@ impl> eh0::Read for UartPeripheral> eh1nb::ErrorType for UartPeripheral { +impl> ErrorType for UartPeripheral { type Error = ReadErrorType; } -impl> eh1nb::Read for UartPeripheral { +impl> Read for UartPeripheral { fn read(&mut self) -> nb::Result { let byte: &mut [u8] = &mut [0; 1]; @@ -393,7 +393,7 @@ impl> eh0::Write for UartPeripheral> eh1nb::Write for UartPeripheral { +impl> Write for UartPeripheral { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { if self.write_raw(&[word]).is_err() { Err(WouldBlock) @@ -412,7 +412,6 @@ impl> eh1nb::Write for UartPeripheral> fmt::Write for UartPeripheral { fn write_str(&mut self, s: &str) -> fmt::Result { - use eh0::Write; s.bytes() .try_for_each(|c| nb::block!(self.write(c))) .map_err(|_| fmt::Error) From d1c49ae0c9a06cbf27ec2b75c529fef7d73a78ed Mon Sep 17 00:00:00 2001 From: "Jonathan Pallant (Ferrous Systems)" Date: Fri, 12 Jan 2024 10:24:25 +0000 Subject: [PATCH 12/16] Add 1.0 impls for InOutPin. --- rp2040-hal/src/gpio/mod.rs | 48 +++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index 6bb20b707..ce1423e1e 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1399,7 +1399,10 @@ impl embedded_hal_0_2::digital::v2::OutputPin for InOutPin { mod eh1 { use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin}; - use super::{Error, FunctionSio, Pin, PinId, PullType, SioConfig, SioInput, SioOutput}; + use super::{ + func, AnyPin, AsInputPin, Error, FunctionSio, InOutPin, Pin, PinId, PullType, SioConfig, + SioInput, SioOutput, + }; impl ErrorType for Pin, P> where @@ -1459,18 +1462,16 @@ mod eh1 { } } - impl<'a, I, F, P> ErrorType for super::AsInputPin<'a, I, F, P> + impl<'a, I, F, P> ErrorType for AsInputPin<'a, I, F, P> where I: PinId, - F: super::func::Function, + F: func::Function, P: PullType, { type Error = Error; } - impl<'a, I: PinId, F: super::func::Function, P: PullType> InputPin - for super::AsInputPin<'a, I, F, P> - { + impl<'a, I: PinId, F: func::Function, P: PullType> InputPin for AsInputPin<'a, I, F, P> { fn is_high(&mut self) -> Result { Ok(self.0._is_high()) } @@ -1479,4 +1480,39 @@ mod eh1 { Ok(self.0._is_low()) } } + + impl ErrorType for InOutPin + where + I: AnyPin, + { + type Error = Error; + } + + impl OutputPin for InOutPin + where + I: AnyPin, + { + fn set_low(&mut self) -> Result<(), Self::Error> { + self.inner._set_low(); + Ok(()) + } + + fn set_high(&mut self) -> Result<(), Self::Error> { + self.inner._set_high(); + Ok(()) + } + } + + impl InputPin for InOutPin + where + I: AnyPin, + { + fn is_high(&mut self) -> Result { + Ok(self.inner._is_high()) + } + + fn is_low(&mut self) -> Result { + Ok(self.inner._is_low()) + } + } } From 2e5237a057d67ce3cceb35a5082955577b8ac749 Mon Sep 17 00:00:00 2001 From: "Jonathan Pallant (Ferrous Systems)" Date: Fri, 12 Jan 2024 11:24:23 +0000 Subject: [PATCH 13/16] Change the examples to use EH 1.0 traits where possible. Adds notes where this isn't (yet) possible. This also involved adding an inherent method to PWM Channels, so you can enable or disable them without using the old trait. --- rp2040-hal/examples/adc.rs | 1 + rp2040-hal/examples/blinky.rs | 4 +- rp2040-hal/examples/dht11.rs | 2 +- rp2040-hal/examples/gpio_dyn_pin_array.rs | 4 +- rp2040-hal/examples/gpio_in_out.rs | 6 +- rp2040-hal/examples/gpio_irq_example.rs | 2 +- rp2040-hal/examples/mem_to_mem_dma.rs | 2 +- rp2040-hal/examples/multicore_fifo_blink.rs | 2 +- rp2040-hal/examples/multicore_polyblink.rs | 2 +- rp2040-hal/examples/pwm_blink.rs | 6 +- rp2040-hal/examples/pwm_irq_input.rs | 5 +- rp2040-hal/examples/rosc_as_system_clock.rs | 2 +- rp2040-hal/examples/rtc_irq_example.rs | 2 +- rp2040-hal/examples/rtc_sleep_example.rs | 2 +- rp2040-hal/examples/spi_dma.rs | 2 +- rp2040-hal/examples/vector_table.rs | 2 +- rp2040-hal/examples/watchdog.rs | 3 +- rp2040-hal/src/adc.rs | 7 +- rp2040-hal/src/gpio/mod.rs | 6 +- rp2040-hal/src/gpio/pin_group.rs | 6 +- rp2040-hal/src/pwm/mod.rs | 124 ++++++++++++-------- rp2040-hal/src/spi.rs | 3 +- rp2040-hal/src/timer.rs | 4 +- rp2040-hal/src/watchdog.rs | 1 + 24 files changed, 120 insertions(+), 80 deletions(-) diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index 32508146e..a6a049450 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -19,6 +19,7 @@ use rp2040_hal as hal; // Some traits we need use core::fmt::Write; +// Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2 use embedded_hal_0_2::adc::OneShot; use hal::fugit::RateExtU32; use rp2040_hal::Clock; diff --git a/rp2040-hal/examples/blinky.rs b/rp2040-hal/examples/blinky.rs index ba877c08e..32825634e 100644 --- a/rp2040-hal/examples/blinky.rs +++ b/rp2040-hal/examples/blinky.rs @@ -21,8 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::blocking::delay::DelayMs; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::delay::DelayNs; +use embedded_hal::digital::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/dht11.rs b/rp2040-hal/examples/dht11.rs index d0adfb547..b6bc64c53 100644 --- a/rp2040-hal/examples/dht11.rs +++ b/rp2040-hal/examples/dht11.rs @@ -24,7 +24,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use hal::Clock; /// The linker will place this boot block at the start of our program image. We diff --git a/rp2040-hal/examples/gpio_dyn_pin_array.rs b/rp2040-hal/examples/gpio_dyn_pin_array.rs index 81adb682e..09462adf4 100644 --- a/rp2040-hal/examples/gpio_dyn_pin_array.rs +++ b/rp2040-hal/examples/gpio_dyn_pin_array.rs @@ -28,8 +28,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::blocking::delay::DelayMs; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::delay::DelayNs; +use embedded_hal::digital::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/gpio_in_out.rs b/rp2040-hal/examples/gpio_in_out.rs index 7adec4489..9dcd49a35 100644 --- a/rp2040-hal/examples/gpio_in_out.rs +++ b/rp2040-hal/examples/gpio_in_out.rs @@ -21,8 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::InputPin; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::InputPin; +use embedded_hal::digital::OutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. @@ -78,7 +78,7 @@ fn main() -> ! { let mut out_pin = pins.gpio25.into_push_pull_output(); // Configure GPIO 23 as an input - let in_pin = pins.gpio23.into_pull_down_input(); + let mut in_pin = pins.gpio23.into_pull_down_input(); // Output is the opposite of the input loop { diff --git a/rp2040-hal/examples/gpio_irq_example.rs b/rp2040-hal/examples/gpio_irq_example.rs index 008c71eda..2cabf3610 100644 --- a/rp2040-hal/examples/gpio_irq_example.rs +++ b/rp2040-hal/examples/gpio_irq_example.rs @@ -34,7 +34,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/mem_to_mem_dma.rs b/rp2040-hal/examples/mem_to_mem_dma.rs index 740e9b11c..a72940dcc 100644 --- a/rp2040-hal/examples/mem_to_mem_dma.rs +++ b/rp2040-hal/examples/mem_to_mem_dma.rs @@ -8,7 +8,7 @@ use cortex_m::singleton; use cortex_m_rt::entry; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use hal::dma::{single_buffer, DMAExt}; use hal::pac; use panic_halt as _; diff --git a/rp2040-hal/examples/multicore_fifo_blink.rs b/rp2040-hal/examples/multicore_fifo_blink.rs index 6380a49a4..0168619e4 100644 --- a/rp2040-hal/examples/multicore_fifo_blink.rs +++ b/rp2040-hal/examples/multicore_fifo_blink.rs @@ -27,7 +27,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/multicore_polyblink.rs b/rp2040-hal/examples/multicore_polyblink.rs index 8e6ad0f87..d30f41b96 100644 --- a/rp2040-hal/examples/multicore_polyblink.rs +++ b/rp2040-hal/examples/multicore_polyblink.rs @@ -26,7 +26,7 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. diff --git a/rp2040-hal/examples/pwm_blink.rs b/rp2040-hal/examples/pwm_blink.rs index 4f3b6647d..2e5d5579b 100644 --- a/rp2040-hal/examples/pwm_blink.rs +++ b/rp2040-hal/examples/pwm_blink.rs @@ -18,7 +18,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal_0_2::PwmPin; +use embedded_hal::pwm::SetDutyCycle; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -105,13 +105,13 @@ fn main() -> ! { // Ramp brightness up for i in LOW..=HIGH { delay.delay_us(8); - channel.set_duty(i); + let _ = channel.set_duty_cycle(i); } // Ramp brightness down for i in (LOW..=HIGH).rev() { delay.delay_us(8); - channel.set_duty(i); + let _ = channel.set_duty_cycle(i); } delay.delay_ms(500); diff --git a/rp2040-hal/examples/pwm_irq_input.rs b/rp2040-hal/examples/pwm_irq_input.rs index 93f369f1e..f28abf40b 100644 --- a/rp2040-hal/examples/pwm_irq_input.rs +++ b/rp2040-hal/examples/pwm_irq_input.rs @@ -20,8 +20,7 @@ use panic_halt as _; use rp2040_hal as hal; // Some traits we need -use embedded_hal_0_2::digital::v2::OutputPin; -use embedded_hal_0_2::PwmPin; +use embedded_hal::digital::OutputPin; // Our interrupt macro use hal::pac::interrupt; @@ -135,7 +134,7 @@ fn main() -> ! { // Connect to GPI O1 as the input to channel B on PWM0 let input_pin = pins.gpio1.reconfigure(); let channel = &mut pwm.channel_b; - channel.enable(); + channel.set_enabled(true); // Enable an interrupt whenever GPI O1 goes from high to low (the end of a pulse) input_pin.set_interrupt_enabled(gpio::Interrupt::EdgeLow, true); diff --git a/rp2040-hal/examples/rosc_as_system_clock.rs b/rp2040-hal/examples/rosc_as_system_clock.rs index d484f51d6..d55d2e661 100644 --- a/rp2040-hal/examples/rosc_as_system_clock.rs +++ b/rp2040-hal/examples/rosc_as_system_clock.rs @@ -21,7 +21,7 @@ use rp2040_hal as hal; // register access use hal::pac; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use fugit::{HertzU32, RateExtU32}; use hal::clocks::{Clock, ClockSource, ClocksManager, StoppableClock}; use hal::pac::rosc::ctrl::FREQ_RANGE_A; diff --git a/rp2040-hal/examples/rtc_irq_example.rs b/rp2040-hal/examples/rtc_irq_example.rs index 490d6f04b..26fe72d03 100644 --- a/rp2040-hal/examples/rtc_irq_example.rs +++ b/rp2040-hal/examples/rtc_irq_example.rs @@ -21,7 +21,7 @@ use rp2040_hal as hal; use hal::{gpio, pac, rtc}; // Some traits we need -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/rtc_sleep_example.rs b/rp2040-hal/examples/rtc_sleep_example.rs index a4b3b75ef..559508a24 100644 --- a/rp2040-hal/examples/rtc_sleep_example.rs +++ b/rp2040-hal/examples/rtc_sleep_example.rs @@ -20,7 +20,7 @@ use rp2040_hal as hal; use hal::{clocks::ClockGate, gpio, pac, rtc}; // Some traits we need -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; // Our interrupt macro use hal::pac::interrupt; diff --git a/rp2040-hal/examples/spi_dma.rs b/rp2040-hal/examples/spi_dma.rs index 0522e8e35..93127adc5 100644 --- a/rp2040-hal/examples/spi_dma.rs +++ b/rp2040-hal/examples/spi_dma.rs @@ -11,7 +11,7 @@ use cortex_m::singleton; use cortex_m_rt::entry; -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use hal::dma::{bidirectional, DMAExt}; use hal::fugit::RateExtU32; use hal::pac; diff --git a/rp2040-hal/examples/vector_table.rs b/rp2040-hal/examples/vector_table.rs index 43ce0150f..1669ab00f 100644 --- a/rp2040-hal/examples/vector_table.rs +++ b/rp2040-hal/examples/vector_table.rs @@ -21,7 +21,7 @@ use hal::pac; // Some traits we need use core::cell::RefCell; use critical_section::Mutex; -use embedded_hal_0_2::digital::v2::ToggleableOutputPin; +use embedded_hal::digital::StatefulOutputPin; use hal::fugit::MicrosDurationU32; use pac::interrupt; use rp2040_hal::clocks::Clock; diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal/examples/watchdog.rs index d4d9db685..4275ad61d 100644 --- a/rp2040-hal/examples/watchdog.rs +++ b/rp2040-hal/examples/watchdog.rs @@ -21,7 +21,8 @@ use rp2040_hal as hal; use hal::pac; // Some traits we need -use embedded_hal_0_2::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; +// Embedded HAL 1.0.0 doesn't have an Watchdog trait, so use the one from 0.2 use embedded_hal_0_2::watchdog::{Watchdog, WatchdogEnable}; use hal::fugit::ExtU32; use rp2040_hal::clocks::Clock; diff --git a/rp2040-hal/src/adc.rs b/rp2040-hal/src/adc.rs index 651256c94..a875ae881 100644 --- a/rp2040-hal/src/adc.rs +++ b/rp2040-hal/src/adc.rs @@ -4,8 +4,10 @@ //! //! ## Usage //! -//! Capture ADC reading from a pin +//! Capture ADC reading from a pin: + //! ```no_run +//! // Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2 //! use embedded_hal_0_2::adc::OneShot; //! use rp2040_hal::{adc::Adc, adc::AdcPin, gpio::Pins, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); @@ -20,7 +22,9 @@ //! ``` //! //! Capture ADC reading from temperature sensor. Note that this needs conversion to be a real-world temperature. +//! //! ```no_run +//! // Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2 //! use embedded_hal_0_2::adc::OneShot; //! use rp2040_hal::{adc::Adc, gpio::Pins, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); @@ -118,6 +122,7 @@ use core::convert::Infallible; use core::marker::PhantomData; +// Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2 use embedded_hal_0_2::adc::{Channel, OneShot}; use crate::{ diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index ce1423e1e..e5b017578 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -2,7 +2,7 @@ //! //! ## Basic usage //! ```no_run -//! use embedded_hal_0_2::digital::v2::{InputPin, OutputPin}; +//! use embedded_hal::digital::{InputPin, OutputPin}; //! use rp2040_hal::{clocks::init_clocks_and_plls, gpio::Pins, watchdog::Watchdog, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); //! let mut watchdog = Watchdog::new(peripherals.WATCHDOG); @@ -19,7 +19,7 @@ //! // Drive output to 0V //! output_pin.set_low().unwrap(); //! // Set a pin to input -//! let input_pin = pins.gpio24.into_floating_input(); +//! let mut input_pin = pins.gpio24.into_floating_input(); //! // pinstate will be true if the pin is above 2V //! let pinstate = input_pin.is_high().unwrap(); //! // pinstate_low will be true if the pin is below 1.15V @@ -39,7 +39,7 @@ // advanced usage of the pin (relative to reading/writing a gpio) and it is the responsibility of // the user to make sure these are in a correct state when converting and passing the pin around. -pub use embedded_hal_0_2::digital::v2::PinState; +pub use embedded_hal::digital::PinState; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, diff --git a/rp2040-hal/src/gpio/pin_group.rs b/rp2040-hal/src/gpio/pin_group.rs index bea6d09c0..99a63bb91 100644 --- a/rp2040-hal/src/gpio/pin_group.rs +++ b/rp2040-hal/src/gpio/pin_group.rs @@ -1,4 +1,8 @@ -use embedded_hal_0_2::digital::v2::PinState; +//! Pin Groups +//! +//! Lets you set multiple GPIOs simultaneously. + +use embedded_hal::digital::PinState; use frunk::{hlist::Plucker, HCons, HNil}; use crate::typelevel::Sealed; diff --git a/rp2040-hal/src/pwm/mod.rs b/rp2040-hal/src/pwm/mod.rs index c17bf3232..9675809a9 100644 --- a/rp2040-hal/src/pwm/mod.rs +++ b/rp2040-hal/src/pwm/mod.rs @@ -37,7 +37,7 @@ //! # &mut pac.RESETS, //! # ); //! # -//! use embedded_hal_0_2::PwmPin; +//! use embedded_hal::pwm::SetDutyCycle; //! //! // Use B channel (which inputs from GPIO 25) //! let mut channel_b = pwm.channel_b; @@ -48,8 +48,8 @@ //! let channel_pin_a = channel_a.output_to(pins.gpio24); //! //! // Set duty cycle -//! channel_a.set_duty(0x00ff); -//! channel_a.get_duty(); +//! channel_a.set_duty_cycle(0x00ff); +//! let max_duty_cycle = channel_a.max_duty_cycle(); //! channel_a.set_inverted(); // Invert the output //! channel_a.clr_inverted(); // Don't invert the output //! ``` @@ -81,7 +81,6 @@ use core::marker::PhantomData; use embedded_dma::Word; use embedded_hal::pwm::{ErrorType, SetDutyCycle}; -use embedded_hal_0_2::PwmPin; use crate::{ atomic_register_access::{write_bitmask_clear, write_bitmask_set}, @@ -626,24 +625,15 @@ impl Channel { impl Sealed for Channel {} -impl PwmPin for Channel { +impl embedded_hal_0_2::PwmPin for Channel { type Duty = u16; - /// We cant disable the channel without disturbing the other channel. - /// So this just sets the duty cycle to zero fn disable(&mut self) { - if self.enabled { - self.duty_cycle = self.regs.read_cc_a(); - } - self.enabled = false; - self.regs.write_cc_a(0) + self.set_enabled(false); } fn enable(&mut self) { - if !self.enabled { - self.enabled = true; - self.regs.write_cc_a(self.duty_cycle) - } + self.set_enabled(true); } fn get_duty(&self) -> Self::Duty { @@ -655,50 +645,23 @@ impl PwmPin for Channel { } fn get_max_duty(&self) -> Self::Duty { - self.regs.read_top() + SetDutyCycle::max_duty_cycle(self) } fn set_duty(&mut self, duty: Self::Duty) { - self.duty_cycle = duty; - if self.enabled { - self.regs.write_cc_a(duty) - } + let _ = SetDutyCycle::set_duty_cycle(self, duty); } } -impl ErrorType for Channel { - type Error = Infallible; -} - -impl SetDutyCycle for Channel { - fn max_duty_cycle(&self) -> u16 { - self.get_max_duty() - } - - fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> { - self.set_duty(duty); - Ok(()) - } -} - -impl PwmPin for Channel { +impl embedded_hal_0_2::PwmPin for Channel { type Duty = u16; - /// We cant disable the channel without disturbing the other channel. - /// So this just sets the duty cycle to zero fn disable(&mut self) { - if self.enabled { - self.duty_cycle = self.regs.read_cc_b(); - } - self.enabled = false; - self.regs.write_cc_b(0) + self.set_enabled(false); } fn enable(&mut self) { - if !self.enabled { - self.enabled = true; - self.regs.write_cc_b(self.duty_cycle) - } + self.set_enabled(true); } fn get_duty(&self) -> Self::Duty { @@ -710,18 +673,66 @@ impl PwmPin for Channel { } fn get_max_duty(&self) -> Self::Duty { - self.regs.read_top().saturating_add(1) + SetDutyCycle::max_duty_cycle(self) } fn set_duty(&mut self, duty: Self::Duty) { + let _ = SetDutyCycle::set_duty_cycle(self, duty); + } +} + +impl ErrorType for Channel { + type Error = Infallible; +} + +impl SetDutyCycle for Channel { + fn max_duty_cycle(&self) -> u16 { + self.regs.read_top().saturating_add(1) + } + + fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> { + self.duty_cycle = duty; + if self.enabled { + self.regs.write_cc_a(duty) + } + Ok(()) + } +} + +impl ErrorType for Channel { + type Error = Infallible; +} + +impl SetDutyCycle for Channel { + fn max_duty_cycle(&self) -> u16 { + self.regs.read_top().saturating_add(1) + } + + fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> { self.duty_cycle = duty; if self.enabled { self.regs.write_cc_b(duty) } + Ok(()) } } impl Channel { + /// Enable or disable the PWM channel + pub fn set_enabled(&mut self, enable: bool) { + if enable && !self.enabled { + // Restore the duty cycle. + self.regs.write_cc_a(self.duty_cycle); + self.enabled = true; + } else if !enable && self.enabled { + // We can't disable it without disturbing the other channel so this + // just sets the duty cycle to zero. + self.duty_cycle = self.regs.read_cc_a(); + self.regs.write_cc_a(0); + self.enabled = false; + } + } + /// Capture a gpio pin and use it as pwm output for channel A pub fn output_to(&mut self, pin: P) -> Pin where @@ -744,6 +755,21 @@ impl Channel { } impl Channel { + /// Enable or disable the PWM channel + pub fn set_enabled(&mut self, enable: bool) { + if enable && !self.enabled { + // Restore the duty cycle. + self.regs.write_cc_b(self.duty_cycle); + self.enabled = true; + } else if !enable && self.enabled { + // We can't disable it without disturbing the other channel so this + // just sets the duty cycle to zero. + self.duty_cycle = self.regs.read_cc_b(); + self.regs.write_cc_b(0); + self.enabled = false; + } + } + /// Capture a gpio pin and use it as pwm output for channel B pub fn output_to(&mut self, pin: P) -> Pin where diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 3851e7f49..73103a233 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -8,7 +8,7 @@ //! ## Usage //! //! ```no_run -//! use embedded_hal_0_2::spi::MODE_0; +//! use embedded_hal::spi::MODE_0; //! use fugit::RateExtU32; //! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio}; //! @@ -29,6 +29,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; use embedded_hal::spi::{self, Phase, Polarity}; +// Support Embedded HAL 0.2 for backwards-compatibility use embedded_hal_0_2::{blocking::spi as blocking_spi02, spi as spi02}; use embedded_hal_nb::spi::FullDuplex; use fugit::{HertzU32, RateExtU32}; diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 6e6d2dee6..083c25761 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -188,7 +188,9 @@ impl embedded_hal::delay::DelayNs for Timer { } } -/// Implementation of the embedded_hal_0_2::Timer traits using rp2040_hal::timer counter +/// Implementation of the embedded_hal_0_2::Timer traits using rp2040_hal::timer counter. +/// +/// There is no Embedded HAL 1.0 equivalent at this time. /// /// ## Usage /// ```no_run diff --git a/rp2040-hal/src/watchdog.rs b/rp2040-hal/src/watchdog.rs index 27b720b4e..212beec69 100644 --- a/rp2040-hal/src/watchdog.rs +++ b/rp2040-hal/src/watchdog.rs @@ -34,6 +34,7 @@ //! ``` //! See [examples/watchdog.rs](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples/watchdog.rs) for a more complete example +// Embedded HAL 1.0.0 doesn't have an ADC trait, so use the one from 0.2 use embedded_hal_0_2::watchdog; use fugit::MicrosDurationU32; From 4f8e6cd069a5fb594fa559437fe3872f3db5345b Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 12 Jan 2024 19:34:18 +0000 Subject: [PATCH 14/16] Work on timer docs --- rp2040-hal/src/timer.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 083c25761..444ce985a 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -188,10 +188,12 @@ impl embedded_hal::delay::DelayNs for Timer { } } -/// Implementation of the embedded_hal_0_2::Timer traits using rp2040_hal::timer counter. +/// Implementation of the [`embedded_hal_0_2::timer`] traits using [`rp2040_hal::timer`] counter. /// /// There is no Embedded HAL 1.0 equivalent at this time. /// +/// If all you need is a delay, [`Timer`] does implement [`embedded_hal::delay::DelayNs`]. +/// /// ## Usage /// ```no_run /// use embedded_hal_0_2::timer::{CountDown, Cancel}; From 4480c1d6f8fb13c1bf1aff69be28012c11e6ec1c Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 13 Jan 2024 18:05:16 +0000 Subject: [PATCH 15/16] embedded_hal_0_2::spi::MODE_0 -> embedded_hal::spi::MODE_0 --- rp2040-hal/examples/spi.rs | 2 +- rp2040-hal/examples/spi_dma.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/examples/spi.rs b/rp2040-hal/examples/spi.rs index 32c20da23..4f47823bb 100644 --- a/rp2040-hal/examples/spi.rs +++ b/rp2040-hal/examples/spi.rs @@ -89,7 +89,7 @@ fn main() -> ! { &mut pac.RESETS, clocks.peripheral_clock.freq(), 16.MHz(), - embedded_hal_0_2::spi::MODE_0, + embedded_hal::spi::MODE_0, ); // Write out 0, ignore return value diff --git a/rp2040-hal/examples/spi_dma.rs b/rp2040-hal/examples/spi_dma.rs index 93127adc5..a18fcfc2f 100644 --- a/rp2040-hal/examples/spi_dma.rs +++ b/rp2040-hal/examples/spi_dma.rs @@ -67,7 +67,7 @@ fn main() -> ! { &mut pac.RESETS, clocks.peripheral_clock.freq(), 16_000_000u32.Hz(), - embedded_hal_0_2::spi::MODE_0, + embedded_hal::spi::MODE_0, ); // Initialize DMA. From da0dfe5d83355e87532c62b874b50097271da667 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Sat, 13 Jan 2024 18:21:30 +0000 Subject: [PATCH 16/16] Implement inherent functions for the watchdog Embedded-hal 0.2 trait impls are now wrappers for inherent functions --- rp2040-hal/examples/watchdog.rs | 2 -- rp2040-hal/src/watchdog.rs | 36 ++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal/examples/watchdog.rs index 4275ad61d..4a9385862 100644 --- a/rp2040-hal/examples/watchdog.rs +++ b/rp2040-hal/examples/watchdog.rs @@ -22,8 +22,6 @@ use hal::pac; // Some traits we need use embedded_hal::digital::OutputPin; -// Embedded HAL 1.0.0 doesn't have an Watchdog trait, so use the one from 0.2 -use embedded_hal_0_2::watchdog::{Watchdog, WatchdogEnable}; use hal::fugit::ExtU32; use rp2040_hal::clocks::Clock; diff --git a/rp2040-hal/src/watchdog.rs b/rp2040-hal/src/watchdog.rs index 212beec69..6969c3551 100644 --- a/rp2040-hal/src/watchdog.rs +++ b/rp2040-hal/src/watchdog.rs @@ -150,18 +150,17 @@ impl Watchdog { w }); } -} -impl watchdog::Watchdog for Watchdog { - fn feed(&mut self) { + /// Set the watchdog counter back to its load value, making sure + /// that the watchdog reboot will not be triggered for the configured + /// period. + pub fn feed(&self) { self.load_counter(self.load_value) } -} - -impl watchdog::WatchdogEnable for Watchdog { - type Time = MicrosDurationU32; - fn start>(&mut self, period: T) { + /// Start the watchdog. This enables a timer which will reboot the + /// rp2040 if [`feed()`] doesnot get called for the configured period. + pub fn start>(&mut self, period: T) { const MAX_PERIOD: u32 = 0xFFFFFF; let delay_us = period.into().to_micros(); @@ -183,10 +182,29 @@ impl watchdog::WatchdogEnable for Watchdog { self.load_counter(self.load_value); self.enable(true); } + + /// Disable the watchdog timer. + pub fn disable(&self) { + self.enable(false) + } +} + +impl watchdog::Watchdog for Watchdog { + fn feed(&mut self) { + (*self).feed() + } +} + +impl watchdog::WatchdogEnable for Watchdog { + type Time = MicrosDurationU32; + + fn start>(&mut self, period: T) { + self.start(period) + } } impl watchdog::WatchdogDisable for Watchdog { fn disable(&mut self) { - self.enable(false) + (*self).disable() } }