| 1 | /* |
| 2 | |
| 3 | u8x8_d_uc1609.c |
| 4 | |
| 5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) |
| 6 | |
| 7 | Copyright (c) 2021, 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 | https://github.com/olikraus/u8g2/issues/1565 |
| 36 | |
| 37 | cad001 |
| 38 | |
| 39 | |
| 40 | */ |
| 41 | #include "u8x8.h" |
| 42 | |
| 43 | |
| 44 | static const uint8_t u8x8_d_uc1609_19264_init_seq[] = { |
| 45 | |
| 46 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 47 | |
| 48 | U8X8_CA(0x0f1, 63), /* set COM end (display height-1) */ |
| 49 | U8X8_C(0x0c0), /* SEG & COM normal */ |
| 50 | U8X8_C(0x040), /* set scroll line to zero */ |
| 51 | U8X8_C(0x02e), /* chare pump */ |
| 52 | U8X8_C(0x0eb), /* set bias 1/2 */ |
| 53 | U8X8_CA(0x081, 0x08f), /* set contrast */ |
| 54 | |
| 55 | /* |
| 56 | AC0: 0: stop at boundary, 1: increment by one |
| 57 | AC1: 0: first column then page, 1: first page, then column increment |
| 58 | AC2: 0: increment page adr, 1: decrement page adr. |
| 59 | */ |
| 60 | U8X8_C(0x088), /* set auto increment, low bits are AC2 AC1 AC0 */ |
| 61 | U8X8_C(0x0a1), /* frame rate 95Hz */ |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | LC0: 0 |
| 66 | MX: Mirror X |
| 67 | MY: Mirror Y |
| 68 | */ |
| 69 | U8X8_C(0x0c4), /* low bits are MY, MX, LC0 */ |
| 70 | |
| 71 | U8X8_C(0x0a6), /* set normal pixel mode (not inverse) */ |
| 72 | U8X8_C(0x0a4), /* set normal pixel mode (not all on) */ |
| 73 | |
| 74 | U8X8_END_TRANSFER(), /* disable chip */ |
| 75 | U8X8_END() /* end of sequence */ |
| 76 | }; |
| 77 | |
| 78 | static const uint8_t u8x8_d_uc1609_19264_powersave0_seq[] = { |
| 79 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 80 | U8X8_C(0x0af), /* display on, UC1609 */ |
| 81 | U8X8_END_TRANSFER(), /* disable chip */ |
| 82 | U8X8_END() /* end of sequence */ |
| 83 | }; |
| 84 | |
| 85 | static const uint8_t u8x8_d_uc1609_19264_powersave1_seq[] = { |
| 86 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 87 | U8X8_C(0x0ae), /* display off, UC1609 */ |
| 88 | U8X8_END_TRANSFER(), /* disable chip */ |
| 89 | U8X8_END() /* end of sequence */ |
| 90 | }; |
| 91 | |
| 92 | static const uint8_t u8x8_d_uc1609_19264_flip0_seq[] = { |
| 93 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 94 | /* |
| 95 | LC0: 0 |
| 96 | MX: Mirror X |
| 97 | MY: Mirror Y |
| 98 | */ |
| 99 | U8X8_C(0x0c4), /* low bits are MY, MX, LC0 */ |
| 100 | U8X8_END_TRANSFER(), /* disable chip */ |
| 101 | U8X8_END() /* end of sequence */ |
| 102 | }; |
| 103 | |
| 104 | static const uint8_t u8x8_d_uc1609_19264_flip1_seq[] = { |
| 105 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 106 | /* |
| 107 | LC0: 0 |
| 108 | MX: Mirror X |
| 109 | MY: Mirror Y |
| 110 | */ |
| 111 | U8X8_C(0x0c2), /* low bits are MY, MX, LC0 */ |
| 112 | U8X8_END_TRANSFER(), /* disable chip */ |
| 113 | U8X8_END() /* end of sequence */ |
| 114 | }; |
| 115 | |
| 116 | |
| 117 | static const u8x8_display_info_t u8x8_uc1609_19264_display_info = |
| 118 | { |
| 119 | /* chip_enable_level = */ 0, |
| 120 | /* chip_disable_level = */ 1, |
| 121 | |
| 122 | /* post_chip_enable_wait_ns = */ 15, |
| 123 | /* pre_chip_disable_wait_ns = */ 15, |
| 124 | /* reset_pulse_width_ms = */ 1, |
| 125 | /* post_reset_wait_ms = */ 6, |
| 126 | /* sda_setup_time_ns = */ 30, |
| 127 | /* sck_pulse_width_ns = */ 63, /* half of cycle time (125ns cycle time according to datasheet) --> 8MHz clock */ |
| 128 | /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 129 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 130 | /* i2c_bus_clock_100kHz = */ 4, |
| 131 | /* data_setup_time_ns = */ 30, |
| 132 | /* write_pulse_width_ns = */ 40, |
| 133 | /* tile_width = */ 24, |
| 134 | /* tile_height = */ 8, |
| 135 | /* default_x_offset = */ 0, |
| 136 | /* flipmode_x_offset = */ 0, |
| 137 | /* pixel_width = */ 192, |
| 138 | /* pixel_height = */ 64 |
| 139 | }; |
| 140 | |
| 141 | |
| 142 | uint8_t u8x8_d_uc1609_slg19264(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 143 | { |
| 144 | uint8_t x, c, page; |
| 145 | uint8_t *ptr; |
| 146 | switch(msg) |
| 147 | { |
| 148 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 149 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1609_19264_display_info); |
| 150 | break; |
| 151 | case U8X8_MSG_DISPLAY_INIT: |
| 152 | u8x8_d_helper_display_init(u8x8); |
| 153 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1609_19264_init_seq); |
| 154 | break; |
| 155 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 156 | if ( arg_int == 0 ) |
| 157 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1609_19264_powersave0_seq); |
| 158 | else |
| 159 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1609_19264_powersave1_seq); |
| 160 | break; |
| 161 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 162 | if ( arg_int == 0 ) |
| 163 | { |
| 164 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1609_19264_flip0_seq); |
| 165 | u8x8->x_offset = u8x8->display_info->default_x_offset; |
| 166 | } |
| 167 | else |
| 168 | { |
| 169 | u8x8_cad_SendSequence(u8x8, u8x8_d_uc1609_19264_flip1_seq); |
| 170 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset; |
| 171 | } |
| 172 | break; |
| 173 | #ifdef U8X8_WITH_SET_CONTRAST |
| 174 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 175 | u8x8_cad_StartTransfer(u8x8); |
| 176 | u8x8_cad_SendCmd(u8x8, 0x081 ); |
| 177 | u8x8_cad_SendArg(u8x8, arg_int ); /* uc1610 has range from 0 to 255 */ |
| 178 | u8x8_cad_EndTransfer(u8x8); |
| 179 | break; |
| 180 | #endif |
| 181 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 182 | u8x8_cad_StartTransfer(u8x8); |
| 183 | |
| 184 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 185 | x *= 8; |
| 186 | x += u8x8->x_offset; |
| 187 | |
| 188 | page = (((u8x8_tile_t *)arg_ptr)->y_pos); |
| 189 | |
| 190 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) ); |
| 191 | u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15))); |
| 192 | u8x8_cad_SendCmd(u8x8, 0x0b0 | page); |
| 193 | |
| 194 | do |
| 195 | { |
| 196 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 197 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 198 | u8x8_cad_SendData(u8x8, c*8, ptr); |
| 199 | arg_int--; |
| 200 | } while( arg_int > 0 ); |
| 201 | u8x8_cad_EndTransfer(u8x8); |
| 202 | |
| 203 | break; |
| 204 | default: |
| 205 | return 0; |
| 206 | } |
| 207 | return 1; |
| 208 | } |