From 734ca7731281ad299afae419680a1017c30bfb5e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 7 Apr 2023 20:26:40 -0500 Subject: [PATCH] more basic reorg --- Marlin/src/HAL/STM32/tft/tft_spi.cpp | 1 - Marlin/src/HAL/STM32F1/tft/tft_spi.cpp | 15 ++-- Marlin/src/inc/Conditionals_LCD.h | 4 ++ Marlin/src/inc/Conditionals_post.h | 35 ++++++++++ .../src/lcd/extui/mks_ui/draw_print_file.cpp | 12 +--- .../extui/mks_ui/tft_lvgl_configuration.cpp | 3 +- Marlin/src/lcd/extui/mks_ui/wifi_module.cpp | 1 + Marlin/src/lcd/tft_io/ili9488.h | 10 --- Marlin/src/lcd/tft_io/tft_io.h | 46 ------------- Marlin/src/lcd/tft_io/tft_orientation.h | 68 +++++++++++++++++++ Marlin/src/lcd/tft_io/touch_calibration.h | 28 +------- 11 files changed, 119 insertions(+), 104 deletions(-) create mode 100644 Marlin/src/lcd/tft_io/tft_orientation.h diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.cpp b/Marlin/src/HAL/STM32/tft/tft_spi.cpp index 6ee4dc3364ee0..dbb93c786b4ee 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32/tft/tft_spi.cpp @@ -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); diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp index eed52f4e8a38f..5264aabef6627 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp @@ -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; + 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); - - return data >> 7; #endif + + return data >> 7; } bool TFT_SPI::isBusy() { diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index e11ad0d3b50d7..e6c3b2aef92d8 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1665,6 +1665,10 @@ #endif #endif +#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT) + #include "../lcd/tft_io/tft_orientation.h" // for TFT_COLOR_UI_PORTRAIT +#endif + #if ENABLED(TFT_RES_320x240) #if ENABLED(TFT_COLOR_UI_PORTRAIT) #define TFT_WIDTH 240 diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 0f28b8ea7b159..bb3bed903fca1 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -3125,6 +3125,41 @@ #endif #endif +// Touch Calibration +#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT) + #ifndef TOUCH_CALIBRATION_X + #ifdef XPT2046_X_CALIBRATION + #define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION + #else + #define TOUCH_CALIBRATION_X 0 + #endif + #endif + #ifndef TOUCH_CALIBRATION_Y + #ifdef XPT2046_Y_CALIBRATION + #define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION + #else + #define TOUCH_CALIBRATION_Y 0 + #endif + #endif + #ifndef TOUCH_OFFSET_X + #ifdef XPT2046_X_OFFSET + #define TOUCH_OFFSET_X XPT2046_X_OFFSET + #else + #define TOUCH_OFFSET_X 0 + #endif + #endif + #ifndef TOUCH_OFFSET_Y + #ifdef XPT2046_Y_OFFSET + #define TOUCH_OFFSET_Y XPT2046_Y_OFFSET + #else + #define TOUCH_OFFSET_Y 0 + #endif + #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 diff --git a/Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp b/Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp index 245fa24fe9b33..3ae893f0c2131 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp @@ -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 @@ -435,21 +433,13 @@ void lv_gcode_file_read(uint8_t *data_buf) { break; } } - 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) { - #if HAS_TFT_LVGL_UI_SPI - *p_index = LV_COLOR_BACKGROUND.full; - #else - *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3 - #endif - } + if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; } - memcpy(data_buf, public_buf, 200); #endif // HAS_MEDIA } diff --git a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp index 972349d287acf..93c56db842e88 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -36,10 +36,11 @@ #include #include "../../../MarlinCore.h" +#include "../../marlinui.h" + #include "../../../inc/MarlinConfig.h" #include HAL_PATH(../../../HAL, tft/xpt2046.h) -#include "../../marlinui.h" XPT2046 touch; #if ENABLED(POWER_LOSS_RECOVERY) diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp index cf2411ee7ef58..bf399f70aad4c 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp @@ -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()); diff --git a/Marlin/src/lcd/tft_io/ili9488.h b/Marlin/src/lcd/tft_io/ili9488.h index fc2add662dbba..f28d411bbd4ec 100644 --- a/Marlin/src/lcd/tft_io/ili9488.h +++ b/Marlin/src/lcd/tft_io/ili9488.h @@ -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), diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h index 57e410314d9c9..61d664b991ba4 100644 --- a/Marlin/src/lcd/tft_io/tft_io.h +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -37,52 +37,6 @@ #error "DMA_MAX_SIZE is not configured for this platform." #endif -#define TFT_EXCHANGE_XY _BV32(1) -#define TFT_INVERT_X _BV32(2) -#define TFT_INVERT_Y _BV32(3) - -#define TFT_NO_ROTATION (0x00) -#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) -#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y) -#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y) - -#define TFT_MIRROR_X (TFT_INVERT_Y) -#define TFT_MIRROR_Y (TFT_INVERT_X) - -#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_MIRROR_X) -#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_MIRROR_Y) - -#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_MIRROR_X) -#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_MIRROR_Y) - -#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_MIRROR_X) -#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_MIRROR_Y) - -// TFT_ROTATION is user configurable -#ifndef TFT_ROTATION - #define TFT_ROTATION TFT_NO_ROTATION -#endif - -// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION -#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION)) - -// Set TFT_COLOR_UI_PORTRAIT flag, if needed -#if ((TFT_ORIENTATION) & TFT_EXCHANGE_XY) == 0 - #define TFT_COLOR_UI_PORTRAIT 1 -#endif - -#define TFT_COLOR_RGB _BV32(3) -#define TFT_COLOR_BGR _BV32(4) - -// Each TFT Driver is responsible for its default color mode. -//#ifndef TFT_COLOR -// #define TFT_COLOR TFT_COLOR_RGB -//#endif - -#define TOUCH_ORIENTATION_NONE 0 -#define TOUCH_LANDSCAPE 1 -#define TOUCH_PORTRAIT 2 - #ifndef TFT_DRIVER #define TFT_DRIVER AUTO #endif diff --git a/Marlin/src/lcd/tft_io/tft_orientation.h b/Marlin/src/lcd/tft_io/tft_orientation.h new file mode 100644 index 0000000000000..99c6a13c64465 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_orientation.h @@ -0,0 +1,68 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2023 MarlinFirmware [/~https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * 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 . + * + */ +#pragma once + +#define TFT_EXCHANGE_XY _BV32(1) +#define TFT_INVERT_X _BV32(2) +#define TFT_INVERT_Y _BV32(3) + +#define TFT_NO_ROTATION (0x00) +#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) +#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y) +#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y) + +#define TFT_MIRROR_X (TFT_INVERT_Y) +#define TFT_MIRROR_Y (TFT_INVERT_X) + +#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_MIRROR_X) +#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_MIRROR_Y) + +#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_MIRROR_X) +#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_MIRROR_Y) + +#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_MIRROR_X) +#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_MIRROR_Y) + +// TFT_ROTATION is user configurable +#ifndef TFT_ROTATION + #define TFT_ROTATION TFT_NO_ROTATION +#endif + +// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION +#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION)) + +// Set TFT_COLOR_UI_PORTRAIT flag, if needed +#if ((TFT_ORIENTATION) & TFT_EXCHANGE_XY) == 0 + #define TFT_COLOR_UI_PORTRAIT 1 +#endif + +#define TFT_COLOR_RGB _BV32(3) +#define TFT_COLOR_BGR _BV32(4) + +// Each TFT Driver is responsible for its default color mode. +//#ifndef TFT_COLOR +// #define TFT_COLOR TFT_COLOR_RGB +//#endif + +#define TOUCH_ORIENTATION_NONE 0 +#define TOUCH_LANDSCAPE 1 +#define TOUCH_PORTRAIT 2 diff --git a/Marlin/src/lcd/tft_io/touch_calibration.h b/Marlin/src/lcd/tft_io/touch_calibration.h index f9528d6f8f400..e9d3110c56d6f 100644 --- a/Marlin/src/lcd/tft_io/touch_calibration.h +++ b/Marlin/src/lcd/tft_io/touch_calibration.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft_io.h" +#include "../../inc/MarlinConfig.h" #ifndef TOUCH_SCREEN_CALIBRATION_PRECISION #define TOUCH_SCREEN_CALIBRATION_PRECISION 80 @@ -30,32 +30,6 @@ #define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500 #endif -// XPT2046_** Compatibility -#if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) \ - && !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION)) - #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 - -#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 - typedef struct __attribute__((__packed__)) { int32_t x, y; int16_t offset_x, offset_y;