Emulated DOGM via HAL TFT, XPT IO (#19017)
This commit is contained in:
committed by
Scott Lahteine
parent
7dea6c53ed
commit
dded56c4bb
@ -82,14 +82,9 @@
|
||||
|
||||
#define U8G_COM_SSD_I2C_HAL u8g_com_arduino_ssd_i2c_fn
|
||||
|
||||
#if PIN_EXISTS(FSMC_CS)
|
||||
uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
|
||||
#define U8G_COM_HAL_FSMC_FN u8g_com_stm32duino_fsmc_fn
|
||||
#endif
|
||||
|
||||
#if ENABLED(SPI_GRAPHICAL_TFT)
|
||||
uint8_t u8g_com_stm32duino_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
|
||||
#define U8G_COM_HAL_FSMC_FN u8g_com_stm32duino_spi_fn
|
||||
#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
|
||||
uint8_t u8g_com_stm32duino_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
|
||||
#define U8G_COM_HAL_TFT_FN u8g_com_stm32duino_tft_fn
|
||||
#endif
|
||||
|
||||
#elif defined(TARGET_LPC1768)
|
||||
@ -122,6 +117,6 @@
|
||||
#ifndef U8G_COM_SSD_I2C_HAL
|
||||
#define U8G_COM_SSD_I2C_HAL u8g_com_null_fn
|
||||
#endif
|
||||
#ifndef U8G_COM_HAL_FSMC_FN
|
||||
#define U8G_COM_HAL_FSMC_FN u8g_com_null_fn
|
||||
#ifndef U8G_COM_HAL_TFT_FN
|
||||
#define U8G_COM_HAL_TFT_FN u8g_com_null_fn
|
||||
#endif
|
||||
|
@ -67,28 +67,24 @@
|
||||
#define HAS_LCD_IO 1
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_IO
|
||||
extern void LCD_IO_Init(uint8_t cs, uint8_t rs);
|
||||
extern uint16_t LCD_IO_ReadData(uint16_t Reg);
|
||||
extern uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
|
||||
extern void LCD_IO_WriteReg(uint16_t Reg);
|
||||
extern void LCD_IO_WriteData(uint16_t RegValue);
|
||||
extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
|
||||
extern void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length);
|
||||
extern void LCD_IO_WaitSequence_Async();
|
||||
extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
|
||||
#if ENABLED(SPI_GRAPHICAL_TFT)
|
||||
#include HAL_PATH(../../HAL, tft/tft_spi.h)
|
||||
#elif ENABLED(FSMC_GRAPHICAL_TFT)
|
||||
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
|
||||
#endif
|
||||
|
||||
TFT_IO tftio;
|
||||
|
||||
#define WIDTH LCD_PIXEL_WIDTH
|
||||
#define HEIGHT LCD_PIXEL_HEIGHT
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
#include "../scaled_tft.h"
|
||||
|
||||
#define UPSCALE0(M) ((M) * (FSMC_UPSCALE))
|
||||
#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
|
||||
#define UPSCALE(A,M) (UPSCALE0(M) + (A))
|
||||
#define X_HI (UPSCALE(LCD_PIXEL_OFFSET_X, WIDTH) - 1)
|
||||
#define Y_HI (UPSCALE(LCD_PIXEL_OFFSET_Y, HEIGHT) - 1)
|
||||
#define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
|
||||
#define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
|
||||
|
||||
// see https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
|
||||
|
||||
@ -156,7 +152,8 @@ static uint32_t lcd_id = 0;
|
||||
|
||||
static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
|
||||
#if HAS_LCD_IO
|
||||
#define IO_REG_DATA(R,D) do { LCD_IO_WriteReg(R); LCD_IO_WriteData(D); }while(0)
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
#define IO_REG_DATA(R,D) do { tftio.WriteReg(R); tftio.WriteData(D); }while(0)
|
||||
#else
|
||||
#define IO_REG_DATA(R,D) do { u8g_WriteByte(u8g, dev, R); u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&D); }while(0)
|
||||
#endif
|
||||
@ -174,7 +171,8 @@ static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_
|
||||
IO_REG_DATA(ILI9328_VASET, Xmin);
|
||||
|
||||
#if HAS_LCD_IO
|
||||
LCD_IO_WriteReg(ILI9328_WRITE_RAM);
|
||||
tftio.WriteReg(ILI9328_WRITE_RAM);
|
||||
tftio.DataTransferEnd();
|
||||
#else
|
||||
u8g_WriteByte(u8g, dev, ILI9328_WRITE_RAM);
|
||||
u8g_SetAddress(u8g, dev, 1);
|
||||
@ -183,19 +181,21 @@ static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_
|
||||
|
||||
static void setWindow_st7789v(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
|
||||
#if HAS_LCD_IO
|
||||
LCD_IO_WriteReg(ST7789V_CASET);
|
||||
LCD_IO_WriteData((Xmin >> 8) & 0xFF);
|
||||
LCD_IO_WriteData(Xmin & 0xFF);
|
||||
LCD_IO_WriteData((Xmax >> 8) & 0xFF);
|
||||
LCD_IO_WriteData(Xmax & 0xFF);
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
tftio.WriteReg(ST7789V_CASET);
|
||||
tftio.WriteData((Xmin >> 8) & 0xFF);
|
||||
tftio.WriteData(Xmin & 0xFF);
|
||||
tftio.WriteData((Xmax >> 8) & 0xFF);
|
||||
tftio.WriteData(Xmax & 0xFF);
|
||||
|
||||
LCD_IO_WriteReg(ST7789V_RASET);
|
||||
LCD_IO_WriteData((Ymin >> 8) & 0xFF);
|
||||
LCD_IO_WriteData(Ymin & 0xFF);
|
||||
LCD_IO_WriteData((Ymax >> 8) & 0xFF);
|
||||
LCD_IO_WriteData(Ymax & 0xFF);
|
||||
tftio.WriteReg(ST7789V_RASET);
|
||||
tftio.WriteData((Ymin >> 8) & 0xFF);
|
||||
tftio.WriteData(Ymin & 0xFF);
|
||||
tftio.WriteData((Ymax >> 8) & 0xFF);
|
||||
tftio.WriteData(Ymax & 0xFF);
|
||||
|
||||
LCD_IO_WriteReg(ST7789V_WRITE_RAM);
|
||||
tftio.WriteReg(ST7789V_WRITE_RAM);
|
||||
tftio.DataTransferEnd();
|
||||
#else
|
||||
u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_CASET); u8g_SetAddress(u8g, dev, 1);
|
||||
u8g_WriteByte(u8g, dev, (Xmin >> 8) & 0xFF);
|
||||
@ -227,17 +227,17 @@ void (*setWindow)(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint
|
||||
for (;;) {
|
||||
data = *sequence++;
|
||||
if (data != 0xFFFF) {
|
||||
LCD_IO_WriteData(data);
|
||||
tftio.WriteData(data);
|
||||
continue;
|
||||
}
|
||||
data = *sequence++;
|
||||
if (data == 0x7FFF) return;
|
||||
if (data == 0xFFFF) {
|
||||
LCD_IO_WriteData(data);
|
||||
tftio.WriteData(data);
|
||||
} else if (data & 0x8000) {
|
||||
delay(data & 0x7FFF);
|
||||
} else if ((data & 0xFF00) == 0) {
|
||||
LCD_IO_WriteReg(data);
|
||||
tftio.WriteReg(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -591,7 +591,7 @@ static const uint16_t st7796_init[] = {
|
||||
#define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1)
|
||||
|
||||
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[BUTTON_SIZE_X * sq(FSMC_UPSCALE)];
|
||||
uint16_t buffer[BUTTON_SIZE_X * sq(GRAPHICAL_TFT_UPSCALE)];
|
||||
|
||||
if (length > BUTTON_SIZE_X) return;
|
||||
|
||||
@ -603,16 +603,16 @@ static const uint16_t st7796_init[] = {
|
||||
v = color;
|
||||
else
|
||||
v = TFT_MARLINBG_COLOR;
|
||||
LOOP_L_N(n, FSMC_UPSCALE) buffer[k++] = v;
|
||||
LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = v;
|
||||
}
|
||||
#if HAS_LCD_IO
|
||||
LOOP_S_L_N(n, 1, FSMC_UPSCALE)
|
||||
LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
|
||||
for (uint16_t l = 0; l < UPSCALE0(length); l++)
|
||||
buffer[l + n * UPSCALE0(length)] = buffer[l];
|
||||
|
||||
LCD_IO_WriteSequence(buffer, length * sq(FSMC_UPSCALE));
|
||||
tftio.WriteSequence(buffer, length * sq(GRAPHICAL_TFT_UPSCALE));
|
||||
#else
|
||||
for (uint8_t i = FSMC_UPSCALE; i--;)
|
||||
for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;)
|
||||
u8g_WriteSequence(u8g, dev, k << 1, (uint8_t*)buffer);
|
||||
#endif
|
||||
}
|
||||
@ -632,22 +632,17 @@ static uint8_t page;
|
||||
uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
|
||||
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||
|
||||
#if ENABLED(SPI_GRAPHICAL_TFT)
|
||||
LCD_IO_Init(-1, -1);
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_IO
|
||||
static uint16_t bufferA[WIDTH * sq(FSMC_UPSCALE)], bufferB[WIDTH * sq(FSMC_UPSCALE)];
|
||||
static uint16_t bufferA[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)], bufferB[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)];
|
||||
uint16_t* buffer = &bufferA[0];
|
||||
bool allow_async = DISABLED(SPI_GRAPHICAL_TFT);
|
||||
#else
|
||||
uint16_t buffer[WIDTH * FSMC_UPSCALE]; // 16-bit RGB 565 pixel line buffer
|
||||
uint16_t buffer[WIDTH * GRAPHICAL_TFT_UPSCALE]; // 16-bit RGB 565 pixel line buffer
|
||||
#endif
|
||||
|
||||
switch (msg) {
|
||||
case U8G_DEV_MSG_INIT:
|
||||
dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, &lcd_id);
|
||||
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
switch (lcd_id & 0xFFFF) {
|
||||
case 0x8552: // ST7789V
|
||||
WRITE_ESC_SEQUENCE(st7789v_init);
|
||||
@ -682,6 +677,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
setWindow = (lcd_id & 0xFF000000) ? setWindow_st7789v : setWindow_ili9328;
|
||||
break;
|
||||
}
|
||||
tftio.DataTransferEnd();
|
||||
|
||||
if (preinit) {
|
||||
preinit = false;
|
||||
@ -689,13 +685,13 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
}
|
||||
|
||||
// Clear Screen
|
||||
setWindow(u8g, dev, 0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
|
||||
setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
|
||||
#if HAS_LCD_IO
|
||||
LCD_IO_WriteMultiple(TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
tftio.WriteMultiple(TFT_MARLINBG_COLOR, uint32_t(TFT_WIDTH) * (TFT_HEIGHT));
|
||||
#else
|
||||
memset2(buffer, TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) / 2);
|
||||
for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT) * sq(FSMC_UPSCALE); i++)
|
||||
u8g_WriteSequence(u8g, dev, LCD_FULL_PIXEL_WIDTH / 2, (uint8_t *)buffer);
|
||||
memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2);
|
||||
for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
|
||||
u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
|
||||
#endif
|
||||
|
||||
// Bottom buttons
|
||||
@ -719,7 +715,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
page = 0;
|
||||
setWindow(u8g, dev, LCD_PIXEL_OFFSET_X, LCD_PIXEL_OFFSET_Y, X_HI, Y_HI);
|
||||
setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
@ -733,26 +729,18 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
for (uint16_t i = 0; i < (uint32_t)pb->width; i++) {
|
||||
const uint8_t b = *(((uint8_t *)pb->buf) + i);
|
||||
const uint16_t c = TEST(b, y) ? TFT_MARLINUI_COLOR : TFT_MARLINBG_COLOR;
|
||||
LOOP_L_N(n, FSMC_UPSCALE) buffer[k++] = c;
|
||||
LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = c;
|
||||
}
|
||||
#if HAS_LCD_IO
|
||||
LOOP_S_L_N(n, 1, FSMC_UPSCALE)
|
||||
LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
|
||||
for (uint16_t l = 0; l < UPSCALE0(WIDTH); l++)
|
||||
buffer[l + n * UPSCALE0(WIDTH)] = buffer[l];
|
||||
|
||||
if (allow_async) {
|
||||
if (y > 0 || page > 1) LCD_IO_WaitSequence_Async();
|
||||
if (y == 7 && page == 8)
|
||||
LCD_IO_WriteSequence(buffer, COUNT(bufferA)); // last line of last page
|
||||
else
|
||||
LCD_IO_WriteSequence_Async(buffer, COUNT(bufferA));
|
||||
}
|
||||
else
|
||||
LCD_IO_WriteSequence(buffer, COUNT(bufferA));
|
||||
tftio.WriteSequence(buffer, COUNT(bufferA));
|
||||
#else
|
||||
uint8_t* bufptr = (uint8_t*) buffer;
|
||||
for (uint8_t i = FSMC_UPSCALE; i--;) {
|
||||
LOOP_S_L_N(n, 0, FSMC_UPSCALE * 2) {
|
||||
for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;) {
|
||||
LOOP_S_L_N(n, 0, GRAPHICAL_TFT_UPSCALE * 2) {
|
||||
u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH * n]);
|
||||
}
|
||||
}
|
||||
@ -770,6 +758,59 @@ 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);
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_FSMC_FN);
|
||||
static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
|
||||
|
||||
uint8_t u8g_com_stm32duino_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
|
||||
if (msgInitCount) {
|
||||
if (msg == U8G_COM_MSG_INIT) msgInitCount--;
|
||||
if (msgInitCount) return -1;
|
||||
}
|
||||
|
||||
static uint8_t isCommand;
|
||||
|
||||
switch (msg) {
|
||||
case U8G_COM_MSG_STOP: break;
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
|
||||
u8g_Delay(50);
|
||||
|
||||
tftio.Init();
|
||||
|
||||
if (arg_ptr) {
|
||||
*((uint32_t *)arg_ptr) = tftio.GetID();
|
||||
}
|
||||
isCommand = 0;
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
|
||||
isCommand = arg_val == 0 ? 1 : 0;
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_RESET:
|
||||
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_BYTE:
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
if (isCommand)
|
||||
tftio.WriteReg(arg_val);
|
||||
else
|
||||
tftio.WriteData((uint16_t)arg_val);
|
||||
tftio.DataTransferEnd();
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
for (uint8_t i = 0; i < arg_val; i += 2)
|
||||
tftio.WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
|
||||
tftio.DataTransferEnd();
|
||||
break;
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN);
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD && FSMC_CS
|
||||
|
@ -33,25 +33,6 @@
|
||||
|
||||
TFT SPI_TFT;
|
||||
|
||||
#ifndef SPI_TFT_MISO_PIN
|
||||
#define SPI_TFT_MISO_PIN PA6
|
||||
#endif
|
||||
#ifndef SPI_TFT_MOSI_PIN
|
||||
#define SPI_TFT_MOSI_PIN PA7
|
||||
#endif
|
||||
#ifndef SPI_TFT_SCK_PIN
|
||||
#define SPI_TFT_SCK_PIN PA5
|
||||
#endif
|
||||
#ifndef SPI_TFT_CS_PIN
|
||||
#define SPI_TFT_CS_PIN PD11
|
||||
#endif
|
||||
#ifndef SPI_TFT_DC_PIN
|
||||
#define SPI_TFT_DC_PIN PD10
|
||||
#endif
|
||||
#ifndef SPI_TFT_RST_PIN
|
||||
#define SPI_TFT_RST_PIN PC6
|
||||
#endif
|
||||
|
||||
// use SPI1 for the spi tft.
|
||||
void TFT::spi_init(uint8_t spiRate) {
|
||||
tftio.Init();
|
||||
@ -93,11 +74,11 @@ void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
|
||||
}
|
||||
|
||||
void TFT::LCD_init() {
|
||||
SPI_TFT_RST_H;
|
||||
TFT_RST_H;
|
||||
delay(150);
|
||||
SPI_TFT_RST_L;
|
||||
TFT_RST_L;
|
||||
delay(150);
|
||||
SPI_TFT_RST_H;
|
||||
TFT_RST_H;
|
||||
|
||||
tftio.DataTransferBegin(DATASIZE_8BIT);
|
||||
|
||||
@ -176,22 +157,22 @@ void TFT::LCD_init() {
|
||||
|
||||
LCD_clear(0x0000); //
|
||||
LCD_Draw_Logo();
|
||||
SPI_TFT_BLK_H;
|
||||
TFT_BLK_H;
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void TFT::LCD_clear(uint16_t color) {
|
||||
SetWindows(0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
|
||||
tftio.WriteMultiple(color, (uint32_t)(LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
SetWindows(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
|
||||
tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT));
|
||||
}
|
||||
|
||||
extern unsigned char bmp_public_buf[17 * 1024];
|
||||
|
||||
void TFT::LCD_Draw_Logo() {
|
||||
SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
||||
for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT); i ++) {
|
||||
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (LCD_FULL_PIXEL_WIDTH) * 2);
|
||||
tftio.WriteSequence((uint16_t *)bmp_public_buf, LCD_FULL_PIXEL_WIDTH);
|
||||
SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
|
||||
for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
|
||||
Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
|
||||
tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,11 @@
|
||||
#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
|
||||
#endif
|
||||
|
||||
#define SPI_TFT_RST_H OUT_WRITE(SPI_TFT_RST_PIN, HIGH)
|
||||
#define SPI_TFT_RST_L OUT_WRITE(SPI_TFT_RST_PIN, LOW)
|
||||
#define TFT_RST_H OUT_WRITE(TFT_RESET_PIN, HIGH)
|
||||
#define TFT_RST_L OUT_WRITE(TFT_RESET_PIN, LOW)
|
||||
|
||||
#define SPI_TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
|
||||
#define SPI_TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
|
||||
#define TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
|
||||
#define TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
|
||||
|
||||
class TFT {
|
||||
public:
|
||||
|
@ -653,10 +653,10 @@ char *creat_title_text() {
|
||||
i += 2;
|
||||
if (*p_index == 0x0000) *p_index = 0xC318;
|
||||
}
|
||||
SPI_TFT_CS_L;
|
||||
SPI_TFT_DC_H;
|
||||
TFT_CS_L;
|
||||
TFT_DC_H;
|
||||
SPI.dmaSend(bmp_public_buf, 400, true);
|
||||
SPI_TFT_CS_H;
|
||||
TFT_CS_H;
|
||||
|
||||
#else
|
||||
for (i = 0; i < 400;) {
|
||||
|
@ -34,8 +34,6 @@
|
||||
#include "pic_manager.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "../../../touch/xpt2046.h"
|
||||
|
||||
#include "../../../../MarlinCore.h"
|
||||
#include "../../../../module/temperature.h"
|
||||
#include "../../../../sd/cardreader.h"
|
||||
|
@ -51,11 +51,11 @@ XPT2046 touch;
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
#ifndef LCD_FULL_PIXEL_WIDTH
|
||||
#define LCD_FULL_PIXEL_WIDTH 480
|
||||
#ifndef TFT_WIDTH
|
||||
#define TFT_WIDTH 480
|
||||
#endif
|
||||
#ifndef LCD_FULL_PIXEL_HEIGHT
|
||||
#define LCD_FULL_PIXEL_HEIGHT 320
|
||||
#ifndef TFT_HEIGHT
|
||||
#define TFT_HEIGHT 320
|
||||
#endif
|
||||
|
||||
#if HAS_SPI_FLASH_FONT
|
||||
@ -135,7 +135,7 @@ void LCD_WriteRAM_Prepare(void) {
|
||||
|
||||
void tft_set_point(uint16_t x, uint16_t y, uint16_t point) {
|
||||
//if (DeviceCode == 0x9488) {
|
||||
if (x > (LCD_FULL_PIXEL_WIDTH) || y > (LCD_FULL_PIXEL_HEIGHT)) return;
|
||||
if (x > (TFT_WIDTH) || y > (TFT_HEIGHT)) return;
|
||||
//}
|
||||
tft_set_cursor(x, y);
|
||||
|
||||
@ -196,8 +196,8 @@ void ili9320_SetWindows(uint16_t StartX, uint16_t StartY, uint16_t width, uint16
|
||||
LCD_WriteReg(0x0053, yEnd);*/
|
||||
LCD_WriteReg(0x0050, StartY); // Specify the start/end positions of the window address in the horizontal direction by an address unit
|
||||
LCD_WriteReg(0x0051, yEnd); // Specify the start positions of the window address in the vertical direction by an address unit
|
||||
LCD_WriteReg(0x0052, (LCD_FULL_PIXEL_HEIGHT) - xEnd);
|
||||
LCD_WriteReg(0x0053, (LCD_FULL_PIXEL_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
|
||||
LCD_WriteReg(0x0052, (TFT_HEIGHT) - xEnd);
|
||||
LCD_WriteReg(0x0053, (TFT_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
|
||||
|
||||
}
|
||||
else {
|
||||
@ -231,16 +231,16 @@ void LCD_Clear(uint16_t Color) {
|
||||
|
||||
if (DeviceCode == 0x9488) {
|
||||
tft_set_cursor(0, 0);
|
||||
ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
||||
ili9320_SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
|
||||
LCD_WriteRAM_Prepare();
|
||||
#ifdef LCD_USE_DMA_FSMC
|
||||
LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
|
||||
#else
|
||||
//index = (LCD_FULL_PIXEL_HEIGHT) / 2 * (LCD_FULL_PIXEL_WIDTH);
|
||||
for (index = 0; index < (LCD_FULL_PIXEL_HEIGHT) * (LCD_FULL_PIXEL_WIDTH); index++)
|
||||
//index = (TFT_HEIGHT) / 2 * (TFT_WIDTH);
|
||||
for (index = 0; index < (TFT_HEIGHT) * (TFT_WIDTH); index++)
|
||||
LCD_IO_WriteData(Color);
|
||||
#endif
|
||||
//LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
//LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
|
||||
//while(index --) LCD_IO_WriteData(Color);
|
||||
}
|
||||
else if (DeviceCode == 0x5761) {
|
||||
@ -378,7 +378,7 @@ void init_tft() {
|
||||
for (i = 0; i < 65535; i++);
|
||||
LCD_IO_WriteReg(0x0029);
|
||||
|
||||
ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
||||
ili9320_SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
|
||||
LCD_Clear(0x0000);
|
||||
|
||||
OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
|
||||
@ -522,8 +522,8 @@ static bool get_point(int16_t *x, int16_t *y) {
|
||||
}
|
||||
|
||||
#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
|
||||
x = (LCD_FULL_PIXEL_WIDTH) - x;
|
||||
y = (LCD_FULL_PIXEL_HEIGHT) - y;
|
||||
x = (TFT_WIDTH) - x;
|
||||
y = (TFT_HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
return is_touched;
|
||||
|
@ -23,28 +23,28 @@
|
||||
|
||||
#include "../inc/MarlinConfig.h"
|
||||
|
||||
#ifndef FSMC_UPSCALE
|
||||
#define FSMC_UPSCALE 2
|
||||
#ifndef GRAPHICAL_TFT_UPSCALE
|
||||
#define GRAPHICAL_TFT_UPSCALE 2
|
||||
#endif
|
||||
|
||||
#ifndef LCD_FULL_PIXEL_WIDTH
|
||||
#if FSMC_UPSCALE == 3
|
||||
#define LCD_FULL_PIXEL_WIDTH 480
|
||||
#ifndef TFT_WIDTH
|
||||
#if GRAPHICAL_TFT_UPSCALE == 3
|
||||
#define TFT_WIDTH 480
|
||||
#else
|
||||
#define LCD_FULL_PIXEL_WIDTH 320
|
||||
#define TFT_WIDTH 320
|
||||
#endif
|
||||
#endif
|
||||
#ifndef LCD_FULL_PIXEL_HEIGHT
|
||||
#if FSMC_UPSCALE == 3
|
||||
#define LCD_FULL_PIXEL_HEIGHT 320
|
||||
#ifndef TFT_HEIGHT
|
||||
#if GRAPHICAL_TFT_UPSCALE == 3
|
||||
#define TFT_HEIGHT 320
|
||||
#else
|
||||
#define LCD_FULL_PIXEL_HEIGHT 240
|
||||
#define TFT_HEIGHT 240
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LCD_PIXEL_OFFSET_X
|
||||
#define LCD_PIXEL_OFFSET_X 48
|
||||
#ifndef TFT_PIXEL_OFFSET_X
|
||||
#define TFT_PIXEL_OFFSET_X 48
|
||||
#endif
|
||||
#ifndef LCD_PIXEL_OFFSET_Y
|
||||
#define LCD_PIXEL_OFFSET_Y 48
|
||||
#ifndef TFT_PIXEL_OFFSET_Y
|
||||
#define TFT_PIXEL_OFFSET_Y 48
|
||||
#endif
|
||||
|
112
Marlin/src/lcd/touch/touch_buttons.cpp
Normal file
112
Marlin/src/lcd/touch/touch_buttons.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_TOUCH_XPT2046
|
||||
|
||||
#include "touch_buttons.h"
|
||||
#include "../scaled_tft.h"
|
||||
|
||||
#include HAL_PATH(../../HAL, tft/xpt2046.h)
|
||||
XPT2046 touchIO;
|
||||
|
||||
#include "../../lcd/ultralcd.h" // For EN_C bit mask
|
||||
|
||||
/**
|
||||
* Draw and Touch processing
|
||||
*
|
||||
* LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
|
||||
* TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
|
||||
* TFT_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
|
||||
*
|
||||
* - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
|
||||
* - The DOGM pixels are is upscaled 2-3x (as needed) for display.
|
||||
* - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to
|
||||
* click and scroll-wheel events (emulating of a common DOGM display).
|
||||
*
|
||||
* TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
|
||||
* and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
|
||||
* new calibration values will be needed.
|
||||
*
|
||||
* The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
|
||||
* fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
|
||||
* navigate and select menu items. Both regions are touchable.
|
||||
*
|
||||
* The Marlin screen touchable area starts at TFT_PIXEL_OFFSET_X/Y (translated to SCREEN_PCT_LEFT/TOP)
|
||||
* and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_PCT_WIDTH/HEIGHT).
|
||||
*/
|
||||
|
||||
// Touch sensor resolution independent of display resolution
|
||||
#define TOUCH_SENSOR_WIDTH 320
|
||||
#define TOUCH_SENSOR_HEIGHT 240
|
||||
|
||||
#define SCREEN_PCT_WIDE(X) ((X) * (TOUCH_SENSOR_WIDTH) / (TFT_WIDTH))
|
||||
#define SCREEN_PCT_HIGH(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (TFT_HEIGHT))
|
||||
|
||||
#define SCREEN_PCT_LEFT SCREEN_PCT_WIDE(TFT_PIXEL_OFFSET_X)
|
||||
#define SCREEN_PCT_TOP SCREEN_PCT_HIGH(TFT_PIXEL_OFFSET_Y)
|
||||
#define SCREEN_PCT_WIDTH SCREEN_PCT_WIDE((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH))
|
||||
#define SCREEN_PCT_HEIGHT SCREEN_PCT_HIGH((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT))
|
||||
|
||||
// Coordinates in terms of 240-unit-tall touch area
|
||||
#define BUTTON_AREA_TOP 175
|
||||
#define BUTTON_AREA_BOT 234
|
||||
|
||||
TouchButtons touch;
|
||||
|
||||
void TouchButtons::init() { touchIO.Init(); }
|
||||
|
||||
uint8_t TouchButtons::read_buttons() {
|
||||
#ifdef HAS_SPI_LCD
|
||||
int16_t x, y;
|
||||
|
||||
if (!touchIO.getRawPoint(&x, &y)) return 0;
|
||||
|
||||
x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET;
|
||||
y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
|
||||
|
||||
#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
|
||||
x = TOUCH_SENSOR_WIDTH - x;
|
||||
y = TOUCH_SENSOR_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
// Touch within the button area simulates an encoder button
|
||||
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
|
||||
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;
|
||||
|
||||
if ( !WITHIN(x, SCREEN_PCT_LEFT, SCREEN_PCT_LEFT + SCREEN_PCT_WIDTH)
|
||||
|| !WITHIN(y, SCREEN_PCT_TOP, SCREEN_PCT_TOP + SCREEN_PCT_HEIGHT)
|
||||
) return 0;
|
||||
|
||||
// Column and row above BUTTON_AREA_TOP
|
||||
int8_t col = (x - (SCREEN_PCT_LEFT)) * (LCD_WIDTH) / (SCREEN_PCT_WIDTH),
|
||||
row = (y - (SCREEN_PCT_TOP)) * (LCD_HEIGHT) / (SCREEN_PCT_HEIGHT);
|
||||
|
||||
// Send the touch to the UI (which will simulate the encoder wheel)
|
||||
MarlinUI::screen_click(row, col, x, y);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAS_TOUCH_XPT2046
|
@ -20,30 +20,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Relies on XPT2046-compatible mode of ADS7843,
|
||||
// hence no Z1 / Z2 measurements are possible.
|
||||
|
||||
#define XPT2046_DFR_MODE 0x00
|
||||
#define XPT2046_SER_MODE 0x04
|
||||
#define XPT2046_CONTROL 0x80
|
||||
|
||||
enum XPTCoordinate : uint8_t {
|
||||
XPT2046_X = 0x10,
|
||||
XPT2046_Y = 0x50,
|
||||
XPT2046_Z1 = 0x30,
|
||||
XPT2046_Z2 = 0x40
|
||||
};
|
||||
|
||||
class XPT2046 {
|
||||
class TouchButtons {
|
||||
public:
|
||||
static void init();
|
||||
static uint8_t read_buttons();
|
||||
bool getTouchPoint(uint16_t &x, uint16_t &y);
|
||||
static bool isTouched();
|
||||
inline void waitForRelease() { while (isTouched()) { /* nada */ } }
|
||||
inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } }
|
||||
private:
|
||||
static uint16_t getInTouch(const XPTCoordinate coordinate);
|
||||
};
|
||||
|
||||
extern XPT2046 touch;
|
||||
extern TouchButtons touch;
|
@ -1,251 +0,0 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_TOUCH_XPT2046
|
||||
|
||||
#include "xpt2046.h"
|
||||
#include "../scaled_tft.h"
|
||||
|
||||
#ifndef XPT2046_Z1_THRESHOLD
|
||||
#define XPT2046_Z1_THRESHOLD 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Draw and Touch processing
|
||||
*
|
||||
* LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
|
||||
* TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
|
||||
* LCD_FULL_PIXEL_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
|
||||
*
|
||||
* - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
|
||||
* - The DOGM pixels are is upscaled 2-3x (as needed) for display.
|
||||
* - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to
|
||||
* click and scroll-wheel events (emulating of a common DOGM display).
|
||||
*
|
||||
* TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
|
||||
* and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
|
||||
* new calibration values will be needed.
|
||||
*
|
||||
* The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
|
||||
* fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
|
||||
* navigate and select menu items. Both regions are touchable.
|
||||
*
|
||||
* The Marlin screen touchable area starts at LCD_PIXEL_OFFSET_X/Y (translated to SCREEN_START_LEFT/TOP)
|
||||
* and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_WIDTH/HEIGHT).
|
||||
*/
|
||||
|
||||
// Coordinates in terms of touch area
|
||||
#define BUTTON_AREA_TOP 175
|
||||
#define BUTTON_AREA_BOT 234
|
||||
|
||||
// Touch sensor resolution independent of display resolution
|
||||
#define TOUCH_SENSOR_WIDTH 320
|
||||
#define TOUCH_SENSOR_HEIGHT 240
|
||||
|
||||
#define SCREEN_WIDTH_PCT(X) ((X) * (TOUCH_SENSOR_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
|
||||
#define SCREEN_HEIGHT_PCT(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
|
||||
|
||||
#define SCREEN_START_LEFT SCREEN_WIDTH_PCT(LCD_PIXEL_OFFSET_X)
|
||||
#define SCREEN_START_TOP SCREEN_HEIGHT_PCT(LCD_PIXEL_OFFSET_Y)
|
||||
#define SCREEN_WIDTH SCREEN_WIDTH_PCT((LCD_PIXEL_WIDTH) * (FSMC_UPSCALE))
|
||||
#define SCREEN_HEIGHT SCREEN_HEIGHT_PCT((LCD_PIXEL_HEIGHT) * (FSMC_UPSCALE))
|
||||
|
||||
#define TOUCHABLE_X_WIDTH SCREEN_WIDTH
|
||||
#define TOUCHABLE_Y_HEIGHT SCREEN_HEIGHT
|
||||
|
||||
#ifndef TOUCH_INT_PIN
|
||||
#define TOUCH_INT_PIN -1
|
||||
#endif
|
||||
#ifndef TOUCH_MISO_PIN
|
||||
#define TOUCH_MISO_PIN MISO_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_MOSI_PIN
|
||||
#define TOUCH_MOSI_PIN MOSI_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_SCK_PIN
|
||||
#define TOUCH_SCK_PIN SCK_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_CS_PIN
|
||||
#define TOUCH_CS_PIN CS_PIN
|
||||
#endif
|
||||
|
||||
XPT2046 touch;
|
||||
|
||||
void XPT2046::init() {
|
||||
SET_INPUT(TOUCH_MISO_PIN);
|
||||
SET_OUTPUT(TOUCH_MOSI_PIN);
|
||||
SET_OUTPUT(TOUCH_SCK_PIN);
|
||||
OUT_WRITE(TOUCH_CS_PIN, HIGH);
|
||||
|
||||
#if PIN_EXISTS(TOUCH_INT)
|
||||
// Optional Pendrive interrupt pin
|
||||
SET_INPUT(TOUCH_INT_PIN);
|
||||
#endif
|
||||
|
||||
// Read once to enable pendrive status pin
|
||||
getInTouch(XPT2046_X);
|
||||
}
|
||||
|
||||
#include "../../lcd/ultralcd.h" // For EN_C bit mask
|
||||
|
||||
uint8_t XPT2046::read_buttons() {
|
||||
#ifdef HAS_SPI_LCD
|
||||
int16_t tsoffsets[4] = { 0 };
|
||||
|
||||
if (tsoffsets[0] + tsoffsets[1] == 0) {
|
||||
// Not yet set, so use defines as fallback...
|
||||
tsoffsets[0] = XPT2046_X_CALIBRATION;
|
||||
tsoffsets[1] = XPT2046_X_OFFSET;
|
||||
tsoffsets[2] = XPT2046_Y_CALIBRATION;
|
||||
tsoffsets[3] = XPT2046_Y_OFFSET;
|
||||
}
|
||||
|
||||
// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
|
||||
|
||||
if (!isTouched()) return 0;
|
||||
uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
|
||||
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
|
||||
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
|
||||
|
||||
#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
|
||||
x = TOUCH_SENSOR_WIDTH - x;
|
||||
y = TOUCH_SENSOR_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
// Touch within the button area simulates an encoder button
|
||||
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
|
||||
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;
|
||||
|
||||
if ( !WITHIN(x, SCREEN_START_LEFT, SCREEN_START_LEFT + SCREEN_WIDTH)
|
||||
|| !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)
|
||||
) return 0;
|
||||
|
||||
// Column and row above BUTTON_AREA_TOP
|
||||
int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
|
||||
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
|
||||
|
||||
// Send the touch to the UI (which will simulate the encoder wheel)
|
||||
MarlinUI::screen_click(row, col, x, y);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool XPT2046::isTouched() {
|
||||
return (
|
||||
#if PIN_EXISTS(TOUCH_INT)
|
||||
READ(TOUCH_INT_PIN) != HIGH
|
||||
#else
|
||||
getInTouch(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#if ENABLED(TOUCH_BUTTONS_HW_SPI)
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
static void touch_spi_init(uint8_t spiRate) {
|
||||
/**
|
||||
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
|
||||
* STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
|
||||
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
|
||||
*/
|
||||
uint8_t clock;
|
||||
switch (spiRate) {
|
||||
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV4; break;
|
||||
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4; break;
|
||||
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
|
||||
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
|
||||
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
|
||||
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
||||
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
||||
}
|
||||
SPI.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
|
||||
SPI.begin();
|
||||
SPI.setClockDivider(clock);
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
}
|
||||
#endif // TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
|
||||
uint16_t data[3];
|
||||
const uint8_t coord = uint8_t(coordinate) | XPT2046_CONTROL | XPT2046_DFR_MODE;
|
||||
|
||||
#if ENABLED(TOUCH_BUTTONS_HW_SPI)
|
||||
|
||||
touch_spi_init(SPI_SPEED_6);
|
||||
for (uint16_t i = 0; i < 3; i++) {
|
||||
OUT_WRITE(TOUCH_CS_PIN, LOW);
|
||||
SPI.transfer(coord);
|
||||
data[i] = (((SPI.transfer(0xFF) << 8) | SPI.transfer(0xFF)) >> 3) & 0x0FFF;
|
||||
WRITE(TOUCH_CS_PIN, HIGH);
|
||||
}
|
||||
|
||||
#else // !TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
OUT_WRITE(TOUCH_CS_PIN, LOW);
|
||||
for (uint16_t i = 0; i < 3; i++) {
|
||||
for (uint8_t j = 0x80; j; j >>= 1) {
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
WRITE(TOUCH_MOSI_PIN, bool(coord & j));
|
||||
WRITE(TOUCH_SCK_PIN, HIGH);
|
||||
}
|
||||
|
||||
data[i] = 0;
|
||||
for (uint16_t j = 0x8000; j; j >>= 1) {
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
if (READ(TOUCH_MISO_PIN)) data[i] |= j;
|
||||
WRITE(TOUCH_SCK_PIN, HIGH);
|
||||
}
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
data[i] >>= 4;
|
||||
}
|
||||
WRITE(TOUCH_CS_PIN, HIGH);
|
||||
|
||||
#endif // !TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
uint16_t delta01 = _MAX(data[0], data[1]) - _MIN(data[0], data[1]),
|
||||
delta02 = _MAX(data[0], data[2]) - _MIN(data[0], data[2]),
|
||||
delta12 = _MAX(data[1], data[2]) - _MIN(data[1], data[2]);
|
||||
|
||||
if (delta01 <= delta02 && delta01 <= delta12)
|
||||
return (data[0] + data[1]) >> 1;
|
||||
|
||||
if (delta02 <= delta12)
|
||||
return (data[0] + data[2]) >> 1;
|
||||
|
||||
return (data[1] + data[2]) >> 1;
|
||||
}
|
||||
|
||||
bool XPT2046::getTouchPoint(uint16_t &x, uint16_t &y) {
|
||||
if (isTouched()) {
|
||||
x = getInTouch(XPT2046_X);
|
||||
y = getInTouch(XPT2046_Y);
|
||||
}
|
||||
return isTouched();
|
||||
}
|
||||
|
||||
#endif // HAS_TOUCH_XPT2046
|
@ -150,7 +150,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
|
||||
volatile uint8_t MarlinUI::slow_buttons;
|
||||
#endif
|
||||
#if HAS_TOUCH_XPT2046
|
||||
#include "touch/xpt2046.h"
|
||||
#include "touch/touch_buttons.h"
|
||||
bool MarlinUI::on_edit_screen = false;
|
||||
#endif
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user