u8x8_d_ssd1607_200x200.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. u8x8_d_ssd1607_200x200.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. SSD1607: 200x300x1
  27. command
  28. 0x22: assign actions
  29. 0x20: execute actions
  30. action for command 0x022 are (more or less guessed)
  31. bit 7: Enable Clock
  32. bit 6: Enable Charge Pump
  33. bit 5: Load Temparture Value (???)
  34. bit 4: Load LUT (???)
  35. bit 3: Initial Display (???)
  36. bit 2: Pattern Display --> Requires about 945ms with the LUT from below
  37. bit 1: Disable Charge Pump
  38. bit 0: Disable Clock
  39. Disable Charge Pump and Clock require about 267ms
  40. Enable Charge Pump and Clock require about 10ms
  41. Notes:
  42. - Introduced a refresh display message, which copies RAM to display
  43. - Charge pump and clock are only enabled for the transfer RAM to display
  44. - U8x8 will not really work because of the two buffers in the SSD1606, however U8g2 should be ok.
  45. */
  46. #include "u8x8.h"
  47. /*=================================================*/
  48. static const u8x8_display_info_t u8x8_ssd1607_200x200_display_info =
  49. {
  50. /* chip_enable_level = */ 0,
  51. /* chip_disable_level = */ 1,
  52. /* values from SSD1606 */
  53. /* post_chip_enable_wait_ns = */ 120,
  54. /* pre_chip_disable_wait_ns = */ 60,
  55. /* reset_pulse_width_ms = */ 100,
  56. /* post_reset_wait_ms = */ 100,
  57. /* sda_setup_time_ns = */ 50, /* SSD1606: */
  58. /* sck_pulse_width_ns = */ 100, /* SSD1606: 100ns */
  59. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  60. /* spi_mode = */ 0, /* active high, rising edge */
  61. /* i2c_bus_clock_100kHz = */ 4,
  62. /* data_setup_time_ns = */ 40,
  63. /* write_pulse_width_ns = */ 150,
  64. /* tile_width = */ 25, /* 25*8 = 200 */
  65. /* tile_hight = */ 25,
  66. /* default_x_offset = */ 0,
  67. /* flipmode_x_offset = */ 0,
  68. /* pixel_width = */ 200,
  69. /* pixel_height = */ 200
  70. };
  71. static const uint8_t u8x8_d_ssd1607_200x200_powersave0_seq[] = {
  72. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  73. U8X8_CA(0x22, 0xc0), /* enable clock and charge pump */
  74. U8X8_C(0x20), /* execute sequence */
  75. U8X8_DLY(200), /* according to my measures it may take up to 150ms */
  76. U8X8_DLY(100), /* but it might take longer */
  77. U8X8_END_TRANSFER(), /* disable chip */
  78. U8X8_END() /* end of sequence */
  79. };
  80. static const uint8_t u8x8_d_ssd1607_200x200_powersave1_seq[] = {
  81. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  82. /* disable clock and charge pump only, deep sleep is not entered, because we will loose RAM content */
  83. U8X8_CA(0x22, 0x02), /* only disable charge pump, HW reset seems to be required if the clock is disabled */
  84. U8X8_C(0x20), /* execute sequence */
  85. U8X8_DLY(20),
  86. U8X8_END_TRANSFER(), /* disable chip */
  87. U8X8_END() /* end of sequence */
  88. };
  89. static const uint8_t u8x8_d_ssd1607_200x200_exec_1000dly_seq[] = {
  90. // assumes, that the start transfer has happend
  91. U8X8_CA(0x22, 0x04), /* display update seq. option: pattern display */
  92. U8X8_C(0x20), /* execute sequence */
  93. U8X8_DLY(250),
  94. U8X8_DLY(250),
  95. U8X8_DLY(250),
  96. U8X8_DLY(250),
  97. U8X8_END_TRANSFER(), /* disable chip */
  98. U8X8_END() /* end of sequence */
  99. };
  100. static void u8x8_d_ssd1607_200x200_first_init(u8x8_t *u8x8)
  101. {
  102. u8x8_ClearDisplay(u8x8);
  103. u8x8_cad_StartTransfer(u8x8);
  104. u8x8_cad_SendCmd(u8x8, 0x032); // program update sequence
  105. u8x8_cad_SendMultipleArg(u8x8, 8, 0x055); // all black
  106. u8x8_cad_SendMultipleArg(u8x8, 12, 0x0aa); // all white
  107. u8x8_cad_SendMultipleArg(u8x8, 10, 0x022); // 830ms
  108. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_exec_1000dly_seq);
  109. }
  110. static uint8_t *u8x8_convert_tile_for_ssd1607(uint8_t *t)
  111. {
  112. uint8_t i;
  113. static uint8_t buf[8];
  114. uint8_t *pbuf = buf;
  115. for( i = 0; i < 8; i++ )
  116. {
  117. *pbuf++ = ~(*t++);
  118. }
  119. return buf;
  120. }
  121. static void u8x8_d_ssd1607_draw_tile(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr) U8X8_NOINLINE;
  122. static void u8x8_d_ssd1607_draw_tile(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr)
  123. {
  124. uint16_t x;
  125. uint8_t c, page;
  126. uint8_t *ptr;
  127. u8x8_cad_StartTransfer(u8x8);
  128. page = u8x8->display_info->tile_height;
  129. page --;
  130. page -= (((u8x8_tile_t *)arg_ptr)->y_pos);
  131. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  132. x *= 8;
  133. x += u8x8->x_offset;
  134. u8x8_cad_SendCmd(u8x8, 0x045 ); /* window start column */
  135. u8x8_cad_SendArg(u8x8, x&255);
  136. u8x8_cad_SendArg(u8x8, x>>8);
  137. u8x8_cad_SendArg(u8x8, 199); /* end of display */
  138. u8x8_cad_SendArg(u8x8, 0);
  139. u8x8_cad_SendCmd(u8x8, 0x044 ); /* window end page */
  140. u8x8_cad_SendArg(u8x8, page);
  141. u8x8_cad_SendArg(u8x8, page);
  142. u8x8_cad_SendCmd(u8x8, 0x04f ); /* window column */
  143. u8x8_cad_SendArg(u8x8, x&255);
  144. u8x8_cad_SendArg(u8x8, x>>8);
  145. u8x8_cad_SendCmd(u8x8, 0x04e ); /* window row */
  146. u8x8_cad_SendArg(u8x8, page);
  147. u8x8_cad_SendCmd(u8x8, 0x024 );
  148. do
  149. {
  150. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  151. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  152. do
  153. {
  154. u8x8_cad_SendData(u8x8, 8, u8x8_convert_tile_for_ssd1607(ptr));
  155. ptr += 8;
  156. x += 8;
  157. c--;
  158. } while( c > 0 );
  159. arg_int--;
  160. } while( arg_int > 0 );
  161. u8x8_cad_EndTransfer(u8x8);
  162. }
  163. /*=================================================*/
  164. #define L(a,b,c,d) (((a)<<6)|((b)<<4)|((c)<<2)|(d))
  165. /* https://github.com/embeddedadventures/SSD1607/blob/master/SSD1607.cpp */
  166. static const uint8_t u8x8_d_ssd1607_200x200_init_seq[] = {
  167. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  168. //U8X8_CA(0x10, 0x00), /* Deep Sleep mode Control: Disable */
  169. U8X8_C(0x01),
  170. U8X8_A(199),U8X8_A(0),U8X8_A(0),
  171. U8X8_CA(0x03, 0x00), /* Gate Driving voltage: 15V (lowest value)*/
  172. U8X8_CA(0x04, 0x0a), /* Source Driving voltage: 15V (mid value and POR)*/
  173. U8X8_CA(0x0f, 0x00), /* scan start ? */
  174. U8X8_CA(0xf0, 0x1f), /* set booster feedback to internal */
  175. U8X8_CA(0x2c, 0xa8), /* write vcom value*/
  176. U8X8_CA(0x3a, 0x1a), /* dummy lines */
  177. U8X8_CA(0x3b, 0x08), /* gate time */
  178. U8X8_CA(0x3c, 0x33), /* select boarder waveform */
  179. U8X8_CA(0x11, 0x03), /* cursor increment mode */
  180. U8X8_CAA(0x44, 0, 24), /* RAM x start & end, each byte has 8 pixel, 25*4=200 */
  181. U8X8_CAAAA(0x45, 0, 0, 299&255, 299>>8), /* RAM y start & end, 0..299 */
  182. U8X8_END_TRANSFER(), /* disable chip */
  183. U8X8_END() /* end of sequence */
  184. };
  185. static const uint8_t u8x8_d_ssd1607_to_display_seq[] = {
  186. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  187. U8X8_C(0x32), /* write LUT register*/
  188. /* according to the command table, the lut has 240 bits (=30 bytes * 8 bits) */
  189. /* Waveform part of the LUT (20 bytes) */
  190. /* bit 7/6: 1 - 1 transition */
  191. /* bit 5/4: 1 - 0 transition */
  192. /* bit 3/2: 0 - 1 transition */
  193. /* bit 1/0: 0 - 0 transition */
  194. /* 00 – VSS */
  195. /* 01 – VSH */
  196. /* 10 – VSL */
  197. /* 11 – NA */
  198. /* original values */
  199. /*
  200. U8X8_A(0x02),
  201. U8X8_A(0x02),
  202. U8X8_A(0x01),
  203. U8X8_A(0x11),
  204. U8X8_A(0x12),
  205. U8X8_A(0x12),
  206. U8X8_A(0x22),
  207. U8X8_A(0x22),
  208. U8X8_A(0x66),
  209. U8X8_A(0x69),
  210. U8X8_A(0x69),
  211. U8X8_A(0x59),
  212. U8X8_A(0x58),
  213. U8X8_A(0x99),
  214. U8X8_A(0x99),
  215. U8X8_A(0x88),
  216. U8X8_A(0x00),
  217. U8X8_A(0x00),
  218. U8X8_A(0x00),
  219. U8X8_A(0x00),
  220. */
  221. /* original values, L-macro */
  222. U8X8_A(L(0,0,0,2)), // 0x02
  223. U8X8_A(L(0,0,0,2)), // 0x02
  224. U8X8_A(L(0,0,0,1)), // 0x01
  225. U8X8_A(L(0,1,0,1)), // 0x11
  226. U8X8_A(L(0,1,0,2)), // 0x12
  227. U8X8_A(L(0,1,0,2)), // 0x12
  228. U8X8_A(L(0,2,0,2)), // 0x22
  229. U8X8_A(L(0,2,0,2)), // 0x22
  230. U8X8_A(L(1,2,1,2)), // 0x66
  231. U8X8_A(L(1,2,2,1)), // 0x69
  232. U8X8_A(L(1,2,2,1)), // 0x69
  233. U8X8_A(L(1,1,2,1)), // 0x59
  234. U8X8_A(L(1,1,2,0)), // 0x58
  235. U8X8_A(L(2,1,2,1)), // 0x99
  236. U8X8_A(L(2,1,2,1)), // 0x99
  237. U8X8_A(L(2,0,2,0)), // 0x88
  238. U8X8_A(L(0,0,0,0)), // 0x00
  239. U8X8_A(L(0,0,0,0)), // 0x00
  240. U8X8_A(L(0,0,0,0)), // 0x00
  241. U8X8_A(L(0,0,0,0)), // 0x00
  242. /* orginal values without 0-0 and 1-1 transition */
  243. /*
  244. U8X8_A(L(3,0,0,3)), // 0x02
  245. U8X8_A(L(3,0,0,3)), // 0x02
  246. U8X8_A(L(3,0,0,3)), // 0x01
  247. U8X8_A(L(3,1,0,3)), // 0x11
  248. U8X8_A(L(3,1,0,3)), // 0x12
  249. U8X8_A(L(3,1,0,3)), // 0x12
  250. U8X8_A(L(3,2,0,3)), // 0x22
  251. U8X8_A(L(3,2,0,3)), // 0x22
  252. U8X8_A(L(3,2,1,3)), // 0x66
  253. U8X8_A(L(3,2,2,3)), // 0x69
  254. U8X8_A(L(3,2,2,3)), // 0x69
  255. U8X8_A(L(3,1,2,3)), // 0x59
  256. U8X8_A(L(3,1,2,3)), // 0x58
  257. U8X8_A(L(3,1,2,3)), // 0x99
  258. U8X8_A(L(3,1,2,3)), // 0x99
  259. U8X8_A(L(3,0,2,3)), // 0x88
  260. U8X8_A(L(3,0,0,3)), // 0x00
  261. U8X8_A(L(3,0,0,3)), // 0x00
  262. U8X8_A(L(3,0,0,3)), // 0x00
  263. U8X8_A(L(3,0,0,3)), // 0x00
  264. */
  265. /* Timing part of the LUT, 20 Phases with 4 bit each: 10 bytes */
  266. U8X8_A(0xF8),
  267. U8X8_A(0xB4),
  268. U8X8_A(0x13),
  269. U8X8_A(0x51),
  270. U8X8_A(0x35),
  271. U8X8_A(0x51),
  272. U8X8_A(0x51),
  273. U8X8_A(0x19),
  274. U8X8_A(0x01),
  275. U8X8_A(0x00),
  276. U8X8_CA(0x22, 0x04), /* display update seq. option: clk -> CP -> LUT -> initial display -> pattern display */
  277. U8X8_C(0x20), /* execute sequence */
  278. U8X8_DLY(250), /* the sequence above requires about 1200ms for the 200x200 display*/
  279. U8X8_DLY(250),
  280. U8X8_DLY(250),
  281. U8X8_DLY(250),
  282. U8X8_DLY(250),
  283. U8X8_DLY(250),
  284. U8X8_DLY(250),
  285. U8X8_END_TRANSFER(), /* disable chip */
  286. U8X8_END() /* end of sequence */
  287. };
  288. uint8_t u8x8_d_ssd1607_200x200(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  289. {
  290. switch(msg)
  291. {
  292. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  293. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1607_200x200_display_info);
  294. break;
  295. case U8X8_MSG_DISPLAY_INIT:
  296. u8x8_d_helper_display_init(u8x8);
  297. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_init_seq);
  298. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  299. u8x8_d_ssd1607_200x200_first_init(u8x8);
  300. break;
  301. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  302. if ( arg_int == 0 )
  303. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  304. else
  305. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave1_seq);
  306. break;
  307. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  308. break;
  309. case U8X8_MSG_DISPLAY_DRAW_TILE:
  310. u8x8_d_ssd1607_draw_tile(u8x8, arg_int, arg_ptr);
  311. break;
  312. case U8X8_MSG_DISPLAY_REFRESH:
  313. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_to_display_seq);
  314. break;
  315. default:
  316. return 0;
  317. }
  318. return 1;
  319. }
  320. /*=================================================*/
  321. /* there is no improvement possible... so i consider the v2 version as obsolete */
  322. static const uint8_t u8x8_d_ssd1607_v2_to_display_seq[] = {
  323. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  324. /*
  325. 0xaa, 0x09, 0x09, 0x19, 0x19,
  326. 0x11, 0x11, 0x11, 0x11, 0x00,
  327. 0x00, 0x00, 0x00, 0x00, 0x00,
  328. 0x00, 0x00, 0x00, 0x00, 0x00,
  329. 0x75, 0x77, 0x77, 0x77, 0x07,
  330. 0x00, 0x00, 0x00, 0x00, 0x00
  331. measured 1240 ms with IL3830 196x128
  332. 0x02, 0x02, 0x01, 0x11, 0x12,
  333. 0x12, 0x12, 0x22, 0x22, 0x66,
  334. 0x69, 0x59, 0x58, 0x99, 0x99,
  335. 0x88, 0x00, 0x00, 0x00, 0x00,
  336. 0xf8, 0xb4, 0x13, 0x51, 0x35,
  337. 0x51, 0x51, 0xe9, 0x04, 0x00
  338. */
  339. U8X8_C(0x32), /* write LUT register*/
  340. /* https://github.com/olikraus/u8g2/issues/347 */
  341. U8X8_A(0x02),
  342. U8X8_A(0x02),
  343. U8X8_A(0x01),
  344. U8X8_A(0x11),
  345. U8X8_A(0x12),
  346. U8X8_A(0x12),
  347. U8X8_A(0x22),
  348. U8X8_A(0x22),
  349. U8X8_A(0x66),
  350. U8X8_A(0x69),
  351. U8X8_A(0x69),
  352. U8X8_A(0x59),
  353. U8X8_A(0x58),
  354. U8X8_A(0x99),
  355. U8X8_A(0x99),
  356. U8X8_A(0x88),
  357. U8X8_A(0x00),
  358. U8X8_A(0x00),
  359. U8X8_A(0x00),
  360. U8X8_A(0x00),
  361. /* Timing part of the LUT, 20 Phases with 4 bit each: 10 bytes */
  362. U8X8_A(0xF8),
  363. U8X8_A(0xB4),
  364. U8X8_A(0x13),
  365. U8X8_A(0x51),
  366. U8X8_A(0x35),
  367. U8X8_A(0x51),
  368. U8X8_A(0x51),
  369. U8X8_A(0xe9),
  370. U8X8_A(0x04),
  371. U8X8_A(0x00),
  372. U8X8_CA(0x22, 0x04), /* display update seq. option: clk -> CP -> LUT -> initial display -> pattern display */
  373. U8X8_C(0x20), /* execute sequence */
  374. U8X8_DLY(250), /* delay for 1500ms. The current sequence takes 1300ms */
  375. U8X8_DLY(250),
  376. U8X8_DLY(250),
  377. U8X8_DLY(250),
  378. U8X8_DLY(250),
  379. U8X8_DLY(250),
  380. U8X8_END_TRANSFER(), /* disable chip */
  381. U8X8_END() /* end of sequence */
  382. };
  383. uint8_t u8x8_d_ssd1607_v2_200x200(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  384. {
  385. switch(msg)
  386. {
  387. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  388. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1607_200x200_display_info);
  389. break;
  390. case U8X8_MSG_DISPLAY_INIT:
  391. u8x8_d_helper_display_init(u8x8);
  392. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_init_seq);
  393. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  394. u8x8_d_ssd1607_200x200_first_init(u8x8);
  395. break;
  396. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  397. if ( arg_int == 0 )
  398. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  399. else
  400. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave1_seq);
  401. break;
  402. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  403. break;
  404. case U8X8_MSG_DISPLAY_DRAW_TILE:
  405. u8x8_d_ssd1607_draw_tile(u8x8, arg_int, arg_ptr);
  406. break;
  407. case U8X8_MSG_DISPLAY_REFRESH:
  408. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_v2_to_display_seq);
  409. break;
  410. default:
  411. return 0;
  412. }
  413. return 1;
  414. }
  415. /*=================================================*/
  416. /* GDEP015OC1 */
  417. /* https://github.com/olikraus/u8g2/issues/454 */
  418. static const uint8_t u8x8_d_ssd1607_gd_to_display_seq[] = {
  419. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  420. /*
  421. 0xaa, 0x09, 0x09, 0x19, 0x19,
  422. 0x11, 0x11, 0x11, 0x11, 0x00,
  423. 0x00, 0x00, 0x00, 0x00, 0x00,
  424. 0x00, 0x00, 0x00, 0x00, 0x00,
  425. 0x75, 0x77, 0x77, 0x77, 0x07,
  426. 0x00, 0x00, 0x00, 0x00, 0x00
  427. measured 1240 ms with IL3830 196x128
  428. 0x02, 0x02, 0x01, 0x11, 0x12,
  429. 0x12, 0x12, 0x22, 0x22, 0x66,
  430. 0x69, 0x59, 0x58, 0x99, 0x99,
  431. 0x88, 0x00, 0x00, 0x00, 0x00,
  432. 0xf8, 0xb4, 0x13, 0x51, 0x35,
  433. 0x51, 0x51, 0xe9, 0x04, 0x00
  434. */
  435. U8X8_C(0x32), /* write LUT register*/
  436. /*
  437. U8X8_A(0x50), U8X8_A(0xAA), U8X8_A(0x55), U8X8_A(0xAA), U8X8_A(0x11),
  438. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  439. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  440. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  441. U8X8_A(0xFF), U8X8_A(0xFF), U8X8_A(0x1F), U8X8_A(0x00), U8X8_A(0x00),
  442. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  443. */
  444. U8X8_A(0x10), U8X8_A(0x18), U8X8_A(0x18), U8X8_A(0x08), U8X8_A(0x18), // numbers based on Waveshare demo code
  445. U8X8_A(0x18), U8X8_A(0x08), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  446. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  447. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  448. U8X8_A(0x13), U8X8_A(0x14), U8X8_A(0x44), U8X8_A(0x12), U8X8_A(0x00),
  449. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  450. U8X8_CA(0x22, 0xc4), /* display update seq. option: clk -> CP -> LUT -> initial display -> pattern display */
  451. U8X8_C(0x20), /* execute sequence */
  452. U8X8_DLY(250), /* delay for 1500ms. The current sequence takes 1300ms */
  453. U8X8_DLY(250),
  454. U8X8_DLY(250),
  455. // U8X8_DLY(250),
  456. // U8X8_DLY(250),
  457. // U8X8_DLY(250),
  458. U8X8_END_TRANSFER(), /* disable chip */
  459. U8X8_END() /* end of sequence */
  460. };
  461. uint8_t u8x8_d_ssd1607_gd_200x200(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  462. {
  463. switch(msg)
  464. {
  465. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  466. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1607_200x200_display_info);
  467. break;
  468. case U8X8_MSG_DISPLAY_INIT:
  469. u8x8_d_helper_display_init(u8x8);
  470. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_init_seq);
  471. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  472. u8x8_d_ssd1607_200x200_first_init(u8x8);
  473. break;
  474. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  475. if ( arg_int == 0 )
  476. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  477. else
  478. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave1_seq);
  479. break;
  480. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  481. break;
  482. case U8X8_MSG_DISPLAY_DRAW_TILE:
  483. u8x8_d_ssd1607_draw_tile(u8x8, arg_int, arg_ptr);
  484. break;
  485. case U8X8_MSG_DISPLAY_REFRESH:
  486. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_gd_to_display_seq);
  487. break;
  488. default:
  489. return 0;
  490. }
  491. return 1;
  492. }
  493. /*=================================================*/
  494. static const uint8_t u8x8_d_ssd1607_ws_to_display_seq[] = {
  495. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  496. U8X8_C(0x32), /* write LUT register*/
  497. U8X8_A(0x10), U8X8_A(0x18), U8X8_A(0x18), U8X8_A(0x08), U8X8_A(0x18), // numbers based on Waveshare demo code
  498. U8X8_A(0x18), U8X8_A(0x08), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  499. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  500. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  501. U8X8_A(0x13), U8X8_A(0x14), U8X8_A(0x44), U8X8_A(0x12), U8X8_A(0x00),
  502. U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00), U8X8_A(0x00),
  503. U8X8_CA(0x22, 0xc4), /* display update seq. option: clk -> CP -> LUT -> initial display -> pattern display */
  504. U8X8_C(0x20), /* execute sequence */
  505. U8X8_DLY(250), /* delay for 1250ms. */
  506. U8X8_DLY(250),
  507. U8X8_DLY(250),
  508. U8X8_DLY(250),
  509. U8X8_DLY(250),
  510. U8X8_END_TRANSFER(), /* disable chip */
  511. U8X8_END() /* end of sequence */
  512. };
  513. static const uint8_t u8x8_d_ssd1607_ws_to_refresh_seq[] = {
  514. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  515. U8X8_CA(0x22, 0x04), /* display update seq. option: clk -> CP -> LUT -> initial display -> pattern display */
  516. U8X8_C(0x20), /* execute sequence */
  517. // U8X8_DLY(250),
  518. // U8X8_DLY(250),
  519. U8X8_END_TRANSFER(), /* disable chip */
  520. U8X8_END() /* end of sequence */
  521. };
  522. /* waveshare 200x200 */
  523. static const uint8_t u8x8_d_ssd1607_ws_200x200_init_seq[] = {
  524. // suggested code from https://github.com/olikraus/u8g2/issues/637
  525. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  526. U8X8_C(0x01), /* DRIVER_OUTPUT_CONTROL: LO(EPD_HEIGHT-1), HI(EPD_HEIGHT-1). GD = 0; SM = 0; TB = 0; */
  527. U8X8_A(199),U8X8_A(0),U8X8_A(0),
  528. U8X8_C(0x0C), /* BOOSTER_SOFT_START_CONTROL */
  529. U8X8_A(0xd7),U8X8_A(0xd6),U8X8_A(0x9d),
  530. U8X8_CA(0x2c, 0xa8), /* WRITE_VCOM_REGISTER: VCOM 7C */
  531. U8X8_CA(0x3a, 0x1a), /* SET_DUMMY_LINE_PERIOD: 4 dummy lines per gate */
  532. U8X8_CA(0x3b, 0x08), /* SET_GATE_TIME: 2us per line */
  533. U8X8_CA(0x11, 0x03), /* DATA_ENTRY_MODE_SETTING: X increment; Y increment */
  534. U8X8_CAA(0x44, 0, 24), /* SET_RAM_X_ADDRESS_START_END_POSITION: LO(x >> 3), LO((w-1) >> 3) */
  535. U8X8_CAAAA(0x45, 0, 0, 199&255, 199>>8), /* SET_RAM_Y_ADDRESS_START_END_POSITION: LO(y), HI(y), LO(h - 1), HI(h - 1) */
  536. U8X8_CA(0x4e, 0), /* LO(x >> 3) */
  537. U8X8_CAA(0x4f, 0, 0), /* LO(y), HI(y >> 8) */
  538. U8X8_END_TRANSFER(), /* disable chip */
  539. U8X8_END() /* end of sequence */
  540. };
  541. uint8_t u8x8_d_ssd1607_ws_200x200(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  542. {
  543. switch(msg)
  544. {
  545. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  546. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1607_200x200_display_info);
  547. break;
  548. case U8X8_MSG_DISPLAY_INIT:
  549. u8x8_d_helper_display_init(u8x8);
  550. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_ws_200x200_init_seq);
  551. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  552. u8x8_d_ssd1607_200x200_first_init(u8x8);
  553. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_ws_to_display_seq);; // to setup LUT
  554. break;
  555. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  556. if ( arg_int == 0 )
  557. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave0_seq);
  558. else
  559. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_200x200_powersave1_seq);
  560. break;
  561. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  562. break;
  563. case U8X8_MSG_DISPLAY_DRAW_TILE:
  564. u8x8_d_ssd1607_draw_tile(u8x8, arg_int, arg_ptr);
  565. break;
  566. case U8X8_MSG_DISPLAY_REFRESH:
  567. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1607_ws_to_refresh_seq);
  568. break;
  569. default:
  570. return 0;
  571. }
  572. return 1;
  573. }