Skip to content

Commit

Permalink
[ext] Update LVGL to v9.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Oct 5, 2024
1 parent 303ace2 commit 580d93f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 106 deletions.
66 changes: 24 additions & 42 deletions examples/stm32f469_discovery/lvgl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,29 @@ using namespace Board::ft6;
using namespace modm::literals;


static uint16_t* displayBuffer;
static lv_disp_draw_buf_t disp_buf;
static lv_color_t* buf;
static constexpr size_t buf_size = LV_HOR_RES_MAX * LV_VER_RES_MAX;

Touch::Data touchData;
Touch touch{touchData, TouchAddress};

void my_touchpad_read(lv_indev_drv_t*, lv_indev_data_t* data)
void my_touchpad_read(lv_indev_t*, lv_indev_data_t* data)
{
RF_CALL_BLOCKING(touch.readTouches());
Touch::touch_t tp;
touch.getData().getTouch(&tp, 0);
// mirror and rotate correctly
uint16_t x{tp.y}, y{uint16_t(480 - tp.x)};
data->state = (tp.event == Touch::Event::Contact) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
if(data->state == LV_INDEV_STATE_PR) {
if (tp.event == Touch::Event::Contact)
{
data->state = LV_INDEV_STATE_PRESSED;
data->point.x = x;
data->point.y = y;
}
else data->state = LV_INDEV_STATE_RELEASED;
}

void my_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
void disp_flush(lv_display_t* disp, const lv_area_t*, uint8_t* px_map)
{
for(lv_coord_t y = area->y1; y <= area->y2; y++) {
std::memcpy(
&displayBuffer[(800*y) + area->x1],
&color_p[(y - area->y1) * (area->x2 - area->x1 + 1)],
(area->x2 - area->x1 + 1) * sizeof(lv_color_t)
);
}
lv_disp_flush_ready(disp_drv);
setDisplayBuffer((uint16_t*) px_map);
lv_display_flush_ready(disp);
}


Expand All @@ -74,45 +65,36 @@ main()

lv_init();

buf = new(modm::MemoryExternal) lv_color_t[buf_size];
displayBuffer = new(modm::MemoryExternal) uint16_t[buf_size];

setDisplayBuffer(displayBuffer);

// Initialize the display buffer
lv_disp_draw_buf_init(&disp_buf, buf, NULL, buf_size);

// Initialize the display:
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = my_flush_cb;
disp_drv.hor_res = LV_HOR_RES_MAX;
disp_drv.ver_res = LV_VER_RES_MAX;
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
lv_display_t *disp = lv_display_create(LV_HOR_RES_MAX, LV_VER_RES_MAX);
lv_display_set_flush_cb(disp, disp_flush);

// Initialize touchscreen driver:
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
static constexpr size_t BufSize = LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof(lv_color_t);
auto buf_1 = new(modm::MemoryExternal) uint8_t[BufSize];
auto buf_2 = new(modm::MemoryExternal) uint8_t[BufSize];
lv_display_set_buffers(disp, buf_1, buf_2, sizeof(buf_1), LV_DISPLAY_RENDER_MODE_DIRECT);

lv_obj_t* scr = lv_disp_get_scr_act(disp); // Get the current screen
// Initialize touchscreen driver:
lv_indev_t* indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);

lv_obj_t* labelA = lv_label_create(scr);
lv_obj_t *labelA = lv_label_create(lv_screen_active());
lv_label_set_text(labelA, "Hello world!");
lv_obj_set_pos(labelA, 10, 10);
lv_obj_set_size(labelA, 120, 50);

lv_obj_t* btn2 = lv_btn_create(lv_scr_act());
lv_obj_t* btn2 = lv_button_create(lv_screen_active());
lv_obj_set_pos(btn2, 140, 10);
lv_obj_set_size(btn2, 120, 50);

lv_obj_t* label2 = lv_label_create(btn2);
lv_label_set_text(label2, "Button2");

