-
Notifications
You must be signed in to change notification settings - Fork 8
/
FT800.c
196 lines (167 loc) · 4.71 KB
/
FT800.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "xc.h"
#include "FT800.h"
#include <string.h>
unsigned short dli;
unsigned short cmd_offset = 0;
void host_command(ft_uint8_t command){
FT800_StartTransmission();
tr8(command);
tr8(0);
tr8(0);
FT800_StopTransmission();
}
void wr8(unsigned short long addr, ft_uint8_t value){
FT800_StartTransmission();
tr8(0x80 | (addr >> 16));
tr8(addr >> 8);
tr8(addr);
tr8(value);
FT800_StopTransmission();
}
void wr16(unsigned short long addr, ft_uint16_t value){
FT800_StartTransmission();
tr8(0x80 | (addr >> 16));
tr8(addr >> 8);
tr8(addr);
tr16(value);
FT800_StopTransmission();
}
void wr32(unsigned short long addr, ft_uint32_t value){
FT800_StartTransmission();
tr8(0x80 | (addr >> 16));
tr8(addr >> 8);
tr8(addr);
tr32(value);
FT800_StopTransmission();
}
ft_uint8_t wr8s(unsigned short long addr, const ft_char8_t *s)
{
FT800_StartTransmission();
tr8(0x80 | (addr >> 16));
tr8(addr >> 8);
tr8(addr);
ft_uint8_t l = strlen(s);
ft_uint8_t i;
for(i=0;i<=l;i++){
tr8(s[i]);
}
for(;i%4>0;i++){
tr8(0);
}
FT800_StopTransmission();
return i;
}
ft_uint8_t rd8(unsigned short long addr){
FT800_StartTransmission();
tr8(addr >> 16);
tr8(addr >> 8);
tr8(addr);
tr8(0); // dummy byte
tr8(0);
FT800_StopTransmission();
return SSPBUF;
}
ft_uint16_t rd16(unsigned short long addr){
FT800_StartTransmission();
tr8(addr >> 16);
tr8(addr >> 8);
tr8(addr);
tr8(0); // dummy byte
tr8(0);
ft_uint8_t temp = SSPBUF;
tr8(0);
FT800_StopTransmission();
return ((ft_uint16_t)SSPBUF << 8) | temp;
}
ft_uint32_t rd32(unsigned short long addr){
FT800_StartTransmission();
tr8(addr >> 16);
tr8(addr >> 8);
tr8(addr);
tr8(0); // dummy byte
tr8(0);
ft_uint32_t temp = SSPBUF;
tr8(0);
temp |= (ft_uint32_t)SSPBUF << 8;
tr8(0);
temp |= (ft_uint32_t)SSPBUF << 16;
tr8(0);
FT800_StopTransmission();
return ((ft_uint32_t)SSPBUF << 24) | temp;
}
/*
ft_char8_t * rd8s(unsigned short long addr, ft_uint8_t len)
{
FT800_StartTransmission();
tr8(addr >> 16);
tr8(addr >> 8);
tr8(addr);
tr8(0); // dummy byte
ft_char8_t *s = (ft_char8_t*) malloc (len+1);
ft_uint8_t i;
for(i=0;i<=len;i++){
tr8(0);
s[i] = SSPBUF;
}
s[len]=0;
FT800_StopTransmission();
return s;
}
*/
void cmd_incrementn(unsigned char n){
cmd_offset=(cmd_offset+n)%4096;
}
void cmd(ft_uint32_t command){
wr32(RAM_CMD + cmd_offset, command);cmd_increment4();
}
#define ACTIVE 0x00
#define STANDBY 0x41
#define SLEEP 0x42
#define PWRDOWN 0x50
#define CLKEXT 0x44
#define CLK48M 0x62
#define CLK36M 0x61
#define CORERST 0x68
inline void FT800_Init(){
PIN_PD = 0;
__delay_ms(20);
PIN_PD = 1;
__delay_ms(20);
host_command(ACTIVE); //send host command "ACTIVE" to FT800
host_command(CLKEXT); //send command to "CLKEXT" to FT800
host_command(CLK48M); //send command to "CLKEXT" to FT800
// Configure display registers - demonstration for WQVGA resolution
wr16(REG_HSIZE, 480); // width resolution
wr16(REG_VSIZE, 272); // height resolution
wr16(REG_HCYCLE, 525); // number if horizontal cycles for display
wr16(REG_HSYNC0, 0); // hsync falls
wr16(REG_HSYNC1, 41); // hsync rise
wr16(REG_HOFFSET, 43); // horizontal offset from starting signal
wr16(REG_VCYCLE, 286); // number of vertical cycles for display
wr16(REG_VSYNC0, 0); // vsync falls
wr16(REG_VSYNC1, 10); // vsync rise
wr16(REG_VOFFSET, 12); // vertical offset from start signal
wr8(REG_CSPREAD, 0); // output clock spread enable
wr8(REG_DITHER, 0); // output number of bits
wr16(REG_OUTBITS, 0x01B6); // output bits resolution
wr8(REG_SWIZZLE, 0x0000); // output swizzle
//wr8(REG_RENDERMODE, 0); // 0 normal, 1 write, 2 read
wr8(REG_PCLK_POL, 1); // clock polarity: 0 - rising edge, 1 - falling edge
//wr32(REG_FREQUENCY, 48000000); // main clock frequency
wr8(REG_ROTATE, 0); // rotate display 180 degrees: 1 - rotate enable, 0 - rotate disable
/*TRISAbits.TRISA4 = 0;
while((rd8(REG_DLSWAP) & 0b11) != DLSWAP_DONE){LATAbits.LATA4 = 1;}
LATAbits.LATA4 = 0;*/
// write first display list
wr32(RAM_DL+0,CLEAR_COLOR_RGB(255,0,0));
wr32(RAM_DL+4,CLEAR(1,1,1));
wr32(RAM_DL+8,DISPLAY());
wr8(REG_DLSWAP,DLSWAP_FRAME);//display list swap
//wr8(REG_GPIO_DIR,0x80 | rd8(REG_GPIO_DIR));
//wr8(REG_GPIO,0x080 | rd8(REG_GPIO));//enable display bit
//wr8(REG_GPIO,0x80);
wr8(REG_GPIO_DIR, 0xfc);
wr8(REG_GPIO, 0xff);
wr8(REG_PCLK,5); // clock prescaler (0: disable, >0: 48MHz/pclock)
cmd_wait();
}