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.

MarlinSerial_Due.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * MarlinSerial_Due.h - Hardware serial library for Arduino DUE
  24. * Copyright (c) 2017 Eduardo José Tagle. All right reserved
  25. * Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti. All right reserved.
  26. */
  27. #ifndef MARLINSERIAL_DUE_H
  28. #define MARLINSERIAL_DUE_H
  29. #include "../../inc/MarlinConfig.h"
  30. #if SERIAL_PORT >= 0
  31. #include <WString.h>
  32. #define DEC 10
  33. #define HEX 16
  34. #define OCT 8
  35. #define BIN 2
  36. // Define constants and variables for buffering incoming serial data. We're
  37. // using a ring buffer (I think), in which rx_buffer_head is the index of the
  38. // location to which to write the next incoming character and rx_buffer_tail
  39. // is the index of the location from which to read.
  40. // 256 is the max limit due to uint8_t head and tail. Use only powers of 2. (...,16,32,64,128,256)
  41. #ifndef RX_BUFFER_SIZE
  42. #define RX_BUFFER_SIZE 128
  43. #endif
  44. #ifndef TX_BUFFER_SIZE
  45. #define TX_BUFFER_SIZE 32
  46. #endif
  47. //#if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
  48. // #error "SERIAL_XON_XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops."
  49. //#elif RX_BUFFER_SIZE && (RX_BUFFER_SIZE < 2 || !IS_POWER_OF_2(RX_BUFFER_SIZE))
  50. // #error "RX_BUFFER_SIZE must be a power of 2 greater than 1."
  51. //#elif TX_BUFFER_SIZE && (TX_BUFFER_SIZE < 2 || TX_BUFFER_SIZE > 256 || !IS_POWER_OF_2(TX_BUFFER_SIZE))
  52. // #error "TX_BUFFER_SIZE must be 0, a power of 2 greater than 1, and no greater than 256."
  53. //#endif
  54. #if RX_BUFFER_SIZE > 256
  55. typedef uint16_t ring_buffer_pos_t;
  56. #else
  57. typedef uint8_t ring_buffer_pos_t;
  58. #endif
  59. #if ENABLED(SERIAL_STATS_DROPPED_RX)
  60. extern uint8_t rx_dropped_bytes;
  61. #endif
  62. #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
  63. extern uint8_t rx_buffer_overruns;
  64. #endif
  65. #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
  66. extern uint8_t rx_framing_errors;
  67. #endif
  68. #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
  69. extern ring_buffer_pos_t rx_max_enqueued;
  70. #endif
  71. class MarlinSerial {
  72. public:
  73. MarlinSerial() {};
  74. static void begin(const long);
  75. static void end();
  76. static int peek(void);
  77. static int read(void);
  78. static void flush(void);
  79. static ring_buffer_pos_t available(void);
  80. static void write(const uint8_t c);
  81. static void flushTX(void);
  82. #if ENABLED(SERIAL_STATS_DROPPED_RX)
  83. FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
  84. #endif
  85. #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
  86. FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
  87. #endif
  88. #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
  89. FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
  90. #endif
  91. #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
  92. FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
  93. #endif
  94. FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
  95. FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
  96. FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
  97. FORCE_INLINE static void print(const char* str) { write(str); }
  98. static void print(char, int = 0);
  99. static void print(unsigned char, int = 0);
  100. static void print(int, int = DEC);
  101. static void print(unsigned int, int = DEC);
  102. static void print(long, int = DEC);
  103. static void print(unsigned long, int = DEC);
  104. static void print(double, int = 2);
  105. static void println(const String& s);
  106. static void println(const char[]);
  107. static void println(char, int = 0);
  108. static void println(unsigned char, int = 0);
  109. static void println(int, int = DEC);
  110. static void println(unsigned int, int = DEC);
  111. static void println(long, int = DEC);
  112. static void println(unsigned long, int = DEC);
  113. static void println(double, int = 2);
  114. static void println(void);
  115. operator bool() { return true; }
  116. private:
  117. static void printNumber(unsigned long, const uint8_t);
  118. static void printFloat(double, uint8_t);
  119. };
  120. extern MarlinSerial customizedSerial;
  121. #endif // SERIAL_PORT >= 0
  122. #endif // MARLINSERIAL_DUE_H