drivers: display_dummy: rework to obtain configuration from devicetree
Add bindings for dummy display controller. Rework dummy display controller driver to obtain configuration from devicetree. Remove unnecessary casts, add multi-instance support. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
dee50e9aae
commit
2d175d14f3
7 changed files with 102 additions and 20 deletions
|
@ -1,19 +1,25 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
* Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||||
|
* Copyright (c) 2021 Nordic Semiconductor
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#define DT_DRV_COMPAT zephyr_dummy_dc
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <drivers/display.h>
|
#include <drivers/display.h>
|
||||||
|
#include <device.h>
|
||||||
|
|
||||||
|
struct dummy_display_config {
|
||||||
|
uint16_t height;
|
||||||
|
uint16_t width;
|
||||||
|
};
|
||||||
|
|
||||||
struct dummy_display_data {
|
struct dummy_display_data {
|
||||||
enum display_pixel_format current_pixel_format;
|
enum display_pixel_format current_pixel_format;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct dummy_display_data dummy_display_data;
|
|
||||||
|
|
||||||
static int dummy_display_init(const struct device *dev)
|
static int dummy_display_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
struct dummy_display_data *disp_data =
|
struct dummy_display_data *disp_data =
|
||||||
|
@ -29,19 +35,21 @@ static int dummy_display_write(const struct device *dev, const uint16_t x,
|
||||||
const struct display_buffer_descriptor *desc,
|
const struct display_buffer_descriptor *desc,
|
||||||
const void *buf)
|
const void *buf)
|
||||||
{
|
{
|
||||||
|
const struct dummy_display_config *config = dev->config;
|
||||||
|
|
||||||
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
|
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
|
||||||
__ASSERT(desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
|
__ASSERT(desc->pitch <= config->width,
|
||||||
"Pitch in descriptor is larger than screen size");
|
"Pitch in descriptor is larger than screen size");
|
||||||
__ASSERT(desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
|
__ASSERT(desc->height <= config->height,
|
||||||
"Height in descriptor is larger than screen size");
|
"Height in descriptor is larger than screen size");
|
||||||
__ASSERT(x + desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
|
__ASSERT(x + desc->pitch <= config->width,
|
||||||
"Writing outside screen boundaries in horizontal direction");
|
"Writing outside screen boundaries in horizontal direction");
|
||||||
__ASSERT(y + desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
|
__ASSERT(y + desc->height <= config->height,
|
||||||
"Writing outside screen boundaries in vertical direction");
|
"Writing outside screen boundaries in vertical direction");
|
||||||
|
|
||||||
if (desc->width > desc->pitch ||
|
if (desc->width > desc->pitch ||
|
||||||
x + desc->pitch > CONFIG_DUMMY_DISPLAY_X_RES ||
|
x + desc->pitch > config->width ||
|
||||||
y + desc->height > CONFIG_DUMMY_DISPLAY_Y_RES) {
|
y + desc->height > config->height) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,12 +94,12 @@ static int dummy_display_set_contrast(const struct device *dev,
|
||||||
static void dummy_display_get_capabilities(const struct device *dev,
|
static void dummy_display_get_capabilities(const struct device *dev,
|
||||||
struct display_capabilities *capabilities)
|
struct display_capabilities *capabilities)
|
||||||
{
|
{
|
||||||
struct dummy_display_data *disp_data =
|
const struct dummy_display_config *config = dev->config;
|
||||||
(struct dummy_display_data *)dev->data;
|
struct dummy_display_data *disp_data = dev->data;
|
||||||
|
|
||||||
memset(capabilities, 0, sizeof(struct display_capabilities));
|
memset(capabilities, 0, sizeof(struct display_capabilities));
|
||||||
capabilities->x_resolution = CONFIG_DUMMY_DISPLAY_X_RES;
|
capabilities->x_resolution = config->width;
|
||||||
capabilities->y_resolution = CONFIG_DUMMY_DISPLAY_Y_RES;
|
capabilities->y_resolution = config->height;
|
||||||
capabilities->supported_pixel_formats = PIXEL_FORMAT_ARGB_8888 |
|
capabilities->supported_pixel_formats = PIXEL_FORMAT_ARGB_8888 |
|
||||||
PIXEL_FORMAT_RGB_888 |
|
PIXEL_FORMAT_RGB_888 |
|
||||||
PIXEL_FORMAT_MONO01 |
|
PIXEL_FORMAT_MONO01 |
|
||||||
|
@ -104,8 +112,7 @@ static void dummy_display_get_capabilities(const struct device *dev,
|
||||||
static int dummy_display_set_pixel_format(const struct device *dev,
|
static int dummy_display_set_pixel_format(const struct device *dev,
|
||||||
const enum display_pixel_format pixel_format)
|
const enum display_pixel_format pixel_format)
|
||||||
{
|
{
|
||||||
struct dummy_display_data *disp_data =
|
struct dummy_display_data *disp_data = dev->data;
|
||||||
(struct dummy_display_data *)dev->data;
|
|
||||||
|
|
||||||
disp_data->current_pixel_format = pixel_format;
|
disp_data->current_pixel_format = pixel_format;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -123,8 +130,19 @@ static const struct display_driver_api dummy_display_api = {
|
||||||
.set_pixel_format = dummy_display_set_pixel_format,
|
.set_pixel_format = dummy_display_set_pixel_format,
|
||||||
};
|
};
|
||||||
|
|
||||||
DEVICE_DEFINE(dummy_display, CONFIG_DUMMY_DISPLAY_DEV_NAME,
|
#define DISPLAY_DUMMY_DEFINE(n) \
|
||||||
&dummy_display_init, NULL,
|
static const struct dummy_display_config dd_config_##n = { \
|
||||||
&dummy_display_data, NULL,
|
.height = DT_INST_PROP(n, height), \
|
||||||
APPLICATION, CONFIG_DISPLAY_INIT_PRIORITY,
|
.width = DT_INST_PROP(n, width), \
|
||||||
&dummy_display_api);
|
}; \
|
||||||
|
\
|
||||||
|
static struct dummy_display_data dd_data_##n; \
|
||||||
|
\
|
||||||
|
DEVICE_DT_INST_DEFINE(n, &dummy_display_init, NULL, \
|
||||||
|
&dd_data_##n, \
|
||||||
|
&dd_config_##n, \
|
||||||
|
APPLICATION, \
|
||||||
|
CONFIG_DISPLAY_INIT_PRIORITY, \
|
||||||
|
&dummy_display_api); \
|
||||||
|
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY(DISPLAY_DUMMY_DEFINE)
|
||||||
|
|
8
dts/bindings/display/zephyr,dummy-dc.yaml
Normal file
8
dts/bindings/display/zephyr,dummy-dc.yaml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
description: Dummy display controller
|
||||||
|
|
||||||
|
compatible: "zephyr,dummy-dc"
|
||||||
|
|
||||||
|
include: display-controller.yaml
|
18
samples/drivers/display/dummy_dc.overlay
Normal file
18
samples/drivers/display/dummy_dc.overlay
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,display = &dummy_dc;
|
||||||
|
};
|
||||||
|
|
||||||
|
dummy_dc: dummy_dc {
|
||||||
|
compatible = "zephyr,dummy-dc";
|
||||||
|
label = "DISPLAY";
|
||||||
|
height = <240>;
|
||||||
|
width = <320>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -56,6 +56,7 @@ tests:
|
||||||
tags: display
|
tags: display
|
||||||
sample.display.dummy:
|
sample.display.dummy:
|
||||||
platform_allow: native_posix
|
platform_allow: native_posix
|
||||||
|
extra_args: DTC_OVERLAY_FILE="dummy_dc.overlay"
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_DUMMY_DISPLAY=y
|
- CONFIG_DUMMY_DISPLAY=y
|
||||||
- CONFIG_SDL_DISPLAY=n
|
- CONFIG_SDL_DISPLAY=n
|
||||||
|
|
18
samples/subsys/display/lvgl/dummy_dc.overlay
Normal file
18
samples/subsys/display/lvgl/dummy_dc.overlay
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,display = &dummy_dc;
|
||||||
|
};
|
||||||
|
|
||||||
|
dummy_dc: dummy_dc {
|
||||||
|
compatible = "zephyr,dummy-dc";
|
||||||
|
label = "DISPLAY";
|
||||||
|
height = <240>;
|
||||||
|
width = <320>;
|
||||||
|
};
|
||||||
|
};
|
|
@ -40,6 +40,7 @@ tests:
|
||||||
sample.display.dummy:
|
sample.display.dummy:
|
||||||
build_only: true
|
build_only: true
|
||||||
platform_allow: native_posix
|
platform_allow: native_posix
|
||||||
|
extra_args: DTC_OVERLAY_FILE="dummy_dc.overlay"
|
||||||
extra_configs:
|
extra_configs:
|
||||||
- CONFIG_DUMMY_DISPLAY=y
|
- CONFIG_DUMMY_DISPLAY=y
|
||||||
- CONFIG_DUMMY_DISPLAY_DEV_NAME="DISPLAY"
|
- CONFIG_DUMMY_DISPLAY_DEV_NAME="DISPLAY"
|
||||||
|
|
18
tests/lib/gui/lvgl/app.overlay
Normal file
18
tests/lib/gui/lvgl/app.overlay
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,display = &dummy_dc;
|
||||||
|
};
|
||||||
|
|
||||||
|
dummy_dc: dummy_dc {
|
||||||
|
compatible = "zephyr,dummy-dc";
|
||||||
|
label = "DISPLAY";
|
||||||
|
height = <240>;
|
||||||
|
width = <320>;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue