u8x8_d_st75160.c 12 KB

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