Browse Source

MKS Robin Nano v3 + TFT_LVGL_UI + WiFi module (#22109)

vanilla_fb_2.0.x
MKS-Sean 3 years ago
committed by Scott Lahteine
parent
commit
cad2f69687
  1. 8
      Marlin/src/HAL/STM32/HAL.cpp
  2. 2
      Marlin/src/HAL/STM32/HAL_MinSerial.cpp
  3. 4
      Marlin/src/HAL/STM32/HAL_SPI.cpp
  4. 4
      Marlin/src/HAL/STM32/MarlinSPI.cpp
  5. 4
      Marlin/src/HAL/STM32/MarlinSerial.cpp
  6. 4
      Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
  7. 4
      Marlin/src/HAL/STM32/Servo.cpp
  8. 4
      Marlin/src/HAL/STM32/eeprom_flash.cpp
  9. 4
      Marlin/src/HAL/STM32/eeprom_sdcard.cpp
  10. 4
      Marlin/src/HAL/STM32/eeprom_sram.cpp
  11. 4
      Marlin/src/HAL/STM32/eeprom_wired.cpp
  12. 4
      Marlin/src/HAL/STM32/fast_pwm.cpp
  13. 4
      Marlin/src/HAL/STM32/fastio.cpp
  14. 14
      Marlin/src/HAL/STM32/msc_sd.cpp
  15. 4
      Marlin/src/HAL/STM32/tft/gt911.cpp
  16. 4
      Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
  17. 4
      Marlin/src/HAL/STM32/tft/tft_ltdc.cpp
  18. 4
      Marlin/src/HAL/STM32/tft/tft_spi.cpp
  19. 4
      Marlin/src/HAL/STM32/tft/xpt2046.cpp
  20. 4
      Marlin/src/HAL/STM32/timers.cpp
  21. 4
      Marlin/src/HAL/STM32/usb_host.cpp
  22. 4
      Marlin/src/HAL/STM32/usb_serial.cpp
  23. 4
      Marlin/src/HAL/STM32/watchdog.cpp
  24. 7
      Marlin/src/HAL/STM32F1/msc_sd.cpp
  25. 7
      Marlin/src/MarlinCore.cpp
  26. 2
      Marlin/src/core/macros.h
  27. 2
      Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/compat.h
  28. 28
      Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp
  29. 5
      Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp
  30. 4
      Marlin/src/lcd/extui/mks_ui/draw_printing.cpp
  31. 112
      Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp
  32. 34
      Marlin/src/lcd/extui/mks_ui/draw_ui.cpp
  33. 10
      Marlin/src/lcd/extui/mks_ui/irq_overrid.cpp
  34. 140
      Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp
  35. 6
      Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h
  36. 5
      Marlin/src/lcd/extui/mks_ui/pic_manager.cpp
  37. 35
      Marlin/src/lcd/extui/mks_ui/printer_operation.cpp
  38. 25
      Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
  39. 2
      Marlin/src/lcd/extui/mks_ui/tft_multi_language.cpp
  40. 74
      Marlin/src/lcd/extui/mks_ui/wifiSerial.h
  41. 352
      Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32.cpp
  42. 63
      Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32.h
  43. 18
      Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32F1.cpp
  44. 77
      Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32F1.h
  45. 546
      Marlin/src/lcd/extui/mks_ui/wifi_module.cpp
  46. 4
      Marlin/src/lcd/extui/mks_ui/wifi_module.h
  47. 10
      Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp
  48. 1
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h
  49. 15
      Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h
  50. 4
      buildroot/tests/mks_robin_nano35
  51. 3
      ini/stm32f1-maple.ini

8
Marlin/src/HAL/STM32/HAL.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "HAL.h"
#include "usb_serial.h"
@ -93,9 +93,7 @@ void HAL_init() {
TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
#if HAS_SD_HOST_DRIVE
MSC_SD_init(); // Enable USB SD card access
#endif
TERN_(HAS_SD_HOST_DRIVE, MSC_SD_init()); // Enable USB SD card access
#if PIN_EXISTS(USB_CONNECT)
OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
@ -167,4 +165,4 @@ void HAL_SYSTICK_Callback() {
if (systick_user_callback) systick_user_callback();
}
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

2
Marlin/src/HAL/STM32/HAL_MinSerial.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfigPre.h"

4
Marlin/src/HAL/STM32/HAL_SPI.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -224,4 +224,4 @@ static SPISettings spiConfig;
#endif // SOFTWARE_SPI
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/MarlinSPI.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(STM32H7xx)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1) && !defined(STM32H7xx)
#include "MarlinSPI.h"
@ -165,4 +165,4 @@ uint8_t MarlinSPI::dmaSend(const void * transmitBuf, uint16_t length, bool minc)
return 1;
}
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1 && !STM32H7xx

