u8x8_d_uc1610.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. u8x8_d_uc1610.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. cad001
  27. */
  28. #include "u8x8.h"
  29. static const uint8_t u8x8_d_uc1610_dogxl160_init_seq[] = {
  30. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  31. U8X8_CA(0x0f1, 0x067), /* set COM end (display height-1) */
  32. U8X8_C(0x0c0), /* SEG & COM normal */
  33. U8X8_C(0x040), /* set scroll line lsb to zero */
  34. U8X8_C(0x050), /* set scroll line msb to zero */
  35. U8X8_C(0x02b), /* set panelloading */
  36. U8X8_C(0x0eb), /* set bias 1/2 */
  37. U8X8_CA(0x081, 0x05f), /* set contrast */
  38. /*
  39. AC0: 0: stop at boundary, 1: increment by one
  40. AC1: 0: first column then page, 1: first page, then column increment
  41. AC2: 0: increment page adr, 1: decrement page adr.
  42. */
  43. U8X8_C(0x08b), /* set auto increment, low bits are AC2 AC1 AC0 */
  44. /*
  45. LC0: 0
  46. MX: Mirror X
  47. MY: Mirror Y
  48. */
  49. U8X8_C(0x0c0), /* low bits are MY, MX, LC0 */
  50. U8X8_C(0x0f8), // window mode off
  51. U8X8_C(0x010), // col high
  52. U8X8_C(0x000), // col low
  53. U8X8_C(0x0b0), // page
  54. U8X8_C(0x0a6), /* set normal pixel mode (not inverse) */
  55. U8X8_C(0x0a4), /* set normal pixel mode (not all on) */
  56. /* test code
  57. U8X8_C(0x0af), // display on
  58. U8X8_C(0x0f8), // window mode off
  59. U8X8_CA(0x0f4, 0), // set window
  60. U8X8_CA(0x0f5, 0),
  61. U8X8_CA(0x0f6, 4),
  62. U8X8_CA(0x0f7, 1),
  63. U8X8_C(0x0f9), // window mode on
  64. U8X8_D1(0x03),
  65. U8X8_D1(0x0c0),
  66. U8X8_D1(0x0ff),
  67. U8X8_D1(0x0ff),
  68. U8X8_D1(0x0ff),
  69. U8X8_D1(0x0ff),
  70. U8X8_D1(0x0ff),
  71. U8X8_D1(0x0ff),
  72. */
  73. U8X8_END_TRANSFER(), /* disable chip */
  74. U8X8_END() /* end of sequence */
  75. };
  76. static const uint8_t u8x8_d_uc1610_dogxl160_powersave0_seq[] = {
  77. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  78. U8X8_C(0x0af), /* display on, UC1610 */
  79. U8X8_END_TRANSFER(), /* disable chip */
  80. U8X8_END() /* end of sequence */
  81. };
  82. static const uint8_t u8x8_d_uc1610_dogxl160_powersave1_seq[] = {
  83. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  84. U8X8_C(0x0ae), /* display off, UC1610 */
  85. U8X8_END_TRANSFER(), /* disable chip */
  86. U8X8_END() /* end of sequence */
  87. };
  88. static const uint8_t u8x8_d_uc1610_dogxl160_flip0_seq[] = {
  89. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  90. /*
  91. LC0: 0
  92. MX: Mirror X
  93. MY: Mirror Y
  94. */
  95. U8X8_C(0x0c0), /* low bits are MY, MX, LC0 */
  96. U8X8_END_TRANSFER(), /* disable chip */
  97. U8X8_END() /* end of sequence */
  98. };
  99. static const uint8_t u8x8_d_uc1610_dogxl160_flip1_seq[] = {
  100. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  101. /*
  102. LC0: 0
  103. MX: Mirror X
  104. MY: Mirror Y
  105. */
  106. U8X8_C(0x0c6), /* low bits are MY, MX, LC0 */
  107. U8X8_END_TRANSFER(), /* disable chip */
  108. U8X8_END() /* end of sequence */
  109. };
  110. /*
  111. UC1610 has two chip select inputs (CS0 and CS1).
  112. CS0 is low active, CS1 is high active. It will depend on the display
  113. module whether the display has a is low or high active chip select.
  114. */
  115. static const u8x8_display_info_t u8x8_uc1610_display_info =
  116. {
  117. /* chip_enable_level = */ 0,
  118. /* chip_disable_level = */ 1,
  119. /* post_chip_enable_wait_ns = */ 15,
  120. /* pre_chip_disable_wait_ns = */ 15,
  121. /* reset_pulse_width_ms = */ 1,
  122. /* post_reset_wait_ms = */ 6,
  123. /* sda_setup_time_ns = */ 30,
  124. /* sck_pulse_width_ns = */ 63, /* half of cycle time (125ns cycle time according to datasheet) --> 8MHz clock */
  125. /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  126. /* spi_mode = */ 0, /* active high, rising edge */
  127. /* i2c_bus_clock_100kHz = */ 4,
  128. /* data_setup_time_ns = */ 30,
  129. /* write_pulse_width_ns = */ 40,
  130. /* tile_width = */ 20,
  131. /* tile_height = */ 13, /* height of 13*8=104 pixel */
  132. /* default_x_offset = */ 0,
  133. /* flipmode_x_offset = */ 0,
  134. /* pixel_width = */ 160,
  135. /* pixel_height = */ 104
  136. };
  137. /*
  138. RAM Organization:
  139. D0 Pix0
  140. D1
  141. D2 Pix1
  142. D3
  143. D4 Pix2
  144. D5
  145. D6 Pix3
  146. D7
  147. D0 Pix4
  148. D1
  149. D2 Pix5
  150. D3
  151. D4 Pix6
  152. D5
  153. D6 Pix7
  154. D7
  155. */
  156. static uint8_t *u8x8_convert_tile_for_uc1610(uint8_t *t)
  157. {
  158. uint8_t i;
  159. uint16_t r;
  160. static uint8_t buf[16];
  161. uint8_t *pbuf = buf;
  162. for( i = 0; i < 8; i++ )
  163. {
  164. r = u8x8_upscale_byte(*t++);
  165. *pbuf++ = r & 255;
  166. r >>= 8;
  167. *pbuf++ = r;
  168. }
  169. return buf;
  170. }
  171. uint8_t u8x8_d_uc1610_ea_dogxl160(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  172. {
  173. uint8_t x, c, page;
  174. uint8_t *ptr;
  175. switch(msg)
  176. {
  177. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  178. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1610_display_info);
  179. break;
  180. case U8X8_MSG_DISPLAY_INIT:
  181. u8x8_d_helper_display_init(u8x8);
  182. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1610_dogxl160_init_seq);
  183. break;
  184. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  185. if ( arg_int == 0 )
  186. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1610_dogxl160_powersave0_seq);
  187. else
  188. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1610_dogxl160_powersave1_seq);
  189. break;
  190. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  191. if ( arg_int == 0 )
  192. {
  193. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1610_dogxl160_flip0_seq);
  194. u8x8->x_offset = u8x8->display_info->default_x_offset;
  195. }
  196. else
  197. {
  198. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1610_dogxl160_flip1_seq);
  199. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  200. }
  201. break;
  202. #ifdef U8X8_WITH_SET_CONTRAST
  203. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  204. u8x8_cad_StartTransfer(u8x8);
  205. u8x8_cad_SendCmd(u8x8, 0x081 );
  206. u8x8_cad_SendArg(u8x8, arg_int ); /* uc1610 has range from 0 to 255 */
  207. u8x8_cad_EndTransfer(u8x8);
  208. break;
  209. #endif
  210. case U8X8_MSG_DISPLAY_DRAW_TILE:
  211. u8x8_cad_StartTransfer(u8x8);
  212. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  213. x *= 8;
  214. x += u8x8->x_offset;
  215. page = (((u8x8_tile_t *)arg_ptr)->y_pos);
  216. page *= 2;
  217. u8x8_cad_SendCmd(u8x8, 0x0f8 ); /* window disable */
  218. //u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  219. //u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  220. //u8x8_cad_SendCmd(u8x8, 0x0b0 | page);
  221. u8x8_cad_SendCmd(u8x8, 0x0f4 ); /* window start column */
  222. u8x8_cad_SendArg(u8x8, x);
  223. u8x8_cad_SendCmd(u8x8, 0x0f5 ); /* window start page */
  224. u8x8_cad_SendArg(u8x8, page);
  225. u8x8_cad_SendCmd(u8x8, 0x0f6 ); /* window end column */
  226. u8x8_cad_SendArg(u8x8, 159); /* end of display */
  227. u8x8_cad_SendCmd(u8x8, 0x0f7 ); /* window end page */
  228. u8x8_cad_SendArg(u8x8, page+1);
  229. u8x8_cad_SendCmd(u8x8, 0x0f9 ); /* window enable */
  230. do
  231. {
  232. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  233. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  234. do
  235. {
  236. u8x8_cad_SendData(u8x8, 16, u8x8_convert_tile_for_uc1610(ptr));
  237. ptr += 8;
  238. x += 8;
  239. c--;
  240. } while( c > 0 );
  241. arg_int--;
  242. } while( arg_int > 0 );
  243. u8x8_cad_EndTransfer(u8x8);
  244. break;
  245. default:
  246. return 0;
  247. }
  248. return 1;
  249. }