Skip to content

Commit ca61d6a

Browse files
salkiniumrleh
andcommitted
[ext] Add LVGL embedded GUI library
Co-authored-by: Raphael Lehmann <[email protected]>
1 parent 316bfba commit ca61d6a

File tree

7 files changed

+224
-0
lines changed

7 files changed

+224
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
[submodule "ext/chan/fatfs"]
3232
path = ext/chan/fatfs
3333
url = https://github.com/modm-ext/fatfs-partial.git
34+
[submodule "ext/lvgl/lvgl"]
35+
path = ext/lvgl/lvgl
36+
url = https://github.com/modm-ext/lvgl-partial.git

ext/lvgl/lv_conf.h.in

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file lv_conf.h
3+
* Configuration file for v7.11.0
4+
*/
5+
6+
#ifndef LV_CONF_H
7+
#define LV_CONF_H
8+
/* clang-format off */
9+
10+
#include <stdint.h>
11+
12+
/* A header file that overwrites with local project settings. */
13+
#if __has_include(<lv_conf_local.h>)
14+
# include <lv_conf_local.h>
15+
#endif
16+
17+
/*====================
18+
Graphical settings
19+
*====================*/
20+
21+
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
22+
typedef int16_t lv_coord_t;
23+
24+
/*=========================
25+
Memory manager settings
26+
*=========================*/
27+
28+
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
29+
#define LV_MEM_CUSTOM 1
30+
31+
/*===================
32+
* HAL settings
33+
*==================*/
34+
35+
/* 1: use a custom tick source.
36+
* It removes the need to manually update the tick with `lv_tick_inc`) */
37+
#define LV_TICK_CUSTOM 1
38+
/*Header for the system time function*/
39+
#define LV_TICK_CUSTOM_INCLUDE <lv_modm_clock.h>
40+
/*Expression evaluating to current system time in ms*/
41+
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (lv_modm_clock_now())
42+
43+
/*================
44+
* Log settings
45+
*===============*/
46+
47+
/* 1: Print the log with 'printf';
48+
* 0: user need to register a callback with `lv_log_register_print_cb`*/
49+
#define LV_LOG_PRINTF 0
50+
51+
/*--END OF LV_CONF_H--*/
52+
53+
#endif /*LV_CONF_H*/

ext/lvgl/lv_modm_clock.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2021 Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include "lv_modm_clock.h"
12+
#include <modm/architecture/interface/clock.hpp>
13+
14+
uint32_t lv_modm_clock_now()
15+
{
16+
return modm::Clock::now().time_since_epoch().count();
17+
}

ext/lvgl/lv_modm_clock.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2021 Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#ifndef LV_MODM_CLOCK_HPP
12+
#define LV_MODM_CLOCK_HPP
13+
14+
#include <stdint.h>
15+
#include <modm/architecture/utils.hpp>
16+
17+
modm_extern_c uint32_t
18+
lv_modm_clock_now(void);
19+
20+
#endif

ext/lvgl/lv_modm_logging.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2021 Raphael Lehmann
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <lvgl/lvgl.h>
12+
#include <modm/debug/logger.hpp>
13+
14+
#if LV_USE_LOG
15+
static void _lv_modm_logging_callback(lv_log_level_t level, const char * file, uint32_t line, const char * fn_name, const char * dsc)
16+
{
17+
switch (level)
18+
{
19+
case LV_LOG_LEVEL_ERROR:
20+
MODM_LOG_ERROR << "LVGL(" << file << ":" << line << ") " << fn_name << ": " << dsc << modm::endl;
21+
break;
22+
case LV_LOG_LEVEL_WARN:
23+
MODM_LOG_WARNING << "LVGL(" << file << ":" << line << ") " << fn_name << ": " << dsc << modm::endl;
24+
break;
25+
case LV_LOG_LEVEL_INFO:
26+
MODM_LOG_INFO << "LVGL(" << file << ":" << line << ") " << fn_name << ": " << dsc << modm::endl;
27+
break;
28+
case LV_LOG_LEVEL_TRACE:
29+
MODM_LOG_DEBUG << "LVGL(" << file << ":" << line << ") " << fn_name << ": " << dsc << modm::endl;
30+
break;
31+
default:
32+
break;
33+
}
34+
}
35+
36+
__attribute__((constructor))
37+
static void lv_register_modm_logging()
38+
{
39+
// register modm logging callback with LVGL
40+
lv_log_register_print_cb(_lv_modm_logging_callback);
41+
}
42+
#endif

ext/lvgl/lvgl

Submodule lvgl added at 315d090

ext/lvgl/lvgl.lb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2020, Raphael Lehmann
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
def init(module):
14+
module.name = ":lvgl"
15+
module.description = """
16+
# LVGL graphics library
17+
18+
LVGL is a free and open-source graphics library providing everything you need
19+
to create embedded GUI with easy-to-use graphical elements, beautiful visual effects
20+
and low memory footprint.
21+
22+
- https://lvgl.io/
23+
- https://github.com/lvgl/lvgl
24+
25+
26+
## Configuration
27+
28+
LVGL defines defaults for all it's configuration settings, which you can find in
29+
the [configuration template][conf_template].
30+
31+
This module generates a `lv_conf.h` file to define the options necessary for
32+
integration with modm which are:
33+
34+
- `LV_MEM_CUSTOM = 1`: Heap is provided by the `modm:platform:heap` module.
35+
- `LV_TICK_CUSTOM = 1`: Tick is implemented via the `modm:platform:clock` module.
36+
- `LV_LOG_PRINTF = 0`: logging is redirected to `MODM_LOG_*` if the
37+
`modm:debug` module is included and `LV_USE_LOG = 1`.
38+
- `typedef int16_t lv_coord_t;`: Hardcoded choice for now.
39+
40+
To add your own configuration you can create a `<lv_conf_local.h>` file which
41+
will automatically be included at the *beginning* of our `lv_conf.h`.
42+
43+
Example `<lv_conf_local.h>` configuration:
44+
45+
```c
46+
// Maximal resolutions
47+
#define LV_HOR_RES_MAX 240
48+
#define LV_VER_RES_MAX 320
49+
#define LV_DPI 200
50+
51+
/* Color depth:
52+
* - 1: 1 byte per pixel
53+
* - 8: RGB332
54+
* - 16: RGB565
55+
* - 32: ARGB8888
56+
*/
57+
#define LV_COLOR_DEPTH 16
58+
59+
// Enable logging at INFO level
60+
#define LV_USE_LOG 1
61+
#define LV_LOG_LEVEL LV_LOG_LEVEL_INFO
62+
63+
// Disable anti-aliasing
64+
#define LV_ANTIALIAS 0
65+
```
66+
67+
[conf_template]: https://github.com/lvgl/lvgl/blob/master/lv_conf_template.h
68+
"""
69+
70+
def prepare(module, options):
71+
module.depends(":architecture:clock")
72+
if options[":target"].identifier.platform != "hosted":
73+
module.depends(":platform:heap")
74+
75+
return True
76+
77+
def build(env):
78+
env.collect(":build:path.include", "modm/ext/lvgl")
79+
env.outbasepath = "modm/ext/lvgl"
80+
81+
env.copy("lvgl/lvgl.h")
82+
env.template("lv_conf.h.in")
83+
env.copy("lvgl/src")
84+
env.copy("lv_modm_clock.h")
85+
env.copy("lv_modm_clock.cpp")
86+
87+
if env.has_module(":debug"):
88+
env.copy("lv_modm_logging.cpp")

0 commit comments

Comments
 (0)