slcd_rhe6616tp01.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /**************************************************************************//**
  2. * @file LCDLIB.c
  3. * @version V3.00
  4. * @brief RHE6616TP01(8-COM, 40-SEG, 1/4 Bias) LCD library source file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2019-2020 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #include <rtthread.h>
  10. #include <rtdevice.h>
  11. #include "drv_slcd.h"
  12. #include "slcd_rhe6616tp01.h"
  13. #define DBG_SECTION_NAME "slcd_demo"
  14. #define DBG_LEVEL DBG_LOG
  15. #include <rtdbg.h>
  16. static rt_device_t g_psDev = RT_NULL;
  17. /**************************************************************************//**
  18. *
  19. * Defines each text's segment (alphabet+numeric) in terms of COM and SEG numbers,
  20. * Using this way that text segment can be consisted of each bit in the
  21. * following bit pattern:
  22. * @illustration
  23. * A
  24. * -----------
  25. * |\ | /|
  26. * F G H I B
  27. * | \ | / |
  28. * --J-- --K--
  29. * | /| \ |
  30. * E L M N C
  31. * | / | \|
  32. * -----------
  33. * D
  34. *
  35. * 0
  36. * -----------
  37. * |\ | /|
  38. * 5| 6 7 8 |1
  39. * | \ | / |
  40. * --9-- -10--
  41. * | /| \ |
  42. * 4| 11 12 13|2
  43. * | / | \|
  44. * -----------
  45. * 3
  46. *
  47. *****************************************************************************/
  48. static const char acMainDigitRawData[ZONE_MAIN_DIG_CNT][ZONE_MAIN_SEG_NUM][2] =
  49. {
  50. {
  51. // digit 1, {com, seg}
  52. // A // B // C // D
  53. {0, 1}, {0, 0}, {3, 0}, {3, 1},
  54. // E // F // G // H
  55. {2, 3}, {0, 3}, {0, 2}, {1, 1},
  56. // I // J // K // L
  57. {1, 0}, {1, 2}, {2, 0}, {3, 2},
  58. // M // N
  59. {2, 2}, {2, 1},
  60. },
  61. {
  62. // digit 2, {com, seg}
  63. // A // B // C // D
  64. {0, 18}, {0, 19}, {3, 19}, {3, 18},
  65. // E // F // G // H
  66. {2, 16}, {0, 16}, {0, 17}, {1, 18},
  67. // I // J // K // L
  68. {1, 19}, {1, 17}, {2, 19}, {3, 17},
  69. // M // N
  70. {2, 17}, {2, 18},
  71. },
  72. {
  73. // digit 3, {com, seg}
  74. // A // B // C // D
  75. {0, 22}, {0, 23}, {3, 23}, {3, 22},
  76. // E // F // G // H
  77. {2, 20}, {0, 20}, {0, 21}, {1, 22},
  78. // I // J // K // L
  79. {1, 23}, {1, 21}, {2, 23}, {3, 21},
  80. // M // N
  81. {2, 21}, {2, 22},
  82. },
  83. {
  84. // digit 4, {com, seg}
  85. // A // B // C // D
  86. {0, 26}, {0, 27}, {3, 27}, {3, 26},
  87. // E // F // G // H
  88. {2, 24}, {0, 24}, {0, 25}, {1, 26},
  89. // I // J // K // L
  90. {1, 27}, {1, 25}, {2, 27}, {3, 25},
  91. // M // N
  92. {2, 25}, {2, 26},
  93. },
  94. {
  95. // digit 5, {com, seg}
  96. // A // B // C // D
  97. {0, 30}, {0, 31}, {3, 31}, {3, 30},
  98. // E // F // G // H
  99. {2, 28}, {0, 28}, {0, 29}, {1, 30},
  100. // I // J // K // L
  101. {1, 31}, {1, 29}, {2, 31}, {3, 29},
  102. // M // N
  103. {2, 29}, {2, 30},
  104. },
  105. {
  106. // digit 6, {com, seg}
  107. // A // B // C // D
  108. {0, 34}, {0, 35}, {3, 35}, {3, 34},
  109. // E // F // G // H
  110. {2, 32}, {0, 32}, {0, 33}, {1, 34},
  111. // I // J // K // L
  112. {1, 35}, {1, 33}, {2, 35}, {3, 33},
  113. // M // N
  114. {2, 33}, {2, 34},
  115. },
  116. {
  117. // digit 7, {com, seg}
  118. // A // B // C // D
  119. {0, 38}, {0, 39}, {3, 39}, {3, 38},
  120. // E // F // G // H
  121. {2, 36}, {0, 36}, {0, 37}, {1, 38},
  122. // I // J // K // L
  123. {1, 39}, {1, 37}, {2, 39}, {3, 37},
  124. // M // N
  125. {2, 37}, {2, 38},
  126. },
  127. };
  128. /**************************************************************************//**
  129. *
  130. * Defines each text's segment (numeric) in terms of COM and BIT numbers,
  131. * Using this way that text segment can be consisted of each bit in the
  132. * following bit pattern:
  133. * @illustration
  134. *
  135. * ---A---
  136. * | |
  137. * F B
  138. * | |
  139. * ---G---
  140. * | |
  141. * E C
  142. * | |
  143. * ---D---
  144. *
  145. * ---0---
  146. * | |
  147. * 5 1
  148. * | |
  149. * ---6---
  150. * | |
  151. * 4 2
  152. * | |
  153. * ---3---
  154. *
  155. *****************************************************************************/
  156. static const char acPPMDigitRawData[ZONE_PPM_DIG_CNT][ZONE_PPM_SEG_NUM][2] =
  157. {
  158. {
  159. // digit 1, {com, seg}
  160. // A // B // C // D
  161. {4, 16}, {5, 17}, {7, 17}, {7, 16},
  162. // E // F // G
  163. {6, 16}, {5, 16}, {6, 17},
  164. },
  165. {
  166. // digit 2, {com, seg}
  167. // A // B // C // D
  168. {4, 18}, {5, 19}, {7, 19}, {7, 18},
  169. // E // F // G
  170. {6, 18}, {5, 18}, {6, 19},
  171. },
  172. {
  173. // digit 3, {com, seg}
  174. // A // B // C // D
  175. {4, 20}, {5, 21}, {7, 21}, {7, 20},
  176. // E // F // G
  177. {6, 20}, {5, 20}, {6, 21},
  178. },
  179. };
  180. static const char acTEMPDigitRawData[ZONE_TEMP_DIG_CNT][ZONE_TEMP_SEG_NUM][2] =
  181. {
  182. {
  183. // digit 1, {com, seg}
  184. // A // B // C // D
  185. {4, 22}, {5, 23}, {7, 23}, {7, 22},
  186. // E // F // G
  187. {6, 22}, {5, 22}, {6, 23},
  188. },
  189. {
  190. // digit 2, {com, seg}
  191. // A // B // C // D
  192. {4, 24}, {5, 25}, {7, 25}, {7, 24},
  193. // E // F // G
  194. {6, 24}, {5, 24}, {6, 25},
  195. },
  196. {
  197. // digit 3, {com, seg}
  198. // A // B // C // D
  199. {4, 26}, {5, 27}, {7, 27}, {7, 26},
  200. // E // F // G
  201. {6, 26}, {5, 26}, {6, 27},
  202. },
  203. };
  204. static const char acVERDigitRawData[ZONE_VER_DIG_CNT][ZONE_VER_SEG_NUM][2] =
  205. {
  206. {
  207. // digit 1, {com, seg}
  208. // A // B // C // D
  209. {4, 28}, {5, 29}, {7, 29}, {7, 28},
  210. // E // F // G
  211. {6, 28}, {5, 28}, {6, 29},
  212. },
  213. {
  214. // digit 2, {com, seg}
  215. // A // B // C // D
  216. {4, 30}, {5, 31}, {7, 31}, {7, 30},
  217. // E // F // G
  218. {6, 30}, {5, 30}, {6, 31},
  219. },
  220. {
  221. // digit 3, {com, seg}
  222. // A // B // C // D
  223. {4, 32}, {5, 33}, {7, 33}, {7, 32},
  224. // E // F // G
  225. {6, 32}, {5, 32}, {6, 33},
  226. },
  227. {
  228. // digit 4, {com, seg}
  229. // A // B // C // D
  230. {4, 34}, {5, 35}, {7, 35}, {7, 34},
  231. // E // F // G
  232. {6, 34}, {5, 34}, {6, 35},
  233. },
  234. {
  235. // digit 5, {com, seg}
  236. // A // B // C // D
  237. {4, 36}, {5, 37}, {7, 37}, {7, 36},
  238. // E // F // G
  239. {6, 36}, {5, 36}, {6, 37},
  240. },
  241. {
  242. // digit 6, {com, seg}
  243. // A // B // C // D
  244. {4, 38}, {5, 39}, {7, 39}, {7, 38},
  245. // E // F // G
  246. {6, 38}, {5, 38}, {6, 39},
  247. },
  248. };
  249. static const char acTimeDigitRawData[ZONE_TIME_DIG_CNT][ZONE_TIME_SEG_NUM][2] =
  250. {
  251. {
  252. // digit 1, {com, seg}
  253. // A // B // C // D
  254. {7, 2}, {6, 3}, {4, 3}, {4, 2},
  255. // E // F // G
  256. {5, 2}, {6, 2}, {5, 3},
  257. },
  258. {
  259. // digit 2, {com, seg}
  260. // A // B // C // D
  261. {7, 4}, {6, 5}, {4, 5}, {4, 4},
  262. // E // F // G
  263. {5, 4}, {6, 4}, {5, 5},
  264. },
  265. {
  266. // digit 3, {com, seg}
  267. // A // B // C // D
  268. {7, 6}, {6, 7}, {4, 7}, {4, 6},
  269. // E // F // G
  270. {5, 6}, {6, 6}, {5, 7},
  271. },
  272. {
  273. // digit 4, {com, seg}
  274. // A // B // C // D
  275. {7, 8}, {6, 9}, {4, 9}, {4, 8},
  276. // E // F // G
  277. {5, 8}, {6, 8}, {5, 9},
  278. },
  279. };
  280. static const char acNuMicroDigitRawData[ZONE_NUMICRO_DIG_CNT][ZONE_NUMICRO_SEG_NUM][2] =
  281. {
  282. {
  283. // digit 1, {com, seg}
  284. // A // B // C // D
  285. {3, 4}, {2, 5}, {0, 5}, {0, 4},
  286. // E // F // G
  287. {1, 4}, {2, 4}, {1, 5},
  288. },
  289. {
  290. // digit 2, {com, seg}
  291. // A // B // C // D
  292. {3, 6}, {2, 7}, {0, 7}, {0, 6},
  293. // E // F // G
  294. {1, 6}, {2, 6}, {1, 7},
  295. },
  296. {
  297. // digit 3, {com, seg}
  298. // A // B // C // D
  299. {3, 8}, {2, 9}, {0, 9}, {0, 8},
  300. // E // F // G
  301. {1, 8}, {2, 8}, {1, 9},
  302. },
  303. };
  304. /**************************************************************************//**
  305. *
  306. * Defines segments for the alphabet - ASCII table 0x20 to 0x7A
  307. * Bit pattern below defined for alphabet (text segments)
  308. *
  309. *****************************************************************************/
  310. static const uint16_t auMainDigitMap[] =
  311. {
  312. 0x0000, /* space */
  313. 0x1100, /* ! */
  314. 0x0280, /* " */
  315. 0x0000, /* # */
  316. 0x0000, /* $ */
  317. 0x0000, /* % */
  318. 0x0000, /* & */
  319. 0x0000, /* ? */
  320. 0x0039, /* ( */
  321. 0x000f, /* ) */
  322. 0x3fc0, /* * */
  323. 0x1540, /* + */
  324. 0x0000, /* , */
  325. 0x0440, /* - */
  326. 0x8000, /* . */
  327. 0x2200, /* / */
  328. 0x003F, /* 0 */
  329. 0x0006, /* 1 */
  330. 0x061B, /* 2 */
  331. 0x060F, /* 3 */
  332. 0x0626, /* 4 */
  333. 0x062D, /* 5 */
  334. 0x063D, /* 6 */
  335. 0x0007, /* 7 */
  336. 0x063F, /* 8 */
  337. 0x062F, /* 9 */
  338. 0x0000, /* : */
  339. 0x0000, /* ; */
  340. 0x2100, /* < */
  341. 0x0000, /* = */
  342. 0x0840, /* > */
  343. 0x1403, /* ? */
  344. 0x3FFF, /* @ */
  345. 0x0637, /* A */
  346. 0x2339, /* B */
  347. 0x0039, /* C */
  348. 0x2139, /* D */
  349. 0x0639, /* E */
  350. 0x0631, /* F */
  351. 0x043D, /* G */
  352. 0x0636, /* H */
  353. 0x1080, /* I */
  354. 0x000E, /* J */
  355. 0x2330, /* K */
  356. 0x0038, /* L */
  357. 0x0176, /* M */
  358. 0x2076, /* N */
  359. 0x003F, /* O */
  360. 0x0633, /* P */
  361. 0x203F, /* Q */
  362. 0x2331, /* R */
  363. 0x062D, /* S */
  364. 0x1081, /* T */
  365. 0x003E, /* U */
  366. 0x0930, /* V */
  367. 0x2836, /* W */
  368. 0x2940, /* X */
  369. 0x1140, /* Y */
  370. 0x0909, /* Z */
  371. 0x0039, /* [ */
  372. 0x0900, /* backslash */
  373. 0x000F, /* ] */
  374. 0x2800, /* ^ */
  375. 0x0008, /* _ */
  376. 0x0040, /* ` */
  377. 0x1218, /* a */
  378. 0x063C, /* b */
  379. 0x0618, /* c */
  380. 0x061E, /* d */
  381. 0x0A18, /* e */
  382. 0x0231, /* f */
  383. 0x048F, /* g */
  384. 0x1230, /* h */
  385. 0x1000, /* i */
  386. 0x000E, /* j */
  387. 0x2330, /* k */
  388. 0x0038, /* l */
  389. 0x1614, /* m */
  390. 0x1404, /* n */
  391. 0x061C, /* o */
  392. 0x0331, /* p */
  393. 0x0447, /* q */
  394. 0x1400, /* r */
  395. 0x2408, /* s */
  396. 0x0238, /* t */
  397. 0x1018, /* u */
  398. 0x0810, /* v */
  399. 0x2814, /* w */
  400. 0x2940, /* x */
  401. 0x0446, /* y */
  402. 0x0A08, /* z */
  403. 0x0000,
  404. };
  405. /**************************************************************************//**
  406. * Defines segments for the numeric display
  407. *****************************************************************************/
  408. static const uint16_t auPPMDigitMap[] =
  409. {
  410. 0x3F, /* 0 */
  411. 0x06, /* 1 */
  412. 0x5B, /* 2 */
  413. 0x4F, /* 3 */
  414. 0x66, /* 4 */
  415. 0x6D, /* 5 */
  416. 0x7D, /* 6 */
  417. 0x07, /* 7 */
  418. 0x7F, /* 8 */
  419. 0x6F, /* 9 */
  420. };
  421. static const uint16_t auTEMPDigitMap[] =
  422. {
  423. 0x3F, /* 0 */
  424. 0x06, /* 1 */
  425. 0x5B, /* 2 */
  426. 0x4F, /* 3 */
  427. 0x66, /* 4 */
  428. 0x6D, /* 5 */
  429. 0x7D, /* 6 */
  430. 0x07, /* 7 */
  431. 0x7F, /* 8 */
  432. 0x6F, /* 9 */
  433. };
  434. static const uint16_t auVERDigitMap[] =
  435. {
  436. 0x3F, /* 0 */
  437. 0x06, /* 1 */
  438. 0x5B, /* 2 */
  439. 0x4F, /* 3 */
  440. 0x66, /* 4 */
  441. 0x6D, /* 5 */
  442. 0x7D, /* 6 */
  443. 0x07, /* 7 */
  444. 0x7F, /* 8 */
  445. 0x6F, /* 9 */
  446. };
  447. static const uint16_t auTimeDigitMap[] =
  448. {
  449. 0x3F, /* 0 */
  450. 0x06, /* 1 */
  451. 0x5B, /* 2 */
  452. 0x4F, /* 3 */
  453. 0x66, /* 4 */
  454. 0x6D, /* 5 */
  455. 0x7D, /* 6 */
  456. 0x07, /* 7 */
  457. 0x7F, /* 8 */
  458. 0x6F, /* 9 */
  459. };
  460. static const uint16_t auNuMicroDigitMap[] =
  461. {
  462. 0x3F, /* 0 */
  463. 0x06, /* 1 */
  464. 0x5B, /* 2 */
  465. 0x4F, /* 3 */
  466. 0x66, /* 4 */
  467. 0x6D, /* 5 */
  468. 0x7D, /* 6 */
  469. 0x07, /* 7 */
  470. 0x7F, /* 8 */
  471. 0x6F, /* 9 */
  472. };
  473. /* Zone information */
  474. static const LCD_ZONE_INFO_T g_LCDZoneInfo[] =
  475. {
  476. {ZONE_MAIN_DIG_CNT, ZONE_MAIN_SEG_NUM},
  477. {ZONE_PPM_DIG_CNT, ZONE_PPM_SEG_NUM},
  478. {ZONE_TEMP_DIG_CNT, ZONE_TEMP_SEG_NUM},
  479. {ZONE_VER_DIG_CNT, ZONE_VER_SEG_NUM},
  480. {ZONE_TIME_DIG_CNT, ZONE_TIME_SEG_NUM},
  481. {ZONE_NUMICRO_DIG_CNT, ZONE_NUMICRO_SEG_NUM},
  482. };
  483. /* Raw data table for each zone */
  484. static const char *g_GetLCDComSeg[] =
  485. {
  486. (const char *)(acMainDigitRawData),
  487. (const char *)(acPPMDigitRawData),
  488. (const char *)(acTEMPDigitRawData),
  489. (const char *)(acVERDigitRawData),
  490. (const char *)(acTimeDigitRawData),
  491. (const char *)(acNuMicroDigitRawData),
  492. };
  493. /* Display mapping table for each zone */
  494. static const uint16_t *g_LCDDispTable[] =
  495. {
  496. (const uint16_t *)(auMainDigitMap),
  497. (const uint16_t *)(auPPMDigitMap),
  498. (const uint16_t *)(auTEMPDigitMap),
  499. (const uint16_t *)(auVERDigitMap),
  500. (const uint16_t *)(auTimeDigitMap),
  501. (const uint16_t *)(auNuMicroDigitMap),
  502. };
  503. void SLCD_SetPixel(uint32_t u32Com, uint32_t u32Seg, uint32_t u32OnFlag)
  504. {
  505. if (g_psDev)
  506. {
  507. struct nu_slcd_pixel sNuSLCDPxl;
  508. sNuSLCDPxl.m_u32Com = u32Com;
  509. sNuSLCDPxl.m_u32Seg = u32Seg;
  510. sNuSLCDPxl.m_u32OnFlag = u32OnFlag;
  511. rt_device_write(g_psDev, 0, (void *)&sNuSLCDPxl, sizeof(struct nu_slcd_pixel));
  512. }
  513. }
  514. /**
  515. * @brief Display text on LCD
  516. *
  517. * @param[in] u32Zone the assigned number of display area
  518. * @param[in] InputStr Text string to show on display
  519. *
  520. * @return None
  521. */
  522. void LCDLIB_Printf(uint32_t u32Zone, char *InputStr)
  523. {
  524. uint32_t i, index, ch, len;
  525. uint16_t DispData;
  526. uint32_t com, seg;
  527. len = rt_strlen(InputStr);
  528. /* Fill out all characters on display */
  529. for (index = 0; index < g_LCDZoneInfo[u32Zone].u32DigitCnt; index++)
  530. {
  531. if (index < len)
  532. {
  533. ch = *InputStr;
  534. }
  535. else
  536. {
  537. /* Padding with SPACE */
  538. ch = 0x20;
  539. }
  540. /* For Main Zone */
  541. if (u32Zone == ZONE_MAIN_DIGIT)
  542. {
  543. /* The Main Digit Table is an ASCII table beginning with "SPACE" (hex is 0x20) */
  544. ch = ch - 0x20;
  545. DispData = *(g_LCDDispTable[u32Zone] + ch);
  546. }
  547. /* For Other Zones (Support '0' ~ '9' only) */
  548. else if ((ch >= '0') && (ch <= '9'))
  549. {
  550. ch = ch - '0';
  551. DispData = *(g_LCDDispTable[u32Zone] + ch);
  552. }
  553. /* Out of definition. Will show "SPACE" */
  554. else
  555. {
  556. DispData = 0;
  557. }
  558. for (i = 0; i < g_LCDZoneInfo[u32Zone].u32MaxSegNum; i++)
  559. {
  560. com = *(g_GetLCDComSeg[u32Zone]
  561. + (index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  562. + (i * 2) + 0);
  563. seg = *(g_GetLCDComSeg[u32Zone]
  564. + (index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  565. + (i * 2) + 1);
  566. /* Turn off display */
  567. SLCD_SetPixel(com, seg, 0);
  568. if (DispData & (1 << i))
  569. {
  570. /* Turn on display */
  571. SLCD_SetPixel(com, seg, 1);
  572. }
  573. }
  574. InputStr++;
  575. }
  576. }
  577. /**
  578. * @brief Display number on LCD
  579. *
  580. * @param[in] u32Zone the assigned number of display area
  581. * @param[in] InputNum number to show on display
  582. *
  583. * @return None
  584. */
  585. void LCDLIB_PrintNumber(uint32_t u32Zone, uint32_t InputNum)
  586. {
  587. uint32_t i, index, val, div;
  588. uint16_t DispData;
  589. uint32_t com, seg;
  590. /* Extract useful digits */
  591. div = 1;
  592. /* Fill out all characters on display */
  593. index = g_LCDZoneInfo[u32Zone].u32DigitCnt;
  594. while (index != 0)
  595. {
  596. index--;
  597. val = (InputNum / div) % 10;
  598. if (u32Zone == ZONE_MAIN_DIGIT)
  599. val += 16; /* The Main Digit Table is an ASCII table beginning with "SPACE" */
  600. DispData = *(g_LCDDispTable[u32Zone] + val);
  601. for (i = 0; i < g_LCDZoneInfo[u32Zone].u32MaxSegNum; i++)
  602. {
  603. com = *(g_GetLCDComSeg[u32Zone]
  604. + (index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  605. + (i * 2) + 0);
  606. seg = *(g_GetLCDComSeg[u32Zone]
  607. + (index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  608. + (i * 2) + 1);
  609. /* Turn off display */
  610. SLCD_SetPixel(com, seg, 0);
  611. if (DispData & (1 << i))
  612. {
  613. /* Turn on display */
  614. SLCD_SetPixel(com, seg, 1);
  615. }
  616. }
  617. div = div * 10;
  618. }
  619. }
  620. /**
  621. * @brief Display character on LCD
  622. *
  623. * @param[in] u32Zone the assigned number of display area
  624. * @param[in] u32Index the requested display position in zone
  625. * @param[in] u8Ch Character to show on display
  626. *
  627. * @return None
  628. */
  629. void LCDLIB_PutChar(uint32_t u32Zone, uint32_t u32Index, uint8_t u8Ch)
  630. {
  631. uint32_t i;
  632. uint16_t DispData;
  633. uint32_t com, seg;
  634. if (u32Index <= g_LCDZoneInfo[u32Zone].u32DigitCnt)
  635. {
  636. /* For Main Zone */
  637. if (u32Zone == ZONE_MAIN_DIGIT)
  638. {
  639. /* The Main Digit Table is an ASCII table beginning with "SPACE" (hex is 0x20) */
  640. u8Ch = u8Ch - 0x20;
  641. DispData = *(g_LCDDispTable[u32Zone] + u8Ch);
  642. }
  643. /* For Other Zones (Support '0' ~ '9' only) */
  644. else if ((u8Ch >= '0') && (u8Ch <= '9'))
  645. {
  646. u8Ch = u8Ch - '0';
  647. DispData = *(g_LCDDispTable[u32Zone] + u8Ch);
  648. }
  649. /* Out of definition. Will show "SPACE" */
  650. else
  651. {
  652. DispData = 0;
  653. }
  654. for (i = 0; i < g_LCDZoneInfo[u32Zone].u32MaxSegNum; i++)
  655. {
  656. com = *(g_GetLCDComSeg[u32Zone]
  657. + (u32Index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  658. + (i * 2) + 0);
  659. seg = *(g_GetLCDComSeg[u32Zone]
  660. + (u32Index * g_LCDZoneInfo[u32Zone].u32MaxSegNum * 2)
  661. + (i * 2) + 1);
  662. /* Turn off display */
  663. SLCD_SetPixel(com, seg, 0);
  664. if (DispData & (1 << i))
  665. {
  666. /* Turn on display */
  667. SLCD_SetPixel(com, seg, 1);
  668. }
  669. }
  670. }
  671. }
  672. /**
  673. * @brief Display symbol on LCD
  674. *
  675. * @param[in] u32Symbol the combination of com, seg position
  676. * @param[in] u32OnOff 1: display symbol
  677. * 0: not display symbol
  678. *
  679. * @return None
  680. */
  681. void LCDLIB_SetSymbol(uint32_t u32Symbol, uint32_t u32OnOff)
  682. {
  683. uint32_t com, seg;
  684. com = (u32Symbol & 0xF);
  685. seg = ((u32Symbol & 0xFF0) >> 4);
  686. if (u32OnOff)
  687. SLCD_SetPixel(com, seg, 1); /* Turn on display */
  688. else
  689. SLCD_SetPixel(com, seg, 0); /* Turn off display */
  690. }
  691. static S_LCD_CFG_T g_LCDCfg_RHE6616TP01 =
  692. {
  693. __LXT, /*!< LCD clock source frequency */
  694. LCD_COM_DUTY_1_8, /*!< COM duty */
  695. LCD_BIAS_LV_1_4, /*!< Bias level */
  696. 64, /*!< Operation frame rate */
  697. LCD_WAVEFORM_TYPE_A_NORMAL, /*!< Waveform type */
  698. LCD_DISABLE_ALL_INT, /*!< Interrupt source */
  699. LCD_LOW_DRIVING_AND_BUF_ON, /*!< Driving mode */
  700. LCD_VOLTAGE_SOURCE_CP, /*!< Voltage source */
  701. };
  702. static int nu_slcd_panel_init(void)
  703. {
  704. uint32_t u32CPVol;
  705. rt_err_t ret = RT_EOK;
  706. g_psDev = rt_device_find("slcd");
  707. if (g_psDev == RT_NULL)
  708. {
  709. LOG_E("can't find slcd failed!\n");
  710. goto fail_nu_slcd_panel_init;
  711. }
  712. /* Give owned SLCD configuration before openning. */
  713. ret = rt_device_control(g_psDev, NU_SLCD_CMD_SET_LCD_CFG, (void *)&g_LCDCfg_RHE6616TP01);
  714. if (ret != RT_EOK)
  715. {
  716. LOG_E("configure SLCD failed!\n");
  717. goto fail_nu_slcd_panel_init;
  718. }
  719. /* Open SLCD. */
  720. ret = rt_device_open(g_psDev, RT_DEVICE_FLAG_WRONLY);
  721. if (ret != RT_EOK)
  722. {
  723. LOG_E("open dev failed!\n");
  724. goto fail_nu_slcd_panel_init;
  725. }
  726. /* Note: This panel need inject 4.8v, but m2354 charge pump max voltage is 3.6v. */
  727. u32CPVol = LCD_CP_VOLTAGE_LV_5;
  728. ret = rt_device_control(g_psDev, NU_SLCD_CMD_SET_CP_VOLTAGE, (void *)&u32CPVol);
  729. if (ret != RT_EOK)
  730. {
  731. LOG_E("faile to control cp voltage!\n");
  732. goto fail_nu_slcd_panel_init;
  733. }
  734. return (int)ret;
  735. fail_nu_slcd_panel_init:
  736. if (g_psDev)
  737. {
  738. rt_device_close(g_psDev);
  739. g_psDev = RT_NULL;
  740. }
  741. return (int)ret;
  742. }
  743. INIT_COMPONENT_EXPORT(nu_slcd_panel_init);
  744. /*** (C) COPYRIGHT 2019-2020 Nuvoton Technology Corp. ***/