| 1 | /* |
| 2 | |
| 3 | u8x8_d_uc1604.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 | |
| 42 | |
| 43 | static const uint8_t u8x8_d_uc1604_powersave0_seq[] = { |
| 44 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 45 | U8X8_DLY(20), |
| 46 | U8X8_C(0x0af), /* display on */ |
| 47 | U8X8_DLY(20), /* during setup, it seems that the startup is more reliable when sending this cmd twice */ |
| 48 | U8X8_C(0x0af), /* display on */ |
| 49 | U8X8_DLY(50), /* startup takes some time */ |
| 50 | U8X8_END_TRANSFER(), /* disable chip */ |
| 51 | U8X8_END() /* end of sequence */ |
| 52 | }; |
| 53 | |
| 54 | static const uint8_t u8x8_d_uc1604_powersave1_seq[] = { |
| 55 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 56 | U8X8_C(0x0ae), /* display off, enter sleep mode */ |
| 57 | U8X8_END_TRANSFER(), /* disable chip */ |
| 58 | U8X8_END() /* end of sequence */ |
| 59 | }; |
| 60 | |
| 61 | static const uint8_t u8x8_d_uc1604_flip0_seq[] = { |
| 62 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 63 | U8X8_C(0x0c4), /* LCD Mapping */ |
| 64 | U8X8_END_TRANSFER(), /* disable chip */ |
| 65 | U8X8_END() /* end of sequence */ |
| 66 | }; |
| 67 | |
| 68 | static const uint8_t u8x8_d_uc1604_flip1_seq[] = { |
| 69 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 70 | U8X8_C(0x0c2), /* LCD Mapping */ |
| 71 | U8X8_END_TRANSFER(), /* disable chip */ |
| 72 | U8X8_END() /* end of sequence */ |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | uint8_t u8x8_d_uc1604_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 77 | { |
| 78 | uint8_t x, y, c; |
| 79 | uint8_t *ptr; |
| 80 | switch(msg) |
| 81 | { |
| 82 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 83 | u8x8_cad_StartTransfer(u8x8); |
| 84 | |
| 85 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 86 | x *= 8; |
| 87 | |
| 88 | u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); |
| 89 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); |
| 90 | |
| 91 | y = ((u8x8_tile_t *)arg_ptr)->y_pos; |
| 92 | y += u8x8->x_offset; |
| 93 | u8x8_cad_SendCmd(u8x8, 0x0b0 | (y&15)); |
| 94 | |
| 95 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 96 | c *= 8; |
| 97 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 98 | do |
| 99 | { |
| 100 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */ |
| 101 | arg_int--; |
| 102 | } while( arg_int > 0 ); |
| 103 | |
| 104 | u8x8_cad_EndTransfer(u8x8); |
| 105 | break; |
| 106 | /* handled in the calling procedure |
| 107 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 108 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_128x64_display_info); |
| 109 | break; |
| 110 | case U8X8_MSG_DISPLAY_INIT: |
| 111 | u8x8_d_helper_display_init(u8x8); |
| 112 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1701_dogs102_init_seq); |
| 113 | break; |
| 114 | */ |
| 115 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 116 | if ( arg_int == 0 ) |
| 117 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_powersave0_seq); |
| 118 | else |
| 119 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_powersave1_seq); |
| 120 | break; |
| 121 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 122 | if ( arg_int == 0 ) |
| 123 | { |
| 124 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_flip0_seq); |
| 125 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_flip1_seq); |
| 130 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 131 | } |
| 132 | break; |
| 133 | #ifdef U8X8_WITH_SET_CONTRAST |
| 134 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 135 | u8x8_cad_StartTransfer(u8x8); |
| 136 | u8x8_cad_SendCmd(u8x8, 0x081 ); |
| 137 | u8x8_cad_SendArg(u8x8, arg_int ); /* uc1604 has range from 0 to 255 */ |
| 138 | u8x8_cad_EndTransfer(u8x8); |
| 139 | break; |
| 140 | #endif |
| 141 | default: |
| 142 | return 0; |
| 143 | } |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | /*================================================*/ |
| 148 | /* JLX12864 */ |
| 149 | |
| 150 | /* |
| 151 | timings from uc1604 |
| 152 | |
| 153 | UC1604 has two chip select inputs (CS0 and CS1). |
| 154 | CS0 is low active, CS1 is high active. It will depend on the display |
| 155 | module whether the display has a is low or high active chip select. |
| 156 | |
| 157 | */ |
| 158 | static const u8x8_display_info_t u8x8_uc1604_128x64_display_info = |
| 159 | { |
| 160 | /* chip_enable_level = */ 0, /* JLX12864G uses CS0, which is low active CS*/ |
| 161 | /* chip_disable_level = */ 1, |
| 162 | |
| 163 | /* post_chip_enable_wait_ns = */ 20, |
| 164 | /* pre_chip_disable_wait_ns = */ 20, |
| 165 | /* reset_pulse_width_ms = */ 1, |
| 166 | /* post_reset_wait_ms = */ 10, |
| 167 | /* sda_setup_time_ns = */ 30, |
| 168 | /* sck_pulse_width_ns = */ 65, /* half of cycle time */ |
| 169 | /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 170 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 171 | /* i2c_bus_clock_100kHz = */ 4, |
| 172 | /* data_setup_time_ns = */ 30, |
| 173 | /* write_pulse_width_ns = */ 35, |
| 174 | /* tile_width = */ 16, /* width of 24*8=192 pixel */ |
| 175 | /* tile_height = */ 8, |
| 176 | /* default_x_offset = */ 0, /* reused as y page offset */ |
| 177 | /* flipmode_x_offset = */ 0, /* reused as y page offset */ |
| 178 | /* pixel_width = */ 128, |
| 179 | /* pixel_height = */ 64 |
| 180 | }; |
| 181 | |
| 182 | static const uint8_t u8x8_d_uc1604_jlx12864_init_seq[] = { |
| 183 | |
| 184 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 185 | |
| 186 | U8X8_C(0x0e2), /* soft reset */ |
| 187 | U8X8_DLY(200), |
| 188 | U8X8_DLY(200), |
| 189 | |
| 190 | U8X8_C(0x02f), /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */ |
| 191 | U8X8_DLY(200), |
| 192 | U8X8_DLY(200), |
| 193 | |
| 194 | U8X8_CA(0x081, 0x038), /* set contrast, JLX19264G suggestion: 0x045 */ |
| 195 | U8X8_C(0x0eb), /* LCD bias Bits 0/1: 00=6 01=7, 10=8, 11=9 */ |
| 196 | |
| 197 | |
| 198 | //U8X8_C(0x023), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */ |
| 199 | //U8X8_C(0x027), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */ |
| 200 | |
| 201 | U8X8_C(0x0c2), /* Map control, Bit 2: MY=1, Bit 1: MX=0 */ |
| 202 | U8X8_C(0x0a0), /* 0xa0: 76Hz FPS, controller default: 0x0a1: 95Hz FPS */ |
| 203 | |
| 204 | |
| 205 | U8X8_C(0x040), /* set scroll line to 0 */ |
| 206 | U8X8_C(0x089), /* RAM access control (controller default: 0x089)*/ |
| 207 | |
| 208 | |
| 209 | U8X8_C(0x000), /* column low nibble */ |
| 210 | U8X8_C(0x010), /* column high nibble */ |
| 211 | U8X8_C(0x0b0), /* page adr */ |
| 212 | |
| 213 | |
| 214 | U8X8_END_TRANSFER(), /* disable chip */ |
| 215 | U8X8_END() /* end of sequence */ |
| 216 | }; |
| 217 | |
| 218 | uint8_t u8x8_d_uc1604_jlx12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 219 | { |
| 220 | /* call common procedure first and handle messages there */ |
| 221 | if ( u8x8_d_uc1604_common(u8x8, msg, arg_int, arg_ptr) == 0 ) |
| 222 | { |
| 223 | /* msg not handled, then try here */ |
| 224 | switch(msg) |
| 225 | { |
| 226 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 227 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_128x64_display_info); |
| 228 | break; |
| 229 | case U8X8_MSG_DISPLAY_INIT: |
| 230 | u8x8_d_helper_display_init(u8x8); |
| 231 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_jlx12864_init_seq); |
| 232 | break; |
| 233 | default: |
| 234 | return 0; /* msg unknown */ |
| 235 | } |
| 236 | } |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | /*================================================*/ |
| 241 | /* JLX19264 */ |
| 242 | |
| 243 | /* |
| 244 | timings from uc1608 |
| 245 | |
| 246 | UC1604 has two chip select inputs (CS0 and CS1). |
| 247 | CS0 is low active, CS1 is high active. It will depend on the display |
| 248 | module whether the display has a is low or high active chip select. |
| 249 | |
| 250 | */ |
| 251 | static const u8x8_display_info_t u8x8_uc1604_192x64_display_info = |
| 252 | { |
| 253 | /* chip_enable_level = */ 0, /* JLX19264G uses CS0, which is low active CS*/ |
| 254 | /* chip_disable_level = */ 1, |
| 255 | |
| 256 | /* post_chip_enable_wait_ns = */ 20, |
| 257 | /* pre_chip_disable_wait_ns = */ 20, |
| 258 | /* reset_pulse_width_ms = */ 1, |
| 259 | /* post_reset_wait_ms = */ 10, |
| 260 | /* sda_setup_time_ns = */ 30, |
| 261 | /* sck_pulse_width_ns = */ 65, /* half of cycle time */ |
| 262 | /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 263 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 264 | /* i2c_bus_clock_100kHz = */ 4, |
| 265 | /* data_setup_time_ns = */ 30, |
| 266 | /* write_pulse_width_ns = */ 35, |
| 267 | /* tile_width = */ 24, /* width of 24*8=192 pixel */ |
| 268 | /* tile_height = */ 8, |
| 269 | /* default_x_offset = */ 0, /* reused as y page offset */ |
| 270 | /* flipmode_x_offset = */ 0, /* reused as y page offset */ |
| 271 | /* pixel_width = */ 192, |
| 272 | /* pixel_height = */ 64 |
| 273 | }; |
| 274 | |
| 275 | static const uint8_t u8x8_d_uc1604_jlx19264_init_seq[] = { |
| 276 | |
| 277 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 278 | |
| 279 | U8X8_C(0x0e2), /* soft reset */ |
| 280 | U8X8_DLY(200), |
| 281 | U8X8_DLY(200), |
| 282 | |
| 283 | U8X8_C(0x02f), /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */ |
| 284 | U8X8_DLY(200), |
| 285 | U8X8_DLY(200), |
| 286 | |
| 287 | U8X8_CA(0x081, 0x052), /* set contrast, JLX19264G suggestion: 0x045 */ |
| 288 | U8X8_C(0x0eb), /* LCD bias Bits 0/1: 00=6 01=7, 10=8, 11=9 */ |
| 289 | |
| 290 | |
| 291 | //U8X8_C(0x023), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */ |
| 292 | //U8X8_C(0x027), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */ |
| 293 | |
| 294 | U8X8_C(0x0c4), /* Map control, Bit 2: MY=1, Bit 1: MX=0 */ |
| 295 | U8X8_C(0x0a0), /* 0xa0: 76Hz FPS, controller default: 0x0a1: 95Hz FPS */ |
| 296 | |
| 297 | |
| 298 | U8X8_C(0x040), /* set scroll line to 0 */ |
| 299 | U8X8_C(0x089), /* RAM access control (controller default: 0x089)*/ |
| 300 | |
| 301 | |
| 302 | U8X8_C(0x000), /* column low nibble */ |
| 303 | U8X8_C(0x010), /* column high nibble */ |
| 304 | U8X8_C(0x0b0), /* page adr */ |
| 305 | |
| 306 | |
| 307 | U8X8_END_TRANSFER(), /* disable chip */ |
| 308 | U8X8_END() /* end of sequence */ |
| 309 | }; |
| 310 | |
| 311 | uint8_t u8x8_d_uc1604_jlx19264(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 312 | { |
| 313 | /* call common procedure first and handle messages there */ |
| 314 | if ( u8x8_d_uc1604_common(u8x8, msg, arg_int, arg_ptr) == 0 ) |
| 315 | { |
| 316 | /* msg not handled, then try here */ |
| 317 | switch(msg) |
| 318 | { |
| 319 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 320 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_192x64_display_info); |
| 321 | break; |
| 322 | case U8X8_MSG_DISPLAY_INIT: |
| 323 | u8x8_d_helper_display_init(u8x8); |
| 324 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_jlx19264_init_seq); |
| 325 | break; |
| 326 | default: |
| 327 | return 0; /* msg unknown */ |
| 328 | } |
| 329 | } |
| 330 | return 1; |
| 331 | } |
| 332 | |
| 333 | |