From ee53fd930192521be6b3e2204560e6b9ccee3250 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Apr 2022 22:07:13 -0400 Subject: [PATCH] refactor(display): Move clear to unblank for EPD driver. --- app/drivers/display/il0323.c | 110 +++++++++++++++++------------------ 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/app/drivers/display/il0323.c b/app/drivers/display/il0323.c index b8117584..f6c9037e 100644 --- a/app/drivers/display/il0323.c +++ b/app/drivers/display/il0323.c @@ -115,28 +115,6 @@ static int il0323_update_display(const struct device *dev) { return 0; } -static int il0323_blanking_off(const struct device *dev) { - struct il0323_data *driver = dev->data; - - if (blanking_on) { - /* Update EPD pannel in normal mode */ - il0323_busy_wait(driver); - if (il0323_update_display(dev)) { - return -EIO; - } - } - - blanking_on = false; - - return 0; -} - -static int il0323_blanking_on(const struct device *dev) { - blanking_on = true; - - return 0; -} - static int il0323_write(const struct device *dev, const uint16_t x, const uint16_t y, const struct display_buffer_descriptor *desc, const void *buf) { struct il0323_data *driver = dev->data; @@ -208,6 +186,58 @@ static int il0323_read(const struct device *dev, const uint16_t x, const uint16_ return -ENOTSUP; } +static int il0323_clear_and_write_buffer(const struct device *dev, uint8_t pattern, bool update) { + struct display_buffer_descriptor desc = { + .buf_size = IL0323_NUMOF_PAGES, + .width = EPD_PANEL_WIDTH, + .height = 1, + .pitch = EPD_PANEL_WIDTH, + }; + uint8_t *line; + + line = k_malloc(IL0323_NUMOF_PAGES); + if (line == NULL) { + return -ENOMEM; + } + + memset(line, pattern, IL0323_NUMOF_PAGES); + for (int i = 0; i < EPD_PANEL_HEIGHT; i++) { + il0323_write(dev, 0, i, &desc, line); + } + + k_free(line); + + if (update == true) { + if (il0323_update_display(dev)) { + return -EIO; + } + } + + return 0; +} + +static int il0323_blanking_off(const struct device *dev) { + struct il0323_data *driver = dev->data; + + if (blanking_on) { + /* Update EPD pannel in normal mode */ + il0323_busy_wait(driver); + if (il0323_clear_and_write_buffer(dev, 0xff, true)) { + return -EIO; + } + } + + blanking_on = false; + + return 0; +} + +static int il0323_blanking_on(const struct device *dev) { + blanking_on = true; + + return 0; +} + static void *il0323_get_framebuffer(const struct device *dev) { LOG_ERR("not supported"); return NULL; @@ -247,36 +277,6 @@ static int il0323_set_pixel_format(const struct device *dev, const enum display_ return -ENOTSUP; } -static int il0323_clear_and_write_buffer(const struct device *dev, uint8_t pattern, bool update) { - struct display_buffer_descriptor desc = { - .buf_size = IL0323_NUMOF_PAGES, - .width = EPD_PANEL_WIDTH, - .height = 1, - .pitch = EPD_PANEL_WIDTH, - }; - uint8_t *line; - - line = k_malloc(IL0323_NUMOF_PAGES); - if (line == NULL) { - return -ENOMEM; - } - - memset(line, pattern, IL0323_NUMOF_PAGES); - for (int i = 0; i < EPD_PANEL_HEIGHT; i++) { - il0323_write(dev, 0, i, &desc, line); - } - - k_free(line); - - if (update == true) { - if (il0323_update_display(dev)) { - return -EIO; - } - } - - return 0; -} - static int il0323_controller_init(const struct device *dev) { struct il0323_data *driver = dev->data; uint8_t tmp[IL0323_TRES_REG_LENGTH]; @@ -350,10 +350,6 @@ static int il0323_controller_init(const struct device *dev) { return -EIO; } - if (il0323_clear_and_write_buffer(dev, 0xff, false)) { - return -1; - } - return 0; } @@ -429,4 +425,4 @@ static struct display_driver_api il0323_driver_api = { }; DEVICE_DT_INST_DEFINE(0, il0323_init, NULL, &il0323_driver, NULL, POST_KERNEL, - CONFIG_APPLICATION_INIT_PRIORITY, &il0323_driver_api); \ No newline at end of file + CONFIG_APPLICATION_INIT_PRIORITY, &il0323_driver_api);