Skip to content

Commit 6be42eb

Browse files
JarmouniAkartben
authored andcommitted
drivers: display: sdl: add windows custom naming
Add the possibility to set a custom name for SDL window in native simulator Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
1 parent 05401b3 commit 6be42eb

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

drivers/display/display_sdl.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct sdl_display_task {
4747
struct sdl_display_config {
4848
uint16_t height;
4949
uint16_t width;
50+
const char *title;
5051
};
5152

5253
struct sdl_display_data {
@@ -116,14 +117,13 @@ static void sdl_task_thread(void *p1, void *p2, void *p3)
116117
sdl_display_zoom_pct = CONFIG_SDL_DISPLAY_ZOOM_PCT;
117118
}
118119

119-
int rc = sdl_display_init_bottom(config->height, config->width, sdl_display_zoom_pct,
120-
use_accelerator, &disp_data->window, dev,
121-
&disp_data->renderer, &disp_data->mutex,
122-
&disp_data->texture, &disp_data->read_texture,
123-
&disp_data->background_texture,
124-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_1,
125-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_2,
126-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_SIZE);
120+
int rc = sdl_display_init_bottom(
121+
config->height, config->width, sdl_display_zoom_pct, use_accelerator,
122+
&disp_data->window, dev, config->title, &disp_data->renderer, &disp_data->mutex,
123+
&disp_data->texture, &disp_data->read_texture, &disp_data->background_texture,
124+
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_1,
125+
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_2,
126+
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_SIZE);
127127

128128
k_sem_give(&disp_data->task_sem);
129129

@@ -734,35 +734,30 @@ static DEVICE_API(display, sdl_display_api) = {
734734
.set_pixel_format = sdl_display_set_pixel_format,
735735
};
736736

737-
#define DISPLAY_SDL_DEFINE(n) \
738-
static const struct sdl_display_config sdl_config_##n = { \
739-
.height = DT_INST_PROP(n, height), \
740-
.width = DT_INST_PROP(n, width), \
741-
}; \
742-
\
743-
static uint8_t sdl_buf_##n[4 * DT_INST_PROP(n, height) \
744-
* DT_INST_PROP(n, width)]; \
745-
static uint8_t sdl_read_buf_##n[4 * DT_INST_PROP(n, height) \
746-
* DT_INST_PROP(n, width)]; \
747-
K_MSGQ_DEFINE(sdl_task_msgq_##n, sizeof(struct sdl_display_task), 1, 4); \
748-
static struct sdl_display_data sdl_data_##n = { \
749-
.buf = sdl_buf_##n, \
750-
.read_buf = sdl_read_buf_##n, \
751-
.task_msgq = &sdl_task_msgq_##n, \
752-
}; \
753-
\
754-
DEVICE_DT_INST_DEFINE(n, &sdl_display_init, NULL, \
755-
&sdl_data_##n, \
756-
&sdl_config_##n, \
757-
POST_KERNEL, \
758-
CONFIG_DISPLAY_INIT_PRIORITY, \
759-
&sdl_display_api); \
760-
\
761-
static void sdl_display_cleanup_##n(void) \
762-
{ \
763-
sdl_display_cleanup(&sdl_data_##n); \
764-
} \
765-
\
737+
#define DISPLAY_SDL_DEFINE(n) \
738+
static const struct sdl_display_config sdl_config_##n = { \
739+
.height = DT_INST_PROP(n, height), \
740+
.width = DT_INST_PROP(n, width), \
741+
.title = DT_INST_PROP_OR(n, title, "Zephyr Display"), \
742+
}; \
743+
\
744+
static uint8_t sdl_buf_##n[4 * DT_INST_PROP(n, height) * DT_INST_PROP(n, width)]; \
745+
static uint8_t sdl_read_buf_##n[4 * DT_INST_PROP(n, height) * DT_INST_PROP(n, width)]; \
746+
K_MSGQ_DEFINE(sdl_task_msgq_##n, sizeof(struct sdl_display_task), 1, 4); \
747+
static struct sdl_display_data sdl_data_##n = { \
748+
.buf = sdl_buf_##n, \
749+
.read_buf = sdl_read_buf_##n, \
750+
.task_msgq = &sdl_task_msgq_##n, \
751+
}; \
752+
\
753+
DEVICE_DT_INST_DEFINE(n, &sdl_display_init, NULL, &sdl_data_##n, &sdl_config_##n, \
754+
POST_KERNEL, CONFIG_DISPLAY_INIT_PRIORITY, &sdl_display_api); \
755+
\
756+
static void sdl_display_cleanup_##n(void) \
757+
{ \
758+
sdl_display_cleanup(&sdl_data_##n); \
759+
} \
760+
\
766761
NATIVE_TASK(sdl_display_cleanup_##n, ON_EXIT, 1);
767762

768763
DT_INST_FOREACH_STATUS_OKAY(DISPLAY_SDL_DEFINE)

drivers/display/display_sdl_bottom.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515

1616
int sdl_display_init_bottom(uint16_t height, uint16_t width, uint16_t zoom_pct,
1717
bool use_accelerator, void **window, const void *window_user_data,
18-
void **renderer, void **mutex, void **texture, void **read_texture,
19-
void **background_texture, uint32_t transparency_grid_color1,
20-
uint32_t transparency_grid_color2, uint16_t transparency_grid_cell_size)
18+
const char *title, void **renderer, void **mutex, void **texture,
19+
void **read_texture, void **background_texture,
20+
uint32_t transparency_grid_color1, uint32_t transparency_grid_color2,
21+
uint16_t transparency_grid_cell_size)
2122
{
22-
*window = SDL_CreateWindow("Zephyr Display", SDL_WINDOWPOS_UNDEFINED,
23-
SDL_WINDOWPOS_UNDEFINED, width * zoom_pct / 100,
23+
/* clang-format off */
24+
*window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
25+
width * zoom_pct / 100,
2426
height * zoom_pct / 100, SDL_WINDOW_SHOWN);
27+
/* clang-format on */
2528
if (*window == NULL) {
26-
nsi_print_warning("Failed to create SDL window: %s", SDL_GetError());
29+
nsi_print_warning("Failed to create SDL window %s: %s", title, SDL_GetError());
2730
return -1;
2831
}
2932
SDL_SetWindowData(*window, "zephyr_display", (void *)window_user_data);

drivers/display/display_sdl_bottom.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ extern "C" {
2222

2323
int sdl_display_init_bottom(uint16_t height, uint16_t width, uint16_t zoom_pct,
2424
bool use_accelerator, void **window, const void *window_user_data,
25-
void **renderer, void **mutex, void **texture, void **read_texture,
26-
void **background_texture, uint32_t transparency_grid_color1,
27-
uint32_t transparency_grid_color2,
25+
const char *title, void **renderer, void **mutex, void **texture,
26+
void **read_texture, void **background_texture,
27+
uint32_t transparency_grid_color1, uint32_t transparency_grid_color2,
2828
uint16_t transparency_grid_cell_size);
2929
void sdl_display_write_bottom(const uint16_t height, const uint16_t width, const uint16_t x,
3030
const uint16_t y, void *renderer, void *mutex, void *texture,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# Copyright (c) 2025 Abderrahmane JARMOUNI
23
# SPDX-License-Identifier: Apache-2.0
34

45
description: SDL based emulated display controller
56

67
compatible: "zephyr,sdl-dc"
78

89
include: display-controller.yaml
10+
11+
properties:
12+
title:
13+
type: string
14+
description: |
15+
Name of graphical window

0 commit comments

Comments
 (0)