lv_obj_add_event_cb(btn2, [](lv_event_t *event) {
static uint16_t btn2Counter = 0;
lv_label_set_text_fmt(lv_obj_get_child(event->target, 0), "Button 2: %d", ++btn2Counter);
lv_label_set_text_fmt((lv_obj_t*) lv_event_get_user_data(event),
"Button 2: %d", ++btn2Counter);
}, LV_EVENT_PRESSED, NULL);

uint16_t counter = 0;
Expand Down
39 changes: 4 additions & 35 deletions ext/lvgl/lv_conf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,17 @@
#ifndef LV_CONF_H
#define LV_CONF_H

#include <stdint.h>

/* A header file that overwrites with local project settings. */
#if __has_include(<lv_conf_local.h>)
# include <lv_conf_local.h>
#endif

/*====================
Graphical settings
*====================*/

/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;

/*=========================
Memory manager settings
STDLIB WRAPPER SETTINGS
*=========================*/

/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#define LV_MEM_CUSTOM 1

/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/
#define LV_MEMCPY_MEMSET_STD 1

/*===================
* HAL settings
*==================*/

/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#define LV_TICK_CUSTOM 1
/*Header for the system time function*/
#define LV_TICK_CUSTOM_INCLUDE <lv_modm_clock.h>
/*Expression evaluating to current system time in ms*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (lv_modm_clock_now())

/*================
* Log settings
*===============*/

/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print_cb`*/
#define LV_LOG_PRINTF 0
#define LV_USE_STDLIB_MALLOC LV_STDLIB_CLIB
#define LV_USE_STDLIB_STRING LV_STDLIB_CLIB
#define LV_USE_STDLIB_SPRINTF LV_STDLIB_CLIB

#endif /*LV_CONF_H*/
7 changes: 4 additions & 3 deletions ext/lvgl/lv_modm_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "lv_modm_clock.h"
#include <lvgl/lvgl.h>
#include <modm/architecture/interface/clock.hpp>

uint32_t lv_modm_clock_now()
__attribute__((constructor))
static void lv_register_clock()
{
return modm::Clock::now().time_since_epoch().count();
lv_tick_set_cb([]{ return modm::Clock::now().time_since_epoch().count(); });
}
20 changes: 0 additions & 20 deletions ext/lvgl/lv_modm_clock.h

This file was deleted.

5 changes: 4 additions & 1 deletion ext/lvgl/lv_modm_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ __attribute__((constructor))
static void lv_register_modm_logging()
{
// register modm logging callback with LVGL
lv_log_register_print_cb([](const char *buffer) { MODM_LOG_INFO << buffer; });
lv_log_register_print_cb([](lv_log_level_t, const char *buffer)
{
MODM_LOG_INFO << buffer;
});
}
#endif
2 changes: 1 addition & 1 deletion ext/lvgl/lvgl
Submodule lvgl updated 942 files
7 changes: 3 additions & 4 deletions ext/lvgl/lvgl.lb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ the [configuration template][conf_template].
This module generates a `lv_conf.h` file to define the options necessary for
integration with modm which are:
- `LV_MEM_CUSTOM = 1`: Heap is provided by the `modm:platform:heap` module.
- `LV_TICK_CUSTOM = 1`: Tick is implemented via the `modm:platform:clock` module.
- Heap is provided by the `modm:platform:heap` module.
- Tick is implemented via the `modm:platform:clock` module.
- `LV_LOG_PRINTF = 0`: logging is redirected to `MODM_LOG_*` if the
`modm:debug` module is included and `LV_USE_LOG = 1`.
- `typedef int16_t lv_coord_t;`: Hardcoded choice for now.
To add your own configuration you can create a `<lv_conf_local.h>` file which
will automatically be included at the *beginning* of our `lv_conf.h`.
Expand Down Expand Up @@ -79,9 +78,9 @@ def build(env):
env.outbasepath = "modm/ext/lvgl"

env.copy("lvgl/lvgl.h")
env.copy("lvgl/lv_version.h")
env.template("lv_conf.h.in")
env.copy("lvgl/src")
env.copy("lv_modm_clock.h")
env.copy("lv_modm_clock.cpp")

if env.has_module(":debug"):
Expand Down

0 comments on commit 580d93f

Please sign in to comment.