diff --git a/boards/arm/mimxrt1050_evk/Kconfig.defconfig b/boards/arm/mimxrt1050_evk/Kconfig.defconfig index 5c44a5a690c0..4478fc8dd977 100644 --- a/boards/arm/mimxrt1050_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1050_evk/Kconfig.defconfig @@ -78,9 +78,6 @@ endif # NETWORKING if LVGL -config LVGL_DISPLAY_DEV_NAME - default "ELCDIF_1" - config LVGL_HOR_RES default 480 diff --git a/boards/arm/mimxrt1060_evk/Kconfig.defconfig b/boards/arm/mimxrt1060_evk/Kconfig.defconfig index 1cc953dbe435..634d5eb567f4 100644 --- a/boards/arm/mimxrt1060_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1060_evk/Kconfig.defconfig @@ -56,9 +56,6 @@ endif # NETWORKING if LVGL -config LVGL_DISPLAY_DEV_NAME - default "ELCDIF_1" - config LVGL_HOR_RES default 480 diff --git a/boards/arm/mimxrt1064_evk/Kconfig.defconfig b/boards/arm/mimxrt1064_evk/Kconfig.defconfig index b5b02f26c626..17bfe3348dd0 100644 --- a/boards/arm/mimxrt1064_evk/Kconfig.defconfig +++ b/boards/arm/mimxrt1064_evk/Kconfig.defconfig @@ -52,9 +52,6 @@ endif # NETWORKING if LVGL -config LVGL_DISPLAY_DEV_NAME - default "ELCDIF_1" - config LVGL_HOR_RES default 480 diff --git a/boards/arm/reel_board/reel_board.dts b/boards/arm/reel_board/reel_board.dts index 17fba78fc85b..8663544d02a8 100644 --- a/boards/arm/reel_board/reel_board.dts +++ b/boards/arm/reel_board/reel_board.dts @@ -60,7 +60,7 @@ ssd16xxfb@0 { compatible = "solomon,ssd16xxfb", "gooddisplay,gdeh0213b1"; - label = "SSD16XX"; + label = "DISPLAY_SSD16XX"; spi-max-frequency = <4000000>; reg = <0>; width = <250>; diff --git a/boards/arm/reel_board/reel_board_v2.dts b/boards/arm/reel_board/reel_board_v2.dts index 43c54e842877..c08eeb282a3b 100644 --- a/boards/arm/reel_board/reel_board_v2.dts +++ b/boards/arm/reel_board/reel_board_v2.dts @@ -36,7 +36,7 @@ ssd16xxfb@0 { compatible = "solomon,ssd16xxfb", "gooddisplay,gdeh0213b72"; - label = "SSD16XX"; + label = "DISPLAY_SSD16XX"; spi-max-frequency = <4000000>; reg = <0>; width = <250>; diff --git a/boards/shields/adafruit_2_8_tft_touch_v2/Kconfig.defconfig b/boards/shields/adafruit_2_8_tft_touch_v2/Kconfig.defconfig index b3b02c1fb7d4..8bd61e3e9437 100644 --- a/boards/shields/adafruit_2_8_tft_touch_v2/Kconfig.defconfig +++ b/boards/shields/adafruit_2_8_tft_touch_v2/Kconfig.defconfig @@ -13,9 +13,6 @@ config ILI9340 if LVGL -config LVGL_DISPLAY_DEV_NAME - default "ILI9340" - config LVGL_HOR_RES default 320 diff --git a/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay b/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay index 0962df038201..e5da3b5159a6 100644 --- a/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay +++ b/boards/shields/adafruit_2_8_tft_touch_v2/adafruit_2_8_tft_touch_v2.overlay @@ -11,7 +11,7 @@ ili9340@0 { compatible = "ilitek,ili9340"; - label = "ILI9340"; + label = "DISPLAY_ILI9340"; spi-max-frequency = <15151515>; reg = <0>; cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ diff --git a/boards/shields/ssd1306/Kconfig.defconfig b/boards/shields/ssd1306/Kconfig.defconfig index a3e45b9cb6fe..f8775baf2c95 100644 --- a/boards/shields/ssd1306/Kconfig.defconfig +++ b/boards/shields/ssd1306/Kconfig.defconfig @@ -13,9 +13,6 @@ config SSD1306 if LVGL -config LVGL_DISPLAY_DEV_NAME - default "SSD1306" - config LVGL_HOR_RES default 128 diff --git a/boards/shields/ssd1306/ssd1306_128x32.overlay b/boards/shields/ssd1306/ssd1306_128x32.overlay index 189fdc5383f7..178fa372df70 100644 --- a/boards/shields/ssd1306/ssd1306_128x32.overlay +++ b/boards/shields/ssd1306/ssd1306_128x32.overlay @@ -10,7 +10,7 @@ ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; - label = "SSD1306"; + label = "DISPLAY_SSD1306"; width = <128>; height = <32>; segment-offset = <0>; diff --git a/boards/shields/ssd1306/ssd1306_128x64.overlay b/boards/shields/ssd1306/ssd1306_128x64.overlay index d198af7b5385..3070497f732a 100644 --- a/boards/shields/ssd1306/ssd1306_128x64.overlay +++ b/boards/shields/ssd1306/ssd1306_128x64.overlay @@ -10,7 +10,7 @@ ssd1306@3c { compatible = "solomon,ssd1306fb"; reg = <0x3c>; - label = "SSD1306"; + label = "DISPLAY_SSD1306"; width = <128>; height = <64>; segment-offset = <0>; diff --git a/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf b/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf index ba88e1f0d2a8..6e7ba899db69 100644 --- a/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf +++ b/boards/shields/st7789v_generic/st7789v_tl019fqv01.conf @@ -6,5 +6,3 @@ CONFIG_ST7789V_RGB888=y CONFIG_LVGL_BITS_PER_PIXEL=24 CONFIG_LVGL_HOR_RES=320 CONFIG_LVGL_VER_RES=170 - -CONFIG_LVGL_DISPLAY_DEV_NAME="ST7789V" diff --git a/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay b/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay index 78c3bca73efb..a1df890356de 100644 --- a/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay +++ b/boards/shields/st7789v_generic/st7789v_tl019fqv01.overlay @@ -10,7 +10,7 @@ st7789v@0 { compatible = "sitronix,st7789v"; - label = "ST7789V"; + label = "DISPLAY_ST7789V"; spi-max-frequency = <20000000>; reg = <0>; cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ diff --git a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf index b2fa7e39656f..ff26fb6cbff0 100644 --- a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf +++ b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.conf @@ -6,5 +6,3 @@ CONFIG_ST7789V_RGB565=y CONFIG_LVGL_BITS_PER_PIXEL=16 CONFIG_LVGL_HOR_RES=240 CONFIG_LVGL_VER_RES=240 - -CONFIG_LVGL_DISPLAY_DEV_NAME="ST7789V" diff --git a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay index cddeb0a0f352..8c4e6319942f 100644 --- a/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay +++ b/boards/shields/st7789v_generic/st7789v_waveshare_240x240.overlay @@ -11,7 +11,7 @@ st7789v@0 { compatible = "sitronix,st7789v"; - label = "ST7789V"; + label = "DISPLAY_ST7789V"; spi-max-frequency = <20000000>; reg = <0>; cmd-data-gpios = <&arduino_header 15 0>; /* D9 */ diff --git a/boards/shields/waveshare_epaper/Kconfig.defconfig b/boards/shields/waveshare_epaper/Kconfig.defconfig index 67387acbae63..88d9171c3d21 100644 --- a/boards/shields/waveshare_epaper/Kconfig.defconfig +++ b/boards/shields/waveshare_epaper/Kconfig.defconfig @@ -17,9 +17,6 @@ config SSD16XX if LVGL -config LVGL_DISPLAY_DEV_NAME - default "SSD16XX" - config LVGL_HOR_RES default 296 if SHIELD_WAVESHARE_EPAPER_GDEH029A1 default 250 if SHIELD_WAVESHARE_EPAPER_GDEH0213B1 diff --git a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b1.overlay b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b1.overlay index 141a83d3cc99..179a365903be 100644 --- a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b1.overlay +++ b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b1.overlay @@ -10,7 +10,7 @@ ssd16xxfb@0 { compatible = "solomon,ssd16xxfb", "gooddisplay,gdeh0213b1"; - label = "SSD16XX"; + label = "DISPLAY_SSD16XX"; spi-max-frequency = <4000000>; reg = <0>; width = <250>; diff --git a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b72.overlay b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b72.overlay index e35d5f63df37..789c3e701d63 100644 --- a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b72.overlay +++ b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh0213b72.overlay @@ -10,7 +10,7 @@ ssd16xxfb@0 { compatible = "solomon,ssd16xxfb", "gooddisplay,gdeh0213b72"; - label = "SSD16XX"; + label = "DISPLAY_SSD16XX"; spi-max-frequency = <4000000>; reg = <0>; width = <250>; diff --git a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh029a1.overlay b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh029a1.overlay index d7fd341b34fd..d24e0986068e 100644 --- a/boards/shields/waveshare_epaper/waveshare_epaper_gdeh029a1.overlay +++ b/boards/shields/waveshare_epaper/waveshare_epaper_gdeh029a1.overlay @@ -10,7 +10,7 @@ ssd16xxfb@0 { compatible = "solomon,ssd16xxfb", "gooddisplay,gdeh029a1"; - label = "SSD16XX"; + label = "DISPLAY_SSD16XX"; spi-max-frequency = <4000000>; reg = <0>; width = <296>; diff --git a/drivers/display/Kconfig.dummy b/drivers/display/Kconfig.dummy index b1d566dbcd17..b4bdd085a565 100644 --- a/drivers/display/Kconfig.dummy +++ b/drivers/display/Kconfig.dummy @@ -12,7 +12,7 @@ if DUMMY_DISPLAY config DUMMY_DISPLAY_DEV_NAME string "Dummy display device name" - default "DUMMY_DISPLAY" + default "DISPLAY_DUMMY" config DUMMY_DISPLAY_X_RES int "X resolution for dummy display" diff --git a/drivers/display/Kconfig.sdl b/drivers/display/Kconfig.sdl index a25986f685a7..ab0b1d26dcc8 100644 --- a/drivers/display/Kconfig.sdl +++ b/drivers/display/Kconfig.sdl @@ -14,7 +14,7 @@ if SDL_DISPLAY config SDL_DISPLAY_DEV_NAME string "SDL display device name" - default "SDL_DISPLAY" + default "DISPLAY_SDL" config SDL_DISPLAY_X_RES int "X resolution for SDL display" diff --git a/dts/arm/nxp/nxp_rt.dtsi b/dts/arm/nxp/nxp_rt.dtsi index a80327e6bd2e..f6606ff58901 100644 --- a/dts/arm/nxp/nxp_rt.dtsi +++ b/dts/arm/nxp/nxp_rt.dtsi @@ -211,7 +211,7 @@ compatible = "fsl,imx6sx-lcdif"; reg = <0x402b8000 0x4000>; interrupts = <42 0>; - label = "ELCDIF_1"; + label = "DISPLAY_ELCDIF_1"; status = "disabled"; }; diff --git a/include/device.h b/include/device.h index 8d32dea18bb7..2e3ee4072fa0 100644 --- a/include/device.h +++ b/include/device.h @@ -293,6 +293,21 @@ void z_sys_device_do_config_level(s32_t level); */ __syscall struct device *device_get_binding(const char *name); +/** + * @brief Retrieve the device structure for a driver by prefix + * + * @details Device objects are created via the DEVICE_INIT() macro and + * placed in memory by the linker. If a driver needs to bind to another driver + * it can use this function to retrieve the device structure of the lower level + * driver by the prefix from the name the driver exposes to the system. + * + * @param prefix device name prefix to search for. + * @param idx device index to search for. + * + * @return pointer to device structure; NULL if not found or cannot be used. + */ +__syscall struct device *device_get_by_prefix(const char *prefix, int idx); + /** * @} */ diff --git a/kernel/device.c b/kernel/device.c index aff82511fec9..6e106de7a94c 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -95,6 +95,30 @@ struct device *z_impl_device_get_binding(const char *name) return NULL; } +struct device *z_impl_device_get_by_prefix(const char *prefix, int idx) +{ + struct device *info; + int n = 0; + int len; + + for (info = __device_init_start; info != __device_init_end; info++) { + if (info->driver_api == NULL || info->config->name == NULL) { + continue; + } + + len = strnlen(prefix, Z_DEVICE_MAX_NAME_LEN); + if (strncmp(info->config->name, prefix, len) == 0) { + if (idx == n) { + return info; + } + + n++; + } + } + + return NULL; +} + #ifdef CONFIG_USERSPACE static inline struct device *z_vrfy_device_get_binding(const char *name) { @@ -108,6 +132,20 @@ static inline struct device *z_vrfy_device_get_binding(const char *name) return z_impl_device_get_binding(name_copy); } #include + +static inline struct device *z_vrfy_device_get_by_prefix(const char *prefix, + int idx) +{ + char prefix_copy[Z_DEVICE_MAX_NAME_LEN]; + + if (z_user_string_copy(prefix_copy, (char *)prefix, sizeof(prefix_copy)) + != 0) { + return 0; + } + + return z_impl_device_get_by_prefix(prefix_copy, idx); +} +#include #endif /* CONFIG_USERSPACE */ #ifdef CONFIG_DEVICE_POWER_MANAGEMENT diff --git a/lib/gui/lvgl/Kconfig b/lib/gui/lvgl/Kconfig index 852f13ef061a..ebb464c48e58 100644 --- a/lib/gui/lvgl/Kconfig +++ b/lib/gui/lvgl/Kconfig @@ -12,12 +12,6 @@ module = LVGL module-str = lvgl source "subsys/logging/Kconfig.template.log_config" -config LVGL_DISPLAY_DEV_NAME - string "Display device name" - default "DISPLAY" - help - Name of the display device to use for rendering. - config LVGL_HOR_RES int "Horizontal Screen Resolution" default 320 diff --git a/lib/gui/lvgl/lvgl.c b/lib/gui/lvgl/lvgl.c index f7e7c39f9cff..fef91db09a1e 100644 --- a/lib/gui/lvgl/lvgl.c +++ b/lib/gui/lvgl/lvgl.c @@ -150,8 +150,7 @@ static int lvgl_init(struct device *dev) { ARG_UNUSED(dev); - struct device *display_dev = - device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME); + struct device *display_dev = device_get_by_prefix("DISPLAY", 0); lv_disp_drv_t disp_drv; if (display_dev == NULL) { diff --git a/samples/display/cfb/src/main.c b/samples/display/cfb/src/main.c index 27343aaf1f26..187fca068f3d 100644 --- a/samples/display/cfb/src/main.c +++ b/samples/display/cfb/src/main.c @@ -9,18 +9,6 @@ #include #include -#if defined(CONFIG_SSD16XX) -#define DISPLAY_DRIVER "SSD16XX" -#endif - -#if defined(CONFIG_SSD1306) -#define DISPLAY_DRIVER "SSD1306" -#endif - -#ifndef DISPLAY_DRIVER -#define DISPLAY_DRIVER "DISPLAY" -#endif - void main(void) { struct device *dev; @@ -29,7 +17,7 @@ void main(void) u8_t font_width; u8_t font_height; - dev = device_get_binding(DISPLAY_DRIVER); + dev = device_get_by_prefix("DISPLAY", 0); if (dev == NULL) { printf("Device not found\n"); @@ -41,7 +29,7 @@ void main(void) return; } - printf("initialized %s\n", DISPLAY_DRIVER); + printf("Device label %s\n", dev->config->name); if (cfb_framebuffer_init(dev)) { printf("Framebuffer initialization failed!\n"); diff --git a/samples/gui/lvgl/boards/native_posix.conf b/samples/gui/lvgl/boards/native_posix.conf index 77136ee89c4e..0b4824c00cc9 100644 --- a/samples/gui/lvgl/boards/native_posix.conf +++ b/samples/gui/lvgl/boards/native_posix.conf @@ -1,5 +1,4 @@ CONFIG_SDL_DISPLAY=y -CONFIG_SDL_DISPLAY_DEV_NAME="DISPLAY" CONFIG_SDL_DISPLAY_X_RES=320 CONFIG_SDL_DISPLAY_Y_RES=240 diff --git a/samples/gui/lvgl/boards/native_posix_64.conf b/samples/gui/lvgl/boards/native_posix_64.conf index 77136ee89c4e..0b4824c00cc9 100644 --- a/samples/gui/lvgl/boards/native_posix_64.conf +++ b/samples/gui/lvgl/boards/native_posix_64.conf @@ -1,5 +1,4 @@ CONFIG_SDL_DISPLAY=y -CONFIG_SDL_DISPLAY_DEV_NAME="DISPLAY" CONFIG_SDL_DISPLAY_X_RES=320 CONFIG_SDL_DISPLAY_Y_RES=240 diff --git a/samples/gui/lvgl/boards/reel_board.overlay b/samples/gui/lvgl/boards/reel_board.overlay deleted file mode 100644 index ff93b76b78b6..000000000000 --- a/samples/gui/lvgl/boards/reel_board.overlay +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2018 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ - -&spi1 { - ssd16xxfb@0 { - label = "DISPLAY"; - }; -}; diff --git a/samples/gui/lvgl/src/main.c b/samples/gui/lvgl/src/main.c index ebe89eb77266..7b71d5b23d50 100644 --- a/samples/gui/lvgl/src/main.c +++ b/samples/gui/lvgl/src/main.c @@ -23,7 +23,7 @@ void main(void) lv_obj_t *hello_world_label; lv_obj_t *count_label; - display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME); + display_dev = device_get_by_prefix("DISPLAY", 0); if (display_dev == NULL) { LOG_ERR("device not found. Aborting test.");