X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/5a5ec547584636187f51c19c786d5a87ee5ba7ff..e943514377152f441aac2b6540df34244f6de79b:/badge/ui/event.c diff --git a/badge/ui/event.c b/badge/ui/event.c index 544625e..c705a0e 100644 --- a/badge/ui/event.c +++ b/badge/ui/event.c @@ -1,6 +1,7 @@ #include "event.h" #include +#include #include #ifdef R0KET @@ -18,17 +19,24 @@ enum { BADGE_EVENT_FLAG_TIMER = 2 }; -static uint8_t badge_input_raw(void) { +uint8_t badge_input_raw(void) { uint8_t result = 0; #ifdef R0KET - if (gpioGetValue(RB_BTN3) == 0) { result |= BADGE_EVENT_KEY_UP ; } - if (gpioGetValue(RB_BTN2) == 0) { result |= BADGE_EVENT_KEY_DOWN ; } + if (gpioGetValue(RB_BTN3) == 0) { result |= BADGE_EVENT_KEY_DOWN ; } + if (gpioGetValue(RB_BTN2) == 0) { result |= BADGE_EVENT_KEY_UP ; } if (gpioGetValue(RB_BTN4) == 0) { result |= BADGE_EVENT_KEY_CENTER; } - if (gpioGetValue(RB_BTN0) == 0) { result |= BADGE_EVENT_KEY_LEFT ; } - if (gpioGetValue(RB_BTN1) == 0) { result |= BADGE_EVENT_KEY_RIGHT ; } + if (gpioGetValue(RB_BTN0) == 0) { result |= BADGE_EVENT_KEY_RIGHT ; } + if (gpioGetValue(RB_BTN1) == 0) { result |= BADGE_EVENT_KEY_LEFT ; } if (gpioGetValue(RB_HB0 ) == 0) { result |= BADGE_EVENT_KEY_BTN_A ; } if (gpioGetValue(RB_HB1 ) == 0) { result |= BADGE_EVENT_KEY_BTN_B ; } +#elif defined(HOB_REV2) + if (gpioGetValue(HOB_PORT(HOB_BTN_UP ), HOB_PIN(HOB_BTN_UP )) == 0) { result |= BADGE_EVENT_KEY_UP ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_DOWN ), HOB_PIN(HOB_BTN_DOWN )) == 0) { result |= BADGE_EVENT_KEY_DOWN ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_LEFT ), HOB_PIN(HOB_BTN_LEFT )) == 0) { result |= BADGE_EVENT_KEY_LEFT ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_RIGHT ), HOB_PIN(HOB_BTN_RIGHT )) == 0) { result |= BADGE_EVENT_KEY_RIGHT ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_A ), HOB_PIN(HOB_BTN_A )) == 0) { result |= BADGE_EVENT_KEY_BTN_A ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_B ), HOB_PIN(HOB_BTN_B )) == 0) { result |= BADGE_EVENT_KEY_BTN_B ; } #else if (gpioGetValue(HOB_PORT(HOB_BTN_UP ), HOB_PIN(HOB_BTN_UP )) == 1) { result |= BADGE_EVENT_KEY_UP ; } if (gpioGetValue(HOB_PORT(HOB_BTN_DOWN ), HOB_PIN(HOB_BTN_DOWN )) == 1) { result |= BADGE_EVENT_KEY_DOWN ; } @@ -61,8 +69,9 @@ void badge_event_irq(void) { } badge_event_t badge_event_wait(void) { - while(!event_flag) - ; + while(!event_flag) { + pmuSleep(); + } // User input takes precedence. if(event_flag & BADGE_EVENT_FLAG_INPUT) { @@ -77,7 +86,11 @@ badge_event_t badge_event_wait(void) { } void badge_event_start(void) { - timer32Init(0, TIMER32_CCLK_10MS * 2); + timer32Init(0, TIMER32_CCLK_10MS / 100 * 133); timer32SetIntHandler(badge_event_irq); timer32Enable(0); } + +void badge_event_stop (void) { + timer32Disable(0); +}