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