summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:13:05 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:13:05 +0100
commitd6ec443c2ed0f609cd9b66df4239f22ab87468a6 (patch)
treed48c49b394244ede141766c87db908b2ab0e8d23 /tests
parent2c74e1d9fc6acde2e596fe7f1a8127236fc2ca0b (diff)
downloadads1x1x-async-d6ec443c2ed0f609cd9b66df4239f22ab87468a6.tar.gz
ads1x1x-async-d6ec443c2ed0f609cd9b66df4239f22ab87468a6.tar.xz
ads1x1x-async-d6ec443c2ed0f609cd9b66df4239f22ab87468a6.zip
Encapsule test in module
Diffstat (limited to 'tests')
-rw-r--r--tests/mux_i2c.rs29
1 files changed, 16 insertions, 13 deletions
diff --git a/tests/mux_i2c.rs b/tests/mux_i2c.rs
index 95f97a5..48fc325 100644
--- a/tests/mux_i2c.rs
+++ b/tests/mux_i2c.rs
@@ -11,22 +11,25 @@ mod common;
use common::{ new_ads1015 as new, destroy_ads1015 as destroy,
DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags as BF, Config };
-use embedded_hal::adc::OneShot;
macro_rules! mux_test {
($name:ident, $CS:ident, $config_bits:expr) => {
- #[test]
- fn $name() {
- let default_config = Config::default();
- let config = Config::default().with_high(BF::OS).with_high($config_bits);
- let transactions = [ I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![default_config.msb(), default_config.lsb()]),
- I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]),
- I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![config.msb(), config.lsb()]),
- I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00] ) ];
- let mut dev = new(&transactions);
- let measurement = block!(dev.read(&mut channel::$CS)).unwrap();
- assert_eq!(-2048, measurement);
- destroy(dev);
+ mod $name {
+ use embedded_hal::adc::OneShot;
+ use super::*;
+ #[test]
+ fn can_read() {
+ let default_config = Config::default();
+ let config = Config::default().with_high(BF::OS).with_high($config_bits);
+ let transactions = [ I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![default_config.msb(), default_config.lsb()]),
+ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]),
+ I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![config.msb(), config.lsb()]),
+ I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00] ) ];
+ let mut dev = new(&transactions);
+ let measurement = block!(dev.read(&mut channel::$CS)).unwrap();
+ assert_eq!(-2048, measurement);
+ destroy(dev);
+ }
}
};
}