-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathili934x_ilmatto._c
174 lines (164 loc) · 4.92 KB
/
ili934x_ilmatto._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
/* -*- mode: c-mode; -*- */
/*
* ili9340.h
*
*
* Created by Steve Gunn on 27/08/2012.
* Copyright 2012 University of Southampton. All rights reserved.
*
*/
/* Basic Commands */
#define NO_OPERATION 0x00
#define SOFTWARE_RESET 0x01
#define READ_DISPLAY_IDENTIFICATION_INFORMATION 0x04
#define READ_DISPLAY_STATUS 0x09
#define READ_DISPLAY_POWER_MODE 0x0A
#define READ_DISPLAY_MADCTL 0x0B
#define READ_DISPLAY_PIXEL_FORMAT 0x0C
#define READ_DISPLAY_IMAGE_FORMAT 0x0D
#define READ_DISPLAY_SIGNAL_MODE 0x0E
#define READ_DISPLAY_SELF_DIAGNOSTIC_RESULT 0x0F
#define ENTER_SLEEP_MODE 0x10
#define SLEEP_OUT 0x11
#define PARTIAL_MODE_ON 0x12
#define NORMAL_DISPLAY_MODE_ON 0x13
#define DISPLAY_INVERSION_OFF 0x20
#define DISPLAY_INVERSION_ON 0x21
#define GAMMA_SET 0x26
#define DISPLAY_OFF 0x28
#define DISPLAY_ON 0x29
#define COLUMN_ADDRESS_SET 0x2A
#define PAGE_ADDRESS_SET 0x2B
#define MEMORY_WRITE 0x2C
#define COLOR_SET 0x2D
#define MEMORY_READ 0x2E
#define PARTIAL_AREA 0x30
#define VERTICAL_SCROLLING_DEFINITION 0x33
#define TEARING_EFFECT_LINE_OFF 0x34
#define TEARING_EFFECT_LINE_ON 0x35
#define MEMORY_ACCESS_CONTROL 0x36
#define VERTICAL_SCROLLING_START_ADDRESS 0x37
#define IDLE_MODE_OFF 0x38
#define IDLE_MODE_ON 0x39
#define PIXEL_FORMAT_SET 0x3A
#define WRITE_MEMORY_CONTINUE 0x3C
#define READ_MEMORY_CONTINUE 0x3E
#define SET_TEAR_SCANLINE 0x44
#define GET_SCANLINE 0x45
#define WRITE_DISPLAY_BRIGHTNESS 0x51
#define READ_DISPLAY_BRIGHTNESS 0x52
#define WRITE_CTRL_DISPLAY 0x53
#define READ_CTRL_DISPLAY 0x54
#define WRITE_CONTENT_ADAPTIVE_BRIGHTNESS_CONTROL 0x55
#define READ_CONTENT_ADAPTIVE_BRIGHTNESS_CONTROL 0x56
#define WRITE_CABC_MINIMUM_BRIGHTNESS 0x5E
#define READ_CABC_MINIMUM_BRIGHTNESS 0x5F
#define READ_ID1 0xDA
#define READ_ID2 0xDB
#define READ_ID3 0xDC
/* Extended Commands */
#define RGB_INTERFACE_SIGNAL_CONTROL 0xB0
#define FRAME_CONTROL_IN_NORMAL_MODE 0xB1
#define FRAME_CONTROL_IN_IDLE_MODE 0xB2
#define FRAME_CONTROL_IN_PARTIAL_MODE 0xB3
#define DISPLAY_INVERSION_CONTROL 0xB4
#define BLANKING_PORCH_CONTROL 0xB5
#define DISPLAY_FUNCTION_CONTROL 0xB6
#define ENTRY_MODE_SET 0xB7
#define BACKLIGHT_CONTROL_1 0xB8
#define BACKLIGHT_CONTROL_2 0xB9
#define BACKLIGHT_CONTROL_3 0xBA
#define BACKLIGHT_CONTROL_4 0xBB
#define BACKLIGHT_CONTROL_5 0xBC
#define BACKLIGHT_CONTROL_7 0xBE
#define BACKLIGHT_CONTROL_8 0xBF
#define POWER_CONTROL_1 0xC0
#define POWER_CONTROL_2 0xC1
#define POWER_CONTROL3_(FOR_NORMAL_MODE) 0xC2
#define POWER_CONTROL4_(FOR_IDLE_MODE) 0xC3
#define POWER_CONTROL5_(FOR_PARTIAL_MODE) 0xC4
#define VCOM_CONTROL_1 0xC5
#define VCOM_CONTROL_2 0xC7
#define NV_MEMORY_WRITE 0xD0
#define NV_MEMORY_PROTECTION_KEY 0xD1
#define NV_MEMORY_STATUS_READ 0xD2
#define READ_ID4 0xD3
#define POSITIVE_GAMMA_CORRECTION 0xE0
#define NEGATIVE_GAMMA_CORRECTION 0xE1
#define DIGITAL_GAMMA_CONTROL 0xE2
#define DIGITAL_GAMMA_CONTROL2 0xE3
#define INTERFACE_CONTROL 0xF6
/* Undocumented commands */
#define INTERNAL_IC_SETTING 0xCB
#define GAMMA_DISABLE 0xF2
__inline__ void write_cmd(uint8_t cmd)
{
RS_lo();
WRITE(cmd);
WR_lo();
WR_hi();
RS_hi();
}
__inline__ void write_data(uint8_t data)
{
WRITE(data);
WR_lo();
WR_hi();
}
__inline__ void write_data16(uint16_t data)
{
write_data(data >> 8);
write_data(data & 0xFF);
}
__inline__ void write_cmd_data(uint8_t cmd, uint8_t ndata, char* data)
{
uint8_t i;
write_cmd(cmd);
for(i=0; i<ndata; i++)
write_data(*data++);
}
void initialise()
{
uint16_t x, y;
init_ports();
RESET_lo();
delay_ms(100);
RESET_hi();
delay_ms(100);
RS_hi();
WR_hi();
RD_hi();
CS_lo();
BLC_lo();
VSYNC_hi();
write_cmd(DISPLAY_OFF);
write_cmd(SLEEP_OUT);
delay_ms(60);
write_cmd_data(INTERNAL_IC_SETTING, 1, "\x01");
write_cmd_data(POWER_CONTROL_1, 2, "\x26\x08");
write_cmd_data(POWER_CONTROL_2, 1, "\x10");
write_cmd_data(VCOM_CONTROL_1, 2, "\x35\x3E");
write_cmd_data(MEMORY_ACCESS_CONTROL, 1, "\x48");
write_cmd_data(RGB_INTERFACE_SIGNAL_CONTROL, 1, "\x4A"); // Set the DE/Hsync/Vsync/Dotclk polarity
write_cmd_data(FRAME_CONTROL_IN_NORMAL_MODE, 2, "\x00\x1B"); // 70Hz
write_cmd_data(DISPLAY_FUNCTION_CONTROL, 4, "\x0A\x82\x27\x00");
write_cmd_data(VCOM_CONTROL_2, 1, "\xB5");
write_cmd_data(INTERFACE_CONTROL, 3, "\x01\x00\x00"); // System interface
write_cmd_data(GAMMA_DISABLE, 1, "\x00");
write_cmd_data(GAMMA_SET, 1, "\x01"); // Select Gamma curve 1
write_cmd_data(PIXEL_FORMAT_SET, 1, "\x55"); // 0x66 - 18bit /pixel, 0x55 - 16bit/pixel
write_cmd_data(POSITIVE_GAMMA_CORRECTION, 15, "\x1F\x1A\x18\x0A\x0F\x06\x45\x87\x32\x0A\x07\x02\x07\x05\x00");
write_cmd_data(NEGATIVE_GAMMA_CORRECTION, 15, "\x00\x25\x27\x05\x10\x09\x3A\x78\x4D\x05\x18\x0D\x38\x3A\x1F");
write_cmd_data(COLUMN_ADDRESS_SET, 4, "\x00\x00\x00\xEF");
write_cmd_data(PAGE_ADDRESS_SET, 4, "\x00\x00\x01\x3F");
write_cmd(TEARING_EFFECT_LINE_OFF);
write_cmd_data(DISPLAY_INVERSION_CONTROL, 1, "\x00");
write_cmd_data(ENTRY_MODE_SET, 1, "\x07");
write_cmd(MEMORY_WRITE);
for(x=0; x<240; x++)
for(y=0; y<320; y++)
write_data16(0x0000);
write_cmd(DISPLAY_ON);
delay_ms(50);
BLC_hi();
};