| 1 | /* |
| 2 | |
| 3 | u8x8_d_ssd1305.c |
| 4 | |
| 5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
| 6 | |
| 7 | Copyright (c) 2017, 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 | |
| 42 | static const uint8_t u8x8_d_ssd1305_powersave0_seq[] = { |
| 43 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 44 | U8X8_C(0x0af), /* display on */ |
| 45 | U8X8_END_TRANSFER(), /* disable chip */ |
| 46 | U8X8_END() /* end of sequence */ |
| 47 | }; |
| 48 | |
| 49 | static const uint8_t u8x8_d_ssd1305_powersave1_seq[] = { |
| 50 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 51 | U8X8_C(0x0ae), /* display off */ |
| 52 | U8X8_END_TRANSFER(), /* disable chip */ |
| 53 | U8X8_END() /* end of sequence */ |
| 54 | }; |
| 55 | |
| 56 | static const uint8_t u8x8_d_ssd1305_128x32_flip0_seq[] = { |
| 57 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 58 | U8X8_CA(0x0d3, 32), /* display offset to 32 */ |
| 59 | U8X8_C(0x0a1), /* segment remap a0/a1*/ |
| 60 | U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */ |
| 61 | U8X8_END_TRANSFER(), /* disable chip */ |
| 62 | U8X8_END() /* end of sequence */ |
| 63 | }; |
| 64 | |
| 65 | static const uint8_t u8x8_d_ssd1305_128x32_flip1_seq[] = { |
| 66 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 67 | U8X8_CA(0x0d3, 0), /* display offset to */ |
| 68 | U8X8_C(0x0a0), /* segment remap a0/a1*/ |
| 69 | U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */ |
| 70 | U8X8_END_TRANSFER(), /* disable chip */ |
| 71 | U8X8_END() /* end of sequence */ |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | |
| 76 | static uint8_t u8x8_d_ssd1305_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 77 | { |
| 78 | uint8_t x, c; |
| 79 | uint8_t *ptr; |
| 80 | switch(msg) |
| 81 | { |
| 82 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 83 | u8x8_cad_StartTransfer(u8x8); |
| 84 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 85 | x *= 8; |
| 86 | x += u8x8->x_offset; |
| 87 | |
| 88 | u8x8_cad_SendCmd(u8x8, 0x040 ); /* set line offset to 0 */ |
| 89 | |
| 90 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); |
| 91 | u8x8_cad_SendArg(u8x8, 0x000 | ((x&15))); |
| 92 | u8x8_cad_SendArg(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos) ); |
| 93 | |
| 94 | |
| 95 | do |
| 96 | { |
| 97 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 98 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 99 | u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */ |
| 100 | /* |
| 101 | do |
| 102 | { |
| 103 | u8x8_cad_SendData(u8x8, 8, ptr); |
| 104 | ptr += 8; |
| 105 | c--; |
| 106 | } while( c > 0 ); |
| 107 | */ |
| 108 | arg_int--; |
| 109 | } while( arg_int > 0 ); |
| 110 | |
| 111 | u8x8_cad_EndTransfer(u8x8); |
| 112 | break; |
| 113 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 114 | if ( arg_int == 0 ) |
| 115 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_powersave0_seq); |
| 116 | else |
| 117 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_powersave1_seq); |
| 118 | break; |
| 119 | #ifdef U8X8_WITH_SET_CONTRAST |
| 120 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 121 | u8x8_cad_StartTransfer(u8x8); |
| 122 | u8x8_cad_SendCmd(u8x8, 0x081 ); |
| 123 | u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1305 has range from 0 to 255 */ |
| 124 | u8x8_cad_EndTransfer(u8x8); |
| 125 | break; |
| 126 | #endif |
| 127 | default: |
| 128 | return 0; |
| 129 | } |
| 130 | return 1; |
| 131 | } |
| 132 | |
| 133 | /* timing from SSD1306 */ |
| 134 | static const u8x8_display_info_t u8x8_ssd1305_128x32_noname_display_info = |
| 135 | { |
| 136 | /* chip_enable_level = */ 0, |
| 137 | /* chip_disable_level = */ 1, |
| 138 | |
| 139 | /* post_chip_enable_wait_ns = */ 20, |
| 140 | /* pre_chip_disable_wait_ns = */ 10, |
| 141 | /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */ |
| 142 | /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */ |
| 143 | /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */ |
| 144 | /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 145 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 146 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 147 | /* i2c_bus_clock_100kHz = */ 4, |
| 148 | /* data_setup_time_ns = */ 40, |
| 149 | /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */ |
| 150 | /* tile_width = */ 16, |
| 151 | /* tile_height = */ 4, |
| 152 | /* default_x_offset = */ 2, |
| 153 | /* flipmode_x_offset = */ 2, |
| 154 | /* pixel_width = */ 128, |
| 155 | /* pixel_height = */ 32 |
| 156 | }; |
| 157 | |
| 158 | |
| 159 | static const uint8_t u8x8_d_ssd1305_128x32_noname_init_seq[] = { |
| 160 | |
| 161 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 162 | |
| 163 | |
| 164 | U8X8_C(0x0ae), /* display off */ |
| 165 | U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */ |
| 166 | U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */ |
| 167 | U8X8_CA(0x0d3, 32), /* display offset to 32 */ |
| 168 | U8X8_C(0x040), /* set display start line to 0 */ |
| 169 | U8X8_CA(0x020, 0x000), /* horizontal addressing mode */ |
| 170 | |
| 171 | U8X8_C(0x0a1), /* segment remap a0/a1*/ |
| 172 | U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */ |
| 173 | // Flipmode |
| 174 | // U8X8_C(0x0a0), /* segment remap a0/a1*/ |
| 175 | // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */ |
| 176 | |
| 177 | U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */ |
| 178 | |
| 179 | U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */ |
| 180 | U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/ |
| 181 | U8X8_CA(0x0db, 0x040), /* vcomh deselect level */ |
| 182 | // if vcomh is 0, then this will give the biggest range for contrast control issue #98 |
| 183 | // restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116 |
| 184 | |
| 185 | U8X8_C(0x02e), /* Deactivate scroll */ |
| 186 | U8X8_C(0x0a4), /* output ram to display */ |
| 187 | U8X8_C(0x0a6), /* none inverted normal display mode */ |
| 188 | |
| 189 | U8X8_END_TRANSFER(), /* disable chip */ |
| 190 | U8X8_END() /* end of sequence */ |
| 191 | }; |
| 192 | |
| 193 | |
| 194 | uint8_t u8x8_d_ssd1305_128x32_noname(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 195 | { |
| 196 | |
| 197 | if ( u8x8_d_ssd1305_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 198 | return 1; |
| 199 | |
| 200 | switch(msg) |
| 201 | { |
| 202 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 203 | if ( arg_int == 0 ) |
| 204 | { |
| 205 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip0_seq); |
| 206 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip1_seq); |
| 211 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 212 | } |
| 213 | break; |
| 214 | case U8X8_MSG_DISPLAY_INIT: |
| 215 | u8x8_d_helper_display_init(u8x8); |
| 216 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_noname_init_seq); |
| 217 | break; |
| 218 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 219 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1305_128x32_noname_display_info); |
| 220 | break; |
| 221 | default: |
| 222 | return 0; |
| 223 | } |
| 224 | return 1; |
| 225 | } |
| 226 | |
| 227 | /*================================================*/ |
| 228 | /* issue 2002: Waveshare */ |
| 229 | |
| 230 | #ifdef SAME_AS_ADAFRUIT |
| 231 | /* timing from SSD1306 */ |
| 232 | static const u8x8_display_info_t u8x8_ssd1305_128x32_waveshare_display_info = |
| 233 | { |
| 234 | /* chip_enable_level = */ 0, |
| 235 | /* chip_disable_level = */ 1, |
| 236 | |
| 237 | /* post_chip_enable_wait_ns = */ 20, |
| 238 | /* pre_chip_disable_wait_ns = */ 10, |
| 239 | /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */ |
| 240 | /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */ |
| 241 | /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */ |
| 242 | /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 243 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 244 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 245 | /* i2c_bus_clock_100kHz = */ 4, |
| 246 | /* data_setup_time_ns = */ 40, |
| 247 | /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */ |
| 248 | /* tile_width = */ 16, |
| 249 | /* tile_height = */ 4, |
| 250 | /* default_x_offset = */ 4, |
| 251 | /* flipmode_x_offset = */ 0, |
| 252 | /* pixel_width = */ 128, |
| 253 | /* pixel_height = */ 32 |
| 254 | }; |
| 255 | |
| 256 | uint8_t u8x8_d_ssd1305_128x32_waveshare(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 257 | { |
| 258 | |
| 259 | if ( u8x8_d_ssd1305_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 260 | return 1; |
| 261 | |
| 262 | switch(msg) |
| 263 | { |
| 264 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 265 | if ( arg_int == 0 ) |
| 266 | { |
| 267 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip0_seq); |
| 268 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip1_seq); |
| 273 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 274 | } |
| 275 | break; |
| 276 | case U8X8_MSG_DISPLAY_INIT: |
| 277 | u8x8_d_helper_display_init(u8x8); |
| 278 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_noname_init_seq); |
| 279 | break; |
| 280 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 281 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1305_128x32_waveshare_display_info); |
| 282 | break; |
| 283 | default: |
| 284 | return 0; |
| 285 | } |
| 286 | return 1; |
| 287 | } |
| 288 | #endif |
| 289 | |
| 290 | |
| 291 | /*================================================*/ |
| 292 | /* adafruit 128x32 SSD1305 OLED, https://www.adafruit.com/product/2675 */ |
| 293 | /* issue 724 */ |
| 294 | |
| 295 | /* timing from SSD1306 */ |
| 296 | static const u8x8_display_info_t u8x8_ssd1305_128x32_adafruit_display_info = |
| 297 | { |
| 298 | /* chip_enable_level = */ 0, |
| 299 | /* chip_disable_level = */ 1, |
| 300 | |
| 301 | /* post_chip_enable_wait_ns = */ 20, |
| 302 | /* pre_chip_disable_wait_ns = */ 10, |
| 303 | /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */ |
| 304 | /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */ |
| 305 | /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */ |
| 306 | /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 307 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 308 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 309 | /* i2c_bus_clock_100kHz = */ 4, |
| 310 | /* data_setup_time_ns = */ 40, |
| 311 | /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */ |
| 312 | /* tile_width = */ 16, |
| 313 | /* tile_height = */ 4, |
| 314 | /* default_x_offset = */ 4, |
| 315 | /* flipmode_x_offset = */ 0, |
| 316 | /* pixel_width = */ 128, |
| 317 | /* pixel_height = */ 32 |
| 318 | }; |
| 319 | |
| 320 | |
| 321 | uint8_t u8x8_d_ssd1305_128x32_adafruit(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 322 | { |
| 323 | |
| 324 | if ( u8x8_d_ssd1305_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 325 | return 1; |
| 326 | |
| 327 | switch(msg) |
| 328 | { |
| 329 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 330 | if ( arg_int == 0 ) |
| 331 | { |
| 332 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip0_seq); |
| 333 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip1_seq); |
| 338 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 339 | } |
| 340 | break; |
| 341 | case U8X8_MSG_DISPLAY_INIT: |
| 342 | u8x8_d_helper_display_init(u8x8); |
| 343 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_noname_init_seq); |
| 344 | break; |
| 345 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 346 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1305_128x32_adafruit_display_info); |
| 347 | break; |
| 348 | default: |
| 349 | return 0; |
| 350 | } |
| 351 | return 1; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | /*================================================*/ |
| 358 | /* adafruit SSD1305 OLED */ |
| 359 | |
| 360 | /* timing from SSD1306 */ |
| 361 | static const u8x8_display_info_t u8x8_ssd1305_128x64_adafruit_display_info = |
| 362 | { |
| 363 | /* chip_enable_level = */ 0, |
| 364 | /* chip_disable_level = */ 1, |
| 365 | |
| 366 | /* post_chip_enable_wait_ns = */ 20, |
| 367 | /* pre_chip_disable_wait_ns = */ 10, |
| 368 | /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */ |
| 369 | /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */ |
| 370 | /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */ |
| 371 | /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 372 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 373 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 374 | /* i2c_bus_clock_100kHz = */ 4, |
| 375 | /* data_setup_time_ns = */ 40, |
| 376 | /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */ |
| 377 | /* tile_width = */ 16, |
| 378 | /* tile_height = */ 8, |
| 379 | /* default_x_offset = */ 2, |
| 380 | /* flipmode_x_offset = */ 2, |
| 381 | /* pixel_width = */ 128, |
| 382 | /* pixel_height = */ 64 |
| 383 | }; |
| 384 | |
| 385 | |
| 386 | static const uint8_t u8x8_d_ssd1305_128x64_adafruit_init_seq[] = { |
| 387 | |
| 388 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 389 | |
| 390 | |
| 391 | U8X8_C(0x0ae), /* display off */ |
| 392 | U8X8_CA(0x0d5, 0x0f0), /* clock divide ratio (0x00=1) and oscillator frequency */ |
| 393 | U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */ |
| 394 | U8X8_CA(0x0d3, 0x040), /* display offset to 32 */ |
| 395 | U8X8_C(0x040), /* set display start line to 0 */ |
| 396 | U8X8_CA(0x020, 0x000), /* horizontal addressing mode */ |
| 397 | |
| 398 | U8X8_C(0x0a1), /* segment remap a0/a1*/ |
| 399 | U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */ |
| 400 | // Flipmode |
| 401 | // U8X8_C(0x0a0), /* segment remap a0/a1*/ |
| 402 | // U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */ |
| 403 | |
| 404 | U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */ |
| 405 | |
| 406 | U8X8_CA(0x081, 0x032), /* [2] set contrast control */ |
| 407 | U8X8_CA(0x082, 0x080), /* set area brightness (reset=0x080) */ |
| 408 | U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/ |
| 409 | U8X8_CA(0x0db, 0x040), /* vcomh deselect level */ |
| 410 | // if vcomh is 0, then this will give the biggest range for contrast control issue #98 |
| 411 | // restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116 |
| 412 | |
| 413 | U8X8_C(0x02e), /* Deactivate scroll */ |
| 414 | U8X8_C(0x0a4), /* output ram to display */ |
| 415 | U8X8_C(0x0a6), /* none inverted normal display mode */ |
| 416 | |
| 417 | U8X8_END_TRANSFER(), /* disable chip */ |
| 418 | U8X8_END() /* end of sequence */ |
| 419 | }; |
| 420 | |
| 421 | |
| 422 | uint8_t u8x8_d_ssd1305_128x64_adafruit(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 423 | { |
| 424 | |
| 425 | if ( u8x8_d_ssd1305_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 426 | return 1; |
| 427 | |
| 428 | switch(msg) |
| 429 | { |
| 430 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 431 | if ( arg_int == 0 ) |
| 432 | { |
| 433 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip0_seq); |
| 434 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip1_seq); |
| 439 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 440 | } |
| 441 | break; |
| 442 | case U8X8_MSG_DISPLAY_INIT: |
| 443 | u8x8_d_helper_display_init(u8x8); |
| 444 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x64_adafruit_init_seq); |
| 445 | break; |
| 446 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 447 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1305_128x64_adafruit_display_info); |
| 448 | break; |
| 449 | default: |
| 450 | return 0; |
| 451 | } |
| 452 | return 1; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /*================================================*/ |
| 457 | /* Raystar RET012864 OLED, issue https://github.com/olikraus/u8g2/issues/1111 */ |
| 458 | |
| 459 | static const u8x8_display_info_t u8x8_ssd1305_128x64_raystar_display_info = |
| 460 | { |
| 461 | /* chip_enable_level = */ 0, |
| 462 | /* chip_disable_level = */ 1, |
| 463 | |
| 464 | /* post_chip_enable_wait_ns = */ 20, |
| 465 | /* pre_chip_disable_wait_ns = */ 10, |
| 466 | /* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */ |
| 467 | /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */ |
| 468 | /* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */ |
| 469 | /* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 470 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 471 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 472 | /* i2c_bus_clock_100kHz = */ 4, |
| 473 | /* data_setup_time_ns = */ 40, |
| 474 | /* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */ |
| 475 | /* tile_width = */ 16, |
| 476 | /* tile_height = */ 8, |
| 477 | /* default_x_offset = */ 4, |
| 478 | /* flipmode_x_offset = */ 0, |
| 479 | /* pixel_width = */ 128, |
| 480 | /* pixel_height = */ 64 |
| 481 | }; |
| 482 | |
| 483 | uint8_t u8x8_d_ssd1305_128x64_raystar(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 484 | { |
| 485 | |
| 486 | if ( u8x8_d_ssd1305_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 487 | return 1; |
| 488 | |
| 489 | switch(msg) |
| 490 | { |
| 491 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 492 | if ( arg_int == 0 ) |
| 493 | { |
| 494 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip0_seq); |
| 495 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x32_flip1_seq); |
| 500 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 501 | } |
| 502 | break; |
| 503 | case U8X8_MSG_DISPLAY_INIT: |
| 504 | u8x8_d_helper_display_init(u8x8); |
| 505 | u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1305_128x64_adafruit_init_seq); |
| 506 | break; |
| 507 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 508 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1305_128x64_raystar_display_info); |
| 509 | break; |
| 510 | default: |
| 511 | return 0; |
| 512 | } |
| 513 | return 1; |
| 514 | } |