u8x8_d_st75320.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. u8x8_d_st75320.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. ST75320: 320x240 monochrome LCD
  27. https://github.com/olikraus/u8g2/issues/921
  28. */
  29. #include "u8x8.h"
  30. static const uint8_t u8x8_d_st75320_jlx320240_powersave0_seq[] = {
  31. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  32. U8X8_C(0x0af), /* display on */
  33. U8X8_END_TRANSFER(), /* disable chip */
  34. U8X8_END() /* end of sequence */
  35. };
  36. static const uint8_t u8x8_d_st75320_jlx320240_powersave1_seq[] = {
  37. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  38. U8X8_C(0x0ae), /* display off */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_st75320_jlx320240_flip0_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_CA(0xC4, 0x02), /* COM Output Status, Bits 0 & 1 */
  45. U8X8_C(0xA1), /* Column Address Direction: Bit 0 */
  46. //U8X8_C(0x0a1), /* segment remap a0/a1*/
  47. //U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  48. U8X8_END_TRANSFER(), /* disable chip */
  49. U8X8_END() /* end of sequence */
  50. };
  51. static const uint8_t u8x8_d_st75320_jlx320240_flip1_seq[] = {
  52. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  53. //U8X8_C(0x0a0), /* segment remap a0/a1*/
  54. //U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  55. U8X8_CA(0xC4, 0x03), /* COM Output Status, Bits 0 & 1 */
  56. U8X8_C(0xA0), /* Column Address Direction: Bit 0 */
  57. U8X8_END_TRANSFER(), /* disable chip */
  58. U8X8_END() /* end of sequence */
  59. };
  60. /*===================================================*/
  61. static uint8_t u8x8_d_st75320_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  62. {
  63. uint16_t x;
  64. uint8_t c;
  65. uint8_t *ptr;
  66. switch(msg)
  67. {
  68. /* handled by the calling function
  69. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  70. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75320_jlx320240_display_info);
  71. break;
  72. */
  73. /* handled by the calling function
  74. case U8X8_MSG_DISPLAY_INIT:
  75. u8x8_d_helper_display_init(u8x8);
  76. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_init_seq);
  77. break;
  78. */
  79. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  80. if ( arg_int == 0 )
  81. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_powersave0_seq);
  82. else
  83. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_powersave1_seq);
  84. break;
  85. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  86. if ( arg_int == 0 )
  87. {
  88. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_flip0_seq);
  89. u8x8->x_offset = u8x8->display_info->default_x_offset;
  90. }
  91. else
  92. {
  93. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_flip1_seq);
  94. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  95. }
  96. break;
  97. #ifdef U8X8_WITH_SET_CONTRAST
  98. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  99. u8x8_cad_StartTransfer(u8x8);
  100. u8x8_cad_SendCmd(u8x8, 0x081 );
  101. u8x8_cad_SendArg(u8x8, arg_int<<2 );
  102. u8x8_cad_SendArg(u8x8, arg_int>>6 );
  103. u8x8_cad_EndTransfer(u8x8);
  104. break;
  105. #endif
  106. case U8X8_MSG_DISPLAY_DRAW_TILE:
  107. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  108. x *= 8;
  109. x += u8x8->x_offset;
  110. u8x8_cad_StartTransfer(u8x8);
  111. u8x8_cad_SendCmd(u8x8, 0x013);
  112. u8x8_cad_SendArg(u8x8, (x>>8) );
  113. u8x8_cad_SendArg(u8x8, (x&255) );
  114. u8x8_cad_SendCmd(u8x8, 0x0b1 );
  115. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  116. u8x8_cad_SendCmd(u8x8, 0x01d ); // write data
  117. do
  118. {
  119. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  120. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  121. /* SendData can not handle more than 255 bytes */
  122. if ( c > 31 )
  123. {
  124. u8x8_cad_SendData(u8x8, 248, ptr); /* 31*8=248 */
  125. ptr+=248;
  126. c -= 31;
  127. }
  128. u8x8_cad_SendData(u8x8, c*8, ptr);
  129. arg_int--;
  130. } while( arg_int > 0 );
  131. u8x8_cad_EndTransfer(u8x8);
  132. break;
  133. default:
  134. return 0;
  135. }
  136. return 1;
  137. }
  138. /*===================================================*/
  139. /* QT-2832TSWUG02/ZJY-2832TSWZG02 */
  140. static const uint8_t u8x8_d_st75320_jlx320240_init_seq[] = {
  141. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  142. U8X8_C(0xAE), // Display OFF
  143. U8X8_CA(0xEA, 0x00), // Power Discharge Control, Discharge OFF
  144. U8X8_C(0xA8), // sleep out
  145. U8X8_C(0xAB), // OSC ON
  146. U8X8_C(0x69), // Temperature Detection ON
  147. U8X8_C(0x4E), // TC Setting
  148. U8X8_A8(0xff, 0x44, 0x12, 0x11, 0x11, 0x11, 0x22, 0x23),
  149. U8X8_CAA(0x39, 0x00, 0x00), //TC Flag
  150. U8X8_CA(0x2B, 0x00), // Frame Rate Level
  151. U8X8_CAA(0x5F, 0x66, 0x66), // Set Frame Frequency, fFR=80Hz in all temperature range
  152. U8X8_CAAA(0xEC, 0x19, 0x64, 0x6e), // FR Compensation Temp. Range, TA = -15 degree, TB = 60 degree, TC = 70 degree
  153. U8X8_CAA(0xED, 0x04, 0x04), // Temp. Hysteresis Value (thermal sensitivity)
  154. U8X8_C(0xA6), // Display Inverse OFF
  155. U8X8_C(0xA4), // Disable Display All Pixel ON
  156. U8X8_CA(0xC4, 0x02), // COM Output Status
  157. U8X8_C(0xA1), // Column Address Direction: MX=0
  158. U8X8_CAA(0x6D, 0x07, 0x00), // Display Area, Duty = 1/240 duty, Start Group = 1
  159. U8X8_C(0x84), // Display Data Input Direction: Column
  160. U8X8_CA(0x36, 0x1e), // Set N-Line
  161. U8X8_C(0xE4), // N-Line On
  162. U8X8_CA(0xE7, 0x19), // LCD Drive Method //NLFR=1//
  163. U8X8_CAA(0x81, 0x4f, 0x01), // OX81: Set EV=64h, 0..255, 0..3
  164. U8X8_CA(0xA2, 0x0a), // BIAS //1/16 BIAS
  165. U8X8_CA(0x25, 0x020), // Power Control //AVDD ON
  166. U8X8_DLY(10),
  167. U8X8_CA(0x25, 0x60), // Power Control//AVDD, MV3 & NAVDD ON
  168. U8X8_DLY(10),
  169. U8X8_CA(0x25, 0x70), // Power Control //AVDD, MV3, NAVDD & V3 ON
  170. U8X8_DLY(10),
  171. U8X8_CA(0x25, 0x78), // Power Control//AVDD, MV3, NAVDD, V3 & VPF ON
  172. U8X8_DLY(10),
  173. U8X8_CA(0x25, 0x7c), // Power Control//AVDD, MV3, NAVDD, V3, VPF & VNF ON
  174. U8X8_DLY(10),
  175. U8X8_CA(0x25, 0x7e), // Power Control//VOUT, AVDD, MV3, NAVDD, V3, VPF & VNF ON
  176. U8X8_DLY(10),
  177. U8X8_CA(0x25, 0x7f), // Power Control/VOUT, AVDD, MV3, NAVDD, V3, VPF & VNF ON
  178. U8X8_DLY(10),
  179. //U8X8_C(0xaf); //Display ON
  180. U8X8_END_TRANSFER(), /* disable chip */
  181. U8X8_END() /* end of sequence */
  182. };
  183. static const u8x8_display_info_t u8x8_st75320_jlx320240_display_info =
  184. {
  185. /* chip_enable_level = */ 0,
  186. /* chip_disable_level = */ 1,
  187. /* post_chip_enable_wait_ns = */ 20,
  188. /* pre_chip_disable_wait_ns = */ 20,
  189. /* reset_pulse_width_ms = */ 5,
  190. /* post_reset_wait_ms = */ 5, /**/
  191. /* sda_setup_time_ns = */ 20, /* */
  192. /* sck_pulse_width_ns = */ 40, /* */
  193. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  194. /* spi_mode = */ 0, /* active high, rising edge */
  195. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
  196. /* data_setup_time_ns = */ 15,
  197. /* write_pulse_width_ns = */ 70,
  198. /* tile_width = */ 40,
  199. /* tile_height = */ 30,
  200. /* default_x_offset = */ 0,
  201. /* flipmode_x_offset = */ 0,
  202. /* pixel_width = */ 320,
  203. /* pixel_height = */ 240
  204. };
  205. uint8_t u8x8_d_st75320_jlx320240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  206. {
  207. if ( u8x8_d_st75320_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
  208. return 1;
  209. switch(msg)
  210. {
  211. case U8X8_MSG_DISPLAY_INIT:
  212. u8x8_d_helper_display_init(u8x8);
  213. u8x8_cad_SendSequence(u8x8, u8x8_d_st75320_jlx320240_init_seq);
  214. break;
  215. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  216. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75320_jlx320240_display_info);
  217. break;
  218. default:
  219. return 0;
  220. }
  221. return 1;
  222. }