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
|
2019-11-26 22:58:07 -05:00
|
|
|
dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
dut.start_app()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect('i2c-tools>', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Get i2c address
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.write('i2cdetect')
|
|
|
|
dut.expect('5b', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Get chip ID
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.write('i2cget -c 0x5b -r 0x20 -l 1')
|
|
|
|
dut.expect('0x81', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Reset sensor
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.write('i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A')
|
|
|
|
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Get status
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
|
|
|
dut.expect_any('0x10', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Change work mode
|
2021-01-25 21:49:01 -05:00
|
|
|
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)
|
2018-10-17 23:25:22 -04:00
|
|
|
# Get new status
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
|
|
|
dut.expect_any('0x98', '0x90', timeout=EXPECT_TIMEOUT)
|
2018-10-17 23:25:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_i2ctools_example()
|