Level eingeordnet.
[hackover2013-badge-firmware.git] / badge / main.c
index 8059155..e8d5acf 100644 (file)
   #include "core/cmd/cmd.h"
 #endif
 
+#include "init.h"
 #include "ui/display.h"
 #include "ui/sprite.h"
 #include "ui/event.h"
+#include "ui/font.h"
+#include "util/util.h"
 #include "jumpnrun/jumpnrun.h"
 
-#include "r0ketports.h"
-#include "drivers/fatfs/ff.h"
-
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof*(arr))
-
-void backlightInit(void) {
-#if HW_IS_PROTOTYPE
-
-
-  // prototype uses WDT CLKOUT to drive the LCD backlight
-  // init without a reset
-
-  IOCON_PIO0_1 &= ~(IOCON_PIO0_1_FUNC_MASK);
-  IOCON_PIO0_1 |=   IOCON_PIO0_1_FUNC_CLKOUT;
-
-  wdtInit(false);
-
-  // use the WDT clock as the default WDT frequency is best frequency
-  // XXX this register value is missing in lpc1343.h
-#define SCB_CLKOUTCLKSEL_SOURCE_WDTCLOCK          ((unsigned int) 0x00000002) // Use the WDT clock
-
-  SCB_CLKOUTCLKSEL = SCB_CLKOUTCLKSEL_SOURCE_WDTCLOCK;
+#include "dataflash/at45db041d.h"
 
-  // toggle from LOW to HIGH to update source
-  SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_DISABLE;
-  SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_UPDATE;
-
-  // divide by 30, to get almost 10 kHz
-  SCB_CLKOUTCLKDIV = 30;
+#include "drivers/fatfs/ff.h"
 
+#include "badge/pinconfig.h"
+#include <funk/nrf24l01p.h>
 
-#else
-
+#ifdef R0KET
 
+#include "r0ketports.h"
+void rbBacklightInit(void) {
   /* Enable the clock for CT16B1 */
   SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
 
@@ -114,18 +94,13 @@ void backlightInit(void) {
   // Enable Step-UP
   gpioSetDir(RB_PWR_LCDBL, gpioDirection_Output);
   gpioSetValue(RB_PWR_LCDBL, 0);
-
-
-#endif
 }
 
 void rbInit() {
-#if !HW_IS_PROTOTYPE
   RB_HB0_IO &= ~IOCON_SWDIO_PIO1_3_FUNC_MASK;
   RB_HB0_IO |=  IOCON_SWDIO_PIO1_3_FUNC_GPIO;
   RB_HB1_IO &= ~IOCON_JTAG_TCK_PIO0_10_FUNC_MASK;
   RB_HB1_IO |=  IOCON_JTAG_TCK_PIO0_10_FUNC_GPIO;
-#endif
 
   struct {
     int port;
@@ -133,14 +108,15 @@ void rbInit() {
     uint32_t volatile *reg;
     gpioPullupMode_t mode;
   } const input_pins[] = {
-#if HW_IS_PROTOTYPE
+#ifdef HOB_REV2
     { RB_BTN0    , &RB_BTN0_IO    , gpioPullupMode_PullDown },
     { RB_BTN1    , &RB_BTN1_IO    , gpioPullupMode_PullDown },
     { RB_BTN2    , &RB_BTN2_IO    , gpioPullupMode_PullDown },
     { RB_BTN3    , &RB_BTN3_IO    , gpioPullupMode_PullDown },
     { RB_BTN4    , &RB_BTN4_IO    , gpioPullupMode_PullDown },
-    { RB_BTN_A   , &RB_BTN_A_IO   , gpioPullupMode_PullDown },
-    { RB_BTN_B   , &RB_BTN_B_IO   , gpioPullupMode_PullDown },
+    { RB_HB0     , &RB_HB0_IO     , gpioPullupMode_PullDown },
+    { RB_HB1     , &RB_HB1_IO     , gpioPullupMode_PullDown },
+    { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullDown }
 #else
     { RB_BTN0    , &RB_BTN0_IO    , gpioPullupMode_PullUp },
     { RB_BTN1    , &RB_BTN1_IO    , gpioPullupMode_PullUp },
@@ -152,16 +128,12 @@ void rbInit() {
     { RB_PWR_CHRG, &RB_PWR_CHRG_IO, gpioPullupMode_PullUp }
 #endif
   };
-    
+
   for(int i = 0; i < ARRAY_SIZE(input_pins); ++i) {
     gpioSetDir(input_pins[i].port, input_pins[i].pin, gpioDirection_Input);
     gpioSetPullup(input_pins[i].reg, input_pins[i].mode);
   }
 
-#if HW_IS_PROTOTYPE
-  IOCON_JTAG_TMS_PIO1_0 &= ~(IOCON_JTAG_TMS_PIO1_0_FUNC_MASK);
-  IOCON_JTAG_TMS_PIO1_0 |=   IOCON_JTAG_TMS_PIO1_0_FUNC_GPIO;
-#else
   // LED3 zur Bestimmung der Umgebungshelligkeit.
   gpioSetDir(RB_LED3, gpioDirection_Input);
   RB_LED3_IO = (RB_LED3_IO & IOCON_PIO1_11_FUNC_MASK) | IOCON_PIO1_11_FUNC_AD7;
@@ -169,7 +141,6 @@ void rbInit() {
   // prepare LEDs
   IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;
   IOCON_JTAG_TDI_PIO0_11 |=  IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
-#endif
 
   struct {
     int port;
@@ -180,7 +151,6 @@ void rbInit() {
     { USB_CONNECT , 1 },
     { RB_LCD_CS   , 1 },
     { RB_SPI_CS_DF, 1 },
-#if !HW_IS_PROTOTYPE
     { RB_SPI_SS2 , 1 },
     { RB_SPI_SS3 , 1 },
     { RB_SPI_SS4 , 1 },
@@ -193,7 +163,6 @@ void rbInit() {
     { RB_HB3     , 1 },
     { RB_HB4     , 1 },
     { RB_HB5     , 1 }
-#endif
   };
 
   for(int i = 0; i < ARRAY_SIZE(output_pins); ++i) {
@@ -201,18 +170,32 @@ void rbInit() {
     gpioSetValue(output_pins[i].port, output_pins[i].pin, output_pins[i].value);
   }
 
-#if !HW_IS_PROTOTYPE
   // Set P0.0 to GPIO
   RB_PWR_LCDBL_IO &= ~RB_PWR_LCDBL_IO_FUNC_MASK;
   RB_PWR_LCDBL_IO |=  RB_PWR_LCDBL_IO_FUNC_GPIO;
 
   gpioSetDir   ( RB_PWR_LCDBL   , gpioDirection_Input);
   gpioSetPullup(&RB_PWR_LCDBL_IO, gpioPullupMode_Inactive);
-#endif
 
-  backlightInit();
+  rbBacklightInit();
+  badge_display_init();
 }
 
+#endif
+
+void usbmode(void) {
+    badge_framebuffer fb = { { { 0 } } };
+
+    badge_framebuffer_render_text(&fb, 23, 30, "USB-Modus");
+/*
+    badge_framebuffer_render_number(&fb, 23, 50, sizeof(jumpnrun_tile));
+    badge_framebuffer_render_number(&fb, 33, 50, sizeof(jumpnrun_item));
+    badge_framebuffer_render_number(&fb, 48, 50, sizeof(jumpnrun_enemy));
+*/
+    badge_framebuffer_flush(&fb);
+    usbMSCInit();
+    for(;;);
+}
 
 /**************************************************************************/
 /*!
@@ -230,105 +213,23 @@ int main(void)
 
   // pmuInit();
   // adcInit();
+#ifdef R0KET
   rbInit();
+#else
+  badge_init();
+#endif
 
-  //  usbMSCInit();
-
-  badge_display_init();
-
-  /*
-  gpioSetDir(0, 11, gpioDirection_Output);
-  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);
-      }
-    } else {
-      gpioSetDir(RB_LED2, gpioDirection_Output);
-      gpioSetValue(RB_LED2, 1);
-    }
+  FATFS fs;
+  f_mount(0, &fs);
 
-    badge_framebuffer_flush(&fb);
+  if(badge_input_raw() & BADGE_EVENT_KEY_DOWN) {
+    usbmode();
   }
-  */
 
   badge_event_start();
-  /*
-  for(;;) {
-    if(JUMPNRUN_ERROR == jumpnrun_play("smb.lvl")) {
-      break;
-    }
-  }
-  */
-
-  uint8_t buttons = 0;
-
-  for(uint8_t i = 0; ; ++i) {
-    badge_event_t event = badge_event_wait();
-
-    //    SCB_CLKOUTCLKDIV = i;
-
-    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 = { { { 0x80 } } };
-
-      SSP_SSP0CR0 =
-       SSP_SSP0CR0_DSS_8BIT     // Data size = 8-bit
-       | SSP_SSP0CR0_FRF_SPI    // Frame format = SPI
-       | SSP_SSP0CR0_SCR_8;
-
-      gpioSetValue(RB_SPI_CS_DF, 0);
-
-      uint8_t st;
-      sspSend(0, "\x05", 1);
-      sspReceive(0, &st, 1);
-
-      gpioSetValue(RB_SPI_CS_DF, 1);
-
-      fb.data[0][1] = st;
-      /*
-      for(int i = 0; i < 9 * 96; ++i) {
-       fb.data[0][i] = 0xbb;
-      }
-      */
-
-      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;
-    }
-    }
-  }
+
+  jumpnrun_play();
+  usbmode();
 
   return 0;
 }
This page took 0.036576 seconds and 4 git commands to generate.