Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions main/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,41 +230,19 @@ static void display_clear(void)
CONFIG_DISPLAY_OFFSET_X, CONFIG_DISPLAY_OFFSET_Y, CONFIG_DISPLAY_WIDTH, CONFIG_DISPLAY_HEIGHT, TFT_BLACK);
}

void display_init(TaskHandle_t* gui_h)
{
JADE_LOGI("display/screen init");
JADE_ASSERT(gui_h);
#ifdef CONFIG_LIBJADE
if (*gui_h) {
return; // Already initialized
}
#endif
JADE_ASSERT(!*gui_h);

JADE_ASSERT(power_screen_on() == ESP_OK);
vTaskDelay(100 / portTICK_PERIOD_MS);

#if defined(CONFIG_ETH_USE_OPENETH)
#if defined(CONFIG_HAS_CAMERA)
qemu_display_init();
#endif
#else
JADE_ASSERT(gui_h);
display_hw_init(gui_h);

#if defined(CONFIG_BOARD_TYPE_TTGO_TWATCHS3) || defined(CONFIG_BOARD_TYPE_M5_CORES3) \
|| defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
#define TOUCH_BUTTON_AREA 40
#define TOUCH_BUTTON_MARGIN 5
#define TOUCH_BUTTON_WIDTH 40
/* The TwatchS3 and core s3 don't have buttons that can be used (just power and
reset)
but it has a touch panel, we use the bottom 40 pixels worth of height
to display 3 buttons (prev, OK, next), we handle this here rather than
in display_hw because we want to draw text inside the virtual buttons */

vTaskDelay(50 / portTICK_PERIOD_MS);

/* The TwatchS3 and core s3 don't have buttons that can be used (just power and
reset)
but it has a touch panel, we use the bottom 40 pixels worth of height
to display 3 buttons (prev, OK, next), we handle this here rather than
in display_hw because we want to draw text inside the virtual buttons.
Called at startup and again whenever the display orientation is flipped,
as flipping remaps the panel and the navbar must be redrawn in place. */
void display_touch_navbar_redraw(void)
{
/* blank the bottom of the display with black */
uint16_t line[CONFIG_DISPLAY_WIDTH] = { TFT_BLACK };
for (int16_t i = 0; i < TOUCH_BUTTON_AREA; ++i) {
Expand All @@ -287,7 +265,35 @@ void display_init(TaskHandle_t* gui_h)
disp_win_virtual_buttons.x2 = (CONFIG_DISPLAY_WIDTH - TOUCH_BUTTON_MARGIN) + CONFIG_DISPLAY_OFFSET_X;
display_print_in_area("I", CENTER, CENTER, disp_win_virtual_buttons, 0);
display_set_font(DEFAULT_FONT);
}
#endif

void display_init(TaskHandle_t* gui_h)
{
JADE_LOGI("display/screen init");
JADE_ASSERT(gui_h);
#ifdef CONFIG_LIBJADE
if (*gui_h) {
return; // Already initialized
}
#endif
JADE_ASSERT(!*gui_h);

JADE_ASSERT(power_screen_on() == ESP_OK);
vTaskDelay(100 / portTICK_PERIOD_MS);

#if defined(CONFIG_ETH_USE_OPENETH)
#if defined(CONFIG_HAS_CAMERA)
qemu_display_init();
#endif
#else
JADE_ASSERT(gui_h);
display_hw_init(gui_h);

#if defined(CONFIG_BOARD_TYPE_TTGO_TWATCHS3) || defined(CONFIG_BOARD_TYPE_M5_CORES3) \
|| defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
vTaskDelay(50 / portTICK_PERIOD_MS);
display_touch_navbar_redraw();
vTaskDelay(50 / portTICK_PERIOD_MS);
#endif
#endif
Expand Down
11 changes: 11 additions & 0 deletions main/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ extern const color_t TFT_PINK;

void display_init(TaskHandle_t* gui_h);
bool display_flip_orientation(bool flipped_orientation);

// Height in pixels of the touch area reserved below the main display for the
// virtual navigation buttons (or the fixed capacitive strip on the M5 Core2)
#define TOUCH_BUTTON_AREA 40

#if defined(CONFIG_BOARD_TYPE_TTGO_TWATCHS3) || defined(CONFIG_BOARD_TYPE_M5_CORES3) \
|| defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
void display_touch_navbar_redraw(void);
#else
static inline void display_touch_navbar_redraw(void) {}
#endif
Icon* get_icon(const uint8_t* start, const uint8_t* end);
Picture* get_picture(const uint8_t* start, const uint8_t* end);
void display_picture(const Picture* imgbuf, int x, int y, dispWin_t area);
Expand Down
7 changes: 6 additions & 1 deletion main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ bool gui_get_flipped_orientation(void) { return gui_orientation_flipped; }

bool gui_set_flipped_orientation(const bool flipped_orientation)
{
gui_orientation_flipped = display_flip_orientation(flipped_orientation);
const bool new_orientation = display_flip_orientation(flipped_orientation);
if (gui_orientation_flipped != new_orientation) {
gui_orientation_flipped = new_orientation;
// Redraw the virtual navbar buttons (if any) at their new position
display_touch_navbar_redraw();
}
return gui_orientation_flipped;
}

Expand Down
26 changes: 22 additions & 4 deletions main/input/touchscreen.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ static void touchscreen_task(void* ignored)
{
esp_lcd_touch_handle_t ret_touch = NULL;
// FIXME: check mirror flags?
// NOTE: the touch panel extends below the main display over the navigation button
// area - y_max must cover it, as it is used when mirroring coordinates on flip
const esp_lcd_touch_config_t tp_cfg = {
.x_max = CONFIG_DISPLAY_WIDTH + CONFIG_DISPLAY_OFFSET_X,
.y_max = CONFIG_DISPLAY_HEIGHT + CONFIG_DISPLAY_OFFSET_Y,
.y_max = CONFIG_DISPLAY_HEIGHT + CONFIG_DISPLAY_OFFSET_Y + TOUCH_BUTTON_AREA,
.rst_gpio_num = GPIO_NUM_NC,
.int_gpio_num = GPIO_NUM_NC,
.levels = {
Expand Down Expand Up @@ -65,17 +67,30 @@ static void touchscreen_task(void* ignored)
uint16_t touch_strength[1];
uint8_t touch_cnt = 10;

#if !defined(CONFIG_BOARD_TYPE_M5_CORE2)
// Track the display orientation and mirror the touch coordinates to match, so the
// virtual navbar buttons keep working when the display is flipped. Not on the M5
// Core2, where the buttons are silk-screened on a fixed strip below the display.
bool touch_mirrored = false;
#endif

// FIXME: don't allow multiple touches within 300 ms?
// FIXME: this doesn't currently work with Display -> Flip Orientation feature
// but it could by changing the touch_y[0] > 200 logic with < 40 and inverting prev with next and viceversa
while (!shutdown_requested) {
#if !defined(CONFIG_BOARD_TYPE_M5_CORE2)
const bool flipped = gui_get_flipped_orientation();
if (touch_mirrored != flipped) {
ESP_ERROR_CHECK(esp_lcd_touch_set_mirror_x(ret_touch, flipped));
ESP_ERROR_CHECK(esp_lcd_touch_set_mirror_y(ret_touch, flipped));
touch_mirrored = flipped;
}
#endif
if (esp_lcd_touch_read_data(ret_touch) == ESP_OK) {
bool touchpad_pressed
= esp_lcd_touch_get_coordinates(ret_touch, touch_x, touch_y, touch_strength, &touch_cnt, 1);
if (touchpad_pressed) {
const uint16_t first_third_end = CONFIG_DISPLAY_WIDTH / 3;
const uint16_t middle_thirds_end = (CONFIG_DISPLAY_WIDTH * 2) / 3;
if (touch_y[0] > 200) {
if (touch_y[0] > CONFIG_DISPLAY_HEIGHT + CONFIG_DISPLAY_OFFSET_Y) {
if (touch_x[0] <= first_third_end) {
gui_prev();
} else if (touch_x[0] > first_third_end && touch_x[0] < middle_thirds_end) {
Expand All @@ -91,6 +106,9 @@ static void touchscreen_task(void* ignored)
}
vTaskDelay(20 / portTICK_PERIOD_MS);
}
// Since IDF 5.5 the i2c bus cannot be deleted while devices are still attached
ESP_ERROR_CHECK(esp_lcd_touch_del(ret_touch));
ESP_ERROR_CHECK(esp_lcd_panel_io_del(tp_io_handle));
ESP_ERROR_CHECK(_i2c_deinit(touch_i2c_handle));
shutdown_finished = true;
vTaskDelete(NULL);
Expand Down
3 changes: 3 additions & 0 deletions main/power/m5stackcores3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ esp_err_t power_init(void)
axp2101_init();

vTaskDelay(100 / portTICK_PERIOD_MS);
// Since IDF 5.5 the i2c bus cannot be deleted while devices are still attached
I2C_CHECK_RET(i2c_master_bus_rm_device(axp2101));
I2C_CHECK_RET(i2c_master_bus_rm_device(aw9523));
I2C_CHECK_RET(_i2c_deinit(NULL));

return ESP_OK;
Expand Down