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_mono(struct _disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)11 void lvgl_flush_cb_mono(struct _disp_drv_t *disp_drv,
12 		const lv_area_t *area, lv_color_t *color_p)
13 {
14 	uint16_t w = area->x2 - area->x1 + 1;
15 	uint16_t h = area->y2 - area->y1 + 1;
16 	const struct device *display_dev = (const struct device *)disp_drv->user_data;
17 	struct display_capabilities cap;
18 	struct display_buffer_descriptor desc;
19 
20 	display_get_capabilities(display_dev, &cap);
21 
22 	desc.buf_size = (w * h)/8U;
23 	desc.width = w;
24 	desc.pitch = w;
25 	desc.height = h;
26 	display_write(display_dev, area->x1, area->y1, &desc, (void *) color_p);
27 	if (cap.screen_info & SCREEN_INFO_DOUBLE_BUFFER) {
28 		display_write(display_dev, area->x1, area->y1, &desc,
29 				(void *) color_p);
30 	}
31 
32 	lv_disp_flush_ready(disp_drv);
33 }
34 
35 
lvgl_set_px_cb_mono(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)36 void lvgl_set_px_cb_mono(struct _disp_drv_t *disp_drv,
37 		uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
38 		lv_color_t color, lv_opa_t opa)
39 {
40 	const struct device *display_dev = (const struct device *)disp_drv->user_data;
41 	uint8_t *buf_xy;
42 	uint8_t bit;
43 	struct display_capabilities cap;
44 
45 	display_get_capabilities(display_dev, &cap);
46 
47 	if (cap.screen_info & SCREEN_INFO_MONO_VTILED) {
48 		buf_xy = buf + x + y/8 * buf_w;
49 
50 		if (cap.screen_info & SCREEN_INFO_MONO_MSB_FIRST) {
51 			bit = 7 - y%8;
52 		} else {
53 			bit = y%8;
54 		}
55 	} else {
56 		buf_xy = buf + x/8 + y * buf_w/8;
57 
58 		if (cap.screen_info & SCREEN_INFO_MONO_MSB_FIRST) {
59 			bit = 7 - x%8;
60 		} else {
61 			bit = x%8;
62 		}
63 	}
64 
65 	if (cap.current_pixel_format == PIXEL_FORMAT_MONO10) {
66 		if (color.full == 0) {
67 			*buf_xy &= ~BIT(bit);
68 		} else {
69 			*buf_xy |= BIT(bit);
70 		}
71 	} else {
72 		if (color.full == 0) {
73 			*buf_xy |= BIT(bit);
74 		} else {
75 			*buf_xy &= ~BIT(bit);
76 		}
77 	}
78 }
79 
lvgl_rounder_cb_mono(struct _disp_drv_t * disp_drv,lv_area_t * area)80 void lvgl_rounder_cb_mono(struct _disp_drv_t *disp_drv,
81 		lv_area_t *area)
82 {
83 	const struct device *display_dev = (const struct device *)disp_drv->user_data;
84 	struct display_capabilities cap;
85 
86 	display_get_capabilities(display_dev, &cap);
87 
88 	if (cap.screen_info & SCREEN_INFO_X_ALIGNMENT_WIDTH) {
89 		area->x1 = 0;
90 		area->x2 = cap.x_resolution - 1;
91 	} else {
92 		if (cap.screen_info & SCREEN_INFO_MONO_VTILED) {
93 			area->y1 &= ~0x7;
94 			area->y2 |= 0x7;
95 		} else {
96 			area->x1 &= ~0x7;
97 			area->x2 |= 0x7;
98 		}
99 	}
100 }
101