summaryrefslogtreecommitdiffstats
path: root/tests/tier2_i2c.rs
blob: 5a3c950f713def4d47cce009d33bfca0ad8421d6 (plain)
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
extern crate embedded_hal;
extern crate embedded_hal_mock as hal;
use hal::i2c::Transaction as I2cTrans;
extern crate ads1x1x;
use ads1x1x::{ ComparatorMode, ComparatorPolarity };

#[macro_use]
mod common;
use common::{ new_ads1014, destroy_ads1014,
              DEVICE_ADDRESS as DEV_ADDR, Register, BitFlags, Config };

macro_rules! test_set_comparator_mode {
    ($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_ads1014(&transactions);
            dev.set_comparator_mode(ComparatorMode::$variant).unwrap();
            destroy_ads1014(dev);
        }
    }
}

mod can_set_comparator_mode {
    use super::*;
    test_set_comparator_mode!(traditional, Traditional, Config::default().with_low( BitFlags::COMP_MODE));
    test_set_comparator_mode!(window,      Window,      Config::default().with_high(BitFlags::COMP_MODE));
}

macro_rules! test_set_comparator_pol {
    ($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_ads1014(&transactions);
            dev.set_comparator_polarity(ComparatorPolarity::$variant).unwrap();
            destroy_ads1014(dev);
        }
    }
}

mod can_set_comparator_polarity {
    use super::*;
    test_set_comparator_pol!(low,  ActiveLow,  Config::default().with_low( BitFlags::COMP_POL));
    test_set_comparator_pol!(high, ActiveHigh, Config::default().with_high(BitFlags::COMP_POL));
}