summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 17:54:44 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 17:54:44 +0100
commitbc0515cd9960d51fbcf367557b3c102196eb210c (patch)
tree0505ab34ec19b9b88ba05f44d36246c3a122eaad
parent3779cf1770e1be03d60623d965f5e56897fbfa43 (diff)
downloadads1x1x-async-bc0515cd9960d51fbcf367557b3c102196eb210c.tar.gz
ads1x1x-async-bc0515cd9960d51fbcf367557b3c102196eb210c.tar.xz
ads1x1x-async-bc0515cd9960d51fbcf367557b3c102196eb210c.zip
Rename data rate to be specific to the resolution
-rw-r--r--src/devices/features/tier1.rs25
-rw-r--r--src/lib.rs4
-rw-r--r--tests/ads1x1x_i2c.rs4
3 files changed, 27 insertions, 6 deletions
diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs
index 30e900e..bd19419 100644
--- a/src/devices/features/tier1.rs
+++ b/src/devices/features/tier1.rs
@@ -1,8 +1,29 @@
//! Common functions
-use { Ads1x1x, DataRate, Error, Register, BitFlags, interface };
+use { Ads1x1x, DataRate12Bit, Error, Register, BitFlags, interface, ic };
+
+impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution12Bit, MODE>
+where
+ DI: interface::WriteData<Error = E>,
+{
+ /// Set data rate
+ pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error<E>> {
+ let config;
+ match rate {
+ DataRate12Bit::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
+ DataRate12Bit::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
+ DataRate12Bit::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
+ DataRate12Bit::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0),
+ DataRate12Bit::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
+ DataRate12Bit::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
+ DataRate12Bit::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
+ }
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
+}
-impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
where
DI: interface::WriteData<Error = E>
{
diff --git a/src/lib.rs b/src/lib.rs
index 4b9cbeb..d4b10e7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -131,9 +131,9 @@ pub mod mode {
pub struct Continuous(());
}
-/// Data rate
+/// Data rate for ADS1013, ADS1014, ADS1015, ADS1018
#[derive(Debug, Clone, PartialEq)]
-pub enum DataRate {
+pub enum DataRate12Bit {
/// 128 SPS
Sps128,
/// 250 SPS
diff --git a/tests/ads1x1x_i2c.rs b/tests/ads1x1x_i2c.rs
index e3dbf21..9470c01 100644
--- a/tests/ads1x1x_i2c.rs
+++ b/tests/ads1x1x_i2c.rs
@@ -2,7 +2,7 @@ extern crate embedded_hal;
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
extern crate ads1x1x;
-use ads1x1x::DataRate;
+use ads1x1x::DataRate12Bit;
#[macro_use]
mod common;
@@ -16,7 +16,7 @@ macro_rules! test_set_data_rate {
fn $name() {
let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()]) ];
let mut dev = new_ads1013(&transactions);
- dev.set_data_rate(DataRate::$variant).unwrap();
+ dev.set_data_rate(DataRate12Bit::$variant).unwrap();
destroy_ads1013(dev);
}
}