From c2d5b63a9882dc02f41017a5b2f24363a55fef8d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 8 Aug 2020 18:21:44 -0500 Subject: [PATCH 01/25] Fix up STATIC_ITEM (#18962) --- Marlin/src/feature/powerloss.cpp | 2 +- Marlin/src/feature/powerloss.h | 2 +- Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp | 12 +++++++----- Marlin/src/lcd/dogm/ultralcd_DOGM.cpp | 17 +++++++++-------- Marlin/src/lcd/language/language_en.h | 2 +- Marlin/src/lcd/lcdprint.h | 1 + Marlin/src/lcd/menu/menu.h | 20 +++++++++++--------- Marlin/src/lcd/menu/menu_addon.h | 2 +- Marlin/src/lcd/menu/menu_configuration.cpp | 4 ++-- Marlin/src/lcd/menu/menu_filament.cpp | 4 ++-- Marlin/src/lcd/menu/menu_info.cpp | 4 ++-- Marlin/src/lcd/menu/menu_led.cpp | 2 +- Marlin/src/lcd/menu/menu_mmu2.cpp | 4 ++-- Marlin/src/lcd/menu/menu_motion.cpp | 8 ++++---- Marlin/src/lcd/tft/ui_320x240.cpp | 6 +++--- Marlin/src/lcd/tft/ui_480x320.cpp | 6 +++--- 16 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 29a2cef97c4a..9a3eee31b55c 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -21,7 +21,7 @@ */ /** - * power_loss_recovery.cpp - Resume an SD print after power-loss + * feature/powerloss.cpp - Resume an SD print after power-loss */ #include "../inc/MarlinConfigPre.h" diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 30ea343424dd..10653493ab8f 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -22,7 +22,7 @@ #pragma once /** - * power_loss_recovery.h - Resume an SD print after power-loss + * feature/powerloss.h - Resume an SD print after power-loss */ #include "../sd/cardreader.h" diff --git a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp index a924528c3053..22dd63f68cb0 100644 --- a/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp @@ -997,15 +997,17 @@ void MarlinUI::draw_status_screen() { #endif // ADVANCED_PAUSE_FEATURE // Draw a static item with no left-right margin required. Centered by default. - void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) { + void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { int8_t n = LCD_WIDTH; lcd_moveto(0, row); - if ((style & SS_CENTER) && !valstr) { - int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; + const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0, + vlen = vstr ? utf8_strlen(vstr) : 0; + if (style & SS_CENTER) { + int8_t pad = (LCD_WIDTH - plen - vlen) / 2; while (--pad >= 0) { lcd_put_wchar(' '); n--; } } - n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n); - if (valstr) n -= lcd_put_u8str_max(valstr, n); + if (plen) n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n); + if (vlen) n -= lcd_put_u8str_max(vstr, n); for (; n > 0; --n) lcd_put_wchar(' '); } diff --git a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp index c6c67bf97e6e..d17c336eec24 100644 --- a/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp +++ b/Marlin/src/lcd/dogm/ultralcd_DOGM.cpp @@ -347,20 +347,21 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop } // Draw a static line of text in the same idiom as a menu item - void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) { + void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { if (mark_as_selected(row, style & SS_INVERT)) { pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed - if ((style & SS_CENTER) && !valstr) - for (int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2; pad > 0; --pad) { - lcd_put_wchar(' '); - n -= MENU_FONT_WIDTH; - } + const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0, + vlen = vstr ? utf8_strlen(vstr) : 0; + if (style & SS_CENTER) { + int8_t pad = (LCD_WIDTH - plen - vlen) / 2; + while (--pad >= 0) n -= lcd_put_wchar(' '); + } - n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH); - if (valstr) n -= lcd_put_u8str_max(valstr, n); + if (plen) n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH); + if (vlen) n -= lcd_put_u8str_max(vstr, n); while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' '); } } diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 391cb598cffc..ca7ddd2b0310 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -504,7 +504,7 @@ namespace Language_en { #if LCD_WIDTH >= 20 PROGMEM Language_Str MSG_INFO_PRINT_COUNT = _UxGT("Print Count"); PROGMEM Language_Str MSG_INFO_COMPLETED_PRINTS = _UxGT("Completed"); - PROGMEM Language_Str MSG_INFO_PRINT_TIME = _UxGT("Total Print time"); + PROGMEM Language_Str MSG_INFO_PRINT_TIME = _UxGT("Total Print Time"); PROGMEM Language_Str MSG_INFO_PRINT_LONGEST = _UxGT("Longest Job Time"); PROGMEM Language_Str MSG_INFO_PRINT_FILAMENT = _UxGT("Extruded Total"); #else diff --git a/Marlin/src/lcd/lcdprint.h b/Marlin/src/lcd/lcdprint.h index 8e611bde8325..00139808aebc 100644 --- a/Marlin/src/lcd/lcdprint.h +++ b/Marlin/src/lcd/lcdprint.h @@ -99,6 +99,7 @@ #endif +#define SETCURSOR_X(col) SETCURSOR(col, _lcdLineNr) #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u) int lcd_glyph_height(); diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index d298376ce26d..7c3df79a19e4 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -83,7 +83,7 @@ class MenuItemBase { class MenuItem_static : public MenuItemBase { public: - static void draw(const uint8_t row, PGM_P const pstr, const uint8_t style=SS_DEFAULT, const char * const valstr=nullptr); + static void draw(const uint8_t row, PGM_P const pstr, const uint8_t style=SS_DEFAULT, const char * const vstr=nullptr); }; // CONFIRM_ITEM(LABEL,Y,N,FY,FN,V...), @@ -418,16 +418,17 @@ class MenuItem_bool : public MenuEditItemBase { }while(0) #define _MENU_ITEM_P(TYPE, V...) do { \ - _skipStatic = false; \ - if (_menuLineNr == _thisItemNr) \ + if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ _MENU_INNER_P(TYPE, ##V); \ + } \ NEXT_ITEM(); \ }while(0) // Indexed items set a global index value and optional data #define _MENU_ITEM_N_S_P(TYPE, N, S, V...) do{ \ - _skipStatic = false; \ if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ MenuItemBase::init(N, S); \ _MENU_INNER_P(TYPE, ##V); \ } \ @@ -436,8 +437,8 @@ class MenuItem_bool : public MenuEditItemBase { // Indexed items set a global index value #define _MENU_ITEM_N_P(TYPE, N, V...) do{ \ - _skipStatic = false; \ if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ MenuItemBase::itemIndex = N; \ _MENU_INNER_P(TYPE, ##V); \ } \ @@ -446,8 +447,8 @@ class MenuItem_bool : public MenuEditItemBase { // Items with a unique string #define _MENU_ITEM_S_P(TYPE, S, V...) do{ \ - _skipStatic = false; \ if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ MenuItemBase::itemString = S; \ _MENU_INNER_P(TYPE, ##V); \ } \ @@ -550,16 +551,17 @@ class MenuItem_bool : public MenuEditItemBase { // Indexed items set a global index value and optional data #define _CONFIRM_ITEM_P(PLABEL, V...) do { \ - _skipStatic = false; \ - if (_menuLineNr == _thisItemNr) \ + if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ _CONFIRM_ITEM_INNER_P(PLABEL, ##V); \ + } \ NEXT_ITEM(); \ }while(0) // Indexed items set a global index value #define _CONFIRM_ITEM_N_S_P(N, S, V...) do{ \ - _skipStatic = false; \ if (_menuLineNr == _thisItemNr) { \ + _skipStatic = false; \ MenuItemBase::init(N, S); \ _CONFIRM_ITEM_INNER_P(TYPE, ##V); \ } \ diff --git a/Marlin/src/lcd/menu/menu_addon.h b/Marlin/src/lcd/menu/menu_addon.h index c276c8865be2..b6eb8e163493 100644 --- a/Marlin/src/lcd/menu/menu_addon.h +++ b/Marlin/src/lcd/menu/menu_addon.h @@ -25,6 +25,6 @@ #define MENU_ITEM_ADDON_START(X) do{ \ if (ui.should_draw() && _menuLineNr == _thisItemNr - 1) { \ - SETCURSOR(X, _lcdLineNr) + SETCURSOR_X(X) #define MENU_ITEM_ADDON_END() } }while(0) diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index ef3ad1ffed1d..26120fc5da6c 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -66,7 +66,7 @@ void menu_advanced_settings(); bar_percent += (int8_t)ui.encoderPosition; LIMIT(bar_percent, 0, 100); ui.encoderPosition = 0; - MenuItem_static::draw(0, GET_TEXT(MSG_PROGRESS_BAR_TEST), SS_CENTER|SS_INVERT); + MenuItem_static::draw(0, GET_TEXT(MSG_PROGRESS_BAR_TEST), SS_DEFAULT|SS_INVERT); lcd_put_int((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2, bar_percent); lcd_put_wchar('%'); lcd_moveto(0, LCD_HEIGHT - 1); ui.draw_progress_bar(bar_percent); } @@ -307,7 +307,7 @@ void menu_advanced_settings(); #define MAXTEMP_ALL _MAX(REPEAT(HOTENDS, _MAXTEMP_ITEM) 0) const uint8_t m = MenuItemBase::itemIndex; START_MENU(); - STATIC_ITEM_P(ui.get_preheat_label(m), SS_CENTER|SS_INVERT); + STATIC_ITEM_P(ui.get_preheat_label(m), SS_DEFAULT|SS_INVERT); BACK_ITEM(MSG_CONFIGURATION); #if HAS_FAN editable.uint8 = uint8_t(ui.material_preset[m].fan_speed); diff --git a/Marlin/src/lcd/menu/menu_filament.cpp b/Marlin/src/lcd/menu/menu_filament.cpp index b430e0448bda..1b11438f4c38 100644 --- a/Marlin/src/lcd/menu/menu_filament.cpp +++ b/Marlin/src/lcd/menu/menu_filament.cpp @@ -87,7 +87,7 @@ void _menu_temp_filament_op(const PauseMode mode, const int8_t extruder) { _change_filament_mode = mode; _change_filament_extruder = extruder; START_MENU(); - if (LCD_HEIGHT >= 4) STATIC_ITEM_P(change_filament_header(mode), SS_CENTER|SS_INVERT); + if (LCD_HEIGHT >= 4) STATIC_ITEM_P(change_filament_header(mode), SS_DEFAULT|SS_INVERT); BACK_ITEM(MSG_BACK); #if PREHEAT_COUNT LOOP_L_N(m, PREHEAT_COUNT) @@ -266,7 +266,7 @@ void _lcd_pause_message(PGM_P const msg) { skip1 = !has2 && (LCD_HEIGHT) >= 5; START_SCREEN(); - STATIC_ITEM_P(pause_header(), SS_CENTER|SS_INVERT); // 1: Header + STATIC_ITEM_P(pause_header(), SS_DEFAULT|SS_INVERT); // 1: Header if (skip1) SKIP_ITEM(); // Move a single-line message down STATIC_ITEM_P(msg1); // 2: Message Line 1 if (has2) STATIC_ITEM_P(msg2); // 3: Message Line 2 diff --git a/Marlin/src/lcd/menu/menu_info.cpp b/Marlin/src/lcd/menu/menu_info.cpp index 697d4b767e7b..b94be2e53f2f 100644 --- a/Marlin/src/lcd/menu/menu_info.cpp +++ b/Marlin/src/lcd/menu/menu_info.cpp @@ -205,7 +205,7 @@ void menu_info_board() { if (ui.use_click()) return ui.go_back(); START_SCREEN(); - STATIC_ITEM_P(PSTR(BOARD_INFO_NAME), SS_CENTER|SS_INVERT); // MyPrinterController + STATIC_ITEM_P(PSTR(BOARD_INFO_NAME), SS_DEFAULT|SS_INVERT); // MyPrinterController #ifdef BOARD_WEBSITE_URL STATIC_ITEM_P(PSTR(BOARD_WEBSITE_URL), SS_LEFT); // www.my3dprinter.com #endif @@ -237,7 +237,7 @@ void menu_info_board() { void menu_info_printer() { if (ui.use_click()) return ui.go_back(); START_SCREEN(); - STATIC_ITEM(MSG_MARLIN, SS_CENTER|SS_INVERT); // Marlin + STATIC_ITEM(MSG_MARLIN, SS_DEFAULT|SS_INVERT); // Marlin STATIC_ITEM_P(PSTR(SHORT_BUILD_VERSION)); // x.x.x-Branch STATIC_ITEM_P(PSTR(STRING_DISTRIBUTION_DATE)); // YYYY-MM-DD HH:MM STATIC_ITEM_P(PSTR(MACHINE_NAME)); // My3DPrinter diff --git a/Marlin/src/lcd/menu/menu_led.cpp b/Marlin/src/lcd/menu/menu_led.cpp index ac56ca0e524c..b117e0baa1dd 100644 --- a/Marlin/src/lcd/menu/menu_led.cpp +++ b/Marlin/src/lcd/menu/menu_led.cpp @@ -37,7 +37,7 @@ void menu_led_presets() { START_MENU(); #if LCD_HEIGHT > 2 - STATIC_ITEM(MSG_LED_PRESETS, SS_CENTER|SS_INVERT); + STATIC_ITEM(MSG_LED_PRESETS, SS_DEFAULT|SS_INVERT); #endif BACK_ITEM(MSG_LED_CONTROL); ACTION_ITEM(MSG_SET_LEDS_WHITE, leds.set_white); diff --git a/Marlin/src/lcd/menu/menu_mmu2.cpp b/Marlin/src/lcd/menu/menu_mmu2.cpp index e9627b8411b4..304e95887784 100644 --- a/Marlin/src/lcd/menu/menu_mmu2.cpp +++ b/Marlin/src/lcd/menu/menu_mmu2.cpp @@ -131,7 +131,7 @@ inline void action_mmu2_choose(const uint8_t tool) { void menu_mmu2_choose_filament() { START_MENU(); #if LCD_HEIGHT > 2 - STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_CENTER|SS_INVERT); + STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT); #endif LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_choose(MenuItemBase::itemIndex); }); END_MENU(); @@ -145,7 +145,7 @@ void menu_mmu2_pause() { currentTool = mmu2.get_current_tool(); START_MENU(); #if LCD_HEIGHT > 2 - STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, SS_CENTER|SS_INVERT); + STATIC_ITEM(MSG_FILAMENT_CHANGE_HEADER, SS_DEFAULT|SS_INVERT); #endif ACTION_ITEM(MSG_MMU2_RESUME, []{ mmuMenuWait = false; }); ACTION_ITEM(MSG_MMU2_UNLOAD_FILAMENT, []{ mmu2.unload(); }); diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 60118a3017d7..622cd091c061 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -178,12 +178,12 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int START_MENU(); if (LCD_HEIGHT >= 4) { switch (axis) { - case X_AXIS: STATIC_ITEM(MSG_MOVE_X, SS_CENTER|SS_INVERT); break; - case Y_AXIS: STATIC_ITEM(MSG_MOVE_Y, SS_CENTER|SS_INVERT); break; - case Z_AXIS: STATIC_ITEM(MSG_MOVE_Z, SS_CENTER|SS_INVERT); break; + case X_AXIS: STATIC_ITEM(MSG_MOVE_X, SS_DEFAULT|SS_INVERT); break; + case Y_AXIS: STATIC_ITEM(MSG_MOVE_Y, SS_DEFAULT|SS_INVERT); break; + case Z_AXIS: STATIC_ITEM(MSG_MOVE_Z, SS_DEFAULT|SS_INVERT); break; default: TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e); - STATIC_ITEM(MSG_MOVE_E, SS_CENTER|SS_INVERT); + STATIC_ITEM(MSG_MOVE_E, SS_DEFAULT|SS_INVERT); break; } } diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index 0b800abc3912..a4ac1465ea25 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -341,11 +341,11 @@ void MarlinUI::draw_status_screen() { } // Draw a static item with no left-right margin required. Centered by default. -void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) { +void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { menu_item(row); tft_string.set(pstr, itemIndex, itemString); - if (valstr) - tft_string.add(valstr); + if (vstr) + tft_string.add(vstr); tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); } diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 3eeed903cb17..c9f0bfd0e9b1 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -345,11 +345,11 @@ void MarlinUI::draw_status_screen() { } // Draw a static item with no left-right margin required. Centered by default. -void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) { +void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { menu_item(row); tft_string.set(pstr, itemIndex, itemString); - if (valstr) - tft_string.add(valstr); + if (vstr) + tft_string.add(vstr); tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); } From e3c0891d2b6f956ab6dbb8b27e37f8215a1d4903 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 8 Aug 2020 20:40:12 -0300 Subject: [PATCH 02/25] Fix compiler search in non-default PIO installs (#18960) --- buildroot/share/PlatformIO/scripts/common-dependencies.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index e09c639ad781..6c1b571bf16b 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -156,16 +156,16 @@ def search_compiler(): # Find the current platform compiler by searching the $PATH if env['PLATFORM'] == 'win32': path_separator = ';' - path_regex = r'platformio\\packages.*\\bin' + path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*\\bin' gcc = "g++.exe" else: path_separator = ':' - path_regex = r'platformio/packages.*/bin' + path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*/bin' gcc = "g++" # Search for the compiler for path in env['ENV']['PATH'].split(path_separator): - if not re.search(path_regex, path): + if not re.search(path_regex, path, re.IGNORECASE): continue for file in os.listdir(path): if not file.endswith(gcc): From 2ef6c8ba970a217259f1b108eee42086c7d8faf4 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 8 Aug 2020 20:45:34 -0300 Subject: [PATCH 03/25] Marlin Color UI for STM32F1 (SPI) (#18958) --- Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h | 6 +- Marlin/src/HAL/STM32F1/tft/tft_spi.cpp | 144 ++++++++++++++++++ Marlin/src/HAL/STM32F1/tft/tft_spi.h | 65 ++++++++ Marlin/src/HAL/STM32F1/tft/xpt2046.cpp | 10 +- Marlin/src/lcd/tft/ili9488.h | 4 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 9 +- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 31 ++++ 7 files changed, 253 insertions(+), 16 deletions(-) create mode 100644 Marlin/src/HAL/STM32F1/tft/tft_spi.cpp create mode 100644 Marlin/src/HAL/STM32F1/tft/tft_spi.h diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h index 0a1d6c820208..09d79030b53e 100644 --- a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h @@ -26,12 +26,8 @@ #undef SD_CHECK_AND_RETRY #endif -#if HAS_SPI_TFT - #error "Sorry! SPI TFT displays are not available for HAL/STM32F1 (yet)." -#endif - // This platform has 'touch/xpt2046', not 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT +#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT && !HAS_SPI_TFT #undef TOUCH_SCREEN #undef TOUCH_SCREEN_CALIBRATION #define HAS_TOUCH_XPT2046 1 diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp new file mode 100644 index 000000000000..a64f90f2b50b --- /dev/null +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp @@ -0,0 +1,144 @@ +/** + * 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 HAS_SPI_TFT + +#include "tft_spi.h" + +// TFT_SPI tft; + +SPIClass TFT_SPI::SPIx(1); + +#define SPI_TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH) +#define SPI_TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW) + +#define SPI_TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH) +#define SPI_TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW) + +#define SPI_TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH) +#define SPI_TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW) + +#define SPI_TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH) +#define SPI_TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW) + +void TFT_SPI::Init() { + #if PIN_EXISTS(TFT_RESET) + // OUT_WRITE(TFT_RESET_PIN, HIGH); + SPI_TFT_RST_H; + delay(100); + #endif + + #if PIN_EXISTS(TFT_BACKLIGHT) + // OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH); + SPI_TFT_BLK_H; + #endif + + SPI_TFT_DC_H; + SPI_TFT_CS_H; + + /** + * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz + * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1 + * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2 + */ + #if SPI_DEVICE == 1 + #define SPI_CLOCK_MAX SPI_CLOCK_DIV4 + #else + #define SPI_CLOCK_MAX SPI_CLOCK_DIV2 + #endif + uint8_t clock; + uint8_t spiRate = SPI_FULL_SPEED; + switch (spiRate) { + case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break; + case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break; + case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break; + case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; + case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break; + case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; + default: clock = SPI_CLOCK_DIV2; // Default from the SPI library + } + SPIx.setModule(1); + SPIx.setClockDivider(clock); + SPIx.setBitOrder(MSBFIRST); + SPIx.setDataMode(SPI_MODE0); +} + +void TFT_SPI::DataTransferBegin(uint16_t DataSize) { + SPIx.setDataSize(DataSize); + SPIx.begin(); + SPI_TFT_CS_L; +} + +uint32_t TFT_SPI::GetID() { + uint32_t id; + id = ReadID(LCD_READ_ID); + + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + id = ReadID(LCD_READ_ID4); + return id; +} + +uint32_t TFT_SPI::ReadID(uint16_t Reg) { + #if !PIN_EXISTS(TFT_MISO) + return 0; + #else + uint16_t d = 0; + DataTransferBegin(DATASIZE_8BIT); + WriteReg(Reg); + + SPI.read((uint8_t*)&d, 1); //dummy read + SPI.read((uint8_t*)&d, 1); + + DataTransferEnd(); + + return d >> 7; + #endif +} + +bool TFT_SPI::isBusy() { + return false; +} + +void TFT_SPI::Abort() { + DataTransferEnd(); +} + +void TFT_SPI::Transmit(uint16_t Data) { + SPIx.send(Data); +} + +void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { + DataTransferBegin(); + SPI_TFT_DC_H; + if (MemoryIncrease == DMA_MINC_ENABLE) { + SPIx.dmaSend(Data, Count, true); + } + else { + SPIx.dmaSend(Data, Count, false); + } + + DataTransferEnd(); +} + +#endif // HAS_SPI_TFT diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h new file mode 100644 index 000000000000..1d1c9b444c8e --- /dev/null +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h @@ -0,0 +1,65 @@ +/** + * 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" + +#include + +#ifndef LCD_READ_ID + #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341) +#endif +#ifndef LCD_READ_ID4 + #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341) +#endif + +#define DATASIZE_8BIT DATA_SIZE_8BIT +#define DATASIZE_16BIT DATA_SIZE_16BIT +#define TFT_IO TFT_SPI + +#define DMA_MINC_ENABLE 1 +#define DMA_MINC_DISABLE 0 + +class TFT_SPI { +private: + static uint32_t ReadID(uint16_t Reg); + static void Transmit(uint16_t Data); + static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count); + +public: + static SPIClass SPIx; + + static void Init(); + static uint32_t GetID(); + static bool isBusy(); + static void Abort(); + + static void DataTransferBegin(uint16_t DataWidth = DATA_SIZE_16BIT); + static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); SPIx.end(); }; + static void DataTransferAbort(); + + static void WriteData(uint16_t Data) { Transmit(Data); } + static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); } + + static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); } + static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } +}; diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp index dc34b0d5b506..e06cace7419a 100644 --- a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp +++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp @@ -65,9 +65,7 @@ void XPT2046::Init() { SET_INPUT(TOUCH_INT_PIN); #endif - #if ENABLED(TOUCH_BUTTONS_HW_SPI) - touch_spi_init(SPI_SPEED_6); - #endif + TERN_(TOUCH_BUTTONS_HW_SPI, touch_spi_init(SPI_SPEED_6)); // Read once to enable pendrive status pin getRawData(XPT2046_X); @@ -95,12 +93,14 @@ uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) { uint16_t data[3]; DataTransferBegin(); + TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.begin()); for (uint16_t i = 0; i < 3 ; i++) { IO(coordinate); data[i] = (IO() << 4) | (IO() >> 4); } + TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.end()); DataTransferEnd(); uint16_t delta01 = delta(data[0], data[1]), @@ -114,14 +114,12 @@ uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) { } uint16_t XPT2046::IO(uint16_t data) { - TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data); + return TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data); } #if ENABLED(TOUCH_BUTTONS_HW_SPI) uint16_t XPT2046::HardwareIO(uint16_t data) { - SPIx.begin(); uint16_t result = SPIx.transfer(data); - SPIx.end(); return result; } #endif diff --git a/Marlin/src/lcd/tft/ili9488.h b/Marlin/src/lcd/tft/ili9488.h index 135f94a57ffc..6aad70486553 100644 --- a/Marlin/src/lcd/tft/ili9488.h +++ b/Marlin/src/lcd/tft/ili9488.h @@ -39,7 +39,9 @@ #define ILI9488_ORIENTATION_DOWN ILI9488_MADCTL_MX // 320x480 ; Cable on the upper side #define ILI9488_COLOR_BGR -#define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT +#ifndef ILI9488_ORIENTATION + #define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT +#endif #define ILI9488_MADCTL_DATA (ILI9488_ORIENTATION | TERN(ILI9488_COLOR_BGR, ILI9488_MADCTL_BGR, ILI9488_MADCTL_RGB)) #define ILI9488_NOP 0x00 // No Operation diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index d314c30fcdf1..afa9354aa2ab 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -225,10 +225,10 @@ #define FSMC_DMA_DEV DMA2 #define FSMC_DMA_CHANNEL DMA_CH5 - #define XPT2046_X_CALIBRATION -17181 - #define XPT2046_Y_CALIBRATION 11434 - #define XPT2046_X_OFFSET 501 - #define XPT2046_Y_OFFSET -9 + #define XPT2046_X_CALIBRATION 17880 + #define XPT2046_Y_CALIBRATION -12234 + #define XPT2046_X_OFFSET -45 + #define XPT2046_Y_OFFSET 349 #define TOUCH_CS_PIN PA7 // SPI2_NSS #define TOUCH_SCK_PIN PB13 // SPI2_SCK @@ -237,6 +237,7 @@ #define TFT_DRIVER ILI9488 #define TFT_BUFFER_SIZE 14400 + #define ILI9488_ORIENTATION ILI9488_MADCTL_MX | ILI9488_MADCTL_MV #endif #define SPI_FLASH 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 9f4e57dd704e..4552f8cd9fe5 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -344,6 +344,37 @@ #define MKS_LCD12864B #undef SHOW_BOOTSCREEN + #elif ENABLED(TFT_480x320_SPI) + #define TFT_CS_PIN PD11 + #define TFT_SCK_PIN PA5 + #define TFT_MISO_PIN PA6 + #define TFT_MOSI_PIN PA7 + #define TFT_DC_PIN PD10 + #define TFT_RST_PIN PC6 + #define TFT_A0_PIN TFT_DC_PIN + + #define TFT_RESET_PIN PC6 + #define TFT_BACKLIGHT_PIN PD13 + + #define XPT2046_X_CALIBRATION -17253 + #define XPT2046_Y_CALIBRATION 11579 + #define XPT2046_X_OFFSET 514 + #define XPT2046_Y_OFFSET -24 + + #define TOUCH_CS_PIN PE14 // SPI1_NSS + #define TOUCH_SCK_PIN PA5 // SPI1_SCK + #define TOUCH_MISO_PIN PA6 // SPI1_MISO + #define TOUCH_MOSI_PIN PA7 // SPI1_MOSI + + #define TFT_DRIVER ST7796 + #define TFT_BUFFER_SIZE 14400 + + #define LCD_READ_ID 0xD3 + #define LCD_USE_DMA_SPI + + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + #else // !MKS_MINI_12864 #define LCD_PINS_D4 PE14 From 58cfdb8f57bd71dd7a5ecaa8dc04388fd6944a5a Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Sun, 9 Aug 2020 00:10:45 +0000 Subject: [PATCH 04/25] [cron] Bump distribution date (2020-08-09) --- 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 a2bc2337f47c..33cd24dd0219 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-08" + #define STRING_DISTRIBUTION_DATE "2020-08-09" #endif /** From 0a1b8659871f681464f24c40b16aa64cd2f7ca8e Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Sat, 8 Aug 2020 21:24:31 -0300 Subject: [PATCH 05/25] W25QXX SPI Flash support (#18897) Co-authored-by: Scott Lahteine --- Marlin/src/gcode/control/M993_M994.cpp | 92 +++++++++++++++++++ Marlin/src/gcode/gcode.cpp | 5 + Marlin/src/gcode/gcode.h | 7 ++ .../lcd/extui/lib/mks_ui/SPIFlashStorage.cpp | 2 + .../lcd/extui/lib/mks_ui/SPIFlashStorage.h | 2 +- Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 2 +- .../extui/lib/mks_ui/mks_hardware_test.cpp | 1 - .../src/lcd/extui/lib/mks_ui/pic_manager.cpp | 4 +- Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h | 4 + .../lib/mks_ui/tft_lvgl_configuration.cpp | 1 - .../{lcd/extui/lib/mks_ui => libs}/W25Qxx.cpp | 44 ++++----- .../{lcd/extui/lib/mks_ui => libs}/W25Qxx.h | 50 +--------- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 5 +- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 5 +- 14 files changed, 140 insertions(+), 84 deletions(-) create mode 100644 Marlin/src/gcode/control/M993_M994.cpp rename Marlin/src/{lcd/extui/lib/mks_ui => libs}/W25Qxx.cpp (90%) rename Marlin/src/{lcd/extui/lib/mks_ui => libs}/W25Qxx.h (67%) diff --git a/Marlin/src/gcode/control/M993_M994.cpp b/Marlin/src/gcode/control/M993_M994.cpp new file mode 100644 index 000000000000..4e13aa9d77df --- /dev/null +++ b/Marlin/src/gcode/control/M993_M994.cpp @@ -0,0 +1,92 @@ +/** + * 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 ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE) + +#include "../gcode.h" +#include "../../sd/cardreader.h" +#include "../../libs/W25Qxx.h" + +/** + * M993: Backup SPI Flash to SD + */ +void GcodeSuite::M993() { + if (!card.isMounted()) card.mount(); + + char fname[] = "spiflash.bin"; + card.openFileWrite(fname); + if (!card.isFileOpen()) { + SERIAL_ECHOLNPAIR("Failed to open ", fname, " to write."); + return; + } + + W25QXXFlash W25QXX; + + uint8_t buf[1024]; + uint32_t addr = 0; + W25QXX.init(SPI_QUARTER_SPEED); + SERIAL_ECHOPGM("Save SPI Flash"); + while (addr < SPI_FLASH_SIZE) { + W25QXX.SPI_FLASH_BufferRead(buf, addr, COUNT(buf)); + addr += COUNT(buf); + card.write(buf, COUNT(buf)); + if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.'); + } + SERIAL_ECHOLNPGM(" done"); + + card.closefile(); +} + +/** + * M994: Load a backup from SD to SPI Flash + */ +void GcodeSuite::M994() { + if (!card.isMounted()) card.mount(); + + char fname[] = "spiflash.bin"; + card.openFileRead(fname); + if (!card.isFileOpen()) { + SERIAL_ECHOLNPAIR("Failed to open ", fname, " to read."); + return; + } + + W25QXXFlash W25QXX; + + uint8_t buf[1024]; + uint32_t addr = 0; + W25QXX.init(SPI_QUARTER_SPEED); + W25QXX.SPI_FLASH_BulkErase(); + SERIAL_ECHOPGM("Load SPI Flash"); + while(addr < SPI_FLASH_SIZE) { + card.read(buf, COUNT(buf)); + W25QXX.SPI_FLASH_BufferWrite(buf, addr, COUNT(buf)); + addr += COUNT(buf); + if (addr % (COUNT(buf) * 10) == 0) SERIAL_CHAR('.'); + } + SERIAL_ECHOLNPGM(" done"); + + card.closefile(); +} + +#endif // HAS_SPI_FLASH && SDSUPPORT && MARLIN_DEV_MODE diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index f1692ee807c6..2309953f8815 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -871,6 +871,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe #endif + #if BOTH(HAS_SPI_FLASH, SDSUPPORT) + case 993: M993(); break; // M993: Backup SPI Flash to SD + case 994: M994(); break; // M994: Load a Backup from SD to SPI Flash + #endif + #if ENABLED(TOUCH_SCREEN_CALIBRATION) case 995: M995(); break; // M995: Touch screen calibration for TFT display #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 7e89e809d006..783781b9c305 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -276,6 +276,8 @@ * ************ Custom codes - This can change to suit future G-code regulations * G425 - Calibrate using a conductive object. (Requires CALIBRATION_GCODE) * M928 - Start SD logging: "M928 filename.gco". Stop with M29. (Requires SDSUPPORT) + * M993 - Backup SPI Flash to SD + * M994 - Load a Backup from SD to SPI Flash * M995 - Touch screen calibration for TFT display * M997 - Perform in-application firmware update * M999 - Restart after being stopped by error @@ -846,6 +848,11 @@ class GcodeSuite { TERN_(TOUCH_SCREEN_CALIBRATION, static void M995()); + #if BOTH(HAS_SPI_FLASH, SDSUPPORT) + static void M993(); + static void M994(); + #endif + TERN_(PLATFORM_M997_SUPPORT, static void M997()); static void M999(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp index 9d3adc1bab93..979c916e5cad 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.cpp @@ -27,6 +27,8 @@ #include "../../../../inc/MarlinConfig.h" #include "SPIFlashStorage.h" +extern W25QXXFlash W25QXX; + uint8_t SPIFlashStorage::m_pageData[SPI_FLASH_PageSize]; uint32_t SPIFlashStorage::m_currentPage; uint16_t SPIFlashStorage::m_pageDataUsed; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.h b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.h index 5a124137095a..98c8067bd3c2 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPIFlashStorage.h @@ -21,7 +21,7 @@ */ #pragma once -#include "W25Qxx.h" +#include "../../../../libs/W25Qxx.h" #define HAS_SPI_FLASH_COMPRESSION 1 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 e8899b9ad122..5d87eb9f8736 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -27,7 +27,6 @@ #include "SPI_TFT.h" #endif -#include "W25Qxx.h" #include "tft_lvgl_configuration.h" #include "pic_manager.h" @@ -50,6 +49,7 @@ #include "../../../../feature/pause.h" #endif +W25QXXFlash W25QXX; CFG_ITMES gCfgItems; UI_CFG uiCfg; DISP_STATE_STACK disp_state_stack; 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 00371d7ab5ab..a35ae29701fb 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 @@ -29,7 +29,6 @@ #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" -#include "W25Qxx.h" #include "mks_hardware_test.h" #include "draw_ui.h" #include "pic_manager.h" diff --git a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp index 072213e499ac..447303a88782 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.cpp @@ -29,10 +29,10 @@ #include "mks_hardware_test.h" #include "SPIFlashStorage.h" -#include "W25Qxx.h" +#include "../../../../libs/W25Qxx.h" -#include "../../../../MarlinCore.h" #include "../../../../sd/cardreader.h" +#include "../../../../MarlinCore.h" extern uint16_t DeviceCode; extern unsigned char bmp_public_buf[17 * 1024]; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h index 354e11a540d4..4d9d08a9b4e3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h @@ -23,6 +23,8 @@ #include "../../../../inc/MarlinConfig.h" +#include "../../../../libs/W25Qxx.h" + #include #include @@ -154,6 +156,8 @@ extern void spi_flash_read_test(); extern void default_view_Read(uint8_t *default_view_Rbuff, uint32_t default_view_Readsize); extern void flash_view_Read(uint8_t *flash_view_Rbuff, uint32_t flash_view_Readsize); +extern W25QXXFlash W25QXX; + #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 fc5b8c1bf24e..81b50a101871 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 @@ -35,7 +35,6 @@ #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" -#include "W25Qxx.h" #include "pic_manager.h" #include "mks_hardware_test.h" #include "draw_ui.h" diff --git a/Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.cpp b/Marlin/src/libs/W25Qxx.cpp similarity index 90% rename from Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.cpp rename to Marlin/src/libs/W25Qxx.cpp index 60b4d0b7ea98..d51dfb819de9 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.cpp +++ b/Marlin/src/libs/W25Qxx.cpp @@ -19,13 +19,12 @@ * along with this program. If not, see . * */ -#include "../../../../inc/MarlinConfigPre.h" -#if 1 // ENABLED(SPI_FLASH) -#if HAS_TFT_LVGL_UI +#include "../inc/MarlinConfig.h" + +#if HAS_SPI_FLASH #include -#include "../../../../inc/MarlinConfig.h" #include "W25Qxx.h" @@ -45,9 +44,7 @@ #define W25QXX_CS_H OUT_WRITE(SPI_FLASH_CS_PIN, HIGH) #define W25QXX_CS_L OUT_WRITE(SPI_FLASH_CS_PIN, LOW) -ext_FLASH W25QXX; - -void ext_FLASH::init(uint8_t spiRate) { +void W25QXXFlash::init(uint8_t spiRate) { OUT_WRITE(SPI_FLASH_CS_PIN, HIGH); @@ -85,12 +82,12 @@ void ext_FLASH::init(uint8_t spiRate) { * * @details */ -uint8_t ext_FLASH::spi_flash_Rec() { +uint8_t W25QXXFlash::spi_flash_Rec() { uint8_t returnByte = SPI.transfer(ff); return returnByte; } -uint8_t ext_FLASH::spi_flash_read_write_byte(uint8_t data) { +uint8_t W25QXXFlash::spi_flash_read_write_byte(uint8_t data) { uint8_t returnByte = SPI.transfer(data); return returnByte; } @@ -104,7 +101,7 @@ uint8_t ext_FLASH::spi_flash_read_write_byte(uint8_t data) { * * @details Uses DMA */ -void ext_FLASH::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0, const_cast(buf), nbyte); } +void W25QXXFlash::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0, const_cast(buf), nbyte); } /** * @brief Send a single byte on SPI port @@ -113,7 +110,7 @@ void ext_FLASH::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0 * * @details */ -void ext_FLASH::spi_flash_Send(uint8_t b) { SPI.send(b); } +void W25QXXFlash::spi_flash_Send(uint8_t b) { SPI.send(b); } /** * @brief Write token and then write from 512 byte buffer to SPI (for SD card) @@ -123,12 +120,12 @@ void ext_FLASH::spi_flash_Send(uint8_t b) { SPI.send(b); } * * @details Use DMA */ -void ext_FLASH::spi_flash_SendBlock(uint8_t token, const uint8_t* buf) { +void W25QXXFlash::spi_flash_SendBlock(uint8_t token, const uint8_t* buf) { SPI.send(token); SPI.dmaSend(const_cast(buf), 512); } -uint16_t ext_FLASH::W25QXX_ReadID(void) { +uint16_t W25QXXFlash::W25QXX_ReadID(void) { uint16_t Temp = 0; W25QXX_CS_L; spi_flash_Send(0x90); @@ -141,7 +138,7 @@ uint16_t ext_FLASH::W25QXX_ReadID(void) { return Temp; } -void ext_FLASH::SPI_FLASH_WriteEnable(void) { +void W25QXXFlash::SPI_FLASH_WriteEnable(void) { /* Select the FLASH: Chip Select low */ W25QXX_CS_L; /* Send "Write Enable" instruction */ @@ -159,7 +156,7 @@ void ext_FLASH::SPI_FLASH_WriteEnable(void) { * Output : None * Return : None *******************************************************************************/ -void ext_FLASH::SPI_FLASH_WaitForWriteEnd(void) { +void W25QXXFlash::SPI_FLASH_WaitForWriteEnd(void) { uint8_t FLASH_Status = 0; /* Select the FLASH: Chip Select low */ @@ -178,7 +175,7 @@ void ext_FLASH::SPI_FLASH_WaitForWriteEnd(void) { W25QXX_CS_H; } -void ext_FLASH::SPI_FLASH_SectorErase(uint32_t SectorAddr) { +void W25QXXFlash::SPI_FLASH_SectorErase(uint32_t SectorAddr) { /* Send write enable instruction */ SPI_FLASH_WriteEnable(); @@ -200,7 +197,7 @@ void ext_FLASH::SPI_FLASH_SectorErase(uint32_t SectorAddr) { SPI_FLASH_WaitForWriteEnd(); } -void ext_FLASH::SPI_FLASH_BlockErase(uint32_t BlockAddr) { +void W25QXXFlash::SPI_FLASH_BlockErase(uint32_t BlockAddr) { SPI_FLASH_WriteEnable(); W25QXX_CS_L; /* Send Sector Erase instruction */ @@ -224,7 +221,7 @@ void ext_FLASH::SPI_FLASH_BlockErase(uint32_t BlockAddr) { * Output : None * Return : None *******************************************************************************/ -void ext_FLASH::SPI_FLASH_BulkErase(void) { +void W25QXXFlash::SPI_FLASH_BulkErase(void) { /* Send write enable instruction */ SPI_FLASH_WriteEnable(); @@ -253,7 +250,7 @@ void ext_FLASH::SPI_FLASH_BulkErase(void) { * Output : None * Return : None *******************************************************************************/ -void ext_FLASH::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { +void W25QXXFlash::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { /* Enable the write access to the FLASH */ SPI_FLASH_WriteEnable(); @@ -296,7 +293,7 @@ void ext_FLASH::SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16 * Output : None * Return : None *******************************************************************************/ -void ext_FLASH::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { +void W25QXXFlash::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { uint8_t NumOfPage = 0, NumOfSingle = 0, Addr = 0, count = 0, temp = 0; Addr = WriteAddr % SPI_FLASH_PageSize; @@ -361,7 +358,7 @@ void ext_FLASH::SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint * Output : None * Return : None *******************************************************************************/ -void ext_FLASH::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) { +void W25QXXFlash::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead) { /* Select the FLASH: Chip Select low */ W25QXX_CS_L; @@ -389,7 +386,4 @@ void ext_FLASH::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16 W25QXX_CS_H; } -void ext_FLASH::lv_pic_read(uint8_t *P_Rbuff, uint32_t addr, uint32_t size) {SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, addr, size);} - -#endif // HAS_TFT_LVGL_UI -#endif // 1 ... SPI_FLASH +#endif // HAS_SPI_FLASH diff --git a/Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.h b/Marlin/src/libs/W25Qxx.h similarity index 67% rename from Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.h rename to Marlin/src/libs/W25Qxx.h index 88d5d6c2f549..81e964345010 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.h +++ b/Marlin/src/libs/W25Qxx.h @@ -52,49 +52,7 @@ #define SPI_FLASH_PageSize 256 #define SPI_FLASH_PerWritePageSize 256 -#if 0 - - #define PIC_NAME_MAX_LEN 50 - - #define LOGO_MAX_SIZE (300*1024) - #define TITLELOGO_MAX_SIZE (150*1024) - #define DEFAULT_VIEW_MAX_SIZE (200*200*2) - #define FLASH_VIEW_MAX_SIZE (200*200*2) - - //Robin 2 - #define PIC_NAME_ADDR 0x003000 - #define PIC_SIZE_ADDR 0x007000 - #define PIC_COUNTER_ADDR 0x008000 - #define PIC_LOGO_ADDR 0x009000 - //#define PIC_DATA_ADDR 0x02f000 - - #define DEFAULT_VIEW_ADDR 0XC5800 - #define BAK_VIEW_ADDR (DEFAULT_VIEW_ADDR+90*1024) - #define PIC_ICON_LOGO_ADDR (BAK_VIEW_ADDR+80*1024) - - #define PIC_DATA_ADDR (PIC_ICON_LOGO_ADDR+350*1024) - - #define FONTINFOADDR 0x600000 - #define UNIGBK_FLASH_ADDR (FONTINFOADDR+4096) // 4*1024 - #define GBK_FLASH_ADDR (UNIGBK_FLASH_ADDR+180224) // 176*1024 - - #define PER_PIC_MAX_SPACE (32*1024) - - union union32 { - uint8_t bytes[4]; - uint32_t dwords; - }; - - struct pic_msg { - uint8_t name[PIC_NAME_MAX_LEN]; - union union32 size; - }; - - typedef struct pic_msg PIC_MSG; - -#endif // if 0 - -class ext_FLASH { +class W25QXXFlash { public: void init(uint8_t spiRate); static uint8_t spi_flash_Rec(); @@ -111,14 +69,8 @@ class ext_FLASH { static void SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite); static void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite); static void SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead); - //uint32_t lv_get_pic_addr(uint8_t *Pname); - void lv_pic_read(uint8_t *P_Rbuff, uint32_t addr, uint32_t size); }; -extern ext_FLASH W25QXX; - -//extern uint32_t lv_get_pic_addr(uint8_t *Pname); - //#ifdef __cplusplus //} /* C-declarations for C++ */ //#endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index afa9354aa2ab..16040643520b 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -240,8 +240,9 @@ #define ILI9488_ORIENTATION ILI9488_MADCTL_MX | ILI9488_MADCTL_MV #endif -#define SPI_FLASH -#if ENABLED(SPI_FLASH) +#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x1000000 // 16MB +#if HAS_SPI_FLASH #define W25QXX_CS_PIN PB12 #define W25QXX_MOSI_PIN PB15 #define W25QXX_MISO_PIN PB14 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 4552f8cd9fe5..be363e45374b 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -398,8 +398,9 @@ #endif // HAS_SPI_LCD -#define SPI_FLASH -#if ENABLED(SPI_FLASH) +#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x1000000 // 16MB +#if HAS_SPI_FLASH #define W25QXX_CS_PIN PB12 #define W25QXX_MOSI_PIN PB15 #define W25QXX_MISO_PIN PB14 From 852e5ae0421810ecc6f44631237208030e70751f Mon Sep 17 00:00:00 2001 From: sherwin-dc <59867245+sherwin-dc@users.noreply.github.com> Date: Sun, 9 Aug 2020 09:00:42 +0800 Subject: [PATCH 06/25] Password via G-code and MarlinUI (#18399) Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 31 +++ Marlin/src/MarlinCore.cpp | 14 +- Marlin/src/core/language.h | 7 + Marlin/src/core/macros.h | 51 +++-- Marlin/src/feature/password/password.cpp | 58 ++++++ Marlin/src/feature/password/password.h | 57 ++++++ .../src/gcode/feature/password/M510-M512.cpp | 83 ++++++++ Marlin/src/gcode/gcode.cpp | 25 +++ Marlin/src/gcode/gcode.h | 13 ++ Marlin/src/inc/SanityCheck.h | 11 ++ Marlin/src/lcd/language/language_en.h | 11 ++ Marlin/src/lcd/menu/menu_advanced.cpp | 8 + Marlin/src/lcd/menu/menu_main.cpp | 8 +- Marlin/src/lcd/menu/menu_password.cpp | 184 ++++++++++++++++++ Marlin/src/module/settings.cpp | 42 +++- .../PlatformIO/scripts/common-dependencies.h | 3 + buildroot/tests/DUE-tests | 2 +- buildroot/tests/rambo-tests | 1 + platformio.ini | 4 + 19 files changed, 588 insertions(+), 25 deletions(-) create mode 100644 Marlin/src/feature/password/password.cpp create mode 100644 Marlin/src/feature/password/password.h create mode 100644 Marlin/src/gcode/feature/password/M510-M512.cpp create mode 100644 Marlin/src/lcd/menu/menu_password.cpp diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 3ad7dfdab339..3b6155f969de 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1642,6 +1642,37 @@ */ //#define PRINTCOUNTER +/** + * Password + * + * Set a numerical password for the printer which can be requested: + * + * - When the printer boots up + * - Upon opening the 'Print from Media' Menu + * - When SD printing is completed or aborted + * + * The following G-codes can be used: + * + * M510 - Lock Printer. Blocks all commands except M511. + * M511 - Unlock Printer. + * M512 - Set, Change and Remove Password. + * + * If you forget the password and get locked out you'll need to re-flash + * the firmware with the feature disabled, reset EEPROM, and (optionally) + * re-flash the firmware again with this feature enabled. + */ +//#define PASSWORD_FEATURE +#if ENABLED(PASSWORD_FEATURE) + #define PASSWORD_LENGTH 4 // (#) Number of digits (1-9). 3 or 4 is recommended + #define PASSWORD_ON_STARTUP + #define PASSWORD_UNLOCK_GCODE // Unlock with the M511 P command. Disable to prevent brute-force attack. + #define PASSWORD_CHANGE_GCODE // Change the password with M512 P N. + //#define PASSWORD_ON_SD_PRINT_MENU // This does not prevent gcodes from running + //#define PASSWORD_AFTER_SD_PRINT_END + //#define PASSWORD_AFTER_SD_PRINT_ABORT + //#include "Configuration_Secure.h" // External file with PASSWORD_DEFAULT_VALUE +#endif + //============================================================================= //============================= LCD and SD support ============================ //============================================================================= diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index a8c4407be29a..39530395eb48 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -213,6 +213,10 @@ #include "libs/L64XX/L64XX_Marlin.h" #endif +#if ENABLED(PASSWORD_FEATURE) + #include "feature/password/password.h" +#endif + PGMSTR(NUL_STR, ""); PGMSTR(M112_KILL_STR, "M112 Shutdown"); PGMSTR(G28_STR, "G28"); @@ -452,11 +456,15 @@ void startOrResumeJob() { #ifdef EVENT_GCODE_SD_STOP queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); #endif + + TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } inline void finishSDPrinting() { - if (queue.enqueue_one_P(PSTR("M1001"))) + if (queue.enqueue_one_P(PSTR("M1001"))) { marlin_state = MF_RUNNING; + TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine()); + } } #endif // SDSUPPORT @@ -1205,6 +1213,10 @@ void setup() { SETUP_RUN(tft_lvgl_init()); #endif + #if ENABLED(PASSWORD_ON_STARTUP) + SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided + #endif + marlin_state = MF_RUNNING; SETUP_LOG("setup() completed."); diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index 5208b3e1bfb6..48431455f0ff 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -266,6 +266,13 @@ #define STR_DEBUG_COMMUNICATION "COMMUNICATION" #define STR_DEBUG_LEVELING "LEVELING" +#define STR_PRINTER_LOCKED "Printer locked! (Unlock with M511 or LCD)" +#define STR_WRONG_PASSWORD "Incorrect Password" +#define STR_PASSWORD_TOO_LONG "Password too long" +#define STR_PASSWORD_REMOVED "Password removed" +#define STR_REMINDER_SAVE_SETTINGS "Remember to save!" +#define STR_PASSWORD_SET "Password is " + // LCD Menu Messages #define LANGUAGE_DATA_INCL_(M) STRINGIFY_(fontdata/langdata_##M.h) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 3bd273872aa7..5fc1081019b5 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -342,15 +342,22 @@ #endif // Macros for adding -#define INC_0 1 -#define INC_1 2 -#define INC_2 3 -#define INC_3 4 -#define INC_4 5 -#define INC_5 6 -#define INC_6 7 -#define INC_7 8 -#define INC_8 9 +#define INC_0 1 +#define INC_1 2 +#define INC_2 3 +#define INC_3 4 +#define INC_4 5 +#define INC_5 6 +#define INC_6 7 +#define INC_7 8 +#define INC_8 9 +#define INC_9 10 +#define INC_10 11 +#define INC_11 12 +#define INC_12 13 +#define INC_13 14 +#define INC_14 15 +#define INC_15 16 #define INCREMENT_(n) INC_##n #define INCREMENT(n) INCREMENT_(n) @@ -367,16 +374,22 @@ #define ADD10(N) ADD5(ADD5(N)) // Macros for subtracting -#define DEC_0 0 -#define DEC_1 0 -#define DEC_2 1 -#define DEC_3 2 -#define DEC_4 3 -#define DEC_5 4 -#define DEC_6 5 -#define DEC_7 6 -#define DEC_8 7 -#define DEC_9 8 +#define DEC_0 0 +#define DEC_1 0 +#define DEC_2 1 +#define DEC_3 2 +#define DEC_4 3 +#define DEC_5 4 +#define DEC_6 5 +#define DEC_7 6 +#define DEC_8 7 +#define DEC_9 8 +#define DEC_10 9 +#define DEC_11 10 +#define DEC_12 11 +#define DEC_13 12 +#define DEC_14 13 +#define DEC_15 14 #define DECREMENT_(n) DEC_##n #define DECREMENT(n) DECREMENT_(n) diff --git a/Marlin/src/feature/password/password.cpp b/Marlin/src/feature/password/password.cpp new file mode 100644 index 000000000000..c519ee7c9c46 --- /dev/null +++ b/Marlin/src/feature/password/password.cpp @@ -0,0 +1,58 @@ +/** + * 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(PASSWORD_FEATURE) + +#include "password.h" +#include "../../gcode/gcode.h" +#include "../../core/serial.h" + +Password password; + +// public: +bool Password::is_set, Password::is_locked; +uint32_t Password::value, Password::value_entry; + +// +// Authenticate user with password. +// Called from Setup, after SD Prinitng Stops/Aborts, and M510 +// +void Password::lock_machine() { + is_locked = true; + TERN_(HAS_LCD_MENU, authenticate_user(ui.status_screen, screen_password_entry)); +} + +// +// Authentication check +// +void Password::authentication_check() { + if (value_entry == value) + is_locked = false; + else + SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD); + + TERN_(HAS_LCD_MENU, authentication_done()); +} + +#endif // PASSWORD_FEATURE diff --git a/Marlin/src/feature/password/password.h b/Marlin/src/feature/password/password.h new file mode 100644 index 000000000000..66f1c70ba314 --- /dev/null +++ b/Marlin/src/feature/password/password.h @@ -0,0 +1,57 @@ +/** + * 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 "../../lcd/ultralcd.h" + +class Password { +public: + static bool is_set, is_locked; + static uint32_t value, value_entry; + + Password() { is_locked = false; } + + static void lock_machine(); + + #if HAS_LCD_MENU + static void access_menu_password(); + static void authentication_check(); + static void authentication_done(); + static void media_gatekeeper(); + + private: + static void authenticate_user(const screenFunc_t, const screenFunc_t); + static void menu_password(); + static void menu_password_entry(); + static void screen_password_entry(); + static void screen_set_password(); + static void start_over(); + + static void digit_entered(); + static void set_password_done(); + static void menu_password_report(); + + static void remove_password(); + #endif +}; + +extern Password password; diff --git a/Marlin/src/gcode/feature/password/M510-M512.cpp b/Marlin/src/gcode/feature/password/M510-M512.cpp new file mode 100644 index 000000000000..bcdeb7b91ccd --- /dev/null +++ b/Marlin/src/gcode/feature/password/M510-M512.cpp @@ -0,0 +1,83 @@ +/** + * 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(PASSWORD_FEATURE) + +#include "../../../feature/password/password.h" +#include "../../../core/serial.h" +#include "../../gcode.h" + +// +// M510: Lock Printer +// +void GcodeSuite::M510() { + password.lock_machine(); +} + +// +// M511: Unlock Printer +// +#if ENABLED(PASSWORD_UNLOCK_GCODE) + + void GcodeSuite::M511() { + if (password.is_locked) { + password.value_entry = parser.ulongval('P'); + password.authentication_check(); + } + } + +#endif // PASSWORD_UNLOCK_GCODE + +// +// M512: Set/Change/Remove Password +// +#if ENABLED(PASSWORD_CHANGE_GCODE) + + void GcodeSuite::M512() { + if (password.is_set && parser.ulongval('P') != password.value) { + SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD); + return; + } + + if (parser.seenval('N')) { + password.value_entry = parser.ulongval('N'); + + if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) { + password.is_set = true; + password.value = password.value_entry; + SERIAL_ECHOLNPAIR(STR_PASSWORD_SET, password.value); // TODO: Update password.string + } + else + SERIAL_ECHOLNPGM(STR_PASSWORD_TOO_LONG); + } + else { + password.is_set = false; + SERIAL_ECHOLNPGM(STR_PASSWORD_REMOVED); + } + SERIAL_ECHOLNPGM(STR_REMINDER_SAVE_SETTINGS); + } + +#endif // PASSWORD_CHANGE_GCODE + +#endif // PASSWORD_FEATURE diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 2309953f8815..840df54f6a76 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -57,6 +57,10 @@ GcodeSuite gcode; #include "../feature/spindle_laser.h" #endif +#if ENABLED(PASSWORD_FEATURE) + #include "../feature/password/password.h" +#endif + #include "../MarlinCore.h" // for idle() // Inactivity shutdown @@ -241,6 +245,17 @@ void GcodeSuite::dwell(millis_t time) { void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { KEEPALIVE_STATE(IN_HANDLER); + /** + * Block all Gcodes except M511 Unlock Printer, if printer is locked + * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu + */ + #if ENABLED(PASSWORD_FEATURE) + if (password.is_locked && !(parser.command_letter == 'M' && parser.codenum == 511)) { + SERIAL_ECHO_MSG(STR_PRINTER_LOCKED); + return; + } + #endif + // Handle a known G, M, or T switch (parser.command_letter) { case 'G': switch (parser.codenum) { @@ -736,6 +751,16 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 504: M504(); break; // M504: Validate EEPROM contents #endif + #if ENABLED(PASSWORD_FEATURE) + case 510: M510(); break; // M510: Lock Printer + #if ENABLED(PASSWORD_UNLOCK_GCODE) + case 511: M511(); break; // M511: Unlock Printer + #endif + #if ENABLED(PASSWORD_CHANGE_GCODE) + case 512: M512(); break; + #endif // M512: Set/Change/Remove Password + #endif + #if ENABLED(SDSUPPORT) case 524: M524(); break; // M524: Abort the current SD print job #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 783781b9c305..e04cd637eb92 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -225,6 +225,9 @@ * M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! ** * M503 - Print the current settings (in memory): "M503 S". S0 specifies compact output. * M504 - Validate EEPROM contents. (Requires EEPROM_SETTINGS) + * M510 - Lock Printer + * M511 - Unlock Printer + * M512 - Set/Change/Remove Password * M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT) * M540 - Enable/disable SD card abort on endstop hit: "M540 S". (Requires SD_ABORT_ON_ENDSTOP_HIT) * M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160) @@ -760,6 +763,16 @@ class GcodeSuite { #endif TERN_(EEPROM_SETTINGS, static void M504()); + #if ENABLED(PASSWORD_FEATURE) + static void M510(); + #if ENABLED(PASSWORD_UNLOCK_GCODE) + static void M511(); + #endif + #if ENABLED(PASSWORD_CHANGE_GCODE) + static void M512(); + #endif + #endif + TERN_(SDSUPPORT, static void M524()); TERN_(SD_ABORT_ON_ENDSTOP_HIT, static void M540()); diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 7fbfda4fe109..f9b65c8bf483 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -3083,5 +3083,16 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #error "ESP3D_WIFISUPPORT or WIFISUPPORT requires an ESP32 controller." #endif +/** + * Sanity Check for Password Feature + */ +#if ENABLED(PASSWORD_FEATURE) + #if NONE(HAS_LCD_MENU, PASSWORD_UNLOCK_GCODE, PASSWORD_CHANGE_GCODE) + #error "Without PASSWORD_UNLOCK_GCODE, PASSWORD_CHANGE_GCODE, or a supported LCD there's no way to unlock the printer or set a password." + #elif DISABLED(EEPROM_SETTINGS) + #warning "PASSWORD_FEATURE settings will be lost on power-off without EEPROM_SETTINGS." + #endif +#endif + // Misc. Cleanup #undef _TEST_PWM diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index ca7ddd2b0310..9f6178ae50cc 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -588,6 +588,17 @@ namespace Language_en { PROGMEM Language_Str MSG_BAD_PAGE = _UxGT("Bad page index"); PROGMEM Language_Str MSG_BAD_PAGE_SPEED = _UxGT("Bad page speed"); + PROGMEM Language_Str MSG_EDIT_PASSWORD = _UxGT("Edit Password"); + PROGMEM Language_Str MSG_LOGIN_REQUIRED = _UxGT("Login Required"); + PROGMEM Language_Str MSG_PASSWORD_SETTINGS = _UxGT("Password Settings"); + PROGMEM Language_Str MSG_ENTER_DIGIT = _UxGT("Enter Digit"); + PROGMEM Language_Str MSG_CHANGE_PASSWORD = _UxGT("Set/Edit Password"); + PROGMEM Language_Str MSG_REMOVE_PASSWORD = _UxGT("Remove Password"); + PROGMEM Language_Str MSG_PASSWORD_SET = _UxGT("Password is "); + PROGMEM Language_Str MSG_START_OVER = _UxGT("Start Over"); + PROGMEM Language_Str MSG_REMINDER_SAVE_SETTINGS = _UxGT("Remember to Save!"); + PROGMEM Language_Str MSG_PASSWORD_REMOVED = _UxGT("Password Removed"); + // // Filament Change screens show up to 3 lines on a 4-line display // ...or up to 2 lines on a 3-line display diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index 34def4d3bd7f..e41786107228 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -51,6 +51,10 @@ #include "../../module/settings.h" #endif +#if ENABLED(PASSWORD_FEATURE) + #include "../../feature/password/password.h" +#endif + void menu_tmc(); void menu_backlash(); @@ -603,6 +607,10 @@ void menu_advanced_settings() { }); #endif + #if ENABLED(PASSWORD_FEATURE) + SUBMENU(MSG_PASSWORD_SETTINGS, password.access_menu_password); + #endif + #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS) CONFIRM_ITEM(MSG_INIT_EEPROM, MSG_BUTTON_INIT, MSG_BUTTON_CANCEL, diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index 059290c5237e..9a1d2ece68e8 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -50,6 +50,10 @@ #include "../../lcd/menu/menu_mmu2.h" #endif +#if ENABLED(PASSWORD_FEATURE) + #include "../../feature/password/password.h" +#endif + void menu_tune(); void menu_cancelobject(); void menu_motion(); @@ -133,7 +137,7 @@ void menu_main() { if (card_detected) { if (!card_open) { - SUBMENU(MSG_MEDIA_MENU, menu_media); + SUBMENU(MSG_MEDIA_MENU, TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media)); MENU_ITEM(gcode, #if PIN_EXISTS(SD_DETECT) MSG_CHANGE_MEDIA, M21_STR @@ -240,7 +244,7 @@ void menu_main() { MSG_RELEASE_MEDIA, PSTR("M22") #endif ); - SUBMENU(MSG_MEDIA_MENU, menu_media); + SUBMENU(MSG_MEDIA_MENU, TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media)); } } else { diff --git a/Marlin/src/lcd/menu/menu_password.cpp b/Marlin/src/lcd/menu/menu_password.cpp new file mode 100644 index 000000000000..f8e0b567218c --- /dev/null +++ b/Marlin/src/lcd/menu/menu_password.cpp @@ -0,0 +1,184 @@ +/** + * 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 . + * + */ + +// +// Advanced Settings Menus +// + +#include "../../inc/MarlinConfigPre.h" + +#if BOTH(HAS_LCD_MENU, PASSWORD_FEATURE) + +#include "../../feature/password/password.h" + +#include "menu.h" +#include "menu_addon.h" + +void menu_advanced_settings(); + +screenFunc_t success_screen, fail_screen; +bool authenticating; // = false +char string[(PASSWORD_LENGTH) + 1]; +static uint8_t digit_no; + +// +// Screen for both editing and setting the password +// +void Password::menu_password_entry() { + START_MENU(); + + // "Login" or "New Code" + STATIC_ITEM_P(authenticating ? GET_TEXT(MSG_LOGIN_REQUIRED) : GET_TEXT(MSG_EDIT_PASSWORD), SS_CENTER|SS_INVERT); + + STATIC_ITEM_P(PSTR(""), SS_CENTER|SS_INVERT, string); + + // Make the digit edit item look like a sub-menu + PGM_P const label = GET_TEXT(MSG_ENTER_DIGIT); + EDIT_ITEM_P(uint8, label, &editable.uint8, 0, 9, digit_entered); + MENU_ITEM_ADDON_START(utf8_strlen_P(label) + 1); + lcd_put_wchar(' '); + lcd_put_wchar('1' + digit_no); + SETCURSOR_X(LCD_WIDTH - 1); + lcd_put_wchar('>'); + MENU_ITEM_ADDON_END(); + + ACTION_ITEM(MSG_START_OVER, start_over); + + if (!authenticating) BACK_ITEM(MSG_BUTTON_CANCEL); + + END_MENU(); +} + +// +// Authentication check +// +void Password::authentication_done() { + ui.goto_screen(is_locked ? fail_screen : success_screen); + ui.completion_feedback(!is_locked); +} + +// A single digit was completed +void Password::digit_entered() { + uint32_t multiplier = CAT(1e, PASSWORD_LENGTH); // 1e5 = 100000 + LOOP_LE_N(i, digit_no) multiplier /= 10; + value_entry += editable.uint8 * multiplier; + string[digit_no++] = '0' + editable.uint8; + + // Exit edit screen menu and go to another screen + ui.goto_previous_screen(); + ui.use_click(); + ui.goto_screen(menu_password_entry); + + // After password has been keyed in + if (digit_no == PASSWORD_LENGTH) { + if (authenticating) + authentication_check(); + else + set_password_done(); + } +} + +// +// Set/Change Password +// +void Password::screen_password_entry() { + value_entry = 0; + digit_no = 0; + editable.uint8 = 0; + memset(string, '-', PASSWORD_LENGTH); + string[PASSWORD_LENGTH] = '\0'; + menu_password_entry(); +} + +void Password::screen_set_password() { + authenticating = false; + screen_password_entry(); +} + +void Password::authenticate_user(const screenFunc_t in_succ_scr, const screenFunc_t in_fail_scr) { + success_screen = in_succ_scr; + fail_screen = in_fail_scr; + if (is_set) { + authenticating = true; + ui.goto_screen(screen_password_entry); + ui.defer_status_screen(); + ui.update(); + } + else { + ui.goto_screen(in_succ_scr); + is_locked = false; + } +} + +void Password::access_menu_password() { + authenticate_user(menu_password, menu_advanced_settings); +} + +#if ENABLED(PASSWORD_ON_SD_PRINT_MENU) + void Password::media_gatekeeper() { + authenticate_user(menu_media, menu_main); + } +#endif + +void Password::start_over() { + ui.goto_previous_screen(); // Goto previous screen, if any + ui.goto_screen(screen_password_entry); +} + +void Password::menu_password_report() { + START_SCREEN(); + BACK_ITEM(MSG_PASSWORD_SETTINGS); + STATIC_ITEM(MSG_PASSWORD_SET, SS_LEFT, string); + STATIC_ITEM(MSG_REMINDER_SAVE_SETTINGS, SS_LEFT); + END_SCREEN(); +} + +void Password::set_password_done() { + is_set = true; + value = value_entry; + ui.completion_feedback(true); + ui.goto_screen(menu_password_report); +} + +void Password::remove_password() { + is_set = false; + string[0] = '0'; + string[1] = '\0'; + ui.completion_feedback(true); + ui.goto_screen(menu_password_report); +} + +// +// Password Menu +// +void Password::menu_password() { + START_MENU(); + BACK_ITEM(MSG_ADVANCED_SETTINGS); + SUBMENU(MSG_CHANGE_PASSWORD, screen_set_password); + ACTION_ITEM(MSG_REMOVE_PASSWORD, []{ ui.save_previous_screen(); remove_password(); } ); + #if ENABLED(EEPROM_SETTINGS) + ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings); + #endif + END_MENU(); +} + +#endif // HAS_LCD_MENU && PASSWORD_FEATURE diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 34af8f2ea398..f1ab0fca6927 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -140,6 +140,10 @@ #define HAS_CASE_LIGHT_BRIGHTNESS 1 #endif +#if ENABLED(PASSWORD_FEATURE) + #include "../feature/password/password.h" +#endif + #if ENABLED(TOUCH_SCREEN_CALIBRATION) #include "../lcd/tft/touch.h" #endif @@ -152,7 +156,7 @@ typedef struct { int16_t X, Y, Z, X2, Y2, Z2, Z3, Z4; typedef struct { bool X, Y, Z, X2, Y2, Z2, Z3, Z4, E0, E1, E2, E3, E4, E5, E6, E7; } tmc_stealth_enabled_t; // Limit an index to an array size -#define ALIM(I,ARR) _MIN(I, signed(COUNT(ARR) - 1)) +#define ALIM(I,ARR) _MIN(I, (signed)COUNT(ARR) - 1) // Defaults for reset / fill in on load static const uint32_t _DMA[] PROGMEM = DEFAULT_MAX_ACCELERATION; @@ -407,6 +411,14 @@ typedef struct SettingsDataStruct { uint8_t caselight_brightness; // M355 P #endif + // + // PASSWORD_FEATURE + // + #if ENABLED(PASSWORD_FEATURE) + bool password_is_set; + uint32_t password_value; + #endif + // // TOUCH_SCREEN_CALIBRATION // @@ -1345,6 +1357,14 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(caselight.brightness); #endif + // + // Password feature + // + #if ENABLED(PASSWORD_FEATURE) + EEPROM_WRITE(password.is_set); + EEPROM_WRITE(password.value); + #endif + // // TOUCH_SCREEN_CALIBRATION // @@ -2185,6 +2205,15 @@ void MarlinSettings::postprocess() { EEPROM_READ(caselight.brightness); #endif + // + // Password feature + // + #if ENABLED(PASSWORD_FEATURE) + _FIELD_TEST(password_is_set); + EEPROM_READ(password.is_set); + EEPROM_READ(password.value); + #endif + // // TOUCH_SCREEN_CALIBRATION // @@ -2665,7 +2694,7 @@ void MarlinSettings::reset() { #define PID_DEFAULT(N,E) DEFAULT_##N #endif HOTEND_LOOP() { - PID_PARAM(Kp, e) = float(PID_DEFAULT(Kp, ALIM(e, defKp))); + PID_PARAM(Kp, e) = float(PID_DEFAULT(Kp, ALIM(e, defKp))); PID_PARAM(Ki, e) = scalePID_i(PID_DEFAULT(Ki, ALIM(e, defKi))); PID_PARAM(Kd, e) = scalePID_d(PID_DEFAULT(Kd, ALIM(e, defKd))); TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = float(PID_DEFAULT(Kc, ALIM(e, defKc)))); @@ -2783,6 +2812,15 @@ void MarlinSettings::reset() { } #endif + #if ENABLED(PASSWORD_FEATURE) + #ifdef PASSWORD_DEFAULT_VALUE + password.is_set = true; + password.value = PASSWORD_DEFAULT_VALUE; + #else + password.is_set = false; + #endif + #endif + postprocess(); DEBUG_ECHO_START(); diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.h b/buildroot/share/PlatformIO/scripts/common-dependencies.h index d18cb8c28135..c41027003e9e 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.h +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.h @@ -143,6 +143,9 @@ #if ENABLED(MMU2_MENUS) #define HAS_MENU_MMU2 #endif + #if ENABLED(PASSWORD_FEATURE) + #define HAS_MENU_PASSWORD + #endif #if HAS_TRINAMIC_CONFIG #define HAS_MENU_TMC #endif diff --git a/buildroot/tests/DUE-tests b/buildroot/tests/DUE-tests index 5c36db03679a..7f488f6126cb 100755 --- a/buildroot/tests/DUE-tests +++ b/buildroot/tests/DUE-tests @@ -33,7 +33,7 @@ opt_set EXTRUDER_AUTO_FAN_SPEED 100 opt_set TEMP_SENSOR_CHAMBER 3 opt_add TEMP_CHAMBER_PIN 6 opt_set HEATER_CHAMBER_PIN 45 -exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), EXTENSIBLE_UI, S-Curve, many options." +exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options." restore_configs opt_set MOTHERBOARD BOARD_RADDS diff --git a/buildroot/tests/rambo-tests b/buildroot/tests/rambo-tests index 0b249e2149cf..ec8af16c23b4 100644 --- a/buildroot/tests/rambo-tests +++ b/buildroot/tests/rambo-tests @@ -33,6 +33,7 @@ opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TE PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 LEVEL_BED_CORNERS \ NOZZLE_PARK_FEATURE FILAMENT_RUNOUT_SENSOR FILAMENT_RUNOUT_DISTANCE_MM \ ADVANCED_PAUSE_FEATURE FILAMENT_LOAD_UNLOAD_GCODES FILAMENT_UNLOAD_ALL_EXTRUDERS \ + PASSWORD_FEATURE PASSWORD_ON_STARTUP PASSWORD_ON_SD_PRINT_MENU PASSWORD_AFTER_SD_PRINT_END PASSWORD_AFTER_SD_PRINT_ABORT \ AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DISTINCT_E_FACTORS \ SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \ BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \ diff --git a/platformio.ini b/platformio.ini index fdb120ae88bd..10990b4d2151 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,6 +41,7 @@ default_src_filter = + - - + - - - + - - - - @@ -86,6 +87,7 @@ default_src_filter = + - - + - - - - + - - - - - - @@ -231,6 +233,7 @@ HAS_MENU_LED = src_filter=+ HAS_MENU_MEDIA = src_filter=+ HAS_MENU_MIXER = src_filter=+ HAS_MENU_MMU2 = src_filter=+ +HAS_MENU_PASSWORD = src_filter=+ HAS_MENU_POWER_MONITOR = src_filter=+ HAS_MENU_CUTTER = src_filter=+ HAS_MENU_TEMPERATURE = src_filter=+ @@ -276,6 +279,7 @@ TEMP_STAT_LEDS = src_filter=+ MAX7219_DEBUG = src_filter=+ + MIXING_EXTRUDER = src_filter=+ + PRUSA_MMU2 = src_filter=+ + +PASSWORD_FEATURE = src_filter=+ + ADVANCED_PAUSE_FEATURE = src_filter=+ + + AUTO_POWER_CONTROL = src_filter=+ HAS_POWER_MONITOR = src_filter=+ + From 8318d90e859219af9aa750ba2b91c7568f4dac55 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 8 Aug 2020 20:13:15 -0500 Subject: [PATCH 07/25] Password followup --- Marlin/src/gcode/feature/password/M510-M512.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/gcode/feature/password/M510-M512.cpp b/Marlin/src/gcode/feature/password/M510-M512.cpp index bcdeb7b91ccd..f26fb75fdada 100644 --- a/Marlin/src/gcode/feature/password/M510-M512.cpp +++ b/Marlin/src/gcode/feature/password/M510-M512.cpp @@ -60,8 +60,8 @@ void GcodeSuite::M510() { return; } - if (parser.seenval('N')) { - password.value_entry = parser.ulongval('N'); + if (parser.seenval('S')) { + password.value_entry = parser.ulongval('S'); if (password.value_entry < CAT(1e, PASSWORD_LENGTH)) { password.is_set = true; From 837dc4727de20856ed9e633d42fce906d8702a15 Mon Sep 17 00:00:00 2001 From: cbaugher Date: Sun, 9 Aug 2020 15:46:47 -0500 Subject: [PATCH 08/25] Tool-change Z move followup (#18963) --- Marlin/src/module/tool_change.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 5d2dc7d3be3f..d1017cea8078 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -1133,7 +1133,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { if (toolchange_settings.enable_park) do_blocking_move_to_xy_z(destination, destination.z, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE)); #else do_blocking_move_to_xy(destination, planner.settings.max_feedrate_mm_s[X_AXIS]); - do_blocking_move_to_z(destination, planner.settings.max_feedrate_mm_s[Z_AXIS]); + do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); #endif #endif From f7b261a363d50f1ca071cd46d859ac3eabc3b4b2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 9 Aug 2020 15:55:11 -0500 Subject: [PATCH 09/25] Shorthand values for M575 B --- Marlin/src/gcode/config/M575.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/config/M575.cpp b/Marlin/src/gcode/config/M575.cpp index 4144c366d114..3aa5844653c2 100644 --- a/Marlin/src/gcode/config/M575.cpp +++ b/Marlin/src/gcode/config/M575.cpp @@ -33,7 +33,21 @@ * B - Baud rate (bits per second) */ void GcodeSuite::M575() { - const int32_t baud = parser.ulongval('B'); + int32_t baud = parser.ulongval('B'); + switch (baud) { + case 24: + case 96: + case 192: + case 384: + case 576: + case 1152: baud *= 100; break; + case 250: + case 500: baud *= 1000; break; + case 19: baud = 19200; break; + case 38: baud = 38400; break; + case 57: baud = 57600; break; + case 115: baud = 115200; break; + } switch (baud) { case 2400: case 9600: case 19200: case 38400: case 57600: case 115200: case 250000: case 500000: case 1000000: { From 81f5973afc6da027bb2eb51f3f76a864585c01f8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 9 Aug 2020 15:57:59 -0500 Subject: [PATCH 10/25] Followup for SPI Flash --- Marlin/src/gcode/gcode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 840df54f6a76..edbeca9c9279 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -896,7 +896,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe #endif - #if BOTH(HAS_SPI_FLASH, SDSUPPORT) + #if ALL(HAS_SPI_FLASH, SDSUPPORT, MARLIN_DEV_MODE) case 993: M993(); break; // M993: Backup SPI Flash to SD case 994: M994(); break; // M994: Load a Backup from SD to SPI Flash #endif From b15c207d0899e838d41bd1dd684917769b93b89d Mon Sep 17 00:00:00 2001 From: ftk Date: Mon, 10 Aug 2020 01:19:35 +0300 Subject: [PATCH 11/25] Remaining Time for LIGHTWEIGHT_UI (#18875) --- .../lcd/dogm/status_screen_lite_ST7920.cpp | 22 +++++++++++++++---- .../src/lcd/dogm/status_screen_lite_ST7920.h | 10 ++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp index fba485d7060e..211acc86c6d4 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp @@ -591,16 +591,17 @@ void ST7920_Lite_Status_Screen::draw_fan_speed(const uint8_t value) { write_byte('%'); } -void ST7920_Lite_Status_Screen::draw_print_time(const duration_t &elapsed) { +void ST7920_Lite_Status_Screen::draw_print_time(const duration_t &elapsed, char suffix) { #if HOTENDS == 1 set_ddram_address(DDRAM_LINE_3); #else set_ddram_address(DDRAM_LINE_3 + 5); #endif char str[7]; - str[elapsed.toDigital(str)] = ' '; + int str_length = elapsed.toDigital(str); + str[str_length++] = suffix; begin_data(); - write_str(str, 6); + write_str(str, str_length); } void ST7920_Lite_Status_Screen::draw_feedrate_percentage(const uint16_t percentage) { @@ -714,6 +715,7 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) { if (forceUpdate || indicators_changed()) { const bool blink = ui.get_blink(); const duration_t elapsed = print_job_timer.duration(); + duration_t remaining = TERN0(USE_M73_REMAINING_TIME, ui.get_remaining_time()); const uint16_t feedrate_perc = feedrate_percentage; const int16_t extruder_1_temp = thermalManager.degHotend(0), extruder_1_target = thermalManager.degTargetHotend(0); @@ -738,7 +740,19 @@ void ST7920_Lite_Status_Screen::update_indicators(const bool forceUpdate) { #endif draw_fan_speed(thermalManager.fanPercent(spd)); - draw_print_time(elapsed); + + // Draw elapsed/remaining time + const bool show_remaining = ENABLED(SHOW_REMAINING_TIME) && (DISABLED(ROTATE_PROGRESS_DISPLAY) || blink); + if (show_remaining && !remaining.second()) { + const auto progress = ui.get_progress_percent(); + if (progress) + remaining = elapsed.second() * (100 - progress) / progress; + } + if (show_remaining && remaining.second()) + draw_print_time(remaining, 'R'); + else + draw_print_time(elapsed); + draw_feedrate_percentage(feedrate_perc); // Update the fan and bed animations diff --git a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.h b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.h index bc18c43f107f..9f0815d099ce 100644 --- a/Marlin/src/lcd/dogm/status_screen_lite_ST7920.h +++ b/Marlin/src/lcd/dogm/status_screen_lite_ST7920.h @@ -80,14 +80,14 @@ class ST7920_Lite_Status_Screen { static void draw_fan_icon(const bool whichIcon); static void draw_heat_icon(const bool whichIcon, const bool heating); static void draw_temps(uint8_t line, const int16_t temp, const int16_t target, bool showTarget, bool targetStateChange); - static void draw_extruder_1_temp(const int16_t temp, const int16_t target, bool forceUpdate = false); - static void draw_extruder_2_temp(const int16_t temp, const int16_t target, bool forceUpdate = false); - static void draw_bed_temp(const int16_t temp, const int16_t target, bool forceUpdate = false); + static void draw_extruder_1_temp(const int16_t temp, const int16_t target, bool forceUpdate=false); + static void draw_extruder_2_temp(const int16_t temp, const int16_t target, bool forceUpdate=false); + static void draw_bed_temp(const int16_t temp, const int16_t target, bool forceUpdate=false); static void draw_fan_speed(const uint8_t value); - static void draw_print_time(const duration_t &elapsed); + static void draw_print_time(const duration_t &elapsed, char suffix=' '); static void draw_feedrate_percentage(const uint16_t percentage); static void draw_status_message(); - static void draw_position(const xyze_pos_t &pos, bool position_known = true); + static void draw_position(const xyze_pos_t &pos, bool position_known=true); static bool indicators_changed(); static bool position_changed(); From f642656bff4e71256ea491c344b3ddb695dd962d Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Mon, 10 Aug 2020 00:10:53 +0000 Subject: [PATCH 12/25] [cron] Bump distribution date (2020-08-10) --- 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 33cd24dd0219..681bbfeca5ee 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-09" + #define STRING_DISTRIBUTION_DATE "2020-08-10" #endif /** From ce3df42e229ea563ef319f42cf5283f5a2ba3fa3 Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Mon, 10 Aug 2020 03:48:57 +0200 Subject: [PATCH 13/25] Fix DISABLE_[XYZE] code (#18970) Co-authored-by: Scott Lahteine --- Marlin/src/module/planner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index c2a9e6ac7716..931daa3322b8 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1281,7 +1281,7 @@ void Planner::recalculate() { void Planner::check_axes_activity() { #if ANY(DISABLE_X, DISABLE_Y, DISABLE_Z, DISABLE_E) - xyze_bool_t axis_active = { true, true, true, true }; + xyze_bool_t axis_active = { false }; #endif #if HAS_FAN @@ -1316,10 +1316,10 @@ void Planner::check_axes_activity() { #if ANY(DISABLE_X, DISABLE_Y, DISABLE_Z, DISABLE_E) for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) { block_t *block = &block_buffer[b]; - if (ENABLED(DISABLE_X) && block->steps[X_AXIS]) axis_active[X_AXIS] = true; - if (ENABLED(DISABLE_Y) && block->steps[Y_AXIS]) axis_active[Y_AXIS] = true; - if (ENABLED(DISABLE_Z) && block->steps[Z_AXIS]) axis_active[Z_AXIS] = true; - if (ENABLED(DISABLE_E) && block->steps[E_AXIS]) axis_active[E_AXIS] = true; + if (ENABLED(DISABLE_X) && block->steps.x) axis_active.x = true; + if (ENABLED(DISABLE_Y) && block->steps.y) axis_active.y = true; + if (ENABLED(DISABLE_Z) && block->steps.z) axis_active.z = true; + if (ENABLED(DISABLE_E) && block->steps.e) axis_active.e = true; } #endif } From 911cdd4d2f90104c74a6f5ee3a5656388eeccfa7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 10 Aug 2020 01:44:11 -0500 Subject: [PATCH 14/25] Fix scripts using gawk and wget --- buildroot/bin/use_example_configs | 17 ++++++++++------- buildroot/share/fonts/uxggenpages.sh | 5 ++++- buildroot/share/git/ghtp | 9 ++++++--- buildroot/share/git/mfclean | 5 ++++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/buildroot/bin/use_example_configs b/buildroot/bin/use_example_configs index 96be67e53d17..a7fe39a85988 100755 --- a/buildroot/bin/use_example_configs +++ b/buildroot/bin/use_example_configs @@ -1,18 +1,21 @@ #!/usr/bin/env bash IFS=: read -r PART1 PART2 <<< "$@" -[ -n "${PART2}" ] && { REPO="$PART1" ; RDIR="$PART2" ; } \ - || { REPO=bugfix-2.0.x ; RDIR="$PART1" ; } +[ -n "${PART2}" ] && { REPO="$PART1" ; RDIR="${PART2// /%20}" ; } \ + || { REPO=bugfix-2.0.x ; RDIR="${PART1// /%20}" ; } EXAMPLES="https://raw.githubusercontent.com/MarlinFirmware/Configurations/$REPO/config/examples" +which curl >/dev/null && TOOL='curl -L -s -S -f -o wgot' +which wget >/dev/null && TOOL='wget -q -O wgot' + restore_configs cd Marlin -wget -q "$EXAMPLES/$RDIR/Configuration.h" -O wgot && mv wgot Configuration.h -wget -q "$EXAMPLES/$RDIR/Configuration_adv.h" -O wgot && mv wgot Configuration_adv.h -wget -q "$EXAMPLES/$RDIR/_Bootscreen.h" -O wgot && mv wgot _Bootscreen.h -wget -q "$EXAMPLES/$RDIR/_Statusscreen.h" -O wgot && mv wgot _Statusscreen.h -rm -f wgot +$TOOL "$EXAMPLES/$RDIR/Configuration.h" >/dev/null 2>&1 && mv wgot Configuration.h +$TOOL "$EXAMPLES/$RDIR/Configuration_adv.h" >/dev/null 2>&1 && mv wgot Configuration.h +$TOOL "$EXAMPLES/$RDIR/_Bootscreen.h" >/dev/null 2>&1 && mv wgot Configuration.h +$TOOL "$EXAMPLES/$RDIR/_Statusscreen.h" >/dev/null 2>&1 && mv wgot Configuration.h +rm -f wgot cd - >/dev/null diff --git a/buildroot/share/fonts/uxggenpages.sh b/buildroot/share/fonts/uxggenpages.sh index 9207835148f6..46ad438f9c85 100755 --- a/buildroot/share/fonts/uxggenpages.sh +++ b/buildroot/share/fonts/uxggenpages.sh @@ -139,11 +139,14 @@ BEGIN { } EOF +which awk >/dev/null && AWK=awk +which gawk >/dev/null && AWK=gawk + grep -Hrn _UxGT . | grep '"' \ | sed 's/_UxGT("/\n&/g;s/[^\n]*\n_UxGT("\([^"]*\)[^\n]*/\1 /g;s/.$//' \ | ${EXEC_GENPAGES} \ | sort -k 1n -k 2n | uniq \ - | gawk -v EXEC_PREFIX=${DN_EXEC} -f "proc.awk" \ + | "$AWK" -v EXEC_PREFIX=${DN_EXEC} -f "proc.awk" \ | while read PAGE BEGIN END UTF8BEGIN UTF8END; do \ if [ ! -f ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h ]; then \ ${EXEC_BDF2U8G} -u ${PAGE} -b ${BEGIN} -e ${END} ${FN_FONT} fontpage_${PAGE}_${BEGIN}_${END} ${DN_DATA}/fontpage_${PAGE}_${BEGIN}_${END}.h > /dev/null 2>&1 ; diff --git a/buildroot/share/git/ghtp b/buildroot/share/git/ghtp index f7a6263012cd..a2fac985ddbb 100755 --- a/buildroot/share/git/ghtp +++ b/buildroot/share/git/ghtp @@ -13,14 +13,17 @@ case "$1" in -[Hh]) TYPE=HTTPS ; MATCH="git@" ; FORMULA="$GH_SSH/$GH_HTTPS" ;; -[Ss]) TYPE=SSH ; MATCH="https:" ; FORMULA="$GH_HTTPS/$GH_SSH" ;; *) - echo "usage: `basename $0` -h | -s" 1>&2 + echo "Usage: `basename $0` -h | -s" 1>&2 echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2 echo -e " \e[0;92m-s\e[0m to switch to SSH" 1>&2 exit 1 ;; esac -REMOTES=$(git remote -v | egrep "\t$MATCH" | gawk '{print $1 " " $2}' | sort -u | sed "s/$FORMULA/") +which awk >/dev/null && AWK=awk +which gawk >/dev/null && AWK=gawk + +REMOTES=$(git remote -v | egrep "\t$MATCH" | "$AWK" '{print $1 " " $2}' | sort -u | sed "s/$FORMULA/") if [[ -z $REMOTES ]]; then echo "Nothing to do." ; exit @@ -29,5 +32,5 @@ fi echo "$REMOTES" | xargs -n2 git remote set-url echo -n "Remotes set to $TYPE: " -echo "$REMOTES" | gawk '{printf "%s ", $1}' +echo "$REMOTES" | "$AWK" '{printf "%s ", $1}' echo diff --git a/buildroot/share/git/mfclean b/buildroot/share/git/mfclean index f38997405bc8..b6ad2b5149ff 100755 --- a/buildroot/share/git/mfclean +++ b/buildroot/share/git/mfclean @@ -6,6 +6,9 @@ # Great way to clean up your branches after messing around a lot # +which awk >/dev/null && AWK=awk +which gawk >/dev/null && AWK=gawk + KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2" echo "Fetching latest upstream and origin..." @@ -18,7 +21,7 @@ git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d echo echo "Pruning Remotely-deleted Branches..." -git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D +git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | "$AWK" '{print $1}' | xargs -n 1 git branch -D echo # List fork branches that don't match local branches From 276d78461eabf9c1e16994ab4a1c8fe4930b5523 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Tue, 11 Aug 2020 00:10:45 +0000 Subject: [PATCH 15/25] [cron] Bump distribution date (2020-08-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 681bbfeca5ee..9b379ba9f54e 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-10" + #define STRING_DISTRIBUTION_DATE "2020-08-11" #endif /** From d2d6c167dfb93dcd63a5f55552200f840fd3aea1 Mon Sep 17 00:00:00 2001 From: InsanityAutomation <38436470+InsanityAutomation@users.noreply.github.com> Date: Mon, 10 Aug 2020 21:04:40 -0400 Subject: [PATCH 16/25] Fix Ender-3 V2 DWIN with manual mesh, host prompt (#18981) --- Marlin/src/lcd/dwin/dwin.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Marlin/src/lcd/dwin/dwin.cpp b/Marlin/src/lcd/dwin/dwin.cpp index 74a0e6d8ff63..87db3c4b2573 100644 --- a/Marlin/src/lcd/dwin/dwin.cpp +++ b/Marlin/src/lcd/dwin/dwin.cpp @@ -53,6 +53,10 @@ #include "../../module/motion.h" #include "../../module/planner.h" +#if ENABLED(HOST_ACTION_COMMANDS) + #include "../../feature/host_actions.h" +#endif + #if HAS_LEVELING #include "../../feature/bedlevel/bedlevel.h" #endif @@ -124,7 +128,7 @@ constexpr uint16_t TROWS = 6, MROWS = TROWS - 1, // Total rows, and other #define MBASE(L) (49 + (L)*MLINE) -#define BABY_Z_VAR TERN(HAS_LEVELING, probe.offset.z, zprobe_zoffset) +#define BABY_Z_VAR TERN(HAS_BED_PROBE, probe.offset.z, zprobe_zoffset) /* Value Init */ HMI_value_t HMI_ValueStruct; @@ -1116,11 +1120,11 @@ void HMI_Zoffset(void) { if (HMI_ValueStruct.show_mode == -4) { checkkey = Prepare; - show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(4 + MROWS - index_prepare), TERN(HAS_LEVELING, probe.offset.z * 100, HMI_ValueStruct.offset_value)); + show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(4 + MROWS - index_prepare), TERN(HAS_BED_PROBE, probe.offset.z * 100, HMI_ValueStruct.offset_value)); } else { checkkey = Tune; - show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(5 + MROWS - index_tune), TERN(HAS_LEVELING, probe.offset.z * 100, HMI_ValueStruct.offset_value)); + show_plus_or_minus(font8x16, Background_black, 2, 2, 202, MBASE(5 + MROWS - index_tune), TERN(HAS_BED_PROBE, probe.offset.z * 100, HMI_ValueStruct.offset_value)); } DWIN_UpdateLCD(); return; @@ -1484,7 +1488,7 @@ void update_variable(void) { DWIN_Draw_IntValue(true, true, 0, STAT_FONT, White, Background_black, 3, 33 + 2 * STAT_CHR_W, 429, feedrate_percentage); last_speed = feedrate_percentage; } - #if HAS_LEVELING + #if HAS_BED_PROBE if (last_probe_zoffset != probe.offset.z) { show_plus_or_minus(STAT_FONT, Background_black, 2, 2, 178 + STAT_CHR_W, 429, probe.offset.z * 100); last_probe_zoffset = probe.offset.z; @@ -2188,7 +2192,7 @@ void HMI_Prepare(void) { Popup_Window_Home(); break; case 4: // Z-offset - #if HAS_LEVELING + #if HAS_BED_PROBE checkkey = Homeoffset; HMI_ValueStruct.show_mode = -4; HMI_ValueStruct.offset_value = probe.offset.z * 100; @@ -3390,7 +3394,7 @@ void EachMomentUpdate(void) { else if (abort_flag && !HMI_flag.home_flag) { // Print Stop abort_flag = 0; HMI_ValueStruct.print_speed = feedrate_percentage = 100; - zprobe_zoffset = TERN(HAS_LEVELING, probe.offset.z, 0); + zprobe_zoffset = TERN(HAS_BED_PROBE, probe.offset.z, 0); planner.finish_and_disable(); From f62578efec85b155a0c969a1794b98bf1f6c19fe Mon Sep 17 00:00:00 2001 From: Marcio T Date: Mon, 10 Aug 2020 19:06:19 -0600 Subject: [PATCH 17/25] For FTDI800 compatibility, remove VERTEX_FORMAT dependency (#18982) --- .../screens/bed_mesh_screen.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp index f8a30e82411e..663555f05de7 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp @@ -88,7 +88,15 @@ void BedMeshScreen::drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI:: const float scale_z = ((val_max == val_min) ? 1 : 1/(val_max - val_min)) * autoscale_max; - // These equations determine the appearance of the grid on the screen. + /** + * The 3D points go through a 3D graphics pipeline to determine the final 2D point on the screen. + * This is written out as a stack of macros that each apply an affine transformation to the point. + * At compile time, the compiler should be able to reduce these expressions. + * + * The last transformation in the chain (TRANSFORM_5) is initially set to a no-op so we can measure + * the dimensions of the grid, but is later replaced with a scaling transform that scales the grid + * to fit. + */ #define TRANSFORM_5(X,Y,Z) (X), (Y) // No transform #define TRANSFORM_4(X,Y,Z) TRANSFORM_5((X)/(Z),(Y)/-(Z), 0) // Perspective @@ -119,8 +127,12 @@ void BedMeshScreen::drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI:: const float center_x = x + w/2; const float center_y = y + h/2; + // Now replace the last transformation in the chain with a scaling operation. + #undef TRANSFORM_5 - #define TRANSFORM_5(X,Y,Z) center_x + (X - grid_cx) * scale_x, center_y + (Y - grid_cy) * scale_y // Fit to bounds + #define TRANSFORM_6(X,Y,Z) (X)*16, (Y)*16 // Scale to 1/16 pixel units + #define TRANSFORM_5(X,Y,Z) TRANSFORM_6( center_x + ((X) - grid_cx) * scale_x, \ + center_y + ((Y) - grid_cy) * scale_y, 0) // Scale to bounds // Draw the grid @@ -128,7 +140,6 @@ void BedMeshScreen::drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI:: CommandProcessor cmd; cmd.cmd(SAVE_CONTEXT()) - .cmd(VERTEX_FORMAT(0)) .cmd(TAG_MASK(false)) .cmd(SAVE_CONTEXT()); From 6dd054895b4566f7d63a629f3ab5f5aa890db8af Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 10 Aug 2020 20:03:13 -0500 Subject: [PATCH 18/25] Add'l CI/git script tweaks, fixes --- buildroot/bin/use_example_configs | 6 +++--- buildroot/share/fonts/uxggenpages.sh | 3 +-- buildroot/share/git/ghtp | 3 +-- buildroot/share/git/mfclean | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/buildroot/bin/use_example_configs b/buildroot/bin/use_example_configs index a7fe39a85988..83c0f5485d2c 100755 --- a/buildroot/bin/use_example_configs +++ b/buildroot/bin/use_example_configs @@ -13,9 +13,9 @@ restore_configs cd Marlin $TOOL "$EXAMPLES/$RDIR/Configuration.h" >/dev/null 2>&1 && mv wgot Configuration.h -$TOOL "$EXAMPLES/$RDIR/Configuration_adv.h" >/dev/null 2>&1 && mv wgot Configuration.h -$TOOL "$EXAMPLES/$RDIR/_Bootscreen.h" >/dev/null 2>&1 && mv wgot Configuration.h -$TOOL "$EXAMPLES/$RDIR/_Statusscreen.h" >/dev/null 2>&1 && mv wgot Configuration.h +$TOOL "$EXAMPLES/$RDIR/Configuration_adv.h" >/dev/null 2>&1 && mv wgot Configuration_adv.h +$TOOL "$EXAMPLES/$RDIR/_Bootscreen.h" >/dev/null 2>&1 && mv wgot _Bootscreen.h +$TOOL "$EXAMPLES/$RDIR/_Statusscreen.h" >/dev/null 2>&1 && mv wgot _Statusscreen.h rm -f wgot cd - >/dev/null diff --git a/buildroot/share/fonts/uxggenpages.sh b/buildroot/share/fonts/uxggenpages.sh index 46ad438f9c85..a99fd9902463 100755 --- a/buildroot/share/fonts/uxggenpages.sh +++ b/buildroot/share/fonts/uxggenpages.sh @@ -139,8 +139,7 @@ BEGIN { } EOF -which awk >/dev/null && AWK=awk -which gawk >/dev/null && AWK=gawk +AWK=$(which gawk || which awk) grep -Hrn _UxGT . | grep '"' \ | sed 's/_UxGT("/\n&/g;s/[^\n]*\n_UxGT("\([^"]*\)[^\n]*/\1 /g;s/.$//' \ diff --git a/buildroot/share/git/ghtp b/buildroot/share/git/ghtp index a2fac985ddbb..3c0e21e371b1 100755 --- a/buildroot/share/git/ghtp +++ b/buildroot/share/git/ghtp @@ -20,8 +20,7 @@ case "$1" in ;; esac -which awk >/dev/null && AWK=awk -which gawk >/dev/null && AWK=gawk +AWK=$(which gawk || which awk) REMOTES=$(git remote -v | egrep "\t$MATCH" | "$AWK" '{print $1 " " $2}' | sort -u | sed "s/$FORMULA/") diff --git a/buildroot/share/git/mfclean b/buildroot/share/git/mfclean index b6ad2b5149ff..fd131c42630c 100755 --- a/buildroot/share/git/mfclean +++ b/buildroot/share/git/mfclean @@ -6,8 +6,7 @@ # Great way to clean up your branches after messing around a lot # -which awk >/dev/null && AWK=awk -which gawk >/dev/null && AWK=gawk +AWK=$(which gawk || which awk) KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2" From b14f630f26b95cd08ef047ba1a83cfb6dc2a537e Mon Sep 17 00:00:00 2001 From: Anders Sahlman <57940217+AndersSahlman@users.noreply.github.com> Date: Tue, 11 Aug 2020 03:21:48 +0200 Subject: [PATCH 19/25] MKS Robin new 320x240 TFT Color UI support (#18985) --- Marlin/src/lcd/tft/ili9341.h | 8 +- Marlin/src/lcd/tft/ili9488.h | 4 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h | 128 ++++++++++++------ 3 files changed, 96 insertions(+), 44 deletions(-) diff --git a/Marlin/src/lcd/tft/ili9341.h b/Marlin/src/lcd/tft/ili9341.h index 42a36b7e342e..22709e4cf7d3 100644 --- a/Marlin/src/lcd/tft/ili9341.h +++ b/Marlin/src/lcd/tft/ili9341.h @@ -38,8 +38,12 @@ #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 -#define ILI9341_COLOR_BGR -#define ILI9341_ORIENTATION ILI9341_ORIENTATION_LEFT +#ifndef ILI9341_COLOR_RGB + #define ILI9341_COLOR_BGR +#endif +#ifndef ILI9341_ORIENTATION + #define ILI9341_ORIENTATION ILI9341_ORIENTATION_LEFT +#endif #define ILI9341_MADCTL_DATA (ILI9341_ORIENTATION | TERN(ILI9341_COLOR_BGR, ILI9341_MADCTL_BGR, ILI9341_MADCTL_RGB)) #define ILI9341_NOP 0x00 // No Operation diff --git a/Marlin/src/lcd/tft/ili9488.h b/Marlin/src/lcd/tft/ili9488.h index 6aad70486553..19fdc78e0a5e 100644 --- a/Marlin/src/lcd/tft/ili9488.h +++ b/Marlin/src/lcd/tft/ili9488.h @@ -38,7 +38,9 @@ #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 -#define ILI9488_COLOR_BGR +#ifndef ILI9488_COLOR_RGB + #define ILI9488_COLOR_BGR +#endif #ifndef ILI9488_ORIENTATION #define ILI9488_ORIENTATION ILI9488_ORIENTATION_LEFT #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index 73e1b12b88eb..716cb1637556 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -22,34 +22,33 @@ #pragma once /** - * MKS Robin MINI (STM32F130VET6) board pin assignments + * MKS Robin mini (STM32F130VET6) board pin assignments */ #ifndef __STM32F1__ #error "Oops! Select an STM32F1 board in 'Tools > Board.'" #elif HOTENDS > 1 || E_STEPPERS > 1 - #error "MKS Robin mini supports up to 1 hotends / E-steppers. Comment out this line to continue." + #error "MKS Robin mini only supports 1 hotend / E-stepper. Comment out this line to continue." #endif -#define BOARD_INFO_NAME "MKS Robin mini" +#define BOARD_INFO_NAME "MKS Robin Mini" // // Release PB4 (Y_ENABLE_PIN) from JTAG NRST role // #define DISABLE_DEBUG +// +// EEPROM +// #if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) #define FLASH_EEPROM_EMULATION - // 2K in a AT24C16N - #define EEPROM_PAGE_SIZE (0x800U) // 2KB - #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) + #define EEPROM_PAGE_SIZE (0x800U) // 2KB + #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL) #define MARLIN_EEPROM_SIZE EEPROM_PAGE_SIZE // 2KB #endif -// -// Note: MKS Robin mini board is using SPI2 interface. -// -#define SPI_MODULE 2 +#define ENABLE_SPI2 // // Limit Switches @@ -82,6 +81,15 @@ #define E0_STEP_PIN PD6 #define E0_DIR_PIN PD3 + +// Motor current PWM pins +#define MOTOR_CURRENT_PWM_XY_PIN PA6 +#define MOTOR_CURRENT_PWM_Z_PIN PA7 +#define MOTOR_CURRENT_PWM_E_PIN PB0 +#define MOTOR_CURRENT_PWM_RANGE 1500 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp +#ifndef DEFAULT_PWM_MOTOR_CURRENT + #define DEFAULT_PWM_MOTOR_CURRENT { 800, 800, 800 } +#endif // // Temperature Sensors // @@ -91,64 +99,102 @@ // // Heaters / Fans // -#define HEATER_0_PIN PC3 // HEATER1 -#define HEATER_BED_PIN PA0 // HOT BED +#define HEATER_0_PIN PC3 +#define HEATER_BED_PIN PA0 #define FAN_PIN PB1 // FAN -// -// Thermocouples -// -//#define MAX6675_SS_PIN PE5 // TC1 - CS1 -//#define MAX6675_SS_PIN PE6 // TC2 - CS2 - // // Misc. Functions // #define POWER_LOSS_PIN PA2 // PW_DET #define PS_ON_PIN PA3 // PW_OFF -//#define LED_PIN PB2 +#define SERVO0_PIN PA8 // Enable BLTOUCH support on IO0 (WIFI connector) + +#define MT_DET_1_PIN PA4 +#define MT_DET_PIN_INVERTING false + +#define WIFI_IO0_PIN PC13 + +// +// SD Card +// +#ifndef SDCARD_CONNECTION + #define SDCARD_CONNECTION ONBOARD +#endif + +#define SDIO_SUPPORT +#define SDIO_CLOCK 4500000 // 4.5 MHz +#define SD_DETECT_PIN PD12 +#define ONBOARD_SD_CS_PIN PC11 // // LCD / Controller // #define BEEPER_PIN PC5 -#define SD_DETECT_PIN PD12 /** * Note: MKS Robin TFT screens use various TFT controllers. * If the screen stays white, disable 'LCD_RESET_PIN' * to let the bootloader init the screen. */ + #define XPT2046_X_CALIBRATION 12033 + #define XPT2046_Y_CALIBRATION -9047 + #define XPT2046_X_OFFSET -30 + #define XPT2046_Y_OFFSET 254 + #if ENABLED(FSMC_GRAPHICAL_TFT) + #define FSMC_CS_PIN PD7 // NE4 #define FSMC_RS_PIN PD11 // A0 - #define LCD_RESET_PIN PC6 + #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT + #define FSMC_DMA_DEV DMA2 + #define FSMC_DMA_CHANNEL DMA_CH5 + + #define LCD_RESET_PIN PC6 // FSMC_RST #define LCD_BACKLIGHT_PIN PD13 #if NEED_TOUCH_PINS - #define TOUCH_CS_PIN PC2 - #define TOUCH_SCK_PIN PB13 - #define TOUCH_MOSI_PIN PB15 - #define TOUCH_MISO_PIN PB14 + #define TOUCH_CS_PIN PC2 // SPI2_NSS + #define TOUCH_SCK_PIN PB13 // SPI2_SCK + #define TOUCH_MISO_PIN PB14 // SPI2_MISO + #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI #endif + +#elif ENABLED(TFT_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 PC2 // 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 #endif -// Motor current PWM pins -#define MOTOR_CURRENT_PWM_XY_PIN PA6 -#define MOTOR_CURRENT_PWM_Z_PIN PA7 -#define MOTOR_CURRENT_PWM_E_PIN PB0 -#define MOTOR_CURRENT_PWM_RANGE 1500 // (255 * (1000mA / 65535)) * 257 = 1000 is equal 1.6v Vref in turn equal 1Amp -#define DEFAULT_PWM_MOTOR_CURRENT { 1030, 1030, 1030 } // 1.05Amp per driver, here is XY, Z and E. This values determined empirically. - -// This is a kind of workaround in case native marlin "digipot" interface won't work. -// Required to enable related code in STM32F1/HAL.cpp -//#ifndef MKS_ROBIN_MINI_VREF_PWM -// #define MKS_ROBIN_MINI_VREF_PWM -//#endif - -//#define VREF_XY_PIN PA6 -//#define VREF_Z_PIN PA7 -//#define VREF_E1_PIN PB0 +#define HAS_SPI_FLASH 1 +#define SPI_FLASH_SIZE 0x1000000 // 16MB +#if HAS_SPI_FLASH + #define W25QXX_CS_PIN PB12 // Flash chip-select + #define W25QXX_MOSI_PIN PB15 + #define W25QXX_MISO_PIN PB14 + #define W25QXX_SCK_PIN PB13 +#endif From 9590fcd85567d578087568bdc8c478073f9808b7 Mon Sep 17 00:00:00 2001 From: Robby Candra Date: Tue, 11 Aug 2020 08:25:35 +0700 Subject: [PATCH 20/25] EVENT_GCODE_SD_STOP => ABORT (#18978) --- Marlin/Configuration_adv.h | 2 +- Marlin/src/MarlinCore.cpp | 4 ++-- Marlin/src/inc/SanityCheck.h | 6 ++++-- Marlin/src/lcd/dwin/dwin.cpp | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a3013611cba6..1b31f0bc3498 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1137,7 +1137,7 @@ //#define MENU_ADDAUTOSTART // Add a menu option to run auto#.g files - #define EVENT_GCODE_SD_STOP "G28XY" // G-code to run on Stop Print (e.g., "G28XY" or "G27") + #define EVENT_GCODE_SD_ABORT "G28XY" // G-code to run on SD Abort Print (e.g., "G28XY" or "G27") #if ENABLED(PRINTER_EVENT_LEDS) #define PE_LEDS_COMPLETED_TIME (30*60) // (seconds) Time to keep the LED "done" color before restoring normal illumination diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 39530395eb48..30b6fbe3d59d 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -453,8 +453,8 @@ void startOrResumeJob() { #endif wait_for_heatup = false; TERN_(POWER_LOSS_RECOVERY, recovery.purge()); - #ifdef EVENT_GCODE_SD_STOP - queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); + #ifdef EVENT_GCODE_SD_ABORT + queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index f9b65c8bf483..6fcd867981de 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -517,6 +517,8 @@ #error "TOUCH_BUTTONS is now TOUCH_SCREEN. Please update your Configuration.h." #elif defined(ANYCUBIC_TFT_MODEL) #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h." +#elif defined(EVENT_GCODE_SD_STOP) + #error "EVENT_GCODE_SD_STOP is now EVENT_GCODE_SD_ABORT. Please update your Configuration.h." #endif #ifdef FIL_RUNOUT_INVERTING @@ -742,8 +744,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif #endif -#if defined(EVENT_GCODE_SD_STOP) && DISABLED(NOZZLE_PARK_FEATURE) - static_assert(nullptr == strstr(EVENT_GCODE_SD_STOP, "G27"), "NOZZLE_PARK_FEATURE is required to use G27 in EVENT_GCODE_SD_STOP."); +#if defined(EVENT_GCODE_SD_ABORT) && DISABLED(NOZZLE_PARK_FEATURE) + static_assert(nullptr == strstr(EVENT_GCODE_SD_ABORT, "G27"), "NOZZLE_PARK_FEATURE is required to use G27 in EVENT_GCODE_SD_ABORT."); #endif /** diff --git a/Marlin/src/lcd/dwin/dwin.cpp b/Marlin/src/lcd/dwin/dwin.cpp index 87db3c4b2573..1aa2656dcfd6 100644 --- a/Marlin/src/lcd/dwin/dwin.cpp +++ b/Marlin/src/lcd/dwin/dwin.cpp @@ -2072,9 +2072,9 @@ void HMI_PauseOrStop(void) { #ifdef ACTION_ON_CANCEL host_action_cancel(); #endif - #ifdef EVENT_GCODE_SD_STOP + #ifdef EVENT_GCODE_SD_ABORT Popup_Window_Home(); - queue.inject_P(PSTR(EVENT_GCODE_SD_STOP)); // For Ender 3 "G28 X Y" + queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif abort_flag = true; #endif From bd690f12bc7fc4abdd2fc5c6971b11b2635c4448 Mon Sep 17 00:00:00 2001 From: qwewer0 <57561110+qwewer0@users.noreply.github.com> Date: Tue, 11 Aug 2020 10:11:40 +0200 Subject: [PATCH 21/25] Mention units for MANUAL_FEEDRATE (#18993) --- Marlin/Configuration_adv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 1b31f0bc3498..1c29af1f46cb 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1025,7 +1025,7 @@ // @section lcd #if EITHER(ULTIPANEL, EXTENSIBLE_UI) - #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // Feedrates for manual moves along X, Y, Z, E from panel + #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // (mm/m) Feedrates for manual moves along X, Y, Z, E from panel #define SHORT_MANUAL_Z_MOVE 0.025 // (mm) Smallest manual Z move (< 0.1mm) #if ENABLED(ULTIPANEL) #define MANUAL_E_MOVES_RELATIVE // Display extruder move distance rather than "position" From ca4eaf92b4d1acda18a5ffba515efd5bd1be0e43 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Wed, 12 Aug 2020 00:10:11 +0000 Subject: [PATCH 22/25] [cron] Bump distribution date (2020-08-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 9b379ba9f54e..bead274b4cda 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-11" + #define STRING_DISTRIBUTION_DATE "2020-08-12" #endif /** From ee28a1079582b39fa97d563f4df4824964552638 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 12 Aug 2020 16:46:51 -0500 Subject: [PATCH 23/25] String interpolation for 2-digit numbers (#18998) --- Marlin/src/core/language.h | 4 ++-- Marlin/src/lcd/lcdprint.cpp | 18 ++++++++++++------ Marlin/src/lcd/tft/tft_string.cpp | 21 ++++++++++----------- Marlin/src/lcd/tft/tft_string.h | 6 +++--- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index 48431455f0ff..f0ddbdd6d096 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -353,7 +353,7 @@ * */ #if ENABLED(NUMBER_TOOLS_FROM_0) - #define LCD_FIRST_TOOL '0' + #define LCD_FIRST_TOOL 0 #define LCD_STR_N0 "0" #define LCD_STR_N1 "1" #define LCD_STR_N2 "2" @@ -363,7 +363,7 @@ #define LCD_STR_N6 "6" #define LCD_STR_N7 "7" #else - #define LCD_FIRST_TOOL '1' + #define LCD_FIRST_TOOL 1 #define LCD_STR_N0 "1" #define LCD_STR_N1 "2" #define LCD_STR_N2 "3" diff --git a/Marlin/src/lcd/lcdprint.cpp b/Marlin/src/lcd/lcdprint.cpp index c982cfe2aa86..0f7f945a9925 100644 --- a/Marlin/src/lcd/lcdprint.cpp +++ b/Marlin/src/lcd/lcdprint.cpp @@ -44,22 +44,28 @@ lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const i if (ch == '=' || ch == '~' || ch == '*') { if (ind >= 0) { if (ch == '*') { lcd_put_wchar('E'); n--; } - if (n) { lcd_put_wchar(ind + ((ch == '=') ? '0' : LCD_FIRST_TOOL)); n--; } + if (n) { + int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL); + if (inum >= 10) { + lcd_put_wchar('0' + (inum / 10)); n--; + inum %= 10; + } + if (n) { lcd_put_wchar('0' + inum); n--; } + } } else { PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED); n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); } if (n) n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); - continue; } else if (ch == '$' && inStr) { n -= lcd_put_u8str_max_P(inStr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH); - continue; } - - lcd_put_wchar(ch); - n--; + else { + lcd_put_wchar(ch); + n--; + } } return n; } diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index f4e203445daf..7e66c3d29cf8 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -86,33 +86,32 @@ void TFT_String::set() { uint8_t read_byte(uint8_t *byte) { return *byte; } -void TFT_String::add(uint8_t *string, uint8_t index, uint8_t *itemString) { - uint8_t character; +void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { wchar_t wchar; while (*string) { string = get_utf8_value_cb(string, read_byte, &wchar); - if (wchar > 255) - wchar |= 0x0080; - character = (uint8_t) (wchar & 0x00FF); + if (wchar > 255) wchar |= 0x0080; + uint8_t ch = uint8_t(wchar & 0x00FF); - if (character == '=' || character == '~' || character == '*') { + if (ch == '=' || ch == '~' || ch == '*') { if (index >= 0) { - if (character == '*') - add_character('E'); - add_character(index + ((character == '=') ? '0' : LCD_FIRST_TOOL)); + int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL); + if (ch == '*') add_character('E'); + if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; } + add_character('0' + inum); } else { add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED)); } continue; } - else if (character == '$' && itemString) { + else if (ch == '$' && itemString) { add(itemString); continue; } - add_character(character); + add_character(ch); } eol(); } diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index b4c94953f759..d83d3af7027e 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -86,11 +86,11 @@ 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, uint8_t index, uint8_t *itemString = NULL); + 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, uint8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); }; + static void set(uint8_t *string, int8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); }; static inline void set(const char *string) { set((uint8_t *)string); } - static inline void set(const char *string, uint8_t index, const char *itemString = NULL) { set((uint8_t *)string, index, itemString); } + static inline void set(const char *string, int8_t index, const char *itemString = NULL) { set((uint8_t *)string, index, itemString); } static inline void add(const char *string) { add((uint8_t *)string); } static void trim(uint8_t character = 0x20); From 3b9e0c3dde3d1879fa59fa1244a050319dc1467a Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Thu, 13 Aug 2020 00:10:41 +0000 Subject: [PATCH 24/25] [cron] Bump distribution date (2020-08-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 bead274b4cda..3babd11a3ca5 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2020-08-12" + #define STRING_DISTRIBUTION_DATE "2020-08-13" #endif /** From ff5c8d35705df99f385a6b27163380a249c2e646 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Thu, 13 Aug 2020 20:31:59 -0300 Subject: [PATCH 25/25] Optimize LVGL with HAL TFT IO (SPI and FSMC) (#18974) --- Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp | 18 +- Marlin/src/HAL/STM32F1/tft/tft_fsmc.h | 7 + Marlin/src/HAL/STM32F1/tft/tft_spi.cpp | 15 +- Marlin/src/HAL/STM32F1/tft/tft_spi.h | 7 + Marlin/src/inc/Conditionals_adv.h | 2 +- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp | 186 ++---------- Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h | 20 +- .../src/lcd/extui/lib/mks_ui/draw_dialog.cpp | 2 + Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp | 69 +---- .../extui/lib/mks_ui/mks_hardware_test.cpp | 2 - Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp | 272 ++--------------- .../lib/mks_ui/tft_lvgl_configuration.cpp | 280 +++--------------- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 25 +- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 25 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 11 + .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 35 ++- 16 files changed, 191 insertions(+), 785 deletions(-) diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp index 33cddd1e05e1..e0047e7d5910 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_FSMC_TFT +#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC) #include "tft_fsmc.h" #include @@ -224,13 +224,15 @@ void TFT_FSMC::Abort() { } void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {}; - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); + #if defined(FSMC_DMA_DEV) && defined(FSMC_DMA_CHANNEL) + dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease); + dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count); + dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); + dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); + + while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {}; + dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); + #endif } #endif // HAS_FSMC_TFT diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h index 5c43361c0cab..6fcfea8a1167 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h @@ -61,4 +61,11 @@ class TFT_FSMC { static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); } static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); } + static void WriteMultiple(uint16_t Color, uint32_t Count) { + static uint16_t Data; Data = Color; + while (Count > 0) { + TransmitDMA(DMA_CIRC_MODE, &Data, Count > 0xFFFF ? 0xFFFF : Count); + Count = Count > 0xFFFF ? Count - 0xFFFF : 0; + } + } }; diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp index a64f90f2b50b..2610262b0f2c 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if HAS_SPI_TFT +#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI) #include "tft_spi.h" @@ -103,16 +103,21 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) { #if !PIN_EXISTS(TFT_MISO) return 0; #else - uint16_t d = 0; + uint8_t d = 0; + uint32_t data = 0; + SPIx.setClockDivider(SPI_CLOCK_DIV16); DataTransferBegin(DATASIZE_8BIT); WriteReg(Reg); - SPI.read((uint8_t*)&d, 1); //dummy read - SPI.read((uint8_t*)&d, 1); + LOOP_L_N(i, 4) { + SPIx.read((uint8_t*)&d, 1); + data = (data << 8) | d; + } DataTransferEnd(); + SPIx.setClockDivider(SPI_CLOCK_MAX); - return d >> 7; + return data >> 7; #endif } diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h index 1d1c9b444c8e..bb26fc21b64f 100644 --- a/Marlin/src/HAL/STM32F1/tft/tft_spi.h +++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h @@ -62,4 +62,11 @@ class TFT_SPI { static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); } static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); } + static void WriteMultiple(uint16_t Color, uint32_t Count) { + static uint16_t Data; Data = Color; + while (Count > 0) { + TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count); + Count = Count > 0xFFFF ? Count - 0xFFFF : 0; + } + } }; diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 277131289a3c..fa4f0cd9b1f6 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -252,7 +252,7 @@ #endif // Full Touch Screen needs 'tft/xpt2046' -#if ENABLED(TOUCH_SCREEN) +#if EITHER(TOUCH_SCREEN, HAS_TFT_LVGL_UI) #define HAS_TFT_XPT2046 1 #endif diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp index 0febc4edbddd..607090ba391d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp @@ -54,112 +54,27 @@ TFT SPI_TFT; // use SPI1 for the spi tft. void TFT::spi_init(uint8_t spiRate) { - - SPI_TFT_CS_H; - - /** - * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz - * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1 - * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2 - */ - uint8_t clock; - switch (spiRate) { - case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV4; break; - case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4; break; - case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break; - case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break; - case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break; - case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; - default: clock = SPI_CLOCK_DIV2; // Default from the SPI library - } - SPI.setModule(1); - SPI.begin(); - SPI.setClockDivider(clock); - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); -} - -uint8_t TFT::spi_Rec() { - uint8_t returnByte = SPI.transfer(ff); - return returnByte; -} - -uint8_t TFT::spi_read_write_byte(uint8_t data) { - uint8_t returnByte = SPI.transfer(data); - return returnByte; -} - -/** - * @brief Receive a number of bytes from the SPI port to a buffer - * - * @param buf Pointer to starting address of buffer to write to. - * @param nbyte Number of bytes to receive. - * @return Nothing - * - * @details Uses DMA - */ -void TFT::spi_Read(uint8_t* buf, uint16_t nbyte) {SPI.dmaTransfer(0, const_cast(buf), nbyte);} - -/** - * @brief Send a single byte on SPI port - * - * @param b Byte to send - * - * @details - */ -void TFT::spi_Send(uint8_t b) {SPI.send(b);} - -/** - * @brief Write token and then write from 512 byte buffer to SPI (for SD card) - * - * @param buf Pointer with buffer start address - * @return Nothing - * - * @details Use DMA - */ -void TFT::spi_SendBlock(uint8_t token, const uint8_t* buf) { - SPI.send(token); - SPI.dmaSend(const_cast(buf), 512); + tftio.Init(); } void TFT::LCD_WR_REG(uint8_t cmd) { - SPI_TFT_CS_L; - SPI_TFT_DC_L; - spi_Send(cmd); - SPI_TFT_CS_H; + tftio.WriteReg(cmd); } -void TFT::LCD_WR_DATA(uint8_t data) { - SPI_TFT_CS_L; - SPI_TFT_DC_H; - spi_Send(data); - SPI_TFT_CS_H; -} -void TFT::LCD_WriteRAM_Prepare() {LCD_WR_REG(0X2C);} -void TFT::SetCursor(uint16_t x, uint16_t y) { - LCD_WR_REG(0x2A); - LCD_WR_DATA(x >> 8); - LCD_WR_DATA(x); - LCD_WR_DATA(x >> 8); - LCD_WR_DATA(x); - LCD_WR_REG(0x2B); - LCD_WR_DATA(y >> 8); - LCD_WR_DATA(y); - LCD_WR_DATA(y >> 8); - LCD_WR_DATA(y); +void TFT::LCD_WR_DATA(uint8_t data) { + tftio.WriteData(data); } void TFT::SetPoint(uint16_t x, uint16_t y, uint16_t point) { if ((x > 480) || (y > 320)) return; - SetCursor(x, y); - - LCD_WriteRAM_Prepare(); - LCD_WR_DATA((uint8_t)(point >> 8)); - LCD_WR_DATA((uint8_t)point); + SetWindows(x, y, 1, 1); + tftio.WriteMultiple(point, (uint16_t)1); } void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { + tftio.DataTransferBegin(DATASIZE_8BIT); + LCD_WR_REG(0x2A); LCD_WR_DATA(x >> 8); LCD_WR_DATA(x); @@ -171,6 +86,10 @@ void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) { LCD_WR_DATA(y); LCD_WR_DATA((y + height - 1) >> 8); LCD_WR_DATA(y + height - 1); + + LCD_WR_REG(0X2C); + + tftio.DataTransferEnd(); } void TFT::LCD_init() { @@ -180,6 +99,8 @@ void TFT::LCD_init() { delay(150); SPI_TFT_RST_H; + tftio.DataTransferBegin(DATASIZE_8BIT); + delay(120); LCD_WR_REG(0x11); delay(120); @@ -251,6 +172,8 @@ void TFT::LCD_init() { delay(120); // Delay 120ms LCD_WR_REG(0x29); // Display ON + tftio.DataTransferEnd(); + LCD_clear(0x0000); // LCD_Draw_Logo(); SPI_TFT_BLK_H; @@ -258,81 +181,18 @@ void TFT::LCD_init() { } void TFT::LCD_clear(uint16_t color) { - unsigned int i; - uint8_t tbuf[960]; - - SetCursor(0, 0); - SetWindows(0, 0, 480 - 1, 320 - 1); - LCD_WriteRAM_Prepare(); - SPI_TFT_CS_L; - SPI_TFT_DC_H; - for (i = 0; i < 960;) { - tbuf[i] = color >> 8; - tbuf[i + 1] = color; - i += 2; - } - for (i = 0; i < 320; i++) { - // for (m=0;m<480;m++) - // { - // LCD_WR_DATA(color>>8); - // LCD_WR_DATA(color); - SPI.dmaSend(tbuf, 960, true); - // SPI_TFT_CS_H; - // } - } - SPI_TFT_CS_H; + SetWindows(0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1); + tftio.WriteMultiple(color, (uint32_t)(LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT)); } extern unsigned char bmp_public_buf[17 * 1024]; void TFT::LCD_Draw_Logo() { - uint16_t i,y_off = 0; - uint16_t *p_index; - uint16_t Color; - - #if 1 - for (y_off = 0; y_off < 320; y_off ++) { - Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, 960); - - SPI_TFT.spi_init(SPI_FULL_SPEED); - SetWindows(0, y_off, 480, 1); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (i = 0; i < 960;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i+=2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf,960,true); - SPI_TFT_CS_H; - } - - #else - - for (index = 0; index < 40; index ++) { - Pic_Logo_Read((uint8_t *)"", bmp_public_buf, 480*8*2); - i = 0; - SetCursor(0,0); - SetWindows(0, y_off * 8, 480, 8); - LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ - for (i = 0; i < 480 * 8 * 2;) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i += 2; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf,480*8*2,true); - SPI_TFT_CS_H; - - y_off++; - } - #endif - - SetWindows(0, 0, 479, 319); + SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT); + for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT); i ++) { + Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (LCD_FULL_PIXEL_WIDTH) * 2); + tftio.WriteSequence((uint16_t *)bmp_public_buf, LCD_FULL_PIXEL_WIDTH); + } } #endif // HAS_TFT_LVGL_UI_SPI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h index 9b676843139c..c4b04e1c2183 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h @@ -21,13 +21,13 @@ */ #pragma once -#include +#include "../../inc/MarlinConfigPre.h" -#define SPI_TFT_CS_H OUT_WRITE(SPI_TFT_CS_PIN, HIGH) -#define SPI_TFT_CS_L OUT_WRITE(SPI_TFT_CS_PIN, LOW) - -#define SPI_TFT_DC_H OUT_WRITE(SPI_TFT_DC_PIN, HIGH) -#define SPI_TFT_DC_L OUT_WRITE(SPI_TFT_DC_PIN, LOW) +#if ENABLED(TFT_LVGL_UI_SPI) + #include HAL_PATH(../../HAL, tft/tft_spi.h) +#elif ENABLED(TFT_LVGL_UI_FSMC) + #include HAL_PATH(../../HAL, tft/tft_fsmc.h) +#endif #define SPI_TFT_RST_H OUT_WRITE(SPI_TFT_RST_PIN, HIGH) #define SPI_TFT_RST_L OUT_WRITE(SPI_TFT_RST_PIN, LOW) @@ -37,20 +37,14 @@ class TFT { public: + TFT_IO tftio; void spi_init(uint8_t spiRate); - uint8_t spi_Rec(); - uint8_t spi_read_write_byte(uint8_t data); - void spi_Read(uint8_t* buf, uint16_t nbyte); - void spi_Send(uint8_t b); - void spi_SendBlock(uint8_t token, const uint8_t* buf); void LCD_WR_REG(uint8_t cmd); void LCD_WR_DATA(uint8_t data); - void SetCursor(uint16_t x, uint16_t y); void SetPoint(uint16_t x, uint16_t y, uint16_t point); void SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height); void LCD_init(); void LCD_clear(uint16_t color); - void LCD_WriteRAM_Prepare(); void LCD_Draw_Logo(); }; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp index 9ef27afc9ba6..aad5e4362e38 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp @@ -51,6 +51,8 @@ #endif #include "../../../../gcode/gcode.h" +#include "pic_manager.h" + static lv_obj_t * scr; extern uint8_t sel_id; extern uint8_t once_flag; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp index 5d87eb9f8736..dc5e4910e939 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp @@ -500,14 +500,9 @@ char *creat_title_text() { } } - //SERIAL_ECHOLNPAIR("gPicturePreviewStart: ", gPicturePreviewStart, " PREVIEW_LITTLE_PIC_SIZE: ", PREVIEW_LITTLE_PIC_SIZE); - card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8); #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetCursor(0,0); SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); #else ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -525,19 +520,11 @@ char *creat_title_text() { if (j >= 400) break; } #if ENABLED(TFT_LVGL_UI_SPI) - uint16_t Color, SpiColor; - SpiColor = (LV_COLOR_BACKGROUND.full >> 8) | ((LV_COLOR_BACKGROUND.full & 0xFF) << 8); - for (i = 0; i < 400;) { + for (i = 0; i < 400; i += 2) { p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xFF) << 8); - i += 2; - if (*p_index == 0x0000) *p_index = SpiColor; + if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(bmp_public_buf, 400, true); - SPI_TFT_CS_H; + SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200); #else for (i = 0; i < 400;) { p_index = (uint16_t *)(&bmp_public_buf[i]); @@ -627,10 +614,7 @@ char *creat_title_text() { card.setIndex((PREVIEW_LITTLE_PIC_SIZE + To_pre_view) + size * row + 8); #if ENABLED(TFT_LVGL_UI_SPI) - SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetCursor(0,0); SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); #else ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1); LCD_WriteRAM_Prepare(); @@ -750,9 +734,6 @@ char *creat_title_text() { void Draw_default_preview(int xpos_pixel, int ypos_pixel, uint8_t sel) { int index; int y_off = 0; - int _y; - uint16_t *p_index; - int i; for (index = 0; index < 10; index++) { // 200*200 #if HAS_BAK_VIEW_IN_FLASH @@ -761,58 +742,24 @@ char *creat_title_text() { } else { default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k - #if ENABLED(TFT_LVGL_UI_SPI) - uint16_t Color; - for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xff) << 8); - i += 2; - } - #endif } #else default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k - #if ENABLED(TFT_LVGL_UI_SPI) - for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) { - p_index = (uint16_t *)(&bmp_public_buf[i]); - Color = (*p_index >> 8); - *p_index = Color | ((*p_index & 0xff) << 8); - i += 2; - } - #endif #endif - i = 0; #if ENABLED(TFT_LVGL_UI_SPI) - - //SPI_TFT.spi_init(SPI_FULL_SPEED); - //SPI_TFT.SetWindows(xpos_pixel, y_off * 20+ypos_pixel, 200,20); //200*200 - //SPI_TFT.LCD_WriteRAM_Prepare(); - int j = 0; - for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) { - SPI_TFT.spi_init(SPI_FULL_SPEED); - SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel + j, 200, 1); // 200*200 - SPI_TFT.LCD_WriteRAM_Prepare(); - - j++; - //memcpy(public_buf,&bmp_public_buf[i],400); - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(&bmp_public_buf[i], 400, true); - SPI_TFT_CS_H; - - i += 400; - if (i >= 8000) break; - } + SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 + SPI_TFT.tftio.WriteSequence((uint16_t*)(bmp_public_buf), DEFAULT_VIEW_MAX_SIZE / 20); #else int x_off = 0; uint16_t temp_p; + int i = 0; + uint16_t *p_index; ili9320_SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200 LCD_WriteRAM_Prepare(); - for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) { + for (int _y = y_off * 20; _y < (y_off + 1) * 20; _y++) { for (x_off = 0; x_off < 200; x_off++) { if (sel == 1) { temp_p = (uint16_t)(bmp_public_buf[i] | bmp_public_buf[i + 1] << 8); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp index a35ae29701fb..a2795e933bcf 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp @@ -590,8 +590,6 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1 } void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor) { - // Select TFT SPI so it can receive data - TERN_(TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED)); while (*string != '\0') { disp_char_1624(x, y, *string, charColor, bkColor); string++; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp index a257d03489cd..62967b9d8061 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp @@ -22,249 +22,39 @@ #include "../../../../inc/MarlinConfig.h" -#if HAS_TFT_LVGL_UI - -#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs - - #include - #include - #include - #include - - /* Timing configuration */ - #define FSMC_ADDRESS_SETUP_TIME 15// AddressSetupTime - #define FSMC_DATA_SETUP_TIME 15// DataSetupTime - - void LCD_IO_Init(uint8_t cs, uint8_t rs); - void LCD_IO_WriteData(uint16_t RegValue); - void LCD_IO_WriteReg(uint16_t Reg); - uint16_t LCD_IO_ReadData(uint16_t RegValue); - uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize); - uint16_t ILI9488_ReadRAM(); - #ifdef LCD_USE_DMA_FSMC - void LCD_IO_WriteMultiple(uint16_t data, uint32_t count); - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); - #endif - - /** - * FSMC LCD IO - */ - #define __ASM __asm - #define __STATIC_INLINE static inline - - __attribute__((always_inline)) __STATIC_INLINE void __DSB() {__ASM volatile ("dsb 0xF" ::: "memory");} - - #define FSMC_CS_NE1 PD7 - - #if ENABLED(STM32_XL_DENSITY) - #define FSMC_CS_NE2 PG9 - #define FSMC_CS_NE3 PG10 - #define FSMC_CS_NE4 PG12 - - #define FSMC_RS_A0 PF0 - #define FSMC_RS_A1 PF1 - #define FSMC_RS_A2 PF2 - #define FSMC_RS_A3 PF3 - #define FSMC_RS_A4 PF4 - #define FSMC_RS_A5 PF5 - #define FSMC_RS_A6 PF12 - #define FSMC_RS_A7 PF13 - #define FSMC_RS_A8 PF14 - #define FSMC_RS_A9 PF15 - #define FSMC_RS_A10 PG0 - #define FSMC_RS_A11 PG1 - #define FSMC_RS_A12 PG2 - #define FSMC_RS_A13 PG3 - #define FSMC_RS_A14 PG4 - #define FSMC_RS_A15 PG5 - #endif - - #define FSMC_RS_A16 PD11 - #define FSMC_RS_A17 PD12 - #define FSMC_RS_A18 PD13 - #define FSMC_RS_A19 PE3 - #define FSMC_RS_A20 PE4 - #define FSMC_RS_A21 PE5 - #define FSMC_RS_A22 PE6 - #define FSMC_RS_A23 PE2 - - #if ENABLED(STM32_XL_DENSITY) - #define FSMC_RS_A24 PG13 - #define FSMC_RS_A25 PG14 - #endif - - static uint8_t fsmcInit = 0; - - typedef struct { - __IO uint16_t REG; - __IO uint16_t RAM; - } LCD_CONTROLLER_TypeDef; - - LCD_CONTROLLER_TypeDef *LCD; - - void LCD_IO_Init(uint8_t cs, uint8_t rs) { - uint32_t controllerAddress; - struct fsmc_nor_psram_reg_map* fsmcPsramRegion; - - if (fsmcInit) return; - fsmcInit = 1; - - switch (cs) { - case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; fsmcPsramRegion = FSMC_NOR_PSRAM1_BASE; break; - #if ENABLED(STM32_XL_DENSITY) - case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; fsmcPsramRegion = FSMC_NOR_PSRAM2_BASE; break; - case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; fsmcPsramRegion = FSMC_NOR_PSRAM3_BASE; break; - case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; fsmcPsramRegion = FSMC_NOR_PSRAM4_BASE; break; - #endif - default: return; - } - - #define _ORADDR(N) controllerAddress |= (_BV32(N) - 2) - - switch (rs) { - #if ENABLED(STM32_XL_DENSITY) - case FSMC_RS_A0: _ORADDR( 1); break; - case FSMC_RS_A1: _ORADDR( 2); break; - case FSMC_RS_A2: _ORADDR( 3); break; - case FSMC_RS_A3: _ORADDR( 4); break; - case FSMC_RS_A4: _ORADDR( 5); break; - case FSMC_RS_A5: _ORADDR( 6); break; - case FSMC_RS_A6: _ORADDR( 7); break; - case FSMC_RS_A7: _ORADDR( 8); break; - case FSMC_RS_A8: _ORADDR( 9); break; - case FSMC_RS_A9: _ORADDR(10); break; - case FSMC_RS_A10: _ORADDR(11); break; - case FSMC_RS_A11: _ORADDR(12); break; - case FSMC_RS_A12: _ORADDR(13); break; - case FSMC_RS_A13: _ORADDR(14); break; - case FSMC_RS_A14: _ORADDR(15); break; - case FSMC_RS_A15: _ORADDR(16); break; - #endif - case FSMC_RS_A16: _ORADDR(17); break; - case FSMC_RS_A17: _ORADDR(18); break; - case FSMC_RS_A18: _ORADDR(19); break; - case FSMC_RS_A19: _ORADDR(20); break; - case FSMC_RS_A20: _ORADDR(21); break; - case FSMC_RS_A21: _ORADDR(22); break; - case FSMC_RS_A22: _ORADDR(23); break; - case FSMC_RS_A23: _ORADDR(24); break; - #if ENABLED(STM32_XL_DENSITY) - case FSMC_RS_A24: _ORADDR(25); break; - case FSMC_RS_A25: _ORADDR(26); break; - #endif - default: return; - } - - rcc_clk_enable(RCC_FSMC); - - gpio_set_mode(GPIOD, 14, GPIO_AF_OUTPUT_PP); // FSMC_D00 - gpio_set_mode(GPIOD, 15, GPIO_AF_OUTPUT_PP); // FSMC_D01 - gpio_set_mode(GPIOD, 0, GPIO_AF_OUTPUT_PP);// FSMC_D02 - gpio_set_mode(GPIOD, 1, GPIO_AF_OUTPUT_PP);// FSMC_D03 - gpio_set_mode(GPIOE, 7, GPIO_AF_OUTPUT_PP);// FSMC_D04 - gpio_set_mode(GPIOE, 8, GPIO_AF_OUTPUT_PP);// FSMC_D05 - gpio_set_mode(GPIOE, 9, GPIO_AF_OUTPUT_PP);// FSMC_D06 - gpio_set_mode(GPIOE, 10, GPIO_AF_OUTPUT_PP); // FSMC_D07 - gpio_set_mode(GPIOE, 11, GPIO_AF_OUTPUT_PP); // FSMC_D08 - gpio_set_mode(GPIOE, 12, GPIO_AF_OUTPUT_PP); // FSMC_D09 - gpio_set_mode(GPIOE, 13, GPIO_AF_OUTPUT_PP); // FSMC_D10 - gpio_set_mode(GPIOE, 14, GPIO_AF_OUTPUT_PP); // FSMC_D11 - gpio_set_mode(GPIOE, 15, GPIO_AF_OUTPUT_PP); // FSMC_D12 - gpio_set_mode(GPIOD, 8, GPIO_AF_OUTPUT_PP);// FSMC_D13 - gpio_set_mode(GPIOD, 9, GPIO_AF_OUTPUT_PP);// FSMC_D14 - gpio_set_mode(GPIOD, 10, GPIO_AF_OUTPUT_PP); // FSMC_D15 - - gpio_set_mode(GPIOD, 4, GPIO_AF_OUTPUT_PP);// FSMC_NOE - gpio_set_mode(GPIOD, 5, GPIO_AF_OUTPUT_PP);// FSMC_NWE - - gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_CS_NEx - gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_RS_Ax - - fsmcPsramRegion->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN; - fsmcPsramRegion->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME; - - afio_remap(AFIO_REMAP_FSMC_NADV); - - LCD = (LCD_CONTROLLER_TypeDef*)controllerAddress; - } - - void LCD_IO_WriteData(uint16_t RegValue) { - LCD->RAM = RegValue; - __DSB(); - } - - void LCD_IO_WriteReg(uint16_t Reg) { - LCD->REG = Reg; - __DSB(); - } - - uint16_t LCD_IO_ReadData(uint16_t RegValue) { - LCD->REG = RegValue; - __DSB(); - - return LCD->RAM; +#if ENABLED(TFT_LVGL_UI_FSMC) + +#include HAL_PATH(../../HAL, tft/tft_fsmc.h) +TFT_IO tftio; + +void LCD_IO_Init(uint8_t cs, uint8_t rs); +void LCD_IO_WriteData(uint16_t RegValue); +void LCD_IO_WriteReg(uint16_t Reg); +#ifdef LCD_USE_DMA_FSMC + void LCD_IO_WriteMultiple(uint16_t data, uint32_t count); + void LCD_IO_WriteSequence(uint16_t *data, uint16_t length); +#endif + +void LCD_IO_Init(uint8_t cs, uint8_t rs) { + tftio.Init(); +} + +void LCD_IO_WriteData(uint16_t RegValue) { + tftio.WriteData(RegValue); +} + +void LCD_IO_WriteReg(uint16_t Reg) { + tftio.WriteReg(Reg); +} + +#ifdef LCD_USE_DMA_FSMC + void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) { + tftio.WriteMultiple(color, count); } - uint16_t ILI9488_ReadRAM() { - uint16_t data; - data = LCD->RAM; - return data; + void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { + tftio.WriteSequence(data, length); } +#endif // LCD_USE_DMA_FSMC - uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) { - volatile uint32_t data; - LCD->REG = RegValue; - __DSB(); - - data = LCD->RAM; // dummy read - data = LCD->RAM & 0x00FF; - - while (--ReadSize) { - data <<= 8; - data |= (LCD->RAM & 0x00FF); - } - return uint32_t(data); - } - - #ifdef LCD_USE_DMA_FSMC - - void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) { - while (count > 0) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {} - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - count = count > 65535 ? count - 65535 : 0; - } - } - - void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {} - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - } - - void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) { - dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE); - dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length); - dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - } - - void LCD_IO_WaitSequence_Async() { - while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {} - dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL); - } - - #endif // LCD_USE_DMA_FSMC - -#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN #endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp index 81b50a101871..391e12ba3fc7 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp @@ -42,9 +42,8 @@ #include "../../../../inc/MarlinConfig.h" -#if HAS_TOUCH_XPT2046 - #include "../../../touch/xpt2046.h" -#endif +#include HAL_PATH(../../HAL, tft/xpt2046.h) +XPT2046 touch; #if ENABLED(POWER_LOSS_RECOVERY) #include "../../../../feature/powerloss.h" @@ -121,14 +120,14 @@ void tft_set_cursor(uint16_t x, uint16_t y) { void LCD_WriteRAM_Prepare(void) { #if 0 - if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x8989)) { - ClrCs - LCD->LCD_REG = R34; - SetCs - } - else { - LCD_WrtReg(0x002C); - } + switch (DeviceCode) { + case 0x9325: case 0x9328: case 0x8989: { + ClrCs + LCD->LCD_REG = R34; + SetCs + } break; + default: LCD_WrtReg(0x002C); + } #else LCD_IO_WriteReg(0x002C); #endif @@ -197,8 +196,8 @@ void ili9320_SetWindows(uint16_t StartX, uint16_t StartY, uint16_t width, uint16 LCD_WriteReg(0x0053, yEnd);*/ LCD_WriteReg(0x0050, StartY); // Specify the start/end positions of the window address in the horizontal direction by an address unit LCD_WriteReg(0x0051, yEnd); // Specify the start positions of the window address in the vertical direction by an address unit - LCD_WriteReg(0x0052, 320 - xEnd); - LCD_WriteReg(0x0053, 320 - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit + LCD_WriteReg(0x0052, (LCD_FULL_PIXEL_HEIGHT) - xEnd); + LCD_WriteReg(0x0053, (LCD_FULL_PIXEL_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit } else { @@ -268,28 +267,10 @@ void LCD_Clear(uint16_t Color) { } } -extern uint16_t ILI9488_ReadRAM(); - +#include HAL_PATH(../../HAL, tft/tft_fsmc.h) +extern TFT_IO tftio; void init_tft() { uint16_t i; - //************* Start Initial Sequence **********// - - //start lcd pins and dma - #if PIN_EXISTS(LCD_BACKLIGHT) - OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away - #endif - - #if PIN_EXISTS(LCD_RESET) - // Perform a clean hardware reset with needed delays - OUT_WRITE(LCD_RESET_PIN, LOW); - _delay_ms(5); - WRITE(LCD_RESET_PIN, HIGH); - _delay_ms(5); - #endif - - #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT) - WRITE(LCD_BACKLIGHT_PIN, HIGH); - #endif TERN_(HAS_LCD_CONTRAST, refresh_contrast()); @@ -303,12 +284,9 @@ void init_tft() { _delay_ms(5); - LCD_IO_WriteReg(0x00D3); - DeviceCode = ILI9488_ReadRAM(); //dummy read - DeviceCode = ILI9488_ReadRAM(); - DeviceCode = ILI9488_ReadRAM(); - DeviceCode <<= 8; - DeviceCode |= ILI9488_ReadRAM(); + DeviceCode = tftio.GetID() & 0xFFFF; + // Chitu and others + if (DeviceCode == 0x8066) DeviceCode = 0x9488; if (DeviceCode == 0x9488) { LCD_IO_WriteReg(0x00E0); @@ -436,7 +414,7 @@ void tft_lvgl_init() { //spi_flash_read_test(); - TERN_(HAS_TOUCH_XPT2046, touch.init()); + touch.Init(); lv_init(); @@ -492,35 +470,14 @@ void tft_lvgl_init() { void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { #if ENABLED(TFT_LVGL_UI_SPI) uint16_t i, width, height; - uint16_t clr_temp; - uint8_t tbuf[(LCD_FULL_PIXEL_WIDTH) * 2]; - - SPI_TFT.spi_init(SPI_FULL_SPEED); width = area->x2 - area->x1 + 1; height = area->y2 - area->y1 + 1; - for (int j = 0; j < height; j++) { - SPI_TFT.SetCursor(0, 0); - SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1 + j, width, 1); - SPI_TFT.LCD_WriteRAM_Prepare(); - - for (i = 0; i < width * 2;) { - clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11) - | ((uint16_t)color_p->ch.green << 5) - | ((uint16_t)color_p->ch.blue)); - - tbuf[i] = clr_temp >> 8; - tbuf[i + 1] = clr_temp; - i += 2; - color_p++; - } - SPI_TFT_CS_L; - SPI_TFT_DC_H; - SPI.dmaSend(tbuf, width * 2, true); - SPI_TFT_CS_H; + SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1, width, height); + for (i = 0; i < height; i++) { + SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width); } - lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ W25QXX.init(SPI_QUARTER_SPEED); @@ -556,174 +513,23 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) { return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick)); } -#if ENABLED(TFT_LVGL_UI_SPI) - - #ifndef USE_XPT2046 - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 1 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - #endif - - #if USE_XPT2046 - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 201 - #define XPT2046_Y_MIN 164 - #define XPT2046_X_MAX 3919 - #define XPT2046_Y_MAX 3776 - #define XPT2046_AVG 4 - #define XPT2046_INV 1 - #endif - -#else - - #ifndef USE_XPT2046 - #define USE_XPT2046 1 - #ifndef XPT2046_XY_SWAP - #define XPT2046_XY_SWAP 1 - #endif - #ifndef XPT2046_X_INV - #define XPT2046_X_INV 0 - #endif - #ifndef XPT2046_Y_INV - #define XPT2046_Y_INV 1 - #endif - #endif - - #if USE_XPT2046 - #ifndef XPT2046_HOR_RES - #define XPT2046_HOR_RES 480 - #endif - #ifndef XPT2046_VER_RES - #define XPT2046_VER_RES 320 - #endif - #ifndef XPT2046_X_MIN - #define XPT2046_X_MIN 201 - #endif - #ifndef XPT2046_Y_MIN - #define XPT2046_Y_MIN 164 - #endif - #ifndef XPT2046_X_MAX - #define XPT2046_X_MAX 3919 - #endif - #ifndef XPT2046_Y_MAX - #define XPT2046_Y_MAX 3776 - #endif - #ifndef XPT2046_AVG - #define XPT2046_AVG 4 - #endif - #ifndef XPT2046_INV - #define XPT2046_INV 0 - #endif - #endif - -#endif - -static void xpt2046_corr(uint16_t *x, uint16_t *y) { - #if XPT2046_XY_SWAP - int16_t swap_tmp; - swap_tmp = *x; - *x = *y; - *y = swap_tmp; - #endif - if ((*x) > XPT2046_X_MIN) (*x) -= XPT2046_X_MIN; else (*x) = 0; - if ((*y) > XPT2046_Y_MIN) (*y) -= XPT2046_Y_MIN; else (*y) = 0; - (*x) = uint32_t(uint32_t(*x) * XPT2046_HOR_RES) / (XPT2046_X_MAX - XPT2046_X_MIN); - (*y) = uint32_t(uint32_t(*y) * XPT2046_VER_RES) / (XPT2046_Y_MAX - XPT2046_Y_MIN); - #if XPT2046_X_INV - (*x) = XPT2046_HOR_RES - (*x); - #endif - #if XPT2046_Y_INV - (*y) = XPT2046_VER_RES - (*y); - #endif -} - -#define times 4 -#define CHX 0x90 -#define CHY 0xD0 - -int SPI2_ReadWrite2Bytes(void) { - #define SPI_READ_WRITE_BYTE(B) TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_read_write_byte, W25QXX.spi_flash_read_write_byte)(B) - const uint16_t t1 = SPI_READ_WRITE_BYTE(0xFF), - t2 = SPI_READ_WRITE_BYTE(0xFF); - return (((t1 << 8) | t2) >> 3) & 0x0FFF; -} +static bool get_point(int16_t *x, int16_t *y) { + bool is_touched = touch.getRawPoint(x, y); -uint16_t x_addata[times], y_addata[times]; -void XPT2046_Rd_Addata(uint16_t *X_Addata, uint16_t *Y_Addata) { - uint16_t i, j, k; - - TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_init, W25QXX.init)(SPI_SPEED_6); - - for (i = 0; i < times; i++) { - #if ENABLED(TFT_LVGL_UI_SPI) - OUT_WRITE(TOUCH_CS_PIN, LOW); - SPI_TFT.spi_read_write_byte(CHX); - y_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - - OUT_WRITE(TOUCH_CS_PIN, LOW); - SPI_TFT.spi_read_write_byte(CHY); - x_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - #else // #if HAS_TOUCH_XPT2046 - OUT_WRITE(TOUCH_CS_PIN, LOW); - W25QXX.spi_flash_read_write_byte(CHX); - y_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - - OUT_WRITE(TOUCH_CS_PIN, LOW); - W25QXX.spi_flash_read_write_byte(CHY); - x_addata[i] = SPI2_ReadWrite2Bytes(); - WRITE(TOUCH_CS_PIN, HIGH); - #endif - - } - TERN(TFT_LVGL_UI_SPI,,W25QXX.init(SPI_QUARTER_SPEED)); - - for (i = 0; i < times; i++) - for (j = i + 1; j < times; j++) - if (x_addata[j] > x_addata[i]) { - k = x_addata[j]; - x_addata[j] = x_addata[i]; - x_addata[i] = k; - } - if (x_addata[times / 2 - 1] - x_addata[times / 2] > 50) { - *X_Addata = *Y_Addata = 0; - return; - } - - *X_Addata = (x_addata[times / 2 - 1] + x_addata[times / 2]) / 2; - - for (i = 0; i < times; i++) - for (j = i + 1; j < times; j++) - if (y_addata[j] > y_addata[i]) { - k = y_addata[j]; - y_addata[j] = y_addata[i]; - y_addata[i] = k; - } - - if (y_addata[times / 2 - 1] - y_addata[times / 2] > 50) { - *X_Addata = *Y_Addata = 0; - return; + if (is_touched) { + *x = int16_t((int32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET; + *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; } - *Y_Addata = (y_addata[times / 2 - 1] + y_addata[times / 2]) / 2; -} - -#define ADC_VALID_OFFSET 10 + #if ENABLED(GRAPHICAL_TFT_ROTATE_180) + x = (LCD_FULL_PIXEL_WIDTH) - x; + y = (LCD_FULL_PIXEL_HEIGHT) - y; + #endif -uint8_t TOUCH_PressValid(uint16_t _usX, uint16_t _usY) { - if ( (_usX <= ADC_VALID_OFFSET) - || (_usY <= ADC_VALID_OFFSET) - || (_usX >= 4095 - ADC_VALID_OFFSET) - || (_usY >= 4095 - ADC_VALID_OFFSET) - ) return 0; - return 1; + return is_touched; } -static lv_coord_t last_x = 0, last_y = 0; +static int16_t last_x = 0, last_y = 0; bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { uint32_t tmpTime, diffTime = 0; @@ -735,34 +541,24 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) { //touchpad_get_xy(&last_x, &last_y); /*Save the pressed coordinates and the state*/ if (diffTime > 10) { - //use marlin touch code if enabled - #if HAS_TOUCH_XPT2046 - touch.getTouchPoint(reinterpret_cast(last_x), reinterpret_cast(last_y)); - #else - XPT2046_Rd_Addata((uint16_t *)&last_x, (uint16_t *)&last_y); - #endif - if (TOUCH_PressValid(last_x, last_y)) { + if (get_point(&last_x, &last_y)) { data->state = LV_INDEV_STATE_PR; - /* Set the coordinates (if released use the last pressed coordinates) */ + // Set the coordinates (if released use the last-pressed coordinates) - // SERIAL_ECHOLNPAIR("antes X: ", last_x, ", y: ", last_y); - xpt2046_corr((uint16_t *)&last_x, (uint16_t *)&last_y); - // SERIAL_ECHOLNPAIR("X: ", last_x, ", y: ", last_y); data->point.x = last_x; data->point.y = last_y; - last_x = 0; - last_y = 0; + last_x = last_y = 0; } - else { + else data->state = LV_INDEV_STATE_REL; - } + touch_time1 = tmpTime; } - return false; /*Return `false` because we are not buffering and no more data to read*/ + return false; // Return `false` since no data is buffering or left to read } #endif // HAS_TFT_LVGL_UI diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index 6be67fc1a263..e4f0014417b1 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -164,7 +164,6 @@ #define HAS_LANG_SELECT_SCREEN 1 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 - #define HAS_TOUCH_XPT2046 1 #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK @@ -183,6 +182,8 @@ #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 + #define TFT_RESET_PIN PF11 + #define TFT_BACKLIGHT_PIN PD13 #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT #define FSMC_CS_PIN PD7 @@ -197,24 +198,10 @@ #define LCD_PIXEL_OFFSET_X 48 #define LCD_PIXEL_OFFSET_Y 48 - #define XPT2046_X_CALIBRATION -12316 - #define XPT2046_Y_CALIBRATION 8981 - #define XPT2046_X_OFFSET 340 - #define XPT2046_Y_OFFSET -20 - - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 0 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 140 - #define XPT2046_Y_MIN 200 - #define XPT2046_X_MAX 1900 - #define XPT2046_Y_MAX 1900 - #define XPT2046_AVG 4 - #define XPT2046_INV 0 + #define XPT2046_X_CALIBRATION -17181 + #define XPT2046_Y_CALIBRATION 11434 + #define XPT2046_X_OFFSET 501 + #define XPT2046_Y_OFFSET -9 #elif ENABLED(TFT_480x320) #define TFT_RESET_PIN PF11 diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 4633de40f2a5..3d36de82424f 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -198,7 +198,6 @@ #define HAS_LANG_SELECT_SCREEN 0 #define HAS_BAK_VIEW_IN_FLASH 0 #define HAS_LOGO_IN_FLASH 0 - #define HAS_TOUCH_XPT2046 1 #define TOUCH_CS_PIN PB7 // SPI1_NSS #define TOUCH_SCK_PIN PA5 // SPI1_SCK @@ -217,6 +216,8 @@ #define LCD_RESET_PIN PF11 #define LCD_BACKLIGHT_PIN PD13 + #define TFT_RESET_PIN PF11 + #define TFT_BACKLIGHT_PIN PD13 #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT #define FSMC_CS_PIN PD7 @@ -231,24 +232,10 @@ #define LCD_PIXEL_OFFSET_X 48 #define LCD_PIXEL_OFFSET_Y 48 - #define XPT2046_X_CALIBRATION -12316 - #define XPT2046_Y_CALIBRATION 8981 - #define XPT2046_X_OFFSET 340 - #define XPT2046_Y_OFFSET -20 - - #define USE_XPT2046 1 - #define XPT2046_XY_SWAP 0 - #define XPT2046_X_INV 1 - #define XPT2046_Y_INV 0 - - #define XPT2046_HOR_RES 480 - #define XPT2046_VER_RES 320 - #define XPT2046_X_MIN 140 - #define XPT2046_Y_MIN 200 - #define XPT2046_X_MAX 1900 - #define XPT2046_Y_MAX 1900 - #define XPT2046_AVG 4 - #define XPT2046_INV 0 + #define XPT2046_X_CALIBRATION -17181 + #define XPT2046_Y_CALIBRATION 11434 + #define XPT2046_X_OFFSET 501 + #define XPT2046_Y_OFFSET -9 #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index 16040643520b..948663f6f059 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -177,6 +177,17 @@ #define LCD_BACKLIGHT_PIN PD13 + #define XPT2046_X_CALIBRATION 17880 + #define XPT2046_Y_CALIBRATION -12234 + #define XPT2046_X_OFFSET -45 + #define XPT2046_Y_OFFSET 349 + + #define LCD_USE_DMA_FSMC // Use DMA transfers to send data to the TFT + #define FSMC_CS_PIN PD7 + #define FSMC_RS_PIN PD11 + #define FSMC_DMA_DEV DMA2 + #define FSMC_DMA_CHANNEL DMA_CH5 + #elif ENABLED(FSMC_GRAPHICAL_TFT) #define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index be363e45374b..feac729c73b2 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -261,17 +261,30 @@ #define BTN_EN2 PE11 #define BTN_ENC PE13 -#elif ENABLED(TFT_LITTLE_VGL_UI) - - #define FSMC_CS_PIN PD7 // NE4 - #define FSMC_RS_PIN PD11 // A0 - - #define TOUCH_CS_PIN PA7 // SPI2_NSS - #define TOUCH_SCK_PIN PB13 // SPI2_SCK - #define TOUCH_MISO_PIN PB14 // SPI2_MISO - #define TOUCH_MOSI_PIN PB15 // SPI2_MOSI - - #define LCD_BACKLIGHT_PIN PD13 + #define TFT_CS_PIN PD11 + #define TFT_SCK_PIN PA5 + #define TFT_MISO_PIN PA6 + #define TFT_MOSI_PIN PA7 + #define TFT_DC_PIN PD10 + #define TFT_RST_PIN PC6 + #define TFT_A0_PIN TFT_DC_PIN + + #define TFT_RESET_PIN PC6 + #define TFT_BACKLIGHT_PIN PD13 + + #define XPT2046_X_CALIBRATION -17253 + #define XPT2046_Y_CALIBRATION 11579 + #define XPT2046_X_OFFSET 514 + #define XPT2046_Y_OFFSET -24 + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + + #ifndef LCD_FULL_PIXEL_WIDTH + #define LCD_FULL_PIXEL_WIDTH 480 + #endif + #ifndef LCD_FULL_PIXEL_HEIGHT + #define LCD_FULL_PIXEL_HEIGHT 320 + #endif #endif