Просмотр исходного кода

Merge branch 'bugfix/i2c_cxx_timeout' into 'master'

[cxx]: fixed I2C master timeout

See merge request espressif/esp-idf!14277
Jakob Hasse 4 лет назад
Родитель
Сommit
e5b556a938

+ 1 - 1
examples/cxx/experimental/experimental_cpp_component/include/i2c_cxx.hpp

@@ -475,7 +475,7 @@ TReturn I2CTransfer<TReturn>::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();
 }

+ 10 - 0
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<uint8_t> 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)