4
Marlin/src/HAL/STM32/MarlinSerial.cpp

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
#include "MarlinSerial.h"
@ -101,4 +101,4 @@ void MarlinSerial::_rx_complete_irq(serial_t *obj) {
}
}
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -343,4 +343,4 @@
#endif // !USBD_USE_CDC_COMPOSITE
#endif // SDIO_SUPPORT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/Servo.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -107,4 +107,4 @@ void libServo::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriori
}
#endif // HAS_SERVOS
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/eeprom_flash.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -270,4 +270,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}
#endif // FLASH_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/eeprom_sdcard.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
/**
* Implementation of EEPROM settings in SD Card
@ -88,4 +88,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, const size_t size, uin
}
#endif // SDCARD_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/eeprom_sram.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -65,4 +65,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}
#endif // SRAM_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/eeprom_wired.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -75,4 +75,4 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
}
#endif // USE_WIRED_EEPROM
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/fast_pwm.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfigPre.h"
@ -56,4 +56,4 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
}
#endif // NEEDS_HARDWARE_PWM
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/fastio.cpp

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -31,4 +31,4 @@ void FastIO_init() {
FastIOPortMap[STM_PORT(digitalPin[i])] = get_GPIO_Port(STM_PORT(digitalPin[i]));
}
#endif
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

14
Marlin/src/HAL/STM32/msc_sd.cpp

@ -13,21 +13,24 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfigPre.h"
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && HAS_SD_HOST_DRIVE
#if HAS_SD_HOST_DRIVE
#include "msc_sd.h"
#include "../shared/Marduino.h"
#include "usbd_core.h"
#include "../shared/Marduino.h"
#include "../../sd/cardreader.h"
#include <USB.h>
#include <USBMscHandler.h>
#define BLOCK_SIZE 512
#define PRODUCT_ID 0x29
#include "../../sd/cardreader.h"
class Sd2CardUSBMscHandler : public USBMscHandler {
public:
DiskIODriver* diskIODriver() {
@ -121,4 +124,5 @@ void MSC_SD_init() {
USBDevice.begin();
}
#endif // __STM32F1__ && HAS_SD_HOST_DRIVE
#endif // HAS_SD_HOST_DRIVE
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/tft/gt911.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfig.h"
@ -199,4 +199,4 @@ bool GT911::getPoint(int16_t *x, int16_t *y) {
}
#endif // TFT_TOUCH_DEVICE_GT911
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/tft/tft_fsmc.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfig.h"
@ -178,4 +178,4 @@ void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
}
#endif // HAS_FSMC_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/tft/tft_ltdc.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfig.h"
@ -384,4 +384,4 @@ void TFT_LTDC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
}
#endif // HAS_LTDC_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/tft/tft_spi.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfig.h"
@ -240,4 +240,4 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
}
#endif // HAS_SPI_TFT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/tft/xpt2046.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfig.h"
@ -167,4 +167,4 @@ uint16_t XPT2046::SoftwareIO(uint16_t data) {
}
#endif // HAS_TFT_XPT2046
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/timers.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -319,4 +319,4 @@ static constexpr bool verify_no_timer_conflicts() {
// when hovering over it, making it easy to identify the conflicting timers.
static_assert(verify_no_timer_conflicts(), "One or more timer conflict detected. Examine \"timers_in_use\" to help identify conflict.");
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/usb_host.cpp

@ -20,7 +20,7 @@
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfig.h"
@ -114,4 +114,4 @@ uint8_t BulkStorage::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t b
}
#endif // USE_OTG_USB_HOST && USBHOST
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/usb_serial.cpp

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfigPre.h"
@ -51,4 +51,4 @@ void USB_Hook_init() {
}
#endif // EMERGENCY_PARSER && USBD_USE_CDC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

4
Marlin/src/HAL/STM32/watchdog.cpp

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../inc/MarlinConfigPre.h"
@ -46,4 +46,4 @@ void HAL_watchdog_refresh() {
}
#endif // USE_WATCHDOG
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

7
Marlin/src/HAL/STM32F1/msc_sd.cpp

@ -13,9 +13,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfigPre.h"
#if defined(__STM32F1__) && HAS_SD_HOST_DRIVE
#if HAS_SD_HOST_DRIVE
#include "msc_sd.h"
#include "SPI.h"
@ -92,4 +94,5 @@ void MSC_SD_init() {
#endif
}
#endif // __STM32F1__ && HAS_SD_HOST_DRIVE
#endif // HAS_SD_HOST_DRIVE
#endif // __STM32F1__

7
Marlin/src/MarlinCore.cpp

@ -1209,13 +1209,6 @@ void setup() {
#endif
#endif
#if BOTH(HAS_TFT_LVGL_UI, MKS_WIFI_MODULE)
mks_esp_wifi_init();
WIFISERIAL.begin(WIFI_BAUDRATE);
serial_connect_timeout = millis() + 1000UL;
while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
#endif
TERN_(DYNAMIC_VECTORTABLE, hook_cpu_exceptions()); // If supported, install Marlin exception handlers at runtime
SETUP_RUN(HAL_init());

2
Marlin/src/core/macros.h

@ -442,7 +442,7 @@
return contains(str, '/') ? findLastPos(findStringEnd(str), '/') : str;
}
// Find the first occurence of a character in a string (or return the last position in the string)
// Find the first occurrence of a character in a string (or return the last position in the string)
constexpr const char* findFirst(const char *str, const char ch) {
return *str == ch || *str == 0 ? (str + 1) : findFirst(str + 1, ch);
}

2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/compat.h

@ -288,7 +288,7 @@
// Remove compiler warning on an unused variable
#ifndef UNUSED
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#define UNUSED(X) (void)X
#else
#define UNUSED(x) ((void)(x))

28
Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp

@ -61,7 +61,7 @@ static lv_obj_t *scr, *tempText1, *filament_bar;
extern uint8_t sel_id;
extern bool once_flag, gcode_preview_over;
extern int upload_result;
extern uint32_t upload_time;
extern uint32_t upload_time_sec;
extern uint32_t upload_size;
extern bool temps_update_flag;
@ -406,28 +406,24 @@ void lv_draw_dialog(uint8_t type) {
char buf[200];
int _index = 0;
strcpy(buf, DIALOG_UPLOAD_FINISH_EN);
strcpy_P(buf, PSTR(DIALOG_UPLOAD_FINISH_EN));
_index = strlen(buf);
buf[_index] = '\n';
_index++;
strcat(buf, DIALOG_UPLOAD_SIZE_EN);
buf[_index++] = '\n';
strcat_P(buf, PSTR(DIALOG_UPLOAD_SIZE_EN));
_index = strlen(buf);
buf[_index] = ':';
_index++;
sprintf(&buf[_index], " %d KBytes\n", (int)(upload_size / 1024));
buf[_index++] = ':';
sprintf_P(&buf[_index], PSTR(" %d KBytes\n"), (int)(upload_size / 1024));
strcat(buf, DIALOG_UPLOAD_TIME_EN);
strcat_P(buf, PSTR(DIALOG_UPLOAD_TIME_EN));
_index = strlen(buf);
buf[_index] = ':';
_index++;
sprintf(&buf[_index], " %d s\n", (int)upload_time);
buf[_index++] = ':';
sprintf_P(&buf[_index], PSTR(" %d s\n"), (int)upload_time_sec);
strcat(buf, DIALOG_UPLOAD_SPEED_EN);
strcat_P(buf, PSTR(DIALOG_UPLOAD_SPEED_EN));
_index = strlen(buf);
buf[_index] = ':';
_index++;
sprintf(&buf[_index], " %d KBytes/s\n", (int)(upload_size / upload_time / 1024));
buf[_index++] = ':';
sprintf_P(&buf[_index], PSTR(" %d KBytes/s\n"), (int)(upload_size / upload_time_sec / 1024));
lv_label_set_text(labelDialog, buf);
lv_obj_align(labelDialog, nullptr, LV_ALIGN_CENTER, 0, -20);

5
Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp

@ -29,9 +29,12 @@
#include "tft_lvgl_configuration.h"
#include "SPI_TFT.h"
#include "mks_hardware_test.h"
#include "../../../inc/MarlinConfig.h"
#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
#endif
static lv_obj_t *scr;
void lv_draw_error_message(PGM_P const msg) {

4
Marlin/src/lcd/extui/mks_ui/draw_printing.cpp

@ -47,14 +47,16 @@ static lv_obj_t *scr;
static lv_obj_t *labelExt1, *labelFan, *labelZpos, *labelTime;
static lv_obj_t *labelPause, *labelStop, *labelOperat;
static lv_obj_t *bar1, *bar1ValueText;
static lv_obj_t *buttonPause, *buttonOperat, *buttonStop, *buttonExt1, *buttonExt2, *buttonBedstate, *buttonFanstate, *buttonZpos;
static lv_obj_t *buttonPause, *buttonOperat, *buttonStop, *buttonExt1, *buttonFanstate, *buttonZpos;
#if HAS_MULTI_EXTRUDER
static lv_obj_t *labelExt2;
static lv_obj_t *buttonExt2;
#endif
#if HAS_HEATED_BED
static lv_obj_t* labelBed;
static lv_obj_t* buttonBedstate;
#endif
enum {

112
Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp

@ -27,7 +27,6 @@
#include "draw_tool.h"
#include <lv_conf.h>
#include "tft_lvgl_configuration.h"
#include "mks_hardware_test.h"
#include "draw_ui.h"
#include <lvgl.h>
@ -40,6 +39,10 @@
#include "draw_touch_calibration.h"
#endif
#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
#endif
#include <stdio.h>
#define ICON_POS_Y 38
@ -48,14 +51,16 @@
extern lv_group_t* g;
static lv_obj_t *scr;
static lv_obj_t *labelExt1, *labelExt1Target, *labelFan;
static lv_obj_t *buttonExt1, *labelExt1, *buttonFanstate, *labelFan;
#if HAS_MULTI_EXTRUDER
static lv_obj_t *labelExt2, *labelExt2Target;
#if HAS_MULTI_HOTEND
static lv_obj_t *labelExt2;
static lv_obj_t *buttonExt2;
#endif
#if HAS_HEATED_BED
static lv_obj_t *labelBed, *labelBedTarget;
static lv_obj_t* labelBed;
static lv_obj_t* buttonBedstate;
#endif
#if ENABLED(MKS_TEST)
@ -136,18 +141,18 @@ void lv_draw_ready_print() {
lv_obj_align(label_tool, buttonTool, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
}
#if HAS_HOTEND
e1 = lv_label_create_empty(scr);
lv_obj_set_pos(e1, 20, 20);
sprintf_P(buf, PSTR("e1: %d"), thermalManager.wholeDegHotend(0));
lv_label_set_text(e1, buf);
#endif
#if HAS_MULTI_HOTEND
e2 = lv_label_create_empty(scr);
lv_obj_set_pos(e2, 20, 45);
sprintf_P(buf, PSTR("e1: %d"), thermalManager.wholeDegHotend(1));
lv_label_set_text(e2, buf);
#endif
#if HAS_HEATED_BED
bed = lv_label_create_empty(scr);
lv_obj_set_pos(bed, 20, 95);
@ -178,72 +183,27 @@ void lv_draw_ready_print() {
lv_label_set_text(det_info, " ");
}
else {
lv_big_button_create(scr, "F:/bmp_tool.bin", main_menu.tool, 20, 180, event_handler, ID_TOOL);
lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 180, event_handler, ID_SET);
lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 180, event_handler, ID_PRINT);
lv_big_button_create(scr, "F:/bmp_tool.bin", main_menu.tool, 20, 150, event_handler, ID_TOOL);
lv_big_button_create(scr, "F:/bmp_set.bin", main_menu.set, 180, 150, event_handler, ID_SET);
lv_big_button_create(scr, "F:/bmp_printing.bin", main_menu.print, 340, 150, event_handler, ID_PRINT);
// Monitoring
lv_obj_t *buttonExt1 = lv_big_button_create(scr, "F:/bmp_ext1_state.bin", " ", 55, ICON_POS_Y, event_handler, ID_INFO_EXT);
#if HAS_MULTI_EXTRUDER
lv_obj_t *buttonExt2 = lv_big_button_create(scr, "F:/bmp_ext2_state.bin", " ", 163, ICON_POS_Y, event_handler, ID_INFO_EXT);
#if HAS_HEATED_BED
lv_obj_t *buttonBedstate = lv_big_button_create(scr, "F:/bmp_bed_state.bin", " ", 271, ICON_POS_Y, event_handler, ID_INFO_BED);
#endif
#else
#if HAS_HEATED_BED
lv_obj_t *buttonBedstate = lv_big_button_create(scr, "F:/bmp_bed_state.bin", " ", 210, ICON_POS_Y, event_handler, ID_INFO_BED);
#if HAS_HOTEND
buttonExt1 = lv_big_button_create(scr, "F:/bmp_ext1_state.bin", " ", 55, ICON_POS_Y, event_handler, ID_INFO_EXT);
#endif
#if HAS_MULTI_HOTEND
buttonExt2 = lv_big_button_create(scr, "F:/bmp_ext2_state.bin", " ", 163, ICON_POS_Y, event_handler, ID_INFO_EXT);
#endif
lv_obj_t *buttonFanstate = lv_big_button_create(scr, "F:/bmp_fan_state.bin", " ", 380, ICON_POS_Y, event_handler, ID_INFO_FAN);
labelExt1 = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
labelExt1Target = lv_label_create(scr, 55, LABEL_MOD_Y, nullptr);
#if HAS_MULTI_EXTRUDER
labelExt2 = lv_label_create(scr, 163, LABEL_MOD_Y, nullptr);
labelExt2Target = lv_label_create(scr, 163, LABEL_MOD_Y, nullptr);
#if HAS_HEATED_BED
labelBed = lv_label_create(scr, 271, LABEL_MOD_Y, nullptr);
labelBedTarget = lv_label_create(scr, 271, LABEL_MOD_Y, nullptr);
#endif
#else
#if HAS_HEATED_BED
labelBed = lv_label_create(scr, 210, LABEL_MOD_Y, nullptr);
labelBedTarget = lv_label_create(scr, 210, LABEL_MOD_Y, nullptr);
#endif
buttonBedstate = lv_big_button_create(scr, "F:/bmp_bed_state.bin", " ", TERN(HAS_MULTI_HOTEND, 271, 210), ICON_POS_Y, event_handler, ID_INFO_BED);
#endif
labelFan = lv_label_create(scr, 380, 80, nullptr);
itoa(thermalManager.degHotend(0), buf, 10);
lv_label_set_text(labelExt1, buf);
lv_obj_align(labelExt1, buttonExt1, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
sprintf_P(buf, PSTR("-> %d"), thermalManager.degTargetHotend(0));
lv_label_set_text(labelExt1Target, buf);
lv_obj_align(labelExt1Target, buttonExt1, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
#if HAS_MULTI_EXTRUDER
itoa(thermalManager.degHotend(1), buf, 10);
lv_label_set_text(labelExt2, buf);
lv_obj_align(labelExt2, buttonExt2, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
sprintf_P(buf, PSTR("-> %d"), thermalManager.degTargetHotend(1));
lv_label_set_text(labelExt2Target, buf);
lv_obj_align(labelExt2Target, buttonExt2, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
#endif
TERN_(HAS_HOTEND, labelExt1 = lv_label_create_empty(scr));
TERN_(HAS_MULTI_HOTEND, labelExt2 = lv_label_create_empty(scr));
TERN_(HAS_HEATED_BED, labelBed = lv_label_create_empty(scr));
TERN_(HAS_FAN, labelFan = lv_label_create_empty(scr));
#if HAS_HEATED_BED
itoa(thermalManager.degBed(), buf, 10);
lv_label_set_text(labelBed, buf);
lv_obj_align(labelBed, buttonBedstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
sprintf_P(buf, PSTR("-> %d"), thermalManager.degTargetBed());
lv_label_set_text(labelBedTarget, buf);
lv_obj_align(labelBedTarget, buttonBedstate, LV_ALIGN_CENTER, 0, TARGET_LABEL_MOD_Y);
#endif
sprintf_P(buf, PSTR("%d%%"), (int)thermalManager.fanSpeedPercent(0));
lv_label_set_text(labelFan, buf);
lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_CENTER, 0, LABEL_MOD_Y);
lv_temp_refr();
}
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
@ -256,17 +216,25 @@ void lv_draw_ready_print() {
}
void lv_temp_refr() {
#if HAS_HEATED_BED
sprintf(public_buf_l, printing_menu.bed_temp, thermalManager.wholeDegBed(), thermalManager.degTargetBed());
lv_label_set_text(labelBed, public_buf_l);
#endif
#if HAS_HOTEND
sprintf(public_buf_l, printing_menu.temp1, thermalManager.wholeDegHotend(0), thermalManager.degTargetHotend(0));
lv_label_set_text(labelExt1, public_buf_l);
#if HAS_MULTI_EXTRUDER
lv_obj_align(labelExt1, buttonExt1, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
#endif
#if HAS_MULTI_HOTEND
sprintf(public_buf_l, printing_menu.temp1, thermalManager.wholeDegHotend(1), thermalManager.degTargetHotend(1));
lv_label_set_text(labelExt2, public_buf_l);
lv_obj_align(labelExt2, buttonExt2, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
#endif
#if HAS_HEATED_BED
sprintf(public_buf_l, printing_menu.bed_temp, thermalManager.wholeDegBed(), thermalManager.degTargetBed());
lv_label_set_text(labelBed, public_buf_l);
lv_obj_align(labelBed, buttonBedstate, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
#endif
#if HAS_FAN
sprintf_P(public_buf_l, PSTR("%d%%"), (int)thermalManager.fanSpeedPercent(0));
lv_label_set_text(labelFan, public_buf_l);
lv_obj_align(labelFan, buttonFanstate, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
#endif
}

34
Marlin/src/lcd/extui/mks_ui/draw_ui.cpp

@ -30,7 +30,6 @@
#include "pic_manager.h"
#include "draw_ui.h"
#include "mks_hardware_test.h"
#include <SPI.h>
@ -52,6 +51,10 @@
#include "draw_touch_calibration.h"
#endif
#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
#endif
CFG_ITMES gCfgItems;
UI_CFG uiCfg;
DISP_STATE_STACK disp_state_stack;
@ -202,27 +205,27 @@ void ui_cfg_init() {
#if ENABLED(MKS_WIFI_MODULE)
memset(&wifiPara, 0, sizeof(wifiPara));
memset(&ipPara, 0, sizeof(ipPara));
strcpy(wifiPara.ap_name, WIFI_AP_NAME);
strcpy(wifiPara.keyCode, WIFI_KEY_CODE);
strcpy_P(wifiPara.ap_name, PSTR(WIFI_AP_NAME));
strcpy_P(wifiPara.keyCode, PSTR(WIFI_KEY_CODE));
//client
strcpy(ipPara.ip_addr, IP_ADDR);
strcpy(ipPara.mask, IP_MASK);
strcpy(ipPara.gate, IP_GATE);
strcpy(ipPara.dns, IP_DNS);
strcpy_P(ipPara.ip_addr, PSTR(IP_ADDR));
strcpy_P(ipPara.mask, PSTR(IP_MASK));
strcpy_P(ipPara.gate, PSTR(IP_GATE));
strcpy_P(ipPara.dns, PSTR(IP_DNS));
ipPara.dhcp_flag = IP_DHCP_FLAG;
//AP
strcpy(ipPara.dhcpd_ip, AP_IP_ADDR);
strcpy(ipPara.dhcpd_mask, AP_IP_MASK);
strcpy(ipPara.dhcpd_gate, AP_IP_GATE);
strcpy(ipPara.dhcpd_dns, AP_IP_DNS);
strcpy(ipPara.start_ip_addr, IP_START_IP);
strcpy(ipPara.end_ip_addr, IP_END_IP);
strcpy_P(ipPara.dhcpd_ip, PSTR(AP_IP_ADDR));
strcpy_P(ipPara.dhcpd_mask, PSTR(AP_IP_MASK));
strcpy_P(ipPara.dhcpd_gate, PSTR(AP_IP_GATE));
strcpy_P(ipPara.dhcpd_dns, PSTR(AP_IP_DNS));
strcpy_P(ipPara.start_ip_addr, PSTR(IP_START_IP));
strcpy_P(ipPara.end_ip_addr, PSTR(IP_END_IP));
ipPara.dhcpd_flag = AP_IP_DHCP_FLAG;
strcpy((char*)uiCfg.cloud_hostUrl, "baizhongyun.cn");
strcpy_P((char*)uiCfg.cloud_hostUrl, PSTR("baizhongyun.cn"));
uiCfg.cloud_port = 10086;
#endif
@ -1362,7 +1365,10 @@ void print_time_count() {
void LV_TASK_HANDLER() {
lv_task_handler();
#if ENABLED(MKS_TEST)
if (mks_test_flag == 0x1E) mks_hardware_test();
#endif
TERN_(HAS_GCODE_PREVIEW, disp_pre_gcode(2, 36));

10
Marlin/src/lcd/extui/mks_ui/irq_overrid.cpp

@ -19,14 +19,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifdef __STM32F1__
#include "../../../inc/MarlinConfigPre.h"
#if HAS_TFT_LVGL_UI
#if BOTH(HAS_TFT_LVGL_UI, MKS_WIFI_MODULE)
#include "tft_lvgl_configuration.h"
#if ENABLED(MKS_WIFI_MODULE)
#include "draw_ui.h"
#include "wifiSerial.h"
@ -56,5 +56,5 @@ void __irq_usart1() {
} /* C-declarations for C++ */
#endif
#endif // MKS_WIFI_MODULE
#endif // HAS_TFT_LVGL_UI
#endif // HAS_TFT_LVGL_UI && MKS_WIFI_MODULE
#endif // __STM32F1__

