Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_st75161.c

428 lines · 14.2 KB · C

1/*
2
3 u8x8_d_st75161.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2024, 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 https://github.com/olikraus/u8g2/issues/2481
35
36
37 0x030 ext 00
38 0x031 ext 01
39 0x038 ext 10
40 0x039 ext 11
41
42 cad 011
43
44
45 normal mode:
46 0x00c bit format
47 U8X8_CA( 0xbc, 0x00 ), data scan dir
48 U8X8_A( 0xa6 ),
49 y: 0 offset
50
51 flip mode:
52 0x008 bit format
53 U8X8_CA( 0xbc, 0x03 ), data scan dir
54 U8X8_A( 0xa6 ),
55 y: 5 offset
56
57
58*/
59
60
61#include "u8x8.h"
62
63
64/* not a real power down for the st75256... just a display off */
65static const uint8_t u8x8_d_st75256_256x128_powersave0_seq[] = {
66 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
67 U8X8_C( 0x030 ), /* select 00 commands */
68 U8X8_C( 0x94 ), /* sleep out */
69 U8X8_DLY(10),
70 U8X8_C( 0xaf ), /* display on */
71 U8X8_END_TRANSFER(), /* disable chip */
72 U8X8_END() /* end of sequence */
73};
74
75static const uint8_t u8x8_d_st75256_256x128_powersave1_seq[] = {
76 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
77 U8X8_C( 0x030 ), /* select 00 commands */
78 U8X8_C( 0xae ), /* display off */
79 U8X8_C( 0x95 ), /* sleep in */
80 U8X8_END_TRANSFER(), /* disable chip */
81 U8X8_END() /* end of sequence */
82};
83
84/* marked as unused to avoid compiler warning, issue 1802 */
85#ifdef NOT_USED
86static const uint8_t u8x8_d_st75256_jlx256128_flip0_seq[] = {
87 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
88 U8X8_C( 0x030 ), /* select 00 commands */
89 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
90 U8X8_A( 0xa6 ), /* ??? */
91
92 //U8X8_C( 0x030 ), /* select 00 commands */
93 U8X8_C( 0x00c ), /* data format LSB top */
94 U8X8_END_TRANSFER(), /* disable chip */
95 U8X8_END() /* end of sequence */
96};
97
98static const uint8_t u8x8_d_st75256_jlx256128_flip1_seq[] = {
99 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
100 U8X8_C( 0x030 ), /* select 00 commands */
101 U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
102 U8X8_A( 0xa6 ), /* ??? */
103
104 //U8X8_C( 0x030 ), /* select 00 commands */
105 U8X8_C( 0x008 ), /* data format MSB top */
106 U8X8_END_TRANSFER(), /* disable chip */
107 U8X8_END() /* end of sequence */
108};
109#endif
110
111static const uint8_t u8x8_d_st75161_jlx160160_flip0_seq[] = {
112 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
113 U8X8_C( 0x030 ), /* select 00 commands */
114 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
115 U8X8_A( 0xa6 ), /* ??? */
116
117 //U8X8_C( 0x030 ), /* select 00 commands */
118 U8X8_C( 0x00c ), /* data format LSB top */
119 U8X8_CA( 0x0AB, 0 ), /* start line */
120 U8X8_END_TRANSFER(), /* disable chip */
121 U8X8_END() /* end of sequence */
122};
123
124static const uint8_t u8x8_d_st75161_jlx160160_flip1_seq[] = {
125 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
126 U8X8_C( 0x030 ), /* select 00 commands */
127 U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
128 U8X8_A( 0xa6 ), /* ??? */
129
130 //U8X8_C( 0x030 ), /* select 00 commands */
131 U8X8_C( 0x008 ), /* data format MSB top */
132 U8X8_CA( 0x0AB, 0 ), /* start line */
133 U8X8_END_TRANSFER(), /* disable chip */
134 U8X8_END() /* end of sequence */
135};
136
137/* marked as unused to avoid compiler warning, issue 1802 */
138#ifdef NOT_USED
139static const uint8_t u8x8_d_st75256_jlx256160_flip0_seq[] = {
140 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
141 U8X8_C( 0x030 ), /* select 00 commands */
142 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
143 U8X8_A( 0xa6 ), /* ??? */
144
145 //U8X8_C( 0x030 ), /* select 00 commands */
146 U8X8_C( 0x00c ), /* data format LSB top */
147 U8X8_END_TRANSFER(), /* disable chip */
148 U8X8_END() /* end of sequence */
149};
150
151static const uint8_t u8x8_d_st75256_jlx256160_flip1_seq[] = {
152 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
153 U8X8_C( 0x030 ), /* select 00 commands */
154 U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
155 U8X8_A( 0xa6 ), /* ??? */
156
157 //U8X8_C( 0x030 ), /* select 00 commands */
158 U8X8_C( 0x008 ), /* data format MSB top */
159 U8X8_END_TRANSFER(), /* disable chip */
160 U8X8_END() /* end of sequence */
161};
162#endif
163
164
165/*=============================================*/
166/* jlx160160 https://github.com/olikraus/u8g2/issues/1642 */
167
168static const u8x8_display_info_t u8x8_st75161_jlx160160_display_info =
169{
170 /* chip_enable_level = */ 0,
171 /* chip_disable_level = */ 1,
172
173 /* post_chip_enable_wait_ns = */ 20,
174 /* pre_chip_disable_wait_ns = */ 20,
175 /* reset_pulse_width_ms = */ 5,
176 /* post_reset_wait_ms = */ 5, /**/
177 /* sda_setup_time_ns = */ 20, /* */
178 /* sck_pulse_width_ns = */ 40, /* */
179 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
180 /* spi_mode = */ 0, /* active high, rising edge */
181 /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
182 /* data_setup_time_ns = */ 15,
183 /* write_pulse_width_ns = */ 70,
184 /* tile_width = */ 20,
185 /* tile_height = */ 20,
186 /* default_x_offset = */ 0, /* y (!) offset in flipmode 0 */
187 /* flipmode_x_offset = */ 1, /* y (!) offset in flipmode 0 */
188 /* pixel_width = */ 160,
189 /* pixel_height = */ 160
190};
191
192
193/*
194from the JLX160160 datasheet:
195
196transfer_command_lcd(0x30);//EXT=0
197transfer_command_lcd(0x94);//Sleep out
198transfer_command_lcd(0x31);//EXT=1
199transfer_command_lcd(0xD7);//Autoread disable
200transfer_data_lcd(0X9F);//
201transfer_command_lcd(0x32);//Analog SET
202transfer_data_lcd(0x00);//OSC Frequency adjustment
203transfer_data_lcd(0x01);//Frequency on booster capacitors->6KHz
204transfer_data_lcd(0x00);//Bias=1/14
205transfer_command_lcd(0x20);// Gray Level
206transfer_data_lcd(0x01);
207transfer_data_lcd(0x03);
208transfer_data_lcd(0x05);
209transfer_data_lcd(0x07);
210transfer_data_lcd(0x09);
211transfer_data_lcd(0x0b);
212transfer_data_lcd(0x0d);
213transfer_data_lcd(0x10);
214transfer_data_lcd(0x11);
215transfer_data_lcd(0x13);
216transfer_data_lcd(0x15);
217transfer_data_lcd(0x17);
218transfer_data_lcd(0x19);
219transfer_data_lcd(0x1b);
220transfer_data_lcd(0x1d);
221transfer_data_lcd(0x1f);
222transfer_command_lcd(0x31);//EXT=1
223transfer_command_lcd(0xf0);//Without this instruction, the voltage will be increased slowly. 0.5s
224transfer_data_lcd(0x0f);
225transfer_data_lcd(0x0f);
226transfer_data_lcd(0x0f);
227transfer_data_lcd(0x0f);
228transfer_command_lcd(0x30);//EXT=0
229transfer_command_lcd(0x75);//Page Address setting
230transfer_data_lcd(0X00);// XS=0
231transfer_data_lcd(0X28);// XE=159 0x28
232transfer_command_lcd(0x15);//Clumn Address setting
233transfer_data_lcd(0X00);// XS=0
234transfer_data_lcd(0Xff);// XE=256
235transfer_command_lcd(0xBC);//Data scan direction
236transfer_data_lcd(0x00);//MX.MY=Normal
237transfer_ command_lcd (0xA6);
238transfer_command_lcd(0xCA);//Display Control
239transfer_data_lcd(0X00);//
240transfer_data_lcd(0X9F);//Duty=160
241transfer_data_lcd(0X20);//Nline=off
242transfer_command_lcd(0xF0);//Display Mode
243transfer_data_lcd(0X10);//10=Monochrome Mode,11=4Gray
244transfer_command_lcd(0x81);//EV control
245transfer_data_lcd(0x1d);//Fine-tune the contrast value, 0x00~0x3f
246transfer_data_lcd(0x04);//Coarse contrast adjustment 0x00~0x07
247transfer_command_lcd(0x20);//Power control
248transfer_data_lcd(0x0B);//D0=regulator ; D1=follower ; D3=booste,
249on:1 off:0
250delay(20);
251transfer_command_lcd(0xAF); //Display on
252
253*/
254
255static const uint8_t u8x8_d_st75161_jlx160160_init_seq[] = {
256 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
257
258 U8X8_DLY(20),
259
260/*
261U8X8_C( 0x030 ), // Extension Command 1
262U8X8_C( 0x06E ),
263
264U8X8_C( 0x031 ), // Extension Command 2
265U8X8_CA( 0x0d7, 0x09f), // Set auto-read instruction, Disable Auto Read
266
267U8X8_CA( 0x0e0 ,0x000), // Enable OTP Read
268U8X8_DLY(10),
269
270U8X8_C( 0x0e3 ), // OTP Read
271U8X8_DLY(20),
272U8X8_C(0xe1), // OTP Control Out
273*/
274
275
276
277
278 U8X8_C( 0x030 ), /* select 00 commands */
279 U8X8_C( 0x094 ), /* sleep out */
280
281 //U8X8_C( 0x030 ), /* select 00 commands */
282 U8X8_C( 0x0ae ), /* display off */
283
284 U8X8_C( 0x031 ), /* select 01 commands */
285 U8X8_CA( 0x0d7, 0x09f ), /* disable auto read */
286
287 //U8X8_C( 0x031 ), /* select 01 commands */
288 U8X8_C( 0x032 ), /* analog circuit set */
289 U8X8_A( 0x000 ), /* code example: OSC Frequency adjustment */
290 U8X8_A( 0x001 ), /* Frequency on booster capacitors 1 = 6KHz? */
291 U8X8_A( 0x000 ), /* Bias: 0: 1/14, 1: 1/13, 2: 1/12, 3: 1/11, 4:1/10, 5:1/9 */
292
293 U8X8_C( 0x031 ), /* select 01 commands */
294 U8X8_C( 0x020 ), /* gray levels */
295 U8X8_A( 0x01 ),
296 U8X8_A( 0x03 ),
297 U8X8_A( 0x05 ),
298 U8X8_A( 0x07 ),
299 U8X8_A( 0x09),
300 U8X8_A( 0x0b ),
301 U8X8_A( 0x0d ),
302 U8X8_A( 0x10 ),
303 U8X8_A( 0x11 ),
304 U8X8_A( 0x13 ),
305 U8X8_A( 0x15 ),
306 U8X8_A( 0x17 ),
307 U8X8_A( 0x19 ),
308 U8X8_A( 0x1b ),
309 U8X8_A( 0x1d ),
310 U8X8_A( 0x1f ),
311
312
313 U8X8_C( 0x031 ), /* select 01 commands */
314 U8X8_CA(0x51, 0xfb), // Booster Level x10
315 U8X8_CAAAA(0xf0, 15, 15, 15, 15), /* Frame Rate Temparature Range */
316
317
318 U8X8_C( 0x030 ), /* select 00 commands */
319 U8X8_CAA(0x75, 0, 0x28), /* row range 0..159*/
320 U8X8_CAA(0x15, 0, 255), /* col range */
321
322 //U8X8_C( 0x030 ), /* select 00 commands */
323 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
324 U8X8_A( 0xa6 ), /* ??? */
325
326 //U8X8_C( 0x030 ), /* select 00 commands */
327 U8X8_C( 0x00c ), /* data format LSB top */
328
329 //U8X8_C( 0x030 ), /* select 00 commands */
330 U8X8_C( 0xca ), /* display control, 3 args follow */
331 U8X8_A( 0x00 ), /* 0x00: no clock division, 0x04: devide clock */
332 U8X8_A( 0x9f ), /* 1/160 duty */
333 U8X8_A( 0x20 ), /* nline off */
334
335 //U8X8_C( 0x030 ), /* select 00 commands */
336 U8X8_CA( 0x0f0, 0x010 ), /* monochrome mode = 0x010, graylevel = 0x011*/
337
338 //U8X8_C( 0x030 ), /* select 00 commands */
339 U8X8_CAA( 0x81, 0x1d, 0x04 ), /* Volume control */
340
341 //U8X8_C( 0x030 ), /* select 00 commands */
342 U8X8_CA( 0x020, 0x00b ), /* Power control: Regulator, follower & booster on */
343 U8X8_DLY(100),
344
345 //U8X8_C( 0xaf ),
346 U8X8_END_TRANSFER(), /* disable chip */
347 U8X8_END() /* end of sequence */
348};
349
350
351uint8_t u8x8_d_st75161_jlx160160(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
352{
353 uint8_t x, c;
354 uint8_t *ptr;
355
356 switch(msg)
357 {
358 case U8X8_MSG_DISPLAY_DRAW_TILE:
359
360 u8x8_cad_StartTransfer(u8x8);
361 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
362 x *= 8;
363
364 u8x8_cad_SendCmd(u8x8, 0x030 ); /* select command set */
365 u8x8_cad_SendCmd(u8x8, 0x075 ); /* row */
366 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos+u8x8->x_offset)); // x offset is reused as y offset
367
368 u8x8_cad_SendArg(u8x8, 0x027);
369 u8x8_cad_SendCmd(u8x8, 0x015 ); /* col */
370 u8x8_cad_SendArg(u8x8, x);
371 u8x8_cad_SendArg(u8x8, 0x9f);
372 u8x8_cad_SendCmd(u8x8, 0x05c );
373
374 do
375 {
376 c = ((u8x8_tile_t *)arg_ptr)->cnt;
377 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
378 c *= 8;
379 u8x8_cad_SendData(u8x8, c, ptr);
380 arg_int--;
381 } while( arg_int > 0 );
382
383 u8x8_cad_EndTransfer(u8x8);
384 return 1;
385 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
386 //u8x8_SetI2CAddress(u8x8, 0x078); /* lowest I2C adr of the ST75161 */
387 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75161_jlx160160_display_info);
388 return 1;
389 case U8X8_MSG_DISPLAY_INIT:
390 u8x8_d_helper_display_init(u8x8);
391 u8x8_cad_SendSequence(u8x8, u8x8_d_st75161_jlx160160_init_seq);
392 return 1;
393 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
394 if ( arg_int == 0 )
395 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave0_seq);
396 else
397 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave1_seq);
398
399 return 1;
400 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
401 if ( arg_int == 0 )
402 {
403 u8x8_cad_SendSequence(u8x8, u8x8_d_st75161_jlx160160_flip0_seq);
404 u8x8->x_offset = u8x8->display_info->default_x_offset;
405 }
406 else
407 {
408 u8x8_cad_SendSequence(u8x8, u8x8_d_st75161_jlx160160_flip1_seq);
409 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
410 }
411 return 1;
412
413#ifdef U8X8_WITH_SET_CONTRAST
414 case U8X8_MSG_DISPLAY_SET_CONTRAST:
415 u8x8_cad_StartTransfer(u8x8);
416
417 u8x8_cad_SendCmd(u8x8, 0x030 );
418 u8x8_cad_SendCmd(u8x8, 0x081 ); /* there are 9 bit for the volume control */
419 u8x8_cad_SendArg(u8x8, (arg_int & 0x1f)<<1 ); /* lower 6 bit */
420 u8x8_cad_SendArg(u8x8, (arg_int>>5)); /* upper 3 bit */
421
422 u8x8_cad_EndTransfer(u8x8);
423 return 1;
424#endif
425 }
426 return 0;
427}
428