Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_st7511.c

355 lines · 11.9 KB · C

1/*
2
3 u8x8_d_st7511.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2019, 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 20 May 2019:
36 https://github.com/olikraus/u8g2/issues/876
37 Probably HW Flip does not work
38
39 640x320: https://github.com/olikraus/u8g2/issues/2737
40
41*/
42#include "u8x8.h"
43
44
45
46
47static const uint8_t u8x8_d_st7511_320x240_powersave0_seq[] = {
48 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
49 U8X8_CA(0x015, 0x0a5), /* display on */
50 U8X8_END_TRANSFER(), /* disable chip */
51 U8X8_END() /* end of sequence */
52};
53
54static const uint8_t u8x8_d_st7511_320x240_powersave1_seq[] = {
55 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
56 U8X8_CA(0x014, 0x0a5), /* display off */
57 // maybe use sleep mode here, but it not clear whether sleep mode will reset all the settings
58 U8X8_END_TRANSFER(), /* disable chip */
59 U8X8_END() /* end of sequence */
60};
61
62static const uint8_t u8x8_d_st7511_320x240_flip0_seq[] = {
63 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
64 U8X8_CAAAA(0x24, 0x01, 0xa5, 0xa5, 0xa5), /* memory control directions */
65 U8X8_END_TRANSFER(), /* disable chip */
66 U8X8_END() /* end of sequence */
67};
68
69static const uint8_t u8x8_d_st7511_320x240_flip1_seq[] = {
70 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
71 U8X8_CAAAA(0x24, 0x02, 0xa5, 0xa5, 0xa5), /* memory control directions */
72 U8X8_END_TRANSFER(), /* disable chip */
73 U8X8_END() /* end of sequence */
74};
75
76
77
78/*=====================================================*/
79/* AV-Display: AVD-TM57QV-NW-001-B, issue 876 */
80
81static const u8x8_display_info_t u8x8_st7511_320x240_display_info =
82{
83 /* chip_enable_level = */ 0,
84 /* chip_disable_level = */ 1,
85
86 /* post_chip_enable_wait_ns = */ 150, /* ST7511 Datasheet */
87 /* pre_chip_disable_wait_ns = */ 150, /* ST7511 Datasheet */
88 /* reset_pulse_width_ms = */ 1,
89 /* post_reset_wait_ms = */ 1,
90 /* sda_setup_time_ns = */ 120, /* ST7511 Datasheet */
91 /* sck_pulse_width_ns = */ 150, /* ST7511 Datasheet */
92 /* sck_clock_hz = */ 3300000UL, /* ST7511 Datasheet: 300ns cycle */
93 /* spi_mode = */ 0, /* active high, rising edge */
94 /* i2c_bus_clock_100kHz = */ 4,
95 /* data_setup_time_ns = */ 200, /* */
96 /* write_pulse_width_ns = */ 250, /* ST7511 Datasheet: 500ns */
97 /* tile_width = */ 40, /* width of 17*8=136 pixel */
98 /* tile_height = */ 30,
99 /* default_x_offset = */ 160,
100 /* flipmode_x_offset = */ 0,
101 /* pixel_width = */ 320,
102 /* pixel_height = */ 240
103};
104
105static const uint8_t u8x8_d_st7511_320x240_init_seq[] = {
106
107 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
108
109 U8X8_CA(0xae, 0xa5), /* SW Reset */
110 U8X8_CAAAA(0x61, 0x0f, 0x04, 0x02, 0xa5), /* all power on */
111 U8X8_CAAAA(0x62, 0x0a, 0x06, 0x0f, 0xa5), /* electronic volumne set 1 */
112 U8X8_CAAAA(0x63, 0x0f, 0x0f, 0xa5, 0xa5), /* electronic volumne set 2 */
113 U8X8_CAAAA(0x66, 0x00, 0xa5, 0xa5, 0xa5), /* electronic volumne set 2 */
114 U8X8_CA(0x12, 0xa5), /* SLeeP OUT */
115 U8X8_DLY(50),
116 // skiping display on here, deviation from https://github.com/olikraus/u8g2/issues/876
117 // will be called later in u8x8_d_st7511_320x240_powersave0_seq
118 U8X8_CAAAA(0x22, 0x00, 0xa5, 0xa5, 0xa5), /* monochrome display */
119 U8X8_CAAAA(0x24, 0x01, 0xa5, 0xa5, 0xa5), /* memory control directions */
120
121 U8X8_DLY(50),
122
123 U8X8_END_TRANSFER(), /* disable chip */
124 U8X8_END() /* end of sequence */
125};
126
127uint8_t u8x8_d_st7511_avd_320x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
128{
129 uint16_t x, c;
130 uint8_t *ptr;
131 switch(msg)
132 {
133 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
134 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7511_320x240_display_info);
135 break;
136 case U8X8_MSG_DISPLAY_INIT:
137 u8x8_d_helper_display_init(u8x8);
138 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_init_seq);
139 break;
140 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
141 if ( arg_int == 0 )
142 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave0_seq);
143 else
144 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave1_seq);
145 break;
146 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
147 if ( arg_int == 0 )
148 {
149 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip0_seq);
150 u8x8->x_offset = u8x8->display_info->default_x_offset;
151 }
152 else
153 {
154 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip1_seq);
155 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
156 }
157 break;
158#ifdef U8X8_WITH_SET_CONTRAST
159 case U8X8_MSG_DISPLAY_SET_CONTRAST:
160 // not sure how to implement this....
161 // u8x8_cad_StartTransfer(u8x8);
162 // u8x8_cad_EndTransfer(u8x8);
163 break;
164#endif
165 case U8X8_MSG_DISPLAY_DRAW_TILE:
166 u8x8_cad_StartTransfer(u8x8);
167
168 // set page
169 u8x8_cad_SendCmd(u8x8, 0x025);
170 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
171 u8x8_cad_SendArg(u8x8, 0x09f); // end page
172 u8x8_cad_SendArg(u8x8, 0x000); // frame 0
173 u8x8_cad_SendArg(u8x8, 0x0a5);
174
175 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
176 x *= 8;
177 x += u8x8->x_offset;
178
179 // set column
180 u8x8_cad_SendCmd(u8x8, 0x026);
181 u8x8_cad_SendArg(u8x8, (x>>8) );
182 u8x8_cad_SendArg(u8x8, (x&255) );
183 u8x8_cad_SendArg(u8x8, 0x002);
184 u8x8_cad_SendArg(u8x8, 0x07f);
185
186 // start data transfer
187 u8x8_cad_SendCmd(u8x8, 0x02c);
188 u8x8_cad_SendArg(u8x8, 0x0a5 );
189
190 do
191 {
192 c = ((u8x8_tile_t *)arg_ptr)->cnt;
193 c *= 8;
194 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
195
196 while ( c > 128 )
197 {
198 u8x8_cad_SendData(u8x8, 128, ptr); /* note: SendData can not handle more than 255 bytes */
199 c -= 128;
200 ptr += 128;
201 }
202 u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
203 arg_int--;
204 } while( arg_int > 0 );
205
206 u8x8_cad_EndTransfer(u8x8);
207 break;
208 default:
209 return 0;
210 }
211 return 1;
212}
213
214
215/*=====================================================*/
216/* 640x320, issue https://github.com/olikraus/u8g2/issues/2737 */
217
218static const u8x8_display_info_t u8x8_st7511_640x320_display_info =
219{
220 /* chip_enable_level = */ 0,
221 /* chip_disable_level = */ 1,
222
223 /* post_chip_enable_wait_ns = */ 150, /* ST7511 Datasheet */
224 /* pre_chip_disable_wait_ns = */ 150, /* ST7511 Datasheet */
225 /* reset_pulse_width_ms = */ 1,
226 /* post_reset_wait_ms = */ 1,
227 /* sda_setup_time_ns = */ 120, /* ST7511 Datasheet */
228 /* sck_pulse_width_ns = */ 150, /* ST7511 Datasheet */
229 /* sck_clock_hz = */ 3300000UL, /* ST7511 Datasheet: 300ns cycle */
230 /* spi_mode = */ 0, /* active high, rising edge */
231 /* i2c_bus_clock_100kHz = */ 4,
232 /* data_setup_time_ns = */ 200, /* */
233 /* write_pulse_width_ns = */ 250, /* ST7511 Datasheet: 500ns */
234 /* tile_width = */ 80, /* width of 17*8=136 pixel */
235 /* tile_height = */ 40,
236 /* default_x_offset = */ 0, // issue 2737: use 0
237 /* flipmode_x_offset = */ 0,
238 /* pixel_width = */ 640,
239 /* pixel_height = */ 320
240};
241
242static const uint8_t u8x8_d_st7511_640x320_init_seq[] = {
243
244 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
245
246 U8X8_CA(0xae, 0xa5), /* SW Reset */
247 U8X8_CAAAA(0x61, 0x0f, 0x04, 0x02, 0xa5), /* all power on */
248 U8X8_CAAAA(0x62, 0x0a, 0x06, 0x0f, 0xa5), /* electronic volumne set 1 */
249 U8X8_CAAAA(0x63, 0x0f, 0x0f, 0xa5, 0xa5), /* electronic volumne set 2 */
250 U8X8_CAAAA(0x66, 0x00, 0xa5, 0xa5, 0xa5), /* electronic volumne set 2 */
251 U8X8_CA(0x12, 0xa5), /* SLeeP OUT */
252 U8X8_DLY(50),
253 // skiping display on here, deviation from https://github.com/olikraus/u8g2/issues/876
254 // will be called later in u8x8_d_st7511_320x240_powersave0_seq
255 U8X8_CAAAA(0x22, 0x00, 0xa5, 0xa5, 0xa5), /* monochrome display */
256 U8X8_CAAAA(0x24, 0x01, 0xa5, 0xa5, 0xa5), /* memory control directions */
257
258 U8X8_CA(0x1b, 0xa5), /* issue 2737: set screen to inverse mode since it default draws white on black */
259 U8X8_CAAAA(0x29, 0x00, 0xa5, 0xa5, 0xa5), /* issue 2737: block fill whole screen with white*/
260
261 U8X8_DLY(50),
262
263 U8X8_END_TRANSFER(), /* disable chip */
264 U8X8_END() /* end of sequence */
265};
266
267uint8_t u8x8_d_st7511_640x320(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
268{
269 uint16_t x, c;
270 uint8_t *ptr;
271 switch(msg)
272 {
273 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
274 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7511_640x320_display_info);
275 break;
276 case U8X8_MSG_DISPLAY_INIT:
277 u8x8_d_helper_display_init(u8x8);
278 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_640x320_init_seq);
279 break;
280 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
281 if ( arg_int == 0 )
282 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave0_seq);
283 else
284 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave1_seq);
285 break;
286 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
287 if ( arg_int == 0 )
288 {
289 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip0_seq);
290 u8x8->x_offset = u8x8->display_info->default_x_offset;
291 }
292 else
293 {
294 u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip1_seq);
295 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
296 }
297 break;
298#ifdef U8X8_WITH_SET_CONTRAST
299 case U8X8_MSG_DISPLAY_SET_CONTRAST:
300 // not sure how to implement this....
301 // u8x8_cad_StartTransfer(u8x8);
302 // u8x8_cad_EndTransfer(u8x8);
303 break;
304#endif
305 case U8X8_MSG_DISPLAY_DRAW_TILE:
306 u8x8_cad_StartTransfer(u8x8);
307
308 // set page
309 u8x8_cad_SendCmd(u8x8, 0x025);
310 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
311 u8x8_cad_SendArg(u8x8, 0x09f); // end page
312 u8x8_cad_SendArg(u8x8, 0x000); // frame 0
313 u8x8_cad_SendArg(u8x8, 0x0a5);
314
315 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
316 x *= 8;
317 x += u8x8->x_offset;
318
319 // set column
320 u8x8_cad_SendCmd(u8x8, 0x026);
321 u8x8_cad_SendArg(u8x8, (x>>8) );
322 u8x8_cad_SendArg(u8x8, (x&255) );
323 u8x8_cad_SendArg(u8x8, 0x002);
324 u8x8_cad_SendArg(u8x8, 0x07f);
325
326 // start data transfer
327 u8x8_cad_SendCmd(u8x8, 0x02c);
328 u8x8_cad_SendArg(u8x8, 0x0a5 );
329
330 do
331 {
332 c = ((u8x8_tile_t *)arg_ptr)->cnt;
333 c *= 8;
334 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
335
336 while ( c > 128 )
337 {
338 u8x8_cad_SendData(u8x8, 128, ptr); /* note: SendData can not handle more than 255 bytes */
339 c -= 128;
340 ptr += 128;
341 }
342 u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
343 arg_int--;
344 } while( arg_int > 0 );
345
346 u8x8_cad_EndTransfer(u8x8);
347 break;
348 default:
349 return 0;
350 }
351 return 1;
352}
353
354
355