From: hackbard Date: Thu, 6 Sep 2007 00:34:09 +0000 (+0200) Subject: button support X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=60432148802391c2ba390e9c56f999514653c969;p=my-code%2Farm.git button support --- diff --git a/betty/Makefile b/betty/Makefile index 0af33ac..54f1d34 100644 --- a/betty/Makefile +++ b/betty/Makefile @@ -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: diff --git a/betty/betty.c b/betty/betty.c index 81b4687..af593d8 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -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<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 index 0000000..e4016b1 --- /dev/null +++ b/betty/buttons.h @@ -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