@@ -47,48 +47,23 @@ typedef struct
4747 void * malloced_data ;
4848 void * callback_func ;
4949
50- uint8_t callback_type ;
5150 uint8_t arg_count ;
51+ // uint8_t callback_type;
5252// uint8_t _reserved[2];
5353
5454 uint32_t arguments [1 ]; // flexible array holder
5555}ada_callback_t ;
5656
5757static_assert (sizeof (ada_callback_t ) == 16 , "Incorrect Size" );
5858
59- /*------------- Defer -------------*/
59+ /*------------- Defer callback type, determined by number of arguments -------------*/
6060typedef void (* adacb_0arg_t ) (void );
6161typedef void (* adacb_1arg_t ) (uint32_t );
6262typedef void (* adacb_2arg_t ) (uint32_t , uint32_t );
6363typedef void (* adacb_3arg_t ) (uint32_t , uint32_t , uint32_t );
6464typedef void (* adacb_4arg_t ) (uint32_t , uint32_t , uint32_t , uint32_t );
6565typedef void (* adacb_5arg_t ) (uint32_t , uint32_t , uint32_t , uint32_t , uint32_t );
6666
67- /*------------------------------------------------------------------*/
68- /* X Macros expansion for callback function
69- * If callbacks from separated classes share the same prototype, only
70- * one instance is enough (mandatory)
71- *------------------------------------------------------------------*/
72- #define ADA_CB_LOOKUP (XPAND ) \
73- XPAND(BLEClientCharacteristic , notify_cb_t ) \
74- /*XPAND(BLEClientCharacteristic , indicate_cb_t)*/ \
75-
76- #define ADA_CB_ENUM_XPAND (_class , _cbname ) \
77- _class##_##_cbname,
78-
79-
80- #define ADA_CB_FUNC_XPAND (_class , _cbname ) \
81- static inline uint8_t ada_callback_type(_class::_cbname _func) { (void) _func; return _class##_##_cbname; }
82-
83- enum
84- {
85- ADA_CB_LOOKUP (ADA_CB_ENUM_XPAND )
86-
87- ADA_CB_DEFERRED_FUNC ,
88- };
89-
90- ADA_CB_LOOKUP (ADA_CB_FUNC_XPAND )
91-
9267/*------------------------------------------------------------------*/
9368/* Macros to force uint32_t casting to all arguments (up to 5)
9469 *------------------------------------------------------------------*/
@@ -103,13 +78,16 @@ ADA_CB_LOOKUP(ADA_CB_FUNC_XPAND)
10378
10479#define _ADA_CB_ARGS (...) _GET_6TH_ARG(_0, ##__VA_ARGS__, _ADA_CB_ARGS_5, _ADA_CB_ARGS_4, _ADA_CB_ARGS_3, _ADA_CB_ARGS_2, _ADA_CB_ARGS_1, _ADA_CB_ARGS_0)(__VA_ARGS__)
10580
106- #define _ada_cb_setup (_malloced , _func , _func_type , ... ) \
81+ /**
82+ * Macro function is called by other module with all intended parameters.
83+ * The first parameter is malloced Pointer (NULL if not), so that callback could know to free memory
84+ */
85+ #define ada_callback (_malloced , _func , ... ) \
10786 do { \
10887 uint8_t const _count = VA_ARGS_NUM(__VA_ARGS__);\
10988 ada_callback_t* cb_data = (ada_callback_t*) rtos_malloc( sizeof(ada_callback_t) + (_count ? (_count-1)*4 : 0) ); \
11089 cb_data->malloced_data = _malloced;\
11190 cb_data->callback_func = (void*)_func;\
112- cb_data->callback_type = _func_type;\
11391 cb_data->arg_count = _count;\
11492 if ( _count ) {\
11593 uint32_t arguments[] = { _ADA_CB_ARGS(__VA_ARGS__) };\
@@ -118,13 +96,6 @@ ADA_CB_LOOKUP(ADA_CB_FUNC_XPAND)
11896 ada_callback_queue(cb_data);\
11997 } while(0)
12098
121- /**
122- * Macro function is called by other module with all intended parameters.
123- * The first parameter is malloced Pointer (NULL if not), so that callback could know to free memory
124- */
125- #define ada_callback (_malloced , _func , ... ) _ada_cb_setup(_malloced, _func, ada_callback_type(_func), __VA_ARGS__)
126- #define ada_callback_defer (_malloced , _func , ...) _ada_cb_setup(_malloced, _func, ADA_CB_DEFERRED_FUNC , __VA_ARGS__)
127-
12899void ada_callback_init (void );
129100void ada_callback_queue (ada_callback_t * cb_data );
130101
0 commit comments