My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MarlinSerialUSB.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifdef ARDUINO_ARCH_SAM
  23. /**
  24. * MarlinSerial_Due.cpp - Hardware serial library for Arduino DUE
  25. * Copyright (c) 2017 Eduardo José Tagle. All right reserved
  26. * Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti. All right reserved.
  27. */
  28. #include "../../inc/MarlinConfig.h"
  29. #if HAS_USB_SERIAL
  30. #include "MarlinSerialUSB.h"
  31. // Imports from Atmel USB Stack/CDC implementation
  32. extern "C" {
  33. bool usb_task_cdc_isenabled();
  34. bool usb_task_cdc_dtr_active();
  35. bool udi_cdc_is_rx_ready();
  36. int udi_cdc_getc();
  37. bool udi_cdc_is_tx_ready();
  38. int udi_cdc_putc(int value);
  39. }
  40. // Pending character
  41. static int pending_char = -1;
  42. // Public Methods
  43. void MarlinSerialUSB::begin(const long) {}
  44. void MarlinSerialUSB::end() {}
  45. int MarlinSerialUSB::peek() {
  46. if (pending_char >= 0)
  47. return pending_char;
  48. // If USB CDC not enumerated or not configured on the PC side
  49. if (!usb_task_cdc_isenabled())
  50. return -1;
  51. // If no bytes sent from the PC
  52. if (!udi_cdc_is_rx_ready())
  53. return -1;
  54. pending_char = udi_cdc_getc();
  55. TERN_(EMERGENCY_PARSER, emergency_parser.update(static_cast<MSerialT1*>(this)->emergency_state, (char)pending_char));
  56. return pending_char;
  57. }
  58. int MarlinSerialUSB::read() {
  59. if (pending_char >= 0) {
  60. int ret = pending_char;
  61. pending_char = -1;
  62. return ret;
  63. }
  64. // If USB CDC not enumerated or not configured on the PC side
  65. if (!usb_task_cdc_isenabled())
  66. return -1;
  67. // If no bytes sent from the PC
  68. if (!udi_cdc_is_rx_ready())
  69. return -1;
  70. int c = udi_cdc_getc();
  71. TERN_(EMERGENCY_PARSER, emergency_parser.update(static_cast<MSerialT1*>(this)->emergency_state, (char)c));
  72. return c;
  73. }
  74. int MarlinSerialUSB::available() {
  75. if (pending_char > 0) return pending_char;
  76. return pending_char == 0 ||
  77. // or USB CDC enumerated and configured on the PC side and some bytes where sent to us */
  78. (usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
  79. }
  80. void MarlinSerialUSB::flush() { }
  81. size_t MarlinSerialUSB::write(const uint8_t c) {
  82. /* Do not even bother sending anything if USB CDC is not enumerated
  83. or not configured on the PC side or there is no program on the PC
  84. listening to our messages */
  85. if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
  86. return 0;
  87. /* Wait until the PC has read the pending to be sent data */
  88. while (usb_task_cdc_isenabled() &&
  89. usb_task_cdc_dtr_active() &&
  90. !udi_cdc_is_tx_ready()) {
  91. };
  92. /* Do not even bother sending anything if USB CDC is not enumerated
  93. or not configured on the PC side or there is no program on the PC
  94. listening to our messages at this point */
  95. if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
  96. return 0;
  97. // Fifo full
  98. // udi_cdc_signal_overrun();
  99. udi_cdc_putc(c);
  100. return 1;
  101. }
  102. // Preinstantiate
  103. #if SERIAL_PORT == -1
  104. MSerialT1 customizedSerial1(TERN0(EMERGENCY_PARSER, true));
  105. #endif
  106. #if SERIAL_PORT_2 == -1
  107. MSerialT2 customizedSerial2(TERN0(EMERGENCY_PARSER, true));
  108. #endif
  109. #if SERIAL_PORT_3 == -1
  110. MSerialT3 customizedSerial3(TERN0(EMERGENCY_PARSER, true));
  111. #endif
  112. #endif // HAS_USB_SERIAL
  113. #endif // ARDUINO_ARCH_SAM