Teensy 4.1 core updated for C++20
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.

492 lines
20KB

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