u8x8_d_uc1604.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. u8x8_d_uc1604.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. */
  27. #include "u8x8.h"
  28. static const uint8_t u8x8_d_uc1604_powersave0_seq[] = {
  29. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  30. U8X8_DLY(20),
  31. U8X8_C(0x0af), /* display on */
  32. U8X8_DLY(20), /* during setup, it seems that the startup is more reliable when sending this cmd twice */
  33. U8X8_C(0x0af), /* display on */
  34. U8X8_DLY(50), /* startup takes some time */
  35. U8X8_END_TRANSFER(), /* disable chip */
  36. U8X8_END() /* end of sequence */
  37. };
  38. static const uint8_t u8x8_d_uc1604_powersave1_seq[] = {
  39. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  40. U8X8_C(0x0ae), /* display off, enter sleep mode */
  41. U8X8_END_TRANSFER(), /* disable chip */
  42. U8X8_END() /* end of sequence */
  43. };
  44. static const uint8_t u8x8_d_uc1604_flip0_seq[] = {
  45. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  46. U8X8_C(0x0c4), /* LCD Mapping */
  47. U8X8_END_TRANSFER(), /* disable chip */
  48. U8X8_END() /* end of sequence */
  49. };
  50. static const uint8_t u8x8_d_uc1604_flip1_seq[] = {
  51. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  52. U8X8_C(0x0c2), /* LCD Mapping */
  53. U8X8_END_TRANSFER(), /* disable chip */
  54. U8X8_END() /* end of sequence */
  55. };
  56. uint8_t u8x8_d_uc1604_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  57. {
  58. uint8_t x, y, c;
  59. uint8_t *ptr;
  60. switch(msg)
  61. {
  62. case U8X8_MSG_DISPLAY_DRAW_TILE:
  63. u8x8_cad_StartTransfer(u8x8);
  64. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  65. x *= 8;
  66. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  67. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  68. y = ((u8x8_tile_t *)arg_ptr)->y_pos;
  69. y += u8x8->x_offset;
  70. u8x8_cad_SendCmd(u8x8, 0x0b0 | (y&15));
  71. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  72. c *= 8;
  73. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  74. do
  75. {
  76. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  77. arg_int--;
  78. } while( arg_int > 0 );
  79. u8x8_cad_EndTransfer(u8x8);
  80. break;
  81. /* handled in the calling procedure
  82. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  83. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_128x64_display_info);
  84. break;
  85. case U8X8_MSG_DISPLAY_INIT:
  86. u8x8_d_helper_display_init(u8x8);
  87. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1701_dogs102_init_seq);
  88. break;
  89. */
  90. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  91. if ( arg_int == 0 )
  92. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_powersave0_seq);
  93. else
  94. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_powersave1_seq);
  95. break;
  96. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  97. if ( arg_int == 0 )
  98. {
  99. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_flip0_seq);
  100. u8x8->x_offset = u8x8->display_info->default_x_offset;
  101. }
  102. else
  103. {
  104. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_flip1_seq);
  105. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  106. }
  107. break;
  108. #ifdef U8X8_WITH_SET_CONTRAST
  109. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  110. u8x8_cad_StartTransfer(u8x8);
  111. u8x8_cad_SendCmd(u8x8, 0x081 );
  112. u8x8_cad_SendArg(u8x8, arg_int ); /* uc1604 has range from 0 to 255 */
  113. u8x8_cad_EndTransfer(u8x8);
  114. break;
  115. #endif
  116. default:
  117. return 0;
  118. }
  119. return 1;
  120. }
  121. /*================================================*/
  122. /* JLX12864 */
  123. /*
  124. timings from uc1604
  125. UC1604 has two chip select inputs (CS0 and CS1).
  126. CS0 is low active, CS1 is high active. It will depend on the display
  127. module whether the display has a is low or high active chip select.
  128. */
  129. static const u8x8_display_info_t u8x8_uc1604_128x64_display_info =
  130. {
  131. /* chip_enable_level = */ 0, /* JLX12864G uses CS0, which is low active CS*/
  132. /* chip_disable_level = */ 1,
  133. /* post_chip_enable_wait_ns = */ 20,
  134. /* pre_chip_disable_wait_ns = */ 20,
  135. /* reset_pulse_width_ms = */ 1,
  136. /* post_reset_wait_ms = */ 10,
  137. /* sda_setup_time_ns = */ 30,
  138. /* sck_pulse_width_ns = */ 65, /* half of cycle time */
  139. /* sck_clock_hz = */ 8000000UL, /* 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 = */ 16, /* width of 24*8=192 pixel */
  145. /* tile_height = */ 8,
  146. /* default_x_offset = */ 0, /* reused as y page offset */
  147. /* flipmode_x_offset = */ 0, /* reused as y page offset */
  148. /* pixel_width = */ 128,
  149. /* pixel_height = */ 64
  150. };
  151. static const uint8_t u8x8_d_uc1604_jlx12864_init_seq[] = {
  152. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  153. U8X8_C(0x0e2), /* soft reset */
  154. U8X8_DLY(200),
  155. U8X8_DLY(200),
  156. U8X8_C(0x02f), /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
  157. U8X8_DLY(200),
  158. U8X8_DLY(200),
  159. U8X8_CA(0x081, 0x038), /* set contrast, JLX19264G suggestion: 0x045 */
  160. U8X8_C(0x0eb), /* LCD bias Bits 0/1: 00=6 01=7, 10=8, 11=9 */
  161. //U8X8_C(0x023), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
  162. //U8X8_C(0x027), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
  163. U8X8_C(0x0c2), /* Map control, Bit 2: MY=1, Bit 1: MX=0 */
  164. U8X8_C(0x0a0), /* 0xa0: 76Hz FPS, controller default: 0x0a1: 95Hz FPS */
  165. U8X8_C(0x040), /* set scroll line to 0 */
  166. U8X8_C(0x089), /* RAM access control (controller default: 0x089)*/
  167. U8X8_C(0x000), /* column low nibble */
  168. U8X8_C(0x010), /* column high nibble */
  169. U8X8_C(0x0b0), /* page adr */
  170. U8X8_END_TRANSFER(), /* disable chip */
  171. U8X8_END() /* end of sequence */
  172. };
  173. uint8_t u8x8_d_uc1604_jlx12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  174. {
  175. /* call common procedure first and handle messages there */
  176. if ( u8x8_d_uc1604_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  177. {
  178. /* msg not handled, then try here */
  179. switch(msg)
  180. {
  181. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  182. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_128x64_display_info);
  183. break;
  184. case U8X8_MSG_DISPLAY_INIT:
  185. u8x8_d_helper_display_init(u8x8);
  186. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_jlx12864_init_seq);
  187. break;
  188. default:
  189. return 0; /* msg unknown */
  190. }
  191. }
  192. return 1;
  193. }
  194. /*================================================*/
  195. /* JLX19264 */
  196. /*
  197. timings from uc1608
  198. UC1604 has two chip select inputs (CS0 and CS1).
  199. CS0 is low active, CS1 is high active. It will depend on the display
  200. module whether the display has a is low or high active chip select.
  201. */
  202. static const u8x8_display_info_t u8x8_uc1604_192x64_display_info =
  203. {
  204. /* chip_enable_level = */ 0, /* JLX19264G uses CS0, which is low active CS*/
  205. /* chip_disable_level = */ 1,
  206. /* post_chip_enable_wait_ns = */ 20,
  207. /* pre_chip_disable_wait_ns = */ 20,
  208. /* reset_pulse_width_ms = */ 1,
  209. /* post_reset_wait_ms = */ 10,
  210. /* sda_setup_time_ns = */ 30,
  211. /* sck_pulse_width_ns = */ 65, /* half of cycle time */
  212. /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  213. /* spi_mode = */ 0, /* active high, rising edge */
  214. /* i2c_bus_clock_100kHz = */ 4,
  215. /* data_setup_time_ns = */ 30,
  216. /* write_pulse_width_ns = */ 35,
  217. /* tile_width = */ 24, /* width of 24*8=192 pixel */
  218. /* tile_height = */ 8,
  219. /* default_x_offset = */ 0, /* reused as y page offset */
  220. /* flipmode_x_offset = */ 0, /* reused as y page offset */
  221. /* pixel_width = */ 192,
  222. /* pixel_height = */ 64
  223. };
  224. static const uint8_t u8x8_d_uc1604_jlx19264_init_seq[] = {
  225. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  226. U8X8_C(0x0e2), /* soft reset */
  227. U8X8_DLY(200),
  228. U8X8_DLY(200),
  229. U8X8_C(0x02f), /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
  230. U8X8_DLY(200),
  231. U8X8_DLY(200),
  232. U8X8_CA(0x081, 0x052), /* set contrast, JLX19264G suggestion: 0x045 */
  233. U8X8_C(0x0eb), /* LCD bias Bits 0/1: 00=6 01=7, 10=8, 11=9 */
  234. //U8X8_C(0x023), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
  235. //U8X8_C(0x027), /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
  236. U8X8_C(0x0c4), /* Map control, Bit 2: MY=1, Bit 1: MX=0 */
  237. U8X8_C(0x0a0), /* 0xa0: 76Hz FPS, controller default: 0x0a1: 95Hz FPS */
  238. U8X8_C(0x040), /* set scroll line to 0 */
  239. U8X8_C(0x089), /* RAM access control (controller default: 0x089)*/
  240. U8X8_C(0x000), /* column low nibble */
  241. U8X8_C(0x010), /* column high nibble */
  242. U8X8_C(0x0b0), /* page adr */
  243. U8X8_END_TRANSFER(), /* disable chip */
  244. U8X8_END() /* end of sequence */
  245. };
  246. uint8_t u8x8_d_uc1604_jlx19264(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  247. {
  248. /* call common procedure first and handle messages there */
  249. if ( u8x8_d_uc1604_common(u8x8, msg, arg_int, arg_ptr) == 0 )
  250. {
  251. /* msg not handled, then try here */
  252. switch(msg)
  253. {
  254. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  255. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1604_192x64_display_info);
  256. break;
  257. case U8X8_MSG_DISPLAY_INIT:
  258. u8x8_d_helper_display_init(u8x8);
  259. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1604_jlx19264_init_seq);
  260. break;
  261. default:
  262. return 0; /* msg unknown */
  263. }
  264. }
  265. return 1;
  266. }