Skip to content

Commit b298b5c

Browse files
committed
TEST: try to fix Break2 via callback redirection
1 parent 698c5dc commit b298b5c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: examples/Breaks_2/Thread.inot

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void myEventHandler()
1212

1313
void setup()
1414
{
15-
attachInterrupt(digitalPinToInterrupt(2), myEventHandler, CHANGE);
15+
attachInterrupt(digitalPinToInterrupt(2), CB(myEventHandler), CHANGE);
1616
}
1717

1818
void loop()

Diff for: src/Arduino_Threads.h

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ public: \
9090

9191
#define ARDUINO_THREADS_TO_STRING(sequence) #sequence
9292

93+
94+
/**************************************************************************************
95+
* CALLBACK HELPERS DECLARATION
96+
**************************************************************************************/
97+
struct __callback__container__ {
98+
mbed::Callback<void()> fn;
99+
};
100+
101+
inline void attachInterrupt(pin_size_t interruptNum, mbed::Callback<void()> func, PinStatus mode) {
102+
struct __callback__container__* a = new __callback__container__();
103+
a->fn = func;
104+
auto callback = [](void* a) -> void {
105+
((__callback__container__*)a)->fn();
106+
};
107+
108+
attachInterruptParam(interruptNum, callback, mode, (void*)a);
109+
}
110+
111+
#define CB(x) mbed::callback(this, &ARDUINO_THREADS_CONCAT(tabname, Class)::x)
112+
93113
/**************************************************************************************
94114
* CLASS DECLARATION
95115
**************************************************************************************/

0 commit comments

Comments
 (0)