Skip to content

Commit

Permalink
Use Lvgl built-in memory allocation.
Browse files Browse the repository at this point in the history
Reduce startup time by removing unnecessary calls.
Compile Lvgl code with -O3 optimisation.
  • Loading branch information
philmoz committed May 27, 2024
1 parent 4e6d8ba commit 8efa3f8
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MAIN_STACK_SIZE = 8192;
BOOTLOADER_SIZE = 0x20000;

/* Minimum Heap Size (indicative) */
MIN_HEAP_SIZE = 4096K;
MIN_HEAP_SIZE = 0;

/* SDRAM definitions */
SDRAM_START = DEFINED(__sdram_start) ? __sdram_start : 0xD0000000;
Expand Down
14 changes: 10 additions & 4 deletions radio/src/gui/colorlcd/LvglWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,19 @@ static void init_lvgl_drivers()

void initLvglTheme()
{
static lv_theme_t theme;

/* Initialize the ETX theme */
lv_theme_t* th = etx_lv_theme_init(
NULL, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
LV_FONT_DEFAULT);
theme.disp = NULL;
theme.color_primary = lv_palette_main(LV_PALETTE_BLUE);
theme.color_secondary = lv_palette_main(LV_PALETTE_RED);
theme.font_small = LV_FONT_DEFAULT;
theme.font_normal = LV_FONT_DEFAULT;
theme.font_large = LV_FONT_DEFAULT;
theme.flags = 0;

/* Assign the theme to the current display*/
lv_disp_set_theme(NULL, th);
lv_disp_set_theme(NULL, &theme);
}

LvglWrapper::LvglWrapper()
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/hw_bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ BluetoothConfigWindow::BluetoothConfigWindow(Window* parent, FlexGridLayout& gri
lv_obj_set_style_grid_cell_x_align(box->getLvObj(), LV_GRID_ALIGN_STRETCH, 0);
lv_obj_set_style_flex_cross_place(box->getLvObj(), LV_FLEX_ALIGN_CENTER, 0);

auto mode = new Choice(
new Choice(
box, rect_t{}, STR_BLUETOOTH_MODES, BLUETOOTH_OFF, BLUETOOTH_TRAINER,
GET_DEFAULT(g_eeGeneral.bluetoothMode), [=](int value) {
g_eeGeneral.bluetoothMode = value;
Expand Down
4 changes: 4 additions & 0 deletions radio/src/gui/colorlcd/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bitmapbuffer.h"
#include "board.h"
#include "dma2d.h"
#include "themes/etx_lv_theme.h"

pixel_t LCD_FIRST_FRAME_BUFFER[DISPLAY_BUFFER_SIZE] __SDRAM;
pixel_t LCD_SECOND_FRAME_BUFFER[DISPLAY_BUFFER_SIZE] __SDRAM;
Expand Down Expand Up @@ -141,6 +142,9 @@ void lcdInitDisplayDriver()
if (disp != nullptr) return;

lv_init();
#if !defined(BOOT)
useMainStyle();
#endif

// Clear buffers first
memset(LCD_FIRST_FRAME_BUFFER, 0, sizeof(LCD_FIRST_FRAME_BUFFER));
Expand Down
5 changes: 2 additions & 3 deletions radio/src/gui/colorlcd/startup_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ void cancelSplash()
splashScreen->deleteLater();
splashScreen = nullptr;
MainWindow::instance()->setActiveScreen();
lv_refr_now(nullptr);
splashStartTime = 0;
}
}
Expand All @@ -148,7 +147,7 @@ void waitSplash()
#endif // defined(SIMU)

splashStartTime += SPLASH_TIMEOUT;
do {
while (splashStartTime >= get_tmr10ms()) {
LvglWrapper::instance()->run();
MainWindow::instance()->run();
WDG_RESET();
Expand All @@ -167,7 +166,7 @@ void waitSplash()
break;
}
#endif // defined(SIMU)
} while (splashStartTime >= get_tmr10ms());
}

// Reset timer so special/global functions set to !1x don't get triggered
START_SILENCE_PERIOD();
Expand Down
44 changes: 17 additions & 27 deletions radio/src/gui/colorlcd/themes/etx_lv_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

extern lv_color_t makeLvColor(uint32_t colorFlags);

static lv_theme_t theme;

/**********************
* Constant Styles
**********************/
Expand Down Expand Up @@ -349,41 +347,33 @@ void EdgeTxStyles::applyColors()
lv_style_set_arc_color(&arc_color, makeLvColor(COLOR_THEME_SECONDARY1));
}

