Skip to content

Commit

Permalink
API review (esp-idf): Replace the use of std::optional<esp_lcd_touch_…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
tronical committed Jul 8, 2024
1 parent 877bf78 commit 01e8b9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/cpp/esp-idf/slint/include/slint-esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ struct SlintPlatformConfiguration
slint::PhysicalSize size;
/// The handle to the display as previously initialized by `bsp_display_new` or
/// `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.
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
/// calls esp_lcd_panel_draw_bitmap to flush the buffer to the screen.
std::optional<std::span<slint::platform::Rgb565Pixel>> buffer1 = {};
Expand Down
10 changes: 5 additions & 5 deletions api/cpp/esp-idf/slint/src/slint-esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct EspPlatform : public slint::platform::Platform
private:
slint::PhysicalSize size;
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>> buffer2;
bool color_swap_16;
Expand Down Expand Up @@ -127,7 +127,7 @@ void EspPlatform::run_event_loop()

if (touch_handle) {
if (esp_lcd_touch_register_interrupt_callback(
*touch_handle, [](auto) { vTaskNotifyGiveFromISR(task, nullptr); })
touch_handle, [](auto) { vTaskNotifyGiveFromISR(task, nullptr); })
!= ESP_OK) {

// No touch interrupt assigned or supported? Fall back to polling like esp_lvgl_port.
Expand Down Expand Up @@ -179,11 +179,11 @@ void EspPlatform::run_event_loop()
uint8_t touchpad_cnt = 0;

/* Read touch controller data */
esp_lcd_touch_read_data(*touch_handle);
esp_lcd_touch_read_data(touch_handle);

/* 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) {
// ESP_LOGI(TAG, "x: %i, y: %i", touchpad_x[0], touchpad_y[0]);
Expand Down Expand Up @@ -345,7 +345,7 @@ void slint_esp_init(slint::PhysicalSize size, esp_lcd_panel_handle_t panel,
{
SlintPlatformConfiguration config { .size = size,
.panel = panel,
.touch = touch,
.touch = touch ? *touch : nullptr,
.buffer1 = std::nullopt,
.buffer2 = std::nullopt,
.rotation = rotation,
Expand Down

0 comments on commit 01e8b9e

Please sign in to comment.