Skip to content

Commit

Permalink
sample: gui: Added basic sample for lvgl library
Browse files Browse the repository at this point in the history
Added a basic sample showing how to use the LittlevGL library in an
application.

Signed-off-by: Jan Van Winkel <[email protected]>
  • Loading branch information
vanwinkeljan authored and nashif committed Jan 7, 2019
1 parent cbfcae7 commit 81301bf
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/gui/gui.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _gui-samples:

GUI Samples
###########

.. toctree::
:maxdepth: 1
:glob:

**/*
17 changes: 17 additions & 0 deletions samples/gui/lvgl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
75 changes: 75 additions & 0 deletions samples/gui/lvgl/README.rst
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions samples/gui/lvgl/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions samples/gui/lvgl/boards/nrf52840_pca10056.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_SPI=y
CONFIG_SPI_1=y
CONFIG_SPI_NRFX=y

CONFIG_ILI9340=y

CONFIG_LVGL_BITS_PER_PIXEL=24
9 changes: 9 additions & 0 deletions samples/gui/lvgl/boards/reel_board.conf
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions samples/gui/lvgl/dts_fixup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018 Jan Van Winkel <[email protected]>
*
* 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

19 changes: 19 additions & 0 deletions samples/gui/lvgl/nrf52840_pca10056.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2018 Jan Van Winkel <[email protected]>
*
* 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>;
};
};
8 changes: 8 additions & 0 deletions samples/gui/lvgl/prj.conf
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions samples/gui/lvgl/reel_board.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2018 Jan Van Winkel <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

&spi3 {
ssd1673fb@0 {
label = "DISPLAY";
};
};
8 changes: 8 additions & 0 deletions samples/gui/lvgl/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions samples/gui/lvgl/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 Jan Van Winkel <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <device.h>
#include <display.h>
#include <lvgl.h>
#include <stdio.h>
#include <string.h>
#include <zephyr.h>

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <logging/log.h>
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;
}
}
1 change: 1 addition & 0 deletions samples/samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit 81301bf

Please sign in to comment.