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:
committed by
GitHub
parent
25b966a340
commit
4f635d38e3
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user