docs(i2c): Modify some variables in I2C driver for good docs

This commit is contained in:
Cao Sen Miao
2023-11-08 10:48:48 +08:00
parent 614aed7409
commit 9d3d9d16f0
5 changed files with 37 additions and 34 deletions
+24 -24
View File
@@ -930,13 +930,13 @@ esp_err_t i2c_del_master_bus(i2c_master_bus_handle_t bus_handle)
return ESP_OK;
}
esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t handle)
esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle)
{
ESP_RETURN_ON_FALSE((handle != NULL), ESP_ERR_INVALID_ARG, TAG, "This bus is not initialized");
ESP_RETURN_ON_FALSE((bus_handle != NULL), ESP_ERR_INVALID_ARG, TAG, "This bus is not initialized");
// Reset I2C master bus
ESP_RETURN_ON_ERROR(s_i2c_hw_fsm_reset(handle), TAG, "I2C master bus reset failed");
ESP_RETURN_ON_ERROR(s_i2c_hw_fsm_reset(bus_handle), TAG, "I2C master bus reset failed");
// Reset I2C status state
atomic_store(&handle->status, I2C_STATUS_IDLE);
atomic_store(&bus_handle->status, I2C_STATUS_IDLE);
return ESP_OK;
}
@@ -1019,24 +1019,24 @@ esp_err_t i2c_master_receive(i2c_master_dev_handle_t i2c_dev, uint8_t *read_buff
return ESP_OK;
}
esp_err_t i2c_master_probe(i2c_master_bus_handle_t i2c_master, uint16_t address, int xfer_timeout_ms)
esp_err_t i2c_master_probe(i2c_master_bus_handle_t bus_handle, uint16_t address, int xfer_timeout_ms)
{
ESP_RETURN_ON_FALSE(i2c_master != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized");
ESP_RETURN_ON_FALSE(bus_handle != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized");
TickType_t ticks_to_wait = (xfer_timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(xfer_timeout_ms);
if (xSemaphoreTake(i2c_master->bus_lock_mux, ticks_to_wait) != pdTRUE) {
if (xSemaphoreTake(bus_handle->bus_lock_mux, ticks_to_wait) != pdTRUE) {
return ESP_ERR_TIMEOUT;
}
i2c_master->cmd_idx = 0;
i2c_master->trans_idx = 0;
i2c_master->trans_done = false;
i2c_hal_context_t *hal = &i2c_master->base->hal;
bus_handle->cmd_idx = 0;
bus_handle->trans_idx = 0;
bus_handle->trans_done = false;
i2c_hal_context_t *hal = &bus_handle->base->hal;
i2c_operation_t i2c_ops[] = {
{.hw_cmd = I2C_TRANS_START_COMMAND},
{.hw_cmd = I2C_TRANS_STOP_COMMAND},
};
i2c_master->i2c_trans = (i2c_transaction_t) {
bus_handle->i2c_trans = (i2c_transaction_t) {
.device_address = address,
.ops = i2c_ops,
.cmd_count = DIM(i2c_ops),
@@ -1044,18 +1044,18 @@ esp_err_t i2c_master_probe(i2c_master_bus_handle_t i2c_master, uint16_t address,
// I2C probe does not have i2c device module. So set the clock parameter independently
// This will not influence device transaction.
i2c_hal_set_bus_timing(hal, 100000, i2c_master->base->clk_src, i2c_master->base->clk_src_freq_hz);
i2c_hal_set_bus_timing(hal, 100000, bus_handle->base->clk_src, bus_handle->base->clk_src_freq_hz);
i2c_ll_master_set_fractional_divider(hal->dev, 0, 0);
i2c_ll_update(hal->dev);
s_i2c_send_commands(i2c_master, ticks_to_wait);
if (i2c_master->status == I2C_STATUS_ACK_ERROR) {
s_i2c_send_commands(bus_handle, ticks_to_wait);
if (bus_handle->status == I2C_STATUS_ACK_ERROR) {
// Reset the status to done, in order not influence next time transaction.
i2c_master->status = I2C_STATUS_DONE;
xSemaphoreGive(i2c_master->bus_lock_mux);
bus_handle->status = I2C_STATUS_DONE;
xSemaphoreGive(bus_handle->bus_lock_mux);
return ESP_ERR_NOT_FOUND;
}
xSemaphoreGive(i2c_master->bus_lock_mux);
xSemaphoreGive(bus_handle->bus_lock_mux);
return ESP_OK;
}
@@ -1082,19 +1082,19 @@ esp_err_t i2c_master_register_event_callbacks(i2c_master_dev_handle_t i2c_dev, c
return ESP_OK;
}
esp_err_t i2c_master_wait_all_done(i2c_master_bus_handle_t i2c_master, int timeout_ms)
esp_err_t i2c_master_bus_wait_all_done(i2c_master_bus_handle_t bus_handle, int timeout_ms)
{
ESP_RETURN_ON_FALSE(i2c_master, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
TickType_t wait_ticks = timeout_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
i2c_transaction_t t;
size_t cnt = i2c_master->num_trans_inflight;
size_t cnt = bus_handle->num_trans_inflight;
for (size_t i = 0; i < cnt; i++) {
ESP_RETURN_ON_FALSE(xQueueReceive(i2c_master->trans_queues[I2C_TRANS_QUEUE_COMPLETE], &t, wait_ticks) == pdTRUE,
ESP_RETURN_ON_FALSE(xQueueReceive(bus_handle->trans_queues[I2C_TRANS_QUEUE_COMPLETE], &t, wait_ticks) == pdTRUE,
ESP_ERR_TIMEOUT, TAG, "flush timeout");
ESP_RETURN_ON_FALSE(xQueueSend(i2c_master->trans_queues[I2C_TRANS_QUEUE_READY], &t, 0) == pdTRUE,
ESP_RETURN_ON_FALSE(xQueueSend(bus_handle->trans_queues[I2C_TRANS_QUEUE_READY], &t, 0) == pdTRUE,
ESP_ERR_INVALID_STATE, TAG, "ready queue full");
i2c_master->num_trans_inflight--;
bus_handle->num_trans_inflight--;
}
return ESP_OK;