Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize LVGL #172

Merged
merged 19 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ Currently, IceNav works with the following hardware setups and specs
| Driver [^1] | Resolution | SPI | 8bit | 16bit | Touch | Build Flags [^2] |
|:------------|:----------:|:---:|:----:|:-----:|:---------:|:---------------------------------|
| ILI9488 [^3]| 320x480 | yes | --- | --- | XPT2046 | ```-D ILI9488_XPT2046_SPI = 1``` |
| ILI9488 | 320x480 | yes | --- | --- | FT5x06 | ```-D ILI9488_FT5x06_SPI = 1 ``` |
| ILI9488 | 320x480 | --- | --- | yes | FT5x06 | ```-D ILI9488_FT5x06_16B = 1``` |
| ILI9341 | 320x240 | yes | --- | --- | XPT2046 | ```-D ILI9341_XPT2046_SPI = 1``` |

If TFT shares SPI bus with SD card add the following Build Flag to platformio.ini

```-D SPI_SHARED = 1```

### Modules

| | Type | Build Flags [^2] | lib_deps [^4] (**no common environment**) |
Expand Down
17 changes: 6 additions & 11 deletions include/hal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@
*
*/
#ifdef ARDUINO_ESP32S3_DEV
#ifdef MAKERF_ESP32S3
#define I2C_SDA_PIN 38
#define I2C_SCL_PIN 39
#else
#define I2C_SDA_PIN 8
#define I2C_SCL_PIN 9
#endif
#define I2C_SDA_PIN 38
#define I2C_SCL_PIN 39
#endif

