font2b + default_font.h fix (hopefully), display and rom ld just to sync
[my-code/arm.git] / betty / display.c
index fad0804..2da19ef 100644 (file)
  *
  */
 
+/*
+ * some comments on alpha blending!
+ *
+ * ...
+ *
+ */
+
 #include "display.h"
+#include "system.h"
+#include "default_logo.h"
+#include "uart.h"
 
 /*
  * functions
  */
 
-void display_clear_screen(void) {
-
-       u32 cnt;
+void display_fill_screen(u8 fill) {
+
+       u8 page,width;
+       u8 buf[2];
+
+       buf[0]=0;
+       buf[1]=0;
+
+       switch(fill) {
+               case DISPLAY_FILL_LG:
+                       buf[1]=0xff;
+                       break;
+               case DISPLAY_FILL_DG:
+                       buf[0]=0xff;
+                       break;
+               case DISPLAY_FILL_B:
+                       buf[0]=0xff;
+                       buf[1]=0xff;
+                       break;
+               case DISPLAY_FILL_W:
+               default:
+                       break;
+       }
+
+       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=buf[0];
+                       DISPLAY_DATA=buf[1];
+               }
+       }
+}
 
-       DISPLAY_SET_PAGE_ADDR(0);
-       DISPLAY_SET_C_ADDR(0);
+void display_clear_screen(void) {
 
-       for(cnt=0;cnt<DISPLAY_RAM_CONTENT;cnt++)
-               DISPLAY_DATA=0x00;
+       display_fill_screen(DISPLAY_FILL_W);
 }
 
 void display_init(void) {
 
-       /* configure the ext mem bank interface */
-       BCFG1=0x00000c42;
-
-       DISPLAY_SOFT_RESET;
-
-       pause(0xffffff);
-
+       /* oscillator, regulator, boost, opamp, contrast */
        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_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR|DISPLAY_OPAMP);
+
+       // gray scale palette
+       DISPLAY_SET_WHITE(0,0,0,0);
+       DISPLAY_SET_LGRAY(5,5,5,5);     // obviously 3, but it's too bright!
+       DISPLAY_SET_DGRAY(7,7,7,7);     // obviously 6, but again too bright!
+       DISPLAY_SET_BLACK(9,9,9,9);
+
+       /* normal mode, display depending ram content */
+       DISPLAY_RAM_CONTENTS_ON;
        display_clear_screen();
+       DISPLAY_NORMAL;                 // 00 -> white, 11 -> black
+       DISPLAY_SET_COM_ODIR_REMAPPED;  // start counting at the top
 
+       /* switch on the display */
        DISPLAY_SET_ON;
 }
 
 void display_load_logo(u8 *src) {
 
-       u32 cnt;
-
-       DISPLAY_SET_PAGE_ADDR(0);
-       DISPLAY_SET_C_ADDR(0);
+       u8 *s;
+       u8 page,width;
+
+       s=src;
+       if(s==0)
+               s=default_logo;
+
+       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++;
+                       DISPLAY_DATA=*s++;
+               }
+       }
+}
 
-       for(cnt=0;cnt<DISPLAY_RAM_CONTENT;cnt++)
-               DISPLAY_DATA=src[cnt];
+void display_draw_rectangle(int x,int y,int w,int h,u8 fill,u8 alpha) {
+
+       int c,r,rmax;
+       u8 p,spage,epage;
+       u8 b[2],a[2];           // c = a over b => c=alpha*a+(1-alpha)*b
+
+       a[0]=0;
+       a[1]=0;
+       switch(fill) {
+               case DISPLAY_FILL_LG:
+                       a[1]=1;
+                       break;
+               case DISPLAY_FILL_DG:
+                       a[0]=1;
+                       break;
+               case DISPLAY_FILL_B:
+                       a[0]=1;
+                       a[1]=1;
+               case DISPLAY_FILL_W:
+               default:
+                       break;
+       }
+
+       spage=y>>3;                                     // start page = y/8
+       epage=(y+h)>>3;                                 // end page (y+h)/8
+
+       for(p=spage;p<=epage;p++) {
+               DISPLAY_SET_PAGE_ADDR(p);
+               for(c=x;c<x+w;c++) {
+                       DISPLAY_SET_C_ADDR(c);
+                       b[0]=DISPLAY_DATA;              // dummy read (p.16)
+                       b[0]=DISPLAY_DATA;
+                       b[1]=DISPLAY_DATA;
+                       rmax=y+8>y+h?y+h:y+8;
+                       for(r=y;r<rmax;r++) {
+                               b[0]&=~(1<<r);
+                               b[1]&=~(1<<r);
+                               b[0]|=a[0]<<r;
+                               b[1]|=a[1]<<r;
+                       }
+                       DISPLAY_SET_C_ADDR(c);
+                       DISPLAY_DATA=b[0];
+                       DISPLAY_DATA=b[1];
+               }
+               y+=8;
+       }
 }
 
 void display_bl_init(void) {
 
-       PINSEL0&=~(1<<9|(1<<8));
        IODIR0|=(1<<4);
+       IOSET0=(1<<4);  // off by default
 }
 
 void display_bl_toggle(void) {