basic lcd control (must get improved!)
[my-code/arm.git] / betty / display.c
index 1d6af1a..e102141 100644 (file)
@@ -6,6 +6,9 @@
  */
 
 #include "display.h"
+#include "system.h"
+#include "default_logo.h"
+#include "uart.h"
 
 /*
  * functions
 
 void display_clear_screen(void) {
 
-       u32 cnt;
-
-       DISPLAY_SET_PAGE_ADDR(0);
-       DISPLAY_SET_C_ADDR(0);
+       u8 page,width;
 
-       for(cnt=0;cnt<DISPLAY_RAM_CONTENT;cnt++)
-               DISPLAY_DATA=0x00;
+       for(page=0;page<DISPLAY_PAGE_MAX;page++) {
+               DISPLAY_SET_C_ADDR(0);
+               DISPLAY_SET_PAGE_ADDR(page);
+               for(width=0;width<DISPLAY_DIMX;width++) {
+                       DISPLAY_DATA=0x00;
+                       DISPLAY_DATA=0x00;
+               }
+       }
 }
 
 void display_init(void) {
 
-       /* configure the ext mem bank interface */
-       BCFG1=0x00000c42;
-
        DISPLAY_EXIT_POWER_SAVE;
 
-       /* reset the display, wait until its up again */
        DISPLAY_SOFT_RESET;
        pause(0xffffff);
 
        DISPLAY_START_OSCILLATOR;
 
-       DISPLAY_SET_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR);
+       DISPLAY_SET_REGULATOR(7);
+
+       DISPLAY_SET_CONTRAST(0x38);
+
+       DISPLAY_SET_CONV_FACTOR(0x01);
+
+       DISPLAY_SET_PWM_FRC(0,0);
+
+       // gray scale palette
+       DISPLAY_SET_WHITE(0,0,0,0);
+       DISPLAY_SET_LGRAY(2,2,2,2);
+       DISPLAY_SET_DGRAY(6,6,6,6);
+       DISPLAY_SET_BLACK(9,9,9,9);
+
+       DISPLAY_SET_POWER(DISPLAY_REGULATOR|DISPLAY_OPAMP);
+       pause(0xffffff);
+       DISPLAY_SET_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR|DISPLAY_OPAMP);
+       
+       DISPLAY_RAM_CONTENTS_ON;
+
+       DISPLAY_NORMAL;
 
        display_clear_screen();
 
@@ -44,19 +66,30 @@ void display_init(void) {
 
 void display_load_logo(u8 *src) {
 
+       u8 *s;
+       u8 page,width;
        u32 cnt;
 
-       DISPLAY_SET_PAGE_ADDR(0);
-       DISPLAY_SET_C_ADDR(0);
-
-       for(cnt=0;cnt<DISPLAY_RAM_CONTENT;cnt++)
-               DISPLAY_DATA=src[cnt];
+       s=src;
+       if(s==0)
+               s=default_logo;
+
+       cnt=0;
+       for(page=0;page<DISPLAY_PAGE_MAX;page++) {
+               DISPLAY_SET_C_ADDR(0);
+               DISPLAY_SET_PAGE_ADDR(page);
+               for(width=0;width<DISPLAY_DIMX;width++) {
+                       DISPLAY_DATA=s[cnt];
+                       DISPLAY_DATA=s[cnt+1];
+                       cnt+=2;
+               }
+       }
 }
 
 void display_bl_init(void) {
 
-       PINSEL0&=~(1<<9|(1<<8));
        IODIR0|=(1<<4);
+       IOSET0=(1<<4);  // off by default
 }
 
 void display_bl_toggle(void) {