问题描述
图形界面采用LVGL,显示驱动采用的是ST7789V+8080并口协议8位。
驱动部分都能正常显示LVGL的图形,但是颜色反转了。
例如:红色显示成蓝色
白色显示成黑色。
问题定位
开始怀疑是LVGL的反色显示打开了。
于是找到lvgl的配置文件lv_conf.h
1
2
3
|
#define LV_COLOR_16_SWAP 0
|
配置是关闭状态,显然,不关LVGL反色设置的问题。
在LVGL的显示驱动lv_port_disp.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
|
static void disp_flush_cb(lv_disp_drv_t *disp, const lv_area_t *area,
lv_color_t *color_p) {
disp_drv_p = disp;
const lv_coord_t w = (area->x2 - area->x1 + 1);
const lv_coord_t h = (area->y2 - area->y1 + 1);
const uint32_t len = w * h;
HAL::Display_SetAddrWindow(area->x1, area->y1, area->x2, area->y2);
//HAL::Display_SendPixels((uint16_t*)color_p, len);
HAL::Display_SendPixelsByCoordinate((uint16_t*) color_p, len);
//通知LVGL准备刷新
lv_disp_flush_ready(disp);
}
|
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
|
void HAL::Display_SendPixelsByCoordinate(const uint16_t* pixels, uint32_t len) {
while(len--){
screen.pushColor(*(pixels++));
}
if(Disp_Callback)
{
Disp_Callback();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
void Adafruit_ST7789_8080_8bit::pushColor(uint16_t color) {
writeData(color >> 8);
writeData(color);
}
|
怀疑是pushColor这个函数数据写入顺序问题。通过调整代码,调转了方向后,还是不行。
最后没办法。直接开驱动底层。
知道是反色相关的代码,所以找到ST7789的协议说明,搜索反色指令。
开始找了一通,并没有找到反色相关的指令。
按我的经验理解,默认应该是正常色。后来实在没办法。
就在初始化最后加上了反色关闭的指令,在没有报希望的情况下刷进板子试试。
反色关闭指令:writeCommand(0x20); (如果你的不行,可以试试writeCommand(0x21);打开反色)
结果立马显示正常了。
这个刷新我的认知,竟然默认是反色的,很是坑。
附赠ST7789指令说明
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/*=========================ST7789V协议定义===========================*/
#define ST7789V_CMD_NOP (0x00) /* Empty command */
#define ST7789V_CMD_SWRESET (0x01) /* Software Reset */
#define ST7789V_CMD_RDDID (0x04) /* Read Display ID */
#define ST7789V_CMD_RDDST (0x09) /* Read Display Status */
#define ST7789V_CMD_RDDPM (0x0A) /* Read Display Power Mode */
#define ST7789V_CMD_RDDMADCTL (0x0B) /* Read Display MADCTL */
#define ST7789V_CMD_RDDCOLMOD (0x0C) /* Read Display Pixel Format */
#define ST7789V_CMD_RDDIM (0x0D) /* Read Display Image Mode */
#define ST7789V_CMD_RDDSM (0x0E) /* Read Display Signal Mode */
#define ST7789V_CMD_RDDSDR (0x0F) /* Read Display Self-Diagnostic Result */
#define ST7789V_CMD_SLPIN (0x10) /* Sleep in */
#define ST7789V_CMD_SLPOUT (0x11) /* Sleep Out */
#define ST7789V_CMD_PTLON (0x12) /* Partial Display Mode On */
#define ST7789V_CMD_NORON (0x13) /* Normal Display Mode On */
#define ST7789V_CMD_INVOFF (0x20) /* Display Inversion Off */
#define ST7789V_CMD_INVON (0x21) /* Display Inversion On */
#define ST7789V_CMD_GAMSET (0x26) /* Gamma Set */
#define ST7789V_CMD_DISPOFF (0x28) /* Display Off */
#define ST7789V_CMD_DISPON (0x29) /* Display On */
#define ST7789V_CMD_CASET (0x2A) /* Column Address Set */
#define ST7789V_CMD_RASET (0x2B) /* Row Address Set */
#define ST7789V_CMD_RAMWR (0x2C) /* Memory Write */
#define ST7789V_CMD_RAMRD (0x2E) /* Memory Read */
#define ST7789V_CMD_PTLAR (0x30) /* Partial Area */
#define ST7789V_CMD_VSCRDEF (0x33) /* Vertical Scrolling Definition */
#define ST7789V_CMD_TEOFF (0x34) /* Tearing Effect Line OFF */
#define ST7789V_CMD_TEON (0x35) /* Tearing Effect Line On */
#define ST7789V_CMD_MADCTL (0x36) /* Memory Data Access Control */
#define ST7789V_CMD_VSCSAD (0x37) /* Vertical Scroll Start Address of RAM */
#define ST7789V_CMD_IDMOFF (0x38) /* Idle Mode Off */
#define ST7789V_CMD_IDMON (0x39) /* Idle mode on */
#define ST7789V_CMD_COLMOD (0x3A) /* Interface Pixel Format */
#define ST7789V_CMD_WRMEMC (0x3C) /* Write Memory Continue */
#define ST7789V_CMD_RDMEMC (0x3E) /* Read Memory Continue */
#define ST7789V_CMD_STE (0x44) /* Set Tear Scanline */
#define ST7789V_CMD_GSCAN (0x45) /* Get Scanline */
#define ST7789V_CMD_WRDISBV (0x51) /* Write Display Brightness */
#define ST7789V_CMD_RDDISBV (0x52) /* Read Display Brightness Value */
#define ST7789V_CMD_WRCTRLD (0x53) /* Write CTRL Display */
#define ST7789V_CMD_RDCTRLD (0x54) /* Read CTRL Value Display */
#define ST7789V_CMD_WRCACE (0x55) /* Wr. Content Adaptive Brightness Control & Color Enhance */
#define ST7789V_CMD_RDCABC (0x56) /* Read Content Adaptive Brightness Control */
#define ST7789V_CMD_WRCABCMB (0x5E) /* Write CABC Minimum Brightness */
#define ST7789V_CMD_RDCABCMB (0x5F) /* Read CABC Minimum Brightness */
#define ST7789V_CMD_RDABCSDR (0x68) /* Read Automatic Brightness Control Self-Diagnostic Result */
#define ST7789V_CMD_RDID1 (0xDA) /* Read ID1 */
#define ST7789V_CMD_RDID2 (0xDB) /* Read ID2 */
#define ST7789V_CMD_RDID3 (0xDC) /* Read ID3 */
#define ST7789V_CMD_RAMCTRL (0xB0) /* RAM Control */
#define ST7789V_CMD_RGBCTRL (0xB1) /* RGB Interface Control */
#define ST7789V_CMD_PORCTRL (0xB2) /* Porch Setting */
#define ST7789V_CMD_FRCTRL1 (0xB3) /* Frame Rate Control 1 (In partial mode/ idle colors) */
#define ST7789V_CMD_PARCTRL (0xB5) /* Partial mode Control */
#define ST7789V_CMD_GCTRL (0xB7) /* Gate Control */
#define ST7789V_CMD_GTADJ (0xB8) /* Gate On Timing Adjustment */
#define ST7789V_CMD_DGMEN (0xBA) /* Digital Gamma Enable */
#define ST7789V_CMD_VCOMS (0xBB) /* VCOMS Setting */
#define ST7789V_CMD_LCMCTRL (0xC0) /* LCM Control */
#define ST7789V_CMD_IDSET (0xC1) /* ID Code Setting */
#define ST7789V_CMD_VDVVRHEN (0xC2) /* VDV and VRH Command Enable */
#define ST7789V_CMD_VRHS (0xC3) /* VRH Set */
#define ST7789V_CMD_VDVS (0xC4) /* VDV Set */
#define ST7789V_CMD_VCMOFSET (0xC5) /* VCOMS Offset Set */
#define ST7789V_CMD_FRCTRL2 (0xC6) /* Frame Rate Control in Normal Mode */
#define ST7789V_CMD_CABCCTRL (0xC7) /* CABC Control */
#define ST7789V_CMD_REGSEL1 (0xC8) /* Register Value Selection 1 */
#define ST7789V_CMD_REGSEL2 (0xCA) /* Register Value Selection 2 */
#define ST7789V_CMD_PWMFRSEL (0xCC) /* PWM Frequency Selection */
#define ST7789V_CMD_PWCTRL1 (0xD0) /* Power Control 1 */
#define ST7789V_CMD_VAPVANEN (0xD2) /* Enable VAP/VAN signal output */
#define ST7789V_CMD_CMD2EN (0xDF) /* Command 2 Enable */
#define ST7789V_CMD_PVGAMCTRL (0xE0) /* Positive Voltage Gamma Control */
#define ST7789V_CMD_NVGAMCTRL (0xE1) /* Negative Voltage Gamma Control */
#define ST7789V_CMD_DGMLUTR (0xE2) /* Digital Gamma Look-up Table for Red */
#define ST7789V_CMD_DGMLUTB (0xE3) /* Digital Gamma Look-up Table for Blue */
#define ST7789V_CMD_GATECTRL (0xE4) /* Gate Control */
#define ST7789V_CMD_SPI2EN (0xE7) /* SPI2 Enable */
#define ST7789V_CMD_PWCTRL2 (0xE8) /* Power Control 2 */
#define ST7789V_CMD_EQCTRL (0xE9) /* Equalize time control */
#define ST7789V_CMD_PROMCTRL (0xEC) /* Program Mode Control */
#define ST7789V_CMD_PROMEN (0xFA) /* Program Mode Enable */
#define ST7789V_CMD_NVMSET (0xFC) /* NVM Setting */
#define ST7789V_CMD_PROMACT (0xFE) /* Program action */
|