From 406f8363bc45e57c7a8a5c5bb20b7fa30f8c2e1f Mon Sep 17 00:00:00 2001 From: ellensp Date: Sat, 10 Oct 2020 22:39:12 +1300 Subject: [PATCH 01/46] HAS_CHARACTER_LCD => HAS_MARLINUI_HD44780 (#19673) --- Marlin/src/lcd/menu/menu_probe_offset.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index 29c7d4112964..87957e6207ef 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -94,7 +94,7 @@ void probe_offset_wizard_menu() { if ((SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) { extern const char NUL_STR[]; SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); }); - MENU_ITEM_ADDON_START(0 + ENABLED(HAS_CHARACTER_LCD)); + MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780)); char tmp[20], numstr[10]; // Determine digits needed right of decimal const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 : From 6fdaaf3d203002fb7b437e86cd3aaa80e5da77bd Mon Sep 17 00:00:00 2001 From: Serhiy-K <52166448+Serhiy-K@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:01:46 +0300 Subject: [PATCH 02/46] Fixes for TFTGLCD Panel, FastIO (#19614) --- Marlin/src/HAL/STM32/fastio.h | 18 +- Marlin/src/core/language.h | 2 +- Marlin/src/core/utility.h | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp | 223 +++++++----------- Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h | 1 + Marlin/src/lcd/menu/menu_advanced.cpp | 2 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 16 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h | 2 +- Marlin/src/pins/stm32f0/pins_MALYAN_M300.h | 3 + Marlin/src/pins/stm32f1/pins_MORPHEUS.h | 1 + 12 files changed, 112 insertions(+), 162 deletions(-) diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h index d90b2fbeb02d..7d02062b5374 100644 --- a/Marlin/src/HAL/STM32/fastio.h +++ b/Marlin/src/HAL/STM32/fastio.h @@ -51,19 +51,19 @@ void FastIO_init(); // Must be called before using fast io macros #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx) #define _WRITE(IO, V) do { \ - if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \ - else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \ + if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ + else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ }while(0) #else - #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16))) + #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) + ((V) ? 0 : 16))) #endif -#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO])))) -#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO]))) +#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(digitalPinToPinName(IO) & 0x1F))) +#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(digitalPinToPinName(IO) & 0x1F)) #define _GET_MODE(IO) #define _SET_MODE(IO,M) pinMode(IO, M) -#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */ +#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) //!< Output Push Pull Mode & GPIO_NOPULL #define _SET_OUTPUT_OD(IO) pinMode(IO, OUTPUT_OPEN_DRAIN) #define WRITE(IO,V) _WRITE(IO,V) @@ -73,9 +73,9 @@ void FastIO_init(); // Must be called before using fast io macros #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0) #define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0) -#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */ -#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ -#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ +#define SET_INPUT(IO) _SET_MODE(IO, INPUT) //!< Input Floating Mode +#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) //!< Input with Pull-up activation +#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) //!< Input with Pull-down activation #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_PWM(IO) _SET_MODE(IO, PWM) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index a644ab2fc8be..60d9aa6b720a 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -303,7 +303,7 @@ #define LCD_STR_C STR_C #define LCD_STR_E STR_E -#if HAS_MARLINUI_HD44780 +#if EITHER(HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL) // Custom characters defined in the first 8 characters of the LCD #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string! diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index 0481ffc02a2e..645a4be80735 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -71,7 +71,7 @@ class restorer { inline void restore() { ref_ = val_; } }; -#define REMEMBER(N,X,V...) restorer restorer_##N(X, ##V) +#define REMEMBER(N,X,V...) restorer<__typeof__(X)> restorer_##N(X, ##V) #define RESTORE(N) restorer_##N.restore() // Converts from an uint8_t in the range of 0-255 to an uint8_t diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 210bf3e91bca..42d82dcc1066 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -226,9 +226,9 @@ #define LCD_PROGRESS_BAR #endif #if ENABLED(TFTGLCD_PANEL_I2C) - #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD for I2C and SPI buses (LiquidTWI2 not required) #define LCD_I2C_ADDRESS 0x27 // Must be equal to panel's I2C slave addres #endif + #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD, used for both I2C and SPI buses (LiquidTWI2 not required) #define STD_ENCODER_PULSES_PER_STEP 2 #define STD_ENCODER_STEPS_PER_MENU_ITEM 1 #define LCD_WIDTH 20 // 20 or 24 chars in line diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 80c42955e92d..f832137f5b40 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2457,7 +2457,7 @@ /** * Buzzer/Speaker */ -#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER, IS_TFTGLCD_PANEL) +#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) #define HAS_BUZZER 1 #if PIN_EXISTS(BEEPER) #define USE_BEEPER 1 diff --git a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp index a537d92081d1..b5789091dc2f 100644 --- a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp @@ -32,7 +32,7 @@ * and supports color output. */ -#if NONE(__AVR__, MCU_LPC1768, __STM32F1__, STM32F4xx) +#if NONE(__AVR__, TARGET_LPC1768, __STM32F1__, STM32F4xx) #warning "Selected platform not yet tested. Please contribute your good pin mappings." #endif @@ -72,16 +72,17 @@ TFTGLCD lcd; #define ICON_HOT B01000000 //when any T > 50deg #define PIC_MASK 0x7F -//LEDs not used, for compatibility with Smoothieware +// LEDs not used, for compatibility with Smoothieware #define LED_HOTEND_ON B00000001 #define LED_BED_ON B00000010 #define LED_FAN_ON B00000100 #define LED_HOT B00001000 #define LED_MASK 0x0F -#define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2) +#define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2) +#define MIDDLE_Y ((LCD_HEIGHT - 1) / 2) -//markers for change line color +// Markers for change line colors #define COLOR_EDIT '#' #define COLOR_ERROR '!' @@ -114,7 +115,8 @@ enum Commands { // based on Smoothieware commands GET_LCD_ROW = 0xE0, // for detect panel GET_LCD_COL, // reserved for compatibility with Smoothieware, not used LCD_PUT, // write one line to LCD - INIT_SCREEN = 0xFE, // clear panel buffer + CLR_SCREEN, + INIT_SCREEN = 0xFE // clear panel buffer }; static unsigned char framebuffer[FBSIZE]; @@ -123,28 +125,62 @@ static uint8_t cour_line; static uint8_t picBits, ledBits, hotBits; static uint8_t PanelDetected = 0; +// Different platforms use different SPI methods +#if ANY(__AVR__, TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) + #define SPI_SEND_ONE(V) SPI.transfer(V); + #define SPI_SEND_TWO(V) SPI.transfer16(V); +#elif defined(STM32F4xx) + #define SPI_SEND_ONE(V) SPI.transfer(V, SPI_CONTINUE); + #define SPI_SEND_TWO(V) SPI.transfer16(V, SPI_CONTINUE); +#elif defined(ARDUINO_ARCH_ESP32) + #define SPI_SEND_ONE(V) SPI.write(V); + #define SPI_SEND_TWO(V) SPI.write16(V); +#endif + +#if ANY(__AVR__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) + #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L); +#elif defined(STM32F4xx) + #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L, SPI_CONTINUE); +#elif ANY(TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_ESP32) + #define SPI_SEND_SOME(V,L,Z) do{ for (uint16_t i = 0; i < L; i++) SPI_SEND_ONE(V[(Z)+i]); }while(0) +#endif + // Constructor TFTGLCD::TFTGLCD() {} -//clearing local buffer +// Clear local buffer void TFTGLCD::clear_buffer() { memset(&framebuffer[0], ' ', FBSIZE - 2); framebuffer[FBSIZE - 1] = framebuffer[FBSIZE - 2] = 0; picBits = ledBits = 0; } -//set new text cursor position +// Clear panel's screen +void TFTGLCD::clr_screen() { + if (!PanelDetected) return; + #if ENABLED(TFTGLCD_PANEL_SPI) + WRITE(TFTGLCD_CS, LOW); + SPI_SEND_ONE(CLR_SCREEN); + WRITE(TFTGLCD_CS, HIGH); + #else + Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address + Wire.write(CLR_SCREEN); + Wire.endTransmission(); //transmit data + #endif +} + +// Set new text cursor position void TFTGLCD::setCursor(uint8_t col, uint8_t row) { fb = &framebuffer[0] + col + row * LCD_WIDTH; cour_line = row; } -//send char to buffer +// Send char to buffer void TFTGLCD::write(char c) { *fb++ = c; } -//send text line to buffer +// Send text line to buffer void TFTGLCD::print(const char *line) { while (*line) *fb++ = *line++; } @@ -154,27 +190,9 @@ void TFTGLCD::print_line() { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #ifdef __AVR__ - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); - #elif EITHER(MCU_LPC1768, __STM32F1__) - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.transfer(framebuffer[cour_line * LCD_WIDTH + i]); - #elif defined(STM32F4xx) - SPI.transfer(LCD_PUT, SPI_CONTINUE); - SPI.transfer(cour_line, SPI_CONTINUE); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(LCD_PUT); - SPI.write(cour_line); - for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.write(framebuffer[cour_line * LCD_WIDTH + i]); - #endif + SPI_SEND_ONE(LCD_PUT); + SPI_SEND_ONE(cour_line); + SPI_SEND_SOME(framebuffer, LCD_WIDTH, cour_line * LCD_WIDTH); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address @@ -193,22 +211,8 @@ void TFTGLCD::print_screen(){ #if ENABLED(TFTGLCD_PANEL_SPI) // Send all framebuffer to panel WRITE(TFTGLCD_CS, LOW); - #ifdef __AVR__ - SPI.transfer(LCD_WRITE); - SPI.transfer(&framebuffer[0], FBSIZE); - #elif EITHER(MCU_LPC1768, __STM32F1__) - SPI.transfer(LCD_WRITE); - for (uint16_t i = 0; i < FBSIZE; i++) SPI.transfer(framebuffer[i]); - #elif defined(STM32F4xx) - SPI.transfer(LCD_WRITE, SPI_CONTINUE); - SPI.transfer(&framebuffer[0], FBSIZE, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(LCD_WRITE); - SPI.transfer(&framebuffer[0], FBSIZE); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(LCD_WRITE); - for (uint16_t i = 0; i < FBSIZE; i++) SPI.write(framebuffer[i]); - #endif + SPI_SEND_ONE(LCD_WRITE); + SPI_SEND_SOME(framebuffer, FBSIZE, 0); WRITE(TFTGLCD_CS, HIGH); #else uint8_t r; @@ -235,19 +239,8 @@ void TFTGLCD::setContrast(uint16_t contrast) { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(CONTRAST); - SPI.transfer((uint8_t)contrast); - #elif defined(STM32F4xx) - SPI.transfer(CONTRAST, SPI_CONTINUE); - SPI.transfer((uint8_t)contrast, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(CONTRAST); - SPI.transfer((uint8_t)contrast); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(CONTRAST); - SPI.write((uint8_t)contrast); - #endif + SPI_SEND_ONE(CONTRAST); + SPI_SEND_ONE((uint8_t)contrast); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -257,37 +250,24 @@ void TFTGLCD::setContrast(uint16_t contrast) { #endif } -//reading buttons and encoder states extern volatile int8_t encoderDiff; +// Read buttons and encoder states uint8_t MarlinUI::read_slow_buttons(void) { if (!PanelDetected) return 0; #if ENABLED(TFTGLCD_PANEL_SPI) uint8_t b = 0; WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay - b = SPI.transfer(GET_SPI_DATA); - #elif defined(STM32F4xx) - SPI.transfer(READ_ENCODER, SPI_CONTINUE); - encoderDiff += SPI.transfer(READ_BUTTONS, SPI_CONTINUE); - b = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - b = SPI.transfer(GET_SPI_DATA); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - b = SPI.transfer(GET_SPI_DATA); + SPI_SEND_ONE(READ_ENCODER); + #ifndef STM32F4xx + WRITE(TFTGLCD_CS, LOW); // for delay #endif + encoderDiff += SPI_SEND_ONE(READ_BUTTONS); + #ifndef STM32F4xx + WRITE(TFTGLCD_CS, LOW); // for delay + WRITE(TFTGLCD_CS, LOW); + #endif + b = SPI_SEND_ONE(GET_SPI_DATA); WRITE(TFTGLCD_CS, HIGH); return b; #else @@ -298,7 +278,7 @@ uint8_t MarlinUI::read_slow_buttons(void) { Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1); #elif defined(__STM32F1__) Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2); - #elif EITHER(STM32F4xx, MCU_LPC1768) + #elif EITHER(STM32F4xx, TARGET_LPC1768) Wire.requestFrom(LCD_I2C_ADDRESS, 2); #endif encoderDiff += Wire.read(); @@ -306,28 +286,14 @@ uint8_t MarlinUI::read_slow_buttons(void) { #endif } -// duration in ms, freq in Hz +// Duration in ms, freq in Hz void MarlinUI::buzz(const long duration, const uint16_t freq) { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(BUZZER); - SPI.transfer16((uint16_t)duration); - SPI.transfer16(freq); - #elif defined(STM32F4xx) - SPI.transfer(BUZZER, SPI_CONTINUE); - SPI.transfer16((uint16_t)duration, SPI_CONTINUE); - SPI.transfer16(freq, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(BUZZER); - SPI.transfer16((uint16_t)duration); - SPI.transfer16(freq); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(BUZZER); - SPI.write16((uint16_t)duration); - SPI.write16(freq); - #endif + SPI_SEND_ONE(BUZZER); + SPI_SEND_TWO((uint16_t)duration); + SPI_SEND_TWO(freq); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -346,24 +312,14 @@ void MarlinUI::init_lcd() { t = 0; #if ENABLED(TFTGLCD_PANEL_SPI) // SPI speed must be less 10MHz - OUT_WRITE(TFTGLCD_CS, HIGH); + _SET_OUTPUT(TFTGLCD_CS); + WRITE(TFTGLCD_CS, HIGH); spiInit(TERN(__STM32F1__, SPI_QUARTER_SPEED, SPI_FULL_SPEED)); WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #elif defined(STM32F4xx) - SPI.transfer(GET_LCD_ROW, SPI_CONTINUE); - t = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #endif + SPI_SEND_ONE(GET_LCD_ROW); + t = SPI_SEND_ONE(GET_SPI_DATA); #else - #ifdef MCU_LPC1768 + #ifdef TARGET_LPC1768 Wire.begin(); //init twi/I2C #else Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C @@ -373,7 +329,7 @@ void MarlinUI::init_lcd() { Wire.endTransmission(); // send buffer #ifdef __AVR__ Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1); - #elif ANY(__STM32F1__, STM32F4xx, MCU_LPC1768) + #elif ANY(__STM32F1__, STM32F4xx, TARGET_LPC1768) Wire.requestFrom(LCD_I2C_ADDRESS, 1); #endif t = (uint8_t)Wire.read(); @@ -382,20 +338,8 @@ void MarlinUI::init_lcd() { if (t == LCD_HEIGHT) { PanelDetected = 1; #if ENABLED(TFTGLCD_PANEL_SPI) - PanelDetected = 1; - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(INIT_SCREEN); - SPI.transfer(Marlin); - #elif defined(STM32F4xx) - SPI.transfer(INIT_SCREEN, SPI_CONTINUE); - SPI.transfer(Marlin, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(INIT_SCREEN); - SPI.transfer(Marlin); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(INIT_SCREEN); - SPI.write(Marlin); - #endif + SPI_SEND_ONE(INIT_SCREEN); + SPI_SEND_ONE(Marlin); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -415,8 +359,8 @@ bool MarlinUI::detected() { void MarlinUI::clear_lcd() { if (!PanelDetected) return; + lcd.clr_screen(); lcd.clear_buffer(); - lcd.print_screen(); } int16_t MarlinUI::contrast; // Initialized by settings.load() @@ -583,10 +527,10 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p lcd.write('%'); lcd.write(percent); } else { // For progress bar test - lcd.setCursor(LCD_WIDTH / 2 - 2, LCD_HEIGHT / 2 - 2); + lcd.setCursor(LCD_WIDTH / 2 - 2, MIDDLE_Y); lcd.print(i16tostr3rj(percent)); lcd.write('%'); lcd.print_line(); - lcd.setCursor(0, LCD_HEIGHT / 2 - 1); + lcd.setCursor(0, MIDDLE_Y + 1); lcd.write('%'); lcd.write(percent); lcd.print_line(); } @@ -912,16 +856,17 @@ void MarlinUI::draw_status_screen() { } // Low-level draw_edit_screen can be used to draw an edit screen from anyplace + // This line moves to the last line of the screen for UBL plot screen on the panel side void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { if (!PanelDetected) return; ui.encoder_direction_normal(); - lcd.setCursor(0, LCD_HEIGHT - 1); //last line is free most time + lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd_put_u8str_P(pstr); if (value != nullptr) { lcd.write(':'); - lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), LCD_HEIGHT - 1); // Right-justified, padded by spaces - lcd.write(' '); // Overwrite char if value gets shorter + lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces + lcd.write(' '); // Overwrite char if value gets shorter lcd.print(value); lcd.write(' '); lcd.print_line(); @@ -932,10 +877,10 @@ void MarlinUI::draw_status_screen() { void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff) { if (!PanelDetected) return; ui.draw_select_screen_prompt(pref, string, suff); - lcd.setCursor(0, LCD_HEIGHT - 1); + lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']'); - lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, LCD_HEIGHT - 1); + lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, MIDDLE_Y); lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' '); lcd.print_line(); } diff --git a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h index 9f54730c3c89..eedcc4afa073 100644 --- a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h +++ b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h @@ -45,6 +45,7 @@ class TFTGLCD { public: TFTGLCD(); void clear_buffer(); + void clr_screen(); void setCursor(uint8_t col, uint8_t row); void write(char c); void print(const char *line); diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index c0a72bbe6c8a..68a10245e951 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -490,7 +490,7 @@ void menu_backlash(); #if ENABLED(PROBE_OFFSET_WIZARD) SUBMENU(MSG_PROBE_WIZARD, goto_probe_offset_wizard); #endif - + END_MENU(); } #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 8cb06824b409..5bb32a420aee 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -223,14 +223,14 @@ #endif /** - * _____ _____ - * NC | · · | GND 5V | · · | GND - * RESET | · · | 1.31(SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6) - * (MOSI)0.18 | · · | 3.25(BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4) - * (SD_SS)0.16 | · · | 3.26(BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN) - * (SCK)0.15 | · · | 0.17(MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER) - * ----- ----- - * EXP2 EXP1 + * _____ _____ + * NC | · · | GND 5V | · · | GND + * RESET | · · | 1.31 (SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6) + * (MOSI) 0.18 | · · | 3.25 (BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4) + * (SD_SS) 0.16 | · · | 3.26 (BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN) + * (SCK) 0.15 | · · | 0.17 (MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER) + * ----- ----- + * EXP2 EXP1 */ #if HAS_WIRED_LCD #if ENABLED(ANET_FULL_GRAPHICS_LCD) diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h index fd902afda42f..820c35a01cb9 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h @@ -92,7 +92,7 @@ // // LCD / Controller // -#if HAS_WIRED_LCD +#if HAS_WIRED_LCD && DISABLED(LCD_USE_I2C_BUZZER) #define BEEPER_PIN P1_30 // (37) not 5V tolerant #endif diff --git a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h index dfa413b63fad..a0e035a91688 100644 --- a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h +++ b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h @@ -33,6 +33,9 @@ // #if NO_EEPROM_SELECTED #define FLASH_EEPROM_EMULATION + #ifndef MARLIN_EEPROM_SIZE + #define MARLIN_EEPROM_SIZE 0x800U // 2KB + #endif #endif // diff --git a/Marlin/src/pins/stm32f1/pins_MORPHEUS.h b/Marlin/src/pins/stm32f1/pins_MORPHEUS.h index 28262eaa828c..ccc92b7527d1 100644 --- a/Marlin/src/pins/stm32f1/pins_MORPHEUS.h +++ b/Marlin/src/pins/stm32f1/pins_MORPHEUS.h @@ -89,3 +89,4 @@ // #define LED_PIN PC13 #define SDSS PA3 +#define TFTGLCD_CS PA4 From a90edd5eb48d000eac80a417379b83c152cadf4a Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 10 Oct 2020 13:47:28 -0300 Subject: [PATCH 03/46] Restore correct STM32 port-bits code (#19678) --- Marlin/src/HAL/STM32/fastio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h index 7d02062b5374..f000d68cf0c3 100644 --- a/Marlin/src/HAL/STM32/fastio.h +++ b/Marlin/src/HAL/STM32/fastio.h @@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx) #define _WRITE(IO, V) do { \ - if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ - else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ + if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \ + else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \ }while(0) #else - #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) + ((V) ? 0 : 16))) + #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16))) #endif -#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(digitalPinToPinName(IO) & 0x1F))) -#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(digitalPinToPinName(IO) & 0x1F)) +#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO])))) +#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO]))) #define _GET_MODE(IO) #define _SET_MODE(IO,M) pinMode(IO, M) From 98427ea92ac538374f8366542c5a51bc213780b5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 10 Oct 2020 12:07:00 -0500 Subject: [PATCH 04/46] Save PLR on resume from pause (#19676) Co-Authored-By: shahab <32130261+SHBnik@users.noreply.github.com> --- Marlin/src/feature/pause.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index a36ff5075683..0ab659402181 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -61,6 +61,10 @@ #include "../libs/buzzer.h" #endif +#if ENABLED(POWER_LOSS_RECOVERY) + #include "powerloss.h" +#endif + #include "../libs/nozzle.h" #include "pause.h" @@ -640,6 +644,9 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le // Set extruder to saved position planner.set_e_position_mm((destination.e = current_position.e = resume_position.e)); + // Write PLR now to update the z axis value + TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true)); + TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_STATUS)); #ifdef ACTION_ON_RESUMED From a14e26c095c5d13835597cb5112c6c1d8ce05cb4 Mon Sep 17 00:00:00 2001 From: Serhiy-K <52166448+Serhiy-K@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:01:46 +0300 Subject: [PATCH 05/46] Fixes for TFTGLCD Panel, FastIO (#19614) --- Marlin/src/HAL/STM32/fastio.h | 8 +- Marlin/src/core/language.h | 2 +- Marlin/src/core/utility.h | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 +- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp | 223 +++++++----------- Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h | 1 + Marlin/src/lcd/menu/menu_advanced.cpp | 2 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 16 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h | 2 +- Marlin/src/pins/stm32f0/pins_MALYAN_M300.h | 3 + Marlin/src/pins/stm32f1/pins_MORPHEUS.h | 1 + 12 files changed, 107 insertions(+), 157 deletions(-) diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h index d90b2fbeb02d..f000d68cf0c3 100644 --- a/Marlin/src/HAL/STM32/fastio.h +++ b/Marlin/src/HAL/STM32/fastio.h @@ -63,7 +63,7 @@ void FastIO_init(); // Must be called before using fast io macros #define _GET_MODE(IO) #define _SET_MODE(IO,M) pinMode(IO, M) -#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */ +#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) //!< Output Push Pull Mode & GPIO_NOPULL #define _SET_OUTPUT_OD(IO) pinMode(IO, OUTPUT_OPEN_DRAIN) #define WRITE(IO,V) _WRITE(IO,V) @@ -73,9 +73,9 @@ void FastIO_init(); // Must be called before using fast io macros #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0) #define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0) -#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */ -#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ -#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ +#define SET_INPUT(IO) _SET_MODE(IO, INPUT) //!< Input Floating Mode +#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) //!< Input with Pull-up activation +#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) //!< Input with Pull-down activation #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_PWM(IO) _SET_MODE(IO, PWM) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index a644ab2fc8be..60d9aa6b720a 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -303,7 +303,7 @@ #define LCD_STR_C STR_C #define LCD_STR_E STR_E -#if HAS_MARLINUI_HD44780 +#if EITHER(HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL) // Custom characters defined in the first 8 characters of the LCD #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string! diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index 0481ffc02a2e..645a4be80735 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -71,7 +71,7 @@ class restorer { inline void restore() { ref_ = val_; } }; -#define REMEMBER(N,X,V...) restorer restorer_##N(X, ##V) +#define REMEMBER(N,X,V...) restorer<__typeof__(X)> restorer_##N(X, ##V) #define RESTORE(N) restorer_##N.restore() // Converts from an uint8_t in the range of 0-255 to an uint8_t diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 210bf3e91bca..42d82dcc1066 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -226,9 +226,9 @@ #define LCD_PROGRESS_BAR #endif #if ENABLED(TFTGLCD_PANEL_I2C) - #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD for I2C and SPI buses (LiquidTWI2 not required) #define LCD_I2C_ADDRESS 0x27 // Must be equal to panel's I2C slave addres #endif + #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD, used for both I2C and SPI buses (LiquidTWI2 not required) #define STD_ENCODER_PULSES_PER_STEP 2 #define STD_ENCODER_STEPS_PER_MENU_ITEM 1 #define LCD_WIDTH 20 // 20 or 24 chars in line diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 80c42955e92d..f832137f5b40 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2457,7 +2457,7 @@ /** * Buzzer/Speaker */ -#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER, IS_TFTGLCD_PANEL) +#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) #define HAS_BUZZER 1 #if PIN_EXISTS(BEEPER) #define USE_BEEPER 1 diff --git a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp index a537d92081d1..b5789091dc2f 100644 --- a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.cpp @@ -32,7 +32,7 @@ * and supports color output. */ -#if NONE(__AVR__, MCU_LPC1768, __STM32F1__, STM32F4xx) +#if NONE(__AVR__, TARGET_LPC1768, __STM32F1__, STM32F4xx) #warning "Selected platform not yet tested. Please contribute your good pin mappings." #endif @@ -72,16 +72,17 @@ TFTGLCD lcd; #define ICON_HOT B01000000 //when any T > 50deg #define PIC_MASK 0x7F -//LEDs not used, for compatibility with Smoothieware +// LEDs not used, for compatibility with Smoothieware #define LED_HOTEND_ON B00000001 #define LED_BED_ON B00000010 #define LED_FAN_ON B00000100 #define LED_HOT B00001000 #define LED_MASK 0x0F -#define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2) +#define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2) +#define MIDDLE_Y ((LCD_HEIGHT - 1) / 2) -//markers for change line color +// Markers for change line colors #define COLOR_EDIT '#' #define COLOR_ERROR '!' @@ -114,7 +115,8 @@ enum Commands { // based on Smoothieware commands GET_LCD_ROW = 0xE0, // for detect panel GET_LCD_COL, // reserved for compatibility with Smoothieware, not used LCD_PUT, // write one line to LCD - INIT_SCREEN = 0xFE, // clear panel buffer + CLR_SCREEN, + INIT_SCREEN = 0xFE // clear panel buffer }; static unsigned char framebuffer[FBSIZE]; @@ -123,28 +125,62 @@ static uint8_t cour_line; static uint8_t picBits, ledBits, hotBits; static uint8_t PanelDetected = 0; +// Different platforms use different SPI methods +#if ANY(__AVR__, TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) + #define SPI_SEND_ONE(V) SPI.transfer(V); + #define SPI_SEND_TWO(V) SPI.transfer16(V); +#elif defined(STM32F4xx) + #define SPI_SEND_ONE(V) SPI.transfer(V, SPI_CONTINUE); + #define SPI_SEND_TWO(V) SPI.transfer16(V, SPI_CONTINUE); +#elif defined(ARDUINO_ARCH_ESP32) + #define SPI_SEND_ONE(V) SPI.write(V); + #define SPI_SEND_TWO(V) SPI.write16(V); +#endif + +#if ANY(__AVR__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) + #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L); +#elif defined(STM32F4xx) + #define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L, SPI_CONTINUE); +#elif ANY(TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_ESP32) + #define SPI_SEND_SOME(V,L,Z) do{ for (uint16_t i = 0; i < L; i++) SPI_SEND_ONE(V[(Z)+i]); }while(0) +#endif + // Constructor TFTGLCD::TFTGLCD() {} -//clearing local buffer +// Clear local buffer void TFTGLCD::clear_buffer() { memset(&framebuffer[0], ' ', FBSIZE - 2); framebuffer[FBSIZE - 1] = framebuffer[FBSIZE - 2] = 0; picBits = ledBits = 0; } -//set new text cursor position +// Clear panel's screen +void TFTGLCD::clr_screen() { + if (!PanelDetected) return; + #if ENABLED(TFTGLCD_PANEL_SPI) + WRITE(TFTGLCD_CS, LOW); + SPI_SEND_ONE(CLR_SCREEN); + WRITE(TFTGLCD_CS, HIGH); + #else + Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address + Wire.write(CLR_SCREEN); + Wire.endTransmission(); //transmit data + #endif +} + +// Set new text cursor position void TFTGLCD::setCursor(uint8_t col, uint8_t row) { fb = &framebuffer[0] + col + row * LCD_WIDTH; cour_line = row; } -//send char to buffer +// Send char to buffer void TFTGLCD::write(char c) { *fb++ = c; } -//send text line to buffer +// Send text line to buffer void TFTGLCD::print(const char *line) { while (*line) *fb++ = *line++; } @@ -154,27 +190,9 @@ void TFTGLCD::print_line() { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #ifdef __AVR__ - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); - #elif EITHER(MCU_LPC1768, __STM32F1__) - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.transfer(framebuffer[cour_line * LCD_WIDTH + i]); - #elif defined(STM32F4xx) - SPI.transfer(LCD_PUT, SPI_CONTINUE); - SPI.transfer(cour_line, SPI_CONTINUE); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(LCD_PUT); - SPI.transfer(cour_line); - SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(LCD_PUT); - SPI.write(cour_line); - for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.write(framebuffer[cour_line * LCD_WIDTH + i]); - #endif + SPI_SEND_ONE(LCD_PUT); + SPI_SEND_ONE(cour_line); + SPI_SEND_SOME(framebuffer, LCD_WIDTH, cour_line * LCD_WIDTH); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address @@ -193,22 +211,8 @@ void TFTGLCD::print_screen(){ #if ENABLED(TFTGLCD_PANEL_SPI) // Send all framebuffer to panel WRITE(TFTGLCD_CS, LOW); - #ifdef __AVR__ - SPI.transfer(LCD_WRITE); - SPI.transfer(&framebuffer[0], FBSIZE); - #elif EITHER(MCU_LPC1768, __STM32F1__) - SPI.transfer(LCD_WRITE); - for (uint16_t i = 0; i < FBSIZE; i++) SPI.transfer(framebuffer[i]); - #elif defined(STM32F4xx) - SPI.transfer(LCD_WRITE, SPI_CONTINUE); - SPI.transfer(&framebuffer[0], FBSIZE, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(LCD_WRITE); - SPI.transfer(&framebuffer[0], FBSIZE); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(LCD_WRITE); - for (uint16_t i = 0; i < FBSIZE; i++) SPI.write(framebuffer[i]); - #endif + SPI_SEND_ONE(LCD_WRITE); + SPI_SEND_SOME(framebuffer, FBSIZE, 0); WRITE(TFTGLCD_CS, HIGH); #else uint8_t r; @@ -235,19 +239,8 @@ void TFTGLCD::setContrast(uint16_t contrast) { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(CONTRAST); - SPI.transfer((uint8_t)contrast); - #elif defined(STM32F4xx) - SPI.transfer(CONTRAST, SPI_CONTINUE); - SPI.transfer((uint8_t)contrast, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(CONTRAST); - SPI.transfer((uint8_t)contrast); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(CONTRAST); - SPI.write((uint8_t)contrast); - #endif + SPI_SEND_ONE(CONTRAST); + SPI_SEND_ONE((uint8_t)contrast); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -257,37 +250,24 @@ void TFTGLCD::setContrast(uint16_t contrast) { #endif } -//reading buttons and encoder states extern volatile int8_t encoderDiff; +// Read buttons and encoder states uint8_t MarlinUI::read_slow_buttons(void) { if (!PanelDetected) return 0; #if ENABLED(TFTGLCD_PANEL_SPI) uint8_t b = 0; WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay - b = SPI.transfer(GET_SPI_DATA); - #elif defined(STM32F4xx) - SPI.transfer(READ_ENCODER, SPI_CONTINUE); - encoderDiff += SPI.transfer(READ_BUTTONS, SPI_CONTINUE); - b = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - b = SPI.transfer(GET_SPI_DATA); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.transfer(READ_ENCODER); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - encoderDiff += SPI.transfer(READ_BUTTONS); - WRITE(TFTGLCD_CS, LOW); //for delay ???? - b = SPI.transfer(GET_SPI_DATA); + SPI_SEND_ONE(READ_ENCODER); + #ifndef STM32F4xx + WRITE(TFTGLCD_CS, LOW); // for delay #endif + encoderDiff += SPI_SEND_ONE(READ_BUTTONS); + #ifndef STM32F4xx + WRITE(TFTGLCD_CS, LOW); // for delay + WRITE(TFTGLCD_CS, LOW); + #endif + b = SPI_SEND_ONE(GET_SPI_DATA); WRITE(TFTGLCD_CS, HIGH); return b; #else @@ -298,7 +278,7 @@ uint8_t MarlinUI::read_slow_buttons(void) { Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1); #elif defined(__STM32F1__) Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2); - #elif EITHER(STM32F4xx, MCU_LPC1768) + #elif EITHER(STM32F4xx, TARGET_LPC1768) Wire.requestFrom(LCD_I2C_ADDRESS, 2); #endif encoderDiff += Wire.read(); @@ -306,28 +286,14 @@ uint8_t MarlinUI::read_slow_buttons(void) { #endif } -// duration in ms, freq in Hz +// Duration in ms, freq in Hz void MarlinUI::buzz(const long duration, const uint16_t freq) { if (!PanelDetected) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(BUZZER); - SPI.transfer16((uint16_t)duration); - SPI.transfer16(freq); - #elif defined(STM32F4xx) - SPI.transfer(BUZZER, SPI_CONTINUE); - SPI.transfer16((uint16_t)duration, SPI_CONTINUE); - SPI.transfer16(freq, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(BUZZER); - SPI.transfer16((uint16_t)duration); - SPI.transfer16(freq); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(BUZZER); - SPI.write16((uint16_t)duration); - SPI.write16(freq); - #endif + SPI_SEND_ONE(BUZZER); + SPI_SEND_TWO((uint16_t)duration); + SPI_SEND_TWO(freq); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -346,24 +312,14 @@ void MarlinUI::init_lcd() { t = 0; #if ENABLED(TFTGLCD_PANEL_SPI) // SPI speed must be less 10MHz - OUT_WRITE(TFTGLCD_CS, HIGH); + _SET_OUTPUT(TFTGLCD_CS); + WRITE(TFTGLCD_CS, HIGH); spiInit(TERN(__STM32F1__, SPI_QUARTER_SPEED, SPI_FULL_SPEED)); WRITE(TFTGLCD_CS, LOW); - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #elif defined(STM32F4xx) - SPI.transfer(GET_LCD_ROW, SPI_CONTINUE); - t = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(GET_LCD_ROW); - t = SPI.transfer(GET_SPI_DATA); - #endif + SPI_SEND_ONE(GET_LCD_ROW); + t = SPI_SEND_ONE(GET_SPI_DATA); #else - #ifdef MCU_LPC1768 + #ifdef TARGET_LPC1768 Wire.begin(); //init twi/I2C #else Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C @@ -373,7 +329,7 @@ void MarlinUI::init_lcd() { Wire.endTransmission(); // send buffer #ifdef __AVR__ Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1); - #elif ANY(__STM32F1__, STM32F4xx, MCU_LPC1768) + #elif ANY(__STM32F1__, STM32F4xx, TARGET_LPC1768) Wire.requestFrom(LCD_I2C_ADDRESS, 1); #endif t = (uint8_t)Wire.read(); @@ -382,20 +338,8 @@ void MarlinUI::init_lcd() { if (t == LCD_HEIGHT) { PanelDetected = 1; #if ENABLED(TFTGLCD_PANEL_SPI) - PanelDetected = 1; - #if ANY(__AVR__, MCU_LPC1768, __STM32F1__) - SPI.transfer(INIT_SCREEN); - SPI.transfer(Marlin); - #elif defined(STM32F4xx) - SPI.transfer(INIT_SCREEN, SPI_CONTINUE); - SPI.transfer(Marlin, SPI_CONTINUE); - #elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__) - SPI.transfer(INIT_SCREEN); - SPI.transfer(Marlin); - #elif defined(ARDUINO_ARCH_ESP32) - SPI.write(INIT_SCREEN); - SPI.write(Marlin); - #endif + SPI_SEND_ONE(INIT_SCREEN); + SPI_SEND_ONE(Marlin); WRITE(TFTGLCD_CS, HIGH); #else Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); @@ -415,8 +359,8 @@ bool MarlinUI::detected() { void MarlinUI::clear_lcd() { if (!PanelDetected) return; + lcd.clr_screen(); lcd.clear_buffer(); - lcd.print_screen(); } int16_t MarlinUI::contrast; // Initialized by settings.load() @@ -583,10 +527,10 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p lcd.write('%'); lcd.write(percent); } else { // For progress bar test - lcd.setCursor(LCD_WIDTH / 2 - 2, LCD_HEIGHT / 2 - 2); + lcd.setCursor(LCD_WIDTH / 2 - 2, MIDDLE_Y); lcd.print(i16tostr3rj(percent)); lcd.write('%'); lcd.print_line(); - lcd.setCursor(0, LCD_HEIGHT / 2 - 1); + lcd.setCursor(0, MIDDLE_Y + 1); lcd.write('%'); lcd.write(percent); lcd.print_line(); } @@ -912,16 +856,17 @@ void MarlinUI::draw_status_screen() { } // Low-level draw_edit_screen can be used to draw an edit screen from anyplace + // This line moves to the last line of the screen for UBL plot screen on the panel side void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { if (!PanelDetected) return; ui.encoder_direction_normal(); - lcd.setCursor(0, LCD_HEIGHT - 1); //last line is free most time + lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd_put_u8str_P(pstr); if (value != nullptr) { lcd.write(':'); - lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), LCD_HEIGHT - 1); // Right-justified, padded by spaces - lcd.write(' '); // Overwrite char if value gets shorter + lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces + lcd.write(' '); // Overwrite char if value gets shorter lcd.print(value); lcd.write(' '); lcd.print_line(); @@ -932,10 +877,10 @@ void MarlinUI::draw_status_screen() { void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff) { if (!PanelDetected) return; ui.draw_select_screen_prompt(pref, string, suff); - lcd.setCursor(0, LCD_HEIGHT - 1); + lcd.setCursor(0, MIDDLE_Y); lcd.write(COLOR_EDIT); lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']'); - lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, LCD_HEIGHT - 1); + lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, MIDDLE_Y); lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' '); lcd.print_line(); } diff --git a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h index 9f54730c3c89..eedcc4afa073 100644 --- a/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h +++ b/Marlin/src/lcd/TFTGLCD/ultralcd_TFTGLCD.h @@ -45,6 +45,7 @@ class TFTGLCD { public: TFTGLCD(); void clear_buffer(); + void clr_screen(); void setCursor(uint8_t col, uint8_t row); void write(char c); void print(const char *line); diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index c0a72bbe6c8a..68a10245e951 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -490,7 +490,7 @@ void menu_backlash(); #if ENABLED(PROBE_OFFSET_WIZARD) SUBMENU(MSG_PROBE_WIZARD, goto_probe_offset_wizard); #endif - + END_MENU(); } #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 8cb06824b409..5bb32a420aee 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -223,14 +223,14 @@ #endif /** - * _____ _____ - * NC | · · | GND 5V | · · | GND - * RESET | · · | 1.31(SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6) - * (MOSI)0.18 | · · | 3.25(BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4) - * (SD_SS)0.16 | · · | 3.26(BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN) - * (SCK)0.15 | · · | 0.17(MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER) - * ----- ----- - * EXP2 EXP1 + * _____ _____ + * NC | · · | GND 5V | · · | GND + * RESET | · · | 1.31 (SD_DETECT) (LCD_D7) 1.23 | · · | 1.22 (LCD_D6) + * (MOSI) 0.18 | · · | 3.25 (BTN_EN2) (LCD_D5) 1.21 | · · | 1.20 (LCD_D4) + * (SD_SS) 0.16 | · · | 3.26 (BTN_EN1) (LCD_RS) 1.19 | · · | 1.18 (LCD_EN) + * (SCK) 0.15 | · · | 0.17 (MISO) (BTN_ENC) 0.28 | · · | 1.30 (BEEPER) + * ----- ----- + * EXP2 EXP1 */ #if HAS_WIRED_LCD #if ENABLED(ANET_FULL_GRAPHICS_LCD) diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h index fd902afda42f..820c35a01cb9 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h @@ -92,7 +92,7 @@ // // LCD / Controller // -#if HAS_WIRED_LCD +#if HAS_WIRED_LCD && DISABLED(LCD_USE_I2C_BUZZER) #define BEEPER_PIN P1_30 // (37) not 5V tolerant #endif diff --git a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h index dfa413b63fad..a0e035a91688 100644 --- a/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h +++ b/Marlin/src/pins/stm32f0/pins_MALYAN_M300.h @@ -33,6 +33,9 @@ // #if NO_EEPROM_SELECTED #define FLASH_EEPROM_EMULATION + #ifndef MARLIN_EEPROM_SIZE + #define MARLIN_EEPROM_SIZE 0x800U // 2KB + #endif #endif // diff --git a/Marlin/src/pins/stm32f1/pins_MORPHEUS.h b/Marlin/src/pins/stm32f1/pins_MORPHEUS.h index 28262eaa828c..ccc92b7527d1 100644 --- a/Marlin/src/pins/stm32f1/pins_MORPHEUS.h +++ b/Marlin/src/pins/stm32f1/pins_MORPHEUS.h @@ -89,3 +89,4 @@ // #define LED_PIN PC13 #define SDSS PA3 +#define TFTGLCD_CS PA4 From e4c23f85d39228cf6386d80927e33af0769e751e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 10 Oct 2020 01:17:34 -0500 Subject: [PATCH 06/46] Marlin 2.0.7.1 --- Marlin/Configuration.h | 3 +-- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- config/README.md | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ec8b162cd643..9f92bc4782ed 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -346,11 +346,10 @@ #endif #endif -// @section temperature - //=========================================================================== //============================= Thermal Settings ============================ //=========================================================================== +// @section temperature /** * --NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table diff --git a/Marlin/Version.h b/Marlin/Version.h index 5759771f7f4e..f642fec7567a 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -28,7 +28,7 @@ /** * Marlin release version identifier */ -//#define SHORT_BUILD_VERSION "2.0.7" +//#define SHORT_BUILD_VERSION "2.0.7.1" /** * Verbose version identifier which should contain a reference to the location diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index ad7f2e1d599c..274659c48b17 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -25,7 +25,7 @@ * Release version. Leave the Marlin version or apply a custom scheme. */ #ifndef SHORT_BUILD_VERSION - #define SHORT_BUILD_VERSION "2.0.7" + #define SHORT_BUILD_VERSION "2.0.7.1" #endif /** diff --git a/config/README.md b/config/README.md index 95d761155717..3d73a9bbbc71 100644 --- a/config/README.md +++ b/config/README.md @@ -1,3 +1,3 @@ # Where have all the configurations gone? -## https://github.com/MarlinFirmware/Configurations/archive/release-2.0.7.zip +## https://github.com/MarlinFirmware/Configurations/archive/release-2.0.7.1.zip From 349465b1688ae9f3c47cfc94f5d05b98d6ad5654 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Sun, 11 Oct 2020 00:15:24 +0000 Subject: [PATCH 07/46] [cron] Bump distribution date (2020-10-11) --- Marlin/src/inc/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 441ea22c2ab1..2b97b173a239 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-10-10" + #define STRING_DISTRIBUTION_DATE "2020-10-11" #endif /** From 492ba2a111ce541513d4515c4af3f57ceaa897ea Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 11 Oct 2020 14:58:35 -0500 Subject: [PATCH 08/46] Digipots refactor / cleanup (#19690) --- Marlin/src/HAL/DUE/fastio/G2_PWM.cpp | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/MarlinCore.cpp | 12 ++-- Marlin/src/feature/dac/dac_mcp4728.cpp | 50 ++++++++-------- Marlin/src/feature/dac/dac_mcp4728.h | 25 ++++---- Marlin/src/feature/dac/stepper_dac.cpp | 55 ++++++++--------- Marlin/src/feature/dac/stepper_dac.h | 19 +++--- Marlin/src/feature/digipot/digipot.h | 12 +++- .../src/feature/digipot/digipot_mcp4018.cpp | 12 ++-- .../src/feature/digipot/digipot_mcp4451.cpp | 8 ++- .../src/gcode/feature/digipot/M907-M910.cpp | 52 ++++++++-------- Marlin/src/gcode/gcode.cpp | 6 +- Marlin/src/gcode/gcode.h | 12 ++-- Marlin/src/inc/Conditionals_adv.h | 2 +- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/inc/SanityCheck.h | 2 +- Marlin/src/lcd/menu/menu_advanced.cpp | 8 +-- Marlin/src/module/settings.cpp | 59 ++++++++++++++----- Marlin/src/module/stepper.cpp | 55 ++++++++--------- Marlin/src/module/stepper.h | 22 ++++--- Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h | 2 +- .../src/pins/teensy2/pins_PRINTRBOARD_REVF.h | 2 +- platformio.ini | 4 +- 23 files changed, 239 insertions(+), 186 deletions(-) diff --git a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp index 1682faea666d..d9fbabce2148 100644 --- a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp +++ b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp @@ -154,7 +154,7 @@ void Stepper::digipot_init() { NVIC_SetPriority(PWM_IRQn, NVIC_EncodePriority(0, 10, 0)); // normal priority for PWM module (can stand some jitter on the Vref signals) } -void Stepper::digipot_current(const uint8_t driver, const int16_t current) { +void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) { if (!(PWM->PWM_CH_NUM[0].PWM_CPRD == PWM_PERIOD_US)) digipot_init(); // Init PWM system if needed diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index fd82e2884ae9..f5051d32a168 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -191,7 +191,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o // // Flag any i2c pin conflicts // -#if ANY(HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM) +#if ANY(HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM) #define USEDI2CDEV_M 1 // /Wire.cpp #if USEDI2CDEV_M == 0 // P0_27 [D57] (AUX-1) .......... P0_28 [D58] (AUX-1) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 672858d05a35..3a20cf3ee330 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -97,7 +97,7 @@ #include "feature/closedloop.h" #endif -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #include "feature/digipot/digipot.h" #endif @@ -125,7 +125,7 @@ #include "module/servo.h" #endif -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "feature/dac/stepper_dac.h" #endif @@ -1137,12 +1137,12 @@ void setup() { SETUP_RUN(enableStepperDrivers()); #endif - #if HAS_I2C_DIGIPOT - SETUP_RUN(digipot_i2c_init()); + #if HAS_MOTOR_CURRENT_I2C + SETUP_RUN(digipot_i2c.init()); #endif - #if ENABLED(DAC_STEPPER_CURRENT) - SETUP_RUN(dac_init()); + #if ENABLED(HAS_MOTOR_CURRENT_DAC) + SETUP_RUN(stepper_dac.init()); #endif #if EITHER(Z_PROBE_SLED, SOLENOID_PROBE) && HAS_SOLENOID_1 diff --git a/Marlin/src/feature/dac/dac_mcp4728.cpp b/Marlin/src/feature/dac/dac_mcp4728.cpp index 55f10a49ef70..81c465cf29e4 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.cpp +++ b/Marlin/src/feature/dac/dac_mcp4728.cpp @@ -32,16 +32,18 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "dac_mcp4728.h" -xyze_uint_t mcp4728_values; +MCP4728 mcp4728; + +xyze_uint_t dac_values; /** * Begin I2C, get current values (input register and eeprom) of mcp4728 */ -void mcp4728_init() { +void MCP4728::init() { Wire.begin(); Wire.requestFrom(I2C_ADDRESS(DAC_DEV_ADDRESS), uint8_t(24)); while (Wire.available()) { @@ -50,7 +52,7 @@ void mcp4728_init() { loByte = Wire.read(); if (!(deviceID & 0x08)) - mcp4728_values[(deviceID & 0x30) >> 4] = word((hiByte & 0x0F), loByte); + dac_values[(deviceID & 0x30) >> 4] = word((hiByte & 0x0F), loByte); } } @@ -58,9 +60,9 @@ void mcp4728_init() { * Write input resister value to specified channel using fastwrite method. * Channel : 0-3, Values : 0-4095 */ -uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value) { - mcp4728_values[channel] = value; - return mcp4728_fastWrite(); +uint8_t MCP4728::analogWrite(const uint8_t channel, const uint16_t value) { + dac_values[channel] = value; + return fastWrite(); } /** @@ -68,12 +70,12 @@ uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value) { * This will update both input register and EEPROM value * This will also write current Vref, PowerDown, Gain settings to EEPROM */ -uint8_t mcp4728_eepromWrite() { +uint8_t MCP4728::eepromWrite() { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(SEQWRITE); LOOP_XYZE(i) { - Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i])); - Wire.write(lowByte(mcp4728_values[i])); + Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(dac_values[i])); + Wire.write(lowByte(dac_values[i])); } return Wire.endTransmission(); } @@ -81,7 +83,7 @@ uint8_t mcp4728_eepromWrite() { /** * Write Voltage reference setting to all input regiters */ -uint8_t mcp4728_setVref_all(const uint8_t value) { +uint8_t MCP4728::setVref_all(const uint8_t value) { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(VREFWRITE | (value ? 0x0F : 0x00)); return Wire.endTransmission(); @@ -89,7 +91,7 @@ uint8_t mcp4728_setVref_all(const uint8_t value) { /** * Write Gain setting to all input regiters */ -uint8_t mcp4728_setGain_all(const uint8_t value) { +uint8_t MCP4728::setGain_all(const uint8_t value) { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(GAINWRITE | (value ? 0x0F : 0x00)); return Wire.endTransmission(); @@ -98,16 +100,16 @@ uint8_t mcp4728_setGain_all(const uint8_t value) { /** * Return Input Register value */ -uint16_t mcp4728_getValue(const uint8_t channel) { return mcp4728_values[channel]; } +uint16_t MCP4728::getValue(const uint8_t channel) { return dac_values[channel]; } #if 0 /** * Steph: Might be useful in the future * Return Vout */ -uint16_t mcp4728_getVout(const uint8_t channel) { +uint16_t MCP4728::getVout(const uint8_t channel) { const uint32_t vref = 2048, - vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096; + vOut = (vref * dac_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096; return _MIN(vOut, defaultVDD); } #endif @@ -115,15 +117,15 @@ uint16_t mcp4728_getVout(const uint8_t channel) { /** * Returns DAC values as a 0-100 percentage of drive strength */ -uint8_t mcp4728_getDrvPct(const uint8_t channel) { return uint8_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); } +uint8_t MCP4728::getDrvPct(const uint8_t channel) { return uint8_t(100.0 * dac_values[channel] / (DAC_STEPPER_MAX) + 0.5); } /** * Receives all Drive strengths as 0-100 percent values, updates * DAC Values array and calls fastwrite to update the DAC. */ -void mcp4728_setDrvPct(xyze_uint8_t &pct) { - mcp4728_values *= 0.01 * pct * (DAC_STEPPER_MAX); - mcp4728_fastWrite(); +void MCP4728::setDrvPct(xyze_uint8_t &pct) { + dac_values *= 0.01 * pct * (DAC_STEPPER_MAX); + fastWrite(); } /** @@ -131,11 +133,11 @@ void mcp4728_setDrvPct(xyze_uint8_t &pct) { * DAC Input and PowerDown bits update. * No EEPROM update */ -uint8_t mcp4728_fastWrite() { +uint8_t MCP4728::fastWrite() { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); LOOP_XYZE(i) { - Wire.write(highByte(mcp4728_values[i])); - Wire.write(lowByte(mcp4728_values[i])); + Wire.write(highByte(dac_values[i])); + Wire.write(lowByte(dac_values[i])); } return Wire.endTransmission(); } @@ -143,10 +145,10 @@ uint8_t mcp4728_fastWrite() { /** * Common function for simple general commands */ -uint8_t mcp4728_simpleCommand(const byte simpleCommand) { +uint8_t MCP4728::simpleCommand(const byte simpleCommand) { Wire.beginTransmission(I2C_ADDRESS(GENERALCALL)); Wire.write(simpleCommand); return Wire.endTransmission(); } -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/feature/dac/dac_mcp4728.h b/Marlin/src/feature/dac/dac_mcp4728.h index fc69bd8ff4eb..571716d4834e 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.h +++ b/Marlin/src/feature/dac/dac_mcp4728.h @@ -65,13 +65,18 @@ // DAC_OR_ADDRESS defined in pins_BOARD.h file #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS) -void mcp4728_init(); -uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value); -uint8_t mcp4728_eepromWrite(); -uint8_t mcp4728_setVref_all(const uint8_t value); -uint8_t mcp4728_setGain_all(const uint8_t value); -uint16_t mcp4728_getValue(const uint8_t channel); -uint8_t mcp4728_fastWrite(); -uint8_t mcp4728_simpleCommand(const byte simpleCommand); -uint8_t mcp4728_getDrvPct(const uint8_t channel); -void mcp4728_setDrvPct(xyze_uint8_t &pct); +class MCP4728 { +public: + static void init(); + static uint8_t analogWrite(const uint8_t channel, const uint16_t value); + static uint8_t eepromWrite(); + static uint8_t setVref_all(const uint8_t value); + static uint8_t setGain_all(const uint8_t value); + static uint16_t getValue(const uint8_t channel); + static uint8_t fastWrite(); + static uint8_t simpleCommand(const byte simpleCommand); + static uint8_t getDrvPct(const uint8_t channel); + static void setDrvPct(xyze_uint8_t &pct); +}; + +extern MCP4728 mcp4728; diff --git a/Marlin/src/feature/dac/stepper_dac.cpp b/Marlin/src/feature/dac/stepper_dac.cpp index 6b140a002510..5f10b4ccfbdc 100644 --- a/Marlin/src/feature/dac/stepper_dac.cpp +++ b/Marlin/src/feature/dac/stepper_dac.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "stepper_dac.h" #include "../../MarlinCore.h" // for SP_X_LBL... @@ -35,56 +35,53 @@ bool dac_present = false; constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER; xyze_uint8_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT; -int dac_init() { +StepperDAC stepper_dac; + +int StepperDAC::init() { #if PIN_EXISTS(DAC_DISABLE) OUT_WRITE(DAC_DISABLE_PIN, LOW); // set pin low to enable DAC #endif - mcp4728_init(); + mcp4728.init(); - if (mcp4728_simpleCommand(RESET)) return -1; + if (mcp4728.simpleCommand(RESET)) return -1; dac_present = true; - mcp4728_setVref_all(DAC_STEPPER_VREF); - mcp4728_setGain_all(DAC_STEPPER_GAIN); + mcp4728.setVref_all(DAC_STEPPER_VREF); + mcp4728.setGain_all(DAC_STEPPER_GAIN); - if (mcp4728_getDrvPct(0) < 1 || mcp4728_getDrvPct(1) < 1 || mcp4728_getDrvPct(2) < 1 || mcp4728_getDrvPct(3) < 1 ) { - mcp4728_setDrvPct(dac_channel_pct); - mcp4728_eepromWrite(); + if (mcp4728.getDrvPct(0) < 1 || mcp4728.getDrvPct(1) < 1 || mcp4728.getDrvPct(2) < 1 || mcp4728.getDrvPct(3) < 1 ) { + mcp4728.setDrvPct(dac_channel_pct); + mcp4728.eepromWrite(); } return 0; } -void dac_current_percent(uint8_t channel, float val) { +void StepperDAC::set_current_value(const uint8_t channel, uint16_t val) { if (!dac_present) return; - NOMORE(val, 100); + NOMORE(val, uint16_t(DAC_STEPPER_MAX)); - mcp4728_analogWrite(dac_order[channel], val * 0.01 * (DAC_STEPPER_MAX)); - mcp4728_simpleCommand(UPDATE); + mcp4728.analogWrite(dac_order[channel], val); + mcp4728.simpleCommand(UPDATE); } -void dac_current_raw(uint8_t channel, uint16_t val) { - if (!dac_present) return; - - NOMORE(val, uint16_t(DAC_STEPPER_MAX)); - - mcp4728_analogWrite(dac_order[channel], val); - mcp4728_simpleCommand(UPDATE); +void StepperDAC::set_current_percent(const uint8_t channel, float val) { + set_current_value(channel, _MIN(val, 100.0f) * (DAC_STEPPER_MAX) / 100.0f); } -static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); } -static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); } +static float dac_perc(int8_t n) { return 100.0 * mcp4728.getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); } +static float dac_amps(int8_t n) { return mcp4728.getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); } -uint8_t dac_current_get_percent(const AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); } -void dac_current_set_percents(xyze_uint8_t &pct) { +uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); } +void StepperDAC::set_current_percents(xyze_uint8_t &pct) { LOOP_XYZE(i) dac_channel_pct[i] = pct[dac_order[i]]; - mcp4728_setDrvPct(dac_channel_pct); + mcp4728.setDrvPct(dac_channel_pct); } -void dac_print_values() { +void StepperDAC::print_values() { if (!dac_present) return; SERIAL_ECHO_MSG("Stepper current values in % (Amps):"); SERIAL_ECHO_START(); @@ -94,9 +91,9 @@ void dac_print_values() { SERIAL_ECHOLNPAIR_P(SP_E_LBL, dac_perc(E_AXIS), PSTR(" ("), dac_amps(E_AXIS), PSTR(")")); } -void dac_commit_eeprom() { +void StepperDAC::commit_eeprom() { if (!dac_present) return; - mcp4728_eepromWrite(); + mcp4728.eepromWrite(); } -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/feature/dac/stepper_dac.h b/Marlin/src/feature/dac/stepper_dac.h index 0543b6275e2c..6836335e9806 100644 --- a/Marlin/src/feature/dac/stepper_dac.h +++ b/Marlin/src/feature/dac/stepper_dac.h @@ -27,10 +27,15 @@ #include "dac_mcp4728.h" -int dac_init(); -void dac_current_percent(uint8_t channel, float val); -void dac_current_raw(uint8_t channel, uint16_t val); -void dac_print_values(); -void dac_commit_eeprom(); -uint8_t dac_current_get_percent(AxisEnum axis); -void dac_current_set_percents(xyze_uint8_t &pct); +class StepperDAC { +public: + static int init(); + static void set_current_percent(const uint8_t channel, float val); + static void set_current_value(const uint8_t channel, uint16_t val); + static void print_values(); + static void commit_eeprom(); + static uint8_t get_current_percent(AxisEnum axis); + static void set_current_percents(xyze_uint8_t &pct); +}; + +extern StepperDAC stepper_dac; diff --git a/Marlin/src/feature/digipot/digipot.h b/Marlin/src/feature/digipot/digipot.h index d59f8b930af5..c53f8093dd52 100644 --- a/Marlin/src/feature/digipot/digipot.h +++ b/Marlin/src/feature/digipot/digipot.h @@ -21,5 +21,13 @@ */ #pragma once -void digipot_i2c_set_current(const uint8_t channel, const float current); -void digipot_i2c_init(); +// +// Header for MCP4018 and MCP4451 current control i2c devices +// +class DigipotI2C { +public: + static void init(); + static void set_current(const uint8_t channel, const float current); +}; + +DigipotI2C digipot_i2c; diff --git a/Marlin/src/feature/digipot/digipot_mcp4018.cpp b/Marlin/src/feature/digipot/digipot_mcp4018.cpp index 35c513a32c39..6260185fc32d 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4018.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4018.cpp @@ -24,6 +24,8 @@ #if ENABLED(DIGIPOT_MCP4018) +#include "digipot.h" + #include #include // https://github.com/stawel/SlowSoftI2CMaster @@ -68,7 +70,7 @@ static SlowSoftI2CMaster pots[DIGIPOT_I2C_NUM_CHANNELS] = { #endif }; -static void i2c_send(const uint8_t channel, const byte v) { +static void digipot_i2c_send(const uint8_t channel, const byte v) { if (WITHIN(channel, 0, DIGIPOT_I2C_NUM_CHANNELS - 1)) { pots[channel].i2c_start(((DIGIPOT_I2C_ADDRESS_A) << 1) | I2C_WRITE); pots[channel].i2c_write(v); @@ -77,12 +79,12 @@ static void i2c_send(const uint8_t channel, const byte v) { } // This is for the MCP4018 I2C based digipot -void digipot_i2c_set_current(const uint8_t channel, const float current) { +void DigipotI2C::set_current(const uint8_t channel, const float current) { const float ival = _MIN(_MAX(current, 0), float(DIGIPOT_MCP4018_MAX_VALUE)); - i2c_send(channel, current_to_wiper(ival)); + digipot_i2c_send(channel, current_to_wiper(ival)); } -void digipot_i2c_init() { +void DigipotI2C::init() { LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS) pots[i].i2c_init(); // Init currents according to Configuration_adv.h @@ -94,7 +96,7 @@ void digipot_i2c_init() { #endif ; LOOP_L_N(i, COUNT(digipot_motor_current)) - digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i])); + set_current(i, pgm_read_float(&digipot_motor_current[i])); } #endif // DIGIPOT_MCP4018 diff --git a/Marlin/src/feature/digipot/digipot_mcp4451.cpp b/Marlin/src/feature/digipot/digipot_mcp4451.cpp index 0c8ff04a0bbf..7e6ace49a06a 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4451.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4451.cpp @@ -24,6 +24,8 @@ #if ENABLED(DIGIPOT_MCP4451) +#include "digipot.h" + #include #include @@ -61,7 +63,7 @@ static void digipot_i2c_send(const byte addr, const byte a, const byte b) { } // This is for the MCP4451 I2C based digipot -void digipot_i2c_set_current(const uint8_t channel, const float current) { +void DigipotI2C::set_current(const uint8_t channel, const float current) { // These addresses are specific to Azteeg X3 Pro, can be set to others. // In this case first digipot is at address A0=0, A1=0, second one is at A0=0, A1=1 const byte addr = channel < 4 ? DIGIPOT_I2C_ADDRESS_A : DIGIPOT_I2C_ADDRESS_B; // channel 0-3 vs 4-7 @@ -75,7 +77,7 @@ void digipot_i2c_set_current(const uint8_t channel, const float current) { digipot_i2c_send(addr, addresses[channel & 0x3], current_to_wiper(_MIN(float(_MAX(current, 0)), DIGIPOT_I2C_MAX_CURRENT))); } -void digipot_i2c_init() { +void DigipotI2C::init() { #if MB(MKS_SBASE) configure_i2c(16); // Set clock_option to 16 ensure I2C is initialized at 400kHz #else @@ -90,7 +92,7 @@ void digipot_i2c_init() { #endif ; LOOP_L_N(i, COUNT(digipot_motor_current)) - digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i])); + set_current(i, pgm_read_float(&digipot_motor_current[i])); } #endif // DIGIPOT_MCP4451 diff --git a/Marlin/src/gcode/feature/digipot/M907-M910.cpp b/Marlin/src/gcode/feature/digipot/M907-M910.cpp index 54599a045134..e46366620798 100644 --- a/Marlin/src/gcode/feature/digipot/M907-M910.cpp +++ b/Marlin/src/gcode/feature/digipot/M907-M910.cpp @@ -22,19 +22,19 @@ #include "../../../inc/MarlinConfig.h" -#if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) +#if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) #include "../../gcode.h" -#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM +#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM #include "../../../module/stepper.h" #endif -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #include "../../../feature/digipot/digipot.h" #endif -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "../../../feature/dac/stepper_dac.h" #endif @@ -42,61 +42,61 @@ * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S */ void GcodeSuite::M907() { - #if HAS_DIGIPOTSS + #if HAS_MOTOR_CURRENT_SPI - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int()); - if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int()); - if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.digipot_current(i, parser.value_int()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.set_digipot_current(i, parser.value_int()); + if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int()); + if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int()); #elif HAS_MOTOR_CURRENT_PWM #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY) - if (parser.seenval('X') || parser.seenval('Y')) stepper.digipot_current(0, parser.value_int()); + if (parser.seenval('X') || parser.seenval('Y')) stepper.set_digipot_current(0, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) - if (parser.seenval('Z')) stepper.digipot_current(1, parser.value_int()); + if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_E) - if (parser.seenval('E')) stepper.digipot_current(2, parser.value_int()); + if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int()); #endif #endif - #if HAS_I2C_DIGIPOT + #if HAS_MOTOR_CURRENT_I2C // this one uses actual amps in floating point - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c.set_current(i, parser.value_float()); // Additional extruders use B,C,D for channels 4,5,6. // TODO: Change these parameters because 'E' is used. B? for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++) - if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c_set_current(i, parser.value_float()); + if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float()); #endif - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) if (parser.seenval('S')) { const float dac_percent = parser.value_float(); - LOOP_LE_N(i, 4) dac_current_percent(i, dac_percent); + LOOP_LE_N(i, 4) stepper_dac.set_current_percent(i, dac_percent); } - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper_dac.set_current_percent(i, parser.value_float()); #endif } -#if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) +#if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) /** * M908: Control digital trimpot directly (M908 P S) */ void GcodeSuite::M908() { - TERN_(HAS_DIGIPOTSS, stepper.digitalPotWrite(parser.intval('P'), parser.intval('S'))); - TERN_(DAC_STEPPER_CURRENT, dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0))); + TERN_(HAS_MOTOR_CURRENT_SPI, stepper.set_digipot_value_spi(parser.intval('P'), parser.intval('S'))); + TERN_(HAS_MOTOR_CURRENT_DAC, stepper_dac.set_current_value(parser.byteval('P', -1), parser.ushortval('S', 0))); } -#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT + #if ENABLED(HAS_MOTOR_CURRENT_DAC) -#if ENABLED(DAC_STEPPER_CURRENT) + void GcodeSuite::M909() { stepper_dac.print_values(); } + void GcodeSuite::M910() { stepper_dac.commit_eeprom(); } - void GcodeSuite::M909() { dac_print_values(); } - void GcodeSuite::M910() { dac_commit_eeprom(); } + #endif // HAS_MOTOR_CURRENT_DAC -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC -#endif // HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || HAS_I2C_DIGIPOT || DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index cbf62e0fcf97..1d4e8f9d4d07 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -823,11 +823,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 900: M900(); break; // M900: Set advance K factor. #endif - #if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) + #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes. - #if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) + #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) case 908: M908(); break; // M908: Control digital trimpot directly. - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) case 909: M909(); break; // M909: Print digipot/DAC current value case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 73a372781370..683642bec60f 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -258,9 +258,9 @@ * M900 - Get or Set Linear Advance K-factor. (Requires LIN_ADVANCE) * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660 or L6470) * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots) - * M908 - Control digital trimpot directly. (Requires DAC_STEPPER_CURRENT or DIGIPOTSS_PIN) - * M909 - Print digipot/DAC current value. (Requires DAC_STEPPER_CURRENT) - * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires DAC_STEPPER_CURRENT) + * M908 - Control digital trimpot directly. (Requires HAS_MOTOR_CURRENT_DAC or DIGIPOTSS_PIN) + * M909 - Print digipot/DAC current value. (Requires HAS_MOTOR_CURRENT_DAC) + * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires HAS_MOTOR_CURRENT_DAC) * M911 - Report stepper driver overtemperature pre-warn condition. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M913 - Set HYBRID_THRESHOLD speed. (Requires HYBRID_THRESHOLD) @@ -847,11 +847,11 @@ class GcodeSuite { static void M918(); #endif - #if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) + #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) static void M907(); - #if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) + #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) static void M908(); - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) static void M909(); static void M910(); #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 0952148d1989..255470bca6e7 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -175,7 +175,7 @@ #endif #if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451) - #define HAS_I2C_DIGIPOT 1 + #define HAS_MOTOR_CURRENT_I2C 1 #endif // Multiple Z steppers diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index f832137f5b40..798bf009c639 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1976,7 +1976,7 @@ #define HAS_STEPPER_RESET 1 #endif #if PIN_EXISTS(DIGIPOTSS) - #define HAS_DIGIPOTSS 1 + #define HAS_MOTOR_CURRENT_SPI 1 #endif #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_E) #define HAS_MOTOR_CURRENT_PWM 1 diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c4dcfd54ae82..6e97a349f673 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2667,7 +2667,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal /** * Digipot requirement */ -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #if BOTH(DIGIPOT_MCP4018, DIGIPOT_MCP4451) #error "Enable only one of DIGIPOT_MCP4018 or DIGIPOT_MCP4451." #elif !MB(MKS_SBASE) \ diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index 68a10245e951..642d9d84d94f 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -58,16 +58,16 @@ void menu_tmc(); void menu_backlash(); -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "../../feature/dac/stepper_dac.h" void menu_dac() { static xyze_uint8_t driverPercent; - LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); + LOOP_XYZE(i) driverPercent[i] = stepper_dac.get_current_percent((AxisEnum)i); START_MENU(); BACK_ITEM(MSG_ADVANCED_SETTINGS); - #define EDIT_DAC_PERCENT(A) EDIT_ITEM(uint8, MSG_DAC_PERCENT_##A, &driverPercent[_AXIS(A)], 0, 100, []{ dac_current_set_percents(driverPercent); }) + #define EDIT_DAC_PERCENT(A) EDIT_ITEM(uint8, MSG_DAC_PERCENT_##A, &driverPercent[_AXIS(A)], 0, 100, []{ stepper_dac.set_current_percents(driverPercent); }) EDIT_DAC_PERCENT(X); EDIT_DAC_PERCENT(Y); EDIT_DAC_PERCENT(Z); @@ -568,7 +568,7 @@ void menu_advanced_settings() { SUBMENU(MSG_BACKLASH, menu_backlash); #endif - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) SUBMENU(MSG_DRIVE_STRENGTH, menu_dac); #endif #if HAS_MOTOR_CURRENT_PWM diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 3ccd8ffd9185..33e5c351abc1 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -36,7 +36,7 @@ */ // Change EEPROM version if the structure changes -#define EEPROM_VERSION "V81" +#define EEPROM_VERSION "V82" #define EEPROM_OFFSET 100 // Check the integrity of data offsets. @@ -365,7 +365,10 @@ typedef struct SettingsDataStruct { // // HAS_MOTOR_CURRENT_PWM // - uint32_t motor_current_setting[3]; // M907 X Z E + #ifndef MOTOR_CURRENT_COUNT + #define MOTOR_CURRENT_COUNT 3 + #endif + uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E // // CNC_COORDINATE_SYSTEMS @@ -1277,10 +1280,10 @@ void MarlinSettings::postprocess() { { _FIELD_TEST(motor_current_setting); - #if HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM EEPROM_WRITE(stepper.motor_current_setting); #else - const uint32_t no_current[3] = { 0 }; + const uint32_t no_current[MOTOR_CURRENT_COUNT] = { 0 }; EEPROM_WRITE(no_current); #endif } @@ -2110,10 +2113,16 @@ void MarlinSettings::postprocess() { // Motor Current PWM // { - uint32_t motor_current_setting[3]; _FIELD_TEST(motor_current_setting); + uint32_t motor_current_setting[MOTOR_CURRENT_COUNT] + #if HAS_MOTOR_CURRENT_SPI + = DIGIPOT_MOTOR_CURRENT + #endif + ; + DEBUG_ECHOLNPGM("DIGIPOTS Loading"); EEPROM_READ(motor_current_setting); - #if HAS_MOTOR_CURRENT_PWM + DEBUG_ECHOLNPGM("DIGIPOTS Loaded"); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM if (!validating) COPY(stepper.motor_current_setting, motor_current_setting); #endif @@ -2791,9 +2800,20 @@ void MarlinSettings::reset() { // #if HAS_MOTOR_CURRENT_PWM - constexpr uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT; - LOOP_L_N(q, 3) - stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q])); + constexpr uint32_t tmp_motor_current_setting[MOTOR_CURRENT_COUNT] = PWM_MOTOR_CURRENT; + LOOP_L_N(q, MOTOR_CURRENT_COUNT) + stepper.set_digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q])); + #endif + + // + // DIGIPOTS + // + #if HAS_MOTOR_CURRENT_SPI + static constexpr uint32_t tmp_motor_current_setting[] = DIGIPOT_MOTOR_CURRENT; + DEBUG_ECHOLNPGM("Writing Digipot"); + LOOP_L_N(q, COUNT(tmp_motor_current_setting)) + stepper.set_digipot_current(q, tmp_motor_current_setting[q]); + DEBUG_ECHOLNPGM("Digipot Written"); #endif // @@ -3695,14 +3715,23 @@ void MarlinSettings::reset() { #endif #endif - #if HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM CONFIG_ECHO_HEADING("Stepper motor currents:"); CONFIG_ECHO_START(); - SERIAL_ECHOLNPAIR_P( - PSTR(" M907 X"), stepper.motor_current_setting[0] - , SP_Z_STR, stepper.motor_current_setting[1] - , SP_E_STR, stepper.motor_current_setting[2] - ); + #if HAS_MOTOR_CURRENT_PWM + SERIAL_ECHOLNPAIR_P( + PSTR(" M907 X"), stepper.motor_current_setting[0] + , SP_Z_STR, stepper.motor_current_setting[1] + , SP_E_STR, stepper.motor_current_setting[2] + ); + #elif HAS_MOTOR_CURRENT_SPI + SERIAL_ECHOPGM(" M907"); + LOOP_L_N(q, MOTOR_CURRENT_COUNT) { + SERIAL_CHAR(' '); + SERIAL_CHAR(axis_codes[q]); + SERIAL_ECHO(stepper.motor_current_setting[q]); + } + #endif #endif /** diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 56a75d1b4812..8a5de4b6087b 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -83,10 +83,6 @@ Stepper stepper; // Singleton #define BABYSTEPPING_EXTRA_DIR_WAIT -#if HAS_MOTOR_CURRENT_PWM - bool Stepper::initialized; // = false -#endif - #ifdef __AVR__ #include "speed_lookuptable.h" #endif @@ -110,7 +106,7 @@ Stepper stepper; // Singleton #include "../feature/dac/dac_dac084s085.h" #endif -#if HAS_DIGIPOTSS +#if HAS_MOTOR_CURRENT_SPI #include #endif @@ -142,8 +138,12 @@ Stepper stepper; // Singleton bool Stepper::separate_multi_axis = false; #endif -#if HAS_MOTOR_CURRENT_PWM - uint32_t Stepper::motor_current_setting[3]; // Initialized by settings.load() +#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + bool Stepper::initialized; // = false + uint32_t Stepper::motor_current_setting[MOTOR_CURRENT_COUNT]; // Initialized by settings.load() + #if HAS_MOTOR_CURRENT_SPI + constexpr uint32_t Stepper::digipot_count[]; + #endif #endif // private: @@ -2590,8 +2590,8 @@ void Stepper::init() { set_directions(); - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM - TERN_(HAS_MOTOR_CURRENT_PWM, initialized = true); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + initialized = true; digipot_init(); #endif } @@ -2930,10 +2930,10 @@ void Stepper::report_positions() { * Software-controlled Stepper Motor Current */ -#if HAS_DIGIPOTSS +#if HAS_MOTOR_CURRENT_SPI // From Arduino DigitalPotControl example - void Stepper::digitalPotWrite(const int16_t address, const int16_t value) { + void Stepper::set_digipot_value_spi(const int16_t address, const int16_t value) { WRITE(DIGIPOTSS_PIN, LOW); // Take the SS pin low to select the chip SPI.transfer(address); // Send the address and value via SPI SPI.transfer(value); @@ -2941,7 +2941,7 @@ void Stepper::report_positions() { //delay(10); } -#endif // HAS_DIGIPOTSS +#endif // HAS_MOTOR_CURRENT_SPI #if HAS_MOTOR_CURRENT_PWM @@ -2958,7 +2958,7 @@ void Stepper::report_positions() { #if ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_E0, MOTOR_CURRENT_PWM_E1) case 2: #endif - digipot_current(i, motor_current_setting[i]); + set_digipot_current(i, motor_current_setting[i]); default: break; } } @@ -2968,21 +2968,22 @@ void Stepper::report_positions() { #if !MB(PRINTRBOARD_G2) - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM - void Stepper::digipot_current(const uint8_t driver, const int16_t current) { + void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) { + if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) + motor_current_setting[driver] = current; // update motor_current_setting - #if HAS_DIGIPOTSS + if (!initialized) return; - const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; - digitalPotWrite(digipot_ch[driver], current); + #if HAS_MOTOR_CURRENT_SPI - #elif HAS_MOTOR_CURRENT_PWM + //SERIAL_ECHOLNPAIR("Digipotss current ", current); - if (!initialized) return; + const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; + set_digipot_value_spi(digipot_ch[driver], current); - if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) - motor_current_setting[driver] = current; // update motor_current_setting + #elif HAS_MOTOR_CURRENT_PWM #define _WRITE_CURRENT_PWM(P) analogWrite(pin_t(MOTOR_CURRENT_PWM_## P ##_PIN), 255L * current / (MOTOR_CURRENT_PWM_RANGE)) switch (driver) { @@ -3019,17 +3020,13 @@ void Stepper::report_positions() { void Stepper::digipot_init() { - #if HAS_DIGIPOTSS - - static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT; + #if HAS_MOTOR_CURRENT_SPI SPI.begin(); SET_OUTPUT(DIGIPOTSS_PIN); - LOOP_L_N(i, COUNT(digipot_motor_current)) { - //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]); - digipot_current(i, digipot_motor_current[i]); - } + LOOP_L_N(i, COUNT(motor_current_setting)) + set_digipot_current(i, motor_current_setting[i]); #elif HAS_MOTOR_CURRENT_PWM diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index da38192d8ea3..572c3f3f9b2d 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -245,12 +245,18 @@ class Stepper { static bool separate_multi_axis; #endif - #if HAS_MOTOR_CURRENT_PWM - #ifndef PWM_MOTOR_CURRENT - #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_PWM + #ifndef PWM_MOTOR_CURRENT + #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT + #endif + #define MOTOR_CURRENT_COUNT 3 + #elif HAS_MOTOR_CURRENT_SPI + static constexpr uint32_t digipot_count[] = DIGIPOT_MOTOR_CURRENT; + #define MOTOR_CURRENT_COUNT COUNT(Stepper::digipot_count) #endif - static uint32_t motor_current_setting[3]; static bool initialized; + static uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // Initialized by settings.load() #endif // Last-moved extruder, as set when the last movement was fetched from planner @@ -457,9 +463,9 @@ class Stepper { // Triggered position of an axis in steps static int32_t triggered_position(const AxisEnum axis); - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM - static void digitalPotWrite(const int16_t address, const int16_t value); - static void digipot_current(const uint8_t driver, const int16_t current); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + static void set_digipot_value_spi(const int16_t address, const int16_t value); + static void set_digipot_current(const uint8_t driver, const int16_t current); #endif #if HAS_MICROSTEPS @@ -582,7 +588,7 @@ class Stepper { static int32_t _eval_bezier_curve(const uint32_t curr_step); #endif - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM static void digipot_init(); #endif diff --git a/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h b/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h index 406cbec8167f..1428de31a22b 100644 --- a/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h +++ b/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h @@ -34,7 +34,7 @@ // // I2C based DAC like on the Printrboard REVF -#define DAC_STEPPER_CURRENT +#define HAS_MOTOR_CURRENT_DAC // Channels available for DAC, For Rigidboard there are 4 #define DAC_STEPPER_ORDER { 0, 1, 2, 3 } diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h index 6ffd35dff273..4809cc8d86b8 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h @@ -143,7 +143,7 @@ #endif // NO_EXTRUDRBOARD // Enable control of stepper motor currents with the I2C based MCP4728 DAC used on Printrboard REVF -#define DAC_STEPPER_CURRENT +#define HAS_MOTOR_CURRENT_DAC // Set default drive strength percents if not already defined - X, Y, Z, E axis #ifndef DAC_MOTOR_CURRENT_DEFAULT diff --git a/platformio.ini b/platformio.ini index d4beca6519be..9d3fafd69e38 100644 --- a/platformio.ini +++ b/platformio.ini @@ -211,7 +211,7 @@ HAS_TRINAMIC_CONFIG = TMCStepper@~0.7.1 src_filter=+ + + + + HAS_STEALTHCHOP = src_filter=+ SR_LCD_3W_NL = SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/master.zip -HAS_I2C_DIGIPOT = SlowSoftI2CMaster +HAS_MOTOR_CURRENT_I2C = SlowSoftI2CMaster src_filter=+ HAS_TMC26X = TMC26XStepper=https://github.com/trinamic/TMC26XStepper/archive/master.zip src_filter=+ @@ -277,7 +277,7 @@ CANCEL_OBJECTS = src_filter=+ + + EXTERNAL_CLOSED_LOOP_CONTROLLER = src_filter=+ + USE_CONTROLLER_FAN = src_filter=+ -DAC_STEPPER_CURRENT = src_filter=+ +HAS_MOTOR_CURRENT_DAC = src_filter=+ DIRECT_STEPPING = src_filter=+ + EMERGENCY_PARSER = src_filter=+ - I2C_POSITION_ENCODERS = src_filter=+ From 45731bd0221beee768e009195ee3aa9a0b0f2a88 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 16:13:01 -0700 Subject: [PATCH 09/46] Fix at90usb1286 build (#19687) * Skip check for USBCON during dependency detection * Ignore incompatible Teensy_ADC library, which requires Teensy >= 3 * Add IS_AT90USB Co-authored-by: Scott Lahteine --- Marlin/src/HAL/AVR/HAL.h | 4 ++-- Marlin/src/HAL/AVR/MarlinSerial.cpp | 6 +++--- Marlin/src/HAL/AVR/MarlinSerial.h | 2 +- Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp | 3 +-- Marlin/src/gcode/control/M111.cpp | 4 ++-- Marlin/src/gcode/queue.cpp | 2 +- Marlin/src/inc/Conditionals_adv.h | 8 ++++---- Marlin/src/inc/SanityCheck.h | 6 +++--- Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h | 2 +- platformio.ini | 1 + 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index ce15ed29fb3a..6e0afa8f10ed 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -25,7 +25,7 @@ #include "watchdog.h" #include "math.h" -#ifdef USBCON +#ifdef IS_AT90USB #include #else #define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion @@ -81,7 +81,7 @@ typedef int8_t pin_t; //extern uint8_t MCUSR; // Serial ports -#ifdef USBCON +#ifdef IS_AT90USB #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) #else #if !WITHIN(SERIAL_PORT, -1, 3) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 63599efd4132..8feac32aa74c 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -38,7 +38,7 @@ #include "../../inc/MarlinConfig.h" -#if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) +#if !IS_AT90USB && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) #include "MarlinSerial.h" #include "../../MarlinCore.h" @@ -792,10 +792,10 @@ MarlinSerial> customizedSerial1; #endif -#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) +#endif // !IS_AT90USB && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) // For AT90USB targets use the UART for BT interfacing -#if defined(USBCON) && ENABLED(BLUETOOTH) +#if BOTH(IS_AT90USB, BLUETOOTH) HardwareSerial bluetoothSerial; #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index 8a0423d143d8..3850e2a47e2a 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -327,6 +327,6 @@ #endif // Use the UART for Bluetooth in AT90USB configurations -#if defined(USBCON) && ENABLED(BLUETOOTH) +#if BOTH(IS_AT90USB, BLUETOOTH) extern HardwareSerial bluetoothSerial; #endif diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp index f88fa8850788..60596054e820 100644 --- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp +++ b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp @@ -22,7 +22,6 @@ #if BOTH(HAS_MARLINUI_U8GLIB, FORCE_SOFT_SPI) -#include "../HAL.h" #include #undef SPI_SPEED @@ -161,5 +160,5 @@ uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, return 1; } -#endif // HAS_MARLINUI_U8GLIB +#endif // HAS_MARLINUI_U8GLIB && FORCE_SOFT_SPI #endif // STM32F1 diff --git a/Marlin/src/gcode/control/M111.cpp b/Marlin/src/gcode/control/M111.cpp index e31c3e2fb7b2..cc871bf38b52 100644 --- a/Marlin/src/gcode/control/M111.cpp +++ b/Marlin/src/gcode/control/M111.cpp @@ -55,7 +55,7 @@ void GcodeSuite::M111() { } else { SERIAL_ECHOPGM(STR_DEBUG_OFF); - #if !defined(__AVR__) || !defined(USBCON) + #if !IS_AT90USB #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS) SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns()); #endif @@ -71,7 +71,7 @@ void GcodeSuite::M111() { #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued()); #endif - #endif // !defined(__AVR__) || !defined(USBCON) + #endif // !IS_AT90USB } SERIAL_EOL(); } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index b9169d90e1c7..a02d2c016042 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -624,7 +624,7 @@ void GCodeQueue::advance() { card.closefile(); SERIAL_ECHOLNPGM(STR_FILE_SAVED); - #if !defined(__AVR__) || !defined(USBCON) + #if !IS_AT90USB #if ENABLED(SERIAL_STATS_DROPPED_RX) SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped()); #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 255470bca6e7..bab05e5ff60d 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -208,7 +208,10 @@ #define NEEDS_HARDWARE_PWM 1 #endif -#if !defined(__AVR__) || !defined(USBCON) +#if defined(__AVR__) && defined(USBCON) + #define IS_AT90USB 1 + #undef SERIAL_XON_XOFF // Not supported on USB-native devices +#else // Define constants and variables for buffering serial data. // Use only 0 or powers of 2 greater than 1 // : [0, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...] @@ -220,9 +223,6 @@ #ifndef TX_BUFFER_SIZE #define TX_BUFFER_SIZE 32 #endif -#else - // SERIAL_XON_XOFF not supported on USB-native devices - #undef SERIAL_XON_XOFF #endif #if ENABLED(HOST_ACTION_COMMANDS) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 6e97a349f673..25188906c7eb 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -582,7 +582,7 @@ /** * Serial */ -#if !(defined(__AVR__) && defined(USBCON)) +#if !IS_AT90USB #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024 #error "SERIAL_XON_XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops." #elif RX_BUFFER_SIZE && (RX_BUFFER_SIZE < 2 || !IS_POWER_OF_2(RX_BUFFER_SIZE)) @@ -2104,9 +2104,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #endif /** - * emergency-command parser + * Emergency Command Parser */ -#if ENABLED(EMERGENCY_PARSER) && defined(__AVR__) && defined(USBCON) +#if BOTH(IS_AT90USB, EMERGENCY_PARSER) #error "EMERGENCY_PARSER does not work on boards with AT90USB processors (USBCON)." #endif diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h index 4809cc8d86b8..d4f9fc76415d 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h @@ -67,7 +67,7 @@ #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" #endif -#ifndef USBCON +#if !defined(__MARLIN_DEPS__) && !defined(USBCON) #error "USBCON should be defined by the platform for this board." #endif diff --git a/platformio.ini b/platformio.ini index 9d3fafd69e38..d2c7cfafbe48 100644 --- a/platformio.ini +++ b/platformio.ini @@ -557,6 +557,7 @@ build_unflags = -g -ggdb platform = teensy extends = common_avr8 board = at90usb1286 +lib_ignore = ${env:common_avr8.lib_ignore} Teensy_ADC # # AT90USB1286 boards using DFU bootloader From c762b7c91b03415d37bbb96c5b2b6b8308ee3ba8 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:06:57 -0700 Subject: [PATCH 10/46] Fix various errors, warnings in example config builds (#19686) Co-authored-by: Scott Lahteine --- Marlin/src/gcode/bedlevel/G26.cpp | 8 +- Marlin/src/gcode/motion/M290.cpp | 2 +- Marlin/src/lcd/dogm/dogm_Statusscreen.h | 2 +- .../lcd/extui/lib/mks_ui/draw_printing.cpp | 18 +- .../lib/mks_ui/tft_lvgl_configuration.cpp | 40 ++-- .../src/lcd/extui/lib/mks_ui/wifi_upload.cpp | 182 ++++++++---------- Marlin/src/lcd/menu/menu_delta_calibrate.cpp | 2 +- Marlin/src/lcd/menu/menu_ubl.cpp | 3 +- Marlin/src/module/thermistor/thermistor_666.h | 3 +- Marlin/src/pins/sensitive_pins.h | 29 ++- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h | 1 + 11 files changed, 133 insertions(+), 157 deletions(-) diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index c66d4a7d4974..661128b04ebe 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -511,11 +511,9 @@ void GcodeSuite::G26() { g26_keep_heaters_on = parser.boolval('K'); // Accept 'I' if temperature presets are defined - const uint8_t preset_index = (0 - #if PREHEAT_COUNT - + (parser.seenval('I') ? _MIN(parser.value_byte(), PREHEAT_COUNT - 1) + 1 : 0) - #endif - ); + #if PREHEAT_COUNT + const uint8_t preset_index = parser.seenval('I') ? _MIN(parser.value_byte(), PREHEAT_COUNT - 1) + 1 : 0; + #endif #if HAS_HEATED_BED diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index 7158525ed9d9..18cc161fce29 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -127,7 +127,7 @@ void GcodeSuite::M290() { #else PSTR("Babystep Z") #endif - , babystep.axis_total[BS_AXIS_IND(Z_AXIS)] + , babystep.axis_total[BS_TOTAL_IND(Z_AXIS)] ); } #endif diff --git a/Marlin/src/lcd/dogm/dogm_Statusscreen.h b/Marlin/src/lcd/dogm/dogm_Statusscreen.h index 70802f905e1d..c6ad566cffaf 100644 --- a/Marlin/src/lcd/dogm/dogm_Statusscreen.h +++ b/Marlin/src/lcd/dogm/dogm_Statusscreen.h @@ -1341,7 +1341,7 @@ #undef STATUS_LOGO_WIDTH #endif - #if (HAS_MULTI_HOTEND && STATUS_LOGO_WIDTH && BED_OR_CHAMBER_OR_FAN) || (HOTENDS >= 3 && !BED_OR_CHAMBER_OR_FAN) + #if !defined(STATUS_HEATERS_X) && ((HAS_MULTI_HOTEND && STATUS_LOGO_WIDTH && BED_OR_CHAMBER_OR_FAN) || (HOTENDS >= 3 && !BED_OR_CHAMBER_OR_FAN)) #define _STATUS_HEATERS_X(H,S,N) ((LCD_PIXEL_WIDTH - (H * (S + N)) - (_EXTRA_WIDTH) + (STATUS_LOGO_WIDTH)) / 2) #if STATUS_HOTEND1_WIDTH #if HOTENDS > 2 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp index a81b5b851bb3..c6369db41383 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp @@ -46,7 +46,8 @@ extern lv_group_t * g; static lv_obj_t * scr; -static lv_obj_t *labelExt1, * labelExt2, * labelFan, * labelZpos, * labelTime; +static lv_obj_t *labelExt1, * labelFan, * labelZpos, * labelTime; +TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2;) static lv_obj_t *labelPause, * labelStop, * labelOperat; static lv_obj_t * bar1, *bar1ValueText; static lv_obj_t * buttonPause, *buttonOperat, *buttonStop; @@ -137,9 +138,6 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { } void lv_draw_printing(void) { - lv_obj_t *buttonExt1, *buttonExt2, *buttonFanstate, *buttonZpos, *buttonTime; - TERN_(HAS_HEATED_BED, lv_obj_t * buttonBedstate); - disp_state_stack._disp_index = 0; ZERO(disp_state_stack._disp_state); disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINTING_UI; @@ -162,16 +160,16 @@ void lv_draw_printing(void) { lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonExt1 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt1 = lv_img_create(scr, NULL); #if HAS_MULTI_EXTRUDER - buttonExt2 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt2 = lv_img_create(scr, NULL); #endif #if HAS_HEATED_BED - buttonBedstate = lv_img_create(scr, NULL); + lv_obj_t *buttonBedstate = lv_img_create(scr, NULL); #endif - buttonFanstate = lv_img_create(scr, NULL); - buttonTime = lv_img_create(scr, NULL); - buttonZpos = lv_img_create(scr, NULL); + lv_obj_t *buttonFanstate = lv_img_create(scr, NULL); + lv_obj_t *buttonTime = lv_img_create(scr, NULL); + lv_obj_t *buttonZpos = lv_img_create(scr, NULL); buttonPause = lv_imgbtn_create(scr, NULL); buttonStop = lv_imgbtn_create(scr, NULL); buttonOperat = lv_imgbtn_create(scr, NULL); 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 49b44799a69f..3f8110feb446 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 @@ -799,39 +799,39 @@ void lv_encoder_pin_init() { //static const int8_t encoderDirection = 1; //static int16_t enc_Direction; void lv_update_encoder() { - static uint8_t buttons; static uint32_t encoder_time1; uint32_t tmpTime, diffTime = 0; tmpTime = millis(); diffTime = getTickDiff(tmpTime, encoder_time1); if (diffTime > 50) { - #if ANY_BUTTON(EN1, EN2, ENC, BACK) + #if HAS_ENCODER_WHEEL - uint8_t newbutton = 0; + #if ANY_BUTTON(EN1, EN2, ENC, BACK) - #if BUTTON_EXISTS(EN1) - if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; - #endif - #if BUTTON_EXISTS(EN2) - if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; - #endif - #if BUTTON_EXISTS(ENC) - if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; - #endif - #if BUTTON_EXISTS(BACK) - if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; - #endif + uint8_t newbutton = 0; - #else + #if BUTTON_EXISTS(EN1) + if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; + #endif + #if BUTTON_EXISTS(EN2) + if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; + #endif + #if BUTTON_EXISTS(ENC) + if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; + #endif + #if BUTTON_EXISTS(BACK) + if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; + #endif - constexpr uint8_t newbutton = 0; + #else - #endif + constexpr uint8_t newbutton = 0; - buttons = newbutton; + #endif - #if HAS_ENCODER_WHEEL + + static uint8_t buttons = newbutton; static uint8_t lastEncoderBits; #define encrot0 0 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp index 77bcb767b72d..087a3b21105c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp @@ -110,24 +110,17 @@ const char *resultMessages[] = { // 230400b always manages to connect. static const uint32_t uploadBaudRates[] = { 460800, 230400, 115200, 74880 }; - - signed char IsReady() { return esp_upload.state == upload_idle; } - - - - void uploadPort_write(const uint8_t *buf, size_t len) { #if 0 int i; - for(i = 0; i < len; i++) { - while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); - - USART_SendData(USART1, *(buf + i)); + for (i = 0; i < len; i++) { + while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { /* nada */ } + USART_SendData(USART1, *(buf + i)); } #endif } @@ -138,28 +131,22 @@ char uploadPort_read() { return retChar; else return 0; - } int uploadPort_available() { return usartFifoAvailable(&WifiRxFifo); } - void uploadPort_begin() { esp_port_begin(1); } void uploadPort_close() { - //WIFI_COM.end(); //WIFI_COM.begin(115200, true); - esp_port_begin(0); - } - void flushInput() { while (uploadPort_available() != 0) { (void)uploadPort_read(); @@ -304,7 +291,6 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t *bodyLen = 0; - while (state != done) { uint8_t c; EspUploadResult stat; @@ -322,73 +308,73 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t } // sufficient bytes have been received for the current state, process them - switch(state) { - case begin: // expecting frame start - c = uploadPort_read(); - if (c != (uint8_t)0xC0) { - break; - } - state = header; - needBytes = 2; + switch (state) { + case begin: // expecting frame start + c = uploadPort_read(); + if (c != (uint8_t)0xC0) { + break; + } + state = header; + needBytes = 2; - break; - case end: // expecting frame end - c = uploadPort_read(); - if (c != (uint8_t)0xC0) { - return slipFrame; - } - state = done; + break; + case end: // expecting frame end + c = uploadPort_read(); + if (c != (uint8_t)0xC0) { + return slipFrame; + } + state = done; - break; + break; - case header: // reading an 8-byte header - case body: // reading the response body - { - int rslt; - // retrieve a byte with SLIP decoding - rslt = ReadByte(&c, 1); - if (rslt != 1 && rslt != 2) { - // some error occurred - stat = (rslt == 0 || rslt == -2) ? slipData : slipFrame; - return stat; - } - else if (state == header) { - //store the header byte - hdr[hdrIdx++] = c; - if (hdrIdx >= headerLength) { - // get the body length, prepare a buffer for it - *bodyLen = (uint16_t)getData(2, hdr, 2); - - // extract the value, if requested - if (valp != 0) { - *valp = getData(4, hdr, 4); + case header: // reading an 8-byte header + case body: // reading the response body + { + int rslt; + // retrieve a byte with SLIP decoding + rslt = ReadByte(&c, 1); + if (rslt != 1 && rslt != 2) { + // some error occurred + stat = (rslt == 0 || rslt == -2) ? slipData : slipFrame; + return stat; + } + else if (state == header) { + //store the header byte + hdr[hdrIdx++] = c; + if (hdrIdx >= headerLength) { + // get the body length, prepare a buffer for it + *bodyLen = (uint16_t)getData(2, hdr, 2); + + // extract the value, if requested + if (valp != 0) { + *valp = getData(4, hdr, 4); + } + + if (*bodyLen != 0) { + state = body; + } + else { + needBytes = 1; + state = end; + } } - - if (*bodyLen != 0) { - state = body; + } + else { + // Store the response body byte, check for completion + if (bodyIdx < ARRAY_SIZE(respBuf)) { + respBuf[bodyIdx] = c; } - else { + ++bodyIdx; + if (bodyIdx >= *bodyLen) { needBytes = 1; state = end; } } } - else { - // Store the response body byte, check for completion - if (bodyIdx < ARRAY_SIZE(respBuf)) { - respBuf[bodyIdx] = c; - } - ++bodyIdx; - if (bodyIdx >= *bodyLen) { - needBytes = 1; - state = end; - } - } - } - break; + break; - default: // this shouldn't happen - return slipState; + default: // this shouldn't happen + return slipState; } } @@ -397,7 +383,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t opRet = (uint8_t)getData(1, hdr, 1); // Sync packets often provoke a response with a zero opcode instead of ESP_SYNC if (resp != 0x01 || opRet != op) { -//debug//printf("resp %02x %02x\n", resp, opRet); + //printf("resp %02x %02x\n", resp, opRet); //debug return respHeader; } @@ -432,20 +418,19 @@ void _writePacket(const uint8_t *data, size_t len) { // 0xC0 and 0xDB replaced by the two-byte sequences {0xDB, 0xDC} and {0xDB, 0xDD} respectively. void writePacket(const uint8_t *hdr, size_t hdrLen, const uint8_t *data, size_t dataLen) { - - WriteByteRaw(0xC0); // send the packet start character + WriteByteRaw(0xC0); // send the packet start character _writePacket(hdr, hdrLen); // send the header - _writePacket(data, dataLen); // send the data block - WriteByteRaw(0xC0); // send the packet end character + _writePacket(data, dataLen); // send the data block + WriteByteRaw(0xC0); // send the packet end character } // Send a packet to the serial port while performing SLIP framing. The packet data comprises a header and an optional data block. // This is like writePacket except that it does a fast block write for both the header and the main data with no SLIP encoding. Used to send sync commands. void writePacketRaw(const uint8_t *hdr, size_t hdrLen, const uint8_t *data, size_t dataLen) { - WriteByteRaw(0xC0); // send the packet start character - _writePacketRaw(hdr, hdrLen); // send the header + WriteByteRaw(0xC0); // send the packet start character + _writePacketRaw(hdr, hdrLen); // send the header _writePacketRaw(data, dataLen); // send the data block in raw mode - WriteByteRaw(0xC0); // send the packet end character + WriteByteRaw(0xC0); // send the packet end character } // Send a command to the attached device together with the supplied data, if any. @@ -460,12 +445,10 @@ void sendCommand(uint8_t op, uint32_t checkVal, const uint8_t *data, size_t data // send the packet //flushInput(); - if (op == ESP_SYNC) { + if (op == ESP_SYNC) writePacketRaw(hdr, sizeof(hdr), data, dataLen); - } - else { + else writePacket(hdr, sizeof(hdr), data, dataLen); - } } // Send a command to the attached device together with the supplied data, if any, and get the response @@ -476,9 +459,8 @@ EspUploadResult doCommand(uint8_t op, const uint8_t *data, size_t dataLen, uint3 sendCommand(op, checkVal, data, dataLen); stat = readPacket(op, valp, &bodyLen, msTimeout); - if (stat == success && bodyLen != 2) { + if (stat == success && bodyLen != 2) stat = badReply; - } return stat; } @@ -611,6 +593,8 @@ EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask) { //printf("Upload %d\%\n", ftell(&esp_upload.uploadFile) * 100 / esp_upload.fileSize); return stat; + #else + return success; #endif } @@ -625,15 +609,14 @@ void upload_spin() { esp_upload.uploadResult = connected; esp_upload.state = done; } - else{ + else { // Reset the serial port at the new baud rate. Also reset the ESP8266. - // const uint32_t baud = uploadBaudRates[esp_upload.connectAttemptNumber/esp_upload.retriesPerBaudRate]; + // const uint32_t baud = uploadBaudRates[esp_upload.connectAttemptNumber/esp_upload.retriesPerBaudRate]; if (esp_upload.connectAttemptNumber % esp_upload.retriesPerBaudRate == 0) { } - // uploadPort.begin(baud); - // uploadPort_close(); - + //uploadPort.begin(baud); + //uploadPort_close(); uploadPort_begin(); @@ -654,7 +637,7 @@ void upload_spin() { esp_upload.lastAttemptTime = getWifiTick(); if (res == success) { // Successful connection -// //MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); + //MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); //printf("connect success\n"); esp_upload.state = erasing; } @@ -675,14 +658,13 @@ void upload_spin() { const uint32_t sectorSize = 4096; const uint32_t numSectors = (esp_upload.fileSize + sectorSize - 1)/sectorSize; const uint32_t startSector = esp_upload.uploadAddress/sectorSize; + uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); + NOMORE(headSectors, numSectors); - if (numSectors < headSectors) { - headSectors = numSectors; - } - eraseSize = (numSectors < 2 * headSectors) - ? (numSectors + 1) / 2 * sectorSize - : (numSectors - headSectors) * sectorSize; + eraseSize = (numSectors < 2 * headSectors) + ? (numSectors + 1) / 2 * sectorSize + : (numSectors - headSectors) * sectorSize; //MessageF("Erasing %u bytes...\n", fileSize); esp_upload.uploadResult = flashBegin(esp_upload.uploadAddress, eraseSize); @@ -755,7 +737,7 @@ void SendUpdateFile(const char *file, uint32_t address) { if (res != FR_OK) return; - esp_upload.fileSize = f_size(&esp_upload.uploadFile); + esp_upload.fileSize = f_size(&esp_upload.uploadFile); if (esp_upload.fileSize == 0) { f_close(&esp_upload.uploadFile); return; diff --git a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp index 705ec4161120..4efcb7c8eded 100644 --- a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp +++ b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp @@ -118,7 +118,7 @@ void lcd_delta_settings() { } void menu_delta_calibrate() { - const bool all_homed = all_axes_homed(); + TERN_(DELTA_CALIBRATION_MENU, const bool all_homed = all_axes_homed()); // Acquire ahead of loop START_MENU(); BACK_ITEM(MSG_MAIN); diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 2cd300958f8b..f0f5c21beca2 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -188,11 +188,10 @@ void _lcd_ubl_edit_mesh() { */ void _lcd_ubl_validate_custom_mesh() { char ubl_lcd_gcode[24]; - const int16_t temp = TERN(HAS_HEATED_BED, custom_bed_temp, 0); sprintf_P(ubl_lcd_gcode, PSTR("G28\nG26 C P H%" PRIi16 TERN_(HAS_HEATED_BED, " B%" PRIi16)) , custom_hotend_temp #if HAS_HEATED_BED - , temp + , custom_bed_temp #endif ); queue.inject(ubl_lcd_gcode); diff --git a/Marlin/src/module/thermistor/thermistor_666.h b/Marlin/src/module/thermistor/thermistor_666.h index 86493988e053..490dbd5f3ee9 100644 --- a/Marlin/src/module/thermistor/thermistor_666.h +++ b/Marlin/src/module/thermistor/thermistor_666.h @@ -33,8 +33,7 @@ * B: 0.00031362 * C: -2.03978e-07 */ -#define NUMTEMPS 61 -const short temptable_666[NUMTEMPS][2] PROGMEM = { +const temp_entry_t temptable_666[] PROGMEM = { { OV( 1), 794 }, { OV( 18), 288 }, { OV( 35), 234 }, diff --git a/Marlin/src/pins/sensitive_pins.h b/Marlin/src/pins/sensitive_pins.h index 169f74b43787..d7eb1872458f 100644 --- a/Marlin/src/pins/sensitive_pins.h +++ b/Marlin/src/pins/sensitive_pins.h @@ -608,12 +608,6 @@ #define _Z_PROBE #endif -#if TEMP_SENSOR_BED && PIN_EXISTS(HEATER_BED) - #define _HEATER_BED HEATER_BED_PIN, -#else - #define _HEATER_BED -#endif - #if PIN_EXISTS(FAN) #define _FAN0 FAN_PIN, #else @@ -660,21 +654,26 @@ #define _FANC #endif -#if PIN_EXISTS(HEATER_BED) && PIN_EXISTS(TEMP_BED) +#if TEMP_SENSOR_BED && PINS_EXIST(TEMP_BED, HEATER_BED) #define _BED_PINS HEATER_BED_PIN, analogInputToDigitalPin(TEMP_BED_PIN), #else #define _BED_PINS #endif -#if PIN_EXISTS(TEMP_CHAMBER) - #define __CHAMBER_PINS CHAMBER_AUTO_FAN_PIN, analogInputToDigitalPin(TEMP_CHAMBER_PIN), +#if TEMP_SENSOR_CHAMBER && PIN_EXISTS(TEMP_CHAMBER) + #define _CHAMBER_TEMP analogInputToDigitalPin(TEMP_CHAMBER_PIN), +#else + #define _CHAMBER_TEMP +#endif +#if TEMP_SENSOR_CHAMBER && PINS_EXIST(TEMP_CHAMBER, HEATER_CHAMBER) + #define _CHAMBER_HEATER HEATER_CHAMBER_PIN, #else - #define __CHAMBER_PINS + #define _CHAMBER_HEATER #endif -#if PIN_EXISTS(HEATER_CHAMBER) - #define _CHAMBER_PINS __CHAMBER_PINS HEATER_CHAMBER_PIN, +#if TEMP_SENSOR_CHAMBER && PINS_EXIST(TEMP_CHAMBER, CHAMBER_AUTO_FAN) + #define _CHAMBER_FAN CHAMBER_AUTO_FAN_PIN, #else - #define _CHAMBER_PINS + #define _CHAMBER_FAN #endif #ifndef HAL_SENSITIVE_PINS @@ -685,6 +684,6 @@ _X_PINS _Y_PINS _Z_PINS _X2_PINS _Y2_PINS _Z2_PINS _Z3_PINS _Z4_PINS _Z_PROBE \ _E0_PINS _E1_PINS _E2_PINS _E3_PINS _E4_PINS _E5_PINS _E6_PINS _E7_PINS \ _H0_PINS _H1_PINS _H2_PINS _H3_PINS _H4_PINS _H5_PINS _H6_PINS _H7_PINS \ - _PS_ON _HEATER_BED _FAN0 _FAN1 _FAN2 _FAN3 _FAN4 _FAN5 _FAN6 _FAN7 _FANC \ - _BED_PINS _CHAMBER_PINS HAL_SENSITIVE_PINS \ + _PS_ON _FAN0 _FAN1 _FAN2 _FAN3 _FAN4 _FAN5 _FAN6 _FAN7 _FANC \ + _BED_PINS _CHAMBER_TEMP _CHAMBER_HEATER _CHAMBER_FAN HAL_SENSITIVE_PINS \ } diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 12c40b31b374..32203f52ea8d 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -200,6 +200,7 @@ #elif SD_CONNECTION_IS(ONBOARD) #define SDIO_SUPPORT #define SD_DETECT_PIN PD12 + #define ONBOARD_SD_CS_PIN PC11 #elif SD_CONNECTION_IS(CUSTOM_CABLE) #error "No custom SD drive cable defined for this board." #endif From bdd555990bc94f3c3243cdc02f59d0f67ac1e9f2 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Mon, 12 Oct 2020 00:15:08 +0000 Subject: [PATCH 11/46] [cron] Bump distribution date (2020-10-12) --- Marlin/src/inc/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 2b97b173a239..74f713091d2a 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-10-11" + #define STRING_DISTRIBUTION_DATE "2020-10-12" #endif /** From 24fd19259d082718673d762aa3d6d9cc9a6d5c0a Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:23:23 -0700 Subject: [PATCH 12/46] Fix I2C_ADDRESS sign warning (#19685) --- Marlin/src/HAL/HAL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index 8b6a978d2103..5eca2f7eacfe 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -34,7 +34,7 @@ #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #ifndef I2C_ADDRESS - #define I2C_ADDRESS(A) (A) + #define I2C_ADDRESS(A) uint8_t(A) #endif // Needed for AVR sprintf_P PROGMEM extension From 18dd0d00a64581264828fad13dcc9b65201bab14 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 11 Oct 2020 21:26:16 -0300 Subject: [PATCH 13/46] Implement wait_for_user for Color UI (#19694) --- Marlin/src/gcode/config/M43.cpp | 9 ++++++++- Marlin/src/lcd/tft/touch.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/config/M43.cpp b/Marlin/src/gcode/config/M43.cpp index 1e7374542c3d..1e780ca05afd 100644 --- a/Marlin/src/gcode/config/M43.cpp +++ b/Marlin/src/gcode/config/M43.cpp @@ -46,6 +46,10 @@ #include "../../lcd/extui/ui_api.h" #endif +#if HAS_RESUME_CONTINUE + #include "../../lcd/ultralcd.h" +#endif + #ifndef GET_PIN_MAP_PIN_M43 #define GET_PIN_MAP_PIN_M43(Q) GET_PIN_MAP_PIN(Q) #endif @@ -362,7 +366,10 @@ void GcodeSuite::M43() { } } - if (TERN0(HAS_RESUME_CONTINUE, !wait_for_user)) break; + #if HAS_RESUME_CONTINUE + ui.update(); + if (!wait_for_user) break; + #endif safe_delay(200); } diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index d19cc4bf1d95..80c65f074ae6 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -50,6 +50,9 @@ touch_calibration_t Touch::calibration; calibrationState Touch::calibration_state = CALIBRATION_NONE; touch_calibration_point_t Touch::calibration_points[4]; #endif +#if HAS_RESUME_CONTINUE + extern bool wait_for_user; +#endif void Touch::init() { calibration_reset(); @@ -80,6 +83,15 @@ void Touch::idle() { now = millis(); if (get_point(&_x, &_y)) { + #if HAS_RESUME_CONTINUE + // UI is waiting for a click anywhere? + if (wait_for_user) { + touch_control_type = CLICK; + ui.lcd_clicked = true; + return; + } + #endif + #if LCD_TIMEOUT_TO_STATUS ui.return_to_status_ms = now + LCD_TIMEOUT_TO_STATUS; #endif From 639b0b8f50b4665b45b4a601e14d93ebe6c6e1b2 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 11 Oct 2020 21:31:21 -0300 Subject: [PATCH 14/46] Option to prevent (extra) Watchdog init on STM32 (#19693) --- Marlin/src/HAL/STM32/watchdog.cpp | 6 +++++- Marlin/src/HAL/STM32F1/watchdog.cpp | 4 +++- Marlin/src/pins/stm32f1/pins_MALYAN_M200.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/STM32/watchdog.cpp b/Marlin/src/HAL/STM32/watchdog.cpp index 37e5638b05c0..cc1855314968 100644 --- a/Marlin/src/HAL/STM32/watchdog.cpp +++ b/Marlin/src/HAL/STM32/watchdog.cpp @@ -30,7 +30,11 @@ #include "watchdog.h" #include - void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout + void watchdog_init() { + #if DISABLED(DISABLE_WATCHDOG_INIT) + IWatchdog.begin(4000000); // 4 sec timeout + #endif + } void HAL_watchdog_refresh() { IWatchdog.reload(); diff --git a/Marlin/src/HAL/STM32F1/watchdog.cpp b/Marlin/src/HAL/STM32F1/watchdog.cpp index 4123bc3ef0ff..ca91a6fe4350 100644 --- a/Marlin/src/HAL/STM32F1/watchdog.cpp +++ b/Marlin/src/HAL/STM32F1/watchdog.cpp @@ -52,7 +52,9 @@ void watchdogSetup() { * @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0) */ void watchdog_init() { - //iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); + #if DISABLED(DISABLE_WATCHDOG_INIT) + iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); + #endif } #endif // USE_WATCHDOG diff --git a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h index d3c26c497d8f..95e7e92174fa 100644 --- a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h +++ b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h @@ -33,6 +33,9 @@ #define BOARD_INFO_NAME "Malyan M200" #endif +// Prevents hanging from an extra watchdog init +#define DISABLE_WATCHDOG_INIT + // Assume Flash EEPROM #if NO_EEPROM_SELECTED #define FLASH_EEPROM_EMULATION From edda32e6b4b7ca004eb49f76fe2f7bd72b0293aa Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:42:50 -0700 Subject: [PATCH 15/46] Fix motion compile w/out probe-oriented settings (#19684) --- Marlin/src/module/motion.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index b904309018d6..da1cb173e56c 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -510,7 +510,7 @@ void do_z_clearance(const float &zclear, const bool z_known/*=true*/, const bool const bool rel = raise_on_unknown && !z_known; float zdest = zclear + (rel ? current_position.z : 0.0f); if (!lower_allowed) NOLESS(zdest, current_position.z); - do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(Z_PROBE_SPEED_FAST)); + do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(TERN(HAS_BED_PROBE, Z_PROBE_SPEED_FAST, HOMING_FEEDRATE_Z))); } // @@ -1126,8 +1126,9 @@ bool homing_needed_error(uint8_t axis_bits/*=0x07*/) { * Homing bump feedrate (mm/s) */ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { - if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) - return MMM_TO_MMS(Z_PROBE_SPEED_SLOW); + #if HOMING_Z_WITH_PROBE + if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_SPEED_SLOW); + #endif static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR; uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]); if (hbd < 1) { @@ -1588,7 +1589,7 @@ void homeaxis(const AxisEnum axis) { // When homing Z with probe respect probe clearance const bool use_probe_bump = TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && home_bump_mm(Z_AXIS)); const float bump = axis_home_dir * ( - use_probe_bump ? _MAX(Z_CLEARANCE_BETWEEN_PROBES, home_bump_mm(Z_AXIS)) : home_bump_mm(axis) + use_probe_bump ? _MAX(TERN0(HOMING_Z_WITH_PROBE, Z_CLEARANCE_BETWEEN_PROBES), home_bump_mm(Z_AXIS)) : home_bump_mm(axis) ); // If a second homing move is configured... From f21b91f1a722e25c820dee2479f608acfc6a98dc Mon Sep 17 00:00:00 2001 From: qwewer0 <57561110+qwewer0@users.noreply.github.com> Date: Mon, 12 Oct 2020 04:30:18 +0200 Subject: [PATCH 16/46] Add REPORT_TRAMMING_MM option (#19682) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 8 +++----- Marlin/src/gcode/bedlevel/G35.cpp | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 59a1813610ff..0d14f67cb28b 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -806,11 +806,9 @@ #define TRAMMING_POINT_NAME_3 "Back-Right" #define TRAMMING_POINT_NAME_4 "Back-Left" - // Enable to restore leveling setup after operation - #define RESTORE_LEVELING_AFTER_G35 - - // Add a menu item for Assisted Tramming - //#define ASSISTED_TRAMMING_MENU_ITEM + #define RESTORE_LEVELING_AFTER_G35 // Enable to restore leveling setup after operation + //#define REPORT_TRAMMING_MM // Report Z deviation (mm) for each point relative to the first + //#define ASSISTED_TRAMMING_MENU_ITEM // Add a menu item for Assisted Tramming /** * Screw thread: diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index bd7f4f0411e1..0ede4e79c680 100755 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -160,6 +160,7 @@ void GcodeSuite::G35() { " ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", " by ", abs(full_turns), " turns"); if (minutes) SERIAL_ECHOPAIR(" and ", abs(minutes), " minutes"); + if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPAIR(" (", -diff, "mm)"); SERIAL_EOL(); } } From e7838c5f7904924eed7e996d2ff95fff0f64e30e Mon Sep 17 00:00:00 2001 From: InsanityAutomation <38436470+InsanityAutomation@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:34:27 -0400 Subject: [PATCH 17/46] G34 Mechanical Gantry Calibration (like Prusa M915) (#18972) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 19 +++ Marlin/src/gcode/calibrate/G34.cpp | 153 ++++++++++++++++++++++++ Marlin/src/gcode/calibrate/G34_M422.cpp | 98 ++++++++++----- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/gcode.h | 5 +- Marlin/src/inc/SanityCheck.h | 17 ++- Marlin/src/lcd/language/language_en.h | 3 + Marlin/src/lcd/menu/menu_motion.cpp | 2 +- buildroot/tests/LPC1769-tests | 2 +- platformio.ini | 2 + 10 files changed, 269 insertions(+), 34 deletions(-) create mode 100644 Marlin/src/gcode/calibrate/G34.cpp diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 0d14f67cb28b..db54716cde54 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3376,6 +3376,25 @@ //#define JOYSTICK_DEBUG #endif +/** + * Mechanical Gantry Calibration + * Modern replacement for the Prusa TMC_Z_CALIBRATION. + * Adds capability to work with any adjustable current drivers. + * Implemented as G34 because M915 is deprecated. + */ +//#define MECHANICAL_GANTRY_CALIBRATION +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + #define GANTRY_CALIBRATION_CURRENT 600 // Default calibration current in ma + #define GANTRY_CALIBRATION_EXTRA_HEIGHT 15 // Extra distance in mm past Z_###_POS to move + #define GANTRY_CALIBRATION_FEEDRATE 500 // Feedrate for correction move + //#define GANTRY_CALIBRATION_TO_MIN // Enable to calibrate Z in the MIN direction + + //#define GANTRY_CALIBRATION_SAFE_POSITION { X_CENTER, Y_CENTER } // Safe position for nozzle + //#define GANTRY_CALIBRATION_XY_PARK_FEEDRATE 3000 // XY Park Feedrate - MMM + //#define GANTRY_CALIBRATION_COMMANDS_PRE "" + #define GANTRY_CALIBRATION_COMMANDS_POST "G28" // G28 highly recommended to ensure an accurate position +#endif + /** * MAX7219 Debug Matrix * diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp new file mode 100644 index 000000000000..eb1d32f90927 --- /dev/null +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -0,0 +1,153 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + +#include "../gcode.h" +#include "../../module/motion.h" +#include "../../module/stepper.h" +#include "../../module/endstops.h" + +#if HAS_LEVELING + #include "../../feature/bedlevel/bedlevel.h" +#endif + +#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) +#include "../../core/debug_out.h" + +void GcodeSuite::G34() { + + if (homing_needed()) return; + + TEMPORARY_SOFT_ENDSTOP_STATE(false); + TEMPORARY_BED_LEVELING_STATE(false); + TemporaryGlobalEndstopsState unlock_z(false); + + #ifdef GANTRY_CALIBRATION_COMMANDS_PRE + gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_PRE)); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Sub Commands Processed"); + #endif + + #ifdef GANTRY_CALIBRATION_SAFE_POSITION + // Move XY to safe position + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Parking XY"); + const xy_pos_t safe_pos = GANTRY_CALIBRATION_SAFE_POSITION; + do_blocking_move_to(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE)); + #endif + + const float move_distance = parser.intval('Z', GANTRY_CALIBRATION_EXTRA_HEIGHT), + zbase = ENABLED(GANTRY_CALIBRATION_TO_MIN) ? Z_MIN_POS : Z_MAX_POS, + zpounce = zbase - move_distance, zgrind = zbase + move_distance; + + // Move Z to pounce position + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce"); + do_blocking_move_to_z(zpounce, MMM_TO_MMS(HOMING_FEEDRATE_Z)); + + // Store current motor settings, then apply reduced value + + #define _REDUCE_CURRENT ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_I2C, HAS_TRINAMIC_CONFIG) + #if _REDUCE_CURRENT + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Reducing Current"); + #endif + + #if HAS_MOTOR_CURRENT_SPI + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; + stepper.set_digipot_current(Z_AXIS, target_current); + #elif HAS_MOTOR_CURRENT_PWM + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; + stepper.set_digipot_current(1, target_current); + #elif HAS_MOTOR_CURRENT_DAC + const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT); + const float previous_current = dac_amps(Z_AXIS, target_current); + stepper_dac.set_current_value(Z_AXIS, target_current); + #elif ENABLED(HAS_MOTOR_CURRENT_I2C) + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + previous_current = dac_amps(Z_AXIS); + digipot_i2c.set_current(Z_AXIS, target_current) + #elif HAS_TRINAMIC_CONFIG + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + static uint16_t previous_current_arr[NUM_Z_STEPPER_DRIVERS]; + #if AXIS_IS_TMC(Z) + previous_current_arr[0] = stepperZ.getMilliamps(); + stepperZ.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z2) + previous_current_arr[1] = stepperZ2.getMilliamps(); + stepperZ2.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z3) + previous_current_arr[2] = stepperZ3.getMilliamps(); + stepperZ3.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z4) + previous_current_arr[3] = stepperZ4.getMilliamps(); + stepperZ4.rms_current(target_current); + #endif + #endif + + // Do Final Z move to adjust + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Final Z Move"); + do_blocking_move_to_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + + // Back off end plate, back to normal motion range + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Backoff"); + do_blocking_move_to_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + + #if _REDUCE_CURRENT + // Reset current to original values + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore Current"); + #endif + + #if HAS_MOTOR_CURRENT_SPI + stepper.set_digipot_current(Z_AXIS, previous_current); + #elif HAS_MOTOR_CURRENT_PWM + stepper.set_digipot_current(1, previous_current); + #elif HAS_MOTOR_CURRENT_DAC + stepper_dac.set_current_value(Z_AXIS, previous_current); + #elif ENABLED(HAS_MOTOR_CURRENT_I2C) + digipot_i2c.set_current(Z_AXIS, previous_current) + #elif HAS_TRINAMIC_CONFIG + #if AXIS_IS_TMC(Z) + stepperZ.rms_current(previous_current_arr[0]); + #endif + #if AXIS_IS_TMC(Z2) + stepperZ2.rms_current(previous_current_arr[1]); + #endif + #if AXIS_IS_TMC(Z3) + stepperZ3.rms_current(previous_current_arr[2]); + #endif + #if AXIS_IS_TMC(Z4) + stepperZ4.rms_current(previous_current_arr[3]); + #endif + #endif + + #ifdef GANTRY_CALIBRATION_COMMANDS_POST + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); + gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST)); + #endif +} + +#endif // MECHANICAL_GANTRY_CALIBRATION diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 1fd0754ec780..24292477f9c1 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -20,28 +20,29 @@ * */ -#include "../../inc/MarlinConfig.h" +#include "../../inc/MarlinConfigPre.h" #if ENABLED(Z_STEPPER_AUTO_ALIGN) #include "../../feature/z_stepper_align.h" #include "../gcode.h" -#include "../../module/planner.h" -#include "../../module/stepper.h" #include "../../module/motion.h" +#include "../../module/stepper.h" +#include "../../module/planner.h" #include "../../module/probe.h" - -#if HAS_MULTI_HOTEND - #include "../../module/tool_change.h" -#endif +#include "../../lcd/ultralcd.h" // for LCD_MESSAGEPGM #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif +#if HAS_MULTI_HOTEND + #include "../../module/tool_change.h" +#endif + #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) - #include "../../libs/least_squares_fit.h" + #include "../../libs/least_squares_fit.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) @@ -117,7 +118,7 @@ void GcodeSuite::G34() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G34 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - #define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE) + #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE)) // Compute a worst-case clearance height to probe from. After the first // iteration this will be re-calculated based on the actual bed position @@ -154,21 +155,29 @@ void GcodeSuite::G34() { z_maxdiff = 0.0f, amplification = z_auto_align_amplification; - // These are needed after the for-loop - uint8_t iteration; - bool err_break = false; - float z_measured_min; - #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) bool adjustment_reverse = false; #endif - // 'iteration' is declared above and is also used after the for-loop. - // *not* the same as LOOP_L_N(iteration, z_auto_align_iterations) - for (iteration = 0; iteration < z_auto_align_iterations; ++iteration) { + #if HAS_DISPLAY + PGM_P const msg_iteration = GET_TEXT(MSG_ITERATION); + const uint8_t iter_str_len = strlen_P(msg_iteration); + #endif + + // Final z and iteration values will be used after breaking the loop + float z_measured_min; + uint8_t iteration = 0; + bool err_break = false; // To break out of nested loops + while (iteration < z_auto_align_iterations) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> probing all positions."); - SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1)); + const int iter = iteration + 1; + SERIAL_ECHOLNPAIR("\nG34 Iteration: ", iter); + #if HAS_DISPLAY + char str[iter_str_len + 2 + 1]; + sprintf_P(str, msg_iteration, iter); + ui.set_status(str); + #endif // Initialize minimum value z_measured_min = 100000.0f; @@ -190,7 +199,8 @@ void GcodeSuite::G34() { // current_position.z has been manually altered in the "dirty trick" above. const float z_probed_height = probe.probe_at_point(z_stepper_align.xy[iprobe], raise_after, 0, true, false); if (isnan(z_probed_height)) { - SERIAL_ECHOLNPGM("Probing failed."); + SERIAL_ECHOLNPGM("Probing failed"); + LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED); err_break = true; break; } @@ -249,8 +259,39 @@ void GcodeSuite::G34() { , " Z3-Z1=", ABS(z_measured[2] - z_measured[0]) #endif ); + #if HAS_DISPLAY + char fstr1[10]; + #if NUM_Z_STEPPER_DRIVERS == 2 + char msg[6 + (6 + 5) * 1 + 1]; + #else + char msg[6 + (6 + 5) * 3 + 1], fstr2[10], fstr3[10]; + #endif + sprintf_P(msg, + PSTR("Diffs Z1-Z2=%s" + #if NUM_Z_STEPPER_DRIVERS == 3 + " Z2-Z3=%s" + " Z3-Z1=%s" + #endif + ), dtostrf(ABS(z_measured[0] - z_measured[1]), 1, 3, fstr1) + #if NUM_Z_STEPPER_DRIVERS == 3 + , dtostrf(ABS(z_measured[1] - z_measured[2]), 1, 3, fstr2) + , dtostrf(ABS(z_measured[2] - z_measured[0]), 1, 3, fstr3) + #endif + ); + ui.set_status(msg); + #endif + + auto decreasing_accuracy = [](const float &v1, const float &v2){ + if (v1 < v2 * 0.7f) { + SERIAL_ECHOLNPGM("Decreasing Accuracy Detected."); + LCD_MESSAGEPGM(MSG_DECREASING_ACCURACY); + return true; + } + return false; + }; #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) + // Check if the applied corrections go in the correct direction. // Calculate the sum of the absolute deviations from the mean of the probe measurements. // Compare to the last iteration to ensure it's getting better. @@ -266,11 +307,8 @@ void GcodeSuite::G34() { z_align_level_indicator += ABS(z_measured[zstepper] - z_measured_mean); // If it's getting worse, stop and throw an error - if (last_z_align_level_indicator < z_align_level_indicator * 0.7f) { - SERIAL_ECHOLNPGM("Decreasing accuracy detected."); - err_break = true; - break; - } + err_break = decreasing_accuracy(last_z_align_level_indicator, z_align_level_indicator); + if (err_break) break; last_z_align_level_indicator = z_align_level_indicator; #endif @@ -290,8 +328,7 @@ void GcodeSuite::G34() { if (z_align_abs) amplification = (iteration == 1) ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification; // Check for less accuracy compared to last move - if (last_z_align_move[zstepper] < z_align_abs * 0.7f) { - SERIAL_ECHOLNPGM("Decreasing accuracy detected."); + if (decreasing_accuracy(last_z_align_move[zstepper], z_align_abs)) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("> Z", int(zstepper + 1), " last_z_align_move = ", last_z_align_move[zstepper]); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("> Z", int(zstepper + 1), " z_align_abs = ", z_align_abs); adjustment_reverse = !adjustment_reverse; @@ -329,9 +366,14 @@ void GcodeSuite::G34() { if (err_break) break; - if (success_break) { SERIAL_ECHOLNPGM("Target accuracy achieved."); break; } + if (success_break) { + SERIAL_ECHOLNPGM("Target accuracy achieved."); + LCD_MESSAGEPGM(MSG_ACCURACY_ACHIEVED); + break; + } - } // for (iteration) + iteration++; + } // while (iteration < z_auto_align_iterations) if (err_break) SERIAL_ECHOLNPGM("G34 aborted."); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 1d4e8f9d4d07..f2bd81e670dc 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -327,7 +327,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 33: G33(); break; // G33: Delta Auto-Calibration #endif - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) case 34: G34(); break; // G34: Z Stepper automatic alignment using probe #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 683642bec60f..3d745eff8939 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -465,11 +465,12 @@ class GcodeSuite { TERN_(DELTA_AUTO_CALIBRATION, static void G33()); - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) static void G34(); - static void M422(); #endif + TERN_(Z_STEPPER_AUTO_ALIGN, static void M422()); + TERN_(ASSISTED_TRAMMING, static void G35()); TERN_(G38_PROBE_TARGET, static void G38(const int8_t subcode)); diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 25188906c7eb..c3708c267654 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -422,7 +422,7 @@ #elif defined(CHAMBER_HEATER_PIN) #error "CHAMBER_HEATER_PIN is now HEATER_CHAMBER_PIN. Please update your configuration and/or pins." #elif defined(TMC_Z_CALIBRATION) - #error "TMC_Z_CALIBRATION has been deprecated in favor of Z_STEPPER_AUTO_ALIGN. Please update your configuration." + #error "TMC_Z_CALIBRATION has been deprecated in favor of MECHANICAL_GANTRY_CALIBRATION. Please update your configuration." #elif defined(Z_MIN_PROBE_ENDSTOP) #error "Z_MIN_PROBE_ENDSTOP is no longer required. Please remove it from Configuration.h." #elif defined(DUAL_NOZZLE_DUPLICATION_MODE) @@ -2788,6 +2788,21 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #endif #endif +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + #if NONE(HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC, HAS_TRINAMIC_CONFIG, HAS_MOTOR_CURRENT_PWM) + #error "It is highly recommended to have adjustable current drivers to prevent damage. Disable this line to continue anyway." + #elif !defined(GANTRY_CALIBRATION_CURRENT) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_CURRENT to be set." + #elif !defined(GANTRY_CALIBRATION_EXTRA_HEIGHT) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_EXTRA_HEIGHT to be set." + #elif !defined(GANTRY_CALIBRATION_FEEDRATE) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_FEEDRATE to be set." + #endif + #if defined(GANTRY_CALIBRATION_SAFE_POSITION) && !defined(GANTRY_CALIBRATION_XY_PARK_FEEDRATE) + #error "GANTRY_CALIBRATION_SAFE_POSITION Requires GANTRY_CALIBRATION_XY_PARK_FEEDRATE to be set." + #endif +#endif + #if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS) #error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration." #endif diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index b41515a73428..e8b4769cc216 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -67,6 +67,9 @@ namespace Language_en { PROGMEM Language_Str MSG_AUTO_HOME_Z = _UxGT("Home Z"); PROGMEM Language_Str MSG_AUTO_Z_ALIGN = _UxGT("Auto Z-Align"); PROGMEM Language_Str MSG_ASSISTED_TRAMMING = _UxGT("Assisted Tramming"); + PROGMEM Language_Str MSG_ITERATION = _UxGT("G34 Iteration: %i"); + PROGMEM Language_Str MSG_DECREASING_ACCURACY = _UxGT("Accuracy Decreasing!"); + PROGMEM Language_Str MSG_ACCURACY_ACHIEVED = _UxGT("Accuracy Achieved"); PROGMEM Language_Str MSG_LEVEL_BED_HOMING = _UxGT("Homing XYZ"); PROGMEM Language_Str MSG_LEVEL_BED_WAITING = _UxGT("Click to Begin"); PROGMEM Language_Str MSG_LEVEL_BED_NEXT_POINT = _UxGT("Next Point"); diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index dff9895c6b64..676ba46ea730 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -358,7 +358,7 @@ void menu_motion() { // // Auto Z-Align // - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) GCODES_ITEM(MSG_AUTO_Z_ALIGN, PSTR("G34")); #endif diff --git a/buildroot/tests/LPC1769-tests b/buildroot/tests/LPC1769-tests index a7a6456d026d..4314b0d5ff8d 100755 --- a/buildroot/tests/LPC1769-tests +++ b/buildroot/tests/LPC1769-tests @@ -61,7 +61,7 @@ opt_set MOTHERBOARD BOARD_COHESION3D_REMIX opt_set X_DRIVER_TYPE TMC2130 opt_set Y_DRIVER_TYPE TMC2130 opt_set Z_DRIVER_TYPE TMC2130 -opt_enable AUTO_BED_LEVELING_BILINEAR EEPROM_SETTINGS EEPROM_CHITCHAT \ +opt_enable AUTO_BED_LEVELING_BILINEAR EEPROM_SETTINGS EEPROM_CHITCHAT MECHANICAL_GANTRY_CALIBRATION \ TMC_USE_SW_SPI MONITOR_DRIVER_STATUS STEALTHCHOP_XY STEALTHCHOP_Z HYBRID_THRESHOLD \ SENSORLESS_PROBING Z_SAFE_HOMING X_STALL_SENSITIVITY Y_STALL_SENSITIVITY Z_STALL_SENSITIVITY TMC_DEBUG \ EXPERIMENTAL_I2CBUS diff --git a/platformio.ini b/platformio.ini index d2c7cfafbe48..4c974e5a87bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -110,6 +110,7 @@ default_src_filter = + - - + - - - + - - - - @@ -309,6 +310,7 @@ MK2_MULTIPLEXER = src_filter=+ EXT_SOLENOID|MANUAL_SOLENOID_CONTROL = src_filter=+ + HAS_CUTTER = src_filter=+ + EXPERIMENTAL_I2CBUS = src_filter=+ + +MECHANICAL_GANTRY_CAL.+ = src_filter=+ Z_STEPPER_AUTO_ALIGN = src_filter=+ + G26_MESH_VALIDATION = src_filter=+ ASSISTED_TRAMMING = src_filter=+ From a866a758cc0ac671363fdce462dd967e488aa4e4 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 22:40:39 -0700 Subject: [PATCH 18/46] Allow MAX31865 resistance values configuration (#19695) --- Marlin/Configuration.h | 6 ++++++ Marlin/src/inc/SanityCheck.h | 4 ++++ Marlin/src/module/temperature.cpp | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ec8b162cd643..59f2be18c666 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -432,6 +432,12 @@ #define DUMMY_THERMISTOR_998_VALUE 25 #define DUMMY_THERMISTOR_999_VALUE 100 +// Resistor values when using a MAX31865 (sensor -5) +// Sensor value is typically 100 (PT100) or 1000 (PT1000) +// Calibration value is typically 430 ohm for AdaFruit PT100 modules and 4300 ohm for AdaFruit PT1000 modules. +//#define MAX31865_SENSOR_OHMS 100 +//#define MAX31865_CALIBRATION_OHMS 430 + // Use temp sensor 1 as a redundant sensor with sensor 0. If the readings // from the two sensors differ too much the print will be aborted. //#define TEMP_SENSOR_1_AS_REDUNDANT diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c3708c267654..59a74411ef7d 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1845,6 +1845,10 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #error "TEMP_SENSOR_1 is required with TEMP_SENSOR_1_AS_REDUNDANT." #endif +#if ENABLED(MAX6675_IS_MAX31865) && (!defined(MAX31865_SENSOR_OHMS) || !defined(MAX31865_CALIBRATION_OHMS)) + #error "MAX31865_SENSOR_OHMS and MAX31865_CALIBRATION_OHMS must be set in Configuration.h when using a MAX31865 temperature sensor." +#endif + /** * Test Heater, Temp Sensor, and Extruder Pins */ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index f8ff972f8034..9ecbb7c766fd 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1461,7 +1461,7 @@ void Temperature::manage_heater() { #elif ENABLED(HEATER_0_USES_MAX6675) return ( #if ENABLED(MAX6675_IS_MAX31865) - max31865.temperature(100, 400) // 100 ohms = PT100 resistance. 400 ohms = calibration resistor + max31865.temperature(MAX31865_SENSOR_OHMS, MAX31865_CALIBRATION_OHMS) #else raw * 0.25 #endif @@ -2236,7 +2236,7 @@ void Temperature::disable_all_heaters() { next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL; #if ENABLED(MAX6675_IS_MAX31865) - max6675_temp = int(max31865.temperature(100, 400)); // 100 ohms = PT100 resistance. 400 ohms = calibration resistor + max6675_temp = int(max31865.temperature(MAX31865_SENSOR_OHMS, MAX31865_CALIBRATION_OHMS)); #endif // From bcf65aa503b7e827744ba53bd00a7b6a43af2725 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 12 Oct 2020 00:59:30 -0500 Subject: [PATCH 19/46] Fix screen click reading too often (#19696) Co-authored-by: andreibobirica <39415547+andreibobirica@users.noreply.github.com> --- Marlin/src/lcd/ultralcd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 58e6d9473b35..7003d13fdd7a 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -1553,12 +1553,15 @@ void MarlinUI::update() { // - On edit screens, touch Up Half for -, Bottom Half to + // void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t, const uint8_t) { + const millis_t now = millis(); + if (PENDING(now, next_button_update_ms)) return; + next_button_update_ms = now + repeat_delay; // Assume the repeat delay const int8_t xdir = col < (LCD_WIDTH ) / 2 ? -1 : 1, ydir = row < (LCD_HEIGHT) / 2 ? -1 : 1; if (on_edit_screen) encoderDiff = epps * ydir; else if (screen_items > 0) { - // Last 3 cols act as a scroll :-) + // Last 5 cols act as a scroll :-) if (col > (LCD_WIDTH) - 5) // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.) encoderDiff = epps * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir; From c0920bbf6a2490b7ea66d2a9e828c0f527a6c77b Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 12 Oct 2020 18:38:07 -0300 Subject: [PATCH 20/46] TFT Refactoring (#19192) * split tft folder in two: tft for color ui; tft_io for shared tft code * after the files got moved, now the code was moved to the right place * classic ui using TFT IO init lcd codes * feature to compile tft_io when enabled * compiling fix * lvgl spi tft working with tft io init codes * there is no need for separeted fsmc and spi class in lvgl anymore, as tft io handle everything * remove debug * base for TFT rotation and mirroring API, and ILI9488 support * ST7796S rotate and mirror support * ST7789V rotate and mirror support * ST7735 rotate and mirror support * ILI9341 rotate and mirror support * ILI9328 rotate and mirror support * R61505 rotate and mirror support * MKS TFT definitions * more configs for mks tfts * update config * naming typo * to configure the user interface * ANYCUBIC_TFT35 * tft configs * support for SSD1963 * tft display types * updated conditionals lcd; first board fully working with the new code - all 3 ui! * compatiblity * changed name * move classic ui file name * rename TURN -> ROTATE * GRAPHICAL_TFT_ROTATE_180 deprecated * first fsmc board fully working - chitu v5 * mks robin nano v1.2 + tft 35 ok! * right pin name * anycubic tft tested in a TRIGORILLA_PRO * chitu v6 * nano 32 tft orientation * mks tft43 * mks tft43 rotation * fixed LONGER LK tft setup * GRAPHICAL_TFT_UPSCALE defined by the display type * better offsets defaults * Update Configuration.h * Update tft_fsmc.cpp * Update Conditionals_LCD.h * Tweak comments * update nano tests * Revert "update nano tests" This reverts commit a071ebbfad30e28855a4a5695ec8a726542a1a65. * default tft * outdated comments * to not break non-vscode builds * upscale tft 35 * support tft 180 rotation for color ui * Each TFT Driver is responsible for its default color mode. * use auto detect in mks displays, because some of them could be shipped with diferent drivers * extra s * unused code * wrong -1 * missing mirror options * Smaller regex pattern * Comment updates * Clean up old defines * Apply pins formatting * GRAPHICAL_TFT_ROTATE_180 => TFT_ROTATE_180 * MKS_ROBIN_TFT_V1_1R * merge fix * correct resolution * auto is default, dont need be there, and it will allow the user to configure it even for named displays * to not use rotation with MKS_ROBIN_TFT_V1_1R * i like () in macros * avoid sleepy commits * default for st7789 is rgb * nano follow up * to allow ili9328 rotation * default is rgb * boards merge follow up * to match bootloader orientation * HAS_TOUCH_XPT2046 is not hal specific anymore * lets not forget LPC * 180 rotation for ili9328 and R61505 * Clean up whitespace Co-authored-by: Scott Lahteine Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 74 ++-- Marlin/Configuration_adv.h | 3 +- Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h | 7 - Marlin/src/HAL/LPC1768/tft/tft_spi.h | 2 +- Marlin/src/HAL/STM32/tft/tft_fsmc.h | 2 +- Marlin/src/HAL/STM32/tft/tft_spi.h | 2 +- Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h | 7 - Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp | 13 - Marlin/src/HAL/STM32F1/tft/tft_fsmc.h | 2 +- Marlin/src/HAL/STM32F1/tft/tft_spi.h | 2 +- Marlin/src/core/macros.h | 6 + Marlin/src/inc/Conditionals_LCD.h | 176 +++++++- Marlin/src/inc/SanityCheck.h | 4 +- ...pp => u8g_dev_tft_upscale_from_128x64.cpp} | 347 +--------------- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp | 146 ++----- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h | 18 +- .../extui/lib/mks_ui/draw_error_message.cpp | 6 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 65 +-- .../extui/lib/mks_ui/mks_hardware_test.cpp | 12 +- Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp | 60 --- Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h | 30 -- .../lib/mks_ui/tft_lvgl_configuration.cpp | 385 +----------------- .../extui/lib/mks_ui/tft_lvgl_configuration.h | 2 +- Marlin/src/lcd/scaled_tft.h | 9 +- Marlin/src/lcd/tft/tft.cpp | 159 +------- Marlin/src/lcd/tft/tft.h | 26 +- Marlin/src/lcd/tft/tft_io.h | 30 -- Marlin/src/lcd/tft/touch.cpp | 4 + Marlin/src/lcd/{tft => tft_io}/ili9328.h | 29 +- Marlin/src/lcd/{tft => tft_io}/ili9341.h | 18 +- Marlin/src/lcd/{tft => tft_io}/ili9488.h | 18 +- Marlin/src/lcd/{tft => tft_io}/r65105.h | 29 +- Marlin/src/lcd/tft_io/ssd1963.h | 131 ++++++ Marlin/src/lcd/{tft => tft_io}/st7735.h | 16 +- Marlin/src/lcd/{tft => tft_io}/st7789v.h | 16 +- Marlin/src/lcd/{tft => tft_io}/st7796s.h | 16 +- Marlin/src/lcd/tft_io/tft_io.cpp | 226 ++++++++++ Marlin/src/lcd/tft_io/tft_io.h | 124 ++++++ Marlin/src/lcd/touch/touch_buttons.cpp | 2 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 31 +- Marlin/src/pins/lpc1768/pins_MKS_SBASE.h | 2 +- Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h | 2 +- .../src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h | 2 +- Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h | 4 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 18 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 22 +- .../src/pins/stm32f1/pins_JGAURORA_A5S_A1.h | 2 +- Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h | 11 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h | 4 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h | 1 + Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 61 +-- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 18 +- Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 52 ++- Marlin/src/pins/teensy4/pins_T41U5XBB.h | 6 +- Marlin/src/pins/teensy4/pins_TEENSY41.h | 10 +- platformio.ini | 6 +- 56 files changed, 1000 insertions(+), 1476 deletions(-) rename Marlin/src/lcd/dogm/{u8g_dev_tft_320x240_upscale_from_128x64.cpp => u8g_dev_tft_upscale_from_128x64.cpp} (60%) delete mode 100644 Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp delete mode 100644 Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h delete mode 100644 Marlin/src/lcd/tft/tft_io.h rename Marlin/src/lcd/{tft => tft_io}/ili9328.h (87%) rename Marlin/src/lcd/{tft => tft_io}/ili9341.h (94%) rename Marlin/src/lcd/{tft => tft_io}/ili9488.h (93%) rename Marlin/src/lcd/{tft => tft_io}/r65105.h (87%) create mode 100644 Marlin/src/lcd/tft_io/ssd1963.h rename Marlin/src/lcd/{tft => tft_io}/st7735.h (92%) rename Marlin/src/lcd/{tft => tft_io}/st7789v.h (93%) rename Marlin/src/lcd/{tft => tft_io}/st7796s.h (93%) create mode 100644 Marlin/src/lcd/tft_io/tft_io.cpp create mode 100644 Marlin/src/lcd/tft_io/tft_io.h diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 59f2be18c666..8f37f1e799ba 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2205,43 +2205,47 @@ //=============================== Graphical TFTs ============================== //============================================================================= -// -// TFT display with optional touch screen -// Color Marlin UI with standard menu system -// -//#define TFT_320x240 -//#define TFT_320x240_SPI -//#define TFT_480x320 -//#define TFT_480x320_SPI - -// -// Skip autodetect and force specific TFT driver -// Mandatory for SPI screens with no MISO line -// Available drivers are: ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488 -// -//#define TFT_DRIVER AUTO - -// -// SPI display (MKS Robin Nano V2.0, MKS Gen L V2.0) -// Upscaled 128x64 Marlin UI -// -//#define SPI_GRAPHICAL_TFT +/** + * TFT Type - Select your Display type + * + * Available options are: + * MKS_TS35_V2_0, + * MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, + * MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R + * TFT_TRONXY_X5SA, ANYCUBIC_TFT35, LONGER_LK_TFT28 + * TFT_GENERIC + * + * For TFT_GENERIC, you need to configure these 3 options: + * Driver: TFT_DRIVER + * Current Drivers are: AUTO, ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488 + * Resolution: TFT_WIDTH and TFT_HEIGHT + * Interface: TFT_INTERFACE_FSMC or TFT_INTERFACE_SPI + */ +//#define TFT_GENERIC -// -// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.) -// Upscaled 128x64 Marlin UI -// -//#define FSMC_GRAPHICAL_TFT +/** + * TFT UI - User Interface Selection. Enable one of the following options: + * + * TFT_CLASSIC_UI - Emulated DOGM - 128x64 Upscaled + * TFT_COLOR_UI - Marlin Default Menus, Touch Friendly, using full TFT capabilities + * TFT_LVGL_UI - A Modern UI using LVGL + * + * For LVGL_UI also copy the 'assets' folder from the build directory to the + * root of your SD card, together with the compiled firmware. + */ +//#define TFT_CLASSIC_UI +//#define TFT_COLOR_UI +//#define TFT_LVGL_UI -// -// TFT LVGL UI -// -// Using default MKS icons and fonts from: https://git.io/JJvzK -// Just copy the 'assets' folder from the build directory to the -// root of your SD card, together with the compiled firmware. -// -//#define TFT_LVGL_UI_FSMC // Robin nano v1.2 uses FSMC -//#define TFT_LVGL_UI_SPI // Robin nano v2.0 uses SPI +/** + * TFT Rotation. Set to one of the following values: + * + * TFT_ROTATE_90, TFT_ROTATE_90_MIRROR_X, TFT_ROTATE_90_MIRROR_Y, + * TFT_ROTATE_180, TFT_ROTATE_180_MIRROR_X, TFT_ROTATE_180_MIRROR_Y, + * TFT_ROTATE_270, TFT_ROTATE_270_MIRROR_X, TFT_ROTATE_270_MIRROR_Y, + * TFT_MIRROR_X, TFT_MIRROR_Y, TFT_NO_ROTATION + */ +//#define TFT_ROTATION TFT_NO_ROTATION //============================================================================= //============================ Other Controllers ============================ diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index db54716cde54..bcacddd20d42 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1560,10 +1560,9 @@ #endif // -// FSMC / SPI Graphical TFT +// Classic UI Options // #if TFT_SCALED_DOGLCD - //#define GRAPHICAL_TFT_ROTATE_180 //#define TFT_MARLINUI_COLOR 0xFFFF // White //#define TFT_MARLINBG_COLOR 0x0000 // Black //#define TFT_DISABLED_COLOR 0x0003 // Almost black diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h index b9bc0bf82e61..32ef908d633c 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h @@ -24,10 +24,3 @@ #if HAS_FSMC_TFT #error "Sorry! FSMC TFT displays are not current available for HAL/LPC1768." #endif - -// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT - #undef TOUCH_SCREEN - #undef TOUCH_SCREEN_CALIBRATION - #define HAS_TOUCH_XPT2046 1 -#endif diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.h b/Marlin/src/HAL/LPC1768/tft/tft_spi.h index 8d3e3127bbd1..4753fdbae9a0 100644 --- a/Marlin/src/HAL/LPC1768/tft/tft_spi.h +++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.h @@ -36,7 +36,7 @@ #define DATASIZE_8BIT SSP_DATABIT_8 #define DATASIZE_16BIT SSP_DATABIT_16 -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI #define DMA_MINC_ENABLE 1 #define DMA_MINC_DISABLE 0 diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.h b/Marlin/src/HAL/STM32/tft/tft_fsmc.h index 8500fee113eb..cbec7613ef4a 100644 --- a/Marlin/src/HAL/STM32/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.h @@ -38,7 +38,7 @@ #define DATASIZE_8BIT SPI_DATASIZE_8BIT #define DATASIZE_16BIT SPI_DATASIZE_16BIT -#define TFT_IO TFT_FSMC +#define TFT_IO_DRIVER TFT_FSMC #ifdef STM32F1xx #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN) diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.h b/Marlin/src/HAL/STM32/tft/tft_spi.h index 1eed45a709cc..d477b58c004d 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32/tft/tft_spi.h @@ -38,7 +38,7 @@ #define DATASIZE_8BIT SPI_DATASIZE_8BIT #define DATASIZE_16BIT SPI_DATASIZE_16BIT -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI class TFT_SPI { private: diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h index 25110d7c80e4..f52e6fec2b1e 100644 --- a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h @@ -25,10 +25,3 @@ //#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE." #undef SD_CHECK_AND_RETRY #endif - -// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT - #undef TOUCH_SCREEN - #undef TOUCH_SCREEN_CALIBRATION - #define HAS_TOUCH_XPT2046 1 -#endif diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp index 008301d9bc0c..5b52fb416fa3 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp @@ -89,25 +89,12 @@ void TFT_FSMC::Init() { uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN; uint32_t controllerAddress; - #if PIN_EXISTS(TFT_BACKLIGHT) - OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); - #endif - #if ENABLED(LCD_USE_DMA_FSMC) dma_init(FSMC_DMA_DEV); dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM); #endif - #if PIN_EXISTS(TFT_RESET) - OUT_WRITE(TFT_RESET_PIN, HIGH); - delay(100); - #endif - - #if PIN_EXISTS(TFT_BACKLIGHT) - OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); - #endif - struct fsmc_nor_psram_reg_map* fsmcPsramRegion; if (fsmcInit) return; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h index 6fcfea8a1167..11eb1ffa8410 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h @@ -32,7 +32,7 @@ #define DATASIZE_8BIT DMA_SIZE_8BITS #define DATASIZE_16BIT DMA_SIZE_16BITS -#define TFT_IO TFT_FSMC +#define TFT_IO_DRIVER TFT_FSMC typedef struct { __IO uint16_t REG; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h index bb26fc21b64f..da9a8e0c223e 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h @@ -34,7 +34,7 @@ #define DATASIZE_8BIT DATA_SIZE_8BIT #define DATASIZE_16BIT DATA_SIZE_16BIT -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI #define DMA_MINC_ENABLE 1 #define DMA_MINC_DISABLE 0 diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 72644b195ccd..21bb32c4cf24 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -452,6 +452,12 @@ #define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)()) #define _END_OF_ARGUMENTS_() 0 + +// Simple Inline IF Macros, friendly to use in other macro definitions +#define IF(O, A, B) ((O) ? (A) : (B)) +#define IF_0(O, A) IF(O, A, 0) +#define IF_1(O, A) IF(O, A, 1) + // // REPEAT core macros. Recurse N times with ascending I. // diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 42d82dcc1066..56ce2ca5ed82 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -311,13 +311,40 @@ #define IS_ULTIPANEL #endif +// Compatibility +#if ENABLED(FSMC_GRAPHICAL_TFT) + #define TFT_CLASSIC_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif ENABLED(SPI_GRAPHICAL_TFT) + #define TFT_CLASSIC_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#elif EITHER(TFT_320x240, TFT_480x320) + #define TFT_COLOR_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif EITHER(TFT_320x240_SPI, TFT_480x320_SPI) + #define TFT_COLOR_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#elif ENABLED(TFT_LVGL_UI_FSMC) + #define TFT_LVGL_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif ENABLED(TFT_LVGL_UI_SPI) + #define TFT_LVGL_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#endif + // FSMC/SPI TFT Panels (LVGL) -#if EITHER(TFT_LVGL_UI_SPI, TFT_LVGL_UI_FSMC) +#if ENABLED(TFT_LVGL_UI) #define HAS_TFT_LVGL_UI 1 #endif // FSMC/SPI TFT Panels -#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT) +#if ENABLED(TFT_CLASSIC_UI) #define TFT_SCALED_DOGLCD 1 #endif @@ -325,32 +352,16 @@ #define DOGLCD #define IS_ULTIPANEL #define DELAYED_BACKLIGHT_INIT -#elif ENABLED(TFT_LVGL_UI_SPI) +#elif ENABLED(TFT_LVGL_UI) #define DELAYED_BACKLIGHT_INIT #endif -// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h -#if ANY(TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC, FSMC_GRAPHICAL_TFT) - #define HAS_FSMC_TFT 1 -#elif ANY(TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI, SPI_GRAPHICAL_TFT) - #define HAS_SPI_TFT 1 -#endif - // Color UI -#if ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI) +#if ENABLED(TFT_COLOR_UI) #define HAS_GRAPHICAL_TFT 1 #define IS_ULTIPANEL #endif -// Fewer lines with touch buttons on-screen -#if EITHER(TFT_320x240, TFT_320x240_SPI) - #define HAS_UI_320x240 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) -#elif EITHER(TFT_480x320, TFT_480x320_SPI) - #define HAS_UI_480x320 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) -#endif - /** * I2C Panels */ @@ -810,3 +821,128 @@ #ifndef EXTRUDE_MINTEMP #define EXTRUDE_MINTEMP 170 #endif + +/** + * TFT Displays + * + * Configure parameters for TFT displays: + * - TFT_DEFAULT_ORIENTATION + * - TFT_DRIVER + * - TFT_WIDTH + * - TFT_HEIGHT + * - TFT_INTERFACE_(SPI|FSMC) + * - TFT_COLOR + * - GRAPHICAL_TFT_UPSCALE + */ +#if ENABLED(MKS_TS35_V2_0) + // Most common: ST7796 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_SPI + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(MKS_ROBIN_TFT24) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT28) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT32) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT35) + // Most common: ILI9488 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(MKS_ROBIN_TFT43) + #define TFT_DEFAULT_ORIENTATION 0 + #define TFT_DRIVER SSD1963 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 272 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT_V1_1R) + // ILI9328 or R61505 + #define TFT_DEFAULT_ORIENTATION (TFT_INVERT_X | TFT_INVERT_Y | TFT_EXCHANGE_XY) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_DRIVER ILI9488 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(LONGER_LK_TFT28) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(TFT_GENERIC) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) +#endif + +// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h +#if ENABLED(TFT_INTERFACE_FSMC) + #define HAS_FSMC_TFT 1 + #if ENABLED(TFT_CLASSIC_UI) + #define FSMC_GRAPHICAL_TFT + #elif ENABLED(TFT_LVGL_UI) + #define TFT_LVGL_UI_FSMC + #endif +#elif ENABLED(TFT_INTERFACE_SPI) + #define HAS_SPI_TFT 1 + #if ENABLED(TFT_CLASSIC_UI) + #define SPI_GRAPHICAL_TFT + #elif ENABLED(TFT_LVGL_UI) + #define TFT_LVGL_UI_SPI + #endif +#endif + +#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_320x240_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_320x240 + #endif +#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x320_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x320 + #endif +#endif + +// Fewer lines with touch buttons on-screen +#if EITHER(TFT_320x240, TFT_320x240_SPI) + #define HAS_UI_320x240 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) +#elif EITHER(TFT_480x320, TFT_480x320_SPI) + #define HAS_UI_480x320 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) +#endif + +// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' +#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT + #undef TOUCH_SCREEN + #undef TOUCH_SCREEN_CALIBRATION + #define HAS_TOUCH_XPT2046 1 +#endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 59a74411ef7d..7acb5e70c994 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -447,8 +447,6 @@ #error "POWER_SUPPLY is now obsolete. Please remove it from Configuration.h." #elif defined(MKS_ROBIN_TFT) #error "MKS_ROBIN_TFT is now FSMC_GRAPHICAL_TFT. Please update your configuration." -#elif defined(TFT_LVGL_UI) - #error "TFT_LVGL_UI is now TFT_LVGL_UI_FSMC. Please update your configuration." #elif defined(SDPOWER) #error "SDPOWER is now SDPOWER_PIN. Please update your configuration and/or pins." #elif defined(STRING_SPLASH_LINE1) || defined(STRING_SPLASH_LINE2) @@ -535,6 +533,8 @@ #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h." #elif defined(EVENT_GCODE_SD_STOP) #error "EVENT_GCODE_SD_STOP is now EVENT_GCODE_SD_ABORT. Please update your Configuration.h." +#elif defined(GRAPHICAL_TFT_ROTATE_180) + #error "GRAPHICAL_TFT_ROTATE_180 is now TFT_ROTATION set to TFT_ROTATE_180. Please update your Configuration.h." #elif defined(FIL_RUNOUT_INVERTING) #if FIL_RUNOUT_INVERTING #error "FIL_RUNOUT_INVERTING true is now FIL_RUNOUT_STATE HIGH. Please update your Configuration.h." diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp similarity index 60% rename from Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp rename to Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 0f53e45a27b5..d18b617987cb 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -66,12 +66,7 @@ #define HAS_LCD_IO 1 #endif -#if ENABLED(SPI_GRAPHICAL_TFT) - #include HAL_PATH(../../HAL, tft/tft_spi.h) -#elif ENABLED(FSMC_GRAPHICAL_TFT) - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) -#endif - +#include "../tft_io/tft_io.h" TFT_IO tftio; #define WIDTH LCD_PIXEL_WIDTH @@ -132,299 +127,10 @@ TFT_IO tftio; #define TFT_BTOKMENU_COLOR COLOR_RED #endif -static uint32_t lcd_id = 0; - -#define ST7789V_CASET 0x2A /* Column address register */ -#define ST7789V_RASET 0x2B /* Row address register */ -#define ST7789V_WRITE_RAM 0x2C /* Write data to GRAM */ - - -/* Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X */ -#define ILI9328_HASET 0x20 /* Horizontal GRAM address register (0-255) */ -#define ILI9328_VASET 0x21 /* Vertical GRAM address register (0-511)*/ -#define ILI9328_WRITE_RAM 0x22 /* Write data to GRAM */ - -#define ILI9328_HASTART 0x50 /* Horizontal address start position (0-255) */ -#define ILI9328_HAEND 0x51 /* Horizontal address end position (0-255) */ -#define ILI9328_VASTART 0x52 /* Vertical address start position (0-511) */ -#define ILI9328_VAEND 0x53 /* Vertical address end position (0-511) */ - -static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #if HAS_LCD_IO - tftio.DataTransferBegin(DATASIZE_8BIT); - #define IO_REG_DATA(R,D) do { tftio.WriteReg(R); tftio.WriteData(D); }while(0) - #else - #define IO_REG_DATA(R,D) do { u8g_WriteByte(u8g, dev, R); u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&D); }while(0) - #endif - - #if NONE(LCD_USE_DMA_FSMC, LCD_USE_DMA_SPI) - u8g_SetAddress(u8g, dev, 0); - #endif - - IO_REG_DATA(ILI9328_HASTART, Ymin); - IO_REG_DATA(ILI9328_HAEND, Ymax); - IO_REG_DATA(ILI9328_VASTART, Xmin); - IO_REG_DATA(ILI9328_VAEND, Xmax); - - IO_REG_DATA(ILI9328_HASET, Ymin); - IO_REG_DATA(ILI9328_VASET, Xmin); - - #if HAS_LCD_IO - tftio.WriteReg(ILI9328_WRITE_RAM); - tftio.DataTransferEnd(); - #else - u8g_WriteByte(u8g, dev, ILI9328_WRITE_RAM); - u8g_SetAddress(u8g, dev, 1); - #endif -} - -static void setWindow_st7789v(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #if HAS_LCD_IO - tftio.DataTransferBegin(DATASIZE_8BIT); - tftio.WriteReg(ST7789V_CASET); - tftio.WriteData((Xmin >> 8) & 0xFF); - tftio.WriteData(Xmin & 0xFF); - tftio.WriteData((Xmax >> 8) & 0xFF); - tftio.WriteData(Xmax & 0xFF); - - tftio.WriteReg(ST7789V_RASET); - tftio.WriteData((Ymin >> 8) & 0xFF); - tftio.WriteData(Ymin & 0xFF); - tftio.WriteData((Ymax >> 8) & 0xFF); - tftio.WriteData(Ymax & 0xFF); - - tftio.WriteReg(ST7789V_WRITE_RAM); - tftio.DataTransferEnd(); - #else - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_CASET); u8g_SetAddress(u8g, dev, 1); - u8g_WriteByte(u8g, dev, (Xmin >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Xmin & 0xFF); - u8g_WriteByte(u8g, dev, (Xmax >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Xmax & 0xFF); - - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_RASET); u8g_SetAddress(u8g, dev, 1); - u8g_WriteByte(u8g, dev, (Ymin >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Ymin & 0xFF); - u8g_WriteByte(u8g, dev, (Ymax >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Ymax & 0xFF); - - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_WRITE_RAM); u8g_SetAddress(u8g, dev, 1); - #endif +static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { + tftio.set_window(Xmin, Ymin, Xmax, Ymax); } -static void setWindow_none(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {} -void (*setWindow)(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) = setWindow_none; - -#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x -#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) -#define ESC_END 0xFFFF, 0x7FFF -#define ESC_FFFF 0xFFFF, 0xFFFF - -#if HAS_LCD_IO - void writeEscSequence(const uint16_t *sequence) { - uint16_t data; - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - tftio.WriteData(data); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - tftio.WriteData(data); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - tftio.WriteReg(data); - } - } - } - #define WRITE_ESC_SEQUENCE(V) writeEscSequence(V) - #define WRITE_ESC_SEQUENCE16(V) writeEscSequence(V) -#else - void writeEscSequence8(u8g_t *u8g, u8g_dev_t *dev, const uint16_t *sequence) { - uint16_t data; - u8g_SetAddress(u8g, dev, 1); - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - u8g_WriteByte(u8g, dev, data & 0xFF); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - u8g_WriteByte(u8g, dev, data & 0xFF); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - u8g_SetAddress(u8g, dev, 0); - u8g_WriteByte(u8g, dev, data & 0xFF); - u8g_SetAddress(u8g, dev, 1); - } - } - } - - #define WRITE_ESC_SEQUENCE(V) writeEscSequence8(u8g, dev, V) - - void writeEscSequence16(u8g_t *u8g, u8g_dev_t *dev, const uint16_t *sequence) { - uint16_t data; - u8g_SetAddress(u8g, dev, 0); - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&data); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&data); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - u8g_WriteByte(u8g, dev, data & 0xFF); - } - } - u8g_SetAddress(u8g, dev, 1); - } - - #define WRITE_ESC_SEQUENCE16(V) writeEscSequence16(u8g, dev, V) -#endif - -static const uint16_t st7789v_init[] = { - ESC_REG(0x0010), ESC_DELAY(10), - ESC_REG(0x0001), ESC_DELAY(200), - ESC_REG(0x0011), ESC_DELAY(120), - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x0060, 0x00A0), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x002A), 0x0000, 0x0000, 0x0001, 0x003F, - ESC_REG(0x002B), 0x0000, 0x0000, 0x0000, 0x00EF, - ESC_REG(0x00B2), 0x000C, 0x000C, 0x0000, 0x0033, 0x0033, - ESC_REG(0x00B7), 0x0035, - ESC_REG(0x00BB), 0x001F, - ESC_REG(0x00C0), 0x002C, - ESC_REG(0x00C2), 0x0001, 0x00C3, - ESC_REG(0x00C4), 0x0020, - ESC_REG(0x00C6), 0x000F, - ESC_REG(0x00D0), 0x00A4, 0x00A1, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_END -}; - -static const uint16_t ili9328_init[] = { - ESC_REG(0x0001), 0x0100, - ESC_REG(0x0002), 0x0400, - ESC_REG(0x0003), 0x1038, - ESC_REG(0x0004), 0x0000, - ESC_REG(0x0008), 0x0202, - ESC_REG(0x0009), 0x0000, - ESC_REG(0x000A), 0x0000, - ESC_REG(0x000C), 0x0000, - ESC_REG(0x000D), 0x0000, - ESC_REG(0x000F), 0x0000, - ESC_REG(0x0010), 0x0000, - ESC_REG(0x0011), 0x0007, - ESC_REG(0x0012), 0x0000, - ESC_REG(0x0013), 0x0000, - ESC_REG(0x0007), 0x0001, - ESC_DELAY(200), - ESC_REG(0x0010), 0x1690, - ESC_REG(0x0011), 0x0227, - ESC_DELAY(50), - ESC_REG(0x0012), 0x008C, - ESC_DELAY(50), - ESC_REG(0x0013), 0x1500, - ESC_REG(0x0029), 0x0004, - ESC_REG(0x002B), 0x000D, - ESC_DELAY(50), - ESC_REG(0x0050), 0x0000, - ESC_REG(0x0051), 0x00EF, - ESC_REG(0x0052), 0x0000, - ESC_REG(0x0053), 0x013F, - ESC_REG(0x0020), 0x0000, - ESC_REG(0x0021), 0x0000, - ESC_REG(0x0060), 0x2700, - ESC_REG(0x0061), 0x0001, - ESC_REG(0x006A), 0x0000, - ESC_REG(0x0080), 0x0000, - ESC_REG(0x0081), 0x0000, - ESC_REG(0x0082), 0x0000, - ESC_REG(0x0083), 0x0000, - ESC_REG(0x0084), 0x0000, - ESC_REG(0x0085), 0x0000, - ESC_REG(0x0090), 0x0010, - ESC_REG(0x0092), 0x0600, - ESC_REG(0x0007), 0x0133, - ESC_REG(0x0022), - ESC_END -}; - -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, 0x0028, 0x00E8), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x002A), 0x0000, 0x0000, 0x0001, 0x003F, - ESC_REG(0x002B), 0x0000, 0x0000, 0x0000, 0x00EF, - ESC_REG(0x00C5), 0x003E, 0x0028, - ESC_REG(0x00C7), 0x0086, - ESC_REG(0x00B1), 0x0000, 0x0018, - ESC_REG(0x00C0), 0x0023, - ESC_REG(0x00C1), 0x0010, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - -static const uint16_t ili9488_init[] = { - ESC_REG(0x00E0), 0x0000, 0x0007, 0x000F, 0x000D, 0x001B, 0x000A, 0x003C, 0x0078, 0x004A, 0x0007, 0x000E, 0x0009, 0x001B, 0x001E, 0x000F, - ESC_REG(0x00E1), 0x0000, 0x0022, 0x0024, 0x0006, 0x0012, 0x0007, 0x0036, 0x0047, 0x0047, 0x0006, 0x000A, 0x0007, 0x0030, 0x0037, 0x000F, - ESC_REG(0x00C0), 0x0010, 0x0010, - ESC_REG(0x00C1), 0x0041, - ESC_REG(0x00C5), 0x0000, 0x0022, 0x0080, - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x00A8, 0x0068), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x00B0), 0x0000, - ESC_REG(0x00B1), 0x00B0, 0x0011, - ESC_REG(0x00B4), 0x0002, - ESC_REG(0x00B6), 0x0002, 0x0042, - ESC_REG(0x00B7), 0x00C6, - ESC_REG(0x00E9), 0x0000, - ESC_REG(0x00F0), 0x00A9, 0x0051, 0x002C, 0x0082, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - -static const uint16_t st7796_init[] = { - ESC_REG(0x0010), ESC_DELAY(120), - ESC_REG(0x0001), ESC_DELAY(120), - ESC_REG(0x0011), ESC_DELAY(120), - ESC_REG(0x00F0), 0x00C3, - ESC_REG(0x00F0), 0x0096, - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x00E8, 0x0028), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x00B4), 0x0001, - ESC_REG(0x00B7), 0x00C6, - ESC_REG(0x00E8), 0x0040, 0x008A, 0x0000, 0x0000, 0x0029, 0x0019, 0x00A5, 0x0033, - ESC_REG(0x00C1), 0x0006, - ESC_REG(0x00C2), 0x00A7, - ESC_REG(0x00C5), 0x0018, - ESC_REG(0x00E0), 0x00F0, 0x0009, 0x000B, 0x0006, 0x0004, 0x0015, 0x002F, 0x0054, 0x0042, 0x003C, 0x0017, 0x0014, 0x0018, 0x001B, - ESC_REG(0x00E1), 0x00F0, 0x0009, 0x000B, 0x0006, 0x0004, 0x0003, 0x002D, 0x0043, 0x0042, 0x003B, 0x0016, 0x0014, 0x0017, 0x001B, - ESC_REG(0x00F0), 0x003C, - ESC_REG(0x00F0), 0x0069, ESC_DELAY(120), - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - #if HAS_TOUCH_XPT2046 static const uint8_t buttonD[] = { @@ -640,43 +346,9 @@ 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, &lcd_id); - tftio.DataTransferBegin(DATASIZE_8BIT); - switch (lcd_id & 0xFFFF) { - case 0x8552: // ST7789V - WRITE_ESC_SEQUENCE(st7789v_init); - setWindow = setWindow_st7789v; - break; - case 0x9328: // ILI9328 - WRITE_ESC_SEQUENCE16(ili9328_init); - 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; - break; - case 0x7796: - WRITE_ESC_SEQUENCE(st7796_init); - setWindow = setWindow_st7789v; - break; - case 0x9488: - WRITE_ESC_SEQUENCE(ili9488_init); - setWindow = setWindow_st7789v; - case 0x0404: // No connected display on FSMC - lcd_id = 0; - return 0; - case 0xFFFF: // No connected display on SPI - lcd_id = 0; - return 0; - default: - setWindow = (lcd_id & 0xFF000000) ? setWindow_st7789v : setWindow_ili9328; - break; - } - tftio.DataTransferEnd(); + dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL); + tftio.Init(); + tftio.InitTFT(); if (preinit) { preinit = false; @@ -771,14 +443,7 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: u8g_SetPIOutput(u8g, U8G_PI_RESET); - u8g_Delay(50); - - tftio.Init(); - - if (arg_ptr) { - *((uint32_t *)arg_ptr) = tftio.GetID(); - } isCommand = 0; break; 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 351d033d01ec..394ce4807572 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp @@ -22,7 +22,7 @@ #include "../../../../inc/MarlinConfigPre.h" -#if ENABLED(TFT_LVGL_UI_SPI) +#if HAS_TFT_LVGL_UI #include "SPI_TFT.h" #include "pic_manager.h" @@ -32,6 +32,8 @@ #include +#include "draw_ui.h" + TFT SPI_TFT; // use SPI1 for the spi tft. @@ -39,142 +41,48 @@ void TFT::spi_init(uint8_t spiRate) { tftio.Init(); } -void TFT::LCD_WR_REG(uint8_t cmd) { - tftio.WriteReg(cmd); -} - -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; - SetWindows(x, y, 1, 1); + setWindow(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); - LCD_WR_DATA((x + with - 1) >> 8); - LCD_WR_DATA((x + with - 1)); - - LCD_WR_REG(0x2B); - LCD_WR_DATA(y >> 8); - 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::setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { + tftio.set_window(x, y, (x + with - 1), (y + height - 1)); } void TFT::LCD_init() { - TFT_BLK_L; - TFT_RST_H; - delay(150); - TFT_RST_L; - delay(150); - TFT_RST_H; - - tftio.DataTransferBegin(DATASIZE_8BIT); - - delay(120); - LCD_WR_REG(0x11); - delay(120); - - LCD_WR_REG(0xF0); - LCD_WR_DATA(0xC3); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x96); - - LCD_WR_REG(0x36); - LCD_WR_DATA(0x28 + TERN0(GRAPHICAL_TFT_ROTATE_180, 0x80)); - LCD_WR_REG(0x3A); - LCD_WR_DATA(0x55); - - LCD_WR_REG(0xB4); - LCD_WR_DATA(0x01); - LCD_WR_REG(0xB7); - LCD_WR_DATA(0xC6); - LCD_WR_REG(0xE8); - LCD_WR_DATA(0x40); - LCD_WR_DATA(0x8A); - LCD_WR_DATA(0x00); - LCD_WR_DATA(0x00); - LCD_WR_DATA(0x29); - LCD_WR_DATA(0x19); - LCD_WR_DATA(0xA5); - LCD_WR_DATA(0x33); - LCD_WR_REG(0xC1); - LCD_WR_DATA(0x06); - LCD_WR_REG(0xC2); - LCD_WR_DATA(0xA7); - LCD_WR_REG(0xC5); - LCD_WR_DATA(0x18); - LCD_WR_REG(0xE0); // Positive Voltage Gamma Control - LCD_WR_DATA(0xF0); - LCD_WR_DATA(0x09); - LCD_WR_DATA(0x0B); - LCD_WR_DATA(0x06); - LCD_WR_DATA(0x04); - LCD_WR_DATA(0x15); - LCD_WR_DATA(0x2F); - LCD_WR_DATA(0x54); - LCD_WR_DATA(0x42); - LCD_WR_DATA(0x3C); - LCD_WR_DATA(0x17); - LCD_WR_DATA(0x14); - LCD_WR_DATA(0x18); - LCD_WR_DATA(0x1B); - LCD_WR_REG(0xE1); // Negative Voltage Gamma Control - LCD_WR_DATA(0xF0); - LCD_WR_DATA(0x09); - LCD_WR_DATA(0x0B); - LCD_WR_DATA(0x06); - LCD_WR_DATA(0x04); - LCD_WR_DATA(0x03); - LCD_WR_DATA(0x2D); - LCD_WR_DATA(0x43); - LCD_WR_DATA(0x42); - LCD_WR_DATA(0x3B); - LCD_WR_DATA(0x16); - LCD_WR_DATA(0x14); - LCD_WR_DATA(0x17); - LCD_WR_DATA(0x1B); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x3C); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x69); - delay(120); // Delay 120ms - LCD_WR_REG(0x29); // Display ON - - tftio.DataTransferEnd(); - - LCD_clear(0x0000); // + tftio.InitTFT(); + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, LOW); + #endif + delay(100); + LCD_clear(0x0000); LCD_Draw_Logo(); - TFT_BLK_H; - delay(2000); + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + #endif + #if HAS_LOGO_IN_FLASH + delay(2000); + #endif } void TFT::LCD_clear(uint16_t color) { - SetWindows(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1); + setWindow(0, 0, (TFT_WIDTH), (TFT_HEIGHT)); tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT)); } extern unsigned char bmp_public_buf[17 * 1024]; void TFT::LCD_Draw_Logo() { - SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT); - for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); - tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); - } + #if HAS_LOGO_IN_FLASH + setWindow(0, 0, TFT_WIDTH, TFT_HEIGHT); + for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { + Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); + tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); + } + #endif } -#endif // HAS_TFT_LVGL_UI_SPI +#endif // HAS_TFT_LVGL_UI 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 e40039fe8649..696bc16974be 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h @@ -23,29 +23,21 @@ #include "../../inc/MarlinConfigPre.h" -#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 +#if HAS_TFT_LVGL_UI -#define TFT_RST_H OUT_WRITE(TFT_RESET_PIN, HIGH) -#define TFT_RST_L OUT_WRITE(TFT_RESET_PIN, LOW) - -#define TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH) -#define TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW) +#include "../../../tft_io/tft_io.h" class TFT { public: TFT_IO tftio; void spi_init(uint8_t spiRate); - void LCD_WR_REG(uint8_t cmd); - void LCD_WR_DATA(uint8_t data); 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 setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height); void LCD_init(); void LCD_clear(uint16_t color); void LCD_Draw_Logo(); }; extern TFT SPI_TFT; + +#endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp index 1bcdccda414a..c21ee3612c3a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "lv_conf.h" #include "draw_ui.h" @@ -77,7 +75,7 @@ void lv_draw_error_message(PGM_P const msg) { lv_task_handler(); #endif - TERN(TFT_LVGL_UI_SPI, SPI_TFT.LCD_clear, LCD_Clear)(0x0000); + SPI_TFT.LCD_clear(0x0000); if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000); disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000); disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000); 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 458620801b1b..d600b09a5f16 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" @@ -165,7 +163,7 @@ void gCfgItems_init() { W25QXX.SPI_FLASH_BufferWrite((uint8_t *)&custom_gcode_command[4], OTHERS_COMMAND_ADDR_4, 100); } - const byte rot = TERN0(GRAPHICAL_TFT_ROTATE_180, 0xEE); + const byte rot = (TFT_ROTATION & TFT_ROTATE_180) ? 0xEE : 0x00; if (gCfgItems.disp_rotation_180 != rot) { gCfgItems.disp_rotation_180 = rot; update_spi_flash(); @@ -655,12 +653,7 @@ char *creat_title_text() { } card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8); - #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - #else - LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1); - LCD_WriteRAM_Prepare(); - #endif + SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1); j = i = 0; @@ -673,20 +666,11 @@ char *creat_title_text() { } if (j >= 400) break; } - #if ENABLED(TFT_LVGL_UI_SPI) - for (i = 0; i < 400; i += 2) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; - } - SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); - #else - for (i = 0; i < 400;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color; - LCD_IO_WriteData(*p_index); - i += 2; - } - #endif + for (i = 0; i < 400; i += 2) { + p_index = (uint16_t *)(&bmp_public_buf[i]); + if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; + } + SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); #if HAS_BAK_VIEW_IN_FLASH W25QXX.init(SPI_QUARTER_SPEED); if (row < 20) W25QXX.SPI_FLASH_SectorErase(BAK_VIEW_ADDR_TFT35 + row * 4096); @@ -768,7 +752,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.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); + SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1); #else LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -901,34 +885,9 @@ char *creat_title_text() { default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 8k #endif - #if ENABLED(TFT_LVGL_UI_SPI) - 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; - LCD_setWindowArea(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 - - LCD_WriteRAM_Prepare(); - - 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); - p_index = &temp_p; - } - else { - p_index = (uint16_t *)(&bmp_public_buf[i]); - } - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color; - LCD_IO_WriteData(*p_index); - i += 2; - } - if (i >= 8000) break; - } - #endif // TFT_LVGL_UI_SPI + SPI_TFT.setWindow(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); + y_off++; } W25QXX.init(SPI_QUARTER_SPEED); 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 eeb6bae706bc..bc329aa82b89 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 @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" @@ -626,10 +624,8 @@ static const uint16_t ASCII_Table_16x24[] PROGMEM = { void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint16_t bkColor) { for (uint16_t i = 0; i < 24; i++) { const uint16_t tmp_char = pgm_read_word(&ASCII_Table_16x24[((c - 0x20) * 24) + i]); - for (uint16_t j = 0; j < 16; j++) { - TERN(TFT_LVGL_UI_SPI, SPI_TFT.SetPoint, tft_set_point) - (x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor); - } + for (uint16_t j = 0; j < 16; j++) + SPI_TFT.SetPoint(x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor); } } @@ -643,7 +639,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor //static lv_obj_t * scr_test; void disp_assets_update() { - TERN(TFT_LVGL_UI_SPI,, LCD_Clear(0x0000)); + SPI_TFT.LCD_clear(0x0000); disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp deleted file mode 100644 index 62967b9d8061..000000000000 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "../../../../inc/MarlinConfig.h" - -#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); - } - - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { - tftio.WriteSequence(data, length); - } -#endif // LCD_USE_DMA_FSMC - -#endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h deleted file mode 100644 index b2e19d66f8f8..000000000000 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#ifdef __cplusplus - extern "C" { /* C-declarations for C++ */ -#endif - -#ifdef __cplusplus - } /* C-declarations for C++ */ -#endif 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 3f8110feb446..ecd4eb482a6a 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 @@ -29,9 +29,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" @@ -74,24 +72,6 @@ lv_group_t* g; uint16_t DeviceCode = 0x9488; extern uint8_t sel_id; -#define SetCs -#define ClrCs - -#define HDP 799 // Horizontal Display Period -#define HT 1000 // Horizontal Total -#define HPS 51 // LLINE Pulse Start Position -#define LPS 3 // Horizontal Display Period Start Position -#define HPW 8 // LLINE Pulse Width - -#define VDP 479 // Vertical Display Period -#define VT 530 // Vertical Total -#define VPS 24 // LFRAME Pulse Start Position -#define FPS 23 // Vertical Display Period Start Positio -#define VPW 3 // LFRAME Pulse Width - -#define MAX_HZ_POSX HDP+1 -#define MAX_HZ_POSY VDP+1 - extern uint8_t gcode_preview_over, flash_preview_begin, default_preview_flg; uint8_t bmp_public_buf[17 * 1024]; @@ -125,317 +105,7 @@ void SysTick_Callback() { } } -#if DISABLED(TFT_LVGL_UI_SPI) - - extern void LCD_IO_Init(uint8_t cs, uint8_t rs); - extern void LCD_IO_WriteData(uint16_t RegValue); - extern void LCD_IO_WriteReg(uint16_t Reg); - - extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count); - void tft_set_cursor(uint16_t x, uint16_t y) { - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(x >> 8); - LCD_IO_WriteData(x & 0x00FF); - LCD_IO_WriteData(x >> 8); - LCD_IO_WriteData(x & 0x00FF); - //ILI9488_WriteData(0x01); - //ILI9488_WriteData(0xDF); - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(y >> 8); - LCD_IO_WriteData(y & 0x00FF); - LCD_IO_WriteData(y >> 8); - LCD_IO_WriteData(y & 0x00FF); - //ILI9488_WriteData(0x01); - //ILI9488_WriteData(0x3F); - } - - void LCD_WriteRAM_Prepare(void) { - #if 0 - 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 - } - - void tft_set_point(uint16_t x, uint16_t y, uint16_t point) { - //if (DeviceCode == 0x9488) { - if (x > (TFT_WIDTH) || y > (TFT_HEIGHT)) return; - //} - tft_set_cursor(x, y); - - LCD_WriteRAM_Prepare(); - //LCD_WriteRAM(point); - LCD_IO_WriteData(point); - } - - void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue) { - /* Write 16-bit Index, then Write Reg */ - ClrCs - LCD_IO_WriteReg(LCD_Reg); - /* Write 16-bit Reg */ - LCD_IO_WriteData(LCD_RegValue); - SetCs - } - - void LCD_setWindowArea(uint16_t StartX, uint16_t StartY, uint16_t width, uint16_t heigh) { - uint16_t s_h, s_l, e_h, e_l; - uint16_t xEnd, yEnd; - xEnd = StartX + width; - yEnd = StartY + heigh - 1; - if (DeviceCode == 0x8989) { - /*LCD_WriteReg(0x0044, (StartX & 0xFF) | (xEnd << 8)); - LCD_WriteReg(0x0045, StartY); - LCD_WriteReg(0x0046, yEnd);*/ - LCD_WriteReg(0x0044, (StartY & 0xFF) | (yEnd << 8)); - LCD_WriteReg(0x0045, StartX); - LCD_WriteReg(0x0046, xEnd); - } - else if (DeviceCode == 0x9488) { - s_h = (StartX >> 8) & 0x00FF; - s_l = StartX & 0x00FF; - e_h = ((StartX + width - 1) >> 8) & 0x00FF; - e_l = (StartX + width - 1) & 0x00FF; - - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - - s_h = (StartY >> 8) & 0x00FF; - s_l = StartY & 0x00FF; - e_h = ((StartY + heigh - 1) >> 8) & 0x00FF; - e_l = (StartY + heigh - 1) & 0x00FF; - - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - } - else if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x1505)) { - /* LCD_WriteReg(0x0050, StartX); - LCD_WriteReg(0x0052, StartY); - LCD_WriteReg(0x0051, xEnd); - 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, (TFT_HEIGHT) - xEnd); - LCD_WriteReg(0x0053, (TFT_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit - - } - else { - s_h = (StartX >> 8) & 0xFF; - s_l = StartX & 0xFF; - e_h = ((StartX + width - 1) >> 8) & 0xFF; - e_l = (StartX + width - 1) & 0xFF; - - LCD_IO_WriteReg(0x2A); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - - s_h = (StartY >> 8) & 0xFF; - s_l = StartY & 0xFF; - e_h = ((StartY + heigh - 1) >> 8) & 0xFF; - e_l = (StartY + heigh - 1) & 0xFF; - - LCD_IO_WriteReg(0x2B); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - } - } - - void LCD_Clear(uint16_t Color) { - uint32_t index = 0; - unsigned int count; - - if (DeviceCode == 0x9488) { - tft_set_cursor(0, 0); - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - LCD_WriteRAM_Prepare(); - #ifdef LCD_USE_DMA_FSMC - LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT)); - #else - //index = (TFT_HEIGHT) / 2 * (TFT_WIDTH); - for (index = 0; index < (TFT_HEIGHT) * (TFT_WIDTH); index++) - LCD_IO_WriteData(Color); - #endif - //LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT)); - //while(index --) LCD_IO_WriteData(Color); - } - else if (DeviceCode == 0x5761) { - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(0); - LCD_IO_WriteData(0); - LCD_IO_WriteData(HDP >> 8); - LCD_IO_WriteData(HDP & 0x00FF); - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(0); - LCD_IO_WriteData(0); - LCD_IO_WriteData(VDP >> 8); - LCD_IO_WriteData(VDP & 0x00FF); - LCD_IO_WriteReg(0x002C); - LCD_IO_WriteReg(0x002C); - for (count = 0; count < (HDP + 1) * (VDP + 1); count++) - LCD_IO_WriteData(Color); - } - else { - tft_set_cursor(0, 0); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (index = 0; index < 76800; index++) - LCD_IO_WriteData(Color); - } - } - - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) - extern TFT_IO tftio; - void fsmc_tft_init() { - uint16_t i; - - TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - - #ifdef LCD_USE_DMA_FSMC - dma_init(FSMC_DMA_DEV); - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM); - #endif - - LCD_IO_Init(FSMC_CS_PIN, FSMC_RS_PIN); - - _delay_ms(5); - - DeviceCode = tftio.GetID() & 0xFFFF; - // Chitu and others - if (DeviceCode == 0x8066) DeviceCode = 0x9488; - - if (DeviceCode == 0x9488) { - LCD_IO_WriteReg(0x00E0); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x000F); - LCD_IO_WriteData(0x000D); - LCD_IO_WriteData(0x001B); - LCD_IO_WriteData(0x000A); - LCD_IO_WriteData(0x003C); - LCD_IO_WriteData(0x0078); - LCD_IO_WriteData(0x004A); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x000E); - LCD_IO_WriteData(0x0009); - LCD_IO_WriteData(0x001B); - LCD_IO_WriteData(0x001E); - LCD_IO_WriteData(0x000F); - - LCD_IO_WriteReg(0x00E1); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0022); - LCD_IO_WriteData(0x0024); - LCD_IO_WriteData(0x0006); - LCD_IO_WriteData(0x0012); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x0036); - LCD_IO_WriteData(0x0047); - LCD_IO_WriteData(0x0047); - LCD_IO_WriteData(0x0006); - LCD_IO_WriteData(0x000A); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x0030); - LCD_IO_WriteData(0x0037); - LCD_IO_WriteData(0x000F); - - LCD_IO_WriteReg(0x00C0); - LCD_IO_WriteData(0x0010); - LCD_IO_WriteData(0x0010); - - LCD_IO_WriteReg(0x00C1); - LCD_IO_WriteData(0x0041); - - LCD_IO_WriteReg(0x00C5); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0022); - LCD_IO_WriteData(0x0080); - - LCD_IO_WriteReg(0x0036); - LCD_IO_WriteData(TERN(GRAPHICAL_TFT_ROTATE_180, 0xE8, 0x0068)); - - LCD_IO_WriteReg(0x003A); //Interface Mode Control - LCD_IO_WriteData(0x0055); - - LCD_IO_WriteReg(0x00B0); //Interface Mode Control - LCD_IO_WriteData(0x0000); - LCD_IO_WriteReg(0x00B1); //Frame rate 70HZ - LCD_IO_WriteData(0x00B0); - LCD_IO_WriteData(0x0011); - LCD_IO_WriteReg(0x00B4); - LCD_IO_WriteData(0x0002); - LCD_IO_WriteReg(0x00B6); //RGB/MCU Interface Control - LCD_IO_WriteData(0x0002); - LCD_IO_WriteData(0x0042); - - LCD_IO_WriteReg(0x00B7); - LCD_IO_WriteData(0x00C6); - - //WriteComm(0xBE); - //WriteData(0x00); - //WriteData(0x04); - - LCD_IO_WriteReg(0x00E9); - LCD_IO_WriteData(0x0000); - - LCD_IO_WriteReg(0x00F7); - LCD_IO_WriteData(0x00A9); - LCD_IO_WriteData(0x0051); - LCD_IO_WriteData(0x002C); - LCD_IO_WriteData(0x0082); - - LCD_IO_WriteReg(0x0011); - for (i = 0; i < 65535; i++) { /* do nothing */ } - LCD_IO_WriteReg(0x0029); - - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - - OUT_WRITE(LCD_BACKLIGHT_PIN, LOW); - LCD_Clear(0x0000); - - TERN_(HAS_LOGO_IN_FLASH, lcd_draw_logo()); - - OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH); - delay(2000); - } - } - - extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); - - void lcd_draw_logo() { - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - LCD_WriteRAM_Prepare(); - - for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); - #ifdef LCD_USE_DMA_FSMC - LCD_IO_WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); - #else - int index = 0;,x_off = 0; - for (x_off = 0; x_off < TFT_WIDTH; x_off++) { - LCD_IO_WriteData((uint16_t)bmp_public_buf[index]); - index += 2; - } - #endif - } - } - -#endif // !TFT_LVGL_UI_SPI +extern uint8_t bmp_public_buf[17 * 1024]; void tft_lvgl_init() { @@ -448,12 +118,8 @@ void tft_lvgl_init() { disp_language_init(); //init tft first! - #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - SPI_TFT.LCD_init(); - #else - fsmc_tft_init(); - #endif + SPI_TFT.spi_init(SPI_FULL_SPEED); + SPI_TFT.LCD_init(); //spi_flash_read_test(); #if ENABLED(SDSUPPORT) @@ -548,41 +214,18 @@ 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; - - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; + uint16_t i, width, height; - 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); + width = area->x2 - area->x1 + 1; + height = area->y2 - area->y1 + 1; - #else // !TFT_LVGL_UI_SPI - - #if 1 - uint16_t i, width, height; - //uint16_t clr_temp; - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; - LCD_setWindowArea((uint16_t)area->x1, (uint16_t)area->y1, width, height); - LCD_WriteRAM_Prepare(); - for (i = 0; i < width * height - 2; i++) { - //clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11) - //| ((uint16_t)color_p->ch.green << 5) - //| ((uint16_t)color_p->ch.blue)); - LCD_IO_WriteData(color_p->full); - color_p++; - } - - lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ - #endif + SPI_TFT.setWindow((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*/ - #endif // !TFT_LVGL_UI_SPI + W25QXX.init(SPI_QUARTER_SPEED); } #define TICK_CYCLE 1 @@ -599,7 +242,7 @@ static bool get_point(int16_t *x, int16_t *y) { *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; } - #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + #if (TFT_ROTATION & TFT_ROTATE_180) *x = int16_t((TFT_WIDTH) - (int)(*x)); *y = int16_t((TFT_HEIGHT) - (int)(*y)); #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h index 7e24f948fd09..727ab33aea30 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h @@ -32,7 +32,7 @@ #include -//#define GRAPHICAL_TFT_ROTATE_180 +//#define TFT_ROTATION TFT_ROTATE_180 #define USE_WIFI_FUNCTION 0 extern void tft_lvgl_init(); diff --git a/Marlin/src/lcd/scaled_tft.h b/Marlin/src/lcd/scaled_tft.h index be846f70a9dd..2c05e5f26d81 100644 --- a/Marlin/src/lcd/scaled_tft.h +++ b/Marlin/src/lcd/scaled_tft.h @@ -43,8 +43,13 @@ #endif #ifndef TFT_PIXEL_OFFSET_X - #define TFT_PIXEL_OFFSET_X 48 + #if GRAPHICAL_TFT_UPSCALE == 2 + #define TFT_PIXEL_OFFSET_X 32 + #else + #define TFT_PIXEL_OFFSET_X 48 + #endif #endif #ifndef TFT_PIXEL_OFFSET_Y - #define TFT_PIXEL_OFFSET_Y 48 + // 32 is better for both 320x240 and 480x320 + #define TFT_PIXEL_OFFSET_Y 32 #endif diff --git a/Marlin/src/lcd/tft/tft.cpp b/Marlin/src/lcd/tft/tft.cpp index 81fe6788e7c7..fa3c2c241f79 100644 --- a/Marlin/src/lcd/tft/tft.cpp +++ b/Marlin/src/lcd/tft/tft.cpp @@ -25,173 +25,16 @@ #if HAS_GRAPHICAL_TFT #include "tft.h" -#include "st7735.h" -#include "st7789v.h" -#include "st7796s.h" -#include "r65105.h" -#include "ili9328.h" -#include "ili9341.h" -#include "ili9488.h" //#define DEBUG_GRAPHICAL_TFT #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) #include "../../core/debug_out.h" uint16_t TFT::buffer[]; -uint32_t TFT::lcd_id = 0xFFFFFFFF; void TFT::init() { - if (lcd_id != 0xFFFFFFFF) return; - io.Init(); - - #if TFT_DRIVER != AUTO - lcd_id = TFT_DRIVER; - #endif - - #if TFT_DRIVER == ST7735 - write_esc_sequence(st7735_init); - #elif TFT_DRIVER == ST7789 - write_esc_sequence(st7789v_init); - #elif TFT_DRIVER == ST7796 - write_esc_sequence(st7796s_init); - #elif TFT_DRIVER == R61505 - write_esc_sequence(r61505_init); - #elif TFT_DRIVER == ILI9328 - write_esc_sequence(ili9328_init); - #elif TFT_DRIVER == ILI9341 - write_esc_sequence(ili9341_init); - #elif TFT_DRIVER == ILI9488 - write_esc_sequence(ili9488_init); - #elif TFT_DRIVER == LERDGE_ST7796 - lcd_id = ST7796; - write_esc_sequence(lerdge_st7796s_init); - - #elif TFT_DRIVER == AUTO // autodetect - - lcd_id = io.GetID() & 0xFFFF; - - switch (lcd_id) { - case ST7796: // ST7796S 480x320 - DEBUG_ECHO_MSG(" ST7796S"); - write_esc_sequence(st7796s_init); - break; - case ST7789: // ST7789V 320x240 - DEBUG_ECHO_MSG(" ST7789V"); - write_esc_sequence(st7789v_init); - break; - case ST7735: // ST7735 160x128 - DEBUG_ECHO_MSG(" ST7735"); - write_esc_sequence(st7735_init); - break; - case R61505: // R61505U 320x240 - DEBUG_ECHO_MSG(" R61505U"); - write_esc_sequence(r61505_init); - break; - case ILI9328: // ILI9328 320x240 - DEBUG_ECHO_MSG(" ILI9328"); - write_esc_sequence(ili9328_init); - break; - case ILI9341: // ILI9341 320x240 - DEBUG_ECHO_MSG(" ILI9341"); - write_esc_sequence(ili9341_init); - break; - case ILI9488: // ILI9488 480x320 - DEBUG_ECHO_MSG(" ILI9488"); - write_esc_sequence(ili9488_init); - break; - default: - lcd_id = 0; - } - #else - #error Unsupported TFT driver - #endif -} - -void TFT::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #ifdef OFFSET_X - Xmin += OFFSET_X; Xmax += OFFSET_X; - #endif - #ifdef OFFSET_Y - Ymin += OFFSET_Y; Ymax += OFFSET_Y; - #endif - - switch (lcd_id) { - case ST7735: // ST7735 160x128 - case ST7789: // ST7789V 320x240 - case ST7796: // ST7796 480x320 - case ILI9341: // ILI9341 320x240 - case ILI9488: // ILI9488 480x320 - io.DataTransferBegin(DATASIZE_8BIT); - - // CASET: Column Address Set - io.WriteReg(ILI9341_CASET); - io.WriteData((Xmin >> 8) & 0xFF); - io.WriteData(Xmin & 0xFF); - io.WriteData((Xmax >> 8) & 0xFF); - io.WriteData(Xmax & 0xFF); - - // RASET: Row Address Set - io.WriteReg(ILI9341_PASET); - io.WriteData((Ymin >> 8) & 0xFF); - io.WriteData(Ymin & 0xFF); - io.WriteData((Ymax >> 8) & 0xFF); - io.WriteData(Ymax & 0xFF); - - // RAMWR: Memory Write - io.WriteReg(ILI9341_RAMWR); - break; - case R61505: // R61505U 320x240 - case ILI9328: // ILI9328 320x240 - io.DataTransferBegin(DATASIZE_16BIT); - - // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X - io.WriteReg(ILI9328_HASTART); - io.WriteData(Ymin); - io.WriteReg(ILI9328_HAEND); - io.WriteData(Ymax); - io.WriteReg(ILI9328_VASTART); - io.WriteData(Xmin); - io.WriteReg(ILI9328_VAEND); - io.WriteData(Xmax); - - io.WriteReg(ILI9328_HASET); - io.WriteData(Ymin); - io.WriteReg(ILI9328_VASET); - io.WriteData(Xmin); - - io.WriteReg(ILI9328_RAMWR); - break; - default: - break; - } - - io.DataTransferEnd(); -} - -void TFT::write_esc_sequence(const uint16_t *Sequence) { - uint16_t dataWidth, data; - - dataWidth = *Sequence++; - io.DataTransferBegin(dataWidth); - - for (;;) { - data = *Sequence++; - if (data != 0xFFFF) { - io.WriteData(data); - continue; - } - data = *Sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) - io.WriteData(0xFFFF); - else if (data & 0x8000) - delay(data & 0x7FFF); - else if ((data & 0xFF00) == 0) - io.WriteReg(data); - } - - io.DataTransferEnd(); + io.InitTFT(); } TFT tft; diff --git a/Marlin/src/lcd/tft/tft.h b/Marlin/src/lcd/tft/tft.h index 6d429109c892..ed3d5e35c157 100644 --- a/Marlin/src/lcd/tft/tft.h +++ b/Marlin/src/lcd/tft/tft.h @@ -26,7 +26,7 @@ #include "tft_color.h" #include "tft_string.h" #include "tft_image.h" -#include "tft_io.h" +#include "../tft_io/tft_io.h" #include "../../inc/MarlinConfig.h" @@ -40,20 +40,6 @@ #error "Unsupported display resolution!" #endif -#define ST7735 0x89F0 -#define ST7789 0x8552 -#define ST7796 0x7796 -#define R61505 0x1505 -#define ILI9328 0x9328 -#define ILI9341 0x9341 -#define ILI9488 0x9488 -#define LERDGE_ST7796 0xFFFE -#define AUTO 0xFFFF - -#ifndef TFT_DRIVER - #define TFT_DRIVER AUTO -#endif - #ifndef TFT_BUFFER_SIZE #ifdef STM32F103xB #define TFT_BUFFER_SIZE 1024 @@ -71,14 +57,8 @@ #error "TFT_BUFFER_SIZE can not exceed 65535" #endif -#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x -#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) -#define ESC_END 0xFFFF, 0x7FFF -#define ESC_FFFF 0xFFFF, 0xFFFF - class TFT { private: - static uint32_t lcd_id; static TFT_String string; static TFT_IO io; @@ -91,13 +71,11 @@ class TFT { static inline void set_font(const uint8_t *Font) { string.set_font(Font); } static inline void add_glyphs(const uint8_t *Font) { string.add_glyphs(Font); } - static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax); - static void write_esc_sequence(const uint16_t *Sequence); - static inline bool is_busy() { return io.isBusy(); } static inline void abort() { io.Abort(); } static inline void write_multiple(uint16_t Data, uint16_t Count) { io.WriteMultiple(Data, Count); } static inline void write_sequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); } + static inline void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { io.set_window(Xmin, Ymin, Xmax, Ymax); } static inline void fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color) { queue.fill(x, y, width, height, color); } static inline void canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { queue.canvas(x, y, width, height); } diff --git a/Marlin/src/lcd/tft/tft_io.h b/Marlin/src/lcd/tft/tft_io.h deleted file mode 100644 index bffe92b0ff30..000000000000 --- a/Marlin/src/lcd/tft/tft_io.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include "../../inc/MarlinConfig.h" - -#if HAS_SPI_TFT - #include HAL_PATH(../../HAL, tft/tft_spi.h) -#elif HAS_FSMC_TFT - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) -#endif diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 80c65f074ae6..2124a42e28ca 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -295,6 +295,10 @@ bool Touch::get_point(int16_t *x, int16_t *y) { if (is_touched && calibration.orientation != TOUCH_ORIENTATION_NONE) { *x = int16_t((int32_t(*x) * calibration.x) >> 16) + calibration.offset_x; *y = int16_t((int32_t(*y) * calibration.y) >> 16) + calibration.offset_y; + #if (TFT_ROTATION & TFT_ROTATE_180) + *x = TFT_WIDTH - *x; + *y = TFT_HEIGHT - *y; + #endif } return is_touched; } diff --git a/Marlin/src/lcd/tft/ili9328.h b/Marlin/src/lcd/tft_io/ili9328.h similarity index 87% rename from Marlin/src/lcd/tft/ili9328.h rename to Marlin/src/lcd/tft_io/ili9328.h index 85edfa7bee0a..818dd05b348f 100644 --- a/Marlin/src/lcd/tft/ili9328.h +++ b/Marlin/src/lcd/tft_io/ili9328.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -40,8 +40,29 @@ #define ILI9328_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical // MKS Robin TFT v1.1 - 320x240 ; Cable on the left side -#define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS -#define ILI9328_ETMOD_DATA ILI9328_ETMOD_BGR | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0 | ILI9328_ETMOD_AM + +#if TFT_ROTATION == TFT_ROTATE_180 + #define ILI9328_DRVCTL_DATA 0x0000 + #define ILI9328_GATE_SCANCTL1_DATA 0xA700 +#else + #define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS + #define ILI9328_GATE_SCANCTL1_DATA 0x2700 +#endif + +// #define ILI9328_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9328_ETMOD_AM) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9328_ETMOD_ID1) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9328_ETMOD_ID0) + +#define ILI9328_ETMOD_ORIENTATION (ILI9328_ETMOD_AM | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_RGB +#endif + +#define ILI9328_ETMOD_DATA (ILI9328_ETMOD_ORIENTATION) | (ILI9328_ETMOD_COLOR) + #define ILI9328_RDDID 0x00 // ID code - 0x9328 #define ILI9328_DRVCTL 0x01 // Driver Output Control @@ -134,7 +155,7 @@ static const uint16_t ili9328_init[] = { ESC_REG(ILI9328_PWCTRL7), 0x0004, ESC_REG(ILI9328_FRMCTR), 0x000D, ESC_DELAY(50), - ESC_REG(ILI9328_GATE_SCANCTL1), 0x2700, + ESC_REG(ILI9328_GATE_SCANCTL1), ILI9328_GATE_SCANCTL1_DATA, ESC_REG(ILI9328_GATE_SCANCTL2), 0x0001, ESC_REG(ILI9328_GATE_SCANCTL3), 0x0000, ESC_REG(ILI9328_PLTPOS1), 0x0000, diff --git a/Marlin/src/lcd/tft/ili9341.h b/Marlin/src/lcd/tft_io/ili9341.h similarity index 94% rename from Marlin/src/lcd/tft/ili9341.h rename to Marlin/src/lcd/tft_io/ili9341.h index d4a493412fb2..dda326df6d5b 100644 --- a/Marlin/src/lcd/tft/ili9341.h +++ b/Marlin/src/lcd/tft_io/ili9341.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,13 +38,17 @@ #define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; Cable on the left side #define ILI9341_ORIENTATION_DOWN ILI9341_MADCTL_MX // 240x320 ; Cable on the upper side -#ifndef ILI9341_COLOR_RGB - #define ILI9341_COLOR_BGR -#endif -#ifndef ILI9341_ORIENTATION - #define ILI9341_ORIENTATION ILI9341_ORIENTATION_LEFT +#define ILI9341_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9341_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9341_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9341_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9341_COLOR ILI9341_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9341_COLOR ILI9341_MADCTL_RGB #endif -#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION | TERN(ILI9341_COLOR_BGR, ILI9341_MADCTL_BGR, ILI9341_MADCTL_RGB)) + +#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION) | (ILI9341_COLOR) #define ILI9341_NOP 0x00 // No Operation #define ILI9341_SWRESET 0x01 // Software Reset diff --git a/Marlin/src/lcd/tft/ili9488.h b/Marlin/src/lcd/tft_io/ili9488.h similarity index 93% rename from Marlin/src/lcd/tft/ili9488.h rename to Marlin/src/lcd/tft_io/ili9488.h index 19fdc78e0a5e..e71c0d16d775 100644 --- a/Marlin/src/lcd/tft/ili9488.h +++ b/Marlin/src/lcd/tft_io/ili9488.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,13 +38,17 @@ #define ILI9488_ORIENTATION_LEFT ILI9488_MADCTL_MY | ILI9488_MADCTL_MX | ILI9488_MADCTL_MV // 480x320 ; Cable on the left side #define ILI9488_ORIENTATION_DOWN ILI9488_MADCTL_MX // 320x480 ; Cable on the upper side -#ifndef ILI9488_COLOR_RGB - #define ILI9488_COLOR_BGR -#endif -#ifndef ILI9488_ORIENTATION - #define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT +#define ILI9488_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9488_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9488_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9488_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9488_COLOR ILI9488_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9488_COLOR ILI9488_MADCTL_RGB #endif -#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION | TERN(ILI9488_COLOR_BGR, ILI9488_MADCTL_BGR, ILI9488_MADCTL_RGB)) + +#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION) | (ILI9488_COLOR) #define ILI9488_NOP 0x00 // No Operation #define ILI9488_SWRESET 0x01 // Software Reset diff --git a/Marlin/src/lcd/tft/r65105.h b/Marlin/src/lcd/tft_io/r65105.h similarity index 87% rename from Marlin/src/lcd/tft/r65105.h rename to Marlin/src/lcd/tft_io/r65105.h index 8d073f5d0d1c..a813c3260b1a 100644 --- a/Marlin/src/lcd/tft/r65105.h +++ b/Marlin/src/lcd/tft_io/r65105.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -42,9 +42,28 @@ #define R61505_DRVCTRL_GS 0x8000 // Gate Scan direction // MKS Robin TFT v1.1 - 320x240 ; Cable on the left side -#define R61505_DRVCTL_DATA R61505_DRVCTL_SS -#define R61505_ETMOD_DATA R61505_ETMOD_BGR | R61505_ETMOD_ID1 | R61505_ETMOD_ID0 | R61505_ETMOD_AM -#define R61505_DRVCTRL_GSDIR R61505_DRVCTRL_GS + +#if TFT_ROTATION == TFT_ROTATE_180 + #define R61505_DRVCTL_DATA 0x0000 + #define R61505_DRVCTRL_DATA (0x2700 | R61505_DRVCTRL_GS) +#else + #define R61505_DRVCTL_DATA R61505_DRVCTL_SS + #define R61505_DRVCTRL_DATA 0x2700 +#endif + +// #define R61505_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, R61505_ETMOD_AM) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_X, R61505_ETMOD_ID0) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, R61505_ETMOD_ID1) + +#define R61505_ETMOD_ORIENTATION (R61505_ETMOD_AM | R61505_ETMOD_ID0 | R61505_ETMOD_ID1) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define R61505_ETMOD_COLOR R61505_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define R61505_ETMOD_COLOR R61505_ETMOD_RGB +#endif + +#define R61505_ETMOD_DATA (R61505_ETMOD_ORIENTATION) | (R61505_ETMOD_COLOR) #define R61505_RDDID 0x00 // ID code - 0x1505 @@ -141,7 +160,7 @@ static const uint16_t r61505_init[] = { ESC_REG(R61505_GAMCTRL9), 0x0700, ESC_REG(R61505_GAMCTRLA), 0x0A1F, - ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_GSDIR | 0x2700, + ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_DATA, ESC_REG(R61505_BASE_IMAGE_CTRL), 0x0001, ESC_REG(R61505_VSCROLL_CTRL), 0x0000, diff --git a/Marlin/src/lcd/tft_io/ssd1963.h b/Marlin/src/lcd/tft_io/ssd1963.h new file mode 100644 index 000000000000..4953a96233e8 --- /dev/null +++ b/Marlin/src/lcd/tft_io/ssd1963.h @@ -0,0 +1,131 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define SSD1963_MADCTL_MY 0x80 // Row Address Order +#define SSD1963_MADCTL_MX 0x40 // Column Address Order +#define SSD1963_MADCTL_MV 0x20 // Row/Column Exchange +#define SSD1963_MADCTL_MH 0x10 // Horizontal Refresh Order +#define SSD1963_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define SSD1963_MADCTL_RGB 0x00 +#define SSD1963_MADCTL_ML 0x04 // Vertical Refresh Order +#define SSD1963_MADCTL_FH 0x02 // Flip Horizontal +#define SSD1963_MADCTL_FV 0x01 // Flip Vertical + +#define SSD1963_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, SSD1963_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define SSD1963_COLOR SSD1963_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define SSD1963_COLOR SSD1963_MADCTL_RGB +#endif + +#define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR) + +#define SSD1963_NOP 0x00 // No Operation +#define SSD1963_SWRESET 0x01 // Software reset +#define SSD1963_RDDPM 0x0A // Read Display Power Mode +#define SSD1963_RDDMADCTL 0x0B // Read Display MADCTL +#define SSD1963_RDDCOLMOD 0x0C // Read Display Pixel Format +#define SSD1963_RDDIM 0x0D // Read Display Image Mode +#define SSD1963_RDDSM 0x0E // Read Display Signal Mode +#define SSD1963_SLPIN 0x10 // Sleep In +#define SSD1963_SLPOUT 0x11 // Sleep Out +#define SSD1963_PTLON 0x12 // Partial Display Mode On +#define SSD1963_NORON 0x13 // Normal Display Mode On +#define SSD1963_INVOFF 0x20 // Display Inversion Off +#define SSD1963_INVON 0x21 // Display Inversion On +#define SSD1963_GAMSET 0x26 // Gamma Set +#define SSD1963_DISPOFF 0x28 // Display Off +#define SSD1963_DISPON 0x29 // Display On +#define SSD1963_CASET 0x2A // Column Address Set +#define SSD1963_RASET 0x2B // Row Address Set +#define SSD1963_RAMWR 0x2C // Memory Write +#define SSD1963_RAMRD 0x2E // Memory Read +#define SSD1963_PTLAR 0x30 // Partial Area +#define SSD1963_VSCRDEF 0x33 // Vertical Scrolling Definition +#define SSD1963_TEOFF 0x34 // Tearing Effect Line OFF +#define SSD1963_TEON 0x35 // Tearing Effect Line ON +#define SSD1963_MADCTL 0x36 // Memory Data Access Control +#define SSD1963_VSCSAD 0x37 // Vertical Scroll Start Address of RAM +#define SSD1963_IDMOFF 0x38 // Idle Mode Off +#define SSD1963_IDMON 0x39 // Idle Mode On +#define SSD1963_WRMEMC 0x3C // Write Memory Continue +#define SSD1963_RDMEMC 0x3E // Read Memory Continue +#define SSD1963_STE 0x44 // Set Tear Scanline +#define SSD1963_GSCAN 0x45 // Get Scanline +#define SSD1963_WRDISBV 0x51 // Write Display Brightness +#define SSD1963_RDDISBV 0x52 // Read Display Brightness +#define SSD1963_WRCTRLD 0x53 // Write CTRL Display +#define SSD1963_RDCTRLD 0x54 // Read CTRL Value Display +#define SSD1963_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement +#define SSD1963_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define SSD1963_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define SSD1963_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define SSD1963_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result +#define SSD1963_RDDDB 0xA1 // Read Device Descriptor Block +#define SSD1963_SLCDMODE 0xB0 // Set the LCD panel mode and resolution +#define SSD1963_SHSYNC 0xB4 // Set HSYNC +#define SSD1963_GHSYNC 0xB5 // Get HSYNC +#define SSD1963_SVSYNC 0xB6 // Set VSYNC +#define SSD1963_GVSYNC 0xB7 // Get VSYNC +#define SSD1963_SGPIOCFG 0xB8 // Set GPIO Conf +#define SSD1963_SGPIOV 0xBA // Set GPIO Value +#define SSD1963_SPWMCFG 0xBE // Set PWM Conf +#define SSD1963_GPWMCFG 0xBF // Get PWM Conf +#define SSD1963_SDBCCFG 0xD0 // Set Dynamic Back Light Config +#define SSD1963_GDBCCFG 0xD1 // Get Dynamic Back Light Config +#define SSD1963_PLLON 0xE0 // PLL Enable +#define SSD1963_PLLMN 0xE2 // Set PLL Multiplier +#define SSD1963_SLSHIFT 0xE6 // Set the LSHIFT (pixel clock) frequency +#define SSD1963_COLMOD 0xF0 // Interface Pixel Format + +static const uint16_t ssd1963_init[] = { + DATASIZE_8BIT, + ESC_REG(SSD1963_PLLMN), 0x0023, 0x0002, 0x0054, + ESC_REG(SSD1963_PLLON), 0x0001, ESC_DELAY(10), + ESC_REG(SSD1963_PLLON), 0x0003, ESC_DELAY(10), + ESC_REG(SSD1963_SWRESET), ESC_DELAY(100), + + ESC_REG(SSD1963_SLSHIFT), 0x0001, 0x001F, 0x00FF, + ESC_REG(SSD1963_SLCDMODE), 0x0020, 0x0000, 0x0001, 0x00DF, 0x0001, 0x000F, 0x0000, + ESC_REG(SSD1963_SHSYNC), 0x0002, 0x0013, 0x0000, 0x0008, 0x002B, 0x0000, 0x0002, 0x0000, + ESC_REG(SSD1963_SVSYNC), 0x0001, 0x0020, 0x0000, 0x0004, 0x000C, 0x0000, 0x0002, + ESC_REG(SSD1963_SGPIOV), 0x000F, + ESC_REG(SSD1963_SGPIOCFG), 0x0007, 0x0001, + + ESC_REG(SSD1963_MADCTL), SSD1963_MADCTL_DATA, + ESC_REG(SSD1963_COLMOD), 0x0003, ESC_DELAY(1),//RBG 565 + + ESC_REG(SSD1963_NORON), + ESC_REG(SSD1963_DISPON), + + ESC_REG(SSD1963_SPWMCFG), 0x0006, 0x00f0, 0x0001, 0x00f0, 0x0000, 0x0000, + ESC_REG(SSD1963_SDBCCFG), 0x000D, + ESC_END +}; diff --git a/Marlin/src/lcd/tft/st7735.h b/Marlin/src/lcd/tft_io/st7735.h similarity index 92% rename from Marlin/src/lcd/tft/st7735.h rename to Marlin/src/lcd/tft_io/st7735.h index 62f93d5044c0..1b0d23b6c4b9 100644 --- a/Marlin/src/lcd/tft/st7735.h +++ b/Marlin/src/lcd/tft_io/st7735.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,9 +38,17 @@ #define ST7735_ORIENTATION_LEFT ST7735_MADCTL_MV | ST7735_MADCTL_MX // 160x128 ; Cable on the left side #define ST7735_ORIENTATION_DOWN ST7735_MADCTL_MX | ST7735_MADCTL_MY // 128x160 ; Cable on the lower side -//#define ST7735_COLOR_BGR -#define ST7735_ORIENTATION ST7735_ORIENTATION_DOWN -#define ST7735_MADCTL_DATA (ST7735_ORIENTATION | TERN(ST7735_COLOR_BGR, ST7735_MADCTL_BGR, ST7735_MADCTL_RGB)) +#define ST7735_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7735_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7735_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7735_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7735_COLOR ST7735_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7735_COLOR ST7735_MADCTL_BGR +#endif + +#define ST7735_MADCTL_DATA (ST7735_ORIENTATION) | (ST7735_COLOR) #define ST7735_NOP 0x00 // No Operation #define ST7735_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft/st7789v.h b/Marlin/src/lcd/tft_io/st7789v.h similarity index 93% rename from Marlin/src/lcd/tft/st7789v.h rename to Marlin/src/lcd/tft_io/st7789v.h index 67da67966d2c..d0cf969c66ce 100644 --- a/Marlin/src/lcd/tft/st7789v.h +++ b/Marlin/src/lcd/tft_io/st7789v.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,11 +38,17 @@ #define ST7789V_ORIENTATION_LEFT ST7789V_MADCTL_MY | ST7789V_MADCTL_MV // 320x240 ; Cable on the left side #define ST7789V_ORIENTATION_DOWN 0 // 240x320 ; Cable on the lower side -//#define ST7789V_COLOR_BGR -#ifndef ST7789V_ORIENTATION - #define ST7789V_ORIENTATION ST7789V_ORIENTATION_LEFT +#define ST7789V_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7789V_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7789V_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7789V_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7789V_COLOR ST7789V_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7789V_COLOR ST7789V_MADCTL_BGR #endif -#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION | TERN(ST7789V_COLOR_BGR, ST7789V_MADCTL_BGR, ST7789V_MADCTL_RGB)) + +#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION) | (ST7789V_COLOR) #define ST7789V_NOP 0x00 // No Operation #define ST7789V_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft/st7796s.h b/Marlin/src/lcd/tft_io/st7796s.h similarity index 93% rename from Marlin/src/lcd/tft/st7796s.h rename to Marlin/src/lcd/tft_io/st7796s.h index 10452293de0b..8653a49ca2ef 100644 --- a/Marlin/src/lcd/tft/st7796s.h +++ b/Marlin/src/lcd/tft_io/st7796s.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -33,9 +33,17 @@ #define ST7796S_MADCTL_RGB 0x00 #define ST7796S_MADCTL_MH 0x04 // Horizontal Refresh Order -#define ST7796S_COLOR_BGR -#define ST7796S_ORIENTATION ST7796S_MADCTL_MV -#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION | TERN(ST7796S_COLOR_BGR, ST7796S_MADCTL_BGR, ST7796S_MADCTL_RGB)) +#define ST7796S_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7796S_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7796S_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7796S_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ST7796S_COLOR ST7796S_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ST7796S_COLOR ST7796S_MADCTL_RGB +#endif + +#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION) | (ST7796S_COLOR) #define ST7796S_NOP 0x00 // No Operation #define ST7796S_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp new file mode 100644 index 000000000000..cd535458a181 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -0,0 +1,226 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "tft_io.h" + +#if HAS_SPI_TFT || HAS_FSMC_TFT + +#include "st7735.h" +#include "st7789v.h" +#include "st7796s.h" +#include "r65105.h" +#include "ili9328.h" +#include "ili9341.h" +#include "ili9488.h" +#include "ssd1963.h" + +#define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) +#include "../../core/debug_out.h" + +TFT_IO_DRIVER TFT_IO::io; +uint32_t TFT_IO::lcd_id = 0xFFFFFFFF; + +void TFT_IO::InitTFT() { +if (lcd_id != 0xFFFFFFFF) return; + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, LOW); + #endif + + #if PIN_EXISTS(TFT_RESET) + OUT_WRITE(TFT_RESET_PIN, HIGH); + delay(10); + OUT_WRITE(TFT_RESET_PIN, LOW); + delay(10); + OUT_WRITE(TFT_RESET_PIN, HIGH); + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); + #endif + + // io.Init(); + delay(100); + + #if TFT_DRIVER != AUTO + lcd_id = TFT_DRIVER; + #endif + + #if TFT_DRIVER == ST7735 + write_esc_sequence(st7735_init); + #elif TFT_DRIVER == SSD1963 + write_esc_sequence(ssd1963_init); + #elif TFT_DRIVER == ST7789 + write_esc_sequence(st7789v_init); + #elif TFT_DRIVER == ST7796 + write_esc_sequence(st7796s_init); + #elif TFT_DRIVER == R61505 + write_esc_sequence(r61505_init); + #elif TFT_DRIVER == ILI9328 + write_esc_sequence(ili9328_init); + #elif TFT_DRIVER == ILI9341 + write_esc_sequence(ili9341_init); + #elif TFT_DRIVER == ILI9488 + write_esc_sequence(ili9488_init); + #elif TFT_DRIVER == LERDGE_ST7796 + lcd_id = ST7796; + write_esc_sequence(lerdge_st7796s_init); + + #elif TFT_DRIVER == AUTO // autodetect + + lcd_id = io.GetID() & 0xFFFF; + + switch (lcd_id) { + case ST7796: // ST7796S 480x320 + DEBUG_ECHO_MSG(" ST7796S"); + write_esc_sequence(st7796s_init); + break; + case ST7789: // ST7789V 320x240 + DEBUG_ECHO_MSG(" ST7789V"); + write_esc_sequence(st7789v_init); + break; + case SSD1963: // SSD1963 + DEBUG_ECHO_MSG(" SSD1963"); + write_esc_sequence(ssd1963_init); + break; + case ST7735: // ST7735 160x128 + DEBUG_ECHO_MSG(" ST7735"); + write_esc_sequence(st7735_init); + break; + case R61505: // R61505U 320x240 + DEBUG_ECHO_MSG(" R61505U"); + write_esc_sequence(r61505_init); + break; + case ILI9328: // ILI9328 320x240 + DEBUG_ECHO_MSG(" ILI9328"); + write_esc_sequence(ili9328_init); + break; + case ILI9341: // ILI9341 320x240 + DEBUG_ECHO_MSG(" ILI9341"); + write_esc_sequence(ili9341_init); + break; + case ILI9488: // ILI9488 480x320 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + DEBUG_ECHO_MSG(" ILI9488"); + write_esc_sequence(ili9488_init); + break; + default: + lcd_id = 0; + } + #else + #error Unsupported TFT driver + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) + OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + #endif +} + +void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { + #ifdef OFFSET_X + Xmin += OFFSET_X; Xmax += OFFSET_X; + #endif + #ifdef OFFSET_Y + Ymin += OFFSET_Y; Ymax += OFFSET_Y; + #endif + + switch (lcd_id) { + case ST7735: // ST7735 160x128 + case ST7789: // ST7789V 320x240 + case ST7796: // ST7796 480x320 + case ILI9341: // ILI9341 320x240 + case ILI9488: // ILI9488 480x320 + case SSD1963: // SSD1963 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + io.DataTransferBegin(DATASIZE_8BIT); + + // CASET: Column Address Set + io.WriteReg(ILI9341_CASET); + io.WriteData((Xmin >> 8) & 0xFF); + io.WriteData(Xmin & 0xFF); + io.WriteData((Xmax >> 8) & 0xFF); + io.WriteData(Xmax & 0xFF); + + // RASET: Row Address Set + io.WriteReg(ILI9341_PASET); + io.WriteData((Ymin >> 8) & 0xFF); + io.WriteData(Ymin & 0xFF); + io.WriteData((Ymax >> 8) & 0xFF); + io.WriteData(Ymax & 0xFF); + + // RAMWR: Memory Write + io.WriteReg(ILI9341_RAMWR); + break; + case R61505: // R61505U 320x240 + case ILI9328: // ILI9328 320x240 + io.DataTransferBegin(DATASIZE_16BIT); + + // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X + io.WriteReg(ILI9328_HASTART); + io.WriteData(Ymin); + io.WriteReg(ILI9328_HAEND); + io.WriteData(Ymax); + io.WriteReg(ILI9328_VASTART); + io.WriteData(Xmin); + io.WriteReg(ILI9328_VAEND); + io.WriteData(Xmax); + + io.WriteReg(ILI9328_HASET); + io.WriteData(Ymin); + io.WriteReg(ILI9328_VASET); + io.WriteData(Xmin); + + io.WriteReg(ILI9328_RAMWR); + break; + default: + break; + } + + io.DataTransferEnd(); +} + +void TFT_IO::write_esc_sequence(const uint16_t *Sequence) { + uint16_t dataWidth, data; + + dataWidth = *Sequence++; + io.DataTransferBegin(dataWidth); + + for (;;) { + data = *Sequence++; + if (data != 0xFFFF) { + io.WriteData(data); + continue; + } + data = *Sequence++; + if (data == 0x7FFF) return; + if (data == 0xFFFF) + io.WriteData(0xFFFF); + else if (data & 0x8000) + delay(data & 0x7FFF); + else if ((data & 0xFF00) == 0) + io.WriteReg(data); + } + + io.DataTransferEnd(); +} + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h new file mode 100644 index 000000000000..63d6936ac0b8 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -0,0 +1,124 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../../inc/MarlinConfig.h" + +#if HAS_SPI_TFT || HAS_FSMC_TFT + +#if HAS_SPI_TFT + #include HAL_PATH(../../HAL, tft/tft_spi.h) +#elif HAS_FSMC_TFT + #include HAL_PATH(../../HAL, tft/tft_fsmc.h) +#else + #error "TFT IO only supports SPI or FSMC interface" +#endif + +#define TFT_EXCHANGE_XY (1UL << 1) +#define TFT_INVERT_X (1UL << 2) +#define TFT_INVERT_Y (1UL << 3) + +#define TFT_NO_ROTATION (0x00) +#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) +#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y) +#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y) + +#define TFT_MIRROR_X (TFT_INVERT_Y) +#define TFT_MIRROR_Y (TFT_INVERT_X) + +#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_INVERT_Y) +#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_INVERT_X) + +#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_INVERT_Y) +#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_INVERT_X) + +#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_INVERT_Y) +#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_INVERT_X) + +// TFT_ROTATION is user configurable +#ifndef TFT_ROTATION + #define TFT_ROTATION TFT_NO_ROTATION +#endif + + +// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION +#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION)) + +#define TFT_COLOR_RGB (1UL << 3) +#define TFT_COLOR_BGR (1UL << 4) + +// Each TFT Driver is responsible for its default color mode. +// #ifndef TFT_COLOR +// #define TFT_COLOR TFT_COLOR_RGB +// #endif + +#define SSD1963 0x5761 +#define ST7735 0x89F0 +#define ST7789 0x8552 +#define ST7796 0x7796 +#define R61505 0x1505 +#define ILI9328 0x9328 +#define ILI9341 0x9341 +#define ILI9488 0x9488 +#define ILI9488_ID1 0x8066 //Some ILI9488 have 0x8066 in the 0x04 +#define LERDGE_ST7796 0xFFFE +#define AUTO 0xFFFF + +#ifndef TFT_DRIVER + #define TFT_DRIVER AUTO +#endif + +#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x +#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) +#define ESC_END 0xFFFF, 0x7FFF +#define ESC_FFFF 0xFFFF, 0xFFFF + +class TFT_IO { +public: + static TFT_IO_DRIVER io; + + static void InitTFT(); + static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax); + static void write_esc_sequence(const uint16_t *Sequence); + + // Deletaged methods + inline static void Init() { io.Init(); }; + inline static bool isBusy() { return io.isBusy(); }; + inline static void Abort() { io.Abort(); }; + inline static uint32_t GetID() { return io.GetID(); }; + + inline static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) { io.DataTransferBegin(DataWidth); } + inline static void DataTransferEnd() { io.DataTransferEnd(); }; + // inline static void DataTransferAbort() { io.DataTransferAbort(); }; + + inline static void WriteData(uint16_t Data) { io.WriteData(Data); }; + inline static void WriteReg(uint16_t Reg) { io.WriteReg(Reg); }; + + inline static void WriteSequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); }; + // static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } + inline static void WriteMultiple(uint16_t Color, uint32_t Count) { io.WriteMultiple(Color, Count); }; + +protected: + static uint32_t lcd_id; +}; + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index c97018c379c0..7d25c0df7eb9 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -82,7 +82,7 @@ uint8_t TouchButtons::read_buttons() { x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; - #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + #if (TFT_ROTATION & TFT_ROTATE_180) x = TOUCH_SENSOR_WIDTH - x; y = TOUCH_SENSOR_HEIGHT - y; #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 5bb32a420aee..4686e984b088 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -296,25 +296,44 @@ #ifndef GRAPHICAL_TFT_UPSCALE #define GRAPHICAL_TFT_UPSCALE 3 #endif + // SPI 1 + #define SCK_PIN P0_15 + #define MISO_PIN P0_17 + #define MOSI_PIN P0_18 // Disable any LCD related PINs config #define LCD_PINS_ENABLE -1 #define LCD_PINS_RS -1 - // Emulated DOGM have xpt calibration values independent of display resolution - #if ENABLED(SPI_GRAPHICAL_TFT) + // XPT2046 Touch Screen calibration + #if ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11245 + #define XPT2046_X_CALIBRATION -11245 #endif #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8629 + #define XPT2046_Y_CALIBRATION 8629 #endif #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 685 + #define XPT2046_X_OFFSET 685 #endif #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -285 + #define XPT2046_Y_OFFSET -285 #endif + #elif ENABLED(TFT_480x320_SPI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -17232 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 11196 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 1047 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -358 + #endif + + #define TFT_BUFFER_SIZE 2400 #endif #elif IS_TFTGLCD_PANEL diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h index 196503c822c5..6c6a9ea306ec 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h @@ -220,7 +220,7 @@ #if IS_TFTGLCD_PANEL #if ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS P3_25 // EXP2.3 + #define TFTGLCD_CS P3_25 // EXP2.3 #endif #if SD_CONNECTION_IS(LCD) diff --git a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h index c602af1c3028..294e7527a875 100644 --- a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h +++ b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h @@ -371,7 +371,7 @@ #endif #if ANY(VIKI2, miniVIKI) - // #define LCD_SCREEN_ROT_180 + //#define LCD_SCREEN_ROT_180 #define DOGLCD_CS P0_16 // (16) #define DOGLCD_A0 P2_06 // (59) J3-8 & AUX-2 diff --git a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h index 76c54c3bba21..6d6d7557f57d 100644 --- a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h +++ b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h @@ -161,7 +161,7 @@ // #define TEMP_0_PIN P0_24 #define TEMP_1_PIN P0_23 -//#define TEMP_2_PIN P1_30 // Onboard thermistor +//#define TEMP_2_PIN P1_30 // Onboard thermistor #define TEMP_BED_PIN P0_25 // diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h index cbbe8a9416d4..62660935f5bd 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h @@ -39,7 +39,7 @@ //#define SDCARD_EEPROM_EMULATION //#define I2C_EEPROM // AT24C32 #define FLASH_EEPROM_EMULATION - #define MARLIN_EEPROM_SIZE 0x1000 // 4KB + #define MARLIN_EEPROM_SIZE 0x1000 // 4KB #endif // @@ -190,7 +190,7 @@ #define E1_SERIAL_RX_PIN P1_17 // Reduce baud rate to improve software serial reliability - #define TMC_BAUD_RATE 19200 + #define TMC_BAUD_RATE 19200 #endif // HAS_TMC_UART // diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index 5d81d1eca9ab..b02d414089ff 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -129,8 +129,6 @@ #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 #define TFT_RESET_PIN PF11 #define TFT_BACKLIGHT_PIN PD13 @@ -140,14 +138,9 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define TFT_WIDTH 480 - #define TFT_HEIGHT 320 - #define TFT_PIXEL_OFFSET_X 48 - #define TFT_PIXEL_OFFSET_Y 32 - #endif -#if HAS_TFT_LVGL_UI +#if ENABLED(TFT_LVGL_UI) // LVGL #define HAS_SPI_FLASH_FONT 1 #define HAS_GCODE_PREVIEW 1 @@ -155,16 +148,17 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 -#elif ENABLED(TFT_480x320) +#elif ENABLED(TFT_COLOR_UI) // Color UI #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) // Emulated DOGM #define GRAPHICAL_TFT_UPSCALE 3 #endif -#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -177,7 +171,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12316 #endif diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index e6c9b33a5a29..cafd50dcf22c 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -135,15 +135,15 @@ // TronXY TFT Support // -// Shared FSMC Configs #if HAS_FSMC_TFT + + // Shared FSMC + #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 #define TFT_RESET_PIN PF11 #define TFT_BACKLIGHT_PIN PD13 @@ -153,14 +153,9 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define TFT_WIDTH 480 - #define TFT_HEIGHT 320 - #define TFT_PIXEL_OFFSET_X 48 - #define TFT_PIXEL_OFFSET_Y 32 - #endif -#if HAS_TFT_LVGL_UI +#if ENABLED(TFT_LVGL_UI) // LVGL #define HAS_SPI_FLASH_FONT 1 #define HAS_GCODE_PREVIEW 1 @@ -168,16 +163,17 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 -#elif ENABLED(TFT_480x320) +#elif ENABLED(TFT_COLOR_UI) // Color UI #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) // Emulated DOGM #define GRAPHICAL_TFT_UPSCALE 3 #endif -#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -190,7 +186,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12316 #endif diff --git a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h index 64948039baf9..3c277233d73e 100644 --- a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h +++ b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h @@ -39,7 +39,7 @@ #define STM32_XL_DENSITY #endif -// #define MCU_STM32F103ZE // not yet required +//#define MCU_STM32F103ZE // not yet required // Enable EEPROM Emulation for this board, so that we don't overwrite factory data //#define I2C_EEPROM // AT24C64 diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 47d7118b53d1..af81bbebe2d4 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -118,7 +118,6 @@ * because Marlin uses the reset as a failsafe to revive a glitchy LCD. */ -#define LCD_RESET_PIN PC4 // pin 33 #define TFT_RESET_PIN PC4 // pin 33 #define TFT_BACKLIGHT_PIN PD12 // pin 59 #define FSMC_CS_PIN PD7 // pin 88 = FSMC_NE1 @@ -131,13 +130,11 @@ #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 -#define GRAPHICAL_TFT_UPSCALE 2 -#define TFT_WIDTH 320 -#define TFT_HEIGHT 240 -#define TFT_PIXEL_OFFSET_X 32 -#define TFT_PIXEL_OFFSET_Y 32 +// Longer/Alfawise TFT +#define LONGER_LK_TFT28 -//#define TFT_DRIVER ILI9341 +// Buffer for Color UI +#define TFT_BUFFER_SIZE 3200 /** * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h index 26a0c9260e03..8831d6804b05 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h @@ -143,8 +143,8 @@ #define LCD_BACKLIGHT_PIN PG11 #define FSMC_CS_PIN PG12 // NE4 #define FSMC_RS_PIN PF0 // A0 - #define TFT_CS_PIN FSMC_CS_PIN - #define TFT_RS_PIN FSMC_RS_PIN + #define TFT_CS_PIN FSMC_CS_PIN + #define TFT_RS_PIN FSMC_RS_PIN #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT #define FSMC_DMA_DEV DMA2 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index d9ba4e3c408b..94a28953ccf3 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -290,6 +290,7 @@ #define TFT_BUFFER_SIZE 14400 #endif +// XPT2046 Touch Screen calibration #if EITHER(HAS_TFT_LVGL_UI, TFT_480x320_SPI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17253 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 35909ed43080..16d6d2ffc442 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -171,6 +171,9 @@ // Shared FSMC Configs #if HAS_FSMC_TFT + #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h + #define DOGLCD_SCK -1 + #define FSMC_CS_PIN PD7 // NE4 #define FSMC_RS_PIN PD11 // A0 @@ -179,9 +182,6 @@ #define TOUCH_MISO_PIN PB14 // SPI2_MISO #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI - #define LCD_RESET_PIN PC6 // FSMC_RST - #define LCD_BACKLIGHT_PIN PD13 - #define TFT_RESET_PIN PC6 // FSMC_RST #define TFT_BACKLIGHT_PIN PD13 @@ -193,60 +193,11 @@ #define TOUCH_BUTTONS_HW_SPI #define TOUCH_BUTTONS_HW_SPI_DEVICE 2 -#endif - -#if ENABLED(FSMC_GRAPHICAL_TFT) - // Emulated DOGM - #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h - #define DOGLCD_SCK -1 - - #ifndef GRAPHICAL_TFT_UPSCALE - #define GRAPHICAL_TFT_UPSCALE 3 - #endif - #ifndef TFT_WIDTH - #define TFT_WIDTH 480 - #endif - #ifndef TFT_PIXEL_OFFSET_X - #define TFT_PIXEL_OFFSET_X 48 - #endif - #ifndef TFT_HEIGHT - #define TFT_HEIGHT 320 - #endif - #ifndef TFT_PIXEL_OFFSET_Y - #define TFT_PIXEL_OFFSET_Y 32 - #endif - -#elif ENABLED(TFT_320x240) // TFT32/28 - #define TFT_RESET_PIN PC6 - #define TFT_BACKLIGHT_PIN PD13 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - - #define 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 TFT_DRIVER ILI9341 - #define TFT_BUFFER_SIZE 14400 - - // YV for normal screen mounting - //#define ILI9341_ORIENTATION ILI9341_MADCTL_MY | ILI9341_MADCTL_MV - // XV for 180° rotated screen mounting - #define ILI9341_ORIENTATION ILI9341_MADCTL_MX | ILI9341_MADCTL_MV - - #define ILI9341_COLOR_RGB -#elif ENABLED(TFT_480x320) - #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 - #define ILI9488_ORIENTATION ILI9488_MADCTL_MX | ILI9488_MADCTL_MV #endif +// XPT2046 Touch Screen calibration #if EITHER(TFT_LVGL_UI_FSMC, TFT_480x320) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION 17880 @@ -260,7 +211,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET 349 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION 12149 #endif @@ -273,7 +224,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET 256 #endif -#elif ENABLED(TFT_320x240) // TFT32/28 +#elif ENABLED(TFT_320x240) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12246 #endif 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 b40c66496af6..846fe80a08fa 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -269,19 +269,11 @@ #define TOUCH_BUTTONS_HW_SPI #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 - #ifndef TFT_WIDTH - #define TFT_WIDTH 480 - #endif - #ifndef TFT_HEIGHT - #define TFT_HEIGHT 320 - #endif - - #define LCD_READ_ID 0xD3 #define LCD_USE_DMA_SPI #endif -#if ENABLED(SPI_GRAPHICAL_TFT) +#if ENABLED(TFT_CLASSIC_UI) // Emulated DOGM SPI #ifndef GRAPHICAL_TFT_UPSCALE #define GRAPHICAL_TFT_UPSCALE 3 @@ -297,12 +289,12 @@ #define LCD_PINS_ENABLE PD13 #define LCD_PINS_RS PC6 -#elif ENABLED(TFT_480x320_SPI) - #define TFT_DRIVER ST7796 +#elif ENABLED(TFT_COLOR_UI) #define TFT_BUFFER_SIZE 14400 #endif -#if EITHER(TFT_LVGL_UI_SPI, TFT_480x320_SPI) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17253 #endif @@ -315,7 +307,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -24 #endif -#elif ENABLED(SPI_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -11386 #endif diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index 4745641ea934..bfd1f2abdcbd 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -120,14 +120,50 @@ * Setting an 'LCD_RESET_PIN' may cause a flicker when entering the LCD menu * because Marlin uses the reset as a failsafe to revive a glitchy LCD. */ -#define LCD_RESET_PIN PF11 -#define LCD_BACKLIGHT_PIN PD13 -#define FSMC_CS_PIN PD7 // NE4 -#define FSMC_RS_PIN PD11 // A0 - -#define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT -#define FSMC_DMA_DEV DMA2 -#define FSMC_DMA_CHANNEL DMA_CH5 +#if HAS_FSMC_TFT + #define TFT_RESET_PIN PF11 + #define TFT_BACKLIGHT_PIN PD13 + #define FSMC_CS_PIN PD7 // NE4 + #define FSMC_RS_PIN PD11 // A0 + + #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT + #define FSMC_DMA_DEV DMA2 + #define FSMC_DMA_CHANNEL DMA_CH5 + + #define ANYCUBIC_TFT35 +#else + #define LCD_RESET_PIN PF11 + #define LCD_BACKLIGHT_PIN PD13 +#endif + +// XPT2046 Touch Screen calibration +#if ENABLED(TFT_COLOR_UI) || ENABLED(TFT_LVGL_UI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -17181 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 11434 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 501 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -9 + #endif +#elif ENABLED(TFT_CLASSIC_UI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -12316 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 8981 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 340 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -20 + #endif +#endif #if NEED_TOUCH_PINS #define TOUCH_CS_PIN PB7 // SPI2_NSS diff --git a/Marlin/src/pins/teensy4/pins_T41U5XBB.h b/Marlin/src/pins/teensy4/pins_T41U5XBB.h index 830637bebd93..5f62bb05a64b 100644 --- a/Marlin/src/pins/teensy4/pins_T41U5XBB.h +++ b/Marlin/src/pins/teensy4/pins_T41U5XBB.h @@ -85,17 +85,17 @@ #define X_STEP_PIN 2 #define X_DIR_PIN 3 #define X_ENABLE_PIN 10 -//#define X_CS_PIN 30 +//#define X_CS_PIN 30 #define Y_STEP_PIN 4 #define Y_DIR_PIN 5 #define Y_ENABLE_PIN 40 -//#define Y_CS_PIN 31 +//#define Y_CS_PIN 31 #define Z_STEP_PIN 6 #define Z_DIR_PIN 7 #define Z_ENABLE_PIN 39 -//#define Z_CS_PIN 32 +//#define Z_CS_PIN 32 #define E0_STEP_PIN 8 #define E0_DIR_PIN 9 diff --git a/Marlin/src/pins/teensy4/pins_TEENSY41.h b/Marlin/src/pins/teensy4/pins_TEENSY41.h index 31c6fda5c900..21a1ff675f24 100644 --- a/Marlin/src/pins/teensy4/pins_TEENSY41.h +++ b/Marlin/src/pins/teensy4/pins_TEENSY41.h @@ -81,17 +81,17 @@ #define X_STEP_PIN 0 #define X_DIR_PIN 1 #define X_ENABLE_PIN 6 -//#define X_CS_PIN 30 +//#define X_CS_PIN 30 #define Y_STEP_PIN 2 #define Y_DIR_PIN 3 #define Y_ENABLE_PIN 7 -//#define Y_CS_PIN 31 +//#define Y_CS_PIN 31 #define Z_STEP_PIN 4 #define Z_DIR_PIN 5 #define Z_ENABLE_PIN 8 -//#define Z_CS_PIN 32 +//#define Z_CS_PIN 32 #define E0_STEP_PIN 9 #define E0_DIR_PIN 10 @@ -123,8 +123,8 @@ // #define LED_PIN 13 #define SOL0_PIN 28 -//#define PS_ON_PIN 1 -//#define FILWIDTH_PIN 6 // A6 +//#define PS_ON_PIN 1 +//#define FILWIDTH_PIN 6 // A6 #ifndef SDCARD_CONNECTION #define SDCARD_CONNECTION ONBOARD diff --git a/platformio.ini b/platformio.ini index 4c974e5a87bb..9c9460d1a32a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ include_dir = Marlin # [common] default_src_filter = + - - + - - - - - - + - - - - - - - - - - - - @@ -227,7 +227,7 @@ HAS_WIRED_LCD = src_filter=+ HAS_MARLINUI_HD44780 = src_filter=+ HAS_MARLINUI_U8GLIB = U8glib-HAL@~0.4.1 src_filter=+ -HAS_(FSMC|SPI)_TFT = src_filter=+ + +HAS_(FSMC|SPI)_TFT = src_filter=+ + + HAS_FSMC_TFT = src_filter=+ + HAS_SPI_TFT = src_filter=+ + HAS_GRAPHICAL_TFT = src_filter=+ @@ -909,8 +909,6 @@ build_flags = ${common_stm32f1.build_flags} # # MKS Robin Nano (STM32F103VET6) -# v1.2 - Emulated Graphical 128x64 (DOGM) UI and LVGL UI -# v2.0 - LVGL UI # [env:mks_robin_nano35] platform = ${common_stm32f1.platform} From f5139f8bf433b5c2bfd4022e14e91a51ac46d951 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 12 Oct 2020 14:39:31 -0700 Subject: [PATCH 21/46] Add D100 Watchdog Test (#19697) --- Marlin/src/gcode/gcode_d.cpp | 82 ++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/Marlin/src/gcode/gcode_d.cpp b/Marlin/src/gcode/gcode_d.cpp index 4bc3b6c6c377..1f38a85b9135 100644 --- a/Marlin/src/gcode/gcode_d.cpp +++ b/Marlin/src/gcode/gcode_d.cpp @@ -25,8 +25,10 @@ #include "gcode.h" #include "../module/settings.h" + #include "../module/temperature.h" #include "../libs/hex_print.h" #include "../HAL/shared/eeprom_if.h" + #include "../HAL/shared/Delay.h" /** * Dn: G-code for development and testing @@ -84,40 +86,23 @@ } } break; - case 3: { // D3 Read / Write EEPROM - uint8_t *pointer = parser.hex_adr_val('A'); - uint16_t len = parser.ushortval('C', 1); - uintptr_t addr = (uintptr_t)pointer; - #ifndef MARLIN_EEPROM_SIZE - #define MARLIN_EEPROM_SIZE size_t(E2END + 1) - #endif - NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1)); - NOMORE(len, MARLIN_EEPROM_SIZE - addr); - if (parser.seenval('X')) { - uint16_t val = parser.hex_val('X'); - #if ENABLED(EEPROM_SETTINGS) - persistentStore.access_start(); - while(len--) { - int pos = 0; - persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); - } - SERIAL_EOL(); - persistentStore.access_finish(); - #else - SERIAL_ECHOLN("NO EEPROM"); + #if ENABLED(EEPROM_SETTINGS) + case 3: { // D3 Read / Write EEPROM + uint8_t *pointer = parser.hex_adr_val('A'); + uint16_t len = parser.ushortval('C', 1); + uintptr_t addr = (uintptr_t)pointer; + #ifndef MARLIN_EEPROM_SIZE + #define MARLIN_EEPROM_SIZE size_t(E2END + 1) #endif - } - else { - while (len--) { - // Read bytes from EEPROM + NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1)); + NOMORE(len, MARLIN_EEPROM_SIZE - addr); + if (parser.seenval('X')) { + uint16_t val = parser.hex_val('X'); #if ENABLED(EEPROM_SETTINGS) persistentStore.access_start(); - uint8_t val; while(len--) { int pos = 0; - if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { - print_hex_byte(val); - } + persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); } SERIAL_EOL(); persistentStore.access_finish(); @@ -125,9 +110,28 @@ SERIAL_ECHOLN("NO EEPROM"); #endif } - SERIAL_EOL(); - } - } break; + else { + while (len--) { + // Read bytes from EEPROM + #if ENABLED(EEPROM_SETTINGS) + persistentStore.access_start(); + uint8_t val; + while(len--) { + int pos = 0; + if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { + print_hex_byte(val); + } + } + SERIAL_EOL(); + persistentStore.access_finish(); + #else + SERIAL_ECHOLN("NO EEPROM"); + #endif + } + SERIAL_EOL(); + } + } break; + #endif case 4: { // D4 Read / Write PIN // const uint8_t pin = parser.byteval('P'); @@ -167,6 +171,20 @@ SERIAL_EOL(); } } break; + + case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test) + SERIAL_ECHOLN("Disabling heaters and attempting to trigger Watchdog"); + SERIAL_ECHOLN("(USE_WATCHDOG " TERN(USE_WATCHDOG, "ENABLED", "DISABLED") ")"); + thermalManager.disable_all_heaters(); + delay(1000); // Allow time to print + DISABLE_ISRS(); + // Use a low-level delay that does not rely on interrupts to function + // Do not spin forever, to avoid thermal risks if heaters are enabled and + // watchdog does not work. + DELAY_US(10000000); + ENABLE_ISRS(); + SERIAL_ECHOLN("FAILURE: Watchdog did not trigger board reset."); + } } } From 193c0a52d9f1fbd31e42a29734f551aa26ed269a Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 12 Oct 2020 14:48:04 -0700 Subject: [PATCH 22/46] Add loose soft endstop state, apply to UBL fine-tune (#19681) Co-authored-by: Scott Lahteine --- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 4 ++ Marlin/src/gcode/bedlevel/abl/G29.cpp | 16 +++--- Marlin/src/gcode/bedlevel/mbl/G29.cpp | 16 ++---- Marlin/src/gcode/calibrate/G28.cpp | 5 +- Marlin/src/gcode/calibrate/G34.cpp | 4 +- Marlin/src/gcode/calibrate/G425.cpp | 9 ++-- Marlin/src/gcode/control/M211.cpp | 4 +- Marlin/src/gcode/feature/clean/G12.cpp | 4 +- Marlin/src/lcd/extui/ui_api.cpp | 28 ++-------- Marlin/src/lcd/menu/menu_motion.cpp | 27 ++-------- Marlin/src/lcd/menu/menu_probe_offset.cpp | 8 +-- Marlin/src/lcd/tft/ui_480x320.cpp | 24 ++------- Marlin/src/libs/nozzle.cpp | 2 +- Marlin/src/module/motion.cpp | 21 ++++---- Marlin/src/module/motion.h | 59 ++++++++++++++++----- Marlin/src/module/tool_change.cpp | 8 +-- 16 files changed, 106 insertions(+), 133 deletions(-) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index dc91b7d6b185..e41af9f3cd23 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -1009,6 +1009,8 @@ lcd_mesh_edit_setup(new_z); + SET_SOFT_ENDSTOP_LOOSE(true); + do { idle(); new_z = lcd_mesh_edit(); @@ -1016,6 +1018,8 @@ SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } while (!ui.button_pressed()); + SET_SOFT_ENDSTOP_LOOSE(false); + if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index e9b6e0e3a6db..f7de6c8cee57 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -201,10 +201,6 @@ G29_TYPE GcodeSuite::G29() { ABL_VAR int abl_probe_index; #endif - #if BOTH(HAS_SOFTWARE_ENDSTOPS, PROBE_MANUALLY) - ABL_VAR bool saved_soft_endstops_state = true; - #endif - #if ABL_GRID #if ENABLED(PROBE_MANUALLY) @@ -461,7 +457,7 @@ G29_TYPE GcodeSuite::G29() { // Abort current G29 procedure, go back to idle state if (seenA && g29_in_progress) { SERIAL_ECHOLNPGM("Manual G29 aborted"); - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); set_bed_leveling_enabled(abl_should_enable); g29_in_progress = false; TERN_(LCD_BED_LEVELING, ui.wait_for_move = false); @@ -482,7 +478,7 @@ G29_TYPE GcodeSuite::G29() { if (abl_probe_index == 0) { // For the initial G29 S2 save software endstop state - TERN_(HAS_SOFTWARE_ENDSTOPS, saved_soft_endstops_state = soft_endstops_enabled); + SET_SOFT_ENDSTOP_LOOSE(true); // Move close to the bed before the first point do_blocking_move_to_z(0); } @@ -552,14 +548,14 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(probePos); // Can be used here too! // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false); + SET_SOFT_ENDSTOP_LOOSE(true); G29_RETURN(false); } else { // Leveling done! Fall through to G29 finishing code below SERIAL_ECHOLNPGM("Grid probing done."); // Re-enable software endstops, if needed - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); } #elif ENABLED(AUTO_BED_LEVELING_3POINT) @@ -570,7 +566,7 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(probePos); // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false); + SET_SOFT_ENDSTOP_LOOSE(true); G29_RETURN(false); } else { @@ -578,7 +574,7 @@ G29_TYPE GcodeSuite::G29() { SERIAL_ECHOLNPGM("3-point probing done."); // Re-enable software endstops, if needed - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); if (!dryrun) { vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal(); diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 5da99386adc5..d94c16052bcf 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -61,7 +61,6 @@ inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM(" void GcodeSuite::G29() { static int mbl_probe_index = -1; - TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state); MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport); if (!WITHIN(state, 0, 5)) { @@ -98,26 +97,19 @@ void GcodeSuite::G29() { } // For each G29 S2... if (mbl_probe_index == 0) { - #if HAS_SOFTWARE_ENDSTOPS - // For the initial G29 S2 save software endstop state - saved_soft_endstops_state = soft_endstops_enabled; - #endif // Move close to the bed before the first point do_blocking_move_to_z(0); } else { // Save Z for the previous mesh position mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z); - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); } // If there's another point to sample, move there with optional lift. if (mbl_probe_index < GRID_MAX_POINTS) { - #if HAS_SOFTWARE_ENDSTOPS - // Disable software endstops to allow manual adjustment - // If G29 is not completed, they will not be re-enabled - soft_endstops_enabled = false; - #endif - + // Disable software endstops to allow manual adjustment + // If G29 is left hanging without completion they won't be re-enabled! + SET_SOFT_ENDSTOP_LOOSE(true); mbl.zigzag(mbl_probe_index++, ix, iy); _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] }); } diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 7bc40b2127c4..34209568035d 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -222,8 +222,9 @@ void GcodeSuite::G28() { return; } - // Wait for planner moves to finish! - planner.synchronize(); + planner.synchronize(); // Wait for planner moves to finish! + + SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state // Disable the leveling matrix before homing #if HAS_LEVELING diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp index eb1d32f90927..fd876d3fe9ea 100644 --- a/Marlin/src/gcode/calibrate/G34.cpp +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -40,7 +40,7 @@ void GcodeSuite::G34() { if (homing_needed()) return; - TEMPORARY_SOFT_ENDSTOP_STATE(false); + SET_SOFT_ENDSTOP_LOOSE(true); TEMPORARY_BED_LEVELING_STATE(false); TemporaryGlobalEndstopsState unlock_z(false); @@ -148,6 +148,8 @@ void GcodeSuite::G34() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST)); #endif + + SET_SOFT_ENDSTOP_LOOSE(false); } #endif // MECHANICAL_GANTRY_CALIBRATION diff --git a/Marlin/src/gcode/calibrate/G425.cpp b/Marlin/src/gcode/calibrate/G425.cpp index 746cb108766b..8968f789995f 100644 --- a/Marlin/src/gcode/calibrate/G425.cpp +++ b/Marlin/src/gcode/calibrate/G425.cpp @@ -581,13 +581,12 @@ void GcodeSuite::G425() { GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE)); #endif - TEMPORARY_SOFT_ENDSTOP_STATE(false); - TEMPORARY_BED_LEVELING_STATE(false); - if (homing_needed_error()) return; - measurements_t m; + TEMPORARY_BED_LEVELING_STATE(false); + SET_SOFT_ENDSTOP_LOOSE(true); + measurements_t m; float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN; if (parser.seen('B')) @@ -612,6 +611,8 @@ void GcodeSuite::G425() { else calibrate_all(); + SET_SOFT_ENDSTOP_LOOSE(false); + #ifdef CALIBRATION_SCRIPT_POST GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST)); #endif diff --git a/Marlin/src/gcode/control/M211.cpp b/Marlin/src/gcode/control/M211.cpp index ffad722f3f7a..2049f1eb6955 100644 --- a/Marlin/src/gcode/control/M211.cpp +++ b/Marlin/src/gcode/control/M211.cpp @@ -37,8 +37,8 @@ void GcodeSuite::M211() { l_soft_max = soft_endstop.max.asLogical(); SERIAL_ECHO_START(); SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS); - if (parser.seen('S')) soft_endstops_enabled = parser.value_bool(); - serialprint_onoff(soft_endstops_enabled); + if (parser.seen('S')) soft_endstop._enabled = parser.value_bool(); + serialprint_onoff(soft_endstop._enabled); print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" ")); print_xyz(l_soft_max, PSTR(STR_SOFT_MAX)); } diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp index f91db39703f0..216db5bae374 100644 --- a/Marlin/src/gcode/feature/clean/G12.cpp +++ b/Marlin/src/gcode/feature/clean/G12.cpp @@ -70,9 +70,11 @@ void GcodeSuite::G12() { TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active); #endif - TEMPORARY_SOFT_ENDSTOP_STATE(parser.boolval('E')); + SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E')); nozzle.clean(pattern, strokes, radius, objects, cleans); + + SET_SOFT_ENDSTOP_LOOSE(false); } #endif // NOZZLE_CLEAN_FEATURE diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 0acfc9c025c1..30cf696f3ed7 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -305,27 +305,9 @@ namespace ExtUI { } void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) { - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 @@ -389,8 +371,8 @@ namespace ExtUI { } #if HAS_SOFTWARE_ENDSTOPS - bool getSoftEndstopState() { return soft_endstops_enabled; } - void setSoftEndstopState(const bool value) { soft_endstops_enabled = value; } + bool getSoftEndstopState() { return soft_endstop._enabled; } + void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; } #endif #if HAS_TRINAMIC_CONFIG diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 676ba46ea730..2972920f34a7 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -57,28 +57,9 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); if (ui.encoderPosition && !ui.manual_move.processing) { - - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 @@ -238,7 +219,7 @@ void menu_move() { BACK_ITEM(MSG_MOTION); #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM) - EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled); + EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled); #endif if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) { diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index 87957e6207ef..6b7830b853d8 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -48,16 +48,12 @@ float z_offset_backup, calculated_z_offset; TERN_(HAS_LEVELING, bool leveling_was_active); -TERN_(HAS_SOFTWARE_ENDSTOPS, bool store_soft_endstops_enabled); void prepare_for_calibration() { z_offset_backup = probe.offset.z; // Disable soft endstops for free Z movement - #if HAS_SOFTWARE_ENDSTOPS - store_soft_endstops_enabled = soft_endstops_enabled; - soft_endstops_enabled = false; - #endif + SET_SOFT_ENDSTOP_LOOSE(true); // Disable leveling for raw planner motion #if HAS_LEVELING @@ -68,7 +64,7 @@ void prepare_for_calibration() { void set_offset_and_go_back(const float &z) { probe.offset.z = z; - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = store_soft_endstops_enabled); + SET_SOFT_ENDSTOP_LOOSE(false); TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); ui.goto_previous_screen_no_defer(); } diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 549cbc4d9ba5..3dab9418f5fa 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -813,27 +813,9 @@ static void moveAxis(AxisEnum axis, const int8_t direction) { } if (!ui.manual_move.processing) { - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index f93e5524813a..10021005e5b3 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -161,7 +161,7 @@ Nozzle nozzle; LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ }while(0) - if (soft_endstops_enabled) { + if (soft_endstop.enabled()) { LIMIT_AXIS(x); LIMIT_AXIS(y); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index da1cb173e56c..92712b0c221c 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -534,12 +534,11 @@ void restore_feedrate_and_scaling() { #if HAS_SOFTWARE_ENDSTOPS - bool soft_endstops_enabled = true; - // Software Endstops are based on the configured limits. - axis_limits_t soft_endstop = { + soft_endstops_t soft_endstop = { { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }, - { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } + { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }, + { true, false } }; /** @@ -624,9 +623,9 @@ void restore_feedrate_and_scaling() { #endif - if (DEBUGGING(LEVELING)) - SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); -} + if (DEBUGGING(LEVELING)) + SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); + } /** * Constrain the given coordinates to the software endstops. @@ -636,7 +635,7 @@ void restore_feedrate_and_scaling() { */ void apply_motion_limits(xyz_pos_t &target) { - if (!soft_endstops_enabled) return; + if (!soft_endstop._enabled) return; #if IS_KINEMATIC @@ -688,7 +687,11 @@ void restore_feedrate_and_scaling() { } } -#endif // HAS_SOFTWARE_ENDSTOPS +#else // !HAS_SOFTWARE_ENDSTOPS + + soft_endstops_t soft_endstop; + +#endif // !HAS_SOFTWARE_ENDSTOPS #if !UBL_SEGMENTED diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 2b108b053177..338eb387cf9d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -148,26 +148,61 @@ inline float home_bump_mm(const AxisEnum axis) { constexpr xyz_pos_t hotend_offset[1] = { { 0 } }; #endif -typedef struct { xyz_pos_t min, max; } axis_limits_t; #if HAS_SOFTWARE_ENDSTOPS - extern bool soft_endstops_enabled; - extern axis_limits_t soft_endstop; + + typedef struct { + xyz_pos_t min, max; + struct { + bool _enabled:1; + bool _loose:1; + }; + bool enabled() { return _enabled && !_loose; } + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + amin = -100000; amax = 100000; // "No limits" + #if HAS_SOFTWARE_ENDSTOPS + if (enabled()) switch (axis) { + case X_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x); + TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x); + break; + case Y_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y); + TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y); + break; + case Z_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z); + TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z); + default: break; + } + #endif + } + } soft_endstops_t; + + extern soft_endstops_t soft_endstop; void apply_motion_limits(xyz_pos_t &target); void update_software_endstops(const AxisEnum axis #if HAS_HOTEND_OFFSET , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0 #endif ); - #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable); -#else - constexpr bool soft_endstops_enabled = false; - //constexpr axis_limits_t soft_endstop = { - // { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }, - // { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } }; - #define apply_motion_limits(V) NOOP + #define SET_SOFT_ENDSTOP_LOOSE(loose) (soft_endstop._loose = loose) + +#else // !HAS_SOFTWARE_ENDSTOPS + + typedef struct { + bool enabled() { return false; } + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + // No limits + amin = current_position[axis] - 1000; + amax = current_position[axis] + 1000; + } + } soft_endstops_t; + extern soft_endstops_t soft_endstop; + #define apply_motion_limits(V) NOOP #define update_software_endstops(...) NOOP - #define TEMPORARY_SOFT_ENDSTOP_STATE(...) NOOP -#endif + #define SET_SOFT_ENDSTOP_LOOSE() NOOP + +#endif // !HAS_SOFTWARE_ENDSTOPS void report_real_position(); void report_current_position(); diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 0f823cfbd000..4ab818f41d2e 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -1017,14 +1017,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Raise by a configured distance to avoid workpiece, except with // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead. if (!no_move) { - #if HAS_SOFTWARE_ENDSTOPS - const float maxz = _MIN(soft_endstop.max.z, Z_MAX_POS); - #else - constexpr float maxz = Z_MAX_POS; - #endif + const float newz = current_position.z + _MAX(-diff.z, 0.0); // Check if Z has space to compensate at least z_offset, and if not, just abort now - const float newz = current_position.z + _MAX(-diff.z, 0.0); + const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS); if (newz > maxz) return; current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz); From f9f8fd37debb795cd042975d19aa7f4ec181a23e Mon Sep 17 00:00:00 2001 From: Keith Bennett <13375512+thisiskeithb@users.noreply.github.com> Date: Mon, 12 Oct 2020 14:52:56 -0700 Subject: [PATCH 23/46] Sanity-check mutually-exclusive G34 features (#19706) --- Marlin/src/inc/SanityCheck.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 7acb5e70c994..2cffde0907f7 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2807,6 +2807,10 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #endif #endif +#if BOTH(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) + #error "You cannot use Z_STEPPER_AUTO_ALIGN and MECHANICAL_GANTRY_CALIBRATION at the same time." +#endif + #if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS) #error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration." #endif From 0d9706f1e73de9bee1238e52f06affeb76a73836 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 12 Oct 2020 18:38:07 -0300 Subject: [PATCH 24/46] TFT Refactoring (#19192) * split tft folder in two: tft for color ui; tft_io for shared tft code * after the files got moved, now the code was moved to the right place * classic ui using TFT IO init lcd codes * feature to compile tft_io when enabled * compiling fix * lvgl spi tft working with tft io init codes * there is no need for separeted fsmc and spi class in lvgl anymore, as tft io handle everything * remove debug * base for TFT rotation and mirroring API, and ILI9488 support * ST7796S rotate and mirror support * ST7789V rotate and mirror support * ST7735 rotate and mirror support * ILI9341 rotate and mirror support * ILI9328 rotate and mirror support * R61505 rotate and mirror support * MKS TFT definitions * more configs for mks tfts * update config * naming typo * to configure the user interface * ANYCUBIC_TFT35 * tft configs * support for SSD1963 * tft display types * updated conditionals lcd; first board fully working with the new code - all 3 ui! * compatiblity * changed name * move classic ui file name * rename TURN -> ROTATE * GRAPHICAL_TFT_ROTATE_180 deprecated * first fsmc board fully working - chitu v5 * mks robin nano v1.2 + tft 35 ok! * right pin name * anycubic tft tested in a TRIGORILLA_PRO * chitu v6 * nano 32 tft orientation * mks tft43 * mks tft43 rotation * fixed LONGER LK tft setup * GRAPHICAL_TFT_UPSCALE defined by the display type * better offsets defaults * Update Configuration.h * Update tft_fsmc.cpp * Update Conditionals_LCD.h * Tweak comments * update nano tests * Revert "update nano tests" This reverts commit a071ebbfad30e28855a4a5695ec8a726542a1a65. * default tft * outdated comments * to not break non-vscode builds * upscale tft 35 * support tft 180 rotation for color ui * Each TFT Driver is responsible for its default color mode. * use auto detect in mks displays, because some of them could be shipped with diferent drivers * extra s * unused code * wrong -1 * missing mirror options * Smaller regex pattern * Comment updates * Clean up old defines * Apply pins formatting * GRAPHICAL_TFT_ROTATE_180 => TFT_ROTATE_180 * MKS_ROBIN_TFT_V1_1R * merge fix * correct resolution * auto is default, dont need be there, and it will allow the user to configure it even for named displays * to not use rotation with MKS_ROBIN_TFT_V1_1R * i like () in macros * avoid sleepy commits * default for st7789 is rgb * nano follow up * to allow ili9328 rotation * default is rgb * boards merge follow up * to match bootloader orientation * HAS_TOUCH_XPT2046 is not hal specific anymore * lets not forget LPC * 180 rotation for ili9328 and R61505 * Clean up whitespace Co-authored-by: Scott Lahteine Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 74 ++-- Marlin/Configuration_adv.h | 3 +- Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h | 7 - Marlin/src/HAL/LPC1768/tft/tft_spi.h | 2 +- Marlin/src/HAL/STM32/tft/tft_fsmc.h | 2 +- Marlin/src/HAL/STM32/tft/tft_spi.h | 2 +- Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h | 7 - Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp | 13 - Marlin/src/HAL/STM32F1/tft/tft_fsmc.h | 2 +- Marlin/src/HAL/STM32F1/tft/tft_spi.h | 2 +- Marlin/src/core/macros.h | 6 + Marlin/src/inc/Conditionals_LCD.h | 176 +++++++- Marlin/src/inc/SanityCheck.h | 4 +- ...pp => u8g_dev_tft_upscale_from_128x64.cpp} | 347 +--------------- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp | 146 ++----- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h | 18 +- .../extui/lib/mks_ui/draw_error_message.cpp | 6 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 65 +-- .../extui/lib/mks_ui/mks_hardware_test.cpp | 12 +- Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp | 60 --- Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h | 30 -- .../lib/mks_ui/tft_lvgl_configuration.cpp | 385 +----------------- .../extui/lib/mks_ui/tft_lvgl_configuration.h | 2 +- Marlin/src/lcd/scaled_tft.h | 9 +- Marlin/src/lcd/tft/tft.cpp | 159 +------- Marlin/src/lcd/tft/tft.h | 26 +- Marlin/src/lcd/tft/tft_io.h | 30 -- Marlin/src/lcd/tft/touch.cpp | 4 + Marlin/src/lcd/{tft => tft_io}/ili9328.h | 29 +- Marlin/src/lcd/{tft => tft_io}/ili9341.h | 18 +- Marlin/src/lcd/{tft => tft_io}/ili9488.h | 18 +- Marlin/src/lcd/{tft => tft_io}/r65105.h | 29 +- Marlin/src/lcd/tft_io/ssd1963.h | 131 ++++++ Marlin/src/lcd/{tft => tft_io}/st7735.h | 16 +- Marlin/src/lcd/{tft => tft_io}/st7789v.h | 16 +- Marlin/src/lcd/{tft => tft_io}/st7796s.h | 16 +- Marlin/src/lcd/tft_io/tft_io.cpp | 226 ++++++++++ Marlin/src/lcd/tft_io/tft_io.h | 124 ++++++ Marlin/src/lcd/touch/touch_buttons.cpp | 2 +- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 31 +- Marlin/src/pins/lpc1768/pins_MKS_SBASE.h | 2 +- Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h | 2 +- .../src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h | 2 +- Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h | 4 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 18 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 22 +- .../src/pins/stm32f1/pins_JGAURORA_A5S_A1.h | 2 +- Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h | 11 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h | 4 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h | 1 + Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 61 +-- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 18 +- Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 52 ++- Marlin/src/pins/teensy4/pins_T41U5XBB.h | 6 +- Marlin/src/pins/teensy4/pins_TEENSY41.h | 10 +- platformio.ini | 6 +- 56 files changed, 1000 insertions(+), 1476 deletions(-) rename Marlin/src/lcd/dogm/{u8g_dev_tft_320x240_upscale_from_128x64.cpp => u8g_dev_tft_upscale_from_128x64.cpp} (60%) delete mode 100644 Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp delete mode 100644 Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h delete mode 100644 Marlin/src/lcd/tft/tft_io.h rename Marlin/src/lcd/{tft => tft_io}/ili9328.h (87%) rename Marlin/src/lcd/{tft => tft_io}/ili9341.h (94%) rename Marlin/src/lcd/{tft => tft_io}/ili9488.h (93%) rename Marlin/src/lcd/{tft => tft_io}/r65105.h (87%) create mode 100644 Marlin/src/lcd/tft_io/ssd1963.h rename Marlin/src/lcd/{tft => tft_io}/st7735.h (92%) rename Marlin/src/lcd/{tft => tft_io}/st7789v.h (93%) rename Marlin/src/lcd/{tft => tft_io}/st7796s.h (93%) create mode 100644 Marlin/src/lcd/tft_io/tft_io.cpp create mode 100644 Marlin/src/lcd/tft_io/tft_io.h diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9f92bc4782ed..d32dbbbfb32f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2198,43 +2198,47 @@ //=============================== Graphical TFTs ============================== //============================================================================= -// -// TFT display with optional touch screen -// Color Marlin UI with standard menu system -// -//#define TFT_320x240 -//#define TFT_320x240_SPI -//#define TFT_480x320 -//#define TFT_480x320_SPI - -// -// Skip autodetect and force specific TFT driver -// Mandatory for SPI screens with no MISO line -// Available drivers are: ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488 -// -//#define TFT_DRIVER AUTO - -// -// SPI display (MKS Robin Nano V2.0, MKS Gen L V2.0) -// Upscaled 128x64 Marlin UI -// -//#define SPI_GRAPHICAL_TFT +/** + * TFT Type - Select your Display type + * + * Available options are: + * MKS_TS35_V2_0, + * MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, + * MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R + * TFT_TRONXY_X5SA, ANYCUBIC_TFT35, LONGER_LK_TFT28 + * TFT_GENERIC + * + * For TFT_GENERIC, you need to configure these 3 options: + * Driver: TFT_DRIVER + * Current Drivers are: AUTO, ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488 + * Resolution: TFT_WIDTH and TFT_HEIGHT + * Interface: TFT_INTERFACE_FSMC or TFT_INTERFACE_SPI + */ +//#define TFT_GENERIC -// -// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.) -// Upscaled 128x64 Marlin UI -// -//#define FSMC_GRAPHICAL_TFT +/** + * TFT UI - User Interface Selection. Enable one of the following options: + * + * TFT_CLASSIC_UI - Emulated DOGM - 128x64 Upscaled + * TFT_COLOR_UI - Marlin Default Menus, Touch Friendly, using full TFT capabilities + * TFT_LVGL_UI - A Modern UI using LVGL + * + * For LVGL_UI also copy the 'assets' folder from the build directory to the + * root of your SD card, together with the compiled firmware. + */ +//#define TFT_CLASSIC_UI +//#define TFT_COLOR_UI +//#define TFT_LVGL_UI -// -// TFT LVGL UI -// -// Using default MKS icons and fonts from: https://git.io/JJvzK -// Just copy the 'assets' folder from the build directory to the -// root of your SD card, together with the compiled firmware. -// -//#define TFT_LVGL_UI_FSMC // Robin nano v1.2 uses FSMC -//#define TFT_LVGL_UI_SPI // Robin nano v2.0 uses SPI +/** + * TFT Rotation. Set to one of the following values: + * + * TFT_ROTATE_90, TFT_ROTATE_90_MIRROR_X, TFT_ROTATE_90_MIRROR_Y, + * TFT_ROTATE_180, TFT_ROTATE_180_MIRROR_X, TFT_ROTATE_180_MIRROR_Y, + * TFT_ROTATE_270, TFT_ROTATE_270_MIRROR_X, TFT_ROTATE_270_MIRROR_Y, + * TFT_MIRROR_X, TFT_MIRROR_Y, TFT_NO_ROTATION + */ +//#define TFT_ROTATION TFT_NO_ROTATION //============================================================================= //============================ Other Controllers ============================ diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 59a1813610ff..9c439c90a71f 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1562,10 +1562,9 @@ #endif // -// FSMC / SPI Graphical TFT +// Classic UI Options // #if TFT_SCALED_DOGLCD - //#define GRAPHICAL_TFT_ROTATE_180 //#define TFT_MARLINUI_COLOR 0xFFFF // White //#define TFT_MARLINBG_COLOR 0x0000 // Black //#define TFT_DISABLED_COLOR 0x0003 // Almost black diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h index b9bc0bf82e61..32ef908d633c 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h @@ -24,10 +24,3 @@ #if HAS_FSMC_TFT #error "Sorry! FSMC TFT displays are not current available for HAL/LPC1768." #endif - -// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT - #undef TOUCH_SCREEN - #undef TOUCH_SCREEN_CALIBRATION - #define HAS_TOUCH_XPT2046 1 -#endif diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.h b/Marlin/src/HAL/LPC1768/tft/tft_spi.h index 8d3e3127bbd1..4753fdbae9a0 100644 --- a/Marlin/src/HAL/LPC1768/tft/tft_spi.h +++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.h @@ -36,7 +36,7 @@ #define DATASIZE_8BIT SSP_DATABIT_8 #define DATASIZE_16BIT SSP_DATABIT_16 -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI #define DMA_MINC_ENABLE 1 #define DMA_MINC_DISABLE 0 diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.h b/Marlin/src/HAL/STM32/tft/tft_fsmc.h index 8500fee113eb..cbec7613ef4a 100644 --- a/Marlin/src/HAL/STM32/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.h @@ -38,7 +38,7 @@ #define DATASIZE_8BIT SPI_DATASIZE_8BIT #define DATASIZE_16BIT SPI_DATASIZE_16BIT -#define TFT_IO TFT_FSMC +#define TFT_IO_DRIVER TFT_FSMC #ifdef STM32F1xx #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN) diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.h b/Marlin/src/HAL/STM32/tft/tft_spi.h index 1eed45a709cc..d477b58c004d 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32/tft/tft_spi.h @@ -38,7 +38,7 @@ #define DATASIZE_8BIT SPI_DATASIZE_8BIT #define DATASIZE_16BIT SPI_DATASIZE_16BIT -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI class TFT_SPI { private: diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h index 25110d7c80e4..f52e6fec2b1e 100644 --- a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h @@ -25,10 +25,3 @@ //#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE." #undef SD_CHECK_AND_RETRY #endif - -// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT - #undef TOUCH_SCREEN - #undef TOUCH_SCREEN_CALIBRATION - #define HAS_TOUCH_XPT2046 1 -#endif diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp index 008301d9bc0c..5b52fb416fa3 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp @@ -89,25 +89,12 @@ void TFT_FSMC::Init() { uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN; uint32_t controllerAddress; - #if PIN_EXISTS(TFT_BACKLIGHT) - OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); - #endif - #if ENABLED(LCD_USE_DMA_FSMC) dma_init(FSMC_DMA_DEV); dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM); #endif - #if PIN_EXISTS(TFT_RESET) - OUT_WRITE(TFT_RESET_PIN, HIGH); - delay(100); - #endif - - #if PIN_EXISTS(TFT_BACKLIGHT) - OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); - #endif - struct fsmc_nor_psram_reg_map* fsmcPsramRegion; if (fsmcInit) return; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h index 6fcfea8a1167..11eb1ffa8410 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h @@ -32,7 +32,7 @@ #define DATASIZE_8BIT DMA_SIZE_8BITS #define DATASIZE_16BIT DMA_SIZE_16BITS -#define TFT_IO TFT_FSMC +#define TFT_IO_DRIVER TFT_FSMC typedef struct { __IO uint16_t REG; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h index bb26fc21b64f..da9a8e0c223e 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h @@ -34,7 +34,7 @@ #define DATASIZE_8BIT DATA_SIZE_8BIT #define DATASIZE_16BIT DATA_SIZE_16BIT -#define TFT_IO TFT_SPI +#define TFT_IO_DRIVER TFT_SPI #define DMA_MINC_ENABLE 1 #define DMA_MINC_DISABLE 0 diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 72644b195ccd..21bb32c4cf24 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -452,6 +452,12 @@ #define HAS_ARGS(V...) _BOOL(FIRST(_END_OF_ARGUMENTS_ V)()) #define _END_OF_ARGUMENTS_() 0 + +// Simple Inline IF Macros, friendly to use in other macro definitions +#define IF(O, A, B) ((O) ? (A) : (B)) +#define IF_0(O, A) IF(O, A, 0) +#define IF_1(O, A) IF(O, A, 1) + // // REPEAT core macros. Recurse N times with ascending I. // diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 42d82dcc1066..56ce2ca5ed82 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -311,13 +311,40 @@ #define IS_ULTIPANEL #endif +// Compatibility +#if ENABLED(FSMC_GRAPHICAL_TFT) + #define TFT_CLASSIC_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif ENABLED(SPI_GRAPHICAL_TFT) + #define TFT_CLASSIC_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#elif EITHER(TFT_320x240, TFT_480x320) + #define TFT_COLOR_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif EITHER(TFT_320x240_SPI, TFT_480x320_SPI) + #define TFT_COLOR_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#elif ENABLED(TFT_LVGL_UI_FSMC) + #define TFT_LVGL_UI + #define TFT_INTERFACE_FSMC + #define TFT_GENERIC +#elif ENABLED(TFT_LVGL_UI_SPI) + #define TFT_LVGL_UI + #define TFT_INTERFACE_SPI + #define TFT_GENERIC +#endif + // FSMC/SPI TFT Panels (LVGL) -#if EITHER(TFT_LVGL_UI_SPI, TFT_LVGL_UI_FSMC) +#if ENABLED(TFT_LVGL_UI) #define HAS_TFT_LVGL_UI 1 #endif // FSMC/SPI TFT Panels -#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT) +#if ENABLED(TFT_CLASSIC_UI) #define TFT_SCALED_DOGLCD 1 #endif @@ -325,32 +352,16 @@ #define DOGLCD #define IS_ULTIPANEL #define DELAYED_BACKLIGHT_INIT -#elif ENABLED(TFT_LVGL_UI_SPI) +#elif ENABLED(TFT_LVGL_UI) #define DELAYED_BACKLIGHT_INIT #endif -// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h -#if ANY(TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC, FSMC_GRAPHICAL_TFT) - #define HAS_FSMC_TFT 1 -#elif ANY(TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI, SPI_GRAPHICAL_TFT) - #define HAS_SPI_TFT 1 -#endif - // Color UI -#if ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI) +#if ENABLED(TFT_COLOR_UI) #define HAS_GRAPHICAL_TFT 1 #define IS_ULTIPANEL #endif -// Fewer lines with touch buttons on-screen -#if EITHER(TFT_320x240, TFT_320x240_SPI) - #define HAS_UI_320x240 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) -#elif EITHER(TFT_480x320, TFT_480x320_SPI) - #define HAS_UI_480x320 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) -#endif - /** * I2C Panels */ @@ -810,3 +821,128 @@ #ifndef EXTRUDE_MINTEMP #define EXTRUDE_MINTEMP 170 #endif + +/** + * TFT Displays + * + * Configure parameters for TFT displays: + * - TFT_DEFAULT_ORIENTATION + * - TFT_DRIVER + * - TFT_WIDTH + * - TFT_HEIGHT + * - TFT_INTERFACE_(SPI|FSMC) + * - TFT_COLOR + * - GRAPHICAL_TFT_UPSCALE + */ +#if ENABLED(MKS_TS35_V2_0) + // Most common: ST7796 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY) + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_SPI + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(MKS_ROBIN_TFT24) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT28) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT32) + // Most common: ST7789 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT35) + // Most common: ILI9488 + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(MKS_ROBIN_TFT43) + #define TFT_DEFAULT_ORIENTATION 0 + #define TFT_DRIVER SSD1963 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 272 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(MKS_ROBIN_TFT_V1_1R) + // ILI9328 or R61505 + #define TFT_DEFAULT_ORIENTATION (TFT_INVERT_X | TFT_INVERT_Y | TFT_EXCHANGE_XY) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_DRIVER ILI9488 + #define TFT_WIDTH 480 + #define TFT_HEIGHT 320 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 3 +#elif ENABLED(LONGER_LK_TFT28) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) + #define TFT_WIDTH 320 + #define TFT_HEIGHT 240 + #define TFT_INTERFACE_FSMC + #define GRAPHICAL_TFT_UPSCALE 2 +#elif ENABLED(TFT_GENERIC) + #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y) +#endif + +// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h +#if ENABLED(TFT_INTERFACE_FSMC) + #define HAS_FSMC_TFT 1 + #if ENABLED(TFT_CLASSIC_UI) + #define FSMC_GRAPHICAL_TFT + #elif ENABLED(TFT_LVGL_UI) + #define TFT_LVGL_UI_FSMC + #endif +#elif ENABLED(TFT_INTERFACE_SPI) + #define HAS_SPI_TFT 1 + #if ENABLED(TFT_CLASSIC_UI) + #define SPI_GRAPHICAL_TFT + #elif ENABLED(TFT_LVGL_UI) + #define TFT_LVGL_UI_SPI + #endif +#endif + +#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_320x240_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_320x240 + #endif +#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x320_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x320 + #endif +#endif + +// Fewer lines with touch buttons on-screen +#if EITHER(TFT_320x240, TFT_320x240_SPI) + #define HAS_UI_320x240 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) +#elif EITHER(TFT_480x320, TFT_480x320_SPI) + #define HAS_UI_480x320 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) +#endif + +// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' +#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT + #undef TOUCH_SCREEN + #undef TOUCH_SCREEN_CALIBRATION + #define HAS_TOUCH_XPT2046 1 +#endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c4dcfd54ae82..7e3b6724d035 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -447,8 +447,6 @@ #error "POWER_SUPPLY is now obsolete. Please remove it from Configuration.h." #elif defined(MKS_ROBIN_TFT) #error "MKS_ROBIN_TFT is now FSMC_GRAPHICAL_TFT. Please update your configuration." -#elif defined(TFT_LVGL_UI) - #error "TFT_LVGL_UI is now TFT_LVGL_UI_FSMC. Please update your configuration." #elif defined(SDPOWER) #error "SDPOWER is now SDPOWER_PIN. Please update your configuration and/or pins." #elif defined(STRING_SPLASH_LINE1) || defined(STRING_SPLASH_LINE2) @@ -535,6 +533,8 @@ #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h." #elif defined(EVENT_GCODE_SD_STOP) #error "EVENT_GCODE_SD_STOP is now EVENT_GCODE_SD_ABORT. Please update your Configuration.h." +#elif defined(GRAPHICAL_TFT_ROTATE_180) + #error "GRAPHICAL_TFT_ROTATE_180 is now TFT_ROTATION set to TFT_ROTATE_180. Please update your Configuration.h." #elif defined(FIL_RUNOUT_INVERTING) #if FIL_RUNOUT_INVERTING #error "FIL_RUNOUT_INVERTING true is now FIL_RUNOUT_STATE HIGH. Please update your Configuration.h." diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp similarity index 60% rename from Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp rename to Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 0f53e45a27b5..d18b617987cb 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -66,12 +66,7 @@ #define HAS_LCD_IO 1 #endif -#if ENABLED(SPI_GRAPHICAL_TFT) - #include HAL_PATH(../../HAL, tft/tft_spi.h) -#elif ENABLED(FSMC_GRAPHICAL_TFT) - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) -#endif - +#include "../tft_io/tft_io.h" TFT_IO tftio; #define WIDTH LCD_PIXEL_WIDTH @@ -132,299 +127,10 @@ TFT_IO tftio; #define TFT_BTOKMENU_COLOR COLOR_RED #endif -static uint32_t lcd_id = 0; - -#define ST7789V_CASET 0x2A /* Column address register */ -#define ST7789V_RASET 0x2B /* Row address register */ -#define ST7789V_WRITE_RAM 0x2C /* Write data to GRAM */ - - -/* Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X */ -#define ILI9328_HASET 0x20 /* Horizontal GRAM address register (0-255) */ -#define ILI9328_VASET 0x21 /* Vertical GRAM address register (0-511)*/ -#define ILI9328_WRITE_RAM 0x22 /* Write data to GRAM */ - -#define ILI9328_HASTART 0x50 /* Horizontal address start position (0-255) */ -#define ILI9328_HAEND 0x51 /* Horizontal address end position (0-255) */ -#define ILI9328_VASTART 0x52 /* Vertical address start position (0-511) */ -#define ILI9328_VAEND 0x53 /* Vertical address end position (0-511) */ - -static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #if HAS_LCD_IO - tftio.DataTransferBegin(DATASIZE_8BIT); - #define IO_REG_DATA(R,D) do { tftio.WriteReg(R); tftio.WriteData(D); }while(0) - #else - #define IO_REG_DATA(R,D) do { u8g_WriteByte(u8g, dev, R); u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&D); }while(0) - #endif - - #if NONE(LCD_USE_DMA_FSMC, LCD_USE_DMA_SPI) - u8g_SetAddress(u8g, dev, 0); - #endif - - IO_REG_DATA(ILI9328_HASTART, Ymin); - IO_REG_DATA(ILI9328_HAEND, Ymax); - IO_REG_DATA(ILI9328_VASTART, Xmin); - IO_REG_DATA(ILI9328_VAEND, Xmax); - - IO_REG_DATA(ILI9328_HASET, Ymin); - IO_REG_DATA(ILI9328_VASET, Xmin); - - #if HAS_LCD_IO - tftio.WriteReg(ILI9328_WRITE_RAM); - tftio.DataTransferEnd(); - #else - u8g_WriteByte(u8g, dev, ILI9328_WRITE_RAM); - u8g_SetAddress(u8g, dev, 1); - #endif -} - -static void setWindow_st7789v(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #if HAS_LCD_IO - tftio.DataTransferBegin(DATASIZE_8BIT); - tftio.WriteReg(ST7789V_CASET); - tftio.WriteData((Xmin >> 8) & 0xFF); - tftio.WriteData(Xmin & 0xFF); - tftio.WriteData((Xmax >> 8) & 0xFF); - tftio.WriteData(Xmax & 0xFF); - - tftio.WriteReg(ST7789V_RASET); - tftio.WriteData((Ymin >> 8) & 0xFF); - tftio.WriteData(Ymin & 0xFF); - tftio.WriteData((Ymax >> 8) & 0xFF); - tftio.WriteData(Ymax & 0xFF); - - tftio.WriteReg(ST7789V_WRITE_RAM); - tftio.DataTransferEnd(); - #else - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_CASET); u8g_SetAddress(u8g, dev, 1); - u8g_WriteByte(u8g, dev, (Xmin >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Xmin & 0xFF); - u8g_WriteByte(u8g, dev, (Xmax >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Xmax & 0xFF); - - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_RASET); u8g_SetAddress(u8g, dev, 1); - u8g_WriteByte(u8g, dev, (Ymin >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Ymin & 0xFF); - u8g_WriteByte(u8g, dev, (Ymax >> 8) & 0xFF); - u8g_WriteByte(u8g, dev, Ymax & 0xFF); - - u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_WRITE_RAM); u8g_SetAddress(u8g, dev, 1); - #endif +static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { + tftio.set_window(Xmin, Ymin, Xmax, Ymax); } -static void setWindow_none(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {} -void (*setWindow)(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) = setWindow_none; - -#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x -#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) -#define ESC_END 0xFFFF, 0x7FFF -#define ESC_FFFF 0xFFFF, 0xFFFF - -#if HAS_LCD_IO - void writeEscSequence(const uint16_t *sequence) { - uint16_t data; - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - tftio.WriteData(data); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - tftio.WriteData(data); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - tftio.WriteReg(data); - } - } - } - #define WRITE_ESC_SEQUENCE(V) writeEscSequence(V) - #define WRITE_ESC_SEQUENCE16(V) writeEscSequence(V) -#else - void writeEscSequence8(u8g_t *u8g, u8g_dev_t *dev, const uint16_t *sequence) { - uint16_t data; - u8g_SetAddress(u8g, dev, 1); - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - u8g_WriteByte(u8g, dev, data & 0xFF); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - u8g_WriteByte(u8g, dev, data & 0xFF); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - u8g_SetAddress(u8g, dev, 0); - u8g_WriteByte(u8g, dev, data & 0xFF); - u8g_SetAddress(u8g, dev, 1); - } - } - } - - #define WRITE_ESC_SEQUENCE(V) writeEscSequence8(u8g, dev, V) - - void writeEscSequence16(u8g_t *u8g, u8g_dev_t *dev, const uint16_t *sequence) { - uint16_t data; - u8g_SetAddress(u8g, dev, 0); - for (;;) { - data = *sequence++; - if (data != 0xFFFF) { - u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&data); - continue; - } - data = *sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) { - u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&data); - } else if (data & 0x8000) { - delay(data & 0x7FFF); - } else if ((data & 0xFF00) == 0) { - u8g_WriteByte(u8g, dev, data & 0xFF); - } - } - u8g_SetAddress(u8g, dev, 1); - } - - #define WRITE_ESC_SEQUENCE16(V) writeEscSequence16(u8g, dev, V) -#endif - -static const uint16_t st7789v_init[] = { - ESC_REG(0x0010), ESC_DELAY(10), - ESC_REG(0x0001), ESC_DELAY(200), - ESC_REG(0x0011), ESC_DELAY(120), - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x0060, 0x00A0), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x002A), 0x0000, 0x0000, 0x0001, 0x003F, - ESC_REG(0x002B), 0x0000, 0x0000, 0x0000, 0x00EF, - ESC_REG(0x00B2), 0x000C, 0x000C, 0x0000, 0x0033, 0x0033, - ESC_REG(0x00B7), 0x0035, - ESC_REG(0x00BB), 0x001F, - ESC_REG(0x00C0), 0x002C, - ESC_REG(0x00C2), 0x0001, 0x00C3, - ESC_REG(0x00C4), 0x0020, - ESC_REG(0x00C6), 0x000F, - ESC_REG(0x00D0), 0x00A4, 0x00A1, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_END -}; - -static const uint16_t ili9328_init[] = { - ESC_REG(0x0001), 0x0100, - ESC_REG(0x0002), 0x0400, - ESC_REG(0x0003), 0x1038, - ESC_REG(0x0004), 0x0000, - ESC_REG(0x0008), 0x0202, - ESC_REG(0x0009), 0x0000, - ESC_REG(0x000A), 0x0000, - ESC_REG(0x000C), 0x0000, - ESC_REG(0x000D), 0x0000, - ESC_REG(0x000F), 0x0000, - ESC_REG(0x0010), 0x0000, - ESC_REG(0x0011), 0x0007, - ESC_REG(0x0012), 0x0000, - ESC_REG(0x0013), 0x0000, - ESC_REG(0x0007), 0x0001, - ESC_DELAY(200), - ESC_REG(0x0010), 0x1690, - ESC_REG(0x0011), 0x0227, - ESC_DELAY(50), - ESC_REG(0x0012), 0x008C, - ESC_DELAY(50), - ESC_REG(0x0013), 0x1500, - ESC_REG(0x0029), 0x0004, - ESC_REG(0x002B), 0x000D, - ESC_DELAY(50), - ESC_REG(0x0050), 0x0000, - ESC_REG(0x0051), 0x00EF, - ESC_REG(0x0052), 0x0000, - ESC_REG(0x0053), 0x013F, - ESC_REG(0x0020), 0x0000, - ESC_REG(0x0021), 0x0000, - ESC_REG(0x0060), 0x2700, - ESC_REG(0x0061), 0x0001, - ESC_REG(0x006A), 0x0000, - ESC_REG(0x0080), 0x0000, - ESC_REG(0x0081), 0x0000, - ESC_REG(0x0082), 0x0000, - ESC_REG(0x0083), 0x0000, - ESC_REG(0x0084), 0x0000, - ESC_REG(0x0085), 0x0000, - ESC_REG(0x0090), 0x0010, - ESC_REG(0x0092), 0x0600, - ESC_REG(0x0007), 0x0133, - ESC_REG(0x0022), - ESC_END -}; - -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, 0x0028, 0x00E8), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x002A), 0x0000, 0x0000, 0x0001, 0x003F, - ESC_REG(0x002B), 0x0000, 0x0000, 0x0000, 0x00EF, - ESC_REG(0x00C5), 0x003E, 0x0028, - ESC_REG(0x00C7), 0x0086, - ESC_REG(0x00B1), 0x0000, 0x0018, - ESC_REG(0x00C0), 0x0023, - ESC_REG(0x00C1), 0x0010, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - -static const uint16_t ili9488_init[] = { - ESC_REG(0x00E0), 0x0000, 0x0007, 0x000F, 0x000D, 0x001B, 0x000A, 0x003C, 0x0078, 0x004A, 0x0007, 0x000E, 0x0009, 0x001B, 0x001E, 0x000F, - ESC_REG(0x00E1), 0x0000, 0x0022, 0x0024, 0x0006, 0x0012, 0x0007, 0x0036, 0x0047, 0x0047, 0x0006, 0x000A, 0x0007, 0x0030, 0x0037, 0x000F, - ESC_REG(0x00C0), 0x0010, 0x0010, - ESC_REG(0x00C1), 0x0041, - ESC_REG(0x00C5), 0x0000, 0x0022, 0x0080, - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x00A8, 0x0068), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x00B0), 0x0000, - ESC_REG(0x00B1), 0x00B0, 0x0011, - ESC_REG(0x00B4), 0x0002, - ESC_REG(0x00B6), 0x0002, 0x0042, - ESC_REG(0x00B7), 0x00C6, - ESC_REG(0x00E9), 0x0000, - ESC_REG(0x00F0), 0x00A9, 0x0051, 0x002C, 0x0082, - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - -static const uint16_t st7796_init[] = { - ESC_REG(0x0010), ESC_DELAY(120), - ESC_REG(0x0001), ESC_DELAY(120), - ESC_REG(0x0011), ESC_DELAY(120), - ESC_REG(0x00F0), 0x00C3, - ESC_REG(0x00F0), 0x0096, - ESC_REG(0x0036), TERN(GRAPHICAL_TFT_ROTATE_180, 0x00E8, 0x0028), - ESC_REG(0x003A), 0x0055, - ESC_REG(0x00B4), 0x0001, - ESC_REG(0x00B7), 0x00C6, - ESC_REG(0x00E8), 0x0040, 0x008A, 0x0000, 0x0000, 0x0029, 0x0019, 0x00A5, 0x0033, - ESC_REG(0x00C1), 0x0006, - ESC_REG(0x00C2), 0x00A7, - ESC_REG(0x00C5), 0x0018, - ESC_REG(0x00E0), 0x00F0, 0x0009, 0x000B, 0x0006, 0x0004, 0x0015, 0x002F, 0x0054, 0x0042, 0x003C, 0x0017, 0x0014, 0x0018, 0x001B, - ESC_REG(0x00E1), 0x00F0, 0x0009, 0x000B, 0x0006, 0x0004, 0x0003, 0x002D, 0x0043, 0x0042, 0x003B, 0x0016, 0x0014, 0x0017, 0x001B, - ESC_REG(0x00F0), 0x003C, - ESC_REG(0x00F0), 0x0069, ESC_DELAY(120), - ESC_REG(0x0029), - ESC_REG(0x0011), - ESC_DELAY(100), - ESC_END -}; - #if HAS_TOUCH_XPT2046 static const uint8_t buttonD[] = { @@ -640,43 +346,9 @@ 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, &lcd_id); - tftio.DataTransferBegin(DATASIZE_8BIT); - switch (lcd_id & 0xFFFF) { - case 0x8552: // ST7789V - WRITE_ESC_SEQUENCE(st7789v_init); - setWindow = setWindow_st7789v; - break; - case 0x9328: // ILI9328 - WRITE_ESC_SEQUENCE16(ili9328_init); - 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; - break; - case 0x7796: - WRITE_ESC_SEQUENCE(st7796_init); - setWindow = setWindow_st7789v; - break; - case 0x9488: - WRITE_ESC_SEQUENCE(ili9488_init); - setWindow = setWindow_st7789v; - case 0x0404: // No connected display on FSMC - lcd_id = 0; - return 0; - case 0xFFFF: // No connected display on SPI - lcd_id = 0; - return 0; - default: - setWindow = (lcd_id & 0xFF000000) ? setWindow_st7789v : setWindow_ili9328; - break; - } - tftio.DataTransferEnd(); + dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL); + tftio.Init(); + tftio.InitTFT(); if (preinit) { preinit = false; @@ -771,14 +443,7 @@ uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_p case U8G_COM_MSG_STOP: break; case U8G_COM_MSG_INIT: u8g_SetPIOutput(u8g, U8G_PI_RESET); - u8g_Delay(50); - - tftio.Init(); - - if (arg_ptr) { - *((uint32_t *)arg_ptr) = tftio.GetID(); - } isCommand = 0; break; 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 351d033d01ec..394ce4807572 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp @@ -22,7 +22,7 @@ #include "../../../../inc/MarlinConfigPre.h" -#if ENABLED(TFT_LVGL_UI_SPI) +#if HAS_TFT_LVGL_UI #include "SPI_TFT.h" #include "pic_manager.h" @@ -32,6 +32,8 @@ #include +#include "draw_ui.h" + TFT SPI_TFT; // use SPI1 for the spi tft. @@ -39,142 +41,48 @@ void TFT::spi_init(uint8_t spiRate) { tftio.Init(); } -void TFT::LCD_WR_REG(uint8_t cmd) { - tftio.WriteReg(cmd); -} - -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; - SetWindows(x, y, 1, 1); + setWindow(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); - LCD_WR_DATA((x + with - 1) >> 8); - LCD_WR_DATA((x + with - 1)); - - LCD_WR_REG(0x2B); - LCD_WR_DATA(y >> 8); - 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::setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { + tftio.set_window(x, y, (x + with - 1), (y + height - 1)); } void TFT::LCD_init() { - TFT_BLK_L; - TFT_RST_H; - delay(150); - TFT_RST_L; - delay(150); - TFT_RST_H; - - tftio.DataTransferBegin(DATASIZE_8BIT); - - delay(120); - LCD_WR_REG(0x11); - delay(120); - - LCD_WR_REG(0xF0); - LCD_WR_DATA(0xC3); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x96); - - LCD_WR_REG(0x36); - LCD_WR_DATA(0x28 + TERN0(GRAPHICAL_TFT_ROTATE_180, 0x80)); - LCD_WR_REG(0x3A); - LCD_WR_DATA(0x55); - - LCD_WR_REG(0xB4); - LCD_WR_DATA(0x01); - LCD_WR_REG(0xB7); - LCD_WR_DATA(0xC6); - LCD_WR_REG(0xE8); - LCD_WR_DATA(0x40); - LCD_WR_DATA(0x8A); - LCD_WR_DATA(0x00); - LCD_WR_DATA(0x00); - LCD_WR_DATA(0x29); - LCD_WR_DATA(0x19); - LCD_WR_DATA(0xA5); - LCD_WR_DATA(0x33); - LCD_WR_REG(0xC1); - LCD_WR_DATA(0x06); - LCD_WR_REG(0xC2); - LCD_WR_DATA(0xA7); - LCD_WR_REG(0xC5); - LCD_WR_DATA(0x18); - LCD_WR_REG(0xE0); // Positive Voltage Gamma Control - LCD_WR_DATA(0xF0); - LCD_WR_DATA(0x09); - LCD_WR_DATA(0x0B); - LCD_WR_DATA(0x06); - LCD_WR_DATA(0x04); - LCD_WR_DATA(0x15); - LCD_WR_DATA(0x2F); - LCD_WR_DATA(0x54); - LCD_WR_DATA(0x42); - LCD_WR_DATA(0x3C); - LCD_WR_DATA(0x17); - LCD_WR_DATA(0x14); - LCD_WR_DATA(0x18); - LCD_WR_DATA(0x1B); - LCD_WR_REG(0xE1); // Negative Voltage Gamma Control - LCD_WR_DATA(0xF0); - LCD_WR_DATA(0x09); - LCD_WR_DATA(0x0B); - LCD_WR_DATA(0x06); - LCD_WR_DATA(0x04); - LCD_WR_DATA(0x03); - LCD_WR_DATA(0x2D); - LCD_WR_DATA(0x43); - LCD_WR_DATA(0x42); - LCD_WR_DATA(0x3B); - LCD_WR_DATA(0x16); - LCD_WR_DATA(0x14); - LCD_WR_DATA(0x17); - LCD_WR_DATA(0x1B); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x3C); - LCD_WR_REG(0xF0); - LCD_WR_DATA(0x69); - delay(120); // Delay 120ms - LCD_WR_REG(0x29); // Display ON - - tftio.DataTransferEnd(); - - LCD_clear(0x0000); // + tftio.InitTFT(); + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, LOW); + #endif + delay(100); + LCD_clear(0x0000); LCD_Draw_Logo(); - TFT_BLK_H; - delay(2000); + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + #endif + #if HAS_LOGO_IN_FLASH + delay(2000); + #endif } void TFT::LCD_clear(uint16_t color) { - SetWindows(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1); + setWindow(0, 0, (TFT_WIDTH), (TFT_HEIGHT)); tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT)); } extern unsigned char bmp_public_buf[17 * 1024]; void TFT::LCD_Draw_Logo() { - SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT); - for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); - tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); - } + #if HAS_LOGO_IN_FLASH + setWindow(0, 0, TFT_WIDTH, TFT_HEIGHT); + for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { + Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); + tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); + } + #endif } -#endif // HAS_TFT_LVGL_UI_SPI +#endif // HAS_TFT_LVGL_UI 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 e40039fe8649..696bc16974be 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h @@ -23,29 +23,21 @@ #include "../../inc/MarlinConfigPre.h" -#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 +#if HAS_TFT_LVGL_UI -#define TFT_RST_H OUT_WRITE(TFT_RESET_PIN, HIGH) -#define TFT_RST_L OUT_WRITE(TFT_RESET_PIN, LOW) - -#define TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH) -#define TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW) +#include "../../../tft_io/tft_io.h" class TFT { public: TFT_IO tftio; void spi_init(uint8_t spiRate); - void LCD_WR_REG(uint8_t cmd); - void LCD_WR_DATA(uint8_t data); 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 setWindow(uint16_t x, uint16_t y, uint16_t with, uint16_t height); void LCD_init(); void LCD_clear(uint16_t color); void LCD_Draw_Logo(); }; extern TFT SPI_TFT; + +#endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp index 1bcdccda414a..c21ee3612c3a 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "lv_conf.h" #include "draw_ui.h" @@ -77,7 +75,7 @@ void lv_draw_error_message(PGM_P const msg) { lv_task_handler(); #endif - TERN(TFT_LVGL_UI_SPI, SPI_TFT.LCD_clear, LCD_Clear)(0x0000); + SPI_TFT.LCD_clear(0x0000); if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000); disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000); disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000); 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 458620801b1b..d600b09a5f16 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" @@ -165,7 +163,7 @@ void gCfgItems_init() { W25QXX.SPI_FLASH_BufferWrite((uint8_t *)&custom_gcode_command[4], OTHERS_COMMAND_ADDR_4, 100); } - const byte rot = TERN0(GRAPHICAL_TFT_ROTATE_180, 0xEE); + const byte rot = (TFT_ROTATION & TFT_ROTATE_180) ? 0xEE : 0x00; if (gCfgItems.disp_rotation_180 != rot) { gCfgItems.disp_rotation_180 = rot; update_spi_flash(); @@ -655,12 +653,7 @@ char *creat_title_text() { } card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8); - #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - #else - LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1); - LCD_WriteRAM_Prepare(); - #endif + SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1); j = i = 0; @@ -673,20 +666,11 @@ char *creat_title_text() { } if (j >= 400) break; } - #if ENABLED(TFT_LVGL_UI_SPI) - for (i = 0; i < 400; i += 2) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; - } - SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); - #else - for (i = 0; i < 400;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color; - LCD_IO_WriteData(*p_index); - i += 2; - } - #endif + for (i = 0; i < 400; i += 2) { + p_index = (uint16_t *)(&bmp_public_buf[i]); + if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; + } + SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); #if HAS_BAK_VIEW_IN_FLASH W25QXX.init(SPI_QUARTER_SPEED); if (row < 20) W25QXX.SPI_FLASH_SectorErase(BAK_VIEW_ADDR_TFT35 + row * 4096); @@ -768,7 +752,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.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); + SPI_TFT.setWindow(xpos_pixel, ypos_pixel + row, 200, 1); #else LCD_setWindowArea(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -901,34 +885,9 @@ char *creat_title_text() { default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 8k #endif - #if ENABLED(TFT_LVGL_UI_SPI) - 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; - LCD_setWindowArea(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 - - LCD_WriteRAM_Prepare(); - - 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); - p_index = &temp_p; - } - else { - p_index = (uint16_t *)(&bmp_public_buf[i]); - } - if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; //gCfgItems.preview_bk_color; - LCD_IO_WriteData(*p_index); - i += 2; - } - if (i >= 8000) break; - } - #endif // TFT_LVGL_UI_SPI + SPI_TFT.setWindow(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); + y_off++; } W25QXX.init(SPI_QUARTER_SPEED); 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 eeb6bae706bc..bc329aa82b89 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 @@ -23,9 +23,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" @@ -626,10 +624,8 @@ static const uint16_t ASCII_Table_16x24[] PROGMEM = { void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint16_t bkColor) { for (uint16_t i = 0; i < 24; i++) { const uint16_t tmp_char = pgm_read_word(&ASCII_Table_16x24[((c - 0x20) * 24) + i]); - for (uint16_t j = 0; j < 16; j++) { - TERN(TFT_LVGL_UI_SPI, SPI_TFT.SetPoint, tft_set_point) - (x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor); - } + for (uint16_t j = 0; j < 16; j++) + SPI_TFT.SetPoint(x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor); } } @@ -643,7 +639,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor //static lv_obj_t * scr_test; void disp_assets_update() { - TERN(TFT_LVGL_UI_SPI,, LCD_Clear(0x0000)); + SPI_TFT.LCD_clear(0x0000); disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000); } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp deleted file mode 100644 index 62967b9d8061..000000000000 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "../../../../inc/MarlinConfig.h" - -#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); - } - - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { - tftio.WriteSequence(data, length); - } -#endif // LCD_USE_DMA_FSMC - -#endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h deleted file mode 100644 index b2e19d66f8f8..000000000000 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#ifdef __cplusplus - extern "C" { /* C-declarations for C++ */ -#endif - -#ifdef __cplusplus - } /* C-declarations for C++ */ -#endif 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 49b44799a69f..922848d84f0b 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 @@ -29,9 +29,7 @@ #if HAS_TFT_LVGL_UI -#if ENABLED(TFT_LVGL_UI_SPI) - #include "SPI_TFT.h" -#endif +#include "SPI_TFT.h" #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" @@ -74,24 +72,6 @@ lv_group_t* g; uint16_t DeviceCode = 0x9488; extern uint8_t sel_id; -#define SetCs -#define ClrCs - -#define HDP 799 // Horizontal Display Period -#define HT 1000 // Horizontal Total -#define HPS 51 // LLINE Pulse Start Position -#define LPS 3 // Horizontal Display Period Start Position -#define HPW 8 // LLINE Pulse Width - -#define VDP 479 // Vertical Display Period -#define VT 530 // Vertical Total -#define VPS 24 // LFRAME Pulse Start Position -#define FPS 23 // Vertical Display Period Start Positio -#define VPW 3 // LFRAME Pulse Width - -#define MAX_HZ_POSX HDP+1 -#define MAX_HZ_POSY VDP+1 - extern uint8_t gcode_preview_over, flash_preview_begin, default_preview_flg; uint8_t bmp_public_buf[17 * 1024]; @@ -125,317 +105,7 @@ void SysTick_Callback() { } } -#if DISABLED(TFT_LVGL_UI_SPI) - - extern void LCD_IO_Init(uint8_t cs, uint8_t rs); - extern void LCD_IO_WriteData(uint16_t RegValue); - extern void LCD_IO_WriteReg(uint16_t Reg); - - extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count); - void tft_set_cursor(uint16_t x, uint16_t y) { - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(x >> 8); - LCD_IO_WriteData(x & 0x00FF); - LCD_IO_WriteData(x >> 8); - LCD_IO_WriteData(x & 0x00FF); - //ILI9488_WriteData(0x01); - //ILI9488_WriteData(0xDF); - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(y >> 8); - LCD_IO_WriteData(y & 0x00FF); - LCD_IO_WriteData(y >> 8); - LCD_IO_WriteData(y & 0x00FF); - //ILI9488_WriteData(0x01); - //ILI9488_WriteData(0x3F); - } - - void LCD_WriteRAM_Prepare(void) { - #if 0 - 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 - } - - void tft_set_point(uint16_t x, uint16_t y, uint16_t point) { - //if (DeviceCode == 0x9488) { - if (x > (TFT_WIDTH) || y > (TFT_HEIGHT)) return; - //} - tft_set_cursor(x, y); - - LCD_WriteRAM_Prepare(); - //LCD_WriteRAM(point); - LCD_IO_WriteData(point); - } - - void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue) { - /* Write 16-bit Index, then Write Reg */ - ClrCs - LCD_IO_WriteReg(LCD_Reg); - /* Write 16-bit Reg */ - LCD_IO_WriteData(LCD_RegValue); - SetCs - } - - void LCD_setWindowArea(uint16_t StartX, uint16_t StartY, uint16_t width, uint16_t heigh) { - uint16_t s_h, s_l, e_h, e_l; - uint16_t xEnd, yEnd; - xEnd = StartX + width; - yEnd = StartY + heigh - 1; - if (DeviceCode == 0x8989) { - /*LCD_WriteReg(0x0044, (StartX & 0xFF) | (xEnd << 8)); - LCD_WriteReg(0x0045, StartY); - LCD_WriteReg(0x0046, yEnd);*/ - LCD_WriteReg(0x0044, (StartY & 0xFF) | (yEnd << 8)); - LCD_WriteReg(0x0045, StartX); - LCD_WriteReg(0x0046, xEnd); - } - else if (DeviceCode == 0x9488) { - s_h = (StartX >> 8) & 0x00FF; - s_l = StartX & 0x00FF; - e_h = ((StartX + width - 1) >> 8) & 0x00FF; - e_l = (StartX + width - 1) & 0x00FF; - - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - - s_h = (StartY >> 8) & 0x00FF; - s_l = StartY & 0x00FF; - e_h = ((StartY + heigh - 1) >> 8) & 0x00FF; - e_l = (StartY + heigh - 1) & 0x00FF; - - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - } - else if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x1505)) { - /* LCD_WriteReg(0x0050, StartX); - LCD_WriteReg(0x0052, StartY); - LCD_WriteReg(0x0051, xEnd); - 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, (TFT_HEIGHT) - xEnd); - LCD_WriteReg(0x0053, (TFT_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit - - } - else { - s_h = (StartX >> 8) & 0xFF; - s_l = StartX & 0xFF; - e_h = ((StartX + width - 1) >> 8) & 0xFF; - e_l = (StartX + width - 1) & 0xFF; - - LCD_IO_WriteReg(0x2A); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - - s_h = (StartY >> 8) & 0xFF; - s_l = StartY & 0xFF; - e_h = ((StartY + heigh - 1) >> 8) & 0xFF; - e_l = (StartY + heigh - 1) & 0xFF; - - LCD_IO_WriteReg(0x2B); - LCD_IO_WriteData(s_h); - LCD_IO_WriteData(s_l); - LCD_IO_WriteData(e_h); - LCD_IO_WriteData(e_l); - } - } - - void LCD_Clear(uint16_t Color) { - uint32_t index = 0; - unsigned int count; - - if (DeviceCode == 0x9488) { - tft_set_cursor(0, 0); - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - LCD_WriteRAM_Prepare(); - #ifdef LCD_USE_DMA_FSMC - LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT)); - #else - //index = (TFT_HEIGHT) / 2 * (TFT_WIDTH); - for (index = 0; index < (TFT_HEIGHT) * (TFT_WIDTH); index++) - LCD_IO_WriteData(Color); - #endif - //LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT)); - //while(index --) LCD_IO_WriteData(Color); - } - else if (DeviceCode == 0x5761) { - LCD_IO_WriteReg(0x002A); - LCD_IO_WriteData(0); - LCD_IO_WriteData(0); - LCD_IO_WriteData(HDP >> 8); - LCD_IO_WriteData(HDP & 0x00FF); - LCD_IO_WriteReg(0x002B); - LCD_IO_WriteData(0); - LCD_IO_WriteData(0); - LCD_IO_WriteData(VDP >> 8); - LCD_IO_WriteData(VDP & 0x00FF); - LCD_IO_WriteReg(0x002C); - LCD_IO_WriteReg(0x002C); - for (count = 0; count < (HDP + 1) * (VDP + 1); count++) - LCD_IO_WriteData(Color); - } - else { - tft_set_cursor(0, 0); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (index = 0; index < 76800; index++) - LCD_IO_WriteData(Color); - } - } - - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) - extern TFT_IO tftio; - void fsmc_tft_init() { - uint16_t i; - - TERN_(HAS_LCD_CONTRAST, refresh_contrast()); - - #ifdef LCD_USE_DMA_FSMC - dma_init(FSMC_DMA_DEV); - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM); - #endif - - LCD_IO_Init(FSMC_CS_PIN, FSMC_RS_PIN); - - _delay_ms(5); - - DeviceCode = tftio.GetID() & 0xFFFF; - // Chitu and others - if (DeviceCode == 0x8066) DeviceCode = 0x9488; - - if (DeviceCode == 0x9488) { - LCD_IO_WriteReg(0x00E0); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x000F); - LCD_IO_WriteData(0x000D); - LCD_IO_WriteData(0x001B); - LCD_IO_WriteData(0x000A); - LCD_IO_WriteData(0x003C); - LCD_IO_WriteData(0x0078); - LCD_IO_WriteData(0x004A); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x000E); - LCD_IO_WriteData(0x0009); - LCD_IO_WriteData(0x001B); - LCD_IO_WriteData(0x001E); - LCD_IO_WriteData(0x000F); - - LCD_IO_WriteReg(0x00E1); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0022); - LCD_IO_WriteData(0x0024); - LCD_IO_WriteData(0x0006); - LCD_IO_WriteData(0x0012); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x0036); - LCD_IO_WriteData(0x0047); - LCD_IO_WriteData(0x0047); - LCD_IO_WriteData(0x0006); - LCD_IO_WriteData(0x000A); - LCD_IO_WriteData(0x0007); - LCD_IO_WriteData(0x0030); - LCD_IO_WriteData(0x0037); - LCD_IO_WriteData(0x000F); - - LCD_IO_WriteReg(0x00C0); - LCD_IO_WriteData(0x0010); - LCD_IO_WriteData(0x0010); - - LCD_IO_WriteReg(0x00C1); - LCD_IO_WriteData(0x0041); - - LCD_IO_WriteReg(0x00C5); - LCD_IO_WriteData(0x0000); - LCD_IO_WriteData(0x0022); - LCD_IO_WriteData(0x0080); - - LCD_IO_WriteReg(0x0036); - LCD_IO_WriteData(TERN(GRAPHICAL_TFT_ROTATE_180, 0xE8, 0x0068)); - - LCD_IO_WriteReg(0x003A); //Interface Mode Control - LCD_IO_WriteData(0x0055); - - LCD_IO_WriteReg(0x00B0); //Interface Mode Control - LCD_IO_WriteData(0x0000); - LCD_IO_WriteReg(0x00B1); //Frame rate 70HZ - LCD_IO_WriteData(0x00B0); - LCD_IO_WriteData(0x0011); - LCD_IO_WriteReg(0x00B4); - LCD_IO_WriteData(0x0002); - LCD_IO_WriteReg(0x00B6); //RGB/MCU Interface Control - LCD_IO_WriteData(0x0002); - LCD_IO_WriteData(0x0042); - - LCD_IO_WriteReg(0x00B7); - LCD_IO_WriteData(0x00C6); - - //WriteComm(0xBE); - //WriteData(0x00); - //WriteData(0x04); - - LCD_IO_WriteReg(0x00E9); - LCD_IO_WriteData(0x0000); - - LCD_IO_WriteReg(0x00F7); - LCD_IO_WriteData(0x00A9); - LCD_IO_WriteData(0x0051); - LCD_IO_WriteData(0x002C); - LCD_IO_WriteData(0x0082); - - LCD_IO_WriteReg(0x0011); - for (i = 0; i < 65535; i++) { /* do nothing */ } - LCD_IO_WriteReg(0x0029); - - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - - OUT_WRITE(LCD_BACKLIGHT_PIN, LOW); - LCD_Clear(0x0000); - - TERN_(HAS_LOGO_IN_FLASH, lcd_draw_logo()); - - OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH); - delay(2000); - } - } - - extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); - - void lcd_draw_logo() { - LCD_setWindowArea(0, 0, TFT_WIDTH, TFT_HEIGHT); - LCD_WriteRAM_Prepare(); - - for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2); - #ifdef LCD_USE_DMA_FSMC - LCD_IO_WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH); - #else - int index = 0;,x_off = 0; - for (x_off = 0; x_off < TFT_WIDTH; x_off++) { - LCD_IO_WriteData((uint16_t)bmp_public_buf[index]); - index += 2; - } - #endif - } - } - -#endif // !TFT_LVGL_UI_SPI +extern uint8_t bmp_public_buf[17 * 1024]; void tft_lvgl_init() { @@ -448,12 +118,8 @@ void tft_lvgl_init() { disp_language_init(); //init tft first! - #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - SPI_TFT.LCD_init(); - #else - fsmc_tft_init(); - #endif + SPI_TFT.spi_init(SPI_FULL_SPEED); + SPI_TFT.LCD_init(); //spi_flash_read_test(); #if ENABLED(SDSUPPORT) @@ -548,41 +214,18 @@ 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 i, width, height; - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; + width = area->x2 - area->x1 + 1; + height = area->y2 - area->y1 + 1; - 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); - - #else // !TFT_LVGL_UI_SPI - - #if 1 - uint16_t i, width, height; - //uint16_t clr_temp; - width = area->x2 - area->x1 + 1; - height = area->y2 - area->y1 + 1; - LCD_setWindowArea((uint16_t)area->x1, (uint16_t)area->y1, width, height); - LCD_WriteRAM_Prepare(); - for (i = 0; i < width * height - 2; i++) { - //clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11) - //| ((uint16_t)color_p->ch.green << 5) - //| ((uint16_t)color_p->ch.blue)); - LCD_IO_WriteData(color_p->full); - color_p++; - } - - lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ - #endif + SPI_TFT.setWindow((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*/ - #endif // !TFT_LVGL_UI_SPI + W25QXX.init(SPI_QUARTER_SPEED); } #define TICK_CYCLE 1 @@ -599,7 +242,7 @@ static bool get_point(int16_t *x, int16_t *y) { *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; } - #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + #if (TFT_ROTATION & TFT_ROTATE_180) *x = int16_t((TFT_WIDTH) - (int)(*x)); *y = int16_t((TFT_HEIGHT) - (int)(*y)); #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h index 7e24f948fd09..727ab33aea30 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.h @@ -32,7 +32,7 @@ #include -//#define GRAPHICAL_TFT_ROTATE_180 +//#define TFT_ROTATION TFT_ROTATE_180 #define USE_WIFI_FUNCTION 0 extern void tft_lvgl_init(); diff --git a/Marlin/src/lcd/scaled_tft.h b/Marlin/src/lcd/scaled_tft.h index be846f70a9dd..2c05e5f26d81 100644 --- a/Marlin/src/lcd/scaled_tft.h +++ b/Marlin/src/lcd/scaled_tft.h @@ -43,8 +43,13 @@ #endif #ifndef TFT_PIXEL_OFFSET_X - #define TFT_PIXEL_OFFSET_X 48 + #if GRAPHICAL_TFT_UPSCALE == 2 + #define TFT_PIXEL_OFFSET_X 32 + #else + #define TFT_PIXEL_OFFSET_X 48 + #endif #endif #ifndef TFT_PIXEL_OFFSET_Y - #define TFT_PIXEL_OFFSET_Y 48 + // 32 is better for both 320x240 and 480x320 + #define TFT_PIXEL_OFFSET_Y 32 #endif diff --git a/Marlin/src/lcd/tft/tft.cpp b/Marlin/src/lcd/tft/tft.cpp index 81fe6788e7c7..fa3c2c241f79 100644 --- a/Marlin/src/lcd/tft/tft.cpp +++ b/Marlin/src/lcd/tft/tft.cpp @@ -25,173 +25,16 @@ #if HAS_GRAPHICAL_TFT #include "tft.h" -#include "st7735.h" -#include "st7789v.h" -#include "st7796s.h" -#include "r65105.h" -#include "ili9328.h" -#include "ili9341.h" -#include "ili9488.h" //#define DEBUG_GRAPHICAL_TFT #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) #include "../../core/debug_out.h" uint16_t TFT::buffer[]; -uint32_t TFT::lcd_id = 0xFFFFFFFF; void TFT::init() { - if (lcd_id != 0xFFFFFFFF) return; - io.Init(); - - #if TFT_DRIVER != AUTO - lcd_id = TFT_DRIVER; - #endif - - #if TFT_DRIVER == ST7735 - write_esc_sequence(st7735_init); - #elif TFT_DRIVER == ST7789 - write_esc_sequence(st7789v_init); - #elif TFT_DRIVER == ST7796 - write_esc_sequence(st7796s_init); - #elif TFT_DRIVER == R61505 - write_esc_sequence(r61505_init); - #elif TFT_DRIVER == ILI9328 - write_esc_sequence(ili9328_init); - #elif TFT_DRIVER == ILI9341 - write_esc_sequence(ili9341_init); - #elif TFT_DRIVER == ILI9488 - write_esc_sequence(ili9488_init); - #elif TFT_DRIVER == LERDGE_ST7796 - lcd_id = ST7796; - write_esc_sequence(lerdge_st7796s_init); - - #elif TFT_DRIVER == AUTO // autodetect - - lcd_id = io.GetID() & 0xFFFF; - - switch (lcd_id) { - case ST7796: // ST7796S 480x320 - DEBUG_ECHO_MSG(" ST7796S"); - write_esc_sequence(st7796s_init); - break; - case ST7789: // ST7789V 320x240 - DEBUG_ECHO_MSG(" ST7789V"); - write_esc_sequence(st7789v_init); - break; - case ST7735: // ST7735 160x128 - DEBUG_ECHO_MSG(" ST7735"); - write_esc_sequence(st7735_init); - break; - case R61505: // R61505U 320x240 - DEBUG_ECHO_MSG(" R61505U"); - write_esc_sequence(r61505_init); - break; - case ILI9328: // ILI9328 320x240 - DEBUG_ECHO_MSG(" ILI9328"); - write_esc_sequence(ili9328_init); - break; - case ILI9341: // ILI9341 320x240 - DEBUG_ECHO_MSG(" ILI9341"); - write_esc_sequence(ili9341_init); - break; - case ILI9488: // ILI9488 480x320 - DEBUG_ECHO_MSG(" ILI9488"); - write_esc_sequence(ili9488_init); - break; - default: - lcd_id = 0; - } - #else - #error Unsupported TFT driver - #endif -} - -void TFT::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { - #ifdef OFFSET_X - Xmin += OFFSET_X; Xmax += OFFSET_X; - #endif - #ifdef OFFSET_Y - Ymin += OFFSET_Y; Ymax += OFFSET_Y; - #endif - - switch (lcd_id) { - case ST7735: // ST7735 160x128 - case ST7789: // ST7789V 320x240 - case ST7796: // ST7796 480x320 - case ILI9341: // ILI9341 320x240 - case ILI9488: // ILI9488 480x320 - io.DataTransferBegin(DATASIZE_8BIT); - - // CASET: Column Address Set - io.WriteReg(ILI9341_CASET); - io.WriteData((Xmin >> 8) & 0xFF); - io.WriteData(Xmin & 0xFF); - io.WriteData((Xmax >> 8) & 0xFF); - io.WriteData(Xmax & 0xFF); - - // RASET: Row Address Set - io.WriteReg(ILI9341_PASET); - io.WriteData((Ymin >> 8) & 0xFF); - io.WriteData(Ymin & 0xFF); - io.WriteData((Ymax >> 8) & 0xFF); - io.WriteData(Ymax & 0xFF); - - // RAMWR: Memory Write - io.WriteReg(ILI9341_RAMWR); - break; - case R61505: // R61505U 320x240 - case ILI9328: // ILI9328 320x240 - io.DataTransferBegin(DATASIZE_16BIT); - - // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X - io.WriteReg(ILI9328_HASTART); - io.WriteData(Ymin); - io.WriteReg(ILI9328_HAEND); - io.WriteData(Ymax); - io.WriteReg(ILI9328_VASTART); - io.WriteData(Xmin); - io.WriteReg(ILI9328_VAEND); - io.WriteData(Xmax); - - io.WriteReg(ILI9328_HASET); - io.WriteData(Ymin); - io.WriteReg(ILI9328_VASET); - io.WriteData(Xmin); - - io.WriteReg(ILI9328_RAMWR); - break; - default: - break; - } - - io.DataTransferEnd(); -} - -void TFT::write_esc_sequence(const uint16_t *Sequence) { - uint16_t dataWidth, data; - - dataWidth = *Sequence++; - io.DataTransferBegin(dataWidth); - - for (;;) { - data = *Sequence++; - if (data != 0xFFFF) { - io.WriteData(data); - continue; - } - data = *Sequence++; - if (data == 0x7FFF) return; - if (data == 0xFFFF) - io.WriteData(0xFFFF); - else if (data & 0x8000) - delay(data & 0x7FFF); - else if ((data & 0xFF00) == 0) - io.WriteReg(data); - } - - io.DataTransferEnd(); + io.InitTFT(); } TFT tft; diff --git a/Marlin/src/lcd/tft/tft.h b/Marlin/src/lcd/tft/tft.h index 6d429109c892..ed3d5e35c157 100644 --- a/Marlin/src/lcd/tft/tft.h +++ b/Marlin/src/lcd/tft/tft.h @@ -26,7 +26,7 @@ #include "tft_color.h" #include "tft_string.h" #include "tft_image.h" -#include "tft_io.h" +#include "../tft_io/tft_io.h" #include "../../inc/MarlinConfig.h" @@ -40,20 +40,6 @@ #error "Unsupported display resolution!" #endif -#define ST7735 0x89F0 -#define ST7789 0x8552 -#define ST7796 0x7796 -#define R61505 0x1505 -#define ILI9328 0x9328 -#define ILI9341 0x9341 -#define ILI9488 0x9488 -#define LERDGE_ST7796 0xFFFE -#define AUTO 0xFFFF - -#ifndef TFT_DRIVER - #define TFT_DRIVER AUTO -#endif - #ifndef TFT_BUFFER_SIZE #ifdef STM32F103xB #define TFT_BUFFER_SIZE 1024 @@ -71,14 +57,8 @@ #error "TFT_BUFFER_SIZE can not exceed 65535" #endif -#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x -#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) -#define ESC_END 0xFFFF, 0x7FFF -#define ESC_FFFF 0xFFFF, 0xFFFF - class TFT { private: - static uint32_t lcd_id; static TFT_String string; static TFT_IO io; @@ -91,13 +71,11 @@ class TFT { static inline void set_font(const uint8_t *Font) { string.set_font(Font); } static inline void add_glyphs(const uint8_t *Font) { string.add_glyphs(Font); } - static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax); - static void write_esc_sequence(const uint16_t *Sequence); - static inline bool is_busy() { return io.isBusy(); } static inline void abort() { io.Abort(); } static inline void write_multiple(uint16_t Data, uint16_t Count) { io.WriteMultiple(Data, Count); } static inline void write_sequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); } + static inline void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { io.set_window(Xmin, Ymin, Xmax, Ymax); } static inline void fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color) { queue.fill(x, y, width, height, color); } static inline void canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { queue.canvas(x, y, width, height); } diff --git a/Marlin/src/lcd/tft/tft_io.h b/Marlin/src/lcd/tft/tft_io.h deleted file mode 100644 index bffe92b0ff30..000000000000 --- a/Marlin/src/lcd/tft/tft_io.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include "../../inc/MarlinConfig.h" - -#if HAS_SPI_TFT - #include HAL_PATH(../../HAL, tft/tft_spi.h) -#elif HAS_FSMC_TFT - #include HAL_PATH(../../HAL, tft/tft_fsmc.h) -#endif diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index d19cc4bf1d95..5889ac0a9908 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -283,6 +283,10 @@ bool Touch::get_point(int16_t *x, int16_t *y) { if (is_touched && calibration.orientation != TOUCH_ORIENTATION_NONE) { *x = int16_t((int32_t(*x) * calibration.x) >> 16) + calibration.offset_x; *y = int16_t((int32_t(*y) * calibration.y) >> 16) + calibration.offset_y; + #if (TFT_ROTATION & TFT_ROTATE_180) + *x = TFT_WIDTH - *x; + *y = TFT_HEIGHT - *y; + #endif } return is_touched; } diff --git a/Marlin/src/lcd/tft/ili9328.h b/Marlin/src/lcd/tft_io/ili9328.h similarity index 87% rename from Marlin/src/lcd/tft/ili9328.h rename to Marlin/src/lcd/tft_io/ili9328.h index 85edfa7bee0a..818dd05b348f 100644 --- a/Marlin/src/lcd/tft/ili9328.h +++ b/Marlin/src/lcd/tft_io/ili9328.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -40,8 +40,29 @@ #define ILI9328_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical // MKS Robin TFT v1.1 - 320x240 ; Cable on the left side -#define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS -#define ILI9328_ETMOD_DATA ILI9328_ETMOD_BGR | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0 | ILI9328_ETMOD_AM + +#if TFT_ROTATION == TFT_ROTATE_180 + #define ILI9328_DRVCTL_DATA 0x0000 + #define ILI9328_GATE_SCANCTL1_DATA 0xA700 +#else + #define ILI9328_DRVCTL_DATA ILI9328_DRVCTL_SS + #define ILI9328_GATE_SCANCTL1_DATA 0x2700 +#endif + +// #define ILI9328_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9328_ETMOD_AM) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9328_ETMOD_ID1) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9328_ETMOD_ID0) + +#define ILI9328_ETMOD_ORIENTATION (ILI9328_ETMOD_AM | ILI9328_ETMOD_ID1 | ILI9328_ETMOD_ID0) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9328_ETMOD_COLOR ILI9328_ETMOD_RGB +#endif + +#define ILI9328_ETMOD_DATA (ILI9328_ETMOD_ORIENTATION) | (ILI9328_ETMOD_COLOR) + #define ILI9328_RDDID 0x00 // ID code - 0x9328 #define ILI9328_DRVCTL 0x01 // Driver Output Control @@ -134,7 +155,7 @@ static const uint16_t ili9328_init[] = { ESC_REG(ILI9328_PWCTRL7), 0x0004, ESC_REG(ILI9328_FRMCTR), 0x000D, ESC_DELAY(50), - ESC_REG(ILI9328_GATE_SCANCTL1), 0x2700, + ESC_REG(ILI9328_GATE_SCANCTL1), ILI9328_GATE_SCANCTL1_DATA, ESC_REG(ILI9328_GATE_SCANCTL2), 0x0001, ESC_REG(ILI9328_GATE_SCANCTL3), 0x0000, ESC_REG(ILI9328_PLTPOS1), 0x0000, diff --git a/Marlin/src/lcd/tft/ili9341.h b/Marlin/src/lcd/tft_io/ili9341.h similarity index 94% rename from Marlin/src/lcd/tft/ili9341.h rename to Marlin/src/lcd/tft_io/ili9341.h index d4a493412fb2..dda326df6d5b 100644 --- a/Marlin/src/lcd/tft/ili9341.h +++ b/Marlin/src/lcd/tft_io/ili9341.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,13 +38,17 @@ #define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; Cable on the left side #define ILI9341_ORIENTATION_DOWN ILI9341_MADCTL_MX // 240x320 ; Cable on the upper side -#ifndef ILI9341_COLOR_RGB - #define ILI9341_COLOR_BGR -#endif -#ifndef ILI9341_ORIENTATION - #define ILI9341_ORIENTATION ILI9341_ORIENTATION_LEFT +#define ILI9341_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9341_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9341_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9341_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9341_COLOR ILI9341_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9341_COLOR ILI9341_MADCTL_RGB #endif -#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION | TERN(ILI9341_COLOR_BGR, ILI9341_MADCTL_BGR, ILI9341_MADCTL_RGB)) + +#define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION) | (ILI9341_COLOR) #define ILI9341_NOP 0x00 // No Operation #define ILI9341_SWRESET 0x01 // Software Reset diff --git a/Marlin/src/lcd/tft/ili9488.h b/Marlin/src/lcd/tft_io/ili9488.h similarity index 93% rename from Marlin/src/lcd/tft/ili9488.h rename to Marlin/src/lcd/tft_io/ili9488.h index 19fdc78e0a5e..e71c0d16d775 100644 --- a/Marlin/src/lcd/tft/ili9488.h +++ b/Marlin/src/lcd/tft_io/ili9488.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,13 +38,17 @@ #define ILI9488_ORIENTATION_LEFT ILI9488_MADCTL_MY | ILI9488_MADCTL_MX | ILI9488_MADCTL_MV // 480x320 ; Cable on the left side #define ILI9488_ORIENTATION_DOWN ILI9488_MADCTL_MX // 320x480 ; Cable on the upper side -#ifndef ILI9488_COLOR_RGB - #define ILI9488_COLOR_BGR -#endif -#ifndef ILI9488_ORIENTATION - #define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT +#define ILI9488_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9488_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9488_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ILI9488_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ILI9488_COLOR ILI9488_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ILI9488_COLOR ILI9488_MADCTL_RGB #endif -#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION | TERN(ILI9488_COLOR_BGR, ILI9488_MADCTL_BGR, ILI9488_MADCTL_RGB)) + +#define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION) | (ILI9488_COLOR) #define ILI9488_NOP 0x00 // No Operation #define ILI9488_SWRESET 0x01 // Software Reset diff --git a/Marlin/src/lcd/tft/r65105.h b/Marlin/src/lcd/tft_io/r65105.h similarity index 87% rename from Marlin/src/lcd/tft/r65105.h rename to Marlin/src/lcd/tft_io/r65105.h index 8d073f5d0d1c..a813c3260b1a 100644 --- a/Marlin/src/lcd/tft/r65105.h +++ b/Marlin/src/lcd/tft_io/r65105.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -42,9 +42,28 @@ #define R61505_DRVCTRL_GS 0x8000 // Gate Scan direction // MKS Robin TFT v1.1 - 320x240 ; Cable on the left side -#define R61505_DRVCTL_DATA R61505_DRVCTL_SS -#define R61505_ETMOD_DATA R61505_ETMOD_BGR | R61505_ETMOD_ID1 | R61505_ETMOD_ID0 | R61505_ETMOD_AM -#define R61505_DRVCTRL_GSDIR R61505_DRVCTRL_GS + +#if TFT_ROTATION == TFT_ROTATE_180 + #define R61505_DRVCTL_DATA 0x0000 + #define R61505_DRVCTRL_DATA (0x2700 | R61505_DRVCTRL_GS) +#else + #define R61505_DRVCTL_DATA R61505_DRVCTL_SS + #define R61505_DRVCTRL_DATA 0x2700 +#endif + +// #define R61505_ETMOD_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, R61505_ETMOD_AM) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_X, R61505_ETMOD_ID0) | \ +// IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, R61505_ETMOD_ID1) + +#define R61505_ETMOD_ORIENTATION (R61505_ETMOD_AM | R61505_ETMOD_ID0 | R61505_ETMOD_ID1) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define R61505_ETMOD_COLOR R61505_ETMOD_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define R61505_ETMOD_COLOR R61505_ETMOD_RGB +#endif + +#define R61505_ETMOD_DATA (R61505_ETMOD_ORIENTATION) | (R61505_ETMOD_COLOR) #define R61505_RDDID 0x00 // ID code - 0x1505 @@ -141,7 +160,7 @@ static const uint16_t r61505_init[] = { ESC_REG(R61505_GAMCTRL9), 0x0700, ESC_REG(R61505_GAMCTRLA), 0x0A1F, - ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_GSDIR | 0x2700, + ESC_REG(R61505_DRVCTRL), R61505_DRVCTRL_DATA, ESC_REG(R61505_BASE_IMAGE_CTRL), 0x0001, ESC_REG(R61505_VSCROLL_CTRL), 0x0000, diff --git a/Marlin/src/lcd/tft_io/ssd1963.h b/Marlin/src/lcd/tft_io/ssd1963.h new file mode 100644 index 000000000000..4953a96233e8 --- /dev/null +++ b/Marlin/src/lcd/tft_io/ssd1963.h @@ -0,0 +1,131 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "tft_io.h" + +#include "../../inc/MarlinConfig.h" + +#define SSD1963_MADCTL_MY 0x80 // Row Address Order +#define SSD1963_MADCTL_MX 0x40 // Column Address Order +#define SSD1963_MADCTL_MV 0x20 // Row/Column Exchange +#define SSD1963_MADCTL_MH 0x10 // Horizontal Refresh Order +#define SSD1963_MADCTL_BGR 0x08 // RGB-BGR ORDER +#define SSD1963_MADCTL_RGB 0x00 +#define SSD1963_MADCTL_ML 0x04 // Vertical Refresh Order +#define SSD1963_MADCTL_FH 0x02 // Flip Horizontal +#define SSD1963_MADCTL_FV 0x01 // Flip Vertical + +#define SSD1963_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, SSD1963_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define SSD1963_COLOR SSD1963_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define SSD1963_COLOR SSD1963_MADCTL_RGB +#endif + +#define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR) + +#define SSD1963_NOP 0x00 // No Operation +#define SSD1963_SWRESET 0x01 // Software reset +#define SSD1963_RDDPM 0x0A // Read Display Power Mode +#define SSD1963_RDDMADCTL 0x0B // Read Display MADCTL +#define SSD1963_RDDCOLMOD 0x0C // Read Display Pixel Format +#define SSD1963_RDDIM 0x0D // Read Display Image Mode +#define SSD1963_RDDSM 0x0E // Read Display Signal Mode +#define SSD1963_SLPIN 0x10 // Sleep In +#define SSD1963_SLPOUT 0x11 // Sleep Out +#define SSD1963_PTLON 0x12 // Partial Display Mode On +#define SSD1963_NORON 0x13 // Normal Display Mode On +#define SSD1963_INVOFF 0x20 // Display Inversion Off +#define SSD1963_INVON 0x21 // Display Inversion On +#define SSD1963_GAMSET 0x26 // Gamma Set +#define SSD1963_DISPOFF 0x28 // Display Off +#define SSD1963_DISPON 0x29 // Display On +#define SSD1963_CASET 0x2A // Column Address Set +#define SSD1963_RASET 0x2B // Row Address Set +#define SSD1963_RAMWR 0x2C // Memory Write +#define SSD1963_RAMRD 0x2E // Memory Read +#define SSD1963_PTLAR 0x30 // Partial Area +#define SSD1963_VSCRDEF 0x33 // Vertical Scrolling Definition +#define SSD1963_TEOFF 0x34 // Tearing Effect Line OFF +#define SSD1963_TEON 0x35 // Tearing Effect Line ON +#define SSD1963_MADCTL 0x36 // Memory Data Access Control +#define SSD1963_VSCSAD 0x37 // Vertical Scroll Start Address of RAM +#define SSD1963_IDMOFF 0x38 // Idle Mode Off +#define SSD1963_IDMON 0x39 // Idle Mode On +#define SSD1963_WRMEMC 0x3C // Write Memory Continue +#define SSD1963_RDMEMC 0x3E // Read Memory Continue +#define SSD1963_STE 0x44 // Set Tear Scanline +#define SSD1963_GSCAN 0x45 // Get Scanline +#define SSD1963_WRDISBV 0x51 // Write Display Brightness +#define SSD1963_RDDISBV 0x52 // Read Display Brightness +#define SSD1963_WRCTRLD 0x53 // Write CTRL Display +#define SSD1963_RDCTRLD 0x54 // Read CTRL Value Display +#define SSD1963_WRCACE 0x55 // Write Content Adaptive Brightness Control and Color Enhancement +#define SSD1963_RDCABC 0x56 // Read Content Adaptive Brightness Control +#define SSD1963_WRCABCMB 0x5E // Write CABC Minimum Brightness +#define SSD1963_RDCABCMB 0x5F // Read CABC Minimum Brightness +#define SSD1963_RDABCSDR 0x68 // Read Automatic Brightness Control Self-Diagnostic Result +#define SSD1963_RDDDB 0xA1 // Read Device Descriptor Block +#define SSD1963_SLCDMODE 0xB0 // Set the LCD panel mode and resolution +#define SSD1963_SHSYNC 0xB4 // Set HSYNC +#define SSD1963_GHSYNC 0xB5 // Get HSYNC +#define SSD1963_SVSYNC 0xB6 // Set VSYNC +#define SSD1963_GVSYNC 0xB7 // Get VSYNC +#define SSD1963_SGPIOCFG 0xB8 // Set GPIO Conf +#define SSD1963_SGPIOV 0xBA // Set GPIO Value +#define SSD1963_SPWMCFG 0xBE // Set PWM Conf +#define SSD1963_GPWMCFG 0xBF // Get PWM Conf +#define SSD1963_SDBCCFG 0xD0 // Set Dynamic Back Light Config +#define SSD1963_GDBCCFG 0xD1 // Get Dynamic Back Light Config +#define SSD1963_PLLON 0xE0 // PLL Enable +#define SSD1963_PLLMN 0xE2 // Set PLL Multiplier +#define SSD1963_SLSHIFT 0xE6 // Set the LSHIFT (pixel clock) frequency +#define SSD1963_COLMOD 0xF0 // Interface Pixel Format + +static const uint16_t ssd1963_init[] = { + DATASIZE_8BIT, + ESC_REG(SSD1963_PLLMN), 0x0023, 0x0002, 0x0054, + ESC_REG(SSD1963_PLLON), 0x0001, ESC_DELAY(10), + ESC_REG(SSD1963_PLLON), 0x0003, ESC_DELAY(10), + ESC_REG(SSD1963_SWRESET), ESC_DELAY(100), + + ESC_REG(SSD1963_SLSHIFT), 0x0001, 0x001F, 0x00FF, + ESC_REG(SSD1963_SLCDMODE), 0x0020, 0x0000, 0x0001, 0x00DF, 0x0001, 0x000F, 0x0000, + ESC_REG(SSD1963_SHSYNC), 0x0002, 0x0013, 0x0000, 0x0008, 0x002B, 0x0000, 0x0002, 0x0000, + ESC_REG(SSD1963_SVSYNC), 0x0001, 0x0020, 0x0000, 0x0004, 0x000C, 0x0000, 0x0002, + ESC_REG(SSD1963_SGPIOV), 0x000F, + ESC_REG(SSD1963_SGPIOCFG), 0x0007, 0x0001, + + ESC_REG(SSD1963_MADCTL), SSD1963_MADCTL_DATA, + ESC_REG(SSD1963_COLMOD), 0x0003, ESC_DELAY(1),//RBG 565 + + ESC_REG(SSD1963_NORON), + ESC_REG(SSD1963_DISPON), + + ESC_REG(SSD1963_SPWMCFG), 0x0006, 0x00f0, 0x0001, 0x00f0, 0x0000, 0x0000, + ESC_REG(SSD1963_SDBCCFG), 0x000D, + ESC_END +}; diff --git a/Marlin/src/lcd/tft/st7735.h b/Marlin/src/lcd/tft_io/st7735.h similarity index 92% rename from Marlin/src/lcd/tft/st7735.h rename to Marlin/src/lcd/tft_io/st7735.h index 62f93d5044c0..1b0d23b6c4b9 100644 --- a/Marlin/src/lcd/tft/st7735.h +++ b/Marlin/src/lcd/tft_io/st7735.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,9 +38,17 @@ #define ST7735_ORIENTATION_LEFT ST7735_MADCTL_MV | ST7735_MADCTL_MX // 160x128 ; Cable on the left side #define ST7735_ORIENTATION_DOWN ST7735_MADCTL_MX | ST7735_MADCTL_MY // 128x160 ; Cable on the lower side -//#define ST7735_COLOR_BGR -#define ST7735_ORIENTATION ST7735_ORIENTATION_DOWN -#define ST7735_MADCTL_DATA (ST7735_ORIENTATION | TERN(ST7735_COLOR_BGR, ST7735_MADCTL_BGR, ST7735_MADCTL_RGB)) +#define ST7735_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7735_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7735_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7735_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7735_COLOR ST7735_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7735_COLOR ST7735_MADCTL_BGR +#endif + +#define ST7735_MADCTL_DATA (ST7735_ORIENTATION) | (ST7735_COLOR) #define ST7735_NOP 0x00 // No Operation #define ST7735_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft/st7789v.h b/Marlin/src/lcd/tft_io/st7789v.h similarity index 93% rename from Marlin/src/lcd/tft/st7789v.h rename to Marlin/src/lcd/tft_io/st7789v.h index 67da67966d2c..d0cf969c66ce 100644 --- a/Marlin/src/lcd/tft/st7789v.h +++ b/Marlin/src/lcd/tft_io/st7789v.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -38,11 +38,17 @@ #define ST7789V_ORIENTATION_LEFT ST7789V_MADCTL_MY | ST7789V_MADCTL_MV // 320x240 ; Cable on the left side #define ST7789V_ORIENTATION_DOWN 0 // 240x320 ; Cable on the lower side -//#define ST7789V_COLOR_BGR -#ifndef ST7789V_ORIENTATION - #define ST7789V_ORIENTATION ST7789V_ORIENTATION_LEFT +#define ST7789V_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7789V_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7789V_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7789V_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB + #define ST7789V_COLOR ST7789V_MADCTL_RGB +#elif TFT_COLOR == TFT_COLOR_BGR + #define ST7789V_COLOR ST7789V_MADCTL_BGR #endif -#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION | TERN(ST7789V_COLOR_BGR, ST7789V_MADCTL_BGR, ST7789V_MADCTL_RGB)) + +#define ST7789V_MADCTL_DATA (ST7789V_ORIENTATION) | (ST7789V_COLOR) #define ST7789V_NOP 0x00 // No Operation #define ST7789V_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft/st7796s.h b/Marlin/src/lcd/tft_io/st7796s.h similarity index 93% rename from Marlin/src/lcd/tft/st7796s.h rename to Marlin/src/lcd/tft_io/st7796s.h index 10452293de0b..8653a49ca2ef 100644 --- a/Marlin/src/lcd/tft/st7796s.h +++ b/Marlin/src/lcd/tft_io/st7796s.h @@ -21,7 +21,7 @@ */ #pragma once -#include "tft.h" +#include "tft_io.h" #include "../../inc/MarlinConfig.h" @@ -33,9 +33,17 @@ #define ST7796S_MADCTL_RGB 0x00 #define ST7796S_MADCTL_MH 0x04 // Horizontal Refresh Order -#define ST7796S_COLOR_BGR -#define ST7796S_ORIENTATION ST7796S_MADCTL_MV -#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION | TERN(ST7796S_COLOR_BGR, ST7796S_MADCTL_BGR, ST7796S_MADCTL_RGB)) +#define ST7796S_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ST7796S_MADCTL_MV) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ST7796S_MADCTL_MX) | \ + IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, ST7796S_MADCTL_MY) + +#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR + #define ST7796S_COLOR ST7796S_MADCTL_BGR +#elif TFT_COLOR == TFT_COLOR_RGB + #define ST7796S_COLOR ST7796S_MADCTL_RGB +#endif + +#define ST7796S_MADCTL_DATA (ST7796S_ORIENTATION) | (ST7796S_COLOR) #define ST7796S_NOP 0x00 // No Operation #define ST7796S_SWRESET 0x01 // Software reset diff --git a/Marlin/src/lcd/tft_io/tft_io.cpp b/Marlin/src/lcd/tft_io/tft_io.cpp new file mode 100644 index 000000000000..cd535458a181 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.cpp @@ -0,0 +1,226 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "tft_io.h" + +#if HAS_SPI_TFT || HAS_FSMC_TFT + +#include "st7735.h" +#include "st7789v.h" +#include "st7796s.h" +#include "r65105.h" +#include "ili9328.h" +#include "ili9341.h" +#include "ili9488.h" +#include "ssd1963.h" + +#define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT) +#include "../../core/debug_out.h" + +TFT_IO_DRIVER TFT_IO::io; +uint32_t TFT_IO::lcd_id = 0xFFFFFFFF; + +void TFT_IO::InitTFT() { +if (lcd_id != 0xFFFFFFFF) return; + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, LOW); + #endif + + #if PIN_EXISTS(TFT_RESET) + OUT_WRITE(TFT_RESET_PIN, HIGH); + delay(10); + OUT_WRITE(TFT_RESET_PIN, LOW); + delay(10); + OUT_WRITE(TFT_RESET_PIN, HIGH); + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) + OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); + #endif + + // io.Init(); + delay(100); + + #if TFT_DRIVER != AUTO + lcd_id = TFT_DRIVER; + #endif + + #if TFT_DRIVER == ST7735 + write_esc_sequence(st7735_init); + #elif TFT_DRIVER == SSD1963 + write_esc_sequence(ssd1963_init); + #elif TFT_DRIVER == ST7789 + write_esc_sequence(st7789v_init); + #elif TFT_DRIVER == ST7796 + write_esc_sequence(st7796s_init); + #elif TFT_DRIVER == R61505 + write_esc_sequence(r61505_init); + #elif TFT_DRIVER == ILI9328 + write_esc_sequence(ili9328_init); + #elif TFT_DRIVER == ILI9341 + write_esc_sequence(ili9341_init); + #elif TFT_DRIVER == ILI9488 + write_esc_sequence(ili9488_init); + #elif TFT_DRIVER == LERDGE_ST7796 + lcd_id = ST7796; + write_esc_sequence(lerdge_st7796s_init); + + #elif TFT_DRIVER == AUTO // autodetect + + lcd_id = io.GetID() & 0xFFFF; + + switch (lcd_id) { + case ST7796: // ST7796S 480x320 + DEBUG_ECHO_MSG(" ST7796S"); + write_esc_sequence(st7796s_init); + break; + case ST7789: // ST7789V 320x240 + DEBUG_ECHO_MSG(" ST7789V"); + write_esc_sequence(st7789v_init); + break; + case SSD1963: // SSD1963 + DEBUG_ECHO_MSG(" SSD1963"); + write_esc_sequence(ssd1963_init); + break; + case ST7735: // ST7735 160x128 + DEBUG_ECHO_MSG(" ST7735"); + write_esc_sequence(st7735_init); + break; + case R61505: // R61505U 320x240 + DEBUG_ECHO_MSG(" R61505U"); + write_esc_sequence(r61505_init); + break; + case ILI9328: // ILI9328 320x240 + DEBUG_ECHO_MSG(" ILI9328"); + write_esc_sequence(ili9328_init); + break; + case ILI9341: // ILI9341 320x240 + DEBUG_ECHO_MSG(" ILI9341"); + write_esc_sequence(ili9341_init); + break; + case ILI9488: // ILI9488 480x320 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + DEBUG_ECHO_MSG(" ILI9488"); + write_esc_sequence(ili9488_init); + break; + default: + lcd_id = 0; + } + #else + #error Unsupported TFT driver + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) + OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + #endif +} + +void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { + #ifdef OFFSET_X + Xmin += OFFSET_X; Xmax += OFFSET_X; + #endif + #ifdef OFFSET_Y + Ymin += OFFSET_Y; Ymax += OFFSET_Y; + #endif + + switch (lcd_id) { + case ST7735: // ST7735 160x128 + case ST7789: // ST7789V 320x240 + case ST7796: // ST7796 480x320 + case ILI9341: // ILI9341 320x240 + case ILI9488: // ILI9488 480x320 + case SSD1963: // SSD1963 + case ILI9488_ID1: // 0x8066 ILI9488 480x320 + io.DataTransferBegin(DATASIZE_8BIT); + + // CASET: Column Address Set + io.WriteReg(ILI9341_CASET); + io.WriteData((Xmin >> 8) & 0xFF); + io.WriteData(Xmin & 0xFF); + io.WriteData((Xmax >> 8) & 0xFF); + io.WriteData(Xmax & 0xFF); + + // RASET: Row Address Set + io.WriteReg(ILI9341_PASET); + io.WriteData((Ymin >> 8) & 0xFF); + io.WriteData(Ymin & 0xFF); + io.WriteData((Ymax >> 8) & 0xFF); + io.WriteData(Ymax & 0xFF); + + // RAMWR: Memory Write + io.WriteReg(ILI9341_RAMWR); + break; + case R61505: // R61505U 320x240 + case ILI9328: // ILI9328 320x240 + io.DataTransferBegin(DATASIZE_16BIT); + + // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X + io.WriteReg(ILI9328_HASTART); + io.WriteData(Ymin); + io.WriteReg(ILI9328_HAEND); + io.WriteData(Ymax); + io.WriteReg(ILI9328_VASTART); + io.WriteData(Xmin); + io.WriteReg(ILI9328_VAEND); + io.WriteData(Xmax); + + io.WriteReg(ILI9328_HASET); + io.WriteData(Ymin); + io.WriteReg(ILI9328_VASET); + io.WriteData(Xmin); + + io.WriteReg(ILI9328_RAMWR); + break; + default: + break; + } + + io.DataTransferEnd(); +} + +void TFT_IO::write_esc_sequence(const uint16_t *Sequence) { + uint16_t dataWidth, data; + + dataWidth = *Sequence++; + io.DataTransferBegin(dataWidth); + + for (;;) { + data = *Sequence++; + if (data != 0xFFFF) { + io.WriteData(data); + continue; + } + data = *Sequence++; + if (data == 0x7FFF) return; + if (data == 0xFFFF) + io.WriteData(0xFFFF); + else if (data & 0x8000) + delay(data & 0x7FFF); + else if ((data & 0xFF00) == 0) + io.WriteReg(data); + } + + io.DataTransferEnd(); +} + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/tft_io/tft_io.h b/Marlin/src/lcd/tft_io/tft_io.h new file mode 100644 index 000000000000..63d6936ac0b8 --- /dev/null +++ b/Marlin/src/lcd/tft_io/tft_io.h @@ -0,0 +1,124 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../../inc/MarlinConfig.h" + +#if HAS_SPI_TFT || HAS_FSMC_TFT + +#if HAS_SPI_TFT + #include HAL_PATH(../../HAL, tft/tft_spi.h) +#elif HAS_FSMC_TFT + #include HAL_PATH(../../HAL, tft/tft_fsmc.h) +#else + #error "TFT IO only supports SPI or FSMC interface" +#endif + +#define TFT_EXCHANGE_XY (1UL << 1) +#define TFT_INVERT_X (1UL << 2) +#define TFT_INVERT_Y (1UL << 3) + +#define TFT_NO_ROTATION (0x00) +#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X) +#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y) +#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y) + +#define TFT_MIRROR_X (TFT_INVERT_Y) +#define TFT_MIRROR_Y (TFT_INVERT_X) + +#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_INVERT_Y) +#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_INVERT_X) + +#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_INVERT_Y) +#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_INVERT_X) + +#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_INVERT_Y) +#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_INVERT_X) + +// TFT_ROTATION is user configurable +#ifndef TFT_ROTATION + #define TFT_ROTATION TFT_NO_ROTATION +#endif + + +// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION +#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION)) + +#define TFT_COLOR_RGB (1UL << 3) +#define TFT_COLOR_BGR (1UL << 4) + +// Each TFT Driver is responsible for its default color mode. +// #ifndef TFT_COLOR +// #define TFT_COLOR TFT_COLOR_RGB +// #endif + +#define SSD1963 0x5761 +#define ST7735 0x89F0 +#define ST7789 0x8552 +#define ST7796 0x7796 +#define R61505 0x1505 +#define ILI9328 0x9328 +#define ILI9341 0x9341 +#define ILI9488 0x9488 +#define ILI9488_ID1 0x8066 //Some ILI9488 have 0x8066 in the 0x04 +#define LERDGE_ST7796 0xFFFE +#define AUTO 0xFFFF + +#ifndef TFT_DRIVER + #define TFT_DRIVER AUTO +#endif + +#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x +#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF) +#define ESC_END 0xFFFF, 0x7FFF +#define ESC_FFFF 0xFFFF, 0xFFFF + +class TFT_IO { +public: + static TFT_IO_DRIVER io; + + static void InitTFT(); + static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax); + static void write_esc_sequence(const uint16_t *Sequence); + + // Deletaged methods + inline static void Init() { io.Init(); }; + inline static bool isBusy() { return io.isBusy(); }; + inline static void Abort() { io.Abort(); }; + inline static uint32_t GetID() { return io.GetID(); }; + + inline static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) { io.DataTransferBegin(DataWidth); } + inline static void DataTransferEnd() { io.DataTransferEnd(); }; + // inline static void DataTransferAbort() { io.DataTransferAbort(); }; + + inline static void WriteData(uint16_t Data) { io.WriteData(Data); }; + inline static void WriteReg(uint16_t Reg) { io.WriteReg(Reg); }; + + inline static void WriteSequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); }; + // static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } + inline static void WriteMultiple(uint16_t Color, uint32_t Count) { io.WriteMultiple(Color, Count); }; + +protected: + static uint32_t lcd_id; +}; + +#endif // HAS_SPI_TFT || HAS_FSMC_TFT diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index c97018c379c0..7d25c0df7eb9 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -82,7 +82,7 @@ uint8_t TouchButtons::read_buttons() { x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; - #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + #if (TFT_ROTATION & TFT_ROTATE_180) x = TOUCH_SENSOR_WIDTH - x; y = TOUCH_SENSOR_HEIGHT - y; #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 5bb32a420aee..4686e984b088 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -296,25 +296,44 @@ #ifndef GRAPHICAL_TFT_UPSCALE #define GRAPHICAL_TFT_UPSCALE 3 #endif + // SPI 1 + #define SCK_PIN P0_15 + #define MISO_PIN P0_17 + #define MOSI_PIN P0_18 // Disable any LCD related PINs config #define LCD_PINS_ENABLE -1 #define LCD_PINS_RS -1 - // Emulated DOGM have xpt calibration values independent of display resolution - #if ENABLED(SPI_GRAPHICAL_TFT) + // XPT2046 Touch Screen calibration + #if ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11245 + #define XPT2046_X_CALIBRATION -11245 #endif #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8629 + #define XPT2046_Y_CALIBRATION 8629 #endif #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 685 + #define XPT2046_X_OFFSET 685 #endif #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -285 + #define XPT2046_Y_OFFSET -285 #endif + #elif ENABLED(TFT_480x320_SPI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -17232 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 11196 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 1047 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -358 + #endif + + #define TFT_BUFFER_SIZE 2400 #endif #elif IS_TFTGLCD_PANEL diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h index 196503c822c5..6c6a9ea306ec 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h @@ -220,7 +220,7 @@ #if IS_TFTGLCD_PANEL #if ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS P3_25 // EXP2.3 + #define TFTGLCD_CS P3_25 // EXP2.3 #endif #if SD_CONNECTION_IS(LCD) diff --git a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h index c602af1c3028..294e7527a875 100644 --- a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h +++ b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h @@ -371,7 +371,7 @@ #endif #if ANY(VIKI2, miniVIKI) - // #define LCD_SCREEN_ROT_180 + //#define LCD_SCREEN_ROT_180 #define DOGLCD_CS P0_16 // (16) #define DOGLCD_A0 P2_06 // (59) J3-8 & AUX-2 diff --git a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h index 76c54c3bba21..6d6d7557f57d 100644 --- a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h +++ b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h @@ -161,7 +161,7 @@ // #define TEMP_0_PIN P0_24 #define TEMP_1_PIN P0_23 -//#define TEMP_2_PIN P1_30 // Onboard thermistor +//#define TEMP_2_PIN P1_30 // Onboard thermistor #define TEMP_BED_PIN P0_25 // diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h index cbbe8a9416d4..62660935f5bd 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h @@ -39,7 +39,7 @@ //#define SDCARD_EEPROM_EMULATION //#define I2C_EEPROM // AT24C32 #define FLASH_EEPROM_EMULATION - #define MARLIN_EEPROM_SIZE 0x1000 // 4KB + #define MARLIN_EEPROM_SIZE 0x1000 // 4KB #endif // @@ -190,7 +190,7 @@ #define E1_SERIAL_RX_PIN P1_17 // Reduce baud rate to improve software serial reliability - #define TMC_BAUD_RATE 19200 + #define TMC_BAUD_RATE 19200 #endif // HAS_TMC_UART // diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index 5d81d1eca9ab..b02d414089ff 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -129,8 +129,6 @@ #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 #define TFT_RESET_PIN PF11 #define TFT_BACKLIGHT_PIN PD13 @@ -140,14 +138,9 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define TFT_WIDTH 480 - #define TFT_HEIGHT 320 - #define TFT_PIXEL_OFFSET_X 48 - #define TFT_PIXEL_OFFSET_Y 32 - #endif -#if HAS_TFT_LVGL_UI +#if ENABLED(TFT_LVGL_UI) // LVGL #define HAS_SPI_FLASH_FONT 1 #define HAS_GCODE_PREVIEW 1 @@ -155,16 +148,17 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 -#elif ENABLED(TFT_480x320) +#elif ENABLED(TFT_COLOR_UI) // Color UI #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) // Emulated DOGM #define GRAPHICAL_TFT_UPSCALE 3 #endif -#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -177,7 +171,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12316 #endif diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index e6c9b33a5a29..cafd50dcf22c 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -135,15 +135,15 @@ // TronXY TFT Support // -// Shared FSMC Configs #if HAS_FSMC_TFT + + // Shared FSMC + #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK #define TOUCH_MISO_PIN PA6 // SPI1_MISO #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI - #define LCD_RESET_PIN PF11 - #define LCD_BACKLIGHT_PIN PD13 #define TFT_RESET_PIN PF11 #define TFT_BACKLIGHT_PIN PD13 @@ -153,14 +153,9 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define TFT_WIDTH 480 - #define TFT_HEIGHT 320 - #define TFT_PIXEL_OFFSET_X 48 - #define TFT_PIXEL_OFFSET_Y 32 - #endif -#if HAS_TFT_LVGL_UI +#if ENABLED(TFT_LVGL_UI) // LVGL #define HAS_SPI_FLASH_FONT 1 #define HAS_GCODE_PREVIEW 1 @@ -168,16 +163,17 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 -#elif ENABLED(TFT_480x320) +#elif ENABLED(TFT_COLOR_UI) // Color UI #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) // Emulated DOGM #define GRAPHICAL_TFT_UPSCALE 3 #endif -#if EITHER(HAS_TFT_LVGL_UI, TFT_480x320) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -190,7 +186,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12316 #endif diff --git a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h index 64948039baf9..3c277233d73e 100644 --- a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h +++ b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h @@ -39,7 +39,7 @@ #define STM32_XL_DENSITY #endif -// #define MCU_STM32F103ZE // not yet required +//#define MCU_STM32F103ZE // not yet required // Enable EEPROM Emulation for this board, so that we don't overwrite factory data //#define I2C_EEPROM // AT24C64 diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 47d7118b53d1..af81bbebe2d4 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -118,7 +118,6 @@ * because Marlin uses the reset as a failsafe to revive a glitchy LCD. */ -#define LCD_RESET_PIN PC4 // pin 33 #define TFT_RESET_PIN PC4 // pin 33 #define TFT_BACKLIGHT_PIN PD12 // pin 59 #define FSMC_CS_PIN PD7 // pin 88 = FSMC_NE1 @@ -131,13 +130,11 @@ #define DOGLCD_MOSI -1 // Prevent auto-define by Conditionals_post.h #define DOGLCD_SCK -1 -#define GRAPHICAL_TFT_UPSCALE 2 -#define TFT_WIDTH 320 -#define TFT_HEIGHT 240 -#define TFT_PIXEL_OFFSET_X 32 -#define TFT_PIXEL_OFFSET_Y 32 +// Longer/Alfawise TFT +#define LONGER_LK_TFT28 -//#define TFT_DRIVER ILI9341 +// Buffer for Color UI +#define TFT_BUFFER_SIZE 3200 /** * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h index 26a0c9260e03..8831d6804b05 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN.h @@ -143,8 +143,8 @@ #define LCD_BACKLIGHT_PIN PG11 #define FSMC_CS_PIN PG12 // NE4 #define FSMC_RS_PIN PF0 // A0 - #define TFT_CS_PIN FSMC_CS_PIN - #define TFT_RS_PIN FSMC_RS_PIN + #define TFT_CS_PIN FSMC_CS_PIN + #define TFT_RS_PIN FSMC_RS_PIN #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT #define FSMC_DMA_DEV DMA2 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index d9ba4e3c408b..94a28953ccf3 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -290,6 +290,7 @@ #define TFT_BUFFER_SIZE 14400 #endif +// XPT2046 Touch Screen calibration #if EITHER(HAS_TFT_LVGL_UI, TFT_480x320_SPI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17253 diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 35909ed43080..16d6d2ffc442 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -171,6 +171,9 @@ // Shared FSMC Configs #if HAS_FSMC_TFT + #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h + #define DOGLCD_SCK -1 + #define FSMC_CS_PIN PD7 // NE4 #define FSMC_RS_PIN PD11 // A0 @@ -179,9 +182,6 @@ #define TOUCH_MISO_PIN PB14 // SPI2_MISO #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI - #define LCD_RESET_PIN PC6 // FSMC_RST - #define LCD_BACKLIGHT_PIN PD13 - #define TFT_RESET_PIN PC6 // FSMC_RST #define TFT_BACKLIGHT_PIN PD13 @@ -193,60 +193,11 @@ #define TOUCH_BUTTONS_HW_SPI #define TOUCH_BUTTONS_HW_SPI_DEVICE 2 -#endif - -#if ENABLED(FSMC_GRAPHICAL_TFT) - // Emulated DOGM - #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h - #define DOGLCD_SCK -1 - - #ifndef GRAPHICAL_TFT_UPSCALE - #define GRAPHICAL_TFT_UPSCALE 3 - #endif - #ifndef TFT_WIDTH - #define TFT_WIDTH 480 - #endif - #ifndef TFT_PIXEL_OFFSET_X - #define TFT_PIXEL_OFFSET_X 48 - #endif - #ifndef TFT_HEIGHT - #define TFT_HEIGHT 320 - #endif - #ifndef TFT_PIXEL_OFFSET_Y - #define TFT_PIXEL_OFFSET_Y 32 - #endif - -#elif ENABLED(TFT_320x240) // TFT32/28 - #define TFT_RESET_PIN PC6 - #define TFT_BACKLIGHT_PIN PD13 - - #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT - #define FSMC_CS_PIN PD7 - #define FSMC_RS_PIN PD11 - #define FSMC_DMA_DEV DMA2 - #define FSMC_DMA_CHANNEL DMA_CH5 - - #define 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 TFT_DRIVER ILI9341 - #define TFT_BUFFER_SIZE 14400 - - // YV for normal screen mounting - //#define ILI9341_ORIENTATION ILI9341_MADCTL_MY | ILI9341_MADCTL_MV - // XV for 180° rotated screen mounting - #define ILI9341_ORIENTATION ILI9341_MADCTL_MX | ILI9341_MADCTL_MV - - #define ILI9341_COLOR_RGB -#elif ENABLED(TFT_480x320) - #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 - #define ILI9488_ORIENTATION ILI9488_MADCTL_MX | ILI9488_MADCTL_MV #endif +// XPT2046 Touch Screen calibration #if EITHER(TFT_LVGL_UI_FSMC, TFT_480x320) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION 17880 @@ -260,7 +211,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET 349 #endif -#elif ENABLED(FSMC_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION 12149 #endif @@ -273,7 +224,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET 256 #endif -#elif ENABLED(TFT_320x240) // TFT32/28 +#elif ENABLED(TFT_320x240) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12246 #endif 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 b40c66496af6..846fe80a08fa 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -269,19 +269,11 @@ #define TOUCH_BUTTONS_HW_SPI #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 - #ifndef TFT_WIDTH - #define TFT_WIDTH 480 - #endif - #ifndef TFT_HEIGHT - #define TFT_HEIGHT 320 - #endif - - #define LCD_READ_ID 0xD3 #define LCD_USE_DMA_SPI #endif -#if ENABLED(SPI_GRAPHICAL_TFT) +#if ENABLED(TFT_CLASSIC_UI) // Emulated DOGM SPI #ifndef GRAPHICAL_TFT_UPSCALE #define GRAPHICAL_TFT_UPSCALE 3 @@ -297,12 +289,12 @@ #define LCD_PINS_ENABLE PD13 #define LCD_PINS_RS PC6 -#elif ENABLED(TFT_480x320_SPI) - #define TFT_DRIVER ST7796 +#elif ENABLED(TFT_COLOR_UI) #define TFT_BUFFER_SIZE 14400 #endif -#if EITHER(TFT_LVGL_UI_SPI, TFT_480x320_SPI) +// XPT2046 Touch Screen calibration +#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17253 #endif @@ -315,7 +307,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -24 #endif -#elif ENABLED(SPI_GRAPHICAL_TFT) +#elif ENABLED(TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -11386 #endif diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index 4745641ea934..bfd1f2abdcbd 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -120,14 +120,50 @@ * Setting an 'LCD_RESET_PIN' may cause a flicker when entering the LCD menu * because Marlin uses the reset as a failsafe to revive a glitchy LCD. */ -#define LCD_RESET_PIN PF11 -#define LCD_BACKLIGHT_PIN PD13 -#define FSMC_CS_PIN PD7 // NE4 -#define FSMC_RS_PIN PD11 // A0 - -#define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT -#define FSMC_DMA_DEV DMA2 -#define FSMC_DMA_CHANNEL DMA_CH5 +#if HAS_FSMC_TFT + #define TFT_RESET_PIN PF11 + #define TFT_BACKLIGHT_PIN PD13 + #define FSMC_CS_PIN PD7 // NE4 + #define FSMC_RS_PIN PD11 // A0 + + #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT + #define FSMC_DMA_DEV DMA2 + #define FSMC_DMA_CHANNEL DMA_CH5 + + #define ANYCUBIC_TFT35 +#else + #define LCD_RESET_PIN PF11 + #define LCD_BACKLIGHT_PIN PD13 +#endif + +// XPT2046 Touch Screen calibration +#if ENABLED(TFT_COLOR_UI) || ENABLED(TFT_LVGL_UI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -17181 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 11434 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 501 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -9 + #endif +#elif ENABLED(TFT_CLASSIC_UI) + #ifndef XPT2046_X_CALIBRATION + #define XPT2046_X_CALIBRATION -12316 + #endif + #ifndef XPT2046_Y_CALIBRATION + #define XPT2046_Y_CALIBRATION 8981 + #endif + #ifndef XPT2046_X_OFFSET + #define XPT2046_X_OFFSET 340 + #endif + #ifndef XPT2046_Y_OFFSET + #define XPT2046_Y_OFFSET -20 + #endif +#endif #if NEED_TOUCH_PINS #define TOUCH_CS_PIN PB7 // SPI2_NSS diff --git a/Marlin/src/pins/teensy4/pins_T41U5XBB.h b/Marlin/src/pins/teensy4/pins_T41U5XBB.h index 830637bebd93..5f62bb05a64b 100644 --- a/Marlin/src/pins/teensy4/pins_T41U5XBB.h +++ b/Marlin/src/pins/teensy4/pins_T41U5XBB.h @@ -85,17 +85,17 @@ #define X_STEP_PIN 2 #define X_DIR_PIN 3 #define X_ENABLE_PIN 10 -//#define X_CS_PIN 30 +//#define X_CS_PIN 30 #define Y_STEP_PIN 4 #define Y_DIR_PIN 5 #define Y_ENABLE_PIN 40 -//#define Y_CS_PIN 31 +//#define Y_CS_PIN 31 #define Z_STEP_PIN 6 #define Z_DIR_PIN 7 #define Z_ENABLE_PIN 39 -//#define Z_CS_PIN 32 +//#define Z_CS_PIN 32 #define E0_STEP_PIN 8 #define E0_DIR_PIN 9 diff --git a/Marlin/src/pins/teensy4/pins_TEENSY41.h b/Marlin/src/pins/teensy4/pins_TEENSY41.h index 31c6fda5c900..21a1ff675f24 100644 --- a/Marlin/src/pins/teensy4/pins_TEENSY41.h +++ b/Marlin/src/pins/teensy4/pins_TEENSY41.h @@ -81,17 +81,17 @@ #define X_STEP_PIN 0 #define X_DIR_PIN 1 #define X_ENABLE_PIN 6 -//#define X_CS_PIN 30 +//#define X_CS_PIN 30 #define Y_STEP_PIN 2 #define Y_DIR_PIN 3 #define Y_ENABLE_PIN 7 -//#define Y_CS_PIN 31 +//#define Y_CS_PIN 31 #define Z_STEP_PIN 4 #define Z_DIR_PIN 5 #define Z_ENABLE_PIN 8 -//#define Z_CS_PIN 32 +//#define Z_CS_PIN 32 #define E0_STEP_PIN 9 #define E0_DIR_PIN 10 @@ -123,8 +123,8 @@ // #define LED_PIN 13 #define SOL0_PIN 28 -//#define PS_ON_PIN 1 -//#define FILWIDTH_PIN 6 // A6 +//#define PS_ON_PIN 1 +//#define FILWIDTH_PIN 6 // A6 #ifndef SDCARD_CONNECTION #define SDCARD_CONNECTION ONBOARD diff --git a/platformio.ini b/platformio.ini index d4beca6519be..7ede4c321fd0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ include_dir = Marlin # [common] default_src_filter = + - - + - - - - - - + - - - - - - - - - - - - @@ -226,7 +226,7 @@ HAS_WIRED_LCD = src_filter=+ HAS_MARLINUI_HD44780 = src_filter=+ HAS_MARLINUI_U8GLIB = U8glib-HAL@~0.4.1 src_filter=+ -HAS_(FSMC|SPI)_TFT = src_filter=+ + +HAS_(FSMC|SPI)_TFT = src_filter=+ + + HAS_FSMC_TFT = src_filter=+ + HAS_SPI_TFT = src_filter=+ + HAS_GRAPHICAL_TFT = src_filter=+ @@ -906,8 +906,6 @@ build_flags = ${common_stm32f1.build_flags} # # MKS Robin Nano (STM32F103VET6) -# v1.2 - Emulated Graphical 128x64 (DOGM) UI and LVGL UI -# v2.0 - LVGL UI # [env:mks_robin_nano35] platform = ${common_stm32f1.platform} From e173b7f78dcbf82fac0463c270f399b7ecbb1097 Mon Sep 17 00:00:00 2001 From: InsanityAutomation <38436470+InsanityAutomation@users.noreply.github.com> Date: Sun, 11 Oct 2020 22:34:27 -0400 Subject: [PATCH 25/46] G34 Mechanical Gantry Calibration (like Prusa M915) (#18972) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 19 +++ Marlin/src/gcode/calibrate/G34.cpp | 153 ++++++++++++++++++++++++ Marlin/src/gcode/calibrate/G34_M422.cpp | 98 ++++++++++----- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/gcode.h | 5 +- Marlin/src/inc/SanityCheck.h | 17 ++- Marlin/src/lcd/language/language_en.h | 3 + Marlin/src/lcd/menu/menu_motion.cpp | 2 +- buildroot/tests/LPC1769-tests | 2 +- platformio.ini | 2 + 10 files changed, 269 insertions(+), 34 deletions(-) create mode 100644 Marlin/src/gcode/calibrate/G34.cpp diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 9c439c90a71f..48e6a8db3962 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3377,6 +3377,25 @@ //#define JOYSTICK_DEBUG #endif +/** + * Mechanical Gantry Calibration + * Modern replacement for the Prusa TMC_Z_CALIBRATION. + * Adds capability to work with any adjustable current drivers. + * Implemented as G34 because M915 is deprecated. + */ +//#define MECHANICAL_GANTRY_CALIBRATION +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + #define GANTRY_CALIBRATION_CURRENT 600 // Default calibration current in ma + #define GANTRY_CALIBRATION_EXTRA_HEIGHT 15 // Extra distance in mm past Z_###_POS to move + #define GANTRY_CALIBRATION_FEEDRATE 500 // Feedrate for correction move + //#define GANTRY_CALIBRATION_TO_MIN // Enable to calibrate Z in the MIN direction + + //#define GANTRY_CALIBRATION_SAFE_POSITION { X_CENTER, Y_CENTER } // Safe position for nozzle + //#define GANTRY_CALIBRATION_XY_PARK_FEEDRATE 3000 // XY Park Feedrate - MMM + //#define GANTRY_CALIBRATION_COMMANDS_PRE "" + #define GANTRY_CALIBRATION_COMMANDS_POST "G28" // G28 highly recommended to ensure an accurate position +#endif + /** * MAX7219 Debug Matrix * diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp new file mode 100644 index 000000000000..eb1d32f90927 --- /dev/null +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -0,0 +1,153 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + +#include "../gcode.h" +#include "../../module/motion.h" +#include "../../module/stepper.h" +#include "../../module/endstops.h" + +#if HAS_LEVELING + #include "../../feature/bedlevel/bedlevel.h" +#endif + +#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) +#include "../../core/debug_out.h" + +void GcodeSuite::G34() { + + if (homing_needed()) return; + + TEMPORARY_SOFT_ENDSTOP_STATE(false); + TEMPORARY_BED_LEVELING_STATE(false); + TemporaryGlobalEndstopsState unlock_z(false); + + #ifdef GANTRY_CALIBRATION_COMMANDS_PRE + gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_PRE)); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Sub Commands Processed"); + #endif + + #ifdef GANTRY_CALIBRATION_SAFE_POSITION + // Move XY to safe position + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Parking XY"); + const xy_pos_t safe_pos = GANTRY_CALIBRATION_SAFE_POSITION; + do_blocking_move_to(safe_pos, MMM_TO_MMS(GANTRY_CALIBRATION_XY_PARK_FEEDRATE)); + #endif + + const float move_distance = parser.intval('Z', GANTRY_CALIBRATION_EXTRA_HEIGHT), + zbase = ENABLED(GANTRY_CALIBRATION_TO_MIN) ? Z_MIN_POS : Z_MAX_POS, + zpounce = zbase - move_distance, zgrind = zbase + move_distance; + + // Move Z to pounce position + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce"); + do_blocking_move_to_z(zpounce, MMM_TO_MMS(HOMING_FEEDRATE_Z)); + + // Store current motor settings, then apply reduced value + + #define _REDUCE_CURRENT ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_I2C, HAS_TRINAMIC_CONFIG) + #if _REDUCE_CURRENT + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Reducing Current"); + #endif + + #if HAS_MOTOR_CURRENT_SPI + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; + stepper.set_digipot_current(Z_AXIS, target_current); + #elif HAS_MOTOR_CURRENT_PWM + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS]; + stepper.set_digipot_current(1, target_current); + #elif HAS_MOTOR_CURRENT_DAC + const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT); + const float previous_current = dac_amps(Z_AXIS, target_current); + stepper_dac.set_current_value(Z_AXIS, target_current); + #elif ENABLED(HAS_MOTOR_CURRENT_I2C) + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + previous_current = dac_amps(Z_AXIS); + digipot_i2c.set_current(Z_AXIS, target_current) + #elif HAS_TRINAMIC_CONFIG + const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT); + static uint16_t previous_current_arr[NUM_Z_STEPPER_DRIVERS]; + #if AXIS_IS_TMC(Z) + previous_current_arr[0] = stepperZ.getMilliamps(); + stepperZ.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z2) + previous_current_arr[1] = stepperZ2.getMilliamps(); + stepperZ2.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z3) + previous_current_arr[2] = stepperZ3.getMilliamps(); + stepperZ3.rms_current(target_current); + #endif + #if AXIS_IS_TMC(Z4) + previous_current_arr[3] = stepperZ4.getMilliamps(); + stepperZ4.rms_current(target_current); + #endif + #endif + + // Do Final Z move to adjust + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Final Z Move"); + do_blocking_move_to_z(zgrind, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + + // Back off end plate, back to normal motion range + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Backoff"); + do_blocking_move_to_z(zpounce, MMM_TO_MMS(GANTRY_CALIBRATION_FEEDRATE)); + + #if _REDUCE_CURRENT + // Reset current to original values + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore Current"); + #endif + + #if HAS_MOTOR_CURRENT_SPI + stepper.set_digipot_current(Z_AXIS, previous_current); + #elif HAS_MOTOR_CURRENT_PWM + stepper.set_digipot_current(1, previous_current); + #elif HAS_MOTOR_CURRENT_DAC + stepper_dac.set_current_value(Z_AXIS, previous_current); + #elif ENABLED(HAS_MOTOR_CURRENT_I2C) + digipot_i2c.set_current(Z_AXIS, previous_current) + #elif HAS_TRINAMIC_CONFIG + #if AXIS_IS_TMC(Z) + stepperZ.rms_current(previous_current_arr[0]); + #endif + #if AXIS_IS_TMC(Z2) + stepperZ2.rms_current(previous_current_arr[1]); + #endif + #if AXIS_IS_TMC(Z3) + stepperZ3.rms_current(previous_current_arr[2]); + #endif + #if AXIS_IS_TMC(Z4) + stepperZ4.rms_current(previous_current_arr[3]); + #endif + #endif + + #ifdef GANTRY_CALIBRATION_COMMANDS_POST + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); + gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST)); + #endif +} + +#endif // MECHANICAL_GANTRY_CALIBRATION diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 1fd0754ec780..24292477f9c1 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -20,28 +20,29 @@ * */ -#include "../../inc/MarlinConfig.h" +#include "../../inc/MarlinConfigPre.h" #if ENABLED(Z_STEPPER_AUTO_ALIGN) #include "../../feature/z_stepper_align.h" #include "../gcode.h" -#include "../../module/planner.h" -#include "../../module/stepper.h" #include "../../module/motion.h" +#include "../../module/stepper.h" +#include "../../module/planner.h" #include "../../module/probe.h" - -#if HAS_MULTI_HOTEND - #include "../../module/tool_change.h" -#endif +#include "../../lcd/ultralcd.h" // for LCD_MESSAGEPGM #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif +#if HAS_MULTI_HOTEND + #include "../../module/tool_change.h" +#endif + #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) - #include "../../libs/least_squares_fit.h" + #include "../../libs/least_squares_fit.h" #endif #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) @@ -117,7 +118,7 @@ void GcodeSuite::G34() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G34 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - #define Z_BASIC_CLEARANCE Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE) + #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + 7.0f * BOTH(BLTOUCH, BLTOUCH_HS_MODE)) // Compute a worst-case clearance height to probe from. After the first // iteration this will be re-calculated based on the actual bed position @@ -154,21 +155,29 @@ void GcodeSuite::G34() { z_maxdiff = 0.0f, amplification = z_auto_align_amplification; - // These are needed after the for-loop - uint8_t iteration; - bool err_break = false; - float z_measured_min; - #if DISABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) bool adjustment_reverse = false; #endif - // 'iteration' is declared above and is also used after the for-loop. - // *not* the same as LOOP_L_N(iteration, z_auto_align_iterations) - for (iteration = 0; iteration < z_auto_align_iterations; ++iteration) { + #if HAS_DISPLAY + PGM_P const msg_iteration = GET_TEXT(MSG_ITERATION); + const uint8_t iter_str_len = strlen_P(msg_iteration); + #endif + + // Final z and iteration values will be used after breaking the loop + float z_measured_min; + uint8_t iteration = 0; + bool err_break = false; // To break out of nested loops + while (iteration < z_auto_align_iterations) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> probing all positions."); - SERIAL_ECHOLNPAIR("\nITERATION: ", int(iteration + 1)); + const int iter = iteration + 1; + SERIAL_ECHOLNPAIR("\nG34 Iteration: ", iter); + #if HAS_DISPLAY + char str[iter_str_len + 2 + 1]; + sprintf_P(str, msg_iteration, iter); + ui.set_status(str); + #endif // Initialize minimum value z_measured_min = 100000.0f; @@ -190,7 +199,8 @@ void GcodeSuite::G34() { // current_position.z has been manually altered in the "dirty trick" above. const float z_probed_height = probe.probe_at_point(z_stepper_align.xy[iprobe], raise_after, 0, true, false); if (isnan(z_probed_height)) { - SERIAL_ECHOLNPGM("Probing failed."); + SERIAL_ECHOLNPGM("Probing failed"); + LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED); err_break = true; break; } @@ -249,8 +259,39 @@ void GcodeSuite::G34() { , " Z3-Z1=", ABS(z_measured[2] - z_measured[0]) #endif ); + #if HAS_DISPLAY + char fstr1[10]; + #if NUM_Z_STEPPER_DRIVERS == 2 + char msg[6 + (6 + 5) * 1 + 1]; + #else + char msg[6 + (6 + 5) * 3 + 1], fstr2[10], fstr3[10]; + #endif + sprintf_P(msg, + PSTR("Diffs Z1-Z2=%s" + #if NUM_Z_STEPPER_DRIVERS == 3 + " Z2-Z3=%s" + " Z3-Z1=%s" + #endif + ), dtostrf(ABS(z_measured[0] - z_measured[1]), 1, 3, fstr1) + #if NUM_Z_STEPPER_DRIVERS == 3 + , dtostrf(ABS(z_measured[1] - z_measured[2]), 1, 3, fstr2) + , dtostrf(ABS(z_measured[2] - z_measured[0]), 1, 3, fstr3) + #endif + ); + ui.set_status(msg); + #endif + + auto decreasing_accuracy = [](const float &v1, const float &v2){ + if (v1 < v2 * 0.7f) { + SERIAL_ECHOLNPGM("Decreasing Accuracy Detected."); + LCD_MESSAGEPGM(MSG_DECREASING_ACCURACY); + return true; + } + return false; + }; #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) + // Check if the applied corrections go in the correct direction. // Calculate the sum of the absolute deviations from the mean of the probe measurements. // Compare to the last iteration to ensure it's getting better. @@ -266,11 +307,8 @@ void GcodeSuite::G34() { z_align_level_indicator += ABS(z_measured[zstepper] - z_measured_mean); // If it's getting worse, stop and throw an error - if (last_z_align_level_indicator < z_align_level_indicator * 0.7f) { - SERIAL_ECHOLNPGM("Decreasing accuracy detected."); - err_break = true; - break; - } + err_break = decreasing_accuracy(last_z_align_level_indicator, z_align_level_indicator); + if (err_break) break; last_z_align_level_indicator = z_align_level_indicator; #endif @@ -290,8 +328,7 @@ void GcodeSuite::G34() { if (z_align_abs) amplification = (iteration == 1) ? _MIN(last_z_align_move[zstepper] / z_align_abs, 2.0f) : z_auto_align_amplification; // Check for less accuracy compared to last move - if (last_z_align_move[zstepper] < z_align_abs * 0.7f) { - SERIAL_ECHOLNPGM("Decreasing accuracy detected."); + if (decreasing_accuracy(last_z_align_move[zstepper], z_align_abs)) { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("> Z", int(zstepper + 1), " last_z_align_move = ", last_z_align_move[zstepper]); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("> Z", int(zstepper + 1), " z_align_abs = ", z_align_abs); adjustment_reverse = !adjustment_reverse; @@ -329,9 +366,14 @@ void GcodeSuite::G34() { if (err_break) break; - if (success_break) { SERIAL_ECHOLNPGM("Target accuracy achieved."); break; } + if (success_break) { + SERIAL_ECHOLNPGM("Target accuracy achieved."); + LCD_MESSAGEPGM(MSG_ACCURACY_ACHIEVED); + break; + } - } // for (iteration) + iteration++; + } // while (iteration < z_auto_align_iterations) if (err_break) SERIAL_ECHOLNPGM("G34 aborted."); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index cbf62e0fcf97..3f51272c662a 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -327,7 +327,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 33: G33(); break; // G33: Delta Auto-Calibration #endif - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) case 34: G34(); break; // G34: Z Stepper automatic alignment using probe #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 73a372781370..3ba2451919be 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -465,11 +465,12 @@ class GcodeSuite { TERN_(DELTA_AUTO_CALIBRATION, static void G33()); - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) static void G34(); - static void M422(); #endif + TERN_(Z_STEPPER_AUTO_ALIGN, static void M422()); + TERN_(ASSISTED_TRAMMING, static void G35()); TERN_(G38_PROBE_TARGET, static void G38(const int8_t subcode)); diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 7e3b6724d035..ec5400755183 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -422,7 +422,7 @@ #elif defined(CHAMBER_HEATER_PIN) #error "CHAMBER_HEATER_PIN is now HEATER_CHAMBER_PIN. Please update your configuration and/or pins." #elif defined(TMC_Z_CALIBRATION) - #error "TMC_Z_CALIBRATION has been deprecated in favor of Z_STEPPER_AUTO_ALIGN. Please update your configuration." + #error "TMC_Z_CALIBRATION has been deprecated in favor of MECHANICAL_GANTRY_CALIBRATION. Please update your configuration." #elif defined(Z_MIN_PROBE_ENDSTOP) #error "Z_MIN_PROBE_ENDSTOP is no longer required. Please remove it from Configuration.h." #elif defined(DUAL_NOZZLE_DUPLICATION_MODE) @@ -2788,6 +2788,21 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #endif #endif +#if ENABLED(MECHANICAL_GANTRY_CALIBRATION) + #if NONE(HAS_MOTOR_CURRENT_DAC, HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC, HAS_TRINAMIC_CONFIG, HAS_MOTOR_CURRENT_PWM) + #error "It is highly recommended to have adjustable current drivers to prevent damage. Disable this line to continue anyway." + #elif !defined(GANTRY_CALIBRATION_CURRENT) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_CURRENT to be set." + #elif !defined(GANTRY_CALIBRATION_EXTRA_HEIGHT) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_EXTRA_HEIGHT to be set." + #elif !defined(GANTRY_CALIBRATION_FEEDRATE) + #error "MECHANICAL_GANTRY_CALIBRATION Requires GANTRY_CALIBRATION_FEEDRATE to be set." + #endif + #if defined(GANTRY_CALIBRATION_SAFE_POSITION) && !defined(GANTRY_CALIBRATION_XY_PARK_FEEDRATE) + #error "GANTRY_CALIBRATION_SAFE_POSITION Requires GANTRY_CALIBRATION_XY_PARK_FEEDRATE to be set." + #endif +#endif + #if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS) #error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration." #endif diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index b41515a73428..e8b4769cc216 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -67,6 +67,9 @@ namespace Language_en { PROGMEM Language_Str MSG_AUTO_HOME_Z = _UxGT("Home Z"); PROGMEM Language_Str MSG_AUTO_Z_ALIGN = _UxGT("Auto Z-Align"); PROGMEM Language_Str MSG_ASSISTED_TRAMMING = _UxGT("Assisted Tramming"); + PROGMEM Language_Str MSG_ITERATION = _UxGT("G34 Iteration: %i"); + PROGMEM Language_Str MSG_DECREASING_ACCURACY = _UxGT("Accuracy Decreasing!"); + PROGMEM Language_Str MSG_ACCURACY_ACHIEVED = _UxGT("Accuracy Achieved"); PROGMEM Language_Str MSG_LEVEL_BED_HOMING = _UxGT("Homing XYZ"); PROGMEM Language_Str MSG_LEVEL_BED_WAITING = _UxGT("Click to Begin"); PROGMEM Language_Str MSG_LEVEL_BED_NEXT_POINT = _UxGT("Next Point"); diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index dff9895c6b64..676ba46ea730 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -358,7 +358,7 @@ void menu_motion() { // // Auto Z-Align // - #if ENABLED(Z_STEPPER_AUTO_ALIGN) + #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) GCODES_ITEM(MSG_AUTO_Z_ALIGN, PSTR("G34")); #endif diff --git a/buildroot/tests/LPC1769-tests b/buildroot/tests/LPC1769-tests index a7a6456d026d..4314b0d5ff8d 100755 --- a/buildroot/tests/LPC1769-tests +++ b/buildroot/tests/LPC1769-tests @@ -61,7 +61,7 @@ opt_set MOTHERBOARD BOARD_COHESION3D_REMIX opt_set X_DRIVER_TYPE TMC2130 opt_set Y_DRIVER_TYPE TMC2130 opt_set Z_DRIVER_TYPE TMC2130 -opt_enable AUTO_BED_LEVELING_BILINEAR EEPROM_SETTINGS EEPROM_CHITCHAT \ +opt_enable AUTO_BED_LEVELING_BILINEAR EEPROM_SETTINGS EEPROM_CHITCHAT MECHANICAL_GANTRY_CALIBRATION \ TMC_USE_SW_SPI MONITOR_DRIVER_STATUS STEALTHCHOP_XY STEALTHCHOP_Z HYBRID_THRESHOLD \ SENSORLESS_PROBING Z_SAFE_HOMING X_STALL_SENSITIVITY Y_STALL_SENSITIVITY Z_STALL_SENSITIVITY TMC_DEBUG \ EXPERIMENTAL_I2CBUS diff --git a/platformio.ini b/platformio.ini index 7ede4c321fd0..10b9f899d581 100644 --- a/platformio.ini +++ b/platformio.ini @@ -110,6 +110,7 @@ default_src_filter = + - - + - - - + - - - - @@ -309,6 +310,7 @@ MK2_MULTIPLEXER = src_filter=+ EXT_SOLENOID|MANUAL_SOLENOID_CONTROL = src_filter=+ + HAS_CUTTER = src_filter=+ + EXPERIMENTAL_I2CBUS = src_filter=+ + +MECHANICAL_GANTRY_CAL.+ = src_filter=+ Z_STEPPER_AUTO_ALIGN = src_filter=+ + G26_MESH_VALIDATION = src_filter=+ ASSISTED_TRAMMING = src_filter=+ From 8003a4390e36603346200c6c4fc46a4da05106a5 Mon Sep 17 00:00:00 2001 From: Keith Bennett <13375512+thisiskeithb@users.noreply.github.com> Date: Mon, 12 Oct 2020 14:52:56 -0700 Subject: [PATCH 26/46] Sanity-check mutually-exclusive G34 features (#19706) --- Marlin/src/inc/SanityCheck.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index ec5400755183..820d8a04b561 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2803,6 +2803,10 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #endif #endif +#if BOTH(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION) + #error "You cannot use Z_STEPPER_AUTO_ALIGN and MECHANICAL_GANTRY_CALIBRATION at the same time." +#endif + #if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS) #error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration." #endif From d53c01138dcebe11d0feb073bab03800e0bb5a56 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 12 Oct 2020 00:59:30 -0500 Subject: [PATCH 27/46] Fix screen click reading too often (#19696) Co-authored-by: andreibobirica <39415547+andreibobirica@users.noreply.github.com> --- Marlin/src/lcd/ultralcd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 58e6d9473b35..7003d13fdd7a 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -1553,12 +1553,15 @@ void MarlinUI::update() { // - On edit screens, touch Up Half for -, Bottom Half to + // void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t, const uint8_t) { + const millis_t now = millis(); + if (PENDING(now, next_button_update_ms)) return; + next_button_update_ms = now + repeat_delay; // Assume the repeat delay const int8_t xdir = col < (LCD_WIDTH ) / 2 ? -1 : 1, ydir = row < (LCD_HEIGHT) / 2 ? -1 : 1; if (on_edit_screen) encoderDiff = epps * ydir; else if (screen_items > 0) { - // Last 3 cols act as a scroll :-) + // Last 5 cols act as a scroll :-) if (col > (LCD_WIDTH) - 5) // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.) encoderDiff = epps * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir; From e0b2dd204edbf5f5b3e603b45c392345a25b7480 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 11 Oct 2020 21:31:21 -0300 Subject: [PATCH 28/46] Option to prevent (extra) Watchdog init on STM32 (#19693) --- Marlin/src/HAL/STM32/watchdog.cpp | 6 +++++- Marlin/src/HAL/STM32F1/watchdog.cpp | 4 +++- Marlin/src/pins/stm32f1/pins_MALYAN_M200.h | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/STM32/watchdog.cpp b/Marlin/src/HAL/STM32/watchdog.cpp index 37e5638b05c0..cc1855314968 100644 --- a/Marlin/src/HAL/STM32/watchdog.cpp +++ b/Marlin/src/HAL/STM32/watchdog.cpp @@ -30,7 +30,11 @@ #include "watchdog.h" #include - void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout + void watchdog_init() { + #if DISABLED(DISABLE_WATCHDOG_INIT) + IWatchdog.begin(4000000); // 4 sec timeout + #endif + } void HAL_watchdog_refresh() { IWatchdog.reload(); diff --git a/Marlin/src/HAL/STM32F1/watchdog.cpp b/Marlin/src/HAL/STM32F1/watchdog.cpp index 4123bc3ef0ff..ca91a6fe4350 100644 --- a/Marlin/src/HAL/STM32F1/watchdog.cpp +++ b/Marlin/src/HAL/STM32F1/watchdog.cpp @@ -52,7 +52,9 @@ void watchdogSetup() { * @details The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and 625 reload value (counts down to 0) */ void watchdog_init() { - //iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); + #if DISABLED(DISABLE_WATCHDOG_INIT) + iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD); + #endif } #endif // USE_WATCHDOG diff --git a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h index d3c26c497d8f..95e7e92174fa 100644 --- a/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h +++ b/Marlin/src/pins/stm32f1/pins_MALYAN_M200.h @@ -33,6 +33,9 @@ #define BOARD_INFO_NAME "Malyan M200" #endif +// Prevents hanging from an extra watchdog init +#define DISABLE_WATCHDOG_INIT + // Assume Flash EEPROM #if NO_EEPROM_SELECTED #define FLASH_EEPROM_EMULATION From 9543240c4156e51679b6a38bc41fd5ba760700f3 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sun, 11 Oct 2020 21:26:16 -0300 Subject: [PATCH 29/46] Implement wait_for_user for Color UI (#19694) --- Marlin/src/gcode/config/M43.cpp | 9 ++++++++- Marlin/src/lcd/tft/touch.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/config/M43.cpp b/Marlin/src/gcode/config/M43.cpp index 1e7374542c3d..1e780ca05afd 100644 --- a/Marlin/src/gcode/config/M43.cpp +++ b/Marlin/src/gcode/config/M43.cpp @@ -46,6 +46,10 @@ #include "../../lcd/extui/ui_api.h" #endif +#if HAS_RESUME_CONTINUE + #include "../../lcd/ultralcd.h" +#endif + #ifndef GET_PIN_MAP_PIN_M43 #define GET_PIN_MAP_PIN_M43(Q) GET_PIN_MAP_PIN(Q) #endif @@ -362,7 +366,10 @@ void GcodeSuite::M43() { } } - if (TERN0(HAS_RESUME_CONTINUE, !wait_for_user)) break; + #if HAS_RESUME_CONTINUE + ui.update(); + if (!wait_for_user) break; + #endif safe_delay(200); } diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 5889ac0a9908..2124a42e28ca 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -50,6 +50,9 @@ touch_calibration_t Touch::calibration; calibrationState Touch::calibration_state = CALIBRATION_NONE; touch_calibration_point_t Touch::calibration_points[4]; #endif +#if HAS_RESUME_CONTINUE + extern bool wait_for_user; +#endif void Touch::init() { calibration_reset(); @@ -80,6 +83,15 @@ void Touch::idle() { now = millis(); if (get_point(&_x, &_y)) { + #if HAS_RESUME_CONTINUE + // UI is waiting for a click anywhere? + if (wait_for_user) { + touch_control_type = CLICK; + ui.lcd_clicked = true; + return; + } + #endif + #if LCD_TIMEOUT_TO_STATUS ui.return_to_status_ms = now + LCD_TIMEOUT_TO_STATUS; #endif From cc4db8e4a99db81a441a765a1e86e98e2e53a04d Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 12 Oct 2020 20:01:03 -0300 Subject: [PATCH 30/46] Fix UTF8 handling for Color UI (#19708) --- Marlin/src/lcd/tft/tft_string.cpp | 11 +++++++++++ Marlin/src/lcd/tft/tft_string.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 7e66c3d29cf8..663ed97c36c8 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -116,6 +116,17 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { eol(); } +void TFT_String::add(uint8_t *string) { + wchar_t wchar; + while (*string) { + string = get_utf8_value_cb(string, read_byte, &wchar); + if (wchar > 255) wchar |= 0x0080; + uint8_t ch = uint8_t(wchar & 0x00FF); + add_character(ch); + } + eol(); +} + void TFT_String::add_character(uint8_t character) { if (length < MAX_STRING_LENGTH) { data[length] = character; diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index d83d3af7027e..924d6de43027 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -85,7 +85,7 @@ class TFT_String { static void set(); static void add(uint8_t character) { add_character(character); eol(); } - static void add(uint8_t *string) { while (*string) { add_character(*string++); } eol(); } + static void add(uint8_t *string); static void add(uint8_t *string, int8_t index, uint8_t *itemString = NULL); static void set(uint8_t *string) { set(); add(string); }; static void set(uint8_t *string, int8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); }; From ae36ed390312c80b03fb36225755fddf9f9205b7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 12 Oct 2020 17:48:50 -0500 Subject: [PATCH 31/46] Move @section temperature --- Marlin/Configuration.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 8f37f1e799ba..db266b524b35 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -346,11 +346,10 @@ #endif #endif -// @section temperature - //=========================================================================== //============================= Thermal Settings ============================ //=========================================================================== +// @section temperature /** * --NORMAL IS 4.7kohm PULLUP!-- 1kohm pullup can be used on hotend sensor, using correct resistor and table From ab6d0333100c0837698a74d0e34050408530a52d Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 12 Oct 2020 20:01:03 -0300 Subject: [PATCH 32/46] Fix UTF8 handling for Color UI (#19708) --- Marlin/src/lcd/tft/tft_string.cpp | 11 +++++++++++ Marlin/src/lcd/tft/tft_string.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 7e66c3d29cf8..663ed97c36c8 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -116,6 +116,17 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { eol(); } +void TFT_String::add(uint8_t *string) { + wchar_t wchar; + while (*string) { + string = get_utf8_value_cb(string, read_byte, &wchar); + if (wchar > 255) wchar |= 0x0080; + uint8_t ch = uint8_t(wchar & 0x00FF); + add_character(ch); + } + eol(); +} + void TFT_String::add_character(uint8_t character) { if (length < MAX_STRING_LENGTH) { data[length] = character; diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index d83d3af7027e..924d6de43027 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -85,7 +85,7 @@ class TFT_String { static void set(); static void add(uint8_t character) { add_character(character); eol(); } - static void add(uint8_t *string) { while (*string) { add_character(*string++); } eol(); } + static void add(uint8_t *string); static void add(uint8_t *string, int8_t index, uint8_t *itemString = NULL); static void set(uint8_t *string) { set(); add(string); }; static void set(uint8_t *string, int8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); }; From da79674f84ef65cb014288a27d60f8709b1f0936 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Tue, 13 Oct 2020 00:15:19 +0000 Subject: [PATCH 33/46] [cron] Bump distribution date (2020-10-13) --- Marlin/src/inc/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 74f713091d2a..b1576c06be02 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-10-12" + #define STRING_DISTRIBUTION_DATE "2020-10-13" #endif /** From 27e2139a67fa90d78575863977461cc217b58690 Mon Sep 17 00:00:00 2001 From: Serhiy-K <52166448+Serhiy-K@users.noreply.github.com> Date: Sat, 10 Oct 2020 13:01:46 +0300 Subject: [PATCH 34/46] Fixes for TFTGLCD Panel, FastIO (#19614) --- Marlin/src/HAL/STM32/fastio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h index f000d68cf0c3..7d02062b5374 100644 --- a/Marlin/src/HAL/STM32/fastio.h +++ b/Marlin/src/HAL/STM32/fastio.h @@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx) #define _WRITE(IO, V) do { \ - if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \ - else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \ + if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ + else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ }while(0) #else - #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16))) + #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) + ((V) ? 0 : 16))) #endif -#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO])))) -#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO]))) +#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(digitalPinToPinName(IO) & 0x1F))) +#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(digitalPinToPinName(IO) & 0x1F)) #define _GET_MODE(IO) #define _SET_MODE(IO,M) pinMode(IO, M) From a327e2d3f7c7f98df989d975849c096dcc49086b Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 10 Oct 2020 13:47:28 -0300 Subject: [PATCH 35/46] Restore correct STM32 port-bits code (#19678) --- Marlin/src/HAL/STM32/fastio.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h index 7d02062b5374..f000d68cf0c3 100644 --- a/Marlin/src/HAL/STM32/fastio.h +++ b/Marlin/src/HAL/STM32/fastio.h @@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx) #define _WRITE(IO, V) do { \ - if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ - else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \ + if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \ + else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \ }while(0) #else - #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) + ((V) ? 0 : 16))) + #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16))) #endif -#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(digitalPinToPinName(IO) & 0x1F))) -#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(digitalPinToPinName(IO) & 0x1F)) +#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO])))) +#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO]))) #define _GET_MODE(IO) #define _SET_MODE(IO,M) pinMode(IO, M) From 4579b3fcfef491a86b48c8fcb980a1731f0d2f7e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 10 Oct 2020 12:07:00 -0500 Subject: [PATCH 36/46] Save PLR on resume from pause (#19676) Co-Authored-By: shahab <32130261+SHBnik@users.noreply.github.com> --- Marlin/src/feature/pause.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index a36ff5075683..0ab659402181 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -61,6 +61,10 @@ #include "../libs/buzzer.h" #endif +#if ENABLED(POWER_LOSS_RECOVERY) + #include "powerloss.h" +#endif + #include "../libs/nozzle.h" #include "pause.h" @@ -640,6 +644,9 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le // Set extruder to saved position planner.set_e_position_mm((destination.e = current_position.e = resume_position.e)); + // Write PLR now to update the z axis value + TERN_(POWER_LOSS_RECOVERY, if (recovery.enabled) recovery.save(true)); + TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_STATUS)); #ifdef ACTION_ON_RESUMED From 33e081594eb9f8a86064bc3b70ae3e2f31db5f87 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 11 Oct 2020 14:58:35 -0500 Subject: [PATCH 37/46] Digipots refactor / cleanup (#19690) --- Marlin/src/HAL/DUE/fastio/G2_PWM.cpp | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/MarlinCore.cpp | 12 ++-- Marlin/src/feature/dac/dac_mcp4728.cpp | 50 ++++++++-------- Marlin/src/feature/dac/dac_mcp4728.h | 25 ++++---- Marlin/src/feature/dac/stepper_dac.cpp | 55 ++++++++--------- Marlin/src/feature/dac/stepper_dac.h | 19 +++--- Marlin/src/feature/digipot/digipot.h | 12 +++- .../src/feature/digipot/digipot_mcp4018.cpp | 12 ++-- .../src/feature/digipot/digipot_mcp4451.cpp | 8 ++- .../src/gcode/feature/digipot/M907-M910.cpp | 52 ++++++++-------- Marlin/src/gcode/gcode.cpp | 6 +- Marlin/src/gcode/gcode.h | 12 ++-- Marlin/src/inc/Conditionals_adv.h | 2 +- Marlin/src/inc/Conditionals_post.h | 2 +- Marlin/src/inc/SanityCheck.h | 2 +- Marlin/src/lcd/menu/menu_advanced.cpp | 8 +-- Marlin/src/module/settings.cpp | 59 ++++++++++++++----- Marlin/src/module/stepper.cpp | 55 ++++++++--------- Marlin/src/module/stepper.h | 22 ++++--- Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h | 2 +- .../src/pins/teensy2/pins_PRINTRBOARD_REVF.h | 2 +- platformio.ini | 4 +- 23 files changed, 239 insertions(+), 186 deletions(-) diff --git a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp index 1682faea666d..d9fbabce2148 100644 --- a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp +++ b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp @@ -154,7 +154,7 @@ void Stepper::digipot_init() { NVIC_SetPriority(PWM_IRQn, NVIC_EncodePriority(0, 10, 0)); // normal priority for PWM module (can stand some jitter on the Vref signals) } -void Stepper::digipot_current(const uint8_t driver, const int16_t current) { +void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) { if (!(PWM->PWM_CH_NUM[0].PWM_CPRD == PWM_PERIOD_US)) digipot_init(); // Init PWM system if needed diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index fd82e2884ae9..f5051d32a168 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -191,7 +191,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o // // Flag any i2c pin conflicts // -#if ANY(HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM) +#if ANY(HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM) #define USEDI2CDEV_M 1 // /Wire.cpp #if USEDI2CDEV_M == 0 // P0_27 [D57] (AUX-1) .......... P0_28 [D58] (AUX-1) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 672858d05a35..3a20cf3ee330 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -97,7 +97,7 @@ #include "feature/closedloop.h" #endif -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #include "feature/digipot/digipot.h" #endif @@ -125,7 +125,7 @@ #include "module/servo.h" #endif -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "feature/dac/stepper_dac.h" #endif @@ -1137,12 +1137,12 @@ void setup() { SETUP_RUN(enableStepperDrivers()); #endif - #if HAS_I2C_DIGIPOT - SETUP_RUN(digipot_i2c_init()); + #if HAS_MOTOR_CURRENT_I2C + SETUP_RUN(digipot_i2c.init()); #endif - #if ENABLED(DAC_STEPPER_CURRENT) - SETUP_RUN(dac_init()); + #if ENABLED(HAS_MOTOR_CURRENT_DAC) + SETUP_RUN(stepper_dac.init()); #endif #if EITHER(Z_PROBE_SLED, SOLENOID_PROBE) && HAS_SOLENOID_1 diff --git a/Marlin/src/feature/dac/dac_mcp4728.cpp b/Marlin/src/feature/dac/dac_mcp4728.cpp index 55f10a49ef70..81c465cf29e4 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.cpp +++ b/Marlin/src/feature/dac/dac_mcp4728.cpp @@ -32,16 +32,18 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "dac_mcp4728.h" -xyze_uint_t mcp4728_values; +MCP4728 mcp4728; + +xyze_uint_t dac_values; /** * Begin I2C, get current values (input register and eeprom) of mcp4728 */ -void mcp4728_init() { +void MCP4728::init() { Wire.begin(); Wire.requestFrom(I2C_ADDRESS(DAC_DEV_ADDRESS), uint8_t(24)); while (Wire.available()) { @@ -50,7 +52,7 @@ void mcp4728_init() { loByte = Wire.read(); if (!(deviceID & 0x08)) - mcp4728_values[(deviceID & 0x30) >> 4] = word((hiByte & 0x0F), loByte); + dac_values[(deviceID & 0x30) >> 4] = word((hiByte & 0x0F), loByte); } } @@ -58,9 +60,9 @@ void mcp4728_init() { * Write input resister value to specified channel using fastwrite method. * Channel : 0-3, Values : 0-4095 */ -uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value) { - mcp4728_values[channel] = value; - return mcp4728_fastWrite(); +uint8_t MCP4728::analogWrite(const uint8_t channel, const uint16_t value) { + dac_values[channel] = value; + return fastWrite(); } /** @@ -68,12 +70,12 @@ uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value) { * This will update both input register and EEPROM value * This will also write current Vref, PowerDown, Gain settings to EEPROM */ -uint8_t mcp4728_eepromWrite() { +uint8_t MCP4728::eepromWrite() { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(SEQWRITE); LOOP_XYZE(i) { - Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(mcp4728_values[i])); - Wire.write(lowByte(mcp4728_values[i])); + Wire.write(DAC_STEPPER_VREF << 7 | DAC_STEPPER_GAIN << 4 | highByte(dac_values[i])); + Wire.write(lowByte(dac_values[i])); } return Wire.endTransmission(); } @@ -81,7 +83,7 @@ uint8_t mcp4728_eepromWrite() { /** * Write Voltage reference setting to all input regiters */ -uint8_t mcp4728_setVref_all(const uint8_t value) { +uint8_t MCP4728::setVref_all(const uint8_t value) { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(VREFWRITE | (value ? 0x0F : 0x00)); return Wire.endTransmission(); @@ -89,7 +91,7 @@ uint8_t mcp4728_setVref_all(const uint8_t value) { /** * Write Gain setting to all input regiters */ -uint8_t mcp4728_setGain_all(const uint8_t value) { +uint8_t MCP4728::setGain_all(const uint8_t value) { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); Wire.write(GAINWRITE | (value ? 0x0F : 0x00)); return Wire.endTransmission(); @@ -98,16 +100,16 @@ uint8_t mcp4728_setGain_all(const uint8_t value) { /** * Return Input Register value */ -uint16_t mcp4728_getValue(const uint8_t channel) { return mcp4728_values[channel]; } +uint16_t MCP4728::getValue(const uint8_t channel) { return dac_values[channel]; } #if 0 /** * Steph: Might be useful in the future * Return Vout */ -uint16_t mcp4728_getVout(const uint8_t channel) { +uint16_t MCP4728::getVout(const uint8_t channel) { const uint32_t vref = 2048, - vOut = (vref * mcp4728_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096; + vOut = (vref * dac_values[channel] * (_DAC_STEPPER_GAIN + 1)) / 4096; return _MIN(vOut, defaultVDD); } #endif @@ -115,15 +117,15 @@ uint16_t mcp4728_getVout(const uint8_t channel) { /** * Returns DAC values as a 0-100 percentage of drive strength */ -uint8_t mcp4728_getDrvPct(const uint8_t channel) { return uint8_t(100.0 * mcp4728_values[channel] / (DAC_STEPPER_MAX) + 0.5); } +uint8_t MCP4728::getDrvPct(const uint8_t channel) { return uint8_t(100.0 * dac_values[channel] / (DAC_STEPPER_MAX) + 0.5); } /** * Receives all Drive strengths as 0-100 percent values, updates * DAC Values array and calls fastwrite to update the DAC. */ -void mcp4728_setDrvPct(xyze_uint8_t &pct) { - mcp4728_values *= 0.01 * pct * (DAC_STEPPER_MAX); - mcp4728_fastWrite(); +void MCP4728::setDrvPct(xyze_uint8_t &pct) { + dac_values *= 0.01 * pct * (DAC_STEPPER_MAX); + fastWrite(); } /** @@ -131,11 +133,11 @@ void mcp4728_setDrvPct(xyze_uint8_t &pct) { * DAC Input and PowerDown bits update. * No EEPROM update */ -uint8_t mcp4728_fastWrite() { +uint8_t MCP4728::fastWrite() { Wire.beginTransmission(I2C_ADDRESS(DAC_DEV_ADDRESS)); LOOP_XYZE(i) { - Wire.write(highByte(mcp4728_values[i])); - Wire.write(lowByte(mcp4728_values[i])); + Wire.write(highByte(dac_values[i])); + Wire.write(lowByte(dac_values[i])); } return Wire.endTransmission(); } @@ -143,10 +145,10 @@ uint8_t mcp4728_fastWrite() { /** * Common function for simple general commands */ -uint8_t mcp4728_simpleCommand(const byte simpleCommand) { +uint8_t MCP4728::simpleCommand(const byte simpleCommand) { Wire.beginTransmission(I2C_ADDRESS(GENERALCALL)); Wire.write(simpleCommand); return Wire.endTransmission(); } -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/feature/dac/dac_mcp4728.h b/Marlin/src/feature/dac/dac_mcp4728.h index fc69bd8ff4eb..571716d4834e 100644 --- a/Marlin/src/feature/dac/dac_mcp4728.h +++ b/Marlin/src/feature/dac/dac_mcp4728.h @@ -65,13 +65,18 @@ // DAC_OR_ADDRESS defined in pins_BOARD.h file #define DAC_DEV_ADDRESS (BASE_ADDR | DAC_OR_ADDRESS) -void mcp4728_init(); -uint8_t mcp4728_analogWrite(const uint8_t channel, const uint16_t value); -uint8_t mcp4728_eepromWrite(); -uint8_t mcp4728_setVref_all(const uint8_t value); -uint8_t mcp4728_setGain_all(const uint8_t value); -uint16_t mcp4728_getValue(const uint8_t channel); -uint8_t mcp4728_fastWrite(); -uint8_t mcp4728_simpleCommand(const byte simpleCommand); -uint8_t mcp4728_getDrvPct(const uint8_t channel); -void mcp4728_setDrvPct(xyze_uint8_t &pct); +class MCP4728 { +public: + static void init(); + static uint8_t analogWrite(const uint8_t channel, const uint16_t value); + static uint8_t eepromWrite(); + static uint8_t setVref_all(const uint8_t value); + static uint8_t setGain_all(const uint8_t value); + static uint16_t getValue(const uint8_t channel); + static uint8_t fastWrite(); + static uint8_t simpleCommand(const byte simpleCommand); + static uint8_t getDrvPct(const uint8_t channel); + static void setDrvPct(xyze_uint8_t &pct); +}; + +extern MCP4728 mcp4728; diff --git a/Marlin/src/feature/dac/stepper_dac.cpp b/Marlin/src/feature/dac/stepper_dac.cpp index 6b140a002510..5f10b4ccfbdc 100644 --- a/Marlin/src/feature/dac/stepper_dac.cpp +++ b/Marlin/src/feature/dac/stepper_dac.cpp @@ -26,7 +26,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "stepper_dac.h" #include "../../MarlinCore.h" // for SP_X_LBL... @@ -35,56 +35,53 @@ bool dac_present = false; constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER; xyze_uint8_t dac_channel_pct = DAC_MOTOR_CURRENT_DEFAULT; -int dac_init() { +StepperDAC stepper_dac; + +int StepperDAC::init() { #if PIN_EXISTS(DAC_DISABLE) OUT_WRITE(DAC_DISABLE_PIN, LOW); // set pin low to enable DAC #endif - mcp4728_init(); + mcp4728.init(); - if (mcp4728_simpleCommand(RESET)) return -1; + if (mcp4728.simpleCommand(RESET)) return -1; dac_present = true; - mcp4728_setVref_all(DAC_STEPPER_VREF); - mcp4728_setGain_all(DAC_STEPPER_GAIN); + mcp4728.setVref_all(DAC_STEPPER_VREF); + mcp4728.setGain_all(DAC_STEPPER_GAIN); - if (mcp4728_getDrvPct(0) < 1 || mcp4728_getDrvPct(1) < 1 || mcp4728_getDrvPct(2) < 1 || mcp4728_getDrvPct(3) < 1 ) { - mcp4728_setDrvPct(dac_channel_pct); - mcp4728_eepromWrite(); + if (mcp4728.getDrvPct(0) < 1 || mcp4728.getDrvPct(1) < 1 || mcp4728.getDrvPct(2) < 1 || mcp4728.getDrvPct(3) < 1 ) { + mcp4728.setDrvPct(dac_channel_pct); + mcp4728.eepromWrite(); } return 0; } -void dac_current_percent(uint8_t channel, float val) { +void StepperDAC::set_current_value(const uint8_t channel, uint16_t val) { if (!dac_present) return; - NOMORE(val, 100); + NOMORE(val, uint16_t(DAC_STEPPER_MAX)); - mcp4728_analogWrite(dac_order[channel], val * 0.01 * (DAC_STEPPER_MAX)); - mcp4728_simpleCommand(UPDATE); + mcp4728.analogWrite(dac_order[channel], val); + mcp4728.simpleCommand(UPDATE); } -void dac_current_raw(uint8_t channel, uint16_t val) { - if (!dac_present) return; - - NOMORE(val, uint16_t(DAC_STEPPER_MAX)); - - mcp4728_analogWrite(dac_order[channel], val); - mcp4728_simpleCommand(UPDATE); +void StepperDAC::set_current_percent(const uint8_t channel, float val) { + set_current_value(channel, _MIN(val, 100.0f) * (DAC_STEPPER_MAX) / 100.0f); } -static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); } -static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); } +static float dac_perc(int8_t n) { return 100.0 * mcp4728.getValue(dac_order[n]) * RECIPROCAL(DAC_STEPPER_MAX); } +static float dac_amps(int8_t n) { return mcp4728.getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * RECIPROCAL(DAC_STEPPER_SENSE); } -uint8_t dac_current_get_percent(const AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); } -void dac_current_set_percents(xyze_uint8_t &pct) { +uint8_t StepperDAC::get_current_percent(const AxisEnum axis) { return mcp4728.getDrvPct(dac_order[axis]); } +void StepperDAC::set_current_percents(xyze_uint8_t &pct) { LOOP_XYZE(i) dac_channel_pct[i] = pct[dac_order[i]]; - mcp4728_setDrvPct(dac_channel_pct); + mcp4728.setDrvPct(dac_channel_pct); } -void dac_print_values() { +void StepperDAC::print_values() { if (!dac_present) return; SERIAL_ECHO_MSG("Stepper current values in % (Amps):"); SERIAL_ECHO_START(); @@ -94,9 +91,9 @@ void dac_print_values() { SERIAL_ECHOLNPAIR_P(SP_E_LBL, dac_perc(E_AXIS), PSTR(" ("), dac_amps(E_AXIS), PSTR(")")); } -void dac_commit_eeprom() { +void StepperDAC::commit_eeprom() { if (!dac_present) return; - mcp4728_eepromWrite(); + mcp4728.eepromWrite(); } -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/feature/dac/stepper_dac.h b/Marlin/src/feature/dac/stepper_dac.h index 0543b6275e2c..6836335e9806 100644 --- a/Marlin/src/feature/dac/stepper_dac.h +++ b/Marlin/src/feature/dac/stepper_dac.h @@ -27,10 +27,15 @@ #include "dac_mcp4728.h" -int dac_init(); -void dac_current_percent(uint8_t channel, float val); -void dac_current_raw(uint8_t channel, uint16_t val); -void dac_print_values(); -void dac_commit_eeprom(); -uint8_t dac_current_get_percent(AxisEnum axis); -void dac_current_set_percents(xyze_uint8_t &pct); +class StepperDAC { +public: + static int init(); + static void set_current_percent(const uint8_t channel, float val); + static void set_current_value(const uint8_t channel, uint16_t val); + static void print_values(); + static void commit_eeprom(); + static uint8_t get_current_percent(AxisEnum axis); + static void set_current_percents(xyze_uint8_t &pct); +}; + +extern StepperDAC stepper_dac; diff --git a/Marlin/src/feature/digipot/digipot.h b/Marlin/src/feature/digipot/digipot.h index d59f8b930af5..c53f8093dd52 100644 --- a/Marlin/src/feature/digipot/digipot.h +++ b/Marlin/src/feature/digipot/digipot.h @@ -21,5 +21,13 @@ */ #pragma once -void digipot_i2c_set_current(const uint8_t channel, const float current); -void digipot_i2c_init(); +// +// Header for MCP4018 and MCP4451 current control i2c devices +// +class DigipotI2C { +public: + static void init(); + static void set_current(const uint8_t channel, const float current); +}; + +DigipotI2C digipot_i2c; diff --git a/Marlin/src/feature/digipot/digipot_mcp4018.cpp b/Marlin/src/feature/digipot/digipot_mcp4018.cpp index 35c513a32c39..6260185fc32d 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4018.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4018.cpp @@ -24,6 +24,8 @@ #if ENABLED(DIGIPOT_MCP4018) +#include "digipot.h" + #include #include // https://github.com/stawel/SlowSoftI2CMaster @@ -68,7 +70,7 @@ static SlowSoftI2CMaster pots[DIGIPOT_I2C_NUM_CHANNELS] = { #endif }; -static void i2c_send(const uint8_t channel, const byte v) { +static void digipot_i2c_send(const uint8_t channel, const byte v) { if (WITHIN(channel, 0, DIGIPOT_I2C_NUM_CHANNELS - 1)) { pots[channel].i2c_start(((DIGIPOT_I2C_ADDRESS_A) << 1) | I2C_WRITE); pots[channel].i2c_write(v); @@ -77,12 +79,12 @@ static void i2c_send(const uint8_t channel, const byte v) { } // This is for the MCP4018 I2C based digipot -void digipot_i2c_set_current(const uint8_t channel, const float current) { +void DigipotI2C::set_current(const uint8_t channel, const float current) { const float ival = _MIN(_MAX(current, 0), float(DIGIPOT_MCP4018_MAX_VALUE)); - i2c_send(channel, current_to_wiper(ival)); + digipot_i2c_send(channel, current_to_wiper(ival)); } -void digipot_i2c_init() { +void DigipotI2C::init() { LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS) pots[i].i2c_init(); // Init currents according to Configuration_adv.h @@ -94,7 +96,7 @@ void digipot_i2c_init() { #endif ; LOOP_L_N(i, COUNT(digipot_motor_current)) - digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i])); + set_current(i, pgm_read_float(&digipot_motor_current[i])); } #endif // DIGIPOT_MCP4018 diff --git a/Marlin/src/feature/digipot/digipot_mcp4451.cpp b/Marlin/src/feature/digipot/digipot_mcp4451.cpp index 0c8ff04a0bbf..7e6ace49a06a 100644 --- a/Marlin/src/feature/digipot/digipot_mcp4451.cpp +++ b/Marlin/src/feature/digipot/digipot_mcp4451.cpp @@ -24,6 +24,8 @@ #if ENABLED(DIGIPOT_MCP4451) +#include "digipot.h" + #include #include @@ -61,7 +63,7 @@ static void digipot_i2c_send(const byte addr, const byte a, const byte b) { } // This is for the MCP4451 I2C based digipot -void digipot_i2c_set_current(const uint8_t channel, const float current) { +void DigipotI2C::set_current(const uint8_t channel, const float current) { // These addresses are specific to Azteeg X3 Pro, can be set to others. // In this case first digipot is at address A0=0, A1=0, second one is at A0=0, A1=1 const byte addr = channel < 4 ? DIGIPOT_I2C_ADDRESS_A : DIGIPOT_I2C_ADDRESS_B; // channel 0-3 vs 4-7 @@ -75,7 +77,7 @@ void digipot_i2c_set_current(const uint8_t channel, const float current) { digipot_i2c_send(addr, addresses[channel & 0x3], current_to_wiper(_MIN(float(_MAX(current, 0)), DIGIPOT_I2C_MAX_CURRENT))); } -void digipot_i2c_init() { +void DigipotI2C::init() { #if MB(MKS_SBASE) configure_i2c(16); // Set clock_option to 16 ensure I2C is initialized at 400kHz #else @@ -90,7 +92,7 @@ void digipot_i2c_init() { #endif ; LOOP_L_N(i, COUNT(digipot_motor_current)) - digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i])); + set_current(i, pgm_read_float(&digipot_motor_current[i])); } #endif // DIGIPOT_MCP4451 diff --git a/Marlin/src/gcode/feature/digipot/M907-M910.cpp b/Marlin/src/gcode/feature/digipot/M907-M910.cpp index 54599a045134..e46366620798 100644 --- a/Marlin/src/gcode/feature/digipot/M907-M910.cpp +++ b/Marlin/src/gcode/feature/digipot/M907-M910.cpp @@ -22,19 +22,19 @@ #include "../../../inc/MarlinConfig.h" -#if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) +#if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) #include "../../gcode.h" -#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM +#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM #include "../../../module/stepper.h" #endif -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #include "../../../feature/digipot/digipot.h" #endif -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "../../../feature/dac/stepper_dac.h" #endif @@ -42,61 +42,61 @@ * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S */ void GcodeSuite::M907() { - #if HAS_DIGIPOTSS + #if HAS_MOTOR_CURRENT_SPI - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.digipot_current(i, parser.value_int()); - if (parser.seenval('B')) stepper.digipot_current(4, parser.value_int()); - if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.digipot_current(i, parser.value_int()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper.set_digipot_current(i, parser.value_int()); + if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int()); + if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int()); #elif HAS_MOTOR_CURRENT_PWM #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY) - if (parser.seenval('X') || parser.seenval('Y')) stepper.digipot_current(0, parser.value_int()); + if (parser.seenval('X') || parser.seenval('Y')) stepper.set_digipot_current(0, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) - if (parser.seenval('Z')) stepper.digipot_current(1, parser.value_int()); + if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int()); #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_E) - if (parser.seenval('E')) stepper.digipot_current(2, parser.value_int()); + if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int()); #endif #endif - #if HAS_I2C_DIGIPOT + #if HAS_MOTOR_CURRENT_I2C // this one uses actual amps in floating point - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c_set_current(i, parser.value_float()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) digipot_i2c.set_current(i, parser.value_float()); // Additional extruders use B,C,D for channels 4,5,6. // TODO: Change these parameters because 'E' is used. B? for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++) - if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c_set_current(i, parser.value_float()); + if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float()); #endif - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) if (parser.seenval('S')) { const float dac_percent = parser.value_float(); - LOOP_LE_N(i, 4) dac_current_percent(i, dac_percent); + LOOP_LE_N(i, 4) stepper_dac.set_current_percent(i, dac_percent); } - LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) dac_current_percent(i, parser.value_float()); + LOOP_XYZE(i) if (parser.seenval(axis_codes[i])) stepper_dac.set_current_percent(i, parser.value_float()); #endif } -#if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) +#if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) /** * M908: Control digital trimpot directly (M908 P S) */ void GcodeSuite::M908() { - TERN_(HAS_DIGIPOTSS, stepper.digitalPotWrite(parser.intval('P'), parser.intval('S'))); - TERN_(DAC_STEPPER_CURRENT, dac_current_raw(parser.byteval('P', -1), parser.ushortval('S', 0))); + TERN_(HAS_MOTOR_CURRENT_SPI, stepper.set_digipot_value_spi(parser.intval('P'), parser.intval('S'))); + TERN_(HAS_MOTOR_CURRENT_DAC, stepper_dac.set_current_value(parser.byteval('P', -1), parser.ushortval('S', 0))); } -#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT + #if ENABLED(HAS_MOTOR_CURRENT_DAC) -#if ENABLED(DAC_STEPPER_CURRENT) + void GcodeSuite::M909() { stepper_dac.print_values(); } + void GcodeSuite::M910() { stepper_dac.commit_eeprom(); } - void GcodeSuite::M909() { dac_print_values(); } - void GcodeSuite::M910() { dac_commit_eeprom(); } + #endif // HAS_MOTOR_CURRENT_DAC -#endif // DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_DAC -#endif // HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || HAS_I2C_DIGIPOT || DAC_STEPPER_CURRENT +#endif // HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM || HAS_MOTOR_CURRENT_I2C || HAS_MOTOR_CURRENT_DAC diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 3f51272c662a..f2bd81e670dc 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -823,11 +823,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 900: M900(); break; // M900: Set advance K factor. #endif - #if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) + #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) case 907: M907(); break; // M907: Set digital trimpot motor current using axis codes. - #if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) + #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) case 908: M908(); break; // M908: Control digital trimpot directly. - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) case 909: M909(); break; // M909: Print digipot/DAC current value case 910: M910(); break; // M910: Commit digipot/DAC value to external EEPROM #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 3ba2451919be..3d745eff8939 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -258,9 +258,9 @@ * M900 - Get or Set Linear Advance K-factor. (Requires LIN_ADVANCE) * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660 or L6470) * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots) - * M908 - Control digital trimpot directly. (Requires DAC_STEPPER_CURRENT or DIGIPOTSS_PIN) - * M909 - Print digipot/DAC current value. (Requires DAC_STEPPER_CURRENT) - * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires DAC_STEPPER_CURRENT) + * M908 - Control digital trimpot directly. (Requires HAS_MOTOR_CURRENT_DAC or DIGIPOTSS_PIN) + * M909 - Print digipot/DAC current value. (Requires HAS_MOTOR_CURRENT_DAC) + * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires HAS_MOTOR_CURRENT_DAC) * M911 - Report stepper driver overtemperature pre-warn condition. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660) * M913 - Set HYBRID_THRESHOLD speed. (Requires HYBRID_THRESHOLD) @@ -848,11 +848,11 @@ class GcodeSuite { static void M918(); #endif - #if ANY(HAS_DIGIPOTSS, HAS_MOTOR_CURRENT_PWM, HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT) + #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC) static void M907(); - #if EITHER(HAS_DIGIPOTSS, DAC_STEPPER_CURRENT) + #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC) static void M908(); - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) static void M909(); static void M910(); #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 0952148d1989..255470bca6e7 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -175,7 +175,7 @@ #endif #if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451) - #define HAS_I2C_DIGIPOT 1 + #define HAS_MOTOR_CURRENT_I2C 1 #endif // Multiple Z steppers diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index f832137f5b40..798bf009c639 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1976,7 +1976,7 @@ #define HAS_STEPPER_RESET 1 #endif #if PIN_EXISTS(DIGIPOTSS) - #define HAS_DIGIPOTSS 1 + #define HAS_MOTOR_CURRENT_SPI 1 #endif #if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_E) #define HAS_MOTOR_CURRENT_PWM 1 diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 820d8a04b561..016afbd3bcd3 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2667,7 +2667,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal /** * Digipot requirement */ -#if HAS_I2C_DIGIPOT +#if HAS_MOTOR_CURRENT_I2C #if BOTH(DIGIPOT_MCP4018, DIGIPOT_MCP4451) #error "Enable only one of DIGIPOT_MCP4018 or DIGIPOT_MCP4451." #elif !MB(MKS_SBASE) \ diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index 68a10245e951..642d9d84d94f 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -58,16 +58,16 @@ void menu_tmc(); void menu_backlash(); -#if ENABLED(DAC_STEPPER_CURRENT) +#if ENABLED(HAS_MOTOR_CURRENT_DAC) #include "../../feature/dac/stepper_dac.h" void menu_dac() { static xyze_uint8_t driverPercent; - LOOP_XYZE(i) driverPercent[i] = dac_current_get_percent((AxisEnum)i); + LOOP_XYZE(i) driverPercent[i] = stepper_dac.get_current_percent((AxisEnum)i); START_MENU(); BACK_ITEM(MSG_ADVANCED_SETTINGS); - #define EDIT_DAC_PERCENT(A) EDIT_ITEM(uint8, MSG_DAC_PERCENT_##A, &driverPercent[_AXIS(A)], 0, 100, []{ dac_current_set_percents(driverPercent); }) + #define EDIT_DAC_PERCENT(A) EDIT_ITEM(uint8, MSG_DAC_PERCENT_##A, &driverPercent[_AXIS(A)], 0, 100, []{ stepper_dac.set_current_percents(driverPercent); }) EDIT_DAC_PERCENT(X); EDIT_DAC_PERCENT(Y); EDIT_DAC_PERCENT(Z); @@ -568,7 +568,7 @@ void menu_advanced_settings() { SUBMENU(MSG_BACKLASH, menu_backlash); #endif - #if ENABLED(DAC_STEPPER_CURRENT) + #if ENABLED(HAS_MOTOR_CURRENT_DAC) SUBMENU(MSG_DRIVE_STRENGTH, menu_dac); #endif #if HAS_MOTOR_CURRENT_PWM diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 3ccd8ffd9185..33e5c351abc1 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -36,7 +36,7 @@ */ // Change EEPROM version if the structure changes -#define EEPROM_VERSION "V81" +#define EEPROM_VERSION "V82" #define EEPROM_OFFSET 100 // Check the integrity of data offsets. @@ -365,7 +365,10 @@ typedef struct SettingsDataStruct { // // HAS_MOTOR_CURRENT_PWM // - uint32_t motor_current_setting[3]; // M907 X Z E + #ifndef MOTOR_CURRENT_COUNT + #define MOTOR_CURRENT_COUNT 3 + #endif + uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E // // CNC_COORDINATE_SYSTEMS @@ -1277,10 +1280,10 @@ void MarlinSettings::postprocess() { { _FIELD_TEST(motor_current_setting); - #if HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM EEPROM_WRITE(stepper.motor_current_setting); #else - const uint32_t no_current[3] = { 0 }; + const uint32_t no_current[MOTOR_CURRENT_COUNT] = { 0 }; EEPROM_WRITE(no_current); #endif } @@ -2110,10 +2113,16 @@ void MarlinSettings::postprocess() { // Motor Current PWM // { - uint32_t motor_current_setting[3]; _FIELD_TEST(motor_current_setting); + uint32_t motor_current_setting[MOTOR_CURRENT_COUNT] + #if HAS_MOTOR_CURRENT_SPI + = DIGIPOT_MOTOR_CURRENT + #endif + ; + DEBUG_ECHOLNPGM("DIGIPOTS Loading"); EEPROM_READ(motor_current_setting); - #if HAS_MOTOR_CURRENT_PWM + DEBUG_ECHOLNPGM("DIGIPOTS Loaded"); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM if (!validating) COPY(stepper.motor_current_setting, motor_current_setting); #endif @@ -2791,9 +2800,20 @@ void MarlinSettings::reset() { // #if HAS_MOTOR_CURRENT_PWM - constexpr uint32_t tmp_motor_current_setting[3] = PWM_MOTOR_CURRENT; - LOOP_L_N(q, 3) - stepper.digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q])); + constexpr uint32_t tmp_motor_current_setting[MOTOR_CURRENT_COUNT] = PWM_MOTOR_CURRENT; + LOOP_L_N(q, MOTOR_CURRENT_COUNT) + stepper.set_digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q])); + #endif + + // + // DIGIPOTS + // + #if HAS_MOTOR_CURRENT_SPI + static constexpr uint32_t tmp_motor_current_setting[] = DIGIPOT_MOTOR_CURRENT; + DEBUG_ECHOLNPGM("Writing Digipot"); + LOOP_L_N(q, COUNT(tmp_motor_current_setting)) + stepper.set_digipot_current(q, tmp_motor_current_setting[q]); + DEBUG_ECHOLNPGM("Digipot Written"); #endif // @@ -3695,14 +3715,23 @@ void MarlinSettings::reset() { #endif #endif - #if HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM CONFIG_ECHO_HEADING("Stepper motor currents:"); CONFIG_ECHO_START(); - SERIAL_ECHOLNPAIR_P( - PSTR(" M907 X"), stepper.motor_current_setting[0] - , SP_Z_STR, stepper.motor_current_setting[1] - , SP_E_STR, stepper.motor_current_setting[2] - ); + #if HAS_MOTOR_CURRENT_PWM + SERIAL_ECHOLNPAIR_P( + PSTR(" M907 X"), stepper.motor_current_setting[0] + , SP_Z_STR, stepper.motor_current_setting[1] + , SP_E_STR, stepper.motor_current_setting[2] + ); + #elif HAS_MOTOR_CURRENT_SPI + SERIAL_ECHOPGM(" M907"); + LOOP_L_N(q, MOTOR_CURRENT_COUNT) { + SERIAL_CHAR(' '); + SERIAL_CHAR(axis_codes[q]); + SERIAL_ECHO(stepper.motor_current_setting[q]); + } + #endif #endif /** diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 56a75d1b4812..8a5de4b6087b 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -83,10 +83,6 @@ Stepper stepper; // Singleton #define BABYSTEPPING_EXTRA_DIR_WAIT -#if HAS_MOTOR_CURRENT_PWM - bool Stepper::initialized; // = false -#endif - #ifdef __AVR__ #include "speed_lookuptable.h" #endif @@ -110,7 +106,7 @@ Stepper stepper; // Singleton #include "../feature/dac/dac_dac084s085.h" #endif -#if HAS_DIGIPOTSS +#if HAS_MOTOR_CURRENT_SPI #include #endif @@ -142,8 +138,12 @@ Stepper stepper; // Singleton bool Stepper::separate_multi_axis = false; #endif -#if HAS_MOTOR_CURRENT_PWM - uint32_t Stepper::motor_current_setting[3]; // Initialized by settings.load() +#if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + bool Stepper::initialized; // = false + uint32_t Stepper::motor_current_setting[MOTOR_CURRENT_COUNT]; // Initialized by settings.load() + #if HAS_MOTOR_CURRENT_SPI + constexpr uint32_t Stepper::digipot_count[]; + #endif #endif // private: @@ -2590,8 +2590,8 @@ void Stepper::init() { set_directions(); - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM - TERN_(HAS_MOTOR_CURRENT_PWM, initialized = true); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + initialized = true; digipot_init(); #endif } @@ -2930,10 +2930,10 @@ void Stepper::report_positions() { * Software-controlled Stepper Motor Current */ -#if HAS_DIGIPOTSS +#if HAS_MOTOR_CURRENT_SPI // From Arduino DigitalPotControl example - void Stepper::digitalPotWrite(const int16_t address, const int16_t value) { + void Stepper::set_digipot_value_spi(const int16_t address, const int16_t value) { WRITE(DIGIPOTSS_PIN, LOW); // Take the SS pin low to select the chip SPI.transfer(address); // Send the address and value via SPI SPI.transfer(value); @@ -2941,7 +2941,7 @@ void Stepper::report_positions() { //delay(10); } -#endif // HAS_DIGIPOTSS +#endif // HAS_MOTOR_CURRENT_SPI #if HAS_MOTOR_CURRENT_PWM @@ -2958,7 +2958,7 @@ void Stepper::report_positions() { #if ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_E0, MOTOR_CURRENT_PWM_E1) case 2: #endif - digipot_current(i, motor_current_setting[i]); + set_digipot_current(i, motor_current_setting[i]); default: break; } } @@ -2968,21 +2968,22 @@ void Stepper::report_positions() { #if !MB(PRINTRBOARD_G2) - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM - void Stepper::digipot_current(const uint8_t driver, const int16_t current) { + void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) { + if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) + motor_current_setting[driver] = current; // update motor_current_setting - #if HAS_DIGIPOTSS + if (!initialized) return; - const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; - digitalPotWrite(digipot_ch[driver], current); + #if HAS_MOTOR_CURRENT_SPI - #elif HAS_MOTOR_CURRENT_PWM + //SERIAL_ECHOLNPAIR("Digipotss current ", current); - if (!initialized) return; + const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; + set_digipot_value_spi(digipot_ch[driver], current); - if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) - motor_current_setting[driver] = current; // update motor_current_setting + #elif HAS_MOTOR_CURRENT_PWM #define _WRITE_CURRENT_PWM(P) analogWrite(pin_t(MOTOR_CURRENT_PWM_## P ##_PIN), 255L * current / (MOTOR_CURRENT_PWM_RANGE)) switch (driver) { @@ -3019,17 +3020,13 @@ void Stepper::report_positions() { void Stepper::digipot_init() { - #if HAS_DIGIPOTSS - - static const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT; + #if HAS_MOTOR_CURRENT_SPI SPI.begin(); SET_OUTPUT(DIGIPOTSS_PIN); - LOOP_L_N(i, COUNT(digipot_motor_current)) { - //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]); - digipot_current(i, digipot_motor_current[i]); - } + LOOP_L_N(i, COUNT(motor_current_setting)) + set_digipot_current(i, motor_current_setting[i]); #elif HAS_MOTOR_CURRENT_PWM diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index da38192d8ea3..572c3f3f9b2d 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -245,12 +245,18 @@ class Stepper { static bool separate_multi_axis; #endif - #if HAS_MOTOR_CURRENT_PWM - #ifndef PWM_MOTOR_CURRENT - #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_PWM + #ifndef PWM_MOTOR_CURRENT + #define PWM_MOTOR_CURRENT DEFAULT_PWM_MOTOR_CURRENT + #endif + #define MOTOR_CURRENT_COUNT 3 + #elif HAS_MOTOR_CURRENT_SPI + static constexpr uint32_t digipot_count[] = DIGIPOT_MOTOR_CURRENT; + #define MOTOR_CURRENT_COUNT COUNT(Stepper::digipot_count) #endif - static uint32_t motor_current_setting[3]; static bool initialized; + static uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // Initialized by settings.load() #endif // Last-moved extruder, as set when the last movement was fetched from planner @@ -457,9 +463,9 @@ class Stepper { // Triggered position of an axis in steps static int32_t triggered_position(const AxisEnum axis); - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM - static void digitalPotWrite(const int16_t address, const int16_t value); - static void digipot_current(const uint8_t driver, const int16_t current); + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM + static void set_digipot_value_spi(const int16_t address, const int16_t value); + static void set_digipot_current(const uint8_t driver, const int16_t current); #endif #if HAS_MICROSTEPS @@ -582,7 +588,7 @@ class Stepper { static int32_t _eval_bezier_curve(const uint32_t curr_step); #endif - #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM + #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM static void digipot_init(); #endif diff --git a/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h b/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h index 406cbec8167f..1428de31a22b 100644 --- a/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h +++ b/Marlin/src/pins/ramps/pins_RIGIDBOARD_V2.h @@ -34,7 +34,7 @@ // // I2C based DAC like on the Printrboard REVF -#define DAC_STEPPER_CURRENT +#define HAS_MOTOR_CURRENT_DAC // Channels available for DAC, For Rigidboard there are 4 #define DAC_STEPPER_ORDER { 0, 1, 2, 3 } diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h index 6ffd35dff273..4809cc8d86b8 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h @@ -143,7 +143,7 @@ #endif // NO_EXTRUDRBOARD // Enable control of stepper motor currents with the I2C based MCP4728 DAC used on Printrboard REVF -#define DAC_STEPPER_CURRENT +#define HAS_MOTOR_CURRENT_DAC // Set default drive strength percents if not already defined - X, Y, Z, E axis #ifndef DAC_MOTOR_CURRENT_DEFAULT diff --git a/platformio.ini b/platformio.ini index 10b9f899d581..035d1b2aad6b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -212,7 +212,7 @@ HAS_TRINAMIC_CONFIG = TMCStepper@~0.7.1 src_filter=+ + + + + HAS_STEALTHCHOP = src_filter=+ SR_LCD_3W_NL = SailfishLCD=https://github.com/mikeshub/SailfishLCD/archive/master.zip -HAS_I2C_DIGIPOT = SlowSoftI2CMaster +HAS_MOTOR_CURRENT_I2C = SlowSoftI2CMaster src_filter=+ HAS_TMC26X = TMC26XStepper=https://github.com/trinamic/TMC26XStepper/archive/master.zip src_filter=+ @@ -278,7 +278,7 @@ CANCEL_OBJECTS = src_filter=+ + + EXTERNAL_CLOSED_LOOP_CONTROLLER = src_filter=+ + USE_CONTROLLER_FAN = src_filter=+ -DAC_STEPPER_CURRENT = src_filter=+ +HAS_MOTOR_CURRENT_DAC = src_filter=+ DIRECT_STEPPING = src_filter=+ + EMERGENCY_PARSER = src_filter=+ - I2C_POSITION_ENCODERS = src_filter=+ From 7d030ba27f9e6c7ffaaead6c96711ceefab38fe0 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 16:13:01 -0700 Subject: [PATCH 38/46] Fix at90usb1286 build (#19687) * Skip check for USBCON during dependency detection * Ignore incompatible Teensy_ADC library, which requires Teensy >= 3 * Add IS_AT90USB Co-authored-by: Scott Lahteine --- Marlin/src/HAL/AVR/HAL.h | 4 ++-- Marlin/src/HAL/AVR/MarlinSerial.cpp | 6 +++--- Marlin/src/HAL/AVR/MarlinSerial.h | 2 +- Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp | 3 +-- Marlin/src/gcode/control/M111.cpp | 4 ++-- Marlin/src/gcode/queue.cpp | 2 +- Marlin/src/inc/Conditionals_adv.h | 8 ++++---- Marlin/src/inc/SanityCheck.h | 6 +++--- Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h | 2 +- platformio.ini | 1 + 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h index ce15ed29fb3a..6e0afa8f10ed 100644 --- a/Marlin/src/HAL/AVR/HAL.h +++ b/Marlin/src/HAL/AVR/HAL.h @@ -25,7 +25,7 @@ #include "watchdog.h" #include "math.h" -#ifdef USBCON +#ifdef IS_AT90USB #include #else #define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion @@ -81,7 +81,7 @@ typedef int8_t pin_t; //extern uint8_t MCUSR; // Serial ports -#ifdef USBCON +#ifdef IS_AT90USB #define MYSERIAL0 TERN(BLUETOOTH, bluetoothSerial, Serial) #else #if !WITHIN(SERIAL_PORT, -1, 3) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 63599efd4132..8feac32aa74c 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -38,7 +38,7 @@ #include "../../inc/MarlinConfig.h" -#if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) +#if !IS_AT90USB && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)) #include "MarlinSerial.h" #include "../../MarlinCore.h" @@ -792,10 +792,10 @@ MarlinSerial> customizedSerial1; #endif -#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) +#endif // !IS_AT90USB && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) // For AT90USB targets use the UART for BT interfacing -#if defined(USBCON) && ENABLED(BLUETOOTH) +#if BOTH(IS_AT90USB, BLUETOOTH) HardwareSerial bluetoothSerial; #endif diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index 8a0423d143d8..3850e2a47e2a 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -327,6 +327,6 @@ #endif // Use the UART for Bluetooth in AT90USB configurations -#if defined(USBCON) && ENABLED(BLUETOOTH) +#if BOTH(IS_AT90USB, BLUETOOTH) extern HardwareSerial bluetoothSerial; #endif diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp index f88fa8850788..60596054e820 100644 --- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp +++ b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp @@ -22,7 +22,6 @@ #if BOTH(HAS_MARLINUI_U8GLIB, FORCE_SOFT_SPI) -#include "../HAL.h" #include #undef SPI_SPEED @@ -161,5 +160,5 @@ uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, return 1; } -#endif // HAS_MARLINUI_U8GLIB +#endif // HAS_MARLINUI_U8GLIB && FORCE_SOFT_SPI #endif // STM32F1 diff --git a/Marlin/src/gcode/control/M111.cpp b/Marlin/src/gcode/control/M111.cpp index e31c3e2fb7b2..cc871bf38b52 100644 --- a/Marlin/src/gcode/control/M111.cpp +++ b/Marlin/src/gcode/control/M111.cpp @@ -55,7 +55,7 @@ void GcodeSuite::M111() { } else { SERIAL_ECHOPGM(STR_DEBUG_OFF); - #if !defined(__AVR__) || !defined(USBCON) + #if !IS_AT90USB #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS) SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns()); #endif @@ -71,7 +71,7 @@ void GcodeSuite::M111() { #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued()); #endif - #endif // !defined(__AVR__) || !defined(USBCON) + #endif // !IS_AT90USB } SERIAL_EOL(); } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index b9169d90e1c7..a02d2c016042 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -624,7 +624,7 @@ void GCodeQueue::advance() { card.closefile(); SERIAL_ECHOLNPGM(STR_FILE_SAVED); - #if !defined(__AVR__) || !defined(USBCON) + #if !IS_AT90USB #if ENABLED(SERIAL_STATS_DROPPED_RX) SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped()); #endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 255470bca6e7..bab05e5ff60d 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -208,7 +208,10 @@ #define NEEDS_HARDWARE_PWM 1 #endif -#if !defined(__AVR__) || !defined(USBCON) +#if defined(__AVR__) && defined(USBCON) + #define IS_AT90USB 1 + #undef SERIAL_XON_XOFF // Not supported on USB-native devices +#else // Define constants and variables for buffering serial data. // Use only 0 or powers of 2 greater than 1 // : [0, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...] @@ -220,9 +223,6 @@ #ifndef TX_BUFFER_SIZE #define TX_BUFFER_SIZE 32 #endif -#else - // SERIAL_XON_XOFF not supported on USB-native devices - #undef SERIAL_XON_XOFF #endif #if ENABLED(HOST_ACTION_COMMANDS) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 016afbd3bcd3..b7007e3be555 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -582,7 +582,7 @@ /** * Serial */ -#if !(defined(__AVR__) && defined(USBCON)) +#if !IS_AT90USB #if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024 #error "SERIAL_XON_XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops." #elif RX_BUFFER_SIZE && (RX_BUFFER_SIZE < 2 || !IS_POWER_OF_2(RX_BUFFER_SIZE)) @@ -2104,9 +2104,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #endif /** - * emergency-command parser + * Emergency Command Parser */ -#if ENABLED(EMERGENCY_PARSER) && defined(__AVR__) && defined(USBCON) +#if BOTH(IS_AT90USB, EMERGENCY_PARSER) #error "EMERGENCY_PARSER does not work on boards with AT90USB processors (USBCON)." #endif diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h index 4809cc8d86b8..d4f9fc76415d 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h @@ -67,7 +67,7 @@ #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" #endif -#ifndef USBCON +#if !defined(__MARLIN_DEPS__) && !defined(USBCON) #error "USBCON should be defined by the platform for this board." #endif diff --git a/platformio.ini b/platformio.ini index 035d1b2aad6b..9c9460d1a32a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -559,6 +559,7 @@ build_unflags = -g -ggdb platform = teensy extends = common_avr8 board = at90usb1286 +lib_ignore = ${env:common_avr8.lib_ignore} Teensy_ADC # # AT90USB1286 boards using DFU bootloader From 1dc8f0c77cf62cb5cf75dfe05b6f518dedd029e2 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:06:57 -0700 Subject: [PATCH 39/46] Fix various errors, warnings in example config builds (#19686) Co-authored-by: Scott Lahteine --- Marlin/src/gcode/bedlevel/G26.cpp | 8 +- Marlin/src/gcode/motion/M290.cpp | 2 +- Marlin/src/lcd/dogm/dogm_Statusscreen.h | 2 +- .../lcd/extui/lib/mks_ui/draw_printing.cpp | 18 +- .../lib/mks_ui/tft_lvgl_configuration.cpp | 40 ++-- .../src/lcd/extui/lib/mks_ui/wifi_upload.cpp | 182 ++++++++---------- Marlin/src/lcd/menu/menu_delta_calibrate.cpp | 2 +- Marlin/src/lcd/menu/menu_ubl.cpp | 3 +- Marlin/src/module/thermistor/thermistor_666.h | 3 +- Marlin/src/pins/sensitive_pins.h | 29 ++- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h | 1 + 11 files changed, 133 insertions(+), 157 deletions(-) diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index c66d4a7d4974..661128b04ebe 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -511,11 +511,9 @@ void GcodeSuite::G26() { g26_keep_heaters_on = parser.boolval('K'); // Accept 'I' if temperature presets are defined - const uint8_t preset_index = (0 - #if PREHEAT_COUNT - + (parser.seenval('I') ? _MIN(parser.value_byte(), PREHEAT_COUNT - 1) + 1 : 0) - #endif - ); + #if PREHEAT_COUNT + const uint8_t preset_index = parser.seenval('I') ? _MIN(parser.value_byte(), PREHEAT_COUNT - 1) + 1 : 0; + #endif #if HAS_HEATED_BED diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index 7158525ed9d9..18cc161fce29 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -127,7 +127,7 @@ void GcodeSuite::M290() { #else PSTR("Babystep Z") #endif - , babystep.axis_total[BS_AXIS_IND(Z_AXIS)] + , babystep.axis_total[BS_TOTAL_IND(Z_AXIS)] ); } #endif diff --git a/Marlin/src/lcd/dogm/dogm_Statusscreen.h b/Marlin/src/lcd/dogm/dogm_Statusscreen.h index 70802f905e1d..c6ad566cffaf 100644 --- a/Marlin/src/lcd/dogm/dogm_Statusscreen.h +++ b/Marlin/src/lcd/dogm/dogm_Statusscreen.h @@ -1341,7 +1341,7 @@ #undef STATUS_LOGO_WIDTH #endif - #if (HAS_MULTI_HOTEND && STATUS_LOGO_WIDTH && BED_OR_CHAMBER_OR_FAN) || (HOTENDS >= 3 && !BED_OR_CHAMBER_OR_FAN) + #if !defined(STATUS_HEATERS_X) && ((HAS_MULTI_HOTEND && STATUS_LOGO_WIDTH && BED_OR_CHAMBER_OR_FAN) || (HOTENDS >= 3 && !BED_OR_CHAMBER_OR_FAN)) #define _STATUS_HEATERS_X(H,S,N) ((LCD_PIXEL_WIDTH - (H * (S + N)) - (_EXTRA_WIDTH) + (STATUS_LOGO_WIDTH)) / 2) #if STATUS_HOTEND1_WIDTH #if HOTENDS > 2 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp index a81b5b851bb3..c6369db41383 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_printing.cpp @@ -46,7 +46,8 @@ extern lv_group_t * g; static lv_obj_t * scr; -static lv_obj_t *labelExt1, * labelExt2, * labelFan, * labelZpos, * labelTime; +static lv_obj_t *labelExt1, * labelFan, * labelZpos, * labelTime; +TERN_(HAS_MULTI_EXTRUDER, static lv_obj_t *labelExt2;) static lv_obj_t *labelPause, * labelStop, * labelOperat; static lv_obj_t * bar1, *bar1ValueText; static lv_obj_t * buttonPause, *buttonOperat, *buttonStop; @@ -137,9 +138,6 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { } void lv_draw_printing(void) { - lv_obj_t *buttonExt1, *buttonExt2, *buttonFanstate, *buttonZpos, *buttonTime; - TERN_(HAS_HEATED_BED, lv_obj_t * buttonBedstate); - disp_state_stack._disp_index = 0; ZERO(disp_state_stack._disp_state); disp_state_stack._disp_state[disp_state_stack._disp_index] = PRINTING_UI; @@ -162,16 +160,16 @@ void lv_draw_printing(void) { lv_refr_now(lv_refr_get_disp_refreshing()); // Create image buttons - buttonExt1 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt1 = lv_img_create(scr, NULL); #if HAS_MULTI_EXTRUDER - buttonExt2 = lv_img_create(scr, NULL); + lv_obj_t *buttonExt2 = lv_img_create(scr, NULL); #endif #if HAS_HEATED_BED - buttonBedstate = lv_img_create(scr, NULL); + lv_obj_t *buttonBedstate = lv_img_create(scr, NULL); #endif - buttonFanstate = lv_img_create(scr, NULL); - buttonTime = lv_img_create(scr, NULL); - buttonZpos = lv_img_create(scr, NULL); + lv_obj_t *buttonFanstate = lv_img_create(scr, NULL); + lv_obj_t *buttonTime = lv_img_create(scr, NULL); + lv_obj_t *buttonZpos = lv_img_create(scr, NULL); buttonPause = lv_imgbtn_create(scr, NULL); buttonStop = lv_imgbtn_create(scr, NULL); buttonOperat = lv_imgbtn_create(scr, NULL); 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 922848d84f0b..ecd4eb482a6a 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 @@ -442,39 +442,39 @@ void lv_encoder_pin_init() { //static const int8_t encoderDirection = 1; //static int16_t enc_Direction; void lv_update_encoder() { - static uint8_t buttons; static uint32_t encoder_time1; uint32_t tmpTime, diffTime = 0; tmpTime = millis(); diffTime = getTickDiff(tmpTime, encoder_time1); if (diffTime > 50) { - #if ANY_BUTTON(EN1, EN2, ENC, BACK) + #if HAS_ENCODER_WHEEL - uint8_t newbutton = 0; + #if ANY_BUTTON(EN1, EN2, ENC, BACK) - #if BUTTON_EXISTS(EN1) - if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; - #endif - #if BUTTON_EXISTS(EN2) - if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; - #endif - #if BUTTON_EXISTS(ENC) - if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; - #endif - #if BUTTON_EXISTS(BACK) - if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; - #endif + uint8_t newbutton = 0; + + #if BUTTON_EXISTS(EN1) + if (BUTTON_PRESSED(EN1)) newbutton |= EN_A; + #endif + #if BUTTON_EXISTS(EN2) + if (BUTTON_PRESSED(EN2)) newbutton |= EN_B; + #endif + #if BUTTON_EXISTS(ENC) + if (BUTTON_PRESSED(ENC)) newbutton |= EN_C; + #endif + #if BUTTON_EXISTS(BACK) + if (BUTTON_PRESSED(BACK)) newbutton |= EN_D; + #endif - #else + #else - constexpr uint8_t newbutton = 0; + constexpr uint8_t newbutton = 0; - #endif + #endif - buttons = newbutton; - #if HAS_ENCODER_WHEEL + static uint8_t buttons = newbutton; static uint8_t lastEncoderBits; #define encrot0 0 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp index 77bcb767b72d..087a3b21105c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_upload.cpp @@ -110,24 +110,17 @@ const char *resultMessages[] = { // 230400b always manages to connect. static const uint32_t uploadBaudRates[] = { 460800, 230400, 115200, 74880 }; - - signed char IsReady() { return esp_upload.state == upload_idle; } - - - - void uploadPort_write(const uint8_t *buf, size_t len) { #if 0 int i; - for(i = 0; i < len; i++) { - while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); - - USART_SendData(USART1, *(buf + i)); + for (i = 0; i < len; i++) { + while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { /* nada */ } + USART_SendData(USART1, *(buf + i)); } #endif } @@ -138,28 +131,22 @@ char uploadPort_read() { return retChar; else return 0; - } int uploadPort_available() { return usartFifoAvailable(&WifiRxFifo); } - void uploadPort_begin() { esp_port_begin(1); } void uploadPort_close() { - //WIFI_COM.end(); //WIFI_COM.begin(115200, true); - esp_port_begin(0); - } - void flushInput() { while (uploadPort_available() != 0) { (void)uploadPort_read(); @@ -304,7 +291,6 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t *bodyLen = 0; - while (state != done) { uint8_t c; EspUploadResult stat; @@ -322,73 +308,73 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t } // sufficient bytes have been received for the current state, process them - switch(state) { - case begin: // expecting frame start - c = uploadPort_read(); - if (c != (uint8_t)0xC0) { - break; - } - state = header; - needBytes = 2; + switch (state) { + case begin: // expecting frame start + c = uploadPort_read(); + if (c != (uint8_t)0xC0) { + break; + } + state = header; + needBytes = 2; - break; - case end: // expecting frame end - c = uploadPort_read(); - if (c != (uint8_t)0xC0) { - return slipFrame; - } - state = done; + break; + case end: // expecting frame end + c = uploadPort_read(); + if (c != (uint8_t)0xC0) { + return slipFrame; + } + state = done; - break; + break; - case header: // reading an 8-byte header - case body: // reading the response body - { - int rslt; - // retrieve a byte with SLIP decoding - rslt = ReadByte(&c, 1); - if (rslt != 1 && rslt != 2) { - // some error occurred - stat = (rslt == 0 || rslt == -2) ? slipData : slipFrame; - return stat; - } - else if (state == header) { - //store the header byte - hdr[hdrIdx++] = c; - if (hdrIdx >= headerLength) { - // get the body length, prepare a buffer for it - *bodyLen = (uint16_t)getData(2, hdr, 2); - - // extract the value, if requested - if (valp != 0) { - *valp = getData(4, hdr, 4); + case header: // reading an 8-byte header + case body: // reading the response body + { + int rslt; + // retrieve a byte with SLIP decoding + rslt = ReadByte(&c, 1); + if (rslt != 1 && rslt != 2) { + // some error occurred + stat = (rslt == 0 || rslt == -2) ? slipData : slipFrame; + return stat; + } + else if (state == header) { + //store the header byte + hdr[hdrIdx++] = c; + if (hdrIdx >= headerLength) { + // get the body length, prepare a buffer for it + *bodyLen = (uint16_t)getData(2, hdr, 2); + + // extract the value, if requested + if (valp != 0) { + *valp = getData(4, hdr, 4); + } + + if (*bodyLen != 0) { + state = body; + } + else { + needBytes = 1; + state = end; + } } - - if (*bodyLen != 0) { - state = body; + } + else { + // Store the response body byte, check for completion + if (bodyIdx < ARRAY_SIZE(respBuf)) { + respBuf[bodyIdx] = c; } - else { + ++bodyIdx; + if (bodyIdx >= *bodyLen) { needBytes = 1; state = end; } } } - else { - // Store the response body byte, check for completion - if (bodyIdx < ARRAY_SIZE(respBuf)) { - respBuf[bodyIdx] = c; - } - ++bodyIdx; - if (bodyIdx >= *bodyLen) { - needBytes = 1; - state = end; - } - } - } - break; + break; - default: // this shouldn't happen - return slipState; + default: // this shouldn't happen + return slipState; } } @@ -397,7 +383,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t opRet = (uint8_t)getData(1, hdr, 1); // Sync packets often provoke a response with a zero opcode instead of ESP_SYNC if (resp != 0x01 || opRet != op) { -//debug//printf("resp %02x %02x\n", resp, opRet); + //printf("resp %02x %02x\n", resp, opRet); //debug return respHeader; } @@ -432,20 +418,19 @@ void _writePacket(const uint8_t *data, size_t len) { // 0xC0 and 0xDB replaced by the two-byte sequences {0xDB, 0xDC} and {0xDB, 0xDD} respectively. void writePacket(const uint8_t *hdr, size_t hdrLen, const uint8_t *data, size_t dataLen) { - - WriteByteRaw(0xC0); // send the packet start character + WriteByteRaw(0xC0); // send the packet start character _writePacket(hdr, hdrLen); // send the header - _writePacket(data, dataLen); // send the data block - WriteByteRaw(0xC0); // send the packet end character + _writePacket(data, dataLen); // send the data block + WriteByteRaw(0xC0); // send the packet end character } // Send a packet to the serial port while performing SLIP framing. The packet data comprises a header and an optional data block. // This is like writePacket except that it does a fast block write for both the header and the main data with no SLIP encoding. Used to send sync commands. void writePacketRaw(const uint8_t *hdr, size_t hdrLen, const uint8_t *data, size_t dataLen) { - WriteByteRaw(0xC0); // send the packet start character - _writePacketRaw(hdr, hdrLen); // send the header + WriteByteRaw(0xC0); // send the packet start character + _writePacketRaw(hdr, hdrLen); // send the header _writePacketRaw(data, dataLen); // send the data block in raw mode - WriteByteRaw(0xC0); // send the packet end character + WriteByteRaw(0xC0); // send the packet end character } // Send a command to the attached device together with the supplied data, if any. @@ -460,12 +445,10 @@ void sendCommand(uint8_t op, uint32_t checkVal, const uint8_t *data, size_t data // send the packet //flushInput(); - if (op == ESP_SYNC) { + if (op == ESP_SYNC) writePacketRaw(hdr, sizeof(hdr), data, dataLen); - } - else { + else writePacket(hdr, sizeof(hdr), data, dataLen); - } } // Send a command to the attached device together with the supplied data, if any, and get the response @@ -476,9 +459,8 @@ EspUploadResult doCommand(uint8_t op, const uint8_t *data, size_t dataLen, uint3 sendCommand(op, checkVal, data, dataLen); stat = readPacket(op, valp, &bodyLen, msTimeout); - if (stat == success && bodyLen != 2) { + if (stat == success && bodyLen != 2) stat = badReply; - } return stat; } @@ -611,6 +593,8 @@ EspUploadResult flashWriteBlock(uint16_t flashParmVal, uint16_t flashParmMask) { //printf("Upload %d\%\n", ftell(&esp_upload.uploadFile) * 100 / esp_upload.fileSize); return stat; + #else + return success; #endif } @@ -625,15 +609,14 @@ void upload_spin() { esp_upload.uploadResult = connected; esp_upload.state = done; } - else{ + else { // Reset the serial port at the new baud rate. Also reset the ESP8266. - // const uint32_t baud = uploadBaudRates[esp_upload.connectAttemptNumber/esp_upload.retriesPerBaudRate]; + // const uint32_t baud = uploadBaudRates[esp_upload.connectAttemptNumber/esp_upload.retriesPerBaudRate]; if (esp_upload.connectAttemptNumber % esp_upload.retriesPerBaudRate == 0) { } - // uploadPort.begin(baud); - // uploadPort_close(); - + //uploadPort.begin(baud); + //uploadPort_close(); uploadPort_begin(); @@ -654,7 +637,7 @@ void upload_spin() { esp_upload.lastAttemptTime = getWifiTick(); if (res == success) { // Successful connection -// //MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); + //MessageF(" success on attempt %d\n", (connectAttemptNumber % retriesPerBaudRate) + 1); //printf("connect success\n"); esp_upload.state = erasing; } @@ -675,14 +658,13 @@ void upload_spin() { const uint32_t sectorSize = 4096; const uint32_t numSectors = (esp_upload.fileSize + sectorSize - 1)/sectorSize; const uint32_t startSector = esp_upload.uploadAddress/sectorSize; + uint32_t headSectors = sectorsPerBlock - (startSector % sectorsPerBlock); + NOMORE(headSectors, numSectors); - if (numSectors < headSectors) { - headSectors = numSectors; - } - eraseSize = (numSectors < 2 * headSectors) - ? (numSectors + 1) / 2 * sectorSize - : (numSectors - headSectors) * sectorSize; + eraseSize = (numSectors < 2 * headSectors) + ? (numSectors + 1) / 2 * sectorSize + : (numSectors - headSectors) * sectorSize; //MessageF("Erasing %u bytes...\n", fileSize); esp_upload.uploadResult = flashBegin(esp_upload.uploadAddress, eraseSize); @@ -755,7 +737,7 @@ void SendUpdateFile(const char *file, uint32_t address) { if (res != FR_OK) return; - esp_upload.fileSize = f_size(&esp_upload.uploadFile); + esp_upload.fileSize = f_size(&esp_upload.uploadFile); if (esp_upload.fileSize == 0) { f_close(&esp_upload.uploadFile); return; diff --git a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp index 705ec4161120..4efcb7c8eded 100644 --- a/Marlin/src/lcd/menu/menu_delta_calibrate.cpp +++ b/Marlin/src/lcd/menu/menu_delta_calibrate.cpp @@ -118,7 +118,7 @@ void lcd_delta_settings() { } void menu_delta_calibrate() { - const bool all_homed = all_axes_homed(); + TERN_(DELTA_CALIBRATION_MENU, const bool all_homed = all_axes_homed()); // Acquire ahead of loop START_MENU(); BACK_ITEM(MSG_MAIN); diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 2cd300958f8b..f0f5c21beca2 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -188,11 +188,10 @@ void _lcd_ubl_edit_mesh() { */ void _lcd_ubl_validate_custom_mesh() { char ubl_lcd_gcode[24]; - const int16_t temp = TERN(HAS_HEATED_BED, custom_bed_temp, 0); sprintf_P(ubl_lcd_gcode, PSTR("G28\nG26 C P H%" PRIi16 TERN_(HAS_HEATED_BED, " B%" PRIi16)) , custom_hotend_temp #if HAS_HEATED_BED - , temp + , custom_bed_temp #endif ); queue.inject(ubl_lcd_gcode); diff --git a/Marlin/src/module/thermistor/thermistor_666.h b/Marlin/src/module/thermistor/thermistor_666.h index 86493988e053..490dbd5f3ee9 100644 --- a/Marlin/src/module/thermistor/thermistor_666.h +++ b/Marlin/src/module/thermistor/thermistor_666.h @@ -33,8 +33,7 @@ * B: 0.00031362 * C: -2.03978e-07 */ -#define NUMTEMPS 61 -const short temptable_666[NUMTEMPS][2] PROGMEM = { +const temp_entry_t temptable_666[] PROGMEM = { { OV( 1), 794 }, { OV( 18), 288 }, { OV( 35), 234 }, diff --git a/Marlin/src/pins/sensitive_pins.h b/Marlin/src/pins/sensitive_pins.h index 169f74b43787..d7eb1872458f 100644 --- a/Marlin/src/pins/sensitive_pins.h +++ b/Marlin/src/pins/sensitive_pins.h @@ -608,12 +608,6 @@ #define _Z_PROBE #endif -#if TEMP_SENSOR_BED && PIN_EXISTS(HEATER_BED) - #define _HEATER_BED HEATER_BED_PIN, -#else - #define _HEATER_BED -#endif - #if PIN_EXISTS(FAN) #define _FAN0 FAN_PIN, #else @@ -660,21 +654,26 @@ #define _FANC #endif -#if PIN_EXISTS(HEATER_BED) && PIN_EXISTS(TEMP_BED) +#if TEMP_SENSOR_BED && PINS_EXIST(TEMP_BED, HEATER_BED) #define _BED_PINS HEATER_BED_PIN, analogInputToDigitalPin(TEMP_BED_PIN), #else #define _BED_PINS #endif -#if PIN_EXISTS(TEMP_CHAMBER) - #define __CHAMBER_PINS CHAMBER_AUTO_FAN_PIN, analogInputToDigitalPin(TEMP_CHAMBER_PIN), +#if TEMP_SENSOR_CHAMBER && PIN_EXISTS(TEMP_CHAMBER) + #define _CHAMBER_TEMP analogInputToDigitalPin(TEMP_CHAMBER_PIN), +#else + #define _CHAMBER_TEMP +#endif +#if TEMP_SENSOR_CHAMBER && PINS_EXIST(TEMP_CHAMBER, HEATER_CHAMBER) + #define _CHAMBER_HEATER HEATER_CHAMBER_PIN, #else - #define __CHAMBER_PINS + #define _CHAMBER_HEATER #endif -#if PIN_EXISTS(HEATER_CHAMBER) - #define _CHAMBER_PINS __CHAMBER_PINS HEATER_CHAMBER_PIN, +#if TEMP_SENSOR_CHAMBER && PINS_EXIST(TEMP_CHAMBER, CHAMBER_AUTO_FAN) + #define _CHAMBER_FAN CHAMBER_AUTO_FAN_PIN, #else - #define _CHAMBER_PINS + #define _CHAMBER_FAN #endif #ifndef HAL_SENSITIVE_PINS @@ -685,6 +684,6 @@ _X_PINS _Y_PINS _Z_PINS _X2_PINS _Y2_PINS _Z2_PINS _Z3_PINS _Z4_PINS _Z_PROBE \ _E0_PINS _E1_PINS _E2_PINS _E3_PINS _E4_PINS _E5_PINS _E6_PINS _E7_PINS \ _H0_PINS _H1_PINS _H2_PINS _H3_PINS _H4_PINS _H5_PINS _H6_PINS _H7_PINS \ - _PS_ON _HEATER_BED _FAN0 _FAN1 _FAN2 _FAN3 _FAN4 _FAN5 _FAN6 _FAN7 _FANC \ - _BED_PINS _CHAMBER_PINS HAL_SENSITIVE_PINS \ + _PS_ON _FAN0 _FAN1 _FAN2 _FAN3 _FAN4 _FAN5 _FAN6 _FAN7 _FANC \ + _BED_PINS _CHAMBER_TEMP _CHAMBER_HEATER _CHAMBER_FAN HAL_SENSITIVE_PINS \ } diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 12c40b31b374..32203f52ea8d 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -200,6 +200,7 @@ #elif SD_CONNECTION_IS(ONBOARD) #define SDIO_SUPPORT #define SD_DETECT_PIN PD12 + #define ONBOARD_SD_CS_PIN PC11 #elif SD_CONNECTION_IS(CUSTOM_CABLE) #error "No custom SD drive cable defined for this board." #endif From f1e7880e7fc4b741278b76bbbb932f53d57d71d6 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:23:23 -0700 Subject: [PATCH 40/46] Fix I2C_ADDRESS sign warning (#19685) --- Marlin/src/HAL/HAL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index 8b6a978d2103..5eca2f7eacfe 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -34,7 +34,7 @@ #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION) #ifndef I2C_ADDRESS - #define I2C_ADDRESS(A) (A) + #define I2C_ADDRESS(A) uint8_t(A) #endif // Needed for AVR sprintf_P PROGMEM extension From d90c988765addf62fb5d52a93328f85a663d0c6b Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 17:42:50 -0700 Subject: [PATCH 41/46] Fix motion compile w/out probe-oriented settings (#19684) --- Marlin/src/module/motion.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index b904309018d6..da1cb173e56c 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -510,7 +510,7 @@ void do_z_clearance(const float &zclear, const bool z_known/*=true*/, const bool const bool rel = raise_on_unknown && !z_known; float zdest = zclear + (rel ? current_position.z : 0.0f); if (!lower_allowed) NOLESS(zdest, current_position.z); - do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(Z_PROBE_SPEED_FAST)); + do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(TERN(HAS_BED_PROBE, Z_PROBE_SPEED_FAST, HOMING_FEEDRATE_Z))); } // @@ -1126,8 +1126,9 @@ bool homing_needed_error(uint8_t axis_bits/*=0x07*/) { * Homing bump feedrate (mm/s) */ feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { - if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) - return MMM_TO_MMS(Z_PROBE_SPEED_SLOW); + #if HOMING_Z_WITH_PROBE + if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_SPEED_SLOW); + #endif static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR; uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]); if (hbd < 1) { @@ -1588,7 +1589,7 @@ void homeaxis(const AxisEnum axis) { // When homing Z with probe respect probe clearance const bool use_probe_bump = TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && home_bump_mm(Z_AXIS)); const float bump = axis_home_dir * ( - use_probe_bump ? _MAX(Z_CLEARANCE_BETWEEN_PROBES, home_bump_mm(Z_AXIS)) : home_bump_mm(axis) + use_probe_bump ? _MAX(TERN0(HOMING_Z_WITH_PROBE, Z_CLEARANCE_BETWEEN_PROBES), home_bump_mm(Z_AXIS)) : home_bump_mm(axis) ); // If a second homing move is configured... From 7e476b1cbc0d1e93bea7ff50a721adb14216040c Mon Sep 17 00:00:00 2001 From: qwewer0 <57561110+qwewer0@users.noreply.github.com> Date: Mon, 12 Oct 2020 04:30:18 +0200 Subject: [PATCH 42/46] Add REPORT_TRAMMING_MM option (#19682) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 8 +++----- Marlin/src/gcode/bedlevel/G35.cpp | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 48e6a8db3962..bcacddd20d42 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -806,11 +806,9 @@ #define TRAMMING_POINT_NAME_3 "Back-Right" #define TRAMMING_POINT_NAME_4 "Back-Left" - // Enable to restore leveling setup after operation - #define RESTORE_LEVELING_AFTER_G35 - - // Add a menu item for Assisted Tramming - //#define ASSISTED_TRAMMING_MENU_ITEM + #define RESTORE_LEVELING_AFTER_G35 // Enable to restore leveling setup after operation + //#define REPORT_TRAMMING_MM // Report Z deviation (mm) for each point relative to the first + //#define ASSISTED_TRAMMING_MENU_ITEM // Add a menu item for Assisted Tramming /** * Screw thread: diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index bd7f4f0411e1..0ede4e79c680 100755 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -160,6 +160,7 @@ void GcodeSuite::G35() { " ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", " by ", abs(full_turns), " turns"); if (minutes) SERIAL_ECHOPAIR(" and ", abs(minutes), " minutes"); + if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPAIR(" (", -diff, "mm)"); SERIAL_EOL(); } } From d67f34364362d64dc74cac3bd9fc0264ddea2e7b Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Sun, 11 Oct 2020 22:40:39 -0700 Subject: [PATCH 43/46] Allow MAX31865 resistance values configuration (#19695) --- Marlin/Configuration.h | 6 ++++++ Marlin/src/inc/SanityCheck.h | 4 ++++ Marlin/src/module/temperature.cpp | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d32dbbbfb32f..db266b524b35 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -431,6 +431,12 @@ #define DUMMY_THERMISTOR_998_VALUE 25 #define DUMMY_THERMISTOR_999_VALUE 100 +// Resistor values when using a MAX31865 (sensor -5) +// Sensor value is typically 100 (PT100) or 1000 (PT1000) +// Calibration value is typically 430 ohm for AdaFruit PT100 modules and 4300 ohm for AdaFruit PT1000 modules. +//#define MAX31865_SENSOR_OHMS 100 +//#define MAX31865_CALIBRATION_OHMS 430 + // Use temp sensor 1 as a redundant sensor with sensor 0. If the readings // from the two sensors differ too much the print will be aborted. //#define TEMP_SENSOR_1_AS_REDUNDANT diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index b7007e3be555..2cffde0907f7 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1845,6 +1845,10 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #error "TEMP_SENSOR_1 is required with TEMP_SENSOR_1_AS_REDUNDANT." #endif +#if ENABLED(MAX6675_IS_MAX31865) && (!defined(MAX31865_SENSOR_OHMS) || !defined(MAX31865_CALIBRATION_OHMS)) + #error "MAX31865_SENSOR_OHMS and MAX31865_CALIBRATION_OHMS must be set in Configuration.h when using a MAX31865 temperature sensor." +#endif + /** * Test Heater, Temp Sensor, and Extruder Pins */ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index f8ff972f8034..9ecbb7c766fd 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1461,7 +1461,7 @@ void Temperature::manage_heater() { #elif ENABLED(HEATER_0_USES_MAX6675) return ( #if ENABLED(MAX6675_IS_MAX31865) - max31865.temperature(100, 400) // 100 ohms = PT100 resistance. 400 ohms = calibration resistor + max31865.temperature(MAX31865_SENSOR_OHMS, MAX31865_CALIBRATION_OHMS) #else raw * 0.25 #endif @@ -2236,7 +2236,7 @@ void Temperature::disable_all_heaters() { next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL; #if ENABLED(MAX6675_IS_MAX31865) - max6675_temp = int(max31865.temperature(100, 400)); // 100 ohms = PT100 resistance. 400 ohms = calibration resistor + max6675_temp = int(max31865.temperature(MAX31865_SENSOR_OHMS, MAX31865_CALIBRATION_OHMS)); #endif // From 8289bf76923b6eeaaa4b5486a196bfe129f1a0c8 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 12 Oct 2020 14:39:31 -0700 Subject: [PATCH 44/46] Add D100 Watchdog Test (#19697) --- Marlin/src/gcode/gcode_d.cpp | 82 ++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/Marlin/src/gcode/gcode_d.cpp b/Marlin/src/gcode/gcode_d.cpp index 4bc3b6c6c377..1f38a85b9135 100644 --- a/Marlin/src/gcode/gcode_d.cpp +++ b/Marlin/src/gcode/gcode_d.cpp @@ -25,8 +25,10 @@ #include "gcode.h" #include "../module/settings.h" + #include "../module/temperature.h" #include "../libs/hex_print.h" #include "../HAL/shared/eeprom_if.h" + #include "../HAL/shared/Delay.h" /** * Dn: G-code for development and testing @@ -84,40 +86,23 @@ } } break; - case 3: { // D3 Read / Write EEPROM - uint8_t *pointer = parser.hex_adr_val('A'); - uint16_t len = parser.ushortval('C', 1); - uintptr_t addr = (uintptr_t)pointer; - #ifndef MARLIN_EEPROM_SIZE - #define MARLIN_EEPROM_SIZE size_t(E2END + 1) - #endif - NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1)); - NOMORE(len, MARLIN_EEPROM_SIZE - addr); - if (parser.seenval('X')) { - uint16_t val = parser.hex_val('X'); - #if ENABLED(EEPROM_SETTINGS) - persistentStore.access_start(); - while(len--) { - int pos = 0; - persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); - } - SERIAL_EOL(); - persistentStore.access_finish(); - #else - SERIAL_ECHOLN("NO EEPROM"); + #if ENABLED(EEPROM_SETTINGS) + case 3: { // D3 Read / Write EEPROM + uint8_t *pointer = parser.hex_adr_val('A'); + uint16_t len = parser.ushortval('C', 1); + uintptr_t addr = (uintptr_t)pointer; + #ifndef MARLIN_EEPROM_SIZE + #define MARLIN_EEPROM_SIZE size_t(E2END + 1) #endif - } - else { - while (len--) { - // Read bytes from EEPROM + NOMORE(addr, (size_t)(MARLIN_EEPROM_SIZE - 1)); + NOMORE(len, MARLIN_EEPROM_SIZE - addr); + if (parser.seenval('X')) { + uint16_t val = parser.hex_val('X'); #if ENABLED(EEPROM_SETTINGS) persistentStore.access_start(); - uint8_t val; while(len--) { int pos = 0; - if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { - print_hex_byte(val); - } + persistentStore.write_data(pos, (uint8_t *)&val, sizeof(val)); } SERIAL_EOL(); persistentStore.access_finish(); @@ -125,9 +110,28 @@ SERIAL_ECHOLN("NO EEPROM"); #endif } - SERIAL_EOL(); - } - } break; + else { + while (len--) { + // Read bytes from EEPROM + #if ENABLED(EEPROM_SETTINGS) + persistentStore.access_start(); + uint8_t val; + while(len--) { + int pos = 0; + if (!persistentStore.read_data(pos, (uint8_t *)&val, sizeof(val))) { + print_hex_byte(val); + } + } + SERIAL_EOL(); + persistentStore.access_finish(); + #else + SERIAL_ECHOLN("NO EEPROM"); + #endif + } + SERIAL_EOL(); + } + } break; + #endif case 4: { // D4 Read / Write PIN // const uint8_t pin = parser.byteval('P'); @@ -167,6 +171,20 @@ SERIAL_EOL(); } } break; + + case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test) + SERIAL_ECHOLN("Disabling heaters and attempting to trigger Watchdog"); + SERIAL_ECHOLN("(USE_WATCHDOG " TERN(USE_WATCHDOG, "ENABLED", "DISABLED") ")"); + thermalManager.disable_all_heaters(); + delay(1000); // Allow time to print + DISABLE_ISRS(); + // Use a low-level delay that does not rely on interrupts to function + // Do not spin forever, to avoid thermal risks if heaters are enabled and + // watchdog does not work. + DELAY_US(10000000); + ENABLE_ISRS(); + SERIAL_ECHOLN("FAILURE: Watchdog did not trigger board reset."); + } } } From aa1db63de4e574cfc3371c6340e58a2fb39e2456 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 12 Oct 2020 14:48:04 -0700 Subject: [PATCH 45/46] Add loose soft endstop state, apply to UBL fine-tune (#19681) Co-authored-by: Scott Lahteine --- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 4 ++ Marlin/src/gcode/bedlevel/abl/G29.cpp | 16 +++--- Marlin/src/gcode/bedlevel/mbl/G29.cpp | 16 ++---- Marlin/src/gcode/calibrate/G28.cpp | 5 +- Marlin/src/gcode/calibrate/G34.cpp | 4 +- Marlin/src/gcode/calibrate/G425.cpp | 9 ++-- Marlin/src/gcode/control/M211.cpp | 4 +- Marlin/src/gcode/feature/clean/G12.cpp | 4 +- Marlin/src/lcd/extui/ui_api.cpp | 28 ++-------- Marlin/src/lcd/menu/menu_motion.cpp | 27 ++-------- Marlin/src/lcd/menu/menu_probe_offset.cpp | 8 +-- Marlin/src/lcd/tft/ui_480x320.cpp | 24 ++------- Marlin/src/libs/nozzle.cpp | 2 +- Marlin/src/module/motion.cpp | 21 ++++---- Marlin/src/module/motion.h | 59 ++++++++++++++++----- Marlin/src/module/tool_change.cpp | 8 +-- 16 files changed, 106 insertions(+), 133 deletions(-) diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index dc91b7d6b185..e41af9f3cd23 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -1009,6 +1009,8 @@ lcd_mesh_edit_setup(new_z); + SET_SOFT_ENDSTOP_LOOSE(true); + do { idle(); new_z = lcd_mesh_edit(); @@ -1016,6 +1018,8 @@ SERIAL_FLUSH(); // Prevent host M105 buffer overrun. } while (!ui.button_pressed()); + SET_SOFT_ENDSTOP_LOOSE(false); + if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index e9b6e0e3a6db..f7de6c8cee57 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -201,10 +201,6 @@ G29_TYPE GcodeSuite::G29() { ABL_VAR int abl_probe_index; #endif - #if BOTH(HAS_SOFTWARE_ENDSTOPS, PROBE_MANUALLY) - ABL_VAR bool saved_soft_endstops_state = true; - #endif - #if ABL_GRID #if ENABLED(PROBE_MANUALLY) @@ -461,7 +457,7 @@ G29_TYPE GcodeSuite::G29() { // Abort current G29 procedure, go back to idle state if (seenA && g29_in_progress) { SERIAL_ECHOLNPGM("Manual G29 aborted"); - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); set_bed_leveling_enabled(abl_should_enable); g29_in_progress = false; TERN_(LCD_BED_LEVELING, ui.wait_for_move = false); @@ -482,7 +478,7 @@ G29_TYPE GcodeSuite::G29() { if (abl_probe_index == 0) { // For the initial G29 S2 save software endstop state - TERN_(HAS_SOFTWARE_ENDSTOPS, saved_soft_endstops_state = soft_endstops_enabled); + SET_SOFT_ENDSTOP_LOOSE(true); // Move close to the bed before the first point do_blocking_move_to_z(0); } @@ -552,14 +548,14 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(probePos); // Can be used here too! // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false); + SET_SOFT_ENDSTOP_LOOSE(true); G29_RETURN(false); } else { // Leveling done! Fall through to G29 finishing code below SERIAL_ECHOLNPGM("Grid probing done."); // Re-enable software endstops, if needed - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); } #elif ENABLED(AUTO_BED_LEVELING_3POINT) @@ -570,7 +566,7 @@ G29_TYPE GcodeSuite::G29() { _manual_goto_xy(probePos); // Disable software endstops to allow manual adjustment // If G29 is not completed, they will not be re-enabled - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = false); + SET_SOFT_ENDSTOP_LOOSE(true); G29_RETURN(false); } else { @@ -578,7 +574,7 @@ G29_TYPE GcodeSuite::G29() { SERIAL_ECHOLNPGM("3-point probing done."); // Re-enable software endstops, if needed - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); if (!dryrun) { vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal(); diff --git a/Marlin/src/gcode/bedlevel/mbl/G29.cpp b/Marlin/src/gcode/bedlevel/mbl/G29.cpp index 5da99386adc5..d94c16052bcf 100644 --- a/Marlin/src/gcode/bedlevel/mbl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/mbl/G29.cpp @@ -61,7 +61,6 @@ inline void echo_not_entered(const char c) { SERIAL_CHAR(c); SERIAL_ECHOLNPGM(" void GcodeSuite::G29() { static int mbl_probe_index = -1; - TERN_(HAS_SOFTWARE_ENDSTOPS, static bool saved_soft_endstops_state); MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport); if (!WITHIN(state, 0, 5)) { @@ -98,26 +97,19 @@ void GcodeSuite::G29() { } // For each G29 S2... if (mbl_probe_index == 0) { - #if HAS_SOFTWARE_ENDSTOPS - // For the initial G29 S2 save software endstop state - saved_soft_endstops_state = soft_endstops_enabled; - #endif // Move close to the bed before the first point do_blocking_move_to_z(0); } else { // Save Z for the previous mesh position mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z); - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = saved_soft_endstops_state); + SET_SOFT_ENDSTOP_LOOSE(false); } // If there's another point to sample, move there with optional lift. if (mbl_probe_index < GRID_MAX_POINTS) { - #if HAS_SOFTWARE_ENDSTOPS - // Disable software endstops to allow manual adjustment - // If G29 is not completed, they will not be re-enabled - soft_endstops_enabled = false; - #endif - + // Disable software endstops to allow manual adjustment + // If G29 is left hanging without completion they won't be re-enabled! + SET_SOFT_ENDSTOP_LOOSE(true); mbl.zigzag(mbl_probe_index++, ix, iy); _manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] }); } diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 7bc40b2127c4..34209568035d 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -222,8 +222,9 @@ void GcodeSuite::G28() { return; } - // Wait for planner moves to finish! - planner.synchronize(); + planner.synchronize(); // Wait for planner moves to finish! + + SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state // Disable the leveling matrix before homing #if HAS_LEVELING diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp index eb1d32f90927..fd876d3fe9ea 100644 --- a/Marlin/src/gcode/calibrate/G34.cpp +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -40,7 +40,7 @@ void GcodeSuite::G34() { if (homing_needed()) return; - TEMPORARY_SOFT_ENDSTOP_STATE(false); + SET_SOFT_ENDSTOP_LOOSE(true); TEMPORARY_BED_LEVELING_STATE(false); TemporaryGlobalEndstopsState unlock_z(false); @@ -148,6 +148,8 @@ void GcodeSuite::G34() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Running Post Commands"); gcode.process_subcommands_now_P(PSTR(GANTRY_CALIBRATION_COMMANDS_POST)); #endif + + SET_SOFT_ENDSTOP_LOOSE(false); } #endif // MECHANICAL_GANTRY_CALIBRATION diff --git a/Marlin/src/gcode/calibrate/G425.cpp b/Marlin/src/gcode/calibrate/G425.cpp index 746cb108766b..8968f789995f 100644 --- a/Marlin/src/gcode/calibrate/G425.cpp +++ b/Marlin/src/gcode/calibrate/G425.cpp @@ -581,13 +581,12 @@ void GcodeSuite::G425() { GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_PRE)); #endif - TEMPORARY_SOFT_ENDSTOP_STATE(false); - TEMPORARY_BED_LEVELING_STATE(false); - if (homing_needed_error()) return; - measurements_t m; + TEMPORARY_BED_LEVELING_STATE(false); + SET_SOFT_ENDSTOP_LOOSE(true); + measurements_t m; float uncertainty = parser.seenval('U') ? parser.value_float() : CALIBRATION_MEASUREMENT_UNCERTAIN; if (parser.seen('B')) @@ -612,6 +611,8 @@ void GcodeSuite::G425() { else calibrate_all(); + SET_SOFT_ENDSTOP_LOOSE(false); + #ifdef CALIBRATION_SCRIPT_POST GcodeSuite::process_subcommands_now_P(PSTR(CALIBRATION_SCRIPT_POST)); #endif diff --git a/Marlin/src/gcode/control/M211.cpp b/Marlin/src/gcode/control/M211.cpp index ffad722f3f7a..2049f1eb6955 100644 --- a/Marlin/src/gcode/control/M211.cpp +++ b/Marlin/src/gcode/control/M211.cpp @@ -37,8 +37,8 @@ void GcodeSuite::M211() { l_soft_max = soft_endstop.max.asLogical(); SERIAL_ECHO_START(); SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS); - if (parser.seen('S')) soft_endstops_enabled = parser.value_bool(); - serialprint_onoff(soft_endstops_enabled); + if (parser.seen('S')) soft_endstop._enabled = parser.value_bool(); + serialprint_onoff(soft_endstop._enabled); print_xyz(l_soft_min, PSTR(STR_SOFT_MIN), PSTR(" ")); print_xyz(l_soft_max, PSTR(STR_SOFT_MAX)); } diff --git a/Marlin/src/gcode/feature/clean/G12.cpp b/Marlin/src/gcode/feature/clean/G12.cpp index f91db39703f0..216db5bae374 100644 --- a/Marlin/src/gcode/feature/clean/G12.cpp +++ b/Marlin/src/gcode/feature/clean/G12.cpp @@ -70,9 +70,11 @@ void GcodeSuite::G12() { TEMPORARY_BED_LEVELING_STATE(!TEST(cleans, Z_AXIS) && planner.leveling_active); #endif - TEMPORARY_SOFT_ENDSTOP_STATE(parser.boolval('E')); + SET_SOFT_ENDSTOP_LOOSE(!parser.boolval('E')); nozzle.clean(pattern, strokes, radius, objects, cleans); + + SET_SOFT_ENDSTOP_LOOSE(false); } #endif // NOZZLE_CLEAN_FEATURE diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 0acfc9c025c1..30cf696f3ed7 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -305,27 +305,9 @@ namespace ExtUI { } void setAxisPosition_mm(const float position, const axis_t axis, const feedRate_t feedrate/*=0*/) { - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits((AxisEnum)axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 @@ -389,8 +371,8 @@ namespace ExtUI { } #if HAS_SOFTWARE_ENDSTOPS - bool getSoftEndstopState() { return soft_endstops_enabled; } - void setSoftEndstopState(const bool value) { soft_endstops_enabled = value; } + bool getSoftEndstopState() { return soft_endstop._enabled; } + void setSoftEndstopState(const bool value) { soft_endstop._enabled = value; } #endif #if HAS_TRINAMIC_CONFIG diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 676ba46ea730..2972920f34a7 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -57,28 +57,9 @@ static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) { if (ui.use_click()) return ui.goto_previous_screen_no_defer(); if (ui.encoderPosition && !ui.manual_move.processing) { - - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 @@ -238,7 +219,7 @@ void menu_move() { BACK_ITEM(MSG_MOTION); #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM) - EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled); + EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled); #endif if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) { diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index 87957e6207ef..6b7830b853d8 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -48,16 +48,12 @@ float z_offset_backup, calculated_z_offset; TERN_(HAS_LEVELING, bool leveling_was_active); -TERN_(HAS_SOFTWARE_ENDSTOPS, bool store_soft_endstops_enabled); void prepare_for_calibration() { z_offset_backup = probe.offset.z; // Disable soft endstops for free Z movement - #if HAS_SOFTWARE_ENDSTOPS - store_soft_endstops_enabled = soft_endstops_enabled; - soft_endstops_enabled = false; - #endif + SET_SOFT_ENDSTOP_LOOSE(true); // Disable leveling for raw planner motion #if HAS_LEVELING @@ -68,7 +64,7 @@ void prepare_for_calibration() { void set_offset_and_go_back(const float &z) { probe.offset.z = z; - TERN_(HAS_SOFTWARE_ENDSTOPS, soft_endstops_enabled = store_soft_endstops_enabled); + SET_SOFT_ENDSTOP_LOOSE(false); TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active)); ui.goto_previous_screen_no_defer(); } diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 549cbc4d9ba5..3dab9418f5fa 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -813,27 +813,9 @@ static void moveAxis(AxisEnum axis, const int8_t direction) { } if (!ui.manual_move.processing) { - // Start with no limits to movement - float min = current_position[axis] - 1000, - max = current_position[axis] + 1000; - - // Limit to software endstops, if enabled - #if HAS_SOFTWARE_ENDSTOPS - if (soft_endstops_enabled) switch (axis) { - case X_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_X, min = soft_endstop.min.x); - TERN_(MAX_SOFTWARE_ENDSTOP_X, max = soft_endstop.max.x); - break; - case Y_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Y, min = soft_endstop.min.y); - TERN_(MAX_SOFTWARE_ENDSTOP_Y, max = soft_endstop.max.y); - break; - case Z_AXIS: - TERN_(MIN_SOFTWARE_ENDSTOP_Z, min = soft_endstop.min.z); - TERN_(MAX_SOFTWARE_ENDSTOP_Z, max = soft_endstop.max.z); - default: break; - } - #endif // HAS_SOFTWARE_ENDSTOPS + // Get motion limit from software endstops, if any + float min, max; + soft_endstop.get_manual_axis_limits(axis, min, max); // Delta limits XY based on the current offset from center // This assumes the center is 0,0 diff --git a/Marlin/src/libs/nozzle.cpp b/Marlin/src/libs/nozzle.cpp index f93e5524813a..10021005e5b3 100644 --- a/Marlin/src/libs/nozzle.cpp +++ b/Marlin/src/libs/nozzle.cpp @@ -161,7 +161,7 @@ Nozzle nozzle; LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \ }while(0) - if (soft_endstops_enabled) { + if (soft_endstop.enabled()) { LIMIT_AXIS(x); LIMIT_AXIS(y); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index da1cb173e56c..92712b0c221c 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -534,12 +534,11 @@ void restore_feedrate_and_scaling() { #if HAS_SOFTWARE_ENDSTOPS - bool soft_endstops_enabled = true; - // Software Endstops are based on the configured limits. - axis_limits_t soft_endstop = { + soft_endstops_t soft_endstop = { { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }, - { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } + { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }, + { true, false } }; /** @@ -624,9 +623,9 @@ void restore_feedrate_and_scaling() { #endif - if (DEBUGGING(LEVELING)) - SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); -} + if (DEBUGGING(LEVELING)) + SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); + } /** * Constrain the given coordinates to the software endstops. @@ -636,7 +635,7 @@ void restore_feedrate_and_scaling() { */ void apply_motion_limits(xyz_pos_t &target) { - if (!soft_endstops_enabled) return; + if (!soft_endstop._enabled) return; #if IS_KINEMATIC @@ -688,7 +687,11 @@ void restore_feedrate_and_scaling() { } } -#endif // HAS_SOFTWARE_ENDSTOPS +#else // !HAS_SOFTWARE_ENDSTOPS + + soft_endstops_t soft_endstop; + +#endif // !HAS_SOFTWARE_ENDSTOPS #if !UBL_SEGMENTED diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 2b108b053177..338eb387cf9d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -148,26 +148,61 @@ inline float home_bump_mm(const AxisEnum axis) { constexpr xyz_pos_t hotend_offset[1] = { { 0 } }; #endif -typedef struct { xyz_pos_t min, max; } axis_limits_t; #if HAS_SOFTWARE_ENDSTOPS - extern bool soft_endstops_enabled; - extern axis_limits_t soft_endstop; + + typedef struct { + xyz_pos_t min, max; + struct { + bool _enabled:1; + bool _loose:1; + }; + bool enabled() { return _enabled && !_loose; } + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + amin = -100000; amax = 100000; // "No limits" + #if HAS_SOFTWARE_ENDSTOPS + if (enabled()) switch (axis) { + case X_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_X, amin = min.x); + TERN_(MAX_SOFTWARE_ENDSTOP_X, amax = max.x); + break; + case Y_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_Y, amin = min.y); + TERN_(MAX_SOFTWARE_ENDSTOP_Y, amax = max.y); + break; + case Z_AXIS: + TERN_(MIN_SOFTWARE_ENDSTOP_Z, amin = min.z); + TERN_(MAX_SOFTWARE_ENDSTOP_Z, amax = max.z); + default: break; + } + #endif + } + } soft_endstops_t; + + extern soft_endstops_t soft_endstop; void apply_motion_limits(xyz_pos_t &target); void update_software_endstops(const AxisEnum axis #if HAS_HOTEND_OFFSET , const uint8_t old_tool_index=0, const uint8_t new_tool_index=0 #endif ); - #define TEMPORARY_SOFT_ENDSTOP_STATE(enable) REMEMBER(tes, soft_endstops_enabled, enable); -#else - constexpr bool soft_endstops_enabled = false; - //constexpr axis_limits_t soft_endstop = { - // { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }, - // { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } }; - #define apply_motion_limits(V) NOOP + #define SET_SOFT_ENDSTOP_LOOSE(loose) (soft_endstop._loose = loose) + +#else // !HAS_SOFTWARE_ENDSTOPS + + typedef struct { + bool enabled() { return false; } + void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { + // No limits + amin = current_position[axis] - 1000; + amax = current_position[axis] + 1000; + } + } soft_endstops_t; + extern soft_endstops_t soft_endstop; + #define apply_motion_limits(V) NOOP #define update_software_endstops(...) NOOP - #define TEMPORARY_SOFT_ENDSTOP_STATE(...) NOOP -#endif + #define SET_SOFT_ENDSTOP_LOOSE() NOOP + +#endif // !HAS_SOFTWARE_ENDSTOPS void report_real_position(); void report_current_position(); diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 0f823cfbd000..4ab818f41d2e 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -1017,14 +1017,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Raise by a configured distance to avoid workpiece, except with // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead. if (!no_move) { - #if HAS_SOFTWARE_ENDSTOPS - const float maxz = _MIN(soft_endstop.max.z, Z_MAX_POS); - #else - constexpr float maxz = Z_MAX_POS; - #endif + const float newz = current_position.z + _MAX(-diff.z, 0.0); // Check if Z has space to compensate at least z_offset, and if not, just abort now - const float newz = current_position.z + _MAX(-diff.z, 0.0); + const float maxz = _MIN(TERN(HAS_SOFTWARE_ENDSTOPS, soft_endstop.max.z, Z_MAX_POS), Z_MAX_POS); if (newz > maxz) return; current_position.z = _MIN(newz + toolchange_settings.z_raise, maxz); From e99ddb2fc430a3e0b19851f11fde9d3400b14b42 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 13 Oct 2020 14:54:56 -0500 Subject: [PATCH 46/46] Simple bool in soft_endstops_t --- Marlin/src/module/motion.cpp | 4 ++-- Marlin/src/module/motion.h | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 92712b0c221c..5b3fab10b1e9 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -536,9 +536,9 @@ void restore_feedrate_and_scaling() { // Software Endstops are based on the configured limits. soft_endstops_t soft_endstop = { + true, false, { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }, - { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }, - { true, false } + { X_MAX_POS, Y_MAX_POS, Z_MAX_POS } }; /** diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 338eb387cf9d..550168e8a86d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -151,12 +151,10 @@ inline float home_bump_mm(const AxisEnum axis) { #if HAS_SOFTWARE_ENDSTOPS typedef struct { - xyz_pos_t min, max; - struct { - bool _enabled:1; - bool _loose:1; - }; + bool _enabled, _loose; bool enabled() { return _enabled && !_loose; } + + xyz_pos_t min, max; void get_manual_axis_limits(const AxisEnum axis, float &amin, float &amax) { amin = -100000; amax = 100000; // "No limits" #if HAS_SOFTWARE_ENDSTOPS