From 3d73884ae809767be3e2134cf5fda19edfa9a54a Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Fri, 19 Sep 2025 15:14:48 +0800 Subject: [PATCH] refactor(i2c_master): Change member type of `i2c_operation_job_t` Closes https://github.com/espressif/esp-idf/issues/17585 --- components/esp_driver_i2c/i2c_master.c | 2 +- components/esp_driver_i2c/include/driver/i2c_master.h | 6 +++++- docs/sphinx-known-warnings.txt | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/esp_driver_i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c index 8d5f617e69..023122659f 100644 --- a/components/esp_driver_i2c/i2c_master.c +++ b/components/esp_driver_i2c/i2c_master.c @@ -1436,7 +1436,7 @@ esp_err_t i2c_master_execute_defined_operations(i2c_master_dev_handle_t i2c_dev, case I2C_MASTER_CMD_WRITE: i2c_ops[i].hw_cmd.op_code = I2C_LL_CMD_WRITE; i2c_ops[i].hw_cmd.ack_en = i2c_operation[i].write.ack_check; - i2c_ops[i].data = i2c_operation[i].write.data; + i2c_ops[i].data = (uint8_t *)i2c_operation[i].write.data; i2c_ops[i].total_bytes = i2c_operation[i].write.total_bytes; break; case I2C_MASTER_CMD_READ: diff --git a/components/esp_driver_i2c/include/driver/i2c_master.h b/components/esp_driver_i2c/include/driver/i2c_master.h index b53d69d356..a2fe71051e 100644 --- a/components/esp_driver_i2c/include/driver/i2c_master.h +++ b/components/esp_driver_i2c/include/driver/i2c_master.h @@ -59,6 +59,10 @@ typedef struct { * * This structure is used to define individual I2C operations (write or read) * within a sequence of I2C master transactions. + * + * @note The union contains either write or read operation parameters. + * - For write operations: use `.write.data` (const uint8_t *) to provide data to be written + * - For read operations: use `.read.data` (uint8_t *) to provide buffer for storing read data */ typedef struct { i2c_master_command_t command; /**< I2C command indicating the type of operation (START, WRITE, READ, or STOP) */ @@ -70,7 +74,7 @@ typedef struct { */ struct { bool ack_check; /**< Whether to enable ACK check during WRITE operation */ - uint8_t *data; /**< Pointer to the data to be written */ + const uint8_t *data; /**< Pointer to the data to be written */ size_t total_bytes; /**< Total number of bytes to write */ } write; /** diff --git a/docs/sphinx-known-warnings.txt b/docs/sphinx-known-warnings.txt index e53934c1d0..b5669ed51d 100644 --- a/docs/sphinx-known-warnings.txt +++ b/docs/sphinx-known-warnings.txt @@ -193,6 +193,8 @@ If declarator-id: struct esp_cam_ctlr_csi_config_t --------------------------------^ +i2c_master.inc:line: WARNING: Duplicate C++ declaration, also defined at api-reference/peripherals/i2c:line. +Declaration is '.. cpp:member:: uint8_t * data'. isp_types.inc:line: WARNING: Error in declarator or parameters-and-qualifiers If pointer to member declarator: Invalid C++ declaration: Expected identifier in nested name. [error at 32]