| 1 | /* |
| 2 | |
| 3 | u8x8_d_pcd8544_84x48.c (so called "Nokia 5110" displays) |
| 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 | #include "u8x8.h" |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | static const uint8_t u8x8_d_pcd8544_84x48_init_seq[] = { |
| 42 | |
| 43 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 44 | |
| 45 | U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ |
| 46 | U8X8_C(0x006), /* temp. control: b10 = 2 */ |
| 47 | U8X8_C(0x013), /* bias system 1:48 */ |
| 48 | U8X8_C(0x0c0), /* medium Vop */ |
| 49 | |
| 50 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ |
| 51 | U8X8_C(0x008), /* blank */ |
| 52 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */ |
| 53 | |
| 54 | U8X8_END_TRANSFER(), /* disable chip */ |
| 55 | U8X8_END() /* end of sequence */ |
| 56 | }; |
| 57 | |
| 58 | static const uint8_t u8x8_d_pcd8544_84x48_powersave0_seq[] = { |
| 59 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 60 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ |
| 61 | U8X8_C(0x00c), /* display on */ |
| 62 | U8X8_END_TRANSFER(), /* disable chip */ |
| 63 | U8X8_END() /* end of sequence */ |
| 64 | }; |
| 65 | |
| 66 | static const uint8_t u8x8_d_pcd8544_84x48_powersave1_seq[] = { |
| 67 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */ |
| 68 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ |
| 69 | U8X8_C(0x008), /* blank */ |
| 70 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */ |
| 71 | U8X8_END_TRANSFER(), /* disable chip */ |
| 72 | U8X8_END() /* end of sequence */ |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | |
| 77 | static const u8x8_display_info_t u8x8_pcd8544_84x48_display_info = |
| 78 | { |
| 79 | /* chip_enable_level = */ 0, |
| 80 | /* chip_disable_level = */ 1, |
| 81 | |
| 82 | /* post_chip_enable_wait_ns = */ 5, |
| 83 | /* pre_chip_disable_wait_ns = */ 5, |
| 84 | /* reset_pulse_width_ms = */ 2, |
| 85 | /* post_reset_wait_ms = */ 2, |
| 86 | /* sda_setup_time_ns = */ 12, |
| 87 | /* sck_pulse_width_ns = */ 75, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */ |
| 88 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ |
| 89 | /* spi_mode = */ 0, /* active high, rising edge */ |
| 90 | /* i2c_bus_clock_100kHz = */ 4, |
| 91 | /* data_setup_time_ns = */ 30, |
| 92 | /* write_pulse_width_ns = */ 40, |
| 93 | /* tile_width = */ 11, /* width of 11*8=88 pixel */ |
| 94 | /* tile_height = */ 6, |
| 95 | /* default_x_offset = */ 0, |
| 96 | /* flipmode_x_offset = */ 0, |
| 97 | /* pixel_width = */ 84, |
| 98 | /* pixel_height = */ 48 |
| 99 | }; |
| 100 | |
| 101 | uint8_t u8x8_d_pcd8544_84x48(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) |
| 102 | { |
| 103 | uint8_t x, c; |
| 104 | uint8_t *ptr; |
| 105 | switch(msg) |
| 106 | { |
| 107 | case U8X8_MSG_DISPLAY_SETUP_MEMORY: |
| 108 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcd8544_84x48_display_info); |
| 109 | break; |
| 110 | case U8X8_MSG_DISPLAY_INIT: |
| 111 | u8x8_d_helper_display_init(u8x8); |
| 112 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_init_seq); |
| 113 | break; |
| 114 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE: |
| 115 | if ( arg_int == 0 ) |
| 116 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave0_seq); |
| 117 | else |
| 118 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave1_seq); |
| 119 | break; |
| 120 | // case U8X8_MSG_DISPLAY_SET_FLIP_MODE: |
| 121 | // break; NOT SUPPORTED |
| 122 | |
| 123 | #ifdef U8X8_WITH_SET_CONTRAST |
| 124 | case U8X8_MSG_DISPLAY_SET_CONTRAST: |
| 125 | u8x8_cad_StartTransfer(u8x8); |
| 126 | u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */ |
| 127 | u8x8_cad_SendCmd(u8x8, 0x080 | (arg_int >> 1) ); |
| 128 | u8x8_cad_EndTransfer(u8x8); |
| 129 | break; |
| 130 | #endif |
| 131 | case U8X8_MSG_DISPLAY_DRAW_TILE: |
| 132 | u8x8_cad_StartTransfer(u8x8); |
| 133 | |
| 134 | x = ((u8x8_tile_t *)arg_ptr)->x_pos; |
| 135 | x *= 8; |
| 136 | x += u8x8->x_offset; |
| 137 | u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ |
| 138 | u8x8_cad_SendCmd(u8x8, 0x080 | (x) ); /* set X address */ |
| 139 | u8x8_cad_SendCmd(u8x8, 0x040 | (((u8x8_tile_t *)arg_ptr)->y_pos) ); /* set Y address */ |
| 140 | |
| 141 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; |
| 142 | c = ((u8x8_tile_t *)arg_ptr)->cnt; |
| 143 | c *= 8; |
| 144 | do |
| 145 | { |
| 146 | if ( c + x > 84u ) |
| 147 | { |
| 148 | if ( x >= 84u ) |
| 149 | break; |
| 150 | c = 84u; |
| 151 | c -= x; |
| 152 | } |
| 153 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */ |
| 154 | x += c; |
| 155 | arg_int--; |
| 156 | } while( arg_int > 0 ); |
| 157 | |
| 158 | u8x8_cad_EndTransfer(u8x8); |
| 159 | break; |
| 160 | default: |
| 161 | return 0; |
| 162 | } |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | |