From 0b64ff578509398eaaf0160304d631a45ec9c260 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 12 Apr 2022 22:18:46 +0200 Subject: [PATCH] Remove ADC traits --- CHANGELOG.md | 3 ++ src/adc.rs | 114 --------------------------------------------------- src/lib.rs | 1 - 3 files changed, 3 insertions(+), 115 deletions(-) delete mode 100644 src/adc.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0b047c4..53bdbdd72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `spi`: Add `SpiDevice` trait to represent a single device in a (possibly shared) bus, with managed chip-select (CS) pin. - `spi`: Clarify that implementations are allowed to return before operations are finished, add `flush` to wait until finished. +### Removed +- ADC traits: `adc::nb::OneShot` and `adc::nb::Channel`. + ## [v1.0.0-alpha.7] - 2022-02-09 *** This is (also) an alpha release with breaking changes (sorry) *** diff --git a/src/adc.rs b/src/adc.rs deleted file mode 100644 index ea131afc5..000000000 --- a/src/adc.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! Analog-digital conversion traits - -/// Non-blocking ADC traits -pub mod nb { - /// A marker trait to identify MCU pins that can be used as inputs to an ADC channel. - /// - /// This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the - /// ADC. As ADCs channels can be supplied by multiple pins, this trait defines the relationship - /// between the physical interface and the ADC sampling buffer. - /// - /// ``` - /// # use core::marker::PhantomData; - /// # use embedded_hal::adc::nb::Channel; - /// - /// struct Adc1; // Example ADC with single bank of 8 channels - /// struct Gpio1Pin1(PhantomData); - /// struct Analog(()); // marker type to denote a pin in "analog" mode - /// - /// // GPIO 1 pin 1 can supply an ADC channel when it is configured in Analog mode - /// impl Channel for Gpio1Pin1 { - /// type ID = u8; // ADC channels are identified numerically - /// - /// fn channel(&self) -> Self::ID { - /// 7_u8 // GPIO pin 1 is connected to ADC channel 7 - /// } - /// } - /// - /// struct Adc2; // ADC with two banks of 16 channels - /// struct Gpio2PinA(PhantomData); - /// struct AltFun(()); // marker type to denote some alternate function mode for the pin - /// - /// // GPIO 2 pin A can supply an ADC channel when it's configured in some alternate function mode - /// impl Channel for Gpio2PinA { - /// type ID = (u8, u8); // ADC channels are identified by bank number and channel number - /// - /// fn channel(&self) -> Self::ID { - /// (0, 3) // bank 0 channel 3 - /// } - /// } - /// ``` - pub trait Channel { - /// Channel ID type - /// - /// A type used to identify this ADC channel. For example, if the ADC has eight channels, this - /// might be a `u8`. If the ADC has multiple banks of channels, it could be a tuple, like - /// `(u8: bank_id, u8: channel_id)`. - type ID: Copy; - - /// Get the specific ID that identifies this channel, for example `0_u8` for the first ADC - /// channel, if Self::ID is u8. - fn channel(&self) -> Self::ID; - } - - impl, ADC> Channel for &T { - type ID = T::ID; - - fn channel(&self) -> Self::ID { - T::channel(self) - } - } - - /// ADCs that sample on single channels per request, and do so at the time of the request. - /// - /// This trait is the interface to an ADC that is configured to read a specific channel at the time - /// of the request (in contrast to continuous asynchronous sampling). - /// - /// ``` - /// use embedded_hal::adc::nb::{Channel, OneShot}; - /// - /// struct MyAdc; // 10-bit ADC, with 5 channels - /// # impl MyAdc { - /// # pub fn power_up(&mut self) {} - /// # pub fn power_down(&mut self) {} - /// # pub fn do_conversion(&mut self, chan: u8) -> u16 { 0xAA55_u16 } - /// # } - /// - /// impl OneShot for MyAdc - /// where - /// WORD: From, - /// PIN: Channel, - /// { - /// type Error = (); - /// - /// fn read(&mut self, pin: &mut PIN) -> nb::Result { - /// let chan = 1 << pin.channel(); - /// self.power_up(); - /// let result = self.do_conversion(chan); - /// self.power_down(); - /// Ok(result.into()) - /// } - /// } - /// ``` - pub trait OneShot> { - /// Error type returned by ADC methods - type Error: core::fmt::Debug; - - /// Request that the ADC begin a conversion on the specified pin - /// - /// This method takes a `Pin` reference, as it is expected that the ADC will be able to sample - /// whatever channel underlies the pin. - fn read(&mut self, pin: &mut Pin) -> nb::Result; - } - - impl> OneShot for &mut T - where - T: OneShot, - { - type Error = T::Error; - - fn read(&mut self, pin: &mut Pin) -> nb::Result { - T::read(self, pin) - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 56f61c0a6..30099bf0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,7 +355,6 @@ pub mod fmt; pub use nb; -pub mod adc; pub mod can; pub mod delay; pub mod digital;