Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 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 | |
Anas Nashif | 9e35d53 | 2019-06-25 15:56:36 -0400 | [diff] [blame] | 13 | #include <drivers/display.h> |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 14 | #include <display/framebuf.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | static int framebuf_blanking_on(const struct device *dev) |
| 18 | { |
| 19 | return -ENOTSUP; |
| 20 | } |
| 21 | |
| 22 | static int framebuf_blanking_off(const struct device *dev) |
| 23 | { |
| 24 | return -ENOTSUP; |
| 25 | } |
| 26 | |
| 27 | static void *framebuf_get_framebuffer(const struct device *dev) |
| 28 | { |
| 29 | return NULL; |
| 30 | } |
| 31 | |
| 32 | static int framebuf_set_brightness(const struct device *dev, |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 33 | const uint8_t brightness) |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 34 | { |
| 35 | return -ENOTSUP; |
| 36 | } |
| 37 | |
| 38 | static int framebuf_set_contrast(const struct device *dev, |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 39 | const uint8_t contrast) |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 40 | { |
| 41 | return -ENOTSUP; |
| 42 | } |
| 43 | |
| 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 | |
| 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 | |
| 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 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 79 | static int framebuf_write(const struct device *dev, const uint16_t x, |
| 80 | const uint16_t y, |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 81 | const struct display_buffer_descriptor *desc, |
| 82 | const void *buf) |
| 83 | { |
| 84 | struct framebuf_dev_data *data = FRAMEBUF_DATA(dev); |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 85 | uint32_t *dst = data->buffer; |
| 86 | const uint32_t *src = buf; |
| 87 | uint32_t row; |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 88 | |
| 89 | dst += x; |
| 90 | dst += (y * data->pitch); |
| 91 | |
| 92 | for (row = 0; row < desc->height; ++row) { |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 93 | (void) memcpy(dst, src, desc->width * sizeof(uint32_t)); |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 94 | dst += data->pitch; |
| 95 | src += desc->pitch; |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 101 | static int framebuf_read(const struct device *dev, const uint16_t x, |
| 102 | const uint16_t y, |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 103 | const struct display_buffer_descriptor *desc, |
| 104 | void *buf) |
| 105 | { |
| 106 | struct framebuf_dev_data *data = FRAMEBUF_DATA(dev); |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 107 | uint32_t *src = data->buffer; |
| 108 | uint32_t *dst = buf; |
| 109 | uint32_t row; |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 110 | |
| 111 | src += x; |
| 112 | src += (y * data->pitch); |
| 113 | |
| 114 | for (row = 0; row < desc->height; ++row) { |
Kumar Gala | a1b77fd | 2020-05-27 11:26:57 -0500 | [diff] [blame] | 115 | (void) memcpy(dst, src, desc->width * sizeof(uint32_t)); |
Charles E. Youse | 4c63e29 | 2019-05-29 10:52:31 -0700 | [diff] [blame] | 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 | }; |