Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_st75160.c

362 lines · 12.0 KB · C

1/*
2
3 u8x8_d_st75160.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2021, 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 REQUESTED IN
35 https://github.com/olikraus/u8g2/issues/1642
36
37 STATUS 13 Aug 2022: NOT TESTED, MAY NOT WORK..
38
39
40 0x030 ext 00
41 0x031 ext 01
42 0x038 ext 10
43 0x039 ext 11
44
45 cad 011
46
47
48 code examples:
49 http://www.it610.com/article/2601023.htm
50
51 normal mode:
52 0x00c bit format
53 U8X8_CA( 0xbc, 0x00 ), data scan dir
54 U8X8_A( 0xa6 ),
55 y: 0 offset
56
57 flip mode:
58 0x008 bit format
59 U8X8_CA( 0xbc, 0x03 ), data scan dir
60 U8X8_A( 0xa6 ),
61 y: 5 offset
62
63
64*/
65
66
67#include "u8x8.h"
68
69
70/* not a real power down for the st75256... just a display off */
71static const uint8_t u8x8_d_st75256_256x128_powersave0_seq[] = {
72 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
73 U8X8_C( 0x030 ), /* select 00 commands */
74 U8X8_C( 0x94 ), /* sleep out */
75 U8X8_DLY(10),
76 U8X8_C( 0xaf ), /* display on */
77 U8X8_END_TRANSFER(), /* disable chip */
78 U8X8_END() /* end of sequence */
79};
80
81static const uint8_t u8x8_d_st75256_256x128_powersave1_seq[] = {
82 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
83 U8X8_C( 0x030 ), /* select 00 commands */
84 U8X8_C( 0xae ), /* display off */
85 U8X8_C( 0x95 ), /* sleep in */
86 U8X8_END_TRANSFER(), /* disable chip */
87 U8X8_END() /* end of sequence */
88};
89
90/* marked as unused to avoid compiler warning, issue 1802 */
91#ifdef NOT_USED
92static const uint8_t u8x8_d_st75256_jlx256128_flip0_seq[] = {
93 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
94 U8X8_C( 0x030 ), /* select 00 commands */
95 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
96 U8X8_A( 0xa6 ), /* ??? */
97
98 //U8X8_C( 0x030 ), /* select 00 commands */
99 U8X8_C( 0x00c ), /* data format LSB top */
100 U8X8_END_TRANSFER(), /* disable chip */
101 U8X8_END() /* end of sequence */
102};
103
104static const uint8_t u8x8_d_st75256_jlx256128_flip1_seq[] = {
105 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
106 U8X8_C( 0x030 ), /* select 00 commands */
107 U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
108 U8X8_A( 0xa6 ), /* ??? */
109
110 //U8X8_C( 0x030 ), /* select 00 commands */
111 U8X8_C( 0x008 ), /* data format MSB top */
112 U8X8_END_TRANSFER(), /* disable chip */
113 U8X8_END() /* end of sequence */
114};
115#endif
116
117static const uint8_t u8x8_d_st75256_jlx172104_flip0_seq[] = {
118 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
119 U8X8_C( 0x030 ), /* select 00 commands */
120 U8X8_CA( 0xbc, 0x02 ), /* data scan dir */
121 U8X8_A( 0xa6 ), /* ??? */
122
123 //U8X8_C( 0x030 ), /* select 00 commands */
124 U8X8_C( 0x00c ), /* data format LSB top */
125 U8X8_END_TRANSFER(), /* disable chip */
126 U8X8_END() /* end of sequence */
127};
128
129static const uint8_t u8x8_d_st75256_jlx172104_flip1_seq[] = {
130 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
131 U8X8_C( 0x030 ), /* select 00 commands */
132 U8X8_CA( 0xbc, 0x01 ), /* data scan dir */
133 U8X8_A( 0xa6 ), /* ??? */
134
135 //U8X8_C( 0x030 ), /* select 00 commands */
136 U8X8_C( 0x008 ), /* data format MSB top */
137 U8X8_END_TRANSFER(), /* disable chip */
138 U8X8_END() /* end of sequence */
139};
140
141/* marked as unused to avoid compiler warning, issue 1802 */
142#ifdef NOT_USED
143static const uint8_t u8x8_d_st75256_jlx256160_flip0_seq[] = {
144 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
145 U8X8_C( 0x030 ), /* select 00 commands */
146 U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
147 U8X8_A( 0xa6 ), /* ??? */
148
149 //U8X8_C( 0x030 ), /* select 00 commands */
150 U8X8_C( 0x00c ), /* data format LSB top */
151 U8X8_END_TRANSFER(), /* disable chip */
152 U8X8_END() /* end of sequence */
153};
154
155static const uint8_t u8x8_d_st75256_jlx256160_flip1_seq[] = {
156 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
157 U8X8_C( 0x030 ), /* select 00 commands */
158 U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
159 U8X8_A( 0xa6 ), /* ??? */
160
161 //U8X8_C( 0x030 ), /* select 00 commands */
162 U8X8_C( 0x008 ), /* data format MSB top */
163 U8X8_END_TRANSFER(), /* disable chip */
164 U8X8_END() /* end of sequence */
165};
166#endif
167
168
169/*=============================================*/
170/* JM16096 https://github.com/olikraus/u8g2/issues/1642 */
171
172static const u8x8_display_info_t u8x8_st75160_jm16096_display_info =
173{
174 /* chip_enable_level = */ 0,
175 /* chip_disable_level = */ 1,
176
177 /* post_chip_enable_wait_ns = */ 20,
178 /* pre_chip_disable_wait_ns = */ 20,
179 /* reset_pulse_width_ms = */ 5,
180 /* post_reset_wait_ms = */ 5, /**/
181 /* sda_setup_time_ns = */ 20, /* */
182 /* sck_pulse_width_ns = */ 40, /* */
183 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
184 /* spi_mode = */ 0, /* active high, rising edge */
185 /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
186 /* data_setup_time_ns = */ 15,
187 /* write_pulse_width_ns = */ 70,
188 /* tile_width = */ 20,
189 /* tile_height = */ 12,
190 /* default_x_offset = */ 0, /* x offset in flipmode 0 */
191 /* flipmode_x_offset = */ 0, /* */
192 /* pixel_width = */ 160,
193 /* pixel_height = */ 96
194};
195
196
197static const uint8_t u8x8_d_st75160_jm16096_init_seq[] = {
198 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
199
200 U8X8_DLY(20),
201
202 U8X8_C( 0x030 ), /* select 00 commands */
203 U8X8_C( 0x094 ), /* sleep out */
204
205 //U8X8_C( 0x030 ), /* select 00 commands */
206 U8X8_C( 0x0ae ), /* display off */
207
208 U8X8_C( 0x031 ), /* select 01 commands */
209 U8X8_CA( 0x0d7, 0x09f ), /* disable auto read */
210
211 //U8X8_C( 0x031 ), /* select 01 commands */
212 U8X8_C( 0x032 ), /* analog circuit set */
213 U8X8_A( 0x000 ), /* code example: OSC Frequency adjustment */
214 U8X8_A( 0x001 ), /* Frequency on booster capacitors 1 = 6KHz? */
215 U8X8_A( 0x004 ), /* Bias: 1: 1/13, 2: 1/12, 3: 1/11, 4:1/10, 5:1/9 */
216
217 //U8X8_C( 0x031 ), /* select 01 commands */
218 U8X8_C( 0x020 ), /* gray levels */
219 U8X8_A( 0x01 ),
220 U8X8_A( 0x03 ),
221 U8X8_A( 0x05 ),
222 U8X8_A( 0x07 ),
223 U8X8_A( 0x09),
224 U8X8_A( 0x0b ),
225 U8X8_A( 0x0d ),
226 U8X8_A( 0x10 ),
227 U8X8_A( 0x11 ),
228 U8X8_A( 0x13 ),
229 U8X8_A( 0x15 ),
230 U8X8_A( 0x17 ),
231 U8X8_A( 0x19 ),
232 U8X8_A( 0x1b ),
233 U8X8_A( 0x1d ),
234 U8X8_A( 0x1f ),
235
236
237 U8X8_C( 0x030 ), /* select 00 commands */
238 U8X8_CAA(0x75, 0, 0x4f), /* row range */
239 U8X8_CAA(0x15, 0, 239), /* col range */
240
241 //U8X8_C( 0x030 ), /* select 00 commands */
242 U8X8_CA( 0xbc, 0x02 ), /* data scan dir */
243 U8X8_A( 0xa6 ), /* ??? */
244
245 //U8X8_C( 0x030 ), /* select 00 commands */
246 U8X8_C( 0x00c ), /* data format LSB top */
247
248 //U8X8_C( 0x030 ), /* select 00 commands */
249 U8X8_C( 0xca ), /* display control, 3 args follow */
250 U8X8_A( 0x00 ), /* 0x00: no clock division, 0x04: devide clock */
251 U8X8_A( 95 ), /* 1/96 duty */
252 U8X8_A( 0x20 ), /* nline off */
253
254 //U8X8_C( 0x030 ), /* select 00 commands */
255 U8X8_CA( 0x0f0, 0x010 ), /* monochrome mode = 0x010*/
256
257 //U8X8_C( 0x030 ), /* select 00 commands */
258 U8X8_CAA( 0x81, 0x18, 0x04 ), /* Volume control */
259
260 //U8X8_C( 0x030 ), /* select 00 commands */
261 U8X8_CA( 0x020, 0x00b ), /* Power control: Regulator, follower & booster on */
262 U8X8_DLY(100),
263
264 U8X8_END_TRANSFER(), /* disable chip */
265 U8X8_END() /* end of sequence */
266};
267
268
269uint8_t u8x8_d_st75160_jm16096(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
270{
271 uint8_t x, c;
272 uint8_t *ptr;
273
274 switch(msg)
275 {
276 case U8X8_MSG_DISPLAY_DRAW_TILE:
277
278 u8x8_cad_StartTransfer(u8x8);
279 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
280 x *= 8;
281
282 u8x8_cad_SendCmd(u8x8, 0x030 ); /* select command set */
283 u8x8_cad_SendCmd(u8x8, 0x075 ); /* row */
284 if ( u8x8->x_offset == 0 ) /* 0 means flip mode 1 */
285 u8x8_cad_SendArg(u8x8, 1+(((u8x8_tile_t *)arg_ptr)->y_pos));
286 else
287 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
288 u8x8_cad_SendArg(u8x8, 0x04f);
289 //u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
290 u8x8_cad_SendCmd(u8x8, 0x015 ); /* col */
291 u8x8_cad_SendArg(u8x8, x+u8x8->x_offset);
292 u8x8_cad_SendArg(u8x8, 255);
293 u8x8_cad_SendCmd(u8x8, 0x05c );
294
295
296 do
297 {
298 c = ((u8x8_tile_t *)arg_ptr)->cnt;
299 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
300 c *= 8;
301
302 if ( c + x > 160u )
303 {
304 c = 160u;
305 c -= x;
306 }
307
308 u8x8_cad_SendData(u8x8, c, ptr);
309 x += c;
310 arg_int--;
311 } while( arg_int > 0 );
312
313 u8x8_cad_EndTransfer(u8x8);
314 return 1;
315 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
316 //u8x8_SetI2CAddress(u8x8, 0x078); /* lowest I2C adr of the ST75256 */
317 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75160_jm16096_display_info);
318 return 1;
319 case U8X8_MSG_DISPLAY_INIT:
320 u8x8_d_helper_display_init(u8x8);
321 u8x8_cad_SendSequence(u8x8, u8x8_d_st75160_jm16096_init_seq);
322 return 1;
323 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
324 if ( arg_int == 0 )
325 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave0_seq);
326 else
327 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave1_seq);
328
329 return 1;
330 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
331 if ( arg_int == 0 )
332 {
333 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_jlx172104_flip0_seq);
334 u8x8->x_offset = u8x8->display_info->default_x_offset;
335 }
336 else
337 {
338 u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_jlx172104_flip1_seq);
339 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
340 }
341 return 1;
342
343#ifdef U8X8_WITH_SET_CONTRAST
344 case U8X8_MSG_DISPLAY_SET_CONTRAST:
345
346 u8x8_cad_StartTransfer(u8x8);
347
348 u8x8_cad_SendCmd(u8x8, 0x030 );
349 u8x8_cad_SendCmd(u8x8, 0x081 ); /* there are 9 bit for the volume control */
350 u8x8_cad_SendArg(u8x8, (arg_int & 0x1f)<<1 ); /* lower 6 bit */
351 u8x8_cad_SendArg(u8x8, (arg_int>>5)); /* upper 3 bit */
352
353 u8x8_cad_EndTransfer(u8x8);
354 return 1;
355#endif
356 }
357 return 0;
358
359
360
361}
362