X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Fbetty.c;h=af593d87008cfc5fcc6e4d163037a81f3d2032fc;hb=60432148802391c2ba390e9c56f999514653c969;hp=68c86f7b319aad9f785e283cb337eb0440a61907;hpb=2cbc6d2f18a38237fcd1df2ef67ba315af080f03;p=my-code%2Farm.git diff --git a/betty/betty.c b/betty/betty.c index 68c86f7..af593d8 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -5,43 +5,12 @@ * */ -/* - * includes - */ - -#include "lpc2xxx.h" - -/* - * defines - */ - -/* bank 0/2 and boootloader addr/size */ -#define BANK0 0x80000000 -#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))) +#include "betty.h" /* - * type definitions + * functions */ -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; - - /* - * functions - */ - void mmap_init(u8 memtype) { MEMMAP=memtype; @@ -79,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 @@ -166,21 +138,152 @@ u8 uart0_get_byte(void) { return rx; } +void pause(int cnt) { + + while(cnt--) + asm volatile ("nop"); +} + +void init_lcd(u8 s) { + + LCD_CMD=0xe1; // ? + LCD_CMD=0xe2; + pause(48000); + LCD_CMD=0xab; + LCD_CMD=0x27; + LCD_CMD=0x81; + LCD_CMD=0x3f; + LCD_CMD=0x65; + LCD_CMD=0x60; + LCD_CMD=0x1c; + LCD_CMD=0x61; + LCD_CMD=0x0a; + LCD_CMD=0x62; + LCD_CMD=0x75; + LCD_CMD=0x63; + LCD_CMD=0x81; + LCD_CMD=0x90; + LCD_CMD=0x88; + LCD_CMD=0x00; + LCD_CMD=0x89; + LCD_CMD=0x00; + LCD_CMD=0x8a; + LCD_CMD=0x33; + LCD_CMD=0x8b; + LCD_CMD=0x33; + LCD_CMD=0x8c; + LCD_CMD=0x66; + LCD_CMD=0x8d; + LCD_CMD=0x66; + LCD_CMD=0x8e; + LCD_CMD=0x99; + LCD_CMD=0x8f; + LCD_CMD=0x99; + if(s) { + LCD_CMD=0xa1; + LCD_CMD=0xc0; + } + else { + LCD_CMD=0xa0; + LCD_CMD=0xc8; + } + LCD_CMD=0x2e; + pause(48000); + LCD_CMD=0x2f; + LCD_CMD=0xa4; + LCD_CMD=0xa6; +} + +/* + * spi0 stuff (+ cc1100) + */ + +#define SLAVE 0 +#define MASTER 1 + +void spi1_init(u8 width,u8 type,u8 div) { + + if((width<8)|(width>16)) + width=8; + if(width==16) + width=0; + + div&=0xfe; + if(div<8) + div=8; + + S1SPCR=(1<<2)|(width<<8)|(type<<5); + S1SPCCR=div; +} + +#define cc1100_init spi1_init(8,MASTER,8) + +void spi1_send(u16 data) { + + S1SPDR=data; + + while(!(S1SPSR&(1<<7))) + continue; +} + +void bl_init(void) { + + IODIR0|=(1<<4); +} + +void bl_toggle(void) { + + if(IOPIN0&(1<<4)) + IOCLR0=(1<<4); + else + IOSET0=(1<<4); +} + +void bl_on(void) { + + IOCLR0=(1<<4); +} + +void bl_off(void) { + + IOSET0=(1<<4); +} + /* * main function */ int main() { - char buf="betty - live from the flash at 0x80000000! ;)\r\n"; + char buf[]="betty - live from the flash at 0x80000000! ;)\r\n"; + u64 keys; + u8 i; pll_init(); uart0_init(); ext_mem_bank_init(); pin_select_init(); - - while(1) - uart0_send_string(buf); + init_lcd(0); + bl_init(); + button_init(); + + pause(0xffffff); + + bl_toggle(); + + while(1) { + 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<