button support
[my-code/arm.git] / betty / betty.c
index 81b4687..af593d8 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;