1 /*
2 * Copyright (c) 2019 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr.h>
8 #include <lvgl.h>
9 #include "lvgl_display.h"
10
lvgl_flush_cb_24bit(struct _disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)11 void lvgl_flush_cb_24bit(struct _disp_drv_t *disp_drv,
12 const lv_area_t *area, lv_color_t *color_p)
13 {
14 const struct device *display_dev = (const struct device *)disp_drv->user_data;
15 uint16_t w = area->x2 - area->x1 + 1;
16 uint16_t h = area->y2 - area->y1 + 1;
17 struct display_buffer_descriptor desc;
18
19 desc.buf_size = w * 3U * h;
20 desc.width = w;
21 desc.pitch = w;
22 desc.height = h;
23 display_write(display_dev, area->x1, area->y1, &desc, (void *) color_p);
24
25 lv_disp_flush_ready(disp_drv);
26 }
27
lvgl_set_px_cb_24bit(struct _disp_drv_t * disp_drv,uint8_t * buf,lv_coord_t buf_w,lv_coord_t x,lv_coord_t y,lv_color_t color,lv_opa_t opa)28 void lvgl_set_px_cb_24bit(struct _disp_drv_t *disp_drv,
29 uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
30 lv_color_t color, lv_opa_t opa)
31 {
32 uint8_t *buf_xy = buf + x * 3U + y * 3U * buf_w;
33 lv_color32_t converted_color;
34
35 #ifdef CONFIG_LVGL_COLOR_DEPTH_32
36 if (opa != LV_OPA_COVER) {
37 lv_color_t mix_color;
38
39 mix_color.ch.red = *buf_xy;
40 mix_color.ch.green = *(buf_xy+1);
41 mix_color.ch.blue = *(buf_xy+2);
42 color = lv_color_mix(color, mix_color, opa);
43 }
44 #endif
45
46 converted_color.full = lv_color_to32(color);
47 *buf_xy = converted_color.ch.red;
48 *(buf_xy + 1) = converted_color.ch.green;
49 *(buf_xy + 2) = converted_color.ch.blue;
50 }
51