Skip to content

Commit 8db7e7f

Browse files
committed
tested and verified to work
1 parent ba351a8 commit 8db7e7f

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

cores/esp32/HardwareSerial.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void HardwareSerial::updateBaudRate(unsigned long baud)
8484
}
8585

8686
// Make sure that the function that the function pointer is pointing to is inside IRAM
87-
void HardwareSerial::setRXInterrupt(void (*arg)(char* c)){
87+
void HardwareSerial::setRXInterrupt(void (*arg)(char c)){
8888
uartDisableInterrupt(_uart);
8989
uartEnableInterrupt(_uart, &arg);
9090
}

cores/esp32/HardwareSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class HardwareSerial: public Stream
5858
void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL);
5959
void end();
6060
void updateBaudRate(unsigned long baud);
61-
void setRXInterrupt(void (*arg)(char* c));
61+
void setRXInterrupt(void (*arg)(char));
6262
int available(void);
6363
int availableForWrite(void);
6464
int peek(void);

cores/esp32/esp32-hal-uart.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static uart_t _uart_bus_array[3] = {
6969

7070
static void uart_on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb);
7171

72-
static void IRAM_ATTR _uart_isr(void *arg)
72+
static void IRAM_ATTR _uart_isr(void (*arg)(char))
7373
{
7474
uint8_t i, c;
7575
BaseType_t xHigherPriorityTaskWoken;
@@ -87,7 +87,7 @@ static void IRAM_ATTR _uart_isr(void *arg)
8787
c = uart->dev->fifo.rw_byte;
8888
if(arg != NULL){ // Check if an interrupt handler function has been specified
8989
// Fully optimized code would not create the queue anymore if an function has been specified as an argument.
90-
(*((void(**)())arg))(c); // There is, call it with c as an parameter. Don't pass it to the queue anymore
90+
(*arg)((char*)&c); // There is, call it with c as an parameter. Don't pass it to the queue anymore
9191
}else if(uart->queue != NULL) {
9292
xQueueSendFromISR(uart->queue, &c, &xHigherPriorityTaskWoken);
9393
}
@@ -99,7 +99,7 @@ static void IRAM_ATTR _uart_isr(void *arg)
9999
}
100100
}
101101

102-
void uartEnableInterrupt(uart_t* uart, void * func)
102+
void uartEnableInterrupt(uart_t* uart, void (*func)(char))
103103
{
104104
UART_MUTEX_LOCK();
105105
uart->dev->conf1.rxfifo_full_thrhd = 112;

cores/esp32/esp32-hal-uart.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ unsigned long uartDetectBaudrate(uart_t *uart);
8181
bool uartRxActive(uart_t* uart);
8282

8383
void uartDisableInterrupt(uart_t* uart);
84-
void uartEnableInterrupt(uart_t* uart,void * func );
84+
void uartEnableInterrupt(uart_t* uart, void (*func)(char));
8585

8686
#ifdef __cplusplus
8787
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
HardwareSerial hwSerial(0);
22
HardwareSerial hwSerial2(2);
33

4+
static void IRAM_ATTR onSerialRX(char c){
5+
hwSerial.print(c);
6+
}
7+
48
void setup()
59
{
610
hwSerial.begin(115200);
711
hwSerial2.begin(115200);
8-
hwSerial2.setRXInterrupt(onSerialRX);
12+
hwSerial2.setRXInterrupt(&onSerialRX);
913

1014
}
1115

1216
void loop()
1317
{
1418
delay(1);
1519
}
16-
17-
void onSerialRX(char* c){
18-
hwSerial.print(c);
19-
}

0 commit comments

Comments
 (0)