Updates for removal of deprecated HAL (#37)

Update all apps to replace deprecated LVGL code and to use the new kernel APIs.
This commit is contained in:
Ken Van Hoeylandt
2026-07-26 12:47:03 +02:00
committed by GitHub
parent 25b966a340
commit 4f635d38e3
45 changed files with 200 additions and 257 deletions
+16 -16
View File
@@ -4,17 +4,17 @@
#include "drivers/Colors.h"
#include <cstring>
#include <tt_hal_display.h>
#include <tactility/drivers/display.h>
class PixelBuffer {
uint16_t pixelWidth;
uint16_t pixelHeight;
ColorFormat colorFormat;
enum DisplayColorFormat colorFormat;
uint8_t* data;
public:
PixelBuffer(uint16_t pixelWidth, uint16_t pixelHeight, ColorFormat colorFormat) :
PixelBuffer(uint16_t pixelWidth, uint16_t pixelHeight, enum DisplayColorFormat colorFormat) :
pixelWidth(pixelWidth),
pixelHeight(pixelHeight),
colorFormat(colorFormat)
@@ -35,7 +35,7 @@ public:
return pixelHeight;
}
ColorFormat getColorFormat() const {
enum DisplayColorFormat getColorFormat() const {
return colorFormat;
}
@@ -58,14 +58,14 @@ public:
uint8_t getPixelSize() const {
switch (colorFormat) {
case COLOR_FORMAT_MONOCHROME:
case DISPLAY_COLOR_FORMAT_MONOCHROME:
return 1;
case COLOR_FORMAT_BGR565:
case COLOR_FORMAT_BGR565_SWAPPED:
case COLOR_FORMAT_RGB565:
case COLOR_FORMAT_RGB565_SWAPPED:
case DISPLAY_COLOR_FORMAT_BGR565:
case DISPLAY_COLOR_FORMAT_BGR565_SWAPPED:
case DISPLAY_COLOR_FORMAT_RGB565:
case DISPLAY_COLOR_FORMAT_RGB565_SWAPPED:
return 2;
case COLOR_FORMAT_RGB888:
case DISPLAY_COLOR_FORMAT_RGB888:
return 3;
default:
// TODO: Crash with error
@@ -82,13 +82,13 @@ public:
void setPixel(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b) const {
auto address = getPixelAddress(x, y);
switch (colorFormat) {
case COLOR_FORMAT_MONOCHROME:
case DISPLAY_COLOR_FORMAT_MONOCHROME:
*address = (uint8_t)((uint16_t)r + (uint16_t)g + (uint16_t)b / 3);
break;
case COLOR_FORMAT_BGR565:
case DISPLAY_COLOR_FORMAT_BGR565:
Colors::rgb888ToBgr565(r, g, b, reinterpret_cast<uint16_t*>(address));
break;
case COLOR_FORMAT_BGR565_SWAPPED: {
case DISPLAY_COLOR_FORMAT_BGR565_SWAPPED: {
// TODO: Make proper conversion function
Colors::rgb888ToBgr565(r, g, b, reinterpret_cast<uint16_t*>(address));
uint8_t temp = *address;
@@ -96,11 +96,11 @@ public:
*(address + 1) = temp;
break;
}
case COLOR_FORMAT_RGB565: {
case DISPLAY_COLOR_FORMAT_RGB565: {
Colors::rgb888ToRgb565(r, g, b, reinterpret_cast<uint16_t*>(address));
break;
}
case COLOR_FORMAT_RGB565_SWAPPED: {
case DISPLAY_COLOR_FORMAT_RGB565_SWAPPED: {
// TODO: Make proper conversion function
Colors::rgb888ToRgb565(r, g, b, reinterpret_cast<uint16_t*>(address));
uint8_t temp = *address;
@@ -108,7 +108,7 @@ public:
*(address + 1) = temp;
break;
}
case COLOR_FORMAT_RGB888: {
case DISPLAY_COLOR_FORMAT_RGB888: {
uint8_t pixel[3] = { r, g, b };
memcpy(address, pixel, 3);
break;
@@ -1,49 +1,47 @@
#pragma once
#include <cassert>
#include <tt_hal_display.h>
#include <tactility/device.h>
#include <tactility/drivers/display.h>
#include <Tactility/kernel/Kernel.h>
/**
* Wrapper for tt_hal_display_driver_*
* Wrapper for display_* device driver functions
*/
class DisplayDriver {
DisplayDriverHandle handle = nullptr;
struct Device* device;
public:
explicit DisplayDriver(DeviceId id) {
assert(tt_hal_display_driver_supported(id));
handle = tt_hal_display_driver_alloc(id);
assert(handle != nullptr);
explicit DisplayDriver(struct Device* device) : device(device) {
device_get(device);
}
~DisplayDriver() {
tt_hal_display_driver_free(handle);
device_put(device);
}
bool lock(TickType_t timeout = tt::kernel::MAX_TICKS) const {
return tt_hal_display_driver_lock(handle, timeout);
return device_try_lock(device, timeout);
}
void unlock() const {
tt_hal_display_driver_unlock(handle);
device_unlock(device);
}
uint16_t getWidth() const {
return tt_hal_display_driver_get_pixel_width(handle);
return display_get_resolution_x(device);
}
uint16_t getHeight() const {
return tt_hal_display_driver_get_pixel_height(handle);
return display_get_resolution_y(device);
}
ColorFormat getColorFormat() const {
return tt_hal_display_driver_get_colorformat(handle);
enum DisplayColorFormat getColorFormat() const {
return display_get_color_format(device);
}
void drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) const {
tt_hal_display_driver_draw_bitmap(handle, xStart, yStart, xEnd, yEnd, pixelData);
display_draw_bitmap(device, xStart, yStart, xEnd, yEnd, pixelData);
}
};
@@ -1,28 +1,28 @@
#pragma once
#include <cassert>
#include <tt_hal_touch.h>
#include <tactility/device.h>
#include <tactility/drivers/pointer.h>
/**
* Wrapper for tt_hal_touch_driver_*
* Wrapper for pointer_* device driver functions
*/
class TouchDriver {
TouchDriverHandle handle = nullptr;
struct Device* device;
public:
explicit TouchDriver(DeviceId id) {
assert(tt_hal_touch_driver_supported(id));
handle = tt_hal_touch_driver_alloc(id);
assert(handle != nullptr);
explicit TouchDriver(struct Device* device) : device(device) {
device_get(device);
}
~TouchDriver() {
tt_hal_touch_driver_free(handle);
device_put(device);
}
bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* count, uint8_t maxCount) const {
return tt_hal_touch_driver_get_touched_points(handle, x, y, strength, count, maxCount);
// Poll without blocking: perform one read attempt, then report whatever is cached.
pointer_read_data(device, 0);
return pointer_get_touched_points(device, x, y, strength, count, maxCount);
}
};
+23 -44
View File
@@ -6,65 +6,44 @@
#include <tt_app.h>
#include <tt_app_alertdialog.h>
#include <tt_lvgl.h>
#include <tactility/device.h>
#include <tactility/drivers/display.h>
#include <tactility/drivers/pointer.h>
#include <lvgl/lvgl.h>
#include <lvgl/module.h>
#include <tactility/module.h>
constexpr auto TAG = "Main";
/** Find a DisplayDevice that supports the DisplayDriver interface */
static bool findUsableDisplay(DeviceId& deviceId) {
uint16_t display_count = 0;
if (!tt_hal_device_find(DEVICE_TYPE_DISPLAY, &deviceId, &display_count, 1)) {
ESP_LOGE(TAG, "No display device found");
return false;
}
if (!tt_hal_display_driver_supported(deviceId)) {
ESP_LOGE(TAG, "Display doesn't support driver mode");
return false;
}
return true;
}
/** Find a TouchDevice that supports the TouchDriver interface */
static bool findUsableTouch(DeviceId& deviceId) {
uint16_t touch_count = 0;
if (!tt_hal_device_find(DEVICE_TYPE_TOUCH, &deviceId, &touch_count, 1)) {
ESP_LOGE(TAG, "No touch device found");
return false;
}
if (!tt_hal_touch_driver_supported(deviceId)) {
ESP_LOGE(TAG, "Touch doesn't support driver mode");
return false;
}
return true;
}
static void onCreate(AppHandle appHandle, void* data) {
DeviceId display_id;
if (!findUsableDisplay(display_id)) {
struct Device* display_device;
if (device_get_first_active_by_type(&DISPLAY_TYPE, &display_device) != ERROR_NONE) {
ESP_LOGE(TAG, "No display device found");
tt_app_stop();
tt_app_alertdialog_start("Error", "The display doesn't support the required features.", nullptr, 0);
tt_app_alertdialog_start("Error", "No display device was found.", nullptr, 0);
return;
}
DeviceId touch_id;
if (!findUsableTouch(touch_id)) {
struct Device* touch_device;
if (device_get_first_active_by_type(&POINTER_TYPE, &touch_device) != ERROR_NONE) {
ESP_LOGE(TAG, "No touch device found");
device_put(display_device);
tt_app_stop();
tt_app_alertdialog_start("Error", "The touch driver doesn't support the required features.", nullptr, 0);
tt_app_alertdialog_start("Error", "No touch device was found.", nullptr, 0);
return;
}
// Stop LVGL first (because it's currently using the drivers we want to use)
tt_lvgl_stop();
module_stop(&lvgl_module);
ESP_LOGI(TAG, "Creating display driver");
auto display = new DisplayDriver(display_id);
auto display = new DisplayDriver(display_device);
device_put(display_device);
ESP_LOGI(TAG, "Creating touch driver");
auto touch = new TouchDriver(touch_id);
auto touch = new TouchDriver(touch_device);
device_put(touch_device);
// Run the main logic
ESP_LOGI(TAG, "Running application");
@@ -82,9 +61,9 @@ static void onCreate(AppHandle appHandle, void* data) {
static void onDestroy(AppHandle appHandle, void* data) {
// Restart LVGL to resume rendering of regular apps
if (!tt_lvgl_is_started()) {
if (!module_is_started(&lvgl_module)) {
ESP_LOGI(TAG, "Restarting LVGL");
tt_lvgl_start();
module_start(&lvgl_module);
}
}
+2 -2
View File
@@ -2,6 +2,6 @@ manifest.version=0.2
target.sdk=0.8.0-dev
target.platforms=esp32,esp32s3,esp32c6,esp32p4
app.id=one.tactility.mystifydemo
app.version.name=0.6.0
app.version.code=6
app.version.name=0.7.0
app.version.code=7
app.name=Mystify Demo