summaryrefslogtreecommitdiffstats
path: root/src/devices/features
diff options
context:
space:
mode:
authorMarkus Reiter <me@reitermark.us>2024-01-19 15:09:19 +0100
committerGitHub <noreply@github.com>2024-01-19 15:09:19 +0100
commit5cd361340635aafe8806c82805622bc6afc4c4d7 (patch)
treee71f39a729a95020ca299925b93d0990416666b7 /src/devices/features
parent6f417d833e2a4041f32a6578332b050d79028910 (diff)
downloadads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.tar.gz
ads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.tar.xz
ads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.zip
Remove `I2cInterface`. (#20)
* Merge `ReadData` and `WriteData` traits. * Remove `I2cInterface`. * Update changelog. * Fix links.
Diffstat (limited to 'src/devices/features')
-rw-r--r--src/devices/features/tier1.rs16
-rw-r--r--src/devices/features/tier2.rs26
2 files changed, 20 insertions, 22 deletions
diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs
index 0c940ee..c6aa8cd 100644
--- a/src/devices/features/tier1.rs
+++ b/src/devices/features/tier1.rs
@@ -1,12 +1,10 @@
//! Common functions
-use crate::{
- ic, interface, Ads1x1x, BitFlags as BF, DataRate12Bit, DataRate16Bit, Error, Register,
-};
+use crate::{ic, Ads1x1x, BitFlags as BF, DataRate12Bit, DataRate16Bit, Error, Register};
-impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution12Bit, MODE>
+impl<I2C, IC, MODE, E> Ads1x1x<I2C, IC, ic::Resolution12Bit, MODE>
where
- DI: interface::WriteData<Error = E>,
+ I2C: embedded_hal::i2c::I2c<Error = E>,
{
/// Set data rate
pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error<E>> {
@@ -21,15 +19,15 @@ where
DR::Sps2400 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_high(BF::DR0),
DR::Sps3300 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
}
-impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution16Bit, MODE>
+impl<I2C, IC, MODE, E> Ads1x1x<I2C, IC, ic::Resolution16Bit, MODE>
where
- DI: interface::WriteData<Error = E>,
+ I2C: embedded_hal::i2c::I2c<Error = E>,
{
/// Set data rate
pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> {
@@ -45,7 +43,7 @@ where
DR::Sps475 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0),
DR::Sps860 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_high(BF::DR0),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs
index 96330a0..4eb989e 100644
--- a/src/devices/features/tier2.rs
+++ b/src/devices/features/tier2.rs
@@ -3,13 +3,13 @@
//! These are the features included only in ADS1x14, ADS1x15
use crate::{
- conversion, ic, interface, Ads1x1x, BitFlags as BF, ComparatorLatching, ComparatorMode,
+ conversion, ic, Ads1x1x, BitFlags as BF, ComparatorLatching, ComparatorMode,
ComparatorPolarity, ComparatorQueue, Error, FullScaleRange, Register,
};
-impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
+impl<I2C, IC, CONV, MODE, E> Ads1x1x<I2C, IC, CONV, MODE>
where
- DI: interface::WriteData<Error = E>,
+ I2C: embedded_hal::i2c::I2c<Error = E>,
IC: ic::Tier2Features,
CONV: conversion::ConvertThreshold<E>,
{
@@ -42,7 +42,7 @@ where
.with_low(BF::PGA1)
.with_high(BF::PGA0),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -55,7 +55,7 @@ where
/// selected. See [`FullScaleRange`](enum.FullScaleRange.html).
pub fn set_low_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> {
let register_value = CONV::convert_threshold(value)?;
- self.iface.write_register(Register::LOW_TH, register_value)
+ self.write_register(Register::LOW_TH, register_value)
}
/// Set raw comparator upper threshold
@@ -66,7 +66,7 @@ where
/// selected. See [`FullScaleRange`](enum.FullScaleRange.html).
pub fn set_high_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> {
let register_value = CONV::convert_threshold(value)?;
- self.iface.write_register(Register::HIGH_TH, register_value)
+ self.write_register(Register::HIGH_TH, register_value)
}
/// Set comparator mode
@@ -75,7 +75,7 @@ where
ComparatorMode::Traditional => self.config.with_low(BF::COMP_MODE),
ComparatorMode::Window => self.config.with_high(BF::COMP_MODE),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -89,7 +89,7 @@ where
ComparatorPolarity::ActiveLow => self.config.with_low(BF::COMP_POL),
ComparatorPolarity::ActiveHigh => self.config.with_high(BF::COMP_POL),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -103,7 +103,7 @@ where
ComparatorLatching::Nonlatching => self.config.with_low(BF::COMP_LAT),
ComparatorLatching::Latching => self.config.with_high(BF::COMP_LAT),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -117,7 +117,7 @@ where
ComparatorQueue::Two => self.config.with_low(BF::COMP_QUE1).with_high(BF::COMP_QUE0),
ComparatorQueue::Four => self.config.with_high(BF::COMP_QUE1).with_low(BF::COMP_QUE0),
};
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -132,7 +132,7 @@ where
.config
.with_high(BF::COMP_QUE1)
.with_high(BF::COMP_QUE0);
- self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
}
@@ -153,7 +153,7 @@ where
{
self.disable_comparator()?;
}
- self.iface.write_register(Register::HIGH_TH, 0x8000)?;
- self.iface.write_register(Register::LOW_TH, 0)
+ self.write_register(Register::HIGH_TH, 0x8000)?;
+ self.write_register(Register::LOW_TH, 0)
}
}