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)
%.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
# host clean
clean:
- rm -f lpcload fwdump
+ rm -vf lpcload fwdump
# arm clean
arm_clean:
*
*/
-/*
- * 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;
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
int main() {
char buf[]="betty - live from the flash at 0x80000000! ;)\r\n";
+ u64 keys;
+ u8 i;
pll_init();
uart0_init();
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;
--- /dev/null
+/*
+ * 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;
+}
+
--- /dev/null
+/*
+ * 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