stupid mistake fixed, display basically working now!
[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         u32 cnt;
77
78         s=src;
79         if(s==0)
80                 s=default_logo;
81
82         cnt=0;
83         for(page=0;page<DISPLAY_PAGE_MAX;page++) {
84                 DISPLAY_SET_C_ADDR(0);
85                 DISPLAY_SET_PAGE_ADDR(page);
86                 for(width=0;width<DISPLAY_DIMX;width++) {
87                         DISPLAY_DATA=s[cnt];
88                         DISPLAY_DATA=s[cnt+1];
89                         cnt+=2;
90                 }
91         }
92 }
93
94 void display_bl_init(void) {
95
96         IODIR0|=(1<<4);
97         IOSET0=(1<<4);  // off by default
98 }
99
100 void display_bl_toggle(void) {
101
102         if(IOPIN0&(1<<4))
103                 IOCLR0=(1<<4);
104         else
105                 IOSET0=(1<<4);
106 }
107
108 void display_bl_on(void) {
109
110         IOCLR0=(1<<4);
111 }
112
113 void display_bl_off(void) {
114
115         IOSET0=(1<<4);
116 }
117