components/u8g2/csrc/u8x8_d_sh1122.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8x8_d_sh1122.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
35 Copied from sh1122 mostly because of the similar RAM architecture.
36 However: Commands are very different!
37
38 */
39 #include "u8x8.h"
40
41
42
43
44 static const uint8_t u8x8_d_sh1122_powersave0_seq[] = {
45 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
46 U8X8_C(0x0af), /* sh1122: display on */
47 U8X8_END_TRANSFER(), /* disable chip */
48 U8X8_END() /* end of sequence */
49 };
50
51 static const uint8_t u8x8_d_sh1122_powersave1_seq[] = {
52 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
53 U8X8_C(0x0ae), /* sh1122: display off */
54 U8X8_END_TRANSFER(), /* disable chip */
55 U8X8_END() /* end of sequence */
56 };
57
58
59
60
61 /*
62 input:
63 one tile (8 Bytes)
64 output:
65 Tile for SH1122 (32 Bytes)
66 */
67
68 /*
69 static uint8_t u8x8_sh1122_to32_dest_buf[32];
70
71 static uint8_t *u8x8_sh1122_8to32(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
72 {
73 uint8_t v;
74 uint8_t a,b;
75 uint8_t i, j;
76 uint8_t *dest;
77
78 for( j = 0; j < 4; j++ )
79 {
80 dest = u8x8_sh1122_to32_dest_buf;
81 dest += j;
82 a =*ptr;
83 ptr++;
84 b = *ptr;
85 ptr++;
86 for( i = 0; i < 8; i++ )
87 {
88 v = 0;
89 if ( a&1 ) v |= 0xf0;
90 if ( b&1 ) v |= 0x0f;
91 *dest = v;
92 dest+=4;
93 a >>= 1;
94 b >>= 1;
95 }
96 }
97
98 return u8x8_sh1122_to32_dest_buf;
99 }
100 */
101
102
103 static uint8_t u8x8_write_byte_to_16gr_device(u8x8_t *u8x8, uint8_t b)
104 {
105 static uint8_t buf[4];
106 static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
107 buf [3] = map[b & 3];
108 b>>=2;
109 buf [2] = map[b & 3];
110 b>>=2;
111 buf [1] = map[b & 3];
112 b>>=2;
113 buf [0] = map[b & 3];
114 return u8x8_cad_SendData(u8x8, 4, buf);
115 }
116
117 uint8_t u8x8_d_sh1122_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
118 {
119 uint8_t x;
120 uint8_t y, c, i;
121 uint8_t *ptr;
122 switch(msg)
123 {
124 /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
125 /*
126 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
127 break;
128 case U8X8_MSG_DISPLAY_INIT:
129 u8x8_d_helper_display_init(u8x8);
130 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_256x64_init_seq);
131 break;
132 */
133 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
134 if ( arg_int == 0 )
135 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_powersave0_seq);
136 else
137 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_powersave1_seq);
138 break;
139 #ifdef U8X8_WITH_SET_CONTRAST
140 case U8X8_MSG_DISPLAY_SET_CONTRAST:
141 u8x8_cad_StartTransfer(u8x8);
142 u8x8_cad_SendCmd(u8x8, 0x081 );
143 u8x8_cad_SendArg(u8x8, arg_int ); /* sh1122 has range from 0 to 255 */
144 u8x8_cad_EndTransfer(u8x8);
145 break;
146 #endif
147 case U8X8_MSG_DISPLAY_DRAW_TILE:
148 u8x8_cad_StartTransfer(u8x8);
149 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
150 x *= 2; // only every 4th col can be addressed
151 x += u8x8->x_offset;
152
153 y = (((u8x8_tile_t *)arg_ptr)->y_pos);
154 y *= 8;
155
156
157 c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
158 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */
159 for( i = 0; i < 8; i++ )
160 {
161 u8x8_cad_SendCmd(u8x8, 0x0b0 ); /* set row address */
162 u8x8_cad_SendArg(u8x8, y);
163 u8x8_cad_SendCmd(u8x8, x & 15 ); /* lower 4 bit*/
164 u8x8_cad_SendCmd(u8x8, 0x010 | (x >> 4) ); /* higher 3 bit */
165 c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
166
167 while ( c > 0 )
168 {
169 u8x8_write_byte_to_16gr_device(u8x8, *ptr);
170 c--;
171 ptr++;
172 }
173 y++;
174 }
175
176
177 u8x8_cad_EndTransfer(u8x8);
178 break;
179 default:
180 return 0;
181 }
182 return 1;
183 }
184
185 /*=========================================================*/
186
187 static const uint8_t u8x8_d_sh1122_256x64_flip0_seq[] = {
188 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
189 U8X8_C(0x0a1), /* remap */
190 U8X8_C(0x0c8), /* remap */
191 U8X8_C(0x060),
192 U8X8_END_TRANSFER(), /* disable chip */
193 U8X8_END() /* end of sequence */
194 };
195
196 static const uint8_t u8x8_d_sh1122_256x64_flip1_seq[] = {
197 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
198 U8X8_C(0x0a0), /* remap */
199 U8X8_C(0x0c0), /* remap */
200 U8X8_C(0x040),
201 U8X8_END_TRANSFER(), /* disable chip */
202 U8X8_END() /* end of sequence */
203 };
204
205 static const u8x8_display_info_t u8x8_sh1122_256x64_display_info =
206 {
207 /* chip_enable_level = */ 0,
208 /* chip_disable_level = */ 1,
209
210 /* post_chip_enable_wait_ns = */ 20,
211 /* pre_chip_disable_wait_ns = */ 10,
212 /* reset_pulse_width_ms = */ 10, /* sh1122: 10 us */
213 /* post_reset_wait_ms = */ 20, /* */
214 /* sda_setup_time_ns = */ 125, /* sh1122: cycle time is 250ns, so use 250/2 */
215 /* sck_pulse_width_ns = */ 125, /* sh1122: cycle time is 250ns, so use 250/2 */
216 /* sck_clock_hz = */ 40000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
217 /* spi_mode = */ 0, /* active high, rising edge */
218 /* i2c_bus_clock_100kHz = */ 4,
219 /* data_setup_time_ns = */ 10,
220 /* write_pulse_width_ns = */ 150, /* sh1122: cycle time is 300ns, so use 300/2 = 150 */
221 /* tile_width = */ 32, /* 256 pixel, so we require 32 bytes for this */
222 /* tile_hight = */ 8,
223 /* default_x_offset = */ 0, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
224 /* flipmode_x_offset = */ 0,
225 /* pixel_width = */ 256,
226 /* pixel_height = */ 64
227 };
228
229
230 static const uint8_t u8x8_d_sh1122_256x64_init_seq[] = {
231
232 U8X8_DLY(1),
233 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
234 U8X8_DLY(1),
235
236 U8X8_C(0xae), /* display off */
237 U8X8_C(0x40), /* display start line */
238 U8X8_C(0x0a0), /* remap */
239 U8X8_C(0x0c0), /* remap */
240 U8X8_CA(0x81, 0x80), /* set display contrast */
241 U8X8_CA(0xa8, 0x3f), /* multiplex ratio 1/64 Duty (0x0F~0x3F) */
242 U8X8_CA(0xad, 0x81), /* use buildin DC-DC with 0.6 * 500 kHz */
243
244 U8X8_CA(0xd5, 0x50), /* set display clock divide ratio (lower 4 bit)/oscillator frequency (upper 4 bit) */
245 U8X8_CA(0xd3, 0x00), /* display offset, shift mapping ram counter */
246 U8X8_CA(0xd9, 0x22), /* pre charge (lower 4 bit) and discharge(higher 4 bit) period */
247 U8X8_CA(0xdb, 0x35), /* VCOM deselect level */
248 U8X8_CA(0xdc, 0x35), /* Pre Charge output voltage */
249 U8X8_C(0x030), /* discharge level */
250
251 U8X8_DLY(1), /* delay */
252
253 U8X8_END_TRANSFER(), /* disable chip */
254 U8X8_END() /* end of sequence */
255 };
256
257
258 uint8_t u8x8_d_sh1122_256x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
259 {
260 switch(msg)
261 {
262 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
263 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1122_256x64_display_info);
264 break;
265 case U8X8_MSG_DISPLAY_INIT:
266 u8x8_d_helper_display_init(u8x8);
267 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_256x64_init_seq);
268 break;
269 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
270 if ( arg_int == 0 )
271 {
272 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_256x64_flip0_seq);
273 u8x8->x_offset = u8x8->display_info->default_x_offset;
274 }
275 else
276 {
277 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1122_256x64_flip1_seq);
278 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
279 }
280 break;
281
282 default:
283 return u8x8_d_sh1122_common(u8x8, msg, arg_int, arg_ptr);
284 }
285 return 1;
286 }
287

mercurial