Teensy 4.1 core updated for C++20
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

10 роки тому
10 роки тому
10 роки тому
10 роки тому
10 роки тому
10 роки тому
10 роки тому
10 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 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. These are default disabled to save memory.
  34. //#define SERIAL_9BIT_SUPPORT
  35. //
  36. // On Windows & Linux, this file is in Arduino's hardware/teensy/avr/cores/teensy3
  37. // folder. The Windows installer puts Arduino in C:\Program Files (x86)\Arduino
  38. // On Macintosh, you must control-click Arduino and select "Show Package Contents", then
  39. // look in Contents/Java/hardware/teensy/avr/cores/teensy3 to find this file.
  40. //
  41. // Teensy 3.x boards support 9 bit mode on all their serial ports
  42. // Teensy LC only supports 9 bit mode on Serial1. Serial2 & Serial3 can't use 9 bits.
  43. #define SERIAL_7E1 0x02
  44. #define SERIAL_7O1 0x03
  45. #define SERIAL_8N1 0x00
  46. #define SERIAL_8N2 0x04
  47. #define SERIAL_8E1 0x06
  48. #define SERIAL_8O1 0x07
  49. #define SERIAL_7E1_RXINV 0x12
  50. #define SERIAL_7O1_RXINV 0x13
  51. #define SERIAL_8N1_RXINV 0x10
  52. #define SERIAL_8N2_RXINV 0x14
  53. #define SERIAL_8E1_RXINV 0x16
  54. #define SERIAL_8O1_RXINV 0x17
  55. #define SERIAL_7E1_TXINV 0x22
  56. #define SERIAL_7O1_TXINV 0x23
  57. #define SERIAL_8N1_TXINV 0x20
  58. #define SERIAL_8N2_TXINV 0x24
  59. #define SERIAL_8E1_TXINV 0x26
  60. #define SERIAL_8O1_TXINV 0x27
  61. #define SERIAL_7E1_RXINV_TXINV 0x32
  62. #define SERIAL_7O1_RXINV_TXINV 0x33
  63. #define SERIAL_8N1_RXINV_TXINV 0x30
  64. #define SERIAL_8N2_RXINV_TXINV 0x34
  65. #define SERIAL_8E1_RXINV_TXINV 0x36
  66. #define SERIAL_8O1_RXINV_TXINV 0x37
  67. #ifdef SERIAL_9BIT_SUPPORT
  68. #define SERIAL_9N1 0x84
  69. #define SERIAL_9E1 0x8E
  70. #define SERIAL_9O1 0x8F
  71. #define SERIAL_9N1_RXINV 0x94
  72. #define SERIAL_9E1_RXINV 0x9E
  73. #define SERIAL_9O1_RXINV 0x9F
  74. #define SERIAL_9N1_TXINV 0xA4
  75. #define SERIAL_9E1_TXINV 0xAE
  76. #define SERIAL_9O1_TXINV 0xAF
  77. #define SERIAL_9N1_RXINV_TXINV 0xB4
  78. #define SERIAL_9E1_RXINV_TXINV 0xBE
  79. #define SERIAL_9O1_RXINV_TXINV 0xBF
  80. #endif
  81. // Teensy LC and 3.5 and 3.6 Uarts have 1/2 bit stop setting
  82. #if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(KINETISL)
  83. #define SERIAL_2STOP_BITS 0x100
  84. #define SERIAL_8E2 (SERIAL_8E1 | SERIAL_2STOP_BITS)
  85. #define SERIAL_8O2 (SERIAL_8O1 | SERIAL_2STOP_BITS)
  86. #define SERIAL_8E2_RXINV (SERIAL_8E1_RXINV | SERIAL_2STOP_BITS)
  87. #define SERIAL_8O2_RXINV (SERIAL_8O1_RXINV | SERIAL_2STOP_BITS)
  88. #define SERIAL_8E2_TXINV (SERIAL_8E1_TXINV | SERIAL_2STOP_BITS)
  89. #define SERIAL_8O2_TXINV (SERIAL_8O1_TXINV | SERIAL_2STOP_BITS)
  90. #define SERIAL_8E2_RXINV_TXINV (SERIAL_8E1_RXINV_TXINV | SERIAL_2STOP_BITS)
  91. #define SERIAL_8O2_RXINV_TXINV (SERIAL_8O1_RXINV_TXINV | SERIAL_2STOP_BITS)
  92. #endif
  93. // bit0: parity, 0=even, 1=odd
  94. // bit1: parity, 0=disable, 1=enable
  95. // bit2: mode, 1=9bit, 0=8bit
  96. // bit3: mode10: 1=10bit, 0=8bit
  97. // bit4: rxinv, 0=normal, 1=inverted
  98. // bit5: txinv, 0=normal, 1=inverted
  99. // bit6: unused
  100. // bit7: actual data goes into 9th bit
  101. #if defined(KINETISK)
  102. #define BAUD2DIV(baud) (((F_CPU * 2) + ((baud) >> 1)) / (baud))
  103. #define BAUD2DIV2(baud) (((F_CPU * 2) + ((baud) >> 1)) / (baud))
  104. #define BAUD2DIV3(baud) (((F_BUS * 2) + ((baud) >> 1)) / (baud))
  105. #elif defined(KINETISL)
  106. #if F_CPU <= 2000000
  107. #define BAUD2DIV(baud) (((F_PLL / 16 ) + ((baud) >> 1)) / (baud))
  108. #elif F_CPU <= 16000000
  109. #define BAUD2DIV(baud) (((F_PLL / (F_PLL / 1000000)) + ((baud) >> 1)) / (baud))
  110. #else
  111. #define BAUD2DIV(baud) (((F_PLL / 2 / 16) + ((baud) >> 1)) / (baud))
  112. #endif
  113. #define BAUD2DIV2(baud) (((F_BUS / 16) + ((baud) >> 1)) / (baud))
  114. #define BAUD2DIV3(baud) (((F_BUS / 16) + ((baud) >> 1)) / (baud))
  115. #endif
  116. // C language implementation
  117. //
  118. #ifdef __cplusplus
  119. extern "C" {
  120. #endif
  121. void serial_begin(uint32_t divisor);
  122. void serial_format(uint32_t format);
  123. void serial_end(void);
  124. void serial_set_transmit_pin(uint8_t pin);
  125. void serial_set_rx(uint8_t pin);
  126. void serial_set_tx(uint8_t pin, uint8_t opendrain);
  127. int serial_set_rts(uint8_t pin);
  128. int serial_set_cts(uint8_t pin);
  129. void serial_putchar(uint32_t c);
  130. void serial_write(const void *buf, unsigned int count);
  131. void serial_flush(void);
  132. int serial_write_buffer_free(void);
  133. int serial_available(void);
  134. int serial_getchar(void);
  135. int serial_peek(void);
  136. void serial_clear(void);
  137. void serial_print(const char *p);
  138. void serial_phex(uint32_t n);
  139. void serial_phex16(uint32_t n);
  140. void serial_phex32(uint32_t n);
  141. void serial2_begin(uint32_t divisor);
  142. void serial2_format(uint32_t format);
  143. void serial2_end(void);
  144. void serial2_set_transmit_pin(uint8_t pin);
  145. void serial2_set_rx(uint8_t pin);
  146. void serial2_set_tx(uint8_t pin, uint8_t opendrain);
  147. int serial2_set_rts(uint8_t pin);
  148. int serial2_set_cts(uint8_t pin);
  149. void serial2_putchar(uint32_t c);
  150. void serial2_write(const void *buf, unsigned int count);
  151. void serial2_flush(void);
  152. int serial2_write_buffer_free(void);
  153. int serial2_available(void);
  154. int serial2_getchar(void);
  155. int serial2_peek(void);
  156. void serial2_clear(void);
  157. void serial3_begin(uint32_t divisor);
  158. void serial3_format(uint32_t format);
  159. void serial3_end(void);
  160. void serial3_set_transmit_pin(uint8_t pin);
  161. void serial3_set_rx(uint8_t pin);
  162. void serial3_set_tx(uint8_t pin, uint8_t opendrain);
  163. int serial3_set_rts(uint8_t pin);
  164. int serial3_set_cts(uint8_t pin);
  165. void serial3_putchar(uint32_t c);
  166. void serial3_write(const void *buf, unsigned int count);
  167. void serial3_flush(void);
  168. int serial3_write_buffer_free(void);
  169. int serial3_available(void);
  170. int serial3_getchar(void);
  171. int serial3_peek(void);
  172. void serial3_clear(void);
  173. void serial4_begin(uint32_t divisor);
  174. void serial4_format(uint32_t format);
  175. void serial4_end(void);
  176. void serial4_set_transmit_pin(uint8_t pin);
  177. void serial4_set_rx(uint8_t pin);
  178. void serial4_set_tx(uint8_t pin, uint8_t opendrain);
  179. int serial4_set_rts(uint8_t pin);
  180. int serial4_set_cts(uint8_t pin);
  181. void serial4_putchar(uint32_t c);
  182. void serial4_write(const void *buf, unsigned int count);
  183. void serial4_flush(void);
  184. int serial4_write_buffer_free(void);
  185. int serial4_available(void);
  186. int serial4_getchar(void);
  187. int serial4_peek(void);
  188. void serial4_clear(void);
  189. void serial5_begin(uint32_t divisor);
  190. void serial5_format(uint32_t format);
  191. void serial5_end(void);
  192. void serial5_set_transmit_pin(uint8_t pin);
  193. void serial5_set_rx(uint8_t pin);
  194. void serial5_set_tx(uint8_t pin, uint8_t opendrain);
  195. int serial5_set_rts(uint8_t pin);
  196. int serial5_set_cts(uint8_t pin);
  197. void serial5_putchar(uint32_t c);
  198. void serial5_write(const void *buf, unsigned int count);
  199. void serial5_flush(void);
  200. int serial5_write_buffer_free(void);
  201. int serial5_available(void);
  202. int serial5_getchar(void);
  203. int serial5_peek(void);
  204. void serial5_clear(void);
  205. void serial6_begin(uint32_t divisor);
  206. void serial6_format(uint32_t format);
  207. void serial6_end(void);
  208. void serial6_set_transmit_pin(uint8_t pin);
  209. void serial6_set_rx(uint8_t pin);
  210. void serial6_set_tx(uint8_t pin, uint8_t opendrain);
  211. int serial6_set_rts(uint8_t pin);
  212. int serial6_set_cts(uint8_t pin);
  213. void serial6_putchar(uint32_t c);
  214. void serial6_write(const void *buf, unsigned int count);
  215. void serial6_flush(void);
  216. int serial6_write_buffer_free(void);
  217. int serial6_available(void);
  218. int serial6_getchar(void);
  219. int serial6_peek(void);
  220. void serial6_clear(void);
  221. #ifdef __cplusplus
  222. }
  223. #endif
  224. // C++ interface
  225. //
  226. #ifdef __cplusplus
  227. #include "Stream.h"
  228. class HardwareSerial : public Stream
  229. {
  230. public:
  231. constexpr HardwareSerial() {}
  232. virtual void begin(uint32_t baud) { serial_begin(BAUD2DIV(baud)); }
  233. virtual void begin(uint32_t baud, uint32_t format) {
  234. serial_begin(BAUD2DIV(baud));
  235. serial_format(format); }
  236. virtual void end(void) { serial_end(); }
  237. virtual void transmitterEnable(uint8_t pin) { serial_set_transmit_pin(pin); }
  238. virtual void setRX(uint8_t pin) { serial_set_rx(pin); }
  239. virtual void setTX(uint8_t pin, bool opendrain=false) { serial_set_tx(pin, opendrain); }
  240. virtual bool attachRts(uint8_t pin) { return serial_set_rts(pin); }
  241. virtual bool attachCts(uint8_t pin) { return serial_set_cts(pin); }
  242. virtual int available(void) { return serial_available(); }
  243. virtual int peek(void) { return serial_peek(); }
  244. virtual int read(void) { return serial_getchar(); }
  245. virtual void flush(void) { serial_flush(); }
  246. virtual void clear(void) { serial_clear(); }
  247. virtual int availableForWrite(void) { return serial_write_buffer_free(); }
  248. using Print::write;
  249. virtual size_t write(uint8_t c) { serial_putchar(c); return 1; }
  250. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  251. virtual size_t write(long n) { return write((uint8_t)n); }
  252. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  253. virtual size_t write(int n) { return write((uint8_t)n); }
  254. virtual size_t write(const uint8_t *buffer, size_t size)
  255. { serial_write(buffer, size); return size; }
  256. virtual size_t write(const char *str) { size_t len = strlen(str);
  257. serial_write((const uint8_t *)str, len);
  258. return len; }
  259. virtual size_t write9bit(uint32_t c) { serial_putchar(c); return 1; }
  260. operator bool() { return true; }
  261. };
  262. extern HardwareSerial Serial1;
  263. extern void serialEvent1(void);
  264. class HardwareSerial2 : public HardwareSerial
  265. {
  266. public:
  267. constexpr HardwareSerial2() {}
  268. virtual void begin(uint32_t baud) { serial2_begin(BAUD2DIV2(baud)); }
  269. virtual void begin(uint32_t baud, uint32_t format) {
  270. serial2_begin(BAUD2DIV2(baud));
  271. serial2_format(format); }
  272. virtual void end(void) { serial2_end(); }
  273. virtual void transmitterEnable(uint8_t pin) { serial2_set_transmit_pin(pin); }
  274. virtual void setRX(uint8_t pin) { serial2_set_rx(pin); }
  275. virtual void setTX(uint8_t pin, bool opendrain=false) { serial2_set_tx(pin, opendrain); }
  276. virtual bool attachRts(uint8_t pin) { return serial2_set_rts(pin); }
  277. virtual bool attachCts(uint8_t pin) { return serial2_set_cts(pin); }
  278. virtual int available(void) { return serial2_available(); }
  279. virtual int peek(void) { return serial2_peek(); }
  280. virtual int read(void) { return serial2_getchar(); }
  281. virtual void flush(void) { serial2_flush(); }
  282. virtual void clear(void) { serial2_clear(); }
  283. virtual int availableForWrite(void) { return serial2_write_buffer_free(); }
  284. using Print::write;
  285. virtual size_t write(uint8_t c) { serial2_putchar(c); return 1; }
  286. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  287. virtual size_t write(long n) { return write((uint8_t)n); }
  288. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  289. virtual size_t write(int n) { return write((uint8_t)n); }
  290. virtual size_t write(const uint8_t *buffer, size_t size)
  291. { serial2_write(buffer, size); return size; }
  292. virtual size_t write(const char *str) { size_t len = strlen(str);
  293. serial2_write((const uint8_t *)str, len);
  294. return len; }
  295. virtual size_t write9bit(uint32_t c) { serial2_putchar(c); return 1; }
  296. operator bool() { return true; }
  297. };
  298. extern HardwareSerial2 Serial2;
  299. extern void serialEvent2(void);
  300. class HardwareSerial3 : public HardwareSerial
  301. {
  302. public:
  303. constexpr HardwareSerial3() {}
  304. virtual void begin(uint32_t baud) { serial3_begin(BAUD2DIV3(baud)); }
  305. virtual void begin(uint32_t baud, uint32_t format) {
  306. serial3_begin(BAUD2DIV3(baud));
  307. serial3_format(format); }
  308. virtual void end(void) { serial3_end(); }
  309. virtual void transmitterEnable(uint8_t pin) { serial3_set_transmit_pin(pin); }
  310. virtual void setRX(uint8_t pin) { serial3_set_rx(pin); }
  311. virtual void setTX(uint8_t pin, bool opendrain=false) { serial3_set_tx(pin, opendrain); }
  312. virtual bool attachRts(uint8_t pin) { return serial3_set_rts(pin); }
  313. virtual bool attachCts(uint8_t pin) { return serial3_set_cts(pin); }
  314. virtual int available(void) { return serial3_available(); }
  315. virtual int peek(void) { return serial3_peek(); }
  316. virtual int read(void) { return serial3_getchar(); }
  317. virtual void flush(void) { serial3_flush(); }
  318. virtual void clear(void) { serial3_clear(); }
  319. virtual int availableForWrite(void) { return serial3_write_buffer_free(); }
  320. using Print::write;
  321. virtual size_t write(uint8_t c) { serial3_putchar(c); return 1; }
  322. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  323. virtual size_t write(long n) { return write((uint8_t)n); }
  324. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  325. virtual size_t write(int n) { return write((uint8_t)n); }
  326. virtual size_t write(const uint8_t *buffer, size_t size)
  327. { serial3_write(buffer, size); return size; }
  328. virtual size_t write(const char *str) { size_t len = strlen(str);
  329. serial3_write((const uint8_t *)str, len);
  330. return len; }
  331. virtual size_t write9bit(uint32_t c) { serial3_putchar(c); return 1; }
  332. operator bool() { return true; }
  333. };
  334. extern HardwareSerial3 Serial3;
  335. extern void serialEvent3(void);
  336. class HardwareSerial4 : public HardwareSerial
  337. {
  338. public:
  339. constexpr HardwareSerial4() {}
  340. virtual void begin(uint32_t baud) { serial4_begin(BAUD2DIV3(baud)); }
  341. virtual void begin(uint32_t baud, uint32_t format) {
  342. serial4_begin(BAUD2DIV3(baud));
  343. serial4_format(format); }
  344. virtual void end(void) { serial4_end(); }
  345. virtual void transmitterEnable(uint8_t pin) { serial4_set_transmit_pin(pin); }
  346. virtual void setRX(uint8_t pin) { serial4_set_rx(pin); }
  347. virtual void setTX(uint8_t pin, bool opendrain=false) { serial4_set_tx(pin, opendrain); }
  348. virtual bool attachRts(uint8_t pin) { return serial4_set_rts(pin); }
  349. virtual bool attachCts(uint8_t pin) { return serial4_set_cts(pin); }
  350. virtual int available(void) { return serial4_available(); }
  351. virtual int peek(void) { return serial4_peek(); }
  352. virtual int read(void) { return serial4_getchar(); }
  353. virtual void flush(void) { serial4_flush(); }
  354. virtual void clear(void) { serial4_clear(); }
  355. virtual int availableForWrite(void) { return serial4_write_buffer_free(); }
  356. using Print::write;
  357. virtual size_t write(uint8_t c) { serial4_putchar(c); return 1; }
  358. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  359. virtual size_t write(long n) { return write((uint8_t)n); }
  360. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  361. virtual size_t write(int n) { return write((uint8_t)n); }
  362. virtual size_t write(const uint8_t *buffer, size_t size)
  363. { serial4_write(buffer, size); return size; }
  364. virtual size_t write(const char *str) { size_t len = strlen(str);
  365. serial4_write((const uint8_t *)str, len);
  366. return len; }
  367. virtual size_t write9bit(uint32_t c) { serial4_putchar(c); return 1; }
  368. operator bool() { return true; }
  369. };
  370. extern HardwareSerial4 Serial4;
  371. extern void serialEvent4(void);
  372. class HardwareSerial5 : public HardwareSerial
  373. {
  374. public:
  375. constexpr HardwareSerial5() {}
  376. virtual void begin(uint32_t baud) { serial5_begin(BAUD2DIV3(baud)); }
  377. virtual void begin(uint32_t baud, uint32_t format) {
  378. serial5_begin(BAUD2DIV3(baud));
  379. serial5_format(format); }
  380. virtual void end(void) { serial5_end(); }
  381. virtual void transmitterEnable(uint8_t pin) { serial5_set_transmit_pin(pin); }
  382. virtual void setRX(uint8_t pin) { serial5_set_rx(pin); }
  383. virtual void setTX(uint8_t pin, bool opendrain=false) { serial5_set_tx(pin, opendrain); }
  384. virtual bool attachRts(uint8_t pin) { return serial5_set_rts(pin); }
  385. virtual bool attachCts(uint8_t pin) { return serial5_set_cts(pin); }
  386. virtual int available(void) { return serial5_available(); }
  387. virtual int peek(void) { return serial5_peek(); }
  388. virtual int read(void) { return serial5_getchar(); }
  389. virtual void flush(void) { serial5_flush(); }
  390. virtual void clear(void) { serial5_clear(); }
  391. virtual int availableForWrite(void) { return serial5_write_buffer_free(); }
  392. using Print::write;
  393. virtual size_t write(uint8_t c) { serial5_putchar(c); return 1; }
  394. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  395. virtual size_t write(long n) { return write((uint8_t)n); }
  396. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  397. virtual size_t write(int n) { return write((uint8_t)n); }
  398. virtual size_t write(const uint8_t *buffer, size_t size)
  399. { serial5_write(buffer, size); return size; }
  400. virtual size_t write(const char *str) { size_t len = strlen(str);
  401. serial5_write((const uint8_t *)str, len);
  402. return len; }
  403. virtual size_t write9bit(uint32_t c) { serial5_putchar(c); return 1; }
  404. operator bool() { return true; }
  405. };
  406. extern HardwareSerial5 Serial5;
  407. extern void serialEvent5(void);
  408. class HardwareSerial6 : public HardwareSerial
  409. {
  410. public:
  411. constexpr HardwareSerial6() {}
  412. #if defined(__MK66FX1M0__) // For LPUART just pass baud straight in.
  413. virtual void begin(uint32_t baud) { serial6_begin(baud); }
  414. virtual void begin(uint32_t baud, uint32_t format) {
  415. serial6_begin(baud);
  416. serial6_format(format); }
  417. #else
  418. virtual void begin(uint32_t baud) { serial6_begin(BAUD2DIV3(baud)); }
  419. virtual void begin(uint32_t baud, uint32_t format) {
  420. serial6_begin(BAUD2DIV3(baud));
  421. serial6_format(format); }
  422. #endif
  423. virtual void end(void) { serial6_end(); }
  424. virtual void transmitterEnable(uint8_t pin) { serial6_set_transmit_pin(pin); }
  425. virtual void setRX(uint8_t pin) { serial6_set_rx(pin); }
  426. virtual void setTX(uint8_t pin, bool opendrain=false) { serial6_set_tx(pin, opendrain); }
  427. virtual bool attachRts(uint8_t pin) { return serial6_set_rts(pin); }
  428. virtual bool attachCts(uint8_t pin) { return serial6_set_cts(pin); }
  429. virtual int available(void) { return serial6_available(); }
  430. virtual int peek(void) { return serial6_peek(); }
  431. virtual int read(void) { return serial6_getchar(); }
  432. virtual void flush(void) { serial6_flush(); }
  433. virtual void clear(void) { serial6_clear(); }
  434. virtual int availableForWrite(void) { return serial6_write_buffer_free(); }
  435. using Print::write;
  436. virtual size_t write(uint8_t c) { serial6_putchar(c); return 1; }
  437. virtual size_t write(unsigned long n) { return write((uint8_t)n); }
  438. virtual size_t write(long n) { return write((uint8_t)n); }
  439. virtual size_t write(unsigned int n) { return write((uint8_t)n); }
  440. virtual size_t write(int n) { return write((uint8_t)n); }
  441. virtual size_t write(const uint8_t *buffer, size_t size)
  442. { serial6_write(buffer, size); return size; }
  443. virtual size_t write(const char *str) { size_t len = strlen(str);
  444. serial6_write((const uint8_t *)str, len);
  445. return len; }
  446. virtual size_t write9bit(uint32_t c) { serial6_putchar(c); return 1; }
  447. operator bool() { return true; }
  448. };
  449. extern HardwareSerial6 Serial6;
  450. extern void serialEvent6(void);
  451. #endif
  452. #endif