u8x8_d_st75160.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. u8x8_d_st75160.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2021, 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. https://github.com/olikraus/u8g2/issues/1642
  27. 0x030 ext 00
  28. 0x031 ext 01
  29. 0x038 ext 10
  30. 0x039 ext 11
  31. cad 011
  32. code examples:
  33. http://www.it610.com/article/2601023.htm
  34. normal mode:
  35. 0x00c bit format
  36. U8X8_CA( 0xbc, 0x00 ), data scan dir
  37. U8X8_A( 0xa6 ),
  38. y: 0 offset
  39. flip mode:
  40. 0x008 bit format
  41. U8X8_CA( 0xbc, 0x03 ), data scan dir
  42. U8X8_A( 0xa6 ),
  43. y: 5 offset
  44. */
  45. #include "u8x8.h"
  46. /* not a real power down for the st75256... just a display off */
  47. static const uint8_t u8x8_d_st75256_256x128_powersave0_seq[] = {
  48. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  49. U8X8_C( 0x030 ), /* select 00 commands */
  50. U8X8_C( 0x94 ), /* sleep out */
  51. U8X8_DLY(10),
  52. U8X8_C( 0xaf ), /* display on */
  53. U8X8_END_TRANSFER(), /* disable chip */
  54. U8X8_END() /* end of sequence */
  55. };
  56. static const uint8_t u8x8_d_st75256_256x128_powersave1_seq[] = {
  57. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  58. U8X8_C( 0x030 ), /* select 00 commands */
  59. U8X8_C( 0xae ), /* display off */
  60. U8X8_C( 0x95 ), /* sleep in */
  61. U8X8_END_TRANSFER(), /* disable chip */
  62. U8X8_END() /* end of sequence */
  63. };
  64. // static const uint8_t u8x8_d_st75256_jlx256128_flip0_seq[] = {
  65. // U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  66. // U8X8_C( 0x030 ), /* select 00 commands */
  67. // U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
  68. // U8X8_A( 0xa6 ), /* ??? */
  69. // //U8X8_C( 0x030 ), /* select 00 commands */
  70. // U8X8_C( 0x00c ), /* data format LSB top */
  71. // U8X8_END_TRANSFER(), /* disable chip */
  72. // U8X8_END() /* end of sequence */
  73. // };
  74. // static const uint8_t u8x8_d_st75256_jlx256128_flip1_seq[] = {
  75. // U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  76. // U8X8_C( 0x030 ), /* select 00 commands */
  77. // U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
  78. // U8X8_A( 0xa6 ), /* ??? */
  79. // //U8X8_C( 0x030 ), /* select 00 commands */
  80. // U8X8_C( 0x008 ), /* data format MSB top */
  81. // U8X8_END_TRANSFER(), /* disable chip */
  82. // U8X8_END() /* end of sequence */
  83. // };
  84. static const uint8_t u8x8_d_st75256_jlx172104_flip0_seq[] = {
  85. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  86. U8X8_C( 0x030 ), /* select 00 commands */
  87. U8X8_CA( 0xbc, 0x02 ), /* data scan dir */
  88. U8X8_A( 0xa6 ), /* ??? */
  89. //U8X8_C( 0x030 ), /* select 00 commands */
  90. U8X8_C( 0x00c ), /* data format LSB top */
  91. U8X8_END_TRANSFER(), /* disable chip */
  92. U8X8_END() /* end of sequence */
  93. };
  94. static const uint8_t u8x8_d_st75256_jlx172104_flip1_seq[] = {
  95. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  96. U8X8_C( 0x030 ), /* select 00 commands */
  97. U8X8_CA( 0xbc, 0x01 ), /* data scan dir */
  98. U8X8_A( 0xa6 ), /* ??? */
  99. //U8X8_C( 0x030 ), /* select 00 commands */
  100. U8X8_C( 0x008 ), /* data format MSB top */
  101. U8X8_END_TRANSFER(), /* disable chip */
  102. U8X8_END() /* end of sequence */
  103. };
  104. // static const uint8_t u8x8_d_st75256_jlx256160_flip0_seq[] = {
  105. // U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  106. // U8X8_C( 0x030 ), /* select 00 commands */
  107. // U8X8_CA( 0xbc, 0x00 ), /* data scan dir */
  108. // U8X8_A( 0xa6 ), /* ??? */
  109. // //U8X8_C( 0x030 ), /* select 00 commands */
  110. // U8X8_C( 0x00c ), /* data format LSB top */
  111. // U8X8_END_TRANSFER(), /* disable chip */
  112. // U8X8_END() /* end of sequence */
  113. // };
  114. // static const uint8_t u8x8_d_st75256_jlx256160_flip1_seq[] = {
  115. // U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  116. // U8X8_C( 0x030 ), /* select 00 commands */
  117. // U8X8_CA( 0xbc, 0x03 ), /* data scan dir */
  118. // U8X8_A( 0xa6 ), /* ??? */
  119. // //U8X8_C( 0x030 ), /* select 00 commands */
  120. // U8X8_C( 0x008 ), /* data format MSB top */
  121. // U8X8_END_TRANSFER(), /* disable chip */
  122. // U8X8_END() /* end of sequence */
  123. // };
  124. /*=============================================*/
  125. /* JM16096 https://github.com/olikraus/u8g2/issues/1642 */
  126. static const u8x8_display_info_t u8x8_st75160_jm16096_display_info =
  127. {
  128. /* chip_enable_level = */ 0,
  129. /* chip_disable_level = */ 1,
  130. /* post_chip_enable_wait_ns = */ 20,
  131. /* pre_chip_disable_wait_ns = */ 20,
  132. /* reset_pulse_width_ms = */ 5,
  133. /* post_reset_wait_ms = */ 5, /**/
  134. /* sda_setup_time_ns = */ 20, /* */
  135. /* sck_pulse_width_ns = */ 40, /* */
  136. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  137. /* spi_mode = */ 0, /* active high, rising edge */
  138. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
  139. /* data_setup_time_ns = */ 15,
  140. /* write_pulse_width_ns = */ 70,
  141. /* tile_width = */ 20,
  142. /* tile_hight = */ 12,
  143. /* default_x_offset = */ 0, /* x offset in flipmode 0 */
  144. /* flipmode_x_offset = */ 0, /* */
  145. /* pixel_width = */ 160,
  146. /* pixel_height = */ 96
  147. };
  148. static const uint8_t u8x8_d_st75160_jm16096_init_seq[] = {
  149. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  150. U8X8_DLY(20),
  151. U8X8_C( 0x030 ), /* select 00 commands */
  152. U8X8_C( 0x094 ), /* sleep out */
  153. //U8X8_C( 0x030 ), /* select 00 commands */
  154. U8X8_C( 0x0ae ), /* display off */
  155. U8X8_C( 0x031 ), /* select 01 commands */
  156. U8X8_CA( 0x0d7, 0x09f ), /* disable auto read */
  157. //U8X8_C( 0x031 ), /* select 01 commands */
  158. U8X8_C( 0x032 ), /* analog circuit set */
  159. U8X8_A( 0x000 ), /* code example: OSC Frequency adjustment */
  160. U8X8_A( 0x001 ), /* Frequency on booster capacitors 1 = 6KHz? */
  161. U8X8_A( 0x004 ), /* Bias: 1: 1/13, 2: 1/12, 3: 1/11, 4:1/10, 5:1/9 */
  162. //U8X8_C( 0x031 ), /* select 01 commands */
  163. U8X8_C( 0x020 ), /* gray levels */
  164. U8X8_A( 0x01 ),
  165. U8X8_A( 0x03 ),
  166. U8X8_A( 0x05 ),
  167. U8X8_A( 0x07 ),
  168. U8X8_A( 0x09),
  169. U8X8_A( 0x0b ),
  170. U8X8_A( 0x0d ),
  171. U8X8_A( 0x10 ),
  172. U8X8_A( 0x11 ),
  173. U8X8_A( 0x13 ),
  174. U8X8_A( 0x15 ),
  175. U8X8_A( 0x17 ),
  176. U8X8_A( 0x19 ),
  177. U8X8_A( 0x1b ),
  178. U8X8_A( 0x1d ),
  179. U8X8_A( 0x1f ),
  180. U8X8_C( 0x030 ), /* select 00 commands */
  181. U8X8_CAA(0x75, 0, 0x4f), /* row range */
  182. U8X8_CAA(0x15, 0, 239), /* col range */
  183. //U8X8_C( 0x030 ), /* select 00 commands */
  184. U8X8_CA( 0xbc, 0x02 ), /* data scan dir */
  185. U8X8_A( 0xa6 ), /* ??? */
  186. //U8X8_C( 0x030 ), /* select 00 commands */
  187. U8X8_C( 0x00c ), /* data format LSB top */
  188. //U8X8_C( 0x030 ), /* select 00 commands */
  189. U8X8_C( 0xca ), /* display control, 3 args follow */
  190. U8X8_A( 0x00 ), /* 0x00: no clock division, 0x04: devide clock */
  191. U8X8_A( 95 ), /* 1/96 duty */
  192. U8X8_A( 0x20 ), /* nline off */
  193. //U8X8_C( 0x030 ), /* select 00 commands */
  194. U8X8_CA( 0x0f0, 0x010 ), /* monochrome mode = 0x010*/
  195. //U8X8_C( 0x030 ), /* select 00 commands */
  196. U8X8_CAA( 0x81, 0x18, 0x04 ), /* Volume control */
  197. //U8X8_C( 0x030 ), /* select 00 commands */
  198. U8X8_CA( 0x020, 0x00b ), /* Power control: Regulator, follower & booster on */
  199. U8X8_DLY(100),
  200. U8X8_END_TRANSFER(), /* disable chip */
  201. U8X8_END() /* end of sequence */
  202. };
  203. uint8_t u8x8_d_st75160_jm16096(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  204. {
  205. uint8_t x, c;
  206. uint8_t *ptr;
  207. switch(msg)
  208. {
  209. case U8X8_MSG_DISPLAY_DRAW_TILE:
  210. u8x8_cad_StartTransfer(u8x8);
  211. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  212. x *= 8;
  213. u8x8_cad_SendCmd(u8x8, 0x030 ); /* select command set */
  214. u8x8_cad_SendCmd(u8x8, 0x075 ); /* row */
  215. if ( u8x8->x_offset == 0 ) /* 0 means flip mode 1 */
  216. u8x8_cad_SendArg(u8x8, 1+(((u8x8_tile_t *)arg_ptr)->y_pos));
  217. else
  218. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  219. u8x8_cad_SendArg(u8x8, 0x04f);
  220. //u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  221. u8x8_cad_SendCmd(u8x8, 0x015 ); /* col */
  222. u8x8_cad_SendArg(u8x8, x+u8x8->x_offset);
  223. u8x8_cad_SendArg(u8x8, 255);
  224. u8x8_cad_SendCmd(u8x8, 0x05c );
  225. do
  226. {
  227. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  228. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  229. c *= 8;
  230. if ( c + x > 160u )
  231. {
  232. c = 160u;
  233. c -= x;
  234. }
  235. u8x8_cad_SendData(u8x8, c, ptr);
  236. x += c;
  237. arg_int--;
  238. } while( arg_int > 0 );
  239. u8x8_cad_EndTransfer(u8x8);
  240. return 1;
  241. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  242. //u8x8_SetI2CAddress(u8x8, 0x078); /* lowest I2C adr of the ST75256 */
  243. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75160_jm16096_display_info);
  244. return 1;
  245. case U8X8_MSG_DISPLAY_INIT:
  246. u8x8_d_helper_display_init(u8x8);
  247. u8x8_cad_SendSequence(u8x8, u8x8_d_st75160_jm16096_init_seq);
  248. return 1;
  249. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  250. if ( arg_int == 0 )
  251. u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave0_seq);
  252. else
  253. u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_powersave1_seq);
  254. return 1;
  255. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  256. if ( arg_int == 0 )
  257. {
  258. u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_jlx172104_flip0_seq);
  259. u8x8->x_offset = u8x8->display_info->default_x_offset;
  260. }
  261. else
  262. {
  263. u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_jlx172104_flip1_seq);
  264. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  265. }
  266. return 1;
  267. #ifdef U8X8_WITH_SET_CONTRAST
  268. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  269. u8x8_cad_StartTransfer(u8x8);
  270. u8x8_cad_SendCmd(u8x8, 0x030 );
  271. u8x8_cad_SendCmd(u8x8, 0x081 ); /* there are 9 bit for the volume control */
  272. u8x8_cad_SendArg(u8x8, (arg_int & 0x1f)<<1 ); /* lower 6 bit */
  273. u8x8_cad_SendArg(u8x8, (arg_int>>5)); /* upper 3 bit */
  274. u8x8_cad_EndTransfer(u8x8);
  275. return 1;
  276. #endif
  277. }
  278. return 0;
  279. }