1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
extern crate ads1x1x;
use ads1x1x::{ ComparatorMode, ComparatorPolarity, ComparatorLatching};
#[macro_use]
mod common;
use common::{ new_ads1014, destroy_ads1014,
DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags, Config };
macro_rules! set_value_test {
($name:ident, $method:ident, $value:expr, $reg:ident, $msb:expr, $lsb:expr) => {
#[test]
fn $name() {
let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::$reg, $msb, $lsb]) ];
let mut dev = new_ads1014(&transactions);
dev.$method($value).unwrap();
destroy_ads1014(dev);
}
}
}
macro_rules! config_test {
($name:ident, $method:ident, $value:expr, $config:expr) => {
set_value_test!($name, $method, $value, CONFIG, $config.msb(), $config.lsb());
}
}
mod can_set_comparator_thresholds {
use super::*;
set_value_test!(low, set_low_threshold, 2047, LOW_TH, 0x7F, 0xF0);
set_value_test!(high, set_high_threshold, 2047, HIGH_TH, 0x7F, 0xF0);
}
mod can_set_comparator_mode {
use super::*;
config_test!(traditional, set_comparator_mode, ComparatorMode::Traditional, Config::default().with_low( BitFlags::COMP_MODE));
config_test!(window, set_comparator_mode, ComparatorMode::Window, Config::default().with_high(BitFlags::COMP_MODE));
}
mod can_set_comparator_polarity {
use super::*;
config_test!(low, set_comparator_polarity, ComparatorPolarity::ActiveLow, Config::default().with_low( BitFlags::COMP_POL));
config_test!(high, set_comparator_polarity, ComparatorPolarity::ActiveHigh, Config::default().with_high(BitFlags::COMP_POL));
}
mod can_set_comparator_latching {
use super::*;
config_test!(non, set_comparator_latching, ComparatorLatching::Nonlatching, Config::default().with_low( BitFlags::COMP_LAT));
config_test!(lat, set_comparator_latching, ComparatorLatching::Latching, Config::default().with_high(BitFlags::COMP_LAT));
}
#[test]
fn can_disable_comparator() {
let config = Config::default().with_high(BitFlags::COMP_QUE1).with_high(BitFlags::COMP_QUE0);
let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ];
let mut dev = new_ads1014(&transactions);
dev.disable_comparator().unwrap();
destroy_ads1014(dev);
}
|