Skip to content

Commit eb648c1

Browse files
committed
added optional argument pointer
added optional argument pointer, see arduino/ArduinoCore-sam#95 (comment)
1 parent b4f3984 commit eb648c1

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Diff for: cores/arduino/HardwareSerial.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,12 @@ size_t HardwareSerial::write(uint8_t c)
285285
return 1;
286286
}
287287

288-
void HardwareSerial::attachInterrupt_Receive( isrRx_t fn )
288+
void HardwareSerial::attachInterrupt_Receive( isrRx_t fn, void* args )
289289
{
290290
uint8_t oldSREG = SREG;
291291
cli();
292292
_isrRx = fn;
293+
_rxArg = args;
293294
SREG = oldSREG;
294295
}
295296

Diff for: cores/arduino/HardwareSerial.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ class HardwareSerial : public Stream
119119
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
120120

121121
// custom handlers for RX and TXC interrupts
122-
typedef void (* isrRx_t)( uint8_t d, uint8_t s );
122+
typedef void (* isrRx_t)( uint8_t data, uint8_t status, void* args );
123123
typedef void (* isrTx_t)( void );
124124
isrRx_t _isrRx;
125125
isrTx_t _isrTx;
126+
void* _rxArg;
126127

127128
public:
128129
inline HardwareSerial(
@@ -151,7 +152,7 @@ class HardwareSerial : public Stream
151152
inline void _tx_complete_irq(void);
152153

153154
// attach custom handlers for RX and TXC interrupts
154-
void attachInterrupt_Receive( isrRx_t fn );
155+
void attachInterrupt_Receive( isrRx_t fn, void *args = NULL );
155156
void detachInterrupt_Receive( void ) { attachInterrupt_Receive( (isrRx_t) NULL ); };
156157
void attachInterrupt_Send( isrTx_t fn );
157158
void detachInterrupt_Send( void );

Diff for: cores/arduino/HardwareSerial_private.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ HardwareSerial::HardwareSerial(
9595
_udr(udr),
9696
_rx_buffer_head(0), _rx_buffer_tail(0),
9797
_tx_buffer_head(0), _tx_buffer_tail(0),
98-
_isrRx(NULL), _isrTx(dummyTxFct)
98+
_isrRx(NULL), _isrTx(dummyTxFct), _rxArg(NULL)
9999
{
100100
}
101101

102102
// Actual interrupt handlers //////////////////////////////////////////////////////////////
103103

104104
void HardwareSerial::_rx_complete_irq(void)
105105
{
106-
// user receive function was attached -> call it with data and status byte
106+
// user receive function was attached -> call it with data, status byte and optional argument pointer
107107
if (_isrRx) {
108108
unsigned char status = *_ucsra;
109109
unsigned char data = *_udr;
110-
_isrRx( data, status );
110+
_isrRx( data, status, _rxArg );
111111
}
112112

113113
// default: save data in ring buffer

0 commit comments

Comments
 (0)