u8x8_d_ssd1320.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /*
  2. u8x8_d_ssd1320.c
  3. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  4. Copyright (c) 2020, 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. https://github.com/olikraus/u8g2/issues/1351
  27. SSD1320:
  28. 160 x 160 dot matrix
  29. 16 gray scale
  30. Adapted from u8x8_d_ssd1322.c with the command set of the SSD1320 controller
  31. "official" procedure is described here: https://github.com/olikraus/u8g2/wiki/internal
  32. NOTE: U8x8 does NOT work! --> not clear, needs to be checked
  33. https://github.com/olikraus/u8g2/issues/1816
  34. */
  35. #include "u8x8.h"
  36. static const uint8_t u8x8_d_ssd1320_cs1_160x132_nhd_powersave0_seq[] = {
  37. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  38. U8X8_C(0x0af), /* ssd1320: display on */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_ssd1320_cs1_160x132_nhd_powersave1_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_C(0x0ae), /* ssd1320: display off */
  45. U8X8_END_TRANSFER(), /* disable chip */
  46. U8X8_END() /* end of sequence */
  47. };
  48. /*
  49. input:32
  50. one tile (8 Bytes; 1 byte per column)
  51. output:
  52. Tile for SSD1320 (32 Bytes)
  53. */
  54. static uint8_t u8x8_ssd1320_to32_dest_buf[32];
  55. static uint8_t *u8x8_ssd1320_8to32(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
  56. {
  57. uint8_t v;
  58. uint8_t a,b;
  59. uint8_t i, j;
  60. uint8_t *dest;
  61. for( j = 0; j < 4; j++ )
  62. {
  63. dest = u8x8_ssd1320_to32_dest_buf;
  64. dest += j;
  65. a =*ptr;
  66. ptr++;
  67. b = *ptr;
  68. ptr++;
  69. for( i = 0; i < 8; i++ )
  70. {
  71. v = 0;
  72. if ( a&1 ) v |= 0x0f;
  73. if ( b&1 ) v |= 0xf0;
  74. *dest = v;
  75. dest+=4;
  76. a >>= 1;
  77. b >>= 1;
  78. }
  79. }
  80. return u8x8_ssd1320_to32_dest_buf;
  81. }
  82. uint8_t u8x8_d_ssd1320_common(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  83. {
  84. uint8_t x;
  85. uint8_t y, c;
  86. uint8_t *ptr;
  87. switch(msg)
  88. {
  89. /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
  90. /*
  91. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  92. break;
  93. case U8X8_MSG_DISPLAY_INIT:
  94. u8x8_d_helper_display_init(u8x8);
  95. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_256x64_init_seq);
  96. break;
  97. */
  98. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  99. if ( arg_int == 0 )
  100. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_powersave0_seq);
  101. else
  102. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_powersave1_seq);
  103. break;
  104. #ifdef U8X8_WITH_SET_CONTRAST
  105. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  106. u8x8_cad_StartTransfer(u8x8);
  107. u8x8_cad_SendCmd(u8x8, 0x081 );
  108. u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1320 has range from 1 to 255 */
  109. u8x8_cad_EndTransfer(u8x8);
  110. break;
  111. #endif
  112. case U8X8_MSG_DISPLAY_DRAW_TILE:
  113. u8x8_cad_StartTransfer(u8x8);
  114. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  115. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  116. x += u8x8->x_offset;
  117. y *= 8;
  118. u8x8_cad_SendCmd(u8x8, 0x022 ); /* set row address, moved out of the loop (issue 302) */
  119. u8x8_cad_SendArg(u8x8, y);
  120. u8x8_cad_SendArg(u8x8, y+7);
  121. do {
  122. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  123. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  124. do {
  125. u8x8_cad_SendCmd(u8x8, 0x021 ); /* set column address */
  126. u8x8_cad_SendArg(u8x8, x ); /* start */
  127. u8x8_cad_SendArg(u8x8, x+3 ); /* end */
  128. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1320_8to32(u8x8, ptr));
  129. ptr += 8;
  130. x += 4;
  131. c--;
  132. } while( c > 0 );
  133. //x += 2;
  134. arg_int--;
  135. } while( arg_int > 0 );
  136. u8x8_cad_EndTransfer(u8x8);
  137. break;
  138. default:
  139. return 0;
  140. }
  141. return 1;
  142. }
  143. static uint8_t *u8x8_ssd1320_8to32_2(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
  144. {
  145. uint8_t v;
  146. uint8_t a,b;
  147. uint8_t i, j;
  148. uint8_t *dest;
  149. for( j = 0; j < 4; j++ )
  150. {
  151. dest = u8x8_ssd1320_to32_dest_buf;
  152. dest += j;
  153. a =*ptr;
  154. ptr++;
  155. b = *ptr;
  156. ptr++;
  157. for( i = 0; i < 8; i++ )
  158. {
  159. v = 0;
  160. if ( a&1 ) v |= 0xf0; // changed from 0x0f to 0xf0, https://github.com/olikraus/u8g2/issues/1816
  161. if ( b&1 ) v |= 0x0f; // changed from 0xf0 to 0x0f, https://github.com/olikraus/u8g2/issues/1816
  162. *dest = v;
  163. dest+=4;
  164. a >>= 1;
  165. b >>= 1;
  166. }
  167. }
  168. return u8x8_ssd1320_to32_dest_buf;
  169. }
  170. uint8_t u8x8_d_ssd1320_common_2(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  171. {
  172. uint8_t x;
  173. uint8_t y, c;
  174. uint8_t *ptr;
  175. switch(msg)
  176. {
  177. /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
  178. /*
  179. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  180. break;
  181. case U8X8_MSG_DISPLAY_INIT:
  182. u8x8_d_helper_display_init(u8x8);
  183. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_256x64_init_seq);
  184. break;
  185. */
  186. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  187. if ( arg_int == 0 )
  188. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_powersave0_seq);
  189. else
  190. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_powersave1_seq);
  191. break;
  192. #ifdef U8X8_WITH_SET_CONTRAST
  193. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  194. u8x8_cad_StartTransfer(u8x8);
  195. u8x8_cad_SendCmd(u8x8, 0x081 );
  196. u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1320 has range from 1 to 255 */
  197. u8x8_cad_EndTransfer(u8x8);
  198. break;
  199. #endif
  200. case U8X8_MSG_DISPLAY_DRAW_TILE:
  201. u8x8_cad_StartTransfer(u8x8);
  202. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  203. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  204. x += u8x8->x_offset;
  205. y *= 8;
  206. u8x8_cad_SendCmd(u8x8, 0x022 ); /* set row address, moved out of the loop (issue 302) */
  207. u8x8_cad_SendArg(u8x8, y);
  208. u8x8_cad_SendArg(u8x8, y+7);
  209. do {
  210. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  211. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  212. do {
  213. u8x8_cad_SendCmd(u8x8, 0x021 ); /* set column address */
  214. u8x8_cad_SendArg(u8x8, x ); /* start */
  215. u8x8_cad_SendArg(u8x8, x+3 ); /* end */
  216. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1320_8to32_2(u8x8, ptr));
  217. ptr += 8;
  218. x += 4;
  219. c--;
  220. } while( c > 0 );
  221. //x += 2;
  222. arg_int--;
  223. } while( arg_int > 0 );
  224. u8x8_cad_EndTransfer(u8x8);
  225. break;
  226. default:
  227. return 0;
  228. }
  229. return 1;
  230. }
  231. /*=========================================================*/
  232. /* 160x32 */
  233. static const uint8_t u8x8_d_ssd1320_cs1_160x32_nhd_flip0_seq[] = {
  234. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  235. U8X8_C(0x0a0), /* remap */
  236. U8X8_END_TRANSFER(), /* disable chip */
  237. U8X8_END() /* end of sequence */
  238. };
  239. static const uint8_t u8x8_d_ssd1320_cs1_160x32_nhd_flip1_seq[] = {
  240. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  241. U8X8_C(0x0a1), /* remap */
  242. U8X8_END_TRANSFER(), /* disable chip */
  243. U8X8_END() /* end of sequence */
  244. };
  245. static const u8x8_display_info_t u8x8_d_ssd1320_cs1_160x32_display_info =
  246. {
  247. /* chip_enable_level = */ 0,
  248. /* chip_disable_level = */ 1,
  249. /* post_chip_enable_wait_ns = */ 20,
  250. /* pre_chip_disable_wait_ns = */ 10,
  251. /* reset_pulse_width_ms = */ 100, /* ssd1320: 2 us */
  252. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  253. /* sda_setup_time_ns = */ 50, /* ssd1320: 15ns, but cycle time is 100ns, so use 100/2 */
  254. /* sck_pulse_width_ns = */ 50, /* ssd1320: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  255. /* 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) */
  256. /* spi_mode = */ 0, /* active high, rising edge */
  257. /* i2c_bus_clock_100kHz = */ 4,
  258. /* data_setup_time_ns = */ 10,
  259. /* write_pulse_width_ns = */ 150, /* ssd1320: cycle time is 300ns, so use 300/2 = 150 */
  260. /* tile_width = */ 20, /* 160 pixel, so we require 20 bytes for this */
  261. /* tile_height = */ 4,
  262. /* default_x_offset = */ 0, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  263. /* flipmode_x_offset = */ 0,
  264. /* pixel_width = */ 160,
  265. /* pixel_height = */ 32
  266. };
  267. // initialisation sequence from the Arduino Library
  268. // (see https://github.com/sparkfun/SparkFun_SSD1320_OLED_Arduino_Library)
  269. static const uint8_t u8x8_d_ssd1320_cs1_160x32_init_seq[] = {
  270. U8X8_DLY(1),
  271. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  272. U8X8_DLY(1),
  273. U8X8_C(0xae), /* display off */
  274. U8X8_CA(0xd5, 0xC2), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  275. U8X8_CA(0xa8, 0x1f), /* multiplex ratio 1/64 Duty (0x0F~0x3F) */
  276. U8X8_CA(0xa2, 0x00), /* display start line */
  277. U8X8_C(0xa0), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS1 */
  278. // U8X8_C(0xa1), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS2 */
  279. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  280. // U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS2 */
  281. U8X8_CA(0xd3, 0x72), /* CS1 */
  282. // U8X8_CA(0xd3, 0x92), /* CS2 */
  283. U8X8_CA(0xda, 0x12), /* Set SEG Pins Hardware Configuration: */
  284. U8X8_CA(0x81, 0x5a), /* contrast */
  285. U8X8_CA(0xd9, 0x22), /* Set Phase Length */
  286. U8X8_CA(0xdb, 0x30), /* VCOMH Deselect Level */
  287. U8X8_CA(0xad, 0x10), /* Internal IREF Enable */
  288. U8X8_CA(0x20, 0x00), /* Memory Addressing Mode: Horizontal */
  289. U8X8_CA(0x8d, 0x01), /* disable internal charge pump 1 */
  290. U8X8_CA(0xac, 0x00), /* disable internal charge pump 2 */
  291. U8X8_C(0xa4), /* display on */
  292. U8X8_C(0xa6), /* normal display */
  293. U8X8_DLY(1), /* delay 2ms */
  294. U8X8_END_TRANSFER(), /* disable chip */
  295. U8X8_END() /* end of sequence */
  296. };
  297. uint8_t u8x8_d_ssd1320_160x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  298. {
  299. switch(msg)
  300. {
  301. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  302. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_ssd1320_cs1_160x32_display_info);
  303. break;
  304. case U8X8_MSG_DISPLAY_INIT:
  305. u8x8_d_helper_display_init(u8x8);
  306. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x32_init_seq);
  307. break;
  308. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  309. if ( arg_int == 0 ){
  310. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x32_nhd_flip0_seq);
  311. u8x8->x_offset = u8x8->display_info->default_x_offset;
  312. }
  313. else{
  314. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x32_nhd_flip1_seq);
  315. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  316. }
  317. break;
  318. default:
  319. return u8x8_d_ssd1320_common(u8x8, msg, arg_int, arg_ptr);
  320. }
  321. return 1;
  322. }
  323. /*=========================================================*/
  324. /* 160x132 (actually 320x132) */
  325. static const uint8_t u8x8_d_ssd1320_cs1_160x132_nhd_flip0_seq[] = {
  326. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  327. U8X8_C(0x0a0), /* remap */
  328. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  329. U8X8_CA(0xd3, 0x0e), /* CS1 */
  330. U8X8_END_TRANSFER(), /* disable chip */
  331. U8X8_END() /* end of sequence */
  332. };
  333. static const uint8_t u8x8_d_ssd1320_cs1_160x132_nhd_flip1_seq[] = {
  334. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  335. U8X8_C(0x0a1), /* remap */
  336. U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS1 */
  337. U8X8_CA(0xd3, 0x92), /* CS1 */
  338. U8X8_END_TRANSFER(), /* disable chip */
  339. U8X8_END() /* end of sequence */
  340. };
  341. static const u8x8_display_info_t u8x8_d_ssd1320_cs1_160x132_display_info =
  342. {
  343. /* chip_enable_level = */ 0,
  344. /* chip_disable_level = */ 1,
  345. /* post_chip_enable_wait_ns = */ 20,
  346. /* pre_chip_disable_wait_ns = */ 10,
  347. /* reset_pulse_width_ms = */ 100, /* ssd1320: 2 us */
  348. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  349. /* sda_setup_time_ns = */ 50, /* ssd1320: 15ns, but cycle time is 100ns, so use 100/2 */
  350. /* sck_pulse_width_ns = */ 50, /* ssd1320: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  351. /* 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) */
  352. /* spi_mode = */ 0, /* active high, rising edge */
  353. /* i2c_bus_clock_100kHz = */ 4,
  354. /* data_setup_time_ns = */ 10,
  355. /* write_pulse_width_ns = */ 150, /* ssd1320: cycle time is 300ns, so use 300/2 = 150 */
  356. /* tile_width = */ 20, /* 160 pixel, so we require 20 bytes for this */
  357. /* tile_height = */ 17,
  358. /* default_x_offset = */ 0, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  359. /* flipmode_x_offset = */ 0,
  360. /* pixel_width = */ 160,
  361. /* pixel_height = */ 132
  362. };
  363. /* the following sequence will work, but requires contrast to be very high */
  364. /* added #ifdef to avoid compiler warning, issue 1802 */
  365. #ifdef NOT_USED
  366. static const uint8_t u8x8_d_ssd1320_cs1_160x132_init_seq[] = {
  367. U8X8_DLY(1),
  368. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  369. U8X8_DLY(1),
  370. U8X8_C(0xae), /* display off */
  371. U8X8_CA(0xd5, 0xC2), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  372. U8X8_CA(0xa8, 0x83), /* multiplex ratio 1/132 Duty */
  373. U8X8_CA(0xa2, 0x00), /* display start line */
  374. U8X8_C(0xa0), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS1 */
  375. // U8X8_C(0xa1), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS2 */
  376. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  377. // U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS2 */
  378. U8X8_CA(0xd3, 0x0e), /* CS1 */
  379. // U8X8_CA(0xd3, 0x92), /* CS2 */
  380. U8X8_CA(0xda, 0x12), /* Set SEG Pins Hardware Configuration: */
  381. U8X8_CA(0x81, 0x5a), /* contrast */
  382. U8X8_CA(0xd9, 0x22), /* Set Phase Length */
  383. U8X8_CA(0xdb, 0x30), /* VCOMH Deselect Level */
  384. U8X8_CA(0xad, 0x10), /* Internal IREF Enable */
  385. U8X8_CA(0x20, 0x00), /* Memory Addressing Mode: Horizontal */
  386. U8X8_CA(0x8d, 0x01), /* disable internal charge pump 1 */
  387. U8X8_CA(0xac, 0x00), /* disable internal charge pump 2 */
  388. U8X8_C(0xa4), /* display on */
  389. U8X8_C(0xa6), /* normal display */
  390. U8X8_DLY(1), /* delay 2ms */
  391. U8X8_END_TRANSFER(), /* disable chip */
  392. U8X8_END() /* end of sequence */
  393. };
  394. #endif
  395. /*
  396. OLED_WR_Byte(0xae,OLED_CMD);//Display OFF
  397. OLED_WR_Byte(0xfd,OLED_CMD);//Set Command Lock
  398. OLED_WR_Byte(0x12,OLED_CMD);
  399. OLED_WR_Byte(0x20,OLED_CMD);//Set Memory Addressing Mode
  400. OLED_WR_Byte(0x00,OLED_CMD);
  401. OLED_WR_Byte(0x25,OLED_CMD);//Set Portrait Addressing Mode
  402. OLED_WR_Byte(0x00,OLED_CMD);//Normal Addressing Mode
  403. OLED_WR_Byte(0x81,OLED_CMD);//Set Contrast Control
  404. OLED_WR_Byte(0x6b,OLED_CMD);
  405. OLED_WR_Byte1(0xa0,OLED_CMD,1);//Set Seg Remap LEFT DISPLAY
  406. OLED_WR_Byte1(0xa1,OLED_CMD,2);//Set Seg Remap RIGHT DISPLAY
  407. OLED_WR_Byte(0xa2,OLED_CMD);//Set Display Start Line
  408. OLED_WR_Byte(0x00,OLED_CMD);
  409. OLED_WR_Byte(0xa4,OLED_CMD);//Resume to RAM content display
  410. OLED_WR_Byte(0xa6,OLED_CMD);//Set Normal Display
  411. OLED_WR_Byte(0xa8,OLED_CMD);//Set MUX Ratio
  412. OLED_WR_Byte(0x83,OLED_CMD);//1/132 duty
  413. OLED_WR_Byte(0xad,OLED_CMD);//Select external or internal IREF
  414. OLED_WR_Byte(0x10,OLED_CMD);
  415. OLED_WR_Byte(0xbc,OLED_CMD);//Set Pre-charge voltage
  416. OLED_WR_Byte(0x1e,OLED_CMD);//
  417. OLED_WR_Byte(0xbf,OLED_CMD);//Linear LUT
  418. OLED_WR_Byte1(0xc8,OLED_CMD,1);//Set COM Output Scan Direction LEFT DISPLAY
  419. OLED_WR_Byte1(0xc0,OLED_CMD,2);//Set COM Output Scan Direction RIGHT DISPLAY
  420. OLED_WR_Byte(0xd3,OLED_CMD);//Set Display Offset
  421. OLED_WR_Byte1(0x0e,OLED_CMD,1); //LEFT DISPLAY
  422. OLED_WR_Byte1(0x92,OLED_CMD,2); // RIGHT DISPLAY
  423. OLED_WR_Byte(0xd5,OLED_CMD);//Set Display Clock Divide Ratio/Oscillator Frequency
  424. OLED_WR_Byte(0xc2,OLED_CMD);//85Hz
  425. OLED_WR_Byte(0xd9,OLED_CMD);//Set Pre-charge Period
  426. OLED_WR_Byte(0x72,OLED_CMD);//
  427. OLED_WR_Byte(0xda,OLED_CMD);//Set SEG Pins Hardware Configuration
  428. OLED_WR_Byte(0x32,OLED_CMD);
  429. OLED_WR_Byte(0xbd,OLED_CMD);//Set VP
  430. OLED_WR_Byte(0x03,OLED_CMD);
  431. OLED_WR_Byte(0xdb,OLED_CMD);//Set VCOMH
  432. OLED_WR_Byte(0x30,OLED_CMD);
  433. OLED_WR_Byte(0xaf,OLED_CMD);//Display on
  434. */
  435. static const uint8_t u8x8_d_ssd1320_160x132_init_seq[] = {
  436. U8X8_DLY(1),
  437. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  438. U8X8_DLY(1),
  439. U8X8_C(0xae), /* display off */
  440. U8X8_CA(0xd5, 0xC2), /* set display clock divide ratio/oscillator frequency (set clock as 80 frames/sec) */
  441. U8X8_CA(0xa8, 0x83), /* multiplex ratio 1/132 Duty */
  442. U8X8_CA(0xa2, 0x00), /* display start line */
  443. U8X8_C(0xa0), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS1 */
  444. // U8X8_C(0xa1), /* Set Segment Re-Map: column address 0 mapped to SEG0 CS2 */
  445. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  446. // U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS2 */
  447. U8X8_CA(0xad, 0x10), /* select Iref: 0x00 external (reset default), 0x10 internal */
  448. U8X8_CA(0xbc, 0x1e), /* pre-charge voltage level 0x00..0x1f, reset default: 0x1e */
  449. U8X8_C(0xbf), /* select linear LUT */
  450. U8X8_CA(0xd5, 0xc2), /* Bit 0..3: clock ratio 1, 2, 4, 8, ...256, reset=0x1, Bit 4..7: F_osc 0..15 */
  451. U8X8_CA(0xd9, 0x72), /* Set Phase 1&2 Length, Bit 0..3: Phase 1, Bit 4..7: Phase 2, reset default 0x72 */
  452. U8X8_CA(0xbd, 0x03), /* from the vendor init sequence */
  453. U8X8_CA(0xdb, 0x30), /* VCOMH Deselect Level */
  454. U8X8_CA(0xd3, 0x0e), /* CS1 */
  455. // U8X8_CA(0xd3, 0x92), /* CS2 */
  456. U8X8_CA(0xda, 0x12), /* Set SEG Pins Hardware Configuration: */
  457. U8X8_CA(0x81, 0x6b), /* contrast */
  458. //U8X8_CA(0xd9, 0x22), /* Set Phase Length */
  459. //U8X8_CA(0xdb, 0x30), /* VCOMH Deselect Level */
  460. //U8X8_CA(0xad, 0x10), /* Internal IREF Enable */
  461. U8X8_CA(0x20, 0x00), /* Memory Addressing Mode: Horizontal */
  462. //U8X8_CA(0x8d, 0x01), /* unknown in SSD1320 datasheet, disable internal charge pump 1 */
  463. //U8X8_CA(0xac, 0x00), /* unknown in SSD1320 datasheet, disable internal charge pump 2 */
  464. U8X8_C(0xa4), /* display RAM on */
  465. U8X8_C(0xa6), /* normal display */
  466. U8X8_DLY(1), /* delay 2ms */
  467. U8X8_END_TRANSFER(), /* disable chip */
  468. U8X8_END() /* end of sequence */
  469. };
  470. uint8_t u8x8_d_ssd1320_160x132(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  471. {
  472. switch(msg)
  473. {
  474. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  475. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_ssd1320_cs1_160x132_display_info);
  476. break;
  477. case U8X8_MSG_DISPLAY_INIT:
  478. u8x8_d_helper_display_init(u8x8);
  479. // u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_init_seq);
  480. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_160x132_init_seq);
  481. break;
  482. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  483. if ( arg_int == 0 ){
  484. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_flip0_seq);
  485. u8x8->x_offset = u8x8->display_info->default_x_offset;
  486. }
  487. else{
  488. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_cs1_160x132_nhd_flip1_seq);
  489. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  490. }
  491. break;
  492. default:
  493. return u8x8_d_ssd1320_common(u8x8, msg, arg_int, arg_ptr);
  494. }
  495. return 1;
  496. }
  497. /*=========================================================*/
  498. /* https://github.com/olikraus/u8g2/issues/1816 */
  499. /* 160x80, https://de.aliexpress.com/item/1005003510267760.html */
  500. static const uint8_t u8x8_d_ssd1320_160x80_flip0_seq[] = {
  501. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  502. U8X8_C(0x0a0), /* remap */
  503. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  504. U8X8_CA(0xd3, 39), /* display offset */
  505. U8X8_END_TRANSFER(), /* disable chip */
  506. U8X8_END() /* end of sequence */
  507. };
  508. static const uint8_t u8x8_d_ssd1320_160x80_flip1_seq[] = {
  509. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  510. U8X8_C(0x0a1), /* remap */
  511. U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS1 */
  512. U8X8_CA(0xd3, 120), /* display offset */
  513. U8X8_END_TRANSFER(), /* disable chip */
  514. U8X8_END() /* end of sequence */
  515. };
  516. static const u8x8_display_info_t u8x8_d_ssd1320_160x80_display_info =
  517. {
  518. /* chip_enable_level = */ 0,
  519. /* chip_disable_level = */ 1,
  520. /* post_chip_enable_wait_ns = */ 20,
  521. /* pre_chip_disable_wait_ns = */ 10,
  522. /* reset_pulse_width_ms = */ 100, /* ssd1320: 2 us */
  523. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  524. /* sda_setup_time_ns = */ 50, /* ssd1320: 15ns, but cycle time is 100ns, so use 100/2 */
  525. /* sck_pulse_width_ns = */ 50, /* ssd1320: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  526. /* 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) */
  527. /* spi_mode = */ 0, /* active high, rising edge */
  528. /* i2c_bus_clock_100kHz = */ 4,
  529. /* data_setup_time_ns = */ 10,
  530. /* write_pulse_width_ns = */ 150, /* ssd1320: cycle time is 300ns, so use 300/2 = 150 */
  531. /* tile_width = */ 20, /* 160 pixel, so we require 20 bytes for this */
  532. /* tile_height = */ 10,
  533. /* default_x_offset = */ 0, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  534. /* flipmode_x_offset = */ 0,
  535. /* pixel_width = */ 160,
  536. /* pixel_height = */ 80
  537. };
  538. static const uint8_t u8x8_d_ssd1320_160x80_init_seq[] = {
  539. U8X8_DLY(1),
  540. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  541. U8X8_DLY(1),
  542. U8X8_C(0xae), /* display off */
  543. U8X8_CA(0xa8, 80), /* multiplex ratio 1/80 Duty */
  544. U8X8_CA(0xa2, 0), /* display start line */
  545. U8X8_C(0xa0), /* Set Segment Re-Map */
  546. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode */
  547. U8X8_CA(0xad, 0x10), /* select Iref: 0x00 external (reset default), 0x10 internal */
  548. U8X8_CA(0xbc, 0x1e), /* pre-charge voltage level 0x00..0x1f, reset default: 0x1e */
  549. U8X8_C(0xbf), /* select linear LUT */
  550. U8X8_CA(0xd5, 0xc2), /* Bit 0..3: clock ratio 1, 2, 4, 8, ...256, reset=0x1, Bit 4..7: F_osc 0..15 */
  551. U8X8_CA(0xd9, 0x72), /* Set Phase 1&2 Length, Bit 0..3: Phase 1, Bit 4..7: Phase 2, reset default 0x72 */
  552. U8X8_CA(0xd3, 39), /* display offset */
  553. U8X8_CA(0xda, 0x12), /* Set SEG Pins Hardware Configuration: */
  554. U8X8_CA(0x81, 0x70), /* contrast */
  555. U8X8_CA(0x20, 0x00), /* Memory Addressing Mode: Horizontal */
  556. U8X8_C(0xa4), /* display RAM on */
  557. U8X8_C(0xa6), /* normal display */
  558. U8X8_DLY(1), /* delay 2ms */
  559. U8X8_END_TRANSFER(), /* disable chip */
  560. U8X8_END() /* end of sequence */
  561. };
  562. uint8_t u8x8_d_ssd1320_160x80(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  563. {
  564. if ( u8x8_d_ssd1320_common_2(u8x8, msg, arg_int, arg_ptr) != 0 )
  565. return 1;
  566. switch(msg)
  567. {
  568. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  569. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_ssd1320_160x80_display_info);
  570. break;
  571. case U8X8_MSG_DISPLAY_INIT:
  572. u8x8_d_helper_display_init(u8x8);
  573. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_160x80_init_seq);
  574. break;
  575. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  576. if ( arg_int == 0 ){
  577. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_160x80_flip0_seq);
  578. u8x8->x_offset = u8x8->display_info->default_x_offset;
  579. }
  580. else{
  581. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_160x80_flip1_seq);
  582. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  583. }
  584. break;
  585. default:
  586. break;
  587. }
  588. return 1;
  589. }
  590. /*=========================================================*/
  591. /* https://github.com/olikraus/u8g2/issues/2565 */
  592. /* 128x72, https://www.buydisplay.com/128x72-grayscale-oled-spi-white-0-72-inch-arduino-raspberry-pi */
  593. static const uint8_t u8x8_d_ssd1320_128x72_flip0_seq[] = {
  594. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  595. U8X8_C(0x0a0), /* remap */
  596. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode CS1 */
  597. U8X8_CA(0xd3, 0x2c), /* display offset WARNING: ALSO ASSIGN THIS IN THE INIT SEQ */
  598. U8X8_END_TRANSFER(), /* disable chip */
  599. U8X8_END() /* end of sequence */
  600. };
  601. static const uint8_t u8x8_d_ssd1320_128x72_flip1_seq[] = {
  602. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  603. U8X8_C(0x0a1), /* remap */
  604. U8X8_C(0xc0), /* Set COM Output Scan Direction: normal mode CS1 */
  605. U8X8_CA(0xd3, 0x74), /* display offset */
  606. U8X8_END_TRANSFER(), /* disable chip */
  607. U8X8_END() /* end of sequence */
  608. };
  609. static const u8x8_display_info_t u8x8_d_ssd1320_128x72_display_info =
  610. {
  611. /* chip_enable_level = */ 0,
  612. /* chip_disable_level = */ 1,
  613. /* post_chip_enable_wait_ns = */ 20,
  614. /* pre_chip_disable_wait_ns = */ 10,
  615. /* reset_pulse_width_ms = */ 100, /* ssd1320: 2 us */
  616. /* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
  617. /* sda_setup_time_ns = */ 50, /* ssd1320: 15ns, but cycle time is 100ns, so use 100/2 */
  618. /* sck_pulse_width_ns = */ 50, /* ssd1320: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
  619. /* 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) */
  620. /* spi_mode = */ 0, /* active high, rising edge */
  621. /* i2c_bus_clock_100kHz = */ 4,
  622. /* data_setup_time_ns = */ 10,
  623. /* write_pulse_width_ns = */ 150, /* ssd1320: cycle time is 300ns, so use 300/2 = 150 */
  624. /* tile_width = */ 16, /* 128 */
  625. /* tile_height = */ 9, /* 72 */
  626. /* default_x_offset = */ 16, /* this is the byte offset (there are two pixel per byte with 4 bit per pixel) */
  627. /* flipmode_x_offset = */ 0,
  628. /* pixel_width = */ 128,
  629. /* pixel_height = */ 72
  630. };
  631. /* from the buydisplay.com example code for the 8051:
  632. Contrast_level=0xDF
  633. OLED_WR_Byte(0xae,OLED_CMD);//Set y Off
  634. OLED_WR_Byte(0xD5,OLED_CMD);//Set Display Clock Divide Ratio/Oscillator Frequency
  635. OLED_WR_Byte(0x11,OLED_CMD);
  636. OLED_WR_Byte(0xA8,OLED_CMD);//Set Multiplex Ratio
  637. OLED_WR_Byte(0x47,OLED_CMD);
  638. OLED_WR_Byte(0xA2,OLED_CMD);//Set Display Start Line
  639. OLED_WR_Byte(0x00,OLED_CMD);
  640. if(USE_HORIZONTAL==0)
  641. {
  642. x_offset=0x10;
  643. OLED_WR_Byte(0xD3,OLED_CMD);//Set Display Offset
  644. OLED_WR_Byte(0x2C,OLED_CMD);
  645. OLED_WR_Byte(0xa0,OLED_CMD);//Set COM Output Scan Direction
  646. OLED_WR_Byte(0xC8,OLED_CMD);
  647. }
  648. else
  649. {
  650. x_offset=0;
  651. OLED_WR_Byte(0xD3,OLED_CMD);//Set Display Offset
  652. OLED_WR_Byte(0x74,OLED_CMD);
  653. OLED_WR_Byte(0xa1,OLED_CMD);//Set COM Output Scan Direction
  654. OLED_WR_Byte(0xC0,OLED_CMD);
  655. }
  656. OLED_WR_Byte(0xDA,OLED_CMD);//SetSEGPinsHardwareConfiguration
  657. OLED_WR_Byte(0x32,OLED_CMD);
  658. OLED_WR_Byte(0x81,OLED_CMD);//Set Contrast Control
  659. OLED_WR_Byte(Contrast_level,OLED_CMD);
  660. OLED_WR_Byte(0xD9,OLED_CMD);//SSet Pre-Charge Priod
  661. OLED_WR_Byte(0x72,OLED_CMD);
  662. OLED_WR_Byte(0xDB,OLED_CMD);//Set VCOMH Deselect Level
  663. OLED_WR_Byte(0x20,OLED_CMD);
  664. OLED_WR_Byte(0xAD,OLED_CMD);//Set Internal IREF Enable
  665. OLED_WR_Byte(0x00,OLED_CMD);
  666. OLED_WR_Byte(0xBC,OLED_CMD);
  667. OLED_WR_Byte(0x1E,OLED_CMD);
  668. */
  669. static const uint8_t u8x8_d_ssd1320_128x72_init_seq[] = {
  670. U8X8_DLY(1),
  671. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  672. U8X8_DLY(1),
  673. U8X8_C(0xae), /* display off */
  674. U8X8_CA(0xa8, 0x47), /* multiplex ratio 1/72 Duty (128x72 init code) */
  675. U8X8_CA(0xa2, 0), /* display start line (128x72 init code) */
  676. U8X8_C(0xa0), /* Set Segment Re-Map */
  677. U8X8_C(0xc8), /* Set COM Output Scan Direction: normal mode */
  678. U8X8_CA(0xad, 0x10), /* select Iref: 0x00 external (reset default), 0x10 internal (datasheet: 0x00, but no difference with 0x10) */
  679. U8X8_CA(0xbc, 0x1e), /* pre-charge voltage level 0x00..0x1f, reset default: 0x1e (128x72 init code)*/
  680. U8X8_C(0xbf), /* select linear LUT */
  681. //U8X8_DLY(1),
  682. U8X8_CA(0xd5, 0x11 ), /* Bit 0..3: clock ratio 1, 2, 4, 8, ...256, reset=0x1, Bit 4..7: F_osc 0..15 (128x72 init code)*/
  683. U8X8_CA(0xd3, 0x2c), /* display offset */
  684. U8X8_CA(0xda, 0x12), /* Set SEG Pins Hardware Configuration: (128x72 init code: 0x32, but 0x12 req here) */
  685. U8X8_CA(0x81, 0xDF), /* contrast (128x72 init code) */
  686. U8X8_CA(0xd9, 0x72), /* Set Phase 1&2 Length, Bit 0..3: Phase 1, Bit 4..7: Phase 2, reset default 0x72 */
  687. U8X8_CA(0xdb, 0x20), /* VCOMH Deselect Level (128x72 init code 0x20) */
  688. U8X8_CA(0x20, 0x00), /* Memory Addressing Mode: Horizontal */
  689. U8X8_C(0xa4), /* display RAM on */
  690. U8X8_C(0xa6), /* normal display */
  691. U8X8_DLY(1), /* delay 2ms */
  692. U8X8_END_TRANSFER(), /* disable chip */
  693. U8X8_END() /* end of sequence */
  694. };
  695. uint8_t u8x8_d_ssd1320_128x72(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  696. {
  697. if ( u8x8_d_ssd1320_common_2(u8x8, msg, arg_int, arg_ptr) != 0 )
  698. return 1;
  699. switch(msg)
  700. {
  701. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  702. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_d_ssd1320_128x72_display_info);
  703. break;
  704. case U8X8_MSG_DISPLAY_INIT:
  705. u8x8_d_helper_display_init(u8x8);
  706. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_128x72_init_seq);
  707. break;
  708. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  709. if ( arg_int == 0 ){
  710. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_128x72_flip0_seq);
  711. u8x8->x_offset = u8x8->display_info->default_x_offset;
  712. }
  713. else{
  714. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1320_128x72_flip1_seq);
  715. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  716. }
  717. break;
  718. default:
  719. break;
  720. }
  721. return 1;
  722. }