Merge branch 'feat/i2c_port_handle_func_v5.3' into 'release/v5.3'

feat(i2c_master): Add an api for retrieveing handle via port (backport v5.3)

See merge request espressif/esp-idf!34438
This commit is contained in:
morris
2024-10-28 12:44:33 +08:00
7 changed files with 92 additions and 6 deletions

View File

@@ -140,6 +140,26 @@ Once the :cpp:type:`i2c_device_config_t` structure is populated with mandatory p
i2c_master_dev_handle_t dev_handle;
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
Get I2C master handle via port
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Given that i2c master handle has been initialized in some module(e.g. an audio module), an another module(e.g. a video module) is not convenient to reused the handle. We have a helper function, :cpp:func:`i2c_master_get_bus_handle` for getting the initialized handle via port. However, please make sure the handle has already been initialized ahead of time. Otherwise an error would be reported.
.. code:: c
// Source File 1
#include "driver/i2c_master.h"
i2c_master_bus_handle_t bus_handle;
i2c_master_bus_config_t i2c_mst_config = {
... // same as others
};
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
// Source File 2
#include "driver/i2c_master.h"
i2c_master_bus_handle_t handle;
ESP_ERROR_CHECK(i2c_master_get_bus_handle(0, &handle));
.. only:: SOC_LP_I2C_SUPPORTED
Install I2C master bus with LP I2C Peripheral