Skip to content

Commit d50ec79

Browse files
jfischer-nocarlescufi
authored andcommitted
drivers: ssd1306: derive buffer length from width and height attributes
Derive buffer length from width and height attributes and do not use buf_size direct. Signed-off-by: Johann Fischer <[email protected]>
1 parent e924879 commit d50ec79

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/display/ssd1306.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,15 @@ int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y,
231231
const struct display_buffer_descriptor *desc,
232232
const void *buf)
233233
{
234+
size_t buf_len;
235+
234236
if (desc->pitch < desc->width) {
235237
LOG_ERR("Pitch is smaller then width");
236238
return -1;
237239
}
238240

239-
if (buf == NULL || desc->buf_size == 0U) {
241+
buf_len = MIN(desc->buf_size, desc->height * desc->width / 8);
242+
if (buf == NULL || buf_len == 0U) {
240243
LOG_ERR("Display buffer is not available");
241244
return -1;
242245
}
@@ -282,7 +285,7 @@ int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y,
282285
return i2c_burst_write(driver->i2c,
283286
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
284287
SSD1306_CONTROL_LAST_BYTE_DATA,
285-
(u8_t *)buf, desc->buf_size);
288+
(u8_t *)buf, buf_len);
286289

287290
#elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE)
288291
if (x != 0U && y != 0U) {

0 commit comments

Comments
 (0)