Skip to content

Commit

Permalink
esp32_i2c: allow to read many bytes
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Grokhotkov <igrokhotkov@gmail.com>
  • Loading branch information
2 people authored and o-marshmallow committed May 18, 2023
1 parent d13e182 commit 5396d5c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hw/i2c/esp32_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,15 @@ static void esp32_i2c_do_transaction(Esp32I2CState * s)
break;
}
case I2C_OPCODE_READ: {
uint8_t data = i2c_recv(s->bus);
fifo8_push(&s->rx_fifo, data);
size_t length = FIELD_EX32(cmd, I2C_CMD, BYTE_NUM);
for (size_t nbytes = 0; nbytes < length; ++nbytes) {
if (fifo8_num_free(&s->rx_fifo) == 0) {
error_report("esp32_i2c: RX FIFO overflow");
} else {
uint8_t data = i2c_recv(s->bus);
fifo8_push(&s->rx_fifo, data);
}
}
break;
}
case I2C_OPCODE_STOP:
Expand Down

0 comments on commit 5396d5c

Please sign in to comment.