From fadc8a1944600f849a660f8b52439524b7d768b2 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Wed, 23 Dec 2020 23:01:21 -0300 Subject: [PATCH] LVGL and Classic UI for STM32 (#20552) --- Marlin/src/HAL/STM32/HAL_SPI.cpp | 1 - Marlin/src/HAL/STM32/MarlinSPI.cpp | 12 ++++--- Marlin/src/HAL/STM32/tft/tft_fsmc.cpp | 30 ++++++++-------- Marlin/src/HAL/STM32/tft/tft_fsmc.h | 9 +++-- Marlin/src/HAL/STM32/tft/tft_spi.cpp | 10 ++++-- Marlin/src/HAL/STM32/tft/tft_spi.h | 7 ++++ Marlin/src/HAL/STM32/tft/xpt2046.cpp | 22 +----------- Marlin/src/HAL/STM32/tft/xpt2046.h | 5 +-- Marlin/src/gcode/calibrate/G34.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- Marlin/src/inc/SanityCheck.h | 2 +- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 17 +++++---- Marlin/src/lcd/tft/tft.h | 2 +- Marlin/src/lcd/tft_io/tft_io.h | 2 +- Marlin/src/lcd/touch/touch_buttons.cpp | 4 ++- Marlin/src/pins/stm32f4/pins_ANET_ET4.h | 6 +++- .../src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h | 24 ++----------- .../src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h | 26 ++------------ .../PlatformIO/scripts/anet_et4_openblt.py | 14 ++++++++ .../PlatformIO/scripts/stm32_bootloader.py | 10 +++--- .../variants/MARLIN_F4x7Vx/PeripheralPins.c | 4 +-- platformio.ini | 35 +++++++++++-------- 22 files changed, 113 insertions(+), 133 deletions(-) create mode 100644 buildroot/share/PlatformIO/scripts/anet_et4_openblt.py diff --git a/Marlin/src/HAL/STM32/HAL_SPI.cpp b/Marlin/src/HAL/STM32/HAL_SPI.cpp index f947e6ef3..d79f72cad 100644 --- a/Marlin/src/HAL/STM32/HAL_SPI.cpp +++ b/Marlin/src/HAL/STM32/HAL_SPI.cpp @@ -157,7 +157,6 @@ static SPISettings spiConfig; SPI.setMISO(MISO_PIN); SPI.setMOSI(MOSI_PIN); SPI.setSCLK(SCK_PIN); - SPI.setSSEL(SS_PIN); #endif SPI.begin(); diff --git a/Marlin/src/HAL/STM32/MarlinSPI.cpp b/Marlin/src/HAL/STM32/MarlinSPI.cpp index 399430f5e..5086b4178 100644 --- a/Marlin/src/HAL/STM32/MarlinSPI.cpp +++ b/Marlin/src/HAL/STM32/MarlinSPI.cpp @@ -60,7 +60,6 @@ void MarlinSPI::setupDma(SPI_HandleTypeDef &_spiHandle, DMA_HandleTypeDef &_dmaH _dmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; } #ifdef STM32F4xx - _dmaHandle.Init.Channel = DMA_CHANNEL_3; _dmaHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; #endif @@ -73,7 +72,8 @@ void MarlinSPI::setupDma(SPI_HandleTypeDef &_spiHandle, DMA_HandleTypeDef &_dmaH _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA1_Channel3 : DMA1_Channel2; #elif defined(STM32F4xx) __HAL_RCC_DMA2_CLK_ENABLE(); - _dmaHandle.Instance = DMA2_Stream3; + _dmaHandle.Init.Channel = DMA_CHANNEL_3; + _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA2_Stream3 : DMA2_Stream0; #endif } #endif @@ -83,7 +83,9 @@ void MarlinSPI::setupDma(SPI_HandleTypeDef &_spiHandle, DMA_HandleTypeDef &_dmaH __HAL_RCC_DMA1_CLK_ENABLE(); _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA1_Channel5 : DMA1_Channel4; #elif defined(STM32F4xx) - //TODO: f4 dma config + __HAL_RCC_DMA1_CLK_ENABLE(); + _dmaHandle.Init.Channel = DMA_CHANNEL_0; + _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA1_Stream4 : DMA1_Stream3; #endif } #endif @@ -93,7 +95,9 @@ void MarlinSPI::setupDma(SPI_HandleTypeDef &_spiHandle, DMA_HandleTypeDef &_dmaH __HAL_RCC_DMA2_CLK_ENABLE(); _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA2_Channel2 : DMA2_Channel1; #elif defined(STM32F4xx) - //TODO: f4 dma config + __HAL_RCC_DMA1_CLK_ENABLE(); + _dmaHandle.Init.Channel = DMA_CHANNEL_0; + _dmaHandle.Instance = (direction == DMA_MEMORY_TO_PERIPH) ? DMA1_Stream5 : DMA1_Stream2; #endif } #endif diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp index 2a5ad4595..87ca2dbbe 100644 --- a/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp +++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp @@ -154,29 +154,27 @@ uint32_t TFT_FSMC::ReadID(tft_data_t Reg) { } bool TFT_FSMC::isBusy() { - if (__IS_DMA_ENABLED(&DMAtx)) + #if defined(STM32F1xx) + volatile bool dmaEnabled = (DMAtx.Instance->CCR & DMA_CCR_EN) != RESET; + #elif defined(STM32F4xx) + volatile bool dmaEnabled = DMAtx.Instance->CR & DMA_SxCR_EN; + #endif + if (dmaEnabled) { if (__HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx)) != 0 || __HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx)) != 0) Abort(); - return __IS_DMA_ENABLED(&DMAtx); + } + else + Abort(); + return dmaEnabled; } void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { DMAtx.Init.PeriphInc = MemoryIncrease; HAL_DMA_Init(&DMAtx); - - __HAL_DMA_CLEAR_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx)); - __HAL_DMA_CLEAR_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx)); - - #ifdef STM32F1xx - DMAtx.Instance->CNDTR = Count; - DMAtx.Instance->CPAR = (uint32_t)Data; - DMAtx.Instance->CMAR = (uint32_t)&(LCD->RAM); - #elif defined(STM32F4xx) - DMAtx.Instance->NDTR = Count; - DMAtx.Instance->PAR = (uint32_t)Data; - DMAtx.Instance->M0AR = (uint32_t)&(LCD->RAM); - #endif - __HAL_DMA_ENABLE(&DMAtx); + DataTransferBegin(); + HAL_DMA_Start(&DMAtx, (uint32_t)Data, (uint32_t)&(LCD->RAM), Count); + HAL_DMA_PollForTransfer(&DMAtx, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY); + Abort(); } #endif // HAS_FSMC_TFT diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.h b/Marlin/src/HAL/STM32/tft/tft_fsmc.h index ad39d10d6..7c40151e2 100644 --- a/Marlin/src/HAL/STM32/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.h @@ -25,10 +25,8 @@ #ifdef STM32F1xx #include "stm32f1xx_hal.h" - #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN) #elif defined(STM32F4xx) #include "stm32f4xx_hal.h" - #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN) #else #error "FSMC TFT is currently only supported on STM32F1 and STM32F4 hardware." #endif @@ -77,6 +75,13 @@ class TFT_FSMC { static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_ENABLE, Data, Count); } static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_PINC_DISABLE, &Data, Count); } + static void WriteMultiple(uint16_t Color, uint32_t Count) { + static uint16_t Data; Data = Color; + while (Count > 0) { + TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count); + Count = Count > 0xFFFF ? Count - 0xFFFF : 0; + } + } }; diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.cpp b/Marlin/src/HAL/STM32/tft/tft_spi.cpp index 1c61d0952..3cb797d5f 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32/tft/tft_spi.cpp @@ -88,7 +88,7 @@ void TFT_SPI::Init() { #elif defined(STM32F4xx) __HAL_RCC_DMA1_CLK_ENABLE(); DMAtx.Instance = DMA1_Stream4; - DMAtx.Init.Channel = DMA_CHANNEL_4; + DMAtx.Init.Channel = DMA_CHANNEL_0; #endif } #endif @@ -101,7 +101,7 @@ void TFT_SPI::Init() { #elif defined(STM32F4xx) __HAL_RCC_DMA1_CLK_ENABLE(); DMAtx.Instance = DMA1_Stream5; - DMAtx.Init.Channel = DMA_CHANNEL_5; + DMAtx.Init.Channel = DMA_CHANNEL_0; #endif } #endif @@ -183,6 +183,9 @@ bool TFT_SPI::isBusy() { } void TFT_SPI::Abort() { + // Wait for any running spi + while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {} + while ((SPIx.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY) {} // First, abort any running dma HAL_DMA_Abort(&DMAtx); // DeInit objects @@ -223,6 +226,9 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun __HAL_SPI_ENABLE(&SPIx); SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); /* Enable Tx DMA Request */ + + HAL_DMA_PollForTransfer(&DMAtx, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY); + Abort(); } #endif // HAS_SPI_TFT diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.h b/Marlin/src/HAL/STM32/tft/tft_spi.h index d477b58c0..667b5f366 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32/tft/tft_spi.h @@ -64,4 +64,11 @@ public: static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); } static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } + static void WriteMultiple(uint16_t Color, uint32_t Count) { + static uint16_t Data; Data = Color; + while (Count > 0) { + TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count); + Count = Count > 0xFFFF ? Count - 0xFFFF : 0; + } + } }; diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.cpp b/Marlin/src/HAL/STM32/tft/xpt2046.cpp index 7e2dbfd15..04294e669 100644 --- a/Marlin/src/HAL/STM32/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32/tft/xpt2046.cpp @@ -23,7 +23,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_TFT_XPT2046 +#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS #include "xpt2046.h" #include "pinconfig.h" @@ -31,7 +31,6 @@ uint16_t delta(uint16_t a, uint16_t b) { return a > b ? a - b : b - a; } SPI_HandleTypeDef XPT2046::SPIx; -DMA_HandleTypeDef XPT2046::DMAtx; void XPT2046::Init() { SPI_TypeDef *spiInstance; @@ -71,34 +70,16 @@ void XPT2046::Init() { if (SPIx.Instance == SPI1) { __HAL_RCC_SPI1_CLK_ENABLE(); SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - #ifdef STM32F1xx - DMAtx.Instance = DMA1_Channel3; - #elif defined(STM32F4xx) - DMAtx.Instance = DMA2_Stream3; // DMA2_Stream5 - #endif - //SERIAL_ECHO_MSG(" Touch Screen on SPI1"); } #endif #ifdef SPI2_BASE if (SPIx.Instance == SPI2) { __HAL_RCC_SPI2_CLK_ENABLE(); - #ifdef STM32F1xx - DMAtx.Instance = DMA1_Channel5; - #elif defined(STM32F4xx) - DMAtx.Instance = DMA1_Stream4; - #endif - //SERIAL_ECHO_MSG(" Touch Screen on SPI2"); } #endif #ifdef SPI3_BASE if (SPIx.Instance == SPI3) { __HAL_RCC_SPI3_CLK_ENABLE(); - #ifdef STM32F1xx - DMAtx.Instance = DMA2_Channel2; - #elif defined(STM32F4xx) - DMAtx.Instance = DMA1_Stream5; // DMA1_Stream7 - #endif - //SERIAL_ECHO_MSG(" Touch Screen on SPI3"); } #endif } @@ -107,7 +88,6 @@ void XPT2046::Init() { SET_INPUT(TOUCH_MISO_PIN); SET_OUTPUT(TOUCH_MOSI_PIN); SET_OUTPUT(TOUCH_SCK_PIN); - //SERIAL_ECHO_MSG(" Touch Screen on Software SPI"); } getRawData(XPT2046_Z1); diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.h b/Marlin/src/HAL/STM32/tft/xpt2046.h index 78cb7a4ba..5b8acf4b8 100644 --- a/Marlin/src/HAL/STM32/tft/xpt2046.h +++ b/Marlin/src/HAL/STM32/tft/xpt2046.h @@ -23,10 +23,8 @@ #ifdef STM32F1xx #include - #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN) #elif defined(STM32F4xx) #include - #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN) #endif #include "../../../inc/MarlinConfig.h" @@ -65,9 +63,8 @@ enum XPTCoordinate : uint8_t { class XPT2046 { private: static SPI_HandleTypeDef SPIx; - static DMA_HandleTypeDef DMAtx; - static bool isBusy() { return SPIx.Instance ? __IS_DMA_ENABLED(&DMAtx) : false; } + static bool isBusy() { return false; } static uint16_t getRawData(const XPTCoordinate coordinate); static bool isTouched(); diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp index e8d484117..bcca00dd4 100644 --- a/Marlin/src/gcode/calibrate/G34.cpp +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -42,7 +42,7 @@ void GcodeSuite::G34() { if (!all_axes_trusted()) home_all_axes(); TERN_(HAS_LEVELING, TEMPORARY_BED_LEVELING_STATE(false)); - + SET_SOFT_ENDSTOP_LOOSE(true); TemporaryGlobalEndstopsState unlock_z(false); diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 7c581bef9..3e61eb6d4 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1187,7 +1187,7 @@ // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' #if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT #undef TOUCH_SCREEN - #if !HAS_TFT_LVGL_UI + #if ENABLED(TFT_CLASSIC_UI) #define HAS_TOUCH_BUTTONS 1 #endif #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a975ac146..0aadeef0e 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -3242,7 +3242,7 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) /** * Touch Buttons */ -#if ENABLED(TOUCH_SCREEN) +#if ENABLED(TOUCH_SCREEN) && DISABLED(TOUCH_SCREEN_CALIBRATION) #ifndef TOUCH_CALIBRATION_X #error "TOUCH_CALIBRATION_X must be defined with TOUCH_SCREEN." #endif diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index cbb05bc35..7f88df7bc 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -339,6 +339,8 @@ static uint8_t page; } #endif // HAS_TOUCH_BUTTONS +static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT + 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); @@ -352,19 +354,21 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u switch (msg) { case U8G_DEV_MSG_INIT: dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, nullptr); - tftio.Init(); - tftio.InitTFT(); - TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); if (preinit) { preinit = false; return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); } + if (msgInitCount) return -1; + tftio.Init(); + tftio.InitTFT(); + TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset()); + // Clear Screen setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1); #if HAS_LCD_IO - tftio.WriteMultiple(TFT_MARLINBG_COLOR, uint32_t(TFT_WIDTH) * (TFT_HEIGHT)); + tftio.WriteMultiple(TFT_MARLINBG_COLOR, (TFT_WIDTH) * (TFT_HEIGHT)); #else memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2); for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++) @@ -420,8 +424,6 @@ 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); } -static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT - uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { if (msgInitCount) { if (msg == U8G_COM_MSG_INIT) msgInitCount--; @@ -433,8 +435,6 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p switch (msg) { case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: - u8g_SetPIOutput(u8g, U8G_PI_RESET); - u8g_Delay(50); isCommand = 0; break; @@ -443,7 +443,6 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p break; case U8G_COM_MSG_RESET: - u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); break; case U8G_COM_MSG_WRITE_BYTE: diff --git a/Marlin/src/lcd/tft/tft.h b/Marlin/src/lcd/tft/tft.h index 159d0e1c1..431973b89 100644 --- a/Marlin/src/lcd/tft/tft.h +++ b/Marlin/src/lcd/tft/tft.h @@ -30,7 +30,7 @@ #include "../../inc/MarlinConfig.h" -#if TFT_INTERFACE_FSMC_8BIT +#if ENABLED(TFT_INTERFACE_FSMC_8BIT) // When we have a 8 bit interface, we need to invert the bytes of the color #define ENDIAN_COLOR(C) (((C) >> 8) | ((C) << 8)) #else diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h index aa081be48..245635857 100644 --- a/Marlin/src/lcd/tft_io/tft_io.h +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -121,7 +121,7 @@ public: static void write_esc_sequence(const uint16_t *Sequence); // Deletaged methods - inline static void Init() { io.Init(); }; + inline static void Init() { io.Init(); io.Abort(); }; inline static bool isBusy() { return io.isBusy(); }; inline static void Abort() { io.Abort(); }; inline static uint32_t GetID() { return io.GetID(); }; diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 8e231ca9a..3d1cc26cd 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -32,6 +32,7 @@ XPT2046 touchIO; #endif #include "../marlinui.h" // For EN_C bit mask +#include "../tft_io/tft_io.h" #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X #define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y @@ -49,7 +50,8 @@ uint8_t TouchButtons::read_buttons() { #ifdef HAS_WIRED_LCD int16_t x, y; - if (!touchIO.getRawPoint(&x, &y)) return 0; + const bool is_touched = (TERN(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration.orientation, TOUCH_ORIENTATION) == TOUCH_PORTRAIT ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y)); + if (!is_touched) return 0; #if ENABLED(TOUCH_SCREEN_CALIBRATION) const calibrationState state = touch_calibration.get_calibration_state(); diff --git a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h index c0bbe2f42..7f429d449 100644 --- a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h +++ b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h @@ -139,11 +139,15 @@ #define TFT_RS_PIN PD13 #define TFT_INTERFACE_FSMC_8BIT +#define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT +#define FSMC_CS_PIN TFT_CS_PIN +#define FSMC_RS_PIN TFT_RS_PIN + // // Touch Screen // https://ldm-systems.ru/f/doc/catalog/HY-TFT-2,8/XPT2046.pdf // -#if ENABLED(TOUCH_SCREEN) +#if NEED_TOUCH_PINS #define TOUCH_CS_PIN PB2 #define TOUCH_SCK_PIN PB0 #define TOUCH_MOSI_PIN PE5 diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h index c48cbc9e5..e2b3f2c31 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h @@ -32,7 +32,7 @@ #define BOARD_INFO_NAME "MKS Robin Nano V3" // Avoid conflict with TIMER_TONE -#define STEP_TIMER 13 +#define STEP_TIMER 10 // Use one of these or SDCard-based Emulation will be used //#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation @@ -255,7 +255,7 @@ * EXP1 EXP2 */ -#if EITHER(TFT_480x320_SPI, TFT_LVGL_UI_SPI) +#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X #define TOUCH_CALIBRATION_X -17253 #endif @@ -345,26 +345,6 @@ #define BOARD_ST7920_DELAY_3 DELAY_NS(600) #endif // !MKS_MINI_12864 - -#elif ENABLED(SPI_GRAPHICAL_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 - - #define LCD_BACKLIGHT_PIN PD13 - - #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 BTN_EN1 PE8 - #define BTN_EN2 PE11 - #define BEEPER_PIN PC5 - #define BTN_ENC PE13 #endif // HAS_SPI_LCD #define HAS_OTG_USB_HOST_SUPPORT diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h index 40da40918..05648cf12 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h @@ -30,7 +30,7 @@ #define BOARD_INFO_NAME "MKS Robin PRO V2" // Avoid conflict with TIMER_TONE -#define STEP_TIMER 13 +#define STEP_TIMER 10 // Use one of these or SDCard-based Emulation will be used //#define SRAM_EEPROM_EMULATION // Use BackSRAM-based EEPROM emulation @@ -243,7 +243,7 @@ // // LCD / Controller #define SPI_FLASH -// #define HAS_SPI_FLASH 1 +#define HAS_SPI_FLASH 1 #define SPI_DEVICE 2 #define SPI_FLASH_SIZE 0x1000000 #if ENABLED(SPI_FLASH) @@ -264,7 +264,7 @@ * EXP1 EXP2 */ -#if EITHER(TFT_480x320_SPI, TFT_LVGL_UI_SPI) +#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X #define TOUCH_CALIBRATION_X -17253 #endif @@ -361,24 +361,4 @@ #endif #endif // !MKS_MINI_12864 - -#elif ENABLED(SPI_GRAPHICAL_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 - - #define LCD_BACKLIGHT_PIN PD13 - - #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 BTN_EN1 PE8 - #define BTN_EN2 PE11 - #define BEEPER_PIN PC5 - #define BTN_ENC PE13 #endif // HAS_SPI_LCD diff --git a/buildroot/share/PlatformIO/scripts/anet_et4_openblt.py b/buildroot/share/PlatformIO/scripts/anet_et4_openblt.py new file mode 100644 index 000000000..2911a28e7 --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/anet_et4_openblt.py @@ -0,0 +1,14 @@ +# Generate the firmware as OpenBLT needs + +import os,sys +from os.path import join + +Import("env") + +env.AddPostAction( + "$BUILD_DIR/${PROGNAME}.elf", + env.VerboseAction(" ".join([ + "$OBJCOPY", "-O", "srec", + "\"$BUILD_DIR/${PROGNAME}.elf\"", "\"$BUILD_DIR/${PROGNAME}.srec\"" + ]), "Building " + join("$BUILD_DIR","${PROGNAME}.srec")) +) diff --git a/buildroot/share/PlatformIO/scripts/stm32_bootloader.py b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py index d517f1c8d..7f49ea0e6 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_bootloader.py +++ b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py @@ -6,9 +6,7 @@ board = DefaultEnvironment().BoardConfig() def noencrypt(source, target, env): firmware = os.path.join(target[0].dir.path, board.get("build.firmware")) - # do not overwrite encrypted firmware if present - if not os.path.isfile(firmware): - shutil.copy(target[0].path, firmware) + shutil.copy(target[0].path, firmware) if 'offset' in board.get("build").keys(): LD_FLASH_OFFSET = board.get("build.offset") @@ -26,5 +24,7 @@ if 'offset' in board.get("build").keys(): if "-Wl,--defsym=LD_MAX_DATA_SIZE" in flag: env["LINKFLAGS"][i] = "-Wl,--defsym=LD_MAX_DATA_SIZE=" + str(maximum_ram_size - 40) - if 'firmware' in board.get("build").keys(): - env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", noencrypt); +board_keys = board.get("build").keys() +# Only copy file if there's no encryptation +if 'firmware' in board_keys and not 'encrypt' in board_keys: + env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", noencrypt) diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/PeripheralPins.c b/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/PeripheralPins.c index 0fbd848da..51ebf6058 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/PeripheralPins.c +++ b/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/PeripheralPins.c @@ -254,7 +254,7 @@ WEAK const PinMap PinMap_SPI_MOSI[] = { {PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, // {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_5, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - // {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_12, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} @@ -266,7 +266,7 @@ WEAK const PinMap PinMap_SPI_MISO[] = { {PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, // {PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)}, {PB_4, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, - // {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, + {PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)}, {PC_11, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)}, {NC, NP, 0} diff --git a/platformio.ini b/platformio.ini index bf44808b3..a95647cf4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -970,6 +970,7 @@ board_build.core = stm32 board_build.variant = MARLIN_F103Zx board_build.ldscript = ldscript.ld board_build.offset = 0x7000 +board_build.encrypt = Yes board_build.firmware = Robin.bin build_flags = ${common_stm32.build_flags} -DENABLE_HWSERIAL3 -DTRANSFER_CLOCK_DIV=8 -DTIMER_SERIAL=TIM5 @@ -1155,6 +1156,7 @@ board_build.variant = MARLIN_F103Vx board_build.ldscript = ldscript.ld board_build.offset = 0x7000 board_build.firmware = Robin_mini.bin +board_build.encrypt = Yes board_upload.offset_address = 0x08007000 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC extra_scripts = ${common.extra_scripts} @@ -1247,6 +1249,8 @@ board_build.core = stm32 board_build.variant = MARLIN_F4x7Vx board_build.ldscript = ldscript.ld board_build.firmware = firmware.srec +# Just anet_et4_openblt.py generates the file, not stm32_bootloader.py +board_build.encrypt = Yes board_build.offset = 0x10000 board_upload.offset_address = 0x08010000 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 @@ -1255,6 +1259,7 @@ upload_protocol = jlink extra_scripts = ${common.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py + buildroot/share/PlatformIO/scripts/anet_et4_openblt.py # # BigTreeTech SKR Pro (STM32F407ZGT6 ARM Cortex-M4) @@ -1304,19 +1309,20 @@ extra_scripts = ${common.extra_scripts} # Lerdge base # [lerdge_common] -platform = ${common_stm32.platform} -extends = common_stm32 -board = LERDGE -board_build.offset = 0x10000 -extra_scripts = ${common.extra_scripts} - pre:buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py - buildroot/share/PlatformIO/scripts/stm32_bootloader.py - buildroot/share/PlatformIO/scripts/lerdge.py -build_flags = ${common_stm32.build_flags} +platform = ${common_stm32.platform} +extends = common_stm32 +board = LERDGE +board_build.offset = 0x10000 +board_build.encrypt = Yes +extra_scripts = ${common.extra_scripts} + pre:buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py + buildroot/share/PlatformIO/scripts/stm32_bootloader.py + buildroot/share/PlatformIO/scripts/lerdge.py +build_flags = ${common_stm32.build_flags} -DSTM32F4 -DSTM32F4xx -DTARGET_STM32F4 -DDISABLE_GENERIC_SERIALUSB -DARDUINO_ARCH_STM32 -DARDUINO_LERDGE -DTRANSFER_CLOCK_DIV=8 -DHAL_SRAM_MODULE_ENABLED -build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 +build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC -DUSBD_VID=0x0483 # # Lerdge X @@ -1369,6 +1375,7 @@ board_build.core = stm32 board_build.variant = MARLIN_F103Vx board_build.ldscript = ldscript.ld board_build.offset = 0x7000 +board_build.encrypt = Yes board_build.firmware = Robin_nano35.bin board_upload.offset_address = 0x08007000 build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC @@ -1385,19 +1392,18 @@ extra_scripts = ${common.extra_scripts} [env:mks_robin_pro2] platform = ${common_stm32.platform} extends = common_stm32 -build_flags = ${common_stm32.build_flags} -DHAL_HCD_MODULE_ENABLED -DUSBHOST -DARDUINO_BLACK_F407VE +build_flags = ${common_stm32.build_flags} -DHAL_HCD_MODULE_ENABLED -DUSBHOST board = genericSTM32F407VET6 board_build.core = stm32 -board_build.variant = MARLIN_F407VE +board_build.variant = MARLIN_F4x7Vx board_build.ldscript = ldscript.ld -board_build.firmware = Robin_nano35.bin +board_build.firmware = firmware.bin build_unflags = ${common_stm32.build_unflags} -DUSBCON -DUSBD_USE_CDC debug_tool = jlink upload_protocol = jlink extra_scripts = ${common.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py - buildroot/share/PlatformIO/scripts/mks_encrypt.py # # MKS Robin Nano V3 @@ -1419,7 +1425,6 @@ upload_protocol = jlink extra_scripts = ${common.extra_scripts} pre:buildroot/share/PlatformIO/scripts/generic_create_variant.py buildroot/share/PlatformIO/scripts/stm32_bootloader.py - buildroot/share/PlatformIO/scripts/mks_encrypt.py ################################# # #