From 7a44fa473fd90c40cd58eeb926f3e31cb61a390c Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Wed, 18 Dec 2019 09:16:24 +0100 Subject: [PATCH 1/3] 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 --- drivers/display/ssd1306.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/display/ssd1306.c b/drivers/display/ssd1306.c index 3def1e92b1675..39e346afbabc6 100644 --- a/drivers/display/ssd1306.c +++ b/drivers/display/ssd1306.c @@ -231,12 +231,15 @@ int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y, const struct display_buffer_descriptor *desc, const void *buf) { + size_t buf_len; + if (desc->pitch < desc->width) { LOG_ERR("Pitch is smaller then width"); return -1; } - if (buf == NULL || desc->buf_size == 0U) { + buf_len = MIN(desc->buf_size, desc->height * desc->width / 8); + if (buf == NULL || buf_len == 0U) { LOG_ERR("Display buffer is not available"); return -1; } @@ -282,7 +285,7 @@ int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y, return i2c_burst_write(driver->i2c, DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS, SSD1306_CONTROL_LAST_BYTE_DATA, - (u8_t *)buf, desc->buf_size); + (u8_t *)buf, buf_len); #elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE) if (x != 0U && y != 0U) { From 26b11af421ccca63ec6222ff6397413051b25082 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Wed, 18 Dec 2019 10:12:29 +0100 Subject: [PATCH 2/3] drivers: ssd1306: cleanup and make functions static Cleanup and make functions static. Signed-off-by: Johann Fischer --- drivers/display/ssd1306.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/display/ssd1306.c b/drivers/display/ssd1306.c index 39e346afbabc6..5c08037dfbaad 100644 --- a/drivers/display/ssd1306.c +++ b/drivers/display/ssd1306.c @@ -169,7 +169,7 @@ static inline int ssd1306_set_charge_pump(const struct device *dev) DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS); } -int ssd1306_resume(const struct device *dev) +static int ssd1306_resume(const struct device *dev) { struct ssd1306_data *driver = dev->driver_data; /* set display on */ @@ -177,7 +177,7 @@ int ssd1306_resume(const struct device *dev) SSD1306_DISPLAY_ON); } -int ssd1306_suspend(const struct device *dev) +static int ssd1306_suspend(const struct device *dev) { struct ssd1306_data *driver = dev->driver_data; /* set display on */ @@ -185,17 +185,12 @@ int ssd1306_suspend(const struct device *dev) SSD1306_DISPLAY_OFF); } -int ssd1306_write_page(const struct device *dev, u8_t page, void const *data, - size_t length) +#if defined(CONFIG_SSD1306_SH1106_COMPATIBLE) +static int ssd1306_write_page(const struct device *dev, u8_t page, + void const *data, size_t length) { struct ssd1306_data *driver = dev->driver_data; u8_t cmd_buf[] = { -#ifdef OLED_PANEL_CONTROLLER_SSD1306 - SSD1306_CONTROL_BYTE_CMD, - SSD1306_SET_MEM_ADDRESSING_MODE, - SSD1306_CONTROL_BYTE_CMD, - SSD1306_SET_MEM_ADDRESSING_PAGE, -#endif SSD1306_CONTROL_BYTE_CMD, SSD1306_SET_LOWER_COL_ADDRESS | (DT_INST_0_SOLOMON_SSD1306FB_SEGMENT_OFFSET & @@ -226,10 +221,11 @@ int ssd1306_write_page(const struct device *dev, u8_t page, void const *data, SSD1306_CONTROL_LAST_BYTE_DATA, data, length); } +#endif -int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y, - const struct display_buffer_descriptor *desc, - const void *buf) +static int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y, + const struct display_buffer_descriptor *desc, + const void *buf) { size_t buf_len; @@ -332,7 +328,7 @@ static int ssd1306_set_brightness(const struct device *dev, return -ENOTSUP; } -int ssd1306_set_contrast(const struct device *dev, const u8_t contrast) +static int ssd1306_set_contrast(const struct device *dev, const u8_t contrast) { struct ssd1306_data *driver = dev->driver_data; u8_t cmd_buf[] = { From 2c0d76f4d4bc1f09005b1aef0ba00580eb08eef6 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Wed, 18 Dec 2019 10:24:55 +0100 Subject: [PATCH 3/3] drivers: ssd16xx: 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 --- drivers/display/ssd16xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/display/ssd16xx.c b/drivers/display/ssd16xx.c index cf48fd74db2e8..dd80950ad3116 100644 --- a/drivers/display/ssd16xx.c +++ b/drivers/display/ssd16xx.c @@ -231,6 +231,7 @@ static int ssd16xx_write(const struct device *dev, const u16_t x, { struct ssd16xx_data *driver = dev->driver_data; int err; + size_t buf_len; u16_t x_start; u16_t x_end; u16_t y_start; @@ -241,7 +242,8 @@ static int ssd16xx_write(const struct device *dev, const u16_t x, return -EINVAL; } - if (buf == NULL || desc->buf_size == 0U) { + buf_len = MIN(desc->buf_size, desc->height * desc->width / 8); + if (buf == NULL || buf_len == 0U) { LOG_ERR("Display buffer is not available"); return -EINVAL; } @@ -311,7 +313,7 @@ static int ssd16xx_write(const struct device *dev, const u16_t x, } err = ssd16xx_write_cmd(driver, SSD16XX_CMD_WRITE_RAM, (u8_t *)buf, - desc->buf_size); + buf_len); if (err < 0) { return err; }