You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/16 12:52:07 UTC
[GitHub] mkiiskila closed pull request #1054: hw/util/button: allow to
specify eventq
mkiiskila closed pull request #1054: hw/util/button: allow to specify eventq
URL: https://github.com/apache/mynewt-core/pull/1054
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/hw/util/button/include/button/button.h b/hw/util/button/include/button/button.h
index 6991b1ccdf..a5509eab17 100644
--- a/hw/util/button/include/button/button.h
+++ b/hw/util/button/include/button/button.h
@@ -62,7 +62,7 @@
* debounce_init(&dbtn_2, BUTTON_2, HAL_GPIO_PULL_UP, 5);
*
* debounce_start(&dbtn_1, DEBOUNCE_CALLBACK_EVENT_ANY,
- * button_debounce_handler, &btns[0]);
+ * button_debounce_handler, &btns[0]);
* debounce_start(&dbtn_2, DEBOUNCE_CALLBACK_EVENT_ANY,
* button_debounce_handler, &btns[1]);
*
@@ -70,7 +70,7 @@
*
* void button_callback(button_id_t id, uint8_t type, uint8_t flags) {
* if (type != BUTTON_ACTION) // Only interested by action
- * return;
+ * return;
*
* switch(id) {
* case 1:
@@ -78,11 +78,11 @@
* alert("some action was lost");
* console_printf("BUTTON[%d] ", id);
* if (flags & BUTTON_FLG_PRESSED) {
- * console_printf("ACTION=");
- * if (flags & BUTTON_FLG_LONG) console_printf("long ");
+ * console_printf("ACTION=");
+ * if (flags & BUTTON_FLG_LONG) console_printf("long ");
* if (flags & BUTTON_FLG_DOUBLED) console_printf("double ");
* console_printf("click");
- * if (flags & BUTTON_FLG_REPEATING) console_printf(" repeated");
+ * if (flags & BUTTON_FLG_REPEATING) console_printf(" repeated");
* console_printf("\n");
* }
* break;
@@ -118,40 +118,40 @@
/**
* Pressed state/action
*/
-#define BUTTON_FLG_PRESSED 0x01
+#define BUTTON_FLG_PRESSED 0x01
#if MYNEWT_VAL(BUTTON_USE_DOUBLE)
/**
* Doubled pressed state/action
*/
-#define BUTTON_FLG_DOUBLED 0x02
+#define BUTTON_FLG_DOUBLED 0x02
#endif
#if MYNEWT_VAL(BUTTON_USE_LONG)
/**
* Long pressed state/action
*/
-#define BUTTON_FLG_LONG 0x04
+#define BUTTON_FLG_LONG 0x04
#endif
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
/**
* Repeating state, continuously repeating last action
*/
-#define BUTTON_FLG_REPEATING 0x08
+#define BUTTON_FLG_REPEATING 0x08
#endif
/**
* Some event have been missed (not enough buffer event,
* increase BUTTON_EVENT_MAX)
*/
-#define BUTTON_FLG_MISSED 0x40
+#define BUTTON_FLG_MISSED 0x40
/**
* Indicate State Changed
*/
-#define BUTTON_STATE_CHANGED 0x01
+#define BUTTON_STATE_CHANGED 0x01
/**
* Indicate Action
*/
-#define BUTTON_ACTION 0x02
+#define BUTTON_ACTION 0x02
/**
@@ -293,6 +293,14 @@ typedef struct button {
* Type of state changed or action that should be taken into account.
*/
uint8_t mode;
+#if MYNEWT_VAL(BUTTON_USE_PER_BUTTON_CALLBACK_EVENTQ) > 0
+ /**
+ * Specific Event queue for this button callback.
+ * If not defined (ie: is NULL), the default event queue
+ * specified by button_callback_default_evq_set() will be used.
+ */
+ struct os_eventq *eventq;
+#endif
/*
* Current button state
*/
@@ -327,18 +335,18 @@ typedef struct button {
#endif
#if MYNEWT_VAL(BUTTON_USE_FILTERING)
struct {
- /**
- * Enable filtering (reducing number of events emited)
- */
- bool enabled;
- /**
- * List of state change to emit, based on BUTTON_FLG_*
- */
- uint8_t state;
- /**
- * List of action to emit, base on BUTTON_FLG_*
- */
- uint8_t action;
+ /**
+ * Enable filtering (reducing number of events emited)
+ */
+ bool enabled;
+ /**
+ * List of state change to emit, based on BUTTON_FLG_*
+ */
+ uint8_t state;
+ /**
+ * List of action to emit, base on BUTTON_FLG_*
+ */
+ uint8_t action;
} filter;
#endif
} button_t;
@@ -346,9 +354,9 @@ typedef struct button {
/**
* Definition of the callback use to notify of action or state change.
*
- * @param button concerned button
- * @param type type of event (BUTTON_STATE_CHANGED or BUTTON_ACTION)
- * @param flags flag indicating the action or state change
+ * @param button concerned button
+ * @param type type of event (BUTTON_STATE_CHANGED or BUTTON_ACTION)
+ * @param flags flag indicating the action or state change
* (see BUTTON_FLG_*)
*/
typedef void (*button_callback_t)(button_id_t id, uint8_t type, uint8_t flags);
@@ -357,17 +365,37 @@ typedef void (*button_callback_t)(button_id_t id, uint8_t type, uint8_t flags);
* Drive the button, by setting the the low level state (pressed / released)
* when it happens.
*
- * @param button button
- * @param pressed low level button state
+ * @param button button
+ * @param pressed low level button state
*/
void button_set_low_level_state(button_t *button, bool pressed);
+/**
+ * Specify an alternate queue for the buttons internal management.
+ *
+ * @note If not called, the default OS eventq will be used: os_eventq_dflt_get()
+ *
+ * @note Calling this function afer button initialisation has been done
+ * will result in an undefined behaviour.
+ */
+void button_internal_evq_set(struct os_eventq *evq);
+
+/**
+ * Specify an alternate default queue for processing button callback.
+ *
+ * @note If not called, the default OS eventq will be used: os_eventq_dflt_get()
+ *
+ * @note Calling this function afer button initialisation has been done
+ * will result in an undefined behaviour.
+ */
+void button_callback_default_evq_set(struct os_eventq *evq);
+
/**
* Initialisation of the buttons
*
- * @param buttons buttons definition
- * @param count number of defined buttons
- * @param cb callback used to notify of state change or action
+ * @param buttons buttons definition
+ * @param count number of defined buttons
+ * @param cb callback used to notify of state change or action
*/
void button_init(button_t *buttons, unsigned int count, button_callback_t cb);
diff --git a/hw/util/button/src/button.c b/hw/util/button/src/button.c
index ea1c4c4239..2744b1cb85 100644
--- a/hw/util/button/src/button.c
+++ b/hw/util/button/src/button.c
@@ -21,15 +21,15 @@
#include "os/mynewt.h"
#include "button/button.h"
-#define _BUTTON_FSM_INIT 0
-#define _BUTTON_FSM_PRESSED 1
-#define _BUTTON_FSM_WAIT_DBLPRESSED 2
-#define _BUTTON_FSM_DBLPRESSED 3
-#define _BUTTON_FSM_HOLD_OR_REPEAT 4
+#define _BUTTON_FSM_INIT 0
+#define _BUTTON_FSM_PRESSED 1
+#define _BUTTON_FSM_WAIT_DBLPRESSED 2
+#define _BUTTON_FSM_DBLPRESSED 3
+#define _BUTTON_FSM_HOLD_OR_REPEAT 4
-#define _BUTTON_RELEASED 0
-#define _BUTTON_PRESSED 1
-#define _BUTTON_TIMEOUT 2
+#define _BUTTON_RELEASED 0
+#define _BUTTON_PRESSED 1
+#define _BUTTON_TIMEOUT 2
struct button_event {
struct os_event os_event;
@@ -37,10 +37,13 @@ struct button_event {
uint8_t flags;
};
-#define BUTTON_POST_STATE_EVENT(button, flags) \
+static struct os_eventq *button_internal_evq = NULL;
+static struct os_eventq *button_callback_default_evq = NULL;
+
+#define BUTTON_POST_STATE_EVENT(button, flags) \
button_post_event(button, BUTTON_STATE_CHANGED, flags)
-#define BUTTON_POST_ACTION_EVENT(button, flags) \
+#define BUTTON_POST_ACTION_EVENT(button, flags) \
button_post_event(button, BUTTON_ACTION, flags)
static struct button_event button_event[MYNEWT_VAL(BUTTON_EVENT_MAX)] = { 0 };
@@ -49,9 +52,14 @@ static button_callback_t button_callback = NULL;
static struct button_event *
button_alloc_event(void)
{
- for (int i = 0 ; i < MYNEWT_VAL(BUTTON_EVENT_MAX) ; i++)
- if (!OS_EVENT_QUEUED(&button_event[i].os_event))
- return &button_event[i];
+ int i;
+
+ for (i = 0 ; i < MYNEWT_VAL(BUTTON_EVENT_MAX) ; i++) {
+ if (!OS_EVENT_QUEUED(&button_event[i].os_event)) {
+ return &button_event[i];
+ }
+ }
+
return NULL;
}
@@ -74,11 +82,11 @@ button_event_handler(struct os_event *ev)
/**
* Post an event to the default queue.
*
- * @param button button generating the event
- * @param type type of event (state or action)
- * @param flags event description (BUTTON_FLG_*)
+ * @param button button generating the event
+ * @param type type of event (state or action)
+ * @param flags event description (BUTTON_FLG_*)
*
- * @return -1 unable to post event (not enough buffer)
+ * @return -1 unable to post event (not enough buffer)
* 0 event posted
* 1 event not posted due to filtering
*/
@@ -89,36 +97,41 @@ button_post_event(button_t *button, uint8_t type, uint8_t flags)
#if MYNEWT_VAL(BUTTON_USE_FILTERING)
if (button->filter.enabled) {
- uint8_t filter = 0xff;
- switch(type) {
+ uint8_t filter = 0xff;
+ switch(type) {
#if MYNEWT_VAL(BUTTON_EMIT_STATE_CHANGED)
- case BUTTON_STATE_CHANGED:
- filter = button->filter.state;
- break;
+ case BUTTON_STATE_CHANGED:
+ filter = button->filter.state;
+ break;
#endif
#if MYNEWT_VAL(BUTTON_EMIT_ACTION)
- case BUTTON_ACTION:
- filter = button->filter.action;
- break;
-#endif
- }
- if (~filter & flags) {
- return 1;
- }
+ case BUTTON_ACTION:
+ filter = button->filter.action;
+ break;
+#endif
+ }
+ if (~filter & flags) {
+ return 1;
+ }
}
#endif
evt = button_alloc_event();
- if (evt) {
- evt->os_event.ev_cb = button_event_handler;
- evt->os_event.ev_arg = button;
- evt->type = type;
- evt->flags = flags;
- os_eventq_put(os_eventq_dflt_get(), &evt->os_event);
- return 0;
+ if (evt) {
+ evt->os_event.ev_cb = button_event_handler;
+ evt->os_event.ev_arg = button;
+ evt->type = type;
+ evt->flags = flags;
+
+#if MYNEWT_VAL(BUTTON_USE_PER_BUTTON_CALLBACK_EVENTQ) > 0
+ os_eventq_put(button->eventq, &evt->os_event);
+#else
+ os_eventq_put(button_callback_default_evq, &evt->os_event);
+#endif
+ return 0;
} else {
- button->state |= BUTTON_FLG_MISSED;
- return -1;
+ button->state |= BUTTON_FLG_MISSED;
+ return -1;
}
}
@@ -126,7 +139,7 @@ button_post_event(button_t *button, uint8_t type, uint8_t flags)
/**
* Perform button emulation.
*
- * @param button the button to emulate
+ * @param button the button to emulate
*/
static void
button_emulating(button_t *button)
@@ -135,53 +148,53 @@ button_emulating(button_t *button)
bool released = true;
for (button_t **from = button->emulated ; *from ; from++) {
- if ((*from)->state & BUTTON_FLG_PRESSED) {
- released = false;
- } else {
- pressed = false;
- }
+ if ((*from)->state & BUTTON_FLG_PRESSED) {
+ released = false;
+ } else {
+ pressed = false;
+ }
}
if (pressed != !released)
- return;
+ return;
if (pressed || (released && button->emulating)) {
- button->emulating = pressed;
- button_set_low_level_state(button, pressed);
+ button->emulating = pressed;
+ button_set_low_level_state(button, pressed);
}
}
/**
* Process children of a button. Used for emulating button.
*
- * @param button the button to look for children
+ * @param button the button to look for children
*/
static void
button_process_children(button_t *button)
{
if (button->children == NULL)
- return;
+ return;
for (button_t **child = button->children ; *child ; child++)
- if ((*child)->emulated)
- button_emulating(*child);
+ if ((*child)->emulated)
+ button_emulating(*child);
}
/**
* Check if one of the children is using the action, and so
* we shouldn't generate one for ourself.
*
- * @param button the button to look for children
+ * @param button the button to look for children
*/
static bool
button_stealed_action(button_t *button)
{
if (button->children == NULL)
- return false;
+ return false;
for (button_t **child = button->children ; *child ; child++)
- if ((*child)->emulated && (*child)->emulating)
- return true;
+ if ((*child)->emulated && (*child)->emulating)
+ return true;
return false;
}
@@ -192,9 +205,9 @@ button_stealed_action(button_t *button)
* This one deal with simple state/action, where only pressed/released/click
* are considered.
*
- * @param button button to process
- * @param action low level action associated to the button
- * (_BUTTON_PRESSED, _BUTTON_RELEASED)
+ * @param button button to process
+ * @param action low level action associated to the button
+ * (_BUTTON_PRESSED, _BUTTON_RELEASED)
*/
static void
button_exec_simple(button_t *button, int action)
@@ -203,17 +216,17 @@ button_exec_simple(button_t *button, int action)
switch(action) {
case _BUTTON_PRESSED:
- button->state = BUTTON_FLG_PRESSED;
- break;
+ button->state = BUTTON_FLG_PRESSED;
+ break;
case _BUTTON_RELEASED:
#if MYNEWT_VAL(BUTTON_EMIT_ACTION)
#if MYNEWT_VAL(BUTTON_USE_EMULATION)
- if (!button_stealed_action(button))
+ if (!button_stealed_action(button))
#endif
- BUTTON_POST_ACTION_EVENT(button, button->state);
+ BUTTON_POST_ACTION_EVENT(button, button->state);
#endif
- button->state &= ~BUTTON_FLG_PRESSED;
- break;
+ button->state &= ~BUTTON_FLG_PRESSED;
+ break;
}
#if MYNEWT_VAL(BUTTON_EMIT_STATE_CHANGED)
@@ -233,9 +246,9 @@ button_exec_simple(button_t *button, int action)
* This one deal with complexe action, such as generating double click,
* long click, repeating action, ...
*
- * @param button the button to process
- * @param action low level action associated to the button
- * (_BUTTON_PRESSED, _BUTTON_RELEASED, _BUTTON_TIMEOUT)
+ * @param button the button to process
+ * @param action low level action associated to the button
+ * (_BUTTON_PRESSED, _BUTTON_RELEASED, _BUTTON_TIMEOUT)
*/
static void
button_exec_fsm(button_t *button, int action)
@@ -246,105 +259,105 @@ button_exec_fsm(button_t *button, int action)
switch (button->fsm_state) {
case _BUTTON_FSM_INIT:
- switch(action) {
- case _BUTTON_PRESSED:
- goto do_pressed;
- case _BUTTON_RELEASED:
- goto do_nothing;
- case _BUTTON_TIMEOUT:
- goto do_assert;
- }
- break;
+ switch(action) {
+ case _BUTTON_PRESSED:
+ goto do_pressed;
+ case _BUTTON_RELEASED:
+ goto do_nothing;
+ case _BUTTON_TIMEOUT:
+ goto do_assert;
+ }
+ break;
case _BUTTON_FSM_PRESSED:
- switch(action) {
- case _BUTTON_PRESSED:
- goto do_nothing;
- case _BUTTON_RELEASED:
+ switch(action) {
+ case _BUTTON_PRESSED:
+ goto do_nothing;
+ case _BUTTON_RELEASED:
#if MYNEWT_VAL(BUTTON_USE_DOUBLE)
- if (button->mode & BUTTON_FLG_DOUBLED) {
- goto to_wait_dblpressed;
- } else {
+ if (button->mode & BUTTON_FLG_DOUBLED) {
+ goto to_wait_dblpressed;
+ } else {
#endif
- goto do_release;
+ goto do_release;
#if MYNEWT_VAL(BUTTON_USE_DOUBLE)
- }
+ }
#endif
- case _BUTTON_TIMEOUT:
+ case _BUTTON_TIMEOUT:
#if MYNEWT_VAL(BUTTON_USE_LONG)
- if (button->mode & BUTTON_FLG_LONG) {
- goto do_longpress;
+ if (button->mode & BUTTON_FLG_LONG) {
+ goto do_longpress;
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
- } else if (button->mode & BUTTON_FLG_REPEATING) {
- goto do_repeat;
+ } else if (button->mode & BUTTON_FLG_REPEATING) {
+ goto do_repeat;
#endif
} else {
- goto do_assert;
- }
+ goto do_assert;
+ }
#elif MYNEWT_VAL(BUTTON_USE_REPEAT)
goto do_repeat;
#else
- goto do_assert;
+ goto do_assert;
#endif
- }
- break;
-
+ }
+ break;
+
#if MYNEWT_VAL(BUTTON_USE_DOUBLE)
case _BUTTON_FSM_WAIT_DBLPRESSED:
- switch(action) {
- case _BUTTON_TIMEOUT:
- goto do_release;
- case _BUTTON_PRESSED:
- goto do_dblpressed;
- case _BUTTON_RELEASED:
- goto do_nothing;
- }
- break;
+ switch(action) {
+ case _BUTTON_TIMEOUT:
+ goto do_release;
+ case _BUTTON_PRESSED:
+ goto do_dblpressed;
+ case _BUTTON_RELEASED:
+ goto do_nothing;
+ }
+ break;
case _BUTTON_FSM_DBLPRESSED:
- switch(action) {
- case _BUTTON_TIMEOUT :
+ switch(action) {
+ case _BUTTON_TIMEOUT :
#if MYNEWT_VAL(BUTTON_USE_LONG)
- if (button->mode & BUTTON_FLG_LONG) {
- goto do_longpress;
+ if (button->mode & BUTTON_FLG_LONG) {
+ goto do_longpress;
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
- } else if (button->mode & BUTTON_FLG_REPEATING) {
- goto do_repeat;
+ } else if (button->mode & BUTTON_FLG_REPEATING) {
+ goto do_repeat;
#endif
- } else {
- goto do_assert;
- }
+ } else {
+ goto do_assert;
+ }
#elif MYNEWT_VAL(BUTTON_USE_REPEAT)
- goto do_repeat;
+ goto do_repeat;
#else
- goto do_assert;
+ goto do_assert;
#endif
- case _BUTTON_RELEASED: goto do_release;
- case _BUTTON_PRESSED : goto do_nothing;
- }
- break;
+ case _BUTTON_RELEASED: goto do_release;
+ case _BUTTON_PRESSED : goto do_nothing;
+ }
+ break;
#endif
#if MYNEWT_VAL(BUTTON_USE_LONG ) || \
MYNEWT_VAL(BUTTON_USE_REPEAT)
case _BUTTON_FSM_HOLD_OR_REPEAT:
- switch(action) {
- case _BUTTON_TIMEOUT:
+ switch(action) {
+ case _BUTTON_TIMEOUT:
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
- if (button->mode & BUTTON_FLG_REPEATING) {
- goto do_repeat;
- } else {
+ if (button->mode & BUTTON_FLG_REPEATING) {
+ goto do_repeat;
+ } else {
#endif
- goto do_assert;
+ goto do_assert;
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
- }
+ }
#endif
- case _BUTTON_RELEASED:
- goto do_release;
- case _BUTTON_PRESSED:
- goto do_nothing;
- }
- break;
+ case _BUTTON_RELEASED:
+ goto do_release;
+ case _BUTTON_PRESSED:
+ goto do_nothing;
+ }
+ break;
#endif
}
@@ -360,7 +373,7 @@ button_exec_fsm(button_t *button, int action)
os_callout_reset(callout, MYNEWT_VAL(BUTTON_LONGHOLD_TICKS));
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
} else if (button->mode & BUTTON_FLG_REPEATING) {
- os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
+ os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
#endif
}
#elif MYNEWT_VAL(BUTTON_USE_REPEAT)
@@ -385,14 +398,14 @@ button_exec_fsm(button_t *button, int action)
do_dblpressed:
#if MYNEWT_VAL(BUTTON_USE_LONG)
if (button->mode & BUTTON_FLG_LONG) {
- os_callout_reset(callout, MYNEWT_VAL(BUTTON_LONGHOLD_TICKS));
+ os_callout_reset(callout, MYNEWT_VAL(BUTTON_LONGHOLD_TICKS));
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
} else if (button->mode & BUTTON_FLG_REPEATING) {
- os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
+ os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
#endif
} else {
- os_callout_stop(callout);
- }
+ os_callout_stop(callout);
+ }
#elif MYNEWT_VAL(BUTTON_USE_REPEAT)
os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
#else
@@ -410,7 +423,7 @@ button_exec_fsm(button_t *button, int action)
do_longpress:
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
if (button->mode & BUTTON_FLG_REPEATING)
- os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
+ os_callout_reset(callout, MYNEWT_VAL(BUTTON_REPEAT_FIRST_TICKS));
#endif
button->state |= BUTTON_FLG_LONG;
#if MYNEWT_VAL(BUTTON_EMIT_STATE_CHANGED)
@@ -428,13 +441,13 @@ button_exec_fsm(button_t *button, int action)
#if MYNEWT_VAL(BUTTON_USE_EMULATION)
if (!button_stealed_action(button))
#endif
- BUTTON_POST_ACTION_EVENT(button, button->state);
+ BUTTON_POST_ACTION_EVENT(button, button->state);
#endif
if (!(button->state & BUTTON_FLG_REPEATING)) {
- button->state |= BUTTON_FLG_REPEATING;
+ button->state |= BUTTON_FLG_REPEATING;
#if MYNEWT_VAL(BUTTON_EMIT_STATE_CHANGED)
- BUTTON_POST_STATE_EVENT(button, button->state);
+ BUTTON_POST_STATE_EVENT(button, button->state);
#endif
}
return;
@@ -448,9 +461,9 @@ button_exec_fsm(button_t *button, int action)
if (!button_stealed_action(button)) {
#endif
#if MYNEWT_VAL(BUTTON_USE_REPEAT)
- if (!(button->state & BUTTON_FLG_REPEATING))
+ if (!(button->state & BUTTON_FLG_REPEATING))
#endif
- BUTTON_POST_ACTION_EVENT(button, button->state);
+ BUTTON_POST_ACTION_EVENT(button, button->state);
#if MYNEWT_VAL(BUTTON_USE_EMULATION)
}
#endif
@@ -471,7 +484,7 @@ button_exec_fsm(button_t *button, int action)
* Callout function used for processing timeout.
* Used for processing complexe action.
*
- * @param ev event from callout
+ * @param ev event from callout
*/
static void
button_fsm_callout(struct os_event *ev)
@@ -486,15 +499,38 @@ button_fsm_callout(struct os_event *ev)
void
button_init(button_t *buttons, unsigned int count, button_callback_t cb)
{
- button_callback = cb;
+#if MYNEWT_VAL(BUTTON_USE_DOUBLE) || \
+ MYNEWT_VAL(BUTTON_USE_LONG ) || \
+ MYNEWT_VAL(BUTTON_USE_REPEAT) || \
+ MYNEWT_VAL(BUTTON_USE_PER_BUTTON_CALLBACK_EVENTQ) > 0
+ unsigned int i;
+#endif
+ if (button_internal_evq == NULL) {
+ button_internal_evq = os_eventq_dflt_get();
+ }
+ if (button_callback_default_evq == NULL) {
+ button_callback_default_evq = os_eventq_dflt_get();
+ }
+
+ button_callback = cb;
+
#if MYNEWT_VAL(BUTTON_USE_DOUBLE) || \
MYNEWT_VAL(BUTTON_USE_LONG ) || \
MYNEWT_VAL(BUTTON_USE_REPEAT)
- for (unsigned int i = 0 ; i < count ; i++) {
- button_t *button = &buttons[i];
- os_callout_init(&button->callout, os_eventq_dflt_get(),
- button_fsm_callout, button);
+ for (i = 0 ; i < count ; i++) {
+ button_t *button = &buttons[i];
+ os_callout_init(&button->callout, button_internal_evq,
+ button_fsm_callout, button);
+ }
+#endif
+
+#if MYNEWT_VAL(BUTTON_USE_PER_BUTTON_CALLBACK_EVENTQ) > 0
+ for (i = 0 ; i < count ; i++) {
+ button_t *button = &buttons[i];
+ if (button->eventq == NULL) {
+ button->eventq = button_callback_default_evq;
+ }
}
#endif
}
@@ -509,11 +545,23 @@ button_set_low_level_state(button_t *button, bool pressed)
MYNEWT_VAL(BUTTON_USE_LONG ) || \
MYNEWT_VAL(BUTTON_USE_REPEAT)
if (button->mode & ~(BUTTON_FLG_PRESSED)) {
- button_exec_fsm(button, action);
+ button_exec_fsm(button, action);
} else {
- button_exec_simple(button, action);
+ button_exec_simple(button, action);
}
#else
button_exec_simple(button, action);
#endif
}
+
+void
+button_internal_evq_set(struct os_eventq *evq)
+{
+ button_internal_evq = evq;
+}
+
+void
+button_callback_default_evq_set(struct os_eventq *evq)
+{
+ button_callback_default_evq = evq;
+}
diff --git a/hw/util/button/syscfg.yml b/hw/util/button/syscfg.yml
index ab54f16b0b..5e0f4ca09f 100644
--- a/hw/util/button/syscfg.yml
+++ b/hw/util/button/syscfg.yml
@@ -70,3 +70,8 @@ syscfg.defs:
description: >
Include code for generation of state changed event.
value: 0
+ BUTTON_USE_PER_BUTTON_CALLBACK_EVENTQ:
+ description: >
+ Allow to specify per button event queue for callback processing.
+ By default os_eventq_dflt_get()
+ value: 0
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services