Merge branch 'bugfix/i2c_driver_release_opt' into 'master'

driver/i2c: write i2c command structure to hardware in one operation

See merge request idf/esp-idf!4538
This commit is contained in:
Ivan Grokhotkov 2019-03-19 10:59:21 +08:00
commit 8fbb63c2a7

View file

@ -90,8 +90,10 @@ typedef struct {
uint8_t ack_val; /*!< ack value to send */
uint8_t* data; /*!< data address */
uint8_t byte_cmd; /*!< to save cmd for one byte command mode */
i2c_opmode_t op_code; /*!< haredware cmd type */
}i2c_cmd_t;
i2c_opmode_t op_code; /*!< hardware cmd type */
} i2c_cmd_t;
typedef typeof(I2C[0]->command[0]) i2c_hw_cmd_t;
typedef struct i2c_cmd_link{
i2c_cmd_t cmd; /*!< command in current cmd link */
@ -1160,12 +1162,17 @@ static void IRAM_ATTR i2c_master_cmd_begin_static(i2c_port_t i2c_num)
}
while (p_i2c->cmd_link.head) {
i2c_cmd_t *cmd = &p_i2c->cmd_link.head->cmd;
I2C[i2c_num]->command[p_i2c->cmd_idx].val = 0;
I2C[i2c_num]->command[p_i2c->cmd_idx].ack_en = cmd->ack_en;
I2C[i2c_num]->command[p_i2c->cmd_idx].ack_exp = cmd->ack_exp;
I2C[i2c_num]->command[p_i2c->cmd_idx].ack_val = cmd->ack_val;
I2C[i2c_num]->command[p_i2c->cmd_idx].byte_num = cmd->byte_num;
I2C[i2c_num]->command[p_i2c->cmd_idx].op_code = cmd->op_code;
i2c_hw_cmd_t * const p_cur_hw_cmd = &I2C[i2c_num]->command[p_i2c->cmd_idx];
i2c_hw_cmd_t hw_cmd = {
.ack_en = cmd->ack_en,
.ack_exp = cmd->ack_exp,
.ack_val = cmd->ack_val,
.byte_num = cmd->byte_num,
.op_code = cmd->op_code
};
const i2c_hw_cmd_t hw_end_cmd = {
.op_code = I2C_CMD_END
};
if (cmd->op_code == I2C_CMD_WRITE) {
uint32_t wr_filled = 0;
//TODO: to reduce interrupt number
@ -1182,10 +1189,9 @@ static void IRAM_ATTR i2c_master_cmd_begin_static(i2c_port_t i2c_num)
cmd->byte_num--;
wr_filled ++;
}
//Workaround for register field operation.
I2C[i2c_num]->command[p_i2c->cmd_idx].byte_num = wr_filled;
I2C[i2c_num]->command[p_i2c->cmd_idx + 1].val = 0;
I2C[i2c_num]->command[p_i2c->cmd_idx + 1].op_code = I2C_CMD_END;
hw_cmd.byte_num = wr_filled;
*p_cur_hw_cmd = hw_cmd;
*(p_cur_hw_cmd + 1) = hw_end_cmd;
p_i2c->tx_fifo_remain = I2C_FIFO_LEN;
p_i2c->cmd_idx = 0;
if (cmd->byte_num > 0) {
@ -1198,13 +1204,14 @@ static void IRAM_ATTR i2c_master_cmd_begin_static(i2c_port_t i2c_num)
//TODO: to reduce interrupt number
p_i2c->rx_cnt = cmd->byte_num > p_i2c->rx_fifo_remain ? p_i2c->rx_fifo_remain : cmd->byte_num;
cmd->byte_num -= p_i2c->rx_cnt;
I2C[i2c_num]->command[p_i2c->cmd_idx].byte_num = p_i2c->rx_cnt;
I2C[i2c_num]->command[p_i2c->cmd_idx].ack_val = cmd->ack_val;
I2C[i2c_num]->command[p_i2c->cmd_idx + 1].val = 0;
I2C[i2c_num]->command[p_i2c->cmd_idx + 1].op_code = I2C_CMD_END;
hw_cmd.byte_num = p_i2c->rx_cnt;
hw_cmd.ack_val = cmd->ack_val;
*p_cur_hw_cmd = hw_cmd;
*(p_cur_hw_cmd + 1) = hw_end_cmd;
p_i2c->status = I2C_STATUS_READ;
break;
} else {
*p_cur_hw_cmd = hw_cmd;
}
p_i2c->cmd_idx++;
p_i2c->cmd_link.head = p_i2c->cmd_link.head->next;