u8x8_d_ist3020.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. u8x8_d_ist3020.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2017, olikraus@gmail.com
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice, this list
  9. of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice, this
  11. list of conditions and the following disclaimer in the documentation and/or other
  12. materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  14. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "u8x8.h"
  28. static const uint8_t u8x8_d_ist3020_erc19264_powersave0_seq[] = {
  29. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  30. U8X8_C(0x0a4), /* all pixel off, issue 142 */
  31. U8X8_C(0x0af), /* display on */
  32. U8X8_END_TRANSFER(), /* disable chip */
  33. U8X8_END() /* end of sequence */
  34. };
  35. static const uint8_t u8x8_d_ist3020_erc19264_powersave1_seq[] = {
  36. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  37. U8X8_C(0x0ae), /* display off */
  38. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_ist3020_erc19264_flip0_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_C(0x0a0), /* segment remap a0/a1*/
  45. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  46. U8X8_END_TRANSFER(), /* disable chip */
  47. U8X8_END() /* end of sequence */
  48. };
  49. static const uint8_t u8x8_d_ist3020_erc19264_flip1_seq[] = {
  50. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  51. U8X8_C(0x0a1), /* segment remap a0/a1*/
  52. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  53. U8X8_END_TRANSFER(), /* disable chip */
  54. U8X8_END() /* end of sequence */
  55. };
  56. static const u8x8_display_info_t u8x8_ist3020_erc19264_display_info =
  57. {
  58. /* chip_enable_level = */ 0,
  59. /* chip_disable_level = */ 1,
  60. /* post_chip_enable_wait_ns = */ 150, /* IST3020 datasheet, page 56 */
  61. /* pre_chip_disable_wait_ns = */ 150, /* IST3020 datasheet, page 56 */
  62. /* reset_pulse_width_ms = */ 1,
  63. /* post_reset_wait_ms = */ 1,
  64. /* sda_setup_time_ns = */ 100, /* IST3020 datasheet, page 56 */
  65. /* sck_pulse_width_ns = */ 100, /* IST3020 datasheet, page 56 */
  66. /* sck_clock_hz = */ 4000000UL, /* */
  67. /* spi_mode = */ 0, /* active high, rising edge */
  68. /* i2c_bus_clock_100kHz = */ 4,
  69. /* data_setup_time_ns = */ 40, /* IST3020 datasheet, page 54 */
  70. /* write_pulse_width_ns = */ 60, /* IST3020 datasheet, page 54 */
  71. /* tile_width = */ 24, /* width of 24*8=192 pixel */
  72. /* tile_hight = */ 8,
  73. /* default_x_offset = */ 0,
  74. /* flipmode_x_offset = */ 64,
  75. /* pixel_width = */ 192,
  76. /* pixel_height = */ 64
  77. };
  78. static const uint8_t u8x8_d_ist3020_erc19264_init_seq[] = {
  79. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  80. U8X8_C(0x0e2), /* soft reset */
  81. U8X8_C(0x0ab), /* build in osc on, used in ER code, but not mentioned in data sheet */
  82. U8X8_C(0x0ae), /* display off */
  83. U8X8_C(0x040), /* set display start line to 0 */
  84. U8X8_C(0x0a0), /* ADC set to reverse */
  85. U8X8_C(0x0c8), /* common output mode */
  86. // Flipmode
  87. //U8X8_C(0x0a0), /* ADC set to reverse */
  88. //U8X8_C(0x0c8), /* common output mode */
  89. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  90. U8X8_C(0x0a3), /* FIX: LCD bias 1/7, old value was 1/9 (0x0a2) */
  91. U8X8_C(0x028|4), /* all power control circuits on */
  92. U8X8_DLY(50),
  93. U8X8_C(0x028|6), /* all power control circuits on */
  94. U8X8_DLY(50),
  95. U8X8_C(0x028|7), /* all power control circuits on */
  96. U8X8_DLY(50),
  97. U8X8_C(0x020), /* v0 voltage resistor ratio */
  98. U8X8_CA(0x081, 0x019), /* set contrast, contrast value (from ER code: 45) */
  99. U8X8_C(0x0ae), /* display off */
  100. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  101. U8X8_END_TRANSFER(), /* disable chip */
  102. U8X8_END() /* end of sequence */
  103. };
  104. uint8_t u8x8_d_ist3020_erc19264(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  105. {
  106. uint8_t x, c;
  107. uint8_t *ptr;
  108. switch(msg)
  109. {
  110. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  111. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist3020_erc19264_display_info);
  112. break;
  113. case U8X8_MSG_DISPLAY_INIT:
  114. u8x8_d_helper_display_init(u8x8);
  115. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3020_erc19264_init_seq);
  116. break;
  117. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  118. if ( arg_int == 0 )
  119. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3020_erc19264_powersave0_seq);
  120. else
  121. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3020_erc19264_powersave1_seq);
  122. break;
  123. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  124. if ( arg_int == 0 )
  125. {
  126. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3020_erc19264_flip0_seq);
  127. u8x8->x_offset = u8x8->display_info->default_x_offset;
  128. }
  129. else
  130. {
  131. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3020_erc19264_flip1_seq);
  132. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  133. }
  134. break;
  135. #ifdef U8X8_WITH_SET_CONTRAST
  136. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  137. u8x8_cad_StartTransfer(u8x8);
  138. u8x8_cad_SendCmd(u8x8, 0x081 );
  139. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  140. u8x8_cad_EndTransfer(u8x8);
  141. break;
  142. #endif
  143. case U8X8_MSG_DISPLAY_DRAW_TILE:
  144. u8x8_cad_StartTransfer(u8x8);
  145. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  146. x *= 8;
  147. x += u8x8->x_offset;
  148. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  149. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  150. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  151. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  152. c *= 8;
  153. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  154. do
  155. {
  156. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  157. arg_int--;
  158. } while( arg_int > 0 );
  159. u8x8_cad_EndTransfer(u8x8);
  160. break;
  161. default:
  162. return 0;
  163. }
  164. return 1;
  165. }