/**
Expand Down Expand Up @@ -115,10 +110,10 @@ extern const bool TFT_INVERT = true;
extern const uint8_t SD_MOSI = 2;
extern const uint8_t SD_CLK = 42;
#else
extern const uint8_t SD_CS = 1;
extern const uint8_t SD_MISO = 40;
extern const uint8_t SD_MOSI = 41;
extern const uint8_t SD_CLK = 39;
extern const uint8_t SD_CS = 21;
extern const uint8_t SD_MISO = 13;
extern const uint8_t SD_MOSI = 11;
extern const uint8_t SD_CLK = 12;
#endif
#endif

Expand Down
3 changes: 2 additions & 1 deletion lib/gui/src/buttonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool isOptionLoaded = false;

lv_obj_t *settingsScreen;
lv_obj_t *buttonBar;
lv_obj_t *menuBtn;

/**
* @brief Button events
Expand Down Expand Up @@ -195,7 +196,7 @@ void createButtonBarScr()
lv_obj_set_size(buttonBar, 50 * scaleBut, 50 * scaleBut);
lv_obj_align(buttonBar, LV_ALIGN_BOTTOM_RIGHT, 0, -LV_DPX(14) );

lv_obj_t *menuBtn = lv_img_create(mainScreen);
menuBtn = lv_img_create(mainScreen);
lv_img_set_src(menuBtn, menuIconFile);
lv_obj_add_flag(menuBtn, LV_OBJ_FLAG_FLOATING | LV_OBJ_FLAG_CLICKABLE);
lv_img_set_zoom(menuBtn,buttonScale);
Expand Down
4 changes: 1 addition & 3 deletions lib/gui/src/globalGuiDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ extern lv_obj_t *deviceSettingsScreen; // Device Settings Screen
extern bool needReboot; // Flag to force device reboot
extern bool isSearchingSat; // Flag to indicate that is searching satellites
extern lv_obj_t *buttonBar; // Button Bar

static lv_timer_t *mainTimer; // Main Screen Timer
#define UPDATE_MAINSCR_PERIOD 10 // Main Screen update time
extern lv_obj_t *menuBtn;

#ifdef LARGE_SCREEN
static const lv_font_t *fontDefault = &lv_font_montserrat_14;
Expand Down
154 changes: 56 additions & 98 deletions lib/gui/src/mainScr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
bool isMainScreen = false; // Flag to indicate main screen is selected
bool isScrolled = true; // Flag to indicate when tileview was scrolled
bool isReady = false; // Flag to indicate when tileview scroll was finished
bool redrawMap = false; // Flag to indicate when needs to redraw Map
bool redrawMap = true; // Flag to indicate when needs to redraw Map
uint8_t activeTile = 0; // Current active tile

lv_obj_t *compassHeading;
lv_obj_t *compassImg;
lv_obj_t *latitude;
lv_obj_t *longitude;
lv_obj_t *altitude;
lv_obj_t *speedLabel;
lv_obj_t *compassTile;
lv_obj_t *navTile;
lv_obj_t *mapTile;
lv_obj_t *satTrackTile;

/**
* @brief Update compass screen event
Expand Down Expand Up @@ -131,22 +143,22 @@ void getActTile(lv_event_t *event)
isScrolled = true;
log_d("Free PSRAM: %d", ESP.getFreePsram());
log_d("Used PSRAM: %d", ESP.getPsramSize() - ESP.getFreePsram());
// if (activeTile == MAP || activeTile == NAV)
if (activeTile == MAP)
{
createMapScrSprites();
isPosMoved = true;
redrawMap = true;
}

if (activeTile == SATTRACK)
{
createSatSprite(spriteSat);
createConstelSprite(constelSprite);
}
if (activeTile == MAP)
if (activeTile == MAP)
{
lv_obj_add_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
else
lv_obj_clear_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
}
else
{
lv_obj_clear_flag(buttonBar,LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(menuBtn,LV_OBJ_FLAG_HIDDEN);
}
}
else
{
Expand All @@ -167,72 +179,12 @@ void scrollTile(lv_event_t *event)
{
isScrolled = false;
isReady = false;
redrawMap = false;

deleteMapScrSprites();
//deleteMapScrSprites();
deleteSatInfoSprites();
}

/**
* @brief Update Main Screen
*
*/
void updateMainScreen(lv_timer_t *t)
{
if (isScrolled && isMainScreen)
{
switch (activeTile)
{
case COMPASS:
#ifdef ENABLE_COMPASS
if (!waitScreenRefresh)
heading = getHeading();
#endif
lv_obj_send_event(compassHeading, LV_EVENT_VALUE_CHANGED, NULL);


if(GPS.location.isValid())
{
lv_obj_send_event(latitude, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_send_event(longitude, LV_EVENT_VALUE_CHANGED, NULL);
}
if (GPS.altitude.isValid())
{
lv_obj_send_event(altitude, LV_EVENT_VALUE_CHANGED, NULL);
}

if (GPS.speed.isValid())
lv_obj_send_event(speedLabel, LV_EVENT_VALUE_CHANGED, NULL);
break;

case MAP:
// if (GPS.location.isUpdated())
#ifdef ENABLE_COMPASS
if (!waitScreenRefresh)
heading = getHeading();
#endif
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
break;

//case NAV:
// mapTempSprite.fillScreen(TFT_BLACK);
// mapTempSprite.drawPngFile(SPIFFS, "/TODO.png", (MAP_WIDTH / 2) - 50, (MAP_HEIGHT / 2) - 50);
// mapTempSprite.drawCenterString("NAVIGATION SCREEN", (MAP_WIDTH / 2), (MAP_HEIGHT >> 1) + 65, &fonts::DejaVu18);
// mapSprite.pushSprite(0, 27);
// mapTempSprite.pushSprite(&mapSprite, 0, 0, TFT_TRANSPARENT);
// break;

case SATTRACK:
constelSprite.pushSprite(150 * scale, 40 * scale);
lv_obj_send_event(satTrackTile, LV_EVENT_VALUE_CHANGED, NULL);
break;


default:
break;
}
}
}

/**
* @brief Update zoom value
*
Expand Down Expand Up @@ -297,35 +249,41 @@ void getZoomValue(lv_event_t *event)
*/
void updateMap(lv_event_t *event)
{
if (!waitScreenRefresh)
if (isVectorMap)
{
if (tft.getStartCount() == 0)
tft.startWrite();

if (isVectorMap)
{
getPosition(getLat(), getLon());

if (isPosMoved)
{
tileSize = VECTOR_TILE_SIZE;
viewPort.setCenter(point);
getMapBlocks(viewPort.bbox, memCache);
generateVectorMap(viewPort, memCache, mapTempSprite);
isPosMoved = false;
}
}
else
getPosition(getLat(), getLon());
if (isPosMoved)
{
tileSize = RENDER_TILE_SIZE;
generateRenderMap();
}
tileSize = VECTOR_TILE_SIZE;
viewPort.setCenter(point);

displayMap(tileSize);
#ifdef SPI_SHARED
tft.waitDisplay();
tft.endTransaction();
tft.releaseBus();
initSD();
#endif

getMapBlocks(viewPort.bbox, memCache);

#ifdef SPI_SHARED
SD.end();
tft.initBus();
#endif

if (tft.getStartCount() > 0)
tft.endWrite();
deleteMapScrSprites();
createMapScrSprites();
generateVectorMap(viewPort, memCache, mapTempSprite);

isPosMoved = false;
}
}
else
{
tileSize = RENDER_TILE_SIZE;
generateRenderMap();
}
displayMap(tileSize);
}

