Implement LVGL with SDL for simulator (#16)

* Implemented LVGL with SDL for simulator

* cleanup

* added SDL to build

* build fix

* mutex fixes

* sim app cleanup and improvements

* docs updated

* fix for sdl?

* fix for SDL cmake setup
This commit is contained in:
Ken Van Hoeylandt
2024-01-21 22:27:00 +01:00
committed by GitHub
parent 18a5c5aa45
commit d6baf40d0b
118 changed files with 15327 additions and 1181 deletions
@@ -12,7 +12,7 @@ extern "C" {
typedef struct {
PubSubSubscription* wifi_subscription;
Mutex* mutex;
Mutex mutex;
WifiConnectState state;
WifiConnectView view;
bool view_enabled;
@@ -10,7 +10,7 @@ extern "C" {
typedef struct {
PubSubSubscription* wifi_subscription;
Mutex* mutex;
Mutex mutex;
WifiManageState state;
WifiManageView view;
bool view_enabled;
+2 -2
View File
@@ -1,8 +1,8 @@
#include "check.h"
#include "display.h"
DisplayDevice _Nonnull* tt_display_device_alloc(DisplayDriver _Nonnull* driver) {
DisplayDevice _Nonnull* display = malloc(sizeof(DisplayDevice));
DisplayDevice* tt_display_device_alloc(DisplayDriver* driver) {
DisplayDevice* display = malloc(sizeof(DisplayDevice));
memset(display, 0, sizeof(DisplayDevice));
tt_check(driver->create_display_device(display), "failed to create display");
tt_check(display->io_handle != NULL);
+3 -3
View File
@@ -7,8 +7,8 @@ extern "C" {
#endif
typedef struct {
esp_lcd_panel_io_handle_t _Nonnull io_handle;
esp_lcd_panel_handle_t _Nonnull display_handle;
esp_lcd_panel_io_handle_t io_handle;
esp_lcd_panel_handle_t display_handle;
uint16_t horizontal_resolution;
uint16_t vertical_resolution;
uint16_t draw_buffer_height;
@@ -31,7 +31,7 @@ typedef struct {
* @param[in] driver
* @return allocated display object
*/
DisplayDevice _Nonnull* tt_display_device_alloc(DisplayDriver _Nonnull* driver);
DisplayDevice* tt_display_device_alloc(DisplayDriver* driver);
#ifdef __cplusplus
}
+3 -3
View File
@@ -5,7 +5,7 @@
#define TAG "lvgl"
Lvgl tt_graphics_init(Hardware _Nonnull* hardware) {
Lvgl tt_graphics_init(Hardware* hardware) {
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4,
.task_stack = 8096,
@@ -15,7 +15,7 @@ Lvgl tt_graphics_init(Hardware _Nonnull* hardware) {
};
tt_check(lvgl_port_init(&lvgl_cfg) == ESP_OK, "lvgl port init failed");
DisplayDevice _Nonnull* display = hardware->display;
DisplayDevice* display = hardware->display;
// Add display
TT_LOG_I(TAG, "lvgl add display");
@@ -37,7 +37,7 @@ Lvgl tt_graphics_init(Hardware _Nonnull* hardware) {
}
};
lv_disp_t _Nonnull* disp = lvgl_port_add_disp(&disp_cfg);
lv_disp_t* disp = lvgl_port_add_disp(&disp_cfg);
tt_check(disp != NULL, "failed to add display");
lv_indev_t _Nullable* touch_indev = NULL;
+1 -1
View File
@@ -7,7 +7,7 @@ extern "C" {
#endif
typedef struct {
lv_disp_t* _Nonnull disp;
lv_disp_t* disp;
lv_indev_t* _Nullable touch_indev;
} Lvgl;
+2 -2
View File
@@ -1,13 +1,13 @@
#pragma once
#include "graphics.h"
#include "hardare.h"
#include "hardware.h"
#ifdef __cplusplus
extern "C" {
#endif
Lvgl tt_graphics_init(Hardware _Nonnull* hardware);
Lvgl tt_graphics_init(Hardware* hardware);
#ifdef __cplusplus
}
+1 -1
View File
@@ -4,7 +4,7 @@
#define TAG "hardware"
Hardware tt_hardware_init(const HardwareConfig _Nonnull* config) {
Hardware tt_hardware_init(const HardwareConfig* config) {
if (config->bootstrap != NULL) {
TT_LOG_I(TAG, "Bootstrapping");
config->bootstrap();
@@ -8,7 +8,7 @@ extern "C" {
#endif
typedef struct {
DisplayDevice* _Nonnull display;
DisplayDevice* display;
TouchDevice* _Nullable touch;
} Hardware;
+1 -1
View File
@@ -6,7 +6,7 @@
extern "C" {
#endif
Hardware tt_hardware_init(const HardwareConfig _Nonnull* config);
Hardware tt_hardware_init(const HardwareConfig* config);
#ifdef __cplusplus
}
+1 -1
View File
@@ -17,7 +17,7 @@
typedef struct {
/** @brief Locking mechanism for modifying the Wifi instance */
Mutex* mutex;
Mutex mutex;
/** @brief The public event bus */
PubSub* pubsub;
/** @brief The internal message queue */
@@ -11,35 +11,40 @@
#define TT_NVS_NAMESPACE "tt_wifi_cred" // limited by NVS_KEY_NAME_MAX_SIZE
#define TT_NVS_PARTITION "nvs"
static void tt_wifi_credentials_mutex_lock();
static void tt_wifi_credentials_mutex_unlock();
static void hash_reset_all();
// region Hash
static Mutex* hash_mutex = NULL;
static int8_t ssid_hash_index = -1;
static uint32_t ssid_hashes[TT_WIFI_CREDENTIALS_LIMIT] = { 0 };
static Mutex hash_mutex = NULL;
static int8_t hash_index = -1;
static uint32_t hashes[TT_WIFI_CREDENTIALS_LIMIT] = { 0 };
static void hash_init() {
tt_assert(hash_mutex == NULL);
hash_mutex = tt_mutex_alloc(MutexTypeNormal);
hash_reset_all();
}
static void tt_hash_mutex_lock() {
tt_assert(tt_mutex_acquire(hash_mutex, 100) == TtStatusOk);
}
static void tt_hash_mutex_unlock() {
tt_assert(tt_mutex_release(hash_mutex) == TtStatusOk);
}
static int hash_find_value(uint32_t hash) {
tt_wifi_credentials_mutex_lock();
for (int i = 0; i < ssid_hash_index; ++i) {
if (ssid_hashes[i] == hash) {
tt_hash_mutex_lock();
for (int i = 0; i < hash_index; ++i) {
if (hashes[i] == hash) {
tt_hash_mutex_unlock();
return i;
}
}
tt_wifi_credentials_mutex_unlock();
tt_hash_mutex_unlock();
return -1;
}
static int hash_find_string(const char* ssid) {
uint32_t hash = tt_hash_string_djb2(ssid);
return hash_find_value(hash);
}
static bool hash_contains_string(const char* ssid) {
return hash_find_string(ssid) != -1;
}
static bool hash_contains_value(uint32_t value) {
return hash_find_value(value) != -1;
}
@@ -47,30 +52,22 @@ static bool hash_contains_value(uint32_t value) {
static void hash_add(const char* ssid) {
uint32_t hash = tt_hash_string_djb2(ssid);
if (!hash_contains_value(hash)) {
tt_wifi_credentials_mutex_lock();
tt_check((ssid_hash_index + 1) < TT_WIFI_CREDENTIALS_LIMIT, "exceeding wifi credentials list size");
ssid_hash_index++;
ssid_hashes[ssid_hash_index] = hash;
tt_wifi_credentials_mutex_unlock();
tt_hash_mutex_lock();
tt_check((hash_index + 1) < TT_WIFI_CREDENTIALS_LIMIT, "exceeding wifi credentials list size");
hash_index++;
hashes[hash_index] = hash;
tt_hash_mutex_unlock();
}
}
static void hash_reset_all() {
ssid_hash_index = -1;
hash_index = -1;
}
// endregion Hash
// region Wi-Fi Credentials - static
static void tt_wifi_credentials_mutex_lock() {
tt_mutex_acquire(hash_mutex, TtWaitForever);
}
static void tt_wifi_credentials_mutex_unlock() {
tt_mutex_release(hash_mutex);
}
static esp_err_t tt_wifi_credentials_nvs_open(nvs_handle_t* handle, nvs_open_mode_t mode) {
return nvs_open(TT_NVS_NAMESPACE, NVS_READWRITE, handle);
}
@@ -122,11 +119,8 @@ bool tt_wifi_credentials_contains(const char* ssid) {
}
void tt_wifi_credentials_init() {
hash_reset_all();
if (hash_mutex == NULL) {
hash_mutex = tt_mutex_alloc(MutexTypeRecursive);
}
TT_LOG_I(TAG, "init started");
hash_init();
nvs_handle_t handle;
esp_err_t result = tt_wifi_credentials_nvs_open(&handle, NVS_READWRITE);
@@ -146,6 +140,7 @@ void tt_wifi_credentials_init() {
nvs_release_iterator(iterator);
tt_wifi_credentials_nvs_close(handle);
TT_LOG_I(TAG, "init finished");
}
bool tt_wifi_credentials_get(const char* ssid, char password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT]) {
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include "hardare.h"
#include "hardware.h"
#include "tactility.h"
#ifdef __cplusplus
@@ -16,7 +16,7 @@ typedef struct {
// Optional bootstrapping method (e.g. to turn peripherals on)
const Bootstrap _Nullable bootstrap;
// Required driver for display
const CreateDisplayDriver _Nonnull display_driver;
const CreateDisplayDriver display_driver;
// Optional driver for touch input
const CreateTouchDriver _Nullable touch_driver;
} HardwareConfig;
+2 -2
View File
@@ -1,8 +1,8 @@
#include "check.h"
#include "touch.h"
TouchDevice _Nonnull* tt_touch_alloc(TouchDriver _Nonnull* driver) {
TouchDevice _Nonnull* touch = malloc(sizeof(TouchDevice));
TouchDevice* tt_touch_alloc(TouchDriver* driver) {
TouchDevice* touch = malloc(sizeof(TouchDevice));
bool success = driver->create_touch_device(
&(touch->io_handle),
&(touch->touch_handle)
+3 -3
View File
@@ -15,15 +15,15 @@ typedef struct {
} TouchDriver;
typedef struct {
esp_lcd_panel_io_handle_t _Nonnull io_handle;
esp_lcd_touch_handle_t _Nonnull touch_handle;
esp_lcd_panel_io_handle_t io_handle;
esp_lcd_touch_handle_t touch_handle;
} TouchDevice;
/**
* @param[in] driver
* @return a newly allocated instance
*/
TouchDevice _Nonnull* tt_touch_alloc(TouchDriver _Nonnull* driver);
TouchDevice* tt_touch_alloc(TouchDriver* driver);
#ifdef __cplusplus
}