fix(i2c_master): Fix bug on esp32 that read one byte data fails

This commit is contained in:
Cao Sen Miao
2024-02-21 18:42:21 +08:00
parent 0c8b9f75f4
commit 715ee3576e
2 changed files with 80 additions and 1 deletions
+9
View File
@@ -251,6 +251,15 @@ static bool s_i2c_read_command(i2c_master_bus_handle_t i2c_master, i2c_operation
}
#else
portENTER_CRITICAL_SAFE(&handle->spinlock);
// If the read command work with ack_val, but no bytes to read, we skip
// this command, and run next command directly.
if (hw_cmd.ack_val == ACK_VAL) {
if (i2c_operation->total_bytes == 0) {
i2c_master->trans_idx++;
hw_cmd = i2c_master->i2c_trans.ops[i2c_master->trans_idx].hw_cmd;
i2c_master->i2c_trans.cmd_count--;
}
}
i2c_ll_master_write_cmd_reg(hal->dev, hw_cmd, i2c_master->cmd_idx);
i2c_ll_master_write_cmd_reg(hal->dev, hw_end_cmd, i2c_master->cmd_idx + 1);
portEXIT_CRITICAL_SAFE(&handle->spinlock);