Badge-Initialisierung komplett umgeschrieben, um neue pinconfig.h zu benutzen.
authorWintermute <wintermute@hannover.ccc.de>
Sat, 12 Oct 2013 17:21:30 +0000 (19:21 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Sat, 12 Oct 2013 17:21:30 +0000 (19:21 +0200)
14 files changed:
Makefile
badge/init.c [new file with mode: 0644]
badge/init.h [new file with mode: 0644]
badge/main.c
badge/pinconfig.h [new file with mode: 0644]
badge/ui/display.c
badge/ui/event.c
badge/util/util.h [new file with mode: 0644]
dataflash/at25df041a.c
dataflash/at45db041d.c
dataflash/at45db041d.h
drivers/fatfs/ffconf.h
pinconfig.h [deleted file]
r0ketports.h

index 8241138..e1ce46d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ OPTDEFINES = -D __NEWLIB__
 \r
 SRCS = \\r
   badge/main.c \\r
+  badge/init.c \\r
   badge/jumpnrun/collision.c \\r
   badge/jumpnrun/enemies.c \\r
   badge/jumpnrun/items.c \\r
@@ -45,8 +46,7 @@ SRCS = \
 SRCS += \\r
   dataflash/iobase.c \\r
   dataflash/diskio.c \\r
-  dataflash/at25df041a.c\r
-#  dataflash/at45db041d.c\r
+  dataflash/at45db041d.c\r
 \r
 SRCS += \\r
   project/commands.c\r
diff --git a/badge/init.c b/badge/init.c
new file mode 100644 (file)
index 0000000..5acecad
--- /dev/null
@@ -0,0 +1,49 @@
+#include "init.h"
+#include "pinconfig.h"
+#include "util/util.h"
+#include "ui/display.h"
+
+#include <core/wdt/wdt.h>
+#include <core/gpio/gpio.h>
+
+static void badge_init_backlight(void) {
+  HOB_SET_PIN_FUNC(HOB_LCD_BACKLIGHT, CLKOUT);
+
+  wdtInit(false);
+  SCB_CLKOUTCLKSEL = SCB_MAINCLKSEL_SOURCE_WDTOSC;
+  SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_DISABLE;
+  SCB_CLKOUTCLKUEN = SCB_CLKOUTCLKUEN_UPDATE;
+  SCB_CLKOUTCLKDIV = 30;
+}
+
+void badge_init(void) {
+#define INPUT_PIN_CONFIG(spec, mode) do {                              \
+    HOB_SET_PIN_FUNC(spec, GPIO);                                      \
+    gpioSetDir(HOB_PORT(spec), HOB_PIN(spec), gpioDirection_Input);    \
+    gpioSetPullup(&HOB_IOCON(spec), (mode));                           \
+  } while(0)
+
+  INPUT_PIN_CONFIG(HOB_BTN_UP    , gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_RIGHT , gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_DOWN  , gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_LEFT  , gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_CENTER, gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_A     , gpioPullupMode_PullDown);
+  INPUT_PIN_CONFIG(HOB_BTN_B     , gpioPullupMode_PullDown);
+#undef INPUT_PIN_CONFIG
+
+#define OUTPUT_PIN_CONFIG(spec, value) do {                            \
+    HOB_SET_PIN_FUNC(spec, GPIO);                                      \
+    gpioSetDir(HOB_PORT(spec), HOB_PIN(spec), gpioDirection_Output);   \
+    gpioSetValue(HOB_PORT(spec), HOB_PIN(spec), (value));              \
+  } while(0)
+
+  OUTPUT_PIN_CONFIG(HOB_USB_CONNECT , 1);
+  OUTPUT_PIN_CONFIG(HOB_LCD_CS      , 1);
+  OUTPUT_PIN_CONFIG(HOB_LCD_RST     , 1);
+  OUTPUT_PIN_CONFIG(HOB_DATAFLASH_CS, 1);
+#undef OUTPUT_PIN_CONFIG
+
+  badge_init_backlight();
+  badge_display_init();
+}
diff --git a/badge/init.h b/badge/init.h
new file mode 100644 (file)
index 0000000..70610a8
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_HACKOVER2013_BADGE_INIT_H
+#define INCLUDED_HACKOVER2013_BADGE_INIT_H
+
+void badge_init(void);
+
+#endif
index 8059155..99ecee2 100644 (file)
   #include "core/cmd/cmd.h"
 #endif
 
