Hal refactored (#99)
This commit is contained in:
committed by
GitHub
parent
0188ce721c
commit
33bb742dfb
@@ -5,8 +5,8 @@
|
||||
|
||||
#define TAG "cores3_lvgl"
|
||||
|
||||
_Nullable lv_disp_t* m5stack_lvgl_display(bool usePsram);
|
||||
_Nullable lv_indev_t* m5stack_lvgl_touch();
|
||||
_Nullable lv_disp_t* createDisplay(bool usePsram);
|
||||
_Nullable lv_indev_t* createTouch();
|
||||
|
||||
bool m5stack_lvgl_init() {
|
||||
static lv_display_t* display = nullptr;
|
||||
@@ -24,21 +24,6 @@ bool m5stack_lvgl_init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add display
|
||||
display = m5stack_lvgl_display(true);
|
||||
if (display == nullptr) {
|
||||
TT_LOG_E(TAG, "failed to add display");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add touch
|
||||
lv_indev_t* touch_indev = m5stack_lvgl_touch();
|
||||
if (touch_indev == nullptr) {
|
||||
TT_LOG_E(TAG, "failed to add touch");
|
||||
return false;
|
||||
}
|
||||
lv_indev_set_display(touch_indev, display);
|
||||
|
||||
// Set syncing functions
|
||||
tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock);
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "M5Unified.hpp"
|
||||
#include "lvgl.h"
|
||||
#include "TactilityCore.h"
|
||||
|
||||
#define TAG "cores3_touch"
|
||||
|
||||
static void read_callback(TT_UNUSED lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
lgfx::touch_point_t point; // Making it static makes it unreliable
|
||||
bool touched = M5.Lcd.getTouch(&point) > 0;
|
||||
if (!touched) {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
data->point.x = point.x;
|
||||
data->point.y = point.y;
|
||||
}
|
||||
}
|
||||
|
||||
_Nullable lv_indev_t* m5stack_lvgl_touch() {
|
||||
static lv_indev_t* indev = lv_indev_create();
|
||||
LV_ASSERT_MALLOC(indev)
|
||||
if (indev == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(indev, read_callback);
|
||||
return indev;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Power.h"
|
||||
#include "hal/M5stackTouch.h"
|
||||
#include "hal/M5stackDisplay.h"
|
||||
#include "hal/sdcard/Sdcard.h"
|
||||
|
||||
extern bool m5stack_bootstrap();
|
||||
|
||||
+31
-3
@@ -1,4 +1,11 @@
|
||||
#include "TactilityCore.h"
|
||||
#include "M5stackDisplay.h"
|
||||
#include "M5stackTouch.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include <TactilityCore.h>
|
||||
|
||||
#define TAG "m5shared_display"
|
||||
|
||||
|
||||
#include "M5Unified.hpp"
|
||||
#include "esp_err.h"
|
||||
@@ -18,8 +25,7 @@ static void flush_callback(lv_display_t* display, const lv_area_t* area, uint8_t
|
||||
lv_display_flush_ready(display);
|
||||
}
|
||||
|
||||
|
||||
_Nullable lv_disp_t* m5stack_lvgl_display(bool usePsram) {
|
||||
_Nullable lv_disp_t* createDisplay(bool usePsram) {
|
||||
M5GFX& gfx = M5.Display;
|
||||
|
||||
static lv_display_t* display = lv_display_create(gfx.width(), gfx.height());
|
||||
@@ -59,3 +65,25 @@ _Nullable lv_disp_t* m5stack_lvgl_display(bool usePsram) {
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
bool M5stackDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
displayHandle = createDisplay(true);
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool M5stackDisplay::stop() {
|
||||
tt_assert(displayHandle != nullptr);
|
||||
lv_display_delete(displayHandle);
|
||||
displayHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
tt::hal::Touch* _Nullable M5stackDisplay::createTouch() {
|
||||
return static_cast<tt::hal::Touch*>(new M5stackTouch());
|
||||
}
|
||||
|
||||
tt::hal::Display* createDisplay() {
|
||||
return static_cast<tt::hal::Display*>(new M5stackDisplay());
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "hal/Display.h"
|
||||
|
||||
extern lv_disp_t* displayHandle;
|
||||
|
||||
class M5stackDisplay : public tt::hal::Display {
|
||||
|
||||
private:
|
||||
|
||||
lv_display_t* displayHandle = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
void setPowerOn(bool turnOn) override {}
|
||||
bool isPoweredOn() const override { return true; };
|
||||
bool supportsPowerControl() const override { return false; }
|
||||
|
||||
tt::hal::Touch* _Nullable createTouch() override;
|
||||
|
||||
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();
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "M5stackTouch.h"
|
||||
#include "M5Unified.hpp"
|
||||
#include "esp_err.h"
|
||||
#include "Log.h"
|
||||
|
||||
#define TAG "m5stack_touch"
|
||||
|
||||
static void touchReadCallback(TT_UNUSED lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
lgfx::touch_point_t point; // Making it static makes it unreliable
|
||||
bool touched = M5.Lcd.getTouch(&point) > 0;
|
||||
if (!touched) {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
data->point.x = point.x;
|
||||
data->point.y = point.y;
|
||||
}
|
||||
}
|
||||
|
||||
_Nullable lv_indev_t* createTouch() {
|
||||
static lv_indev_t* indev = lv_indev_create();
|
||||
LV_ASSERT_MALLOC(indev)
|
||||
if (indev == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(indev, touchReadCallback);
|
||||
return indev;
|
||||
}
|
||||
bool M5stackTouch::start(lv_display_t* display) {
|
||||
|
||||
TT_LOG_I(TAG, "Adding touch to LVGL");
|
||||
deviceHandle = createTouch();
|
||||
if (deviceHandle == nullptr) {
|
||||
TT_LOG_E(TAG, "Adding touch failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool M5stackTouch::stop() {
|
||||
tt_assert(deviceHandle != nullptr);
|
||||
lv_indev_delete(deviceHandle);
|
||||
deviceHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Touch.h"
|
||||
#include "TactilityCore.h"
|
||||
|
||||
class M5stackTouch : public tt::hal::Touch {
|
||||
private:
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
public:
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
};
|
||||
Reference in New Issue
Block a user