blob: b0503fc579f328e11f5209c4b9417af95da4adb3 [file] [log] [blame]
Charles E. Youse4c63e292019-05-29 10:52:31 -07001/*
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
Anas Nashif9e35d532019-06-25 15:56:36 -040013#include <drivers/display.h>
Charles E. Youse4c63e292019-05-29 10:52:31 -070014#include <display/framebuf.h>
15#include <string.h>
16
17static int framebuf_blanking_on(const struct device *dev)
18{
19 return -ENOTSUP;
20}
21
22static int framebuf_blanking_off(const struct device *dev)
23{
24 return -ENOTSUP;
25}
26
27static void *framebuf_get_framebuffer(const struct device *dev)
28{
29 return NULL;
30}
31
32static int framebuf_set_brightness(const struct device *dev,
Kumar Galaa1b77fd2020-05-27 11:26:57 -050033 const uint8_t brightness)
Charles E. Youse4c63e292019-05-29 10:52:31 -070034{
35 return -ENOTSUP;
36}
37
38static int framebuf_set_contrast(const struct device *dev,
Kumar Galaa1b77fd2020-05-27 11:26:57 -050039 const uint8_t contrast)
Charles E. Youse4c63e292019-05-29 10:52:31 -070040{
41 return -ENOTSUP;
42}
43
44static 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
55static 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
66static 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
Kumar Galaa1b77fd2020-05-27 11:26:57 -050079static int framebuf_write(const struct device *dev, const uint16_t x,
80 const uint16_t y,
Charles E. Youse4c63e292019-05-29 10:52:31 -070081 const struct display_buffer_descriptor *desc,
82 const void *buf)
83{
84 struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
Kumar Galaa1b77fd2020-05-27 11:26:57 -050085 uint32_t *dst = data->buffer;
86 const uint32_t *src = buf;
87 uint32_t row;
Charles E. Youse4c63e292019-05-29 10:52:31 -070088
89 dst += x;
90 dst += (y * data->pitch);
91
92 for (row = 0; row < desc->height; ++row) {
Kumar Galaa1b77fd2020-05-27 11:26:57 -050093 (void) memcpy(dst, src, desc->width * sizeof(uint32_t));
Charles E. Youse4c63e292019-05-29 10:52:31 -070094 dst += data->pitch;
95 src += desc->pitch;
96 }
97
98 return 0;
99}
100
Kumar Galaa1b77fd2020-05-27 11:26:57 -0500101static int framebuf_read(const struct device *dev, const uint16_t x,
102 const uint16_t y,
Charles E. Youse4c63e292019-05-29 10:52:31 -0700103 const struct display_buffer_descriptor *desc,
104 void *buf)
105{
106 struct framebuf_dev_data *data = FRAMEBUF_DATA(dev);
Kumar Galaa1b77fd2020-05-27 11:26:57 -0500107 uint32_t *src = data->buffer;
108 uint32_t *dst = buf;
109 uint32_t row;
Charles E. Youse4c63e292019-05-29 10:52:31 -0700110
111 src += x;
112 src += (y * data->pitch);
113
114 for (row = 0; row < desc->height; ++row) {
Kumar Galaa1b77fd2020-05-27 11:26:57 -0500115 (void) memcpy(dst, src, desc->width * sizeof(uint32_t));
Charles E. Youse4c63e292019-05-29 10:52:31 -0700116 src += data->pitch;
117 dst += desc->pitch;
118 }
119
120 return 0;
121}
122
123const 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};