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

478 lines
19KB

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