From 5deca5a18f9f51f1e9e34863a28f167974c451d8 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 1 Nov 2020 23:15:06 -0300 Subject: [PATCH] Increase SPI Speed on LPC. Color and Classic UI for MKS SGEN L. (#19945) --- Marlin/src/HAL/LPC1768/HAL_SPI.cpp | 4 +- Marlin/src/HAL/LPC1768/include/SPI.h | 15 ++++--- Marlin/src/HAL/LPC1768/tft/tft_spi.cpp | 4 +- Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h | 53 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp index cb0d54c003..b800721c5a 100644 --- a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp +++ b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp @@ -357,8 +357,8 @@ void SPIClass::setDataSize(uint32_t ds) { void SPIClass::updateSettings() { //SSP_DeInit(_currentSetting->spi_d); //todo: need force de init?! - // divide PCLK by 2 for SSP0 - CLKPWR_SetPCLKDiv(_currentSetting->spi_d == LPC_SSP0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2); + // Divide PCLK by 2 for SSP0 + //CLKPWR_SetPCLKDiv(_currentSetting->spi_d == LPC_SSP0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2); SSP_CFG_Type HW_SPI_init; // data structure to hold init values SSP_ConfigStructInit(&HW_SPI_init); // set values for SPI mode diff --git a/Marlin/src/HAL/LPC1768/include/SPI.h b/Marlin/src/HAL/LPC1768/include/SPI.h index 9da2a32556..ffcd87fe96 100644 --- a/Marlin/src/HAL/LPC1768/include/SPI.h +++ b/Marlin/src/HAL/LPC1768/include/SPI.h @@ -37,13 +37,14 @@ #define DATA_SIZE_8BIT SSP_DATABIT_8 #define DATA_SIZE_16BIT SSP_DATABIT_16 -#define SPI_CLOCK_DIV2 8333333 //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED -#define SPI_CLOCK_DIV4 4166667 //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED -#define SPI_CLOCK_DIV8 2083333 //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED -#define SPI_CLOCK_DIV16 1000000 //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED -#define SPI_CLOCK_DIV32 500000 //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5 -#define SPI_CLOCK_DIV64 250000 //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6 -#define SPI_CLOCK_DIV128 125000 //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h +#define SPI_CLOCK_MAX_TFT 30000000UL +#define SPI_CLOCK_DIV2 8333333 //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED +#define SPI_CLOCK_DIV4 4166667 //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED +#define SPI_CLOCK_DIV8 2083333 //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED +#define SPI_CLOCK_DIV16 1000000 //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED +#define SPI_CLOCK_DIV32 500000 //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5 +#define SPI_CLOCK_DIV64 250000 //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6 +#define SPI_CLOCK_DIV128 125000 //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h #define SPI_CLOCK_MAX SPI_CLOCK_DIV2 diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp index 84907acd07..a2cb66ab5b 100644 --- a/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp +++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp @@ -89,7 +89,7 @@ void TFT_SPI::Init() { #elif TFT_MISO_PIN == BOARD_SPI2_MISO_PIN SPIx.setModule(2); #endif - SPIx.setClock(SPI_CLOCK_MAX); + SPIx.setClock(SPI_CLOCK_MAX_TFT); SPIx.setBitOrder(MSBFIRST); SPIx.setDataMode(SPI_MODE0); } @@ -125,7 +125,7 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) { } DataTransferEnd(); - SPIx.setClock(SPI_CLOCK_MAX); + SPIx.setClock(SPI_CLOCK_MAX_TFT); #endif return data >> 7; diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h index 0a8f3a6da8..f948c32f92 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h @@ -249,6 +249,59 @@ #define LCD_PINS_ENABLE P1_22 #define LCD_PINS_D4 P0_17 + #elif HAS_SPI_TFT // Config for Classic UI (emulated DOGM) and Color UI + #define TFT_CS_PIN P1_00 + #define TFT_A0_PIN P1_22 + #define TFT_DC_PIN P1_22 + #define TFT_MISO_PIN P0_08 + #define TFT_BACKLIGHT_PIN P0_18 + #define TFT_RESET_PIN P0_16 + + #define LCD_USE_DMA_SPI + + #define TOUCH_INT_PIN P0_17 + #define TOUCH_CS_PIN P0_15 + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 2 + + // Disable any LCD related PINs config + #define LCD_PINS_ENABLE -1 + #define LCD_PINS_RS -1 + + // XPT2046 Touch Screen calibration + #if ENABLED(TFT_CLASSIC_UI) + #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 689 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -273 + #endif + #elif ENABLED(TFT_COLOR_UI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -16741 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 11258 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 1024 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -367 + #endif + + #define TFT_BUFFER_SIZE 2400 + #endif + + #define BTN_EN1 P3_25 + #define BTN_EN2 P3_26 + #elif IS_TFTGLCD_PANEL #undef BEEPER_PIN