Compilerswitch für Firmware, die nur den Dataflash per USB rausreicht (zum
[hackover2013-badge-firmware.git] / badge / main.c
index 00b0982..cb9a0c9 100644 (file)
@@ -43,7 +43,9 @@
 #include "core/adc/adc.h"
 #include "core/cpu/cpu.h"
 #include "core/pmu/pmu.h"
+#include "core/wdt/wdt.h"
 #include "core/gpio/gpio.h"
+#include "core/ssp/ssp.h"
 #include "core/systick/systick.h"
 #include "core/usbhid-rom/usbmsc.h"
 
   #include "core/cmd/cmd.h"
 #endif
 
+#include "fahrplan.h"
+#include "init.h"
+#include "ui/browser.h"
 #include "ui/display.h"
-#include "ui/sprite.h"
 #include "ui/event.h"
+#include "ui/font.h"
+#include "ui/menu.h"
+#include "ui/sprite.h"
+#include "ui/vanity.h"
+#include "util/util.h"
 #include "jumpnrun/jumpnrun.h"
 
-#include "r0ketports.h"
+#include "dataflash/at45db041d.h"
+
 #include "drivers/fatfs/ff.h"
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof*(arr))
+#include "badge/pinconfig.h"
+#include <funk/nrf24l01p.h>
 
