2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
2021-02-15 10:05:04 +01:00
|
|
|
* apps/examples/lvgldemo/lvgldemo.c
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2018-01-18 14:12:31 +01:00
|
|
|
#include <sys/boardctl.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
#include <unistd.h>
|
2021-04-05 15:03:18 +02:00
|
|
|
#include <stddef.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
2021-02-15 10:05:04 +01:00
|
|
|
#include <debug.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2020-07-15 14:33:00 +02:00
|
|
|
#include <lvgl/lvgl.h>
|
2018-01-18 14:12:31 +01:00
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
#include "fbdev.h"
|
2021-02-15 10:05:04 +01:00
|
|
|
#include "lcddev.h"
|
2021-03-31 20:19:47 +02:00
|
|
|
|
2021-04-12 21:06:40 +02:00
|
|
|
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
2018-01-16 22:35:55 +01:00
|
|
|
#include "tp.h"
|
|
|
|
#include "tp_cal.h"
|
2021-03-31 20:19:47 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-18 14:12:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Should we perform board-specific driver initialization? There are two
|
|
|
|
* ways that board initialization can occur: 1) automatically via
|
2020-04-15 12:17:45 +02:00
|
|
|
* board_late_initialize() during bootupif CONFIG_BOARD_LATE_INITIALIZE
|
|
|
|
* or 2).
|
|
|
|
* via a call to boardctl() if the interface is enabled
|
2021-08-01 08:59:37 +02:00
|
|
|
* (CONFIG_BOARDCTL=y).
|
2018-01-18 14:12:31 +01:00
|
|
|
* If this task is running as an NSH built-in application, then that
|
|
|
|
* initialization has probably already been performed otherwise we do it
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef NEED_BOARDINIT
|
|
|
|
|
2021-08-01 08:59:37 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL) && !defined(CONFIG_NSH_ARCHINIT)
|
2018-01-18 14:12:31 +01:00
|
|
|
# define NEED_BOARDINIT 1
|
|
|
|
#endif
|
|
|
|
|
2020-06-17 10:50:05 +02:00
|
|
|
#define DISPLAY_BUFFER_SIZE (CONFIG_LV_HOR_RES * \
|
|
|
|
CONFIG_EXAMPLES_LVGLDEMO_BUFF_SIZE)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void lv_demo_benchmark(void);
|
|
|
|
void lv_demo_printer(void);
|
|
|
|
void lv_demo_stress(void);
|
|
|
|
void lv_demo_widgets(void);
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: monitor_cb
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Monitoring callback from lvgl every time the screen is flushed.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px)
|
|
|
|
{
|
|
|
|
ginfo("%" PRIu32 " px refreshed in %" PRIu32 " ms\n", px, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-04-05 15:03:18 +02:00
|
|
|
static lv_color_t buffer1[DISPLAY_BUFFER_SIZE];
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_DOUBLE_BUFFERING
|
|
|
|
static lv_color_t buffer2[DISPLAY_BUFFER_SIZE];
|
|
|
|
#else
|
|
|
|
# define buffer2 NULL
|
|
|
|
#endif
|
2021-02-15 10:05:04 +01:00
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: main or lvgldemo_main
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard argc and argv
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a positive, non-zero value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
2018-01-18 14:12:31 +01:00
|
|
|
lv_disp_drv_t disp_drv;
|
2020-04-07 03:43:02 +02:00
|
|
|
lv_disp_buf_t disp_buf;
|
|
|
|
|
2021-04-12 21:07:54 +02:00
|
|
|
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
2020-06-10 05:12:59 +02:00
|
|
|
#ifndef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE
|
|
|
|
lv_point_t p[4];
|
|
|
|
|
|
|
|
/* top left */
|
|
|
|
|
|
|
|
p[0].x = 0;
|
|
|
|
p[0].y = 0;
|
|
|
|
|
|
|
|
/* top right */
|
|
|
|
|
|
|
|
p[1].x = LV_HOR_RES;
|
|
|
|
p[1].y = 0;
|
|
|
|
|
|
|
|
/* bottom left */
|
|
|
|
|
|
|
|
p[2].x = 0;
|
|
|
|
p[2].y = LV_VER_RES;
|
|
|
|
|
|
|
|
/* bottom right */
|
|
|
|
|
|
|
|
p[3].x = LV_HOR_RES;
|
|
|
|
p[3].y = LV_VER_RES;
|
|
|
|
#endif
|
2021-04-12 21:07:54 +02:00
|
|
|
#endif
|
2020-06-10 05:12:59 +02:00
|
|
|
|
2018-01-18 14:12:31 +01:00
|
|
|
#ifdef NEED_BOARDINIT
|
|
|
|
/* Perform board-specific driver initialization */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_INIT, 0);
|
2018-08-28 23:44:03 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_BOARDCTL_FINALINIT
|
|
|
|
/* Perform architecture-specific final-initialization (if configured) */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_FINALINIT, 0);
|
2018-08-28 23:44:03 +02:00
|
|
|
#endif
|
2018-01-18 14:12:31 +01:00
|
|
|
#endif
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* LVGL initialization */
|
2018-01-18 14:12:31 +01:00
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
lv_init();
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* Basic LVGL display driver initialization */
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-04-05 15:03:18 +02:00
|
|
|
lv_disp_buf_init(&disp_buf, buffer1, buffer2, DISPLAY_BUFFER_SIZE);
|
2018-01-16 22:35:55 +01:00
|
|
|
lv_disp_drv_init(&disp_drv);
|
2020-04-07 03:43:02 +02:00
|
|
|
disp_drv.buffer = &disp_buf;
|
2021-02-15 10:05:04 +01:00
|
|
|
disp_drv.monitor_cb = monitor_cb;
|
|
|
|
|
|
|
|
/* Display interface initialization */
|
|
|
|
|
|
|
|
if (fbdev_init(&disp_drv) != EXIT_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Failed to use framebuffer falling back to lcd driver */
|
|
|
|
|
|
|
|
if (lcddev_init(&disp_drv) != EXIT_SUCCESS)
|
|
|
|
{
|
|
|
|
/* No possible drivers left, fail */
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
lv_disp_drv_register(&disp_drv);
|
|
|
|
|
2021-04-12 21:06:40 +02:00
|
|
|
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
2018-01-16 22:35:55 +01:00
|
|
|
/* Touchpad Initialization */
|
|
|
|
|
|
|
|
tp_init();
|
|
|
|
lv_indev_drv_t indev_drv;
|
|
|
|
lv_indev_drv_init(&indev_drv);
|
|
|
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
|
|
|
|
|
|
|
/* This function will be called periodically (by the library) to get the
|
|
|
|
* mouse position and state.
|
|
|
|
*/
|
|
|
|
|
2020-04-07 03:43:02 +02:00
|
|
|
indev_drv.read_cb = tp_read;
|
2018-01-16 22:35:55 +01:00
|
|
|
lv_indev_drv_register(&indev_drv);
|
2021-03-31 20:19:47 +02:00
|
|
|
#endif
|
|
|
|
|
2020-06-17 10:50:05 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_LVGLDEMO_BENCHMARK)
|
|
|
|
lv_demo_benchmark();
|
|
|
|
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_PRINTER)
|
|
|
|
lv_demo_printer();
|
|
|
|
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_STRESS)
|
|
|
|
lv_demo_stress();
|
|
|
|
#elif defined(CONFIG_EXAMPLES_LVGLDEMO_WIDGETS)
|
|
|
|
lv_demo_widgets();
|
|
|
|
#endif
|
|
|
|
|
2021-04-12 21:06:40 +02:00
|
|
|
#if defined(CONFIG_INPUT_TOUCHSCREEN) || defined(CONFIG_INPUT_MOUSE)
|
2018-01-16 22:35:55 +01:00
|
|
|
/* Start TP calibration */
|
|
|
|
|
2020-06-10 05:12:59 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_CALIBRATE
|
2018-01-16 22:35:55 +01:00
|
|
|
tp_cal_create();
|
2020-06-10 05:12:59 +02:00
|
|
|
#else
|
|
|
|
tp_set_cal_values(p, p + 1, p + 2, p + 3);
|
|
|
|
#endif
|
2021-03-31 20:19:47 +02:00
|
|
|
#endif
|
|
|
|
|
2020-06-17 10:50:05 +02:00
|
|
|
/* Handle LVGL tasks */
|
2018-01-16 22:35:55 +01:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
lv_task_handler();
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|