From 4e8f79894961dfee4ca2c913af614a7ab4e8616d Mon Sep 17 00:00:00 2001 From: Jan Van Winkel Date: Tue, 16 Oct 2018 21:35:06 +0200 Subject: [PATCH 1/2] driver: SDL based display emulation driver This driver introduces an emulated LCD display for the native POSIX board. The emulated display driver makes use of SDL2 to render the displays frame buffer into a dedicated desktop window. Signed-off-by: Jan Van Winkel --- boards/posix/native_posix/CMakeLists.txt | 9 + boards/posix/native_posix/Kconfig | 5 + boards/posix/native_posix/Kconfig.defconfig | 7 + boards/posix/native_posix/doc/board.rst | 17 + boards/posix/native_posix/hw_models_top.c | 32 +- boards/posix/native_posix/sdl_events.c | 75 +++++ boards/posix/native_posix/sdl_events.h | 14 + drivers/display/CMakeLists.txt | 3 + drivers/display/Kconfig | 2 +- drivers/display/Kconfig.sdl | 30 ++ drivers/display/display_sdl.c | 333 ++++++++++++++++++++ include/display.h | 1 + 12 files changed, 521 insertions(+), 7 deletions(-) create mode 100644 boards/posix/native_posix/sdl_events.c create mode 100644 boards/posix/native_posix/sdl_events.h create mode 100644 drivers/display/Kconfig.sdl create mode 100644 drivers/display/display_sdl.c diff --git a/boards/posix/native_posix/CMakeLists.txt b/boards/posix/native_posix/CMakeLists.txt index 4aeb04859b5ff0..5ec39a8e74129d 100644 --- a/boards/posix/native_posix/CMakeLists.txt +++ b/boards/posix/native_posix/CMakeLists.txt @@ -12,6 +12,15 @@ zephyr_library_sources( cmdline.c ) +if(CONFIG_HAS_SDL) + find_package(PkgConfig REQUIRED) + pkg_search_module(SDL2 REQUIRED sdl2) + zephyr_include_directories(${SDL2_INCLUDE_DIRS}) + zephyr_link_libraries(${SDL2_LIBRARIES}) + zephyr_compile_options(${SDL2_CFLAGS_OTHER}) + zephyr_library_sources(sdl_events.c) +endif() + zephyr_ld_options( -lm ) diff --git a/boards/posix/native_posix/Kconfig b/boards/posix/native_posix/Kconfig index c4807d8be0589c..4291a2e2f2bf60 100644 --- a/boards/posix/native_posix/Kconfig +++ b/boards/posix/native_posix/Kconfig @@ -15,4 +15,9 @@ config NATIVE_POSIX_SLOWDOWN_TO_REAL_TIME case the zephyr kernel and application cannot tell the difference unless they interact with some other driver/device which runs at real time. +config HAS_SDL + bool + help + This option specifies that the target board has SDL support + endif diff --git a/boards/posix/native_posix/Kconfig.defconfig b/boards/posix/native_posix/Kconfig.defconfig index 9224bfceb9b8d8..726185766de199 100644 --- a/boards/posix/native_posix/Kconfig.defconfig +++ b/boards/posix/native_posix/Kconfig.defconfig @@ -72,4 +72,11 @@ config UART_CONSOLE endif #CONSOLE +if DISPLAY + +config SDL_DISPLAY + default y + +endif # DISPLAY + endif # BOARD_NATIVE_POSIX diff --git a/boards/posix/native_posix/doc/board.rst b/boards/posix/native_posix/doc/board.rst index 85124487a3c8ea..752a632a335a42 100644 --- a/boards/posix/native_posix/doc/board.rst +++ b/boards/posix/native_posix/doc/board.rst @@ -519,6 +519,23 @@ The following peripherals are currently provided with this board: must be powered down and support Bluetooth Low Energy (i.e. support the Bluetooth specification version 4.0 or greater). +**Display driver**: + A display driver is provided that creates a window on the host machine to + render display content. + + This driver requires a 32-bit version of the `SDL2`_ library on the host + machine and ``pkg-config`` settings to correctly pickup the SDL2 install path + and compiler flags. + + On a Ubuntu 18.04 host system, for example, install the ``pkg-config`` and + ``libsdl2-dev:i386`` packages, and configure the pkg-config search path with + these commands:: + + $ sudo apt-get install pkg-config libsdl2-dev:i386 + $ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig + +.. _SDL2: + https://www.libsdl.org/download-2.0.php UART ***** diff --git a/boards/posix/native_posix/hw_models_top.c b/boards/posix/native_posix/hw_models_top.c index a694ba98f46cec..a2b965f98041b6 100644 --- a/boards/posix/native_posix/hw_models_top.c +++ b/boards/posix/native_posix/hw_models_top.c @@ -12,12 +12,16 @@ #include #include #include +#include +#include #include "hw_models_top.h" #include "timer_model.h" #include "irq_ctrl.h" #include "posix_board_if.h" #include "posix_soc_if.h" #include "posix_arch_internal.h" +#include "sdl_events.h" +#include static u64_t simu_time; /* The actual time as known by the HW models */ @@ -26,13 +30,26 @@ static u64_t end_of_time = NEVER; /* When will this device stop */ /* List of HW model timers: */ extern u64_t hw_timer_timer; /* When should this timer_model be called */ extern u64_t irq_ctrl_timer; - -static enum { HWTIMER = 0, IRQCNT, NUMBER_OF_TIMERS, NONE } - next_timer_index = NONE; +#ifdef CONFIG_HAS_SDL +extern u64_t sdl_event_timer; +#endif + +static enum { + HWTIMER = 0, + IRQCNT, +#ifdef CONFIG_HAS_SDL + SDLEVENTTIMER, +#endif + NUMBER_OF_TIMERS, + NONE +} next_timer_index = NONE; static u64_t *Timer_list[NUMBER_OF_TIMERS] = { &hw_timer_timer, - &irq_ctrl_timer + &irq_ctrl_timer, +#ifdef CONFIG_HAS_SDL + &sdl_event_timer, +#endif }; static u64_t next_timer_time; @@ -40,7 +57,6 @@ static u64_t next_timer_time; /* Have we received a SIGTERM or SIGINT */ static volatile sig_atomic_t signaled_end; - /** * Handler for SIGTERM and SIGINT */ @@ -95,7 +111,6 @@ static void hwm_sleep_until_next_timer(void) if (signaled_end || (simu_time > end_of_time)) { posix_print_trace("\nStopped at %.3Lfs\n", ((long double)simu_time)/1.0e6); - posix_exit(0); } } @@ -134,6 +149,11 @@ void hwm_main_loop(void) case IRQCNT: hw_irq_ctrl_timer_triggered(); break; +#ifdef CONFIG_HAS_SDL + case SDLEVENTTIMER: + sdl_handle_events(); + break; +#endif default: /* LCOV_EXCL_START */ posix_print_error_and_exit( diff --git a/boards/posix/native_posix/sdl_events.c b/boards/posix/native_posix/sdl_events.c new file mode 100644 index 00000000000000..7e8381d13cd142 --- /dev/null +++ b/boards/posix/native_posix/sdl_events.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "posix_board_if.h" +#include "posix_trace.h" +#include "posix_arch_internal.h" +#include "soc.h" +#include "hw_models_top.h" + +u64_t sdl_event_timer; + +static void sdl_handle_window_event(const SDL_Event *event) +{ + SDL_Window *window; + SDL_Renderer *renderer; + + switch (event->window.event) { + case SDL_WINDOWEVENT_EXPOSED: + + window = SDL_GetWindowFromID(event->window.windowID); + if (window == NULL) { + return; + } + + renderer = SDL_GetRenderer(window); + if (renderer == NULL) { + return; + } + SDL_RenderPresent(renderer); + break; + default: + break; + } +} + +void sdl_handle_events(void) +{ + SDL_Event event; + + sdl_event_timer = hwm_get_time() + 10000; + + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_WINDOWEVENT: + sdl_handle_window_event(&event); + break; + case SDL_QUIT: + posix_exit(0); + break; + default: + break; + } + } + +} + +static void sdl_init(void) +{ + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + posix_print_error_and_exit("Error on SDL_Init (%s)\n", + SDL_GetError()); + } +} + +static void sdl_cleanup(void) +{ + SDL_Quit(); +} + +NATIVE_TASK(sdl_init, PRE_BOOT_2, 1); +NATIVE_TASK(sdl_cleanup, ON_EXIT, 2); diff --git a/boards/posix/native_posix/sdl_events.h b/boards/posix/native_posix/sdl_events.h new file mode 100644 index 00000000000000..17e1c1fbc37a0c --- /dev/null +++ b/boards/posix/native_posix/sdl_events.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H +#define ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H + +#include + +void sdl_handle_events(void); + +#endif /* ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H */ + diff --git a/drivers/display/CMakeLists.txt b/drivers/display/CMakeLists.txt index e0b0be4107191e..8fcba7a6d1d54d 100644 --- a/drivers/display/CMakeLists.txt +++ b/drivers/display/CMakeLists.txt @@ -10,3 +10,6 @@ zephyr_sources_ifdef(CONFIG_ILI9340_LCD_ADAFRUIT_1480 ) zephyr_sources_ifdef(CONFIG_SSD1306 ssd1306.c) zephyr_sources_ifdef(CONFIG_SSD1673 ssd1673.c) + +zephyr_sources_ifdef(CONFIG_SDL_DISPLAY display_sdl.c) + diff --git a/drivers/display/Kconfig b/drivers/display/Kconfig index cc31e4ea4533dd..4f9473579f1029 100644 --- a/drivers/display/Kconfig +++ b/drivers/display/Kconfig @@ -20,8 +20,8 @@ source "subsys/logging/Kconfig.template.log_config" source "drivers/display/Kconfig.grove" source "drivers/display/Kconfig.microbit" - source "drivers/display/Kconfig.ili9340" +source "drivers/display/Kconfig.sdl" source "drivers/display/Kconfig.ssd1306" diff --git a/drivers/display/Kconfig.sdl b/drivers/display/Kconfig.sdl new file mode 100644 index 00000000000000..ff7bff61b58267 --- /dev/null +++ b/drivers/display/Kconfig.sdl @@ -0,0 +1,30 @@ +# Kconfig - SDL based emulated display configuration options + +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig SDL_DISPLAY + bool "SDL based emulated display" + depends on BOARD_NATIVE_POSIX + select HAS_SDL + help + Enable SDL based emulated display compliant with display driver API. + +if SDL_DISPLAY + +config SDL_DISPLAY_DEV_NAME + string "SDL display device name" + default "SDL_DISPLAY" + +config SDL_DISPLAY_X_RES + int "X resolution for SDL display" + default 320 + +config SDL_DISPLAY_Y_RES + int "Y resolution for SDL display" + default 240 + +endif #SDL_DISPLAY diff --git a/drivers/display/display_sdl.c b/drivers/display/display_sdl.c new file mode 100644 index 00000000000000..a42981305cf924 --- /dev/null +++ b/drivers/display/display_sdl.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include + +#define LOG_LEVEL CONFIG_DISPLAY_LOG_LEVEL +#include +LOG_MODULE_REGISTER(display_sdl); + +struct sdl_display_data { + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *texture; + bool display_on; + enum display_pixel_format current_pixel_format; + u8_t buf[4 * CONFIG_SDL_DISPLAY_X_RES * CONFIG_SDL_DISPLAY_Y_RES]; +}; + +static struct sdl_display_data sdl_display_data; + +static int sdl_display_init(struct device *dev) +{ + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + LOG_DBG("Initializing display driver"); + + memset(disp_data, 0, sizeof(struct sdl_display_data)); + + disp_data->current_pixel_format = PIXEL_FORMAT_ARGB_8888; + + disp_data->window = + SDL_CreateWindow("Zephyr Display", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, CONFIG_SDL_DISPLAY_X_RES, + CONFIG_SDL_DISPLAY_Y_RES, SDL_WINDOW_SHOWN); + if (disp_data->window == NULL) { + LOG_ERR("Failed to create SDL window: %s", SDL_GetError()); + return -EIO; + } + + disp_data->renderer = + SDL_CreateRenderer(disp_data->window, -1, SDL_RENDERER_ACCELERATED); + if (disp_data->renderer == NULL) { + LOG_ERR("Failed to create SDL renderer: %s", + SDL_GetError()); + return -EIO; + } + + disp_data->texture = SDL_CreateTexture( + disp_data->renderer, SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STATIC, CONFIG_SDL_DISPLAY_X_RES, + CONFIG_SDL_DISPLAY_Y_RES); + if (disp_data->texture == NULL) { + LOG_ERR("Failed to create SDL texture: %s", SDL_GetError()); + return -EIO; + } + + disp_data->display_on = false; + SDL_SetRenderDrawColor(disp_data->renderer, 0, 0, 0, 0xFF); + SDL_RenderClear(disp_data->renderer); + SDL_RenderPresent(disp_data->renderer); + + return 0; +} + +static void sdl_display_write_argb8888(void *disp_buf, + const struct display_buffer_descriptor *desc, const void *buf) +{ + __ASSERT((4 * desc->pitch * desc->height) <= desc->buf_size, + "Input buffer to small"); + + memcpy(disp_buf, buf, 4 * desc->pitch * desc->height); +} + +static void sdl_display_write_rgb888(u8_t *disp_buf, + const struct display_buffer_descriptor *desc, const void *buf) +{ + u32_t w_idx; + u32_t h_idx; + u32_t pixel; + const u8_t *byte_ptr; + + __ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size, + "Input buffer to small"); + + for (h_idx = 0; h_idx < desc->height; ++h_idx) { + for (w_idx = 0; w_idx < desc->width; ++w_idx) { + byte_ptr = (const u8_t *)buf + + 3 * ((h_idx * desc->pitch) + w_idx); + pixel = *byte_ptr << 16; + pixel |= *(byte_ptr + 1) << 8; + pixel |= *(byte_ptr + 2); + *((u32_t *)disp_buf) = pixel; + disp_buf += 4; + } + } +} + +static void sdl_display_write_mono(u8_t *disp_buf, + const struct display_buffer_descriptor *desc, const void *buf, + const bool one_is_black) +{ + u32_t w_idx; + u32_t h_idx; + u32_t tile_idx; + u32_t pixel; + const u8_t *byte_ptr; + u32_t one_color; + u8_t *disp_buf_start; + + __ASSERT((desc->pitch * desc->height) <= (8 * desc->buf_size), + "Input buffer to small"); + __ASSERT((desc->height % 8) == 0, + "Input buffer height not aligned per 8 pixels"); + + if (one_is_black) { + one_color = 0; + } else { + one_color = 0x00FFFFFF; + } + + for (tile_idx = 0; tile_idx < desc->height/8; ++tile_idx) { + for (w_idx = 0; w_idx < desc->width; ++w_idx) { + byte_ptr = (const u8_t *)buf + + ((tile_idx * desc->pitch) + w_idx); + disp_buf_start = disp_buf; + for (h_idx = 0; h_idx < 8; ++h_idx) { + if ((*byte_ptr & BIT(7-h_idx)) != 0) { + pixel = one_color; + } else { + pixel = (~one_color) & 0x00FFFFFF; + } + *((u32_t *)disp_buf) = pixel; + disp_buf += (4 * desc->width); + } + disp_buf = disp_buf_start; + disp_buf += 4; + } + disp_buf += 7 * (4 * desc->width); + } +} + +static int sdl_display_write(const struct device *dev, const u16_t x, + const u16_t y, + const struct display_buffer_descriptor *desc, + const void *buf) +{ + SDL_Rect rect; + + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + + LOG_DBG("Writing %dx%d (w,h) bitmap @ %dx%d (x,y)", desc->width, + desc->height, x, y); + + __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width"); + + if (disp_data->current_pixel_format == PIXEL_FORMAT_ARGB_8888) { + sdl_display_write_argb8888(disp_data->buf, desc, buf); + } else if (disp_data->current_pixel_format == PIXEL_FORMAT_RGB_888) { + sdl_display_write_rgb888(disp_data->buf, desc, buf); + } else if (disp_data->current_pixel_format == PIXEL_FORMAT_MONO10) { + sdl_display_write_mono(disp_data->buf, desc, buf, true); + } else if (disp_data->current_pixel_format == PIXEL_FORMAT_MONO01) { + sdl_display_write_mono(disp_data->buf, desc, buf, false); + } + + rect.x = x; + rect.y = y; + rect.w = desc->width; + rect.h = desc->height; + + SDL_UpdateTexture(disp_data->texture, &rect, disp_data->buf, + 4 * rect.w); + + if (disp_data->display_on) { + SDL_RenderClear(disp_data->renderer); + SDL_RenderCopy(disp_data->renderer, disp_data->texture, NULL, + NULL); + SDL_RenderPresent(disp_data->renderer); + } + + return 0; +} + +static int sdl_display_read(const struct device *dev, const u16_t x, + const u16_t y, + const struct display_buffer_descriptor *desc, + void *buf) +{ + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + SDL_Rect rect; + + rect.x = x; + rect.y = y; + rect.w = desc->width; + rect.h = desc->height; + + LOG_DBG("Reading %dx%d (w,h) bitmap @ %dx%d (x,y)", desc->width, + desc->height, x, y); + + __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width"); + __ASSERT((3 * desc->pitch * desc->height) <= desc->buf_size, + "Input buffer to small"); + + return SDL_RenderReadPixels(disp_data->renderer, &rect, 0, buf, + 4 * desc->pitch); +} + +static void *sdl_display_get_framebuffer(const struct device *dev) +{ + return NULL; +} + +static int sdl_display_blanking_off(const struct device *dev) +{ + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + + LOG_DBG("Turning display blacking off"); + + disp_data->display_on = true; + + SDL_RenderClear(disp_data->renderer); + SDL_RenderCopy(disp_data->renderer, disp_data->texture, NULL, NULL); + SDL_RenderPresent(disp_data->renderer); + + return 0; +} + +static int sdl_display_blanking_on(const struct device *dev) +{ + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + + LOG_DBG("Turning display blanking on"); + + disp_data->display_on = false; + + SDL_RenderClear(disp_data->renderer); + SDL_RenderPresent(disp_data->renderer); + return 0; +} + +static int sdl_display_set_brightness(const struct device *dev, + const u8_t brightness) +{ + return -ENOTSUP; +} + +static int sdl_display_set_contrast(const struct device *dev, + const u8_t contrast) +{ + return -ENOTSUP; +} + +static void sdl_display_get_capabilities( + const struct device *dev, struct display_capabilities *capabilities) +{ + memset(capabilities, 0, sizeof(struct display_capabilities)); + capabilities->x_resolution = CONFIG_SDL_DISPLAY_X_RES; + capabilities->y_resolution = CONFIG_SDL_DISPLAY_Y_RES; + capabilities->supported_pixel_formats = PIXEL_FORMAT_ARGB_8888 | + PIXEL_FORMAT_RGB_888 | + PIXEL_FORMAT_MONO01 | + PIXEL_FORMAT_MONO10; + capabilities->current_pixel_format = PIXEL_FORMAT_ARGB_8888; + capabilities->screen_info = SCREEN_INFO_MONO_VTILED | + SCREEN_INFO_MONO_MSB_FIRST; +} + +static int sdl_display_set_pixel_format(const struct device *dev, + const enum display_pixel_format pixel_format) +{ + struct sdl_display_data *disp_data = + (struct sdl_display_data *)dev->driver_data; + + switch (pixel_format) { + case PIXEL_FORMAT_ARGB_8888: + case PIXEL_FORMAT_RGB_888: + case PIXEL_FORMAT_MONO01: + case PIXEL_FORMAT_MONO10: + disp_data->current_pixel_format = pixel_format; + return 0; + default: + LOG_ERR("Pixel format not supported"); + return -ENOTSUP; + } +} + +static void sdl_display_cleanup(void) +{ + if (sdl_display_data.texture != NULL) { + SDL_DestroyTexture(sdl_display_data.texture); + sdl_display_data.texture = NULL; + } + + if (sdl_display_data.renderer != NULL) { + SDL_DestroyRenderer(sdl_display_data.renderer); + sdl_display_data.renderer = NULL; + } + + if (sdl_display_data.window != NULL) { + SDL_DestroyWindow(sdl_display_data.window); + sdl_display_data.window = NULL; + } +} + +static const struct display_driver_api sdl_display_api = { + .blanking_on = sdl_display_blanking_on, + .blanking_off = sdl_display_blanking_off, + .write = sdl_display_write, + .read = sdl_display_read, + .get_framebuffer = sdl_display_get_framebuffer, + .set_brightness = sdl_display_set_brightness, + .set_contrast = sdl_display_set_contrast, + .get_capabilities = sdl_display_get_capabilities, + .set_pixel_format = sdl_display_set_pixel_format, +}; + +DEVICE_AND_API_INIT(sdl_display, CONFIG_SDL_DISPLAY_DEV_NAME, &sdl_display_init, + &sdl_display_data, NULL, APPLICATION, + CONFIG_APPLICATION_INIT_PRIORITY, &sdl_display_api); + + +NATIVE_TASK(sdl_display_cleanup, ON_EXIT, 1); diff --git a/include/display.h b/include/display.h index d05e960e2afaa0..4b79f37fda880d 100644 --- a/include/display.h +++ b/include/display.h @@ -31,6 +31,7 @@ enum display_pixel_format { PIXEL_FORMAT_RGB_888 = BIT(0), PIXEL_FORMAT_MONO01 = BIT(1), /* 0=Black 1=White */ PIXEL_FORMAT_MONO10 = BIT(2), /* 1=Black 0=White */ + PIXEL_FORMAT_ARGB_8888 = BIT(3), }; enum display_screen_info { From c37531339ed53ae19ab815fe96ae4ef82db3f2e3 Mon Sep 17 00:00:00 2001 From: Jan Van Winkel Date: Sat, 20 Oct 2018 23:48:57 +0200 Subject: [PATCH 2/2] samples: Added native posix board to cfb sample Added support for native posix board to character framebuffer sample. Signed-off-by: Jan Van Winkel --- samples/display/cfb/prj.conf | 1 - samples/display/cfb/prj_native_posix.conf | 11 +++++++++++ samples/display/cfb/src/main.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 samples/display/cfb/prj_native_posix.conf diff --git a/samples/display/cfb/prj.conf b/samples/display/cfb/prj.conf index a0065e664fa550..79d9eef37359dc 100644 --- a/samples/display/cfb/prj.conf +++ b/samples/display/cfb/prj.conf @@ -5,7 +5,6 @@ CONFIG_HEAP_MEM_POOL_SIZE=16384 CONFIG_DISPLAY=y CONFIG_LOG=y -CONFIG_DISPLAY_LOG_LEVEL_DBG=y CONFIG_CFB_LOG_LEVEL_DBG=y CONFIG_CHARACTER_FRAMEBUFFER=y diff --git a/samples/display/cfb/prj_native_posix.conf b/samples/display/cfb/prj_native_posix.conf new file mode 100644 index 00000000000000..72307ce90fd435 --- /dev/null +++ b/samples/display/cfb/prj_native_posix.conf @@ -0,0 +1,11 @@ +CONFIG_HEAP_MEM_POOL_SIZE=16384 + +CONFIG_DISPLAY=y +CONFIG_SDL_DISPLAY_DEV_NAME="DISPLAY" +CONFIG_SDL_DISPLAY_X_RES=250 +CONFIG_SDL_DISPLAY_Y_RES=120 + +CONFIG_LOG=y + +CONFIG_CFB_LOG_LEVEL_DBG=y +CONFIG_CHARACTER_FRAMEBUFFER=y diff --git a/samples/display/cfb/src/main.c b/samples/display/cfb/src/main.c index f7c548deb543cb..c4e74cbd278fd3 100644 --- a/samples/display/cfb/src/main.c +++ b/samples/display/cfb/src/main.c @@ -17,6 +17,10 @@ #define DISPLAY_DRIVER "SSD1306" #endif +#ifndef DISPLAY_DRIVER +#define DISPLAY_DRIVER "DISPLAY" +#endif + void main(void) { struct device *dev; @@ -33,6 +37,11 @@ void main(void) return; } + if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO10) != 0) { + printf("Failed to set required pixel format\n"); + return; + } + printf("initialized %s\n", DISPLAY_DRIVER); if (cfb_framebuffer_init(dev)) { @@ -43,6 +52,8 @@ void main(void) api = dev->driver_api; cfb_framebuffer_clear(dev, true); + display_blanking_off(dev); + rows = cfb_get_display_parameter(dev, CFB_DISPLAY_ROWS); ppt = cfb_get_display_parameter(dev, CFB_DISPLAY_PPT); @@ -73,6 +84,9 @@ void main(void) } cfb_framebuffer_finalize(dev); +#if defined(CONFIG_ARCH_POSIX) + k_sleep(100); +#endif } } }