|
1 /* |
|
2 |
|
3 u8x8_d_ld7032_60x32.c |
|
4 Note: Flip Mode is NOT supported |
|
5 |
|
6 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
|
7 |
|
8 Copyright (c) 2016, olikraus@gmail.com |
|
9 All rights reserved. |
|
10 |
|
11 Redistribution and use in source and binary forms, with or without modification, |
|
12 are permitted provided that the following conditions are met: |
|
13 |
|
14 * Redistributions of source code must retain the above copyright notice, this list |
|
15 of conditions and the following disclaimer. |
|
16 |
|
17 * Redistributions in binary form must reproduce the above copyright notice, this |
|
18 list of conditions and the following disclaimer in the documentation and/or other |
|
19 materials provided with the distribution. |
|
20 |
|
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
22 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
31 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
33 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
34 |
|
35 */ |
|
36 |
|
37 |
|
38 #include "u8x8.h" |
|
39 |
|
40 |
|
41 /* testboard U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board) */ |
|
42 /* http://www.seeedstudio.com/document/pdf/0.5OLED%20SPEC.pdf */ |
|
43 #ifdef OBSOLETE |
|
44 static const uint8_t u8x8_d_ld7032_60x32_init_seq_old[] = { |
|
45 |
|
46 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
47 |
|
48 //U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */ |
|
49 U8X8_CA(0x014, 0x000), /* Stand-by OFF */ |
|
50 U8X8_CA(0x01a, 0x004), /* Dot Matrix Frame Rate, special value for this OLED from manual*/ |
|
51 U8X8_CA(0x01d, 0x000), /* Graphics Memory Writing Direction: reset default (right down, horizontal) */ |
|
52 U8X8_CA(0x009, 0x000), /* Display Direction: reset default (x,y: min --> max) */ |
|
53 U8X8_CAA(0x030, 0x000, 0x03b), /* Display Size X, Column Start - End*/ |
|
54 U8X8_CAA(0x032, 0x000, 0x01f), /* Display Size Y, Row Start - End*/ |
|
55 U8X8_CA(0x010, 0x000), /* Peak Pulse Width Set: 0 SCLK */ |
|
56 U8X8_CA(0x016, 0x000), /* Peak Pulse Delay Set: 0 SCLK */ |
|
57 U8X8_CA(0x012, 0x040), /* Dot Matrix Current Level Set: 0x050 * 1 uA = 80 uA */ |
|
58 U8X8_CA(0x018, 0x003), /* Pre-Charge Pulse Width: 3 SCLK */ |
|
59 U8X8_CA(0x044, 0x002), /* Pre-Charge Mode: Every Time */ |
|
60 U8X8_CA(0x048, 0x003), /* Row overlap timing: Pre-Charge + Peak Delay + Peak boot Timing */ |
|
61 U8X8_CA(0x03f, 0x011), /* VCC_R_SEL: ??? */ |
|
62 U8X8_CA(0x03d, 0x000), /* VSS selection: 2.8V */ |
|
63 //U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */ |
|
64 |
|
65 |
|
66 U8X8_END_TRANSFER(), /* disable chip */ |
|
67 U8X8_END() /* end of sequence */ |
|
68 }; |
|
69 #endif |
|
70 |
|
71 /* new sequence https://github.com/olikraus/u8g2/issues/865 */ |
|
72 static const uint8_t u8x8_d_ld7032_60x32_init_seq[] = { |
|
73 |
|
74 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
75 |
|
76 U8X8_CA(0x02, 0x00), /* Dot Matrix Display OFF */ |
|
77 U8X8_CA(0x14, 0x00), /* Stand-by OFF, OSCA Start */ |
|
78 U8X8_CA(0x1a, 0x04), /* Dot Matrix Frame Rate, special value for this OLED from manual 4 => 120Hz*/ |
|
79 U8X8_CA(0x1d, 0x00), /* Graphics Memory Writing Direction: reset default (right down, horizontal) */ |
|
80 U8X8_CA(0x09, 0x00), /* Display Direction: reset default (x,y: min --> max) */ |
|
81 U8X8_CAA(0x30, 0x00, 0x3B), /* Display Size X, Column Start - End 0-0x3b(59)*/ |
|
82 U8X8_CAA(0x32, 0x00, 0x1F), /* Display Size Y, Row Start - End 0-0x1f(31)*/ |
|
83 U8X8_CA(0x34, 0x00), /* Data Reading/Writing Box X start */ |
|
84 U8X8_CA(0x35, 0x07), /* Data Reading/Writing Box X end */ |
|
85 U8X8_CA(0x36, 0x00), /* Data Reading/Writing Box Y start */ |
|
86 U8X8_CA(0x37, 0x1F), /* Data Reading/Writing Box Y end */ |
|
87 U8X8_CA(0x38, 0x00), /* Display Start Address X */ |
|
88 U8X8_CA(0x39, 0x00), /* Display Start Address Y */ |
|
89 U8X8_CA(0x10, 0x00), /* Peak Pulse Width Set: 0 SCLK */ |
|
90 U8X8_CA(0x16, 0x00), /* Peak Pulse Delay Set: 0 SCLK */ |
|
91 U8X8_CA(0x12, 0x40), /* 0x32, 0x50 or 0x40 Dot Matrix Current Level Set: 0x050 * 1 uA = 80 uA */ |
|
92 U8X8_CA(0x18, 0x03), /* Pre-Charge Pulse Width: 3 SCLK */ |
|
93 U8X8_CA(0x44, 0x02), /* Pre-Charge Mode: Every Time */ |
|
94 U8X8_CA(0x48, 0x03), /* Row overlap timing: Pre-Charge + Peak Delay + Peak boot Timing */ |
|
95 U8X8_CA(0x17, 0x00), /* Row Scan */ |
|
96 U8X8_CA(0x13, 0x00), /* Row Scan Sequence Setting */ |
|
97 U8X8_CA(0x1C, 0x00), /* Data Reverse */ |
|
98 U8X8_CA(0x3f, 0x11), /* VCC_R_SEL: Internal Regulator enabled(D4=1) and VCC_R=VCC_C*0.7(D0=1) */ |
|
99 U8X8_CA(0x3d, 0x00), /* VSS selection: 2.8V */ |
|
100 |
|
101 U8X8_END_TRANSFER(), /* disable chip */ |
|
102 U8X8_END() /* end of sequence */ |
|
103 }; |
|
104 |
|
105 static const uint8_t u8x8_d_ld7032_60x32_powersave0_seq[] = { |
|
106 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
107 U8X8_CA(0x002, 0x001), /* Dot Matrix Display ON */ |
|
108 U8X8_END_TRANSFER(), /* disable chip */ |
|
109 U8X8_END() /* end of sequence */ |
|
110 }; |
|
111 |
|
112 static const uint8_t u8x8_d_ld7032_60x32_powersave1_seq[] = { |
|
113 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
114 U8X8_CA(0x002, 0x000), /* Dot Matrix Display ON */ |
|
115 U8X8_END_TRANSFER(), /* disable chip */ |
|
116 U8X8_END() /* end of sequence */ |
|
117 }; |
|
118 |
|
119 static const uint8_t u8x8_d_ld7032_60x32_flip0_seq[] = { |
|
120 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
121 U8X8_CA(0x009, 0x000), /* Display Direction: reset default (x,y: min --> max) */ |
|
122 U8X8_END_TRANSFER(), /* disable chip */ |
|
123 U8X8_END() /* end of sequence */ |
|
124 }; |
|
125 |
|
126 static const uint8_t u8x8_d_ld7032_60x32_flip1_seq[] = { |
|
127 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
|
128 //U8X8_CA(0x009, 0x002), /* Display Direction: reset default (x,y: min --> max) */ |
|
129 U8X8_END_TRANSFER(), /* disable chip */ |
|
130 U8X8_END() /* end of sequence */ |
|
131 }; |
|
132 |
|
133 |
|
134 static uint8_t u8x8_d_ld7032_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
135 { |
|
136 uint8_t x, c; |
|
137 uint8_t *ptr; |
|
138 switch(msg) |
|
139 { |
|
140 /* handled by the calling function |
|
141 case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
|
142 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ld7032_60x32_display_info); |
|
143 break; |
|
144 */ |
|
145 case U8X8_MSG_DISPLAY_INIT: |
|
146 u8x8_d_helper_display_init(u8x8); |
|
147 u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_init_seq); |
|
148 break; |
|
149 case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
|
150 if ( arg_int == 0 ) |
|
151 u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_powersave0_seq); |
|
152 else |
|
153 u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_powersave1_seq); |
|
154 break; |
|
155 case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
|
156 if ( arg_int == 0 ) |
|
157 { |
|
158 u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_flip0_seq); |
|
159 u8x8->x_offset = u8x8->display_info->default_x_offset; |
|
160 } |
|
161 else |
|
162 { |
|
163 u8x8_cad_SendSequence(u8x8, u8x8_d_ld7032_60x32_flip1_seq); |
|
164 u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
|
165 } |
|
166 break; |
|
167 #ifdef U8X8_WITH_SET_CONTRAST |
|
168 case U8X8_MSG_DISPLAY_SET_CONTRAST: |
|
169 u8x8_cad_StartTransfer(u8x8); |
|
170 u8x8_cad_SendCmd(u8x8, 0x012 ); |
|
171 if ( arg_int > 0x07f ) /* default is 0x040, limit to 0x07f to be on the safe side (hopefully) */ |
|
172 arg_int= 0x07f; |
|
173 u8x8_cad_SendArg(u8x8, arg_int ); /* values from 0x00 to 0x0ff are allowed, bit will all values be safe??? */ |
|
174 u8x8_cad_EndTransfer(u8x8); |
|
175 break; |
|
176 #endif |
|
177 case U8X8_MSG_DISPLAY_DRAW_TILE: |
|
178 u8x8_cad_StartTransfer(u8x8); |
|
179 x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
|
180 x += u8x8->x_offset/8; |
|
181 u8x8_cad_SendCmd(u8x8, 0x034 ); |
|
182 u8x8_cad_SendArg(u8x8, x ); |
|
183 u8x8_cad_SendCmd(u8x8, 0x035 ); |
|
184 u8x8_cad_SendArg(u8x8, 0x007 ); |
|
185 u8x8_cad_SendCmd(u8x8, 0x036 ); |
|
186 u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos)*8 ); |
|
187 u8x8_cad_SendCmd(u8x8, 0x037 ); |
|
188 u8x8_cad_SendArg(u8x8, 0x01f ); |
|
189 u8x8_cad_SendCmd(u8x8, 0x008 ); |
|
190 |
|
191 |
|
192 do |
|
193 { |
|
194 c = ((u8x8_tile_t *)arg_ptr)->cnt; |
|
195 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
|
196 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */ |
|
197 arg_int--; |
|
198 } while( arg_int > 0 ); |
|
199 |
|
200 u8x8_cad_EndTransfer(u8x8); |
|
201 break; |
|
202 default: |
|
203 return 0; |
|
204 } |
|
205 return 1; |
|
206 } |
|
207 |
|
208 |
|
209 static const u8x8_display_info_t u8x8_ld7032_60x32_display_info = |
|
210 { |
|
211 /* chip_enable_level = */ 0, |
|
212 /* chip_disable_level = */ 1, |
|
213 |
|
214 /* post_chip_enable_wait_ns = */ 15, |
|
215 /* pre_chip_disable_wait_ns = */ 20, |
|
216 /* reset_pulse_width_ms = */ 100, |
|
217 /* post_reset_wait_ms = */ 100, |
|
218 /* sda_setup_time_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */ |
|
219 /* sck_pulse_width_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */ |
|
220 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
|
221 /* spi_mode = */ 0, /* active high, rising edge */ |
|
222 /* i2c_bus_clock_100kHz = */ 4, |
|
223 /* data_setup_time_ns = */ 20, |
|
224 /* write_pulse_width_ns = */ 40, |
|
225 /* tile_width = */ 8, |
|
226 /* tile_hight = */ 4, |
|
227 /* default_x_offset = */ 0, |
|
228 /* flipmode_x_offset = */ 0, |
|
229 /* pixel_width = */ 60, |
|
230 /* pixel_height = */ 32 |
|
231 }; |
|
232 |
|
233 uint8_t u8x8_d_ld7032_60x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
|
234 { |
|
235 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY ) |
|
236 { |
|
237 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ld7032_60x32_display_info); |
|
238 return 1; |
|
239 } |
|
240 return u8x8_d_ld7032_generic(u8x8, msg, arg_int, arg_ptr); |
|
241 } |
|
242 |
|
243 |