mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 12:10:59 +00:00
feat(i2c_master): Add an api for retrieveing handle via port,
Closes https://github.com/espressif/esp-idf/issues/13968
This commit is contained in:
@@ -46,6 +46,15 @@ static const char *TAG = "i2c.master";
|
||||
#define I2C_FIFO_LEN(port_num) (SOC_I2C_FIFO_LEN)
|
||||
#endif
|
||||
|
||||
// Use the platform to same master bus handle
|
||||
typedef struct i2c_master_bus_platform_t i2c_master_bus_platform_t;
|
||||
|
||||
struct i2c_master_bus_platform_t {
|
||||
i2c_master_bus_handle_t handle[SOC_I2C_NUM];
|
||||
};
|
||||
|
||||
static i2c_master_bus_platform_t s_platform;
|
||||
|
||||
static esp_err_t s_i2c_master_clear_bus(i2c_bus_handle_t handle)
|
||||
{
|
||||
#if !SOC_I2C_SUPPORT_HW_CLR_BUS
|
||||
@@ -989,6 +998,7 @@ esp_err_t i2c_new_master_bus(const i2c_master_bus_config_t *bus_config, i2c_mast
|
||||
xSemaphoreGive(i2c_master->cmd_semphr);
|
||||
|
||||
*ret_bus_handle = i2c_master;
|
||||
s_platform.handle[i2c_port_num] = i2c_master;
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
@@ -1075,6 +1085,18 @@ esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t i2c_master_get_bus_handle(i2c_port_num_t port_num, i2c_master_bus_handle_t *ret_handle)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE((port_num < SOC_I2C_NUM), ESP_ERR_INVALID_ARG, TAG, "invalid i2c port number");
|
||||
if (i2c_bus_occupied(port_num) == false) {
|
||||
ESP_LOGE(TAG, "this port has not been initialized, please initialize it first");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
} else {
|
||||
*ret_handle = s_platform.handle[port_num];
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t i2c_master_multi_buffer_transmit(i2c_master_dev_handle_t i2c_dev, i2c_master_transmit_multi_buffer_info_t *buffer_info_array, size_t array_size, int xfer_timeout_ms)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(i2c_dev != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized");
|
||||
|
Reference in New Issue
Block a user