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>
|
2023-02-22 13:57:02 +01:00
|
|
|
#include <sys/param.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>
|
2022-10-08 11:03:06 +02:00
|
|
|
#include <stdio.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
#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>
|
2022-10-08 11:03:06 +02:00
|
|
|
#include <port/lv_port.h>
|
|
|
|
#include <lvgl/demos/lv_demos.h>
|
2021-03-31 20:19:47 +02:00
|
|
|
|
2023-02-22 09:00:41 +01:00
|
|
|
#ifdef CONFIG_LIBUV
|
|
|
|
# include <uv.h>
|
|
|
|
# include <port/lv_port_libuv.h>
|
|
|
|
#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
|
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Declarations
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
typedef CODE void (*demo_create_func_t)(void);
|
|
|
|
|
|
|
|
struct func_key_pair_s
|
|
|
|
{
|
|
|
|
FAR const char *name;
|
|
|
|
demo_create_func_t func;
|
|
|
|
};
|
2020-06-17 10:50:05 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2022-10-08 11:03:06 +02:00
|
|
|
* Private Data
|
2020-06-17 10:50:05 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
static const struct func_key_pair_s func_key_pair[] =
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_LV_USE_DEMO_WIDGETS
|
|
|
|
{ "widgets", lv_demo_widgets },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER
|
|
|
|
{ "keypad_encoder", lv_demo_keypad_encoder },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LV_USE_DEMO_BENCHMARK
|
|
|
|
{ "benchmark", lv_demo_benchmark },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LV_USE_DEMO_STRESS
|
|
|
|
{ "stress", lv_demo_stress },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_LV_USE_DEMO_MUSIC
|
|
|
|
{ "music", lv_demo_music },
|
|
|
|
#endif
|
|
|
|
{ "", NULL }
|
|
|
|
};
|
2020-06-17 10:50:05 +02:00
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/****************************************************************************
|
2022-10-08 11:03:06 +02:00
|
|
|
* Name: show_usage
|
2021-02-15 10:05:04 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
static void show_usage(void)
|
2021-02-15 10:05:04 +01:00
|
|
|
{
|
2022-10-08 11:03:06 +02:00
|
|
|
int i;
|
2023-02-22 13:57:02 +01:00
|
|
|
const int len = nitems(func_key_pair) - 1;
|
2022-10-08 11:03:06 +02:00
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
printf("lvgldemo: no demo available!\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nUsage: lvgldemo demo_name\n");
|
|
|
|
printf("\ndemo_name:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
printf(" %s\n", func_key_pair[i].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
2021-02-15 10:05:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-10-08 11:03:06 +02:00
|
|
|
* Name: find_demo_create_func
|
2021-02-15 10:05:04 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
static demo_create_func_t find_demo_create_func(FAR const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
2023-02-22 13:57:02 +01:00
|
|
|
const int len = nitems(func_key_pair) - 1;
|
2021-04-05 15:03:18 +02:00
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(name, func_key_pair[i].name) == 0)
|
|
|
|
{
|
|
|
|
return func_key_pair[i].func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("lvgldemo: '%s' not found.\n", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
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[])
|
|
|
|
{
|
2022-10-08 11:03:06 +02:00
|
|
|
demo_create_func_t demo_create_func;
|
2023-01-16 01:29:43 +01:00
|
|
|
FAR const char *demo = NULL;
|
2023-02-22 13:57:02 +01:00
|
|
|
const int func_key_pair_len = nitems(func_key_pair);
|
2020-06-10 05:12:59 +02:00
|
|
|
|
2023-02-22 09:00:41 +01:00
|
|
|
#ifdef CONFIG_LIBUV
|
|
|
|
uv_loop_t ui_loop;
|
|
|
|
#endif
|
|
|
|
|
2023-01-16 01:29:43 +01:00
|
|
|
/* If no arguments are specified and only 1 demo exists, select the demo */
|
|
|
|
|
|
|
|
if (argc == 1 && func_key_pair_len == 2) /* 2 because of NULL sentinel */
|
|
|
|
{
|
|
|
|
demo = func_key_pair[0].name;
|
|
|
|
}
|
|
|
|
else if (argc != 2)
|
2022-10-08 11:03:06 +02:00
|
|
|
{
|
|
|
|
show_usage();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2023-01-16 01:29:43 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
demo = argv[1];
|
|
|
|
}
|
2020-06-10 05:12:59 +02:00
|
|
|
|
2023-01-16 01:29:43 +01:00
|
|
|
demo_create_func = find_demo_create_func(demo);
|
2020-06-10 05:12:59 +02:00
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
if (demo_create_func == NULL)
|
|
|
|
{
|
|
|
|
show_usage();
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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();
|
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
/* LVGL port initialization */
|
2021-02-15 10:05:04 +01:00
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
lv_port_init();
|
2021-02-15 10:05:04 +01:00
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
/* LVGL demo creation */
|
2021-02-15 10:05:04 +01:00
|
|
|
|
2022-10-08 11:03:06 +02:00
|
|
|
demo_create_func();
|
2021-03-31 20:19:47 +02:00
|
|
|
|
2020-06-17 10:50:05 +02:00
|
|
|
/* Handle LVGL tasks */
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2023-02-22 09:00:41 +01:00
|
|
|
#ifdef CONFIG_LIBUV
|
|
|
|
uv_loop_init(&ui_loop);
|
|
|
|
lv_port_libuv_init(&ui_loop);
|
|
|
|
uv_run(&ui_loop, UV_RUN_DEFAULT);
|
|
|
|
#else
|
2018-01-16 22:35:55 +01:00
|
|
|
while (1)
|
|
|
|
{
|
2022-10-08 11:03:06 +02:00
|
|
|
uint32_t idle;
|
|
|
|
idle = lv_timer_handler();
|
|
|
|
|
|
|
|
/* Minimum sleep of 1ms */
|
|
|
|
|
|
|
|
idle = idle ? idle : 1;
|
|
|
|
usleep(idle * 1000);
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
2023-02-22 09:00:41 +01:00
|
|
|
#endif
|
2018-01-16 22:35:55 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|