🐛 Fix TFT Touch Calibration overrides (#25579)

…and other misc. display-related updates

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Keith Bennett 2023-05-03 14:19:32 -07:00 committed by GitHub
parent dbed3f1c41
commit 7642bfbf8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 80 additions and 131 deletions

View file

@ -245,7 +245,6 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
TERN_(TFT_SHARED_IO, while (isBusy()));
}
void TFT_SPI::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
DMAtx.Init.MemInc = MemoryIncrease;
HAL_DMA_Init(&DMAtx);

View file

@ -94,25 +94,24 @@ uint32_t TFT_SPI::GetID() {
}
uint32_t TFT_SPI::ReadID(uint16_t Reg) {
#if !PIN_EXISTS(TFT_MISO)
return 0;
#else
uint8_t d = 0;
uint32_t data = 0;
#if PIN_EXISTS(TFT_MISO)
SPIx.setClockDivider(SPI_CLOCK_DIV16);
DataTransferBegin(DATASIZE_8BIT);
WriteReg(Reg);
LOOP_L_N(i, 4) {
SPIx.read((uint8_t*)&d, 1);
uint8_t d;
SPIx.read(&d, 1);
data = (data << 8) | d;
}
DataTransferEnd();
SPIx.setClockDivider(SPI_CLOCK_MAX);
#endif
return data >> 7;
#endif
}
bool TFT_SPI::isBusy() {

View file

@ -328,24 +328,22 @@
#define IS_ULTIPANEL 1
#endif
// TFT Legacy Compatibility
// TFT Legacy options masquerade as TFT_GENERIC
#if ANY(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
#define IS_LEGACY_TFT 1
#define TFT_GENERIC
#endif
#if ANY(FSMC_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC)
#if ANY(FSMC_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC)
#define TFT_INTERFACE_FSMC
#elif ANY(SPI_GRAPHICAL_TFT, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI)
#elif ANY(SPI_GRAPHICAL_TFT, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI)
#define TFT_INTERFACE_SPI
#endif
#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
#endif
#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
#define TFT_CLASSIC_UI
#elif ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI)
#elif ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI)
#define TFT_COLOR_UI
#elif EITHER(TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
#elif EITHER(TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
#define TFT_LVGL_UI
#endif
#endif
// FSMC/SPI TFT Panels (LVGL)
@ -1671,7 +1669,7 @@
#endif
#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
#include "../lcd/tft_io/tft_orientation.h"
#include "../lcd/tft_io/tft_orientation.h" // for TFT_COLOR_UI_PORTRAIT
#endif
#if ENABLED(TFT_RES_320x240)
@ -1775,17 +1773,6 @@
#endif
#endif
// XPT2046_** Compatibility
#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION))
#if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET)
#define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION
#define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif
#endif
#if X_HOME_DIR || (HAS_Y_AXIS && Y_HOME_DIR) || (HAS_Z_AXIS && Z_HOME_DIR) \
|| (HAS_I_AXIS && I_HOME_DIR) || (HAS_J_AXIS && J_HOME_DIR) || (HAS_K_AXIS && K_HOME_DIR) \
|| (HAS_U_AXIS && U_HOME_DIR) || (HAS_V_AXIS && V_HOME_DIR) || (HAS_W_AXIS && W_HOME_DIR)

View file

@ -560,7 +560,7 @@
#define REINIT_NOISY_LCD 1 // Have the LCD re-init on SD insertion
#endif
#endif
#endif // HAS_MEDIA
/**
* Power Supply
@ -3153,6 +3153,25 @@
#endif
#endif
// Touch Calibration
#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
#ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 0
#endif
#ifndef TOUCH_CALIBRATION_Y
#define TOUCH_CALIBRATION_Y 0
#endif
#ifndef TOUCH_OFFSET_X
#define TOUCH_OFFSET_X 0
#endif
#ifndef TOUCH_OFFSET_Y
#define TOUCH_OFFSET_Y 0
#endif
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif
#endif
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
#define VFAT_ENTRIES_LIMIT 5

View file

@ -556,4 +556,4 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT,
#endif // TOUCH_SCREEN_CALIBRATION
#endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT)
#endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT || HAS_LTDC_GRAPHICAL_TFT)

View file

@ -120,8 +120,6 @@ bool have_pre_pic(char *path) {
static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
uint8_t i, file_count = 0;
//switch (obj->mks_obj_id)
//{
if (obj->mks_obj_id == ID_P_UP) {
if (dir_offset[curDirLever].curPage > 0) {
// 2015.05.19
@ -130,9 +128,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM)
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM;
#if HAS_MEDIA
file_count = search_file();
#endif
TERN_(HAS_MEDIA, file_count = search_file());
if (file_count != 0) {
dir_offset[curDirLever].curPage--;
lv_clear_print_file();
@ -144,9 +140,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (dir_offset[curDirLever].cur_page_last_offset > 0) {
list_file.Sd_file_cnt = 0;
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1;
#if HAS_MEDIA
file_count = search_file();
#endif
TERN_(HAS_MEDIA, file_count = search_file());
if (file_count != 0) {
dir_offset[curDirLever].curPage++;
lv_clear_print_file();
@ -161,17 +155,13 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/');
if (ch) {
*ch = 0;
#if HAS_MEDIA
card.cdup();
#endif
TERN_(HAS_MEDIA, card.cdup());
dir_offset[curDirLever].curPage = 0;
dir_offset[curDirLever].cur_page_first_offset = 0;
dir_offset[curDirLever].cur_page_last_offset = 0;
curDirLever--;
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
#if HAS_MEDIA
file_count = search_file();
#endif
TERN_(HAS_MEDIA, file_count = search_file());
lv_clear_print_file();
disp_gcode_icon(file_count);
}
@ -189,9 +179,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
strcpy(list_file.curDirPath, list_file.file_name[i]);
curDirLever++;
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
#if HAS_MEDIA
file_count = search_file();
#endif
TERN_(HAS_MEDIA, file_count = search_file());
lv_clear_print_file();
disp_gcode_icon(file_count);
}
@ -396,8 +384,7 @@ int ascii2dec_test(char *ascii) {
void lv_gcode_file_read(uint8_t *data_buf) {
#if HAS_MEDIA
uint16_t i = 0, j = 0, k = 0;
uint16_t row_1 = 0;
uint16_t i = 0, j = 0, k = 0, row_1 = 0;
bool ignore_start = true;
char temp_test[200];
volatile uint16_t *p_index;
@ -435,24 +422,13 @@ void lv_gcode_file_read(uint8_t *data_buf) {
break;
}
}
#if HAS_TFT_LVGL_UI_SPI
for (i = 0; i < 200;) {
p_index = (uint16_t *)(&public_buf[i]);
//Color = (*p_index >> 8);
//*p_index = Color | ((*p_index & 0xFF) << 8);
i += 2;
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
}
#else // !HAS_TFT_LVGL_UI_SPI
for (i = 0; i < 200;) {
p_index = (uint16_t *)(&public_buf[i]);
//Color = (*p_index >> 8);
//*p_index = Color | ((*p_index & 0xFF) << 8);
i += 2;
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3;
}
#endif // !HAS_TFT_LVGL_UI_SPI
memcpy(data_buf, public_buf, 200);
#endif // HAS_MEDIA
}

View file

@ -171,12 +171,12 @@
#define QRCODE_Y 40
#define QRCODE_WIDTH 160
#else // ifdef TFT35
#else // !TFT35
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
#endif // ifdef TFT35
#endif
#ifdef __cplusplus
extern "C" {

View file

@ -36,10 +36,11 @@
#include <lvgl.h>
#include "../../../MarlinCore.h"
#include "../../marlinui.h"
#include "../../../inc/MarlinConfig.h"
#include HAL_PATH(../../.., tft/xpt2046.h)
#include "../../marlinui.h"
XPT2046 touch;
#if ENABLED(POWER_LOSS_RECOVERY)

View file

@ -32,8 +32,6 @@
#include <lvgl.h>
//#define TFT_ROTATION TFT_ROTATE_180
extern uint8_t bmp_public_buf[14 * 1024];
extern uint8_t public_buf[513];

View file

@ -1804,6 +1804,7 @@ void stopEspTransfer() {
W25QXX.init(SPI_QUARTER_SPEED);
// ?? Workaround for SPI / Servo issues ??
TERN_(HAS_TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED));
TERN_(HAS_SERVOS, servo_init());
TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());

View file

@ -266,19 +266,18 @@ void Touch::hold(touch_control_t *control, millis_t delay) {
bool Touch::get_point(int16_t *x, int16_t *y) {
#if ENABLED(TFT_TOUCH_DEVICE_XPT2046)
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
const bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
*x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
*y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
}
#else
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
*x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
*y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
#endif
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
#endif
#if HAS_TOUCH_SLEEP
if (is_touched)

View file

@ -146,16 +146,6 @@
#define ILI9488_ADJCTL6 0xFC // Adjust Control 6
#define ILI9488_ADJCTL7 0xFF // Adjust Control 7
#if 0
// https://forum.mikroe.com/viewtopic.php?t=74586
#if ANY(MKS_ROBIN_TFT35, TFT_TRONXY_X5SA, ANYCUBIC_TFT35) // ILI9488
#define TFT_DRIVER ILI9488
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_RES_480x320
#define TFT_INTERFACE_FSMC
#endif
#endif
static const uint16_t ili9488_init[] = {
DATASIZE_8BIT,
ESC_REG(ILI9488_SWRESET), ESC_DELAY(120),

View file

@ -37,8 +37,6 @@
#error "DMA_MAX_SIZE is not configured for this platform."
#endif
#include "tft_orientation.h"
#ifndef TFT_DRIVER
#define TFT_DRIVER AUTO
#endif

View file

@ -66,19 +66,3 @@
#define TOUCH_ORIENTATION_NONE 0
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2
#ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 0
#endif
#ifndef TOUCH_CALIBRATION_Y
#define TOUCH_CALIBRATION_Y 0
#endif
#ifndef TOUCH_OFFSET_X
#define TOUCH_OFFSET_X 0
#endif
#ifndef TOUCH_OFFSET_Y
#define TOUCH_OFFSET_Y 0
#endif
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif

View file

@ -21,13 +21,11 @@
*/
#pragma once
#include "../../inc/MarlinConfigPre.h"
#include "tft_io.h"
#include "../../inc/MarlinConfig.h"
#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
#endif
#ifndef TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS
#define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500
#endif

View file

@ -65,7 +65,7 @@ void TouchButtons::init() {
}
uint8_t TouchButtons::read_buttons() {
#ifdef HAS_WIRED_LCD
#if HAS_WIRED_LCD
int16_t x, y;
#if ENABLED(TFT_TOUCH_DEVICE_XPT2046)

View file

@ -408,7 +408,7 @@
#ifndef TFT_DRIVER
#define TFT_DRIVER ST7796
#endif
#ifndef TOUCH_SCREEN_CALIBRATION
#if DISABLED(TOUCH_SCREEN_CALIBRATION)
#if ENABLED(TFT_RES_320x240)
#ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 20525