Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_ch1120.c

311 lines · 10.9 KB · C

1/*
2
3 u8x8_d_ch1120.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2018, 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
37#include "u8x8.h"
38
39/*
40 code copyied from sh1107
41 ch1120: 160x160 controller from Sino Wealth
42 https://github.com/olikraus/u8g2/issues/2496
43*/
44
45
46
47static const uint8_t u8x8_d_ch1120_noname_powersave0_seq[] = {
48 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
49 U8X8_C(0x0af), /* display on */
50 U8X8_END_TRANSFER(), /* disable chip */
51 U8X8_END() /* end of sequence */
52};
53
54static const uint8_t u8x8_d_ch1120_noname_powersave1_seq[] = {
55 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
56 U8X8_C(0x0ae), /* display off */
57 U8X8_END_TRANSFER(), /* disable chip */
58 U8X8_END() /* end of sequence */
59};
60
61static const uint8_t u8x8_d_ch1120_160x160_noname_powersave0_seq[] = {
62 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
63 U8X8_C(0x0a0), /* segment remap a0/a1*/
64 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
65 U8X8_END_TRANSFER(), /* disable chip */
66 U8X8_END() /* end of sequence */
67};
68
69static const uint8_t u8x8_d_ch1120_160x160_noname_powersave1_seq[] = {
70 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
71 U8X8_C(0x0a1), /* segment remap a0/a1*/
72 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
73 U8X8_END_TRANSFER(), /* disable chip */
74 U8X8_END() /* end of sequence */
75};
76
77
78static uint8_t u8x8_d_ch1120_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
79{
80 uint8_t x, c;
81 uint8_t *ptr;
82 switch(msg)
83 {
84 /* handled by the calling function
85 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
86 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ch1120_64x128_noname_display_info);
87 break;
88 */
89 /* handled by the calling function
90 case U8X8_MSG_DISPLAY_INIT:
91 u8x8_d_helper_display_init(u8x8);
92 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_64x128_noname_init_seq);
93 break;
94 */
95 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
96 if ( arg_int == 0 )
97 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_noname_powersave0_seq);
98 else
99 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_noname_powersave1_seq);
100 break;
101 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
102 if ( arg_int == 0 )
103 {
104 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_160x160_noname_powersave0_seq);
105 u8x8->x_offset = u8x8->display_info->default_x_offset;
106 }
107 else
108 {
109 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_160x160_noname_powersave1_seq);
110 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
111 }
112 break;
113#ifdef U8X8_WITH_SET_CONTRAST
114 case U8X8_MSG_DISPLAY_SET_CONTRAST:
115 u8x8_cad_StartTransfer(u8x8);
116 u8x8_cad_SendCmd(u8x8, 0x081 );
117 u8x8_cad_SendArg(u8x8, arg_int ); /* ch1120 has range from 0 to 255 */
118 u8x8_cad_EndTransfer(u8x8);
119 break;
120#endif
121 case U8X8_MSG_DISPLAY_DRAW_TILE:
122 u8x8_cad_StartTransfer(u8x8);
123 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
124 x *= 8;
125 x += u8x8->x_offset;
126
127 //u8x8_cad_SendCmd(u8x8, 0x040 ); /* set line offset to 0 */
128
129 // set column address
130 u8x8_cad_SendCmd(u8x8, 0x010 | (x >> 4));
131 u8x8_cad_SendCmd(u8x8, 0x000 | ((x & 15)));
132
133 // set page address
134 u8x8_cad_SendCmd(u8x8, 0x0b0 ); // page cmd is a two byte command
135 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
136
137 do
138 {
139 c = ((u8x8_tile_t *)arg_ptr)->cnt;
140 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
141 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
142 arg_int--;
143 } while( arg_int > 0 );
144
145 u8x8_cad_EndTransfer(u8x8);
146 break;
147 default:
148 return 0;
149 }
150 return 1;
151}
152
153/*==================================================*/
154
155#ifdef NOT_YET_REQUESTED
156/* 160x160 OLED */
157static const uint8_t u8x8_d_ch1120_160x160_noname_init_seq[] = {
158
159 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
160
161 U8X8_C(0x0ae), /* display off */
162 U8X8_CA(0x0d5, 0x060), /* clock divide ratio and oscillator frequency */
163 U8X8_CA(0x0a9, 0x003), /* set display resolution, 0=64x160, 1=96x160, 2=128x160, 3=160x160 */
164 U8X8_C(0x020), /* addressing mode */
165 U8X8_CA(0x081, 0x01f), /* set contrast control */
166 U8X8_CA(0x0ad, 0x80), /* DC/DC control 80=Use external Vpp, 89=Use internal DC/DC*/
167 U8X8_C(0x030), /* set discharge VSL level, 0x030..0x03f */
168 U8X8_CA(0x0d9, 0x028), /* pre-charge period */
169 U8X8_CA(0x0db, 0x035), /* vcomh deselect level */
170 U8X8_CA(0x0dc, 0x035), /* VSEGM Deselect Level */
171
172 U8X8_C(0x0a0), /* segment remap a0/a1*/
173 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
174
175 U8X8_C(0x0a4), /* output ram to display */
176 U8X8_C(0x0a6), /* none inverted normal display mode */
177
178 U8X8_END_TRANSFER(), /* disable chip */
179 U8X8_END() /* end of sequence */
180};
181
182static const u8x8_display_info_t u8x8_ch1120_160x160_noname_display_info =
183{
184 /* chip_enable_level = */ 0,
185 /* chip_disable_level = */ 1,
186
187 /* post_chip_enable_wait_ns = */ 60,
188 /* pre_chip_disable_wait_ns = */ 120,
189 /* reset_pulse_width_ms = */ 100, /* ch1120: 3 us */
190 /* post_reset_wait_ms = */ 100, /* sometimes OLEDs need much longer setup time */
191 /* sda_setup_time_ns = */ 100, /* ch1120: 100ns */
192 /* sck_pulse_width_ns = */ 100, /* ch1120: 100ns */
193 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
194 /* spi_mode = */ 0, /* active high, rising edge */
195 /* i2c_bus_clock_100kHz = */ 4,
196 /* data_setup_time_ns = */ 40,
197 /* write_pulse_width_ns = */ 150, /* ch1120: cycle time is 300ns, so use 300/2 = 150 */
198 /* tile_width = */ 20,
199 /* tile_height = */ 20,
200 /* default_x_offset = */ 0,
201 /* flipmode_x_offset = */ 0,
202 /* pixel_width = */ 160,
203 /* pixel_height = */ 160
204};
205
206uint8_t u8x8_d_ch1120_160x160(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
207{
208
209 if ( u8x8_d_ch1120_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
210 return 1;
211
212 switch(msg)
213 {
214 case U8X8_MSG_DISPLAY_INIT:
215 u8x8_d_helper_display_init(u8x8);
216 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_160x160_noname_init_seq);
217 break;
218 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
219 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ch1120_160x160_noname_display_info);
220 break;
221 default:
222 return 0;
223 }
224 return 1;
225}
226#endif
227
228/*==================================================*/
229
230
231/* https://github.com/olikraus/u8g2/issues/2496, 128x160 OLED */
232static const uint8_t u8x8_d_ch1120_128x160_noname_init_seq[] = {
233
234 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
235
236 U8X8_C(0x0ae), /* display off */
237 //U8X8_CAA(0x21, 0x00, 0x1f), /* Set Column Start/End Address of Display RAM, mono mode */
238 //U8X8_CAA(0x22, 0x00, 0x4f), /* Set Row Start/End Address of Display RAM, mono mode */
239 U8X8_CA(0x0a2, 0x000), /* display start */
240 U8X8_CA(0x081, 0x08f), /* set contrast control */
241 U8X8_CA(0x0ac, 0x001), /* mono mode, or 0x003???*/
242 U8X8_CA(0x020, 0x000), /* addressing mode */
243 U8X8_C(0x0C8), /* scan direction */
244 U8X8_CA(0x0a3, 0x000), /* display rotation */
245
246 U8X8_CA(0x0a8, 0x07f), /* multiplex ratio */
247 U8X8_CA(0x0d3, 0x010), /* display offset */
248
249 U8X8_CA(0x0d5, 0x01f), /* clock divide ratio and oscillator frequency */
250
251 U8X8_CA(0x048, 0x002), /* */
252 U8X8_CA(0x093, 0x002), /* */
253 U8X8_CA(0x0d8, 0x001), /* */
254 U8X8_CA(0x049, 0x006), /* */
255 U8X8_CA(0x0d9, 0x00f), /* */
256 U8X8_CA(0x094, 0x01f), /* */
257 U8X8_CA(0x04b, 0x004), /* */
258 U8X8_CA(0x0da, 0x000), /* */
259 U8X8_CA(0x0dc, 0x040), /* VSEGM Deselect Level */
260 U8X8_CA(0x0ad, 0x002), /* */
261
262 U8X8_END_TRANSFER(), /* disable chip */
263 U8X8_END() /* end of sequence */
264};
265
266static const u8x8_display_info_t u8x8_ch1120_128x160_noname_display_info =
267{
268 /* chip_enable_level = */ 0,
269 /* chip_disable_level = */ 1,
270
271 /* post_chip_enable_wait_ns = */ 20,
272 /* pre_chip_disable_wait_ns = */ 20,
273 /* reset_pulse_width_ms = */ 100, /* ch1120: 3 us */
274 /* post_reset_wait_ms = */ 100, /* sometimes OLEDs need much longer setup time */
275 /* sda_setup_time_ns = */ 100, /* ch1120: 100ns */
276 /* sck_pulse_width_ns = */ 100, /* ch1120: 100ns */
277 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
278 /* spi_mode = */ 0, /* active high, rising edge */
279 /* i2c_bus_clock_100kHz = */ 4,
280 /* data_setup_time_ns = */ 40,
281 /* write_pulse_width_ns = */ 40, /* ch1120: cycle time is 300ns, so use 300/2 = 150 */
282 /* tile_width = */ 16,
283 /* tile_height = */ 20,
284 /* default_x_offset = */ 16,
285 /* flipmode_x_offset = */ 16,
286 /* pixel_width = */ 128,
287 /* pixel_height = */ 160
288};
289
290uint8_t u8x8_d_ch1120_128x160(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
291{
292
293 if ( u8x8_d_ch1120_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
294 return 1;
295
296 switch(msg)
297 {
298 case U8X8_MSG_DISPLAY_INIT:
299 u8x8_d_helper_display_init(u8x8);
300 u8x8_cad_SendSequence(u8x8, u8x8_d_ch1120_128x160_noname_init_seq);
301 break;
302 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
303 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ch1120_128x160_noname_display_info);
304 break;
305 default:
306 return 0;
307 }
308 return 1;
309}
310
311/*==================================================*/