Initialisierung bisschen aufgeräumt.
authorWintermute <wintermute@hannover.ccc.de>
Tue, 8 Oct 2013 21:05:57 +0000 (23:05 +0200)
committerWintermute <wintermute@hannover.ccc.de>
Tue, 8 Oct 2013 21:05:57 +0000 (23:05 +0200)
Makefile
badge/main.c
badge/ui/event.c
r0ketports.h

index affa70b..9bf3e37 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ SRAM_USB = 384
 \r
 # Set DEBUGBUILD to 'TRUE' for full debugging (larger, slower binaries), \r
 # or to 'FALSE' for release builds (smallest, fastest binaries)\r
-DEBUGBUILD = FALSE\r
+DEBUGBUILD = TRUE\r
 \r
 ##########################################################################\r
 # IDE Flags (Keeps various IDEs happy)\r
index 6acbd0b..77ce342 100644 (file)
@@ -59,6 +59,8 @@
 #include "r0ketports.h"
 #include "drivers/fatfs/ff.h"
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof*(arr))
+
 void backlightInit(void) {
   /* Enable the clock for CT16B1 */
   SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT16B1);
@@ -97,65 +99,64 @@ void rbInit() {
     gpioSetDir(USB_CONNECT, gpioDirection_Output);
     gpioSetValue(USB_CONNECT, 1);
 
-    static uint8_t ports[] = { RB_BTN0, RB_BTN1, RB_BTN2, RB_BTN3, RB_BTN4,
-                               RB_LED0, RB_LED1, RB_LED2,
-                               RB_HB3, RB_HB4, RB_SPI_SS2,
-                               RB_SPI_SS3, RB_SPI_SS4, RB_SPI_SS5,
-                               RB_HB0, RB_HB1, RB_HB2,
-                               RB_HB3, RB_HB4, RB_HB5};
-
-    volatile uint32_t * regs[] = {&RB_BTN0_IO, &RB_BTN1_IO, &RB_BTN2_IO,
-                                  &RB_BTN3_IO, &RB_BTN4_IO};
-
-    int i = 0;
-    while( i<10 ){
-        gpioSetDir(ports[i], ports[i+1], gpioDirection_Input);
-        gpioSetPullup(regs[i/2], gpioPullupMode_PullUp);
-        i+=2;
+    struct {
+      int port;
+      int pin;
+      uint32_t volatile *reg;
+    } 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_HB3 , &RB_HB3_IO  },
+      { RB_HB4 , &RB_HB4_IO  },
+      { RB_PWR_CHRG, &RB_PWR_CHRG_IO }
+    };
+    
+    //    RB_HB3_IO = IOCON_PIO0_2_FUNC_GPIO | IOCON_PIO0_2_MODE_PULLUP | 0xc0;    
+
+    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);
     }
 
-    // prepate chrg_stat
-    gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
-    gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
-
+    // LED3 zur Bestimmung der Umgebungshelligkeit.
     gpioSetDir(RB_LED3, gpioDirection_Input);
-    IOCON_PIO1_11 = 0x41;
+    RB_LED3_IO = (RB_LED3_IO & IOCON_PIO1_11_FUNC_MASK) | IOCON_PIO1_11_FUNC_AD7;
 
     // 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;
-
-    while( i<16 ){
-        gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
-        gpioSetValue (ports[i], ports[i+1], 0);
-        i+=2;
+    IOCON_JTAG_TDI_PIO0_11 |=  IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
+
+    struct {
+      int port;
+      int pin;
+      int value;
+    } const output_pins[] = {
+      { RB_LED0   , 0 },
+      { RB_LED1   , 0 },
+      { RB_LED2   , 0 },
+      { RB_SPI_SS2, 1 },
+      { RB_SPI_SS3, 1 },
+      { RB_SPI_SS4, 1 },
+      { RB_SPI_SS5, 1 },
+      { RB_LCD_BL , 0 }
+    };
+
+    for(int i = 0; i < ARRAY_SIZE(output_pins); ++i) {
+        gpioSetDir  (output_pins[i].port, output_pins[i].pin, gpioDirection_Output);
+        gpioSetValue(output_pins[i].port, output_pins[i].pin, output_pins[i].value);
     }
 
-    // Set LED3 to ?
-    IOCON_PIO1_11 = 0x41;
-
-    // prepare lcd
-    // TODO FIXME more init needed ?
-    gpioSetDir(RB_LCD_BL, gpioDirection_Output);
-    gpioSetValue (RB_LCD_BL, 0);
-
     // 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);
+    RB_PWR_LCDBL_IO &= ~RB_PWR_LCDBL_IO_FUNC_MASK;
+    RB_PWR_LCDBL_IO |=  RB_PWR_LCDBL_IO_FUNC_GPIO;
 
-    // prepare SPI/SS
-    // TODO FIXME init miso/mosi/sck somehow ?
-    // prepare hackerbus
-    while(i<sizeof(ports)){
-        gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
-        gpioSetValue (ports[i], ports[i+1], 1);
-        i+=2;
-    }
+    gpioSetDir   ( RB_PWR_LCDBL   , gpioDirection_Input);
+    gpioSetPullup(&RB_PWR_LCDBL_IO, gpioPullupMode_Inactive);
 
     backlightInit();
-    //font=&Font_7x8;
 }
 
 
index f5961bf..6e9ab35 100644 (file)
@@ -22,6 +22,8 @@ static uint8_t badge_input_raw(void) {
     if (gpioGetValue(RB_BTN0) == 0) { result |= BADGE_EVENT_KEY_LEFT  ; }
     if (gpioGetValue(RB_BTN1) == 0) { result |= BADGE_EVENT_KEY_RIGHT ; }
     // TODO: Knöpfe.
+    if (gpioGetValue(RB_HB3)  == 0) { result |= BADGE_EVENT_KEY_UP    ; }
+    if (gpioGetValue(RB_HB4)  == 0) { result |= BADGE_EVENT_KEY_UP    ; }
 
     return result;
 }
index 1b753f6..099d9c7 100644 (file)
@@ -3,13 +3,13 @@
 
 // LED
 #define RB_LED0                        0,11
-
+#define RB_LED0_IO              IOCON_PIO0_11
 #define RB_LED1                        1,7
-
+#define RB_LED1_IO              IOCON_PIO1_7
 #define RB_LED2                        1,6
-
+#define RB_LED2_IO              IOCON_PIO1_6
 #define RB_LED3                        1,11
-
+#define RB_LED3_IO              IOCON_PIO1_11
 
 // Infrared
 //#define RB_IROUT             1,5
This page took 0.035623 seconds and 4 git commands to generate.