u8x8_d_ist3088.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. u8x8_d_ist3088.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. IST3088: 320x240 monochrome LCD, 16 gray levels with B/W mode
  27. https://github.com/olikraus/u8g2/issues/1887
  28. CAD: 011
  29. commands and arg/data are always 16 bit, MSB first
  30. */
  31. #include "u8x8.h"
  32. /* powersave: maybe we could go to sleep mode, see register 3 */
  33. static const uint8_t u8x8_d_ist3088_320x240_powersave0_seq[] = {
  34. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  35. U8X8_CCAA(0x0, 0x07, 0x00, 0x01), // Display Control Bit 2: BW, 1: Invert, 0: Display enable
  36. U8X8_END_TRANSFER(), /* disable chip */
  37. U8X8_END() /* end of sequence */
  38. };
  39. static const uint8_t u8x8_d_ist3088_320x240_powersave1_seq[] = {
  40. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  41. U8X8_CCAA(0x0, 0x07, 0x00, 0x00), // Display Control Bit 2: BW, 1: Invert, 0: Display enable
  42. U8X8_END_TRANSFER(), /* disable chip */
  43. U8X8_END() /* end of sequence */
  44. };
  45. static const uint8_t u8x8_d_ist3088_320x240_flip0_seq[] = {
  46. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  47. U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty
  48. U8X8_END_TRANSFER(), /* disable chip */
  49. U8X8_END() /* end of sequence */
  50. };
  51. static const uint8_t u8x8_d_ist3088_320x240_flip1_seq[] = {
  52. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  53. U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty
  54. U8X8_END_TRANSFER(), /* disable chip */
  55. U8X8_END() /* end of sequence */
  56. };
  57. /*===================================================*/
  58. static uint8_t u8x8_d_ist3088_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  59. {
  60. //uint16_t x;
  61. int i;
  62. uint8_t y;
  63. uint8_t c;
  64. uint8_t *ptr;
  65. switch(msg)
  66. {
  67. /* handled by the calling function
  68. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  69. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist3088_320x240_display_info);
  70. break;
  71. */
  72. /* handled by the calling function
  73. case U8X8_MSG_DISPLAY_INIT:
  74. u8x8_d_helper_display_init(u8x8);
  75. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_init_seq);
  76. break;
  77. */
  78. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  79. if ( arg_int == 0 )
  80. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_powersave0_seq);
  81. else
  82. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_powersave1_seq);
  83. break;
  84. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  85. if ( arg_int == 0 )
  86. {
  87. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_flip0_seq);
  88. u8x8->x_offset = u8x8->display_info->default_x_offset;
  89. }
  90. else
  91. {
  92. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_flip1_seq);
  93. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  94. }
  95. break;
  96. #ifdef U8X8_WITH_SET_CONTRAST
  97. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  98. u8x8_cad_StartTransfer(u8x8);
  99. u8x8_cad_SendCmd(u8x8, 0x00 );
  100. u8x8_cad_SendCmd(u8x8, 0x05 );
  101. u8x8_cad_SendArg(u8x8, 0 );
  102. u8x8_cad_SendArg(u8x8, arg_int );
  103. u8x8_cad_EndTransfer(u8x8);
  104. break;
  105. #endif
  106. case U8X8_MSG_DISPLAY_DRAW_TILE:
  107. /*
  108. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  109. x *= 8;
  110. x += u8x8->x_offset;
  111. */
  112. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  113. y*=8;
  114. u8x8_cad_StartTransfer(u8x8);
  115. c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
  116. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */
  117. for( i = 0; i < 8; i++ )
  118. {
  119. u8x8_cad_SendCmd(u8x8, 0x0);
  120. u8x8_cad_SendCmd(u8x8, 0x8);
  121. u8x8_cad_SendArg(u8x8, y);
  122. u8x8_cad_SendArg(u8x8, 0 );
  123. u8x8_cad_SendCmd(u8x8, 0x0); // write data
  124. u8x8_cad_SendCmd(u8x8, 0x9); // write data
  125. //c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
  126. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes, send one line of data */
  127. ptr += u8x8->display_info->tile_width;
  128. y ++;
  129. }
  130. u8x8_cad_EndTransfer(u8x8);
  131. break;
  132. default:
  133. return 0;
  134. }
  135. return 1;
  136. }
  137. /*===================================================*/
  138. /*
  139. SdCmd(0x01); // driver control
  140. SdData(0x00); SdData(0x00); // c1-->c240 s1-->s240 duty=1/240
  141. SdCmd(0x02); // driver control
  142. SdData(0x01); SdData(0x4c); //0x15
  143. SdCmd(0x03); // power control
  144. SdData(0x00); SdData(0x70); // VC VR Vf=1
  145. SdCmd(0x04); // power control
  146. SdData(0x04); SdData(0x61); //0x61 //1/14b
  147. SdCmd(0x05); // CT control
  148. SdData(0x00); SdData(0x6a); // 0X76
  149. SdCmd(0x06); // CT control
  150. SdData(0x00); SdData(0x03);
  151. SdCmd(0x23); // B/W MODE,16G NEED REMOVE
  152. SdData(0x00); SdData(0x04); //04:mono
  153. SdCmd(0x28); // OSC
  154. SdData(0x00); SdData(0x0c);
  155. SdCmd(0x37);
  156. SdData(0x00); SdData(0x12);
  157. SdCmd(0x07);
  158. SdData(0x00); SdData(0x01);
  159. */
  160. /* https://github.com/olikraus/u8g2/issues/1887 */
  161. static const uint8_t u8x8_d_ist3088_320x240_init_seq[] = {
  162. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  163. /* disableLCD */
  164. U8X8_CCAA(0x0, 0x07, 0x00, 0x00), // Display Control Bit 2: BW, 1: Invert, 0: Display enable
  165. U8X8_CCAA(0x0, 0x01, 0x00, 0x00), // Driver Control, 1/240 Duty
  166. U8X8_CCAA(0x0, 0x02, 0x01, 0x4c), // Polarity Control
  167. U8X8_CCAA(0x0, 0x06, 0x00, 0x03), // Entry mode: h/v increment
  168. //U8X8_CCAA(0x0, 0x04, 0x07, 0x61), // Power Control 2: 0x07: 1/16 Bias, Vout1 x 4
  169. U8X8_CCAA(0x0, 0x04, 0x04, 0x61), // Power Control 2: 0x07: 1/16 Bias, Vout1 x 4
  170. U8X8_CCAA(0x0, 0x05, 0x00, 0x6a), // Contrast, 0..255,
  171. U8X8_CCAA(0x0, 0x03, 0x00, 0x40), // Enable voltage converter
  172. U8X8_DLY(10),
  173. U8X8_CCAA(0x0, 0x03, 0x00, 0x60), // Enable voltage regulator
  174. U8X8_DLY(10),
  175. U8X8_CCAA(0x0, 0x03, 0x00, 0x70), // Enable voltage follower
  176. U8X8_DLY(10),
  177. U8X8_CCAA(0x0, 0x23, 0x00, 0x04), // Monochrome mode
  178. U8X8_CCAA(0x0, 0x28, 0x00, 0x0c), // Frame Rate Control
  179. U8X8_CCAA(0x0, 0x37, 0x00, 0x01), // Frame Rate Control
  180. U8X8_CCAA(0x0, 0x0d, 39, 0x00), // X End and X Start
  181. U8X8_CCAA(0x0, 0x0e, 239, 0x00), // Y End and Y Start
  182. /* enable LCD (will be done by powersave0) */
  183. //U8X8_CCAA(0x0, 0x07, 0x00, 0x01), // Display Control Bit 2: BW, 1: Invert, 0: Display enable
  184. U8X8_END_TRANSFER(), /* disable chip */
  185. U8X8_END() /* end of sequence */
  186. };
  187. static const u8x8_display_info_t u8x8_ist3088_320x240_display_info =
  188. {
  189. /* chip_enable_level = */ 0,
  190. /* chip_disable_level = */ 1,
  191. /* post_chip_enable_wait_ns = */ 110,
  192. /* pre_chip_disable_wait_ns = */ 110,
  193. /* reset_pulse_width_ms = */ 10,
  194. /* post_reset_wait_ms = */ 10, /**/
  195. /* sda_setup_time_ns = */ 110, /* */
  196. /* sck_pulse_width_ns = */ 125, /* */
  197. /* sck_clock_hz = */ 4000000UL, /* 250ns cycle, see page 49 of the IST3088 datasheet*/
  198. /* spi_mode = */ 0, /* active high, rising edge */
  199. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz, IST8033 das not include a I2C interface */
  200. /* data_setup_time_ns = */ 70,
  201. /* write_pulse_width_ns = */ 60,
  202. /* tile_width = */ 40,
  203. /* tile_height = */ 30,
  204. /* default_x_offset = */ 0,
  205. /* flipmode_x_offset = */ 0,
  206. /* pixel_width = */ 320,
  207. /* pixel_height = */ 240
  208. };
  209. uint8_t u8x8_d_ist3088_320x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  210. {
  211. if ( u8x8_d_ist3088_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
  212. return 1;
  213. switch(msg)
  214. {
  215. case U8X8_MSG_DISPLAY_INIT:
  216. u8x8_d_helper_display_init(u8x8);
  217. u8x8_cad_SendSequence(u8x8, u8x8_d_ist3088_320x240_init_seq);
  218. break;
  219. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  220. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist3088_320x240_display_info);
  221. break;
  222. default:
  223. return 0;
  224. }
  225. return 1;
  226. }