Skip to content

Commit 6d51555

Browse files
committed
Serial: add bind() API for transparent passthrough
1 parent c8a1dd9 commit 6d51555

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

cores/arduino/UART.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ class UartClass : public HardwareSerial
168168
using Print::write; // pull in write(str) and write(buf, size) from Print
169169
explicit operator bool() { return true; }
170170

171+
void bind(UartClass& ser) {bound = &ser; }
172+
171173
// Interrupt handlers - Not intended to be called externally
172174
inline void _rx_complete_irq(void);
173175
void _tx_data_empty_irq(void);
174176
private:
175177
void _poll_tx_data_empty(void);
178+
UartClass* bound = NULL;
176179
};
177180

178181
#if defined(HWSERIAL0)

cores/arduino/UART_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ void UartClass::_rx_complete_irq(void)
6666
_rx_buffer[_rx_buffer_head] = c;
6767
_rx_buffer_head = i;
6868
}
69+
if (bound != NULL) {
70+
bound->write(c);
71+
}
6972
} else {
7073
// Parity error, read byte but discard it
7174
(*_hwserial_module).RXDATAL;

0 commit comments

Comments
 (0)