My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

wifiSerial_STM32F1.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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 <libmaple/libmaple_types.h>
  24. #include <libmaple/usart.h>
  25. #include <libmaple/libmaple.h>
  26. #include <libmaple/gpio.h>
  27. #include <libmaple/timer.h>
  28. #include <libmaple/ring_buffer.h>
  29. #define DEFINE_WFSERIAL(name, n) WifiSerial name(USART##n, BOARD_USART##n##_TX_PIN, BOARD_USART##n##_RX_PIN)
  30. class WifiSerial {
  31. public:
  32. uint8 wifiRxBuf[WIFI_RX_BUF_SIZE];
  33. public:
  34. WifiSerial(struct usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin);
  35. /* Set up/tear down */
  36. void begin(uint32 baud);
  37. void begin(uint32 baud, uint8_t config);
  38. void end();
  39. int available();
  40. int read();
  41. int write(uint8_t);
  42. inline void wifi_usart_irq(usart_reg_map *regs) {
  43. /* Handling RXNEIE and TXEIE interrupts.
  44. * RXNE signifies availability of a byte in DR.
  45. *
  46. * See table 198 (sec 27.4, p809) in STM document RM0008 rev 15.
  47. * We enable RXNEIE.
  48. */
  49. if ((regs->CR1 & USART_CR1_RXNEIE) && (regs->SR & USART_SR_RXNE)) {
  50. #ifdef USART_SAFE_INSERT
  51. /* If the buffer is full and the user defines USART_SAFE_INSERT,
  52. * ignore new bytes. */
  53. rb_safe_insert(this->usart_device->rb, (uint8)regs->DR);
  54. #else
  55. /* By default, push bytes around in the ring buffer. */
  56. rb_push_insert(this->usart_device->rb, (uint8)regs->DR);
  57. #endif
  58. }
  59. /* TXE signifies readiness to send a byte to DR. */
  60. if ((regs->CR1 & USART_CR1_TXEIE) && (regs->SR & USART_SR_TXE)) {
  61. if (!rb_is_empty(this->usart_device->wb))
  62. regs->DR = rb_remove(this->usart_device->wb);
  63. else
  64. regs->CR1 &= ~((uint32)USART_CR1_TXEIE); // disable TXEIE
  65. }
  66. }
  67. int wifi_rb_is_full();
  68. struct usart_dev *usart_device;
  69. private:
  70. uint8 tx_pin;
  71. uint8 rx_pin;
  72. };