|
| 1 | +#pragma once |
| 2 | + |
| 3 | +//#include <inttypes.h> |
| 4 | +#include "Stream.h" |
| 5 | + |
| 6 | +// definitions neeeded for Serial.begin's config arg |
| 7 | +#define SERIAL_5N1 0x00 |
| 8 | +#define SERIAL_6N1 0x02 |
| 9 | +#define SERIAL_7N1 0x04 |
| 10 | +#define SERIAL_8N1 0x06 |
| 11 | +#define SERIAL_5N2 0x08 |
| 12 | +#define SERIAL_6N2 0x0A |
| 13 | +#define SERIAL_7N2 0x0C |
| 14 | +#define SERIAL_8N2 0x0E |
| 15 | +#define SERIAL_5E1 0x20 |
| 16 | +#define SERIAL_6E1 0x22 |
| 17 | +#define SERIAL_7E1 0x24 |
| 18 | +#define SERIAL_8E1 0x26 |
| 19 | +#define SERIAL_5E2 0x28 |
| 20 | +#define SERIAL_6E2 0x2A |
| 21 | +#define SERIAL_7E2 0x2C |
| 22 | +#define SERIAL_8E2 0x2E |
| 23 | +#define SERIAL_5O1 0x30 |
| 24 | +#define SERIAL_6O1 0x32 |
| 25 | +#define SERIAL_7O1 0x34 |
| 26 | +#define SERIAL_8O1 0x36 |
| 27 | +#define SERIAL_5O2 0x38 |
| 28 | +#define SERIAL_6O2 0x3A |
| 29 | +#define SERIAL_7O2 0x3C |
| 30 | +#define SERIAL_8O2 0x3E |
| 31 | + |
| 32 | +class HardwareSerial : public Stream |
| 33 | +{ |
| 34 | + protected: |
| 35 | + String* mGodmodeDataOut; |
| 36 | + |
| 37 | + public: |
| 38 | + HardwareSerial(String* dataIn, String* dataOut, unsigned long* delay): Stream() { |
| 39 | + mGodmodeDataIn = dataIn; |
| 40 | + mGodmodeDataOut = dataOut; |
| 41 | + mGodmodeMicrosDelay = delay; |
| 42 | + } |
| 43 | + void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } |
| 44 | + void begin(unsigned long baud, uint8_t config) { |
| 45 | + *mGodmodeMicrosDelay = 1000000 / baud; |
| 46 | + } |
| 47 | + void end() {} |
| 48 | + |
| 49 | + // virtual int available(void); |
| 50 | + // virtual int peek(void); |
| 51 | + // virtual int read(void); |
| 52 | + // virtual int availableForWrite(void); |
| 53 | + // virtual void flush(void); |
| 54 | + virtual size_t write(uint8_t aChar) { mGodmodeDataOut->append(String((char)aChar)); return 1; } |
| 55 | + |
| 56 | + inline size_t write(unsigned long n) { return write((uint8_t)n); } |
| 57 | + inline size_t write(long n) { return write((uint8_t)n); } |
| 58 | + inline size_t write(unsigned int n) { return write((uint8_t)n); } |
| 59 | + inline size_t write(int n) { return write((uint8_t)n); } |
| 60 | + // using Print::write; // pull in write(str) and write(buf, size) from Print |
| 61 | + operator bool() { return true; } |
| 62 | + |
| 63 | +}; |
| 64 | + |
| 65 | +#if defined(UBRRH) || defined(UBRR0H) |
| 66 | + extern HardwareSerial Serial; |
| 67 | + #define HAVE_HWSERIAL0 |
| 68 | +#endif |
| 69 | +#if defined(UBRR1H) |
| 70 | + extern HardwareSerial Serial1; |
| 71 | + #define HAVE_HWSERIAL1 |
| 72 | +#endif |
| 73 | +#if defined(UBRR2H) |
| 74 | + extern HardwareSerial Serial2; |
| 75 | + #define HAVE_HWSERIAL2 |
| 76 | +#endif |
| 77 | +#if defined(UBRR3H) |
| 78 | + extern HardwareSerial Serial3; |
| 79 | + #define HAVE_HWSERIAL3 |
| 80 | +#endif |
| 81 | + |
0 commit comments