optimized load logo function (thnx to andersro)
[my-code/arm.git] / betty / display.c
1 /*
2  * display.c - handling the display
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "display.h"
9 #include "system.h"
10 #include "default_logo.h"
11 #include "uart.h"
12
13 /*
14  * functions
15  */
16
17 void display_fill_screen(u8 fill) {
18
19         u8 page,width;
20
21         for(page=0;page<DISPLAY_PAGE_MAX;page++) {
22                 DISPLAY_SET_C_ADDR(0);
23                 DISPLAY_SET_PAGE_ADDR(page);
24                 for(width=0;width<DISPLAY_DIMX;width++) {
25                         DISPLAY_DATA=fill;
26                         DISPLAY_DATA=fill;
27                 }
28         }
29 }
30
31 void display_clear_screen(void) {
32
33         display_fill_screen(0x00);
34 }
35
36 void display_init(void) {
37
38         DISPLAY_EXIT_POWER_SAVE;
39
40         DISPLAY_SOFT_RESET;
41         pause(0xffffff);
42
43         DISPLAY_START_OSCILLATOR;
44
45         DISPLAY_SET_REGULATOR(7);
46
47         DISPLAY_SET_CONTRAST(0x38);
48
49         DISPLAY_SET_CONV_FACTOR(0x01);
50
51         DISPLAY_SET_PWM_FRC(0,0);
52
53         // gray scale palette
54         DISPLAY_SET_WHITE(0,0,0,0);
55         DISPLAY_SET_LGRAY(2,2,2,2);
56         DISPLAY_SET_DGRAY(6,6,6,6);
57         DISPLAY_SET_BLACK(9,9,9,9);
58
59         DISPLAY_SET_POWER(DISPLAY_REGULATOR|DISPLAY_OPAMP);
60         pause(0xffffff);
61         DISPLAY_SET_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR|DISPLAY_OPAMP);
62         
63         DISPLAY_RAM_CONTENTS_ON;
64
65         DISPLAY_NORMAL;
66
67         display_clear_screen();
68
69         DISPLAY_SET_ON;
70 }
71
72 void display_load_logo(u8 *src) {
73
74         u8 *s;
75         u8 page,width;
76
77         s=src;
78         if(s==0)
79                 s=default_logo;
80
81         for(page=0;page<DISPLAY_PAGE_MAX;page++) {
82                 DISPLAY_SET_C_ADDR(0);
83                 DISPLAY_SET_PAGE_ADDR(page);
84                 for(width=0;width<DISPLAY_DIMX;width++) {
85                         DISPLAY_DATA=*s++;
86                         DISPLAY_DATA=*s++;
87                 }
88         }
89 }
90
91 void display_bl_init(void) {
92
93         IODIR0|=(1<<4);
94         IOSET0=(1<<4);  // off by default
95 }
96
97 void display_bl_toggle(void) {
98
99         if(IOPIN0&(1<<4))
100                 IOCLR0=(1<<4);
101         else
102                 IOSET0=(1<<4);
103 }
104
105 void display_bl_on(void) {
106
107         IOCLR0=(1<<4);
108 }
109
110 void display_bl_off(void) {
111
112         IOSET0=(1<<4);
113 }
114