Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Back' Button for Touch TFT 320x240 #15060

Merged
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@
//=============================================================================

//
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, A1, etc.)
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
//
//#define FSMC_GRAPHICAL_TFT

Expand Down
12 changes: 12 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,18 @@
//#define TOUCH_UI_PASSCODE
#endif

//
// FSMC Graphical TFT
//
#if ENABLED(FSMC_GRAPHICAL_TFT)
//#define TFT_MARLINUI_COLOR 0xFFFF // White
//#define TFT_MARLINBG_COLOR 0x0000 // Black
//#define TFT_DISABLED_COLOR 0x0003 // Almost black
//#define TFT_BTCANCEL_COLOR 0xF800 // Red
//#define TFT_BTARROWS_COLOR 0xDEE6 // 11011 110111 00110 Yellow
//#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan
#endif

// @section safety

/**
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/feature/touch/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ uint8_t XPT2046::read_buttons() {

if (y < 175 || y > 234) return 0;

return WITHIN(x, 11, 109) ? EN_A
: WITHIN(x, 111, 209) ? EN_B
: WITHIN(x, 211, 309) ? EN_C
return WITHIN(x, 14, 77) ? EN_D
: WITHIN(x, 90, 153) ? EN_A
: WITHIN(x, 166, 229) ? EN_B
: WITHIN(x, 242, 305) ? EN_C
: 0;
}

Expand Down
215 changes: 128 additions & 87 deletions Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
#define COLOR_BLUE 0x21DD
#define COLOR_RED 0xF800
#define COLOR_DARK 0x0003 // Some dark color
#define COLOR_GREY 0x39E7
#define COLOR_YELLOW 0xEFC0
#define COLOR_ORANGE 0xFC00
#define COLOR_GREEN 0x77E0

#ifndef TFT_MARLINUI_COLOR
#define TFT_MARLINUI_COLOR COLOR_WHITE
Expand All @@ -100,11 +104,14 @@
#ifndef TFT_DISABLED_COLOR
#define TFT_DISABLED_COLOR COLOR_DARK
#endif
#ifndef TFT_BTSLEFT_COLOR
#define TFT_BTSLEFT_COLOR COLOR_BLUE
#ifndef TFT_BTCANCEL_COLOR
#define TFT_BTCANCEL_COLOR COLOR_RED
#endif
#ifndef TFT_BTRIGHT_COLOR
#define TFT_BTRIGHT_COLOR COLOR_RED
#ifndef TFT_BTARROWS_COLOR
#define TFT_BTARROWS_COLOR COLOR_BLUE
#endif
#ifndef TFT_BTOKMENU_COLOR
#define TFT_BTOKMENU_COLOR COLOR_RED
#endif

static uint32_t lcd_id = 0;
Expand Down Expand Up @@ -141,22 +148,29 @@ static const uint8_t clear_screen_sequence[] = {
U8G_ESC_END
};

static const uint8_t button0_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(20), U8G_ESC_DATA(99),
static const uint8_t buttonD_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(14), U8G_ESC_DATA(77),
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
U8G_ESC_END
};

static const uint8_t buttonA_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(90), U8G_ESC_DATA(153),
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
U8G_ESC_END
};

static const uint8_t button1_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(120), U8G_ESC_DATA(199),
static const uint8_t buttonB_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(166), U8G_ESC_DATA(229),
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
U8G_ESC_END
};

static const uint8_t button2_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(220), U8G_ESC_DATA(299),
static const uint8_t buttonC_sequence[] = {
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(242), U8G_ESC_DATA(305),
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
U8G_ESC_END
Expand Down Expand Up @@ -213,77 +227,100 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341

#if ENABLED(TOUCH_BUTTONS)

static const uint8_t button0[] = {
B01111111,B11111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B01000000,B00010000,B00000000,B00000001,
B10000000,B11100000,B00010000,B00000000,B00000001,
B10000001,B11110000,B00010000,B00000000,B00000001,
B10000011,B11111000,B00010000,B00000000,B00000001,
B10000111,B11111100,B00010000,B11111111,B11100001,
B10000000,B11100000,B00010000,B11111111,B11100001,
B10000000,B11100000,B00010000,B00000000,B00000001,
B10000000,B11100000,B00010000,B00000000,B00000001,
B10000000,B11100000,B00010000,B00000000,B00000001,
B10000000,B11100000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111111,B11111110,
static const uint8_t buttonD[] = {
B01111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00011000,B00110000,B00000001,
B10000000,B00001100,B01100000,B00000001,
B10000000,B00000110,B11000000,B00000001,
B10000000,B00000011,B10000000,B00000001,
B10000000,B00000011,B10000000,B00000001,
B10000000,B00000110,B11000000,B00000001,
B10000000,B00001100,B01100000,B00000001,
B10000000,B00011000,B00110000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111110,
};
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved

static const uint8_t buttonA[] = {
B01111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B01000000,B00000000,B00000001,
B10000000,B11100000,B00000000,B00000001,
B10000001,B11110000,B00000000,B00000001,
B10000011,B11111000,B00000000,B00000001,
B10000111,B11111100,B00111111,B11100001,
B10000000,B11100000,B00111111,B11100001,
B10000000,B11100000,B00000000,B00000001,
B10000000,B11100000,B00000000,B00000001,
B10000000,B11100000,B00000000,B00000001,
B10000000,B11100000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111110,
};

static const uint8_t button1[] = {
B01111111,B11111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B11111111,B11110001,
B10000111,B11111100,B00010000,B11111111,B11110001,
B10000011,B11111000,B00010000,B00000110,B00000001,
B10000001,B11110000,B00010000,B00000110,B00000001,
B10000000,B11100000,B00010000,B00000110,B00000001,
B10000000,B01000000,B00010000,B00000110,B00000001,
B10000000,B00000000,B00010000,B00000110,B00000001,
B10000000,B00000000,B00010000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111111,B11111110,
static const uint8_t buttonB[] = {
B01111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B01100000,B00000111,B00000001,
B10000000,B01100000,B00000111,B00000001,
B10000000,B01100000,B00000111,B00000001,
B10000000,B01100000,B00000111,B00000001,
B10000111,B11111110,B00000111,B00000001,
B10000111,B11111110,B00111111,B11100001,
B10000000,B01100000,B00011111,B11000001,
B10000000,B01100000,B00001111,B10000001,
B10000000,B01100000,B00000111,B00000001,
B10000000,B01100000,B00000010,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111110,
};

static const uint8_t button2[] = {
B01111111,B11111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000001,B11000000,B00000001,
B10000000,B00000000,B01000001,B11000000,B00000001,
B10000000,B00000000,B11000001,B11000000,B00000001,
B10000000,B00000001,B11111111,B11000000,B00000001,
B10000000,B00000011,B11111111,B11000000,B00000001,
B10000000,B00000001,B11111111,B11000000,B00000001,
B10000000,B00000000,B11000000,B00000000,B00000001,
B10000000,B00000000,B01000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111111,B11111110,
static const uint8_t buttonC[] = {
B01111111,B11111111,B11111111,B11111110,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00011100,B00000001,
B10000000,B00000100,B00011100,B00000001,
B10000000,B00001100,B00011100,B00000001,
B10000000,B00011111,B11111100,B00000001,
B10000000,B00111111,B11111100,B00000001,
B10000000,B00011111,B11111100,B00000001,
B10000000,B00001100,B00000000,B00000001,
B10000000,B00000100,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B10000000,B00000000,B00000000,B00000001,
B01111111,B11111111,B11111111,B11111110,
};

void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
uint16_t buffer[160];
uint16_t buffer[128];

for (uint16_t i = 0; i < height; i++) {
uint16_t k = 0;
Expand Down Expand Up @@ -332,7 +369,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
uint16_t* buffer = &bufferA[0];
bool allow_async = true;
#else
uint16_t buffer[256]; // 16-bit RGB 565 pixel line buffer
uint16_t buffer[WIDTH*2]; // 16-bit RGB 565 pixel line buffer
#endif
switch (msg) {
case U8G_DEV_MSG_INIT:
Expand All @@ -350,6 +387,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
}

// Clear Screen Sequence
u8g_WriteEscSeqP(u8g, dev, clear_screen_sequence);
#ifdef LCD_USE_DMA_FSMC
LCD_IO_WriteMultiple(TFT_MARLINBG_COLOR, (320*240));
Expand Down Expand Up @@ -377,15 +415,17 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
u8g_WriteSequence(u8g, dev, 150, (uint8_t *)buffer);
#endif

u8g_WriteEscSeqP(u8g, dev, button0_sequence);
drawImage(button0, u8g, dev, 40, 20, TFT_BTSLEFT_COLOR);
u8g_WriteEscSeqP(u8g, dev, buttonD_sequence);
drawImage(buttonD, u8g, dev, 32, 20, TFT_BTCANCEL_COLOR);

u8g_WriteEscSeqP(u8g, dev, button1_sequence);
drawImage(button1, u8g, dev, 40, 20, TFT_BTSLEFT_COLOR);
u8g_WriteEscSeqP(u8g, dev, buttonA_sequence);
drawImage(buttonA, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);

u8g_WriteEscSeqP(u8g, dev, button2_sequence);
drawImage(button2, u8g, dev, 40, 20, TFT_BTRIGHT_COLOR);
u8g_WriteEscSeqP(u8g, dev, buttonB_sequence);
drawImage(buttonB, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);

u8g_WriteEscSeqP(u8g, dev, buttonC_sequence);
drawImage(buttonC, u8g, dev, 32, 20, TFT_BTOKMENU_COLOR);
#endif // TOUCH_BUTTONS

return 0;
Expand All @@ -398,9 +438,9 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
break;

case U8G_DEV_MSG_PAGE_NEXT:
if (++page > 8) return 1;
if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;

for (uint8_t y = 0; y < 8; y++) {
for (uint8_t y = 0; y < PAGE_HEIGHT; y++) {
uint32_t k = 0;
#ifdef LCD_USE_DMA_FSMC
buffer = (y & 1) ? bufferB : bufferA;
Expand All @@ -422,11 +462,12 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
else
LCD_IO_WriteSequence(buffer, 512);
#else
uint8_t* bufptr = (uint8_t*) buffer;
for (uint8_t i = 2; i--;) {
u8g_WriteSequence(u8g, dev, 128, (uint8_t*)buffer);
u8g_WriteSequence(u8g, dev, 128, (uint8_t*)&(buffer[64]));
u8g_WriteSequence(u8g, dev, 128, (uint8_t*)&(buffer[128]));
u8g_WriteSequence(u8g, dev, 128, (uint8_t*)&(buffer[192]));
u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[0]);
u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH]);
u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH*2]);
u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH*3]);
}
#endif
}
Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/lcd/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void MarlinUI::update() {
}
else wait_for_unclick = false;

#if HAS_DIGITAL_BUTTONS && BUTTON_EXISTS(BACK)
#if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS))
if (LCD_BACK_CLICKED()) {
quick_feedback();
goto_previous_screen();
Expand Down Expand Up @@ -885,6 +885,11 @@ void MarlinUI::update() {

#if ENABLED(TOUCH_BUTTONS)
touch_buttons = read_touch_buttons();
if (touch_buttons) {
#if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS
return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
#endif
}
#endif

#if ENABLED(REPRAPWORLD_KEYPAD)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@

#endif

#if BUTTON_EXISTS(BACK)
#if BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS)
#define BLEN_D 3
#define EN_D _BV(BLEN_D)
#define LCD_BACK_CLICKED() (buttons & EN_D)
Expand Down
2 changes: 1 addition & 1 deletion config/default/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@
//=============================================================================

//
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, A1, etc.)
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
//
//#define FSMC_GRAPHICAL_TFT

Expand Down
Loading