Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

HardwareSerial.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #ifndef HardwareSerial_h
  31. #define HardwareSerial_h
  32. #include "kinetis.h"
  33. // uncomment to enable 9 bit formats
  34. //#define SERIAL_9BIT_SUPPORT
  35. #define SERIAL_7E1 0x02
  36. #define SERIAL_7O1 0x03
  37. #define SERIAL_8N1 0x00
  38. #define SERIAL_8N2 0x04
  39. #define SERIAL_8E1 0x06
  40. #define SERIAL_8O1 0x07
  41. #define SERIAL_7E1_RXINV 0x12
  42. #define SERIAL_7O1_RXINV 0x13
  43. #define SERIAL_8N1_RXINV 0x10
  44. #define SERIAL_8N2_RXINV 0x14
  45. #define SERIAL_8E1_RXINV 0x16
  46. #define SERIAL_8O1_RXINV 0x17
  47. #define SERIAL_7E1_TXINV 0x22
  48. #define SERIAL_7O1_TXINV 0x23
  49. #define SERIAL_8N1_TXINV 0x20
  50. #define SERIAL_8N2_TXINV 0x24
  51. #define SERIAL_8E1_TXINV 0x26
  52. #define SERIAL_8O1_TXINV 0x27
  53. #define SERIAL_7E1_RXINV_TXINV 0x32
  54. #define SERIAL_7O1_RXINV_TXINV 0x33
  55. #define SERIAL_8N1_RXINV_TXINV 0x30
  56. #define SERIAL_8N2_RXINV_TXINV 0x34
  57. #define SERIAL_8E1_RXINV_TXINV 0x36
  58. #define SERIAL_8O1_RXINV_TXINV 0x37
  59. #ifdef SERIAL_9BIT_SUPPORT
  60. #define SERIAL_9N1 0x84
  61. #define SERIAL_9E1 0x8E
  62. #define SERIAL_9O1 0x8F
  63. #define SERIAL_9N1_RXINV 0x94
  64. #define SERIAL_9E1_RXINV 0x9E
  65. #define SERIAL_9O1_RXINV 0x9F
  66. #define SERIAL_9N1_TXINV 0xA4
  67. #define SERIAL_9E1_TXINV 0xAE
  68. #define SERIAL_9O1_TXINV 0xAF
  69. #define SERIAL_9N1_RXINV_TXINV 0xB4
  70. #define SERIAL_9E1_RXINV_TXINV 0xBE
  71. #define SERIAL_9O1_RXINV_TXINV 0xBF
  72. #endif
  73. // Teensy LC and 3.5 and 3.6 Uarts have 1/2 bit stop setting
  74. #if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(KINETISL)
  75. #define SERIAL_2STOP_BITS 0x100
  76. #define SERIAL_8E2 (SERIAL_8E1 | SERIAL_2STOP_BITS)
  77. #define SERIAL_8O2 (SERIAL_8O1 | SERIAL_2STOP_BITS)
  78. #define SERIAL_8E2_RXINV (SERIAL_8E1_RXINV | SERIAL_2STOP_BITS)
  79. #define SERIAL_8O2_RXINV (SERIAL_8O1_RXINV | SERIAL_2STOP_BITS)
  80. #define SERIAL_8E2_TXINV (SERIAL_8E1_TXINV | SERIAL_2STOP_BITS)
  81. #define SERIAL_8O2_TXINV (SERIAL_8O1_TXINV | SERIAL_2STOP_BITS)
  82. #define SERIAL_8E2_RXINV_TXINV (SERIAL_8E1_RXINV_TXINV | SERIAL_2STOP_BITS)
  83. #define SERIAL_8O2_RXINV_TXINV (SERIAL_8O1_RXINV_TXINV | SERIAL_2STOP_BITS)
  84. #endif
  85. // bit0: parity, 0=even, 1=odd
  86. // bit1: parity, 0=disable, 1=enable
  87. // bit2: mode, 1=9bit, 0=8bit
  88. // bit3: mode10: 1=10bit, 0=8bit
  89. // bit4: rxinv, 0=normal, 1=inverted
  90. // bit5: txinv, 0=normal, 1=inverted
  91. // bit6: unused
  92. // bit7: actual data goes into 9th bit
  93. #if defined(KINETISK)
  94. #define BAUD2DIV(baud) (((F_CPU * 2) + ((baud) >> 1)) / (baud))
  95. #define BAUD2DIV2(baud) (((F_CPU * 2) + ((baud) >> 1)) / (baud))
  96. #define BAUD2DIV3(baud) (((F_BUS * 2) + ((baud) >> 1)) / (baud))
  97. #elif defined(KINETISL)
  98. #if F_CPU <= 2000000
  99. #define BAUD2DIV(baud) (((F_PLL / 16 ) + ((baud) >> 1)) / (baud))
  100. #elif F_CPU <= 16000000
  101. #define BAUD2DIV(baud) (((F_PLL / (F_PLL / 1000000)) + ((baud) >> 1)) / (baud))
  102. #else
  103. #define BAUD2DIV(baud) (((F_PLL / 2 / 16) + ((baud) >> 1)) / (baud))
  104. #endif
  105. #define BAUD2DIV2(baud) (((F_BUS / 16) + ((baud) >> 1)) / (baud))
  106. #define BAUD2DIV3(baud) (((F_BUS / 16) + ((baud) >> 1)) / (baud))
  107. #endif
  108. // C language implementation
  109. //
  110. #ifdef __cplusplus
  111. extern "C" {
  112. #endif
  113. void serial_begin(uint32_t divisor);
  114. void serial_format(uint32_t format);
  115. void serial_end(void);
  116. void serial_set_transmit_pin(uint8_t pin);
  117. void serial_set_rx(uint8_t pin);
  118. void serial_set_tx(uint8_t pin, uint8_t opendrain);
  119. int serial_set_rts(uint8_t pin);
  120. int serial_set_cts(uint8_t pin);
  121. void serial_putchar(uint32_t c);
  122. void serial_write(const void *buf, unsigned int count);
  123. void serial_flush(void);
  124. int serial_write_buffer_free(void);
  125. int serial_available(void);
  126. int serial_getchar(void);
  127. int serial_peek(void);
  128. void serial_clear(void);
  129. void serial_print(const char *p);
  130. void serial_phex(uint32_t n);
  131. void serial_phex16(uint32_t n);
  132. void serial_phex32(uint32_t n);
  133. void serial2_begin(uint32_t divisor);
  134. void serial2_format(uint32_t format);
  135. void serial2_end(void);
  136. void serial2_set_transmit_pin(uint8_t pin);
  137. void serial2_set_rx(uint8_t pin);
  138. void serial2_set_tx(uint8_t pin, uint8_t opendrain);
  139. int serial2_set_rts(uint8_t pin);
  140. int serial2_set_cts(uint8_t pin);
  141. void serial2_putchar(uint32_t c);
  142. void serial2_write(const void *buf, unsigned int count);
  143. void serial2_flush(void);
  144. int serial2_write_buffer_free(void);
  145. int serial2_available(void);
  146. int serial2_getchar(void);
  147. int serial2_peek(void);
  148. void serial2_clear(void);
  149. void serial3_begin(uint32_t divisor);
  150. void serial3_format(uint32_t format);
  151. void serial3_end(void);
  152. void serial3_set_transmit_pin(uint8_t pin);
  153. void serial3_set_rx(uint8_t pin);
  154. void serial3_set_tx(uint8_t pin, uint8_t opendrain);
  155. int serial3_set_rts(uint8_t pin);
  156. int serial3_set_cts(uint8_t pin);
  157. void serial3_putchar(uint32_t c);
  158. void serial3_write(const void *buf, unsigned int count);
  159. void serial3_flush(void);
  160. int serial3_write_buffer_free(void);
  161. int serial3_available(void);
  162. int serial3_getchar(void);
  163. int serial3_peek(void);
  164. void serial3_clear(void);
  165. void serial4_begin(uint32_t divisor);
  166. void serial4_format(uint32_t format);
  167. void serial4_end(void);
  168. void serial4_set_transmit_pin(uint8_t pin);
  169. void serial4_set_rx(uint8_t pin);
  170. void serial4_set_tx(uint8_t pin, uint8_t opendrain);
  171. int serial4_set_rts(uint8_t pin);
  172. int serial4_set_cts(uint8_t pin);
  173. void serial4_putchar(uint32_t c);
  174. void serial4_write(const void *buf, unsigned int count);
  175. void serial4_flush(void);
  176. int serial4_write_buffer_free(void);
  177. int serial4_available(void);
  178. int serial4_getchar(void);
  179. int serial4_peek(void);
  180. void serial4_clear(void);
  181. void serial5_begin(uint32_t divisor);
  182. void serial5_format(uint32_t format);
  183. void serial5_end(void);
  184. void serial5_set_transmit_pin(uint8_t pin);
  185. void serial5_set_rx(uint8_t pin);
  186. void serial5_set_tx(uint8_t pin, uint8_t opendrain);
  187. int serial5_set_rts(uint8_t pin);
  188. int serial5_set_cts(uint8_t pin);
  189. void serial5_putchar(uint32_t c);
  190. void serial5_write(const void *buf, unsigned int count);
  191. void serial5_flush(void);
  192. int serial5_write_buffer_free(void);
  193. int serial5_available(void);
  194. int serial5_getchar(void);
  195. int serial5_peek(void);
  196. void serial5_clear(void);
  197. void serial6_begin(uint32_t divisor);
  198. void serial6_format(uint32_t format);
  199. void serial6_end(void);
  200. void serial6_set_transmit_pin(uint8_t pin);
  201. void serial6_set_rx(uint8_t pin);
  202. void serial6_set_tx(uint8_t pin, uint8_t opendrain);
  203. int serial6_set_rts(uint8_t pin);
  204. int serial6_set_cts(uint8_t pin);
  205. void serial6_putchar(uint32_t c);
  206. void serial6_write(const void *buf, unsigned int count);
  207. void serial6_flush(void);
  208. int serial6_write_buffer_free(void);
  209. int serial6_available(void);
  210. int serial6_getchar(void);
  211. int serial6_peek(void);
  212. void serial6_clear(void);
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. // C++ interface
  217. //
  218. #ifdef __cplusplus
  219. #include "Stream.h"
  220. class HardwareSerial : public Stream
  221. {
  222. public:
  223. constexpr HardwareSerial() {}
  224. virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); }
  225. virtual void begin(uint32_t baud, uint32_t format) {
  226. serial_begin(BAUD2DIV(baud));
  227. serial_format(format); }
  228. virtual void end(void) { serial_end(); }
  229. virtual void transmitterEnable(uint8_t pin) { serial_set_transmit_pin(pin); }
  230. virtual void setRX(uint8_t pin) { serial_set_rx(pin); }
  231. virtual void setTX(uint8_t pin, bool opendrain=false) { serial_set_tx(pin, opendrain); }
  232. virtual bool attachRts(uint8_t pin) { return serial_set_rts(pin); }
  233. virtual bool attachCts(uint8_t pin) { return serial_set_cts(pin); }
  234. virtual int available(void) { return serial_available(); }
  235. virtual int peek(void) { return serial_peek(); }
  236. virtual int read(void) { return serial_getchar(); }
  237. virtual void flush(void) { serial_flush(); }
  238. virtual void clear(void) { serial_clear(); }
  239. virtual int availableForWrite(void) { return serial_write_buffer_free(); }
  240. using Print::write;
  241. virtual size_t write(uint8_t c) { serial_putchar(c); return 1; }
  242. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  243. virtual size_t write(long n) { return write((uint8_t)n); }
  244. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  245. virtual size_t write(int n) { return write((uint8_t)n); }
  246. virtual size_t write(const uint8_t *buffer, size_t size)
  247. { serial_write(buffer, size); return size; }
  248. virtual size_t write(const char *str) { size_t len = strlen(str);
  249. serial_write((const uint8_t *)str, len);
  250. return len; }
  251. virtual size_t write9bit(uint32_t c) { serial_putchar(c); return 1; }
  252. operator bool() { return true; }
  253. };
  254. extern HardwareSerial Serial1;
  255. extern void serialEvent1(void);
  256. class HardwareSerial2 : public HardwareSerial
  257. {
  258. public:
  259. constexpr HardwareSerial2() {}
  260. virtual void begin(uint32_t baud) { serial2_begin(BAUD2DIV2(baud)); }
  261. virtual void begin(uint32_t baud, uint32_t format) {
  262. serial2_begin(BAUD2DIV2(baud));
  263. serial2_format(format); }
  264. virtual void end(void) { serial2_end(); }
  265. virtual void transmitterEnable(uint8_t pin) { serial2_set_transmit_pin(pin); }
  266. virtual void setRX(uint8_t pin) { serial2_set_rx(pin); }
  267. virtual void setTX(uint8_t pin, bool opendrain=false) { serial2_set_tx(pin, opendrain); }
  268. virtual bool attachRts(uint8_t pin) { return serial2_set_rts(pin); }
  269. virtual bool attachCts(uint8_t pin) { return serial2_set_cts(pin); }
  270. virtual int available(void) { return serial2_available(); }
  271. virtual int peek(void) { return serial2_peek(); }
  272. virtual int read(void) { return serial2_getchar(); }
  273. virtual void flush(void) { serial2_flush(); }
  274. virtual void clear(void) { serial2_clear(); }
  275. virtual int availableForWrite(void) { return serial2_write_buffer_free(); }
  276. using Print::write;
  277. virtual size_t write(uint8_t c) { serial2_putchar(c); return 1; }
  278. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  279. virtual size_t write(long n) { return write((uint8_t)n); }
  280. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  281. virtual size_t write(int n) { return write((uint8_t)n); }
  282. virtual size_t write(const uint8_t *buffer, size_t size)
  283. { serial2_write(buffer, size); return size; }
  284. virtual size_t write(const char *str) { size_t len = strlen(str);
  285. serial2_write((const uint8_t *)str, len);
  286. return len; }
  287. virtual size_t write9bit(uint32_t c) { serial2_putchar(c); return 1; }
  288. operator bool() { return true; }
  289. };
  290. extern HardwareSerial2 Serial2;
  291. extern void serialEvent2(void);
  292. class HardwareSerial3 : public HardwareSerial
  293. {
  294. public:
  295. constexpr HardwareSerial3() {}
  296. virtual void begin(uint32_t baud) { serial3_begin(BAUD2DIV3(baud)); }
  297. virtual void begin(uint32_t baud, uint32_t format) {
  298. serial3_begin(BAUD2DIV3(baud));
  299. serial3_format(format); }
  300. virtual void end(void) { serial3_end(); }
  301. virtual void transmitterEnable(uint8_t pin) { serial3_set_transmit_pin(pin); }
  302. virtual void setRX(uint8_t pin) { serial3_set_rx(pin); }
  303. virtual void setTX(uint8_t pin, bool opendrain=false) { serial3_set_tx(pin, opendrain); }
  304. virtual bool attachRts(uint8_t pin) { return serial3_set_rts(pin); }
  305. virtual bool attachCts(uint8_t pin) { return serial3_set_cts(pin); }
  306. virtual int available(void) { return serial3_available(); }
  307. virtual int peek(void) { return serial3_peek(); }
  308. virtual int read(void) { return serial3_getchar(); }
  309. virtual void flush(void) { serial3_flush(); }
  310. virtual void clear(void) { serial3_clear(); }
  311. virtual int availableForWrite(void) { return serial3_write_buffer_free(); }
  312. using Print::write;
  313. virtual size_t write(uint8_t c) { serial3_putchar(c); return 1; }
  314. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  315. virtual size_t write(long n) { return write((uint8_t)n); }
  316. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  317. virtual size_t write(int n) { return write((uint8_t)n); }
  318. virtual size_t write(const uint8_t *buffer, size_t size)
  319. { serial3_write(buffer, size); return size; }
  320. virtual size_t write(const char *str) { size_t len = strlen(str);
  321. serial3_write((const uint8_t *)str, len);
  322. return len; }
  323. virtual size_t write9bit(uint32_t c) { serial3_putchar(c); return 1; }
  324. operator bool() { return true; }
  325. };
  326. extern HardwareSerial3 Serial3;
  327. extern void serialEvent3(void);
  328. class HardwareSerial4 : public HardwareSerial
  329. {
  330. public:
  331. constexpr HardwareSerial4() {}
  332. virtual void begin(uint32_t baud) { serial4_begin(BAUD2DIV3(baud)); }
  333. virtual void begin(uint32_t baud, uint32_t format) {
  334. serial4_begin(BAUD2DIV3(baud));
  335. serial4_format(format); }
  336. virtual void end(void) { serial4_end(); }
  337. virtual void transmitterEnable(uint8_t pin) { serial4_set_transmit_pin(pin); }
  338. virtual void setRX(uint8_t pin) { serial4_set_rx(pin); }
  339. virtual void setTX(uint8_t pin, bool opendrain=false) { serial4_set_tx(pin, opendrain); }
  340. virtual bool attachRts(uint8_t pin) { return serial4_set_rts(pin); }
  341. virtual bool attachCts(uint8_t pin) { return serial4_set_cts(pin); }
  342. virtual int available(void) { return serial4_available(); }
  343. virtual int peek(void) { return serial4_peek(); }
  344. virtual int read(void) { return serial4_getchar(); }
  345. virtual void flush(void) { serial4_flush(); }
  346. virtual void clear(void) { serial4_clear(); }
  347. virtual int availableForWrite(void) { return serial4_write_buffer_free(); }
  348. using Print::write;
  349. virtual size_t write(uint8_t c) { serial4_putchar(c); return 1; }
  350. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  351. virtual size_t write(long n) { return write((uint8_t)n); }
  352. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  353. virtual size_t write(int n) { return write((uint8_t)n); }
  354. virtual size_t write(const uint8_t *buffer, size_t size)
  355. { serial4_write(buffer, size); return size; }
  356. virtual size_t write(const char *str) { size_t len = strlen(str);
  357. serial4_write((const uint8_t *)str, len);
  358. return len; }
  359. virtual size_t write9bit(uint32_t c) { serial4_putchar(c); return 1; }
  360. operator bool() { return true; }
  361. };
  362. extern HardwareSerial4 Serial4;
  363. extern void serialEvent4(void);
  364. class HardwareSerial5 : public HardwareSerial
  365. {
  366. public:
  367. constexpr HardwareSerial5() {}
  368. virtual void begin(uint32_t baud) { serial5_begin(BAUD2DIV3(baud)); }
  369. virtual void begin(uint32_t baud, uint32_t format) {
  370. serial5_begin(BAUD2DIV3(baud));
  371. serial5_format(format); }
  372. virtual void end(void) { serial5_end(); }
  373. virtual void transmitterEnable(uint8_t pin) { serial5_set_transmit_pin(pin); }
  374. virtual void setRX(uint8_t pin) { serial5_set_rx(pin); }
  375. virtual void setTX(uint8_t pin, bool opendrain=false) { serial5_set_tx(pin, opendrain); }
  376. virtual bool attachRts(uint8_t pin) { return serial5_set_rts(pin); }
  377. virtual bool attachCts(uint8_t pin) { return serial5_set_cts(pin); }
  378. virtual int available(void) { return serial5_available(); }
  379. virtual int peek(void) { return serial5_peek(); }
  380. virtual int read(void) { return serial5_getchar(); }
  381. virtual void flush(void) { serial5_flush(); }
  382. virtual void clear(void) { serial5_clear(); }
  383. virtual int availableForWrite(void) { return serial5_write_buffer_free(); }
  384. using Print::write;
  385. virtual size_t write(uint8_t c) { serial5_putchar(c); return 1; }
  386. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  387. virtual size_t write(long n) { return write((uint8_t)n); }
  388. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  389. virtual size_t write(int n) { return write((uint8_t)n); }
  390. virtual size_t write(const uint8_t *buffer, size_t size)
  391. { serial5_write(buffer, size); return size; }
  392. virtual size_t write(const char *str) { size_t len = strlen(str);
  393. serial5_write((const uint8_t *)str, len);
  394. return len; }
  395. virtual size_t write9bit(uint32_t c) { serial5_putchar(c); return 1; }
  396. operator bool() { return true; }
  397. };
  398. extern HardwareSerial5 Serial5;
  399. extern void serialEvent5(void);
  400. class HardwareSerial6 : public HardwareSerial
  401. {
  402. public:
  403. constexpr HardwareSerial6() {}
  404. #if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
  405. virtual void begin(uint32_t baud) { serial6_begin(baud); }
  406. virtual void begin(uint32_t baud, uint32_t format) {
  407. serial6_begin(baud);
  408. serial6_format(format); }
  409. #else
  410. virtual void begin(uint32_t baud) { serial6_begin(BAUD2DIV3(baud)); }
  411. virtual void begin(uint32_t baud, uint32_t format) {
  412. serial6_begin(BAUD2DIV3(baud));
  413. serial6_format(format); }
  414. #endif
  415. virtual void end(void) { serial6_end(); }
  416. virtual void transmitterEnable(uint8_t pin) { serial6_set_transmit_pin(pin); }
  417. virtual void setRX(uint8_t pin) { serial6_set_rx(pin); }
  418. virtual void setTX(uint8_t pin, bool opendrain=false) { serial6_set_tx(pin, opendrain); }
  419. virtual bool attachRts(uint8_t pin) { return serial6_set_rts(pin); }
  420. virtual bool attachCts(uint8_t pin) { return serial6_set_cts(pin); }
  421. virtual int available(void) { return serial6_available(); }
  422. virtual int peek(void) { return serial6_peek(); }
  423. virtual int read(void) { return serial6_getchar(); }
  424. virtual void flush(void) { serial6_flush(); }
  425. virtual void clear(void) { serial6_clear(); }
  426. virtual int availableForWrite(void) { return serial6_write_buffer_free(); }
  427. using Print::write;
  428. virtual size_t write(uint8_t c) { serial6_putchar(c); return 1; }
  429. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  430. virtual size_t write(long n) { return write((uint8_t)n); }
  431. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  432. virtual size_t write(int n) { return write((uint8_t)n); }
  433. virtual size_t write(const uint8_t *buffer, size_t size)
  434. { serial6_write(buffer, size); return size; }
  435. virtual size_t write(const char *str) { size_t len = strlen(str);
  436. serial6_write((const uint8_t *)str, len);
  437. return len; }
  438. virtual size_t write9bit(uint32_t c) { serial6_putchar(c); return 1; }
  439. operator bool() { return true; }
  440. };
  441. extern HardwareSerial6 Serial6;
  442. extern void serialEvent6(void);
  443. #endif
  444. #endif