1414#if CONFIG_I2C_ENABLE_DEBUG_LOG
1515// The local log level must be defined before including esp_log.h
1616// Set the maximum log level for this source file
17- #define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
17+ #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
1818#endif
1919#include "esp_log.h"
2020#include "esp_intr_alloc.h"
@@ -157,7 +157,7 @@ static void s_i2c_err_log_print(i2c_master_event_t event, bool bypass_nack_log)
157157 }
158158 if (bypass_nack_log != true) {
159159 if (event == I2C_EVENT_NACK ) {
160- ESP_LOGE (TAG , "I2C transaction unexpected nack detected" );
160+ ESP_LOGD (TAG , "I2C transaction unexpected nack detected" );
161161 }
162162 }
163163}
@@ -507,7 +507,7 @@ static void s_i2c_send_commands(i2c_master_bus_handle_t i2c_master, TickType_t t
507507 }
508508
509509 if (atomic_load (& i2c_master -> status ) == I2C_STATUS_ACK_ERROR ) {
510- ESP_LOGE (TAG , "I2C hardware NACK detected" );
510+ ESP_LOGD (TAG , "I2C hardware NACK detected" );
511511 const i2c_ll_hw_cmd_t hw_stop_cmd = {
512512 .op_code = I2C_LL_CMD_STOP ,
513513 };
@@ -942,7 +942,10 @@ static esp_err_t s_i2c_synchronous_transaction(i2c_master_dev_handle_t i2c_dev,
942942 i2c_dev -> master_bus -> trans_finish = false;
943943 i2c_dev -> master_bus -> queue_trans = false;
944944 i2c_dev -> master_bus -> ack_check_disable = i2c_dev -> ack_check_disable ;
945- ESP_GOTO_ON_ERROR (s_i2c_transaction_start (i2c_dev , timeout_ms ), err , TAG , "I2C transaction failed" );
945+ ret = s_i2c_transaction_start (i2c_dev , timeout_ms );
946+ if (ret != ESP_OK ) {
947+ goto err ;
948+ }
946949 xSemaphoreGive (i2c_dev -> master_bus -> bus_lock_mux );
947950 return ret ;
948951
@@ -955,9 +958,6 @@ static esp_err_t s_i2c_synchronous_transaction(i2c_master_dev_handle_t i2c_dev,
955958
956959esp_err_t i2c_new_master_bus (const i2c_master_bus_config_t * bus_config , i2c_master_bus_handle_t * ret_bus_handle )
957960{
958- #if CONFIG_I2C_ENABLE_DEBUG_LOG
959- esp_log_level_set (TAG , ESP_LOG_DEBUG );
960- #endif
961961 esp_err_t ret = ESP_OK ;
962962 i2c_master_bus_t * i2c_master = NULL ;
963963 i2c_port_num_t i2c_port_num = bus_config -> i2c_port ;
@@ -1194,6 +1194,7 @@ esp_err_t i2c_master_multi_buffer_transmit(i2c_master_dev_handle_t i2c_dev, i2c_
11941194 ESP_RETURN_ON_FALSE (array_size <= (SOC_I2C_CMD_REG_NUM - 2 ), ESP_ERR_INVALID_ARG , TAG , "i2c command list cannot contain so many commands" );
11951195 ESP_RETURN_ON_FALSE (buffer_info_array != NULL , ESP_ERR_INVALID_ARG , TAG , "buffer info array is empty" );
11961196
1197+ esp_err_t ret = ESP_OK ;
11971198 size_t op_index = 0 ;
11981199 i2c_operation_t i2c_ops [SOC_I2C_CMD_REG_NUM ] = {};
11991200 i2c_ops [op_index ++ ].hw_cmd .op_code = I2C_LL_CMD_RESTART ;
@@ -1211,11 +1212,11 @@ esp_err_t i2c_master_multi_buffer_transmit(i2c_master_dev_handle_t i2c_dev, i2c_
12111212
12121213 i2c_ops [op_index ++ ].hw_cmd .op_code = I2C_LL_CMD_STOP ;
12131214 if (i2c_dev -> master_bus -> async_trans == false) {
1214- ESP_RETURN_ON_ERROR ( s_i2c_synchronous_transaction (i2c_dev , i2c_ops , op_index , xfer_timeout_ms ), TAG , "I2C transaction failed" );
1215+ ret = s_i2c_synchronous_transaction (i2c_dev , i2c_ops , op_index , xfer_timeout_ms );
12151216 } else {
1216- ESP_RETURN_ON_ERROR ( s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , op_index , xfer_timeout_ms ), TAG , "I2C transaction failed" );
1217+ ret = s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , op_index , xfer_timeout_ms );
12171218 }
1218- return ESP_OK ;
1219+ return ret ;
12191220}
12201221
12211222esp_err_t i2c_master_transmit (i2c_master_dev_handle_t i2c_dev , const uint8_t * write_buffer , size_t write_size , int xfer_timeout_ms )
@@ -1235,6 +1236,7 @@ esp_err_t i2c_master_transmit_receive(i2c_master_dev_handle_t i2c_dev, const uin
12351236 ESP_RETURN_ON_FALSE ((write_buffer != NULL ) && (write_size > 0 ), ESP_ERR_INVALID_ARG , TAG , "i2c transmit buffer or size invalid" );
12361237 ESP_RETURN_ON_FALSE ((read_buffer != NULL ) && (read_size > 0 ), ESP_ERR_INVALID_ARG , TAG , "i2c receive buffer or size invalid" );
12371238
1239+ esp_err_t ret = ESP_OK ;
12381240 i2c_operation_t i2c_ops [] = {
12391241 {.hw_cmd = I2C_TRANS_START_COMMAND },
12401242 {.hw_cmd = I2C_TRANS_WRITE_COMMAND (i2c_dev -> ack_check_disable ? false : true), .data = (uint8_t * )write_buffer , .total_bytes = write_size },
@@ -1245,17 +1247,18 @@ esp_err_t i2c_master_transmit_receive(i2c_master_dev_handle_t i2c_dev, const uin
12451247 };
12461248
12471249 if (i2c_dev -> master_bus -> async_trans == false) {
1248- ESP_RETURN_ON_ERROR ( s_i2c_synchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms ), TAG , "I2C transaction failed" );
1250+ ret = s_i2c_synchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms );
12491251 } else {
1250- ESP_RETURN_ON_ERROR ( s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms ), TAG , "I2C transaction failed" );
1252+ ret = s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms );
12511253 }
1252- return ESP_OK ;
1254+ return ret ;
12531255}
12541256
12551257esp_err_t i2c_master_receive (i2c_master_dev_handle_t i2c_dev , uint8_t * read_buffer , size_t read_size , int xfer_timeout_ms )
12561258{
12571259 ESP_RETURN_ON_FALSE (i2c_dev != NULL , ESP_ERR_INVALID_ARG , TAG , "i2c handle not initialized" );
12581260 ESP_RETURN_ON_FALSE ((read_buffer != NULL ) && (read_size > 0 ), ESP_ERR_INVALID_ARG , TAG , "i2c receive buffer or size invalid" );
1261+ esp_err_t ret = ESP_OK ;
12591262
12601263 i2c_operation_t i2c_ops [] = {
12611264 {.hw_cmd = I2C_TRANS_START_COMMAND },
@@ -1265,11 +1268,11 @@ esp_err_t i2c_master_receive(i2c_master_dev_handle_t i2c_dev, uint8_t *read_buff
12651268 };
12661269
12671270 if (i2c_dev -> master_bus -> async_trans == false) {
1268- ESP_RETURN_ON_ERROR ( s_i2c_synchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms ), TAG , "I2C transaction failed" );
1271+ ret = s_i2c_synchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms );
12691272 } else {
1270- ESP_RETURN_ON_ERROR ( s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms ), TAG , "I2C transaction failed" );
1273+ ret = s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , DIM (i2c_ops ), xfer_timeout_ms );
12711274 }
1272- return ESP_OK ;
1275+ return ret ;
12731276}
12741277
12751278esp_err_t i2c_master_probe (i2c_master_bus_handle_t bus_handle , uint16_t address , int xfer_timeout_ms )
@@ -1362,6 +1365,7 @@ esp_err_t i2c_master_execute_defined_operations(i2c_master_dev_handle_t i2c_dev,
13621365 ESP_RETURN_ON_FALSE (i2c_operation != NULL , ESP_ERR_INVALID_ARG , TAG , "i2c operation pointer is invalid" );
13631366 ESP_RETURN_ON_FALSE (operation_list_num <= (SOC_I2C_CMD_REG_NUM ), ESP_ERR_INVALID_ARG , TAG , "i2c command list cannot contain so many commands" );
13641367
1368+ esp_err_t ret = ESP_OK ;
13651369 i2c_operation_t i2c_ops [operation_list_num ];
13661370 memset (i2c_ops , 0 , sizeof (i2c_ops ));
13671371 for (int i = 0 ; i < operation_list_num ; i ++ ) {
@@ -1398,11 +1402,11 @@ esp_err_t i2c_master_execute_defined_operations(i2c_master_dev_handle_t i2c_dev,
13981402 }
13991403
14001404 if (i2c_dev -> master_bus -> async_trans == false) {
1401- ESP_RETURN_ON_ERROR ( s_i2c_synchronous_transaction (i2c_dev , i2c_ops , operation_list_num , xfer_timeout_ms ), TAG , "I2C transaction failed" );
1405+ ret = s_i2c_synchronous_transaction (i2c_dev , i2c_ops , operation_list_num , xfer_timeout_ms );
14021406 } else {
1403- ESP_RETURN_ON_ERROR ( s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , operation_list_num , xfer_timeout_ms ), TAG , "I2C transaction failed" );
1407+ ret = s_i2c_asynchronous_transaction (i2c_dev , i2c_ops , operation_list_num , xfer_timeout_ms );
14041408 }
1405- return ESP_OK ;
1409+ return ret ;
14061410}
14071411
14081412esp_err_t i2c_master_register_event_callbacks (i2c_master_dev_handle_t i2c_dev , const i2c_master_event_callbacks_t * cbs , void * user_data )
@@ -1445,3 +1449,11 @@ esp_err_t i2c_master_bus_wait_all_done(i2c_master_bus_handle_t bus_handle, int t
14451449 return ESP_OK ;
14461450
14471451}
1452+
1453+ #if CONFIG_I2C_ENABLE_DEBUG_LOG
1454+ __attribute__((constructor ))
1455+ static void i2c_master_override_default_log_level (void )
1456+ {
1457+ esp_log_level_set (TAG , ESP_LOG_VERBOSE );
1458+ }
1459+ #endif
0 commit comments