u8x8_d_st7567.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. u8x8_d_st7567.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. */
  27. #include "u8x8.h"
  28. static const uint8_t u8x8_d_st7567_132x64_powersave0_seq[] = {
  29. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  30. U8X8_C(0x0a4), /* all pixel off, issue 142 */
  31. U8X8_C(0x0af), /* display on */
  32. U8X8_END_TRANSFER(), /* disable chip */
  33. U8X8_END() /* end of sequence */
  34. };
  35. static const uint8_t u8x8_d_st7567_132x64_powersave1_seq[] = {
  36. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  37. U8X8_C(0x0ae), /* display off */
  38. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  39. U8X8_END_TRANSFER(), /* disable chip */
  40. U8X8_END() /* end of sequence */
  41. };
  42. static const uint8_t u8x8_d_st7567_132x64_flip0_seq[] = {
  43. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  44. U8X8_C(0x0a1), /* segment remap a0/a1*/
  45. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  46. U8X8_END_TRANSFER(), /* disable chip */
  47. U8X8_END() /* end of sequence */
  48. };
  49. static const uint8_t u8x8_d_st7567_132x64_flip1_seq[] = {
  50. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  51. U8X8_C(0x0a0), /* segment remap a0/a1*/
  52. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  53. U8X8_END_TRANSFER(), /* disable chip */
  54. U8X8_END() /* end of sequence */
  55. };
  56. static const uint8_t u8x8_d_st7567_n_flip0_seq[] = {
  57. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  58. U8X8_C(0x0a0), /* segment remap a0/a1*/
  59. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  60. U8X8_END_TRANSFER(), /* disable chip */
  61. U8X8_END() /* end of sequence */
  62. };
  63. static const uint8_t u8x8_d_st7567_n_flip1_seq[] = {
  64. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  65. U8X8_C(0x0a1), /* segment remap a0/a1*/
  66. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  67. U8X8_END_TRANSFER(), /* disable chip */
  68. U8X8_END() /* end of sequence */
  69. };
  70. /*=====================================================*/
  71. static const u8x8_display_info_t u8x8_st7567_132x64_display_info =
  72. {
  73. /* chip_enable_level = */ 0,
  74. /* chip_disable_level = */ 1,
  75. /* post_chip_enable_wait_ns = */ 150, /* */
  76. /* pre_chip_disable_wait_ns = */ 50, /* */
  77. /* reset_pulse_width_ms = */ 1,
  78. /* post_reset_wait_ms = */ 1,
  79. /* sda_setup_time_ns = */ 50, /* */
  80. /* sck_pulse_width_ns = */ 120, /* */
  81. /* sck_clock_hz = */ 4000000UL, /* */
  82. /* spi_mode = */ 0, /* active high, rising edge */
  83. /* i2c_bus_clock_100kHz = */ 4,
  84. /* data_setup_time_ns = */ 40, /* */
  85. /* write_pulse_width_ns = */ 80, /* */
  86. /* tile_width = */ 17, /* width of 17*8=136 pixel */
  87. /* tile_hight = */ 8,
  88. /* default_x_offset = */ 0,
  89. /* flipmode_x_offset = */ 0,
  90. /* pixel_width = */ 132,
  91. /* pixel_height = */ 64
  92. };
  93. static const uint8_t u8x8_d_st7567_132x64_init_seq[] = {
  94. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  95. U8X8_C(0x0e2), /* soft reset */
  96. U8X8_C(0x0ae), /* display off */
  97. U8X8_C(0x040), /* set display start line to 0 */
  98. U8X8_C(0x0a1), /* ADC set to reverse */
  99. U8X8_C(0x0c0), /* common output mode */
  100. // Flipmode
  101. //U8X8_C(0x0a0), /* ADC set to reverse */
  102. //U8X8_C(0x0c8), /* common output mode */
  103. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  104. U8X8_C(0x0a3), /* LCD bias 1/7 */
  105. /* power on sequence from paxinstruments */
  106. U8X8_C(0x028|4), /* all power control circuits on */
  107. U8X8_DLY(50),
  108. U8X8_C(0x028|6), /* all power control circuits on */
  109. U8X8_DLY(50),
  110. U8X8_C(0x028|7), /* all power control circuits on */
  111. U8X8_DLY(50),
  112. U8X8_C(0x026), /* v0 voltage resistor ratio */
  113. U8X8_CA(0x081, 0x027), /* set contrast, contrast value*/
  114. U8X8_C(0x0ae), /* display off */
  115. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  116. U8X8_END_TRANSFER(), /* disable chip */
  117. U8X8_END() /* end of sequence */
  118. };
  119. /* pax instruments 132x64 display */
  120. uint8_t u8x8_d_st7567_pi_132x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  121. {
  122. uint8_t x, c;
  123. uint8_t *ptr;
  124. switch(msg)
  125. {
  126. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  127. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_132x64_display_info);
  128. break;
  129. case U8X8_MSG_DISPLAY_INIT:
  130. u8x8_d_helper_display_init(u8x8);
  131. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_init_seq);
  132. break;
  133. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  134. if ( arg_int == 0 )
  135. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  136. else
  137. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  138. break;
  139. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  140. if ( arg_int == 0 )
  141. {
  142. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  143. u8x8->x_offset = u8x8->display_info->default_x_offset;
  144. }
  145. else
  146. {
  147. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  148. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  149. }
  150. break;
  151. #ifdef U8X8_WITH_SET_CONTRAST
  152. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  153. u8x8_cad_StartTransfer(u8x8);
  154. u8x8_cad_SendCmd(u8x8, 0x081 );
  155. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  156. u8x8_cad_EndTransfer(u8x8);
  157. break;
  158. #endif
  159. case U8X8_MSG_DISPLAY_DRAW_TILE:
  160. u8x8_cad_StartTransfer(u8x8);
  161. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  162. x *= 8;
  163. x += u8x8->x_offset;
  164. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  165. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  166. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  167. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  168. c *= 8;
  169. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  170. /*
  171. The following if condition checks the hardware limits of the st7567
  172. controller: It is not allowed to write beyond the display limits.
  173. This is in fact an issue within flip mode.
  174. */
  175. if ( c + x > 132u )
  176. {
  177. c = 132u;
  178. c -= x;
  179. }
  180. do
  181. {
  182. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  183. arg_int--;
  184. } while( arg_int > 0 );
  185. u8x8_cad_EndTransfer(u8x8);
  186. break;
  187. default:
  188. return 0;
  189. }
  190. return 1;
  191. }
  192. /*=====================================================*/
  193. static const u8x8_display_info_t u8x8_st7567_jlx12864_display_info =
  194. {
  195. /* chip_enable_level = */ 0,
  196. /* chip_disable_level = */ 1,
  197. /* post_chip_enable_wait_ns = */ 150, /* */
  198. /* pre_chip_disable_wait_ns = */ 50, /* */
  199. /* reset_pulse_width_ms = */ 1,
  200. /* post_reset_wait_ms = */ 1,
  201. /* sda_setup_time_ns = */ 50, /* */
  202. /* sck_pulse_width_ns = */ 120, /* */
  203. /* sck_clock_hz = */ 4000000UL, /* */
  204. /* spi_mode = */ 0, /* active high, rising edge */
  205. /* i2c_bus_clock_100kHz = */ 4,
  206. /* data_setup_time_ns = */ 40, /* */
  207. /* write_pulse_width_ns = */ 80, /* */
  208. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  209. /* tile_hight = */ 8,
  210. /* default_x_offset = */ 4,
  211. /* flipmode_x_offset = */ 0,
  212. /* pixel_width = */ 128,
  213. /* pixel_height = */ 64
  214. };
  215. static const uint8_t u8x8_st7567_jlx12864_init_seq[] = {
  216. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  217. U8X8_C(0x0e2), /* soft reset */
  218. U8X8_C(0x0ae), /* display off */
  219. U8X8_C(0x040), /* set display start line to 0 */
  220. U8X8_C(0x0a1), /* ADC set to reverse */
  221. U8X8_C(0x0c0), /* common output mode */
  222. // Flipmode
  223. //U8X8_C(0x0a0), /* ADC set to reverse */
  224. //U8X8_C(0x0c8), /* common output mode */
  225. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  226. U8X8_C(0x0a3), /* LCD bias 1/7 */
  227. /* power on sequence from paxinstruments */
  228. U8X8_C(0x028|4), /* all power control circuits on */
  229. U8X8_DLY(50),
  230. U8X8_C(0x028|6), /* all power control circuits on */
  231. U8X8_DLY(50),
  232. U8X8_C(0x028|7), /* all power control circuits on */
  233. U8X8_DLY(50),
  234. U8X8_C(0x023), /* v0 voltage resistor ratio */
  235. U8X8_CA(0x081, 42>>2), /* set contrast, contrast value*/
  236. U8X8_C(0x0ae), /* display off */
  237. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  238. U8X8_END_TRANSFER(), /* disable chip */
  239. U8X8_END() /* end of sequence */
  240. };
  241. /* JLX12864 display */
  242. uint8_t u8x8_d_st7567_jlx12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  243. {
  244. uint8_t x, c;
  245. uint8_t *ptr;
  246. switch(msg)
  247. {
  248. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  249. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_jlx12864_display_info);
  250. break;
  251. case U8X8_MSG_DISPLAY_INIT:
  252. u8x8_d_helper_display_init(u8x8);
  253. u8x8_cad_SendSequence(u8x8, u8x8_st7567_jlx12864_init_seq);
  254. break;
  255. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  256. if ( arg_int == 0 )
  257. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  258. else
  259. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  260. break;
  261. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  262. if ( arg_int == 0 )
  263. {
  264. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  265. u8x8->x_offset = u8x8->display_info->default_x_offset;
  266. }
  267. else
  268. {
  269. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  270. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  271. }
  272. break;
  273. #ifdef U8X8_WITH_SET_CONTRAST
  274. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  275. u8x8_cad_StartTransfer(u8x8);
  276. u8x8_cad_SendCmd(u8x8, 0x081 );
  277. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  278. u8x8_cad_EndTransfer(u8x8);
  279. break;
  280. #endif
  281. case U8X8_MSG_DISPLAY_DRAW_TILE:
  282. u8x8_cad_StartTransfer(u8x8);
  283. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  284. x *= 8;
  285. x += u8x8->x_offset;
  286. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  287. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  288. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  289. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  290. c *= 8;
  291. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  292. /*
  293. The following if condition checks the hardware limits of the st7567
  294. controller: It is not allowed to write beyond the display limits.
  295. This is in fact an issue within flip mode.
  296. */
  297. if ( c + x > 132u )
  298. {
  299. c = 132u;
  300. c -= x;
  301. }
  302. do
  303. {
  304. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  305. arg_int--;
  306. } while( arg_int > 0 );
  307. u8x8_cad_EndTransfer(u8x8);
  308. break;
  309. default:
  310. return 0;
  311. }
  312. return 1;
  313. }
  314. /*=====================================================*/
  315. static const u8x8_display_info_t u8x8_st7567_enh_dg128064_display_info =
  316. {
  317. /* chip_enable_level = */ 0,
  318. /* chip_disable_level = */ 1,
  319. /* post_chip_enable_wait_ns = */ 150, /* */
  320. /* pre_chip_disable_wait_ns = */ 50, /* */
  321. /* reset_pulse_width_ms = */ 1,
  322. /* post_reset_wait_ms = */ 1,
  323. /* sda_setup_time_ns = */ 50, /* */
  324. /* sck_pulse_width_ns = */ 120, /* */
  325. /* sck_clock_hz = */ 4000000UL, /* */
  326. /* spi_mode = */ 0, /* active high, rising edge */
  327. /* i2c_bus_clock_100kHz = */ 4,
  328. /* data_setup_time_ns = */ 40, /* */
  329. /* write_pulse_width_ns = */ 80, /* */
  330. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  331. /* tile_hight = */ 8,
  332. /* default_x_offset = */ 0,
  333. /* flipmode_x_offset = */ 4,
  334. /* pixel_width = */ 128,
  335. /* pixel_height = */ 64
  336. };
  337. static const u8x8_display_info_t u8x8_st7567_enh_dg128064i_display_info =
  338. {
  339. /* chip_enable_level = */ 0,
  340. /* chip_disable_level = */ 1,
  341. /* post_chip_enable_wait_ns = */ 150, /* */
  342. /* pre_chip_disable_wait_ns = */ 50, /* */
  343. /* reset_pulse_width_ms = */ 1,
  344. /* post_reset_wait_ms = */ 1,
  345. /* sda_setup_time_ns = */ 50, /* */
  346. /* sck_pulse_width_ns = */ 120, /* */
  347. /* sck_clock_hz = */ 4000000UL, /* */
  348. /* spi_mode = */ 0, /* active high, rising edge */
  349. /* i2c_bus_clock_100kHz = */ 4,
  350. /* data_setup_time_ns = */ 40, /* */
  351. /* write_pulse_width_ns = */ 80, /* */
  352. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  353. /* tile_hight = */ 8,
  354. /* default_x_offset = */ 4,
  355. /* flipmode_x_offset = */ 0,
  356. /* pixel_width = */ 128,
  357. /* pixel_height = */ 64
  358. };
  359. static const uint8_t u8x8_st7567_enh_dg128064_init_seq[] = {
  360. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  361. U8X8_C(0x0e2), /* soft reset */
  362. U8X8_C(0x0ae), /* display off */
  363. U8X8_C(0x040), /* set display start line to 0 */
  364. U8X8_C(0x0a1), /* ADC set to reverse */
  365. U8X8_C(0x0c0), /* common output mode */
  366. // Flipmode
  367. //U8X8_C(0x0a0), /* ADC set to reverse */
  368. //U8X8_C(0x0c8), /* common output mode */
  369. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  370. U8X8_C(0x0a2), /* LCD bias 1/9 */
  371. /* power on sequence from paxinstruments */
  372. U8X8_C(0x028|4), /* all power control circuits on */
  373. U8X8_DLY(50),
  374. U8X8_C(0x028|6), /* all power control circuits on */
  375. U8X8_DLY(50),
  376. U8X8_C(0x028|7), /* all power control circuits on */
  377. U8X8_DLY(50),
  378. U8X8_C(0x023), /* v0 voltage resistor ratio */
  379. U8X8_CA(0x081, 200>>2), /* set contrast, contrast value*/
  380. U8X8_C(0x0ae), /* display off */
  381. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  382. U8X8_END_TRANSFER(), /* disable chip */
  383. U8X8_END() /* end of sequence */
  384. };
  385. /* ENH-DG128064 transparent display */
  386. static uint8_t u8x8_d_st7567_enh_dg128064_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  387. {
  388. uint8_t x, c;
  389. uint8_t *ptr;
  390. switch(msg)
  391. {
  392. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  393. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_enh_dg128064_display_info);
  394. break;
  395. case U8X8_MSG_DISPLAY_INIT:
  396. u8x8_d_helper_display_init(u8x8);
  397. u8x8_cad_SendSequence(u8x8, u8x8_st7567_enh_dg128064_init_seq);
  398. break;
  399. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  400. if ( arg_int == 0 )
  401. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  402. else
  403. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  404. break;
  405. #ifdef U8X8_WITH_SET_CONTRAST
  406. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  407. u8x8_cad_StartTransfer(u8x8);
  408. u8x8_cad_SendCmd(u8x8, 0x081 );
  409. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  410. u8x8_cad_EndTransfer(u8x8);
  411. break;
  412. #endif
  413. case U8X8_MSG_DISPLAY_DRAW_TILE:
  414. u8x8_cad_StartTransfer(u8x8);
  415. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  416. x *= 8;
  417. x += u8x8->x_offset;
  418. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  419. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  420. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  421. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  422. c *= 8;
  423. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  424. /*
  425. The following if condition checks the hardware limits of the st7567
  426. controller: It is not allowed to write beyond the display limits.
  427. This is in fact an issue within flip mode.
  428. */
  429. if ( c + x > 132u )
  430. {
  431. c = 132u;
  432. c -= x;
  433. }
  434. do
  435. {
  436. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  437. arg_int--;
  438. } while( arg_int > 0 );
  439. u8x8_cad_EndTransfer(u8x8);
  440. break;
  441. default:
  442. return 0;
  443. }
  444. return 1;
  445. }
  446. uint8_t u8x8_d_st7567_enh_dg128064(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  447. {
  448. switch(msg)
  449. {
  450. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  451. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_enh_dg128064_display_info);
  452. break;
  453. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  454. if ( arg_int == 0 )
  455. {
  456. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_n_flip0_seq);
  457. u8x8->x_offset = u8x8->display_info->default_x_offset;
  458. }
  459. else
  460. {
  461. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_n_flip1_seq);
  462. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  463. }
  464. break;
  465. default:
  466. return u8x8_d_st7567_enh_dg128064_generic(u8x8, msg, arg_int, arg_ptr);
  467. }
  468. return 1;
  469. }
  470. uint8_t u8x8_d_st7567_enh_dg128064i(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_st7567_enh_dg128064i_display_info);
  476. break;
  477. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  478. if ( arg_int == 0 )
  479. {
  480. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  481. u8x8->x_offset = u8x8->display_info->default_x_offset;
  482. }
  483. else
  484. {
  485. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  486. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  487. }
  488. break;
  489. default:
  490. return u8x8_d_st7567_enh_dg128064_generic(u8x8, msg, arg_int, arg_ptr);
  491. }
  492. return 1;
  493. }
  494. /*=====================================================*/
  495. /* issue 657 */
  496. static const u8x8_display_info_t u8x8_st7567_64x32_display_info =
  497. {
  498. /* chip_enable_level = */ 0,
  499. /* chip_disable_level = */ 1,
  500. /* post_chip_enable_wait_ns = */ 150, /* */
  501. /* pre_chip_disable_wait_ns = */ 50, /* */
  502. /* reset_pulse_width_ms = */ 1,
  503. /* post_reset_wait_ms = */ 1,
  504. /* sda_setup_time_ns = */ 50, /* */
  505. /* sck_pulse_width_ns = */ 120, /* */
  506. /* sck_clock_hz = */ 4000000UL, /* */
  507. /* spi_mode = */ 0, /* active high, rising edge */
  508. /* i2c_bus_clock_100kHz = */ 4,
  509. /* data_setup_time_ns = */ 40, /* */
  510. /* write_pulse_width_ns = */ 80, /* */
  511. /* tile_width = */ 8,
  512. /* tile_hight = */ 4,
  513. /* default_x_offset = */ 32,
  514. /* flipmode_x_offset = */ 32,
  515. /* pixel_width = */ 64,
  516. /* pixel_height = */ 32
  517. };
  518. static const uint8_t u8x8_st7567_64x32_init_seq[] = {
  519. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  520. U8X8_C(0x0e2), /* soft reset */
  521. U8X8_C(0x0ae), /* display off */
  522. U8X8_C(0x040), /* set display start line to 0 */
  523. U8X8_C(0x0a1), /* ADC */
  524. U8X8_C(0x0c0), /* common output mode */
  525. // Flipmode
  526. //U8X8_C(0x0a0), /* ADC */
  527. //U8X8_C(0x0c8), /* common output mode */
  528. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  529. U8X8_C(0x0a2), /* LCD bias 1/9 */
  530. U8X8_C(0x028|4), /* all power control circuits on */
  531. U8X8_DLY(50),
  532. U8X8_C(0x028|6), /* all power control circuits on */
  533. U8X8_DLY(50),
  534. U8X8_C(0x028|7), /* all power control circuits on */
  535. U8X8_DLY(50),
  536. U8X8_C(0x024), /* v0 voltage resistor ratio, taken from issue 657 */
  537. U8X8_CA(0x081, 0x020), /* set contrast, contrast value*/
  538. /* 18 Apr 2020: the value 0x080 does not make sense, only 6 bit are supported
  539. for contrast, changed to 0x040 */
  540. U8X8_C(0x0ae), /* display off */
  541. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  542. U8X8_END_TRANSFER(), /* disable chip */
  543. U8X8_END() /* end of sequence */
  544. };
  545. uint8_t u8x8_d_st7567_64x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  546. {
  547. uint8_t x, c;
  548. uint8_t *ptr;
  549. switch(msg)
  550. {
  551. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  552. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_64x32_display_info);
  553. break;
  554. case U8X8_MSG_DISPLAY_INIT:
  555. u8x8_d_helper_display_init(u8x8);
  556. u8x8_cad_SendSequence(u8x8, u8x8_st7567_64x32_init_seq);
  557. break;
  558. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  559. if ( arg_int == 0 )
  560. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  561. else
  562. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  563. break;
  564. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  565. if ( arg_int == 0 )
  566. {
  567. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  568. u8x8->x_offset = u8x8->display_info->default_x_offset;
  569. }
  570. else
  571. {
  572. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  573. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  574. }
  575. break;
  576. #ifdef U8X8_WITH_SET_CONTRAST
  577. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  578. u8x8_cad_StartTransfer(u8x8);
  579. u8x8_cad_SendCmd(u8x8, 0x081 );
  580. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  581. u8x8_cad_EndTransfer(u8x8);
  582. break;
  583. #endif
  584. case U8X8_MSG_DISPLAY_DRAW_TILE:
  585. u8x8_cad_StartTransfer(u8x8);
  586. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  587. x *= 8;
  588. x += u8x8->x_offset;
  589. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  590. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  591. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  592. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  593. c *= 8;
  594. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  595. /*
  596. The following if condition checks the hardware limits of the st7567
  597. controller: It is not allowed to write beyond the display limits.
  598. This is in fact an issue within flip mode.
  599. */
  600. if ( c + x > 132u )
  601. {
  602. c = 132u;
  603. c -= x;
  604. }
  605. do
  606. {
  607. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  608. arg_int--;
  609. } while( arg_int > 0 );
  610. u8x8_cad_EndTransfer(u8x8);
  611. break;
  612. default:
  613. return 0;
  614. }
  615. return 1;
  616. }
  617. /*=====================================================*/
  618. /* issue 1159, Lummax HEM6432-03 */
  619. static const u8x8_display_info_t u8x8_st7567_hem6432_display_info =
  620. {
  621. /* chip_enable_level = */ 0,
  622. /* chip_disable_level = */ 1,
  623. /* post_chip_enable_wait_ns = */ 150, /* */
  624. /* pre_chip_disable_wait_ns = */ 50, /* */
  625. /* reset_pulse_width_ms = */ 1,
  626. /* post_reset_wait_ms = */ 1,
  627. /* sda_setup_time_ns = */ 50, /* */
  628. /* sck_pulse_width_ns = */ 120, /* */
  629. /* sck_clock_hz = */ 4000000UL, /* */
  630. /* spi_mode = */ 0, /* active high, rising edge */
  631. /* i2c_bus_clock_100kHz = */ 4,
  632. /* data_setup_time_ns = */ 40, /* */
  633. /* write_pulse_width_ns = */ 80, /* */
  634. /* tile_width = */ 8,
  635. /* tile_hight = */ 4,
  636. /* default_x_offset = */ 36, /* issue 1159 */
  637. /* flipmode_x_offset = */ 32, /* issue 1159 */
  638. /* pixel_width = */ 64,
  639. /* pixel_height = */ 32
  640. };
  641. static const uint8_t u8x8_st7567_hem6432_init_seq[] = {
  642. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  643. U8X8_C(0x0e2), /* soft reset */
  644. U8X8_C(0x0ae), /* display off */
  645. U8X8_C(0x040), /* set display start line to 0 */
  646. U8X8_C(0x0a1), /* ADC */
  647. U8X8_C(0x0c0), /* common output mode */
  648. // Flipmode
  649. //U8X8_C(0x0a0), /* ADC */
  650. //U8X8_C(0x0c8), /* common output mode */
  651. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  652. U8X8_C(0x0a2), /* LCD bias 1/9 */
  653. U8X8_C(0x028|4), /* all power control circuits on */
  654. U8X8_DLY(50),
  655. U8X8_C(0x028|6), /* all power control circuits on */
  656. U8X8_DLY(50),
  657. U8X8_C(0x028|7), /* all power control circuits on */
  658. U8X8_DLY(50),
  659. U8X8_C(0x024), /* v0 voltage resistor ratio, taken from issue 657 */
  660. U8X8_CA(0x081, 225/4), /* set contrast, contrast value as suggested inissue 1159 */
  661. U8X8_C(0x0ae), /* display off */
  662. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  663. U8X8_END_TRANSFER(), /* disable chip */
  664. U8X8_END() /* end of sequence */
  665. };
  666. uint8_t u8x8_d_st7567_hem6432(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  667. {
  668. uint8_t x, c;
  669. uint8_t *ptr;
  670. switch(msg)
  671. {
  672. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  673. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_hem6432_display_info);
  674. u8x8->i2c_address = 0x07e; /* issue 1159, use different i2c address */
  675. break;
  676. case U8X8_MSG_DISPLAY_INIT:
  677. u8x8_d_helper_display_init(u8x8);
  678. u8x8_cad_SendSequence(u8x8, u8x8_st7567_hem6432_init_seq);
  679. break;
  680. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  681. if ( arg_int == 0 )
  682. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  683. else
  684. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  685. break;
  686. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  687. if ( arg_int == 0 )
  688. {
  689. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  690. u8x8->x_offset = u8x8->display_info->default_x_offset;
  691. }
  692. else
  693. {
  694. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  695. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  696. }
  697. break;
  698. #ifdef U8X8_WITH_SET_CONTRAST
  699. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  700. u8x8_cad_StartTransfer(u8x8);
  701. u8x8_cad_SendCmd(u8x8, 0x081 );
  702. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  703. u8x8_cad_EndTransfer(u8x8);
  704. break;
  705. #endif
  706. case U8X8_MSG_DISPLAY_DRAW_TILE:
  707. u8x8_cad_StartTransfer(u8x8);
  708. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  709. x *= 8;
  710. x += u8x8->x_offset;
  711. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  712. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  713. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  714. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  715. c *= 8;
  716. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  717. /*
  718. The following if condition checks the hardware limits of the st7567
  719. controller: It is not allowed to write beyond the display limits.
  720. This is in fact an issue within flip mode.
  721. */
  722. if ( c + x > 132u )
  723. {
  724. c = 132u;
  725. c -= x;
  726. }
  727. do
  728. {
  729. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  730. arg_int--;
  731. } while( arg_int > 0 );
  732. u8x8_cad_EndTransfer(u8x8);
  733. break;
  734. default:
  735. return 0;
  736. }
  737. return 1;
  738. }
  739. /*=====================================================*/
  740. /*
  741. https://github.com/olikraus/u8g2/issues/1088
  742. https://www.dx.com/p/opensmart-33v-26-inch-128x64-serial-spi-monochrome-lcd-breakout-board-module-with-backlight-for-arduino-nano-pro-mini-2710499.html
  743. */
  744. static const u8x8_display_info_t u8x8_st7567_os12864_display_info =
  745. {
  746. /* chip_enable_level = */ 0,
  747. /* chip_disable_level = */ 1,
  748. /* post_chip_enable_wait_ns = */ 150, /* */
  749. /* pre_chip_disable_wait_ns = */ 50, /* */
  750. /* reset_pulse_width_ms = */ 1,
  751. /* post_reset_wait_ms = */ 1,
  752. /* sda_setup_time_ns = */ 50, /* */
  753. /* sck_pulse_width_ns = */ 120, /* */
  754. /* sck_clock_hz = */ 4000000UL, /* */
  755. /* spi_mode = */ 0, /* active high, rising edge */
  756. /* i2c_bus_clock_100kHz = */ 4,
  757. /* data_setup_time_ns = */ 40, /* */
  758. /* write_pulse_width_ns = */ 80, /* */
  759. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  760. /* tile_hight = */ 8,
  761. /* default_x_offset = */ 4,
  762. /* flipmode_x_offset = */ 0,
  763. /* pixel_width = */ 128,
  764. /* pixel_height = */ 64
  765. };
  766. static const uint8_t u8x8_st7567_os12864_init_seq[] = {
  767. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  768. U8X8_C(0x0e2), /* soft reset */
  769. U8X8_C(0x0ae), /* display off */
  770. U8X8_C(0x040), /* set display start line to 0 */
  771. U8X8_C(0x0a1), /* ADC set to reverse */
  772. U8X8_C(0x0c0), /* common output mode */
  773. // Flipmode
  774. //U8X8_C(0x0a0), /* ADC set to reverse */
  775. //U8X8_C(0x0c8), /* common output mode */
  776. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  777. U8X8_C(0x0a3), /* LCD bias 1/7 */
  778. /* power on sequence from paxinstruments */
  779. U8X8_C(0x028|4), /* all power control circuits on */
  780. U8X8_DLY(50),
  781. U8X8_C(0x028|6), /* all power control circuits on */
  782. U8X8_DLY(50),
  783. U8X8_C(0x028|7), /* all power control circuits on */
  784. U8X8_DLY(50),
  785. U8X8_C(0x026), /* v0 voltage resistor ratio */
  786. U8X8_CA(0x081, 50>>2), /* set contrast, contrast value*/
  787. U8X8_C(0x0ae), /* display off */
  788. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  789. U8X8_END_TRANSFER(), /* disable chip */
  790. U8X8_END() /* end of sequence */
  791. };
  792. /* open-smart 12864 display */
  793. uint8_t u8x8_d_st7567_os12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  794. {
  795. uint8_t x, c;
  796. uint8_t *ptr;
  797. switch(msg)
  798. {
  799. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  800. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_os12864_display_info);
  801. break;
  802. case U8X8_MSG_DISPLAY_INIT:
  803. u8x8_d_helper_display_init(u8x8);
  804. u8x8_cad_SendSequence(u8x8, u8x8_st7567_os12864_init_seq);
  805. break;
  806. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  807. if ( arg_int == 0 )
  808. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  809. else
  810. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  811. break;
  812. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  813. if ( arg_int == 0 )
  814. {
  815. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  816. u8x8->x_offset = u8x8->display_info->default_x_offset;
  817. }
  818. else
  819. {
  820. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  821. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  822. }
  823. break;
  824. #ifdef U8X8_WITH_SET_CONTRAST
  825. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  826. u8x8_cad_StartTransfer(u8x8);
  827. u8x8_cad_SendCmd(u8x8, 0x081 );
  828. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  829. u8x8_cad_EndTransfer(u8x8);
  830. break;
  831. #endif
  832. case U8X8_MSG_DISPLAY_DRAW_TILE:
  833. u8x8_cad_StartTransfer(u8x8);
  834. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  835. x *= 8;
  836. x += u8x8->x_offset;
  837. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  838. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  839. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  840. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  841. c *= 8;
  842. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  843. /*
  844. The following if condition checks the hardware limits of the st7567
  845. controller: It is not allowed to write beyond the display limits.
  846. This is in fact an issue within flip mode.
  847. */
  848. if ( c + x > 132u )
  849. {
  850. c = 132u;
  851. c -= x;
  852. }
  853. do
  854. {
  855. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  856. arg_int--;
  857. } while( arg_int > 0 );
  858. u8x8_cad_EndTransfer(u8x8);
  859. break;
  860. default:
  861. return 0;
  862. }
  863. return 1;
  864. }