1 /*
2 * Copyright (c) 2019 Intel Corp.
3 *
4 * This is most of the display driver for a "standard" 32-bpp framebuffer.
5 * Device-specific drivers must still create the device instance and initialize
6 * it accordingly, but this driver implements most/all of the API functions.
7 * This code attempts to be endian-agnostic. It manipulates the framebuffer
8 * address space only in 32-bit words (and assumes those words are 0xAARRGGBB).
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13 #include <drivers/display.h>
14 #include <display/framebuf.h>
15 #include <string.h>
16
framebuf_blanking_on(const struct device * dev)17 static int framebuf_blanking_on(const struct device *dev)
18 {
19 return -ENOTSUP;
20 }
21
framebuf_blanking_off(const struct device * dev)22 static int framebuf_blanking_off(const struct device *dev)
23 {
24 return -ENOTSUP;
25 }
26
framebuf_get_framebuffer(const struct device * dev)27 static void *framebuf_get_framebuffer(const struct device *dev)
28 {
29 return NULL;
30 }
31
framebuf_set_brightness(const struct device * dev,const uint8_t brightness)32 static int framebuf_set_brightness(const struct device *dev,
33 const uint8_t brightness)
34 {
35 return -ENOTSUP;
36 }
37
framebuf_set_contrast(const struct device * dev,const uint8_t contrast)38 static int framebuf_set_contrast(const struct device *dev,
39 const uint8_t contrast)
40 {
41 return -ENOTSUP;
42 }
43
framebuf_set_pixel_format(const struct device * dev,const enum display_pixel_format format)44 static int framebuf_set_pixel_format(const struct device *dev,
45 const enum display_pixel_format format)
46 {
47 switch (format) {
48 case PIXEL_FORMAT_ARGB_8888:
49 return 0;
50 default:
51 return -ENOTSUP;
52 }
53 }
54
framebuf_set_orientation(const struct device * dev,const enum display_orientation orientation)55 static int framebuf_set_orientation(const struct device *dev,
56 const enum display_orientation orientation)
57 {
58 switch (orientation) {
59 case DISPLAY_ORIENTATION_NORMAL:
60 return 0;
61 default:
62 return -ENOTSUP;
63 }
64 }
65
framebuf_get_capabilities(const struct device * dev,struct display_capabilities * caps)66 static void framebuf_get_capabilities(const struct device *dev,
67 struct display_capabilities *caps)
68 {
69 struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
70
71 caps->x_resolution = data->width;
72 caps->y_resolution = data->height;
73 caps->supported_pixel_formats = PIXEL_FORMAT_ARGB_8888;
74 caps->screen_info = 0;
75 caps->current_pixel_format = PIXEL_FORMAT_ARGB_8888;
76 caps->current_orientation = DISPLAY_ORIENTATION_NORMAL;
77 }
78
framebuf_write(const struct device * dev,const uint16_t x,const uint16_t y,const struct display_buffer_descriptor * desc,const void * buf)79 static int framebuf_write(const struct device *dev, const uint16_t x,
80 const uint16_t y,
81 const struct display_buffer_descriptor *desc,
82 const void *buf)
83 {
84 struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
85 uint32_t *dst = data->buffer;
86 const uint32_t *src = buf;
87 uint32_t row;
88
89 dst += x;
90 dst += (y * data->pitch);
91
92 for (row = 0; row < desc->height; ++row) {
93 (void) memcpy(dst, src, desc->width * sizeof(uint32_t));
94 dst += data->pitch;
95 src += desc->pitch;
96 }
97
98 return 0;
99 }
100
framebuf_read(const struct device * dev,const uint16_t x,const uint16_t y,const struct display_buffer_descriptor * desc,void * buf)101 static int framebuf_read(const struct device *dev, const uint16_t x,
102 const uint16_t y,
103 const struct display_buffer_descriptor *desc,
104 void *buf)
105 {
106 struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
107 uint32_t *src = data->buffer;
108 uint32_t *dst = buf;
109 uint32_t row;
110
111 src += x;
112 src += (y * data->pitch);
113
114 for (row = 0; row < desc->height; ++row) {
115 (void) memcpy(dst, src, desc->width * sizeof(uint32_t));
116 src += data->pitch;
117 dst += desc->pitch;
118 }
119
120 return 0;
121 }
122
123 const struct display_driver_api framebuf_display_api = {
124 .blanking_on = framebuf_blanking_on,
125 .blanking_off = framebuf_blanking_off,
126 .write = framebuf_write,
127 .read = framebuf_read,
128 .get_framebuffer = framebuf_get_framebuffer,
129 .set_brightness = framebuf_set_brightness,
130 .set_contrast = framebuf_set_contrast,
131 .get_capabilities = framebuf_get_capabilities,
132 .set_pixel_format = framebuf_set_pixel_format,
133 .set_orientation = framebuf_set_orientation
134 };
135