From 99dfeaf6f28c377eab19768b03dfbbc2e4e1a654 Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Fri, 24 Jun 2022 00:19:41 +0200 Subject: [PATCH] Implement embedded-hal 1.0.0-alpha.8 traits (#366) * Implement embedded-hal 1.0.0-alpha.8 traits * Add comment about missing SPI traits --- rp2040-hal/CHANGELOG.md | 4 ++++ rp2040-hal/Cargo.toml | 2 +- rp2040-hal/README.md | 2 ++ rp2040-hal/src/adc.rs | 49 ----------------------------------------- 4 files changed, 7 insertions(+), 50 deletions(-) diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 3a9c251..e79c94b 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update embedded-hal alpha support to version 1.0.0-alpha.8 + ## [0.5.0] - 2022-06-13 ### MSRV diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 7b5f62b..dc372ab 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0" cortex-m = "0.7.2" cortex-m-rt = ">=0.6.15,<0.8" embedded-hal = { version = "0.2.5", features = ["unproven"] } -eh1_0_alpha = { version = "=1.0.0-alpha.7", package="embedded-hal", optional=true } +eh1_0_alpha = { version = "=1.0.0-alpha.8", package="embedded-hal", optional=true } embedded-time = "0.12.0" itertools = { version = "0.10.1", default-features = false } nb = "1.0" diff --git a/rp2040-hal/README.md b/rp2040-hal/README.md index acc79d0..6f5db1d 100644 --- a/rp2040-hal/README.md +++ b/rp2040-hal/README.md @@ -102,6 +102,8 @@ will be breaking changes even in minor versions of rp2040-hal. Support for embedded-hal 1.0(-alpha) exists in parallel to support for embedded-hal 0.2: Traits of both versions are implemented and can be used at the same time. +The new blocking [SPI traits](https://docs.rs/embedded-hal/1.0.0-alpha.8/embedded_hal/spi/blocking/index.html) +are not yet implemented. ## Contributing diff --git a/rp2040-hal/src/adc.rs b/rp2040-hal/src/adc.rs index cb9fbae..a8a9dcd 100644 --- a/rp2040-hal/src/adc.rs +++ b/rp2040-hal/src/adc.rs @@ -103,15 +103,6 @@ macro_rules! channel { $channel } } - - #[cfg(feature = "eh1_0_alpha")] - impl eh1_0_alpha::adc::nb::Channel for Pin<$pin, FloatingInput> { - type ID = u8; // ADC channels are identified numerically - - fn channel(&self) -> u8 { - $channel - } - } }; } @@ -133,15 +124,6 @@ impl Channel for TempSense { } } -#[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::adc::nb::Channel for TempSense { - type ID = u8; // ADC channels are identified numerically - - fn channel(&self) -> u8 { - TEMPERATURE_SENSOR_CHANNEL - } -} - impl OneShot for Adc where WORD: From, @@ -171,34 +153,3 @@ where Ok(self.device.result.read().result().bits().into()) } } - -#[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::adc::nb::OneShot for Adc -where - WORD: From, - PIN: eh1_0_alpha::adc::nb::Channel, -{ - type Error = (); - - fn read(&mut self, pin: &mut PIN) -> nb::Result { - let chan = PIN::channel(pin); - - if chan == 4 { - self.device.cs.modify(|_, w| w.ts_en().set_bit()) - } - - while !self.device.cs.read().ready().bit_is_set() { - cortex_m::asm::nop(); - } - - self.device - .cs - .modify(|_, w| unsafe { w.ainsel().bits(chan).start_once().set_bit() }); - - while !self.device.cs.read().ready().bit_is_set() { - cortex_m::asm::nop(); - } - - Ok(self.device.result.read().result().bits().into()) - } -}