Merge develop into main (#303)
- `DisplayDevice` improvements related `DisplayDriver` - Replaced incorrect usage of `spiBusHandle` with `spiHostDevice` in all SPI display devices - Disabled `DisplayDriver` support for RGB displays for now - Updated `GraphicsDemo` project for the above changes - TactilityC improvements: - created `tt_hal_device_find()` - created `tt_hal_display_*` - created `tt_hal_touch_*` - created `tt_lvgl_*` - export `tt_app_*` calls
This commit is contained in:
committed by
GitHub
parent
d875ade8cb
commit
fbaff8cbac
@@ -0,0 +1,72 @@
|
||||
#include "Application.h"
|
||||
#include "PixelBuffer.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <tt_kernel.h>
|
||||
|
||||
constexpr auto TAG = "Application";
|
||||
|
||||
static bool isTouched(TouchDriver* touch) {
|
||||
uint16_t x, y, strength;
|
||||
uint8_t pointCount = 0;
|
||||
return touch->getTouchedPoints(&x, &y, &strength, &pointCount, 1);
|
||||
}
|
||||
|
||||
void createRgbRow(PixelBuffer& buffer) {
|
||||
uint8_t offset = buffer.getPixelWidth() / 3;
|
||||
for (int i = 0; i < buffer.getPixelWidth(); ++i) {
|
||||
if (i < offset) {
|
||||
buffer.setPixel(i, 0, 255, 0, 0);
|
||||
} else if (i < offset * 2) {
|
||||
buffer.setPixel(i, 0, 0, 255, 0);
|
||||
} else {
|
||||
buffer.setPixel(i, 0, 0, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createRgbFadingRow(PixelBuffer& buffer) {
|
||||
uint8_t stroke = buffer.getPixelWidth() / 3;
|
||||
for (int i = 0; i < buffer.getPixelWidth(); ++i) {
|
||||
if (i < stroke) {
|
||||
auto color = i * 255 / stroke;
|
||||
buffer.setPixel(i, 0, color, 0, 0);
|
||||
} else if (i < stroke * 2) {
|
||||
auto color = (i - stroke) * 255 / stroke;
|
||||
buffer.setPixel(i, 0, 0, color, 0);
|
||||
} else {
|
||||
auto color = (i - (2*stroke)) * 255 / stroke;
|
||||
buffer.setPixel(i, 0, 0, 0, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void runApplication(DisplayDriver* display, TouchDriver* touch) {
|
||||
// Single row buffers
|
||||
PixelBuffer line_clear_buffer(display->getWidth(), 1, display->getColorFormat());
|
||||
line_clear_buffer.clear();
|
||||
PixelBuffer line_buffer(display->getWidth(), 1, display->getColorFormat());
|
||||
line_buffer.clear();
|
||||
|
||||
do {
|
||||
// Draw row by row
|
||||
// This is placed in a loop to test the SPI locking mechanismss
|
||||
for (int i = 0; i < display->getHeight(); i++) {
|
||||
|
||||
if (i == 0) {
|
||||
createRgbRow(line_buffer);
|
||||
} else if (i == display->getHeight() / 2) {
|
||||
createRgbFadingRow(line_buffer);
|
||||
}
|
||||
|
||||
display->lock();
|
||||
display->drawBitmap(0, i, display->getWidth(), i + 1, line_buffer.getData());
|
||||
display->unlock();
|
||||
}
|
||||
|
||||
// Give other tasks space to breathe
|
||||
// SPI displays would otherwise time out SPI SD card access
|
||||
tt_kernel_delay_ticks(1);
|
||||
} while (!isTouched(touch));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "Application.h"
|
||||
#include "drivers/DisplayDriver.h"
|
||||
#include "drivers/TouchDriver.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <tt_app.h>
|
||||
#include <tt_lvgl.h>
|
||||
|
||||
constexpr auto TAG = "Main";
|
||||
|
||||
static void onCreate(AppHandle appHandle, void* data) {
|
||||
uint16_t display_count = 0;
|
||||
DeviceId display_id;
|
||||
if (!tt_hal_device_find(DEVICE_TYPE_DISPLAY, &display_id, &display_count, 1)) {
|
||||
ESP_LOGI(TAG, "No display device found");
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t touch_count = 0;
|
||||
DeviceId touch_id;
|
||||
if (!tt_hal_device_find(DEVICE_TYPE_TOUCH, &touch_id, &touch_count, 1)) {
|
||||
ESP_LOGI(TAG, "No touch device found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop LVGL first (because it's currently using the drivers we want to use)
|
||||
tt_lvgl_stop();
|
||||
|
||||
ESP_LOGI(TAG, "Creating display driver");
|
||||
auto display = new DisplayDriver(display_id);
|
||||
|
||||
ESP_LOGI(TAG, "Creating touch driver");
|
||||
auto touch = new TouchDriver(touch_id);
|
||||
|
||||
// Run the main logic
|
||||
ESP_LOGI(TAG, "Running application");
|
||||
runApplication(display, touch);
|
||||
|
||||
ESP_LOGI(TAG, "Cleanup display driver");
|
||||
delete display;
|
||||
|
||||
ESP_LOGI(TAG, "Cleanup touch driver");
|
||||
delete touch;
|
||||
|
||||
ESP_LOGI(TAG, "Stopping application");
|
||||
tt_app_stop();
|
||||
}
|
||||
|
||||
static void onDestroy(AppHandle appHandle, void* data) {
|
||||
// Restart LVGL to resume rendering of regular apps
|
||||
if (!tt_lvgl_is_started()) {
|
||||
ESP_LOGI(TAG, "Restarting LVGL");
|
||||
tt_lvgl_start();
|
||||
}
|
||||
}
|
||||
|
||||
ExternalAppManifest manifest = {
|
||||
.name = "Hello World",
|
||||
.onCreate = onCreate,
|
||||
.onDestroy = onDestroy
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
tt_app_register(&manifest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user