+#include "init.h"
 #include "ui/display.h"
 #include "ui/sprite.h"
 #include "ui/event.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;
-
-  // 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 "dataflash/at45db041d.h"
 
-#else
+#include "drivers/fatfs/ff.h"
 
+#ifdef R0KET
 
+#include "r0ketports.h"
+void rbBacklightInit(void) {
   /* Enable the clock for CT16B1 */
   SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
 
@@ -114,18 +90,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,15 +104,6 @@ void rbInit() {
     uint32_t volatile *reg;
     gpioPullupMode_t mode;
   } const input_pins[] = {
-#if HW_IS_PROTOTYPE
-    { 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 },
-#else
     { RB_BTN0    , &RB_BTN0_IO    , gpioPullupMode_PullUp },
     { RB_BTN1    , &RB_BTN1_IO    , gpioPullupMode_PullUp },
     { RB_BTN2    , &RB_BTN2_IO    , gpioPullupMode_PullUp },
@@ -150,7 +112,6 @@ void rbInit() {
     { 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) {
@@ -158,10 +119,6 @@ void rbInit() {
     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 +126,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 +136,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 +148,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 +155,18 @@ 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
 
 /**************************************************************************/
 /*!
@@ -230,48 +184,43 @@ int main(void)
 
   // pmuInit();
   // adcInit();
+#ifdef R0KET
   rbInit();
-
-  //  usbMSCInit();
-
-  badge_display_init();
+#else
+  badge_init();
+#endif
 
   /*
-  gpioSetDir(0, 11, gpioDirection_Output);
-  gpioSetValue(0, 11, 0);
-
-
   {
+    //    f_mkfs(0, 1, 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);
+    while(FR_OK != f_mount(0, &fatvol)) {
+      f_mkfs(0, 1, 0);
+    }
+
+    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)) {
       }
-    } else {
-      gpioSetDir(RB_LED2, gpioDirection_Output);
-      gpioSetValue(RB_LED2, 1);
+
+      f_close(&fil);
     }
 
     badge_framebuffer_flush(&fb);
+
   }
+
+  usbMSCInit();
+  for(;;);
   */
 
   badge_event_start();
+
   /*
   for(;;) {
     if(JUMPNRUN_ERROR == jumpnrun_play("smb.lvl")) {
@@ -285,8 +234,6 @@ int main(void)
   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();
@@ -296,26 +243,6 @@ int main(void)
       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); }
diff --git a/badge/pinconfig.h b/badge/pinconfig.h
new file mode 100644 (file)
index 0000000..dd5f358
--- /dev/null
@@ -0,0 +1,104 @@
+#ifndef INCLUDED_HACKOVER_2013_BADGE_PINCONFIG_H
+#define INCLUDED_HACKOVER_2013_BADGE_PINCONFIG_H
+
+#include <lpc134x.h>
+
+#define HOB_BTN_UP        (3,  2)
+#define HOB_BTN_RIGHT     (1,  5)
+#define HOB_BTN_DOWN      (1,  6)
+#define HOB_BTN_LEFT      (3,  3)
+#define HOB_BTN_CENTER    (1,  7)
+#define HOB_BTN_A         (1, 11)
+#define HOB_BTN_B         (1,  4)
+
+#define HOB_LCD_CS        (1,  0)
+#define HOB_LCD_RST       (1,  1)
+#define HOB_LCD_BACKLIGHT (0,  1)
+
+#define HOB_DATAFLASH_CS  (0,  7)
+
+#define HOB_RADIO_CE      (2, 10)
+#define HOB_RADIO_CS      (2,  9)
+#define HOB_RADIO_IRQ     (2,  2)
+
+#define HOB_USB_CONNECT   (0,  6)
+
+#define HOB_PIO0_0 nRESET_PIO0_0
+#define HOB_PIO0_1 PIO0_1
+#define HOB_PIO0_2 PIO0_2
+#define HOB_PIO0_3 PIO0_3
+#define HOB_PIO0_4 PIO0_4
+#define HOB_PIO0_5 PIO0_5
+#define HOB_PIO0_6 PIO0_6
+#define HOB_PIO0_7 PIO0_7
+#define HOB_PIO0_8 PIO0_8
+#define HOB_PIO0_9 PIO0_9
+#define HOB_PIO0_10 JTAG_TCK_PIO0_10
+#define HOB_PIO0_11 JTAG_TDI_PIO0_11
+
+#define HOB_PIO1_0 JTAG_TMS_PIO1_0
+#define HOB_PIO1_1 JTAG_TDO_PIO1_1
+#define HOB_PIO1_2 JTAG_nTRST_PIO1_2
+#define HOB_PIO1_3 SWDIO_PIO1_3
+#define HOB_PIO1_4 PIO1_4
+#define HOB_PIO1_5 PIO1_5
+#define HOB_PIO1_6 PIO1_6
+#define HOB_PIO1_7 PIO1_7
+#define HOB_PIO1_8 PIO1_8
+#define HOB_PIO1_9 PIO1_9
+#define HOB_PIO1_10 PIO1_10
+#define HOB_PIO1_11 PIO1_11
+
+#define HOB_PIO2_0 PIO2_0
+#define HOB_PIO2_1 PIO2_1
+#define HOB_PIO2_2 PIO2_2
+#define HOB_PIO2_3 PIO2_3
+#define HOB_PIO2_4 PIO2_4
+#define HOB_PIO2_5 PIO2_5
+#define HOB_PIO2_6 PIO2_6
+#define HOB_PIO2_7 PIO2_7
+#define HOB_PIO2_8 PIO2_8
+#define HOB_PIO2_9 PIO2_9
+#define HOB_PIO2_10 PIO2_10
+#define HOB_PIO2_11 PIO2_11
+
+#define HOB_PIO3_0 PIO3_0
+#define HOB_PIO3_1 PIO3_1
+#define HOB_PIO3_2 PIO3_2
+#define HOB_PIO3_3 PIO3_3
+#define HOB_PIO3_4 PIO3_4
+#define HOB_PIO3_5 PIO3_5
+
+#define HOB_EXPAND(foo) foo
+
+#define HOB_PORT_I(port, pin) port
+#define HOB_PIN_I(port, pin) pin
+#define HOB_PORT(spec) HOB_EXPAND(HOB_PORT_I spec)
+#define HOB_PIN(spec)  HOB_EXPAND(HOB_PIN_I spec)
+
+#define HOB_BUILD_PIO_SUFFIX_I(port, pin) HOB_PIO ## port ## _ ## pin
+#define HOB_BUILD_PIO_SUFFIX(port, pin) HOB_BUILD_PIO_SUFFIX_I(port, pin)
+#define HOB_PIO_SUFFIX(spec) HOB_BUILD_PIO_SUFFIX(HOB_PORT(spec), HOB_PIN(spec))
+
+#define HOB_BUILD_IOCON_NAME_I(pio) IOCON_ ## pio
+#define HOB_BUILD_IOCON_NAME(pio) HOB_BUILD_IOCON_NAME_I(pio)
+#define HOB_IOCON(spec) HOB_BUILD_IOCON_NAME(HOB_PIO_SUFFIX(spec))
+
+#define HOB_BUILD_IOCON_MASK_I(pio, flag) IOCON_ ## pio ## _ ## flag
+#define HOB_BUILD_IOCON_MASK(pio, flag) HOB_BUILD_IOCON_MASK_I(pio, flag)
+#define HOB_IOCON_MASK(spec, flag) HOB_BUILD_IOCON_MASK(HOB_PIO_SUFFIX(spec), flag)
+
+#define HOB_SET_PIN_FUNC(spec, func) do {                              \
+    HOB_IOCON(spec) =                                                  \
+      (HOB_IOCON(spec) & ~HOB_IOCON_MASK(spec, FUNC_MASK))             \
+      | HOB_IOCON_MASK(spec, FUNC_ ## func);                           \
+  } while(0)
+
+/*
+HOB_PORT(HOB_LCD_BACKLIGHT)
+HOB_PIN(HOB_LCD_BACKLIGHT)
+HOB_IOCON(HOB_LCD_BACKLIGHT)
+HOB_IOCON_MASK(HOB_LCD_BACKLIGHT, FUNC_GPIO)
+*/
+
+#endif
index 8964900..db04007 100644 (file)
@@ -6,8 +6,26 @@
 #include <sysdefs.h>
 #include <lpc134x.h>
 
+#ifdef R0KET
+
 #include <r0ketports.h>
 
+#define CS_LOW()   gpioSetValue(RB_LCD_CS , 0)
+#define CS_HIGH()  gpioSetValue(RB_LCD_CS , 1)
+#define RST_LOW()  gpioSetValue(RB_LCD_RST, 0)
+#define RST_HIGH() gpioSetValue(RB_LCD_RST, 1)
+
+#else
+
+#include <badge/pinconfig.h>
+
+#define CS_LOW()   gpioSetValue(HOB_PORT(HOB_LCD_CS ), HOB_PIN(HOB_LCD_CS ), 0)
+#define CS_HIGH()  gpioSetValue(HOB_PORT(HOB_LCD_CS ), HOB_PIN(HOB_LCD_CS ), 1)
+#define RST_LOW()  gpioSetValue(HOB_PORT(HOB_LCD_RST), HOB_PIN(HOB_LCD_RST), 0)
+#define RST_HIGH() gpioSetValue(HOB_PORT(HOB_LCD_RST), HOB_PIN(HOB_LCD_RST), 1)
+
+#endif
+
 #ifdef CFG_USBMSC
 #include <core/usbhid-rom/usbmsc.h>
 
@@ -27,11 +45,12 @@ static void lcd_select() {
                          | SSP_SSP0CR0_FRF_SPI    // Frame format = SPI
                          | SSP_SSP0CR0_SCR_8);    // Serial clock rate = 8
   SSP_SSP0CR0 = configReg;
-  gpioSetValue(RB_LCD_CS, 0);
+
+  CS_LOW();
 }
 
 static void lcd_deselect() {
-  gpioSetValue(RB_LCD_CS, 1);
+  CS_HIGH();
   /* reset the bus to 8-Bit frames that everyone else uses */
   uint32_t configReg = ( SSP_SSP0CR0_DSS_8BIT     // Data size = 8-bit
                          | SSP_SSP0CR0_FRF_SPI    // Frame format = SPI
@@ -59,16 +78,13 @@ static void lcd_write_data   (uint8_t data) { lcd_write(0x0100 | data); }
 void badge_display_init(void) {
   sspInit(0, sspClockPolarity_Low, sspClockPhase_RisingEdge);
 
-  gpioSetValue(RB_LCD_CS , 1);
-  gpioSetValue(RB_LCD_RST, 1);
-
-  gpioSetDir  (RB_LCD_CS , gpioDirection_Output);
-  gpioSetDir  (RB_LCD_RST, gpioDirection_Output);
+  CS_HIGH();
+  RST_HIGH();
 
   systickDelay(100);
-  gpioSetValue(RB_LCD_RST, 0);
+  RST_LOW();
   systickDelay(100);
-  gpioSetValue(RB_LCD_RST, 1);
+  RST_HIGH();
   systickDelay(100);
   /*
   int id = lcdRead(220);
index 70b79a6..544625e 100644 (file)
@@ -2,7 +2,12 @@
 
 #include <core/gpio/gpio.h>
 #include <core/timer32/timer32.h>
+
+#ifdef R0KET
 #include <r0ketports.h>
+#else
+#include <badge/pinconfig.h>
+#endif
 
 // We depend on input being popped often, so no queue.
 static badge_event_t volatile event_buffer;
@@ -14,27 +19,27 @@ enum {
 };
 
 static uint8_t badge_input_raw(void) {
-    uint8_t result = BTN_NONE;
+  uint8_t result = 0;
 
-#if HW_IS_PROTOTYPE
-    if (gpioGetValue(RB_BTN3 ) == 1) { result |= BADGE_EVENT_KEY_UP    ; }
-    if (gpioGetValue(RB_BTN2 ) == 1) { result |= BADGE_EVENT_KEY_DOWN  ; }
-    if (gpioGetValue(RB_BTN4 ) == 1) { result |= BADGE_EVENT_KEY_CENTER; }
-    if (gpioGetValue(RB_BTN0 ) == 1) { result |= BADGE_EVENT_KEY_LEFT  ; }
-    if (gpioGetValue(RB_BTN1 ) == 1) { result |= BADGE_EVENT_KEY_RIGHT ; }
-    if (gpioGetValue(RB_BTN_A) == 1) { result |= BADGE_EVENT_KEY_BTN_A ; }
-    if (gpioGetValue(RB_BTN_B) == 1) { result |= BADGE_EVENT_KEY_BTN_B ; }
+#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_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_HB0 ) == 0) { result |= BADGE_EVENT_KEY_BTN_A ; }
+  if (gpioGetValue(RB_HB1 ) == 0) { result |= BADGE_EVENT_KEY_BTN_B ; }
 #else
-    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 ; }
-    if (gpioGetValue(RB_HB0 ) == 0) { result |= BADGE_EVENT_KEY_BTN_A ; }
-    if (gpioGetValue(RB_HB1 ) == 0) { result |= BADGE_EVENT_KEY_BTN_B ; }
+  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) {
diff --git a/badge/util/util.h b/badge/util/util.h
new file mode 100644 (file)
index 0000000..ee566e8
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_HACKOVER2013_BADGE_UTIL_UTIL_H
+#define INCLUDED_HACKOVER2013_BADGE_UTIL_UTIL_H
+
+#include "rectangle.h"
+#include "fixed_point.h"
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr))
+
+#endif
index 04ef300..a164155 100644 (file)
@@ -23,7 +23,7 @@ enum {
   OP_WRITE_ENABLE     = 0x06,
   OP_WRITE_DISABLE    = 0x04,
 
-  OP_SECTOR_PROTEXT   = 0x36,
+  OP_SECTOR_PROTECT   = 0x36,
   OP_SECTOR_UNPROTECT = 0x39,
   OP_SECTOR_STATUS    = 0x3c,
 
@@ -62,15 +62,32 @@ enum {
 
 static volatile DSTATUS status = STA_NOINIT;
 
-static void wait_for_ready() {
-  BYTE reg_status = 0xFF;
+BYTE dataflash_read_status_register(void) {
+  BYTE reg_status = 0xff;
 
   CS_LOW();
   xmit_spi(OP_STATUS_READ);
-  do {
-    rcvr_spi_m((uint8_t *) &reg_status);
-  } while (reg_status & STATUS_BSY);
+  rcvr_spi_m(&reg_status);
   CS_HIGH();
+
+  return reg_status;
+}
+
+/*
+static void dataflash_write_status_register(BYTE status) {
+  CS_LOW();
+  xmit_spi(OP_WRITE_ENABLE);
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_STATUS_WRITE);
+  xmit_spi(status);
+  CS_HIGH();
+}
+*/
+static void wait_for_ready() {
+  while(dataflash_read_status_register() & STATUS_BSY)
+    ;
 }
 
 static void dataflash_powerdown() {
@@ -90,6 +107,9 @@ DSTATUS dataflash_initialize() {
 
   gpioSetDir(RB_SPI_CS_DF, gpioDirection_Output);
   dataflash_resume();
+
+  // BYTE status = dataflash_read_status_register();
+  //  dataflash_write_status_register((status & ~STATUS_SWP) | STATUS_SWP_NONE);
   status &= ~STA_NOINIT;
 
   return status;
@@ -105,11 +125,12 @@ DRESULT dataflash_random_read(BYTE *buff, DWORD offset, DWORD length) {
   if (offset + length > PAGE_MAX * PAGE_SIZE) return RES_PARERR;
 
   wait_for_ready();
+
   CS_LOW();
   xmit_spi(OP_READARRAY);
   xmit_spi((BYTE)(offset >> 16));
-  xmit_spi((BYTE)(offset >> 8));
-  xmit_spi((BYTE)offset);
+  xmit_spi((BYTE)(offset >>  8));
+  xmit_spi((BYTE) offset       );
   xmit_spi(0x00); // follow up with don't care byte
 
   do {
@@ -125,6 +146,73 @@ DRESULT dataflash_read(BYTE *buff, DWORD sector, BYTE count) {
 }
 
 #if _READONLY == 0
+static void dataflash_sector_protect(DWORD addr) {
+  wait_for_ready();
+
+  addr &= ~(PAGE_SIZE - 1);
+
+  CS_LOW();
+  xmit_spi(OP_WRITE_ENABLE);
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_SECTOR_PROTECT);
+  xmit_spi((BYTE)(addr >> 16));
+  xmit_spi((BYTE)(addr >>  8));
+  xmit_spi((BYTE) addr       );      
+  CS_HIGH();
+
+  wait_for_ready();
+}
+
+static void dataflash_sector_unprotect(DWORD addr) {
+  wait_for_ready();
+
+  addr &= ~(PAGE_SIZE - 1);
+
+  CS_LOW();
+  xmit_spi(OP_WRITE_ENABLE);
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_SECTOR_UNPROTECT);
+  xmit_spi((BYTE)(addr >> 16));
+  xmit_spi((BYTE)(addr >>  8));
+  xmit_spi((BYTE) addr       );      
+  CS_HIGH();
+
+  wait_for_ready();
+}
+
+static DRESULT dataflash_write_4k(const BYTE *buff, DWORD addr) {
+  addr &= ~4095u;
+
+  CS_LOW();
+  xmit_spi(OP_WRITE_ENABLE);
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_ERASE_BLOCK_4K);
+  xmit_spi((BYTE)(addr >> 16));
+  xmit_spi((BYTE)(addr >>  8));
+  xmit_spi((BYTE) addr       );
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_WRITE_ENABLE);
+  CS_HIGH();
+
+  CS_LOW();
+  xmit_spi(OP_PROGRAM_PAGE);
+  xmit_spi((BYTE)(addr >> 16));
+  xmit_spi((BYTE)(addr >>  8));
+  xmit_spi((BYTE) addr       );
+  for(int i = 0; i < 4096; ++i) {
+    xmit_spi(buff[i]);
+  }
+  CS_HIGH();
+}
+
 DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length) {
   if (!length) return RES_PARERR;
   if (status & STA_NOINIT) return RES_NOTRDY;
@@ -133,9 +221,13 @@ DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length) {
   do {
     wait_for_ready();
 
-    DWORD pageaddr = (offset / PAGE_SIZE) * PAGE_SIZE;
+    DWORD addr      = offset;
+    DWORD blockaddr = addr & ~4095u;
     DWORD remaining = PAGE_SIZE - offset % PAGE_SIZE;
 
+    BYTE blockbuf[4096];
+    dataflash_random_read(blockbuf, blockaddr, 4096);
+    
     if (remaining > length) {
       remaining = length;
     }
@@ -143,24 +235,27 @@ DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length) {
     length -= remaining;
     offset += remaining;
 
+    dataflash_sector_unprotect(addr);
+
     CS_LOW();
     xmit_spi(OP_WRITE_ENABLE);
     CS_HIGH();
 
-    // read page into the internal buffer
     CS_LOW();
     xmit_spi(OP_PROGRAM_PAGE);
-    xmit_spi((BYTE)(pageaddr >> 16));
-    xmit_spi((BYTE)(pageaddr >>  8));
-    xmit_spi((BYTE) pageaddr       );
-
+    xmit_spi((BYTE)(addr >> 16));
+    xmit_spi((BYTE)(addr >>  8));
+    xmit_spi((BYTE) addr       );
     do {
       xmit_spi(*buff++);
     } while (--remaining);
-
     CS_HIGH();
+
+    dataflash_sector_protect(addr);
   } while (length);
 
+  wait_for_ready();
+
   return RES_OK;
 }
 
index a1d645a..5e2b0eb 100644 (file)
@@ -3,7 +3,12 @@
 #include "iobase.h"
 #include "core/ssp/ssp.h"
 
+#ifdef R0KET
 #include <r0ketports.h>
+#else
+#include <badge/pinconfig.h>
+#define RB_SPI_CS_DF HOB_PORT(HOB_DATAFLASH_CS), HOB_PIN(HOB_DATAFLASH_CS)
+#endif
 
 /* Opcodes */
 #define OP_POWERDOWN      (0xB9)
index a19894c..a15abd0 100644 (file)
@@ -11,4 +11,6 @@ DRESULT dataflash_write(const BYTE *buff, DWORD sector, BYTE count);
 DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length);
 DRESULT dataflash_ioctl(BYTE ctrl, void *buff);
 
+BYTE dataflash_read_status_register(void);
+
 #endif /* _AT45DB041D_H */
index 8575532..1ffe18b 100644 (file)
@@ -21,7 +21,7 @@
 /  data transfer. This reduces memory consumption 512 bytes each file object. */
 
 
-#define _FS_READONLY    1 //CFG_SDCARD_READONLY // 0    /* 0 or 1 */
+#define _FS_READONLY    0 //CFG_SDCARD_READONLY // 0    /* 0 or 1 */
 /* Setting _FS_READONLY to 1 defines read only configuration. This removes
 /  writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
 /  f_truncate and useless f_getfree. */
@@ -41,7 +41,7 @@
 /* To enable string functions, set _USE_STRFUNC to 1 or 2. */
 
 
-#define _USE_MKFS       0               /* 0 or 1 */
+#define _USE_MKFS       1               /* 0 or 1 */
 /* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
 
 
diff --git a/pinconfig.h b/pinconfig.h
deleted file mode 100644 (file)
index a499d84..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#ifndef INCLUDED_HACKOVER_2013_BADGE_PINCONFIG_H
-#define INCLUDED_HACKOVER_2013_BADGE_PINCONFIG_H
-
-#include "lpc134x.h"
-
-#define HOB_TEST (1, 2)
-
-#define HOB_BTN_RIGHT    (1,  5)
-#define HOB_BTN_DOWN     (1,  6)
-#define HOB_BTN_UP       (3,  2)
-#define HOB_BTN_LEFT     (3,  3)
-#define HOB_BTN_CENTER   (1,  7)
-#define HOB_BTN_A        (1, 11)
-#define HOB_BTN_B        (1,  4)
-
-#define HOB_LCD_CS       (1,  0)
-#define HOB_LCD_RST      (1,  1)
-
-#define HOB_DATAFLASH_CS (0,  7)
-
-#define HOB_RADIO_CE     (2, 10)
-#define HOB_RADIO_CS     (2,  9)
-#define HOB_RADIO_IRQ    (2,  2)
-
-#define HOB_IOCON_PIO0_0 IOCON_nRESET_PIO0_0
-#define HOB_IOCON_PIO0_1 IOCON_PIO0_1
-#define HOB_IOCON_PIO0_2 IOCON_PIO0_2
-#define HOB_IOCON_PIO0_3 IOCON_PIO0_3
-#define HOB_IOCON_PIO0_4 IOCON_PIO0_4
-#define HOB_IOCON_PIO0_5 IOCON_PIO0_5
-#define HOB_IOCON_PIO0_6 IOCON_PIO0_6
-#define HOB_IOCON_PIO0_7 IOCON_PIO0_7
-#define HOB_IOCON_PIO0_8 IOCON_PIO0_8
-#define HOB_IOCON_PIO0_9 IOCON_PIO0_9
-#define HOB_IOCON_PIO0_10 IOCON_JTAG_TCK_PIO0_10
-#define HOB_IOCON_PIO0_11 IOCON_JTAG_TDI_PIO0_11
-
-#define HOB_IOCON_PIO1_0 IOCON_JTAG_TMS_PIO1_0
-#define HOB_IOCON_PIO1_1 IOCON_JTAG_TDO_PIO1_1
-#define HOB_IOCON_PIO1_2 IOCON_JTAG_nTRST_PIO1_2
-#define HOB_IOCON_PIO1_3 IOCON_SWDIO_PIO1_3
-#define HOB_IOCON_PIO1_4 IOCON_PIO1_4
-#define HOB_IOCON_PIO1_5 IOCON_PIO1_5
-#define HOB_IOCON_PIO1_6 IOCON_PIO1_6
-#define HOB_IOCON_PIO1_7 IOCON_PIO1_7
-#define HOB_IOCON_PIO1_8 IOCON_PIO1_8
-#define HOB_IOCON_PIO1_9 IOCON_PIO1_9
-#define HOB_IOCON_PIO1_10 IOCON_PIO1_10
-#define HOB_IOCON_PIO1_11 IOCON_PIO1_11
-
-#define HOB_IOCON_PIO2_0 IOCON_PIO2_0
-#define HOB_IOCON_PIO2_1 IOCON_PIO2_1
-#define HOB_IOCON_PIO2_2 IOCON_PIO2_2
-#define HOB_IOCON_PIO2_3 IOCON_PIO2_3
-#define HOB_IOCON_PIO2_4 IOCON_PIO2_4
-#define HOB_IOCON_PIO2_5 IOCON_PIO2_5
-#define HOB_IOCON_PIO2_6 IOCON_PIO2_6
-#define HOB_IOCON_PIO2_7 IOCON_PIO2_7
-#define HOB_IOCON_PIO2_8 IOCON_PIO2_8
-#define HOB_IOCON_PIO2_9 IOCON_PIO2_9
-#define HOB_IOCON_PIO2_10 IOCON_PIO2_10
-#define HOB_IOCON_PIO2_11 IOCON_PIO2_11
-
-#define HOB_IOCON_PIO3_0 IOCON_PIO3_0
-#define HOB_IOCON_PIO3_1 IOCON_PIO3_1
-#define HOB_IOCON_PIO3_2 IOCON_PIO3_2
-#define HOB_IOCON_PIO3_3 IOCON_PIO3_3
-#define HOB_IOCON_PIO3_4 IOCON_PIO3_4
-#define HOB_IOCON_PIO3_5 IOCON_PIO3_5
-
-#define HOB_EXPAND(foo) foo
-
-#define HOB_PORT_I(port, pin) port
-#define HOB_PIN_I(port, pin) pin
-#define HOB_PORT(spec) HOB_EXPAND(HOB_PORT_I HOB_TEST)
-#define HOB_PIN(spec)  HOB_EXPAND(HOB_PIN_I HOB_TEST)
-
-#define HOB_BUILD_IOREG_NAME_I(port, pin) HOB_IOCON_PIO ## port ## _ ## pin
-#define HOB_BUILD_IOREG_NAME(port, pin) HOB_BUILD_IOREG_NAME_I(port, pin)
-#define HOB_IOREG(spec) HOB_BUILD_IOREG_NAME(HOB_PORT(spec), HOB_PIN(spec))
-
-#define R0KET_SPEC_I(x, y) x,y
-#define R0KET_SPEC(hobspec) HOB_EXPAND(R0KET_SPEC_I hobspec)
-
-#define RB_SPI_CS_DF R0KET_SPEC(HOB_DATAFLASH_CS)
-
-#endif
index 47bb247..464e5c2 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef INCLUDED_R0KET_PORTS_H
 #define INCLUDED_R0KET_PORTS_H
 
-#define HW_IS_PROTOTYPE 1
+#ifdef R0KET
 
 // LED
 #define RB_LED0                            0,11
 
 
 // Buttons
-#if HW_IS_PROTOTYPE
-
-// TODO
-// FIXME:
-// order of buttons is without sense!
-#define RB_BTN1                            1,5
-#define RB_BTN1_IO                 IOCON_PIO1_5
-
-#define RB_BTN2                            1,6
-#define RB_BTN2_IO                 IOCON_PIO1_6
-
-#define RB_BTN3                            3,2
-#define RB_BTN3_IO                 IOCON_PIO3_2
-
-#define RB_BTN0                            3,3
-#define RB_BTN0_IO                 IOCON_PIO3_3
-
-#define RB_BTN4                            1,7
-#define RB_BTN4_IO                 IOCON_PIO1_7
-
-// A and B buttons on the hackover badge only
-#define RB_BTN_A            1,11
-#define RB_BTN_A_IO         IOCON_PIO1_11
-
-#define RB_BTN_B            1,4
-#define RB_BTN_B_IO         IOCON_PIO1_4
-
-#else
-
 // TODO: XXX
 // use alternate buttons for the board
 
 #define RB_BTN4                            2,7
 #define RB_BTN4_IO                 IOCON_PIO2_7
 
-
-#endif
-
-
-// LCD
-#if HW_IS_PROTOTYPE
-
-// backlight pin is used     in another way for prototype
-#define RB_LCD_CS              1,0
-#define RB_LCD_RST                 1,1
-
-#define RB_SPI_CS_DF  0,7
-
-#else
-
 #define RB_LCD_BL                  1,9
 #define RB_LCD_CS                  2,1
 #define RB_LCD_RST             2,2
 
 #define RB_SPI_CS_DF       2,0
 
-#endif
-
-
 // I2C
 #define RB_I2C_SCL                 0,4
 
 #define RB_HB5                     1,2
 #define RB_HB5_IO                  IOCON_PIO1_2
 
-// Funk
-#if HW_IS_PROTOTYPE
-
-#define RB_NRF_CE                  2,10
-#define RB_NRF_CE_IO           IOCON_PIO2_10
-#define RB_SPI_NRF_CS          2,9
-#define RB_SPI_NRF_CS_IO       IOCON_PIO2_9
-
-// TODO: this pin is new. support must be added for configuration in main.c
-#define RB_SPI_NRF_IRQ         2,2
-#define RB_SPI_NRF_IRQ_IO      IOCON_PIO2_2
-
-#else
-
 #define RB_NRF_CE                  1,5
 #define RB_NRF_CE_IO           IOCON_PIO1_5
 #define RB_SPI_NRF_CS          1,10
 #define RB_SPI_NRF_CS_IO       IOCON_PIO1_10
 
-#endif
-
 // Misc
 #define RB_BUSINT                  3,0
 #define RB_BUSINT_IO           IOCON_PIO3_0
 
 #endif
 
+#endif
+
This page took 0.075624 seconds and 4 git commands to generate.