diff --git a/cores/nRF5/WInterrupts.c b/cores/nRF5/WInterrupts.c index 3ca2f8b4..9f698852 100644 --- a/cores/nRF5/WInterrupts.c +++ b/cores/nRF5/WInterrupts.c @@ -151,7 +151,7 @@ void GPIOTE_IRQHandler() if (channelMap[ch] != -1 && callbacksInt[ch]) { if ( callbackDeferred[ch] ) { // Adafruit defer callback to non-isr if configured so - ada_callback_fromISR(NULL, 0, callbacksInt[ch]); + ada_callback(NULL, 0, callbacksInt[ch]); }else{ callbacksInt[ch](); } diff --git a/cores/nRF5/utility/AdaCallback.c b/cores/nRF5/utility/AdaCallback.c index 0066bc2f..a2b992e7 100644 --- a/cores/nRF5/utility/AdaCallback.c +++ b/cores/nRF5/utility/AdaCallback.c @@ -72,9 +72,15 @@ void adafruit_callback_task(void* arg) } } -void ada_callback_queue(ada_callback_t* cb_data, bool from_isr) +//! Test if in interrupt mode +static inline bool is_isr(void) { - if ( from_isr ) + return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0 ; +} + +void ada_callback_queue(ada_callback_t* cb_data) +{ + if ( is_isr() ) { xQueueSendFromISR(_cb_queue, (void*) &cb_data, NULL); }else diff --git a/cores/nRF5/utility/AdaCallback.h b/cores/nRF5/utility/AdaCallback.h index cf3b75b9..cfc21f01 100644 --- a/cores/nRF5/utility/AdaCallback.h +++ b/cores/nRF5/utility/AdaCallback.h @@ -94,7 +94,7 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); /** * Macro function is called by other module with all intended parameters. */ -#define _cb_setup(_from_isr, _mdata, _mlen, _func, ... ) \ +#define _cb_setup(_mdata, _mlen, _func, ... ) \ do { \ uint8_t const _count = VA_ARGS_NUM(__VA_ARGS__); \ ada_callback_t* cb_data = (ada_callback_t*) rtos_malloc( sizeof(ada_callback_t) + (_count ? (_count-1)*4 : 0) );\ @@ -115,7 +115,7 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); }\ memcpy(cb_data->arguments, arguments, 4*_count); \ } \ - ada_callback_queue(cb_data, _from_isr); \ + ada_callback_queue(cb_data); \ } while(0) /** @@ -127,15 +127,11 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); * - 3rd arg : function to be invoked * - 3rd-7th arg : function argument, will be cast to uint32_t */ -#define ada_callback(... ) _cb_setup(false, __VA_ARGS__) +#define ada_callback(...) _cb_setup(__VA_ARGS__) -/** - * Similar to ada_callback() but invoke in ISR-context - */ -#define ada_callback_fromISR(... ) _cb_setup(true, __VA_ARGS__) void ada_callback_init(void); -void ada_callback_queue(ada_callback_t* cb_data, bool from_isr); +void ada_callback_queue(ada_callback_t* cb_data); #ifdef __cplusplus } diff --git a/libraries/RotaryEncoder/RotaryEncoder.cpp b/libraries/RotaryEncoder/RotaryEncoder.cpp index 15dc5c8b..6bbda91b 100644 --- a/libraries/RotaryEncoder/RotaryEncoder.cpp +++ b/libraries/RotaryEncoder/RotaryEncoder.cpp @@ -195,7 +195,7 @@ void HwRotaryEncoder::_irq_handler(void) if ( _cb ) { int32_t step = read(); - if ( step ) ada_callback_fromISR(NULL, 0, _cb, step); + if ( step ) ada_callback(NULL, 0, _cb, step); } } } diff --git a/libraries/RotaryEncoder/SwRotaryEncoder.cpp b/libraries/RotaryEncoder/SwRotaryEncoder.cpp index 6d256c4d..8cf4a8bc 100644 --- a/libraries/RotaryEncoder/SwRotaryEncoder.cpp +++ b/libraries/RotaryEncoder/SwRotaryEncoder.cpp @@ -138,7 +138,7 @@ void SwRotaryEncoder::_irq_handler(void) _abs += step; _a_last = bita; - if (_cb) ada_callback_fromISR(NULL, 0, _cb, step); + if (_cb) ada_callback(NULL, 0, _cb, step); } }