File tree 3 files changed +8
-6
lines changed
3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -285,11 +285,12 @@ size_t HardwareSerial::write(uint8_t c)
285
285
return 1 ;
286
286
}
287
287
288
- void HardwareSerial::attachInterrupt_Receive ( isrRx_t fn )
288
+ void HardwareSerial::attachInterrupt_Receive ( isrRx_t fn, void * args )
289
289
{
290
290
uint8_t oldSREG = SREG;
291
291
cli ();
292
292
_isrRx = fn;
293
+ _rxArg = args;
293
294
SREG = oldSREG;
294
295
}
295
296
Original file line number Diff line number Diff line change @@ -119,10 +119,11 @@ class HardwareSerial : public Stream
119
119
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
120
120
121
121
// 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 );
123
123
typedef void (* isrTx_t)( void );
124
124
isrRx_t _isrRx;
125
125
isrTx_t _isrTx;
126
+ void * _rxArg;
126
127
127
128
public:
128
129
inline HardwareSerial (
@@ -151,7 +152,7 @@ class HardwareSerial : public Stream
151
152
inline void _tx_complete_irq (void );
152
153
153
154
// 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 );
155
156
void detachInterrupt_Receive ( void ) { attachInterrupt_Receive ( (isrRx_t) NULL ); };
156
157
void attachInterrupt_Send ( isrTx_t fn );
157
158
void detachInterrupt_Send ( void );
Original file line number Diff line number Diff line change @@ -95,19 +95,19 @@ HardwareSerial::HardwareSerial(
95
95
_udr (udr ),
96
96
_rx_buffer_head (0 ), _rx_buffer_tail (0 ),
97
97
_tx_buffer_head (0 ), _tx_buffer_tail (0 ),
98
- _isrRx (NULL ), _isrTx (dummyTxFct )
98
+ _isrRx (NULL ), _isrTx (dummyTxFct ), _rxArg ( NULL )
99
99
{
100
100
}
101
101
102
102
// Actual interrupt handlers //////////////////////////////////////////////////////////////
103
103
104
104
void HardwareSerial ::_rx_complete_irq (void )
105
105
{
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
107
107
if (_isrRx ) {
108
108
unsigned char status = * _ucsra ;
109
109
unsigned char data = * _udr ;
110
- _isrRx ( data , status );
110
+ _isrRx ( data , status , _rxArg );
111
111
}
112
112
113
113
// default: save data in ring buffer
You can’t perform that action at this time.
0 commit comments