diff --git a/samples/gui/gui.rst b/samples/gui/gui.rst new file mode 100644 index 00000000000000..43e5c92c9b096c --- /dev/null +++ b/samples/gui/gui.rst @@ -0,0 +1,10 @@ +.. _gui-samples: + +GUI Samples +########### + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* diff --git a/samples/gui/lvgl/CMakeLists.txt b/samples/gui/lvgl/CMakeLists.txt new file mode 100644 index 00000000000000..e8a2e4ff6f4ed5 --- /dev/null +++ b/samples/gui/lvgl/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.8.2) +macro(set_conf_file) + if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf) + set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf") + elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) + set(CONF_FILE + "prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf") + else() + set(CONF_FILE "prj.conf") + endif() +endmacro() + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(lvgl) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/gui/lvgl/README.rst b/samples/gui/lvgl/README.rst new file mode 100644 index 00000000000000..343231f9546fe8 --- /dev/null +++ b/samples/gui/lvgl/README.rst @@ -0,0 +1,75 @@ +.. _lvgl-sample: + +LittlevGL Basic Sample +###################### + +Overview +******** + +This sample application displays "Hello World" in the center of the screen +and a counter at the bottom which increments every second. + +Requirements +************ + +- `nRF52840 Preview development kit`_ +- `Adafruit 2.2 inch TFT Display`_ + +or a simulated display environment in a native Posix application: + +- :ref:`native_posix` +- `SDL2`_ + +Wiring +****** + +The nrf52840 Preview development kit should be connected as follows to the +Adafruit TFT display. + ++-------------+----------------+ +| | nrf52840 | | Adafruit TFT | +| | Pin | | Pin | ++=============+================+ +| P0.27 | SCK | ++-------------+----------------+ +| P0.31 | D/C | ++-------------+----------------+ +| P0.30 | RST | ++-------------+----------------+ +| P0.26 | MOSI | ++-------------+----------------+ +| P0.29 | MISO | ++-------------+----------------+ +| P0.4 | NSS | ++-------------+----------------+ + +Building and Running +******************** + +Build this sample using the following commands: + +.. zephyr-app-commands:: + :zephyr-app: samples/gui/lvgl + :board: nrf52840_pca10056 + :goals: build + :compact: + +See :ref:`nrf52840_pca10056` on how to flash the build. + +or + +.. zephyr-app-commands:: + :zephyr-app: samples/gui/lvgl + :board: native_posix + :goals: build + :compact: + +References +********** + +.. target-notes:: + +.. _LittlevGL Web Page: https://littlevgl.com/ +.. _Adafruit 2.2 inch TFT Display: https://www.adafruit.com/product/1480 +.. _nRF52840 Preview development kit: http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK +.. _SDL2: https://www.libsdl.org diff --git a/samples/gui/lvgl/boards/native_posix.conf b/samples/gui/lvgl/boards/native_posix.conf new file mode 100644 index 00000000000000..77136ee89c4e00 --- /dev/null +++ b/samples/gui/lvgl/boards/native_posix.conf @@ -0,0 +1,5 @@ +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/nrf52840_pca10056.conf b/samples/gui/lvgl/boards/nrf52840_pca10056.conf new file mode 100644 index 00000000000000..43a2c343d61053 --- /dev/null +++ b/samples/gui/lvgl/boards/nrf52840_pca10056.conf @@ -0,0 +1,7 @@ +CONFIG_SPI=y +CONFIG_SPI_1=y +CONFIG_SPI_NRFX=y + +CONFIG_ILI9340=y + +CONFIG_LVGL_BITS_PER_PIXEL=24 diff --git a/samples/gui/lvgl/boards/reel_board.conf b/samples/gui/lvgl/boards/reel_board.conf new file mode 100644 index 00000000000000..52918090e66359 --- /dev/null +++ b/samples/gui/lvgl/boards/reel_board.conf @@ -0,0 +1,9 @@ +CONFIG_SPI=y +CONFIG_SSD1673=y + +CONFIG_LVGL_COLOR_DEPTH_1=y +CONFIG_LVGL_BITS_PER_PIXEL=1 +CONFIG_LVGL_HOR_RES=250 +CONFIG_LVGL_VER_RES=120 +CONFIG_LVGL_DPI=130 +CONFIG_LVGL_VDB_SIZE=16 diff --git a/samples/gui/lvgl/dts_fixup.h b/samples/gui/lvgl/dts_fixup.h new file mode 100644 index 00000000000000..fddf43c7eb322a --- /dev/null +++ b/samples/gui/lvgl/dts_fixup.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#if defined(CONFIG_SPI_NRFX) && defined(CONFIG_ILI9340) + +#define DT_ILI9340_SPI_DEV_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_BUS_NAME + +#define DT_ILI9340_SPI_SLAVE_NUMBER \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_BASE_ADDRESS + +#define DT_ILI9340_CMD_DATA_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER + +#define DT_ILI9340_CMD_DATA_PIN \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN + +#define DT_ILI9340_DEV_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_LABEL + +#define DT_ILI9340_RESET_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER + +#define DT_ILI9340_RESET_PIN \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_RESET_GPIOS_PIN + +#define DT_ILI9340_SPI_FREQ \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY + +#define DT_ILI9340_CS_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_CS_GPIOS_CONTROLLER + +#define DT_ILI9340_CS_GPIO_PIN \ + DT_NORDIC_NRF_SPI_40004000_CS_GPIOS_PIN + +#endif + diff --git a/samples/gui/lvgl/nrf52840_pca10056.overlay b/samples/gui/lvgl/nrf52840_pca10056.overlay new file mode 100644 index 00000000000000..c3aa02aeca7635 --- /dev/null +++ b/samples/gui/lvgl/nrf52840_pca10056.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi1 { + status = "ok"; + cs-gpios = <&gpio0 4 0>; + + ili9340@0 { + compatible = "ilitek,ili9340"; + label = "DISPLAY"; + spi-max-frequency = <15151515>; + reg = <0>; + reset-gpios = <&gpio0 30 0>; + cmd-data-gpios = <&gpio0 31 0>; + }; +}; diff --git a/samples/gui/lvgl/prj.conf b/samples/gui/lvgl/prj.conf new file mode 100644 index 00000000000000..49efbe377af951 --- /dev/null +++ b/samples/gui/lvgl/prj.conf @@ -0,0 +1,8 @@ +CONFIG_HEAP_MEM_POOL_SIZE=16384 + +CONFIG_DISPLAY=y +CONFIG_DISPLAY_LOG_LEVEL_ERR=y + +CONFIG_LOG=y + +CONFIG_LVGL=y diff --git a/samples/gui/lvgl/reel_board.overlay b/samples/gui/lvgl/reel_board.overlay new file mode 100644 index 00000000000000..a785c0723462ad --- /dev/null +++ b/samples/gui/lvgl/reel_board.overlay @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi3 { + ssd1673fb@0 { + label = "DISPLAY"; + }; +}; diff --git a/samples/gui/lvgl/sample.yaml b/samples/gui/lvgl/sample.yaml new file mode 100644 index 00000000000000..24393837917d00 --- /dev/null +++ b/samples/gui/lvgl/sample.yaml @@ -0,0 +1,8 @@ +sample: + description: LVGL sample application + name: lvgl +tests: + test: + harness: display + platform_whitelist: nrf52840_pca10056 reel_board + tags: samples display gui diff --git a/samples/gui/lvgl/src/main.c b/samples/gui/lvgl/src/main.c new file mode 100644 index 00000000000000..3932976b8f1cc2 --- /dev/null +++ b/samples/gui/lvgl/src/main.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include +LOG_MODULE_REGISTER(app); + +void main(void) +{ + u32_t count = 0; + char count_str[11] = {0}; + struct device *display_dev; + lv_obj_t *hello_world_label; + lv_obj_t *count_label; + + display_dev = device_get_binding("DISPLAY"); + + if (display_dev == NULL) { + LOG_ERR("device not found. Aborting test."); + return; + } + + hello_world_label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(hello_world_label, "Hello world!"); + lv_obj_align(hello_world_label, NULL, LV_ALIGN_CENTER, 0, 0); + + count_label = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(count_label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + display_blanking_off(display_dev); + + while (1) { + if ((count % 100) == 0) { + sprintf(count_str, "%d", count/100); + lv_label_set_text(count_label, count_str); + } + lv_task_handler(); + k_sleep(10); + ++count; + } +} diff --git a/samples/samples.rst b/samples/samples.rst index 504e35935068a6..3a2e824cef0a8d 100644 --- a/samples/samples.rst +++ b/samples/samples.rst @@ -22,6 +22,7 @@ Samples and Demos display/* shields/* portability/* + gui/* To add a new sample document, please use the template available under :file:`doc/templates/sample.tmpl`