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.

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