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 <errno.h>
8 
9 #include "lvgl_display.h"
10 
set_lvgl_rendering_cb(lv_disp_drv_t * disp_drv)11 int set_lvgl_rendering_cb(lv_disp_drv_t *disp_drv)
12 {
13 	int err = 0;
14 	struct lvgl_disp_data *data =
15 		(struct lvgl_disp_data *)disp_drv->user_data;
16 
17 	switch (data->cap.current_pixel_format) {
18 	case PIXEL_FORMAT_ARGB_8888:
19 		disp_drv->flush_cb = lvgl_flush_cb_32bit;
20 		disp_drv->rounder_cb = NULL;
21 #ifdef CONFIG_LV_COLOR_DEPTH_32
22 		disp_drv->set_px_cb = NULL;
23 #else
24 		disp_drv->set_px_cb = lvgl_set_px_cb_32bit;
25 #endif
26 		break;
27 	case PIXEL_FORMAT_RGB_888:
28 		disp_drv->flush_cb = lvgl_flush_cb_24bit;
29 		disp_drv->rounder_cb = NULL;
30 		disp_drv->set_px_cb = lvgl_set_px_cb_24bit;
31 		break;
32 	case PIXEL_FORMAT_RGB_565:
33 	case PIXEL_FORMAT_BGR_565:
34 		disp_drv->flush_cb = lvgl_flush_cb_16bit;
35 		disp_drv->rounder_cb = NULL;
36 #ifdef CONFIG_LV_COLOR_DEPTH_16
37 		disp_drv->set_px_cb = NULL;
38 #else
39 		disp_drv->set_px_cb = lvgl_set_px_cb_16bit;
40 #endif
41 		break;
42 	case PIXEL_FORMAT_MONO01:
43 	case PIXEL_FORMAT_MONO10:
44 		disp_drv->flush_cb = lvgl_flush_cb_mono;
45 		disp_drv->rounder_cb = lvgl_rounder_cb_mono;
46 		disp_drv->set_px_cb = lvgl_set_px_cb_mono;
47 		break;
48 	default:
49 		disp_drv->flush_cb = NULL;
50 		disp_drv->rounder_cb = NULL;
51 		disp_drv->set_px_cb = NULL;
52 		err = -ENOTSUP;
53 		break;
54 
55 	}
56 
57 	return err;
58 }
59