Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_uc1698.c

358 lines · 11.3 KB · C

1/*
2
3 u8x8_d_uc1698.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2016, olikraus@gmail.com
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without modification,
11 are permitted provided that the following conditions are met:
12
13 * Redistributions of source code must retain the above copyright notice, this list
14 of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above copyright notice, this
17 list of conditions and the following disclaimer in the documentation and/or other
18 materials provided with the distribution.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35
36 There are one controller:
37 UC1698u 160x160
38
39
40
41*/
42#include "u8x8.h"
43
44static const uint8_t u8x8_d_uc1698u_powersave0_seq[] = {
45 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
46 U8X8_C(0x0ad), //on/off mode /* display on, UC1698s */
47 U8X8_END_TRANSFER(), /* disable chip */
48 U8X8_END() /* end of sequence */
49};
50
51static const uint8_t u8x8_d_uc1698u_powersave1_seq[] = {
52 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
53 U8X8_C(0x0ac), //on/off mode /* display off, UC1698s */
54 U8X8_END_TRANSFER(), /* disable chip */
55 U8X8_END() /* end of sequence */
56};
57
58static const uint8_t u8x8_d_uc1698u_flip0_seq[] = {
59 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
60 U8X8_C(0x0c4), /* LCD Mapping */
61 U8X8_END_TRANSFER(), /* disable chip */
62 U8X8_END() /* end of sequence */
63};
64
65static const uint8_t u8x8_d_uc1698u_flip1_seq[] = {
66 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
67 U8X8_C(0x0c0), /* LCD Mapping */
68 U8X8_END_TRANSFER(), /* disable chip */
69 U8X8_END() /* end of sequence */
70};
71
72static const uint8_t lut_nibble[16][2] = {
73 {0x00, 0x00}, // 0b0000
74 {0x00, 0x0F}, // 0b0001
75 {0x00, 0xF0}, // 0b0010
76 {0x00, 0xFF}, // 0b0011
77 {0x0F, 0x00}, // 0b0100
78 {0x0F, 0x0F}, // 0b0101
79 {0x0F, 0xF0}, // 0b0110
80 {0x0F, 0xFF}, // 0b0111
81 {0xF0, 0x00}, // 0b1000
82 {0xF0, 0x0F}, // 0b1001
83 {0xF0, 0xF0}, // 0b1010
84 {0xF0, 0xFF}, // 0b1011
85 {0xFF, 0x00}, // 0b1100
86 {0xFF, 0x0F}, // 0b1101
87 {0xFF, 0xF0}, // 0b1110
88 {0xFF, 0xFF}, // 0b1111
89};
90
91uint8_t u8x8_d_uc1698u_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
92{
93 uint8_t x, y, c;
94 uint8_t *ptr;
95
96 uint8_t data1=0, data2=0;
97
98 switch(msg)
99 {
100 case U8X8_MSG_DISPLAY_DRAW_TILE:
101 u8x8_cad_StartTransfer(u8x8);
102
103 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
104 x = x<<3; // Fast multiplication by 8 with shift
105 x /= 3; //The X-axis is addressed using 1 RAM cell. 1 cell is 3 pixels in 4k RGB format.
106 x += u8x8->x_offset;
107
108 u8x8_cad_SendCmd(u8x8,0xF4); //start X
109 u8x8_cad_SendCmd(u8x8,x);
110
111 y = ((u8x8_tile_t *)arg_ptr)->y_pos;
112 y = y<<3;
113 u8x8_cad_SendCmd(u8x8,0xF5); //start y
114 u8x8_cad_SendCmd(u8x8,y);
115
116 u8x8_cad_SendCmd(u8x8,0xF6); //width
117 u8x8_cad_SendCmd(u8x8,x+53); // 53=159/3 The X-axis is addressed using 1 RAM cell. 1 cell is 3 pixels in 4k RGB format.
118
119 u8x8_cad_SendCmd(u8x8,0xF7); //height
120 u8x8_cad_SendCmd(u8x8,y+u8x8->display_info->tile_height); //20 tile_height
121
122 data1 = (x>>0)&0x0F;
123 data2 = (x>>4)&0x0F;
124 data2 |= 0x10;
125
126 u8x8_cad_SendCmd(u8x8,data1);
127 u8x8_cad_SendCmd(u8x8,data2);
128
129 data1=0, data2=0;
130 data1 = (y>>0)&0x0F;
131 data1 |= 0x60;
132
133 data2 = (y>>4)&0x0F;
134 data2 |= 0x70;
135
136 u8x8_cad_SendCmd(u8x8,data1);
137 u8x8_cad_SendCmd(u8x8,data2);
138
139 c = ((u8x8_tile_t *)arg_ptr)->cnt;
140 c = c<<3; // Fast multiplication by 8 with shift
141 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
142
143 do
144 {
145 for (uint16_t i=0; i<c; i++)
146 {
147 const uint8_t *low = lut_nibble[*ptr & 0x0F];
148 const uint8_t *high = lut_nibble[*ptr >> 4];
149
150 uint8_t arr_4k[4];
151 arr_4k[3] = low[1];
152 arr_4k[2] = low[0];
153 arr_4k[1] = high[1];
154 arr_4k[0] = high[0];
155
156 u8x8_cad_SendData(u8x8, 4, arr_4k);
157
158 if ((i - 19) % 20 == 0)
159 {
160 u8x8_cad_SendData(u8x8, 1, NULL);
161 }
162 ptr++;
163 }
164 arg_int--;
165 } while( arg_int > 0 );
166
167
168 u8x8_cad_EndTransfer(u8x8);
169 break;
170 /* handled in the calling procedure
171 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
172 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1611_128x64_display_info);
173 break;
174 case U8X8_MSG_DISPLAY_INIT:
175 u8x8_d_helper_display_init(u8x8);
176 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1701_dogs102_init_seq);
177 break;
178 */
179#ifdef U8X8_WITH_SET_CONTRAST
180 case U8X8_MSG_DISPLAY_SET_CONTRAST:
181 u8x8_cad_StartTransfer(u8x8);
182 u8x8_cad_SendCmd(u8x8, 0x081 );
183 u8x8_cad_SendArg(u8x8, arg_int ); /* uc1611 has range from 0 to 255 */
184 u8x8_cad_EndTransfer(u8x8);
185 break;
186#endif
187 default:
188 return 0;
189 }
190 return 1;
191}
192
193/*================================================*/
194/* https://github.com/olikraus/u8g2/issues/2164 */
195
196
197static const u8x8_display_info_t u8x8_uc1698u_cg160160_display_info =
198{
199 /* chip_enable_level = */ 0, /* use CS0 of the UC1611 */
200 /* chip_disable_level = */ 1,
201
202 /* post_chip_enable_wait_ns = */ 10, /* uc1611 datasheet, page 60, actually 0 */
203 /* pre_chip_disable_wait_ns = */ 10, /* uc1611 datasheet, page 60, actually 0 */
204 /* reset_pulse_width_ms = */ 20,
205 /* post_reset_wait_ms = */ 200, /* uc1611 datasheet, page 67 */
206 /* sda_setup_time_ns = */ 10, /* uc1611 datasheet, page 64, actually 0 */
207 /* sck_pulse_width_ns = */ 60, /* half of cycle time */
208 /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
209 /* spi_mode = */ 0, /* active high, rising edge */
210 /* i2c_bus_clock_100kHz = */ 4,
211 /* data_setup_time_ns = */ 30, /* uc1611 datasheet, page 60 */
212 /* write_pulse_width_ns = */ 80, /* uc1611 datasheet, page 60 */
213 /* tile_width = */ 20, /* width of 20*8=160 pixel */
214 /* tile_height = */ 20,
215 /* default_x_offset = */ 37,
216 /* flipmode_x_offset = */ 37,
217 /* pixel_width = */ 160,
218 /* pixel_height = */ 160
219};
220
221/*
222System Reset: E2H --> DONE
223Set Temp. Compensation: 24H --> DONE
224Set up LCD format specific parameters MX,MY,etc(double-byte command): C0H,04H --> FLIP0
225Set line rate: A3H --> DONE
226Set Pump Control (internal Vlcd): 2FH --> DONE
227Set Isolation Clock Front (3 bytes command): 82H, 13H, 01H --> DONE
228Set Isolation Clock Back (3 bytes command): 82H, 14H, 00H --> DONE
229Set LCD Bias Ratio: EAH
230LCD Specific Operation Voltage Setting (double-byte command): 81H, 90H --> DONE
231Set RAM Address Control: 80H --> DOES NOT MAKE SENSE
232Set Page Addr. MSB: 72H --> DONE
233Set Page Addr. LSB : 60H --> DONE
234Set Column Addr. LSB: 00H --> DONE
235Set Column Addr.MSB: 10H --> DONE
236Window Program Enable : F8H --> NOT REQURED
237Window Starting Column (double-byte command): F4H , 00H --> NOT REQURED
238Window Ending Column (double-byte command): F6H, 9FH --> NOT REQURED
239Set one bit for one pixel: D1H --> DONE
240Set Display Enable: A9H
241*/
242
243static const uint8_t u8x8_d_uc1698u_cg160160_init_seq[] = {
244
245 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
246 U8X8_C(0x0e2), /* system reset */
247 U8X8_DLY(10),
248
249 /*power control*/
250 U8X8_C(0x0e9), //Bias Ratio:1/10 bias
251 U8X8_C(0x02b), //power control set as internal power
252 U8X8_C(0x024), //set temperate compensation as 0%
253 U8X8_C(0x081), //electronic potentionmeter
254 U8X8_C(0x096), //start contrast level
255
256 /*display control*/
257 U8X8_C(0x0a4), //all pixel off
258 U8X8_C(0x0a6), //inverse display off
259
260 /*lcd control*/
261 U8X8_C(0x0c4), //Set LCD Maping Control (MY=1, MX=0)
262
263
264
265 U8X8_C(0x0a1), //line rate 15.2klps
266 U8X8_C(0x0d1), //rgb-rgb
267
268// U8X8_C(0x0d6), //64k color mode
269 U8X8_C(0x0d5), //4k color mode
270
271 U8X8_C(0x084), //12:partial display control disable
272
273
274 /*n-line inversion*/
275 U8X8_C(0x0c8),
276 U8X8_C(0x010), //enable NIV
277
278 /*com scan fuction*/
279 U8X8_C(0x0da), //enable FRC,PWM,LRM sequence
280
281 /*window*/
282 U8X8_C(0x0f4), //wpc0:column
283 U8X8_C(0x025), //start from 112
284 U8X8_C(0x0f6), //wpc1
285 U8X8_C(0x05A), //end:272
286
287 U8X8_C(0x0f5), //wpp0:row
288 U8X8_C(0x000), //start from 0
289 U8X8_C(0x0f7), //wpp1
290 U8X8_C(0x09F), //end 160
291
292 U8X8_C(0x0f8), //inside mode
293
294 U8X8_C(0x089), //RAM control /** Draw right then down **/
295
296
297 /*scroll line*/
298 U8X8_C(0x040), //low bit of scroll line
299 U8X8_C(0x050), //high bit of scroll line
300
301 U8X8_C(0x090), //14:FLT,FLB set
302 U8X8_C(0x000),
303
304 /*partial display*/
305 U8X8_C(0x084), //12,set partial display control:off
306 U8X8_C(0x0f1), //com end
307 U8X8_C(0x09f), //160
308 U8X8_C(0x0f2), //display start
309 U8X8_C(0x000), //0
310 U8X8_C(0x0f3), //display end
311 U8X8_C(0x0a0), //160
312
313 U8X8_C(0x0ac), //display OFF,select on/off mode.Green Enhance mode disable
314
315 U8X8_END_TRANSFER(), /* disable chip */
316 U8X8_END() /* end of sequence */
317};
318
319/* cg160160 display */
320uint8_t u8x8_d_uc1698_160x160(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
321{
322 /* call common procedure first and handle messages there */
323 if ( u8x8_d_uc1698u_common(u8x8, msg, arg_int, arg_ptr) == 0 )
324 {
325 /* msg not handled, then try here */
326 switch(msg)
327 {
328 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
329 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1698u_cg160160_display_info);
330 break;
331 case U8X8_MSG_DISPLAY_INIT:
332 u8x8_d_helper_display_init(u8x8);
333 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1698u_cg160160_init_seq);
334 break;
335 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
336 if ( arg_int == 0 )
337 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1698u_powersave0_seq);
338 else
339 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1698u_powersave1_seq);
340 break;
341 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
342 if ( arg_int == 0 )
343 {
344 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1698u_flip0_seq);
345 u8x8->x_offset = u8x8->display_info->default_x_offset;
346 }
347 else
348 {
349 u8x8_cad_SendSequence(u8x8, u8x8_d_uc1698u_flip1_seq);
350 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
351 }
352 break;
353 default:
354 return 0; /* msg unknown */
355 }
356 }
357 return 1;
358}