static EdgeTxStyles mainStyles;
static EdgeTxStyles* previewStyles;
EdgeTxStyles* styles = &mainStyles;
static EdgeTxStyles *mainStyles = nullptr;
static EdgeTxStyles* previewStyles = nullptr;
EdgeTxStyles* styles = nullptr;

/**********************
* GLOBAL FUNCTIONS
**********************/

lv_theme_t* etx_lv_theme_init(lv_disp_t* disp, lv_color_t color_primary,
lv_color_t color_secondary, const lv_font_t* font)
{
theme.disp = disp;
theme.color_primary = color_primary;
theme.color_secondary = color_secondary;
theme.font_small = font;
theme.font_normal = font;
theme.font_large = font;
theme.flags = 0;

styles->init();

if (disp == NULL || lv_disp_get_theme(disp) == &theme)
lv_obj_report_style_change(NULL);

return (lv_theme_t*)&theme;
}

void usePreviewStyle()
{
if (!previewStyles) previewStyles = new EdgeTxStyles();
if (!previewStyles) {
previewStyles = new EdgeTxStyles();
previewStyles->init();
}
styles = previewStyles;
styles->init();
styles->applyColors();
}

void useMainStyle() { styles = &mainStyles; }
void useMainStyle()
{
if (!mainStyles) {
mainStyles = new EdgeTxStyles();
mainStyles->init();
}
styles = mainStyles;
styles->applyColors();
}

/**********************
* Custom object creation
Expand Down
11 changes: 0 additions & 11 deletions radio/src/gui/colorlcd/themes/etx_lv_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ enum PaddingSize {
* GLOBAL PROTOTYPES
**********************/

/**
* Initialize the theme
* @param color_primary the primary color of the theme
* @param color_secondary the secondary color for the theme
* @param font pointer to a font to use.
* @return a pointer to reference this theme later
*/
lv_theme_t* etx_lv_theme_init(lv_disp_t* disp, lv_color_t color_primary,
lv_color_t color_secondary,
const lv_font_t* font);

void usePreviewStyle();
void useMainStyle();

Expand Down
10 changes: 7 additions & 3 deletions radio/src/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@
*=========================*/

/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#if defined(BOOT)
#define LV_MEM_CUSTOM 1
#else
#define LV_MEM_CUSTOM 0
#endif
#if LV_MEM_CUSTOM == 0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/
#define LV_MEM_SIZE (1024U * 1024U) /*[bytes]*/

/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
#define LV_MEM_ADR 0 /*0: unused*/
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
#if LV_MEM_ADR == 0
//#define LV_MEM_POOL_INCLUDE your_alloc_library /* Uncomment if using an external allocator*/
//#define LV_MEM_POOL_ALLOC your_alloc /* Uncomment if using an external allocator*/
#undef LV_MEM_POOL_INCLUDE
#undef LV_MEM_POOL_ALLOC
extern void *sbrk(int size);
#define LV_MEM_POOL_ALLOC sbrk
#endif

#else /*LV_MEM_CUSTOM*/
Expand Down
4 changes: 4 additions & 0 deletions radio/src/thirdparty/libopenui/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,9 @@ endforeach()
foreach(LVGL_FILE ${LVGL_SOURCES})
set(LVGL_SRC_FILES ${LVGL_SRC_FILES} ${LVGL_SRC_DIR}/${LVGL_FILE})
endforeach()

foreach(LVGL_FILE ${LVGL_SRC_FILES})
SET_SOURCE_FILES_PROPERTIES( ${LVGL_FILE} PROPERTIES COMPILE_FLAGS -O3 )
endforeach()

set(SRC ${SRC} ${LVGL_SRC_FILES})

0 comments on commit 8efa3f8

Please sign in to comment.