Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_ssd1312.c

354 lines · 12.6 KB · C

1/*
2
3 u8x8_d_ssd1312.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
35 NOTE: There is another SSD1312 128x64 in u8x8_d_ssd1306_128x64_noname.c
36
37*/
38
39
40#include "u8x8.h"
41
42
43static const uint8_t u8x8_d_ssd1312_128x32_powersave0_seq[] = {
44 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
45 U8X8_C(0x0af), /* display on */
46 U8X8_END_TRANSFER(), /* disable chip */
47 U8X8_END() /* end of sequence */
48};
49
50static const uint8_t u8x8_d_ssd1312_128x32_powersave1_seq[] = {
51 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
52 U8X8_C(0x0ae), /* display off */
53 U8X8_END_TRANSFER(), /* disable chip */
54 U8X8_END() /* end of sequence */
55};
56
57
58
59static uint8_t u8x8_d_ssd1312_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
60{
61 uint8_t x, c;
62 uint8_t *ptr;
63 switch(msg)
64 {
65 /* handled by the calling function
66 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
67 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
68 break;
69 */
70 /* handled by the calling function
71 case U8X8_MSG_DISPLAY_INIT:
72 u8x8_d_helper_display_init(u8x8);
73 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_init_seq);
74 break;
75 */
76 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
77 if ( arg_int == 0 )
78 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_powersave0_seq);
79 else
80 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_powersave1_seq);
81 break;
82#ifdef U8X8_WITH_SET_CONTRAST
83 case U8X8_MSG_DISPLAY_SET_CONTRAST:
84 u8x8_cad_StartTransfer(u8x8);
85 u8x8_cad_SendCmd(u8x8, 0x081 );
86 u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1306 has range from 0 to 255 */
87 u8x8_cad_EndTransfer(u8x8);
88 break;
89#endif
90 case U8X8_MSG_DISPLAY_DRAW_TILE:
91 u8x8_cad_StartTransfer(u8x8);
92 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
93 x *= 8;
94 x += u8x8->x_offset;
95
96 u8x8_cad_SendCmd(u8x8, 0x040 ); /* set line offset to 0 */
97
98 u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
99 u8x8_cad_SendArg(u8x8, 0x000 | ((x&15))); /* probably wrong, should be SendCmd */
100 u8x8_cad_SendArg(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); /* probably wrong, should be SendCmd */
101
102
103 do
104 {
105 c = ((u8x8_tile_t *)arg_ptr)->cnt;
106 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
107 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
108 /*
109 do
110 {
111 u8x8_cad_SendData(u8x8, 8, ptr);
112 ptr += 8;
113 c--;
114 } while( c > 0 );
115 */
116 arg_int--;
117 } while( arg_int > 0 );
118
119 u8x8_cad_EndTransfer(u8x8);
120 break;
121 default:
122 return 0;
123 }
124 return 1;
125}
126
127
128static const uint8_t u8x8_d_ssd1312_128x32_flip0_seq[] = {
129 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
130 U8X8_C(0x0a1), /* segment remap a0/a1*/
131 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
132 U8X8_END_TRANSFER(), /* disable chip */
133 U8X8_END() /* end of sequence */
134};
135
136static const uint8_t u8x8_d_ssd1312_128x32_flip1_seq[] = {
137 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
138 U8X8_C(0x0a0), /* segment remap a0/a1*/
139 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
140 U8X8_END_TRANSFER(), /* disable chip */
141 U8X8_END() /* end of sequence */
142};
143
144static const uint8_t u8x8_d_ssd1312_128x32_init_seq[] = {
145
146 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
147
148 U8X8_C(0x0ae), /* display off */
149 U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
150 U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */
151 U8X8_CA(0x0d3, 0x000), /* display offset */
152 U8X8_C(0x040), /* set display start line to 0 */
153 U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, SSD1306 only, should be removed for SH1106 */
154 U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
155
156 U8X8_C(0x0a1), /* segment remap a0/a1*/
157 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
158
159 /* 11 Aug 2025: The value below doesn't mach the bits 4 and 5, actually 0x12 would enable the alternate odd/even remapping */
160 /* probably the correct configuration value should be 0x00, see https://github.com/olikraus/u8g2/issues/2690 ??? */
161 U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
162
163 U8X8_CA(0x0d3, 0x030), /* line shift by 3*16 = 48 */
164
165 U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */
166 U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/
167 U8X8_CA(0x0db, 0x040), /* vcomh deselect level */
168 // if vcomh is 0, then this will give the biggest range for contrast control issue #98
169 // restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116
170
171 U8X8_C(0x02e), /* Deactivate scroll */
172 U8X8_C(0x0a4), /* output ram to display */
173 U8X8_C(0x0a6), /* none inverted normal display mode */
174
175 U8X8_END_TRANSFER(), /* disable chip */
176 U8X8_END() /* end of sequence */
177};
178
179static const u8x8_display_info_t u8x8_ssd1312_128x32_display_info =
180{
181 /* chip_enable_level = */ 0,
182 /* chip_disable_level = */ 1,
183
184 /* post_chip_enable_wait_ns = */ 20,
185 /* pre_chip_disable_wait_ns = */ 10,
186 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
187 /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
188 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
189 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
190 /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215) */
191 /* spi_mode = */ 0, /* active high, rising edge */
192 /* i2c_bus_clock_100kHz = */ 4,
193 /* data_setup_time_ns = */ 40,
194 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
195 /* tile_width = */ 16,
196 /* tile_height = */ 4,
197 /* default_x_offset = */ 0,
198 /* flipmode_x_offset = */ 0,
199 /* pixel_width = */ 128,
200 /* pixel_height = */ 32
201};
202
203/* https://github.com/olikraus/u8g2/issues/2368 128x32 */
204
205
206uint8_t u8x8_d_ssd1312_128x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
207{
208 switch(msg)
209 {
210 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
211 if ( arg_int == 0 )
212 {
213 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip0_seq);
214 u8x8->x_offset = u8x8->display_info->default_x_offset;
215 }
216 else
217 {
218 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip1_seq);
219 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
220 }
221 break;
222 case U8X8_MSG_DISPLAY_INIT:
223 u8x8_d_helper_display_init(u8x8);
224 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_init_seq);
225 break;
226 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
227 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1312_128x32_display_info);
228 break;
229 default:
230 if ( u8x8_d_ssd1312_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
231 return 1;
232 }
233 return 1;
234}
235
236/*====================================*/
237/* issue https://github.com/olikraus/u8g2/issues/2483 */
238
239static const u8x8_display_info_t u8x8_ssd1312_120x32_display_info =
240{
241 /* chip_enable_level = */ 0,
242 /* chip_disable_level = */ 1,
243
244 /* post_chip_enable_wait_ns = */ 20,
245 /* pre_chip_disable_wait_ns = */ 10,
246 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
247 /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
248 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
249 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
250 /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215) */
251 /* spi_mode = */ 0, /* active high, rising edge */
252 /* i2c_bus_clock_100kHz = */ 4,
253 /* data_setup_time_ns = */ 40,
254 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
255 /* tile_width = */ 15,
256 /* tile_height = */ 4,
257 /* default_x_offset = */ 0,
258 /* flipmode_x_offset = */ 0,
259 /* pixel_width = */ 120,
260 /* pixel_height = */ 32
261};
262
263
264uint8_t u8x8_d_ssd1312_120x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
265{
266 switch(msg)
267 {
268 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
269 if ( arg_int == 0 )
270 {
271 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip0_seq);
272 u8x8->x_offset = u8x8->display_info->default_x_offset;
273 }
274 else
275 {
276 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip1_seq);
277 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
278 }
279 break;
280 case U8X8_MSG_DISPLAY_INIT:
281 u8x8_d_helper_display_init(u8x8);
282 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_init_seq);
283 break;
284 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
285 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1312_120x32_display_info);
286 break;
287 default:
288 if ( u8x8_d_ssd1312_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
289 return 1;
290 }
291 return 1;
292}
293
294
295
296
297
298static const u8x8_display_info_t u8x8_ssd1312_120x28_display_info =
299{
300 /* chip_enable_level = */ 0,
301 /* chip_disable_level = */ 1,
302
303 /* post_chip_enable_wait_ns = */ 20,
304 /* pre_chip_disable_wait_ns = */ 10,
305 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
306 /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
307 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
308 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
309 /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215) */
310 /* spi_mode = */ 0, /* active high, rising edge */
311 /* i2c_bus_clock_100kHz = */ 4,
312 /* data_setup_time_ns = */ 40,
313 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
314 /* tile_width = */ 15,
315 /* tile_height = */ 4,
316 /* default_x_offset = */ 0,
317 /* flipmode_x_offset = */ 0,
318 /* pixel_width = */ 120,
319 /* pixel_height = */ 28
320};
321
322
323
324
325uint8_t u8x8_d_ssd1312_120x28(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
326{
327 switch(msg)
328 {
329 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
330 if ( arg_int == 0 )
331 {
332 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip0_seq);
333 u8x8->x_offset = u8x8->display_info->default_x_offset;
334 }
335 else
336 {
337 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_flip1_seq);
338 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
339 }
340 break;
341 case U8X8_MSG_DISPLAY_INIT:
342 u8x8_d_helper_display_init(u8x8);
343 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x32_init_seq);
344 break;
345 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
346 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1312_120x28_display_info);
347 break;
348 default:
349 if ( u8x8_d_ssd1312_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
350 return 1;
351 }
352 return 1;
353}
354