lib_lcd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /**
  2. ******************************************************************************
  3. * @file lib_lcd.c
  4. * @author Application Team
  5. * @version V4.5.0
  6. * @date 2019-05-14
  7. * @brief LCD library.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. ******************************************************************************
  12. */
  13. #include "lib_lcd.h"
  14. #include "lib_LoadNVR.h"
  15. //registers default reset values
  16. #define LCD_CTRL_RSTValue 0
  17. #define LCD_CTRL2_RSTValue 0
  18. #define LCD_SEGCTRL0_RSTValue 0
  19. #define LCD_SEGCTRL1_RSTValue 0
  20. #define LCD_SEGCTRL2_RSTValue 0
  21. /* COMx IO */
  22. const LCD_SEGIO lcd_comio[] =
  23. {
  24. {&GPIOD->OEN, GPIO_Pin_0},
  25. {&GPIOD->OEN, GPIO_Pin_1},
  26. {&GPIOD->OEN, GPIO_Pin_2},
  27. {&GPIOD->OEN, GPIO_Pin_3},
  28. {&GPIOD->OEN, GPIO_Pin_4},
  29. {&GPIOD->OEN, GPIO_Pin_5},
  30. {&GPIOD->OEN, GPIO_Pin_6},
  31. {&GPIOD->OEN, GPIO_Pin_7},
  32. };
  33. /* SEGx IO */
  34. const LCD_SEGIO lcd_segio[] =
  35. { /**************************/
  36. /* SEG | GPIO | Pin */
  37. {&GPIOD->OEN, GPIO_Pin_4}, /* 0 D 4 */
  38. {&GPIOD->OEN, GPIO_Pin_5}, /* 1 D 5 */
  39. {&GPIOD->OEN, GPIO_Pin_6}, /* 2 D 6 */
  40. {&GPIOD->OEN, GPIO_Pin_7}, /* 3 D 7 */
  41. {&GPIOD->OEN, GPIO_Pin_8}, /* 4 D 8 */
  42. {&GPIOD->OEN, GPIO_Pin_9}, /* 5 D 9 */
  43. {&GPIOD->OEN, GPIO_Pin_10}, /* 6 D 10 */
  44. {&GPIOD->OEN, GPIO_Pin_11}, /* 7 D 11 */
  45. {&GPIOD->OEN, GPIO_Pin_12}, /* 8 D 12 */
  46. {&GPIOD->OEN, GPIO_Pin_13}, /* 9 D 13 */
  47. {&GPIOD->OEN, GPIO_Pin_14}, /* 10 D 14 */
  48. {&GPIOD->OEN, GPIO_Pin_15}, /* 11 D 15 */
  49. {&GPIOB->OEN, GPIO_Pin_4}, /* 12 B 4 */
  50. {&GPIOA->OEN, GPIO_Pin_14}, /* 13 A 14 */
  51. {&GPIOB->OEN, GPIO_Pin_5}, /* 14 B 5 */
  52. {&GPIOA->OEN, GPIO_Pin_15}, /* 15 A 15 */
  53. {&GPIOC->OEN, GPIO_Pin_0}, /* 16 C 0 */
  54. {&GPIOC->OEN, GPIO_Pin_1}, /* 17 C 1 */
  55. {&GPIOC->OEN, GPIO_Pin_2}, /* 18 C 2 */
  56. {&GPIOC->OEN, GPIO_Pin_3}, /* 19 C 3 */
  57. {&GPIOC->OEN, GPIO_Pin_4}, /* 20 C 4 */
  58. {&GPIOC->OEN, GPIO_Pin_5}, /* 21 C 5 */
  59. {&GPIOC->OEN, GPIO_Pin_6}, /* 22 C 6 */
  60. {&GPIOC->OEN, GPIO_Pin_7}, /* 23 C 7 */
  61. {&GPIOC->OEN, GPIO_Pin_8}, /* 24 C 8 */
  62. {&GPIOC->OEN, GPIO_Pin_9}, /* 25 C 9 */
  63. {&GPIOC->OEN, GPIO_Pin_10}, /* 26 C 10 */
  64. {&GPIOC->OEN, GPIO_Pin_11}, /* 27 C 11 */
  65. {&GPIOC->OEN, GPIO_Pin_12}, /* 28 C 12 */
  66. {&GPIOC->OEN, GPIO_Pin_13}, /* 29 C 13 */
  67. {&GPIOC->OEN, GPIO_Pin_14}, /* 30 C 14 */
  68. {&GPIOC->OEN, GPIO_Pin_15}, /* 31 C 15 */
  69. {&GPIOE->OEN, GPIO_Pin_10}, /* 32 E 10 */
  70. {&GPIOE->OEN, GPIO_Pin_11}, /* 33 E 11 */
  71. {&GPIOE->OEN, GPIO_Pin_12}, /* 34 E 12 */
  72. {&GPIOB->OEN, GPIO_Pin_8}, /* 35 B 8 */
  73. {&GPIOB->OEN, GPIO_Pin_9}, /* 36 B 9 */
  74. {&GPIOB->OEN, GPIO_Pin_10}, /* 37 B 10 */
  75. {&GPIOB->OEN, GPIO_Pin_11}, /* 38 B 11 */
  76. {&GPIOB->OEN, GPIO_Pin_12}, /* 39 B 12 */
  77. {&GPIOB->OEN, GPIO_Pin_13}, /* 40 B 13 */
  78. {&GPIOB->OEN, GPIO_Pin_14}, /* 41 B 14 */
  79. {&GPIOB->OEN, GPIO_Pin_15}, /* 42 B 15 */
  80. {&GPIOB->OEN, GPIO_Pin_0}, /* 43 B 0 */
  81. {&GPIOB->OEN, GPIO_Pin_6}, /* 44 B 6 */
  82. {&GPIOB->OEN, GPIO_Pin_1}, /* 45 B 1 */
  83. {&GPIOB->OEN, GPIO_Pin_7}, /* 46 B 7 */
  84. {&GPIOA->OEN, GPIO_Pin_11}, /* 47 A 11 */
  85. {&GPIOA->OEN, GPIO_Pin_10}, /* 48 A 10 */
  86. {&GPIOA->OEN, GPIO_Pin_9}, /* 49 A 9 */
  87. {&GPIOA->OEN, GPIO_Pin_8}, /* 50 A 8 */
  88. {&GPIOA->OEN, GPIO_Pin_3}, /* 51 A 3 */
  89. {&GPIOA->OEN, GPIO_Pin_2}, /* 52 A 2 */
  90. {&GPIOA->OEN, GPIO_Pin_1}, /* 53 A 1 */
  91. {&GPIOA->OEN, GPIO_Pin_0}, /* 54 A 0 */
  92. {&GPIOE->OEN, GPIO_Pin_13}, /* 55 E 13 */
  93. {&GPIOE->OEN, GPIO_Pin_14}, /* 56 E 14 */
  94. {&GPIOE->OEN, GPIO_Pin_15}, /* 57 E 15 */
  95. {&GPIOE->OEN, GPIO_Pin_9}, /* 58 E 9 */
  96. {&GPIOE->OEN, GPIO_Pin_8}, /* 59 E 8 */
  97. {&GPIOE->OEN, GPIO_Pin_7}, /* 60 E 7 */
  98. {&GPIOE->OEN, GPIO_Pin_6}, /* 61 E 6 */
  99. {&GPIOE->OEN, GPIO_Pin_5}, /* 62 E 5 */
  100. {&GPIOE->OEN, GPIO_Pin_4}, /* 63 E 4 */
  101. {&GPIOE->OEN, 0}, /* 64 NC NC */
  102. {&GPIOE->OEN, 0}, /* 65 NC NC */
  103. {&GPIOA->OEN, GPIO_Pin_4}, /* 66 A 4 */
  104. {&GPIOA->OEN, GPIO_Pin_5}, /* 67 A 5 */
  105. {&GPIOA->OEN, GPIO_Pin_6}, /* 68 A 6 */
  106. {&GPIOA->OEN, GPIO_Pin_7}, /* 69 A 7 */
  107. {&GPIOB->OEN, GPIO_Pin_2}, /* 70 B 2 */
  108. {&GPIOA->OEN, GPIO_Pin_12}, /* 71 A 12 */
  109. {&GPIOB->OEN, GPIO_Pin_3}, /* 72 B 3 */
  110. {&GPIOA->OEN, GPIO_Pin_13}, /* 73 A 13 */
  111. {&GPIOE->OEN, GPIO_Pin_0}, /* 74 E 0 */
  112. {&GPIOE->OEN, GPIO_Pin_1}, /* 75 E 1 */
  113. {&GPIOE->OEN, GPIO_Pin_2}, /* 76 E 2 */
  114. {&GPIOE->OEN, GPIO_Pin_3}, /* 77 E 3 */
  115. {&GPIOE->OEN, 0}, /* 78 NC NC */
  116. {&GPIOE->OEN, 0} /* 79 NC NC */
  117. };
  118. /**
  119. * @brief LCD initialization.
  120. * @param InitStruct: LCD configuration.
  121. Type:
  122. LCD_TYPE_4COM
  123. LCD_TYPE_6COM
  124. LCD_TYPE_8COM
  125. Drv:
  126. LCD_DRV_300
  127. LCD_DRV_600
  128. LCD_DRV_150
  129. LCD_DRV_200
  130. FRQ:
  131. LCD_FRQ_64H
  132. LCD_FRQ_128H
  133. LCD_FRQ_256H
  134. LCD_FRQ_512H
  135. SWPR: Frame buffer switch period(0.5 sec * (SWPR + 1)).
  136. FBMODE:
  137. LCD_FBMODE_BUFA
  138. LCD_FBMODE_BUFAB
  139. LCD_FBMODE_BUFABLANK
  140. BKFILL:
  141. LCD_BKFILL_1
  142. LCD_BKFILL_0
  143. * @retval None
  144. */
  145. void LCD_Init(LCD_InitType *InitStruct)
  146. {
  147. uint32_t tmp_reg1, tmp_reg2;
  148. /* Check parameters */
  149. assert_parameters(IS_LCD_TYPE(InitStruct->Type));
  150. assert_parameters(IS_LCD_DRV(InitStruct->Drv));
  151. assert_parameters(IS_LCD_FRQ(InitStruct->FRQ));
  152. assert_parameters(IS_LCD_SWPR(InitStruct->SWPR));
  153. assert_parameters(IS_LCD_FBMODE(InitStruct->FBMODE));
  154. assert_parameters(IS_LCD_BKFILL(InitStruct->BKFILL));
  155. tmp_reg1 = LCD->CTRL;
  156. tmp_reg2 = LCD->CTRL2;
  157. tmp_reg1 &= ~(LCD_CTRL_TYPE\
  158. |LCD_CTRL_DRV\
  159. |LCD_CTRL_FRQ);
  160. tmp_reg1 |= (InitStruct->Type\
  161. |InitStruct->Drv\
  162. |InitStruct->FRQ);
  163. tmp_reg2 &= ~(LCD_CTRL2_SWPR\
  164. |LCD_CTRL2_FBMODE\
  165. |LCD_CTRL2_BKFILL);
  166. tmp_reg2 |= ((InitStruct->SWPR << 8)\
  167. |InitStruct->FBMODE\
  168. |InitStruct->BKFILL);
  169. LCD->CTRL = tmp_reg1;
  170. LCD->CTRL2 = tmp_reg2;
  171. }
  172. /**
  173. * @brief Fills each LCD_InitStruct member with its default value.
  174. * @param LCD_InitStruct: pointer to an LCD_InitType structure which will be initialized.
  175. * @retval None
  176. */
  177. void LCD_StructInit(LCD_InitType *LCD_InitStruct)
  178. {
  179. /*--------------- Reset LCD init structure parameters values ---------------*/
  180. /* Initialize the BKFILL member */
  181. LCD_InitStruct->BKFILL = LCD_BKFILL_0;
  182. /* Initialize the Drv member */
  183. LCD_InitStruct->Drv = LCD_DRV_300;
  184. /* Initialize the FBMODE member */
  185. LCD_InitStruct->FBMODE = LCD_FBMODE_BUFA;
  186. /* Initialize the FRQ member */
  187. LCD_InitStruct->FRQ = LCD_FRQ_64H;
  188. /* Initialize the SWPR member */
  189. LCD_InitStruct->SWPR = 0;
  190. /* Initialize the Type member */
  191. LCD_InitStruct->Type = LCD_TYPE_4COM;
  192. }
  193. /**
  194. * @brief Initializes the LCD registers to their default reset values.
  195. * @param None
  196. * @retval None
  197. */
  198. void LCD_DeInit(void)
  199. {
  200. LCD->CTRL &= ~LCD_CTRL_EN;
  201. LCD->CTRL = LCD_CTRL_RSTValue;
  202. LCD->CTRL2 = LCD_CTRL2_RSTValue;
  203. LCD->SEGCTRL0 = LCD_SEGCTRL0_RSTValue;
  204. LCD->SEGCTRL1 = LCD_SEGCTRL1_RSTValue;
  205. LCD->SEGCTRL2 = LCD_SEGCTRL2_RSTValue;
  206. }
  207. /**
  208. * @brief LCD controller enable.
  209. * @param NewState:
  210. ENABLE
  211. DISABLE
  212. * @retval None
  213. */
  214. void LCD_Cmd(uint32_t NewState)
  215. {
  216. /* Check parameters */
  217. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  218. if (NewState != DISABLE)
  219. {
  220. LCD->CTRL |= LCD_CTRL_EN;
  221. }
  222. else
  223. {
  224. LCD->CTRL &= ~LCD_CTRL_EN;
  225. }
  226. }
  227. /**
  228. * @brief Configure LCD COMs'/SEGs' IOs.
  229. * @param ComMode:
  230. LCD_COMMOD_4COM : Control the COM0~3 IO configuration
  231. LCD_COMMOD_6COM : Control the COM0~5 IO configuration
  232. LCD_COMMOD_8COM : Control the COM0~7 IO configuration
  233. * @param SEGVal0 SEGVal1 SEGVal2 : Each bit control the SEGs' IO configuration
  234. * @param NewState:
  235. ENABLE : The corresponded IOs be set to forbidden mode(disable output/disable input), enable SEGs' output and LCD function.
  236. DISABLE : LCD be disabled and the corresponded IOs be set to output(low) mode.
  237. * @retval None
  238. */
  239. void LCD_IOConfig(uint32_t ComMode, uint32_t SEGVal0, uint32_t SEGVal1, uint16_t SEGVal2, uint32_t NewState)
  240. {
  241. uint32_t position, segcurrent;
  242. /* Check parameters */
  243. assert_parameters(IS_LCD_COMMOD(ComMode));
  244. assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  245. if (NewState == DISABLE)
  246. {
  247. /* Disable LCD */
  248. LCD->CTRL &= ~LCD_CTRL_EN;
  249. /* COMs' IO configuration : ouput low */
  250. *(lcd_comio[0].GPIO+2) &= ~lcd_comio[0].Pin;
  251. *lcd_comio[0].GPIO &= ~lcd_comio[0].Pin;
  252. *(lcd_comio[1].GPIO+2) &= ~lcd_comio[1].Pin;
  253. *lcd_comio[1].GPIO &= ~lcd_comio[1].Pin;
  254. *(lcd_comio[2].GPIO+2) &= ~lcd_comio[2].Pin;
  255. *lcd_comio[2].GPIO &= ~lcd_comio[2].Pin;
  256. *(lcd_comio[3].GPIO+2) &= ~lcd_comio[3].Pin;
  257. *lcd_comio[3].GPIO &= ~lcd_comio[3].Pin;
  258. if (ComMode & 2UL)
  259. {
  260. *(lcd_comio[4].GPIO+2) &= ~lcd_comio[4].Pin;
  261. *lcd_comio[4].GPIO &= ~lcd_comio[4].Pin;
  262. *(lcd_comio[5].GPIO+2) &= ~lcd_comio[5].Pin;
  263. *lcd_comio[5].GPIO &= ~lcd_comio[5].Pin;
  264. }
  265. if (ComMode & 4UL)
  266. {
  267. *(lcd_comio[6].GPIO+2) &= ~lcd_comio[6].Pin;
  268. *lcd_comio[6].GPIO &= ~lcd_comio[6].Pin;
  269. *(lcd_comio[7].GPIO+2) &= ~lcd_comio[7].Pin;
  270. *lcd_comio[7].GPIO &= ~lcd_comio[7].Pin;
  271. }
  272. /* SEG0~31 IO Configuration : ouput low */
  273. position = 0;
  274. while ((SEGVal0 >> position) != 0UL)
  275. {
  276. segcurrent = SEGVal0 & (1U << position);
  277. if (segcurrent)
  278. {
  279. *(lcd_segio[position].GPIO + 2) &= ~lcd_segio[position].Pin;
  280. *lcd_segio[position].GPIO &= ~lcd_segio[position].Pin;
  281. }
  282. position++;
  283. }
  284. /* SEG32~63 IO Configuration : ouput low */
  285. position = 0;
  286. while ((SEGVal1 >> position) != 0UL)
  287. {
  288. segcurrent = SEGVal1 & (1U << position);
  289. if (segcurrent)
  290. {
  291. *(lcd_segio[position + 32].GPIO + 2) &= ~lcd_segio[position + 32].Pin;
  292. *lcd_segio[position + 32].GPIO &= ~lcd_segio[position + 32].Pin;
  293. }
  294. position++;
  295. }
  296. /* SEG64~79 IO Configuration : ouput low */
  297. position = 0;
  298. while ((SEGVal2 >> position) != 0UL)
  299. {
  300. segcurrent = SEGVal2 & (1U << position);
  301. if (segcurrent)
  302. {
  303. *(lcd_segio[position + 64].GPIO + 2) &= ~lcd_segio[position + 64].Pin;
  304. *lcd_segio[position + 64].GPIO &= ~lcd_segio[position + 64].Pin;
  305. }
  306. position++;
  307. }
  308. }
  309. else
  310. {
  311. /* COMs' IO configuration : forbidden */
  312. *lcd_comio[0].GPIO |= lcd_comio[0].Pin;
  313. *(lcd_comio[0].GPIO+1) &= ~lcd_comio[0].Pin;
  314. *lcd_comio[1].GPIO |= lcd_comio[1].Pin;
  315. *(lcd_comio[1].GPIO+1) &= ~lcd_comio[1].Pin;
  316. *lcd_comio[2].GPIO |= lcd_comio[2].Pin;
  317. *(lcd_comio[2].GPIO+1) &= ~lcd_comio[2].Pin;
  318. *lcd_comio[3].GPIO |= lcd_comio[3].Pin;
  319. *(lcd_comio[3].GPIO+1) &= ~lcd_comio[3].Pin;
  320. if (ComMode & 2UL)
  321. {
  322. *lcd_comio[4].GPIO |= lcd_comio[4].Pin;
  323. *(lcd_comio[4].GPIO+1) &= ~lcd_comio[4].Pin;
  324. *lcd_comio[5].GPIO |= lcd_comio[5].Pin;
  325. *(lcd_comio[5].GPIO+1) &= ~lcd_comio[5].Pin;
  326. }
  327. if (ComMode & 4UL)
  328. {
  329. *lcd_comio[6].GPIO |= lcd_comio[6].Pin;
  330. *(lcd_comio[6].GPIO+1) &= ~lcd_comio[6].Pin;
  331. *lcd_comio[7].GPIO |= lcd_comio[7].Pin;
  332. *(lcd_comio[7].GPIO+1) &= ~lcd_comio[7].Pin;
  333. }
  334. /* SEG0~31 IO Configuration */
  335. position = 0;
  336. while ((SEGVal0 >> position) != 0UL)
  337. {
  338. segcurrent = SEGVal0 & (1U << position);
  339. if (segcurrent)
  340. {
  341. /* Disable output */
  342. *lcd_segio[position].GPIO |= lcd_segio[position].Pin;
  343. /* Disable input */
  344. *(lcd_segio[position].GPIO + 1) &= ~lcd_segio[position].Pin;
  345. }
  346. position++;
  347. }
  348. /* SEG32~63 IO Configuration */
  349. position = 0;
  350. while ((SEGVal1 >> position) != 0UL)
  351. {
  352. segcurrent = SEGVal1 & (1U << position);
  353. if (segcurrent)
  354. {
  355. /* Disable output */
  356. *lcd_segio[position + 32].GPIO |= lcd_segio[position + 32].Pin;
  357. /* Disable input */
  358. *(lcd_segio[position + 32].GPIO + 1) &= ~lcd_segio[position + 32].Pin;
  359. }
  360. position++;
  361. }
  362. /* SEG64~79 IO Configuration */
  363. position = 0;
  364. while ((SEGVal2 >> position) != 0UL)
  365. {
  366. segcurrent = SEGVal2 & (1U << position);
  367. if (segcurrent)
  368. {
  369. /* Disable output */
  370. *lcd_segio[position + 64].GPIO |= lcd_segio[position + 64].Pin;
  371. /* Disable input */
  372. *(lcd_segio[position + 64].GPIO + 1) &= ~lcd_segio[position + 64].Pin;
  373. }
  374. position++;
  375. }
  376. /* Enable SEGs' function of IOs */
  377. LCD->SEGCTRL0 = SEGVal0;
  378. LCD->SEGCTRL1 = SEGVal1;
  379. LCD->SEGCTRL2 = SEGVal2 & 0xFFFE;
  380. /* Enable LCD */
  381. LCD->CTRL |= LCD_CTRL_EN;
  382. }
  383. }
  384. /**
  385. * @brief LCD SEGx enable.
  386. * @param SEGVal0 SEGVal1 SEGVal2
  387. * @retval None
  388. */
  389. void LCD_SetSEG(uint32_t SEGVal0, uint32_t SEGVal1, uint16_t SEGVal2)
  390. {
  391. uint32_t position;
  392. uint32_t segcurrent;
  393. /* SEG0~31 IO Configuration */
  394. position = 0;
  395. while ((SEGVal0 >> position) != 0UL)
  396. {
  397. segcurrent = SEGVal0 & (1U << position);
  398. if (segcurrent)
  399. {
  400. /* Disable output */
  401. *lcd_segio[position].GPIO |= lcd_segio[position].Pin;
  402. /* Disable input */
  403. *(lcd_segio[position].GPIO + 1) &= ~lcd_segio[position].Pin;
  404. }
  405. position++;
  406. }
  407. /* SEG32~63 IO Configuration */
  408. position = 0;
  409. while ((SEGVal1 >> position) != 0UL)
  410. {
  411. segcurrent = SEGVal1 & (1U << position);
  412. if (segcurrent)
  413. {
  414. /* Disable output */
  415. *lcd_segio[position + 32].GPIO |= lcd_segio[position + 32].Pin;
  416. /* Disable input */
  417. *(lcd_segio[position + 32].GPIO + 1) &= ~lcd_segio[position + 32].Pin;
  418. }
  419. position++;
  420. }
  421. /* SEG64~79 IO Configuration */
  422. position = 0;
  423. while ((SEGVal2 >> position) != 0UL)
  424. {
  425. segcurrent = SEGVal2 & (1U << position);
  426. if (segcurrent)
  427. {
  428. /* Disable output */
  429. *lcd_segio[position + 64].GPIO |= lcd_segio[position + 64].Pin;
  430. /* Disable input */
  431. *(lcd_segio[position + 64].GPIO + 1) &= ~lcd_segio[position + 64].Pin;
  432. }
  433. position++;
  434. }
  435. LCD->SEGCTRL0 = SEGVal0;
  436. LCD->SEGCTRL1 = SEGVal1;
  437. LCD->SEGCTRL2 = SEGVal2 & 0xFFFE;
  438. }
  439. /**
  440. * @brief LCD BIAS mode configure.
  441. * @param BiasSelection:
  442. LCD_BMODE_DIV3
  443. LCD_BMODE_DIV4
  444. * @retval None
  445. */
  446. void LCD_BiasModeConfig(uint32_t BiasSelection)
  447. {
  448. uint32_t tmp;
  449. assert_parameters(IS_LCD_BMODE(BiasSelection));
  450. tmp = ANA->REG6;
  451. tmp &= ~ANA_REG6_LCD_BMODE;
  452. tmp |= BiasSelection;
  453. ANA->REG6 = tmp;
  454. }
  455. /**
  456. * @brief LCD driving voltage configure.
  457. * @note The LCD driving voltage's configuration in NVR will be load to register
  458. * (ANA_REG6[4:1]) in startup_target.s file.
  459. * ex:
  460. * The VLCD information in NVR[0x40D94] 10<<1(-300mV)
  461. * 1. When LCD_VLCD_DEC60MV is selected
  462. * 11<<1(-360mV) will be configured to ANA_REG6[4:1], return 0
  463. * 2. When LCD_VLCD_DEC360MV is selected(out of range)
  464. * 15<<1(-600mV) will be configured to ANA_REG6[4:1], return 2
  465. * @param VLCDSelection:
  466. LCD_VLCD_0
  467. LCD_VLCD_INC60MV
  468. LCD_VLCD_INC120MV
  469. LCD_VLCD_INC180MV
  470. LCD_VLCD_INC240MV
  471. LCD_VLCD_INC300MV
  472. LCD_VLCD_DEC60MV
  473. LCD_VLCD_DEC120MV
  474. LCD_VLCD_DEC180MV
  475. LCD_VLCD_DEC240MV
  476. LCD_VLCD_DEC300MV
  477. LCD_VLCD_DEC360MV
  478. LCD_VLCD_DEC420MV
  479. LCD_VLCD_DEC480MV
  480. LCD_VLCD_DEC540MV
  481. LCD_VLCD_DEC600MV
  482. * @retval 0 Function successed.
  483. 1 NVR LCD information checksum error.
  484. 2 LCD driving voltage's configuration out of range.
  485. */
  486. uint32_t LCD_VoltageConfig(uint32_t VLCDSelection)
  487. {
  488. uint32_t lcd_vol;
  489. uint32_t lcd_vol_tmp;
  490. uint32_t tmp;
  491. NVR_LCDINFO LCD_InfoStruct;
  492. assert_parameters(IS_LCD_VLCD(VLCDSelection));
  493. /* Get NVR LCD information */
  494. if (NVR_GetLCDInfo(&LCD_InfoStruct))
  495. return (1);
  496. else
  497. lcd_vol_tmp = LCD_InfoStruct.MEALCDVol;
  498. tmp = ANA->REG6;
  499. tmp &= ~ANA_REG6_VLCD;
  500. lcd_vol = lcd_vol_tmp<<ANA_REG6_VLCD_Pos;
  501. /*Adjust voltage is postive*/
  502. if ( (lcd_vol_tmp <= 0x5U) && (VLCDSelection <= 0x5U) )
  503. {
  504. /*Adjust voltage is out of range(+300mv)*/
  505. if ((lcd_vol_tmp + VLCDSelection)>0x5U)
  506. {
  507. tmp |= LCD_VLCD_INC300MV << ANA_REG6_VLCD_Pos;
  508. ANA->REG6 = tmp;
  509. return (2);
  510. }
  511. else
  512. {
  513. tmp |= (lcd_vol + (VLCDSelection << ANA_REG6_VLCD_Pos));
  514. ANA->REG6 = tmp;
  515. return (0);
  516. }
  517. }
  518. /*Adjust voltage is negtive*/
  519. else if ( (lcd_vol_tmp > 0x5U) && (VLCDSelection > 0x5U) )
  520. {
  521. /*Adjust voltage is out of range(-600mv)*/
  522. if ((lcd_vol_tmp + VLCDSelection - 5)>0xFU)
  523. {
  524. tmp |= LCD_VLCD_DEC600MV << ANA_REG6_VLCD_Pos;
  525. ANA->REG6 = tmp;
  526. return (2);
  527. }
  528. else
  529. {
  530. tmp |= (lcd_vol + ((VLCDSelection -0x5)<< ANA_REG6_VLCD_Pos));
  531. ANA->REG6 = tmp;
  532. return (0);
  533. }
  534. }
  535. else if ( (lcd_vol_tmp > 0x5U) && (VLCDSelection <= 0x5U) )
  536. {
  537. /*Adjust voltage is postive or 0*/
  538. if ((lcd_vol_tmp - 5) <= VLCDSelection)
  539. {
  540. tmp |= (((VLCDSelection + 0x5) << ANA_REG6_VLCD_Pos) - lcd_vol);
  541. ANA->REG6 = tmp;
  542. return (0);
  543. }
  544. /*Adjust voltage is negtive*/
  545. else
  546. {
  547. tmp |= (lcd_vol - ((VLCDSelection) << ANA_REG6_VLCD_Pos));
  548. ANA->REG6 = tmp;
  549. return (0);
  550. }
  551. }
  552. else
  553. {
  554. /*Adjust voltage is postive or 0*/
  555. if ((VLCDSelection - 5) <= lcd_vol_tmp)
  556. {
  557. tmp |= (lcd_vol - ((VLCDSelection - 0x5) << ANA_REG6_VLCD_Pos));
  558. ANA->REG6 = tmp;
  559. return (0);
  560. }
  561. /*Adjust voltage is negtive*/
  562. else
  563. {
  564. tmp |= ((VLCDSelection << ANA_REG6_VLCD_Pos) - lcd_vol);
  565. ANA->REG6 = tmp;
  566. return (0);
  567. }
  568. }
  569. }
  570. /*********************************** END OF FILE ******************************/