Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8U8g2srcclibu8x8_d_pcf8812.c

331 lines · 10.5 KB · C

1/*
2
3 u8x8_d_pcf8812.c
4
5 pcf8812: 65x102
6 pcf8814: 65x96
7
8 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
9
10 Copyright (c) 2017, olikraus@gmail.com
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification,
14 are permitted provided that the following conditions are met:
15
16 * Redistributions of source code must retain the above copyright notice, this list
17 of conditions and the following disclaimer.
18
19 * Redistributions in binary form must reproduce the above copyright notice, this
20 list of conditions and the following disclaimer in the documentation and/or other
21 materials provided with the distribution.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37*/
38
39
40#include "u8x8.h"
41
42
43
44static const uint8_t u8x8_d_pcf8812_96x65_init_seq[] = {
45
46 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
47
48 U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
49 U8X8_C(0x008), /* blank display */
50
51 U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
52 U8X8_C(0x006), /* temp. control: b10 = 2 */
53 U8X8_C(0x013), /* bias system, 0x010..0x07 1:48 */
54 U8X8_C(0x09f), /* contrast setting, 0..127 */
55 //U8X8_CA(0x020 | 2, 0x080 | 0), /* contrast setting, pcf8814 */
56
57 U8X8_C(0x024), /* deactivate chip (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
58
59 U8X8_END_TRANSFER(), /* disable chip */
60 U8X8_END() /* end of sequence */
61};
62
63
64static const uint8_t u8x8_d_pcf8812_101x64_init_seq[] = {
65 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
66 U8X8_C(0x21), // PowerON, ExtCommandSet
67 U8X8_C(0x09), // Internal HV-gen x3
68 U8X8_C(0xB7), // Set Vop
69 U8X8_C(0x16), // Bias n=2 //15
70 U8X8_C(0x06), // Temperature coeff 2
71 U8X8_C(0x20), // StandartCommandSet
72 U8X8_C(0x0C), // normal mode, display non-inverted
73 U8X8_END_TRANSFER(), /* disable chip */
74 U8X8_END() /* end of sequence */
75};
76
77
78
79static const uint8_t u8x8_d_pcf8812_96x65_powersave0_seq[] = {
80 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
81 U8X8_C(0x020), /* power on */
82 U8X8_C(0x00c), /* display on */
83 U8X8_END_TRANSFER(), /* disable chip */
84 U8X8_END() /* end of sequence */
85};
86
87static const uint8_t u8x8_d_pcf8812_96x65_powersave1_seq[] = {
88 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
89 U8X8_C(0x020), /* power on */
90 U8X8_C(0x008), /* blank display */
91 U8X8_C(0x024), /* power down */
92 U8X8_END_TRANSFER(), /* disable chip */
93 U8X8_END() /* end of sequence */
94};
95
96
97static uint8_t u8x8_d_pcf8812_96x65_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
98{
99 uint8_t x, c;
100 uint8_t *ptr;
101 switch(msg)
102 {
103 /* handled by the calling function
104 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
105 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
106 break;
107 */
108 case U8X8_MSG_DISPLAY_INIT:
109 u8x8_d_helper_display_init(u8x8);
110 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_init_seq);
111 break;
112 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
113 if ( arg_int == 0 )
114 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave0_seq);
115 else
116 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave1_seq);
117 break;
118/*
119 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
120 if ( arg_int == 0 )
121 {
122 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip0_seq);
123 u8x8->x_offset = u8x8->display_info->default_x_offset;
124 }
125 else
126 {
127 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip1_seq);
128 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
129 }
130 break;
131*/
132#ifdef U8X8_WITH_SET_CONTRAST
133 case U8X8_MSG_DISPLAY_SET_CONTRAST:
134 u8x8_cad_StartTransfer(u8x8);
135 u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
136 u8x8_cad_SendArg(u8x8, (arg_int>>1)|0x80 ); /* 0..127 for contrast */
137 u8x8_cad_EndTransfer(u8x8);
138 break;
139#endif
140 case U8X8_MSG_DISPLAY_DRAW_TILE:
141 u8x8_cad_StartTransfer(u8x8);
142 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
143 x *= 8;
144 x += u8x8->x_offset;
145
146 u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
147 u8x8_cad_SendCmd(u8x8, 0x080 | x);
148 u8x8_cad_SendCmd(u8x8, 0x040 | ((u8x8_tile_t *)arg_ptr)->y_pos);
149
150 do
151 {
152 c = ((u8x8_tile_t *)arg_ptr)->cnt;
153 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
154 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
155 /*
156 do
157 {
158 u8x8_cad_SendData(u8x8, 8, ptr);
159 ptr += 8;
160 c--;
161 } while( c > 0 );
162 */
163 arg_int--;
164 } while( arg_int > 0 );
165
166 u8x8_cad_EndTransfer(u8x8);
167 break;
168 default:
169 return 0;
170 }
171 return 1;
172}
173
174
175static uint8_t u8x8_d_pcf8812_101x64_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
176{
177 uint8_t x, c;
178 uint8_t *ptr;
179 switch(msg)
180 {
181 /* handled by the calling function
182 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
183 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
184 break;
185 */
186 case U8X8_MSG_DISPLAY_INIT:
187 u8x8_d_helper_display_init(u8x8);
188 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_101x64_init_seq);
189 break;
190 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
191 if ( arg_int == 0 )
192 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave0_seq);
193 else
194 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave1_seq);
195 break;
196/*
197 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
198 if ( arg_int == 0 )
199 {
200 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip0_seq);
201 u8x8->x_offset = u8x8->display_info->default_x_offset;
202 }
203 else
204 {
205 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip1_seq);
206 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
207 }
208 break;
209*/
210#ifdef U8X8_WITH_SET_CONTRAST
211 case U8X8_MSG_DISPLAY_SET_CONTRAST:
212 u8x8_cad_StartTransfer(u8x8);
213 u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
214 u8x8_cad_SendArg(u8x8, (arg_int>>1)|0x80 ); /* 0..127 for contrast */
215 u8x8_cad_EndTransfer(u8x8);
216 break;
217#endif
218 case U8X8_MSG_DISPLAY_DRAW_TILE:
219 u8x8_cad_StartTransfer(u8x8);
220 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
221 x *= 8;
222 x += u8x8->x_offset;
223
224 u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
225 u8x8_cad_SendCmd(u8x8, 0x080 | x);
226 u8x8_cad_SendCmd(u8x8, 0x040 | ((u8x8_tile_t *)arg_ptr)->y_pos);
227
228 do
229 {
230 c = ((u8x8_tile_t *)arg_ptr)->cnt;
231 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
232 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
233 /*
234 do
235 {
236 u8x8_cad_SendData(u8x8, 8, ptr);
237 ptr += 8;
238 c--;
239 } while( c > 0 );
240 */
241 arg_int--;
242 } while( arg_int > 0 );
243
244 u8x8_cad_EndTransfer(u8x8);
245 break;
246 default:
247 return 0;
248 }
249 return 1;
250}
251
252
253
254
255static const u8x8_display_info_t u8x8_pcf8812_96x65_display_info =
256{
257 /* chip_enable_level = */ 0,
258 /* chip_disable_level = */ 1,
259
260 /* post_chip_enable_wait_ns = */ 100,
261 /* pre_chip_disable_wait_ns = */ 100,
262 /* reset_pulse_width_ms = */ 100,
263 /* post_reset_wait_ms = */ 100,
264 /* sda_setup_time_ns = */ 100,
265 /* sck_pulse_width_ns = */ 100,
266 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
267 /* spi_mode = */ 0, /* active high, rising edge */
268 /* i2c_bus_clock_100kHz = */ 4,
269 /* data_setup_time_ns = */ 40,
270 /* write_pulse_width_ns = */ 150,
271 /* tile_width = */ 12,
272 /* tile_height = */ 9,
273 /* default_x_offset = */ 0,
274 /* flipmode_x_offset = */ 0,
275 /* pixel_width = */ 96,
276 /* pixel_height = */ 65
277};
278
279uint8_t u8x8_d_pcf8812_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
280{
281 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
282 {
283 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
284 return 1;
285 }
286 return u8x8_d_pcf8812_96x65_generic(u8x8, msg, arg_int, arg_ptr);
287}
288
289/* https://github.com/olikraus/u8g2/issues/2421 */
290static const u8x8_display_info_t u8x8_pcf8812_101x64_display_info =
291{
292 /* chip_enable_level = */ 0,
293 /* chip_disable_level = */ 1,
294
295 /* post_chip_enable_wait_ns = */ 100,
296 /* pre_chip_disable_wait_ns = */ 100,
297 /* reset_pulse_width_ms = */ 100,
298 /* post_reset_wait_ms = */ 100,
299 /* sda_setup_time_ns = */ 100,
300 /* sck_pulse_width_ns = */ 100,
301 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
302 /* spi_mode = */ 0, /* active high, rising edge */
303 /* i2c_bus_clock_100kHz = */ 4,
304 /* data_setup_time_ns = */ 40,
305 /* write_pulse_width_ns = */ 150,
306 /* tile_width = */ 13,
307 /* tile_height = */ 8,
308 /* default_x_offset = */ 0,
309 /* flipmode_x_offset = */ 0,
310 /* pixel_width = */ 101,
311 /* pixel_height = */ 64
312};
313
314
315
316
317uint8_t u8x8_d_pcf8812_101x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
318{
319 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
320 {
321 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_101x64_display_info);
322 return 1;
323 }
324 else if ( msg == U8X8_MSG_DISPLAY_INIT )
325 {
326 u8x8_d_helper_display_init(u8x8);
327 u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_101x64_init_seq);
328 }
329 return u8x8_d_pcf8812_101x64_generic(u8x8, msg, arg_int, arg_ptr);
330}
331