-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.c
139 lines (109 loc) · 2.68 KB
/
lcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <lcd.h>
#include <backlight.h>
static void fimd0_clock_select(void)
{
u32 val;
/*SCLK_FIMD0 = MOUTFIMD0/(FIMD0_RATIO + 1) = MOUTFIMD0/(7+1)*/
val = ioread32(CLK_DIV_LCD);
val &= ~0xf;
val |= 0x7;
iowrite32(val, CLK_DIV_LCD);
/*SELECT MPLL_USER_T as MOUTFIMD0*/
val = ioread32(CLK_SRC_LCD0);
val &= ~0xf;
val |= 0x6;
iowrite32(val, CLK_SRC_LCD0);
}
static void window0_init(void)
{
u32 val;
/*set BPP888, WORD SWAP, enable*/
val = (0x1 << 15) | (0xb << 2) | (1 << 0);
iowrite32(val, WINCON0);
/*set left top xy (0, 0)*/
iowrite32(0, VIDOSD0A);
/*set right bootm xy (799, 479)*/
iowrite32((799 << 11) | (479 << 0), VIDOSD0B);
/*the number of word of window0 */
iowrite32(800*480, VIDOSD0C);
/*set window0's frambuff's start and end address*/
iowrite32(FRAMBUFF0, VIDW00ADD0B0);
iowrite32(FRAMBUFF0 + 800*480*4, VIDW00ADD1B0);
/*channel0 select window0, window0 selsect channel0*/
val = ioread32(WINCHMAP2);
val &= ~((0x7 << 16) | (0x7 << 0));
val |= (0x1 << 16) | (0x1 << 0);
iowrite32(val, WINCHMAP2);
/*enable channel0, disable local path*/
val = ioread32(SHADOWCON);
val &= ~(1 << 5);
val |= 1 << 0;
iowrite32(val, SHADOWCON);
}
static void lcd_gpio_set(void)
{
u32 val;
iowrite32(0x22222222, GPF0CON);
iowrite32(0x22222222, GPF1CON);
iowrite32(0x22222222, GPF2CON);
val = ioread32(GPF3CON);
val &= ~0xffff;
val |= 0x2222;
iowrite32(val, GPF3CON);
}
void lcd_init(void)
{
u32 val;
/*set GFP0,GPF1, GPF2, GPF3[0:3] 24pins as display controller uses*/
lcd_gpio_set();
/*100MHz/(2+1) = 33.3MHz*/
val = ioread32(VIDCON0);
val &= ~(0xff << 6);
val |= (0x2 << 6);
iowrite32(val, VIDCON0);
/*VCLK: rising, HSYNC/VSYNC: inverted*/
val = (1 << 9) | (1 << 7) | (1 << 6) | (1 << 5);
iowrite32(val, VIDCON1);
// iowrite32(0, VIDCON2);
/*set VSYNC TIMING ARG*/
val = (12 << 16) | (21 << 8) | (9 << 0);
iowrite32(val, VIDTCON0);
/*set HSYNC TIMING ARG*/
val = (25 << 16) | (209 << 8) | (19 << 0);
iowrite32(val, VIDTCON1);
/*set LCD HARD reselution*/
iowrite32((479 << 11) | (799 << 0), VIDTCON2);
window0_init();
/*set 100MHz*/
fimd0_clock_select();
/*enable blklight*/
val = ioread32(LCDBLK_CFG);
val |= 1 << 1;
iowrite32(val, LCDBLK_CFG);
/*enable display controller control signal*/
val = ioread32(VIDCON0);
val |= 0x3;
iowrite32(val, VIDCON0);
set_backlight_start(127);
}
void draw_point(int buf_n, int x, int y, int col)
{
if (!buf_n) {
*((int *)FRAMBUFF0 + y*800 + x) = col;
} else {
*((int *)FRAMBUFF1 + y*800 + x) = col;
}
}
void clr_screen(int n, int col)
{
int i,j;
for (i = 0; i < 480; i++) {
for (j = 0; j < 800; j++) {
if (!n) {
draw_point(0, j, i, col);
} else {
draw_point(1, j, i, col);
}
}
}
}