Skip to content

Commit 00cfed4

Browse files
committed
upscale, enable calibrate touchUI
1 parent 053fa69 commit 00cfed4

File tree

3 files changed

+167
-74
lines changed

3 files changed

+167
-74
lines changed

Marlin/Configuration.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2084,8 +2084,8 @@
20842084
//
20852085
// ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
20862086
//
2087-
//@ still to do
2088-
//#define TOUCH_BUTTONS
2087+
//@ testing
2088+
#define TOUCH_BUTTONS
20892089
#if ENABLED(TOUCH_BUTTONS)
20902090
#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
20912091
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus

Marlin/src/feature/touch/xpt2046.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ uint8_t XPT2046::read_buttons() {
7878
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
7979
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
8080

81-
if (y < 175 || y > 234) return 0;
81+
//@ little more Y
82+
if (y < 165 || y > 234) return 0;
8283

8384
return WITHIN(x, 14, 77) ? EN_D
8485
: WITHIN(x, 90, 153) ? EN_A

Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp

+163-71
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,25 @@
5858
/*
5959
modified by alpine to 3x upscale for 3.5 TFT of the TwoTrees Sapphire Pro
6060
61-
ToDo:
62-
* touchUI in general
63-
* check touch control to match hotzones to desired design
64-
*
65-
66-
* make selectable upscale options (own class)
61+
ToDo:
62+
63+
* done - linear upscale algorithm to safe cpu
64+
* color selection / temperature indicator
65+
(see old MKS version)
66+
* G-Code control ("on/off"/"brightness"/color profiles)
67+
* nyan cat
68+
69+
longterm:
70+
* make selectable upscale options (in own classes)
6771
* configurable through main/board config
68-
*
69-
70-
for 480x320 px
72+
* submit to marlin
73+
74+
done:
75+
* touchUI in general --> done
76+
* check touch control to match hotzones to desired design --> done
77+
(not quite exact but reasonable close)
7178
72-
desired screen arrangement:
73-
74-
<-- 480 px -->
75-
__________________________
76-
|_| top offset: 32 px |_|
77-
|_|______________________|_| /\
78-
| | Marlin display |_| |
79-
| | 384*192 px |_| |
80-
|_|______________________|_| 320 px
81-
|_| middle spacing 16 px |_| |
82-
|_|______________________|_| |
83-
| | touch UI: 384*64 px |_| \/
84-
| | element Y: 2+60+2 px |_|
85-
|_|______________________|_|
86-
|_| bottom offset: 16 px |_|
87-
|_|______________________|_|
88-
^- left offset: ^- right offset:
89-
48 px 48 px
90-
*/
79+
*/
9180

9281
#include "../../inc/MarlinConfig.h"
9382

@@ -105,6 +94,27 @@
10594
extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
10695
#endif
10796

97+
/*
98+
desired screen arrangement:
99+
100+
(0/0) <-- 480 px -->
101+
\/_________________________
102+
|_| top offset: y 32 px |_|
103+
|_|______________________|_| /\
104+
| | Marlin display |_| |
105+
| | 384*192 px |_| |
106+
|_|______________________|_| 320 px
107+
|_| middle spacing 16 px |_| |
108+
|_|______________________|_| |
109+
|| touch UI: 384*64 px || \/
110+
|| UIelement Y 2+60+2 px ||
111+
||________________________||
112+
|_| bottom offset y 16 px|_|
113+
|_|______________________|_|<- (479/319)
114+
^- left offset: ^- right offset:
115+
48 px 48 px
116+
*/
117+
108118
#define WIDTH LCD_PIXEL_WIDTH
109119
#define HEIGHT LCD_PIXEL_HEIGHT
110120
#define PAGE_HEIGHT 8
@@ -119,6 +129,37 @@
119129
#define LCD_ROW 0x2B /* Row address register */
120130
#define LCD_WRITE_RAM 0x2C
121131

132+
/*
133+
Touch UI
134+
||----------------------------||
135+
|| middle spacing 384*16px ||
136+
||----------------------------||/___ y = 242 px
137+
|| ELX | | ELA || ELB | | ELC ||\
138+
x ||^24 ^136 ^248 ^360 ||/___ y = 301 px
139+
||----------------------------||\
140+
24 px + 96*4 px + 16*3 px + 24 px
141+
*/
142+
143+
#define BUTTON_SIZE_X 32
144+
#define BUTTON_SIZE_Y 20
145+
146+
#define BUTTOND_X_LO 24
147+
#define BUTTOND_X_HI (BUTTOND_X_LO + 3 * BUTTON_SIZE_X -1)
148+
149+
#define BUTTONA_X_LO 136
150+
#define BUTTONA_X_HI (BUTTONA_X_LO + 3 * BUTTON_SIZE_X -1)
151+
152+
#define BUTTONB_X_LO 248
153+
#define BUTTONB_X_HI (BUTTONB_X_LO + 3 * BUTTON_SIZE_X -1)
154+
155+
#define BUTTONC_X_LO 360
156+
#define BUTTONC_X_HI (BUTTONC_X_LO + 3 * BUTTON_SIZE_X -1)
157+
158+
#define BUTTON_Y_LO 242
159+
#define BUTTON_Y_HI (BUTTON_Y_LO + 3 * BUTTON_SIZE_Y -1)
160+
161+
162+
122163
// see https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
123164

124165
#define COLOR_BLACK 0x0000 // #000000
@@ -151,19 +192,19 @@
151192
#define TFT_MARLINUI_COLOR COLOR_WHITE
152193
#endif
153194
#ifndef TFT_MARLINBG_COLOR
154-
#define TFT_MARLINBG_COLOR COLOR_BLACK
195+
#define TFT_MARLINBG_COLOR COLOR_NAVY
155196
#endif
156197
#ifndef TFT_DISABLED_COLOR
157198
#define TFT_DISABLED_COLOR COLOR_DARK
158199
#endif
159200
#ifndef TFT_BTCANCEL_COLOR
160-
#define TFT_BTCANCEL_COLOR COLOR_RED
201+
#define TFT_BTCANCEL_COLOR COLOR_WHITE
161202
#endif
162203
#ifndef TFT_BTARROWS_COLOR
163-
#define TFT_BTARROWS_COLOR COLOR_BLUE
204+
#define TFT_BTARROWS_COLOR COLOR_WHITE
164205
#endif
165206
#ifndef TFT_BTOKMENU_COLOR
166-
#define TFT_BTOKMENU_COLOR COLOR_RED
207+
#define TFT_BTOKMENU_COLOR COLOR_WHITE
167208
#endif
168209

169210
static uint32_t lcd_id = 0;
@@ -186,6 +227,7 @@ static const uint8_t clear_screen_sequence[] = {
186227

187228
//@ ToDo
188229
// check positions for new offsets
230+
// --> done. see marlin/src/feature/touch/xpt2046.cpp
189231

190232
#if ENABLED(TOUCH_BUTTONS)
191233

@@ -204,29 +246,29 @@ static const uint8_t clear_screen_sequence[] = {
204246
};
205247

206248
static const uint8_t buttonD_sequence[] = {
207-
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(14), U8G_ESC_DATA(77),
208-
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
249+
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTOND_X_LO), U8G_ESC_DATA(BUTTOND_X_HI),
250+
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTON_Y_LO), U8G_ESC_DATA(BUTTON_Y_HI),
209251
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
210252
U8G_ESC_END
211253
};
212254

