1 /*
2 * Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <string.h>
8
9 #include <drivers/display.h>
10
11 struct dummy_display_data {
12 enum display_pixel_format current_pixel_format;
13 };
14
15 static struct dummy_display_data dummy_display_data;
16
dummy_display_init(const struct device * dev)17 static int dummy_display_init(const struct device *dev)
18 {
19 struct dummy_display_data *disp_data =
20 (struct dummy_display_data *)dev->data;
21
22 disp_data->current_pixel_format = PIXEL_FORMAT_ARGB_8888;
23
24 return 0;
25 }
26
dummy_display_write(const struct device * dev,const uint16_t x,const uint16_t y,const struct display_buffer_descriptor * desc,const void * buf)27 static int dummy_display_write(const struct device *dev, const uint16_t x,
28 const uint16_t y,
29 const struct display_buffer_descriptor *desc,
30 const void *buf)
31 {
32 __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
33 __ASSERT(desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
34 "Pitch in descriptor is larger than screen size");
35 __ASSERT(desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
36 "Height in descriptor is larger than screen size");
37 __ASSERT(x + desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
38 "Writing outside screen boundaries in horizontal direction");
39 __ASSERT(y + desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
40 "Writing outside screen boundaries in vertical direction");
41
42 if (desc->width > desc->pitch ||
43 x + desc->pitch > CONFIG_DUMMY_DISPLAY_X_RES ||
44 y + desc->height > CONFIG_DUMMY_DISPLAY_Y_RES) {
45 return -EINVAL;
46 }
47
48 return 0;
49 }
50
dummy_display_read(const struct device * dev,const uint16_t x,const uint16_t y,const struct display_buffer_descriptor * desc,void * buf)51 static int dummy_display_read(const struct device *dev, const uint16_t x,
52 const uint16_t y,
53 const struct display_buffer_descriptor *desc,
54 void *buf)
55 {
56 return -ENOTSUP;
57 }
58
dummy_display_get_framebuffer(const struct device * dev)59 static void *dummy_display_get_framebuffer(const struct device *dev)
60 {
61 return NULL;
62 }
63
dummy_display_blanking_off(const struct device * dev)64 static int dummy_display_blanking_off(const struct device *dev)
65 {
66 return 0;
67 }
68
dummy_display_blanking_on(const struct device * dev)69 static int dummy_display_blanking_on(const struct device *dev)
70 {
71 return 0;
72 }
73
dummy_display_set_brightness(const struct device * dev,const uint8_t brightness)74 static int dummy_display_set_brightness(const struct device *dev,
75 const uint8_t brightness)
76 {
77 return 0;
78 }
79
dummy_display_set_contrast(const struct device * dev,const uint8_t contrast)80 static int dummy_display_set_contrast(const struct device *dev,
81 const uint8_t contrast)
82 {
83 return 0;
84 }
85
dummy_display_get_capabilities(const struct device * dev,struct display_capabilities * capabilities)86 static void dummy_display_get_capabilities(const struct device *dev,
87 struct display_capabilities *capabilities)
88 {
89 struct dummy_display_data *disp_data =
90 (struct dummy_display_data *)dev->data;
91
92 memset(capabilities, 0, sizeof(struct display_capabilities));
93 capabilities->x_resolution = CONFIG_DUMMY_DISPLAY_X_RES;
94 capabilities->y_resolution = CONFIG_DUMMY_DISPLAY_Y_RES;
95 capabilities->supported_pixel_formats = PIXEL_FORMAT_ARGB_8888 |
96 PIXEL_FORMAT_RGB_888 |
97 PIXEL_FORMAT_MONO01 |
98 PIXEL_FORMAT_MONO10;
99 capabilities->current_pixel_format = disp_data->current_pixel_format;
100 capabilities->screen_info = SCREEN_INFO_MONO_VTILED |
101 SCREEN_INFO_MONO_MSB_FIRST;
102 }
103
dummy_display_set_pixel_format(const struct device * dev,const enum display_pixel_format pixel_format)104 static int dummy_display_set_pixel_format(const struct device *dev,
105 const enum display_pixel_format pixel_format)
106 {
107 struct dummy_display_data *disp_data =
108 (struct dummy_display_data *)dev->data;
109
110 disp_data->current_pixel_format = pixel_format;
111 return 0;
112 }
113
114 static const struct display_driver_api dummy_display_api = {
115 .blanking_on = dummy_display_blanking_on,
116 .blanking_off = dummy_display_blanking_off,
117 .write = dummy_display_write,
118 .read = dummy_display_read,
119 .get_framebuffer = dummy_display_get_framebuffer,
120 .set_brightness = dummy_display_set_brightness,
121 .set_contrast = dummy_display_set_contrast,
122 .get_capabilities = dummy_display_get_capabilities,
123 .set_pixel_format = dummy_display_set_pixel_format,
124 };
125
126 DEVICE_DEFINE(dummy_display, CONFIG_DUMMY_DISPLAY_DEV_NAME,
127 &dummy_display_init, NULL,
128 &dummy_display_data, NULL,
129 APPLICATION, CONFIG_DISPLAY_INIT_PRIORITY,
130 &dummy_display_api);
131