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.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "../../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "tft_lvgl_configuration.h"
  25. #if ENABLED(USE_WIFI_FUNCTION)
  26. #include "draw_ui.h"
  27. #include "wifiSerial.h"
  28. #include <libmaple/libmaple.h>
  29. #include <libmaple/gpio.h>
  30. #include <libmaple/timer.h>
  31. #include <libmaple/usart.h>
  32. #include <libmaple/ring_buffer.h>
  33. #include "../../../../MarlinCore.h"
  34. DEFINE_WFSERIAL(WifiSerial1, 1);
  35. WifiSerial::WifiSerial(usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) {
  36. this->usart_device = usart_device;
  37. this->tx_pin = tx_pin;
  38. this->rx_pin = rx_pin;
  39. }
  40. /**
  41. * Set up / tear down
  42. */
  43. #if STM32_MCU_SERIES == STM32_SERIES_F1
  44. /* F1 MCUs have no GPIO_AFR[HL], so turn off PWM if there's a conflict
  45. * on this GPIO bit. */
  46. static void disable_timer_if_necessary(timer_dev *dev, uint8 ch) {
  47. if (dev != nullptr) timer_set_mode(dev, ch, TIMER_DISABLED);
  48. }
  49. #elif STM32_MCU_SERIES == STM32_SERIES_F2 || STM32_MCU_SERIES == STM32_SERIES_F4
  50. #define disable_timer_if_necessary(dev, ch) ((void)0)
  51. #else
  52. #warning "Unsupported STM32 series; timer conflicts are possible"
  53. #endif
  54. void WifiSerial::begin(uint32 baud) { begin(baud, SERIAL_8N1); }
  55. /**
  56. * Roger Clark.
  57. * Note. The config parameter is not currently used. This is a work in progress.
  58. * Code needs to be written to set the config of the hardware serial control register in question.
  59. */
  60. void WifiSerial::begin(uint32 baud, uint8_t config) {
  61. //ASSERT(baud <= this->usart_device->max_baud); // Roger Clark. Assert doesn't do anything useful, we may as well save the space in flash and ram etc
  62. if (baud > this->usart_device->max_baud) return;
  63. const stm32_pin_info *txi = &PIN_MAP[this->tx_pin],
  64. *rxi = &PIN_MAP[this->rx_pin];
  65. disable_timer_if_necessary(txi->timer_device, txi->timer_channel);
  66. usart_init(this->usart_device);
  67. // Reinitialize the receive buffer, mks_esp8266 fixed data frame length is 1k bytes
  68. rb_init(this->usart_device->rb, WIFI_RX_BUF_SIZE, wifiRxBuf);
  69. usart_config_gpios_async(this->usart_device,
  70. rxi->gpio_device, rxi->gpio_bit,
  71. txi->gpio_device, txi->gpio_bit,
  72. config);
  73. usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud);
  74. usart_enable(this->usart_device);
  75. }
  76. void WifiSerial::end(void) {
  77. usart_disable(this->usart_device);
  78. }
  79. int WifiSerial::available(void) {
  80. return usart_data_available(this->usart_device);
  81. }
  82. //
  83. // I/O
  84. //
  85. int WifiSerial::read(void) {
  86. if (usart_data_available(usart_device) <= 0) return -1;
  87. return usart_getc(usart_device);
  88. }
  89. int WifiSerial::write(unsigned char ch) {
  90. usart_putc(this->usart_device, ch);
  91. return 1;
  92. }
  93. int WifiSerial::wifi_rb_is_full(void) {
  94. return rb_is_full(this->usart_device->rb);
  95. }
  96. #endif // USE_WIFI_FUNCTION
  97. #endif // HAS_TFT_LVGL_UI