components/u8g2/csrc/u8x8_d_ssd1306_96x16.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8x8_d_ssd1306_96x16.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
36
37 #include "u8x8.h"
38
39
40
41 /* EastRising 0.69 OLED */
42 static const uint8_t u8x8_d_ssd1306_96x16_er_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, 0x00f), /* multiplex ratio, 0.69 OLED: 0x0f */
50 U8X8_CA(0x0d3, 0x000), /* display offset, 0.69 OLED */
51 U8X8_C(0x040), /* set display start line to 0, 0.69 OLED */
52 U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, 0.66 OLED 0x14*/
53 U8X8_CA(0x020, 0x000), /* page addressing mode */
54
55 U8X8_C(0x0a1), /* segment remap a0/a1, 0.66 OLED */
56 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse, 0.66 OLED */
57 // Flipmode
58 // U8X8_C(0x0a0), /* segment remap a0/a1*/
59 // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
60
61 U8X8_CA(0x0da, 0x002), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5), 0.66 OLED */
62 U8X8_CA(0x081, 0x0af), /* [2] set contrast control, 0.69 OLED datasheet: 0xaf */
63 U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x0f1, 0.69 OLED datasheet: 0xf1 */
64 U8X8_CA(0x0db, 0x020), /* vcomh deselect level, 0.69 OLED datasheet: 0x20 */
65
66 U8X8_C(0x02e), /* Deactivate scroll */
67 U8X8_C(0x0a4), /* output ram to display */
68 U8X8_C(0x0a6), /* none inverted normal display mode */
69
70 U8X8_END_TRANSFER(), /* disable chip */
71 U8X8_END() /* end of sequence */
72 };
73
74 static const uint8_t u8x8_d_ssd1306_96x16_powersave0_seq[] = {
75 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
76 U8X8_C(0x0af), /* display on */
77 U8X8_END_TRANSFER(), /* disable chip */
78 U8X8_END() /* end of sequence */
79 };
80
81 static const uint8_t u8x8_d_ssd1306_96x16_powersave1_seq[] = {
82 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
83 U8X8_C(0x0ae), /* display off */
84 U8X8_END_TRANSFER(), /* disable chip */
85 U8X8_END() /* end of sequence */
86 };
87
88 static const uint8_t u8x8_d_ssd1306_96x16_flip0_seq[] = {
89 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
90 U8X8_C(0x0a1), /* segment remap a0/a1*/
91 U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
92 U8X8_END_TRANSFER(), /* disable chip */
93 U8X8_END() /* end of sequence */
94 };
95
96 static const uint8_t u8x8_d_ssd1306_96x16_flip1_seq[] = {
97 U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
98 U8X8_C(0x0a0), /* segment remap a0/a1*/
99 U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
100 U8X8_END_TRANSFER(), /* disable chip */
101 U8X8_END() /* end of sequence */
102 };
103
104
105 static uint8_t u8x8_d_ssd1306_96x16_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
106 {
107 uint8_t x, c;
108 uint8_t *ptr;
109 switch(msg)
110 {
111 /* handled by the calling function
112 case U8X8_MSG_DISPLAY_SETUP_MEMORY:
113 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_96x16_display_info);
114 break;
115 case U8X8_MSG_DISPLAY_INIT:
116 u8x8_d_helper_display_init(u8x8);
117 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_er_init_seq);
118 break;
119 */
120 case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
121 if ( arg_int == 0 )
122 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_powersave0_seq);
123 else
124 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_powersave1_seq);
125 break;
126 case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
127 if ( arg_int == 0 )
128 {
129 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_flip0_seq);
130 u8x8->x_offset = u8x8->display_info->default_x_offset;
131 }
132 else
133 {
134 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_flip1_seq);
135 u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
136 }
137 break;
138 #ifdef U8X8_WITH_SET_CONTRAST
139 case U8X8_MSG_DISPLAY_SET_CONTRAST:
140 u8x8_cad_StartTransfer(u8x8);
141 u8x8_cad_SendCmd(u8x8, 0x081 );
142 u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1306 has range from 0 to 255 */
143 u8x8_cad_EndTransfer(u8x8);
144 break;
145 #endif
146 case U8X8_MSG_DISPLAY_DRAW_TILE:
147 u8x8_cad_StartTransfer(u8x8);
148 x = ((u8x8_tile_t *)arg_ptr)->x_pos;
149 x *= 8;
150 x += u8x8->x_offset;
151 u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
152 u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
153 u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
154
155 do
156 {
157 c = ((u8x8_tile_t *)arg_ptr)->cnt;
158 ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
159 u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
160 arg_int--;
161 } while( arg_int > 0 );
162
163 u8x8_cad_EndTransfer(u8x8);
164 break;
165 default:
166 return 0;
167 }
168 return 1;
169 }
170
171
172 static const u8x8_display_info_t u8x8_ssd1306_96x16_display_info =
173 {
174 /* chip_enable_level = */ 0,
175 /* chip_disable_level = */ 1,
176
177 /* post_chip_enable_wait_ns = */ 20,
178 /* pre_chip_disable_wait_ns = */ 10,
179 /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
180 /* post_reset_wait_ms = */ 100, /* OLEDs need much longer setup time */
181 /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
182 /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
183 /* 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) */
184 /* spi_mode = */ 0, /* active high, rising edge */
185 /* i2c_bus_clock_100kHz = */ 4,
186 /* data_setup_time_ns = */ 40,
187 /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
188 /* tile_width = */ 12,
189 /* tile_hight = */ 2,
190 /* default_x_offset = */ 0,
191 /* flipmode_x_offset = */ 32,
192 /* pixel_width = */ 96,
193 /* pixel_height = */ 16
194 };
195
196 /* East Rising 0.69" OLED */
197 uint8_t u8x8_d_ssd1306_96x16_er(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
198 {
199 if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
200 {
201 u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_96x16_display_info);
202 return 1;
203 }
204 else if ( msg == U8X8_MSG_DISPLAY_INIT )
205 {
206 u8x8_d_helper_display_init(u8x8);
207 u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_96x16_er_init_seq);
208 return 1;
209 }
210 return u8x8_d_ssd1306_96x16_generic(u8x8, msg, arg_int, arg_ptr);
211 }
212
213

mercurial