components/u8g2/csrc/u8x8_d_sh1106_64x32.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8x8_d_sh1106_64x32.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2018, 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
36
37 #include "u8x8.h"
38
39
40
41 /* issue 568 */
42 static const uint8_t u8x8_d_sh1106_64x32_init_seq[] = {
43
44 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
45
46
47 U8X8_C(0x0ae), /* display off */
48 U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
49 U8X8_CA(0x0a8, 0x01f), /* multiplex ratio, 0.42 OLED */
50 U8X8_CA(0x0d3, 0x000), /* display offset, 0.42 OLED */
51 U8X8_C(0x040), /* set display start line to 0, 0.42 OLED */
52 U8X8_CA(0xad, 0x8b), /* DC-DC ON/OFF Mode Set: Built-in DC-DC is used, Normal Display (POR = 0x8b) */
53 U8X8_C(0x33), /* set charge pump voltage 0x30 (POR) .. 0x33 */
54 U8X8_CA(0x020, 0x000), /* page addressing mode */
55
56 U8X8_C(0x0a1), /* segment remap a0/a1, 0.66 OLED */
57 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse, 0.66 OLED */
58 // Flipmode
59 // U8X8_C(0x0a0), /* segment remap a0/a1*/
60 // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
61
62 U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), 0.66 OLED */
63 U8X8_CA(0x081, 0x080), /* [2] set contrast control, 0.42 OLED datasheet: 0xcf */
64 U8X8_CA(0x0d9, 0x022), /* [2] pre-charge period 0x022/f1, 0.42 OLED datasheet: 0x22 */
65 U8X8_CA(0x0db, 0x028), /* vcomh deselect level, 0.42 OLED datasheet: 0x00 */
66
67 U8X8_C(0x02e), /* Deactivate scroll */
68 U8X8_C(0x0a4), /* output ram to display */
69 U8X8_C(0x0a6), /* none inverted normal display mode */
70
71 U8X8_END_TRANSFER(), /* disable chip */
72 U8X8_END() /* end of sequence */
73 };
74
75 static const uint8_t u8x8_d_sh1106_64x32_powersave0_seq[] = {
76 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
77 U8X8_C(0x0af), /* display on */
78 U8X8_END_TRANSFER(), /* disable chip */
79 U8X8_END() /* end of sequence */
80 };
81
82 static const uint8_t u8x8_d_sh1106_64x32_powersave1_seq[] = {
83 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
84 U8X8_C(0x0ae), /* display off */
85 U8X8_END_TRANSFER(), /* disable chip */
86 U8X8_END() /* end of sequence */
87 };
88
89 static const uint8_t u8x8_d_sh1106_64x32_flip0_seq[] = {
90 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
91 U8X8_C(0x0a1), /* segment remap a0/a1*/
92 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
93 U8X8_CA(0x0d3, 0), /* display offset, 0.42 OLED */
94 U8X8_END_TRANSFER(), /* disable chip */
95 U8X8_END() /* end of sequence */
96 };
97
98 static const uint8_t u8x8_d_sh1106_64x32_flip1_seq[] = {
99 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
100 U8X8_C(0x0a0), /* segment remap a0/a1*/
101 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
102 U8X8_CA(0x0d3, 0), /* What is the correct offset in flip 1 mode? --> Issue 547 */
103 U8X8_END_TRANSFER(), /* disable chip */
104 U8X8_END() /* end of sequence */
105 };
106
107
108 static uint8_t u8x8_d_sh1106_64x32_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
109 {
110 uint8_t x, c;
111 uint8_t *ptr;
112 switch(msg)
113 {
114 /* handled by the calling function
115 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
116 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1106_64x32_display_info);
117 break;
118 case U8X8_MSG_DISPLAY_INIT:
119 u8x8_d_helper_display_init(u8x8);
120 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_init_seq);
121 break;
122 */
123 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
124 if ( arg_int == 0 )
125 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_powersave0_seq);
126 else
127 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_powersave1_seq);
128 break;
129 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
130 if ( arg_int == 0 )
131 {
132 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_flip0_seq);
133 u8x8->x_offset = u8x8->display_info->default_x_offset;
134 }
135 else
136 {
137 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_flip1_seq);
138 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
139 }
140 break;
141 #ifdef U8X8_WITH_SET_CONTRAST
142 case U8X8_MSG_DISPLAY_SET_CONTRAST:
143 u8x8_cad_StartTransfer(u8x8);
144 u8x8_cad_SendCmd(u8x8, 0x081 );
145 u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1306 has range from 0 to 255 */
146 u8x8_cad_EndTransfer(u8x8);
147 break;
148 #endif
149 case U8X8_MSG_DISPLAY_DRAW_TILE:
150 u8x8_cad_StartTransfer(u8x8);
151 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
152 x *= 8;
153 x += u8x8->x_offset;
154 u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
155 u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
156 u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
157
158 do
159 {
160 c = ((u8x8_tile_t *)arg_ptr)->cnt;
161 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
162 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
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 /* copied from SSD1306 */
175 static const u8x8_display_info_t u8x8_sh1106_64x32_display_info =
176 {
177 /* chip_enable_level = */ 0,
178 /* chip_disable_level = */ 1,
179
180 /* post_chip_enable_wait_ns = */ 20,
181 /* pre_chip_disable_wait_ns = */ 10,
182 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
183 /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
184 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
185 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
186 /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215) */
187 /* spi_mode = */ 0, /* active high, rising edge */
188 /* i2c_bus_clock_100kHz = */ 4,
189 /* data_setup_time_ns = */ 40,
190 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
191 /* tile_width = */ 8,
192 /* tile_hight = */ 4,
193 /* default_x_offset = */ 32,
194 /* flipmode_x_offset = */ 36,
195 /* pixel_width = */ 64,
196 /* pixel_height = */ 32
197 };
198
199 uint8_t u8x8_d_sh1106_64x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
200 {
201 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
202 {
203 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1106_64x32_display_info);
204 return 1;
205 }
206 else if ( msg == U8X8_MSG_DISPLAY_INIT )
207 {
208 u8x8_d_helper_display_init(u8x8);
209 u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_64x32_init_seq);
210 return 1;
211 }
212 return u8x8_d_sh1106_64x32_generic(u8x8, msg, arg_int, arg_ptr);
213 }
214
215

mercurial