1
0
Fork 0

Arduino: Use readBytes for cart read

The Wire documentation only shows read() to get data from
the I²C stream.
However, Wire inherits from Stream, so it gets access to
all the same functions, like readBytes(), which can read
more than one character.

Replace the innermost loop of the cartridge load by
readBytes instead of calling read() in a loop.
This commit is contained in:
Teo-CD 2023-12-17 13:20:48 +00:00
parent 610ccc630a
commit fab5d22364

View file

@ -75,9 +75,7 @@ void loop() {
// Arduino I2C buffer is 32 bytes, so we need multiple requests per page.
for (int j = 0; j < i2c_buff_per_page; j++) {
Wire.requestFrom(eeprom_addr, i2c_buff_size);
for (int k = 0; k < i2c_buff_size; k++) {
pageData[i2c_buff_size*j + k] = Wire.read();
}
Wire.readBytes(pageData + i2c_buff_size*j, i2c_buff_size);
}
// Try to send the full page via serial until the recipient ACKs.