basic lcd control (must get improved!)
[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_clear_screen(void) {
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=0x00;
26                         DISPLAY_DATA=0x00;
27                 }
28         }
29 }
30
31 void display_init(void) {
32
33         DISPLAY_EXIT_POWER_SAVE;
34
35         DISPLAY_SOFT_RESET;
36         pause(0xffffff);
37
38         DISPLAY_START_OSCILLATOR;
39
40         DISPLAY_SET_REGULATOR(7);
41
42         DISPLAY_SET_CONTRAST(0x38);
43
44         DISPLAY_SET_CONV_FACTOR(0x01);
45
46         DISPLAY_SET_PWM_FRC(0,0);
47
48         // gray scale palette
49         DISPLAY_SET_WHITE(0,0,0,0);
50         DISPLAY_SET_LGRAY(2,2,2,2);
51         DISPLAY_SET_DGRAY(6,6,6,6);
52         DISPLAY_SET_BLACK(9,9,9,9);
53
54         DISPLAY_SET_POWER(DISPLAY_REGULATOR|DISPLAY_OPAMP);
55         pause(0xffffff);
56         DISPLAY_SET_POWER(DISPLAY_V_BOOST|DISPLAY_REGULATOR|DISPLAY_OPAMP);
57         
58         DISPLAY_RAM_CONTENTS_ON;
59
60         DISPLAY_NORMAL;
61
62         display_clear_screen();
63
64         DISPLAY_SET_ON;
65 }
66
67 void display_load_logo(u8 *src) {
68
69         u8 *s;
70         u8 page,width;
71         u32 cnt;
72
73         s=src;
74         if(s==0)
75                 s=default_logo;
76
77         cnt=0;
78         for(page=0;page<DISPLAY_PAGE_MAX;page++) {
79                 DISPLAY_SET_C_ADDR(0);
80                 DISPLAY_SET_PAGE_ADDR(page);
81                 for(width=0;width<DISPLAY_DIMX;width++) {
82                         DISPLAY_DATA=s[cnt];
83                         DISPLAY_DATA=s[cnt+1];
84                         cnt+=2;
85                 }
86         }
87 }
88
89 void display_bl_init(void) {
90
91         IODIR0|=(1<<4);
92         IOSET0=(1<<4);  // off by default
93 }
94
95 void display_bl_toggle(void) {
96
97         if(IOPIN0&(1<<4))
98                 IOCLR0=(1<<4);
99         else
100                 IOSET0=(1<<4);
101 }
102
103 void display_bl_on(void) {
104
105         IOCLR0=(1<<4);
106 }
107
108 void display_bl_off(void) {
109
110         IOSET0=(1<<4);
111 }
112