oled_ssd1306: fix writing to display

This commit is contained in:
King Kévin 2020-02-27 19:43:14 +01:00
parent bea3ff1f53
commit 699e46521f
1 changed files with 5 additions and 6 deletions

View File

@ -127,13 +127,12 @@ void oled_ssd1306_display(const uint8_t* display_data, uint16_t display_length)
if (I2C_MASTER_RC_NONE != i2c_master_select_slave(OLED_SSD1306_I2C, oled_ssd1306_slave_addr, false, true)) { // select OLED display
return;
}
const uint8_t oled_data[] = {
0x40, // control byte: continuous (multiple byes), data
};
if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, oled_data, LENGTH(oled_data))) { // send data header
return;
uint8_t oled_data[display_length + 1]; // we have to copy the data because we need to send a single block since i2c_master_write sends a stop
oled_data[0] = 0x40; // control byte: continuous (multiple byes), data
for (uint16_t i = 0; i < display_length; i++) {
oled_data[i + 1] = display_data[i];
}
if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, display_data, display_length)) { // send template picture to display
if (I2C_MASTER_RC_NONE != i2c_master_write(OLED_SSD1306_I2C, oled_data, display_length + 1)) { // send data header
return;
}
i2c_master_stop(OLED_SSD1306_I2C); // send stop condition