u8x8_d_uc1638.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. u8x8_d_uc1638.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2016, 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. Support for the UC1638 controller
  27. 20 Jun 2021:
  28. The u8x8_d_uc1638_192x96 is tested and works.
  29. The u8x8_d_uc1638_160x128 will probably not work, there is no display to test this
  30. WARNING; The u8x8_d_uc1638_160x128 also has an inverted CS signal !!!
  31. Changed the SPI mode from 3 to 0, because it work nicely with mode 0
  32. */
  33. #include "u8x8.h"
  34. static const uint8_t u8x8_d_uc1638_powersave0_seq[] = {
  35. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  36. U8X8_CA(0x0c9, 0x0ad), /* display on */ /* UC1638 B/W mode */
  37. U8X8_END_TRANSFER(), /* disable chip */
  38. U8X8_END() /* end of sequence */
  39. };
  40. static const uint8_t u8x8_d_uc1638_powersave1_seq[] = {
  41. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  42. U8X8_CA(0x0c9, 0x0ac), /* display off */ /* UC1638 */
  43. U8X8_END_TRANSFER(), /* disable chip */
  44. U8X8_END() /* end of sequence */
  45. };
  46. static const uint8_t u8x8_d_uc1638_flip0_seq[] = {
  47. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  48. U8X8_C(0x0c2), /* LCD Mapping */ /* UC1638*/
  49. U8X8_END_TRANSFER(), /* disable chip */
  50. U8X8_END() /* end of sequence */
  51. };
  52. static const uint8_t u8x8_d_uc1638_flip1_seq[] = {
  53. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  54. U8X8_C(0x0c4), /* LCD Mapping */ /* UC1638*/
  55. U8X8_END_TRANSFER(), /* disable chip */
  56. U8X8_END() /* end of sequence */
  57. };
  58. uint8_t u8x8_d_uc1638_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  59. {
  60. uint8_t x, y, c;
  61. uint8_t *ptr;
  62. switch(msg)
  63. {
  64. case U8X8_MSG_DISPLAY_DRAW_TILE:
  65. u8x8_cad_StartTransfer(u8x8);
  66. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  67. x += u8x8->x_offset & 15;
  68. x *= 8;
  69. u8x8_cad_SendCmd(u8x8, 0x004); /* UC1638 */
  70. u8x8_cad_SendArg(u8x8, x);
  71. y = ((u8x8_tile_t *)arg_ptr)->y_pos;
  72. y += u8x8->x_offset >> 4;
  73. u8x8_cad_SendCmd(u8x8, 0x060 | (y&15)); /* UC1638 */
  74. u8x8_cad_SendCmd(u8x8, 0x070 | (y>>4)); /* UC1638 */
  75. u8x8_cad_SendCmd(u8x8, 0x001); /* UC1638 */
  76. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  77. c *= 8;
  78. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  79. do
  80. {
  81. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  82. arg_int--;
  83. } while( arg_int > 0 );
  84. u8x8_cad_EndTransfer(u8x8);
  85. break;
  86. /* handled in the calling procedure
  87. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  88. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1638_128x64_display_info);
  89. break;
  90. case U8X8_MSG_DISPLAY_INIT:
  91. u8x8_d_helper_display_init(u8x8);
  92. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1701_dogs102_init_seq);
  93. break;
  94. */
  95. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  96. if ( arg_int == 0 )
  97. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_powersave0_seq);
  98. else
  99. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_powersave1_seq);
  100. break;
  101. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  102. if ( arg_int == 0 )
  103. {
  104. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_flip0_seq);
  105. u8x8->x_offset = u8x8->display_info->default_x_offset;
  106. }
  107. else
  108. {
  109. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_flip1_seq);
  110. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  111. }
  112. break;
  113. #ifdef U8X8_WITH_SET_CONTRAST
  114. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  115. u8x8_cad_StartTransfer(u8x8);
  116. u8x8_cad_SendCmd(u8x8, 0x081 );
  117. u8x8_cad_SendArg(u8x8, arg_int ); /* uc1638 has range from 0 to 255 */
  118. u8x8_cad_EndTransfer(u8x8);
  119. break;
  120. #endif
  121. default:
  122. return 0;
  123. }
  124. return 1;
  125. }
  126. /*================================================*/
  127. /* uc1638 160x128 */
  128. /* values taken from uc1608 */
  129. static const u8x8_display_info_t u8x8_uc1638_160x128_display_info =
  130. {
  131. /* chip_enable_level = */ 1, /* uc1638 has high active CS */
  132. /* chip_disable_level = */ 0,
  133. /* post_chip_enable_wait_ns = */ 10, /* */
  134. /* pre_chip_disable_wait_ns = */ 20, /* */
  135. /* reset_pulse_width_ms = */ 5, /* */
  136. /* post_reset_wait_ms = */ 150,
  137. /* sda_setup_time_ns = */ 25, /* */
  138. /* sck_pulse_width_ns = */ 65, /* */
  139. /* sck_clock_hz = */ 1000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  140. /* spi_mode = */ 0, /* active high, rising edge */
  141. /* i2c_bus_clock_100kHz = */ 4,
  142. /* data_setup_time_ns = */ 30, /* */
  143. /* write_pulse_width_ns = */ 35, /* */
  144. /* tile_width = */ 20, /* width of 20*8=160 pixel */
  145. /* tile_height = */ 16,
  146. /* default_x_offset = */ 0, /* lower nibble: x offset, upper nibble: y offset */
  147. /* flipmode_x_offset = */ 0, /* lower nibble: x offset, upper nibble: y offset */
  148. /* pixel_width = */ 160,
  149. /* pixel_height = */ 128
  150. };
  151. static const uint8_t u8x8_d_uc1638_160x128_init_seq[] = {
  152. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  153. U8X8_CA(0x0e1, 0x0e2), /* software reset */ /* UC1638*/
  154. U8X8_END_TRANSFER(), /* disable chip, requirement for I2C */
  155. U8X8_DLY(5), /* 5 ms */
  156. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  157. U8X8_C(0x024), /* set temp comp*/
  158. U8X8_C(0x0c0), /* mirror y and mirror x */ /* WAS: c2 */
  159. U8X8_C(0x0a2), /* line rate */
  160. U8X8_C(0x0d6), /* gray scale 2 */
  161. U8X8_C(0x0eb), /* set bias*/
  162. U8X8_C(0x095), /* set 1 bit per pixel, pattern 0*/
  163. U8X8_C(0x089), /* set auto increment, low bits are AC2 AC1 AC0 */ /* WAS 89 */
  164. U8X8_CA(0x081, 0x0a0), /* set contrast */ /* UC1638*/
  165. U8X8_END_TRANSFER(), /* disable chip */
  166. U8X8_END() /* end of sequence */
  167. };
  168. uint8_t u8x8_d_uc1638_160x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  169. {
  170. /* call common procedure first and handle messages there */
  171. if ( u8x8_d_uc1638_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  172. {
  173. /* msg not handled, then try here */
  174. switch(msg)
  175. {
  176. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  177. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1638_160x128_display_info);
  178. break;
  179. case U8X8_MSG_DISPLAY_INIT:
  180. u8x8_d_helper_display_init(u8x8);
  181. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_160x128_init_seq);
  182. break;
  183. default:
  184. return 0; /* msg unknown */
  185. }
  186. }
  187. return 1;
  188. }
  189. /*================================================*/
  190. /* LG192962-DW-V33, uc1638 192x96, https://github.com/olikraus/u8g2/issues/371 */
  191. static const u8x8_display_info_t u8x8_uc1638_192x96_display_info =
  192. {
  193. /* chip_enable_level = */ 0, /* low active CS for this display */
  194. /* chip_disable_level = */ 1,
  195. /* post_chip_enable_wait_ns = */ 10, /* */
  196. /* pre_chip_disable_wait_ns = */ 20, /* */
  197. /* reset_pulse_width_ms = */ 5, /* */
  198. /* post_reset_wait_ms = */ 150,
  199. /* sda_setup_time_ns = */ 25, /* */
  200. /* sck_pulse_width_ns = */ 65, /* */
  201. /* sck_clock_hz = */ 2000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  202. /* spi_mode = */ 0, /* active high, rising edge */
  203. /* i2c_bus_clock_100kHz = */ 4,
  204. /* data_setup_time_ns = */ 30, /* */
  205. /* write_pulse_width_ns = */ 35, /* */
  206. /* tile_width = */ 24, /* width of 24*8=192 pixel */
  207. /* tile_height = */ 12,
  208. /* default_x_offset = */ 8*16+0, /* lower nibble: x offset, upper nibble: y offset */
  209. /* flipmode_x_offset = */ 0*16+6, /* lower nibble: x offset, upper nibble: y offset */
  210. /* pixel_width = */ 192,
  211. /* pixel_height = */ 96
  212. };
  213. static const uint8_t u8x8_d_uc1638_192x96_init_seq[] = {
  214. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  215. U8X8_CA(0x0e1, 0x0e2), /* software reset */ /* UC1638*/
  216. U8X8_DLY(5), /* 5 ms */
  217. U8X8_C(0x024), /* set temp comp*/
  218. U8X8_C(0x0c2), /* mirror y and mirror x */
  219. U8X8_C(0x0a2), /* line rate */
  220. U8X8_C(0x02d), /* charge pump */
  221. U8X8_C(0x0ea), /* set bias*/
  222. U8X8_CA(0x081, 160), /* set contrast */
  223. //U8X8_C(0x0d6), /* gray scale 2 */
  224. U8X8_C(0x095), /* set 1 bit per pixel, pattern 0*/
  225. U8X8_C(0x086), /* COM scan */
  226. U8X8_CA(0x0f1, 159), /* COM End*/
  227. U8X8_C(0x089), /* set auto increment, low bits are AC2 AC1 AC0 */ /* WAS 89 */
  228. //U8X8_C(0x086), /* scan function 0x86 or 0x87: no effect*/
  229. U8X8_END_TRANSFER(), /* disable chip */
  230. U8X8_END() /* end of sequence */
  231. };
  232. uint8_t u8x8_d_uc1638_192x96(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  233. {
  234. /* call common procedure first and handle messages there */
  235. if ( u8x8_d_uc1638_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  236. {
  237. /* msg not handled, then try here */
  238. switch(msg)
  239. {
  240. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  241. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1638_192x96_display_info);
  242. break;
  243. case U8X8_MSG_DISPLAY_INIT:
  244. u8x8_d_helper_display_init(u8x8);
  245. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_192x96_init_seq);
  246. break;
  247. default:
  248. return 0; /* msg unknown */
  249. }
  250. }
  251. return 1;
  252. }
  253. /*================================================*/
  254. /* issue https://github.com/olikraus/u8g2/issues/2075 */
  255. static const u8x8_display_info_t u8x8_uc1638_240x128_display_info =
  256. {
  257. /* chip_enable_level = */ 0, /* low active CS for this display */
  258. /* chip_disable_level = */ 1,
  259. /* post_chip_enable_wait_ns = */ 10, /* */
  260. /* pre_chip_disable_wait_ns = */ 20, /* */
  261. /* reset_pulse_width_ms = */ 5, /* */
  262. /* post_reset_wait_ms = */ 150,
  263. /* sda_setup_time_ns = */ 25, /* */
  264. /* sck_pulse_width_ns = */ 65, /* */
  265. /* sck_clock_hz = */ 2000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  266. /* spi_mode = */ 0, /* active high, rising edge */
  267. /* i2c_bus_clock_100kHz = */ 4,
  268. /* data_setup_time_ns = */ 30, /* */
  269. /* write_pulse_width_ns = */ 35, /* */
  270. /* tile_width = */ 30, /* width of 30*8=240 pixel */
  271. /* tile_height = */ 16,
  272. /* default_x_offset = */ 0*16+0, /* lower nibble: x offset, upper nibble: y offset */
  273. /* flipmode_x_offset = */ 4*16+0, /* lower nibble: x offset, upper nibble: y offset */
  274. /* pixel_width = */ 240,
  275. /* pixel_height = */ 128
  276. };
  277. static const uint8_t u8x8_d_uc1638_240x128_init_seq[] = {
  278. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  279. U8X8_CA(0x0e1, 0x0e2), /* software reset */ /* UC1638*/
  280. U8X8_DLY(5), /* 5 ms */
  281. U8X8_C(0x024), /* set temp comp*/
  282. U8X8_C(0x0c2), /* mirror y and mirror x */
  283. U8X8_C(0x0a2), /* line rate */
  284. //U8X8_C(0x02d), /* charge pump, issue 2075: not used */
  285. U8X8_C(0x0eb), /* set bias, issue 2075: 0x0eb*/
  286. U8X8_CA(0x081, 120), /* set contrast, issue 2075 */
  287. //U8X8_C(0x0d6), /* gray scale 2 */
  288. U8X8_C(0x095), /* set 1 bit per pixel, pattern 0*/
  289. //U8X8_C(0x086), /* COM scan, issue 2075: not used */
  290. //U8X8_CA(0x0f1, 159), /* COM End, issue 2075: not used */
  291. U8X8_C(0x089), /* set auto increment, low bits are AC2 AC1 AC0 */ /* WAS 89 */
  292. //U8X8_C(0x086), /* scan function 0x86 or 0x87: no effect*/
  293. U8X8_END_TRANSFER(), /* disable chip */
  294. U8X8_END() /* end of sequence */
  295. };
  296. uint8_t u8x8_d_uc1638_240x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  297. {
  298. /* call common procedure first and handle messages there */
  299. if ( u8x8_d_uc1638_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  300. {
  301. /* msg not handled, then try here */
  302. switch(msg)
  303. {
  304. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  305. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1638_240x128_display_info);
  306. break;
  307. case U8X8_MSG_DISPLAY_INIT:
  308. u8x8_d_helper_display_init(u8x8);
  309. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1638_240x128_init_seq);
  310. break;
  311. default:
  312. return 0; /* msg unknown */
  313. }
  314. }
  315. return 1;
  316. }