From a37cf2490054ece3c16f0caca26a02c3d33057c8 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Fri, 21 Aug 2020 20:54:21 -0300 Subject: [PATCH] Emulated DOGM via HAL TFT, XPT IO (#19017) --- .../STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp | 331 ------------------ .../STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp | 236 ------------- Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h | 4 +- Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp | 2 +- Marlin/src/HAL/STM32F1/tft/tft_spi.cpp | 30 +- Marlin/src/HAL/STM32F1/tft/xpt2046.cpp | 2 +- Marlin/src/HAL/STM32F1/tft/xpt2046.h | 20 +- Marlin/src/MarlinCore.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 9 +- Marlin/src/inc/SanityCheck.h | 6 + Marlin/src/lcd/dogm/HAL_LCD_com_defines.h | 15 +- ...8g_dev_tft_320x240_upscale_from_128x64.cpp | 165 +++++---- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp | 39 +-- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h | 8 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 6 +- .../extui/lib/mks_ui/mks_hardware_test.cpp | 2 - .../lib/mks_ui/tft_lvgl_configuration.cpp | 30 +- Marlin/src/lcd/scaled_tft.h | 28 +- Marlin/src/lcd/touch/touch_buttons.cpp | 112 ++++++ .../lcd/touch/{xpt2046.h => touch_buttons.h} | 24 +- Marlin/src/lcd/touch/xpt2046.cpp | 251 ------------- Marlin/src/lcd/ultralcd.cpp | 2 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 131 +++---- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 147 +++----- Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h | 20 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 122 +++---- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 187 ++++------ buildroot/share/scripts/pinsformat.js | 41 ++- 28 files changed, 595 insertions(+), 1377 deletions(-) delete mode 100644 Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp delete mode 100644 Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp create mode 100644 Marlin/src/lcd/touch/touch_buttons.cpp rename Marlin/src/lcd/touch/{xpt2046.h => touch_buttons.h} (56%) delete mode 100644 Marlin/src/lcd/touch/xpt2046.cpp diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp deleted file mode 100644 index 445e53b67f..0000000000 --- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 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 . - * - */ - -/** - * u8g_com_stm32duino_fsmc.cpp - * - * Communication interface for FSMC - */ - -#include "../../../inc/MarlinConfig.h" - -#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs - -#if HAS_GRAPHICAL_LCD - -#include -#include -#include -#include -#include - -#ifndef LCD_READ_ID - #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341) -#endif - -/* Timing configuration */ -#define FSMC_ADDRESS_SETUP_TIME 15 // AddressSetupTime -#define FSMC_DATA_SETUP_TIME 15 // DataSetupTime - -void LCD_IO_Init(uint8_t cs, uint8_t rs); -void LCD_IO_WriteData(uint16_t RegValue); -void LCD_IO_WriteReg(uint16_t Reg); -uint16_t LCD_IO_ReadData(uint16_t RegValue); -uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize); -#ifdef LCD_USE_DMA_FSMC - void LCD_IO_WriteMultiple(uint16_t data, uint32_t count); - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); -#endif - -static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT - -uint8_t u8g_com_stm32duino_fsmc_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); - - #ifdef LCD_USE_DMA_FSMC - dma_init(FSMC_DMA_DEV); - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM); - #endif - - LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]); - u8g_Delay(50); - - if (arg_ptr) { - *((uint32_t *)arg_ptr) = LCD_IO_ReadData(0x0000); - if (*((uint32_t *)arg_ptr) == 0) - *((uint32_t *)arg_ptr) = (LCD_READ_ID << 24) | LCD_IO_ReadData(LCD_READ_ID, 3); - } - 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: - if (isCommand) - LCD_IO_WriteReg(arg_val); - else - LCD_IO_WriteData((uint16_t)arg_val); - break; - - case U8G_COM_MSG_WRITE_SEQ: - for (uint8_t i = 0; i < arg_val; i += 2) - LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i)); - break; - } - return 1; -} - -/** - * FSMC LCD IO - */ -#define __ASM __asm -#define __STATIC_INLINE static inline - -__attribute__((always_inline)) __STATIC_INLINE void __DSB() { - __ASM volatile ("dsb 0xF":::"memory"); -} - -#define FSMC_CS_NE1 PD7 - -#if ENABLED(STM32_XL_DENSITY) - #define FSMC_CS_NE2 PG9 - #define FSMC_CS_NE3 PG10 - #define FSMC_CS_NE4 PG12 - - #define FSMC_RS_A0 PF0 - #define FSMC_RS_A1 PF1 - #define FSMC_RS_A2 PF2 - #define FSMC_RS_A3 PF3 - #define FSMC_RS_A4 PF4 - #define FSMC_RS_A5 PF5 - #define FSMC_RS_A6 PF12 - #define FSMC_RS_A7 PF13 - #define FSMC_RS_A8 PF14 - #define FSMC_RS_A9 PF15 - #define FSMC_RS_A10 PG0 - #define FSMC_RS_A11 PG1 - #define FSMC_RS_A12 PG2 - #define FSMC_RS_A13 PG3 - #define FSMC_RS_A14 PG4 - #define FSMC_RS_A15 PG5 -#endif - -#define FSMC_RS_A16 PD11 -#define FSMC_RS_A17 PD12 -#define FSMC_RS_A18 PD13 -#define FSMC_RS_A19 PE3 -#define FSMC_RS_A20 PE4 -#define FSMC_RS_A21 PE5 -#define FSMC_RS_A22 PE6 -#define FSMC_RS_A23 PE2 - -#if ENABLED(STM32_XL_DENSITY) - #define FSMC_RS_A24 PG13 - #define FSMC_RS_A25 PG14 -#endif - -static uint8_t fsmcInit = 0; - -typedef struct { - __IO uint16_t REG; - __IO uint16_t RAM; -} LCD_CONTROLLER_TypeDef; - -LCD_CONTROLLER_TypeDef *LCD; - -void LCD_IO_Init(uint8_t cs, uint8_t rs) { - uint32_t controllerAddress; - struct fsmc_nor_psram_reg_map* fsmcPsramRegion; - - if (fsmcInit) return; - fsmcInit = 1; - - switch (cs) { - case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; fsmcPsramRegion = FSMC_NOR_PSRAM1_BASE; break; - #if ENABLED(STM32_XL_DENSITY) - case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; fsmcPsramRegion = FSMC_NOR_PSRAM2_BASE; break; - case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; fsmcPsramRegion = FSMC_NOR_PSRAM3_BASE; break; - case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; fsmcPsramRegion = FSMC_NOR_PSRAM4_BASE; break; - #endif - default: return; - } - - #define _ORADDR(N) controllerAddress |= (_BV32(N) - 2) - - switch (rs) { - #if ENABLED(STM32_XL_DENSITY) - case FSMC_RS_A0: _ORADDR( 1); break; - case FSMC_RS_A1: _ORADDR( 2); break; - case FSMC_RS_A2: _ORADDR( 3); break; - case FSMC_RS_A3: _ORADDR( 4); break; - case FSMC_RS_A4: _ORADDR( 5); break; - case FSMC_RS_A5: _ORADDR( 6); break; - case FSMC_RS_A6: _ORADDR( 7); break; - case FSMC_RS_A7: _ORADDR( 8); break; - case FSMC_RS_A8: _ORADDR( 9); break; - case FSMC_RS_A9: _ORADDR(10); break; - case FSMC_RS_A10: _ORADDR(11); break; - case FSMC_RS_A11: _ORADDR(12); break; - case FSMC_RS_A12: _ORADDR(13); break; - case FSMC_RS_A13: _ORADDR(14); break; - case FSMC_RS_A14: _ORADDR(15); break; - case FSMC_RS_A15: _ORADDR(16); break; - #endif - case FSMC_RS_A16: _ORADDR(17); break; - case FSMC_RS_A17: _ORADDR(18); break; - case FSMC_RS_A18: _ORADDR(19); break; - case FSMC_RS_A19: _ORADDR(20); break; - case FSMC_RS_A20: _ORADDR(21); break; - case FSMC_RS_A21: _ORADDR(22); break; - case FSMC_RS_A22: _ORADDR(23); break; - case FSMC_RS_A23: _ORADDR(24); break; - #if ENABLED(STM32_XL_DENSITY) - case FSMC_RS_A24: _ORADDR(25); break; - case FSMC_RS_A25: _ORADDR(26); break; - #endif - default: return; - } - - rcc_clk_enable(RCC_FSMC); - - gpio_set_mode(GPIOD, 14, GPIO_AF_OUTPUT_PP); // FSMC_D00 - gpio_set_mode(GPIOD, 15, GPIO_AF_OUTPUT_PP); // FSMC_D01 - gpio_set_mode(GPIOD, 0, GPIO_AF_OUTPUT_PP); // FSMC_D02 - gpio_set_mode(GPIOD, 1, GPIO_AF_OUTPUT_PP); // FSMC_D03 - gpio_set_mode(GPIOE, 7, GPIO_AF_OUTPUT_PP); // FSMC_D04 - gpio_set_mode(GPIOE, 8, GPIO_AF_OUTPUT_PP); // FSMC_D05 - gpio_set_mode(GPIOE, 9, GPIO_AF_OUTPUT_PP); // FSMC_D06 - gpio_set_mode(GPIOE, 10, GPIO_AF_OUTPUT_PP); // FSMC_D07 - gpio_set_mode(GPIOE, 11, GPIO_AF_OUTPUT_PP); // FSMC_D08 - gpio_set_mode(GPIOE, 12, GPIO_AF_OUTPUT_PP); // FSMC_D09 - gpio_set_mode(GPIOE, 13, GPIO_AF_OUTPUT_PP); // FSMC_D10 - gpio_set_mode(GPIOE, 14, GPIO_AF_OUTPUT_PP); // FSMC_D11 - gpio_set_mode(GPIOE, 15, GPIO_AF_OUTPUT_PP); // FSMC_D12 - gpio_set_mode(GPIOD, 8, GPIO_AF_OUTPUT_PP); // FSMC_D13 - gpio_set_mode(GPIOD, 9, GPIO_AF_OUTPUT_PP); // FSMC_D14 - gpio_set_mode(GPIOD, 10, GPIO_AF_OUTPUT_PP); // FSMC_D15 - - gpio_set_mode(GPIOD, 4, GPIO_AF_OUTPUT_PP); // FSMC_NOE - gpio_set_mode(GPIOD, 5, GPIO_AF_OUTPUT_PP); // FSMC_NWE - - gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_CS_NEx - gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_RS_Ax - - fsmcPsramRegion->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN; - fsmcPsramRegion->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME; - - afio_remap(AFIO_REMAP_FSMC_NADV); - - LCD = (LCD_CONTROLLER_TypeDef*)controllerAddress; -} - -void LCD_IO_WriteData(uint16_t RegValue) { - LCD->RAM = RegValue; - __DSB(); -} - -void LCD_IO_WriteReg(uint16_t Reg) { - LCD->REG = Reg; - __DSB(); -} - -uint16_t LCD_IO_ReadData(uint16_t RegValue) { - LCD->REG = RegValue; - __DSB(); - - return LCD->RAM; -} - -uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) { - volatile uint32_t data; - LCD->REG = RegValue; - __DSB(); - - data = LCD->RAM; // dummy read - data = LCD->RAM & 0x00FF; - - while (--ReadSize) { - data <<= 8; - data |= (LCD->RAM & 0x00FF); - } - return uint32_t(data); -} - -#ifdef LCD_USE_DMA_FSMC - -void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) { - while (count > 0) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {}; - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - count = count > 65535 ? count - 65535 : 0; - } -} - -void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {}; - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); -} - -void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); -} - -void LCD_IO_WaitSequence_Async() { - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {}; - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); -} - -#endif // LCD_USE_DMA_FSMC - -#endif // HAS_GRAPHICAL_LCD -#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp deleted file mode 100644 index 206c3fda3d..0000000000 --- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp +++ /dev/null @@ -1,236 +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 . - * - */ -#ifdef __STM32F1__ - -#include "../../../inc/MarlinConfig.h" - -#if ENABLED(SPI_GRAPHICAL_TFT) && DISABLED(FORCE_SOFT_SPI) - -#include "../HAL.h" -#include -#include - -#define SPI_TFT_CS_H OUT_WRITE(SPI_TFT_CS_PIN, HIGH) -#define SPI_TFT_CS_L OUT_WRITE(SPI_TFT_CS_PIN, LOW) - -#define SPI_TFT_DC_H OUT_WRITE(SPI_TFT_DC_PIN, HIGH) -#define SPI_TFT_DC_L OUT_WRITE(SPI_TFT_DC_PIN, LOW) - -#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 SPI_TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH) -#define SPI_TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW) - -void LCD_IO_Init(uint8_t cs, uint8_t rs); -void LCD_IO_WriteData(uint16_t RegValue); -void LCD_IO_WriteReg(uint16_t Reg); -uint16_t LCD_IO_ReadData(uint16_t RegValue); -uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize); -#ifdef LCD_USE_DMA_SPI - void LCD_IO_WriteMultiple(uint16_t data, uint32_t count); - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); -#endif - -void LCD_WR_REG(uint8_t cmd) { - SPI_TFT_CS_L; - SPI_TFT_DC_L; - SPI.send(cmd); - SPI_TFT_CS_H; -} -void LCD_WR_DATA(uint8_t data) { - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.send(data); - SPI_TFT_CS_H; -} - -void spi1Init(uint8_t spiRate) { - SPI_TFT_CS_H; - - /** - * 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(1); - SPI.begin(); - SPI.setClockDivider(clock); - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); -} - -void LCD_IO_Init(uint8_t cs, uint8_t rs) { - spi1Init(SPI_FULL_SPEED); -} - -void LCD_IO_WriteData(uint16_t RegValue) { - LCD_WR_DATA(RegValue); -} - -void LCD_IO_WriteReg(uint16_t Reg) { - LCD_WR_REG(Reg); -} - -uint16_t LCD_IO_ReadData(uint16_t RegValue) { - uint16_t d = 0; - SPI_TFT_CS_L; - - SPI_TFT_DC_L; - SPI.send(RegValue); - SPI_TFT_DC_H; - - SPI.read((uint8_t*)&d, 1); //dummy read - SPI.read((uint8_t*)&d, 1); - - SPI_TFT_CS_H; - return d >> 7; -} - -uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) { - uint32_t data = 0; - uint8_t d = 0; - SPI_TFT_CS_L; - - SPI_TFT_DC_L; - SPI.send(RegValue); - SPI_TFT_DC_H; - - SPI.read((uint8_t*)&d, 1); //dummy read - SPI.read((uint8_t*)&d, 1); - data = d; - while (--ReadSize) { - data <<= 8; - SPI.read((uint8_t*)&d, 1); - data |= (d & 0xFF); - } - - SPI_TFT_CS_H; - return uint32_t(data >> 7); -} - -#ifdef LCD_USE_DMA_SPI - void LCD_IO_WriteMultiple(uint16_t data, uint32_t count) { - if (SPI.getDataSize() == DATA_SIZE_8BIT) { - count *= 2; - } - while (count > 0) { - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(&data, 1, true); - SPI_TFT_CS_H; - count--; - } - } - - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { - if (SPI.getDataSize() == DATA_SIZE_8BIT) { - length *= 2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(data, length, true); - SPI_TFT_CS_H; - } - - void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) { - if (SPI.getDataSize() == DATA_SIZE_8BIT) { - length *= 2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSendAsync(data, length, true); - SPI_TFT_CS_H; - } - - void LCD_IO_WaitSequence_Async() { - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSendAsync(NULL, 0, true); - SPI_TFT_CS_H; - } -#endif - -static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT - -#ifndef LCD_READ_ID - #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341) -#endif - -uint8_t u8g_com_stm32duino_spi_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; - - LCD_IO_Init(-1, -1); - - switch (msg) { - case U8G_COM_MSG_STOP: break; - case U8G_COM_MSG_INIT: - u8g_SetPIOutput(u8g, U8G_PI_RESET); - - u8g_Delay(50); - - if (arg_ptr) { - spi1Init(SPI_EIGHTH_SPEED); - *((uint32_t *)arg_ptr) = (LCD_READ_ID << 24) | LCD_IO_ReadData(LCD_READ_ID, 3); - spi1Init(SPI_FULL_SPEED); - } - 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: - if (isCommand) - LCD_IO_WriteReg(arg_val); - else - LCD_IO_WriteData((uint16_t)arg_val); - break; - - case U8G_COM_MSG_WRITE_SEQ: - for (uint8_t i = 0; i < arg_val; i += 2) - LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i)); - break; - - } - return 1; -} - -#endif // SPI_GRAPHICAL_TFT && !FORCE_SOFT_SPI -#endif // STM32F1 diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h index 09d79030b5..25110d7c80 100644 --- a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h @@ -26,8 +26,8 @@ #undef SD_CHECK_AND_RETRY #endif -// This platform has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT && !HAS_SPI_TFT +// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' +#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT #undef TOUCH_SCREEN #undef TOUCH_SCREEN_CALIBRATION #define HAS_TOUCH_XPT2046 1 diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp index e0047e7d59..bc1b012dc7 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC) +#if HAS_FSMC_TFT #include "tft_fsmc.h" #include diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp index 2610262b0f..1095389946 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI) +#if HAS_SPI_TFT #include "tft_spi.h" @@ -30,32 +30,32 @@ SPIClass TFT_SPI::SPIx(1); -#define SPI_TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH) -#define SPI_TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW) +#define TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH) +#define TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW) -#define SPI_TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH) -#define SPI_TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW) +#define TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH) +#define TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW) -#define SPI_TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH) -#define SPI_TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW) +#define TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH) +#define TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW) -#define SPI_TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH) -#define SPI_TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW) +#define TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH) +#define TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW) void TFT_SPI::Init() { #if PIN_EXISTS(TFT_RESET) // OUT_WRITE(TFT_RESET_PIN, HIGH); - SPI_TFT_RST_H; + TFT_RST_H; delay(100); #endif #if PIN_EXISTS(TFT_BACKLIGHT) // OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); - SPI_TFT_BLK_H; + TFT_BLK_H; #endif - SPI_TFT_DC_H; - SPI_TFT_CS_H; + TFT_DC_H; + TFT_CS_H; /** * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz @@ -87,7 +87,7 @@ void TFT_SPI::Init() { void TFT_SPI::DataTransferBegin(uint16_t DataSize) { SPIx.setDataSize(DataSize); SPIx.begin(); - SPI_TFT_CS_L; + TFT_CS_L; } uint32_t TFT_SPI::GetID() { @@ -135,7 +135,7 @@ void TFT_SPI::Transmit(uint16_t Data) { void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { DataTransferBegin(); - SPI_TFT_DC_H; + TFT_DC_H; if (MemoryIncrease == DMA_MINC_ENABLE) { SPIx.dmaSend(Data, Count, true); } diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp index e06cace741..616d05fead 100644 --- a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp @@ -19,7 +19,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_TFT_XPT2046 +#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046 #include "xpt2046.h" #include diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.h b/Marlin/src/HAL/STM32F1/tft/xpt2046.h index d2b7ad29b0..019f75efce 100644 --- a/Marlin/src/HAL/STM32F1/tft/xpt2046.h +++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.h @@ -24,16 +24,18 @@ #include #endif -#if !PIN_EXISTS(TOUCH_MISO) - #error "TOUCH_MISO_PIN is not defined." -#elif !PIN_EXISTS(TOUCH_MOSI) - #error "TOUCH_MOSI_PIN is not defined." -#elif !PIN_EXISTS(TOUCH_SCK) - #error "TOUCH_SCK_PIN is not defined." -#elif !PIN_EXISTS(TOUCH_CS) - #error "TOUCH_CS_PIN is not defined." +#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 - #ifndef TOUCH_INT_PIN #define TOUCH_INT_PIN -1 #endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 30b6fbe3d5..3544a8840f 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -57,7 +57,7 @@ #include "lcd/ultralcd.h" #if HAS_TOUCH_XPT2046 - #include "lcd/touch/xpt2046.h" + #include "lcd/touch/touch_buttons.h" #endif #if HAS_TFT_LVGL_UI diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index d8c8103a42..ccafd413cf 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -286,14 +286,15 @@ #define DELAYED_BACKLIGHT_INIT #endif -// FSMC/SPI TFT Panels (HAL STM32) -#if EITHER(TFT_320x240, TFT_480x320) +// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h +#if ANY(TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC, FSMC_GRAPHICAL_TFT) #define HAS_FSMC_TFT 1 -#elif EITHER(TFT_320x240_SPI, TFT_480x320_SPI) +#elif ANY(TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI, SPI_GRAPHICAL_TFT) #define HAS_SPI_TFT 1 #endif -#if HAS_FSMC_TFT || HAS_SPI_TFT +// Color UI +#if ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI) #define HAS_GRAPHICAL_TFT 1 #define IS_ULTIPANEL #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index d31a826778..01243219c2 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -515,6 +515,12 @@ #error "DIGIPOT_I2C is now DIGIPOT_MCP4451 (or DIGIPOT_MCP4018). Please update Configuration_adv.h." #elif defined(TOUCH_BUTTONS) #error "TOUCH_BUTTONS is now TOUCH_SCREEN. Please update your Configuration.h." +#elif defined(LCD_FULL_PIXEL_HEIGHT) + #error "LCD_FULL_PIXEL_HEIGHT is deprecated and should be removed. Please update your Configuration.h." +#elif defined(LCD_FULL_PIXEL_WIDTH) + #error "LCD_FULL_PIXEL_WIDTH is deprecated and should be removed. Please update your Configuration.h." +#elif defined(FSMC_UPSCALE) + #error "FSMC_UPSCALE is now GRAPHICAL_TFT_UPSCALE. Please update your Configuration.h." #elif defined(ANYCUBIC_TFT_MODEL) #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h." #elif defined(EVENT_GCODE_SD_STOP) diff --git a/Marlin/src/lcd/dogm/HAL_LCD_com_defines.h b/Marlin/src/lcd/dogm/HAL_LCD_com_defines.h index 1f9621e9c0..455fc2388e 100644 --- a/Marlin/src/lcd/dogm/HAL_LCD_com_defines.h +++ b/Marlin/src/lcd/dogm/HAL_LCD_com_defines.h @@ -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 diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp index e42faf0255..dc8fbc53fa 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp @@ -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 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp index 607090ba39..ea94d6c1a5 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp @@ -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); } } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h index c4b04e1c21..e40039fe86 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h @@ -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: diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index dc5e4910e9..ff9d0518d3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -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;) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp index a2795e933b..297ba723de 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp @@ -34,8 +34,6 @@ #include "pic_manager.h" #include -#include "../../../touch/xpt2046.h" - #include "../../../../MarlinCore.h" #include "../../../../module/temperature.h" #include "../../../../sd/cardreader.h" diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 391e12ba3f..23072d27c7 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -51,11 +51,11 @@ XPT2046 touch; #include -#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; diff --git a/Marlin/src/lcd/scaled_tft.h b/Marlin/src/lcd/scaled_tft.h index f22bdf696a..be846f70a9 100644 --- a/Marlin/src/lcd/scaled_tft.h +++ b/Marlin/src/lcd/scaled_tft.h @@ -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 diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp new file mode 100644 index 0000000000..8eae73df11 --- /dev/null +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -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 . + * + */ + +#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 diff --git a/Marlin/src/lcd/touch/xpt2046.h b/Marlin/src/lcd/touch/touch_buttons.h similarity index 56% rename from Marlin/src/lcd/touch/xpt2046.h rename to Marlin/src/lcd/touch/touch_buttons.h index 467317901b..451e5a5a37 100644 --- a/Marlin/src/lcd/touch/xpt2046.h +++ b/Marlin/src/lcd/touch/touch_buttons.h @@ -20,30 +20,10 @@ #include -// 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; diff --git a/Marlin/src/lcd/touch/xpt2046.cpp b/Marlin/src/lcd/touch/xpt2046.cpp deleted file mode 100644 index 4407d945d3..0000000000 --- a/Marlin/src/lcd/touch/xpt2046.cpp +++ /dev/null @@ -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 . - * - */ - -#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 - - 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 diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 6fa3006fb7..f30d9c68cf 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -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 diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index e4f0014417..5267888f44 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -44,7 +44,7 @@ #define EEPROM_PAGE_SIZE (0x800U) // 2KB, but will use 2x more (4KB) #define MARLIN_EEPROM_SIZE EEPROM_PAGE_SIZE #else - #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM + #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM #endif // @@ -104,49 +104,6 @@ //#define POWER_LOSS_PIN -1 #define FIL_RUNOUT_PIN PA15 -// -// TronXY TFT Support -// -//#define FSMC_GRAPHICAL_TFT -//#define HAS_TOUCH_XPT2046 1 - -#if ENABLED(FSMC_GRAPHICAL_TFT) - #define FSMC_UPSCALE 3 - - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - - #if NEED_TOUCH_PINS - #define TOUCH_CS_PIN PB7 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - - #define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens - #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus - - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12316 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8981 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 340 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -20 - #endif - - #endif -#endif - // SPI Flash #define SPI_FLASH_SIZE 0x200000 // 2MB #define HAS_SPI_FLASH 1 @@ -157,28 +114,18 @@ #define W25QXX_MISO_PIN PB14 #define W25QXX_SCK_PIN PB13 -#if HAS_TFT_LVGL_UI - #define HAS_SPI_FLASH_FONT 1 - #define HAS_GCODE_PREVIEW 1 - #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH 0 - #define HAS_LANG_SELECT_SCREEN 1 - #define HAS_BAK_VIEW_IN_FLASH 0 - #define HAS_LOGO_IN_FLASH 0 +// +// TronXY TFT Support +// + +#if HAS_FSMC_TFT + + // Shared FSMC #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - //#define TOUCH_INT_PIN PB6 - - #if ENABLED(TFT_LVGL_UI_SPI) - #define SPI_TFT_CS_PIN TOUCH_CS_PIN - #define SPI_TFT_SCK_PIN TOUCH_SCK_PIN - #define SPI_TFT_MISO_PIN TOUCH_MISO_PIN - #define SPI_TFT_MOSI_PIN TOUCH_MOSI_PIN - #define SPI_TFT_DC_PIN PB6 - #define SPI_TFT_RST_PIN PF11 - #endif #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 @@ -191,12 +138,23 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define LCD_PIXEL_WIDTH 480 - #define LCD_PIXEL_HEIGHT 320 - #define LCD_FULL_PIXEL_WIDTH LCD_PIXEL_WIDTH - #define LCD_FULL_PIXEL_HEIGHT LCD_PIXEL_HEIGHT - #define LCD_PIXEL_OFFSET_X 48 - #define LCD_PIXEL_OFFSET_Y 48 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_PIXEL_OFFSET_X 48 + #define TFT_PIXEL_OFFSET_Y 32 + +#endif + +#if HAS_TFT_LVGL_UI + + // LVGL + + #define HAS_SPI_FLASH_FONT 1 + #define HAS_GCODE_PREVIEW 1 + #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH 0 + #define HAS_LANG_SELECT_SCREEN 1 + #define HAS_BAK_VIEW_IN_FLASH 0 + #define HAS_LOGO_IN_FLASH 0 #define XPT2046_X_CALIBRATION -17181 #define XPT2046_Y_CALIBRATION 11434 @@ -204,31 +162,38 @@ #define XPT2046_Y_OFFSET -9 #elif ENABLED(TFT_480x320) - #define TFT_RESET_PIN PF11 - #define TFT_BACKLIGHT_PIN PD13 - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 + // Color UI + + #define TFT_DRIVER ILI9488 + #define TFT_BUFFER_SIZE 14400 #define XPT2046_X_CALIBRATION -17181 #define XPT2046_Y_CALIBRATION 11434 #define XPT2046_X_OFFSET 501 #define XPT2046_Y_OFFSET -9 - #define TOUCH_CS_PIN PB7 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI +#elif ENABLED(FSMC_GRAPHICAL_TFT) - #define TFT_DRIVER ILI9488 - #define TFT_BUFFER_SIZE 14400 + // Emulated DOGM + + #define GRAPHICAL_TFT_UPSCALE 3 + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -12316 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 8981 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 340 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -20 + #endif #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available -// We nee to use the SPI2 +// Needs to use SPI2 #define ENABLE_SPI2 #define SCK_PIN PB13 #define MISO_PIN PB14 @@ -240,5 +205,5 @@ // #define SDIO_SUPPORT #define SD_DETECT_PIN -1 // PF0, but it isn't connected -#define SDIO_CLOCK 4500000 -#define SDIO_READ_RETRIES 16 +#define SDIO_CLOCK 4500000 +#define SDIO_READ_RETRIES 16 diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 3d36de8242..d128d4e1ae 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -48,7 +48,7 @@ #define EEPROM_PAGE_SIZE (0x800U) // 2KB, but will use 2x more (4KB) #define MARLIN_EEPROM_SIZE EEPROM_PAGE_SIZE #else - #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM + #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM #endif // @@ -96,7 +96,7 @@ // #define HEATER_0_PIN PG12 // HEATER1 #define HEATER_BED_PIN PG11 // HOT BED -//#define HEATER_BED_INVERTING true +//#define HEATER_BED_INVERTING true // // Fans @@ -119,71 +119,9 @@ #define FIL_RUNOUT2_PIN PF13 #endif -// -// TronXY TFT Support -// -#if ENABLED(FSMC_GRAPHICAL_TFT) - #define FSMC_UPSCALE 3 - - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - - #if NEED_TOUCH_PINS - #define TOUCH_CS_PIN PB7 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - - #define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens - #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus - - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12316 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8981 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 340 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -20 - #endif - #endif - -#elif ENABLED(TFT_480x320) - #define TFT_RESET_PIN PF11 - #define TFT_BACKLIGHT_PIN PD13 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - - #define XPT2046_X_CALIBRATION -17181 - #define XPT2046_Y_CALIBRATION 11434 - #define XPT2046_X_OFFSET 501 - #define XPT2046_Y_OFFSET -9 - - #define TOUCH_CS_PIN PB7 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - - #define TFT_DRIVER ILI9488 - #define TFT_BUFFER_SIZE 14400 -#endif - // SPI Flash -#define SPI_FLASH_SIZE 0x200000 // 2MB -#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x200000 // 2MB +#define HAS_SPI_FLASH 1 // SPI 2 #define W25QXX_CS_PIN PB12 @@ -191,28 +129,16 @@ #define W25QXX_MISO_PIN PB14 #define W25QXX_SCK_PIN PB13 -#if HAS_TFT_LVGL_UI - #define HAS_SPI_FLASH_FONT 0 - #define HAS_GCODE_PREVIEW 1 - #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH 0 - #define HAS_LANG_SELECT_SCREEN 0 - #define HAS_BAK_VIEW_IN_FLASH 0 - #define HAS_LOGO_IN_FLASH 0 +// +// TronXY TFT Support +// +// Shared FSMC Configs +#if HAS_FSMC_TFT #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - //#define TOUCH_INT_PIN PB6 - - #if ENABLED(TFT_LVGL_UI_SPI) - #define SPI_TFT_CS_PIN TOUCH_CS_PIN - #define SPI_TFT_SCK_PIN TOUCH_SCK_PIN - #define SPI_TFT_MISO_PIN TOUCH_MISO_PIN - #define SPI_TFT_MOSI_PIN TOUCH_MOSI_PIN - #define SPI_TFT_DC_PIN PB6 - #define SPI_TFT_RST_PIN PF11 - #endif #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 @@ -225,17 +151,56 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define LCD_PIXEL_WIDTH 480 - #define LCD_PIXEL_HEIGHT 320 - #define LCD_FULL_PIXEL_WIDTH LCD_PIXEL_WIDTH - #define LCD_FULL_PIXEL_HEIGHT LCD_PIXEL_HEIGHT - #define LCD_PIXEL_OFFSET_X 48 - #define LCD_PIXEL_OFFSET_Y 48 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_PIXEL_OFFSET_X 48 + #define TFT_PIXEL_OFFSET_Y 32 + +#endif + +// LVGL Configs +#if HAS_TFT_LVGL_UI + + #define HAS_SPI_FLASH_FONT 1 + #define HAS_GCODE_PREVIEW 1 + #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH 0 + #define HAS_LANG_SELECT_SCREEN 1 + #define HAS_BAK_VIEW_IN_FLASH 0 + #define HAS_LOGO_IN_FLASH 0 #define XPT2046_X_CALIBRATION -17181 #define XPT2046_Y_CALIBRATION 11434 #define XPT2046_X_OFFSET 501 #define XPT2046_Y_OFFSET -9 + +// Color UI Configs +#elif ENABLED(TFT_480x320) + + #define TFT_DRIVER ILI9488 + #define TFT_BUFFER_SIZE 14400 + + #define XPT2046_X_CALIBRATION -17181 + #define XPT2046_Y_CALIBRATION 11434 + #define XPT2046_X_OFFSET 501 + #define XPT2046_Y_OFFSET -9 + +// Emulated DOGM +#elif ENABLED(FSMC_GRAPHICAL_TFT) + #define GRAPHICAL_TFT_UPSCALE 3 + + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -12316 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 8981 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 340 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -20 + #endif + #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available @@ -251,5 +216,5 @@ // #define SDIO_SUPPORT #define SD_DETECT_PIN -1 // PF0, but it isn't connected -#define SDIO_CLOCK 4500000 -#define SDIO_READ_RETRIES 16 +#define SDIO_CLOCK 4500000 +#define SDIO_READ_RETRIES 16 diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 490fb617d1..32e7e2993c 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -86,8 +86,8 @@ #define FAN_PIN PA15 // pin 77 (4cm Fan) #define FAN_SOFT_PWM // Required to avoid issues with heating or STLink -#define FAN_MIN_PWM 35 // Fan will not start in 1-30 range -#define FAN_MAX_PWM 255 +#define FAN_MIN_PWM 35 // Fan will not start in 1-30 range +#define FAN_MAX_PWM 255 //#define BEEPER_PIN PD13 // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor // Can drive a PC Buzzer, if connected between PWM and 5V pins @@ -130,11 +130,11 @@ #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 -#define FSMC_UPSCALE 2 -#define LCD_FULL_PIXEL_WIDTH 320 -#define LCD_FULL_PIXEL_HEIGHT 240 -#define LCD_PIXEL_OFFSET_X 32 -#define LCD_PIXEL_OFFSET_Y 32 +#define GRAPHICAL_TFT_UPSCALE 2 +#define TFT_WIDTH 320 +#define TFT_HEIGHT 240 +#define TFT_PIXEL_OFFSET_X 32 +#define TFT_PIXEL_OFFSET_Y 32 /** * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer @@ -160,12 +160,12 @@ #if ENABLED(SPI_EEPROM) // SPI1 EEPROM Winbond W25Q64 (8MB/64Mbits) - #define SPI_CHAN_EEPROM1 1 + #define SPI_CHAN_EEPROM1 1 #define SPI_EEPROM1_CS PC5 // pin 34 #define EEPROM_SCK BOARD_SPI1_SCK_PIN // PA5 pin 30 #define EEPROM_MISO BOARD_SPI1_MISO_PIN // PA6 pin 31 #define EEPROM_MOSI BOARD_SPI1_MOSI_PIN // PA7 pin 32 - #define EEPROM_PAGE_SIZE 0x1000U // 4KB (from datasheet) + #define EEPROM_PAGE_SIZE 0x1000U // 4KB (from datasheet) #define MARLIN_EEPROM_SIZE 16UL * (EEPROM_PAGE_SIZE) // Limit to 64KB for now... #elif ENABLED(FLASH_EEPROM_EMULATION) // SoC Flash (framework-arduinoststm32-maple/STM32F1/libraries/EEPROM/EEPROM.h) @@ -173,5 +173,5 @@ #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) #define MARLIN_EEPROM_SIZE (EEPROM_PAGE_SIZE) #else - #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM + #define MARLIN_EEPROM_SIZE 0x800U // On SD, Limit to 2KB, require this amount of RAM #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 948663f6f0..6a015a4709 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -127,10 +127,10 @@ #define PS_ON_PIN PA3 // PW_OFF //#define SUICIDE_PIN PB2 // Enable MKSPWC support ROBIN NANO v1.2 ONLY -//#define SUICIDE_PIN_INVERTING false +//#define SUICIDE_PIN_INVERTING false //#define KILL_PIN PA2 // Enable MKSPWC support ROBIN NANO v1.2 ONLY -//#define KILL_PIN_INVERTING true // Enable MKSPWC support ROBIN NANO v1.2 ONLY +//#define KILL_PIN_INVERTING true // Enable MKSPWC support ROBIN NANO v1.2 ONLY #define SERVO0_PIN PA8 // Enable BLTOUCH support ROBIN NANO v1.2 ONLY @@ -138,7 +138,7 @@ #define MT_DET_1_PIN PA4 #define MT_DET_2_PIN PE6 -#define MT_DET_PIN_INVERTING false +#define MT_DET_PIN_INVERTING false #define WIFI_IO0_PIN PC13 @@ -150,7 +150,7 @@ #endif #define SDIO_SUPPORT -#define SDIO_CLOCK 4500000 // 4.5 MHz +#define SDIO_CLOCK 4500000 // 4.5 MHz #define SD_DETECT_PIN PD12 #define ONBOARD_SD_CS_PIN PC11 @@ -165,8 +165,8 @@ * to let the bootloader init the screen. */ -#if ENABLED(TFT_LVGL_UI_FSMC) - +// Shared FSMC Configs +#if HAS_FSMC_TFT #define FSMC_CS_PIN PD7 // NE4 #define FSMC_RS_PIN PD11 // A0 @@ -175,59 +175,10 @@ #define TOUCH_MISO_PIN PB14 // SPI2_MISO #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI - #define LCD_BACKLIGHT_PIN PD13 - - #define XPT2046_X_CALIBRATION 17880 - #define XPT2046_Y_CALIBRATION -12234 - #define XPT2046_X_OFFSET -45 - #define XPT2046_Y_OFFSET 349 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - -#elif ENABLED(FSMC_GRAPHICAL_TFT) - - #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h - #define DOGLCD_SCK -1 - - #ifndef FSMC_UPSCALE - #define FSMC_UPSCALE 3 - #endif - #ifndef LCD_FULL_PIXEL_WIDTH - #define LCD_FULL_PIXEL_WIDTH 480 - #endif - #ifndef LCD_PIXEL_OFFSET_X - #define LCD_PIXEL_OFFSET_X 48 - #endif - #ifndef LCD_FULL_PIXEL_HEIGHT - #define LCD_FULL_PIXEL_HEIGHT 320 - #endif - #ifndef LCD_PIXEL_OFFSET_Y - #define LCD_PIXEL_OFFSET_Y 32 - #endif - - #define FSMC_CS_PIN PD7 // NE4 - #define FSMC_RS_PIN PD11 // A0 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - #define LCD_RESET_PIN PC6 // FSMC_RST #define LCD_BACKLIGHT_PIN PD13 - #if NEED_TOUCH_PINS - #define TOUCH_CS_PIN PA7 // SPI2_NSS - #define TOUCH_SCK_PIN PB13 // SPI2_SCK - #define TOUCH_MISO_PIN PB14 // SPI2_MISO - #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI - #endif - -#elif ENABLED(TFT_480x320) - #define TFT_RESET_PIN PC6 + #define TFT_RESET_PIN PC6 // FSMC_RST #define TFT_BACKLIGHT_PIN PD13 #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT @@ -236,23 +187,66 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 2 +#endif + +// LVGL Configs +#if ENABLED(TFT_LVGL_UI_FSMC) + #define XPT2046_X_CALIBRATION 17880 #define XPT2046_Y_CALIBRATION -12234 #define XPT2046_X_OFFSET -45 #define XPT2046_Y_OFFSET 349 - #define TOUCH_CS_PIN PA7 // SPI2_NSS - #define TOUCH_SCK_PIN PB13 // SPI2_SCK - #define TOUCH_MISO_PIN PB14 // SPI2_MISO - #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI +// Emulated DOGM Configs +#elif ENABLED(FSMC_GRAPHICAL_TFT) - #define TFT_DRIVER ILI9488 - #define TFT_BUFFER_SIZE 14400 + #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h + #define DOGLCD_SCK -1 + + #ifndef GRAPHICAL_TFT_UPSCALE + #define GRAPHICAL_TFT_UPSCALE 3 + #endif + #ifndef TFT_WIDTH + #define TFT_WIDTH 480 + #endif + #ifndef TFT_PIXEL_OFFSET_X + #define TFT_PIXEL_OFFSET_X 48 + #endif + #ifndef TFT_HEIGHT + #define TFT_HEIGHT 320 + #endif + #ifndef TFT_PIXEL_OFFSET_Y + #define TFT_PIXEL_OFFSET_Y 32 + #endif + + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION 12149 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION -8746 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET -35 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET 256 + #endif + +#elif ENABLED(TFT_480x320) + #define XPT2046_X_CALIBRATION 17880 + #define XPT2046_Y_CALIBRATION -12234 + #define XPT2046_X_OFFSET -45 + #define XPT2046_Y_OFFSET 349 + + #define TFT_DRIVER ILI9488 + #define TFT_BUFFER_SIZE 14400 #define ILI9488_ORIENTATION ILI9488_MADCTL_MX | ILI9488_MADCTL_MV #endif -#define HAS_SPI_FLASH 1 -#define SPI_FLASH_SIZE 0x1000000 // 16MB +#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x1000000 // 16MB #if HAS_SPI_FLASH #define W25QXX_CS_PIN PB12 #define W25QXX_MOSI_PIN PB15 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index feac729c73..0f9e6eb371 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -29,6 +29,8 @@ #error "Oops! Select an STM32F1 board in 'Tools > Board.'" #elif HOTENDS > 2 || E_STEPPERS > 2 #error "MKS Robin nano supports up to 2 hotends / E-steppers. Comment out this line to continue." +#elif HAS_FSMC_TFT + #error "MKS Robin nano v2 doesn't support FSMC-based TFT displays." #endif #define BOARD_INFO_NAME "MKS Robin nano V2.0" @@ -47,13 +49,13 @@ #if EITHER(NO_EEPROM_SELECTED, I2C_EEPROM) #define I2C_EEPROM // EEPROM on I2C-0 - #define MARLIN_EEPROM_SIZE 0x1000 // 4KB + #define MARLIN_EEPROM_SIZE 0x1000 // 4KB #endif // // Note: MKS Robin board is using SPI2 interface. // -//#define SPI_MODULE 2 +//#define SPI_MODULE 2 #define ENABLE_SPI2 // @@ -162,7 +164,7 @@ #define E1_SERIAL_RX_PIN PD8 // Reduce baud rate to improve software serial reliability - #define TMC_BAUD_RATE 19200 + #define TMC_BAUD_RATE 19200 #endif // TMC2208 || TMC2209 // @@ -194,10 +196,10 @@ #define PS_ON_PIN PA3 // PW_OFF //#define SUICIDE_PIN PB2 // Enable MKSPWC support ROBIN NANO v1.2 ONLY -//#define SUICIDE_PIN_INVERTING false +//#define SUICIDE_PIN_INVERTING false //#define KILL_PIN PA2 // Enable MKSPWC support ROBIN NANO v1.2 ONLY -//#define KILL_PIN_INVERTING true // Enable MKSPWC support ROBIN NANO v1.2 ONLY +//#define KILL_PIN_INVERTING true // Enable MKSPWC support ROBIN NANO v1.2 ONLY #define SERVO0_PIN PA8 // Enable BLTOUCH support ROBIN NANO v1.2 ONLY @@ -205,7 +207,7 @@ #define MT_DET_1_PIN PA4 #define MT_DET_2_PIN PE6 -#define MT_DET_PIN_INVERTING false +#define MT_DET_PIN_INVERTING false #ifndef FIL_RUNOUT_PIN #define FIL_RUNOUT_PIN MT_DET_1_PIN @@ -224,7 +226,7 @@ #endif #define SDIO_SUPPORT -#define SDIO_CLOCK 4500000 // 4.5 MHz +#define SDIO_CLOCK 4500000 // 4.5 MHz #define SD_DETECT_PIN PD12 #define ONBOARD_SD_CS_PIN PC11 @@ -241,14 +243,9 @@ * to let the bootloader init the screen. */ -#if ENABLED(TFT_LVGL_UI_SPI) +#if HAS_SPI_TFT - #define SPI_TFT_CS_PIN PD11 - #define SPI_TFT_SCK_PIN PA5 - #define SPI_TFT_MISO_PIN PA6 - #define SPI_TFT_MOSI_PIN PA7 - #define SPI_TFT_DC_PIN PD10 - #define SPI_TFT_RST_PIN PC6 + // Shared SPI TFT #define LCD_BACKLIGHT_PIN PD13 @@ -261,87 +258,88 @@ #define BTN_EN2 PE11 #define BTN_ENC PE13 - #define TFT_CS_PIN PD11 - #define TFT_SCK_PIN PA5 - #define TFT_MISO_PIN PA6 - #define TFT_MOSI_PIN PA7 - #define TFT_DC_PIN PD10 - #define TFT_RST_PIN PC6 - #define TFT_A0_PIN TFT_DC_PIN + #define TFT_CS_PIN PD11 + #define TFT_SCK_PIN PA5 + #define TFT_MISO_PIN PA6 + #define TFT_MOSI_PIN PA7 + #define TFT_DC_PIN PD10 + #define TFT_RST_PIN PC6 + #define TFT_A0_PIN TFT_DC_PIN - #define TFT_RESET_PIN PC6 - #define TFT_BACKLIGHT_PIN PD13 + #define TFT_RESET_PIN PC6 + #define TFT_BACKLIGHT_PIN PD13 - #define XPT2046_X_CALIBRATION -17253 - #define XPT2046_Y_CALIBRATION 11579 - #define XPT2046_X_OFFSET 514 - #define XPT2046_Y_OFFSET -24 #define TOUCH_BUTTONS_HW_SPI - #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 - #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 + #define LCD_READ_ID 0xD3 + #define LCD_USE_DMA_SPI + #endif -#if HAS_SPI_LCD +#if ENABLED(TFT_LVGL_UI_SPI) - #if ENABLED(SPI_GRAPHICAL_TFT) // Emulated DOGM SPI - #define SPI_TFT_CS_PIN PD11 - #define SPI_TFT_SCK_PIN PA5 - #define SPI_TFT_MISO_PIN PA6 - #define SPI_TFT_MOSI_PIN PA7 - #define SPI_TFT_DC_PIN PD10 - #define SPI_TFT_RST_PIN PC6 + // LVGL - #define LCD_BACKLIGHT_PIN PD13 + #define XPT2046_X_CALIBRATION -17253 + #define XPT2046_Y_CALIBRATION 11579 + #define XPT2046_X_OFFSET 514 + #define XPT2046_Y_OFFSET -24 - #define LCD_READ_ID 0xD3 - #define LCD_USE_DMA_SPI +#elif ENABLED(SPI_GRAPHICAL_TFT) - #define TOUCH_BUTTONS_HW_SPI - #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + // Emulated DOGM SPI - //#define TOUCH_SCREEN - #if EITHER(TOUCH_SCREEN, NEED_TOUCH_PINS) - #define TOUCH_CS_PIN PE14 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -11386 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 8684 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 339 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -18 + #endif - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -5481 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 4000 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 343 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 0 - #endif - #endif + #ifndef GRAPHICAL_TFT_UPSCALE + #define GRAPHICAL_TFT_UPSCALE 3 + #endif + #ifndef TFT_PIXEL_OFFSET_Y + #define TFT_PIXEL_OFFSET_Y 32 + #endif - #ifndef FSMC_UPSCALE - #define FSMC_UPSCALE 3 - #endif - #ifndef LCD_PIXEL_OFFSET_Y - #define LCD_PIXEL_OFFSET_Y 32 - #endif + #define BTN_ENC PE13 + #define BTN_EN1 PE8 + #define BTN_EN2 PE11 - #define BTN_ENC PE13 - #define BTN_EN1 PE8 - #define BTN_EN2 PE11 + #define LCD_PINS_ENABLE PD13 + #define LCD_PINS_RS PC6 - #define LCD_PINS_ENABLE PD13 - #define LCD_PINS_RS PC6 +#elif ENABLED(TFT_480x320_SPI) + #define XPT2046_X_CALIBRATION -17253 + #define XPT2046_Y_CALIBRATION 11579 + #define XPT2046_X_OFFSET 514 + #define XPT2046_Y_OFFSET -24 - #elif ENABLED(MKS_MINI_12864) + #define TFT_DRIVER ST7796 + #define TFT_BUFFER_SIZE 14400 + +#endif + +#if HAS_SPI_LCD && !HAS_SPI_TFT + + // NON TFT Displays + + #if ENABLED(MKS_MINI_12864) // MKS MINI12864 and MKS LCD12864B // If using MKS LCD12864A (Need to remove RPK2 resistor) @@ -357,37 +355,6 @@ #define MKS_LCD12864B #undef SHOW_BOOTSCREEN - #elif ENABLED(TFT_480x320_SPI) - #define TFT_CS_PIN PD11 - #define TFT_SCK_PIN PA5 - #define TFT_MISO_PIN PA6 - #define TFT_MOSI_PIN PA7 - #define TFT_DC_PIN PD10 - #define TFT_RST_PIN PC6 - #define TFT_A0_PIN TFT_DC_PIN - - #define TFT_RESET_PIN PC6 - #define TFT_BACKLIGHT_PIN PD13 - - #define XPT2046_X_CALIBRATION -17253 - #define XPT2046_Y_CALIBRATION 11579 - #define XPT2046_X_OFFSET 514 - #define XPT2046_Y_OFFSET -24 - - #define TOUCH_CS_PIN PE14 // SPI1_NSS - #define TOUCH_SCK_PIN PA5 // SPI1_SCK - #define TOUCH_MISO_PIN PA6 // SPI1_MISO - #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - - #define TFT_DRIVER ST7796 - #define TFT_BUFFER_SIZE 14400 - - #define LCD_READ_ID 0xD3 - #define LCD_USE_DMA_SPI - - #define TOUCH_BUTTONS_HW_SPI - #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 - #else // !MKS_MINI_12864 #define LCD_PINS_D4 PE14 @@ -409,10 +376,10 @@ #endif // !MKS_MINI_12864 -#endif // HAS_SPI_LCD +#endif // HAS_SPI_LCD && !HAS_SPI_TFT -#define HAS_SPI_FLASH 1 -#define SPI_FLASH_SIZE 0x1000000 // 16MB +#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x1000000 // 16MB #if HAS_SPI_FLASH #define W25QXX_CS_PIN PB12 #define W25QXX_MOSI_PIN PB15 diff --git a/buildroot/share/scripts/pinsformat.js b/buildroot/share/scripts/pinsformat.js index 3e2a57b556..a82c2f2659 100755 --- a/buildroot/share/scripts/pinsformat.js +++ b/buildroot/share/scripts/pinsformat.js @@ -38,10 +38,12 @@ for (let m of mpatt) mexpr.push(new RegExp('^' + m + '$')); const argv = process.argv.slice(2), argc = argv.length; -var src_file = 0, src_name = 'STDIN', dst_file; +var src_file = 0, src_name = 'STDIN', dst_file, do_log = false; if (argc > 0) { - src_file = src_name = argv[0]; - dst_file = argv[argc > 1 ? 1 : 0]; + let ind = 0; + if (argv[0] == '-v') { do_log = true; ind++; } + dst_file = src_file = src_name = argv[ind++]; + if (ind < argc) dst_file = argv[ind]; } // Read from file or STDIN until it terminates @@ -81,7 +83,7 @@ function process_text(txt) { aliasPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([A-Z_][A-Z0-9_()]+)\\s*(//.*)?$'), switchPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'), undefPatt = new RegExp('^(\\s*(//)?#undef)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'), - defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+(\\w+)\\s*(//.*)?$'), + defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([-_\\w]+)\\s*(//.*)?$'), condPatt = new RegExp('^(\\s*(//)?#(if|ifn?def|else|elif)(\\s+\\S+)*)\\s+(//.*)$'), commPatt = new RegExp('^\\s{20,}(//.*)?$'); const col_value_lj = col_comment - patt.pad - 2; @@ -98,6 +100,7 @@ function process_text(txt) { // // #define MY_PIN [pin] // + if (do_log) console.log("pin:", line); const pinnum = r[4].charAt(0) == 'P' ? r[4] : r[4].lpad(patt.pad); line = r[1] + ' ' + r[3]; line = line.rpad(col_value_lj) + pinnum; @@ -107,31 +110,57 @@ function process_text(txt) { // // #define MY_PIN -1 // + if (do_log) console.log("pin -1:", line); line = r[1] + ' ' + r[3]; line = line.rpad(col_value_lj) + '-1'; if (r[5]) line = line.rpad(col_comment) + r[5]; } else if ((r = skipPatt.exec(line)) !== null) { + // + // #define SKIP_ME + // + if (do_log) console.log("skip:", line); } else if ((r = aliasPatt.exec(line)) !== null) { + // + // #define ALIAS OTHER + // + if (do_log) console.log("alias:", line); line = r[1] + ' ' + r[3]; line += r[4].lpad(col_value_rj + 1 - line.length); if (r[5]) line = line.rpad(col_comment) + r[5]; } else if ((r = switchPatt.exec(line)) !== null) { + // + // #define SWITCH + // + if (do_log) console.log("switch:", line); line = r[1] + ' ' + r[3]; if (r[4]) line = line.rpad(col_comment) + r[4]; check_comment_next = true; } else if ((r = defPatt.exec(line)) !== null) { - line = r[1] + ' ' + r[3] + ' ' + r[4]; - if (r[5]) line = line.rpad(col_comment) + r[5]; + // + // #define ... + // + if (do_log) console.log("def:", line); + line = r[1] + ' ' + r[3] + ' '; + line += r[4].lpad(col_value_rj + 1 - line.length); + if (r[5]) line = line.rpad(col_comment - 1) + ' ' + r[5]; } else if ((r = undefPatt.exec(line)) !== null) { + // + // #undef ... + // + if (do_log) console.log("undef:", line); line = r[1] + ' ' + r[3]; if (r[4]) line = line.rpad(col_comment) + r[4]; } else if ((r = condPatt.exec(line)) !== null) { + // + // #if ... + // + if (do_log) console.log("cond:", line); line = r[1].rpad(col_comment) + r[5]; check_comment_next = true; }