u8x8_d_uc1628.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. u8x8_d_uc1628.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2017, 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. UC1628: Monochrome 163x256 driver
  27. CAD: 011
  28. */
  29. #include "u8x8.h"
  30. static const uint8_t u8x8_d_uc1628_powersave0_seq[] = {
  31. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  32. U8X8_CA( 0x0c9, 0x0ad ), /* display enable */
  33. U8X8_END_TRANSFER(), /* disable chip */
  34. U8X8_END() /* end of sequence */
  35. };
  36. static const uint8_t u8x8_d_uc1628_powersave1_seq[] = {
  37. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  38. U8X8_CA( 0x0c9, 0x0ac ), /* display disable */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_uc1628_flip0_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_C( 0x0c4 ),
  45. U8X8_END_TRANSFER(),
  46. U8X8_END() /* end of sequence */
  47. };
  48. static const uint8_t u8x8_d_uc1628_flip1_seq[] = {
  49. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  50. U8X8_C( 0x0c2 ),
  51. U8X8_END_TRANSFER(), /* disable chip */
  52. U8X8_END() /* end of sequence */
  53. };
  54. static uint8_t u8x8_d_uc1628_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  55. {
  56. uint8_t x, c;
  57. uint8_t *ptr;
  58. switch(msg)
  59. {
  60. /* handled by the calling function
  61. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  62. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st75256_256x128_display_info);
  63. break;
  64. */
  65. /* handled by the calling function
  66. case U8X8_MSG_DISPLAY_INIT:
  67. u8x8_d_helper_display_init(u8x8);
  68. u8x8_cad_SendSequence(u8x8, u8x8_d_st75256_256x128_init_seq);
  69. break;
  70. */
  71. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  72. if ( arg_int == 0 )
  73. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_powersave0_seq);
  74. else
  75. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_powersave1_seq);
  76. break;
  77. #ifdef U8X8_WITH_SET_CONTRAST
  78. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  79. u8x8_cad_StartTransfer(u8x8);
  80. u8x8_cad_SendCmd(u8x8, 0x081 ); /* volume control */
  81. u8x8_cad_SendArg(u8x8, 0 ); /* always 0 */
  82. u8x8_cad_SendArg(u8x8, arg_int); /* 8 bit */
  83. u8x8_cad_EndTransfer(u8x8);
  84. break;
  85. #endif
  86. case U8X8_MSG_DISPLAY_DRAW_TILE:
  87. u8x8_cad_StartTransfer(u8x8);
  88. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  89. x *= 8;
  90. // TODO: u8x8->x_offset IS MISSING here
  91. u8x8_cad_SendCmd(u8x8, 0x004 ); /* col */
  92. u8x8_cad_SendArg(u8x8, x);
  93. u8x8_cad_SendCmd(u8x8, 0x060 ); /* row */
  94. u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos));
  95. u8x8_cad_SendCmd(u8x8, 0x001 ); // write data
  96. do
  97. {
  98. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  99. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  100. /* SendData can not handle more than 255 bytes, treat c > 31 correctly */
  101. if ( c > 31 )
  102. {
  103. u8x8_cad_SendData(u8x8, 248, ptr); /* 31*8=248 */
  104. ptr+=248;
  105. c -= 31;
  106. }
  107. u8x8_cad_SendData(u8x8, c*8, ptr);
  108. arg_int--;
  109. } while( arg_int > 0 );
  110. u8x8_cad_EndTransfer(u8x8);
  111. break;
  112. default:
  113. return 0;
  114. }
  115. return 1;
  116. }
  117. /*=============================================*/
  118. /* 256x128, https://github.com/olikraus/u8g2/issues/2260 */
  119. static const u8x8_display_info_t u8x8_uc1628_256x128_display_info =
  120. {
  121. /* chip_enable_level = */ 0,
  122. /* chip_disable_level = */ 1,
  123. /* post_chip_enable_wait_ns = */ 10,
  124. /* pre_chip_disable_wait_ns = */ 10,
  125. /* reset_pulse_width_ms = */ 5,
  126. /* post_reset_wait_ms = */ 5, /**/
  127. /* sda_setup_time_ns = */ 25, /* */
  128. /* sck_pulse_width_ns = */ 100, /* */
  129. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  130. /* spi_mode = */ 0, /* active high, rising edge */
  131. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
  132. /* data_setup_time_ns = */ 45,
  133. /* write_pulse_width_ns = */ 125,
  134. /* tile_width = */ 32,
  135. /* tile_height = */ 16,
  136. /* default_x_offset = */ 0, /* */
  137. /* flipmode_x_offset = */ 0, /* */
  138. /* pixel_width = */ 256,
  139. /* pixel_height = */ 128
  140. };
  141. static const uint8_t u8x8_d_uc1628_256x128_init_seq[] = {
  142. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  143. U8X8_DLY(20),
  144. U8X8_C( 0x010 ), /* Termp.: Reset default */
  145. U8X8_C( 0x012 ), /* Termp.: Reset default */
  146. U8X8_C( 0x014 ), /* Termp.: Reset default */
  147. /* assign temperature independent framerate */
  148. /* 0x00d = 81,9Hz (reset default) */
  149. /* 0x000 = 40.0 Hz (min) */
  150. /* 0x01f = 140.0 Hz (max) */
  151. U8X8_CAA( 0x016, 0x000, 0x00d ), /* 1st arg: temp. point, 2nd arg: frame rate */
  152. U8X8_CA( 0x040, 0x000 ), /* scroll line */
  153. U8X8_C( 0x020 ), /* temp compensation */
  154. U8X8_C( 0x02d ), /* charge pump control */
  155. U8X8_C( 0x0eb ), /* LCD Bias: 0xe8=6, ... 0xeb=12 ... 0xed=14 */
  156. U8X8_CAA( 0x081, 0x000, 0x048 ), /* Contrast, 1st arg is always 0 */
  157. U8X8_CA( 0x0b8, 0x000 ), /* OTP control: Idle & Ignore */
  158. U8X8_CA( 0x0f1, 0x07f ), /* set COM end */
  159. U8X8_CA( 0x0f2, 0x000 ), /* set partial display start */
  160. U8X8_CA( 0x0f3, 0x07f ), /* set partial display end */
  161. U8X8_C( 0x088 ), /* auto increment control */
  162. U8X8_C( 0x0c4 ), /* XY mirror in bit 1 & 2 */
  163. U8X8_DLY(100),
  164. U8X8_END_TRANSFER(), /* disable chip */
  165. U8X8_END() /* end of sequence */
  166. };
  167. uint8_t u8x8_d_uc1628_256x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  168. {
  169. if ( u8x8_d_uc1628_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
  170. return 1;
  171. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  172. {
  173. u8x8_SetI2CAddress(u8x8, 0x070); /* lowest I2C adr of the UC1628 */
  174. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1628_256x128_display_info);
  175. return 1;
  176. }
  177. else if ( msg == U8X8_MSG_DISPLAY_INIT )
  178. {
  179. u8x8_d_helper_display_init(u8x8);
  180. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_256x128_init_seq);
  181. return 1;
  182. }
  183. else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  184. {
  185. if ( arg_int == 0 )
  186. {
  187. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip0_seq);
  188. u8x8->x_offset = u8x8->display_info->default_x_offset;
  189. }
  190. else
  191. {
  192. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip1_seq);
  193. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  194. }
  195. return 1;
  196. }
  197. return 0;
  198. }
  199. /*=============================================*/
  200. /* 256x32, https://github.com/olikraus/u8g2/issues/2260 */
  201. static const u8x8_display_info_t u8x8_uc1628_256x32_display_info =
  202. {
  203. /* chip_enable_level = */ 0,
  204. /* chip_disable_level = */ 1,
  205. /* post_chip_enable_wait_ns = */ 10,
  206. /* pre_chip_disable_wait_ns = */ 10,
  207. /* reset_pulse_width_ms = */ 5,
  208. /* post_reset_wait_ms = */ 5, /**/
  209. /* sda_setup_time_ns = */ 25, /* */
  210. /* sck_pulse_width_ns = */ 100, /* */
  211. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  212. /* spi_mode = */ 0, /* active high, rising edge */
  213. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
  214. /* data_setup_time_ns = */ 45,
  215. /* write_pulse_width_ns = */ 125,
  216. /* tile_width = */ 32,
  217. /* tile_height = */ 4,
  218. /* default_x_offset = */ 0, /* */
  219. /* flipmode_x_offset = */ 0, /* */
  220. /* pixel_width = */ 256,
  221. /* pixel_height = */ 32
  222. };
  223. static const uint8_t u8x8_d_uc1628_256x32_init_seq[] = {
  224. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  225. U8X8_DLY(20),
  226. U8X8_C( 0x010 ), /* Termp.: Reset default */
  227. U8X8_C( 0x012 ), /* Termp.: Reset default */
  228. U8X8_C( 0x014 ), /* Termp.: Reset default */
  229. /* assign temperature independent framerate */
  230. /* 0x00d = 81,9Hz (reset default) */
  231. /* 0x000 = 40.0 Hz (min) */
  232. /* 0x01f = 140.0 Hz (max) */
  233. U8X8_CAA( 0x016, 0x000, 0x00d ), /* 1st arg: temp. point, 2nd arg: frame rate */
  234. U8X8_CA( 0x040, 0x000 ), /* scroll line */
  235. U8X8_C( 0x020 ), /* temp compensation */
  236. U8X8_C( 0x02d ), /* charge pump control */
  237. U8X8_C( 0x0e8 ), /* LCD Bias: 0xe8=6, ... 0xeb=12 ... 0xed=14 */
  238. U8X8_CAA( 0x081, 0x000, 0x048 ), /* Contrast, 1st arg is always 0 */
  239. U8X8_CA( 0x0b8, 0x000 ), /* OTP control: Idle & Ignore */
  240. U8X8_CA( 0x0f1, 0x01f ), /* set COM end */
  241. U8X8_CA( 0x0f2, 0x000 ), /* set partial display start */
  242. U8X8_CA( 0x0f3, 0x07f ), /* set partial display end */
  243. U8X8_C( 0x088 ), /* auto increment control */
  244. U8X8_C( 0x0c4 ), /* XY mirror in bit 1 & 2 */
  245. U8X8_DLY(100),
  246. U8X8_END_TRANSFER(), /* disable chip */
  247. U8X8_END() /* end of sequence */
  248. };
  249. uint8_t u8x8_d_uc1628_256x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  250. {
  251. if ( u8x8_d_uc1628_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
  252. return 1;
  253. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  254. {
  255. u8x8_SetI2CAddress(u8x8, 0x070); /* lowest I2C adr of the UC1628 */
  256. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1628_256x32_display_info);
  257. return 1;
  258. }
  259. else if ( msg == U8X8_MSG_DISPLAY_INIT )
  260. {
  261. u8x8_d_helper_display_init(u8x8);
  262. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_256x32_init_seq);
  263. return 1;
  264. }
  265. else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  266. {
  267. if ( arg_int == 0 )
  268. {
  269. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip0_seq);
  270. u8x8->x_offset = u8x8->display_info->default_x_offset;
  271. }
  272. else
  273. {
  274. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip1_seq);
  275. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  276. }
  277. return 1;
  278. }
  279. return 0;
  280. }
  281. /*=============================================*/
  282. /* 128x64, https://github.com/olikraus/u8g2/issues/2260
  283. 2 Oct 2023: Probably the LCD Bias is wrong, it should be reduced, maybe 0xea or so
  284. Moreover the COM end should be halfed (0x03f) --> Done, but not tested
  285. */
  286. static const u8x8_display_info_t u8x8_uc1628_128x64_display_info =
  287. {
  288. /* chip_enable_level = */ 0,
  289. /* chip_disable_level = */ 1,
  290. /* post_chip_enable_wait_ns = */ 10,
  291. /* pre_chip_disable_wait_ns = */ 10,
  292. /* reset_pulse_width_ms = */ 5,
  293. /* post_reset_wait_ms = */ 5, /**/
  294. /* sda_setup_time_ns = */ 25, /* */
  295. /* sck_pulse_width_ns = */ 100, /* */
  296. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  297. /* spi_mode = */ 0, /* active high, rising edge */
  298. /* i2c_bus_clock_100kHz = */ 4, /* 400KHz */
  299. /* data_setup_time_ns = */ 45,
  300. /* write_pulse_width_ns = */ 125,
  301. /* tile_width = */ 16,
  302. /* tile_height = */ 8,
  303. /* default_x_offset = */ 0, /* */
  304. /* flipmode_x_offset = */ 0, /* */
  305. /* pixel_width = */ 128,
  306. /* pixel_height = */ 64
  307. };
  308. static const uint8_t u8x8_d_uc1628_128x64_init_seq[] = {
  309. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  310. U8X8_DLY(20),
  311. U8X8_C( 0x010 ), /* Termp.: Reset default */
  312. U8X8_C( 0x012 ), /* Termp.: Reset default */
  313. U8X8_C( 0x014 ), /* Termp.: Reset default */
  314. /* assign temperature independent framerate */
  315. /* 0x00d = 81,9Hz (reset default) */
  316. /* 0x000 = 40.0 Hz (min) */
  317. /* 0x01f = 140.0 Hz (max) */
  318. U8X8_CAA( 0x016, 0x000, 0x00d ), /* 1st arg: temp. point, 2nd arg: frame rate */
  319. U8X8_CA( 0x040, 0x000 ), /* scroll line */
  320. U8X8_C( 0x020 ), /* temp compensation */
  321. U8X8_C( 0x02d ), /* charge pump control */
  322. U8X8_C( 0x0eb ), /* LCD Bias: 0xe8=6, ... 0xeb=12 ... 0xed=14 */
  323. U8X8_CAA( 0x081, 0x000, 0x048 ), /* Contrast, 1st arg is always 0 */
  324. U8X8_CA( 0x0b8, 0x000 ), /* OTP control: Idle & Ignore */
  325. U8X8_CA( 0x0f1, 0x03f ), /* set COM end */
  326. U8X8_CA( 0x0f2, 0x000 ), /* set partial display start */
  327. U8X8_CA( 0x0f3, 0x07f ), /* set partial display end */
  328. U8X8_C( 0x088 ), /* auto increment control */
  329. U8X8_C( 0x0c4 ), /* XY mirror in bit 1 & 2 */
  330. U8X8_DLY(100),
  331. U8X8_END_TRANSFER(), /* disable chip */
  332. U8X8_END() /* end of sequence */
  333. };
  334. uint8_t u8x8_d_uc1628_128x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  335. {
  336. if ( u8x8_d_uc1628_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
  337. return 1;
  338. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  339. {
  340. u8x8_SetI2CAddress(u8x8, 0x070); /* lowest I2C adr of the UC1628 */
  341. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1628_128x64_display_info);
  342. return 1;
  343. }
  344. else if ( msg == U8X8_MSG_DISPLAY_INIT )
  345. {
  346. u8x8_d_helper_display_init(u8x8);
  347. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_128x64_init_seq);
  348. return 1;
  349. }
  350. else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  351. {
  352. if ( arg_int == 0 )
  353. {
  354. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip0_seq);
  355. u8x8->x_offset = u8x8->display_info->default_x_offset;
  356. }
  357. else
  358. {
  359. u8x8_cad_SendSequence(u8x8, u8x8_d_uc1628_flip1_seq);
  360. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  361. }
  362. return 1;
  363. }
  364. return 0;
  365. }