2 * display.c - handling the display
4 * author: hackbard@hackdaworld.org
9 * some comments on alpha blending!
10 * ################################
12 * if c is the result of layer a over layer b with opacity alpha:
14 * c=alpha*a+(1-alpha)*b and if alpha is a byte (0-255)
15 * => c=alpha*a+(255-alpha)*b
21 #include "default_logo.h"
28 void display_fill_screen(u8 fill) {
52 for(page=0;page<DISPLAY_PAGE_MAX;page++) {
53 DISPLAY_SET_COL_ADDR(0);
54 DISPLAY_SET_PAGE_ADDR(page);
55 for(width=0;width<DISPLAY_DIMX;width++) {
62 void display_clear_screen(void) {
64 display_fill_screen(DISPLAY_FILL_W);
67 void display_init(void) {
69 /* oscillator, regulator, boost, opamp, contrast */
70 DISPLAY_START_OSCILLATOR;
71 DISPLAY_SET_REGULATOR(7);
72 DISPLAY_SET_CONTRAST(0x38);
73 DISPLAY_SET_CONV_FACTOR(0x01);
74 DISPLAY_SET_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR|DISPLAY_OPAMP);
77 DISPLAY_SET_WHITE(0,0,0,0);
78 DISPLAY_SET_LGRAY(5,5,5,5); // obviously 3, but it's too bright!
79 DISPLAY_SET_DGRAY(7,7,7,7); // obviously 6, but again too bright!
80 DISPLAY_SET_BLACK(9,9,9,9);
82 /* normal mode, display depending ram content */
83 DISPLAY_RAM_CONTENTS_ON;
84 display_clear_screen();
85 DISPLAY_NORMAL; // 00 -> white, 11 -> black
86 DISPLAY_SET_COM_ODIR_REMAPPED; // start counting at the top
88 /* switch on the display */
92 void display_load_logo(u8 *src) {
101 for(page=0;page<DISPLAY_PAGE_MAX;page++) {
102 DISPLAY_SET_COL_ADDR(0);
103 DISPLAY_SET_PAGE_ADDR(page);
104 for(width=0;width<DISPLAY_DIMX;width++) {
111 #define display_m2i(m,r) (((((m)[0]>>r)&1)<<1)|(((m)[1]>>r)&1))
113 void display_draw_rectangle(u8 x,u8 y,u8 w,u8 h,u8 fill,u8 alpha) {
115 u8 page,col,row,rmax,cnt;
118 u8 a,b,c; // c = a over b
122 for(cnt=0;cnt<a;cnt++) // contribution of a: alpha*a
125 for(page=(y>>3);page<=((y+h)>>3);page++) { // page = y/8
126 DISPLAY_SET_PAGE_ADDR(page);
127 rmax=(page+1)<<3; // row max
130 for(col=x;col<x+w;col++) {
131 DISPLAY_SET_COL_ADDR(col);
132 d[0]=DISPLAY_DATA; // dummy read (p.16)
135 for(row=y;row<rmax;row++) {
136 // contribution of b: (255-alpha)*b
137 b=display_m2i(d,row);
139 for(cnt=0;cnt<b;cnt++)
141 // finally there is c
145 d[0]|=((c>>1)&1)<<row;
148 DISPLAY_SET_COL_ADDR(col);
157 void display_draw_font(u8 x,u8 y,u8 *font,u8 fill,u8 alpha) {
159 u8 page,col,row,rmax,cnt,left;
162 u8 a,b,c; // c = a over b
168 for(cnt=0;cnt<a;cnt++) // contribution of a: alpha*a
171 for(page=(y>>3);page<=((y+8)>>3);page++) { // page = y/8
172 DISPLAY_SET_PAGE_ADDR(page);
173 rmax=(page+1)<<3; // row max
177 for(col=x;col<x+8;col++) {
178 DISPLAY_SET_COL_ADDR(col);
179 d[0]=DISPLAY_DATA; // dummy read (p.16)
183 for(row=y;row<rmax;row++) {
184 // contribution of b: (255-alpha)*b
185 b=display_m2i(d,row);
187 for(cnt=0;cnt<b;cnt++)
189 // finally there is c
190 if((font[cf]>>row)&1) {
194 d[0]|=((c>>1)&1)<<row;
199 DISPLAY_SET_COL_ADDR(col);
209 void display_draw_buf(u8 x,u8 y,u8 w,u8 h,u8 *buf,u8 alpha) {
211 u8 page,col,row,rmax,cnt;
216 for(page=(y>>3);page<=((y+h)>>3);page++) {
217 DISPLAY_SET_PAGE_ADDR(page);
218 for(col=x;col<x+w;col++) {
219 DISPLAY_SET_COL_ADDR(col);
223 for(row=y;row<rmax;row++) {
229 void display_bl_init(void) {
232 IOSET0=(1<<4); // off by default
235 void display_bl_toggle(void) {
243 void display_bl_on(void) {
248 void display_bl_off(void) {