u8x8_d_st7567.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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. ST7567: 65x132 controller
  27. */
  28. #include "u8x8.h"
  29. static const uint8_t u8x8_d_st7567_132x64_powersave0_seq[] = {
  30. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  31. U8X8_C(0x0a4), /* all pixel off, issue 142 */
  32. U8X8_C(0x0af), /* display on */
  33. U8X8_END_TRANSFER(), /* disable chip */
  34. U8X8_END() /* end of sequence */
  35. };
  36. static const uint8_t u8x8_d_st7567_132x64_powersave1_seq[] = {
  37. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  38. U8X8_C(0x0ae), /* display off */
  39. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  40. U8X8_END_TRANSFER(), /* disable chip */
  41. U8X8_END() /* end of sequence */
  42. };
  43. static const uint8_t u8x8_d_st7567_132x64_flip0_seq[] = {
  44. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  45. U8X8_C(0x0a1), /* segment remap a0/a1*/
  46. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  47. U8X8_END_TRANSFER(), /* disable chip */
  48. U8X8_END() /* end of sequence */
  49. };
  50. static const uint8_t u8x8_d_st7567_132x64_flip1_seq[] = {
  51. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  52. U8X8_C(0x0a0), /* segment remap a0/a1*/
  53. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  54. U8X8_END_TRANSFER(), /* disable chip */
  55. U8X8_END() /* end of sequence */
  56. };
  57. #define u8x8_d_st7567_128x64_powersave0_seq u8x8_d_st7567_132x64_powersave0_seq
  58. #define u8x8_d_st7567_128x64_powersave1_seq u8x8_d_st7567_132x64_powersave1_seq
  59. #define u8x8_d_st7567_128x64_flip0_seq u8x8_d_st7567_132x64_flip0_seq
  60. #define u8x8_d_st7567_128x64_flip1_seq u8x8_d_st7567_132x64_flip1_seq
  61. static const uint8_t u8x8_d_st7567_n_flip0_seq[] = {
  62. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  63. U8X8_C(0x0a0), /* segment remap a0/a1*/
  64. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  65. U8X8_END_TRANSFER(), /* disable chip */
  66. U8X8_END() /* end of sequence */
  67. };
  68. static const uint8_t u8x8_d_st7567_n_flip1_seq[] = {
  69. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  70. U8X8_C(0x0a1), /* segment remap a0/a1*/
  71. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  72. U8X8_END_TRANSFER(), /* disable chip */
  73. U8X8_END() /* end of sequence */
  74. };
  75. /*=====================================================*/
  76. static const u8x8_display_info_t u8x8_st7567_132x64_display_info =
  77. {
  78. /* chip_enable_level = */ 0,
  79. /* chip_disable_level = */ 1,
  80. /* post_chip_enable_wait_ns = */ 150, /* */
  81. /* pre_chip_disable_wait_ns = */ 50, /* */
  82. /* reset_pulse_width_ms = */ 1,
  83. /* post_reset_wait_ms = */ 1,
  84. /* sda_setup_time_ns = */ 50, /* */
  85. /* sck_pulse_width_ns = */ 120, /* */
  86. /* sck_clock_hz = */ 4000000UL, /* */
  87. /* spi_mode = */ 0, /* active high, rising edge */
  88. /* i2c_bus_clock_100kHz = */ 4,
  89. /* data_setup_time_ns = */ 40, /* */
  90. /* write_pulse_width_ns = */ 80, /* */
  91. /* tile_width = */ 17, /* width of 17*8=136 pixel */
  92. /* tile_height = */ 8,
  93. /* default_x_offset = */ 0,
  94. /* flipmode_x_offset = */ 0,
  95. /* pixel_width = */ 132,
  96. /* pixel_height = */ 64
  97. };
  98. static const uint8_t u8x8_d_st7567_132x64_init_seq[] = {
  99. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  100. U8X8_C(0x0e2), /* soft reset */
  101. U8X8_C(0x0ae), /* display off */
  102. U8X8_C(0x040), /* set display start line to 0 */
  103. U8X8_C(0x0a1), /* ADC set to reverse */
  104. U8X8_C(0x0c0), /* common output mode */
  105. // Flipmode
  106. //U8X8_C(0x0a0), /* ADC set to reverse */
  107. //U8X8_C(0x0c8), /* common output mode */
  108. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  109. U8X8_C(0x0a3), /* LCD bias 1/7 */
  110. /* power on sequence from paxinstruments */
  111. U8X8_C(0x028|4), /* all power control circuits on */
  112. U8X8_DLY(50),
  113. U8X8_C(0x028|6), /* all power control circuits on */
  114. U8X8_DLY(50),
  115. U8X8_C(0x028|7), /* all power control circuits on */
  116. U8X8_DLY(50),
  117. U8X8_C(0x026), /* v0 voltage resistor ratio */
  118. /* 2025/9/3 刘斌:增加升压步骤 */
  119. U8X8_CA(0x082, 0x2f), /* set contrast bias */
  120. U8X8_CA(0x0f8, 0x00), /* set boost step */
  121. /* 2025/9/3 刘斌:增加升压步骤 */
  122. U8X8_CA(0x081, 0x027), /* set contrast, contrast value*/
  123. U8X8_C(0x0ae), /* display off */
  124. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  125. U8X8_END_TRANSFER(), /* disable chip */
  126. U8X8_END() /* end of sequence */
  127. };
  128. /* pax instruments 132x64 display */
  129. uint8_t u8x8_d_st7567_pi_132x64(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  130. {
  131. uint8_t x, c;
  132. uint8_t *ptr;
  133. switch(msg)
  134. {
  135. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  136. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_132x64_display_info);
  137. break;
  138. case U8X8_MSG_DISPLAY_INIT:
  139. u8x8_d_helper_display_init(u8x8);
  140. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_init_seq);
  141. break;
  142. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  143. if ( arg_int == 0 )
  144. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  145. else
  146. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  147. break;
  148. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  149. if ( arg_int == 0 )
  150. {
  151. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  152. u8x8->x_offset = u8x8->display_info->default_x_offset;
  153. }
  154. else
  155. {
  156. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  157. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  158. }
  159. break;
  160. #ifdef U8X8_WITH_SET_CONTRAST
  161. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  162. u8x8_cad_StartTransfer(u8x8);
  163. u8x8_cad_SendCmd(u8x8, 0x081 );
  164. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  165. u8x8_cad_EndTransfer(u8x8);
  166. break;
  167. #endif
  168. case U8X8_MSG_DISPLAY_DRAW_TILE:
  169. u8x8_cad_StartTransfer(u8x8);
  170. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  171. x *= 8;
  172. x += u8x8->x_offset;
  173. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  174. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  175. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  176. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  177. c *= 8;
  178. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  179. /*
  180. The following if condition checks the hardware limits of the st7567
  181. controller: It is not allowed to write beyond the display limits.
  182. This is in fact an issue within flip mode.
  183. */
  184. if ( c + x > 132u )
  185. {
  186. c = 132u;
  187. c -= x;
  188. }
  189. do
  190. {
  191. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  192. arg_int--;
  193. } while( arg_int > 0 );
  194. u8x8_cad_EndTransfer(u8x8);
  195. break;
  196. default:
  197. return 0;
  198. }
  199. return 1;
  200. }
  201. /*=====================================================*/
  202. static const u8x8_display_info_t u8x8_st7567_jlx12864_display_info =
  203. {
  204. /* chip_enable_level = */ 0,
  205. /* chip_disable_level = */ 1,
  206. /* post_chip_enable_wait_ns = */ 150, /* */
  207. /* pre_chip_disable_wait_ns = */ 50, /* */
  208. /* reset_pulse_width_ms = */ 1,
  209. /* post_reset_wait_ms = */ 1,
  210. /* sda_setup_time_ns = */ 50, /* */
  211. /* sck_pulse_width_ns = */ 120, /* */
  212. /* sck_clock_hz = */ 4000000UL, /* */
  213. /* spi_mode = */ 0, /* active high, rising edge */
  214. /* i2c_bus_clock_100kHz = */ 4,
  215. /* data_setup_time_ns = */ 40, /* */
  216. /* write_pulse_width_ns = */ 80, /* */
  217. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  218. /* tile_height = */ 8,
  219. /* default_x_offset = */ 4,
  220. /* flipmode_x_offset = */ 0,
  221. /* pixel_width = */ 128,
  222. /* pixel_height = */ 64
  223. };
  224. static const uint8_t u8x8_st7567_jlx12864_init_seq[] = {
  225. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  226. U8X8_C(0x0e2), /* soft reset */
  227. U8X8_C(0x0ae), /* display off */
  228. U8X8_C(0x040), /* set display start line to 0 */
  229. U8X8_C(0x0a1), /* ADC set to reverse */
  230. U8X8_C(0x0c0), /* common output mode */
  231. // Flipmode
  232. //U8X8_C(0x0a0), /* ADC set to reverse */
  233. //U8X8_C(0x0c8), /* common output mode */
  234. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  235. U8X8_C(0x0a3), /* LCD bias 1/7 */
  236. /* power on sequence from paxinstruments */
  237. U8X8_C(0x028|4), /* all power control circuits on */
  238. U8X8_DLY(50),
  239. U8X8_C(0x028|6), /* all power control circuits on */
  240. U8X8_DLY(50),
  241. U8X8_C(0x028|7), /* all power control circuits on */
  242. U8X8_DLY(50),
  243. U8X8_C(0x023), /* v0 voltage resistor ratio */
  244. /* 2025/9/3 刘斌:增加升压步骤和提高对比度 */
  245. U8X8_CA(0x082, 0x2f), /* set contrast bias */
  246. U8X8_CA(0x0f8, 0x00), /* set boost step */
  247. U8X8_CA(0x081, 30), /* set contrast, contrast value*/
  248. /* 2025/9/3 刘斌:增加升压步骤和提高对比度 */
  249. U8X8_C(0x0ae), /* display off */
  250. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  251. U8X8_END_TRANSFER(), /* disable chip */
  252. U8X8_END() /* end of sequence */
  253. };
  254. /* JLX12864 display */
  255. uint8_t u8x8_d_st7567_jlx12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  256. {
  257. uint8_t x, c;
  258. uint8_t *ptr;
  259. switch(msg)
  260. {
  261. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  262. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_jlx12864_display_info);
  263. break;
  264. case U8X8_MSG_DISPLAY_INIT:
  265. u8x8_d_helper_display_init(u8x8);
  266. u8x8_cad_SendSequence(u8x8, u8x8_st7567_jlx12864_init_seq);
  267. break;
  268. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  269. if ( arg_int == 0 )
  270. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  271. else
  272. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  273. break;
  274. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  275. if ( arg_int == 0 )
  276. {
  277. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  278. u8x8->x_offset = u8x8->display_info->default_x_offset;
  279. }
  280. else
  281. {
  282. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  283. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  284. }
  285. break;
  286. #ifdef U8X8_WITH_SET_CONTRAST
  287. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  288. u8x8_cad_StartTransfer(u8x8);
  289. u8x8_cad_SendCmd(u8x8, 0x081 );
  290. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  291. u8x8_cad_EndTransfer(u8x8);
  292. break;
  293. #endif
  294. case U8X8_MSG_DISPLAY_DRAW_TILE:
  295. u8x8_cad_StartTransfer(u8x8);
  296. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  297. x *= 8;
  298. x += u8x8->x_offset;
  299. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  300. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  301. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  302. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  303. c *= 8;
  304. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  305. /*
  306. The following if condition checks the hardware limits of the st7567
  307. controller: It is not allowed to write beyond the display limits.
  308. This is in fact an issue within flip mode.
  309. */
  310. if ( c + x > 132u )
  311. {
  312. c = 132u;
  313. c -= x;
  314. }
  315. do
  316. {
  317. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  318. arg_int--;
  319. } while( arg_int > 0 );
  320. u8x8_cad_EndTransfer(u8x8);
  321. break;
  322. default:
  323. return 0;
  324. }
  325. return 1;
  326. }
  327. /*=====================================================*/
  328. /* Sinda Display (sindadisplay.com), SDGG 2232-07 */
  329. /* Issue 1759, 122x32 display, https://github.com/olikraus/u8g2/files/7894362/SDGG12232-07.pdf */
  330. /* copied from jlx12864 */
  331. static const uint8_t u8x8_d_st7567_122x32_flip0_seq[] = {
  332. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  333. U8X8_C(0x040+32), /* set display start line to 32 */
  334. U8X8_C(0x0a1), /* segment remap a0/a1*/
  335. U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
  336. U8X8_END_TRANSFER(), /* disable chip */
  337. U8X8_END() /* end of sequence */
  338. };
  339. static const uint8_t u8x8_d_st7567_122x32_flip1_seq[] = {
  340. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  341. U8X8_C(0x040+0), /* set display start line to 0 */
  342. U8X8_C(0x0a0), /* segment remap a0/a1*/
  343. U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
  344. U8X8_END_TRANSFER(), /* disable chip */
  345. U8X8_END() /* end of sequence */
  346. };
  347. static const u8x8_display_info_t u8x8_st7567_122x32_display_info =
  348. {
  349. /* chip_enable_level = */ 0,
  350. /* chip_disable_level = */ 1,
  351. /* post_chip_enable_wait_ns = */ 150, /* */
  352. /* pre_chip_disable_wait_ns = */ 50, /* */
  353. /* reset_pulse_width_ms = */ 1,
  354. /* post_reset_wait_ms = */ 1,
  355. /* sda_setup_time_ns = */ 50, /* */
  356. /* sck_pulse_width_ns = */ 120, /* */
  357. /* sck_clock_hz = */ 4000000UL, /* */
  358. /* spi_mode = */ 0, /* active high, rising edge */
  359. /* i2c_bus_clock_100kHz = */ 4,
  360. /* data_setup_time_ns = */ 40, /* */
  361. /* write_pulse_width_ns = */ 80, /* */
  362. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  363. /* tile_height = */ 4,
  364. /* default_x_offset = */ 4,
  365. /* flipmode_x_offset = */ 0,
  366. /* pixel_width = */ 122,
  367. /* pixel_height = */ 32
  368. };
  369. static const uint8_t u8x8_st7567_122x32_init_seq[] = {
  370. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  371. U8X8_C(0x0e2), /* soft reset */
  372. U8X8_C(0x0ae), /* display off */
  373. U8X8_C(0x040+32), /* set display start line to 32 */
  374. U8X8_C(0x0a1), /* ADC set to reverse */
  375. U8X8_C(0x0c0), /* common output mode */
  376. // Flipmode
  377. //U8X8_C(0x0a0), /* ADC set to reverse */
  378. //U8X8_C(0x0c8), /* common output mode */
  379. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  380. /* I think datasheet of the 122x32 display suggest to use 0x0a2 instead of 0xa3 here */
  381. U8X8_C(0x0a2), /* LCD bias 1/6 @1/33 duty */
  382. /* power on sequence from paxinstruments */
  383. U8X8_C(0x028|4), /* all power control circuits on */
  384. U8X8_DLY(50),
  385. U8X8_C(0x028|6), /* all power control circuits on */
  386. U8X8_DLY(50),
  387. U8X8_C(0x028|7), /* all power control circuits on */
  388. U8X8_DLY(50),
  389. U8X8_C(0x023), /* v0 voltage resistor ratio */
  390. U8X8_CA(0x081, 42>>2), /* set contrast, contrast value*/
  391. U8X8_C(0x0ae), /* display off */
  392. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  393. U8X8_END_TRANSFER(), /* disable chip */
  394. U8X8_END() /* end of sequence */
  395. };
  396. /* 122x32 display, issue 1759 */
  397. uint8_t u8x8_d_st7567_122x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  398. {
  399. uint8_t x, c;
  400. uint8_t *ptr;
  401. switch(msg)
  402. {
  403. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  404. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_122x32_display_info);
  405. break;
  406. case U8X8_MSG_DISPLAY_INIT:
  407. u8x8_d_helper_display_init(u8x8);
  408. u8x8_cad_SendSequence(u8x8, u8x8_st7567_122x32_init_seq);
  409. break;
  410. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  411. if ( arg_int == 0 )
  412. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  413. else
  414. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  415. break;
  416. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  417. if ( arg_int == 0 )
  418. {
  419. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_122x32_flip0_seq);
  420. u8x8->x_offset = u8x8->display_info->default_x_offset;
  421. }
  422. else
  423. {
  424. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_122x32_flip1_seq);
  425. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  426. }
  427. break;
  428. #ifdef U8X8_WITH_SET_CONTRAST
  429. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  430. u8x8_cad_StartTransfer(u8x8);
  431. u8x8_cad_SendCmd(u8x8, 0x081 );
  432. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  433. u8x8_cad_EndTransfer(u8x8);
  434. break;
  435. #endif
  436. case U8X8_MSG_DISPLAY_DRAW_TILE:
  437. u8x8_cad_StartTransfer(u8x8);
  438. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  439. x *= 8;
  440. x += u8x8->x_offset;
  441. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  442. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  443. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  444. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  445. c *= 8;
  446. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  447. /*
  448. The following if condition checks the hardware limits of the st7567
  449. controller: It is not allowed to write beyond the display limits.
  450. This is in fact an issue within flip mode.
  451. */
  452. if ( c + x > 132u )
  453. {
  454. c = 132u;
  455. c -= x;
  456. }
  457. do
  458. {
  459. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  460. arg_int--;
  461. } while( arg_int > 0 );
  462. u8x8_cad_EndTransfer(u8x8);
  463. break;
  464. default:
  465. return 0;
  466. }
  467. return 1;
  468. }
  469. /*=====================================================*/
  470. static const u8x8_display_info_t u8x8_st7567_enh_dg128064_display_info =
  471. {
  472. /* chip_enable_level = */ 0,
  473. /* chip_disable_level = */ 1,
  474. /* post_chip_enable_wait_ns = */ 150, /* */
  475. /* pre_chip_disable_wait_ns = */ 50, /* */
  476. /* reset_pulse_width_ms = */ 1,
  477. /* post_reset_wait_ms = */ 1,
  478. /* sda_setup_time_ns = */ 50, /* */
  479. /* sck_pulse_width_ns = */ 120, /* */
  480. /* sck_clock_hz = */ 4000000UL, /* */
  481. /* spi_mode = */ 0, /* active high, rising edge */
  482. /* i2c_bus_clock_100kHz = */ 4,
  483. /* data_setup_time_ns = */ 40, /* */
  484. /* write_pulse_width_ns = */ 80, /* */
  485. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  486. /* tile_height = */ 8,
  487. /* default_x_offset = */ 0,
  488. /* flipmode_x_offset = */ 4,
  489. /* pixel_width = */ 128,
  490. /* pixel_height = */ 64
  491. };
  492. static const u8x8_display_info_t u8x8_st7567_enh_dg128064i_display_info =
  493. {
  494. /* chip_enable_level = */ 0,
  495. /* chip_disable_level = */ 1,
  496. /* post_chip_enable_wait_ns = */ 150, /* */
  497. /* pre_chip_disable_wait_ns = */ 50, /* */
  498. /* reset_pulse_width_ms = */ 1,
  499. /* post_reset_wait_ms = */ 1,
  500. /* sda_setup_time_ns = */ 50, /* */
  501. /* sck_pulse_width_ns = */ 120, /* */
  502. /* sck_clock_hz = */ 4000000UL, /* */
  503. /* spi_mode = */ 0, /* active high, rising edge */
  504. /* i2c_bus_clock_100kHz = */ 4,
  505. /* data_setup_time_ns = */ 40, /* */
  506. /* write_pulse_width_ns = */ 80, /* */
  507. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  508. /* tile_height = */ 8,
  509. /* default_x_offset = */ 4,
  510. /* flipmode_x_offset = */ 0,
  511. /* pixel_width = */ 128,
  512. /* pixel_height = */ 64
  513. };
  514. static const uint8_t u8x8_st7567_enh_dg128064_init_seq[] = {
  515. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  516. U8X8_C(0x0e2), /* soft reset */
  517. U8X8_C(0x0ae), /* display off */
  518. U8X8_C(0x040), /* set display start line to 0 */
  519. U8X8_C(0x0a1), /* ADC set to reverse */
  520. U8X8_C(0x0c0), /* common output mode */
  521. // Flipmode
  522. //U8X8_C(0x0a0), /* ADC set to reverse */
  523. //U8X8_C(0x0c8), /* common output mode */
  524. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  525. U8X8_C(0x0a2), /* LCD bias 1/9 */
  526. /* power on sequence from paxinstruments */
  527. U8X8_C(0x028|4), /* all power control circuits on */
  528. U8X8_DLY(50),
  529. U8X8_C(0x028|6), /* all power control circuits on */
  530. U8X8_DLY(50),
  531. U8X8_C(0x028|7), /* all power control circuits on */
  532. U8X8_DLY(50),
  533. U8X8_C(0x023), /* v0 voltage resistor ratio */
  534. /* 2025/9/3 刘斌:增加升压步骤和提高对比度 */
  535. U8X8_CA(0x082, 0x2f), /* set contrast bias */
  536. U8X8_CA(0x0f8, 0x00), /* set boost step */
  537. U8X8_CA(0x081, 30), /* set contrast, contrast value*/
  538. /* 2025/9/3 刘斌:增加升压步骤和提高对比度 */
  539. U8X8_C(0x0ae), /* display off */
  540. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  541. U8X8_END_TRANSFER(), /* disable chip */
  542. U8X8_END() /* end of sequence */
  543. };
  544. /* ENH-DG128064 transparent display */
  545. static uint8_t u8x8_d_st7567_enh_dg128064_generic(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_enh_dg128064_display_info);
  553. break;
  554. case U8X8_MSG_DISPLAY_INIT:
  555. u8x8_d_helper_display_init(u8x8);
  556. u8x8_cad_SendSequence(u8x8, u8x8_st7567_enh_dg128064_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. #ifdef U8X8_WITH_SET_CONTRAST
  565. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  566. u8x8_cad_StartTransfer(u8x8);
  567. u8x8_cad_SendCmd(u8x8, 0x081 );
  568. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  569. u8x8_cad_EndTransfer(u8x8);
  570. break;
  571. #endif
  572. case U8X8_MSG_DISPLAY_DRAW_TILE:
  573. u8x8_cad_StartTransfer(u8x8);
  574. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  575. x *= 8;
  576. x += u8x8->x_offset;
  577. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  578. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  579. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  580. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  581. c *= 8;
  582. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  583. /*
  584. The following if condition checks the hardware limits of the st7567
  585. controller: It is not allowed to write beyond the display limits.
  586. This is in fact an issue within flip mode.
  587. */
  588. if ( c + x > 132u )
  589. {
  590. c = 132u;
  591. c -= x;
  592. }
  593. do
  594. {
  595. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  596. arg_int--;
  597. } while( arg_int > 0 );
  598. u8x8_cad_EndTransfer(u8x8);
  599. break;
  600. default:
  601. return 0;
  602. }
  603. return 1;
  604. }
  605. uint8_t u8x8_d_st7567_enh_dg128064(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  606. {
  607. switch(msg)
  608. {
  609. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  610. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_enh_dg128064_display_info);
  611. break;
  612. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  613. if ( arg_int == 0 )
  614. {
  615. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_n_flip0_seq);
  616. u8x8->x_offset = u8x8->display_info->default_x_offset;
  617. }
  618. else
  619. {
  620. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_n_flip1_seq);
  621. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  622. }
  623. break;
  624. default:
  625. return u8x8_d_st7567_enh_dg128064_generic(u8x8, msg, arg_int, arg_ptr);
  626. }
  627. return 1;
  628. }
  629. uint8_t u8x8_d_st7567_enh_dg128064i(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  630. {
  631. switch(msg)
  632. {
  633. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  634. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_enh_dg128064i_display_info);
  635. break;
  636. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  637. if ( arg_int == 0 )
  638. {
  639. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  640. u8x8->x_offset = u8x8->display_info->default_x_offset;
  641. }
  642. else
  643. {
  644. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  645. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  646. }
  647. break;
  648. default:
  649. return u8x8_d_st7567_enh_dg128064_generic(u8x8, msg, arg_int, arg_ptr);
  650. }
  651. return 1;
  652. }
  653. /*=====================================================*/
  654. /* issue 657 */
  655. static const u8x8_display_info_t u8x8_st7567_64x32_display_info =
  656. {
  657. /* chip_enable_level = */ 0,
  658. /* chip_disable_level = */ 1,
  659. /* post_chip_enable_wait_ns = */ 150, /* */
  660. /* pre_chip_disable_wait_ns = */ 50, /* */
  661. /* reset_pulse_width_ms = */ 1,
  662. /* post_reset_wait_ms = */ 1,
  663. /* sda_setup_time_ns = */ 50, /* */
  664. /* sck_pulse_width_ns = */ 120, /* */
  665. /* sck_clock_hz = */ 4000000UL, /* */
  666. /* spi_mode = */ 0, /* active high, rising edge */
  667. /* i2c_bus_clock_100kHz = */ 4,
  668. /* data_setup_time_ns = */ 40, /* */
  669. /* write_pulse_width_ns = */ 80, /* */
  670. /* tile_width = */ 8,
  671. /* tile_height = */ 4,
  672. /* default_x_offset = */ 32,
  673. /* flipmode_x_offset = */ 32,
  674. /* pixel_width = */ 64,
  675. /* pixel_height = */ 32
  676. };
  677. static const uint8_t u8x8_st7567_64x32_init_seq[] = {
  678. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  679. U8X8_C(0x0e2), /* soft reset */
  680. U8X8_C(0x0ae), /* display off */
  681. U8X8_C(0x040), /* set display start line to 0 */
  682. U8X8_C(0x0a1), /* ADC */
  683. U8X8_C(0x0c0), /* common output mode */
  684. // Flipmode
  685. //U8X8_C(0x0a0), /* ADC */
  686. //U8X8_C(0x0c8), /* common output mode */
  687. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  688. U8X8_C(0x0a2), /* LCD bias 1/9 */
  689. U8X8_C(0x028|4), /* all power control circuits on */
  690. U8X8_DLY(50),
  691. U8X8_C(0x028|6), /* all power control circuits on */
  692. U8X8_DLY(50),
  693. U8X8_C(0x028|7), /* all power control circuits on */
  694. U8X8_DLY(50),
  695. U8X8_C(0x024), /* v0 voltage resistor ratio, taken from issue 657 */
  696. U8X8_CA(0x081, 0x020), /* set contrast, contrast value*/
  697. /* 18 Apr 2020: the value 0x080 does not make sense, only 6 bit are supported
  698. for contrast, changed to 0x040 */
  699. U8X8_C(0x0ae), /* display off */
  700. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  701. U8X8_END_TRANSFER(), /* disable chip */
  702. U8X8_END() /* end of sequence */
  703. };
  704. uint8_t u8x8_d_st7567_64x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  705. {
  706. uint8_t x, c;
  707. uint8_t *ptr;
  708. switch(msg)
  709. {
  710. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  711. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_64x32_display_info);
  712. break;
  713. case U8X8_MSG_DISPLAY_INIT:
  714. u8x8_d_helper_display_init(u8x8);
  715. u8x8_cad_SendSequence(u8x8, u8x8_st7567_64x32_init_seq);
  716. break;
  717. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  718. if ( arg_int == 0 )
  719. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  720. else
  721. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  722. break;
  723. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  724. if ( arg_int == 0 )
  725. {
  726. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  727. u8x8->x_offset = u8x8->display_info->default_x_offset;
  728. }
  729. else
  730. {
  731. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  732. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  733. }
  734. break;
  735. #ifdef U8X8_WITH_SET_CONTRAST
  736. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  737. u8x8_cad_StartTransfer(u8x8);
  738. u8x8_cad_SendCmd(u8x8, 0x081 );
  739. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  740. u8x8_cad_EndTransfer(u8x8);
  741. break;
  742. #endif
  743. case U8X8_MSG_DISPLAY_DRAW_TILE:
  744. u8x8_cad_StartTransfer(u8x8);
  745. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  746. x *= 8;
  747. x += u8x8->x_offset;
  748. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  749. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  750. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  751. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  752. c *= 8;
  753. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  754. /*
  755. The following if condition checks the hardware limits of the st7567
  756. controller: It is not allowed to write beyond the display limits.
  757. This is in fact an issue within flip mode.
  758. */
  759. if ( c + x > 132u )
  760. {
  761. c = 132u;
  762. c -= x;
  763. }
  764. do
  765. {
  766. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  767. arg_int--;
  768. } while( arg_int > 0 );
  769. u8x8_cad_EndTransfer(u8x8);
  770. break;
  771. default:
  772. return 0;
  773. }
  774. return 1;
  775. }
  776. /*=====================================================*/
  777. /* issue 1159, Lummax HEM6432-03 */
  778. static const u8x8_display_info_t u8x8_st7567_hem6432_display_info =
  779. {
  780. /* chip_enable_level = */ 0,
  781. /* chip_disable_level = */ 1,
  782. /* post_chip_enable_wait_ns = */ 150, /* */
  783. /* pre_chip_disable_wait_ns = */ 50, /* */
  784. /* reset_pulse_width_ms = */ 1,
  785. /* post_reset_wait_ms = */ 1,
  786. /* sda_setup_time_ns = */ 50, /* */
  787. /* sck_pulse_width_ns = */ 120, /* */
  788. /* sck_clock_hz = */ 4000000UL, /* */
  789. /* spi_mode = */ 0, /* active high, rising edge */
  790. /* i2c_bus_clock_100kHz = */ 4,
  791. /* data_setup_time_ns = */ 40, /* */
  792. /* write_pulse_width_ns = */ 80, /* */
  793. /* tile_width = */ 8,
  794. /* tile_height = */ 4,
  795. /* default_x_offset = */ 36, /* issue 1159 */
  796. /* flipmode_x_offset = */ 32, /* issue 1159 */
  797. /* pixel_width = */ 64,
  798. /* pixel_height = */ 32
  799. };
  800. static const uint8_t u8x8_st7567_hem6432_init_seq[] = {
  801. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  802. U8X8_C(0x0e2), /* soft reset */
  803. U8X8_C(0x0ae), /* display off */
  804. U8X8_C(0x040), /* set display start line to 0 */
  805. U8X8_C(0x0a1), /* ADC */
  806. U8X8_C(0x0c0), /* common output mode */
  807. // Flipmode
  808. //U8X8_C(0x0a0), /* ADC */
  809. //U8X8_C(0x0c8), /* common output mode */
  810. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  811. U8X8_C(0x0a2), /* LCD bias 1/9 */
  812. U8X8_C(0x028|4), /* all power control circuits on */
  813. U8X8_DLY(50),
  814. U8X8_C(0x028|6), /* all power control circuits on */
  815. U8X8_DLY(50),
  816. U8X8_C(0x028|7), /* all power control circuits on */
  817. U8X8_DLY(50),
  818. U8X8_C(0x024), /* v0 voltage resistor ratio, taken from issue 657 */
  819. U8X8_CA(0x081, 225/4), /* set contrast, contrast value as suggested inissue 1159 */
  820. U8X8_C(0x0ae), /* display off */
  821. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  822. U8X8_END_TRANSFER(), /* disable chip */
  823. U8X8_END() /* end of sequence */
  824. };
  825. uint8_t u8x8_d_st7567_hem6432(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  826. {
  827. uint8_t x, c;
  828. uint8_t *ptr;
  829. switch(msg)
  830. {
  831. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  832. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_hem6432_display_info);
  833. u8x8->i2c_address = 0x07e; /* issue 1159, use different i2c address */
  834. break;
  835. case U8X8_MSG_DISPLAY_INIT:
  836. u8x8_d_helper_display_init(u8x8);
  837. u8x8_cad_SendSequence(u8x8, u8x8_st7567_hem6432_init_seq);
  838. break;
  839. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  840. if ( arg_int == 0 )
  841. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  842. else
  843. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  844. break;
  845. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  846. if ( arg_int == 0 )
  847. {
  848. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  849. u8x8->x_offset = u8x8->display_info->default_x_offset;
  850. }
  851. else
  852. {
  853. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  854. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  855. }
  856. break;
  857. #ifdef U8X8_WITH_SET_CONTRAST
  858. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  859. u8x8_cad_StartTransfer(u8x8);
  860. u8x8_cad_SendCmd(u8x8, 0x081 );
  861. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  862. u8x8_cad_EndTransfer(u8x8);
  863. break;
  864. #endif
  865. case U8X8_MSG_DISPLAY_DRAW_TILE:
  866. u8x8_cad_StartTransfer(u8x8);
  867. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  868. x *= 8;
  869. x += u8x8->x_offset;
  870. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  871. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  872. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  873. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  874. c *= 8;
  875. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  876. /*
  877. The following if condition checks the hardware limits of the st7567
  878. controller: It is not allowed to write beyond the display limits.
  879. This is in fact an issue within flip mode.
  880. */
  881. if ( c + x > 132u )
  882. {
  883. c = 132u;
  884. c -= x;
  885. }
  886. do
  887. {
  888. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  889. arg_int--;
  890. } while( arg_int > 0 );
  891. u8x8_cad_EndTransfer(u8x8);
  892. break;
  893. default:
  894. return 0;
  895. }
  896. return 1;
  897. }
  898. /*=====================================================*/
  899. /*
  900. https://github.com/olikraus/u8g2/issues/1088
  901. 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
  902. */
  903. static const u8x8_display_info_t u8x8_st7567_os12864_display_info =
  904. {
  905. /* chip_enable_level = */ 0,
  906. /* chip_disable_level = */ 1,
  907. /* post_chip_enable_wait_ns = */ 150, /* */
  908. /* pre_chip_disable_wait_ns = */ 50, /* */
  909. /* reset_pulse_width_ms = */ 1,
  910. /* post_reset_wait_ms = */ 1,
  911. /* sda_setup_time_ns = */ 50, /* */
  912. /* sck_pulse_width_ns = */ 120, /* */
  913. /* sck_clock_hz = */ 4000000UL, /* */
  914. /* spi_mode = */ 0, /* active high, rising edge */
  915. /* i2c_bus_clock_100kHz = */ 4,
  916. /* data_setup_time_ns = */ 40, /* */
  917. /* write_pulse_width_ns = */ 80, /* */
  918. /* tile_width = */ 16, /* width of 16*8=128 pixel */
  919. /* tile_height = */ 8,
  920. /* default_x_offset = */ 4,
  921. /* flipmode_x_offset = */ 0,
  922. /* pixel_width = */ 128,
  923. /* pixel_height = */ 64
  924. };
  925. static const uint8_t u8x8_st7567_os12864_init_seq[] = {
  926. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  927. U8X8_C(0x0e2), /* soft reset */
  928. U8X8_C(0x0ae), /* display off */
  929. U8X8_C(0x040), /* set display start line to 0 */
  930. U8X8_C(0x0a1), /* ADC set to reverse */
  931. U8X8_C(0x0c0), /* common output mode */
  932. // Flipmode
  933. //U8X8_C(0x0a0), /* ADC set to reverse */
  934. //U8X8_C(0x0c8), /* common output mode */
  935. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  936. U8X8_C(0x0a3), /* LCD bias 1/7 */
  937. /* power on sequence from paxinstruments */
  938. U8X8_C(0x028|4), /* all power control circuits on */
  939. U8X8_DLY(50),
  940. U8X8_C(0x028|6), /* all power control circuits on */
  941. U8X8_DLY(50),
  942. U8X8_C(0x028|7), /* all power control circuits on */
  943. U8X8_DLY(50),
  944. U8X8_C(0x026), /* v0 voltage resistor ratio */
  945. /* 2025/9/3 刘斌:提高对比度 */
  946. U8X8_CA(0x081, 30), /* set contrast, contrast value*/
  947. /* 2025/9/3 刘斌:提高对比度 */
  948. U8X8_C(0x0ae), /* display off */
  949. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  950. U8X8_END_TRANSFER(), /* disable chip */
  951. U8X8_END() /* end of sequence */
  952. };
  953. /* open-smart 12864 display */
  954. uint8_t u8x8_d_st7567_os12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  955. {
  956. uint8_t x, c;
  957. uint8_t *ptr;
  958. switch(msg)
  959. {
  960. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  961. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_os12864_display_info);
  962. break;
  963. case U8X8_MSG_DISPLAY_INIT:
  964. u8x8_d_helper_display_init(u8x8);
  965. u8x8_cad_SendSequence(u8x8, u8x8_st7567_os12864_init_seq);
  966. break;
  967. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  968. if ( arg_int == 0 )
  969. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  970. else
  971. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  972. break;
  973. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  974. if ( arg_int == 0 )
  975. {
  976. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  977. u8x8->x_offset = u8x8->display_info->default_x_offset;
  978. }
  979. else
  980. {
  981. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  982. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  983. }
  984. break;
  985. #ifdef U8X8_WITH_SET_CONTRAST
  986. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  987. u8x8_cad_StartTransfer(u8x8);
  988. u8x8_cad_SendCmd(u8x8, 0x081 );
  989. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  990. u8x8_cad_EndTransfer(u8x8);
  991. break;
  992. #endif
  993. case U8X8_MSG_DISPLAY_DRAW_TILE:
  994. u8x8_cad_StartTransfer(u8x8);
  995. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  996. x *= 8;
  997. x += u8x8->x_offset;
  998. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  999. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  1000. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  1001. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1002. c *= 8;
  1003. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1004. /*
  1005. The following if condition checks the hardware limits of the st7567
  1006. controller: It is not allowed to write beyond the display limits.
  1007. This is in fact an issue within flip mode.
  1008. */
  1009. if ( c + x > 132u )
  1010. {
  1011. c = 132u;
  1012. c -= x;
  1013. }
  1014. do
  1015. {
  1016. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1017. arg_int--;
  1018. } while( arg_int > 0 );
  1019. u8x8_cad_EndTransfer(u8x8);
  1020. break;
  1021. default:
  1022. return 0;
  1023. }
  1024. return 1;
  1025. }
  1026. /*=====================================================*/
  1027. /*
  1028. https://github.com/olikraus/u8g2/discussions/1868
  1029. https://github.com/olikraus/u8g2/issues/1869
  1030. https://www.buydisplay.com/cog-serial-spi-132x32-graphic-lcd-display-no-backlight-st7567a
  1031. ERC13232
  1032. copied from U8G2_ST7567_PI_132X64
  1033. */
  1034. static const u8x8_display_info_t u8x8_st7567_132x32_display_info =
  1035. {
  1036. /* chip_enable_level = */ 0,
  1037. /* chip_disable_level = */ 1,
  1038. /* post_chip_enable_wait_ns = */ 150, /* */
  1039. /* pre_chip_disable_wait_ns = */ 50, /* */
  1040. /* reset_pulse_width_ms = */ 1,
  1041. /* post_reset_wait_ms = */ 1,
  1042. /* sda_setup_time_ns = */ 50, /* */
  1043. /* sck_pulse_width_ns = */ 120, /* */
  1044. /* sck_clock_hz = */ 4000000UL, /* */
  1045. /* spi_mode = */ 0, /* active high, rising edge */
  1046. /* i2c_bus_clock_100kHz = */ 4,
  1047. /* data_setup_time_ns = */ 40, /* */
  1048. /* write_pulse_width_ns = */ 80, /* */
  1049. /* tile_width = */ 17, /* width of 17*8=136 pixel */
  1050. /* tile_height = */ 4,
  1051. /* default_x_offset = */ 0,
  1052. /* flipmode_x_offset = */ 0,
  1053. /* pixel_width = */ 132,
  1054. /* pixel_height = */ 32
  1055. };
  1056. static const uint8_t u8x8_d_st7567_erc13232_init_seq[] = {
  1057. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  1058. U8X8_C(0x0e2), /* soft reset */
  1059. U8X8_C(0x0ae), /* display off */
  1060. U8X8_C(0x040), /* set display start line to 0 */
  1061. U8X8_C(0x0a1), /* ADC set to reverse */
  1062. U8X8_C(0x0c0), /* common output mode */
  1063. // Flipmode
  1064. //U8X8_C(0x0a0), /* ADC set to reverse */
  1065. //U8X8_C(0x0c8), /* common output mode */
  1066. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  1067. U8X8_C(0x0a3), /* LCD bias 1/7 */
  1068. /* power on sequence from paxinstruments */
  1069. U8X8_C(0x028|4), /* all power control circuits on */
  1070. U8X8_DLY(50),
  1071. U8X8_C(0x028|6), /* all power control circuits on */
  1072. U8X8_DLY(50),
  1073. U8X8_C(0x028|7), /* all power control circuits on */
  1074. U8X8_DLY(50),
  1075. U8X8_C(0x026), /* v0 voltage resistor ratio */
  1076. U8X8_CA(0x081, 0x027), /* set contrast, contrast value*/
  1077. U8X8_C(0x0ae), /* display off */
  1078. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  1079. U8X8_END_TRANSFER(), /* disable chip */
  1080. U8X8_END() /* end of sequence */
  1081. };
  1082. /* ERC13232 */
  1083. uint8_t u8x8_d_st7567_erc13232(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1084. {
  1085. uint8_t x, c;
  1086. uint8_t *ptr;
  1087. switch(msg)
  1088. {
  1089. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  1090. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_132x32_display_info);
  1091. break;
  1092. case U8X8_MSG_DISPLAY_INIT:
  1093. u8x8_d_helper_display_init(u8x8);
  1094. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_erc13232_init_seq);
  1095. break;
  1096. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  1097. if ( arg_int == 0 )
  1098. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  1099. else
  1100. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  1101. break;
  1102. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  1103. if ( arg_int == 0 )
  1104. {
  1105. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  1106. u8x8->x_offset = u8x8->display_info->default_x_offset;
  1107. }
  1108. else
  1109. {
  1110. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  1111. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  1112. }
  1113. break;
  1114. #ifdef U8X8_WITH_SET_CONTRAST
  1115. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  1116. u8x8_cad_StartTransfer(u8x8);
  1117. u8x8_cad_SendCmd(u8x8, 0x081 );
  1118. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  1119. u8x8_cad_EndTransfer(u8x8);
  1120. break;
  1121. #endif
  1122. case U8X8_MSG_DISPLAY_DRAW_TILE:
  1123. u8x8_cad_StartTransfer(u8x8);
  1124. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  1125. x *= 8;
  1126. x += u8x8->x_offset;
  1127. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  1128. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  1129. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  1130. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1131. c *= 8;
  1132. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1133. /*
  1134. The following if condition checks the hardware limits of the st7567
  1135. controller: It is not allowed to write beyond the display limits.
  1136. This is in fact an issue within flip mode.
  1137. */
  1138. if ( c + x > 132u )
  1139. {
  1140. c = 132u;
  1141. c -= x;
  1142. }
  1143. do
  1144. {
  1145. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1146. arg_int--;
  1147. } while( arg_int > 0 );
  1148. u8x8_cad_EndTransfer(u8x8);
  1149. break;
  1150. default:
  1151. return 0;
  1152. }
  1153. return 1;
  1154. }
  1155. /*=====================================================*/
  1156. /*
  1157. https://www.buydisplay.com/2-inch-low-cost-white-128x64-graphic-cog-lcd-display-st7567-spi
  1158. ERC12864FSF-20
  1159. copied from u8x8_st7567_132x32
  1160. */
  1161. static const u8x8_display_info_t u8x8_st7567_128x64_display_info =
  1162. {
  1163. /* chip_enable_level = */ 0,
  1164. /* chip_disable_level = */ 1,
  1165. /* post_chip_enable_wait_ns = */ 150,
  1166. /* pre_chip_disable_wait_ns = */ 50,
  1167. /* reset_pulse_width_ms = */ 1,
  1168. /* post_reset_wait_ms = */ 1,
  1169. /* sda_setup_time_ns = */ 50,
  1170. /* sck_pulse_width_ns = */ 120,
  1171. /* sck_clock_hz = */ 4000000UL,
  1172. /* spi_mode = */ 0, /* active high, rising edge */
  1173. /* i2c_bus_clock_100kHz = */ 4,
  1174. /* data_setup_time_ns = */ 40,
  1175. /* write_pulse_width_ns = */ 80,
  1176. /* tile_width = */ 16, /* width of 16*8=128 pixels */
  1177. /* tile_height = */ 8, /* height of 8*8= 64 pixels */
  1178. /* default_x_offset = */ 4,
  1179. /* flipmode_x_offset = */ 0,
  1180. /* pixel_width = */ 128,
  1181. /* pixel_height = */ 64
  1182. };
  1183. static const uint8_t u8x8_d_st7567_erc12864_init_seq[] = {
  1184. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  1185. U8X8_C(0x0e2), /* soft reset */
  1186. U8X8_C(0x0ae), /* display off */
  1187. U8X8_C(0x040), /* set display start line to 0 */
  1188. U8X8_C(0x0a1), /* ADC set to reverse */
  1189. U8X8_C(0x0c0), /* common output mode */
  1190. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  1191. U8X8_C(0x0a3), /* LCD bias 1/7 */
  1192. /* power on sequence from paxinstruments */
  1193. U8X8_C(0x028|4), /* all power control circuits on */
  1194. U8X8_DLY(50),
  1195. U8X8_C(0x028|6), /* all power control circuits on */
  1196. U8X8_DLY(50),
  1197. U8X8_C(0x028|7), /* all power control circuits on */
  1198. U8X8_DLY(50),
  1199. U8X8_C(0x026), /* v0 voltage resistor ratio */
  1200. U8X8_CA(0x081, 0x027), /* set contrast, contrast value*/
  1201. U8X8_C(0x0ae), /* display off */
  1202. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  1203. U8X8_END_TRANSFER(), /* disable chip */
  1204. U8X8_END() /* end of sequence */
  1205. };
  1206. /* ERC12864 */
  1207. uint8_t u8x8_d_st7567_erc12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1208. {
  1209. uint8_t x, c;
  1210. uint8_t *ptr;
  1211. switch(msg)
  1212. {
  1213. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  1214. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_128x64_display_info);
  1215. break;
  1216. case U8X8_MSG_DISPLAY_INIT:
  1217. u8x8_d_helper_display_init(u8x8);
  1218. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_erc12864_init_seq);
  1219. break;
  1220. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  1221. if ( arg_int == 0 )
  1222. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_128x64_powersave0_seq);
  1223. else
  1224. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_128x64_powersave1_seq);
  1225. break;
  1226. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  1227. if ( arg_int == 0 )
  1228. {
  1229. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_128x64_flip0_seq);
  1230. u8x8->x_offset = u8x8->display_info->default_x_offset;
  1231. }
  1232. else
  1233. {
  1234. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_128x64_flip1_seq);
  1235. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  1236. }
  1237. break;
  1238. #ifdef U8X8_WITH_SET_CONTRAST
  1239. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  1240. u8x8_cad_StartTransfer(u8x8);
  1241. u8x8_cad_SendCmd(u8x8, 0x081 );
  1242. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  1243. u8x8_cad_EndTransfer(u8x8);
  1244. break;
  1245. #endif
  1246. case U8X8_MSG_DISPLAY_DRAW_TILE:
  1247. u8x8_cad_StartTransfer(u8x8);
  1248. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  1249. x *= 8;
  1250. x += u8x8->x_offset;
  1251. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  1252. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  1253. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  1254. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1255. c *= 8;
  1256. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1257. /*
  1258. The following if condition checks the hardware limits of the st7567
  1259. controller: It is not allowed to write beyond the display limits.
  1260. This is in fact an issue within flip mode.
  1261. */
  1262. if ( c + x > 132u )
  1263. {
  1264. c = 132u;
  1265. c -= x;
  1266. }
  1267. do
  1268. {
  1269. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1270. arg_int--;
  1271. } while( arg_int > 0 );
  1272. u8x8_cad_EndTransfer(u8x8);
  1273. break;
  1274. default:
  1275. return 0;
  1276. }
  1277. return 1;
  1278. }
  1279. /*=====================================================*/
  1280. /* LW12864 display, 128x32 (actually 142x36, but with border of weird behavior) */
  1281. /* copied from jlx12864 */
  1282. static const u8x8_display_info_t u8x8_st7567_lw12832_display_info =
  1283. {
  1284. /* chip_enable_level = */ 0,
  1285. /* chip_disable_level = */ 1,
  1286. /* post_chip_enable_wait_ns = */ 150, /* */
  1287. /* pre_chip_disable_wait_ns = */ 50, /* */
  1288. /* reset_pulse_width_ms = */ 1,
  1289. /* post_reset_wait_ms = */ 1,
  1290. /* sda_setup_time_ns = */ 50, /* */
  1291. /* sck_pulse_width_ns = */ 120, /* */
  1292. /* sck_clock_hz = */ 4000000UL, /* */
  1293. /* spi_mode = */ 0, /* active high, rising edge */
  1294. /* i2c_bus_clock_100kHz = */ 4,
  1295. /* data_setup_time_ns = */ 40, /* */
  1296. /* write_pulse_width_ns = */ 80, /* */
  1297. /* tile_width = */ 17, /* rounded up to 17 tiles */
  1298. /* tile_height = */ 9, /* also rounded */
  1299. /* default_x_offset = */ 4,
  1300. /* flipmode_x_offset = */ 0,
  1301. /* pixel_width = */ 128,
  1302. /* pixel_height = */ 32
  1303. };
  1304. static const uint8_t u8x8_st7567_lw12832_init_seq[] = {
  1305. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  1306. U8X8_C(0x0e2), /* soft reset */
  1307. U8X8_C(0x0ae), /* display off */
  1308. U8X8_C(0x040), /* set display start line to 0 */
  1309. U8X8_C(0x0a1), /* ADC set to reverse */
  1310. U8X8_C(0x0c0), /* common output mode */
  1311. // Flipmode
  1312. //U8X8_C(0x0a0), /* ADC set to reverse */
  1313. //U8X8_C(0x0c8), /* common output mode */
  1314. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  1315. U8X8_C(0x0a3), /* LCD bias 1/7 */
  1316. /* power on sequence from paxinstruments */
  1317. U8X8_C(0x028|4), /* all power control circuits on */
  1318. U8X8_DLY(50),
  1319. U8X8_C(0x028|6), /* all power control circuits on */
  1320. U8X8_DLY(50),
  1321. U8X8_C(0x028|7), /* all power control circuits on */
  1322. U8X8_DLY(50),
  1323. U8X8_C(0x023), /* v0 voltage resistor ratio */
  1324. /* 2025/9/3 刘斌:提高对比度 */
  1325. U8X8_CA(0x081, 30), /* set contrast, contrast value*/
  1326. /* 2025/9/3 刘斌:提高对比度 */
  1327. U8X8_C(0x0ae), /* display off */
  1328. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  1329. U8X8_END_TRANSFER(), /* disable chip */
  1330. U8X8_END() /* end of sequence */
  1331. };
  1332. static void st7567_lw12832_clear_ddram(u8x8_t *u8x8)
  1333. {
  1334. // A combination of
  1335. // - void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
  1336. // and
  1337. // - uint8_t u8x8_d_st7567_jlx12864(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1338. uint8_t buf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  1339. uint8_t h = u8x8->display_info->tile_height;
  1340. u8x8_tile_t tile;
  1341. tile.x_pos = 0;
  1342. tile.y_pos = 0;
  1343. tile.cnt = 1;
  1344. tile.tile_ptr = buf;
  1345. do
  1346. {
  1347. // Args
  1348. uint8_t arg_int = u8x8->display_info->tile_width;
  1349. void *arg_ptr = (void *)&tile;
  1350. // ---------------- START OF u8x8_d_st7567_jlx12864 case U8X8_MSG_DISPLAY_DRAW_TILE ----------------
  1351. uint8_t x, c;
  1352. uint8_t *ptr;
  1353. u8x8_cad_StartTransfer(u8x8);
  1354. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  1355. x *= 8;
  1356. /* x += u8x8->x_offset; */ // Note that this is removed intentionally
  1357. u8x8_cad_SendCmd(u8x8, 0x010 | (x >> 4)); // Set Column Address (MSB)
  1358. u8x8_cad_SendCmd(u8x8, 0x000 | ((x & 15))); // Set Column Address (LSB)
  1359. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); // Set Page Address
  1360. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1361. c *= 8;
  1362. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1363. /*
  1364. The following if condition checks the hardware limits of the st7567
  1365. controller: It is not allowed to write beyond the display limits.
  1366. This is in fact an issue within flip mode.
  1367. */
  1368. if (c + x > 132u)
  1369. {
  1370. c = 132u;
  1371. c -= x;
  1372. }
  1373. do
  1374. {
  1375. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1376. arg_int--;
  1377. } while (arg_int > 0);
  1378. u8x8_cad_EndTransfer(u8x8);
  1379. // ---------------- END OF u8x8_d_st7567_jlx12864 case U8X8_MSG_DISPLAY_DRAW_TILE ----------------
  1380. tile.y_pos++;
  1381. } while (tile.y_pos < h);
  1382. }
  1383. /* LW12832 display */
  1384. uint8_t u8x8_d_st7567_lw12832(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1385. {
  1386. uint8_t x, c;
  1387. uint8_t *ptr;
  1388. switch(msg)
  1389. {
  1390. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  1391. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_lw12832_display_info);
  1392. break;
  1393. case U8X8_MSG_DISPLAY_INIT:
  1394. u8x8_d_helper_display_init(u8x8);
  1395. u8x8_cad_SendSequence(u8x8, u8x8_st7567_lw12832_init_seq);
  1396. st7567_lw12832_clear_ddram(u8x8);
  1397. break;
  1398. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  1399. if ( arg_int == 0 )
  1400. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  1401. else
  1402. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  1403. break;
  1404. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  1405. if ( arg_int == 0 )
  1406. {
  1407. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  1408. u8x8->x_offset = u8x8->display_info->default_x_offset;
  1409. }
  1410. else
  1411. {
  1412. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  1413. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  1414. }
  1415. break;
  1416. #ifdef U8X8_WITH_SET_CONTRAST
  1417. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  1418. u8x8_cad_StartTransfer(u8x8);
  1419. u8x8_cad_SendCmd(u8x8, 0x081 );
  1420. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  1421. u8x8_cad_EndTransfer(u8x8);
  1422. break;
  1423. #endif
  1424. case U8X8_MSG_DISPLAY_DRAW_TILE:
  1425. u8x8_cad_StartTransfer(u8x8);
  1426. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  1427. x *= 8;
  1428. x += u8x8->x_offset;
  1429. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  1430. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  1431. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  1432. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1433. c *= 8;
  1434. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1435. /*
  1436. The following if condition checks the hardware limits of the st7567
  1437. controller: It is not allowed to write beyond the display limits.
  1438. This is in fact an issue within flip mode.
  1439. */
  1440. if ( c + x > 132u )
  1441. {
  1442. c = 132u;
  1443. c -= x;
  1444. }
  1445. do
  1446. {
  1447. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1448. arg_int--;
  1449. } while( arg_int > 0 );
  1450. u8x8_cad_EndTransfer(u8x8);
  1451. break;
  1452. default:
  1453. return 0;
  1454. }
  1455. return 1;
  1456. }
  1457. /* https://github.com/olikraus/u8g2/issues/2344 */
  1458. uint8_t u8x8_d_st7567_yxd12832(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1459. {
  1460. return u8x8_d_st7567_lw12832(u8x8, msg, arg_int, arg_ptr);
  1461. }
  1462. /*=====================================================*/
  1463. /*
  1464. 96x65
  1465. https://github.com/olikraus/u8g2/issues/2332
  1466. */
  1467. static const u8x8_display_info_t u8x8_st7567_96x65_display_info =
  1468. {
  1469. /* chip_enable_level = */ 0,
  1470. /* chip_disable_level = */ 1,
  1471. /* post_chip_enable_wait_ns = */ 150, /* */
  1472. /* pre_chip_disable_wait_ns = */ 50, /* */
  1473. /* reset_pulse_width_ms = */ 1,
  1474. /* post_reset_wait_ms = */ 1,
  1475. /* sda_setup_time_ns = */ 50, /* */
  1476. /* sck_pulse_width_ns = */ 120, /* */
  1477. /* sck_clock_hz = */ 4000000UL, /* */
  1478. /* spi_mode = */ 0, /* active high, rising edge */
  1479. /* i2c_bus_clock_100kHz = */ 4,
  1480. /* data_setup_time_ns = */ 40, /* */
  1481. /* write_pulse_width_ns = */ 80, /* */
  1482. /* tile_width = */ 12, /* width of 12*8=96 pixel */
  1483. /* tile_height = */ 9,
  1484. /* default_x_offset = */ 0,
  1485. /* flipmode_x_offset = */ 0,
  1486. /* pixel_width = */ 96,
  1487. /* pixel_height = */ 65
  1488. };
  1489. static const uint8_t u8x8_st7567_96x65_init_seq[] = {
  1490. U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
  1491. U8X8_C(0x0e2), /* soft reset */
  1492. U8X8_C(0x0ae), /* display off */
  1493. U8X8_C(0x040), /* set display start line to 0 */
  1494. U8X8_C(0x0a1), /* ADC set to reverse */
  1495. U8X8_C(0x0c0), /* common output mode */
  1496. // Flipmode
  1497. //U8X8_C(0x0a0), /* ADC set to reverse */
  1498. //U8X8_C(0x0c8), /* common output mode */
  1499. U8X8_C(0x0a6), /* display normal, bit val 0: LCD pixel off. */
  1500. U8X8_C(0x0a3), /* LCD bias 1/7 */
  1501. /* power on sequence from paxinstruments */
  1502. U8X8_C(0x028|4), /* all power control circuits on */
  1503. U8X8_DLY(50),
  1504. U8X8_C(0x028|6), /* all power control circuits on */
  1505. U8X8_DLY(50),
  1506. U8X8_C(0x028|7), /* all power control circuits on */
  1507. U8X8_DLY(50),
  1508. U8X8_C(0x023), /* v0 voltage resistor ratio */
  1509. U8X8_CA(0x081, 42>>2), /* set contrast, contrast value*/
  1510. U8X8_C(0x0ae), /* display off */
  1511. U8X8_C(0x0a5), /* enter powersafe: all pixel on, issue 142 */
  1512. U8X8_END_TRANSFER(), /* disable chip */
  1513. U8X8_END() /* end of sequence */
  1514. };
  1515. uint8_t u8x8_d_st7567_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  1516. {
  1517. uint8_t x, c;
  1518. uint8_t *ptr;
  1519. switch(msg)
  1520. {
  1521. case U8X8_MSG_DISPLAY_SETUP_MEMORY:
  1522. u8x8_d_helper_display_setup_memory(u8x8, &u8x8_st7567_96x65_display_info);
  1523. break;
  1524. case U8X8_MSG_DISPLAY_INIT:
  1525. u8x8_d_helper_display_init(u8x8);
  1526. u8x8_cad_SendSequence(u8x8, u8x8_st7567_96x65_init_seq);
  1527. break;
  1528. case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
  1529. if ( arg_int == 0 )
  1530. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave0_seq);
  1531. else
  1532. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_powersave1_seq);
  1533. break;
  1534. case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
  1535. if ( arg_int == 0 )
  1536. {
  1537. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip0_seq);
  1538. u8x8->x_offset = u8x8->display_info->default_x_offset;
  1539. }
  1540. else
  1541. {
  1542. u8x8_cad_SendSequence(u8x8, u8x8_d_st7567_132x64_flip1_seq);
  1543. u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
  1544. }
  1545. break;
  1546. #ifdef U8X8_WITH_SET_CONTRAST
  1547. case U8X8_MSG_DISPLAY_SET_CONTRAST:
  1548. u8x8_cad_StartTransfer(u8x8);
  1549. u8x8_cad_SendCmd(u8x8, 0x081 );
  1550. u8x8_cad_SendArg(u8x8, arg_int >> 2 ); /* st7567 has range from 0 to 63 */
  1551. u8x8_cad_EndTransfer(u8x8);
  1552. break;
  1553. #endif
  1554. case U8X8_MSG_DISPLAY_DRAW_TILE:
  1555. u8x8_cad_StartTransfer(u8x8);
  1556. x = ((u8x8_tile_t *)arg_ptr)->x_pos;
  1557. x *= 8;
  1558. x += u8x8->x_offset;
  1559. u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
  1560. u8x8_cad_SendCmd(u8x8, 0x000 | ((x&15)));
  1561. u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos));
  1562. c = ((u8x8_tile_t *)arg_ptr)->cnt;
  1563. c *= 8;
  1564. ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
  1565. /*
  1566. The following if condition checks the hardware limits of the st7567
  1567. controller: It is not allowed to write beyond the display limits.
  1568. This is in fact an issue within flip mode.
  1569. */
  1570. if ( c + x > 132u )
  1571. {
  1572. c = 132u;
  1573. c -= x;
  1574. }
  1575. do
  1576. {
  1577. u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
  1578. arg_int--;
  1579. } while( arg_int > 0 );
  1580. u8x8_cad_EndTransfer(u8x8);
  1581. break;
  1582. default:
  1583. return 0;
  1584. }
  1585. return 1;
  1586. }