u8x8_d_ssd1325.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. u8x8_d_ssd1325.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. SSD1325:
  27. 128 x 80, 16 Gray Scale Dot Matrix
  28. SSD0323: Identical to SSD1325, issue 720
  29. */
  30. #include "u8x8.h"
  31. static const uint8_t u8x8_d_ssd1325_128x64_nhd_powersave0_seq[] = {
  32. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  33. U8X8_C(0x0af), /* display on */
  34. U8X8_END_TRANSFER(), /* disable chip */
  35. U8X8_END() /* end of sequence */
  36. };
  37. static const uint8_t u8x8_d_ssd1325_128x64_nhd_powersave1_seq[] = {
  38. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  39. U8X8_C(0x0ae), /* display off */
  40. U8X8_END_TRANSFER(), /* disable chip */
  41. U8X8_END() /* end of sequence */
  42. };
  43. static const uint8_t u8x8_d_ssd1325_128x64_nhd_flip0_seq[] = {
  44. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  45. U8X8_CA(0x0a0, 0x052), /* remap */
  46. U8X8_END_TRANSFER(), /* disable chip */
  47. U8X8_END() /* end of sequence */
  48. };
  49. static const uint8_t u8x8_d_ssd1325_128x64_nhd_flip1_seq[] = {
  50. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  51. U8X8_CA(0x0a0, 0x041), /* remap */
  52. U8X8_END_TRANSFER(), /* disable chip */
  53. U8X8_END() /* end of sequence */
  54. };
  55. /*
  56. input:
  57. one tile (8 Bytes)
  58. output:
  59. Tile for SSD1325 (32 Bytes)
  60. */
  61. static uint8_t u8x8_ssd1325_8to32_dest_buf[32];
  62. static uint8_t *u8x8_ssd1325_8to32(U8X8_UNUSED u8x8_t *u8x8, uint8_t *ptr)
  63. {
  64. uint8_t v;
  65. uint8_t a,b;
  66. uint8_t i, j;
  67. uint8_t *dest;
  68. for( j = 0; j < 4; j++ )
  69. {
  70. dest = u8x8_ssd1325_8to32_dest_buf;
  71. dest += j;
  72. a =*ptr;
  73. ptr++;
  74. b = *ptr;
  75. ptr++;
  76. for( i = 0; i < 8; i++ )
  77. {
  78. v = 0;
  79. if ( a&1 ) v |= 0xf0;
  80. if ( b&1 ) v |= 0x0f;
  81. *dest = v;
  82. dest+=4;
  83. a >>= 1;
  84. b >>= 1;
  85. }
  86. }
  87. return u8x8_ssd1325_8to32_dest_buf;
  88. }
  89. /*===================================================================*/
  90. static uint8_t u8x8_d_ssd1325_128x64_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  91. {
  92. uint8_t x, y, c;
  93. uint8_t *ptr;
  94. switch(msg)
  95. {
  96. /* handled by the calling function
  97. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  98. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1325_128x64_nhd_display_info);
  99. break;
  100. */
  101. /* handled by the calling function
  102. case U8X8_MSG_DISPLAY_INIT:
  103. u8x8_d_helper_display_init(u8x8);
  104. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_init_seq);
  105. break;
  106. */
  107. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  108. if ( arg_int == 0 )
  109. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_powersave0_seq);
  110. else
  111. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_powersave1_seq);
  112. break;
  113. /* handled by the calling function
  114. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  115. if ( arg_int == 0 )
  116. {
  117. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_flip0_seq);
  118. u8x8->x_offset = u8x8->display_info->default_x_offset;
  119. }
  120. else
  121. {
  122. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_flip1_seq);
  123. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  124. }
  125. break;
  126. */
  127. #ifdef U8X8_WITH_SET_CONTRAST
  128. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  129. u8x8_cad_StartTransfer(u8x8);
  130. u8x8_cad_SendCmd(u8x8, 0x081 );
  131. u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1325 has range from 0 to 255 */
  132. u8x8_cad_EndTransfer(u8x8);
  133. break;
  134. #endif
  135. case U8X8_MSG_DISPLAY_DRAW_TILE:
  136. u8x8_cad_StartTransfer(u8x8);
  137. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  138. x *= 4;
  139. y = (((u8x8_tile_t *)arg_ptr)->y_pos);
  140. y *= 8;
  141. y += u8x8->x_offset; /* x_offset is used as y offset for the SSD1325 */
  142. u8x8_cad_SendCmd(u8x8, 0x075 ); /* set row address */
  143. u8x8_cad_SendArg(u8x8, y);
  144. u8x8_cad_SendArg(u8x8, y+7);
  145. do
  146. {
  147. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  148. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  149. do
  150. {
  151. if ( ptr[0] | ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5] | ptr[6] | ptr[7] )
  152. {
  153. /* draw the tile if pattern is not zero for all bytes */
  154. u8x8_cad_SendCmd(u8x8, 0x015 ); /* set column address */
  155. u8x8_cad_SendArg(u8x8, x ); /* start */
  156. u8x8_cad_SendArg(u8x8, x+3 ); /* end */
  157. u8x8_cad_SendData(u8x8, 32, u8x8_ssd1325_8to32(u8x8, ptr));
  158. }
  159. else
  160. {
  161. /* tile is empty, use the graphics acceleration command */
  162. u8x8_cad_SendCmd(u8x8, 0x024 ); // draw rectangle
  163. u8x8_cad_SendArg(u8x8, x );
  164. u8x8_cad_SendArg(u8x8, y );
  165. u8x8_cad_SendArg(u8x8, x+3 );
  166. u8x8_cad_SendArg(u8x8, y+7 );
  167. u8x8_cad_SendArg(u8x8, 0 ); // clear
  168. }
  169. ptr += 8;
  170. x += 4;
  171. c--;
  172. } while( c > 0 );
  173. //x += 4;
  174. arg_int--;
  175. } while( arg_int > 0 );
  176. u8x8_cad_SendCmd(u8x8, 0xe3); // no-op needs to be sent after last byte before cs is toggled.
  177. u8x8_cad_EndTransfer(u8x8);
  178. break;
  179. default:
  180. return 0;
  181. }
  182. return 1;
  183. }
  184. /*===================================================================*/
  185. /* http://www.newhavendisplay.com/app_notes/OLED_2_7_12864.txt */
  186. static const uint8_t u8x8_d_ssd1325_128x64_nhd_init_seq[] = {
  187. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  188. U8X8_C(0x0ae), /* display off */
  189. U8X8_CA(0x0b3, 0x091), /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
  190. U8X8_CA(0x0a8, 0x03f), /* multiplex ratio: 0x03f * 1/64 duty */
  191. U8X8_CA(0x0a2, 0x04c), /* display offset, shift mapping ram counter */
  192. U8X8_CA(0x0a1, 0x000), /* display start line */
  193. U8X8_CA(0x0ad, 0x002), /* master configuration: disable embedded DC-DC, enable internal VCOMH */
  194. U8X8_CA(0x0a0, 0x052), /* remap configuration, horizontal address increment (bit 2 = 0), enable nibble remap (upper nibble is left, bit 1 = 1) */
  195. U8X8_C(0x086), /* full current range (0x084, 0x085, 0x086) */
  196. U8X8_C(0x0b8), /* set gray scale table */
  197. U8X8_A(0x001), /* */
  198. U8X8_A(0x011), /* */
  199. U8X8_A(0x022), /* */
  200. U8X8_A(0x032), /* */
  201. U8X8_A(0x043), /* */
  202. U8X8_A(0x054), /* */
  203. U8X8_A(0x065), /* */
  204. U8X8_A(0x076), /* */
  205. U8X8_CA(0x081, 0x070), /* contrast, brightness, 0..128, Newhaven: 0x040 */
  206. U8X8_CA(0x0b2, 0x051), /* frame frequency (row period) */
  207. U8X8_CA(0x0b1, 0x055), /* phase length */
  208. U8X8_CA(0x0bc, 0x010), /* pre-charge voltage level */
  209. U8X8_CA(0x0b4, 0x002), /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  210. U8X8_CA(0x0b0, 0x028), /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  211. U8X8_CA(0x0be, 0x01c), /* VCOMH voltage */
  212. U8X8_CA(0x0bf, 0x002|0x00d), /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  213. U8X8_C(0x0a4), /* normal display mode */
  214. U8X8_CA(0x023, 0x003), /* graphics accelleration: fill pixel */
  215. U8X8_END_TRANSFER(), /* disable chip */
  216. U8X8_END() /* end of sequence */
  217. };
  218. static const u8x8_display_info_t u8x8_nhd_ssd1325_128x64_display_info =
  219. {
  220. /* chip_enable_level = */ 0,
  221. /* chip_disable_level = */ 1,
  222. /* post_chip_enable_wait_ns = */ 20,
  223. /* pre_chip_disable_wait_ns = */ 10,
  224. /* reset_pulse_width_ms = */ 100,
  225. /* post_reset_wait_ms = */ 100, /**/
  226. /* sda_setup_time_ns = */ 100, /* SSD1325 */
  227. /* sck_pulse_width_ns = */ 100, /* SSD1325 */
  228. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  229. /* spi_mode = */ 0, /* active high, rising edge */
  230. /* i2c_bus_clock_100kHz = */ 4,
  231. /* data_setup_time_ns = */ 40,
  232. /* write_pulse_width_ns = */ 60, /* SSD1325 */
  233. /* tile_width = */ 16,
  234. /* tile_height = */ 8,
  235. /* default_x_offset = */ 0, /* x_offset is used as y offset for the SSD1325 */
  236. /* flipmode_x_offset = */ 8, /* x_offset is used as y offset for the SSD1325 */
  237. /* pixel_width = */ 128,
  238. /* pixel_height = */ 64
  239. };
  240. uint8_t u8x8_d_ssd1325_nhd_128x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  241. {
  242. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  243. {
  244. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_nhd_ssd1325_128x64_display_info);
  245. return 1;
  246. }
  247. else if ( msg == U8X8_MSG_DISPLAY_INIT )
  248. {
  249. u8x8_d_helper_display_init(u8x8);
  250. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_init_seq);
  251. return 1;
  252. }
  253. else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  254. {
  255. if ( arg_int == 0 )
  256. {
  257. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_flip0_seq);
  258. u8x8->x_offset = u8x8->display_info->default_x_offset;
  259. }
  260. else
  261. {
  262. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1325_128x64_nhd_flip1_seq);
  263. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  264. }
  265. return 1;
  266. }
  267. return u8x8_d_ssd1325_128x64_generic(u8x8, msg, arg_int, arg_ptr);
  268. }
  269. /*===================================================================*/
  270. /* OSRAM Pictiva 128x64 OLED */
  271. /* https://github.com/olikraus/u8g2/issues/720 */
  272. static const uint8_t u8x8_d_ssd0323_os128064_init_seq[] = {
  273. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  274. U8X8_C(0x0ae), /* display off */
  275. U8X8_CA(0x0b3, 0x091), /* set display clock divide ratio/oscillator frequency (set clock as 135 frames/sec) */
  276. U8X8_CA(0x0a8, 0x03f), /* multiplex ratio: 0x03f * 1/64 duty */
  277. U8X8_CA(0x0a2, 0x040), /* display offset, shift mapping ram counter */
  278. U8X8_CA(0x0a1, 0x000), /* display start line */
  279. U8X8_CA(0x0ad, 0x002), /* master configuration: disable embedded DC-DC, enable internal VCOMH */
  280. U8X8_CA(0x0a0, 0x052), /* remap configuration, horizontal address increment (bit 2 = 0), enable nibble remap (upper nibble is left, bit 1 = 1) */
  281. U8X8_C(0x086), /* full current range (0x084, 0x085, 0x086) */
  282. U8X8_C(0x0b8), /* set gray scale table */
  283. U8X8_A(0x001), /* */
  284. U8X8_A(0x011), /* */
  285. U8X8_A(0x022), /* */
  286. U8X8_A(0x032), /* */
  287. U8X8_A(0x043), /* */
  288. U8X8_A(0x054), /* */
  289. U8X8_A(0x065), /* */
  290. U8X8_A(0x076), /* */
  291. U8X8_CA(0x081, 0x070), /* contrast, brightness, 0..128, Newhaven: 0x040 */
  292. U8X8_CA(0x0b2, 0x051), /* frame frequency (row period) */
  293. U8X8_CA(0x0b1, 0x055), /* phase length */
  294. U8X8_CA(0x0bc, 0x010), /* pre-charge voltage level */
  295. U8X8_CA(0x0b4, 0x002), /* set pre-charge compensation level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  296. U8X8_CA(0x0b0, 0x028), /* enable pre-charge compensation (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  297. U8X8_CA(0x0be, 0x01c), /* VCOMH voltage */
  298. U8X8_CA(0x0bf, 0x002|0x00d), /* VSL voltage level (not documented in the SDD1325 datasheet, but used in the NHD init seq.) */
  299. U8X8_C(0x0a4), /* normal display mode */
  300. U8X8_CA(0x023, 0x003), /* graphics accelleration: fill pixel */
  301. U8X8_END_TRANSFER(), /* disable chip */
  302. U8X8_END() /* end of sequence */
  303. };
  304. static const uint8_t u8x8_d_ssd0323_os128064_flip0_seq[] = {
  305. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  306. U8X8_CA(0x0a0, 0x052), /* remap */
  307. U8X8_CA(0x0a2, 0x040), /* display offset, shift mapping ram counter */
  308. U8X8_END_TRANSFER(), /* disable chip */
  309. U8X8_END() /* end of sequence */
  310. };
  311. static const uint8_t u8x8_d_ssd0323_os128064_flip1_seq[] = {
  312. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  313. U8X8_CA(0x0a0, 0x041), /* remap */
  314. U8X8_CA(0x0a2, 0x050), /* display offset, shift mapping ram counter */
  315. U8X8_END_TRANSFER(), /* disable chip */
  316. U8X8_END() /* end of sequence */
  317. };
  318. static const u8x8_display_info_t u8x8_ssd0323_os128064_display_info =
  319. {
  320. /* chip_enable_level = */ 0,
  321. /* chip_disable_level = */ 1,
  322. /* post_chip_enable_wait_ns = */ 20,
  323. /* pre_chip_disable_wait_ns = */ 10,
  324. /* reset_pulse_width_ms = */ 100,
  325. /* post_reset_wait_ms = */ 100, /**/
  326. /* sda_setup_time_ns = */ 100, /* SSD1325 */
  327. /* sck_pulse_width_ns = */ 100, /* SSD1325 */
  328. /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
  329. /* spi_mode = */ 0, /* active high, rising edge */
  330. /* i2c_bus_clock_100kHz = */ 4,
  331. /* data_setup_time_ns = */ 40,
  332. /* write_pulse_width_ns = */ 60, /* SSD1325 */
  333. /* tile_width = */ 16,
  334. /* tile_height = */ 8,
  335. /* default_x_offset = */ 0, /* x_offset is used as y offset for the SSD1325 */
  336. /* flipmode_x_offset = */ 0, /* x_offset is used as y offset for the SSD1325 */
  337. /* pixel_width = */ 128,
  338. /* pixel_height = */ 64
  339. };
  340. uint8_t u8x8_d_ssd0323_os128064(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  341. {
  342. if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
  343. {
  344. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd0323_os128064_display_info);
  345. return 1;
  346. }
  347. else if ( msg == U8X8_MSG_DISPLAY_INIT )
  348. {
  349. u8x8_d_helper_display_init(u8x8);
  350. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd0323_os128064_init_seq);
  351. return 1;
  352. }
  353. else if ( msg == U8X8_MSG_DISPLAY_SET_FLIP_MODE )
  354. {
  355. if ( arg_int == 0 )
  356. {
  357. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd0323_os128064_flip0_seq);
  358. u8x8->x_offset = u8x8->display_info->default_x_offset;
  359. }
  360. else
  361. {
  362. u8x8_cad_SendSequence(u8x8, u8x8_d_ssd0323_os128064_flip1_seq);
  363. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  364. }
  365. return 1;
  366. }
  367. return u8x8_d_ssd1325_128x64_generic(u8x8, msg, arg_int, arg_ptr);
  368. }