-void backlightInit(void) {
+#ifdef R0KET
+
+#include "r0ketports.h"
+void rbBacklightInit(void) {
   /* Enable the clock for CT16B1 */
   SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
 
   /* Configure PIO1.9 as Timer1_16 MAT0 Output */
   IOCON_PIO1_9 &= ~IOCON_PIO1_9_FUNC_MASK;
-  IOCON_PIO1_9 |= IOCON_PIO1_9_FUNC_CT16B1_MAT0;
+  IOCON_PIO1_9 |=  IOCON_PIO1_9_FUNC_CT16B1_MAT0;
 
   /* Set default duty cycle (MR1) */
   TMR_TMR16B1MR0 = 0; //(0xFFFF * (100 - brightness)) / 100;
@@ -96,20 +110,32 @@ void rbInit() {
     int port;
     int pin;
     uint32_t volatile *reg;
+    gpioPullupMode_t mode;
   } const input_pins[] = {
-    { RB_BTN0    , &RB_BTN0_IO     },
-    { RB_BTN1    , &RB_BTN1_IO     },
-    { RB_BTN2    , &RB_BTN2_IO     },
-    { RB_BTN3    , &RB_BTN3_IO     },
-    { RB_BTN4    , &RB_BTN4_IO     },
-    { RB_HB0     , &RB_HB0_IO      },
-    { RB_HB1     , &RB_HB1_IO      },
-    { RB_PWR_CHRG, &RB_PWR_CHRG_IO }
+#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_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 },
+    { RB_BTN2    , &RB_BTN2_IO    , gpioPullupMode_PullUp },
+    { RB_BTN3    , &RB_BTN3_IO    , gpioPullupMode_PullUp },
+    { RB_BTN4    , &RB_BTN4_IO    , gpioPullupMode_PullUp },
+    { RB_HB0     , &RB_HB0_IO     , gpioPullupMode_PullUp },
+    { RB_HB1     , &RB_HB1_IO     , gpioPullupMode_PullUp },
+    { 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, gpioPullupMode_PullUp);
+    gpioSetPullup(input_pins[i].reg, input_pins[i].mode);
   }
 
   // LED3 zur Bestimmung der Umgebungshelligkeit.
@@ -125,15 +151,17 @@ void rbInit() {
     int pin;
     int value;
   } const output_pins[] = {
-    { RB_PWR_GOOD, 0 },
-    { USB_CONNECT, 1 },
-    { RB_LED0    , 0 },
-    { RB_LED1    , 0 },
-    { RB_LED2    , 0 },
+    { RB_PWR_GOOD , 0 },
+    { USB_CONNECT , 1 },
+    { RB_LCD_CS   , 1 },
+    { RB_SPI_CS_DF, 1 },
     { RB_SPI_SS2 , 1 },
     { RB_SPI_SS3 , 1 },
     { RB_SPI_SS4 , 1 },
     { RB_SPI_SS5 , 1 },
+    { RB_LED0    , 0 },
+    { RB_LED1    , 0 },
+    { RB_LED2    , 0 },
     { RB_LCD_BL  , 0 },
     { RB_HB2     , 1 },
     { RB_HB3     , 1 },
@@ -153,101 +181,89 @@ void rbInit() {
   gpioSetDir   ( RB_PWR_LCDBL   , gpioDirection_Input);
   gpioSetPullup(&RB_PWR_LCDBL_IO, gpioPullupMode_Inactive);
 
-  backlightInit();
+  rbBacklightInit();
+  badge_display_init();
 }
 
+#endif
 
-/**************************************************************************/
-/*!
-    Main program entry point.  After reset, normal code execution will
-    begin here.
-*/
-/**************************************************************************/
-int main(void)
-{
-  // Configure cpu and mandatory peripherals
-  //systemInit();
-
-  cpuInit();
-  systickInit(CFG_SYSTICK_DELAY_IN_MS);
+static void usbmode(void) {
+  badge_event_stop();
 
-  // pmuInit();
-  // adcInit();
-  rbInit();
+  badge_framebuffer fb = { { { 0 } } };
+  badge_framebuffer_render_text(&fb, 22, 20, "USB-Modus");
+//  badge_framebuffer_render_text(&fb, 10, 35, "Reset to exit");
+  badge_framebuffer_render_text(&fb, 16, 35, "Zurück mit");
+  badge_framebuffer_render_text(&fb, 32, 45, "Reset");
+/*
+    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();
 
-  badge_display_init();
+  for(;;) {
+    pmuSleep();
+  }
+}
 
-  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);
-    }
+uint8_t main_menu_show(uint8_t selected) {
+  // first_visible = 0, weil das Menü so kurz ist. Sollte es
+  // größer werden: Parameter aus main_menu empfangen und merken.
+  uint8_t first_visible = 0;
+  char const *const menu[] = {
+    "Vanity-Screen",
+    "Super Hackio",
+    "Fahrplan",
+    "USB-Modus"
+  };
 
-    badge_framebuffer_flush(&fb);
-  }
+  f_chdir("/");
+  return (uint8_t) badge_menu(menu, ARRAY_SIZE(menu), &first_visible, selected);
+}
 
-  badge_event_start();
+void main_menu(void) {
+  uint8_t selected = 0;
 
   for(;;) {
-    if(JUMPNRUN_ERROR == jumpnrun_play("smb.lvl")) {
-      break;
+    selected = main_menu_show(selected);
+    switch(selected) {
+    case 0: badge_vanity_show(); break;
+    case 1: jumpnrun_play    (); break;
+    case 2: badge_fahrplan   (); break;
+    case 3: usbmode          (); break;
     }
   }
+}
 
-/*
-  uint8_t buttons = 0;
+int main(void)
+{
+  cpuInit();
+  systickInit(CFG_SYSTICK_DELAY_IN_MS);
 
-  for(uint8_t i = 0; ; ++i) {
-    badge_event_t event = badge_event_wait();
+  pmuInit();
+  // adcInit();
+#ifdef R0KET
+  rbInit();
+#else
+  badge_init();
+#endif
 
-    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;
-    }
-    }
+  FATFS fs;
+  f_mount(0, &fs);
+
+#ifdef USBONLY
+  for(;;) usbmode();
+#else
+  if(badge_input_raw() & BADGE_EVENT_KEY_DOWN) {
+    usbmode();
   }
-*/
+
+  badge_event_start();
+  main_menu();
+#endif
 
   return 0;
 }
This page took 0.030094 seconds and 4 git commands to generate.