Skip to content

Commit bd585e5

Browse files
committed
Add HardwareSerial 9 bit
Add HardwareSerial 9 bit
1 parent 50a27fb commit bd585e5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

api/HardwareSerial.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace arduino {
4141
#define SERIAL_DATA_6 (0x200ul)
4242
#define SERIAL_DATA_7 (0x300ul)
4343
#define SERIAL_DATA_8 (0x400ul)
44+
#define SERIAL_DATA_9 (0x500ul)
4445
#define SERIAL_DATA_MASK (0xF00ul)
4546

4647
#define SERIAL_5N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_5)
@@ -83,7 +84,12 @@ namespace arduino {
8384
#define SERIAL_6S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_6)
8485
#define SERIAL_7S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_7)
8586
#define SERIAL_8S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_8)
86-
87+
#define SERIAL_9N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_9)
88+
#define SERIAL_9N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_9)
89+
#define SERIAL_9E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_9)
90+
#define SERIAL_9E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_9)
91+
#define SERIAL_9O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_9)
92+
#define SERIAL_9O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_9)
8793
class HardwareSerial : public Stream
8894
{
8995
public:
@@ -97,6 +103,9 @@ class HardwareSerial : public Stream
97103
virtual size_t write(uint8_t) = 0;
98104
using Print::write; // pull in write(str) and write(buf, size) from Print
99105
virtual operator bool() = 0;
106+
virtual size_t write9bit(uint8_t) = 0;
107+
virtual void set_tx_mode(void) = 0;
108+
virtual void set_rx_mode(void) = 0;
100109
};
101110

102111
// XXX: Are we keeping the serialEvent API?

api/RingBuffer.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ namespace arduino {
3030
// using a ring buffer (I think), in which head is the index of the location
3131
// to which to write the next incoming character and tail is the index of the
3232
// location from which to read.
33-
#define SERIAL_BUFFER_SIZE 64
33+
#define SERIAL_BUFFER_SIZE 256
3434

3535
template <int N>
3636
class RingBufferN
3737
{
3838
public:
39-
uint8_t _aucBuffer[N] ;
39+
uint16_t _aucBuffer[N] ;
4040
volatile int _iHead ;
4141
volatile int _iTail ;
4242
volatile int _numElems;
4343

4444
public:
4545
RingBufferN( void ) ;
46-
void store_char( uint8_t c ) ;
46+
void store_char( uint16_t c ) ;
4747
void clear();
4848
int read_char();
4949
int available();
@@ -62,12 +62,12 @@ typedef RingBufferN<SERIAL_BUFFER_SIZE> RingBuffer;
6262
template <int N>
6363
RingBufferN<N>::RingBufferN( void )
6464
{
65-
memset( _aucBuffer, 0, N ) ;
65+
memset( _aucBuffer, 0, (N * 2) ) ;
6666
clear();
6767
}
6868

6969
template <int N>
70-
void RingBufferN<N>::store_char( uint8_t c )
70+
void RingBufferN<N>::store_char( uint16_t c )
7171
{
7272
// if we should be storing the received character into the location
7373
// just before the tail (meaning that the head would advance to the
@@ -77,7 +77,7 @@ void RingBufferN<N>::store_char( uint8_t c )
7777
{
7878
_aucBuffer[_iHead] = c ;
7979
_iHead = nextIndex(_iHead);
80-
_numElems = _numElems + 1;
80+
_numElems++;
8181
}
8282
}
8383

@@ -95,9 +95,9 @@ int RingBufferN<N>::read_char()
9595
if (isEmpty())
9696
return -1;
9797

98-
uint8_t value = _aucBuffer[_iTail];
98+
uint16_t value = _aucBuffer[_iTail];
9999
_iTail = nextIndex(_iTail);
100-
_numElems = _numElems - 1;
100+
_numElems--;
101101

102102
return value;
103103
}
@@ -138,4 +138,4 @@ bool RingBufferN<N>::isFull()
138138
}
139139

140140
#endif /* _RING_BUFFER_ */
141-
#endif /* __cplusplus */
141+
#endif /* __cplusplus */

0 commit comments

Comments
 (0)