Touch and display driver subsystems reworked (and more) (#302)
- Refactored `TouchDevice`: it can now start/stop LVGL separately, and it has an optional `TouchDriver` interface - Refactored `DisplayDevice`: it can now start/stop LVGL separately, and it has an optional `DisplayDriver` interface - Updated all boards and drivers for above changes - LVGL can now be stopped and (re)started on the fly - Fixed issues with restarting Gui and Statusbar services - Refactored `Gui` service to be class and renamed `Gui` to `GuiService` - Fixed `Statusbar` service: forgot to deregister one of the icons - Updated `esp_lcd_st7701` to v1.1.3 - `lv_textarea_create()` now automatically registers the hardware keyboard hooks (by wrapping the function) - Fixed and updated `tactility.py` - Cleanup of a lot of code - `BootInitLvglBegin` and `BootInitLvglEnd` are replaced by `LvglStarted` and `LvglStopped`. - Introduced `tt::service::State` which is accessible via `tt::service::getState()` (and internally via `ServiceInstance`) - Started replacing `#define TAG` with `constexpr auto TAG = "..";`
This commit is contained in:
committed by
GitHub
parent
15f4fbfdc6
commit
d875ade8cb
@@ -9,13 +9,13 @@
|
||||
#include <hx8357/disp_spi.h>
|
||||
#include <hx8357/hx8357.h>
|
||||
|
||||
#define TAG "unphone_display"
|
||||
#define BUFFER_SIZE (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8)
|
||||
constexpr auto TAG = "UnPhoneDisplay";
|
||||
constexpr auto BUFFER_SIZE = (UNPHONE_LCD_HORIZONTAL_RESOLUTION * UNPHONE_LCD_DRAW_BUFFER_HEIGHT * LV_COLOR_DEPTH / 8);
|
||||
|
||||
extern std::shared_ptr<UnPhoneFeatures> unPhoneFeatures;
|
||||
|
||||
bool UnPhoneDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
TT_LOG_I(TAG, "start");
|
||||
|
||||
disp_spi_add_device(SPI2_HOST);
|
||||
|
||||
@@ -24,39 +24,75 @@ bool UnPhoneDisplay::start() {
|
||||
uint8_t madctl = (1U << MADCTL_BIT_INDEX_COLUMN_ADDRESS_ORDER);
|
||||
hx8357_set_madctl(madctl);
|
||||
|
||||
displayHandle = lv_display_create(UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_physical_resolution(displayHandle, UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_color_format(displayHandle, LV_COLOR_FORMAT_NATIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::stop() {
|
||||
TT_LOG_I(TAG, "stop");
|
||||
disp_spi_remove_device();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::startLvgl() {
|
||||
TT_LOG_I(TAG, "startLvgl");
|
||||
|
||||
if (lvglDisplay != nullptr) {
|
||||
TT_LOG_W(TAG, "LVGL was already started");
|
||||
return false;
|
||||
}
|
||||
|
||||
lvglDisplay = lv_display_create(UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_physical_resolution(lvglDisplay, UNPHONE_LCD_HORIZONTAL_RESOLUTION, UNPHONE_LCD_VERTICAL_RESOLUTION);
|
||||
lv_display_set_color_format(lvglDisplay, LV_COLOR_FORMAT_NATIVE);
|
||||
|
||||
// TODO malloc to use SPIRAM
|
||||
buffer = (uint8_t*)heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_DMA);
|
||||
buffer = static_cast<uint8_t*>(heap_caps_malloc(BUFFER_SIZE, MALLOC_CAP_DMA));
|
||||
assert(buffer != nullptr);
|
||||
|
||||
lv_display_set_buffers(
|
||||
displayHandle,
|
||||
lvglDisplay,
|
||||
buffer,
|
||||
nullptr,
|
||||
BUFFER_SIZE,
|
||||
LV_DISPLAY_RENDER_MODE_PARTIAL
|
||||
);
|
||||
|
||||
lv_display_set_flush_cb(displayHandle, hx8357_flush);
|
||||
lv_display_set_flush_cb(lvglDisplay, hx8357_flush);
|
||||
|
||||
if (displayHandle != nullptr) {
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
unPhoneFeatures->setBacklightPower(true);
|
||||
return true;
|
||||
} else {
|
||||
if (lvglDisplay == nullptr) {
|
||||
TT_LOG_I(TAG, "Failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
unPhoneFeatures->setBacklightPower(true);
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->startLvgl(lvglDisplay);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::stop() {
|
||||
assert(displayHandle != nullptr);
|
||||
bool UnPhoneDisplay::stopLvgl() {
|
||||
TT_LOG_I(TAG, "stopLvgl");
|
||||
|
||||
lv_display_delete(displayHandle);
|
||||
displayHandle = nullptr;
|
||||
if (lvglDisplay == nullptr) {
|
||||
TT_LOG_W(TAG, "LVGL was already stopped");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Just in case
|
||||
disp_wait_for_pending_transactions();
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr && touch_device->getLvglIndev() != nullptr) {
|
||||
TT_LOG_I(TAG, "Stopping touch device");
|
||||
touch_device->stopLvgl();
|
||||
}
|
||||
|
||||
lv_display_delete(lvglDisplay);
|
||||
lvglDisplay = nullptr;
|
||||
|
||||
heap_caps_free(buffer);
|
||||
buffer = nullptr;
|
||||
@@ -64,10 +100,21 @@ bool UnPhoneDisplay::stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable UnPhoneDisplay::createTouch() {
|
||||
return ::createTouch();
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable UnPhoneDisplay::getTouchDevice() {
|
||||
if (touchDevice == nullptr) {
|
||||
touchDevice = std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(createTouch());
|
||||
TT_LOG_I(TAG, "Created touch device");
|
||||
}
|
||||
|
||||
return touchDevice;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
|
||||
return std::make_shared<UnPhoneDisplay>();
|
||||
}
|
||||
|
||||
bool UnPhoneDisplay::UnPhoneDisplayDriver::drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) {
|
||||
lv_area_t area = { xStart, yStart, xEnd, yEnd };
|
||||
hx8357_flush(nullptr, &area, (uint8_t*)pixelData);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user