| 1 | /* |
| 2 | |
| 3 | u8x8_d_uc1601.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 | This is for the uc1601s controller |
| 35 | |
| 36 | |
| 37 | */ |
| 38 | #include "u8x8.h" |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | static const uint8_t u8x8_d_uc1601_128x32_powersave0_seq[] = { |
| 44 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 45 | U8X8_C(0x0af), /* display on */ |
| 46 | U8X8_END_TRANSFER(), /* disable chip */ |
| 47 | U8X8_END() /* end of sequence */ |
| 48 | }; |
| 49 | |
| 50 | static const uint8_t u8x8_d_uc1601_128x32_powersave1_seq[] = { |
| 51 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 52 | U8X8_C(0x0ae), /* display off */ |
| 53 | U8X8_END_TRANSFER(), /* disable chip */ |
| 54 | U8X8_END() /* end of sequence */ |
| 55 | }; |
| 56 | |
| 57 | static const uint8_t u8x8_d_uc1601_128x32_flip0_seq[] = { |
| 58 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 59 | U8X8_C(0x0c4), /* bit 1: MX, bit 2: MY */ |
| 60 | U8X8_C(0x060), /* set display start line to 32 */ |
| 61 | U8X8_END_TRANSFER(), /* disable chip */ |
| 62 | U8X8_END() /* end of sequence */ |
| 63 | }; |
| 64 | |
| 65 | static const uint8_t u8x8_d_uc1601_128x32_flip1_seq[] = { |
| 66 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 67 | U8X8_C(0x0c2), /* bit 1: MX, bit 2: MY */ |
| 68 | U8X8_C(0x040), /* set display start line to 0 */ |
| 69 | U8X8_END_TRANSFER(), /* disable chip */ |
| 70 | U8X8_END() /* end of sequence */ |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | static const u8x8_display_info_t u8x8_uc1601_128x32_display_info = |
| 75 | { |
| 76 | /* chip_enable_level = */ 0, |
| 77 | /* chip_disable_level = */ 1, |
| 78 | |
| 79 | /* post_chip_enable_wait_ns = */ 1, /* uc1601 datasheet, page 46 */ |
| 80 | /* pre_chip_disable_wait_ns = */ 5, /* uc1601 datasheet, page 46 */ |
| 81 | /* reset_pulse_width_ms = */ 1, |
| 82 | /* post_reset_wait_ms = */ 6, |
| 83 | /* sda_setup_time_ns = */ 12, /* uc1601 datasheet, page 44 */ |
| 84 | /* sck_pulse_width_ns = */ 15, /* uc1601 datasheet, page 44 */ |
| 85 | /* sck_clock_hz = */ 2000000UL, /* */ |
| 86 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 87 | /* i2c_bus_clock_100kHz = */ 1, |
| 88 | /* data_setup_time_ns = */ 60, /* uc1601 datasheet, page 43 */ |
| 89 | /* write_pulse_width_ns = */ 80, /* uc1601 datasheet, page 43 */ |
| 90 | /* tile_width = */ 16, |
| 91 | /* tile_height = */ 4, |
| 92 | /* default_x_offset = */ 0, |
| 93 | /* flipmode_x_offset = */ 4, |
| 94 | /* pixel_width = */ 128, |
| 95 | /* pixel_height = */ 32 |
| 96 | }; |
| 97 | |
| 98 | static const uint8_t u8x8_d_uc1601_128x32_init_seq[] = { |
| 99 | |
| 100 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 101 | |
| 102 | U8X8_C(0x0e2), /* soft reset */ |
| 103 | U8X8_C(0x0eb), /* LCD Bias: 0xe8: 6, 0xe9: 7, 0xea: 8, 0xeb: 9 */ |
| 104 | //U8X8_C(0x023), /* 0x020...0x023 only for UC1601, not for UC1601s */ |
| 105 | |
| 106 | |
| 107 | //U8X8_C(0x02e), /* LCD Load + Internal Charge Pump (default: 0x2e) */ |
| 108 | U8X8_C(0x024), /* Temperature Compenstation, default: 0x24 */ |
| 109 | U8X8_C(0x089), /* RAM address ctrl, default: 0x89 */ |
| 110 | U8X8_C(0x0c4), /* RAM mapping ctrl */ |
| 111 | U8X8_C(0x0a0), /* Frame Rate, 0x0a0 or 0x0a1 */ |
| 112 | U8X8_CA(0x081, 0x0df), /* set contrast */ |
| 113 | U8X8_C(0x02e), /* LCD Load + Internal Charge Pump (default: 0x2e) */ |
| 114 | U8X8_C(0x060), /* set display start line to 32 */ |
| 115 | |
| 116 | U8X8_C(0x0a6), /* normal display */ |
| 117 | |
| 118 | U8X8_END_TRANSFER(), /* disable chip */ |
| 119 | U8X8_END() /* end of sequence */ |
| 120 | }; |
| 121 | |
| 122 | uint8_t u8x8_d_uc1601_128x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 123 | { |
| 124 | uint8_t x, c; |
| 125 | uint8_t *ptr; |
| 126 | switch(msg) |
| 127 | { |
| 128 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 129 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1601_128x32_display_info); |
| 130 | break; |
| 131 | case U8X8_MSG_DISPLAY_INIT: |
| 132 | u8x8_d_helper_display_init(u8x8); |
| 133 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_init_seq); |
| 134 | break; |
| 135 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 136 | if ( arg_int == 0 ) |
| 137 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_powersave0_seq); |
| 138 | else |
| 139 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_powersave1_seq); |
| 140 | break; |
| 141 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 142 | if ( arg_int == 0 ) |
| 143 | { |
| 144 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_flip0_seq); |
| 145 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_flip1_seq); |
| 150 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 151 | } |
| 152 | break; |
| 153 | #ifdef U8X8_WITH_SET_CONTRAST |
| 154 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 155 | u8x8_cad_StartTransfer(u8x8); |
| 156 | u8x8_cad_SendCmd(u8x8, 0x081 ); |
| 157 | u8x8_cad_SendArg(u8x8, arg_int ); /* uc1601 has range from 0 to 255 */ |
| 158 | u8x8_cad_EndTransfer(u8x8); |
| 159 | break; |
| 160 | #endif |
| 161 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 162 | u8x8_cad_StartTransfer(u8x8); |
| 163 | |
| 164 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 165 | x *= 8; |
| 166 | x += u8x8->x_offset; |
| 167 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); |
| 168 | u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); |
| 169 | u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); |
| 170 | |
| 171 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 172 | c *= 8; |
| 173 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 174 | do |
| 175 | { |
| 176 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */ |
| 177 | arg_int--; |
| 178 | } while( arg_int > 0 ); |
| 179 | |
| 180 | u8x8_cad_EndTransfer(u8x8); |
| 181 | break; |
| 182 | default: |
| 183 | return 0; |
| 184 | } |
| 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | /* issue https://github.com/olikraus/u8g2/issues/1501 */ |
| 189 | |
| 190 | static const uint8_t u8x8_d_uc1601_128x64_init_seq[] = { |
| 191 | |
| 192 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 193 | |
| 194 | U8X8_C(0x0e2), /* soft reset */ |
| 195 | U8X8_C(0x0eb), /* LCD Bias: 0xe8: 6, 0xe9: 7, 0xea: 8, 0xeb: 9 */ |
| 196 | //U8X8_C(0x023), /* 0x020...0x023 only for UC1601, not for UC1601s */ |
| 197 | |
| 198 | |
| 199 | //U8X8_C(0x02e), /* LCD Load + Internal Charge Pump (default: 0x2e) */ |
| 200 | U8X8_C(0x024), /* Temperature Compenstation, default: 0x24 */ |
| 201 | U8X8_C(0x089), /* RAM address ctrl, default: 0x89 */ |
| 202 | U8X8_C(0x0c4), /* RAM mapping ctrl */ |
| 203 | U8X8_C(0x0a0), /* Frame Rate, 0x0a0 or 0x0a1 */ |
| 204 | U8X8_CA(0x081, 0x0df), /* set contrast */ |
| 205 | U8X8_C(0x02e), /* LCD Load + Internal Charge Pump (default: 0x2e) */ |
| 206 | U8X8_C(0x040), /* set display start: See Issue 1501 */ |
| 207 | |
| 208 | U8X8_C(0x0a6), /* normal display */ |
| 209 | |
| 210 | U8X8_END_TRANSFER(), /* disable chip */ |
| 211 | U8X8_END() /* end of sequence */ |
| 212 | }; |
| 213 | |
| 214 | static const u8x8_display_info_t u8x8_uc1601_128x64_display_info = |
| 215 | { |
| 216 | /* chip_enable_level = */ 0, |
| 217 | /* chip_disable_level = */ 1, |
| 218 | |
| 219 | /* post_chip_enable_wait_ns = */ 1, /* uc1601 datasheet, page 46 */ |
| 220 | /* pre_chip_disable_wait_ns = */ 5, /* uc1601 datasheet, page 46 */ |
| 221 | /* reset_pulse_width_ms = */ 1, |
| 222 | /* post_reset_wait_ms = */ 6, |
| 223 | /* sda_setup_time_ns = */ 12, /* uc1601 datasheet, page 44 */ |
| 224 | /* sck_pulse_width_ns = */ 15, /* uc1601 datasheet, page 44 */ |
| 225 | /* sck_clock_hz = */ 2000000UL, /* */ |
| 226 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 227 | /* i2c_bus_clock_100kHz = */ 1, |
| 228 | /* data_setup_time_ns = */ 60, /* uc1601 datasheet, page 43 */ |
| 229 | /* write_pulse_width_ns = */ 80, /* uc1601 datasheet, page 43 */ |
| 230 | /* tile_width = */ 16, |
| 231 | /* tile_height = */ 8, |
| 232 | /* default_x_offset = */ 2, |
| 233 | /* flipmode_x_offset = */ 4, /* IS THIS CORRECT? */ |
| 234 | /* pixel_width = */ 128, |
| 235 | /* pixel_height = */ 64 |
| 236 | }; |
| 237 | |
| 238 | uint8_t u8x8_d_uc1601_128x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 239 | { |
| 240 | uint8_t x, c; |
| 241 | uint8_t *ptr; |
| 242 | switch(msg) |
| 243 | { |
| 244 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 245 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1601_128x64_display_info); |
| 246 | break; |
| 247 | case U8X8_MSG_DISPLAY_INIT: |
| 248 | u8x8_d_helper_display_init(u8x8); |
| 249 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x64_init_seq); |
| 250 | break; |
| 251 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 252 | if ( arg_int == 0 ) |
| 253 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_powersave0_seq); |
| 254 | else |
| 255 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_powersave1_seq); |
| 256 | break; |
| 257 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 258 | if ( arg_int == 0 ) |
| 259 | { |
| 260 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_flip0_seq); |
| 261 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1601_128x32_flip1_seq); |
| 266 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 267 | } |
| 268 | break; |
| 269 | #ifdef U8X8_WITH_SET_CONTRAST |
| 270 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 271 | u8x8_cad_StartTransfer(u8x8); |
| 272 | u8x8_cad_SendCmd(u8x8, 0x081 ); |
| 273 | u8x8_cad_SendArg(u8x8, arg_int ); /* uc1601 has range from 0 to 255 */ |
| 274 | u8x8_cad_EndTransfer(u8x8); |
| 275 | break; |
| 276 | #endif |
| 277 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 278 | u8x8_cad_StartTransfer(u8x8); |
| 279 | |
| 280 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 281 | x *= 8; |
| 282 | x += u8x8->x_offset; |
| 283 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); |
| 284 | u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); |
| 285 | u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); |
| 286 | |
| 287 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 288 | c *= 8; |
| 289 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 290 | do |
| 291 | { |
| 292 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */ |
| 293 | arg_int--; |
| 294 | } while( arg_int > 0 ); |
| 295 | |
| 296 | u8x8_cad_EndTransfer(u8x8); |
| 297 | break; |
| 298 | default: |
| 299 | return 0; |
| 300 | } |
| 301 | return 1; |
| 302 | } |
| 303 | |
| 304 | |