u8x8_d_ssd1322.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /*
  2. u8x8_d_ssd1322.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. SSD1322:
  27. 480 x 128 dot matrix
  28. 16 gray scale
  29. */
  30. #include "u8x8.h"
  31. static const uint8_t u8x8_d_ssd1322_powersave0_seq[] = {
  32. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  33. U8X8_C(0x0af), /* ssd1322: display on */
  34. U8X8_END_TRANSFER(), /* disable chip */
  35. U8X8_END() /* end of sequence */
  36. };
  37. static const uint8_t u8x8_d_ssd1322_powersave1_seq[] = {
  38. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  39. U8X8_C(0x0ae), /* ssd1322: display off */
  40. U8X8_END_TRANSFER(), /* disable chip */
  41. U8X8_END() /* end of sequence */
  42. };
  43. /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
  44. /* topbit (msb) is sent last */
  45. /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
  46. /* 4 Jan 2017: I think this procedure not required any more. Delete? */
  47. /*
  48. static uint8_t u8x8_write_byte_to_16gr_device(u8x8_t *u8x8, uint8_t b)
  49. {
  50. static uint8_t buf[4];
  51. static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
  52. buf [3] = map[b & 3];
  53. b>>=2;
  54. buf [2] = map[b & 3];
  55. b>>=2;
  56. buf [1] = map[b & 3];
  57. b>>=2;
  58. buf [0] = map[b & 3];
  59. return u8x8_cad_SendData(u8x8, 4, buf);
  60. }
  61. */
  62. /*
  63. input:
  64. one tile (8 Bytes)
  65. output:
  66. Tile for SSD1325 (32 Bytes)
  67. */
  68. static uint8_t u8x8_ssd1322_to32_dest_buf[32];
  69. static uint8_t *u8x8_ssd1322_8to32(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
  70. {
  71. uint8_t v;
  72. uint8_t a,b;
  73. uint8_t i, j;
  74. uint8_t *dest;
  75. for( j = 0; j < 4; j++ )
  76. {
  77. dest = u8x8_ssd1322_to32_dest_buf;
  78. dest += j;
  79. a =*ptr;
  80. ptr++;
  81. b = *ptr;
  82. ptr++;
  83. for( i = 0; i < 8; i++ )
  84. {
  85. v = 0;
  86. if ( a&1 ) v |= 0xf0;
  87. if ( b&1 ) v |= 0x0f;
  88. *dest = v;
  89. dest+=4;
  90. a >>= 1;
  91. b >>= 1;
  92. }
  93. }
  94. return u8x8_ssd1322_to32_dest_buf;
  95. }
  96. static uint8_t *u8x8_ssd1322_4to32(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
  97. {
  98. uint8_t v;
  99. uint8_t a;
  100. uint8_t i, j;
  101. uint8_t *dest;
  102. for( j = 0; j < 4; j++ )
  103. {
  104. dest = u8x8_ssd1322_to32_dest_buf;
  105. dest += j;
  106. a =*ptr;
  107. ptr++;
  108. for( i = 0; i < 8; i++ )
  109. {
  110. v = 0;
  111. if ( a&1 ) v = 0xff;
  112. *dest = v;
  113. dest+=4;
  114. a >>= 1;
  115. }
  116. }
  117. return u8x8_ssd1322_to32_dest_buf;
  118. }
  119. uint8_t u8x8_d_ssd1322_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  120. {
  121. uint8_t x;
  122. uint8_t y, c;
  123. uint8_t *ptr;
  124. switch(msg)
  125. {
  126. /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
  127. /*
  128. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  129. break;
  130. case U8X8_MSG_DISPLAY_INIT:
  131. u8x8_d_helper_display_init(u8x8);
  132. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_init_seq);
  133. break;
  134. */
  135. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  136. if ( arg_int == 0 )
  137. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_powersave0_seq);
  138. else
  139. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_powersave1_seq);
  140. break;
  141. #ifdef U8X8_WITH_SET_CONTRAST
  142. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  143. u8x8_cad_StartTransfer(u8x8);
  144. u8x8_cad_SendCmd(u8x8, 0x0C1 );
  145. u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1322 has range from 0 to 255 */
  146. u8x8_cad_EndTransfer(u8x8);
  147. break;
  148. #endif
  149. case U8X8_MSG_DISPLAY_DRAW_TILE:
  150. u8x8_cad_StartTransfer(u8x8);
  151. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  152. x *= 2; // only every 4th col can be addressed
  153. x += u8x8->x_offset;
  154. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  155. y *= 8;
  156. u8x8_cad_SendCmd(u8x8, 0x075 ); /* set row address, moved out of the loop (issue 302) */
  157. u8x8_cad_SendArg(u8x8, y);
  158. u8x8_cad_SendArg(u8x8, y+7);
  159. do
  160. {
  161. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  162. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  163. do
  164. {
  165. u8x8_cad_SendCmd(u8x8, 0x015 ); /* set column address */
  166. u8x8_cad_SendArg(u8x8, x ); /* start */
  167. u8x8_cad_SendArg(u8x8, x+1 ); /* end */
  168. u8x8_cad_SendCmd(u8x8, 0x05c ); /* write to ram */
  169. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1322_8to32(u8x8, ptr));
  170. ptr += 8;
  171. x += 2;
  172. c--;
  173. } while( c > 0 );
  174. //x += 2;
  175. arg_int--;
  176. } while( arg_int > 0 );
  177. u8x8_cad_EndTransfer(u8x8);
  178. break;
  179. default:
  180. return 0;
  181. }
  182. return 1;
  183. }
  184. /*=========================================================*/
  185. static const uint8_t u8x8_d_ssd1322_256x64_flip0_seq[] = {
  186. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  187. U8X8_CAA(0x0a0, 0x006, 0x011), /* remap */
  188. U8X8_END_TRANSFER(), /* disable chip */
  189. U8X8_END() /* end of sequence */
  190. };
  191. static const uint8_t u8x8_d_ssd1322_256x64_flip1_seq[] = {
  192. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  193. U8X8_CAA(0x0a0, 0x014, 0x011), /* remap */
  194. U8X8_END_TRANSFER(), /* disable chip */
  195. U8X8_END() /* end of sequence */
  196. };
  197. static const u8x8_display_info_t u8x8_ssd1322_256x64_display_info =
  198. {
  199. /* chip_enable_level = */ 0,
  200. /* chip_disable_level = */ 1,
  201. /* post_chip_enable_wait_ns = */ 20,
  202. /* pre_chip_disable_wait_ns = */ 10,
  203. /* reset_pulse_width_ms = */ 100, /* SSD1322: 2 us */
  204. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  205. /* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
  206. /* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  207. /* sck_clock_hz = */ 10000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215), 10 MHz (issue 301) */
  208. /* spi_mode = */ 0, /* active high, rising edge */
  209. /* i2c_bus_clock_100kHz = */ 4,
  210. /* data_setup_time_ns = */ 10,
  211. /* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
  212. /* tile_width = */ 32, /* 256 pixel, so we require 32 bytes for this */
  213. /* tile_height = */ 8,
  214. /* default_x_offset = */ 0x01c, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  215. /* flipmode_x_offset = */ 0x01c,
  216. /* pixel_width = */ 256,
  217. /* pixel_height = */ 64
  218. };
  219. static const uint8_t u8x8_d_ssd1322_256x64_init_seq[] = {
  220. U8X8_DLY(1),
  221. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  222. U8X8_DLY(1),
  223. U8X8_CA(0xfd, 0x12), /* unlock */
  224. U8X8_C(0xae), /* display off */
  225. U8X8_CA(0xb3, 0x91), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  226. U8X8_CA(0xca, 0x3f), /* multiplex ratio 1/64 Duty (0x0F~0x3F) */
  227. U8X8_CA(0xa2, 0x00), /* display offset, shift mapping ram counter */
  228. U8X8_CA(0xa1, 0x00), /* display start line */
  229. //U8X8_CAA(0xa0, 0x14, 0x11), /* Set Re-Map / Dual COM Line Mode */
  230. U8X8_CAA(0xa0, 0x06, 0x011), /* Set Re-Map / Dual COM Line Mode */
  231. U8X8_CA(0xab, 0x01), /* Enable Internal VDD Regulator */
  232. U8X8_CAA(0xb4, 0xa0, 0x005|0x0fd), /* Display Enhancement A */
  233. U8X8_CA(0xc1, 0x9f), /* contrast */
  234. U8X8_CA(0xc7, 0x0f), /* Set Scale Factor of Segment Output Current Control */
  235. U8X8_C(0xb9), /* linear grayscale */
  236. U8X8_CA(0xb1, 0xe2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
  237. U8X8_CAA(0xd1, 0x082|0x020, 0x020), /* Display Enhancement B */
  238. U8X8_CA(0xbb, 0x1f), /* precharge voltage */
  239. U8X8_CA(0xb6, 0x08), /* precharge period */
  240. U8X8_CA(0xbe, 0x07), /* vcomh */
  241. U8X8_C(0xa6), /* normal display */
  242. U8X8_C(0xa9), /* exit partial display */
  243. U8X8_DLY(1), /* delay 2ms */
  244. U8X8_END_TRANSFER(), /* disable chip */
  245. U8X8_END() /* end of sequence */
  246. };
  247. uint8_t u8x8_d_ssd1322_nhd_256x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  248. {
  249. switch(msg)
  250. {
  251. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  252. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1322_256x64_display_info);
  253. break;
  254. case U8X8_MSG_DISPLAY_INIT:
  255. u8x8_d_helper_display_init(u8x8);
  256. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_init_seq);
  257. break;
  258. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  259. if ( arg_int == 0 )
  260. {
  261. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip0_seq);
  262. u8x8->x_offset = u8x8->display_info->default_x_offset;
  263. }
  264. else
  265. {
  266. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip1_seq);
  267. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  268. }
  269. break;
  270. default:
  271. return u8x8_d_ssd1322_common(u8x8, msg, arg_int, arg_ptr);
  272. }
  273. return 1;
  274. }
  275. /*=========================================================*/
  276. /*
  277. https://github.com/olikraus/u8g2/issues/2386
  278. */
  279. static const u8x8_display_info_t u8x8_ssd1322_zjy_256x64_display_info =
  280. {
  281. /* chip_enable_level = */ 0,
  282. /* chip_disable_level = */ 1,
  283. /* post_chip_enable_wait_ns = */ 20,
  284. /* pre_chip_disable_wait_ns = */ 10,
  285. /* reset_pulse_width_ms = */ 100, /* SSD1322: 2 us */
  286. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  287. /* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
  288. /* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  289. /* sck_clock_hz = */ 10000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215), 10 MHz (issue 301) */
  290. /* spi_mode = */ 0, /* active high, rising edge */
  291. /* i2c_bus_clock_100kHz = */ 4,
  292. /* data_setup_time_ns = */ 10,
  293. /* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
  294. /* tile_width = */ 32, /* 256 pixel, so we require 32 bytes for this */
  295. /* tile_height = */ 8,
  296. /* default_x_offset = */ 0x018, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  297. /* flipmode_x_offset = */ 0x018,
  298. /* pixel_width = */ 256,
  299. /* pixel_height = */ 64
  300. };
  301. static const uint8_t u8x8_d_ssd1322_zjy_256x64_init_seq[] = {
  302. U8X8_DLY(1),
  303. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  304. U8X8_DLY(1),
  305. U8X8_CA(0xfd, 0x12), /* unlock */
  306. U8X8_C(0xae), /* display off */
  307. U8X8_CA(0xb3, 0x91), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  308. U8X8_CA(0xca, 0x3f), /* multiplex ratio 1/64 Duty (0x0F~0x3F) */
  309. U8X8_CA(0xa2, 0x00), /* display offset, shift mapping ram counter */
  310. U8X8_CA(0xa1, 0x00), /* display start line */
  311. //U8X8_CAA(0xa0, 0x14, 0x11), /* Set Re-Map / Dual COM Line Mode */
  312. U8X8_CAA(0xa0, 0x16, 0x011), /* Set Re-Map / Dual COM Line Mode */
  313. U8X8_CA(0xab, 0x01), /* Enable Internal VDD Regulator */
  314. U8X8_CAA(0xb4, 0xa0, 0x005|0x0fd), /* Display Enhancement A */
  315. U8X8_CA(0xc1, 0x9f), /* contrast */
  316. U8X8_CA(0xc7, 0x0f), /* Set Scale Factor of Segment Output Current Control */
  317. U8X8_C(0xb9), /* linear grayscale */
  318. U8X8_CA(0xb1, 0xe2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
  319. U8X8_CAA(0xd1, 0x082|0x020, 0x020), /* Display Enhancement B */
  320. U8X8_CA(0xbb, 0x1f), /* precharge voltage */
  321. U8X8_CA(0xb6, 0x08), /* precharge period */
  322. U8X8_CA(0xbe, 0x07), /* vcomh */
  323. U8X8_C(0xa6), /* normal display */
  324. U8X8_C(0xa9), /* exit partial display */
  325. U8X8_DLY(1), /* delay 2ms */
  326. U8X8_END_TRANSFER(), /* disable chip */
  327. U8X8_END() /* end of sequence */
  328. };
  329. uint8_t u8x8_d_ssd1322_zjy_256x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  330. {
  331. switch(msg)
  332. {
  333. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  334. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1322_zjy_256x64_display_info);
  335. break;
  336. case U8X8_MSG_DISPLAY_INIT:
  337. u8x8_d_helper_display_init(u8x8);
  338. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_zjy_256x64_init_seq);
  339. break;
  340. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  341. if ( arg_int == 0 )
  342. {
  343. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip0_seq);
  344. u8x8->x_offset = u8x8->display_info->default_x_offset;
  345. }
  346. else
  347. {
  348. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip1_seq);
  349. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  350. }
  351. break;
  352. default:
  353. return u8x8_d_ssd1322_common(u8x8, msg, arg_int, arg_ptr);
  354. }
  355. return 1;
  356. }
  357. /*=========================================================*/
  358. /*
  359. https://github.com/olikraus/u8g2/issues/2092
  360. */
  361. static const u8x8_display_info_t u8x8_ssd1322_240x128_display_info =
  362. {
  363. /* chip_enable_level = */ 0,
  364. /* chip_disable_level = */ 1,
  365. /* post_chip_enable_wait_ns = */ 20,
  366. /* pre_chip_disable_wait_ns = */ 10,
  367. /* reset_pulse_width_ms = */ 100, /* SSD1322: 2 us */
  368. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  369. /* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
  370. /* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  371. /* sck_clock_hz = */ 10000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215), 10 MHz (issue 301) */
  372. /* spi_mode = */ 0, /* active high, rising edge */
  373. /* i2c_bus_clock_100kHz = */ 4,
  374. /* data_setup_time_ns = */ 10,
  375. /* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
  376. /* tile_width = */ 30, /* 256 pixel, so we require 32 bytes for this */
  377. /* tile_height = */ 16,
  378. /* default_x_offset = */ 24, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  379. /* flipmode_x_offset = */ 0x000,
  380. /* pixel_width = */ 240,
  381. /* pixel_height = */ 128
  382. };
  383. static const uint8_t u8x8_d_ssd1322_240x128_init_seq[] = {
  384. U8X8_DLY(1),
  385. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  386. U8X8_DLY(1),
  387. U8X8_CA(0xfd, 0x12), /* unlock */
  388. U8X8_C(0xae), /* display off */
  389. U8X8_CA(0xb3, 0x91), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  390. U8X8_CA(0xca, 0x7f), /* multiplex ratio 1/128 Duty (0x0F~0x7F) */
  391. U8X8_CA(0xa2, 0x00), /* display offset, shift mapping ram counter */
  392. U8X8_CA(0xa1, 0x00), /* display start line */
  393. //U8X8_CAA(0xa0, 0x14, 0x11), /* Set Re-Map / Dual COM Line Mode */
  394. U8X8_CAA(0xa0, 0x36, 0x011), /* Set Re-Map / Dual COM Line Mode */
  395. U8X8_CA(0xab, 0x01), /* Enable Internal VDD Regulator */
  396. U8X8_CAA(0xb4, 0xa0, 0x005|0x0fd), /* Display Enhancement A */
  397. U8X8_CA(0xc1, 0x9f), /* contrast */
  398. U8X8_CA(0xc7, 0x0f), /* Set Scale Factor of Segment Output Current Control */
  399. U8X8_C(0xb9), /* linear grayscale */
  400. U8X8_CA(0xb1, 0xe2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
  401. U8X8_CAA(0xd1, 0x082|0x020, 0x020), /* Display Enhancement B */
  402. U8X8_CA(0xbb, 0x1f), /* precharge voltage */
  403. U8X8_CA(0xb6, 0x08), /* precharge period */
  404. U8X8_CA(0xbe, 0x07), /* vcomh */
  405. U8X8_C(0xa6), /* normal display */
  406. U8X8_C(0xa9), /* exit partial display */
  407. U8X8_DLY(1), /* delay 2ms */
  408. U8X8_END_TRANSFER(), /* disable chip */
  409. U8X8_END() /* end of sequence */
  410. };
  411. uint8_t u8x8_d_ssd1322_240x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  412. {
  413. switch(msg)
  414. {
  415. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  416. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1322_240x128_display_info);
  417. break;
  418. case U8X8_MSG_DISPLAY_INIT:
  419. u8x8_d_helper_display_init(u8x8);
  420. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_240x128_init_seq);
  421. break;
  422. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  423. if ( arg_int == 0 )
  424. {
  425. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip0_seq);
  426. u8x8->x_offset = u8x8->display_info->default_x_offset;
  427. }
  428. else
  429. {
  430. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_flip1_seq);
  431. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  432. }
  433. break;
  434. default:
  435. return u8x8_d_ssd1322_common(u8x8, msg, arg_int, arg_ptr);
  436. }
  437. return 1;
  438. }
  439. /*=========================================================*/
  440. /*
  441. Top Win OLED 240x128
  442. Discussion: https://github.com/olikraus/u8g2/discussions/2308
  443. Issue: https://github.com/olikraus/u8g2/issues/2310
  444. The main difference to the previous device seems to be the dual com line mode
  445. (0x0a0 command)
  446. */
  447. static const uint8_t u8x8_d_ssd1322_topwin_240x128_flip0_seq[] = {
  448. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  449. U8X8_CAA(0x0a0, 0x036, 0x001), /* remap */
  450. U8X8_END_TRANSFER(), /* disable chip */
  451. U8X8_END() /* end of sequence */
  452. };
  453. static const uint8_t u8x8_d_ssd1322_topwin_240x128_flip1_seq[] = {
  454. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  455. U8X8_CAA(0x0a0, 0x024, 0x001), /* remap */
  456. U8X8_END_TRANSFER(), /* disable chip */
  457. U8X8_END() /* end of sequence */
  458. };
  459. static const u8x8_display_info_t u8x8_ssd1322_topwin_240x128_display_info =
  460. {
  461. /* chip_enable_level = */ 0,
  462. /* chip_disable_level = */ 1,
  463. /* post_chip_enable_wait_ns = */ 20,
  464. /* pre_chip_disable_wait_ns = */ 10,
  465. /* reset_pulse_width_ms = */ 100, /* SSD1322: 2 us */
  466. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  467. /* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
  468. /* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  469. /* sck_clock_hz = */ 10000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215), 10 MHz (issue 301) */
  470. /* spi_mode = */ 0, /* active high, rising edge */
  471. /* i2c_bus_clock_100kHz = */ 4,
  472. /* data_setup_time_ns = */ 10,
  473. /* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
  474. /* tile_width = */ 30, /* 240 pixel, so we require 30 bytes for this */
  475. /* tile_height = */ 16,
  476. /* default_x_offset = */ 24, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  477. /* flipmode_x_offset = */ 0x000,
  478. /* pixel_width = */ 240,
  479. /* pixel_height = */ 128
  480. };
  481. static const uint8_t u8x8_d_ssd1322_topwin_240x128_init_seq[] = {
  482. U8X8_DLY(1),
  483. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  484. U8X8_DLY(1),
  485. U8X8_CA(0xfd, 0x12), /* unlock */
  486. U8X8_C(0xae), /* display off */
  487. U8X8_CA(0xb3, 0x91), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  488. U8X8_CA(0xca, 0x7f), /* multiplex ratio 1/128 Duty (0x0F~0x7F) */
  489. U8X8_CA(0xa2, 0x00), /* display offset, shift mapping ram counter */
  490. U8X8_CA(0xa1, 0x00), /* display start line */
  491. U8X8_CAA(0xa0, 0x36, 0x001), /* Set Re-Map / Dual COM Line Mode, https://github.com/olikraus/u8g2/discussions/2308 */
  492. U8X8_CA(0xab, 0x01), /* Enable Internal VDD Regulator */
  493. U8X8_CAA(0xb4, 0xa0, 0x005|0x0fd), /* Display Enhancement A */
  494. U8X8_CA(0xc1, 0x9f), /* contrast */
  495. U8X8_CA(0xc7, 0x0f), /* Set Scale Factor of Segment Output Current Control */
  496. U8X8_C(0xb9), /* linear grayscale */
  497. U8X8_CA(0xb1, 0xe2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
  498. U8X8_CAA(0xd1, 0x082|0x020, 0x020), /* Display Enhancement B */
  499. U8X8_CA(0xbb, 0x1f), /* precharge voltage */
  500. U8X8_CA(0xb6, 0x08), /* precharge period */
  501. U8X8_CA(0xbe, 0x07), /* vcomh */
  502. U8X8_C(0xa6), /* normal display */
  503. U8X8_C(0xa9), /* exit partial display */
  504. U8X8_DLY(1), /* delay 2ms */
  505. U8X8_END_TRANSFER(), /* disable chip */
  506. U8X8_END() /* end of sequence */
  507. };
  508. uint8_t u8x8_d_ssd1322_topwin_240x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  509. {
  510. switch(msg)
  511. {
  512. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  513. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1322_topwin_240x128_display_info);
  514. break;
  515. case U8X8_MSG_DISPLAY_INIT:
  516. u8x8_d_helper_display_init(u8x8);
  517. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_topwin_240x128_init_seq);
  518. break;
  519. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  520. if ( arg_int == 0 )
  521. {
  522. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_topwin_240x128_flip0_seq);
  523. u8x8->x_offset = u8x8->display_info->default_x_offset;
  524. }
  525. else
  526. {
  527. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_topwin_240x128_flip1_seq);
  528. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  529. }
  530. break;
  531. default:
  532. return u8x8_d_ssd1322_common(u8x8, msg, arg_int, arg_ptr);
  533. }
  534. return 1;
  535. }
  536. /*=========================================================*/
  537. /*
  538. NHD-2.7-12864WDW3-M
  539. http://www.newhavendisplay.com/nhd2712864wdw3m-p-9546.html
  540. http://www.newhavendisplay.com/specs/NHD-2.7-12864WDW3-M.pdf
  541. It looks like that only every second pixel is connected to the OLED
  542. */
  543. uint8_t u8x8_d_ssd1322_common2(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  544. {
  545. uint8_t x;
  546. uint8_t y, c;
  547. uint8_t *ptr;
  548. switch(msg)
  549. {
  550. /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
  551. /*
  552. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  553. break;
  554. case U8X8_MSG_DISPLAY_INIT:
  555. u8x8_d_helper_display_init(u8x8);
  556. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_256x64_init_seq);
  557. break;
  558. */
  559. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  560. if ( arg_int == 0 )
  561. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_powersave0_seq);
  562. else
  563. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_powersave1_seq);
  564. break;
  565. #ifdef U8X8_WITH_SET_CONTRAST
  566. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  567. u8x8_cad_StartTransfer(u8x8);
  568. u8x8_cad_SendCmd(u8x8, 0x0C1 );
  569. u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1322 has range from 0 to 255 */
  570. u8x8_cad_EndTransfer(u8x8);
  571. break;
  572. #endif
  573. case U8X8_MSG_DISPLAY_DRAW_TILE:
  574. u8x8_cad_StartTransfer(u8x8);
  575. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  576. x *= 2; // only every 4th col can be addressed
  577. x *= 2; // only every second pixel is used in the 128x64 NHD OLED
  578. x += u8x8->x_offset;
  579. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  580. y *= 8;
  581. u8x8_cad_SendCmd(u8x8, 0x075 ); /* set row address, moved out of the loop (issue 302) */
  582. u8x8_cad_SendArg(u8x8, y);
  583. u8x8_cad_SendArg(u8x8, y+7);
  584. do
  585. {
  586. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  587. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  588. do
  589. {
  590. u8x8_cad_SendCmd(u8x8, 0x015 ); /* set column address */
  591. u8x8_cad_SendArg(u8x8, x ); /* start */
  592. u8x8_cad_SendArg(u8x8, x+1 ); /* end */
  593. u8x8_cad_SendCmd(u8x8, 0x05c ); /* write to ram */
  594. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1322_4to32(u8x8, ptr));
  595. ptr += 4;
  596. x += 2;
  597. u8x8_cad_SendCmd(u8x8, 0x015 ); /* set column address */
  598. u8x8_cad_SendArg(u8x8, x ); /* start */
  599. u8x8_cad_SendArg(u8x8, x+1 ); /* end */
  600. u8x8_cad_SendCmd(u8x8, 0x05c ); /* write to ram */
  601. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1322_4to32(u8x8, ptr));
  602. ptr += 4;
  603. x += 2;
  604. c--;
  605. } while( c > 0 );
  606. //x += 2;
  607. arg_int--;
  608. } while( arg_int > 0 );
  609. u8x8_cad_EndTransfer(u8x8);
  610. break;
  611. default:
  612. return 0;
  613. }
  614. return 1;
  615. }
  616. static const uint8_t u8x8_d_ssd1322_128x64_flip0_seq[] = {
  617. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  618. U8X8_CAA(0x0a0, 0x016, 0x011), /* remap */
  619. U8X8_END_TRANSFER(), /* disable chip */
  620. U8X8_END() /* end of sequence */
  621. };
  622. static const uint8_t u8x8_d_ssd1322_128x64_flip1_seq[] = {
  623. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  624. U8X8_CAA(0x0a0, 0x004, 0x011), /* remap */
  625. U8X8_END_TRANSFER(), /* disable chip */
  626. U8X8_END() /* end of sequence */
  627. };
  628. static const u8x8_display_info_t u8x8_ssd1322_128x64_display_info =
  629. {
  630. /* chip_enable_level = */ 0,
  631. /* chip_disable_level = */ 1,
  632. /* post_chip_enable_wait_ns = */ 20,
  633. /* pre_chip_disable_wait_ns = */ 10,
  634. /* reset_pulse_width_ms = */ 100, /* SSD1322: 2 us */
  635. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  636. /* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
  637. /* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  638. /* sck_clock_hz = */ 10000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215), 10 MHz (issue 301) */
  639. /* spi_mode = */ 0, /* active high, rising edge */
  640. /* i2c_bus_clock_100kHz = */ 4,
  641. /* data_setup_time_ns = */ 10,
  642. /* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
  643. /* tile_width = */ 16, /* 128 pixel */
  644. /* tile_height = */ 8,
  645. /* default_x_offset = */ 28, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  646. /* flipmode_x_offset = */ 28,
  647. /* pixel_width = */ 128,
  648. /* pixel_height = */ 64
  649. };
  650. static const uint8_t u8x8_d_ssd1322_128x64_init_seq[] = {
  651. U8X8_DLY(1),
  652. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  653. U8X8_DLY(1),
  654. U8X8_CA(0xfd, 0x12), /* unlock */
  655. U8X8_C(0xae), /* display off */
  656. U8X8_CA(0xb3, 0x91), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  657. U8X8_CA(0xca, 0x3f), /* multiplex ratio 1/64 Duty (0x0F~0x3F) */
  658. U8X8_CA(0xa2, 0x00), /* display offset, shift mapping ram counter */
  659. U8X8_CA(0xa1, 0x00), /* display start line */
  660. U8X8_CA(0xab, 0x01), /* Enable Internal VDD Regulator */
  661. /*
  662. A[0]=0b, Horizontal address increment [reset] ***
  663. A[0]=1b, Vertical address increment
  664. A[1]=0b, Disable Column Address Re-map [reset]
  665. A[1]=1b, Enable Column Address Re-map ***
  666. A[2]=0b, Disable Nibble Re-map [reset]
  667. A[2]=1b, Enable Nibble Re-map ***
  668. A[4]=0b, Scan from COM0 to COM[N –1] [reset]
  669. A[4]=1b, Scan from COM[N-1] to COM0, where N is the ***
  670. Multiplex ratio
  671. A[5]=0b, Disable COM Split Odd Even [reset] ***
  672. A[5]=1b, Enable COM Split Odd Even
  673. B[4], Enable / disable Dual COM Line mode
  674. 0b, Disable Dual COM mode [reset]
  675. 1b, Enable Dual COM mode (MUX ≤ 63)
  676. 0x16 = 00010110
  677. */
  678. //U8X8_CAA(0xa0, 0x14, 0x11), /* Set Re-Map / Dual COM Line Mode */
  679. //U8X8_CAA(0xa0, 0x06, 0x011), /* Set Re-Map / Dual COM Line Mode */
  680. U8X8_CAA(0xa0, 0x16, 0x011), /* Set Re-Map / Dual COM Line Mode (NHD-2.7-12864WDW3-M datasheet) */
  681. U8X8_CA(0xc7, 0x0f), /* Set Scale Factor of Segment Output Current Control */
  682. U8X8_CA(0xc1, 0x9f), /* contrast */
  683. //U8X8_CA(0xb1, 0xe2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment */
  684. U8X8_CA(0xb1, 0xf2), /* Phase 1 (Reset) & Phase 2 (Pre-Charge) Period Adjustment (NHD-2.7-12864WDW3-M datasheet) */
  685. U8X8_CA(0xbb, 0x1f), /* precharge voltage */
  686. //U8X8_CAA(0xb4, 0xa0, 0x005|0x0fd), /* Display Enhancement A */
  687. U8X8_CAA(0xb4, 0xa0, 0x0fd), /* Display Enhancement A (NHD-2.7-12864WDW3-M datasheet) */
  688. U8X8_CA(0xbe, 0x04), /* vcomh (NHD-2.7-12864WDW3-M datasheet) */
  689. U8X8_C(0xb9), /* linear grayscale */
  690. //U8X8_CAA(0xd1, 0x082|0x020, 0x020), /* Display Enhancement B */
  691. //U8X8_CA(0xb6, 0x08), /* precharge period */
  692. U8X8_C(0xa6), /* normal display */
  693. U8X8_C(0xa9), /* exit partial display */
  694. U8X8_DLY(1), /* delay 2ms */
  695. U8X8_END_TRANSFER(), /* disable chip */
  696. U8X8_END() /* end of sequence */
  697. };
  698. uint8_t u8x8_d_ssd1322_nhd_128x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  699. {
  700. switch(msg)
  701. {
  702. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  703. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1322_128x64_display_info);
  704. break;
  705. case U8X8_MSG_DISPLAY_INIT:
  706. u8x8_d_helper_display_init(u8x8);
  707. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_128x64_init_seq);
  708. break;
  709. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  710. if ( arg_int == 0 )
  711. {
  712. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_128x64_flip0_seq);
  713. u8x8->x_offset = u8x8->display_info->default_x_offset;
  714. }
  715. else
  716. {
  717. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1322_128x64_flip1_seq);
  718. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  719. }
  720. break;
  721. default:
  722. return u8x8_d_ssd1322_common2(u8x8, msg, arg_int, arg_ptr);
  723. }
  724. return 1;
  725. }