2018-10-17 23:25:22 -04:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
import ttfw_idf
|
2018-10-17 23:25:22 -04:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
EXPECT_TIMEOUT = 20
|
2018-11-29 07:34:57 -05:00
|
|
|
|
2018-10-17 23:25:22 -04:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_I2C_CCS811_SENSOR')
|
2018-10-17 23:25:22 -04:00
|
|
|
def test_i2ctools_example(env, extra_data):
|
|
|
|
# Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig
|
|
|
|
dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools')
|
|
|
|
dut.start_app()
|
|
|
|
dut.expect("esp32>", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Get i2c address
|
|
|
|
dut.write("i2cdetect")
|
|
|
|
dut.expect("5b", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Get chip ID
|
|
|
|
dut.write("i2cget -c 0x5b -r 0x20 -l 1")
|
|
|
|
dut.expect("0x81", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Reset sensor
|
|
|
|
dut.write("i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A")
|
|
|
|
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Get status
|
|
|
|
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
|
|
|
|
dut.expect_any("0x10", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Change work mode
|
|
|
|
dut.write("i2cset -c 0x5b -r 0xF4")
|
|
|
|
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
|
|
|
dut.write("i2cset -c 0x5b -r 0x01 0x10")
|
|
|
|
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
|
|
|
# Get new status
|
|
|
|
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
|
|
|
|
dut.expect_any("0x98", "0x90", timeout=EXPECT_TIMEOUT)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_i2ctools_example()
|