My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wifiSerial.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "tft_lvgl_configuration.h"
  24. #if ENABLED(MKS_WIFI_MODULE)
  25. #ifdef SERIAL_PORT_2
  26. #error "SERIAL_PORT_2 must be disabled with TFT_LVGL_UI* and MKS_WIFI_MODULE."
  27. #endif
  28. #define WIFI_BAUDRATE 115200
  29. #define WIFI_UPLOAD_BAUDRATE 1958400
  30. #define USART_SAFE_INSERT
  31. #define WIFI_RX_BUF_SIZE (1024+1)
  32. #include <libmaple/libmaple_types.h>
  33. #include <libmaple/usart.h>
  34. #include <libmaple/libmaple.h>
  35. #include <libmaple/gpio.h>
  36. #include <libmaple/timer.h>
  37. #include <libmaple/ring_buffer.h>
  38. #define DEFINE_WFSERIAL(name, n)\
  39. WifiSerial name(USART##n, \
  40. BOARD_USART##n##_TX_PIN, \
  41. BOARD_USART##n##_RX_PIN)
  42. class WifiSerial {
  43. public:
  44. uint8 wifiRxBuf[WIFI_RX_BUF_SIZE];
  45. public:
  46. WifiSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin);
  47. /* Set up/tear down */
  48. void begin(uint32 baud);
  49. void begin(uint32 baud,uint8_t config);
  50. void end();
  51. int available();
  52. int read();
  53. int write(uint8_t);
  54. inline void wifi_usart_irq(usart_reg_map *regs) {
  55. /* Handling RXNEIE and TXEIE interrupts.
  56. * RXNE signifies availability of a byte in DR.
  57. *
  58. * See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
  59. * We enable RXNEIE.
  60. */
  61. if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
  62. #ifdef USART_SAFE_INSERT
  63. /* If the buffer is full and the user defines USART_SAFE_INSERT,
  64. * ignore new bytes. */
  65. rb_safe_insert(this->usart_device->rb, (uint8)regs->DR);
  66. #else
  67. /* By default, push bytes around in the ring buffer. */
  68. rb_push_insert(this->usart_device->rb, (uint8)regs->DR);
  69. #endif
  70. }
  71. /* TXE signifies readiness to send a byte to DR. */
  72. if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
  73. if (!rb_is_empty(this->usart_device->wb))
  74. regs->DR=rb_remove(this->usart_device->wb);
  75. else
  76. regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
  77. }
  78. }
  79. int wifi_rb_is_full();
  80. struct usart_dev *usart_device;
  81. private:
  82. uint8 tx_pin;
  83. uint8 rx_pin;
  84. };
  85. extern WifiSerial WifiSerial1;
  86. #define WIFISERIAL WifiSerial1
  87. #endif // MKS_WIFI_MODULE