140
Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp

@ -27,7 +27,6 @@
#include "tft_lvgl_configuration.h"
#include "draw_ready_print.h"
#include "mks_hardware_test.h"
#include "draw_ui.h"
#include "pic_manager.h"
#include <lvgl.h>
@ -36,51 +35,47 @@
#include "../../../module/temperature.h"
#include "../../../sd/cardreader.h"
uint8_t pw_det_sta, pw_off_sta, mt_det_sta, mt_det3_sta;
#if PIN_EXISTS(MT_DET_2)
uint8_t mt_det2_sta;
#endif
uint8_t endstopx1_sta, endstopx2_sta, endstopy1_sta, endstopy2_sta, endstopz1_sta, endstopz2_sta;
void test_gpio_readlevel_L() {
#if ENABLED(MKS_TEST)
volatile uint32_t itest;
WRITE(WIFI_IO0_PIN, HIGH);
itest = 10000;
while (itest--);
pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == 0);
pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == 0);
mt_det_sta = (READ(MT_DET_1_PIN) == 0);
#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
bool pw_det_sta, pw_off_sta, mt_det_sta;
#if PIN_EXISTS(MT_DET_2)
mt_det2_sta = (READ(MT_DET_2_PIN) == 0);
bool mt_det2_sta;
#endif
endstopx1_sta = (READ(X_MIN_PIN) == 0);
endstopy1_sta = (READ(Y_MIN_PIN) == 0);
endstopz1_sta = (READ(Z_MIN_PIN) == 0);
endstopz2_sta = (READ(Z_MAX_PIN) == 0);
bool endstopx1_sta, endstopx2_sta, endstopy1_sta, endstopy2_sta, endstopz1_sta, endstopz2_sta;
void test_gpio_readlevel_L() {
WRITE(WIFI_IO0_PIN, HIGH);
delay(10);
pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == LOW);
pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == LOW);
mt_det_sta = (READ(MT_DET_1_PIN) == LOW);
#if PIN_EXISTS(MT_DET_2)
mt_det2_sta = (READ(MT_DET_2_PIN) == LOW);
#endif
}
endstopx1_sta = (READ(X_MIN_PIN) == LOW);
endstopy1_sta = (READ(Y_MIN_PIN) == LOW);
endstopz1_sta = (READ(Z_MIN_PIN) == LOW);
endstopz2_sta = (READ(Z_MAX_PIN) == LOW);
}
void test_gpio_readlevel_H() {
#if ENABLED(MKS_TEST)
volatile uint32_t itest;
void test_gpio_readlevel_H() {
WRITE(WIFI_IO0_PIN, LOW);
itest = 10000;
while (itest--);
pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == 1);
pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == 1);
mt_det_sta = (READ(MT_DET_1_PIN) == 1);
delay(10);
pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == HIGH);
pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == HIGH);
mt_det_sta = (READ(MT_DET_1_PIN) == HIGH);
#if PIN_EXISTS(MT_DET_2)
mt_det2_sta = (READ(MT_DET_2_PIN) == 1);
#endif
endstopx1_sta = (READ(X_MIN_PIN) == 1);
endstopy1_sta = (READ(Y_MIN_PIN) == 1);
endstopz1_sta = (READ(Z_MIN_PIN) == 1);
endstopz2_sta = (READ(Z_MAX_PIN) == 1);
mt_det2_sta = (READ(MT_DET_2_PIN) == HIGH);
#endif
}
endstopx1_sta = (READ(X_MIN_PIN) == HIGH);
endstopy1_sta = (READ(Y_MIN_PIN) == HIGH);
endstopz1_sta = (READ(Z_MIN_PIN) == HIGH);
endstopz2_sta = (READ(Z_MAX_PIN) == HIGH);
}
void init_test_gpio() {
#ifdef MKS_TEST
void init_test_gpio() {
SET_INPUT_PULLUP(X_MIN_PIN);
SET_INPUT_PULLUP(Y_MIN_PIN);
SET_INPUT_PULLUP(Z_MIN_PIN);
@ -102,7 +97,7 @@ void init_test_gpio() {
SET_OUTPUT(Y_ENABLE_PIN);
SET_OUTPUT(Z_ENABLE_PIN);
SET_OUTPUT(E0_ENABLE_PIN);
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
SET_OUTPUT(E1_ENABLE_PIN);
#endif
@ -110,11 +105,11 @@ void init_test_gpio() {
WRITE(Y_ENABLE_PIN, LOW);
WRITE(Z_ENABLE_PIN, LOW);
WRITE(E0_ENABLE_PIN, LOW);
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
WRITE(E1_ENABLE_PIN, LOW);
#endif
#if MB(MKS_ROBIN_E3P)
#if ENABLED(MKS_HARDWARE_TEST_ONLY_E0)
SET_INPUT_PULLUP(PA1);
SET_INPUT_PULLUP(PA3);
SET_INPUT_PULLUP(PC2);
@ -123,68 +118,56 @@ void init_test_gpio() {
SET_INPUT_PULLUP(PE6);
SET_INPUT_PULLUP(PE7);
#endif
#endif
}
}
void mks_test_beeper() {
#ifdef MKS_TEST
void mks_test_beeper() {
WRITE(BEEPER_PIN, HIGH);
delay(100);
WRITE(BEEPER_PIN, LOW);
delay(100);
#endif
}
}
void mks_gpio_test() {
#if ENABLED(MKS_TEST)
void mks_gpio_test() {
init_test_gpio();
test_gpio_readlevel_L();
test_gpio_readlevel_H();
test_gpio_readlevel_L();
if ((pw_det_sta == 1)
&& (pw_off_sta == 1)
&& (mt_det_sta == 1)
if (pw_det_sta && pw_off_sta && mt_det_sta
#if PIN_EXISTS(MT_DET_2)
&& (mt_det2_sta == 1)
&& mt_det2_sta
#endif
#if MB(MKS_ROBIN_E3P)
&& (READ(PA1) == 0)
&& (READ(PA3) == 0)
&& (READ(PC2) == 0)
&& (READ(PD8) == 0)
&& (READ(PE5) == 0)
&& (READ(PE6) == 0)
&& (READ(PE7) == 0)
#if ENABLED(MKS_HARDWARE_TEST_ONLY_E0)
&& (READ(PA1) == LOW)
&& (READ(PA3) == LOW)
&& (READ(PC2) == LOW)
&& (READ(PD8) == LOW)
&& (READ(PE5) == LOW)
&& (READ(PE6) == LOW)
&& (READ(PE7) == LOW)
#endif
)
disp_det_ok();
else
disp_det_error();
if ( (endstopx1_sta == 1)
&& (endstopy1_sta == 1)
&& (endstopz1_sta == 1)
&& (endstopz2_sta == 1)
)
if (endstopx1_sta && endstopy1_sta && endstopz1_sta && endstopz2_sta)
disp_Limit_ok();
else
disp_Limit_error();
#endif
}
}
void mks_hardware_test() {
#if ENABLED(MKS_TEST)
void mks_hardware_test() {
if (millis() % 2000 < 1000) {
WRITE(X_DIR_PIN, LOW);
WRITE(Y_DIR_PIN, LOW);
WRITE(Z_DIR_PIN, LOW);
WRITE(E0_DIR_PIN, LOW);
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
WRITE(E1_DIR_PIN, LOW);
#endif
thermalManager.fan_speed[0] = 255;
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
WRITE(HEATER_1_PIN, HIGH); // HE1
#endif
WRITE(HEATER_0_PIN, HIGH); // HE0
@ -195,21 +178,18 @@ void mks_hardware_test() {
WRITE(Y_DIR_PIN, HIGH);
WRITE(Z_DIR_PIN, HIGH);
WRITE(E0_DIR_PIN, HIGH);
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
WRITE(E1_DIR_PIN, HIGH);
#endif
thermalManager.fan_speed[0] = 0;
#if !MB(MKS_ROBIN_E3P)
#if DISABLED(MKS_HARDWARE_TEST_ONLY_E0)
WRITE(HEATER_1_PIN, LOW); // HE1
#endif
WRITE(HEATER_0_PIN, LOW); // HE0
WRITE(HEATER_BED_PIN, LOW); // HOT-BED
}
if ( (endstopx1_sta == 1) && (endstopx2_sta == 1)
&& (endstopy1_sta == 1) && (endstopy2_sta == 1)
&& (endstopz1_sta == 1) && (endstopz2_sta == 1)
) {
if (endstopx1_sta && endstopx2_sta && endstopy1_sta && endstopy2_sta && endstopz1_sta && endstopz2_sta) {
// nothing here
}
else {
@ -217,9 +197,9 @@ void mks_hardware_test() {
if (disp_state == PRINT_READY_UI)
mks_disp_test();
}
#endif
}
#endif // MKS_TEST
static const uint16_t ASCII_Table_16x24[] PROGMEM = {
// Space ' '

6
Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h

@ -24,10 +24,12 @@
#include <lvgl.h>
void mks_gpio_test();
void mks_hardware_test();
void mks_test_get();
void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint16_t bkColor);
void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor);
void mks_hardware_test();
void disp_assets_update();
void disp_assets_update_progress(const char *msg);
void mks_test_get();
extern uint8_t mks_test_flag;

5
Marlin/src/lcd/extui/mks_ui/pic_manager.cpp

@ -27,7 +27,10 @@
#include "draw_ui.h"
#include "pic_manager.h"
#include "draw_ready_print.h"
#include "mks_hardware_test.h"
#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
#endif
#include "SPIFlashStorage.h"
#include "../../../libs/W25Qxx.h"

35
Marlin/src/lcd/extui/mks_ui/printer_operation.cpp

@ -158,19 +158,12 @@ void filament_pin_setup() {
}
void filament_check() {
#if ANY_PIN(MT_DET_1, MT_DET_2, MT_DET_3)
const int FIL_DELAY = 20;
#endif
#if PIN_EXISTS(MT_DET_1)
static int fil_det_count_1 = 0;
if (!READ(MT_DET_1_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_1++;
else if (READ(MT_DET_1_PIN) && MT_DET_PIN_INVERTING)
fil_det_count_1++;
else if (fil_det_count_1 > 0)
fil_det_count_1--;
if (!READ(MT_DET_1_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_1++;
else if (READ(MT_DET_1_PIN) && MT_DET_PIN_INVERTING)
if (READ(MT_DET_1_PIN) == MT_DET_PIN_INVERTING)
fil_det_count_1++;
else if (fil_det_count_1 > 0)
fil_det_count_1--;
@ -178,16 +171,7 @@ void filament_check() {
#if PIN_EXISTS(MT_DET_2)
static int fil_det_count_2 = 0;
if (!READ(MT_DET_2_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_2++;
else if (READ(MT_DET_2_PIN) && MT_DET_PIN_INVERTING)
fil_det_count_2++;
else if (fil_det_count_2 > 0)
fil_det_count_2--;
if (!READ(MT_DET_2_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_2++;
else if (READ(MT_DET_2_PIN) && MT_DET_PIN_INVERTING)
if (READ(MT_DET_2_PIN) == MT_DET_PIN_INVERTING)
fil_det_count_2++;
else if (fil_det_count_2 > 0)
fil_det_count_2--;
@ -195,16 +179,7 @@ void filament_check() {
#if PIN_EXISTS(MT_DET_3)
static int fil_det_count_3 = 0;
if (!READ(MT_DET_3_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_3++;
else if (READ(MT_DET_3_PIN) && MT_DET_PIN_INVERTING)
fil_det_count_3++;
else if (fil_det_count_3 > 0)
fil_det_count_3--;
if (!READ(MT_DET_3_PIN) && !MT_DET_PIN_INVERTING)
fil_det_count_3++;
else if (READ(MT_DET_3_PIN) && MT_DET_PIN_INVERTING)
if (READ(MT_DET_3_PIN) == MT_DET_PIN_INVERTING)
fil_det_count_3++;
else if (fil_det_count_3 > 0)
fil_det_count_3--;

25
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp

@ -45,6 +45,14 @@ XPT2046 touch;
#include "../../../feature/powerloss.h"
#endif
#if HAS_SERVOS
#include "../../../module/servo.h"
#endif
#if EITHER(PROBE_TARE, HAS_Z_SERVO_PROBE)
#include "../../../module/probe.h"
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../../tft_io/touch_calibration.h"
#include "draw_touch_calibration.h"
@ -131,9 +139,8 @@ void tft_lvgl_init() {
#if ENABLED(SDSUPPORT)
UpdateAssets();
watchdog_refresh(); // LVGL init takes time
#endif
mks_test_get();
#endif
touch.Init();
@ -193,8 +200,12 @@ void tft_lvgl_init() {
filament_pin_setup();
lv_encoder_pin_init();
TERN_(MKS_WIFI_MODULE, mks_wifi_firmware_update());
#if ENABLED(MKS_WIFI_MODULE)
mks_esp_wifi_init();
mks_wifi_firmware_update();
#endif
TERN_(HAS_SERVOS, servo_init());
TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());
bool ready = true;
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.load();
@ -207,16 +218,22 @@ void tft_lvgl_init() {
uiCfg.print_state = REPRINTING;
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
strncpy(public_buf_m, recovery.info.sd_filename, sizeof(public_buf_m));
card.printLongPath(public_buf_m);
strncpy(list_file.long_name[sel_id], card.longFilename, sizeof(list_file.long_name[0]));
#else
strncpy(list_file.long_name[sel_id], recovery.info.sd_filename, sizeof(list_file.long_name[0]));
#endif
lv_draw_printing();
}
#endif
if (ready) lv_draw_ready_print();
#if ENABLED(MKS_TEST)
if (mks_test_flag == 0x1E) mks_gpio_test();
#endif
}
void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {

2
Marlin/src/lcd/extui/mks_ui/tft_multi_language.cpp

@ -58,6 +58,8 @@ pause_msg_def pause_msg_menu;
eeprom_def eeprom_menu;
media_select_menu_def media_select_menu;
// TODO: Make all strings PSTR and update accessors for the benefit of AVR
machine_common_def machine_menu;
void machine_setting_disp() {
if (gCfgItems.language == LANG_SIMPLE_CHINESE) {

74
Marlin/src/lcd/extui/mks_ui/wifiSerial.h

@ -21,10 +21,6 @@
*/
#pragma once
#include "tft_lvgl_configuration.h"
#if ENABLED(MKS_WIFI_MODULE)
#ifdef SERIAL_PORT_2
#error "SERIAL_PORT_2 must be disabled with TFT_LVGL_UI* and MKS_WIFI_MODULE."
#endif
@ -33,70 +29,16 @@
#define WIFI_UPLOAD_BAUDRATE 1958400
#define USART_SAFE_INSERT
#define WIFI_RX_BUF_SIZE (1024+1)
#include <libmaple/libmaple_types.h>
#include <libmaple/usart.h>
#include <libmaple/libmaple.h>
#include <libmaple/gpio.h>
#include <libmaple/timer.h>
#include <libmaple/ring_buffer.h>
#define DEFINE_WFSERIAL(name, n)\
WifiSerial name(USART##n, \
BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN)
class WifiSerial {
public:
uint8 wifiRxBuf[WIFI_RX_BUF_SIZE];
public:
WifiSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin);
#define WIFI_RX_BUF_SIZE (1024)
#define WIFI_TX_BUF_SIZE (64)
/* Set up/tear down */
void begin(uint32 baud);
void begin(uint32 baud,uint8_t config);
void end();
int available();
int read();
int write(uint8_t);
inline void wifi_usart_irq(usart_reg_map *regs) {
/* Handling RXNEIE and TXEIE interrupts.
* RXNE signifies availability of a byte in DR.
*
* See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
* We enable RXNEIE.
*/
if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
#ifdef USART_SAFE_INSERT
/* If the buffer is full and the user defines USART_SAFE_INSERT,
* ignore new bytes. */
rb_safe_insert(this->usart_device->rb, (uint8)regs->DR);
#else
/* By default, push bytes around in the ring buffer. */
rb_push_insert(this->usart_device->rb, (uint8)regs->DR);
#endif
}
/* TXE signifies readiness to send a byte to DR. */
if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
if (!rb_is_empty(this->usart_device->wb))
regs->DR=rb_remove(this->usart_device->wb);
else
regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
}
}
int wifi_rb_is_full();
#include "tft_lvgl_configuration.h"
struct usart_dev *usart_device;
private:
uint8 tx_pin;
uint8 rx_pin;
};
#ifdef __STM32F1__
#include "wifiSerial_STM32F1.h"
#else
#include "wifiSerial_STM32.h"
#endif
extern WifiSerial WifiSerial1;
#define WIFISERIAL WifiSerial1
#endif // MKS_WIFI_MODULE

352
Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32.cpp

@ -0,0 +1,352 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) && !defined(MAPLE_STM32F1)
#include "../../../inc/MarlinConfigPre.h"
#if BOTH(HAS_TFT_LVGL_UI, MKS_WIFI_MODULE)
#include "tft_lvgl_configuration.h"
#include "draw_ui.h"
#include "wifiSerial.h"
WifiSerial WifiSerial1(USART1);
void WifiSerial::setRx(uint32_t _rx) { _serial.pin_rx = digitalPinToPinName(_rx); }
void WifiSerial::setTx(uint32_t _tx) { _serial.pin_tx = digitalPinToPinName(_tx); }
void WifiSerial::setRx(PinName _rx) { _serial.pin_rx = _rx; }
void WifiSerial::setTx(PinName _tx) { _serial.pin_tx = _tx; }
void WifiSerial::init(PinName _rx, PinName _tx) {
_serial.pin_rx = (_rx == _tx) ? NC : _rx;
_serial.pin_tx = _tx;
_serial.rx_buff = wifiRxBuf;
_serial.rx_head = 0;
_serial.rx_tail = 0;
_serial.tx_buff = wifiTxBuf;
_serial.tx_head = 0;
_serial.tx_tail = 0;
}
WifiSerial::WifiSerial(void *peripheral) {
// If PIN_SERIALy_RX is not defined assume half-duplex
_serial.pin_rx = NC;
// If Serial is defined in variant set
// the Rx/Tx pins for com port if defined
#if defined(Serial) && defined(PIN_SERIAL_TX)
if ((void *)this == (void *)&Serial) {
#ifdef PIN_SERIAL_RX
setRx(PIN_SERIAL_RX);
#endif
setTx(PIN_SERIAL_TX);
} else
#endif
#if defined(PIN_SERIAL1_TX) && defined(USART1_BASE)
if (peripheral == USART1) {
#ifdef PIN_SERIAL1_RX
setRx(PIN_SERIAL1_RX);
#endif
setTx(PIN_SERIAL1_TX);
} else
#endif
#if defined(PIN_SERIAL2_TX) && defined(USART2_BASE)
if (peripheral == USART2) {
#ifdef PIN_SERIAL2_RX
setRx(PIN_SERIAL2_RX);
#endif
setTx(PIN_SERIAL2_TX);
} else
#endif
#if defined(PIN_SERIAL3_TX) && defined(USART3_BASE)
if (peripheral == USART3) {
#ifdef PIN_SERIAL3_RX
setRx(PIN_SERIAL3_RX);
#endif
setTx(PIN_SERIAL3_TX);
} else
#endif
#ifdef PIN_SERIAL4_TX
if (false
#ifdef USART4_BASE
|| peripheral == USART4
#elif defined(UART4_BASE)
|| peripheral == UART4
#endif
) {
#ifdef PIN_SERIAL4_RX
setRx(PIN_SERIAL4_RX);
#endif
setTx(PIN_SERIAL4_TX);
} else
#endif
#ifdef PIN_SERIAL5_TX
if (false
#ifdef USART5_BASE
|| peripheral == USART5
#elif defined(UART5_BASE)
|| peripheral == UART5
#endif
) {
#ifdef PIN_SERIAL5_RX
setRx(PIN_SERIAL5_RX);
#endif
setTx(PIN_SERIAL5_TX);
} else
#endif
#if defined(PIN_SERIAL6_TX) && defined(USART6_BASE)
if (peripheral == USART6) {
#ifdef PIN_SERIAL6_RX
setRx(PIN_SERIAL6_RX);
#endif
setTx(PIN_SERIAL6_TX);
} else
#endif
#ifdef PIN_SERIAL7_TX
if (false
#ifdef USART7_BASE
|| peripheral == USART7
#elif defined(UART7_BASE)
|| peripheral == UART7
#endif
) {
#ifdef PIN_SERIAL7_RX
setRx(PIN_SERIAL7_RX);
#endif
setTx(PIN_SERIAL7_TX);
} else
#endif
#ifdef PIN_SERIAL8_TX
if (false
#ifdef USART8_BASE
|| peripheral == USART8
#elif defined(UART8_BASE)
|| peripheral == UART8
#endif
) {
#ifdef PIN_SERIAL8_RX
setRx(PIN_SERIAL8_RX);
#endif
setTx(PIN_SERIAL8_TX);
} else
#endif
#if defined(PIN_SERIAL9_TX) && defined(UART9_BASE)
if (peripheral == UART9) {
#ifdef PIN_SERIAL9_RX
setRx(PIN_SERIAL9_RX);
#endif
setTx(PIN_SERIAL9_TX);
} else
#endif
#ifdef PIN_SERIAL10_TX
if (false
#ifdef USART10_BASE
|| peripheral == USART10
#elif defined(UART10_BASE)
|| peripheral == UART10
#endif
) {
#ifdef PIN_SERIAL10_RX
setRx(PIN_SERIAL10_RX);
#endif
setTx(PIN_SERIAL10_TX);
} else
#endif
#if defined(PIN_SERIALLP1_TX) && defined(LPUART1_BASE)
if (peripheral == LPUART1) {
#ifdef PIN_SERIALLP1_RX
setRx(PIN_SERIALLP1_RX);
#endif
setTx(PIN_SERIALLP1_TX);
} else
#endif
// else get the pins of the first peripheral occurrence in PinMap
{
_serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX);
_serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX);
}
//if (halfDuplex == HALF_DUPLEX_ENABLED) _serial.pin_rx = NC;
init(_serial.pin_rx, _serial.pin_tx);
}
void WifiSerial::flush() {
// If we have never written a byte, no need to flush. This special
// case is needed since there is no way to force the TXC (transmit
// complete) bit to 1 during initialization
if (!_written) return;
while ((_serial.tx_head != _serial.tx_tail)) {
// nop, the interrupt handler will free up space for us
}
// If we get here, nothing is queued anymore (DRIE is disabled) and
// the hardware finished tranmission (TXC is set).
}
bool WifiSerial::isHalfDuplex() const { return _serial.pin_rx == NC; }
void WifiSerial::enableHalfDuplexRx() {
if (isHalfDuplex()) {
// In half-duplex mode we have to wait for all TX characters to
// be transmitted before we can receive data.
flush();
if (!_rx_enabled) {
_rx_enabled = true;
uart_enable_rx(&_serial);
}
}
}
// Actual interrupt handlers //////////////////////////////////////////////////////////////
void WifiSerial::_rx_complete_irq(serial_t *obj) {
// No Parity error, read byte and store it in the buffer if there is room
unsigned char c;
if (uart_getc(obj, &c) == 0) {
WRITE(WIFI_IO1_PIN, HIGH);
rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % WIFI_RX_BUF_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != obj->rx_tail) {
obj->rx_buff[obj->rx_head] = c;
obj->rx_head = i;
}
}
}
// Actual interrupt handlers //////////////////////////////////////////////////////////////
int WifiSerial::_tx_complete_irq(serial_t *obj) {
// If interrupts are enabled, there must be more data in the output
// buffer. Send the next byte
obj->tx_tail = (obj->tx_tail + 1) % WIFI_TX_BUF_SIZE;
return (obj->tx_head == obj->tx_tail) ? -1 : 0;
}
void WifiSerial::begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
void WifiSerial::begin(unsigned long baud, byte config) {
uint32_t databits = 0, stopbits = 0, parity = 0;
_baud = baud;
_config = config;
// Manage databits
switch (config & 0x07) {
case 0x02: databits = 6; break;
case 0x04: databits = 7; break;
case 0x06: databits = 8; break;
default: databits = 0; break;
}
if ((config & 0x30) == 0x30) {
parity = UART_PARITY_ODD;
databits++;
}
else if ((config & 0x20) == 0x20) {
parity = UART_PARITY_EVEN;
databits++;
}
else
parity = UART_PARITY_NONE;
stopbits = ((config & 0x08) == 0x08) ? UART_STOPBITS_2 : UART_STOPBITS_1;
switch (databits) {
#ifdef UART_WORDLENGTH_7B
case 7: databits = UART_WORDLENGTH_7B; break;
#endif
case 8: databits = UART_WORDLENGTH_8B; break;
case 9: databits = UART_WORDLENGTH_9B; break;
default:
case 0: Error_Handler(); break;
}
uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits);
enableHalfDuplexRx();
if (baud == WIFI_BAUDRATE)
uart_attach_rx_callback(&_serial, _rx_complete_irq);
else
USART1->CR1 |= USART_CR1_RE; // Preserve word length, etc. Use 'or' to preserve USART_CR1_M_8N1
}
void WifiSerial::end() {
// wait for transmission of outgoing data
flush();
uart_deinit(&_serial);
// clear any received data
_serial.rx_head = _serial.rx_tail;
}
int WifiSerial::available() {
return ((unsigned int)(WIFI_RX_BUF_SIZE + _serial.rx_head - _serial.rx_tail)) % WIFI_RX_BUF_SIZE;
}
//
// I/O
//
int WifiSerial::read() {
enableHalfDuplexRx();
// if the head isn't ahead of the tail, we don't have any characters
if (_serial.rx_head == _serial.rx_tail) return -1;
unsigned char c = _serial.rx_buff[_serial.rx_tail];
_serial.rx_tail = (rx_buffer_index_t)(_serial.rx_tail + 1) % WIFI_RX_BUF_SIZE;
return c;
}
int WifiSerial::write(uint8_t c) {
_written = true;
if (isHalfDuplex()) {
if (_rx_enabled) {
_rx_enabled = false;
uart_enable_tx(&_serial);
}
}
tx_buffer_index_t i = (_serial.tx_head + 1) % WIFI_TX_BUF_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
while (i == _serial.tx_tail) {
// nop, the interrupt handler will free up space for us
}
_serial.tx_buff[_serial.tx_head] = c;
_serial.tx_head = i;
if (!serial_tx_active(&_serial))
uart_attach_tx_callback(&_serial, _tx_complete_irq);
return 1;
}
#endif // HAS_TFT_LVGL_UI && MKS_WIFI_MODULE
#endif // !__STM32F1__

63
Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32.h

@ -0,0 +1,63 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <inttypes.h>
#include "Stream.h"
#include "uart.h"
class WifiSerial {
protected:
// Has any byte been written to the UART since begin()
bool _written;
serial_t _serial;
public:
uint8_t wifiRxBuf[WIFI_RX_BUF_SIZE];
uint8_t wifiTxBuf[WIFI_TX_BUF_SIZE];
WifiSerial(void *peripheral);
// Set up / tear down
void begin(uint32_t baud);
void begin(uint32_t baud,uint8_t config);
void end();
int available(void);
int read(void);
int write(uint8_t);
// Interrupt handlers
static int _tx_complete_irq(serial_t *obj);
static void _rx_complete_irq(serial_t *obj);
void flush(void);
bool isHalfDuplex(void) const;
void enableHalfDuplexRx(void);
private:
void setRx(uint32_t _rx);
void setTx(uint32_t _tx);
void setRx(PinName _rx);
void setTx(PinName _tx);
void init(PinName _rx, PinName _tx);
bool _rx_enabled;
uint8_t _config;
unsigned long _baud;
};

18
Marlin/src/lcd/extui/mks_ui/wifiSerial.cpp → Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32F1.cpp

@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
@ -19,14 +19,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifdef __STM32F1__
#include "../../../inc/MarlinConfigPre.h"
#if HAS_TFT_LVGL_UI
#if BOTH(HAS_TFT_LVGL_UI, MKS_WIFI_MODULE)
#include "tft_lvgl_configuration.h"
#if ENABLED(MKS_WIFI_MODULE)
#include "draw_ui.h"
#include "wifiSerial.h"
@ -59,19 +59,19 @@ WifiSerial::WifiSerial(usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) {
if (with_irq) usart_enable(usart_device);
else {
usart_reg_map *regs = usart_device->regs;
regs->CR1 |= (USART_CR1_TE | USART_CR1_RE); // don't change the word length etc, and 'or' in the pattern not overwrite |USART_CR1_M_8N1);
regs->CR1 |= (USART_CR1_TE | USART_CR1_RE); // Preserve word length, etc. Use 'or' to preserve USART_CR1_M_8N1
regs->CR1 |= USART_CR1_UE;
}
}
#elif STM32_MCU_SERIES == STM32_SERIES_F2 || STM32_MCU_SERIES == STM32_SERIES_F4
#define disable_timer_if_necessary(dev, ch) ((void)0)
#define disable_timer_if_necessary(dev, ch) NOOP
static void usart_enable_no_irq(usart_dev *usart_device, bool with_irq) {
if (with_irq) usart_enable(usart_device);
else {
usart_reg_map *regs = usart_device->regs;
regs->CR1 |= (USART_CR1_TE | USART_CR1_RE); // don't change the word length etc, and 'or' in the pattern not overwrite |USART_CR1_M_8N1);
regs->CR1 |= (USART_CR1_TE | USART_CR1_RE); // Preserve word length, etc. Use 'or' to preserve USART_CR1_M_8N1
regs->CR1 |= USART_CR1_UE;
}
}
@ -137,5 +137,5 @@ int WifiSerial::wifi_rb_is_full() {
return rb_is_full(this->usart_device->rb);
}
#endif // MKS_WIFI_MODULE
#endif // HAS_TFT_LVGL_UI
#endif // HAS_TFT_LVGL_UI && MKS_WIFI_MODULE
#endif // __STM32F1__

77
Marlin/src/lcd/extui/mks_ui/wifiSerial_STM32F1.h

@ -0,0 +1,77 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <libmaple/libmaple_types.h>
#include <libmaple/usart.h>
#include <libmaple/libmaple.h>
#include <libmaple/gpio.h>
#include <libmaple/timer.h>
#include <libmaple/ring_buffer.h>
#define DEFINE_WFSERIAL(name, n) WifiSerial name(USART##n, BOARD_USART##n##_TX_PIN, BOARD_USART##n##_RX_PIN)
class WifiSerial {
public:
uint8 wifiRxBuf[WIFI_RX_BUF_SIZE];
public:
WifiSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin);
/* Set up/tear down */
void begin(uint32 baud);
void begin(uint32 baud,uint8_t config);
void end();
int available();
int read();
int write(uint8_t);
inline void wifi_usart_irq(usart_reg_map *regs) {
/* Handling RXNEIE and TXEIE interrupts.
* RXNE signifies availability of a byte in DR.
*
* See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
* We enable RXNEIE.
*/
if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
#ifdef USART_SAFE_INSERT
/* If the buffer is full and the user defines USART_SAFE_INSERT,
* ignore new bytes. */
rb_safe_insert(this->usart_device->rb, (uint8)regs->DR);
#else
/* By default, push bytes around in the ring buffer. */
rb_push_insert(this->usart_device->rb, (uint8)regs->DR);
#endif
}
/* TXE signifies readiness to send a byte to DR. */
if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
if (!rb_is_empty(this->usart_device->wb))
regs->DR=rb_remove(this->usart_device->wb);
else
regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
}
}
int wifi_rb_is_full();
struct usart_dev *usart_device;
private:
uint8 tx_pin;
uint8 rx_pin;
};

546
Marlin/src/lcd/extui/mks_ui/wifi_module.cpp

@ -58,10 +58,6 @@ extern uint8_t Explore_Disk (char *path , uint8_t recu_level);
extern uint8_t commands_in_queue;
extern uint8_t sel_id;
int usartFifoAvailable(SZ_USART_FIFO *fifo);
int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len);
int writeUsartFifo(SZ_USART_FIFO * fifo, int8_t * buf, int32_t len);
extern unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick);
volatile SZ_USART_FIFO WifiRxFifo;
@ -84,7 +80,7 @@ extern volatile uint8_t get_temp_flag;
int upload_result = 0;
uint32_t upload_time = 0;
uint32_t upload_time_sec = 0;
uint32_t upload_size = 0;
volatile WIFI_STATE wifi_link_state;
@ -120,29 +116,19 @@ extern bool flash_dma_mode;
uint32_t getWifiTick() { return millis(); }
uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick) {
if (lastTick <= curTick)
return (curTick - lastTick) * TICK_CYCLE;
else
return (0xFFFFFFFF - lastTick + curTick) * TICK_CYCLE;
return (lastTick <= curTick ? curTick - lastTick : 0xFFFFFFFF - lastTick + curTick) * TICK_CYCLE;
}
void wifi_delay(int n) {
uint32_t begin = getWifiTick();
uint32_t end = begin;
while (getWifiTickDiff(begin, end) < (uint32_t)n) {
const uint32_t start = getWifiTick();
while (getWifiTickDiff(start, getWifiTick()) < (uint32_t)n)
watchdog_refresh();
end = getWifiTick();
}
}
void wifi_reset() {
uint32_t start, now;
start = getWifiTick();
now = start;
uint32_t start = getWifiTick();
WIFI_RESET();
while (getWifiTickDiff(start, now) < 500)
now = getWifiTick();
while (getWifiTickDiff(start, getWifiTick()) < 500) { /* nada */ }
WIFI_SET();
}
@ -154,61 +140,62 @@ void mount_file_sys(uint8_t disk_type) {
}
}
#include <libmaple/timer.h>
#include <libmaple/util.h>
#include <libmaple/rcc.h>
#include <boards.h>
#include <wirish.h>
#include <libmaple/dma.h>
#include <libmaple/bitband.h>
#include <libmaple/libmaple.h>
#include <libmaple/gpio.h>
#include <libmaple/usart.h>
#include <libmaple/ring_buffer.h>
void changeFlashMode(const bool dmaMode) {
if (flash_dma_mode != dmaMode) {
flash_dma_mode = dmaMode;
if (!flash_dma_mode) {
dma_disable(DMA1, DMA_CH5);
dma_clear_isr_bits(DMA1, DMA_CH4);
}
}
}
static bool longName2DosName(const char *longName, char *dosName) {
uint8_t i;
for (i = FILENAME_LENGTH; i--;) dosName[i] = '\0';
uint8_t i = FILENAME_LENGTH;
while (i) dosName[--i] = '\0';
while (*longName) {
uint8_t c = *longName++;
if (c == '.') { // For a dot...
if (i == 0) return false;
strcat_P(dosName, PSTR(".GCO"));
break;
return dosName[0] != '\0';
}
else {
if (c < 0x21 || c == 0x7F) return false; // Check size, non-printable characters
// Fail for illegal characters
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
while (const uint8_t b = pgm_read_byte(p++)) if (b == c) return false;
dosName[i++] = c + (WITHIN(c, 'a', 'z') ? 'A' - 'a' : 0); // Uppercase required for 8.3 name
while (uint8_t b = pgm_read_byte(p++)) if (b == c) return false;
if (c < 0x21 || c == 0x7F) return false; // Check size, non-printable characters
dosName[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a')); // Uppercase required for 8.3 name
}
if (i >= 5) {
strcat_P(dosName, PSTR("~1.GCO"));
break;
return dosName[0] != '\0';
}
}
return dosName[0] != '\0'; // Return true if any name was set
}
static int storeRcvData(volatile uint8_t *bufToCpy, int32_t len) {
unsigned char tmpW = wifiDmaRcvFifo.write_cur;
#ifdef __STM32F1__
if (len > UDISKBUFLEN) return 0;
#include <libmaple/timer.h>
#include <libmaple/util.h>
#include <libmaple/rcc.h>
#include <boards.h>
#include <wirish.h>
#include <libmaple/dma.h>
#include <libmaple/bitband.h>
#include <libmaple/libmaple.h>
#include <libmaple/gpio.h>
#include <libmaple/usart.h>
#include <libmaple/ring_buffer.h>
void changeFlashMode(const bool dmaMode) {
if (flash_dma_mode != dmaMode) {
flash_dma_mode = dmaMode;
if (!flash_dma_mode) {
dma_disable(DMA1, DMA_CH5);
dma_clear_isr_bits(DMA1, DMA_CH4);
}
}
}
static int storeRcvData(volatile uint8_t *bufToCpy, int32_t len) {
unsigned char tmpW = wifiDmaRcvFifo.write_cur;
if (len > UDISKBUFLEN) return 0;
if (wifiDmaRcvFifo.state[tmpW] == udisk_buf_empty) {
memcpy((unsigned char *) wifiDmaRcvFifo.bufferAddr[tmpW], (uint8_t *)bufToCpy, len);
wifiDmaRcvFifo.state[tmpW] = udisk_buf_full;
@ -216,9 +203,9 @@ static int storeRcvData(volatile uint8_t *bufToCpy, int32_t len) {
return 1;
}
return 0;
}
}
static void esp_dma_pre() {
static void esp_dma_pre() {
dma_channel_reg_map *channel_regs = dma_tube_regs(DMA1, DMA_CH5);
CBI32(channel_regs->CCR, 0);
@ -227,9 +214,9 @@ static void esp_dma_pre() {
channel_regs->CNDTR = UART_RX_BUFFER_SIZE;
DMA1->regs->IFCR = 0xF0000;
SBI32(channel_regs->CCR, 0);
}
}
static void dma_ch5_irq_handle() {
static void dma_ch5_irq_handle() {
uint8 status_bits = dma_get_isr_bits(DMA1, DMA_CH5);
dma_clear_isr_bits(DMA1, DMA_CH5);
if (status_bits & 0x8) {
@ -254,9 +241,9 @@ static void dma_ch5_irq_handle() {
// DMA transmit half
WIFI_IO1_SET();
}
}
}
static void wifi_usart_dma_init() {
static void wifi_usart_dma_init() {
dma_init(DMA1);
uint32_t flags = ( DMA_MINC_MODE | DMA_TRNS_CMPLT | DMA_HALF_TRNS | DMA_TRNS_ERR);
dma_xfer_size dma_bit_size = DMA_SIZE_8BITS;
@ -279,49 +266,304 @@ static void wifi_usart_dma_init() {
memset(wifiDmaRcvFifo.bufferAddr[0], 0, 1024 * TRANS_RCV_FIFO_BLOCK_NUM);
wifiDmaRcvFifo.read_cur = 0;
wifiDmaRcvFifo.write_cur = 0;
}
}
void esp_port_begin(uint8_t interrupt) {
void esp_port_begin(uint8_t interrupt) {
WifiRxFifo.uart_read_point = 0;
WifiRxFifo.uart_write_point = 0;
#if 1
#if ENABLED(MKS_WIFI_MODULE)
WIFISERIAL.end();
if (interrupt) {
WIFISERIAL.end();
for (uint16_t i = 0; i < 65535; i++) { /*nada*/ }
WIFISERIAL.begin(WIFI_BAUDRATE);
millis_t serial_connect_timeout = millis() + 1000UL;
while (PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
}
else {
WIFISERIAL.end();
WIFISERIAL.usart_device->regs->CR1 &= ~USART_CR1_RXNEIE;
WIFISERIAL.begin(WIFI_UPLOAD_BAUDRATE);
wifi_usart_dma_init();
}
#endif
}
#else // !__STM32F1__
DMA_HandleTypeDef wifiUsartDMArx;
void changeFlashMode(const bool dmaMode) {
if (flash_dma_mode != dmaMode) {
flash_dma_mode = dmaMode;
if (flash_dma_mode == 1) {
}
else {
}
}
}
#ifdef STM32F1xx
HAL_StatusTypeDef HAL_DMA_PollForTransferCustomize(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout) {
uint32_t temp;
uint32_t tickstart = 0U;
if (HAL_DMA_STATE_BUSY != hdma->State) { // No transfer ongoing
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
__HAL_UNLOCK(hdma);
return HAL_ERROR;
}
// Polling mode not supported in circular mode
if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC)) {
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
return HAL_ERROR;
}
// Get the level transfer complete flag
temp = (CompleteLevel == HAL_DMA_FULL_TRANSFER
? __HAL_DMA_GET_TC_FLAG_INDEX(hdma) // Transfer Complete flag
: __HAL_DMA_GET_HT_FLAG_INDEX(hdma) // Half Transfer Complete flag
);
// Get tick
tickstart = HAL_GetTick();
while (__HAL_DMA_GET_FLAG(hdma, temp) == RESET) {
if ((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)) != RESET)) {
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); // Clear the half transfer complete flag
WIFI_IO1_SET();
}
if ((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)) {
/**
* When a DMA transfer error occurs
* A hardware clear of its EN bits is performed
* Clear all flags
*/
hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TE); // Update error code
hdma->State= HAL_DMA_STATE_READY; // Change the DMA state
__HAL_UNLOCK(hdma); // Process Unlocked
return HAL_ERROR;
}
// Check for the Timeout
if (Timeout != HAL_MAX_DELAY && (!Timeout || (HAL_GetTick() - tickstart) > Timeout)) {
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT); // Update error code
hdma->State = HAL_DMA_STATE_READY; // Change the DMA state
__HAL_UNLOCK(hdma); // Process Unlocked
return HAL_ERROR;
}
}
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
// Clear the transfer complete flag
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
/* The selected Channelx EN bit is cleared (DMA is disabled and
all transfers are complete) */
hdma->State = HAL_DMA_STATE_READY;
}
else
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); // Clear the half transfer complete flag
__HAL_UNLOCK(hdma); // Process unlocked
return HAL_OK;
}
#else // !STM32F1xx
typedef struct {
__IO uint32_t ISR; //!< DMA interrupt status register
__IO uint32_t Reserved0;
__IO uint32_t IFCR; //!< DMA interrupt flag clear register
} MYDMA_Base_Registers;
HAL_StatusTypeDef HAL_DMA_PollForTransferCustomize(DMA_HandleTypeDef *hdma, HAL_DMA_LevelCompleteTypeDef CompleteLevel, uint32_t Timeout) {
HAL_StatusTypeDef status = HAL_OK;
uint32_t mask_cpltlevel;
uint32_t tickstart = HAL_GetTick();
uint32_t tmpisr;
MYDMA_Base_Registers *regs; // Calculate DMA base and stream number
if (HAL_DMA_STATE_BUSY != hdma->State) { // No transfer ongoing
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
__HAL_UNLOCK(hdma);
return HAL_ERROR;
}
// Polling mode not supported in circular mode and double buffering mode
if ((hdma->Instance->CR & DMA_SxCR_CIRC) != RESET) {
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
return HAL_ERROR;
}
// Get the level transfer complete flag
mask_cpltlevel = (CompleteLevel == HAL_DMA_FULL_TRANSFER
? DMA_FLAG_TCIF0_4 << hdma->StreamIndex // Transfer Complete flag
: DMA_FLAG_HTIF0_4 << hdma->StreamIndex // Half Transfer Complete flag
);
regs = (MYDMA_Base_Registers *)hdma->StreamBaseAddress;
tmpisr = regs->ISR;
while (((tmpisr & mask_cpltlevel) == RESET) && ((hdma->ErrorCode & HAL_DMA_ERROR_TE) == RESET)) {
// Check for the Timeout (Not applicable in circular mode)
if (Timeout != HAL_MAX_DELAY) {
if (!Timeout || (HAL_GetTick() - tickstart) > Timeout) {
hdma->ErrorCode = HAL_DMA_ERROR_TIMEOUT; // Update error code
__HAL_UNLOCK(hdma); // Process Unlocked
hdma->State = HAL_DMA_STATE_READY; // Change the DMA state
return HAL_TIMEOUT;
}
}
tmpisr = regs->ISR; // Get the ISR register value
if ((tmpisr & (DMA_FLAG_HTIF0_4 << hdma->StreamIndex)) != RESET) {
regs->IFCR = DMA_FLAG_HTIF0_4 << hdma->StreamIndex; // Clear the Direct Mode error flag
WIFI_IO1_SET();
}
if ((tmpisr & (DMA_FLAG_TEIF0_4 << hdma->StreamIndex)) != RESET) {
hdma->ErrorCode |= HAL_DMA_ERROR_TE; // Update error code
regs->IFCR = DMA_FLAG_TEIF0_4 << hdma->StreamIndex; // Clear the transfer error flag
}
if ((tmpisr & (DMA_FLAG_FEIF0_4 << hdma->StreamIndex)) != RESET) {
hdma->ErrorCode |= HAL_DMA_ERROR_FE; // Update error code
regs->IFCR = DMA_FLAG_FEIF0_4 << hdma->StreamIndex; // Clear the FIFO error flag
}
if ((tmpisr & (DMA_FLAG_DMEIF0_4 << hdma->StreamIndex)) != RESET) {
hdma->ErrorCode |= HAL_DMA_ERROR_DME; // Update error code
regs->IFCR = DMA_FLAG_DMEIF0_4 << hdma->StreamIndex; // Clear the Direct Mode error flag
}
}
if (hdma->ErrorCode != HAL_DMA_ERROR_NONE && (hdma->ErrorCode & HAL_DMA_ERROR_TE) != RESET) {
HAL_DMA_Abort(hdma);
regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex; // Clear the half transfer and transfer complete flags
__HAL_UNLOCK(hdma); // Process Unlocked
hdma->State= HAL_DMA_STATE_READY; // Change the DMA state
return HAL_ERROR;
}
// Get the level transfer complete flag
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
regs->IFCR = (DMA_FLAG_HTIF0_4 | DMA_FLAG_TCIF0_4) << hdma->StreamIndex; // Clear the half transfer and transfer complete flags
__HAL_UNLOCK(hdma); // Process Unlocked
hdma->State = HAL_DMA_STATE_READY;
}
else
regs->IFCR = (DMA_FLAG_HTIF0_4) << hdma->StreamIndex; // Clear the half transfer and transfer complete flags
return status;
}
#endif
static void dmaTransmitBegin() {
wifiUsartDMArx.Init.MemInc = DMA_MINC_ENABLE;
if (HAL_DMA_Init((DMA_HandleTypeDef *)&wifiUsartDMArx) != HAL_OK)
Error_Handler();
if (HAL_DMA_Start(&wifiUsartDMArx, (uint32_t)&(USART1->DR), (uint32_t)WIFISERIAL.wifiRxBuf, UART_RX_BUFFER_SIZE))
Error_Handler();
USART1->CR1 |= USART_CR1_UE;
SET_BIT(USART1->CR3, USART_CR3_DMAR);
WIFI_IO1_RESET();
}
static int storeRcvData(volatile uint8_t *bufToCpy, int32_t len) {
unsigned char tmpW = wifiDmaRcvFifo.write_cur;
if (len > UDISKBUFLEN) return 0;
if (wifiDmaRcvFifo.state[tmpW] == udisk_buf_empty) {
const int timeOut = 2000; //millisecond
dmaTransmitBegin();
if (HAL_DMA_PollForTransferCustomize(&wifiUsartDMArx, HAL_DMA_FULL_TRANSFER, timeOut) == HAL_OK) {
memcpy((unsigned char *) wifiDmaRcvFifo.bufferAddr[tmpW], (uint8_t *)bufToCpy, len);
wifiDmaRcvFifo.state[tmpW] = udisk_buf_full;
wifiDmaRcvFifo.write_cur = (tmpW + 1) % TRANS_RCV_FIFO_BLOCK_NUM;
return 1;
}
}
return 0;
}
static void wifi_usart_dma_init() {
#ifdef STM32F1xx
__HAL_RCC_DMA1_CLK_ENABLE();
wifiUsartDMArx.Instance = DMA1_Channel5;
#else
__HAL_RCC_DMA2_CLK_ENABLE();
wifiUsartDMArx.Instance = DMA2_Stream2;
wifiUsartDMArx.Init.Channel = DMA_CHANNEL_4;
#endif
wifiUsartDMArx.Init.Direction = DMA_PERIPH_TO_MEMORY;
wifiUsartDMArx.Init.PeriphInc = DMA_PINC_DISABLE;
wifiUsartDMArx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
wifiUsartDMArx.Init.MemDataAlignment = DMA_PDATAALIGN_BYTE;
wifiUsartDMArx.Init.Mode = DMA_NORMAL;
#ifdef STM32F4xx
wifiUsartDMArx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
#endif
wifiUsartDMArx.Init.MemInc = DMA_MINC_ENABLE;
if (HAL_DMA_Init((DMA_HandleTypeDef *)&wifiUsartDMArx) != HAL_OK)
Error_Handler();
if (HAL_DMA_Start(&wifiUsartDMArx, (uint32_t)&(USART1->DR), (uint32_t)WIFISERIAL.wifiRxBuf, UART_RX_BUFFER_SIZE))
Error_Handler();
USART1->CR1 |= USART_CR1_UE;
SET_BIT(USART1->CR3, USART_CR3_DMAR); // Enable Rx DMA Request
for (uint8_t i = 0; i < TRANS_RCV_FIFO_BLOCK_NUM; i++) {
wifiDmaRcvFifo.bufferAddr[i] = &bmp_public_buf[1024 * i];
wifiDmaRcvFifo.state[i] = udisk_buf_empty;
}
#if MKS_WIFI_MODULE
memset(wifiDmaRcvFifo.bufferAddr[0], 0, 1024 * TRANS_RCV_FIFO_BLOCK_NUM);
wifiDmaRcvFifo.read_cur = 0;
wifiDmaRcvFifo.write_cur = 0;
}
void esp_port_begin(uint8_t interrupt) {
WifiRxFifo.uart_read_point = 0;
WifiRxFifo.uart_write_point = 0;
#if ENABLED(MKS_WIFI_MODULE)
if (interrupt) {
WIFISERIAL.end();
for (uint16_t i = 0; i < 65535; i++) { /*nada*/ }
WIFISERIAL.begin(interrupt ? WIFI_BAUDRATE : WIFI_UPLOAD_BAUDRATE);
millis_t serial_connect_timeout = millis() + 1000UL;
WIFISERIAL.begin(WIFI_BAUDRATE);
uint32_t serial_connect_timeout = millis() + 1000UL;
while (PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
}
else {
WIFISERIAL.end();
USART1->CR1 &= ~USART_CR1_RXNEIE;
WIFISERIAL.begin(WIFI_UPLOAD_BAUDRATE);
wifi_usart_dma_init();
}
#endif
if (!interrupt) wifi_usart_dma_init();
}
#endif
}
#endif // !__STM32F1__
#if ENABLED(MKS_WIFI_MODULE)
int raw_send_to_wifi(uint8_t *buf, int len) {
if (buf == 0 || len <= 0) return 0;
for (int i = 0; i < len; i++)
WIFISERIAL.write(*(buf + i));
for (int i = 0; i < len; i++) WIFISERIAL.write(*(buf + i));
return len;
}
@ -336,9 +578,9 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
uint8_t wifi_ret_tail = 0xFC;
if (type == WIFI_PARA_SET) {
int data_offset = 4;
int apLen = strlen((const char *)uiCfg.wifi_name);
int keyLen = strlen((const char *)uiCfg.wifi_key);
int data_offset = 4,
apLen = strlen((const char *)uiCfg.wifi_name),
keyLen = strlen((const char *)uiCfg.wifi_key);
ZERO(buf_to_wifi);
index_to_wifi = 0;
@ -378,9 +620,9 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
if (buf_to_wifi[index_to_wifi + 3] == '\n') {
// mask "wait" "busy" "X:"
if (((buf_to_wifi[4] == 'w') && (buf_to_wifi[5] == 'a') && (buf_to_wifi[6] == 'i') && (buf_to_wifi[7] == 't') )
|| ((buf_to_wifi[4] == 'b') && (buf_to_wifi[5] == 'u') && (buf_to_wifi[6] == 's') && (buf_to_wifi[7] == 'y') )
|| ((buf_to_wifi[4] == 'X') && (buf_to_wifi[5] == ':') )
if ( ((buf_to_wifi[4] == 'w') && (buf_to_wifi[5] == 'a') && (buf_to_wifi[6] == 'i') && (buf_to_wifi[7] == 't'))
|| ((buf_to_wifi[4] == 'b') && (buf_to_wifi[5] == 'u') && (buf_to_wifi[6] == 's') && (buf_to_wifi[7] == 'y'))
|| ((buf_to_wifi[4] == 'X') && (buf_to_wifi[5] == ':'))
) {
ZERO(buf_to_wifi);
index_to_wifi = 0;
@ -458,6 +700,7 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
return 1;
}
#define SEND_OK_TO_WIFI send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n"))
int send_to_wifi(uint8_t *buf, int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
@ -651,13 +894,10 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
}
break;
case 21:
/*init sd card*/
SEND_OK_TO_WIFI;
break;
case 21: SEND_OK_TO_WIFI; break; // Init SD card
case 23:
/*select the file*/
// Select the file
if (uiCfg.print_state == IDLE) {
int index = 0;
while (tmpStr[index] == ' ') index++;
@ -747,8 +987,10 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
if (card.isFileOpen()) {
//saved_feedrate_percentage = feedrate_percentage;
feedrate_percentage = 100;
#if EXTRUDERS
planner.flow_percentage[0] = 100;
planner.e_factor[0] = planner.flow_percentage[0] * 0.01f;
#endif
#if EXTRUDERS == 2
planner.flow_percentage[1] = 100;
planner.e_factor[1] = planner.flow_percentage[1] * 0.01f;
@ -786,7 +1028,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
break;
case 25:
/*pause print file*/
// Pause print file
if (uiCfg.print_state == WORKING) {
stop_print_time();
@ -806,7 +1048,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
break;
case 26:
/*stop print file*/
// Stop print file
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED) || (uiCfg.print_state == REPRINTING)) {
stop_print_time();
@ -823,7 +1065,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
break;
case 27:
/*report print rate*/
// Report print rate
if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)|| (uiCfg.print_state == REPRINTING)) {
print_rate = uiCfg.totalSend;
ZERO(tempBuf);
@ -833,7 +1075,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
break;
case 28:
/*begin to transfer file to filesys*/
// Begin to transfer file to filesys
if (uiCfg.print_state == IDLE) {
int index = 0;
@ -887,7 +1129,6 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
sprintf_P(tbuf, PSTR("%d /%d"), thermalManager.wholeDegHotend(0), thermalManager.degTargetHotend(0));
const int tlen = strlen(tbuf);
sprintf_P(outBuf, PSTR("T:%s"), tbuf);
outBuf += 2 + tlen;
@ -909,7 +1150,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
#if HAS_MULTI_HOTEND
sprintf_P(outBuf, PSTR("%d /%d"), thermalManager.wholeDegHotend(1), thermalManager.degTargetHotend(1));
#else
strcat_P(outBuf, PSTR("0 /0"));
strcpy_P(outBuf, PSTR("0 /0"));
#endif
outBuf += 4;
@ -918,17 +1159,11 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
else {
sprintf_P((char *)tempBuf, PSTR("T:%d /%d B:%d /%d T0:%d /%d T1:%d /%d @:0 B@:0\r\n"),
thermalManager.wholeDegHotend(0), thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
thermalManager.wholeDegBed(), thermalManager.degTargetBed(),
#else
0, 0,
#endif
TERN0(HAS_HEATED_BED, thermalManager.wholeDegBed()),
TERN0(HAS_HEATED_BED, thermalManager.degTargetBed()),
thermalManager.wholeDegHotend(0), thermalManager.degTargetHotend(0),
#if HAS_MULTI_HOTEND
thermalManager.wholeDegHotend(1), thermalManager.degTargetHotend(1)
#else
0, 0
#endif
TERN0(HAS_MULTI_HOTEND, thermalManager.wholeDegHotend(1)),
TERN0(HAS_MULTI_HOTEND, thermalManager.degTargetHotend(1))
);
}
@ -977,11 +1212,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
case 998:
if (uiCfg.print_state == IDLE) {
int v = atoi((char *)tmpStr);
if (v == 0)
set_cur_file_sys(0);
else if (v == 1)
set_cur_file_sys(1);
const int v = atoi((char *)tmpStr);
if (v == 0 || v == 1) set_cur_file_sys(v);
wifi_ret_ack();
}
break;
@ -996,18 +1228,14 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
strcat_P((char *)cmd_line, PSTR("\n"));
if (espGcodeFifo.wait_tick > 5) {
uint32_t left;
if (espGcodeFifo.r > espGcodeFifo.w)
left = espGcodeFifo.r - espGcodeFifo.w - 1;
else
left = WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
const uint32_t left = espGcodeFifo.r > espGcodeFifo.w
? espGcodeFifo.r - espGcodeFifo.w - 1
: WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
if (left >= strlen((const char *)cmd_line)) {
uint32_t index = 0;
while (index < strlen((const char *)cmd_line)) {
for (uint32_t index = 0; index < strlen((const char *)cmd_line); index++) {
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index] ;
espGcodeFifo.w = (espGcodeFifo.w + 1) % WIFI_GCODE_BUFFER_SIZE;
index++;
}
if (left - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
SEND_OK_TO_WIFI;
@ -1022,18 +1250,14 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
strcat_P((char *)cmd_line, PSTR("\n"));
if (espGcodeFifo.wait_tick > 5) {
uint32_t left_g;
if (espGcodeFifo.r > espGcodeFifo.w)
left_g = espGcodeFifo.r - espGcodeFifo.w - 1;
else
left_g = WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
const uint32_t left_g = espGcodeFifo.r > espGcodeFifo.w
? espGcodeFifo.r - espGcodeFifo.w - 1
: WIFI_GCODE_BUFFER_SIZE + espGcodeFifo.r - espGcodeFifo.w - 1;
if (left_g >= strlen((const char *)cmd_line)) {
uint32_t index = 0;
while (index < strlen((const char *)cmd_line)) {
for (uint32_t index = 0; index < strlen((const char *)cmd_line); index++) {
espGcodeFifo.Buffer[espGcodeFifo.w] = cmd_line[index] ;
espGcodeFifo.w = (espGcodeFifo.w + 1) % WIFI_GCODE_BUFFER_SIZE;
index++;
}
if (left_g - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
SEND_OK_TO_WIFI;
@ -1061,11 +1285,10 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
if (msgLen <= 0) return;
// ip
// IP address
sprintf_P(ipPara.ip_addr, PSTR("%d.%d.%d.%d"), msg[0], msg[1], msg[2], msg[3]);
// port
// connect state
// port connect state
switch (msg[6]) {
case 0x0A: wifi_link_state = WIFI_CONNECTED; break;
case 0x0E: wifi_link_state = WIFI_EXCEPTION; break;
@ -1075,7 +1298,7 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
// mode
wifiPara.mode = msg[7];
// wifi name
// WiFi name
wifiNameLen = msg[8];
wifiKeyLen = msg[9 + wifiNameLen];
if (wifiNameLen < 32) {
@ -1085,7 +1308,7 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
memset(&wifi_list.wifiConnectedName, 0, sizeof(wifi_list.wifiConnectedName));
memcpy(&wifi_list.wifiConnectedName, &msg[9], wifiNameLen);
// wifi key
// WiFi key
if (wifiKeyLen < 64) {
ZERO(wifiPara.keyCode);
memcpy(wifiPara.keyCode, &msg[10 + wifiNameLen], wifiKeyLen);
@ -1102,7 +1325,7 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
cloud_para.port = msg[12 + wifiNameLen + wifiKeyLen + hostLen] + (msg[13 + wifiNameLen + wifiKeyLen + hostLen] << 8);
}
// id
// ID
id_len = msg[14 + wifiNameLen + wifiKeyLen + hostLen];
if (id_len == 20) {
ZERO(cloud_para.id);
@ -1125,10 +1348,10 @@ static void net_msg_handle(uint8_t * msg, uint16_t msgLen) {
if (cfg_cloud_flag == 1) {
if (((cloud_para.state >> 4) != (char)gCfgItems.cloud_enable)
|| (strncmp(cloud_para.hostUrl, (const char *)uiCfg.cloud_hostUrl, 96) != 0)
|| (cloud_para.port != uiCfg.cloud_port)) {
package_to_wifi(WIFI_CLOUD_CFG, (uint8_t *)0, 0);
}
else cfg_cloud_flag = 0;
|| (cloud_para.port != uiCfg.cloud_port)
) package_to_wifi(WIFI_CLOUD_CFG, (uint8_t *)0, 0);
else
cfg_cloud_flag = 0;
}
}
@ -1366,6 +1589,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
lastFragment = frag;
if ((frag & (~FRAG_MASK)) != 0) {
wifiDmaRcvFifo.receiveEspData = false;
int res = upload_file.write(public_buf, file_writer.write_index);
if (res == -1) {
upload_file.close();
@ -1392,7 +1616,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
ZERO(public_buf);
file_writer.write_index = 0;
file_writer.tick_end = getWifiTick();
upload_time = getWifiTickDiff(file_writer.tick_begin, file_writer.tick_end) / 1000;
upload_time_sec = getWifiTickDiff(file_writer.tick_begin, file_writer.tick_end) / 1000;
upload_size = gCfgItems.curFilesize;
wifi_link_state = WIFI_CONNECTED;
upload_result = 3;
@ -1540,9 +1764,16 @@ void stopEspTransfer() {
WIFI_IO1_SET();
// disable dma
#ifdef __STM32F1__
dma_clear_isr_bits(DMA1, DMA_CH5);
bb_peri_set_bit(&USART1_BASE->CR3, USART_CR3_DMAR_BIT, 0);
dma_disable(DMA1, DMA_CH5);
#else
// First, abort any running dma
HAL_DMA_Abort(&wifiUsartDMArx);
// DeInit objects
HAL_DMA_DeInit(&wifiUsartDMArx);
#endif
wifi_delay(200);
changeFlashMode(true); // Set SPI flash to use DMA mode
@ -1571,6 +1802,9 @@ void wifi_rcv_handle() {
}
}
#else
#ifndef __STM32F1__
if (wifiDmaRcvFifo.receiveEspData) storeRcvData(WIFISERIAL.wifiRxBuf, UART_RX_BUFFER_SIZE);
#endif
len = readWifiFifo(ucStr, UART_RX_BUFFER_SIZE);
#endif
if (len > 0) {
@ -1582,15 +1816,16 @@ void wifi_rcv_handle() {
}
getDataF = 1;
}
#ifdef __STM32F1__
if (esp_state == TRANSFER_STORE) {
if (storeRcvData(WIFISERIAL.usart_device->rb->buf, UART_RX_BUFFER_SIZE)) {
if (storeRcvData(WIFISERIAL.wifiRxBuf, UART_RX_BUFFER_SIZE)) {
esp_state = TRANSFERING;
esp_dma_pre();
if (wifiTransError.flag != 0x1) WIFI_IO1_RESET();
}
else
WIFI_IO1_SET();
else WIFI_IO1_SET();
}
#endif
}
else {
len = readWifiBuf((int8_t *)ucStr, UART_RX_BUFFER_SIZE);
@ -1602,6 +1837,10 @@ void wifi_rcv_handle() {
esp_port_begin(0);
wifi_delay(10);
tick_net_time1 = 0;
#ifndef __STM32F1__
wifiDmaRcvFifo.receiveEspData = true;
return;
#endif
}
if (wifiTransError.flag != 0x1) WIFI_IO1_RESET();
getDataF = 1;
@ -1612,9 +1851,8 @@ void wifi_rcv_handle() {
}
}
if (getDataF == 1) {
if (getDataF == 1)
tick_net_time1 = getWifiTick();
}
else {
tick_net_time2 = getWifiTick();
@ -1664,35 +1902,31 @@ void mks_esp_wifi_init() {
esp_state = TRANSFER_IDLE;
esp_port_begin(1);
watchdog_refresh();
wifi_reset();
#if 0
if (update_flag == 0) {
res = f_open(&esp_upload.uploadFile, ESP_WEB_FIRMWARE_FILE, FA_OPEN_EXISTING | FA_READ);
if (res == FR_OK) {
f_close(&esp_upload.uploadFile);
wifi_delay(2000);
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) {
return;
}
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) return;
clear_cur_ui();
draw_dialog(DIALOG_TYPE_UPDATE_ESP_FIRMWARE);
if (wifi_upload(1) >= 0) {
f_unlink("1:/MKS_WIFI_CUR");
f_rename(ESP_WEB_FIRMWARE_FILE,"/MKS_WIFI_CUR");
}
draw_return_ui();
update_flag = 1;
}
}
if (update_flag == 0) {
res = f_open(&esp_upload.uploadFile, ESP_WEB_FILE, FA_OPEN_EXISTING | FA_READ);
if (res == FR_OK) {
@ -1700,16 +1934,13 @@ void mks_esp_wifi_init() {
wifi_delay(2000);
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) {
return;
}
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) return;
clear_cur_ui();
draw_dialog(DIALOG_TYPE_UPDATE_ESP_DATA);
if (wifi_upload(2) >= 0) {
f_unlink("1:/MKS_WEB_CONTROL_CUR");
f_rename(ESP_WEB_FILE,"/MKS_WEB_CONTROL_CUR");
}
@ -1717,21 +1948,22 @@ void mks_esp_wifi_init() {
}
}
#endif
wifiPara.decodeType = WIFI_DECODE_TYPE;
wifiPara.baud = 115200;
wifi_link_state = WIFI_NOT_CONFIG;
}
void mks_wifi_firmware_update() {
watchdog_refresh();
card.openFileRead((char *)ESP_FIRMWARE_FILE);
if (card.isFileOpen()) {
card.closefile();
wifi_delay(2000);
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20)
return;
watchdog_refresh();
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) return;
clear_cur_ui();
@ -1753,12 +1985,6 @@ void mks_wifi_firmware_update() {
}
}
#define BUF_INC_POINTER(p) ((p + 1 == UART_FIFO_BUFFER_SIZE) ? 0:(p + 1))
int usartFifoAvailable(SZ_USART_FIFO *fifo) {
return WIFISERIAL.available();
}
void get_wifi_commands() {
static char wifi_line_buffer[MAX_CMD_SIZE];
static bool wifi_comment_mode = false;
@ -1836,4 +2062,6 @@ int readWifiBuf(int8_t *buf, int32_t len) {
return i;
}
int usartFifoAvailable(SZ_USART_FIFO *fifo) { return WIFISERIAL.available(); }
#endif // HAS_TFT_LVGL_UI && MKS_WIFI_MODULE

4
Marlin/src/lcd/extui/mks_ui/wifi_module.h

@ -64,6 +64,7 @@ typedef enum{
#define TRANS_RCV_FIFO_BLOCK_NUM 14
typedef struct {
bool receiveEspData;
unsigned char *bufferAddr[TRANS_RCV_FIFO_BLOCK_NUM];
unsigned char *p;
UDISK_DATA_BUFFER_STATE state[TRANS_RCV_FIFO_BLOCK_NUM];
@ -191,6 +192,9 @@ void get_wifi_list_command_send();
void get_wifi_commands();
int readWifiBuf(int8_t *buf, int32_t len);
void mks_wifi_firmware_update();
int usartFifoAvailable(SZ_USART_FIFO *fifo);
int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len);
void esp_port_begin(uint8_t interrupt);
#ifdef __cplusplus
} /* C-declarations for C++ */

10
Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp

@ -40,7 +40,6 @@ extern SZ_USART_FIFO WifiRxFifo;
extern int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len);
extern int writeUsartFifo(SZ_USART_FIFO * fifo, int8_t * buf, int32_t len);
void esp_port_begin(uint8_t interrupt);
extern int usartFifoAvailable(SZ_USART_FIFO *fifo);
void wifi_delay(int n);
#define ARRAY_SIZE(a) sizeof(a) / sizeof((a)[0])
@ -280,7 +279,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t
switch (state) {
case begin: // expecting frame start
c = uploadPort_read();
if (c == (uint8_t)0xC0) break;
if (c != (uint8_t)0xC0) break;
state = header;
needBytes = 2;
break;
@ -644,10 +643,7 @@ static const uint32_t FirmwareAddress = 0x00000000, WebFilesAddress = 0x00100000
void ResetWiFiForUpload(int begin_or_end) {
//#if 0
uint32_t start, now;
start = getWifiTick();
now = start;
uint32_t start = getWifiTick();
if (begin_or_end == 0) {
SET_OUTPUT(WIFI_IO0_PIN);
@ -657,7 +653,7 @@ void ResetWiFiForUpload(int begin_or_end) {
SET_INPUT_PULLUP(WIFI_IO0_PIN);
WIFI_RESET();
while (getWifiTickDiff(start, now) < 500) now = getWifiTick();
while (getWifiTickDiff(start, getWifiTick()) < 500) { /* nada */ }
WIFI_SET();
//#endif
}

1
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h

@ -36,6 +36,7 @@
#define BOARD_INFO_NAME "MKS Robin E3P"
#define BOARD_NO_NATIVE_USB
#define MKS_HARDWARE_TEST_ONLY_E0
//
// Release PB4 (Y_ENABLE_PIN) from JTAG NRST role

15
Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h

@ -178,16 +178,16 @@
//
// Misc. Functions
//
#define MT_DET_1 PA4
#define MT_DET_2 PE6
#define MT_DET_1_PIN PA4
#define MT_DET_2_PIN PE6
#define PW_DET PA13
#define PW_OFF PB2
#ifndef FIL_RUNOUT_PIN
#define FIL_RUNOUT_PIN MT_DET_1
#define FIL_RUNOUT_PIN MT_DET_1_PIN
#endif
#ifndef FIL_RUNOUT2_PIN
#define FIL_RUNOUT2_PIN MT_DET_2
#define FIL_RUNOUT2_PIN MT_DET_2_PIN
#endif
#ifndef POWER_LOSS_PIN
@ -214,6 +214,13 @@
#define SDCARD_CONNECTION ONBOARD
#endif
// MKS WIFI MODULE
#if ENABLED(MKS_WIFI_MODULE)
#define WIFI_IO0_PIN PC13 // MKS ESP WIFI IO0 PIN
#define WIFI_IO1_PIN PC7 // MKS ESP WIFI IO1 PIN
#define WIFI_RESET_PIN PE9 // MKS ESP WIFI RESET PIN
#endif
//
// Onboard SD card
//

4
buildroot/tests/mks_robin_nano35

@ -21,8 +21,8 @@ exec_test $1 $2 "MKS Robin nano v1.2 Emulated DOGM FSMC" "$3"
use_example_configs Mks/Robin
opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2
opt_disable TFT_INTERFACE_FSMC
opt_enable TFT_INTERFACE_SPI
exec_test $1 $2 "MKS Robin v2 nano Emulated DOGM SPI" "$3"
opt_enable TFT_INTERFACE_SPI MKS_WIFI_MODULE
exec_test $1 $2 "MKS Robin v2 nano Emulated DOGM SPI, MKS_WIFI_MODULE" "$3"
#
# MKS Robin nano v1.2 LVGL FSMC

3
ini/stm32f1-maple.ini

@ -26,8 +26,7 @@
platform = ststm32@~12.1
board_build.core = maple
build_flags = !python Marlin/src/HAL/STM32F1/build_flags.py
${common.build_flags}
-DARDUINO_ARCH_STM32
${common.build_flags} -DARDUINO_ARCH_STM32 -DMAPLE_STM32F1
build_unflags = -std=gnu11 -std=gnu++11
src_filter = ${common.default_src_filter} +<src/HAL/STM32F1>
lib_ignore = SPI, FreeRTOS701, FreeRTOS821

Loading…
Cancel
Save