mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-03 05:12:55 +00:00
API review (esp-idf): Replace the use of std::optional<esp_lcd_touch_handle_t> with esp_lcd_touch_handle_t directly
esp_lcd_touch_handle_t is a pointer, so might as well treat it like one. Also default initialize the panel pointer.
This commit is contained in:
parent
df81e28562
commit
4c432c261d
2 changed files with 8 additions and 8 deletions
|
|
@ -38,9 +38,9 @@ struct SlintPlatformConfiguration
|
||||||
slint::PhysicalSize size;
|
slint::PhysicalSize size;
|
||||||
/// The handle to the display as previously initialized by `bsp_display_new` or
|
/// The handle to the display as previously initialized by `bsp_display_new` or
|
||||||
/// `esp_lcd_panel_init`.
|
/// `esp_lcd_panel_init`.
|
||||||
esp_lcd_panel_handle_t panel;
|
esp_lcd_panel_handle_t panel = nullptr;
|
||||||
/// The touch screen handle, if the device is equipped with a touch screen.
|
/// The touch screen handle, if the device is equipped with a touch screen.
|
||||||
std::optional<esp_lcd_touch_handle_t> touch;
|
esp_lcd_touch_handle_t touch = nullptr;
|
||||||
/// The buffer Slint will render into. It must have have the size of at least one frame. Slint
|
/// The buffer Slint will render into. It must have have the size of at least one frame. Slint
|
||||||
/// calls esp_lcd_panel_draw_bitmap to flush the buffer to the screen.
|
/// calls esp_lcd_panel_draw_bitmap to flush the buffer to the screen.
|
||||||
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer1 = {};
|
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer1 = {};
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ struct EspPlatform : public slint::platform::Platform
|
||||||
private:
|
private:
|
||||||
slint::PhysicalSize size;
|
slint::PhysicalSize size;
|
||||||
esp_lcd_panel_handle_t panel_handle;
|
esp_lcd_panel_handle_t panel_handle;
|
||||||
std::optional<esp_lcd_touch_handle_t> touch_handle;
|
esp_lcd_touch_handle_t touch_handle;
|
||||||
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer1;
|
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer1;
|
||||||
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer2;
|
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer2;
|
||||||
bool color_swap_16;
|
bool color_swap_16;
|
||||||
|
|
@ -127,7 +127,7 @@ void EspPlatform::run_event_loop()
|
||||||
|
|
||||||
if (touch_handle) {
|
if (touch_handle) {
|
||||||
if (esp_lcd_touch_register_interrupt_callback(
|
if (esp_lcd_touch_register_interrupt_callback(
|
||||||
*touch_handle, [](auto) { vTaskNotifyGiveFromISR(task, nullptr); })
|
touch_handle, [](auto) { vTaskNotifyGiveFromISR(task, nullptr); })
|
||||||
!= ESP_OK) {
|
!= ESP_OK) {
|
||||||
|
|
||||||
// No touch interrupt assigned or supported? Fall back to polling like esp_lvgl_port.
|
// No touch interrupt assigned or supported? Fall back to polling like esp_lvgl_port.
|
||||||
|
|
@ -179,11 +179,11 @@ void EspPlatform::run_event_loop()
|
||||||
uint8_t touchpad_cnt = 0;
|
uint8_t touchpad_cnt = 0;
|
||||||
|
|
||||||
/* Read touch controller data */
|
/* Read touch controller data */
|
||||||
esp_lcd_touch_read_data(*touch_handle);
|
esp_lcd_touch_read_data(touch_handle);
|
||||||
|
|
||||||
/* Get coordinates */
|
/* Get coordinates */
|
||||||
bool touchpad_pressed = esp_lcd_touch_get_coordinates(
|
bool touchpad_pressed = esp_lcd_touch_get_coordinates(
|
||||||
*touch_handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
|
touch_handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
|
||||||
|
|
||||||
if (touchpad_pressed && touchpad_cnt > 0) {
|
if (touchpad_pressed && touchpad_cnt > 0) {
|
||||||
// ESP_LOGI(TAG, "x: %i, y: %i", touchpad_x[0], touchpad_y[0]);
|
// ESP_LOGI(TAG, "x: %i, y: %i", touchpad_x[0], touchpad_y[0]);
|
||||||
|
|
@ -328,7 +328,7 @@ void slint_esp_init(slint::PhysicalSize size, esp_lcd_panel_handle_t panel,
|
||||||
SlintPlatformConfiguration config {
|
SlintPlatformConfiguration config {
|
||||||
.size = size,
|
.size = size,
|
||||||
.panel = panel,
|
.panel = panel,
|
||||||
.touch = touch,
|
.touch = touch ? *touch : nullptr,
|
||||||
.buffer1 = buffer1,
|
.buffer1 = buffer1,
|
||||||
.buffer2 = buffer2,
|
.buffer2 = buffer2,
|
||||||
// For compatibility with earlier versions of Slint, we compute the value of
|
// For compatibility with earlier versions of Slint, we compute the value of
|
||||||
|
|
@ -345,7 +345,7 @@ void slint_esp_init(slint::PhysicalSize size, esp_lcd_panel_handle_t panel,
|
||||||
{
|
{
|
||||||
SlintPlatformConfiguration config { .size = size,
|
SlintPlatformConfiguration config { .size = size,
|
||||||
.panel = panel,
|
.panel = panel,
|
||||||
.touch = touch,
|
.touch = touch ? *touch : nullptr,
|
||||||
.buffer1 = std::nullopt,
|
.buffer1 = std::nullopt,
|
||||||
.buffer2 = std::nullopt,
|
.buffer2 = std::nullopt,
|
||||||
.rotation = rotation,
|
.rotation = rotation,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue