Skip to content

Commit

Permalink
Remove unused InvalidInputData error.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Nov 22, 2024
1 parent 6518f75 commit c6f5bc1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/devices/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Common functions.
use crate::{register::Config, Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, Error};
use crate::{register::Config, Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115};

macro_rules! impl_common_features {
($Ads:ident) => {
Expand All @@ -9,7 +9,7 @@ macro_rules! impl_common_features {
I2C: embedded_hal::i2c::I2c<Error = E>,
{
/// Checks whether a measurement is currently in progress.
pub fn is_measurement_in_progress(&mut self) -> Result<bool, Error<E>> {
pub fn is_measurement_in_progress(&mut self) -> Result<bool, E> {
let config = self.read_reg_u16::<Config>()?;
Ok(!config.contains(Config::OS))
}
Expand Down
8 changes: 2 additions & 6 deletions src/devices/features/tier1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//! Features supported on all ADS1x1x devices.
use crate::{
Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, DataRate12Bit, DataRate16Bit, Error,
};
use crate::{Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, DataRate12Bit, DataRate16Bit};

macro_rules! impl_tier1_features {
($Ads:ident, $DataRate:ty) => {
Expand All @@ -11,7 +7,7 @@ macro_rules! impl_tier1_features {
I2C: embedded_hal::i2c::I2c<Error = E>,
{
/// Sets the data rate.
pub fn set_data_rate(&mut self, rate: $DataRate) -> Result<(), Error<E>> {
pub fn set_data_rate(&mut self, rate: $DataRate) -> Result<(), E> {
let config = rate.configure(self.config);
self.write_reg_u16(config)?;
self.config = config;
Expand Down
20 changes: 10 additions & 10 deletions src/devices/features/tier2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
register::{Config, Conversion12, Conversion16, HiThresh, LoThresh},
Ads1014, Ads1015, Ads1114, Ads1115, ComparatorLatching, ComparatorMode, ComparatorPolarity,
ComparatorQueue, Error, FullScaleRange,
ComparatorQueue, FullScaleRange,
};

macro_rules! doc_threshold {
Expand Down Expand Up @@ -34,7 +34,7 @@ macro_rules! impl_tier2_features {
/// Sets the input voltage measurable range.
///
/// This configures the programmable gain amplifier (PGA) and determines the measurable input voltage range.
pub fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), Error<E>> {
pub fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), E> {
let config = range.configure(self.config);
self.write_reg_u16(config)?;
self.config = config;
Expand All @@ -47,7 +47,7 @@ macro_rules! impl_tier2_features {
/// full-scale range ([`FullScaleRange`]) selected.
///
#[doc = doc_threshold!($($th_range)+)]
pub fn set_low_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> {
pub fn set_low_threshold_raw(&mut self, value: i16) -> Result<(), E> {
let register_value = <$conv>::convert_threshold(value);
self.write_reg_u16(LoThresh(register_value))
}
Expand All @@ -58,13 +58,13 @@ macro_rules! impl_tier2_features {
/// full-scale range ([`FullScaleRange`]) selected.
///
#[doc = doc_threshold!($($th_range)+)]
pub fn set_high_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> {
pub fn set_high_threshold_raw(&mut self, value: i16) -> Result<(), E> {
let register_value = <$conv>::convert_threshold(value);
self.write_reg_u16(HiThresh(register_value))
}

/// Sets the comparator mode.
pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error<E>> {
pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), E> {
let config = match mode {
ComparatorMode::Traditional => self.config.difference(Config::COMP_MODE),
ComparatorMode::Window => self.config.union(Config::COMP_MODE),
Expand All @@ -78,7 +78,7 @@ macro_rules! impl_tier2_features {
pub fn set_comparator_polarity(
&mut self,
polarity: ComparatorPolarity,
) -> Result<(), Error<E>> {
) -> Result<(), E> {
let config = match polarity {
ComparatorPolarity::ActiveLow => self.config.difference(Config::COMP_POL),
ComparatorPolarity::ActiveHigh => self.config.union(Config::COMP_POL),
Expand All @@ -92,7 +92,7 @@ macro_rules! impl_tier2_features {
pub fn set_comparator_latching(
&mut self,
latching: ComparatorLatching,
) -> Result<(), Error<E>> {
) -> Result<(), E> {
let config = match latching {
ComparatorLatching::Nonlatching => self.config.difference(Config::COMP_LAT),
ComparatorLatching::Latching => self.config.union(Config::COMP_LAT),
Expand All @@ -105,7 +105,7 @@ macro_rules! impl_tier2_features {
/// Activates the comparator and sets the alert queue.
///
/// The comparator can be disabled with [`disable_comparator`](Self::disable_comparator).
pub fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), Error<E>> {
pub fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), E> {
let config = match queue {
ComparatorQueue::One => {
self.config.difference(Config::COMP_QUE1).difference(Config::COMP_QUE0)
Expand All @@ -128,7 +128,7 @@ macro_rules! impl_tier2_features {
///
/// The comparator can be enabled by setting the comparator queue using
/// the [`set_comparator_queue`](Self::set_comparator_queue) method.
pub fn disable_comparator(&mut self) -> Result<(), Error<E>> {
pub fn disable_comparator(&mut self) -> Result<(), E> {
let config = self
.config
.union(Config::COMP_QUE1)
Expand All @@ -144,7 +144,7 @@ macro_rules! impl_tier2_features {
/// in continuous-conversion mode, provides a continuous-conversion ready pulse.
///
/// When calling this the comparator will be reset to default and any thresholds will be cleared.
pub fn use_alert_rdy_pin_as_ready(&mut self) -> Result<(), Error<E>> {
pub fn use_alert_rdy_pin_as_ready(&mut self) -> Result<(), E> {
if !self.config.contains(Config::COMP_QUE)
{
self.set_comparator_queue(ComparatorQueue::default())?;
Expand Down
11 changes: 4 additions & 7 deletions src/devices/mode/continuous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
mode,
register::{Config, Conversion12, Conversion16},
Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, ChannelId, Error,
Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, ChannelId,
};
use core::marker::PhantomData;

Expand All @@ -16,7 +16,7 @@ macro_rules! impl_continuous {
/// Changes to one-shot operating mode.
///
/// On error, returns a pair of the error and the current instance.
pub fn into_one_shot(mut self) -> Result<$Ads<I2C, mode::OneShot>, (Error<E>, Self)> {
pub fn into_one_shot(mut self) -> Result<$Ads<I2C, mode::OneShot>, (E, Self)> {
let config = self.config.union(Config::MODE);
if let Err(e) = self.write_reg_u16(config) {
return Err((e, self));
Expand All @@ -31,7 +31,7 @@ macro_rules! impl_continuous {
}

/// Reads the most recent measurement.
pub fn read(&mut self) -> Result<i16, Error<E>> {
pub fn read(&mut self) -> Result<i16, E> {
let value = self.read_reg_u16::<$conv>()?;
Ok(<$conv>::convert_measurement(value.0))
}
Expand All @@ -42,10 +42,7 @@ macro_rules! impl_continuous {
/// ongoing conversion will be completed.
/// The following conversions will use the new channel configuration.
#[allow(unused_variables)]
pub fn select_channel<CH: ChannelId<Self>>(
&mut self,
channel: CH,
) -> Result<(), Error<E>> {
pub fn select_channel<CH: ChannelId<Self>>(&mut self, channel: CH) -> Result<(), E> {
let config = self.config.with_mux_bits(CH::channel_id());
self.write_reg_u16(config)?;
self.config = config;
Expand Down
10 changes: 4 additions & 6 deletions src/devices/mode/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::marker::PhantomData;
use crate::{
mode,
register::{Config, Conversion12, Conversion16},
Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, ChannelId, Error,
Ads1013, Ads1014, Ads1015, Ads1113, Ads1114, Ads1115, ChannelId,
};

macro_rules! impl_one_shot {
Expand All @@ -17,9 +17,7 @@ macro_rules! impl_one_shot {
/// Changes to continuous operating mode.
///
/// On error, returns a pair of the error and the current instance.
pub fn into_continuous(
mut self,
) -> Result<$Ads<I2C, mode::Continuous>, (Error<E>, Self)> {
pub fn into_continuous(mut self) -> Result<$Ads<I2C, mode::Continuous>, (E, Self)> {
let config = self.config.difference(Config::MODE);
if let Err(e) = self.write_reg_u16(config) {
return Err((e, self));
Expand All @@ -33,7 +31,7 @@ macro_rules! impl_one_shot {
})
}

fn trigger_measurement(&mut self, config: &Config) -> Result<(), Error<E>> {
fn trigger_measurement(&mut self, config: &Config) -> Result<(), E> {
let config = config.union(Config::OS);
self.write_reg_u16(config)
}
Expand All @@ -51,7 +49,7 @@ macro_rules! impl_one_shot {
/// measurement on a different channel is requested, a new measurement on
/// using the new channel selection is triggered.
#[allow(unused_variables)]
pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> {
pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, E> {
if self
.is_measurement_in_progress()
.map_err(nb::Error::Other)?
Expand Down
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod devices;
mod types;
pub use types::{
ComparatorLatching, ComparatorMode, ComparatorPolarity, ComparatorQueue, DataRate12Bit,
DataRate16Bit, Error, FullScaleRange, TargetAddr,
DataRate16Bit, FullScaleRange, TargetAddr,
};
pub mod mode;
pub use mode::*;
Expand Down Expand Up @@ -230,20 +230,17 @@ macro_rules! impl_ads1x1x {
where
I2C: embedded_hal::i2c::I2c<Error = E>,
{
pub(crate) fn read_reg_u16<R: Reg<u16>>(&mut self) -> Result<R, Error<E>> {
pub(crate) fn read_reg_u16<R: Reg<u16>>(&mut self) -> Result<R, E> {
let mut buf = [0, 0];
self.i2c
.write_read(self.address.bits(), &[R::ADDR], &mut buf)
.map_err(Error::I2C)?;
.write_read(self.address.bits(), &[R::ADDR], &mut buf)?;
Ok(R::from_reg(u16::from_be_bytes(buf)))
}

pub(crate) fn write_reg_u16<R: Reg<u16>>(&mut self, reg: R) -> Result<(), Error<E>> {
pub(crate) fn write_reg_u16<R: Reg<u16>>(&mut self, reg: R) -> Result<(), E> {
let buf = reg.to_reg().to_be_bytes();
let payload: [u8; 3] = [R::ADDR, buf[0], buf[1]];
self.i2c
.write(self.address.bits(), &payload)
.map_err(Error::I2C)
self.i2c.write(self.address.bits(), &payload)
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
use crate::Config;

/// Errors in this crate
#[derive(Debug, PartialEq)]
pub enum Error<E> {
/// I²C bus error
I2C(E),
/// Invalid input data provided
InvalidInputData,
}

/// Data rate for ADS101x.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub enum DataRate12Bit {
Expand Down

0 comments on commit c6f5bc1

Please sign in to comment.