Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_ssd1306_96x40.c

328 lines · 12.4 KB · C

1/*
2
3 u8x8_d_ssd1306_96x40.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2016, 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 takeover from 96x16 OLED
35
36 21 Sep 2022: Also added the 96x39 variant here....
37
38*/
39
40
41#include "u8x8.h"
42
43
44
45static const uint8_t u8x8_d_ssd1306_96x40_powersave0_seq[] = {
46 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
47 U8X8_C(0x0af), /* display on */
48 U8X8_END_TRANSFER(), /* disable chip */
49 U8X8_END() /* end of sequence */
50};
51
52static const uint8_t u8x8_d_ssd1306_96x40_powersave1_seq[] = {
53 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
54 U8X8_C(0x0ae), /* display off */
55 U8X8_END_TRANSFER(), /* disable chip */
56 U8X8_END() /* end of sequence */
57};
58
59static const uint8_t u8x8_d_ssd1306_96x40_flip0_seq[] = {
60 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
61 U8X8_C(0x0a1), /* segment remap a0/a1*/
62 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
63 U8X8_END_TRANSFER(), /* disable chip */
64 U8X8_END() /* end of sequence */
65};
66
67static const uint8_t u8x8_d_ssd1306_96x40_flip1_seq[] = {
68 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
69 U8X8_C(0x0a0), /* segment remap a0/a1*/
70 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
71 U8X8_END_TRANSFER(), /* disable chip */
72 U8X8_END() /* end of sequence */
73};
74
75
76static uint8_t u8x8_d_ssd1306_96x40_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
77{
78 uint8_t x, c;
79 uint8_t *ptr;
80 switch(msg)
81 {
82 /* handled by the calling function
83 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
84 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_96x40_display_info);
85 break;
86 case U8X8_MSG_DISPLAY_INIT:
87 u8x8_d_helper_display_init(u8x8);
88 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_er_init_seq);
89 break;
90 */
91 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
92 if ( arg_int == 0 )
93 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_powersave0_seq);
94 else
95 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_powersave1_seq);
96 break;
97 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
98 if ( arg_int == 0 )
99 {
100 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_flip0_seq);
101 u8x8->x_offset = u8x8->display_info->default_x_offset;
102 }
103 else
104 {
105 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_flip1_seq);
106 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
107 }
108 break;
109#ifdef U8X8_WITH_SET_CONTRAST
110 case U8X8_MSG_DISPLAY_SET_CONTRAST:
111 u8x8_cad_StartTransfer(u8x8);
112 u8x8_cad_SendCmd(u8x8, 0x081 );
113 u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1306 has range from 0 to 255 */
114 u8x8_cad_EndTransfer(u8x8);
115 break;
116#endif
117 case U8X8_MSG_DISPLAY_DRAW_TILE:
118 u8x8_cad_StartTransfer(u8x8);
119 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
120 x *= 8;
121 x += u8x8->x_offset;
122 u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
123 u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
124 u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
125
126 do
127 {
128 c = ((u8x8_tile_t *)arg_ptr)->cnt;
129 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
130 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
131 arg_int--;
132 } while( arg_int > 0 );
133
134 u8x8_cad_EndTransfer(u8x8);
135 break;
136 default:
137 return 0;
138 }
139 return 1;
140}
141
142/*===============================================*/
143
144/* https://github.com/olikraus/u8g2/issues/1812 */
145static const uint8_t u8x8_d_ssd1306_96x40_init_seq[] = {
146
147 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
148
149
150 U8X8_C(0x0ae), /* display off */
151 U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
152 U8X8_CA(0x0a8, 0x027), /* multiplex ratio */
153 U8X8_CA(0x0d3, 0x000), /* display offset */
154 U8X8_C(0x040), /* set display start line to 0 */
155 U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, 0.66 OLED 0x14*/
156 U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
157
158 U8X8_C(0x0a1), /* segment remap a0/a1, 0.66 OLED */
159 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse, 0.66 OLED */
160 // Flipmode
161 // U8X8_C(0x0a0), /* segment remap a0/a1*/
162 // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
163
164 U8X8_CA(0x0da, 0x002), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), 0.66 OLED */
165 U8X8_CA(0x081, 0x0af), /* [2] set contrast control */
166 U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x0f1 */
167 U8X8_CA(0x0db, 0x020), /* vcomh deselect level */
168
169 U8X8_C(0x02e), /* Deactivate scroll */
170 U8X8_C(0x0a4), /* output ram to display */
171 U8X8_C(0x0a6), /* none inverted normal display mode */
172
173 U8X8_END_TRANSFER(), /* disable chip */
174 U8X8_END() /* end of sequence */
175};
176
177
178
179static const u8x8_display_info_t u8x8_ssd1306_96x40_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, /* 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 = */ 12,
196 /* tile_height = */ 5,
197 /* default_x_offset = */ 0,
198 /* flipmode_x_offset = */ 32,
199 /* pixel_width = */ 96,
200 /* pixel_height = */ 40
201};
202
203uint8_t u8x8_d_ssd1306_96x40(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
204{
205 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
206 {
207 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_96x40_display_info);
208 return 1;
209 }
210 else if ( msg == U8X8_MSG_DISPLAY_INIT )
211 {
212 u8x8_d_helper_display_init(u8x8);
213 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x40_init_seq);
214 return 1;
215 }
216 return u8x8_d_ssd1306_96x40_generic(u8x8, msg, arg_int, arg_ptr);
217}
218
219/*===============================================*/
220
221/* 96x39 OLED */
222/* https://github.com/olikraus/u8g2/issues/1959 */
223static const uint8_t u8x8_d_ssd1306_96x39_init_seq[] = {
224
225 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
226
227
228 U8X8_C(0x0ae), /* display off */
229 U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
230 U8X8_CA(0x0a8, 0x027), /* multiplex ratio */
231 U8X8_CA(0x0d3, 0), /* display offset, issue 1959 */
232 U8X8_C(0x040), /* set display start line to 0 */
233 U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, 0.66 OLED 0x14*/
234 U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
235
236 U8X8_C(0x0a1), /* segment remap a0/a1, 0.66 OLED */
237 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse, 0.66 OLED */
238 // Flipmode
239 // U8X8_C(0x0a0), /* segment remap a0/a1*/
240 // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
241
242 U8X8_CA(0x0da, 0x010), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), issue 1959: 0x010 */
243 U8X8_CA(0x081, 0x0af), /* [2] set contrast control */
244 U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x0f1 */
245 U8X8_CA(0x0db, 0x020), /* vcomh deselect level */
246
247 U8X8_C(0x02e), /* Deactivate scroll */
248 U8X8_C(0x0a4), /* output ram to display */
249 U8X8_C(0x0a6), /* none inverted normal display mode */
250
251 U8X8_END_TRANSFER(), /* disable chip */
252 U8X8_END() /* end of sequence */
253};
254
255static const uint8_t u8x8_d_ssd1306_96x39_flip0_seq[] = {
256 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
257 U8X8_C(0x0a1), /* segment remap a0/a1*/
258 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
259 U8X8_C(0x07f), /* set display start line to -1 (not exactly sure why...) */
260 U8X8_END_TRANSFER(), /* disable chip */
261 U8X8_END() /* end of sequence */
262};
263
264static const uint8_t u8x8_d_ssd1306_96x39_flip1_seq[] = {
265 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
266 U8X8_C(0x0a0), /* segment remap a0/a1*/
267 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
268 U8X8_C(0x040), /* set display start line to 0 */
269 U8X8_END_TRANSFER(), /* disable chip */
270 U8X8_END() /* end of sequence */
271};
272
273
274static const u8x8_display_info_t u8x8_ssd1306_96x39_display_info =
275{
276 /* chip_enable_level = */ 0,
277 /* chip_disable_level = */ 1,
278
279 /* post_chip_enable_wait_ns = */ 20,
280 /* pre_chip_disable_wait_ns = */ 10,
281 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
282 /* post_reset_wait_ms = */ 100, /* OLEDs need much longer setup time */
283 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
284 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
285 /* 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) */
286 /* spi_mode = */ 0, /* active high, rising edge */
287 /* i2c_bus_clock_100kHz = */ 4,
288 /* data_setup_time_ns = */ 40,
289 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
290 /* tile_width = */ 12,
291 /* tile_height = */ 5,
292 /* default_x_offset = */ 32,
293 /* flipmode_x_offset = */ 0,
294 /* pixel_width = */ 96,
295 /* pixel_height = */ 39
296};
297
298uint8_t u8x8_d_ssd1306_96x39(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
299{
300 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
301 {
302 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_96x39_display_info);
303 return 1;
304 }
305 else if ( msg == U8X8_MSG_DISPLAY_INIT )
306 {
307 u8x8_d_helper_display_init(u8x8);
308 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x39_init_seq);
309 return 1;
310 }
311 else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
312 {
313 if ( arg_int == 0 )
314 {
315 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x39_flip0_seq);
316 u8x8->x_offset = u8x8->display_info->default_x_offset;
317 }
318 else
319 {
320 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x39_flip1_seq);
321 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
322 }
323 }
324 return u8x8_d_ssd1306_96x40_generic(u8x8, msg, arg_int, arg_ptr);
325}
326
327/*===============================================*/
328