u8x8_d_st7511.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. u8x8_d_st7511.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2019, 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. 20 May 2019:
  27. https://github.com/olikraus/u8g2/issues/876
  28. Probably HW Flip does not work
  29. */
  30. #include "u8x8.h"
  31. static const uint8_t u8x8_d_st7511_320x240_powersave0_seq[] = {
  32. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  33. U8X8_CA(0x015, 0x0a5), /* display on */
  34. U8X8_END_TRANSFER(), /* disable chip */
  35. U8X8_END() /* end of sequence */
  36. };
  37. static const uint8_t u8x8_d_st7511_320x240_powersave1_seq[] = {
  38. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  39. U8X8_CA(0x014, 0x0a5), /* display off */
  40. // maybe use sleep mode here, but it not clear whether sleep mode will reset all the settings
  41. U8X8_END_TRANSFER(), /* disable chip */
  42. U8X8_END() /* end of sequence */
  43. };
  44. static const uint8_t u8x8_d_st7511_320x240_flip0_seq[] = {
  45. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  46. U8X8_CAAAA(0x24, 0x01, 0xa5, 0xa5, 0xa5), /* memory control directions */
  47. U8X8_END_TRANSFER(), /* disable chip */
  48. U8X8_END() /* end of sequence */
  49. };
  50. static const uint8_t u8x8_d_st7511_320x240_flip1_seq[] = {
  51. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  52. U8X8_CAAAA(0x24, 0x02, 0xa5, 0xa5, 0xa5), /* memory control directions */
  53. U8X8_END_TRANSFER(), /* disable chip */
  54. U8X8_END() /* end of sequence */
  55. };
  56. /*=====================================================*/
  57. /* AV-Display: AVD-TM57QV-NW-001-B, issue 876 */
  58. static const u8x8_display_info_t u8x8_st7511_320x240_display_info =
  59. {
  60. /* chip_enable_level = */ 0,
  61. /* chip_disable_level = */ 1,
  62. /* post_chip_enable_wait_ns = */ 150, /* ST7511 Datasheet */
  63. /* pre_chip_disable_wait_ns = */ 150, /* ST7511 Datasheet */
  64. /* reset_pulse_width_ms = */ 1,
  65. /* post_reset_wait_ms = */ 1,
  66. /* sda_setup_time_ns = */ 120, /* ST7511 Datasheet */
  67. /* sck_pulse_width_ns = */ 150, /* ST7511 Datasheet */
  68. /* sck_clock_hz = */ 3300000UL, /* ST7511 Datasheet: 300ns cycle */
  69. /* spi_mode = */ 0, /* active high, rising edge */
  70. /* i2c_bus_clock_100kHz = */ 4,
  71. /* data_setup_time_ns = */ 200, /* */
  72. /* write_pulse_width_ns = */ 250, /* ST7511 Datasheet: 500ns */
  73. /* tile_width = */ 40, /* width of 17*8=136 pixel */
  74. /* tile_hight = */ 30,
  75. /* default_x_offset = */ 160,
  76. /* flipmode_x_offset = */ 0,
  77. /* pixel_width = */ 320,
  78. /* pixel_height = */ 240
  79. };
  80. static const uint8_t u8x8_d_st7511_320x240_init_seq[] = {
  81. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  82. U8X8_CA(0xae, 0xa5), /* SW Reset */
  83. U8X8_CAAAA(0x61, 0x0f, 0x04, 0x02, 0xa5), /* all power on */
  84. U8X8_CAAAA(0x62, 0x0a, 0x06, 0x0f, 0xa5), /* electronic volumne set 1 */
  85. U8X8_CAAAA(0x63, 0x0f, 0x0f, 0xa5, 0xa5), /* electronic volumne set 2 */
  86. U8X8_CAAAA(0x66, 0x00, 0xa5, 0xa5, 0xa5), /* electronic volumne set 2 */
  87. U8X8_CA(0x12, 0xa5), /* SLeeP OUT */
  88. U8X8_DLY(50),
  89. // skiping display on here, deviation from https://github.com/olikraus/u8g2/issues/876
  90. // will be called later in u8x8_d_st7511_320x240_powersave0_seq
  91. U8X8_CAAAA(0x22, 0x00, 0xa5, 0xa5, 0xa5), /* monochrome display */
  92. U8X8_CAAAA(0x24, 0x01, 0xa5, 0xa5, 0xa5), /* memory control directions */
  93. U8X8_DLY(50),
  94. U8X8_END_TRANSFER(), /* disable chip */
  95. U8X8_END() /* end of sequence */
  96. };
  97. uint8_t u8x8_d_st7511_avd_320x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  98. {
  99. uint16_t x, c;
  100. uint8_t *ptr;
  101. switch(msg)
  102. {
  103. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  104. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7511_320x240_display_info);
  105. break;
  106. case U8X8_MSG_DISPLAY_INIT:
  107. u8x8_d_helper_display_init(u8x8);
  108. u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_init_seq);
  109. break;
  110. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  111. if ( arg_int == 0 )
  112. u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave0_seq);
  113. else
  114. u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_powersave1_seq);
  115. break;
  116. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  117. if ( arg_int == 0 )
  118. {
  119. u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip0_seq);
  120. u8x8->x_offset = u8x8->display_info->default_x_offset;
  121. }
  122. else
  123. {
  124. u8x8_cad_SendSequence(u8x8, u8x8_d_st7511_320x240_flip1_seq);
  125. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  126. }
  127. break;
  128. #ifdef U8X8_WITH_SET_CONTRAST
  129. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  130. // not sure how to implement this....
  131. // u8x8_cad_StartTransfer(u8x8);
  132. // u8x8_cad_EndTransfer(u8x8);
  133. break;
  134. #endif
  135. case U8X8_MSG_DISPLAY_DRAW_TILE:
  136. u8x8_cad_StartTransfer(u8x8);
  137. // set page
  138. u8x8_cad_SendCmd(u8x8, 0x025);
  139. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  140. u8x8_cad_SendArg(u8x8, 0x09f); // end page
  141. u8x8_cad_SendArg(u8x8, 0x000); // frame 0
  142. u8x8_cad_SendArg(u8x8, 0x0a5);
  143. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  144. x *= 8;
  145. x += u8x8->x_offset;
  146. // set column
  147. u8x8_cad_SendCmd(u8x8, 0x026);
  148. u8x8_cad_SendArg(u8x8, (x>>8) );
  149. u8x8_cad_SendArg(u8x8, (x&255) );
  150. u8x8_cad_SendArg(u8x8, 0x002);
  151. u8x8_cad_SendArg(u8x8, 0x07f);
  152. // start data transfer
  153. u8x8_cad_SendCmd(u8x8, 0x02c);
  154. u8x8_cad_SendArg(u8x8, 0x0a5 );
  155. do
  156. {
  157. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  158. c *= 8;
  159. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  160. while ( c > 128 )
  161. {
  162. u8x8_cad_SendData(u8x8, 128, ptr); /* note: SendData can not handle more than 255 bytes */
  163. c -= 128;
  164. ptr += 128;
  165. }
  166. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  167. arg_int--;
  168. } while( arg_int > 0 );
  169. u8x8_cad_EndTransfer(u8x8);
  170. break;
  171. default:
  172. return 0;
  173. }
  174. return 1;
  175. }