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.

MarlinSerial.cpp 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  20. #include "../../inc/MarlinConfig.h"
  21. #include "MarlinSerial.h"
  22. #if ENABLED(EMERGENCY_PARSER)
  23. #include "../../feature/e_parser.h"
  24. #endif
  25. #ifndef USART4
  26. #define USART4 UART4
  27. #endif
  28. #ifndef USART5
  29. #define USART5 UART5
  30. #endif
  31. #define DECLARE_SERIAL_PORT(ser_num) \
  32. void _rx_complete_irq_ ## ser_num (serial_t * obj); \
  33. MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \
  34. void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); }
  35. #define DECLARE_SERIAL_PORT_EXP(ser_num) DECLARE_SERIAL_PORT(ser_num)
  36. #if defined(SERIAL_PORT) && SERIAL_PORT >= 0
  37. DECLARE_SERIAL_PORT_EXP(SERIAL_PORT)
  38. #endif
  39. #if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
  40. DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
  41. #endif
  42. #if defined(MMU2_SERIAL_PORT) && MMU2_SERIAL_PORT >= 0
  43. DECLARE_SERIAL_PORT_EXP(MMU2_SERIAL_PORT)
  44. #endif
  45. #if defined(LCD_SERIAL_PORT) && LCD_SERIAL_PORT >= 0
  46. DECLARE_SERIAL_PORT_EXP(LCD_SERIAL_PORT)
  47. #endif
  48. void MarlinSerial::begin(unsigned long baud, uint8_t config) {
  49. HardwareSerial::begin(baud, config);
  50. // Replace the IRQ callback with the one we have defined
  51. TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback);
  52. }
  53. // This function is Copyright (c) 2006 Nicholas Zambetti.
  54. void MarlinSerial::_rx_complete_irq(serial_t *obj) {
  55. // No Parity error, read byte and store it in the buffer if there is room
  56. unsigned char c;
  57. if (uart_getc(obj, &c) == 0) {
  58. rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE;
  59. // if we should be storing the received character into the location
  60. // just before the tail (meaning that the head would advance to the
  61. // current location of the tail), we're about to overflow the buffer
  62. // and so we don't write the character or advance the head.
  63. if (i != obj->rx_tail) {
  64. obj->rx_buff[obj->rx_head] = c;
  65. obj->rx_head = i;
  66. }
  67. #if ENABLED(EMERGENCY_PARSER)
  68. emergency_parser.update(emergency_state, c);
  69. #endif
  70. }
  71. }
  72. #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC