Remove legacy fonts and make the bootloader compile with LVGL

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 0404919667
commit ee0c37157d
74 changed files with 2027 additions and 775 deletions
+7 -68
View File
@@ -26,8 +26,6 @@
LvglWrapper* LvglWrapper::_instance = nullptr;
static lv_disp_t* disp;
static lv_disp_draw_buf_t disp_buf;
static lv_indev_drv_t touchDriver;
static lv_indev_drv_t keyboard_drv;
static lv_indev_drv_t rotaryDriver;
@@ -50,38 +48,6 @@ TouchState getLastTochState()
}
#endif
void newLcdRefresh(uint16_t* buffer, const rect_t& copy_area);
static void flushLcd(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
lv_area_t refr_area;
lv_area_copy(&refr_area, area);
#if defined(LCD_VERTICAL_INVERT)
lv_coord_t tmp_coord;
tmp_coord = refr_area.y2;
refr_area.y2 = LCD_H - refr_area.y1 - 1;
refr_area.y1 = LCD_H - tmp_coord - 1;
tmp_coord = refr_area.x2;
refr_area.x2 = LCD_W - refr_area.x1 - 1;
refr_area.x1 = LCD_W - tmp_coord - 1;
#endif
if (refr_area.x1 != 0 || refr_area.x2 != 479 || refr_area.y1 != 0 ||
refr_area.y2 != 271) {
TRACE("partial refresh @ 0x%p {%d,%d,%d,%d}", color_p, refr_area.x1,
refr_area.y1, refr_area.x2, refr_area.y2);
} else {
TRACE("full refresh @ 0x%p", color_p);
}
rect_t copy_area = {refr_area.x1, refr_area.y1,
refr_area.x2 - refr_area.x1 + 1,
refr_area.y2 - refr_area.y1 + 1};
newLcdRefresh((uint16_t*)color_p, copy_area);
lv_disp_flush_ready(disp_drv);
}
extern "C" void keyboardDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
// if there is a keyboard event then call checkevents
@@ -197,41 +163,15 @@ lv_color_t makeLvColor(uint32_t colorFlags)
return lv_color_make(GET_RED(color), GET_GREEN(color), GET_BLUE(color));
}
extern BitmapBuffer * lcdFront;
extern BitmapBuffer * lcd;
static lv_disp_drv_t disp_drv;
void init_disp_drv()
{
lv_disp_draw_buf_init(&disp_buf, lcdFront->getData(), lcd->getData(), LCD_W*LCD_H);
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
disp_drv.flush_cb = flushLcd; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = LCD_PHYS_W; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = LCD_PHYS_H; /*Set the vertical resolution in pixels*/
disp_drv.full_refresh = 0;
disp_drv.direct_mode = 0;
#if defined (LCD_VERTICAL_INVERT)
disp_drv.rotated = LV_DISP_ROT_180;
#endif
// disp_drv.rotated = LV_DISP_ROT_90;
disp_drv.sw_rotate = 1;
// Register the driver and save the created display objects
disp = lv_disp_drv_register(&disp_drv);
}
static void init_lvgl_drivers()
{
// Register the driver and save the created display object
lcdInitDisplayDriver();
// add all lvgl object automatically to a input handling group
inputGroup = lv_group_create();
lv_group_set_default(inputGroup);
// Register the driver and save the created display objects
init_disp_drv();
// Register the driver in LVGL and save the created input device object
lv_indev_drv_init(&touchDriver); /*Basic initialization*/
touchDriver.type = LV_INDEV_TYPE_POINTER; /*See below.*/
@@ -341,7 +281,6 @@ static void init_theme()
LvglWrapper::LvglWrapper()
{
lv_init();
init_lvgl_drivers();
init_theme();
@@ -352,8 +291,8 @@ LvglWrapper::LvglWrapper()
void LvglWrapper::run()
{
tmr10ms_t tick = get_tmr10ms();
lv_tick_inc((tick - lastTick) * 10);
lastTick = tick;
lv_timer_handler();
tmr10ms_t tick = get_tmr10ms();
lv_tick_inc((tick - lastTick) * 10);
lastTick = tick;
lv_timer_handler();
}
+4 -3
View File
@@ -19,19 +19,20 @@
* GNU General Public License for more details.
*/
#include "opentx.h"
#include "libopenui_config.h"
#include "font.h"
#if !defined(BOOT)
static const lv_font_t* lvglFontTable[FONTS_COUNT] = {
LV_FONT_DEFAULT, // FONT_STD_INDEX
#if !defined(BOOT)
&lv_font_roboto_bold_16, // FONT_BOLD_INDEX
&lv_font_roboto_9, // FONT_XXS_INDEX
&lv_font_roboto_13, // FONT_XS_INDEX
&lv_font_roboto_24, // FONT_L_INDEX
&lv_font_roboto_bold_32, // FONT_XL_INDEX
&lv_font_roboto_bold_64, // FONT_XXL_INDEX
#endif
};
#endif
const lv_font_t* getFont(LcdFlags flags)
{
+99 -3
View File
@@ -20,13 +20,109 @@
*/
#include "lcd.h"
#include "opentx.h"
#include <lvgl/lvgl.h>
void lcdSetContrast()
extern BitmapBuffer * lcdFront;
extern BitmapBuffer * lcd;
static lv_disp_draw_buf_t disp_buf;
static lv_disp_drv_t disp_drv;
static lv_disp_t* disp = nullptr;
static lv_area_t screen_area = {
0, 0, LCD_W-1, LCD_H-1
};
void newLcdRefresh(uint16_t* buffer, const rect_t& copy_area);
static void flushLcd(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
lcdSetRefVolt(g_eeGeneral.contrast);
lv_area_t refr_area;
lv_area_copy(&refr_area, area);
#if defined(LCD_VERTICAL_INVERT)
lv_coord_t tmp_coord;
tmp_coord = refr_area.y2;
refr_area.y2 = LCD_H - refr_area.y1 - 1;
refr_area.y1 = LCD_H - tmp_coord - 1;
tmp_coord = refr_area.x2;
refr_area.x2 = LCD_W - refr_area.x1 - 1;
refr_area.x1 = LCD_W - tmp_coord - 1;
#endif
if (refr_area.x1 != 0 || refr_area.x2 != LCD_W-1 || refr_area.y1 != 0 ||
refr_area.y2 != LCD_H-1) {
TRACE("partial refresh @ 0x%p {%d,%d,%d,%d}", color_p, refr_area.x1,
refr_area.y1, refr_area.x2, refr_area.y2);
} else {
TRACE("full refresh @ 0x%p", color_p);
}
rect_t copy_area = {refr_area.x1, refr_area.y1,
refr_area.x2 - refr_area.x1 + 1,
refr_area.y2 - refr_area.y1 + 1};
newLcdRefresh((uint16_t*)color_p, copy_area);
lv_disp_flush_ready(disp_drv);
}
void lcdInitDisplayDriver()
{
lv_init();
lv_disp_draw_buf_init(&disp_buf, lcdFront->getData(), lcd->getData(), LCD_W*LCD_H);
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
disp_drv.flush_cb = flushLcd; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = LCD_W; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = LCD_H; /*Set the vertical resolution in pixels*/
disp_drv.full_refresh = 0;
disp_drv.direct_mode = 0;
#if defined (LCD_VERTICAL_INVERT)
disp_drv.rotated = LV_DISP_ROT_180;
#endif
disp_drv.sw_rotate = 1;
// Register the driver and save the created display object
disp = lv_disp_drv_register(&disp_drv);
// remove all styles on default screen (makes it transparent as well)
lv_obj_remove_style_all(lv_scr_act());
// transparent background:
// - this prevents LVGL overwritting things drawn directly into the bitmap buffer
lv_disp_set_bg_opa(disp, LV_OPA_TRANSP);
// allow drawing at any moment
_lv_refr_set_disp_refreshing(disp);
lv_draw_ctx_t * draw_ctx = disp->driver->draw_ctx;
lcd->setDrawCtx(draw_ctx);
lcdFront->setDrawCtx(draw_ctx);
}
void lcdInitDirectDrawing()
{
lv_draw_ctx_t* draw_ctx = disp->driver->draw_ctx;
draw_ctx->buf = disp->driver->draw_buf->buf_act;
draw_ctx->buf_area = &screen_area;
draw_ctx->clip_area = &screen_area;
lcd->setData((pixel_t*)draw_ctx->buf);
}
void lcdRefresh()
{
_lv_inv_area(nullptr, &screen_area);
lv_refr_now(nullptr);
}
void lcdFlushed()
{
lv_disp_t* disp = _lv_refr_get_disp_refreshing();
lv_disp_flush_ready(disp->driver);
}
//TODO: move this somewhere else
event_t getWindowEvent()
{
return getEvent(false);
+11 -17
View File
@@ -25,28 +25,11 @@
#include "bitmapbuffer.h"
#include "opentx_types.h"
#if LCD_W >= 480
#define LCD_COLS 40
#else
#define LCD_COLS 30
#endif
#define CENTER
#include "colors.h"
#define DISPLAY_PIXELS_COUNT (LCD_W * LCD_H)
#define DISPLAY_BUFFER_SIZE (DISPLAY_PIXELS_COUNT)
extern coord_t lcdNextPos;
inline void lcdClear()
{
lcd->clear();
}
void lcdDrawBlackOverlay();
#if defined(BOOT)
#define BLINK_ON_PHASE (0)
#else
@@ -55,4 +38,15 @@ void lcdDrawBlackOverlay();
#define SLOW_BLINK_ON_PHASE (g_blinkTmr10ms & (1<<7))
#endif
// Init LVGL and its display driver
void lcdInitDisplayDriver();
// Patch the draw context to allow for direct drawing
void lcdInitDirectDrawing();
inline void lcdClear() { lcd->clear(); }
void lcdRefresh();
void lcdFlushed();
#endif // _LCD_H_
+3 -37
View File
@@ -19,9 +19,9 @@
* GNU General Public License for more details.
*/
#ifndef _LIBOPENUI_H_
#define _LIBOPENUI_H_
#pragma once
#if !defined(BOOT)
#include "libopenui_config.h"
#include "libopenui_file.h"
#include "font.h"
@@ -58,38 +58,4 @@
#include "draw_functions.h"
#include "textedits.h"
#include "LvglWrapper.h"
inline MessageDialog * createPopupInformation(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Message", message);
}
inline MessageDialog * createPopupWarning(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Warning", message);
}
inline void POPUP_INFORMATION(const char * message)
{
auto popup = createPopupInformation(message);
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
inline void POPUP_WARNING(const char * message, const char * info = nullptr)
{
auto popup = createPopupWarning(message);
if (info) {
popup->setInfoText(std::string(info));
}
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
#endif // _LIBOPENUI_H_
#endif
+34
View File
@@ -22,8 +22,42 @@
#ifndef _POPUPS_H_
#define _POPUPS_H_
#include "libopenui.h"
#include <functional>
typedef std::function<void(const char *, const char *, int, int)> ProgressHandler;
inline MessageDialog * createPopupInformation(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Message", message);
}
inline MessageDialog * createPopupWarning(const char * message)
{
return new MessageDialog(MainWindow::instance(), "Warning", message);
}
inline void POPUP_INFORMATION(const char * message)
{
auto popup = createPopupInformation(message);
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
inline void POPUP_WARNING(const char * message, const char * info = nullptr)
{
auto popup = createPopupWarning(message);
if (info) {
popup->setInfoText(std::string(info));
}
while (popup->getParent()) {
WDG_RESET();
MainWindow::instance()->run(false);
LvglWrapper::instance()->run();
}
}
#endif // _POPUPS_H_
+2
View File
@@ -23,6 +23,8 @@
#include "opentx.h"
#include "options.h"
#include "libopenui.h"
#include "fw_version.h"
#if defined(CROSSFIRE)
#include "mixer_scheduler.h"
#endif
-7
View File
@@ -55,13 +55,6 @@ void ViewTextWindow::extractNameSansExt()
openFromEnd = !strcmp(ext, LOGS_EXT);
}
void ViewTextWindow::buildBody(Window *window)
{
GridLayout grid(window);
grid.spacer();
int i;
FIL file;
// assume average characte is 10 pixels wide, round the string length to tens.
// Font is not fixed width, so this is for the worst case...
maxLineLength = static_cast<int>(window->width() / 10 / 10) * 10 - 2;
+1
View File
@@ -69,6 +69,7 @@ class ViewTextWindow : public Page
Page::paint(dc);
drawVerticalScrollbar(dc);
}
void checkEvents() override;
#if defined(DEBUG_WINDOWS)
+2
View File
@@ -33,9 +33,11 @@
#define HIDDEN_ROW ((uint8_t)-2)
#if defined(ROTARY_ENCODER_NAVIGATION)
#define CASE_ROTARY_ENCODER(x) x,
#define CASE_EVT_ROTARY_LEFT case EVT_ROTARY_LEFT:
#define CASE_EVT_ROTARY_RIGHT case EVT_ROTARY_RIGHT:
#else
#define CASE_ROTARY_ENCODER(x)
#define CASE_EVT_ROTARY_LEFT
#define CASE_EVT_ROTARY_RIGHT
#endif