From 77909446f5a6a4349bffabe0fda433151f12ba9b Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Mon, 5 Jul 2021 19:10:59 +0800 Subject: [PATCH] [cxx]: fixed I2C master timeout --- .../experimental_cpp_component/include/i2c_cxx.hpp | 2 +- .../experimental_cpp_component/test/test_i2c.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/cxx/experimental/experimental_cpp_component/include/i2c_cxx.hpp b/examples/cxx/experimental/experimental_cpp_component/include/i2c_cxx.hpp index b1663ba771..85240f2e5e 100644 --- a/examples/cxx/experimental/experimental_cpp_component/include/i2c_cxx.hpp +++ b/examples/cxx/experimental/experimental_cpp_component/include/i2c_cxx.hpp @@ -475,7 +475,7 @@ TReturn I2CTransfer::do_transfer(i2c_port_t i2c_num, uint8_t i2c_addr) CHECK_THROW_SPECIFIC(i2c_master_stop(cmd_link.handle), I2CException); - CHECK_THROW_SPECIFIC(i2c_master_cmd_begin(i2c_num, cmd_link.handle, 1000 / portTICK_RATE_MS), I2CTransferException); + CHECK_THROW_SPECIFIC(i2c_master_cmd_begin(i2c_num, cmd_link.handle, driver_timeout / portTICK_RATE_MS), I2CTransferException); return process_result(); } diff --git a/examples/cxx/experimental/experimental_cpp_component/test/test_i2c.cpp b/examples/cxx/experimental/experimental_cpp_component/test/test_i2c.cpp index 0e9e38bd72..ee07e4ed78 100644 --- a/examples/cxx/experimental/experimental_cpp_component/test/test_i2c.cpp +++ b/examples/cxx/experimental/experimental_cpp_component/test/test_i2c.cpp @@ -69,6 +69,16 @@ TEST_CASE("I2CMaster SDA and SCL equal", "[cxx i2c][leaks=300]") TEST_THROW(I2CMaster(0, 0, 0, 400000), I2CException); } +TEST_CASE("I2Transfer timeout", "[cxx i2c][leaks=300]") +{ + std::vector data = {MAGIC_TEST_NUMBER}; + + // I2CWrite directly inherits from I2CTransfer; it's representative for I2CRead and I2CComposed, too. + I2CWrite writer(data, chrono::milliseconds(50)); + + TEST_THROW(writer.do_transfer(I2C_MASTER_NUM, ADDR), I2CTransferException); +} + // TODO The I2C driver tests are disabled, so disable them here, too. Probably due to no runners. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)