diff --git a/tests/pkg_lvgl_touch/Makefile b/tests/pkg_lvgl_touch/Makefile new file mode 100644 index 0000000000..ee21be62f4 --- /dev/null +++ b/tests/pkg_lvgl_touch/Makefile @@ -0,0 +1,15 @@ +BOARD ?= stm32f429i-disc1 +include ../Makefile.tests_common + +# No interactive_sync +DISABLE_MODULE += test_utils_interactive_sync + +USEPKG += lvgl +USEMODULE += lvgl_contrib +USEMODULE += ili9341 + +# Add touch capabilities +USEMODULE += lvgl_contrib_touch +USEMODULE += stmpe811 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_lvgl_touch/Makefile.ci b/tests/pkg_lvgl_touch/Makefile.ci new file mode 100644 index 0000000000..7c661f9211 --- /dev/null +++ b/tests/pkg_lvgl_touch/Makefile.ci @@ -0,0 +1,17 @@ +BOARD_INSUFFICIENT_MEMORY := \ + blackpill \ + bluepill \ + i-nucleo-lrwan1 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f302r8 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + saml10-xpro \ + saml11-xpro \ + stm32f030f4-demo \ + stm32f0discovery \ + stm32l0538-disco \ + # diff --git a/tests/pkg_lvgl_touch/README.md b/tests/pkg_lvgl_touch/README.md new file mode 100644 index 0000000000..43f6c0441e --- /dev/null +++ b/tests/pkg_lvgl_touch/README.md @@ -0,0 +1,18 @@ +LittlevGL sample application +============================ + +This application shows a usage of LittlevGL with touch capabilities. + +### Flashing the application + +The application works without modification on the stm32f429i-disc1 board. To +build, flash and run the application for this board, just use: + +``` +make BOARD=stm32f429i-disc1 -C tests/pkg_lvgl_touch flash +``` + +### Expected result + +The application simply displays a button that can be clicked. Each time the +button is clicked, the message "Button clicked!" is displayed in the terminal. diff --git a/tests/pkg_lvgl_touch/main.c b/tests/pkg_lvgl_touch/main.c new file mode 100644 index 0000000000..47c68bb1d2 --- /dev/null +++ b/tests/pkg_lvgl_touch/main.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2020 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief LittlevGL example application with clickable button + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "lvgl/lvgl.h" +#include "lvgl_riot.h" + +#include "ili9341.h" +#include "ili9341_params.h" +#include "disp_dev.h" +#include "ili9341_disp_dev.h" + +#include "stmpe811.h" +#include "stmpe811_params.h" +#include "touch_dev.h" +#include "stmpe811_touch_dev.h" + +#include "screen_dev.h" + +static screen_dev_t s_screen; +static ili9341_t s_disp_dev; +static stmpe811_t s_touch_dev; + +static void _stmpe811_event_cb(void *arg) +{ + (void)arg; + lvgl_wakeup(); +} + +static void btn_event_cb(lv_obj_t * btn, lv_event_t event) +{ + (void)btn; + if (event == LV_EVENT_CLICKED) { + puts("Button clicked!"); + } +} + +int main(void) +{ + /* Configure the generic display driver interface */ + s_screen.display = (disp_dev_t *)&s_disp_dev; + s_screen.display->driver = &ili9341_disp_dev_driver; + + /* Initialize the concrete display driver */ + ili9341_init(&s_disp_dev, &ili9341_params[0]); + + /* Configure the generic touch driver interface */ + s_screen.touch = (touch_dev_t *)&s_touch_dev; + s_screen.touch->driver = &stmpe811_touch_dev_driver; + + /* Initialize the concrete touch driver */ + stmpe811_init(&s_touch_dev, &stmpe811_params[0], _stmpe811_event_cb, NULL); + + /* Initialize lvgl with the generic screen */ + lvgl_init(&s_screen); + + /* Add a button to the current screen */ + lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); + + /* Set the button position and size */ + lv_coord_t x_size = 100; + lv_coord_t y_size = 50; + lv_coord_t x_pos = (disp_dev_width(s_screen.display) - x_size) / 2; + lv_coord_t y_pos = (disp_dev_height(s_screen.display) - y_size) / 2; + lv_obj_set_pos(btn, x_pos, y_pos); + lv_obj_set_size(btn, 100, 50); + + /*Assign a callback to the button*/ + lv_obj_set_event_cb(btn, btn_event_cb); + + /* Add a label to the button */ + lv_obj_t * label = lv_label_create(btn, NULL); + lv_label_set_text(label, "Click me"); + + return 0; +}