X-Git-Url: http://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/fc45fce2847ac18bbbbe4c11bd34141f5a17def2..f2985c6ba03e46a81bb038cab5b22d97990354f1:/badge/ui/event.c?ds=sidebyside diff --git a/badge/ui/event.c b/badge/ui/event.c index f5961bf..eb4f44a 100644 --- a/badge/ui/event.c +++ b/badge/ui/event.c @@ -2,7 +2,12 @@ #include #include + +#ifdef R0KET #include +#else +#include +#endif // We depend on input being popped often, so no queue. static badge_event_t volatile event_buffer; @@ -13,17 +18,35 @@ enum { BADGE_EVENT_FLAG_TIMER = 2 }; -static uint8_t badge_input_raw(void) { - uint8_t result = BTN_NONE; +uint8_t badge_input_raw(void) { + uint8_t result = 0; - if (gpioGetValue(RB_BTN3) == 0) { result |= BADGE_EVENT_KEY_UP ; } - if (gpioGetValue(RB_BTN2) == 0) { result |= BADGE_EVENT_KEY_DOWN ; } - 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 ; } - // TODO: Knöpfe. +#ifdef R0KET + 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_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 ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_CENTER), HOB_PIN(HOB_BTN_CENTER)) == 1) { result |= BADGE_EVENT_KEY_CENTER; } + if (gpioGetValue(HOB_PORT(HOB_BTN_LEFT ), HOB_PIN(HOB_BTN_LEFT )) == 1) { result |= BADGE_EVENT_KEY_LEFT ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_RIGHT ), HOB_PIN(HOB_BTN_RIGHT )) == 1) { result |= BADGE_EVENT_KEY_RIGHT ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_A ), HOB_PIN(HOB_BTN_A )) == 1) { result |= BADGE_EVENT_KEY_BTN_A ; } + if (gpioGetValue(HOB_PORT(HOB_BTN_B ), HOB_PIN(HOB_BTN_B )) == 1) { result |= BADGE_EVENT_KEY_BTN_B ; } +#endif - return result; + return result; } uint8_t badge_event_current_input_state(void) { @@ -61,7 +84,7 @@ 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); }