213255
static const uint8_t buttonA_sequence[] = {
214-
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(90), U8G_ESC_DATA(153),
215-
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
256+
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTONA_X_LO), U8G_ESC_DATA(BUTTONA_X_HI),
257+
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTON_Y_LO), U8G_ESC_DATA(BUTTON_Y_HI),
216258
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
217259
U8G_ESC_END
218260
};
219261

220262
static const uint8_t buttonB_sequence[] = {
221-
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(166), U8G_ESC_DATA(229),
222-
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
263+
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTONB_X_LO), U8G_ESC_DATA(BUTTONB_X_HI),
264+
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTON_Y_LO), U8G_ESC_DATA(BUTTON_Y_HI),
223265
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
224266
U8G_ESC_END
225267
};
226268

227269
static const uint8_t buttonC_sequence[] = {
228-
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(242), U8G_ESC_DATA(305),
229-
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(185), U8G_ESC_DATA(224),
270+
U8G_ESC_ADR(0), LCD_COLUMN, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTONC_X_LO), U8G_ESC_DATA(BUTTONC_X_HI),
271+
U8G_ESC_ADR(0), LCD_ROW, U8G_ESC_ADR(1), U8G_ESC_DATA(BUTTON_Y_LO), U8G_ESC_DATA(BUTTON_Y_HI),
230272
U8G_ESC_ADR(0), LCD_WRITE_RAM, U8G_ESC_ADR(1),
231273
U8G_ESC_END
232274
};
@@ -430,28 +472,61 @@ static const uint8_t ili9341_init_sequence[] = { // 0x9341 - ILI9341
430472
// *check if other parts of marlin use drawImage
431473

432474
void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
433-
uint16_t buffer[128];
475+
static uint16_t p_buffer[288];
476+
uint16_t* buffer = &p_buffer[0];
434477

435478
for (uint16_t i = 0; i < height; i++) {
436-
uint16_t k = 0;
479+
uint32_t k = 0;
437480
for (uint16_t j = 0; j < length; j++) {
438481
uint16_t v = TFT_MARLINBG_COLOR;
439482
if (*(data + (i * (length >> 3) + (j >> 3))) & (0x80 >> (j & 7)))
440483
v = color;
441484
else
442485
v = TFT_MARLINBG_COLOR;
443-
buffer[k++] = v; buffer[k++] = v;
486+
487+
// linear write should be faster
488+
// optimize later
489+
//
490+
// buffer[k+96] = v;
491+
// buffer[k+192] = v;
492+
// buffer[k++] = v;
493+
// buffer[k+96] = v;
494+
// buffer[k+192] = v;
495+
// buffer[k++] = v;
496+
// buffer[k+96] = v;
497+
// buffer[k+192] = v;
498+
// buffer[k++] = v;
499+
500+
// upscale X 3x
501+
buffer[k++] = v;
502+
buffer[k++] = v;
503+
buffer[k++] = v;
444504
}
445505
#ifdef LCD_USE_DMA_FSMC
446-
if (k <= 80) { // generally is... for our buttons
447-
memcpy(&buffer[k], &buffer[0], k * sizeof(uint16_t));
506+
// if (k <= 80) { // generally is... for our buttons
507+
// memcpy(&buffer[k], &buffer[0], k * sizeof(uint16_t));
448508

449-
LCD_IO_WriteSequence(buffer, k * sizeof(uint16_t));
509+
// LCD_IO_WriteSequence(buffer, k * sizeof(uint16_t));
510+
// }
511+
// else {
512+
// LCD_IO_WriteSequence(buffer, k);
513+
514+
// LCD_IO_WriteSequence(buffer, k);
515+
// }
516+
517+
// Upscale Y 3x
518+
// linear write should be faster for big arrays
519+
//
520+
for (uint16_t l = 0; l < 96; l++)
521+
{
522+
buffer[l+96] = buffer[l];
450523
}
451-
else {
452-
LCD_IO_WriteSequence(buffer, k);
453-
LCD_IO_WriteSequence(buffer, k);
524+
for (uint16_t l = 0; l < 96; l++)
525+
{
526+
buffer[l+192] = buffer[l];
454527
}
528+
529+
LCD_IO_WriteSequence(p_buffer, 288);
455530
#else
456531
u8g_WriteSequence(u8g, dev, k << 1, (uint8_t *)buffer);
457532
u8g_WriteSequence(u8g, dev, k << 1, (uint8_t *)buffer);
@@ -510,20 +585,22 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
510585
// bottom line and buttons
511586
#if ENABLED(TOUCH_BUTTONS)
512587

513-
#ifdef LCD_USE_DMA_FSMC
514-
u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_left);
515-
LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 300);
516-
u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_right);
517-
LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 300);
518-
#else
519-
memset2(buffer, TFT_DISABLED_COLOR, 150);
520-
u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_left);
521-
for (uint8_t i = 4; i--;)
522-
u8g_WriteSequence(u8g, dev, 150, (uint8_t *)buffer);
523-
u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_right);
524-
for (uint8_t i = 4; i--;)
525-
u8g_WriteSequence(u8g, dev, 150, (uint8_t *)buffer);
526-
#endif
588+
// why the linewrites
589+
590+
// #ifdef LCD_USE_DMA_FSMC
591+
// u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_left);
592+
// LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 300);
593+
// u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_right);
594+
// LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 300);
595+
// #else
596+
// memset2(buffer, TFT_DISABLED_COLOR, 150);
597+
// u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_left);
598+
// for (uint8_t i = 4; i--;)
599+
// u8g_WriteSequence(u8g, dev, 150, (uint8_t *)buffer);
600+
// u8g_WriteEscSeqP(u8g, dev, separation_line_sequence_right);
601+
// for (uint8_t i = 4; i--;)
602+
// u8g_WriteSequence(u8g, dev, 150, (uint8_t *)buffer);
603+
// #endif
527604

