Hal refactored (#99)
This commit is contained in:
committed by
GitHub
parent
0188ce721c
commit
33bb742dfb
@@ -1,8 +1,7 @@
|
||||
#include "lvgl_task.h"
|
||||
#include "LvglTask.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "Log.h"
|
||||
#include "lvgl_hal.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "Thread.h"
|
||||
#include "lvgl/LvglSync.h"
|
||||
@@ -66,18 +65,23 @@ void lvgl_task_start() {
|
||||
lvgl_task,
|
||||
"lvgl",
|
||||
8192,
|
||||
NULL,
|
||||
nullptr,
|
||||
tt::Thread::PriorityHigh, // Should be higher than main app task
|
||||
NULL
|
||||
nullptr
|
||||
);
|
||||
|
||||
tt_assert(task_result == pdTRUE);
|
||||
}
|
||||
|
||||
lv_disp_t* displayHandle = nullptr;
|
||||
|
||||
static void lvgl_task(TT_UNUSED void* arg) {
|
||||
TT_LOG_I(TAG, "lvgl task started");
|
||||
|
||||
lv_disp_t* display = lvgl_hal_init();
|
||||
/** Ideally. the display handle would be created during Simulator.start(),
|
||||
* but somehow that doesn't work. Waiting here from a ThreadFlag when that happens
|
||||
* also doesn't work. It seems that it must be called from this task. */
|
||||
displayHandle = lv_sdl_window_create(320, 240);
|
||||
|
||||
uint32_t task_delay_ms = task_max_sleep_ms;
|
||||
|
||||
@@ -96,8 +100,7 @@ static void lvgl_task(TT_UNUSED void* arg) {
|
||||
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
|
||||
}
|
||||
|
||||
lv_disp_remove(display);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
lv_disp_remove(displayHandle);
|
||||
displayHandle = nullptr;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
#include "Main.h"
|
||||
#include "TactilityCore.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "Simulator.h"
|
||||
|
||||
#define TAG "freertos"
|
||||
|
||||
static void main_task(TT_UNUSED void* parameter) {
|
||||
namespace simulator {
|
||||
|
||||
MainFunction mainFunction = nullptr;
|
||||
|
||||
void setMain(MainFunction newMainFunction) {
|
||||
mainFunction = newMainFunction;
|
||||
}
|
||||
|
||||
static void freertosMainTask(TT_UNUSED void* parameter) {
|
||||
TT_LOG_I(TAG, "starting app_main()");
|
||||
executeMainFunction();
|
||||
assert(simulator::mainFunction);
|
||||
mainFunction();
|
||||
TT_LOG_I(TAG, "returned from app_main()");
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
int main_stub() {
|
||||
void freertosMain() {
|
||||
BaseType_t task_result = xTaskCreate(
|
||||
main_task,
|
||||
freertosMainTask,
|
||||
"main",
|
||||
8192,
|
||||
nullptr,
|
||||
@@ -29,6 +39,8 @@ int main_stub() {
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* Assert implementation as defined in the FreeRTOSConfig.h
|
||||
* It allows you to set breakpoints and debug asserts.
|
||||
@@ -47,3 +59,4 @@ void vAssertCalled(unsigned long line, const char* const file) {
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
typedef void (*MainFunction)();
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "Simulator.h"
|
||||
|
||||
MainFunction mainFunction = nullptr;
|
||||
|
||||
void setMainForSim(MainFunction newMainFunction) {
|
||||
mainFunction = newMainFunction;
|
||||
}
|
||||
|
||||
void executeMainFunction() {
|
||||
assert(mainFunction);
|
||||
mainFunction();
|
||||
}
|
||||
@@ -1,10 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Configuration.h"
|
||||
#include "Main.h"
|
||||
|
||||
extern const tt::hal::Configuration sim_hardware;
|
||||
namespace simulator {
|
||||
/** Set the function pointer of the real app_main() */
|
||||
void setMain(MainFunction mainFunction);
|
||||
/** The actual main task */
|
||||
void freertosMain();
|
||||
}
|
||||
|
||||
typedef void (*MainFunction)();
|
||||
void setMainForSim(MainFunction mainFunction);
|
||||
void executeMainFunction();
|
||||
int main_stub();
|
||||
extern "C" {
|
||||
void app_main(); // ESP-IDF's main function, implemented in the application
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Actual main function that passes on app_main() (to be executed in a FreeRTOS task) and bootstraps FreeRTOS
|
||||
simulator::setMain(app_main);
|
||||
simulator::freertosMain();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+9
-8
@@ -1,18 +1,20 @@
|
||||
#include "hal/Configuration.h"
|
||||
#include "lvgl_task.h"
|
||||
#include "LvglTask.h"
|
||||
#include "src/lv_init.h"
|
||||
#include "SdlDisplay.h"
|
||||
#include "SdlKeyboard.h"
|
||||
|
||||
#define TAG "hardware"
|
||||
|
||||
extern const tt::hal::Power power;
|
||||
|
||||
static bool lvgl_init() {
|
||||
static bool initBoot() {
|
||||
lv_init();
|
||||
lvgl_task_start();
|
||||
return true;
|
||||
}
|
||||
|
||||
TT_UNUSED static void lvgl_deinit() {
|
||||
TT_UNUSED static void deinitPower() {
|
||||
lvgl_task_interrupt();
|
||||
while (lvgl_task_is_running()) {
|
||||
tt::delay_ms(10);
|
||||
@@ -23,11 +25,10 @@ TT_UNUSED static void lvgl_deinit() {
|
||||
#endif
|
||||
}
|
||||
|
||||
extern const tt::hal::Configuration sim_hardware = {
|
||||
.initLvgl = &lvgl_init,
|
||||
.display = {
|
||||
.setBacklightDuty = nullptr,
|
||||
},
|
||||
extern const tt::hal::Configuration hardware = {
|
||||
.initBoot = initBoot,
|
||||
.createDisplay = createDisplay,
|
||||
.createKeyboard = createKeyboard,
|
||||
.sdcard = nullptr,
|
||||
.power = &power,
|
||||
.i2c = {
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "hal/Power.h"
|
||||
|
||||
static bool is_charging_enabled = false;
|
||||
|
||||
static bool isCharging() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static bool isChargingEnabled() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static void setChargingEnabled(bool enabled) {
|
||||
is_charging_enabled = enabled;
|
||||
}
|
||||
|
||||
static uint8_t getChargeLevel() {
|
||||
return 204;
|
||||
}
|
||||
|
||||
static int32_t getCurrent() {
|
||||
return is_charging_enabled ? 100 : -50;
|
||||
}
|
||||
|
||||
extern const tt::hal::Power power = {
|
||||
.isCharging = isCharging,
|
||||
.isChargingEnabled = isChargingEnabled,
|
||||
.setChargingEnabled = setChargingEnabled,
|
||||
.getChargeLevel = getChargeLevel,
|
||||
.getCurrent = getCurrent
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "SdlTouch.h"
|
||||
#include "hal/Display.h"
|
||||
|
||||
extern lv_disp_t* displayHandle;
|
||||
|
||||
class SdlDisplay : public tt::hal::Display {
|
||||
public:
|
||||
bool start() override {
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
|
||||
void setPowerOn(bool turnOn) override {}
|
||||
bool isPoweredOn() const override { return displayHandle != nullptr; }
|
||||
bool supportsPowerControl() const override { return false; }
|
||||
|
||||
tt::hal::Touch* _Nullable createTouch() override { return dynamic_cast<tt::hal::Touch*>(new SdlTouch()); }
|
||||
|
||||
void setBacklightDuty(uint8_t backlightDuty) override {}
|
||||
uint8_t getBacklightDuty() const override { return 255; }
|
||||
bool supportsBacklightDuty() const override { return false; }
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
};
|
||||
|
||||
tt::hal::Display* createDisplay() {
|
||||
return static_cast<tt::hal::Display*>(new SdlDisplay());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Keyboard.h"
|
||||
|
||||
#include <TactilityCore.h>
|
||||
|
||||
class SdlKeyboard : public tt::hal::Keyboard {
|
||||
private:
|
||||
lv_indev_t* _Nullable handle = nullptr;
|
||||
|
||||
public:
|
||||
bool start(lv_display_t* display) override {
|
||||
handle = lv_sdl_keyboard_create();
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
|
||||
bool isAttached() const override { return true; }
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
|
||||
};
|
||||
|
||||
tt::hal::Keyboard* createKeyboard() {
|
||||
return static_cast<tt::hal::Keyboard*>(new SdlKeyboard());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Touch.h"
|
||||
|
||||
#include <TactilityCore.h>
|
||||
|
||||
class SdlTouch : public tt::hal::Touch {
|
||||
private:
|
||||
lv_indev_t* _Nullable handle = nullptr;
|
||||
|
||||
public:
|
||||
bool start(lv_display_t* display) override {
|
||||
handle = lv_sdl_mouse_create();
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "lvgl.h"
|
||||
#include "lvgl/LvglKeypad.h"
|
||||
|
||||
lv_display_t* lvgl_hal_init() {
|
||||
static lv_display_t* display = NULL;
|
||||
static lv_indev_t* mouse = NULL;
|
||||
static lv_indev_t* keyboard = NULL;
|
||||
|
||||
display = lv_sdl_window_create(320, 240);
|
||||
mouse = lv_sdl_mouse_create();
|
||||
keyboard = lv_sdl_keyboard_create();
|
||||
tt::lvgl::keypad_set_indev(keyboard);
|
||||
|
||||
return display;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
lv_display_t* lvgl_hal_init();
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "hal/Power.h"
|
||||
|
||||
static bool is_charging_enabled = false;
|
||||
|
||||
static bool power_is_charging() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static bool power_is_charging_enabled() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static void power_set_charging_enabled(bool enabled) {
|
||||
is_charging_enabled = enabled;
|
||||
}
|
||||
|
||||
static uint8_t power_get_charge_level() {
|
||||
return 204;
|
||||
}
|
||||
|
||||
static int32_t power_get_current() {
|
||||
return is_charging_enabled ? 100 : -50;
|
||||
}
|
||||
|
||||
extern const tt::hal::Power power = {
|
||||
.isCharging = &power_is_charging,
|
||||
.isChargingEnabled = &power_is_charging_enabled,
|
||||
.setChargingEnabled = &power_set_charging_enabled,
|
||||
.getChargeLevel = &power_get_charge_level,
|
||||
.getCurrent = &power_get_current
|
||||
};
|
||||
Reference in New Issue
Block a user