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.

HardwareSerial.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); }
  224. virtual void begin(uint32_t baud, uint32_t format) {
  225. serial_begin(BAUD2DIV(baud));
  226. serial_format(format); }
  227. virtual void end(void) { serial_end(); }
  228. virtual void transmitterEnable(uint8_t pin) { serial_set_transmit_pin(pin); }
  229. virtual void setRX(uint8_t pin) { serial_set_rx(pin); }
  230. virtual void setTX(uint8_t pin, bool opendrain=false) { serial_set_tx(pin, opendrain); }
  231. virtual bool attachRts(uint8_t pin) { return serial_set_rts(pin); }
  232. virtual bool attachCts(uint8_t pin) { return serial_set_cts(pin); }
  233. virtual int available(void) { return serial_available(); }
  234. virtual int peek(void) { return serial_peek(); }
  235. virtual int read(void) { return serial_getchar(); }
  236. virtual void flush(void) { serial_flush(); }
  237. virtual void clear(void) { serial_clear(); }
  238. virtual int availableForWrite(void) { return serial_write_buffer_free(); }
  239. virtual size_t write(uint8_t c) { serial_putchar(c); return 1; }
  240. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  241. virtual size_t write(long n) { return write((uint8_t)n); }
  242. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  243. virtual size_t write(int n) { return write((uint8_t)n); }
  244. virtual size_t write(const uint8_t *buffer, size_t size)
  245. { serial_write(buffer, size); return size; }
  246. virtual size_t write(const char *str) { size_t len = strlen(str);
  247. serial_write((const uint8_t *)str, len);
  248. return len; }
  249. virtual size_t write9bit(uint32_t c) { serial_putchar(c); return 1; }
  250. operator bool() { return true; }
  251. };
  252. extern HardwareSerial Serial1;
  253. extern void serialEvent1(void);
  254. class HardwareSerial2 : public HardwareSerial
  255. {
  256. public:
  257. virtual void begin(uint32_t baud) { serial2_begin(BAUD2DIV2(baud)); }
  258. virtual void begin(uint32_t baud, uint32_t format) {
  259. serial2_begin(BAUD2DIV2(baud));
  260. serial2_format(format); }
  261. virtual void end(void) { serial2_end(); }
  262. virtual void transmitterEnable(uint8_t pin) { serial2_set_transmit_pin(pin); }
  263. virtual void setRX(uint8_t pin) { serial2_set_rx(pin); }
  264. virtual void setTX(uint8_t pin, bool opendrain=false) { serial2_set_tx(pin, opendrain); }
  265. virtual bool attachRts(uint8_t pin) { return serial2_set_rts(pin); }
  266. virtual bool attachCts(uint8_t pin) { return serial2_set_cts(pin); }
  267. virtual int available(void) { return serial2_available(); }
  268. virtual int peek(void) { return serial2_peek(); }
  269. virtual int read(void) { return serial2_getchar(); }
  270. virtual void flush(void) { serial2_flush(); }
  271. virtual void clear(void) { serial2_clear(); }
  272. virtual int availableForWrite(void) { return serial2_write_buffer_free(); }
  273. virtual size_t write(uint8_t c) { serial2_putchar(c); return 1; }
  274. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  275. virtual size_t write(long n) { return write((uint8_t)n); }
  276. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  277. virtual size_t write(int n) { return write((uint8_t)n); }
  278. virtual size_t write(const uint8_t *buffer, size_t size)
  279. { serial2_write(buffer, size); return size; }
  280. virtual size_t write(const char *str) { size_t len = strlen(str);
  281. serial2_write((const uint8_t *)str, len);
  282. return len; }
  283. virtual size_t write9bit(uint32_t c) { serial2_putchar(c); return 1; }
  284. operator bool() { return true; }
  285. };
  286. extern HardwareSerial2 Serial2;
  287. extern void serialEvent2(void);
  288. class HardwareSerial3 : public HardwareSerial
  289. {
  290. public:
  291. virtual void begin(uint32_t baud) { serial3_begin(BAUD2DIV3(baud)); }
  292. virtual void begin(uint32_t baud, uint32_t format) {
  293. serial3_begin(BAUD2DIV3(baud));
  294. serial3_format(format); }
  295. virtual void end(void) { serial3_end(); }
  296. virtual void transmitterEnable(uint8_t pin) { serial3_set_transmit_pin(pin); }
  297. virtual void setRX(uint8_t pin) { serial3_set_rx(pin); }
  298. virtual void setTX(uint8_t pin, bool opendrain=false) { serial3_set_tx(pin, opendrain); }
  299. virtual bool attachRts(uint8_t pin) { return serial3_set_rts(pin); }
  300. virtual bool attachCts(uint8_t pin) { return serial3_set_cts(pin); }
  301. virtual int available(void) { return serial3_available(); }
  302. virtual int peek(void) { return serial3_peek(); }
  303. virtual int read(void) { return serial3_getchar(); }
  304. virtual void flush(void) { serial3_flush(); }
  305. virtual void clear(void) { serial3_clear(); }
  306. virtual int availableForWrite(void) { return serial3_write_buffer_free(); }
  307. virtual size_t write(uint8_t c) { serial3_putchar(c); return 1; }
  308. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  309. virtual size_t write(long n) { return write((uint8_t)n); }
  310. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  311. virtual size_t write(int n) { return write((uint8_t)n); }
  312. virtual size_t write(const uint8_t *buffer, size_t size)
  313. { serial3_write(buffer, size); return size; }
  314. virtual size_t write(const char *str) { size_t len = strlen(str);
  315. serial3_write((const uint8_t *)str, len);
  316. return len; }
  317. virtual size_t write9bit(uint32_t c) { serial3_putchar(c); return 1; }
  318. operator bool() { return true; }
  319. };
  320. extern HardwareSerial3 Serial3;
  321. extern void serialEvent3(void);
  322. class HardwareSerial4 : public HardwareSerial
  323. {
  324. public:
  325. virtual void begin(uint32_t baud) { serial4_begin(BAUD2DIV3(baud)); }
  326. virtual void begin(uint32_t baud, uint32_t format) {
  327. serial4_begin(BAUD2DIV3(baud));
  328. serial4_format(format); }
  329. virtual void end(void) { serial4_end(); }
  330. virtual void transmitterEnable(uint8_t pin) { serial4_set_transmit_pin(pin); }
  331. virtual void setRX(uint8_t pin) { serial4_set_rx(pin); }
  332. virtual void setTX(uint8_t pin, bool opendrain=false) { serial4_set_tx(pin, opendrain); }
  333. virtual bool attachRts(uint8_t pin) { return serial4_set_rts(pin); }
  334. virtual bool attachCts(uint8_t pin) { return serial4_set_cts(pin); }
  335. virtual int available(void) { return serial4_available(); }
  336. virtual int peek(void) { return serial4_peek(); }
  337. virtual int read(void) { return serial4_getchar(); }
  338. virtual void flush(void) { serial4_flush(); }
  339. virtual void clear(void) { serial4_clear(); }
  340. virtual int availableForWrite(void) { return serial4_write_buffer_free(); }
  341. virtual size_t write(uint8_t c) { serial4_putchar(c); return 1; }
  342. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  343. virtual size_t write(long n) { return write((uint8_t)n); }
  344. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  345. virtual size_t write(int n) { return write((uint8_t)n); }
  346. virtual size_t write(const uint8_t *buffer, size_t size)
  347. { serial4_write(buffer, size); return size; }
  348. virtual size_t write(const char *str) { size_t len = strlen(str);
  349. serial4_write((const uint8_t *)str, len);
  350. return len; }
  351. virtual size_t write9bit(uint32_t c) { serial4_putchar(c); return 1; }
  352. operator bool() { return true; }
  353. };
  354. extern HardwareSerial4 Serial4;
  355. extern void serialEvent4(void);
  356. class HardwareSerial5 : public HardwareSerial
  357. {
  358. public:
  359. virtual void begin(uint32_t baud) { serial5_begin(BAUD2DIV3(baud)); }
  360. virtual void begin(uint32_t baud, uint32_t format) {
  361. serial5_begin(BAUD2DIV3(baud));
  362. serial5_format(format); }
  363. virtual void end(void) { serial5_end(); }
  364. virtual void transmitterEnable(uint8_t pin) { serial5_set_transmit_pin(pin); }
  365. virtual void setRX(uint8_t pin) { serial5_set_rx(pin); }
  366. virtual void setTX(uint8_t pin, bool opendrain=false) { serial5_set_tx(pin, opendrain); }
  367. virtual bool attachRts(uint8_t pin) { return serial5_set_rts(pin); }
  368. virtual bool attachCts(uint8_t pin) { return serial5_set_cts(pin); }
  369. virtual int available(void) { return serial5_available(); }
  370. virtual int peek(void) { return serial5_peek(); }
  371. virtual int read(void) { return serial5_getchar(); }
  372. virtual void flush(void) { serial5_flush(); }
  373. virtual void clear(void) { serial5_clear(); }
  374. virtual int availableForWrite(void) { return serial5_write_buffer_free(); }
  375. virtual size_t write(uint8_t c) { serial5_putchar(c); return 1; }
  376. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  377. virtual size_t write(long n) { return write((uint8_t)n); }
  378. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  379. virtual size_t write(int n) { return write((uint8_t)n); }
  380. virtual size_t write(const uint8_t *buffer, size_t size)
  381. { serial5_write(buffer, size); return size; }
  382. virtual size_t write(const char *str) { size_t len = strlen(str);
  383. serial5_write((const uint8_t *)str, len);
  384. return len; }
  385. virtual size_t write9bit(uint32_t c) { serial5_putchar(c); return 1; }
  386. operator bool() { return true; }
  387. };
  388. extern HardwareSerial5 Serial5;
  389. extern void serialEvent5(void);
  390. class HardwareSerial6 : public HardwareSerial
  391. {
  392. public:
  393. #if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
  394. virtual void begin(uint32_t baud) { serial6_begin(baud); }
  395. virtual void begin(uint32_t baud, uint32_t format) {
  396. serial6_begin(baud);
  397. serial6_format(format); }
  398. #else
  399. virtual void begin(uint32_t baud) { serial6_begin(BAUD2DIV3(baud)); }
  400. virtual void begin(uint32_t baud, uint32_t format) {
  401. serial6_begin(BAUD2DIV3(baud));
  402. serial6_format(format); }
  403. #endif
  404. virtual void end(void) { serial6_end(); }
  405. virtual void transmitterEnable(uint8_t pin) { serial6_set_transmit_pin(pin); }
  406. virtual void setRX(uint8_t pin) { serial6_set_rx(pin); }
  407. virtual void setTX(uint8_t pin, bool opendrain=false) { serial6_set_tx(pin, opendrain); }
  408. virtual bool attachRts(uint8_t pin) { return serial6_set_rts(pin); }
  409. virtual bool attachCts(uint8_t pin) { return serial6_set_cts(pin); }
  410. virtual int available(void) { return serial6_available(); }
  411. virtual int peek(void) { return serial6_peek(); }
  412. virtual int read(void) { return serial6_getchar(); }
  413. virtual void flush(void) { serial6_flush(); }
  414. virtual void clear(void) { serial6_clear(); }
  415. virtual int availableForWrite(void) { return serial6_write_buffer_free(); }
  416. virtual size_t write(uint8_t c) { serial6_putchar(c); return 1; }
  417. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  418. virtual size_t write(long n) { return write((uint8_t)n); }
  419. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  420. virtual size_t write(int n) { return write((uint8_t)n); }
  421. virtual size_t write(const uint8_t *buffer, size_t size)
  422. { serial6_write(buffer, size); return size; }
  423. virtual size_t write(const char *str) { size_t len = strlen(str);
  424. serial6_write((const uint8_t *)str, len);
  425. return len; }
  426. virtual size_t write9bit(uint32_t c) { serial6_putchar(c); return 1; }
  427. operator bool() { return true; }
  428. };
  429. extern HardwareSerial6 Serial6;
  430. extern void serialEvent6(void);
  431. #endif
  432. #endif