| 1 | /* |
| 2 | |
| 3 | u8x8_d_ist3088.c |
| 4 | |
| 5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
| 6 | |
| 7 | Copyright (c) 2019, 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 | IST3088: 320x240 monochrome LCD, 16 gray levels with B/W mode |
| 36 | |
| 37 | https://github.com/olikraus/u8g2/issues/1887 |
| 38 | |
| 39 | CAD: 011 |
| 40 | commands and arg/data are always 16 bit, MSB first |
| 41 | |
| 42 | */ |
| 43 | |
| 44 | |
| 45 | #include "u8x8.h" |
| 46 | |
| 47 | /* powersave: maybe we could go to sleep mode, see register 3 */ |
| 48 | static const uint8_t u8x8_d_ist3088_320x240_powersave0_seq[] = { |
| 49 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 50 | U8X8_CCAA(0x0, 0x07, 0x00, 0x01), // Display Control Bit 2: BW, 1: Invert, 0: Display enable |
| 51 | U8X8_END_TRANSFER(), /* disable chip */ |
| 52 | U8X8_END() /* end of sequence */ |
| 53 | }; |
| 54 | |
| 55 | static const uint8_t u8x8_d_ist3088_320x240_powersave1_seq[] = { |
| 56 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 57 | U8X8_CCAA(0x0, 0x07, 0x00, 0x00), // Display Control Bit 2: BW, 1: Invert, 0: Display enable |
| 58 | U8X8_END_TRANSFER(), /* disable chip */ |
| 59 | U8X8_END() /* end of sequence */ |
| 60 | }; |
| 61 | |
| 62 | static const uint8_t u8x8_d_ist3088_320x240_flip0_seq[] = { |
| 63 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 64 | U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty |
| 65 | U8X8_END_TRANSFER(), /* disable chip */ |
| 66 | U8X8_END() /* end of sequence */ |
| 67 | }; |
| 68 | |
| 69 | static const uint8_t u8x8_d_ist3088_320x240_flip1_seq[] = { |
| 70 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 71 | U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty |
| 72 | U8X8_END_TRANSFER(), /* disable chip */ |
| 73 | U8X8_END() /* end of sequence */ |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | /*===================================================*/ |
| 80 | |
| 81 | static uint8_t u8x8_d_ist3088_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 82 | { |
| 83 | //uint16_t x; |
| 84 | int i; |
| 85 | uint8_t y; |
| 86 | uint8_t c; |
| 87 | uint8_t *ptr; |
| 88 | switch(msg) |
| 89 | { |
| 90 | /* handled by the calling function |
| 91 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 92 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist3088_320x240_display_info); |
| 93 | break; |
| 94 | */ |
| 95 | /* handled by the calling function |
| 96 | case U8X8_MSG_DISPLAY_INIT: |
| 97 | u8x8_d_helper_display_init(u8x8); |
| 98 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_init_seq); |
| 99 | break; |
| 100 | */ |
| 101 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 102 | if ( arg_int == 0 ) |
| 103 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_powersave0_seq); |
| 104 | else |
| 105 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_powersave1_seq); |
| 106 | break; |
| 107 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 108 | if ( arg_int == 0 ) |
| 109 | { |
| 110 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_flip0_seq); |
| 111 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_flip1_seq); |
| 116 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 117 | } |
| 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, 0x00 ); |
| 123 | u8x8_cad_SendCmd(u8x8, 0x05 ); |
| 124 | u8x8_cad_SendArg(u8x8, 0 ); |
| 125 | u8x8_cad_SendArg(u8x8, arg_int ); |
| 126 | u8x8_cad_EndTransfer(u8x8); |
| 127 | break; |
| 128 | #endif |
| 129 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 130 | /* |
| 131 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 132 | x *= 8; |
| 133 | x += u8x8->x_offset; |
| 134 | */ |
| 135 | |
| 136 | y = (((u8x8_tile_t *)arg_ptr)->y_pos); |
| 137 | y*=8; |
| 138 | |
| 139 | u8x8_cad_StartTransfer(u8x8); |
| 140 | |
| 141 | |
| 142 | c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */ |
| 143 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */ |
| 144 | for( i = 0; i < 8; i++ ) |
| 145 | { |
| 146 | u8x8_cad_SendCmd(u8x8, 0x0); |
| 147 | u8x8_cad_SendCmd(u8x8, 0x8); |
| 148 | u8x8_cad_SendArg(u8x8, y); |
| 149 | u8x8_cad_SendArg(u8x8, 0 ); |
| 150 | |
| 151 | |
| 152 | u8x8_cad_SendCmd(u8x8, 0x0); // write data |
| 153 | u8x8_cad_SendCmd(u8x8, 0x9); // write data |
| 154 | |
| 155 | |
| 156 | //c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */ |
| 157 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes, send one line of data */ |
| 158 | |
| 159 | ptr += u8x8->display_info->tile_width; |
| 160 | y ++; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | u8x8_cad_EndTransfer(u8x8); |
| 165 | break; |
| 166 | default: |
| 167 | return 0; |
| 168 | } |
| 169 | return 1; |
| 170 | } |
| 171 | |
| 172 | /*===================================================*/ |
| 173 | |
| 174 | /* |
| 175 | SdCmd(0x01); // driver control |
| 176 | SdData(0x00); SdData(0x00); // c1-->c240 s1-->s240 duty=1/240 |
| 177 | SdCmd(0x02); // driver control |
| 178 | SdData(0x01); SdData(0x4c); //0x15 |
| 179 | SdCmd(0x03); // power control |
| 180 | SdData(0x00); SdData(0x70); // VC VR Vf=1 |
| 181 | SdCmd(0x04); // power control |
| 182 | SdData(0x04); SdData(0x61); //0x61 //1/14b |
| 183 | SdCmd(0x05); // CT control |
| 184 | SdData(0x00); SdData(0x6a); // 0X76 |
| 185 | SdCmd(0x06); // CT control |
| 186 | SdData(0x00); SdData(0x03); |
| 187 | SdCmd(0x23); // B/W MODE,16G NEED REMOVE |
| 188 | SdData(0x00); SdData(0x04); //04:mono |
| 189 | SdCmd(0x28); // OSC |
| 190 | SdData(0x00); SdData(0x0c); |
| 191 | SdCmd(0x37); |
| 192 | SdData(0x00); SdData(0x12); |
| 193 | SdCmd(0x07); |
| 194 | SdData(0x00); SdData(0x01); |
| 195 | */ |
| 196 | |
| 197 | /* https://github.com/olikraus/u8g2/issues/1887 */ |
| 198 | static const uint8_t u8x8_d_ist3088_320x240_init_seq[] = { |
| 199 | |
| 200 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 201 | |
| 202 | /* disableLCD */ |
| 203 | U8X8_CCAA(0x0, 0x07, 0x00, 0x00), // Display Control Bit 2: BW, 1: Invert, 0: Display enable |
| 204 | |
| 205 | U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty |
| 206 | U8X8_CCAA(0x0, 0x02, 0x01, 0x4c), // Polarity Control |
| 207 | |
| 208 | U8X8_CCAA(0x0, 0x06, 0x00, 0x03), // Entry mode: h/v increment |
| 209 | //U8X8_CCAA(0x0, 0x04, 0x07, 0x61), // Power Control 2: 0x07: 1/16 Bias, Vout1 x 4 |
| 210 | U8X8_CCAA(0x0, 0x04, 0x04, 0x61), // Power Control 2: 0x07: 1/16 Bias, Vout1 x 4 |
| 211 | U8X8_CCAA(0x0, 0x05, 0x00, 0x6a), // Contrast, 0..255, |
| 212 | |
| 213 | U8X8_CCAA(0x0, 0x03, 0x00, 0x40), // Enable voltage converter |
| 214 | U8X8_DLY(10), |
| 215 | U8X8_CCAA(0x0, 0x03, 0x00, 0x60), // Enable voltage regulator |
| 216 | U8X8_DLY(10), |
| 217 | U8X8_CCAA(0x0, 0x03, 0x00, 0x70), // Enable voltage follower |
| 218 | U8X8_DLY(10), |
| 219 | |
| 220 | U8X8_CCAA(0x0, 0x23, 0x00, 0x04), // Monochrome mode |
| 221 | U8X8_CCAA(0x0, 0x28, 0x00, 0x0c), // Frame Rate Control |
| 222 | U8X8_CCAA(0x0, 0x37, 0x00, 0x01), // Frame Rate Control |
| 223 | U8X8_CCAA(0x0, 0x0d, 39, 0x00), // X End and X Start |
| 224 | |
| 225 | U8X8_CCAA(0x0, 0x0e, 239, 0x00), // Y End and Y Start |
| 226 | |
| 227 | /* enable LCD (will be done by powersave0) */ |
| 228 | //U8X8_CCAA(0x0, 0x07, 0x00, 0x01), // Display Control Bit 2: BW, 1: Invert, 0: Display enable |
| 229 | |
| 230 | U8X8_END_TRANSFER(), /* disable chip */ |
| 231 | U8X8_END() /* end of sequence */ |
| 232 | }; |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | static const u8x8_display_info_t u8x8_ist3088_320x240_display_info = |
| 238 | { |
| 239 | /* chip_enable_level = */ 0, |
| 240 | /* chip_disable_level = */ 1, |
| 241 | |
| 242 | /* post_chip_enable_wait_ns = */ 110, |
| 243 | /* pre_chip_disable_wait_ns = */ 110, |
| 244 | /* reset_pulse_width_ms = */ 10, |
| 245 | /* post_reset_wait_ms = */ 10, /**/ |
| 246 | /* sda_setup_time_ns = */ 110, /* */ |
| 247 | /* sck_pulse_width_ns = */ 125, /* */ |
| 248 | /* sck_clock_hz = */ 4000000UL, /* 250ns cycle, see page 49 of the IST3088 datasheet*/ |
| 249 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 250 | /* i2c_bus_clock_100kHz = */ 4, /* 400KHz, IST8033 das not include a I2C interface */ |
| 251 | /* data_setup_time_ns = */ 70, |
| 252 | /* write_pulse_width_ns = */ 60, |
| 253 | /* tile_width = */ 40, |
| 254 | /* tile_height = */ 30, |
| 255 | /* default_x_offset = */ 0, |
| 256 | /* flipmode_x_offset = */ 0, |
| 257 | /* pixel_width = */ 320, |
| 258 | /* pixel_height = */ 240 |
| 259 | }; |
| 260 | |
| 261 | uint8_t u8x8_d_ist3088_320x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 262 | { |
| 263 | |
| 264 | if ( u8x8_d_ist3088_generic(u8x8, msg, arg_int, arg_ptr) != 0 ) |
| 265 | return 1; |
| 266 | |
| 267 | switch(msg) |
| 268 | { |
| 269 | case U8X8_MSG_DISPLAY_INIT: |
| 270 | u8x8_d_helper_display_init(u8x8); |
| 271 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_init_seq); |
| 272 | break; |
| 273 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 274 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist3088_320x240_display_info); |
| 275 | break; |
| 276 | default: |
| 277 | return 0; |
| 278 | } |
| 279 | return 1; |
| 280 | } |