/**
Expand Down Expand Up @@ -531,7 +489,7 @@ void createMainScr()
// Map Tile

// Map Tile Events
lv_obj_add_event_cb(mapTile, updateMap, LV_EVENT_REFRESH, NULL);
lv_obj_add_event_cb(mapTile, updateMap, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(mainScreen, getZoomValue, LV_EVENT_GESTURE, NULL);

// Navigation Tile
Expand Down
26 changes: 11 additions & 15 deletions lib/gui/src/mainScr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "renderMaps.hpp"
#include "vectorMaps.hpp"

//extern lv_timer_t *mainTimer; // Main Screen Timer
//#define UPDATE_MAINSCR_PERIOD 30 // Main Screen update time

extern bool isMainScreen; // Flag to indicate main screen is selected
extern bool isReady; // Flag to indicate when tileview scroll was finished
static TFT_eSprite zoomSprite = TFT_eSprite(&tft); // Zoom sprite
Expand All @@ -32,7 +29,7 @@ static const char *positionIconFile PROGMEM = "F:/pin.bin"; // Position Icon
static const char *altitudeIconFile PROGMEM = "F:/altit.bin"; // Altitude Icon
static const char *speedIconFile PROGMEM = "F:/speed.bin"; // Speed Icon

static uint8_t activeTile = 0; // Active Tile in TileView control
extern uint8_t activeTile; // Active Tile in TileView control
enum tileName
{
COMPASS,
Expand All @@ -48,21 +45,21 @@ static bool canMoveWidget = false;
* @brief Main Screen Tiles
*
*/
static lv_obj_t *compassTile;
static lv_obj_t *navTile;
static lv_obj_t *mapTile;
static lv_obj_t *satTrackTile;
extern lv_obj_t *compassTile;
extern lv_obj_t *navTile;
extern lv_obj_t *mapTile;
extern lv_obj_t *satTrackTile;

/**
* @brief Compass Tile screen objects
*
*/
static lv_obj_t *compassHeading;
static lv_obj_t *compassImg;
static lv_obj_t *latitude;
static lv_obj_t *longitude;
static lv_obj_t *altitude;
static lv_obj_t *speedLabel;
extern lv_obj_t *compassHeading;
extern lv_obj_t *compassImg;
extern lv_obj_t *latitude;
extern lv_obj_t *longitude;
extern lv_obj_t *altitude;
extern lv_obj_t *speedLabel;

/**
* @brief Satellite Tracking Tile screen objects
Expand All @@ -86,7 +83,6 @@ void createMapScrSprites();

void getActTile(lv_event_t *event);
void scrollTile(lv_event_t *event);
void updateMainScreen(lv_timer_t *t);

void generateRenderMap();
void generateVectorMap();
Expand Down
8 changes: 4 additions & 4 deletions lib/lvgl/lvgl_ESP32S3_N16R8_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@

/*1: Show CPU usage and FPS count
* Requires `LV_USE_SYSMON = 1`*/
#define LV_USE_PERF_MONITOR 0
#define LV_USE_PERF_MONITOR 1
#if LV_USE_PERF_MONITOR
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_RIGHT

/*0: Displays performance data on the screen, 1: Prints performance data using log.*/
#define LV_USE_PERF_MONITOR_LOG_MODE 0
Expand All @@ -758,9 +758,9 @@
/*1: Show the used memory and the memory fragmentation
* Requires `LV_USE_BUILTIN_MALLOC = 1`
* Requires `LV_USE_SYSMON = 1`*/
#define LV_USE_MEM_MONITOR 0
#define LV_USE_MEM_MONITOR 1
#if LV_USE_MEM_MONITOR
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_LEFT
#endif

#endif /*LV_USE_SYSMON*/
Expand Down
8 changes: 4 additions & 4 deletions lib/lvgl/lvgl_ESP32_N16R4_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@

/*1: Show CPU usage and FPS count
* Requires `LV_USE_SYSMON = 1`*/
#define LV_USE_PERF_MONITOR 0
#define LV_USE_PERF_MONITOR 1
#if LV_USE_PERF_MONITOR
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_RIGHT

/*0: Displays performance data on the screen, 1: Prints performance data using log.*/
#define LV_USE_PERF_MONITOR_LOG_MODE 0
Expand All @@ -758,9 +758,9 @@
/*1: Show the used memory and the memory fragmentation
* Requires `LV_USE_BUILTIN_MALLOC = 1`
* Requires `LV_USE_SYSMON = 1`*/
#define LV_USE_MEM_MONITOR 0
#define LV_USE_MEM_MONITOR 1
#if LV_USE_MEM_MONITOR
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_LEFT
#endif

#endif /*LV_USE_SYSMON*/
Expand Down
Loading
Loading