]> hackdaworld.org Git - my-code/arm.git/commitdiff
button support
authorhackbard <hackbard@staubsauger.localdomain>
Thu, 6 Sep 2007 00:34:09 +0000 (02:34 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Thu, 6 Sep 2007 00:34:09 +0000 (02:34 +0200)
betty/Makefile
betty/betty.c
betty/buttons.c [new file with mode: 0644]
betty/buttons.h [new file with mode: 0644]

index 0af33acaa0f98a8e698c9ee1cd58dc35c8dc8854..54f1d34b60df3feadbe7140a3ba3d56f42b7a773 100644 (file)
@@ -18,6 +18,9 @@ CROSS_ROM_LDFLAGS = -Tlpc2220_rom.ld -nostartfiles -nostdlib
 HOST_TARGET = lpcload fwdump
 CROSS_TARGET = fwbc.hex fwflash.hex betty.hex
 
+# betty deps
+BETTY_DEPS = buttons.o
+
 # all projects
 all: $(HOST_TARGET) $(CROSS_TARGET)
 
@@ -36,9 +39,10 @@ arm: arm_clean $(CROSS_TARGET)
 %.elf: %.o startup.o
        $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o -o $@ $<
 
-# special linker case ...
-betty.elf: betty.o startup.o
-       $(CROSS_LD) $(CROSS_ROM_LDFLAGS) startup.o -o $@ $<
+# betty is special ;)
+betty.elf: betty.o startup.o $(BETTY_DEPS)
+       #$(CROSS_LD) $(CROSS_ROM_LDFLAGS) startup.o -o $@ $<
+       $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o $(BETTY_DEPS) -o $@ $<
 
 # .hex out of .elf
 %.hex: %.elf
@@ -46,7 +50,7 @@ betty.elf: betty.o startup.o
 
 # host clean
 clean:
-       rm -f lpcload fwdump
+       rm -vf lpcload fwdump
 
 # arm clean
 arm_clean:
index 81b4687e2f18566f931a4e397e0a5b9ccddc3915..af593d87008cfc5fcc6e4d163037a81f3d2032fc 100644 (file)
@@ -5,48 +5,12 @@
  *
  */
 
-/*
- * includes
- */
-
-#include "lpc2xxx.h"
+#include "betty.h"
 
 /*
- * defines
+ * functions
  */
 
-/* bank 0/2 and boootloader addr/size */
-#define BANK0                  0x80000000
-#define BANK1                  0x81000000
-#define BANK2                  0x82000000
-#define BANK_SIZE              0x00100000
-#define BOOTLOADER             0x7fffe000
-#define BL_SIZE                        0x00002000
-
-/* flash cmd addresses - flash[0-18] <--> arm[1-19]*/
-#define B0F555 (*((volatile unsigned short *)(BANK0|0xaaa)))   // 0x555
-#define B0F2AA (*((volatile unsigned short *)(BANK0|0x554)))   // 0x2aa
-#define B0F    (*((volatile unsigned short *)(BANK0)))
-#define B2F555 (*((volatile unsigned short *)(BANK2|0xaaa)))   // 0x555
-#define B2F2AA (*((volatile unsigned short *)(BANK2|0x554)))   // 0x2aa
-#define B2F    (*((volatile unsigned short *)(BANK2)))
-
-/* lcd command and data addresses */
-#define LCD_CMD                (*((volatile unsigned char *)(BANK1)))
-#define LCD_DATA       (*((volatile unsigned char *)(BANK1+1)))
-
-/*
- * type definitions
- */
-
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-
- /*
-  * functions
-  */
-
 void mmap_init(u8 memtype) {
 
        MEMMAP=memtype;
@@ -84,7 +48,10 @@ void pin_select_init() {
 
 void uart0_init(void) {
 
-       PINSEL0=0x05;                   // pin select -> tx, rx
+       /* select pins 0.0 and 0.1 as tx and rx */
+       PINSEL0=(PINSEL0&~(0xf))|0x05;          // pin select -> tx, rx
+
+       /* configure uart0 */
        UART0_FCR=0x07;                 // enable fifo
        UART0_LCR=0x83;                 // set dlab + word length
        UART0_DLL=0x04;                 // br: 38400 @ 10/4 mhz
@@ -289,6 +256,8 @@ void bl_off(void) {
 int main() {
 
        char buf[]="betty - live from the flash at 0x80000000! ;)\r\n";
+       u64 keys;
+       u8 i;
 
        pll_init();
        uart0_init();
@@ -296,13 +265,24 @@ int main() {
        pin_select_init();
        init_lcd(0);
        bl_init();
+       button_init();
 
        pause(0xffffff);
 
+       bl_toggle();
+
        while(1) {
-               uart0_send_string(buf);
-               bl_toggle();
-               pause(0x9ffff);
+               uart0_send_string("\n");
+               //uart0_send_string(buf);
+               //bl_toggle();
+               pause(0x0fffff);
+               button_get_event(&keys,1000);
+               for(i=0;i<42;i++) {
+                       //if(keys&(1<<i)) {
+                       //      uart0_send_byte(0x30+i);
+                       //      break;
+                       uart0_send_byte(keys&(1<<i)?0x31:0x30);
+               }
        }
 
        return 0;
diff --git a/betty/buttons.c b/betty/buttons.c
new file mode 100644 (file)
index 0000000..ba76f8d
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * buttons.c - button api
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#include "buttons.h"
+
+void button_init(void) {
+
+       /* 
+        * select as input the following pins
+        *  - p0.30 : interrupt, wtf is the 'vw 3 p9'?
+        *  - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : column select
+        *
+        *  select as output
+        *  - p2.18-p2.24 : the rows
+        */
+
+       // gpio, as is: p3.20, p3.21
+       PINSEL1&=~((1<<29)|(1<<28));    // p0.30
+       PINSEL1&=~((1<<25)|(1<<24));    // p0.28
+       PINSEL1&=~((1<<23)|(1<<22));    // p0.27
+       PINSEL1&=~((1<<13)|(1<<12));    // p0.22
+       PINSEL0&=~((1<<27)|(1<<26));    // p0.13
+       // ctrl databus for p2.18 - p2.24
+       PINSEL2&=(PINSEL2&(~((1<<5)|(1<<4))))|(1<<4);
+       // input
+       IODIR0&=~((1<<30)|(1<<28)|(1<<27)|(1<<22)|(1<<13));
+       IODIR3&=~((1<<21)|(1<<20));
+       // output + pull them high
+       IODIR2|=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
+       IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
+}
+
+void button_select_row(u8 row) {
+
+       IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
+       if(row>6)
+               return;
+       IOCLR2=(1<<(18+row));
+}
+
+u8 button_get_event(u64 *keys,int retries) {
+
+       u8 row;
+       u8 offset;
+       u8 cnt;
+       u32 port0,port3;
+
+       *keys=0;
+       cnt=0;
+
+       while(retries--) {
+               /* rest counter */
+               offset=0;
+               /* rows */
+               for(row=0;row<7;row++) {
+                       /* select the row */
+                       button_select_row(row);
+                       /* scan the columns 6 */
+                       port0=IOPIN0;
+                       port3=IOPIN2;
+                       if(!(port0&(1<<28))) {
+                               *keys|=(1<<(offset+0));
+                               cnt+=1;
+                       }
+                       if(!(port0&(1<<27))) {
+                               *keys|=(1<<(offset+1));
+                               cnt+=1;
+                       }
+                       if(!(port0&(1<<22))) {
+                               *keys|=(1<<(offset+2));
+                               cnt+=1;
+                       }
+                       if(!(port0&(1<<13))) {
+                               *keys|=(1<<(offset+3));
+                               cnt+=1;
+                       }
+                       if(!(port3&(1<<21))) {
+                               *keys|=(1<<(offset+4));
+                               cnt+=1;
+                       }
+                       if(!(port3&(1<<20))) {
+                               *keys|=(1<<(offset+5));
+                               cnt+=1;
+                       }
+                       offset+=6;
+               }
+               if(*keys)
+                       break;
+       }
+
+       return cnt;
+}
+
diff --git a/betty/buttons.h b/betty/buttons.h
new file mode 100644 (file)
index 0000000..e4016b1
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * buttons.h - button api header file
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#ifndef BUTTONS_H
+#define BUTTONS_H
+
+/* includes */
+#include "betty.h"
+
+/* function prototypes */
+void button_init(void);
+unsigned char button_get_event(unsigned long long int *keys,int retries);
+
+#endif