Skip to content
Open
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
133 changes: 98 additions & 35 deletions main/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,51 @@ static inline void switch_buffer(void)
}
#endif

static inline void draw_bitmap(int x, int y, int w, int h, const uint16_t* color_data);

#if defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
#define DISPLAY_TOUCH_NAV_BUTTON_AREA 40
#define DISPLAY_TOUCH_NAV_BUTTON_MARGIN 5
#define DISPLAY_TOUCH_NAV_BUTTON_WIDTH 40
static void draw_touch_nav_buttons(void)
{
uint16_t line[CONFIG_DISPLAY_WIDTH] = { TFT_BLACK };
for (int16_t i = 0; i < DISPLAY_TOUCH_NAV_BUTTON_AREA; ++i) {
draw_bitmap(CONFIG_DISPLAY_OFFSET_X, CONFIG_DISPLAY_HEIGHT + i + CONFIG_DISPLAY_OFFSET_Y,
CONFIG_DISPLAY_WIDTH + CONFIG_DISPLAY_OFFSET_X, 1, line);
}

const int16_t nav_y1 = CONFIG_DISPLAY_HEIGHT + DISPLAY_TOUCH_NAV_BUTTON_MARGIN + CONFIG_DISPLAY_OFFSET_Y;
const int16_t nav_y2 = (CONFIG_DISPLAY_HEIGHT + (DISPLAY_TOUCH_NAV_BUTTON_AREA - DISPLAY_TOUCH_NAV_BUTTON_MARGIN))
+ CONFIG_DISPLAY_OFFSET_Y;

const int16_t center = (CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X;
const int16_t left = DISPLAY_TOUCH_NAV_BUTTON_MARGIN + CONFIG_DISPLAY_OFFSET_X;
const int16_t right = (CONFIG_DISPLAY_WIDTH - DISPLAY_TOUCH_NAV_BUTTON_MARGIN) + CONFIG_DISPLAY_OFFSET_X;
const int16_t half_width = DISPLAY_TOUCH_NAV_BUTTON_WIDTH / 2;

const struct {
const char* symbol;
int16_t x1;
int16_t x2;
} buttons[] = { { "H", left, left + DISPLAY_TOUCH_NAV_BUTTON_WIDTH },
{ "J", center - half_width, center + half_width },
{ "I", right - DISPLAY_TOUCH_NAV_BUTTON_WIDTH, right } };

display_set_font(JADE_SYMBOLS_16x16_FONT, NULL);
for (size_t i = 0; i < sizeof(buttons) / sizeof(buttons[0]); ++i) {
const dispWin_t button_area
= { .x1 = buttons[i].x1, .y1 = nav_y1, .x2 = buttons[i].x2, .y2 = nav_y2 };
display_print_in_area(buttons[i].symbol, CENTER, CENTER, button_area, 0);
}
display_set_font(DEFAULT_FONT, NULL);
}

void display_touch_navbar_redraw(void) { draw_touch_nav_buttons(); }
#else
void display_touch_navbar_redraw(void) {}
#endif

static inline void draw_bitmap(int x, int y, int w, int h, const uint16_t* color_data)
{
// JADE_ASSERT(color_data == &_fg || color_data == disp_buf);
Expand Down Expand Up @@ -119,6 +164,45 @@ const color_t TFT_ORANGE = 0x20FD;
const color_t TFT_GREENYELLOW = 0xE5AF;
const color_t TFT_PINK = 0x19FE;

#if defined(CONFIG_BOARD_TYPE_TTGO_TWATCHS3) || defined(CONFIG_BOARD_TYPE_M5_CORES3) \
|| defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
static const uint16_t touch_button_area = 40;
static const uint16_t touch_button_margin = 5;
static const uint16_t touch_button_width = 40;

static void draw_touch_navbar(void)
{
/* Blank the nav area and draw the virtual navigation buttons */
vTaskDelay(50 / portTICK_PERIOD_MS);

uint16_t line[CONFIG_DISPLAY_WIDTH] = { TFT_BLACK };
for (uint16_t i = 0; i < touch_button_area; ++i) {
draw_bitmap(CONFIG_DISPLAY_OFFSET_X, CONFIG_DISPLAY_HEIGHT + i + CONFIG_DISPLAY_OFFSET_Y,
CONFIG_DISPLAY_WIDTH + CONFIG_DISPLAY_OFFSET_X, 1, line);
}

dispWin_t disp_win_virtual_buttons = { .x1 = touch_button_margin + CONFIG_DISPLAY_OFFSET_X,
.y1 = CONFIG_DISPLAY_HEIGHT + touch_button_margin + CONFIG_DISPLAY_OFFSET_Y,
.x2 = touch_button_width + CONFIG_DISPLAY_OFFSET_X,
.y2 = (CONFIG_DISPLAY_HEIGHT + (touch_button_area - touch_button_margin)) + CONFIG_DISPLAY_OFFSET_Y };

display_set_font(JADE_SYMBOLS_16x16_FONT, NULL);
display_print_in_area("H", CENTER, CENTER, disp_win_virtual_buttons, 0);

disp_win_virtual_buttons.x1 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) - (touch_button_width / 2);
disp_win_virtual_buttons.x2 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) + (touch_button_width / 2);
display_print_in_area("J", CENTER, CENTER, disp_win_virtual_buttons, 0);

disp_win_virtual_buttons.x1 = ((CONFIG_DISPLAY_WIDTH - touch_button_margin) + CONFIG_DISPLAY_OFFSET_X)
- touch_button_width;
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, NULL);