528605
//@ check button sizes
529606
u8g_WriteEscSeqP(u8g, dev, buttonD_sequence);
@@ -566,23 +643,38 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
566643
//buffer[k++] = c;
567644

568645
//@ 3x upscale X and Y in same loop
646+
// 1 px -> 3*3 px
569647
// resulting buffersize RGB565 * 1152 - 128*3*3
570-
// need to check what solution is faster
571648

572-
buffer[k+384] = c;
573-
buffer[k+768] = c;
649+
// sequential write should be faster
650+
// buffer[k+384] = c;
651+
// buffer[k+768] = c;
652+
// buffer[k++] = c;
653+
// buffer[k+384] = c;
654+
// buffer[k+768] = c;
655+
// buffer[k++] = c;
656+
// buffer[k+384] = c;
657+
// buffer[k+768] = c;
658+
// buffer[k++] = c;
574659
buffer[k++] = c;
575-
buffer[k+384] = c;
576-
buffer[k+768] = c;
577660
buffer[k++] = c;
578-
buffer[k+384] = c;
579-
buffer[k+768] = c;
580661
buffer[k++] = c;
581662
}
582663
#ifdef LCD_USE_DMA_FSMC
583664
//@ 2x upscale Y
584665
// resulting buffersize RGB565 * 512 - 256*2
585666
//memcpy(&buffer[256], &buffer[0], 512);
667+
// Upscale Y 3x
668+
// linear write should be faster for big arrays
669+
//
670+
for (uint16_t l = 0; l < 384; l++)
671+
{
672+
buffer[l+384] = buffer[l];
673+
}
674+
for (uint16_t l = 0; l < 384; l++)
675+
{
676+
buffer[l+768] = buffer[l];
677+
}
586678

587679
if (allow_async) {
588680
if (y > 0 || page > 1) LCD_IO_WaitSequence_Async();
@@ -594,7 +686,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
594686
LCD_IO_WriteSequence_Async(buffer, 1152);
595687
}
596688
else
597-
LCD_IO_WriteSequence(buffer, 512);
689+
LCD_IO_WriteSequence(buffer, 1152);
598690
#else
599691
uint8_t* bufptr = (uint8_t*) buffer;
600692
for (uint8_t i = 2; i--;) {

0 commit comments

Comments
 (0)