diff --git a/.github/workflows/test-builds.yml b/.github/workflows/test-builds.yml index fdb81fbdc9d2..1467f1b33fc4 100644 --- a/.github/workflows/test-builds.yml +++ b/.github/workflows/test-builds.yml @@ -106,7 +106,7 @@ jobs: - name: Install PlatformIO run: | - pip install -U https://github.com/platformio/platformio-core/archive/develop.zip + pip install -U https://github.com/platformio/platformio-core/archive/master.zip platformio update - name: Check out the PR diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c02dfd3bc7e7..aba6c737b03b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2331,6 +2331,7 @@ #define NEOPIXEL_PIN 4 // LED driving pin //#define NEOPIXEL2_TYPE NEOPIXEL_TYPE //#define NEOPIXEL2_PIN 5 + #define NEOPIXEL2_INSERIES false // The default behaviour is 'false' with neopixel2 in parallel #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used #define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once. #define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255) diff --git a/Marlin/src/HAL/AVR/ServoTimers.h b/Marlin/src/HAL/AVR/ServoTimers.h index 564714df6e8e..598db62578d4 100644 --- a/Marlin/src/HAL/AVR/ServoTimers.h +++ b/Marlin/src/HAL/AVR/ServoTimers.h @@ -60,9 +60,11 @@ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //#define _useTimer1 #define _useTimer3 - #define _useTimer4 - #if !HAS_MOTOR_CURRENT_PWM - #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos. + #if NUM_SERVOS > SERVOS_PER_TIMER + #define _useTimer4 + #if !HAS_MOTOR_CURRENT_PWM && SERVOS > 2 * SERVOS_PER_TIMER + #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos. + #endif #endif #elif defined(__AVR_ATmega32U4__) #define _useTimer3 diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index e55e45b73bd0..731cf9286582 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -36,9 +36,10 @@ * Sanity checks for Spindle / Laser PWM */ #if ENABLED(SPINDLE_LASER_PWM) + #include "../ServoTimers.h" // Needed to check timer availability (_useTimer3) #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt." - #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5) + #elif NUM_SERVOS > 0 && defined(_useTimer3) && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system." #endif #elif defined(SPINDLE_LASER_FREQUENCY) diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp index 33cddd1e05e1..e0047e7d5910 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 +#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC) #include "tft_fsmc.h" #include @@ -224,13 +224,15 @@ void TFT_FSMC::Abort() { } void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, 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); + #if defined(FSMC_DMA_DEV) && defined(FSMC_DMA_CHANNEL) + dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease); + dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, 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); + #endif } #endif // HAS_FSMC_TFT diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h index 5c43361c0cab..6fcfea8a1167 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h @@ -61,4 +61,11 @@ class TFT_FSMC { static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); } static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); } + static void WriteMultiple(uint16_t Color, uint32_t Count) { + static uint16_t Data; Data = Color; + while (Count > 0) { + TransmitDMA(DMA_CIRC_MODE, &Data, Count > 0xFFFF ? 0xFFFF : Count); + Count = Count > 0xFFFF ? Count - 0xFFFF : 0; + } + } }; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp index a64f90f2b50b..2610262b0f2c 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 +#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI) #include "tft_spi.h" @@ -103,16 +103,21 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) { #if !PIN_EXISTS(TFT_MISO) return 0; #else - uint16_t d = 0; + uint8_t d = 0; + uint32_t data = 0; + SPIx.setClockDivider(SPI_CLOCK_DIV16); DataTransferBegin(DATASIZE_8BIT); WriteReg(Reg); - SPI.read((uint8_t*)&d, 1); //dummy read - SPI.read((uint8_t*)&d, 1); + LOOP_L_N(i, 4) { + SPIx.read((uint8_t*)&d, 1); + data = (data << 8) | d; + } DataTransferEnd(); + SPIx.setClockDivider(SPI_CLOCK_MAX); - return d >> 7; + return data >> 7; #endif } diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h index 1d1c9b444c8e..bb26fc21b64f 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h @@ -62,4 +62,11 @@ class TFT_SPI { 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/feature/leds/neopixel.cpp b/Marlin/src/feature/leds/neopixel.cpp index 5d80cfe5d22a..520d4d63b22f 100644 --- a/Marlin/src/feature/leds/neopixel.cpp +++ b/Marlin/src/feature/leds/neopixel.cpp @@ -38,7 +38,7 @@ Marlin_NeoPixel neo; int8_t Marlin_NeoPixel::neoindex; Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800) - #if MULTIPLE_NEOPIXEL_TYPES + #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES) , Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800) #endif ; diff --git a/Marlin/src/feature/leds/neopixel.h b/Marlin/src/feature/leds/neopixel.h index 17057498d4d5..0155785e9afb 100644 --- a/Marlin/src/feature/leds/neopixel.h +++ b/Marlin/src/feature/leds/neopixel.h @@ -61,7 +61,7 @@ class Marlin_NeoPixel { private: static Adafruit_NeoPixel adaneo1 - #if MULTIPLE_NEOPIXEL_TYPES + #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES) , adaneo2 #endif ; @@ -82,23 +82,36 @@ class Marlin_NeoPixel { static inline void begin() { adaneo1.begin(); - TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin()); + #if ENABLED(NEOPIXEL2_INSERIES) + adaneo2.begin(); + #else + TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.begin()); + #endif } static inline void set_pixel_color(const uint16_t n, const uint32_t c) { - adaneo1.setPixelColor(n, c); - TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c)); + #if ENABLED(NEOPIXEL2_INSERIES) + if (n >= NEOPIXEL_PIXELS) adaneo2.setPixelColor(n - (NEOPIXEL_PIXELS), c); + else adaneo1.setPixelColor(n, c); + #else + adaneo1.setPixelColor(n, c); + TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setPixelColor(n, c)); + #endif } static inline void set_brightness(const uint8_t b) { adaneo1.setBrightness(b); - TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b)); + #if ENABLED(NEOPIXEL2_INSERIES) + adaneo2.setBrightness(b); + #else + TERN_(MULTIPLE_NEOPIXEL_TYPES, adaneo2.setBrightness(b)); + #endif } static inline void show() { adaneo1.show(); #if PIN_EXISTS(NEOPIXEL2) - #if MULTIPLE_NEOPIXEL_TYPES + #if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES) adaneo2.show(); #else adaneo1.setPin(NEOPIXEL2_PIN); @@ -113,7 +126,7 @@ class Marlin_NeoPixel { #endif // Accessors - static inline uint16_t pixels() { return adaneo1.numPixels(); } + static inline uint16_t pixels() { TERN(NEOPIXEL2_INSERIES, return adaneo1.numPixels() * 2, return adaneo1.numPixels()); } static inline uint8_t brightness() { return adaneo1.getBrightness(); } static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) { return adaneo1.Color(r, g, b, w); diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index 77f352c399b5..2cb9c2df718e 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -582,6 +582,9 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_RESUME)); + // Check Temperature before moving hotend + ensure_safe_temperature(); + // Retract to prevent oozing unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); @@ -594,8 +597,6 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le // Unretract unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE)); - ensure_safe_temperature(); - // Intelligent resuming #if ENABLED(FWRETRACT) // If retracted before goto pause diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index 0dede7ea644c..6302bb5c6787 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -21,16 +21,14 @@ */ #include "../gcode.h" + #include "../../module/temperature.h" -#include "../../module/stepper.h" -#include "../../module/printcounter.h" // for print_job_timer +#include "../../module/planner.h" // for planner.finish_and_disable +#include "../../module/printcounter.h" // for print_job_timer.stop +#include "../../lcd/ultralcd.h" // for LCD_MESSAGEPGM_P #include "../../inc/MarlinConfig.h" -#if HAS_LCD_MENU - #include "../../lcd/ultralcd.h" -#endif - #if HAS_SUICIDE #include "../../MarlinCore.h" #endif @@ -39,6 +37,8 @@ #if ENABLED(AUTO_POWER_CONTROL) #include "../../feature/power.h" + #else + void restore_stepper_drivers(); #endif // Could be moved to a feature, but this is all the data @@ -108,7 +108,5 @@ void GcodeSuite::M81() { PSU_OFF(); #endif - #if HAS_LCD_MENU - LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF ".")); - #endif + LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF ".")); } diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 277131289a3c..fa4f0cd9b1f6 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -252,7 +252,7 @@ #endif // Full Touch Screen needs 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) +#if EITHER(TOUCH_SCREEN, HAS_TFT_LVGL_UI) #define HAS_TFT_XPT2046 1 #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 6243d82aa8c8..29ab2cfc2946 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1622,7 +1622,7 @@ // // Is an endstop plug used for extra Z endstops or the probe? -#define IS_PROBE_PIN(A,M) (HAS_CUSTOM_PROBE_PIN && Z_MIN_PROBE_PIN == P) +#define IS_PROBE_PIN(A,M) (HAS_CUSTOM_PROBE_PIN && Z_MIN_PROBE_PIN == A##_##M##_PIN) #define IS_X2_ENDSTOP(A,M) (ENABLED(X_DUAL_ENDSTOPS) && X2_USE_ENDSTOP == _##A##M##_) #define IS_Y2_ENDSTOP(A,M) (ENABLED(Y_DUAL_ENDSTOPS) && Y2_USE_ENDSTOP == _##A##M##_) #define IS_Z2_ENDSTOP(A,M) (ENABLED(Z_MULTI_ENDSTOPS) && Z2_USE_ENDSTOP == _##A##M##_) diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 3babd11a3ca5..58b40b521d97 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-13" + #define STRING_DISTRIBUTION_DATE "2020-08-16" #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 205cafbccb39..e42faf025527 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 @@ -366,7 +366,7 @@ static const uint16_t ili9328_init[] = { static const uint16_t ili9341_init[] = { ESC_REG(0x0010), ESC_DELAY(10), ESC_REG(0x0001), ESC_DELAY(200), - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x00E8, 0x0028), + ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x0028, 0x00E8), ESC_REG(0x003A), 0x0055, ESC_REG(0x002A), 0x0000, 0x0000, 0x0001, 0x003F, ESC_REG(0x002B), 0x0000, 0x0000, 0x0000, 0x00EF, @@ -658,6 +658,9 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u setWindow = setWindow_ili9328; break; case 0x9341: // ILI9341 + WRITE_ESC_SEQUENCE(ili9341_init); + setWindow = setWindow_st7789v; + break; case 0x8066: // Anycubic / TronXY TFTs (480x320) WRITE_ESC_SEQUENCE(ili9488_init); setWindow = setWindow_st7789v; diff --git a/Marlin/src/lcd/dwin/dwin.cpp b/Marlin/src/lcd/dwin/dwin.cpp index 1aa2656dcfd6..8cd7af15747d 100644 --- a/Marlin/src/lcd/dwin/dwin.cpp +++ b/Marlin/src/lcd/dwin/dwin.cpp @@ -935,7 +935,8 @@ void Goto_PrintProcess(void) { // Copy into filebuf string before entry char * const name = card.longest_filename(); - DWIN_Draw_String(false, false, font8x16, White, Background_black, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 60, name); + const int8_t npos = _MAX(0, DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2; + DWIN_Draw_String(false, false, font8x16, White, Background_black, npos, 60, name); DWIN_ICON_Show(ICON, ICON_PrintTime, 17, 193); DWIN_ICON_Show(ICON, ICON_RemainTime, 150, 191); @@ -1523,7 +1524,7 @@ inline void make_name_without_ext(char *dst, char *src, int maxlen=MENU_CHAR_LIM if (!card.flag.filenameIsDir) while (pos && src[pos] != '.') pos--; // find last '.' (stop at 0) - int len = pos; // nul or '.' + size_t len = pos; // nul or '.' if (len > maxlen) { // Keep the name short pos = len = maxlen; // move nul down dst[--pos] = '.'; // insert dots @@ -3436,7 +3437,8 @@ void EachMomentUpdate(void) { Popup_Window_Resume(); draw_first_option(false); char * const name = card.longest_filename(); - DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, (DWIN_WIDTH - strlen(name) * MENU_CHR_W) / 2, 252, name); + const int8_t npos = _MAX(0, DWIN_WIDTH - strlen(name) * (MENU_CHR_W)) / 2; + DWIN_Draw_String(false, true, font8x16, Font_window, Background_window, npos, 252, name); DWIN_UpdateLCD(); break; } 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 0febc4edbddd..607090ba391d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp @@ -54,112 +54,27 @@ TFT SPI_TFT; // use SPI1 for the spi tft. void TFT::spi_init(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); -} - -uint8_t TFT::spi_Rec() { - uint8_t returnByte = SPI.transfer(ff); - return returnByte; -} - -uint8_t TFT::spi_read_write_byte(uint8_t data) { - uint8_t returnByte = SPI.transfer(data); - return returnByte; -} - -/** - * @brief Receive a number of bytes from the SPI port to a buffer - * - * @param buf Pointer to starting address of buffer to write to. - * @param nbyte Number of bytes to receive. - * @return Nothing - * - * @details Uses DMA - */ -void TFT::spi_Read(uint8_t* buf, uint16_t nbyte) {SPI.dmaTransfer(0, const_cast(buf), nbyte);} - -/** - * @brief Send a single byte on SPI port - * - * @param b Byte to send - * - * @details - */ -void TFT::spi_Send(uint8_t b) {SPI.send(b);} - -/** - * @brief Write token and then write from 512 byte buffer to SPI (for SD card) - * - * @param buf Pointer with buffer start address - * @return Nothing - * - * @details Use DMA - */ -void TFT::spi_SendBlock(uint8_t token, const uint8_t* buf) { - SPI.send(token); - SPI.dmaSend(const_cast(buf), 512); + tftio.Init(); } void TFT::LCD_WR_REG(uint8_t cmd) { - SPI_TFT_CS_L; - SPI_TFT_DC_L; - spi_Send(cmd); - SPI_TFT_CS_H; + tftio.WriteReg(cmd); } -void TFT::LCD_WR_DATA(uint8_t data) { - SPI_TFT_CS_L; - SPI_TFT_DC_H; - spi_Send(data); - SPI_TFT_CS_H; -} -void TFT::LCD_WriteRAM_Prepare() {LCD_WR_REG(0X2C);} -void TFT::SetCursor(uint16_t x, uint16_t y) { - LCD_WR_REG(0x2A); - LCD_WR_DATA(x >> 8); - LCD_WR_DATA(x); - LCD_WR_DATA(x >> 8); - LCD_WR_DATA(x); - LCD_WR_REG(0x2B); - LCD_WR_DATA(y >> 8); - LCD_WR_DATA(y); - LCD_WR_DATA(y >> 8); - LCD_WR_DATA(y); +void TFT::LCD_WR_DATA(uint8_t data) { + tftio.WriteData(data); } void TFT::SetPoint(uint16_t x, uint16_t y, uint16_t point) { if ((x > 480) || (y > 320)) return; - SetCursor(x, y); - - LCD_WriteRAM_Prepare(); - LCD_WR_DATA((uint8_t)(point >> 8)); - LCD_WR_DATA((uint8_t)point); + SetWindows(x, y, 1, 1); + tftio.WriteMultiple(point, (uint16_t)1); } void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { + tftio.DataTransferBegin(DATASIZE_8BIT); + LCD_WR_REG(0x2A); LCD_WR_DATA(x >> 8); LCD_WR_DATA(x); @@ -171,6 +86,10 @@ void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { LCD_WR_DATA(y); LCD_WR_DATA((y + height - 1) >> 8); LCD_WR_DATA(y + height - 1); + + LCD_WR_REG(0X2C); + + tftio.DataTransferEnd(); } void TFT::LCD_init() { @@ -180,6 +99,8 @@ void TFT::LCD_init() { delay(150); SPI_TFT_RST_H; + tftio.DataTransferBegin(DATASIZE_8BIT); + delay(120); LCD_WR_REG(0x11); delay(120); @@ -251,6 +172,8 @@ void TFT::LCD_init() { delay(120); // Delay 120ms LCD_WR_REG(0x29); // Display ON + tftio.DataTransferEnd(); + LCD_clear(0x0000); // LCD_Draw_Logo(); SPI_TFT_BLK_H; @@ -258,81 +181,18 @@ void TFT::LCD_init() { } void TFT::LCD_clear(uint16_t color) { - unsigned int i; - uint8_t tbuf[960]; - - SetCursor(0, 0); - SetWindows(0, 0, 480 - 1, 320 - 1); - LCD_WriteRAM_Prepare(); - SPI_TFT_CS_L; - SPI_TFT_DC_H; - for (i = 0; i < 960;) { - tbuf[i] = color >> 8; - tbuf[i + 1] = color; - i += 2; - } - for (i = 0; i < 320; i++) { - // for (m=0;m<480;m++) - // { - // LCD_WR_DATA(color>>8); - // LCD_WR_DATA(color); - SPI.dmaSend(tbuf, 960, true); - // SPI_TFT_CS_H; - // } - } - SPI_TFT_CS_H; + 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)); } extern unsigned char bmp_public_buf[17 * 1024]; void TFT::LCD_Draw_Logo() { - uint16_t i,y_off = 0; - uint16_t *p_index; - uint16_t Color; - - #if 1 - for (y_off = 0; y_off < 320; y_off ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, 960); - - SPI_TFT.spi_init(SPI_FULL_SPEED); - SetWindows(0, y_off, 480, 1); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (i = 0; i < 960;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i+=2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf,960,true); - SPI_TFT_CS_H; - } - - #else - - for (index = 0; index < 40; index ++) { - Pic_Logo_Read((uint8_t *)"", bmp_public_buf, 480*8*2); - i = 0; - SetCursor(0,0); - SetWindows(0, y_off * 8, 480, 8); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (i = 0; i < 480 * 8 * 2;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i += 2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf,480*8*2,true); - SPI_TFT_CS_H; - - y_off++; - } - #endif - - SetWindows(0, 0, 479, 319); + 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); + } } #endif // HAS_TFT_LVGL_UI_SPI 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 9b676843139c..c4b04e1c2183 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h @@ -21,13 +21,13 @@ */ #pragma once -#include +#include "../../inc/MarlinConfigPre.h" -#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) +#if ENABLED(TFT_LVGL_UI_SPI) + #include HAL_PATH(../../HAL, tft/tft_spi.h) +#elif ENABLED(TFT_LVGL_UI_FSMC) + #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) @@ -37,20 +37,14 @@ class TFT { public: + TFT_IO tftio; void spi_init(uint8_t spiRate); - uint8_t spi_Rec(); - uint8_t spi_read_write_byte(uint8_t data); - void spi_Read(uint8_t* buf, uint16_t nbyte); - void spi_Send(uint8_t b); - void spi_SendBlock(uint8_t token, const uint8_t* buf); void LCD_WR_REG(uint8_t cmd); void LCD_WR_DATA(uint8_t data); - void SetCursor(uint16_t x, uint16_t y); void SetPoint(uint16_t x, uint16_t y, uint16_t point); void SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height); void LCD_init(); void LCD_clear(uint16_t color); - void LCD_WriteRAM_Prepare(); void LCD_Draw_Logo(); }; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 9ef27afc9ba6..aad5e4362e38 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -51,6 +51,8 @@ #endif #include "../../../../gcode/gcode.h" +#include "pic_manager.h" + static lv_obj_t * scr; extern uint8_t sel_id; extern uint8_t once_flag; 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 5d87eb9f8736..dc5e4910e939 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -500,14 +500,9 @@ char *creat_title_text() { } } - //SERIAL_ECHOLNPAIR("gPicturePreviewStart: ", gPicturePreviewStart, " PREVIEW_LITTLE_PIC_SIZE: ", PREVIEW_LITTLE_PIC_SIZE); - card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8); #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetCursor(0,0); SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); #else ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -525,19 +520,11 @@ char *creat_title_text() { if (j >= 400) break; } #if ENABLED(TFT_LVGL_UI_SPI) - uint16_t Color, SpiColor; - SpiColor = (LV_COLOR_BACKGROUND.full >> 8) | ((LV_COLOR_BACKGROUND.full & 0xFF) << 8); - for (i = 0; i < 400;) { + for (i = 0; i < 400; i += 2) { p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i += 2; - if (*p_index == 0x0000) *p_index = SpiColor; + if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf, 400, true); - SPI_TFT_CS_H; + SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); #else for (i = 0; i < 400;) { p_index = (uint16_t *)(&bmp_public_buf[i]); @@ -627,10 +614,7 @@ char *creat_title_text() { card.setIndex((PREVIEW_LITTLE_PIC_SIZE + To_pre_view) + size * row + 8); #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetCursor(0,0); SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); #else ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -750,9 +734,6 @@ char *creat_title_text() { void Draw_default_preview(int xpos_pixel, int ypos_pixel, uint8_t sel) { int index; int y_off = 0; - int _y; - uint16_t *p_index; - int i; for (index = 0; index < 10; index++) { // 200*200 #if HAS_BAK_VIEW_IN_FLASH @@ -761,58 +742,24 @@ char *creat_title_text() { } else { default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k - #if ENABLED(TFT_LVGL_UI_SPI) - uint16_t Color; - for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xff) << 8); - i += 2; - } - #endif } #else default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k - #if ENABLED(TFT_LVGL_UI_SPI) - for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xff) << 8); - i += 2; - } - #endif #endif - i = 0; #if ENABLED(TFT_LVGL_UI_SPI) - - //SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetWindows(xpos_pixel, y_off * 20+ypos_pixel, 200,20); //200*200 - //SPI_TFT.LCD_WriteRAM_Prepare(); - int j = 0; - for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) { - SPI_TFT.spi_init(SPI_FULL_SPEED); - SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel + j, 200, 1); // 200*200 - SPI_TFT.LCD_WriteRAM_Prepare(); - - j++; - //memcpy(public_buf,&bmp_public_buf[i],400); - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(&bmp_public_buf[i], 400, true); - SPI_TFT_CS_H; - - i += 400; - if (i >= 8000) break; - } + SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 + SPI_TFT.tftio.WriteSequence((uint16_t*)(bmp_public_buf), DEFAULT_VIEW_MAX_SIZE / 20); #else int x_off = 0; uint16_t temp_p; + int i = 0; + uint16_t *p_index; ili9320_SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 LCD_WriteRAM_Prepare(); - for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) { + for (int _y = y_off * 20; _y < (y_off + 1) * 20; _y++) { for (x_off = 0; x_off < 200; x_off++) { if (sel == 1) { temp_p = (uint16_t)(bmp_public_buf[i] | bmp_public_buf[i + 1] << 8); 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 a35ae29701fb..a2795e933bcf 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 @@ -590,8 +590,6 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1 } void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor) { - // Select TFT SPI so it can receive data - TERN_(TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED)); while (*string != '\0') { disp_char_1624(x, y, *string, charColor, bkColor); string++; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp index a257d03489cd..62967b9d8061 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp @@ -22,249 +22,39 @@ #include "../../../../inc/MarlinConfig.h" -#if HAS_TFT_LVGL_UI - -#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs - - #include - #include - #include - #include - - /* 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); - uint16_t ILI9488_ReadRAM(); - #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 - - /** - * 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; +#if ENABLED(TFT_LVGL_UI_FSMC) + +#include HAL_PATH(../../HAL, tft/tft_fsmc.h) +TFT_IO tftio; + +void LCD_IO_Init(uint8_t cs, uint8_t rs); +void LCD_IO_WriteData(uint16_t RegValue); +void LCD_IO_WriteReg(uint16_t Reg); +#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 + +void LCD_IO_Init(uint8_t cs, uint8_t rs) { + tftio.Init(); +} + +void LCD_IO_WriteData(uint16_t RegValue) { + tftio.WriteData(RegValue); +} + +void LCD_IO_WriteReg(uint16_t Reg) { + tftio.WriteReg(Reg); +} + +#ifdef LCD_USE_DMA_FSMC + void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) { + tftio.WriteMultiple(color, count); } - uint16_t ILI9488_ReadRAM() { - uint16_t data; - data = LCD->RAM; - return data; + void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { + tftio.WriteSequence(data, length); } +#endif // LCD_USE_DMA_FSMC - 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 // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN #endif // HAS_TFT_LVGL_UI 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 81b50a101871..391e12ba3fc7 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 @@ -42,9 +42,8 @@ #include "../../../../inc/MarlinConfig.h" -#if HAS_TOUCH_XPT2046 - #include "../../../touch/xpt2046.h" -#endif +#include HAL_PATH(../../HAL, tft/xpt2046.h) +XPT2046 touch; #if ENABLED(POWER_LOSS_RECOVERY) #include "../../../../feature/powerloss.h" @@ -121,14 +120,14 @@ void tft_set_cursor(uint16_t x, uint16_t y) { void LCD_WriteRAM_Prepare(void) { #if 0 - if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x8989)) { - ClrCs - LCD->LCD_REG = R34; - SetCs - } - else { - LCD_WrtReg(0x002C); - } + switch (DeviceCode) { + case 0x9325: case 0x9328: case 0x8989: { + ClrCs + LCD->LCD_REG = R34; + SetCs + } break; + default: LCD_WrtReg(0x002C); + } #else LCD_IO_WriteReg(0x002C); #endif @@ -197,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, 320 - xEnd); - LCD_WriteReg(0x0053, 320 - StartX - 1); // Specify the end 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 } else { @@ -268,28 +267,10 @@ void LCD_Clear(uint16_t Color) { } } -extern uint16_t ILI9488_ReadRAM(); - +#include HAL_PATH(../../HAL, tft/tft_fsmc.h) +extern TFT_IO tftio; void init_tft() { uint16_t i; - //************* Start Initial Sequence **********// - - //start lcd pins and dma - #if PIN_EXISTS(LCD_BACKLIGHT) - OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away - #endif - - #if PIN_EXISTS(LCD_RESET) - // Perform a clean hardware reset with needed delays - OUT_WRITE(LCD_RESET_PIN, LOW); - _delay_ms(5); - WRITE(LCD_RESET_PIN, HIGH); - _delay_ms(5); - #endif - - #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) - WRITE(LCD_BACKLIGHT_PIN, HIGH); - #endif TERN_(HAS_LCD_CONTRAST, refresh_contrast()); @@ -303,12 +284,9 @@ void init_tft() { _delay_ms(5); - LCD_IO_WriteReg(0x00D3); - DeviceCode = ILI9488_ReadRAM(); //dummy read - DeviceCode = ILI9488_ReadRAM(); - DeviceCode = ILI9488_ReadRAM(); - DeviceCode <<= 8; - DeviceCode |= ILI9488_ReadRAM(); + DeviceCode = tftio.GetID() & 0xFFFF; + // Chitu and others + if (DeviceCode == 0x8066) DeviceCode = 0x9488; if (DeviceCode == 0x9488) { LCD_IO_WriteReg(0x00E0); @@ -436,7 +414,7 @@ void tft_lvgl_init() { //spi_flash_read_test(); - TERN_(HAS_TOUCH_XPT2046, touch.init()); + touch.Init(); lv_init(); @@ -492,35 +470,14 @@ void tft_lvgl_init() { void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { #if ENABLED(TFT_LVGL_UI_SPI) uint16_t i, width, height; - uint16_t clr_temp; - uint8_t tbuf[(LCD_FULL_PIXEL_WIDTH) * 2]; - - SPI_TFT.spi_init(SPI_FULL_SPEED); width = area->x2 - area->x1 + 1; height = area->y2 - area->y1 + 1; - for (int j = 0; j < height; j++) { - SPI_TFT.SetCursor(0, 0); - SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1 + j, width, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); - - for (i = 0; i < width * 2;) { - clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11) - | ((uint16_t)color_p->ch.green << 5) - | ((uint16_t)color_p->ch.blue)); - - tbuf[i] = clr_temp >> 8; - tbuf[i + 1] = clr_temp; - i += 2; - color_p++; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(tbuf, width * 2, true); - SPI_TFT_CS_H; + SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1, width, height); + for (i = 0; i < height; i++) { + SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); } - lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ W25QXX.init(SPI_QUARTER_SPEED); @@ -556,174 +513,23 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) { return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick)); } -#if ENABLED(TFT_LVGL_UI_SPI) - - #ifndef USE_XPT2046 - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 1 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - #endif - - #if USE_XPT2046 - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 201 - #define XPT2046_Y_MIN 164 - #define XPT2046_X_MAX 3919 - #define XPT2046_Y_MAX 3776 - #define XPT2046_AVG 4 - #define XPT2046_INV 1 - #endif - -#else - - #ifndef USE_XPT2046 - #define USE_XPT2046 1 - #ifndef XPT2046_XY_SWAP - #define XPT2046_XY_SWAP 1 - #endif - #ifndef XPT2046_X_INV - #define XPT2046_X_INV 0 - #endif - #ifndef XPT2046_Y_INV - #define XPT2046_Y_INV 1 - #endif - #endif - - #if USE_XPT2046 - #ifndef XPT2046_HOR_RES - #define XPT2046_HOR_RES 480 - #endif - #ifndef XPT2046_VER_RES - #define XPT2046_VER_RES 320 - #endif - #ifndef XPT2046_X_MIN - #define XPT2046_X_MIN 201 - #endif - #ifndef XPT2046_Y_MIN - #define XPT2046_Y_MIN 164 - #endif - #ifndef XPT2046_X_MAX - #define XPT2046_X_MAX 3919 - #endif - #ifndef XPT2046_Y_MAX - #define XPT2046_Y_MAX 3776 - #endif - #ifndef XPT2046_AVG - #define XPT2046_AVG 4 - #endif - #ifndef XPT2046_INV - #define XPT2046_INV 0 - #endif - #endif - -#endif - -static void xpt2046_corr(uint16_t *x, uint16_t *y) { - #if XPT2046_XY_SWAP - int16_t swap_tmp; - swap_tmp = *x; - *x = *y; - *y = swap_tmp; - #endif - if ((*x) > XPT2046_X_MIN) (*x) -= XPT2046_X_MIN; else (*x) = 0; - if ((*y) > XPT2046_Y_MIN) (*y) -= XPT2046_Y_MIN; else (*y) = 0; - (*x) = uint32_t(uint32_t(*x) * XPT2046_HOR_RES) / (XPT2046_X_MAX - XPT2046_X_MIN); - (*y) = uint32_t(uint32_t(*y) * XPT2046_VER_RES) / (XPT2046_Y_MAX - XPT2046_Y_MIN); - #if XPT2046_X_INV - (*x) = XPT2046_HOR_RES - (*x); - #endif - #if XPT2046_Y_INV - (*y) = XPT2046_VER_RES - (*y); - #endif -} - -#define times 4 -#define CHX 0x90 -#define CHY 0xD0 - -int SPI2_ReadWrite2Bytes(void) { - #define SPI_READ_WRITE_BYTE(B) TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_read_write_byte, W25QXX.spi_flash_read_write_byte)(B) - const uint16_t t1 = SPI_READ_WRITE_BYTE(0xFF), - t2 = SPI_READ_WRITE_BYTE(0xFF); - return (((t1 << 8) | t2) >> 3) & 0x0FFF; -} +static bool get_point(int16_t *x, int16_t *y) { + bool is_touched = touch.getRawPoint(x, y); -uint16_t x_addata[times], y_addata[times]; -void XPT2046_Rd_Addata(uint16_t *X_Addata, uint16_t *Y_Addata) { - uint16_t i, j, k; - - TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_init, W25QXX.init)(SPI_SPEED_6); - - for (i = 0; i < times; i++) { - #if ENABLED(TFT_LVGL_UI_SPI) - OUT_WRITE(TOUCH_CS_PIN, LOW); - SPI_TFT.spi_read_write_byte(CHX); - y_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - - OUT_WRITE(TOUCH_CS_PIN, LOW); - SPI_TFT.spi_read_write_byte(CHY); - x_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - #else // #if HAS_TOUCH_XPT2046 - OUT_WRITE(TOUCH_CS_PIN, LOW); - W25QXX.spi_flash_read_write_byte(CHX); - y_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - - OUT_WRITE(TOUCH_CS_PIN, LOW); - W25QXX.spi_flash_read_write_byte(CHY); - x_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - #endif - - } - TERN(TFT_LVGL_UI_SPI,,W25QXX.init(SPI_QUARTER_SPEED)); - - for (i = 0; i < times; i++) - for (j = i + 1; j < times; j++) - if (x_addata[j] > x_addata[i]) { - k = x_addata[j]; - x_addata[j] = x_addata[i]; - x_addata[i] = k; - } - if (x_addata[times / 2 - 1] - x_addata[times / 2] > 50) { - *X_Addata = *Y_Addata = 0; - return; - } - - *X_Addata = (x_addata[times / 2 - 1] + x_addata[times / 2]) / 2; - - for (i = 0; i < times; i++) - for (j = i + 1; j < times; j++) - if (y_addata[j] > y_addata[i]) { - k = y_addata[j]; - y_addata[j] = y_addata[i]; - y_addata[i] = k; - } - - if (y_addata[times / 2 - 1] - y_addata[times / 2] > 50) { - *X_Addata = *Y_Addata = 0; - return; + if (is_touched) { + *x = int16_t((int32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; } - *Y_Addata = (y_addata[times / 2 - 1] + y_addata[times / 2]) / 2; -} - -#define ADC_VALID_OFFSET 10 + #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + x = (LCD_FULL_PIXEL_WIDTH) - x; + y = (LCD_FULL_PIXEL_HEIGHT) - y; + #endif -uint8_t TOUCH_PressValid(uint16_t _usX, uint16_t _usY) { - if ( (_usX <= ADC_VALID_OFFSET) - || (_usY <= ADC_VALID_OFFSET) - || (_usX >= 4095 - ADC_VALID_OFFSET) - || (_usY >= 4095 - ADC_VALID_OFFSET) - ) return 0; - return 1; + return is_touched; } -static lv_coord_t last_x = 0, last_y = 0; +static int16_t last_x = 0, last_y = 0; bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { uint32_t tmpTime, diffTime = 0; @@ -735,34 +541,24 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { //touchpad_get_xy(&last_x, &last_y); /*Save the pressed coordinates and the state*/ if (diffTime > 10) { - //use marlin touch code if enabled - #if HAS_TOUCH_XPT2046 - touch.getTouchPoint(reinterpret_cast(last_x), reinterpret_cast(last_y)); - #else - XPT2046_Rd_Addata((uint16_t *)&last_x, (uint16_t *)&last_y); - #endif - if (TOUCH_PressValid(last_x, last_y)) { + if (get_point(&last_x, &last_y)) { data->state = LV_INDEV_STATE_PR; - /* Set the coordinates (if released use the last pressed coordinates) */ + // Set the coordinates (if released use the last-pressed coordinates) - // SERIAL_ECHOLNPAIR("antes X: ", last_x, ", y: ", last_y); - xpt2046_corr((uint16_t *)&last_x, (uint16_t *)&last_y); - // SERIAL_ECHOLNPAIR("X: ", last_x, ", y: ", last_y); data->point.x = last_x; data->point.y = last_y; - last_x = 0; - last_y = 0; + last_x = last_y = 0; } - else { + else data->state = LV_INDEV_STATE_REL; - } + touch_time1 = tmpTime; } - return false; /*Return `false` because we are not buffering and no more data to read*/ + return false; // Return `false` since no data is buffering or left to read } #endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index c19275449507..3df9c17f6b8e 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -548,7 +548,7 @@ namespace ExtUI { void setAxisSteps_per_mm(const float value, const extruder_t extruder) { UNUSED_E(extruder); - planner.settings.axis_steps_per_mm[E_AXIS_N(axis - E0)] = value; + planner.settings.axis_steps_per_mm[E_AXIS_N(extruder - E0)] = value; } feedRate_t getAxisMaxFeedrate_mm_s(const axis_t axis) { @@ -557,7 +557,7 @@ namespace ExtUI { feedRate_t getAxisMaxFeedrate_mm_s(const extruder_t extruder) { UNUSED_E(extruder); - return planner.settings.max_feedrate_mm_s[E_AXIS_N(axis - E0)]; + return planner.settings.max_feedrate_mm_s[E_AXIS_N(extruder - E0)]; } void setAxisMaxFeedrate_mm_s(const feedRate_t value, const axis_t axis) { diff --git a/Marlin/src/lcd/fontutils.h b/Marlin/src/lcd/fontutils.h index 8839e36a2bd1..74c4a87fb9d3 100644 --- a/Marlin/src/lcd/fontutils.h +++ b/Marlin/src/lcd/fontutils.h @@ -38,6 +38,6 @@ int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp, /* Get the character, decoding multibyte UTF8 characters and returning a pointer to the start of the next UTF8 character */ uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval); -/* Returns lenght of string in CHARACTERS, NOT BYTES */ +/* Returns length of string in CHARACTERS, NOT BYTES */ uint8_t utf8_strlen(const char *pstart); uint8_t utf8_strlen_P(PGM_P pstart); diff --git a/Marlin/src/lcd/touch/xpt2046.cpp b/Marlin/src/lcd/touch/xpt2046.cpp index 1fed5b78f0e3..4407d945d351 100644 --- a/Marlin/src/lcd/touch/xpt2046.cpp +++ b/Marlin/src/lcd/touch/xpt2046.cpp @@ -133,12 +133,14 @@ uint8_t XPT2046::read_buttons() { // 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; + : WITHIN(x, 90, 153) ? EN_A + : WITHIN(x, 166, 229) ? EN_B + : WITHIN(x, 242, 305) ? EN_C + : 0; - if (x > TOUCH_SENSOR_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 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), @@ -161,6 +163,7 @@ bool XPT2046::isTouched() { } #if ENABLED(TOUCH_BUTTONS_HW_SPI) + #include static void touch_spi_init(uint8_t spiRate) { diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index f1ab0fca6927..c84bbb44aea7 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -626,7 +626,12 @@ void MarlinSettings::postprocess() { #endif EEPROM_WRITE(home_offset); #endif + } + // + // Hotend Offsets, if any + // + { #if HAS_HOTEND_OFFSET // Skip hotend 0 which must be 0 LOOP_S_L_N(e, 1, HOTENDS) @@ -1521,6 +1526,8 @@ void MarlinSettings::postprocess() { _FIELD_TEST(runout_sensor_enabled); EEPROM_READ(runout_sensor_enabled); + TERN_(HAS_FILAMENT_SENSOR, if (runout.enabled) runout.reset()); + float runout_distance_mm; EEPROM_READ(runout_distance_mm); #if HAS_FILAMENT_RUNOUT_DISTANCE diff --git a/Marlin/src/module/stepper/indirection.h b/Marlin/src/module/stepper/indirection.h index 1fd1a72e7e9f..e9705cd3c322 100644 --- a/Marlin/src/module/stepper/indirection.h +++ b/Marlin/src/module/stepper/indirection.h @@ -850,7 +850,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define ENABLE_AXIS_Z() do{ ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); }while(0) #ifdef Z_AFTER_DEACTIVATE - #define Z_RESET() do{ current_position.z = Z_AFTER_DEACTIVATE; planner.sync_plan_position(); }while(0) + #define Z_RESET() do{ current_position.z = Z_AFTER_DEACTIVATE; sync_plan_position(); }while(0) #else #define Z_RESET() #endif diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index f467ba58cbec..83543703e540 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -250,6 +250,30 @@ #define LCD_PINS_ENABLE P1_23 #define LCD_PINS_D4 P1_21 + #elif ENABLED(ENDER2_STOCKDISPLAY) + + /** Creality Ender-2 display pinout + * _____ + * 5V | 1 2 | GND + * (MOSI) 1.23 | 3 4 | 1.22 (LCD_RS) + * (LCD_A0) 1.21 | 5 6 | 1.20 (BTN_EN2) + * RESET 1.19 | 7 8 | 1.18 (BTN_EN1) + * (BTN_ENC) 0.28 | 9 10| 1.30 (SCK) + * ----- + * EXP1 + */ + + #define BTN_EN1 P1_18 + #define BTN_EN2 P1_20 + #define BTN_ENC P0_28 + + #define DOGLCD_CS P1_22 + #define DOGLCD_A0 P1_21 + #define DOGLCD_SCK P1_30 + #define DOGLCD_MOSI P1_23 + #define FORCE_SOFT_SPI + #define LCD_BACKLIGHT_PIN -1 + #else #define BTN_ENC P0_28 // (58) open-drain diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index 6be67fc1a263..e4f0014417b1 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -164,7 +164,6 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 - #define HAS_TOUCH_XPT2046 1 #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK @@ -183,6 +182,8 @@ #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 + #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 @@ -197,24 +198,10 @@ #define LCD_PIXEL_OFFSET_X 48 #define LCD_PIXEL_OFFSET_Y 48 - #define XPT2046_X_CALIBRATION -12316 - #define XPT2046_Y_CALIBRATION 8981 - #define XPT2046_X_OFFSET 340 - #define XPT2046_Y_OFFSET -20 - - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 0 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 140 - #define XPT2046_Y_MIN 200 - #define XPT2046_X_MAX 1900 - #define XPT2046_Y_MAX 1900 - #define XPT2046_AVG 4 - #define XPT2046_INV 0 + #define XPT2046_X_CALIBRATION -17181 + #define XPT2046_Y_CALIBRATION 11434 + #define XPT2046_X_OFFSET 501 + #define XPT2046_Y_OFFSET -9 #elif ENABLED(TFT_480x320) #define TFT_RESET_PIN PF11 diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 4633de40f2a5..3d36de82424f 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -198,7 +198,6 @@ #define HAS_LANG_SELECT_SCREEN 0 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 - #define HAS_TOUCH_XPT2046 1 #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK @@ -217,6 +216,8 @@ #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 + #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 @@ -231,24 +232,10 @@ #define LCD_PIXEL_OFFSET_X 48 #define LCD_PIXEL_OFFSET_Y 48 - #define XPT2046_X_CALIBRATION -12316 - #define XPT2046_Y_CALIBRATION 8981 - #define XPT2046_X_OFFSET 340 - #define XPT2046_Y_OFFSET -20 - - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 0 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 140 - #define XPT2046_Y_MIN 200 - #define XPT2046_X_MAX 1900 - #define XPT2046_Y_MAX 1900 - #define XPT2046_AVG 4 - #define XPT2046_INV 0 + #define XPT2046_X_CALIBRATION -17181 + #define XPT2046_Y_CALIBRATION 11434 + #define XPT2046_X_OFFSET 501 + #define XPT2046_Y_OFFSET -9 #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h index ed281eb00c21..c36b4561b02b 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h @@ -134,6 +134,10 @@ #define ONBOARD_SD_CS_PIN PA4 // SDSS #define SDIO_SUPPORT +#if ENABLED(CR10_STOCKDISPLAY) && NONE(RET6_12864_LCD, VET6_12864_LCD) + #error "Define RET6_12864_LCD or VET6_12864_LCD to select pins for CR10_STOCKDISPLAY with the Creality V4 controller." +#endif + #if ENABLED(RET6_12864_LCD) /* RET6 12864 LCD */ @@ -146,6 +150,7 @@ #define BTN_EN2 PB14 #define BEEPER_PIN PC6 + #elif ENABLED(VET6_12864_LCD) /* VET6 12864 LCD */ diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 2f5dbd010564..490fb617d17d 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -130,6 +130,12 @@ #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 + /** * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer * mixed up MOSI and MISO pins. SPI is managed in SW, and needs pins diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 16040643520b..948663f6f059 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -177,6 +177,17 @@ #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 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 be363e45374b..feac729c73b2 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -261,17 +261,30 @@ #define BTN_EN2 PE11 #define BTN_ENC PE13 -#elif ENABLED(TFT_LITTLE_VGL_UI) - - #define FSMC_CS_PIN PD7 // NE4 - #define FSMC_RS_PIN PD11 // A0 - - #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 - - #define LCD_BACKLIGHT_PIN PD13 + #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_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + + #ifndef LCD_FULL_PIXEL_WIDTH + #define LCD_FULL_PIXEL_WIDTH 480 + #endif + #ifndef LCD_FULL_PIXEL_HEIGHT + #define LCD_FULL_PIXEL_HEIGHT 320 + #endif #endif diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 6c1b571bf16b..d5f6fc195807 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -9,12 +9,24 @@ import configparser except ImportError: import ConfigParser as configparser -from platformio.managers.package import PackageManager +try: + # PIO < 4.4 + from platformio.managers.package import PackageManager +except ImportError: + # PIO >= 4.4 + from platformio.package.meta import PackageSpec as PackageManager Import("env") FEATURE_CONFIG = {} +def parse_pkg_uri(spec): + if PackageManager.__name__ == 'PackageSpec': + return PackageManager(spec).name + else: + name, _, _ = PackageManager.parse_pkg_uri(spec) + return name + def add_to_feat_cnf(feature, flines): feat = FEATURE_CONFIG[feature] atoms = re.sub(',\\s*', '\n', flines).strip().split('\n') @@ -56,7 +68,7 @@ def get_all_known_libs(): if not 'lib_deps' in feat: continue for dep in feat['lib_deps']: - name, _, _ = PackageManager.parse_pkg_uri(dep) + name = parse_pkg_uri(dep) known_libs.append(name) return known_libs @@ -64,7 +76,7 @@ def get_all_env_libs(): env_libs = [] lib_deps = env.GetProjectOption('lib_deps') for dep in lib_deps: - name, _, _ = PackageManager.parse_pkg_uri(dep) + name = parse_pkg_uri(dep) env_libs.append(name) return env_libs @@ -96,20 +108,20 @@ def apply_features_config(): # feat to add deps_to_add = {} for dep in feat['lib_deps']: - name, _, _ = PackageManager.parse_pkg_uri(dep) + name = parse_pkg_uri(dep) deps_to_add[name] = dep # Does the env already have the dependency? deps = env.GetProjectOption('lib_deps') for dep in deps: - name, _, _ = PackageManager.parse_pkg_uri(dep) + name = parse_pkg_uri(dep) if name in deps_to_add: del deps_to_add[name] # Are there any libraries that should be ignored? lib_ignore = env.GetProjectOption('lib_ignore') for dep in deps: - name, _, _ = PackageManager.parse_pkg_uri(dep) + name = parse_pkg_uri(dep) if name in deps_to_add: del deps_to_add[name] diff --git a/buildroot/share/scripts/config-labels.py b/buildroot/share/scripts/config-labels.py index 8effb54eed58..267aa2d27353 100755 --- a/buildroot/share/scripts/config-labels.py +++ b/buildroot/share/scripts/config-labels.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # for python3.5 or higher #----------------------------------- diff --git a/buildroot/share/sublime/MarlinFirmware.sublime-project b/buildroot/share/sublime/MarlinFirmware.sublime-project index e437369ec243..9b5234f7a13c 100644 --- a/buildroot/share/sublime/MarlinFirmware.sublime-project +++ b/buildroot/share/sublime/MarlinFirmware.sublime-project @@ -8,7 +8,6 @@ "MarlinFirmware/lib", "Marlin/lib", "datatmp", - "Marlin/*/src", ".vscode" ], "binary_file_patterns":