#include "ui/display.h"
#include "ui/sprite.h"
+#include "ui/event.h"
#include "r0ketports.h"
#include "drivers/fatfs/ff.h"
-enum {
- BADGE_BTN_UP = 1,
- BADGE_BTN_LEFT = 2,
- BADGE_BTN_DOWN = 4,
- BADGE_BTN_RIGHT = 8,
- BADGE_BTN_A = 16,
- BADGE_BTN_B = 32,
- BADGE_BTN_MID = 64
-};
-
-uint8_t getInputRaw(void) {
- uint8_t result = BTN_NONE;
-
- if (gpioGetValue(RB_BTN3)==0) {
- result |= BADGE_BTN_UP;
- }
-
- if (gpioGetValue(RB_BTN2)==0) {
- result |= BADGE_BTN_DOWN;
- }
-
- if (gpioGetValue(RB_BTN4)==0) {
- result |= BADGE_BTN_MID;
- }
-
- if (gpioGetValue(RB_BTN0)==0) {
- result |= BADGE_BTN_LEFT;
- }
-
- if (gpioGetValue(RB_BTN1)==0) {
- result |= BADGE_BTN_RIGHT;
- }
-
- if(gpioGetValue(RB_HB3) == 0) {
- result |= BADGE_BTN_A;
- }
-
- if(gpioGetValue(RB_HB4) == 0 || gpioGetValue(RB_HB5) == 0) {
- result |= BADGE_BTN_B;
- }
-
- return result;
-}
-
void backlightInit(void) {
/* Enable the clock for CT16B1 */
SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
gpioSetValue(RB_PWR_LCDBL, 0);
}
-
-
void rbInit() {
// TODO FIXME special port disable ? LEDs BTNs ?
cpuInit();
systickInit(CFG_SYSTICK_DELAY_IN_MS);
- //pmuInit();
- //adcInit();
+// pmuInit();
+// adcInit();
rbInit();
badge_display_init();
gpioSetDir(0, 11, gpioDirection_Output);
-
-// usbMSCInit();
-
- RB_HB3_IO&= ~IOCON_PIO0_2_FUNC_MASK;
- RB_HB3_IO|= IOCON_PIO0_2_FUNC_GPIO;
- gpioSetDir(RB_HB3, gpioDirection_Input);
- gpioSetPullup(&RB_HB3_IO, gpioPullupMode_PullUp);
-
- RB_HB4_IO&= ~IOCON_PIO1_4_FUNC_MASK;
- RB_HB4_IO|= IOCON_PIO1_4_FUNC_GPIO;
- gpioSetDir(RB_HB4, gpioDirection_Input);
- gpioSetPullup(&RB_HB4_IO, gpioPullupMode_PullUp);
-
-
- badge_framebuffer fb = {
- {
- {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
- }, {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
- 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
- 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96
+ gpioSetValue(0, 11, 0);
+
+ {
+ badge_framebuffer fb;
+ int res = 0;
+ FATFS fatvol;
+
+ if(FR_OK == f_mount(0, &fatvol)) {
+ FIL fil;
+ if(FR_OK == (res = f_open(&fil, "sshot.dat", FA_OPEN_EXISTING | FA_READ))) {
+ UINT readbytes;
+
+ if(FR_OK != f_read(&fil, &fb, sizeof(fb), &readbytes)) {
+ gpioSetDir(RB_LED3, gpioDirection_Output);
+ gpioSetValue(RB_LED3, 1);
+ }
+
+ f_close(&fil);
+ } else {
+ fb.data[0][0] = res;
+ gpioSetDir(RB_LED1, gpioDirection_Output);
+ gpioSetValue(RB_LED1, 1);
}
- }
- };
-
- // badge_framebuffer_flush(&fb);
-
- int res = 0;
- FATFS fatvol;
-
- if(FR_OK == f_mount(0, &fatvol)) {
- FIL fil;
- if(FR_OK == (res = f_open(&fil, "sshot.dat", FA_OPEN_EXISTING | FA_READ))) {
- UINT readbytes;
-
- if(FR_OK != f_read(&fil, &fb, sizeof(fb), &readbytes)) {
- gpioSetDir(RB_LED3, gpioDirection_Output);
- gpioSetValue(RB_LED3, 1);
- }
-
- f_close(&fil);
} else {
- fb.data[0][0] = res;
- gpioSetDir(RB_LED1, gpioDirection_Output);
- gpioSetValue(RB_LED1, 1);
+ gpioSetDir(RB_LED2, gpioDirection_Output);
+ gpioSetValue(RB_LED2, 1);
}
- } else {
- gpioSetDir(RB_LED2, gpioDirection_Output);
- gpioSetValue(RB_LED2, 1);
- }
-
- badge_framebuffer_flush(&fb);
- for(uint8_t i = 0; ; ++i) {
- gpioSetValue(0, 11, i & 1);
-
- uint8_t buttons = getInputRaw();
- memset(&fb, 0, sizeof(fb));
+ badge_framebuffer_flush(&fb);
+ }
- badge_sprite const sp = { 4, 4, (uint8_t const *) "\xff\xff" };
+ badge_event_start();
- if(buttons & BADGE_BTN_UP) { badge_framebuffer_blt(&fb, 30, 10, &sp, 0); }
- if(buttons & BADGE_BTN_DOWN) { badge_framebuffer_blt(&fb, 30, 50, &sp, 0); }
- if(buttons & BADGE_BTN_LEFT) { badge_framebuffer_blt(&fb, 10, 30, &sp, 0); }
- if(buttons & BADGE_BTN_RIGHT) { badge_framebuffer_blt(&fb, 50, 30, &sp, 0); }
- if(buttons & BADGE_BTN_MID) { badge_framebuffer_blt(&fb, 30, 30, &sp, 0); }
- if(buttons & BADGE_BTN_A) { badge_framebuffer_blt(&fb, 70, 10, &sp, 0); }
- if(buttons & BADGE_BTN_B) { badge_framebuffer_blt(&fb, 70, 50, &sp, 0); }
+ uint8_t buttons = 0;
- badge_framebuffer_flush(&fb);
+ for(uint8_t i = 0; ; ++i) {
+ badge_event_t event = badge_event_wait();
- systickDelay(500);
+ switch(badge_event_type(event)) {
+ case BADGE_EVENT_USER_INPUT: {
+ buttons = badge_event_current_input_state();
+ break;
+ }
+ case BADGE_EVENT_GAME_TICK: {
+ badge_sprite const sp = { 4, 4, (uint8_t const *) "\xff\xff" };
+ badge_framebuffer fb = { { { 0 } } };
+
+ if(buttons & BADGE_EVENT_KEY_UP) { badge_framebuffer_blt(&fb, 30, 10, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_DOWN) { badge_framebuffer_blt(&fb, 30, 50, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_LEFT) { badge_framebuffer_blt(&fb, 10, 30, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_RIGHT) { badge_framebuffer_blt(&fb, 50, 30, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_CENTER){ badge_framebuffer_blt(&fb, 30, 30, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_BTN_A) { badge_framebuffer_blt(&fb, 70, 10, &sp, 0); }
+ if(buttons & BADGE_EVENT_KEY_BTN_B) { badge_framebuffer_blt(&fb, 70, 50, &sp, 0); }
+
+ badge_framebuffer_flush(&fb);
+ break;
+ }
+ }
}
return 0;