summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-08 19:03:13 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-08 19:03:13 +0100
commite31c1d944a814999bd80f86d6fd3fc7f604fc54b (patch)
treebc599a10045831f344de85fa37c6af6ce3f57336
parentdbecb1c3af672b06e7443134e1efc7f5050e99ff (diff)
downloadads1x1x-async-e31c1d944a814999bd80f86d6fd3fc7f604fc54b.tar.gz
ads1x1x-async-e31c1d944a814999bd80f86d6fd3fc7f604fc54b.tar.xz
ads1x1x-async-e31c1d944a814999bd80f86d6fd3fc7f604fc54b.zip
Add tests for setting the data rate
-rw-r--r--tests/ads1x1x_i2c.rs36
-rw-r--r--tests/common/mod.rs7
2 files changed, 40 insertions, 3 deletions
diff --git a/tests/ads1x1x_i2c.rs b/tests/ads1x1x_i2c.rs
new file mode 100644
index 0000000..0163487
--- /dev/null
+++ b/tests/ads1x1x_i2c.rs
@@ -0,0 +1,36 @@
+extern crate embedded_hal;
+extern crate embedded_hal_mock as hal;
+use hal::i2c::Transaction as I2cTrans;
+extern crate ads1x1x;
+use ads1x1x::DataRate;
+
+#[macro_use]
+mod common;
+use common::{ new_ads1013, destroy_ads1013,
+ DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags, Config };
+
+macro_rules! test_set_data_rate {
+ ($name:ident, $variant:ident, $config:expr) => {
+ #[test]
+ 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();
+ destroy_ads1013(dev);
+ }
+ }
+}
+
+mod data_rate {
+ use super::*;
+ test_set_data_rate!(sps128, Sps128, Config::default().with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0));
+ test_set_data_rate!(sps250, Sps250, Config::default().with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0));
+ test_set_data_rate!(sps490, Sps490, Config::default().with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0));
+ test_set_data_rate!(sps920, Sps920, Config::default().with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0));
+ test_set_data_rate!(sps1600, Sps1600, Config::default().with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0));
+ test_set_data_rate!(sps2400, Sps2400, Config::default().with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0));
+ test_set_data_rate!(sps3300, Sps3300, Config::default().with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0));
+}
+
+
+
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 0efbb8a..0a97690 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -14,12 +14,13 @@ impl Register {
}
pub struct BitFlags;
+#[allow(unused)]
impl BitFlags {
//pub const OP_MODE : u16 = 0b0000_0001_0000_0000;
pub const OS : u16 = 0b1000_0000_0000_0000;
- //pub const DR2 : u16 = 0b0000_0000_1000_0000;
- //pub const DR1 : u16 = 0b0000_0000_0100_0000;
- //pub const DR0 : u16 = 0b0000_0000_0010_0000;
+ pub const DR2 : u16 = 0b0000_0000_1000_0000;
+ pub const DR1 : u16 = 0b0000_0000_0100_0000;
+ pub const DR0 : u16 = 0b0000_0000_0010_0000;
}
pub struct Config {