My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

wifiSerial.cpp 3.6KB

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