vTaskDelay(50 / portTICK_PERIOD_MS);
}
#endif

color_t _fg = TFT_WHITE;

static Font cfont = {
Expand Down Expand Up @@ -247,43 +331,15 @@ void display_init(TaskHandle_t* gui_h)
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
#if defined(CONFIG_BOARD_TYPE_TTGO_TWATCHS3) || defined(CONFIG_BOARD_TYPE_M5_CORES3)
/* 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);

/* 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) {
draw_bitmap(CONFIG_DISPLAY_OFFSET_X, CONFIG_DISPLAY_HEIGHT + i + CONFIG_DISPLAY_OFFSET_Y,
CONFIG_DISPLAY_WIDTH + CONFIG_DISPLAY_OFFSET_X, 1, line);
}

dispWin_t disp_win_virtual_buttons = { .x1 = TOUCH_BUTTON_MARGIN + CONFIG_DISPLAY_OFFSET_X,
.y1 = CONFIG_DISPLAY_HEIGHT + TOUCH_BUTTON_MARGIN + CONFIG_DISPLAY_OFFSET_Y,
.x2 = TOUCH_BUTTON_WIDTH + CONFIG_DISPLAY_OFFSET_X,
.y2 = (CONFIG_DISPLAY_HEIGHT + (TOUCH_BUTTON_AREA - TOUCH_BUTTON_MARGIN)) + CONFIG_DISPLAY_OFFSET_Y };

display_set_font(JADE_SYMBOLS_16x16_FONT, NULL);
display_print_in_area("H", CENTER, CENTER, disp_win_virtual_buttons, 0);
disp_win_virtual_buttons.x1 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) - (TOUCH_BUTTON_WIDTH / 2);
disp_win_virtual_buttons.x2 = ((CONFIG_DISPLAY_WIDTH / 2) + CONFIG_DISPLAY_OFFSET_X) + (TOUCH_BUTTON_WIDTH / 2);
display_print_in_area("J", CENTER, CENTER, disp_win_virtual_buttons, 0);
disp_win_virtual_buttons.x1
= ((CONFIG_DISPLAY_WIDTH - TOUCH_BUTTON_MARGIN) + CONFIG_DISPLAY_OFFSET_X) - TOUCH_BUTTON_WIDTH;
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, NULL);
reset). They use a touch panel and reserve the bottom 40 pixels for three
virtual buttons (prev, OK, next). */
draw_touch_navbar();
#endif

vTaskDelay(50 / portTICK_PERIOD_MS);
#if defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
display_touch_navbar_redraw();
#endif
#endif

Expand All @@ -305,6 +361,13 @@ bool display_flip_orientation(const bool flipped_orientation)
#endif
}

void display_touch_navbar_redraw(void)
{
#if defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
draw_touch_navbar();
#endif
}

typedef struct {
Icon* icon;
Picture* pic;
Expand Down
6 changes: 6 additions & 0 deletions main/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extern const color_t TFT_PINK;

void display_init(TaskHandle_t* gui_h);
bool display_flip_orientation(bool flipped_orientation);
void display_touch_navbar_redraw(void);
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 All @@ -101,4 +102,9 @@ int display_get_string_width(const char* str);
void display_set_font(uint8_t font, const char* font_file);
int display_get_font_height(void);
void display_flush(void);
#if defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
void display_touch_navbar_redraw(void);
#else
static inline void display_touch_navbar_redraw(void) {}
#endif
#endif /* DISPLAY_H_ */
5 changes: 4 additions & 1 deletion main/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ 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);
if (gui_orientation_flipped != display_flip_orientation(flipped_orientation)) {
gui_orientation_flipped = !gui_orientation_flipped;
display_touch_navbar_redraw();
}
return gui_orientation_flipped;
}

Expand Down
12 changes: 9 additions & 3 deletions main/input/touchscreen.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "gui.h"
#include "jade_assert.h"
#include "jade_tasks.h"

#if defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
// No PMU, so relevant power files will not have been included
#include "power/i2c.inc"
static const uint16_t display_touch_nav_button_area = 40;
#endif

#include <esp_lcd_touch.h>
Expand Down Expand Up @@ -66,16 +66,22 @@ static void touchscreen_task(void* ignored)
uint8_t touch_cnt = 10;

// 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 (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 defined(CONFIG_BOARD_TYPE_WS_TOUCH_LCD2)
const bool flipped = gui_get_flipped_orientation();
const uint16_t nav_y_start
= flipped ? CONFIG_DISPLAY_OFFSET_Y : CONFIG_DISPLAY_HEIGHT + CONFIG_DISPLAY_OFFSET_Y;
const uint16_t nav_y_end = nav_y_start + display_touch_nav_button_area;
if (touch_y[0] >= nav_y_start && touch_y[0] < nav_y_end) {
#else
if (touch_y[0] > 200) {
#endif
if (touch_x[0] <= first_third_end) {
gui_prev();
} else if (touch_x[0] > first_third_end && touch_x[0] < middle_thirds_end) {
Expand Down