Closed wuyuanyi135 closed 2 weeks ago
Yes, the doc is wrong and it will be updated soon
The factory function :cpp:func:`i2c_new_master_bus` and :cpp:func:`i2c_new_slave_device` are guaranteed to be thread safe by the driver, which means that the functions can be called from different RTOS tasks without protection by extra locks.
I2C master operation functions are also guaranteed to be thread safe by bus operation semaphore.
- :cpp:func:`i2c_master_transmit`
- :cpp:func:`i2c_master_multi_buffer_transmit`
- :cpp:func:`i2c_master_transmit_receive`
- :cpp:func:`i2c_master_receive`
- :cpp:func:`i2c_master_probe`
@mythbuster5 Thank you for the confirmation
Answers checklist.
General issue report
According to the doc, only bus creation was deemed as thread safe. Tracing the source code I found that the API are all semaphore-guarded that prevent racing access on the same bus:
For example: https://github.com/espressif/esp-idf/blob/ce6085349f8d5a95fc857e28e2d73d73dd3629b5/components/esp_driver_i2c/i2c_master.c#L898
If so, why are we recommended to put extra locks as per the doc?