|
32 | 32 | // using a ring buffer (I think), in which head is the index of the location
|
33 | 33 | // to which to write the next incoming character and tail is the index of the
|
34 | 34 | // location from which to read.
|
| 35 | +#if !(defined(SERIAL_TX_BUFFER_SIZE) && defined(SERIAL_RX_BUFFER_SIZE)) |
35 | 36 | #if (RAMEND < 1000)
|
36 |
| - #define SERIAL_BUFFER_SIZE 16 |
| 37 | +#define SERIAL_TX_BUFFER_SIZE 16 |
| 38 | +#define SERIAL_RX_BUFFER_SIZE 16 |
37 | 39 | #else
|
38 |
| - #define SERIAL_BUFFER_SIZE 64 |
| 40 | +#define SERIAL_TX_BUFFER_SIZE 64 |
| 41 | +#define SERIAL_RX_BUFFER_SIZE 64 |
| 42 | +#endif |
| 43 | +#endif |
| 44 | +#if (SERIAL_TX_BUFFER_SIZE>256) |
| 45 | +typedef uint16_t tx_buffer_index_t; |
| 46 | +#else |
| 47 | +typedef uint8_t tx_buffer_index_t; |
| 48 | +#endif |
| 49 | +#if (SERIAL_RX_BUFFER_SIZE>256) |
| 50 | +typedef uint16_t rx_buffer_index_t; |
| 51 | +#else |
| 52 | +typedef uint8_t rx_buffer_index_t; |
39 | 53 | #endif
|
40 | 54 |
|
41 | 55 | // Define config for Serial.begin(baud, config);
|
@@ -76,16 +90,16 @@ class HardwareSerial : public Stream
|
76 | 90 | // Has any byte been written to the UART since begin()
|
77 | 91 | bool _written;
|
78 | 92 |
|
79 |
| - volatile uint8_t _rx_buffer_head; |
80 |
| - volatile uint8_t _rx_buffer_tail; |
81 |
| - volatile uint8_t _tx_buffer_head; |
82 |
| - volatile uint8_t _tx_buffer_tail; |
| 93 | + volatile rx_buffer_index_t _rx_buffer_head; |
| 94 | + volatile rx_buffer_index_t _rx_buffer_tail; |
| 95 | + volatile tx_buffer_index_t _tx_buffer_head; |
| 96 | + volatile tx_buffer_index_t _tx_buffer_tail; |
83 | 97 |
|
84 | 98 | // Don't put any members after these buffers, since only the first
|
85 | 99 | // 32 bytes of this struct can be accessed quickly using the ldd
|
86 | 100 | // instruction.
|
87 |
| - unsigned char _rx_buffer[SERIAL_BUFFER_SIZE]; |
88 |
| - unsigned char _tx_buffer[SERIAL_BUFFER_SIZE]; |
| 101 | + unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE]; |
| 102 | + unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE]; |
89 | 103 |
|
90 | 104 | public:
|
91 | 105 | inline HardwareSerial(
|
|
0 commit comments