summaryrefslogtreecommitdiff
path: root/bsp/Vango/v85xx/libraries/VangoV85xx_standard_peripheral/Source/lib_lcd.c
blob: 50a20154013697b02ceeec90f356c3ab87c50000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/**
  ******************************************************************************
  * @file    lib_lcd.c 
  * @author  Application Team
  * @version V4.5.0
  * @date    2019-05-14
  * @brief   LCD library.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */
#include "lib_lcd.h"
#include "lib_LoadNVR.h"

//registers default reset values
#define LCD_CTRL_RSTValue           0
#define LCD_CTRL2_RSTValue          0
#define LCD_SEGCTRL0_RSTValue       0
#define LCD_SEGCTRL1_RSTValue       0
#define LCD_SEGCTRL2_RSTValue       0

/* COMx IO */
const LCD_SEGIO lcd_comio[] = 
{
  {&GPIOD->OEN, GPIO_Pin_0}, 
  {&GPIOD->OEN, GPIO_Pin_1}, 
  {&GPIOD->OEN, GPIO_Pin_2}, 
  {&GPIOD->OEN, GPIO_Pin_3}, 
  {&GPIOD->OEN, GPIO_Pin_4}, 
  {&GPIOD->OEN, GPIO_Pin_5}, 
  {&GPIOD->OEN, GPIO_Pin_6}, 
  {&GPIOD->OEN, GPIO_Pin_7}, 
};

/* SEGx IO */
const LCD_SEGIO lcd_segio[] = 
{                             /**************************/
                              /*  SEG  |  GPIO  |  Pin  */
  {&GPIOD->OEN, GPIO_Pin_4},  /*   0        D       4   */
  {&GPIOD->OEN, GPIO_Pin_5},  /*   1        D       5   */
  {&GPIOD->OEN, GPIO_Pin_6},  /*   2        D       6   */
  {&GPIOD->OEN, GPIO_Pin_7},  /*   3        D       7   */
  {&GPIOD->OEN, GPIO_Pin_8},  /*   4        D       8   */
  {&GPIOD->OEN, GPIO_Pin_9},  /*   5        D       9   */
  {&GPIOD->OEN, GPIO_Pin_10}, /*   6        D       10  */
  {&GPIOD->OEN, GPIO_Pin_11}, /*   7        D       11  */
  {&GPIOD->OEN, GPIO_Pin_12}, /*   8        D       12  */
  {&GPIOD->OEN, GPIO_Pin_13}, /*   9        D       13  */
  {&GPIOD->OEN, GPIO_Pin_14}, /*   10       D       14  */
  {&GPIOD->OEN, GPIO_Pin_15}, /*   11       D       15  */
  {&GPIOB->OEN, GPIO_Pin_4},  /*   12       B       4   */
  {&GPIOA->OEN, GPIO_Pin_14}, /*   13       A       14  */
  {&GPIOB->OEN, GPIO_Pin_5},  /*   14       B       5   */
  {&GPIOA->OEN, GPIO_Pin_15}, /*   15       A       15  */
  {&GPIOC->OEN, GPIO_Pin_0},  /*   16       C       0   */
  {&GPIOC->OEN, GPIO_Pin_1},  /*   17       C       1   */
  {&GPIOC->OEN, GPIO_Pin_2},  /*   18       C       2   */
  {&GPIOC->OEN, GPIO_Pin_3},  /*   19       C       3   */
  {&GPIOC->OEN, GPIO_Pin_4},  /*   20       C       4   */
  {&GPIOC->OEN, GPIO_Pin_5},  /*   21       C       5   */
  {&GPIOC->OEN, GPIO_Pin_6},  /*   22       C       6   */
  {&GPIOC->OEN, GPIO_Pin_7},  /*   23       C       7   */
  {&GPIOC->OEN, GPIO_Pin_8},  /*   24       C       8   */
  {&GPIOC->OEN, GPIO_Pin_9},  /*   25       C       9   */
  {&GPIOC->OEN, GPIO_Pin_10}, /*   26       C       10  */
  {&GPIOC->OEN, GPIO_Pin_11}, /*   27       C       11  */
  {&GPIOC->OEN, GPIO_Pin_12}, /*   28       C       12  */
  {&GPIOC->OEN, GPIO_Pin_13}, /*   29       C       13  */
  {&GPIOC->OEN, GPIO_Pin_14}, /*   30       C       14  */
  {&GPIOC->OEN, GPIO_Pin_15}, /*   31       C       15  */
  {&GPIOE->OEN, GPIO_Pin_10}, /*   32       E       10  */
  {&GPIOE->OEN, GPIO_Pin_11}, /*   33       E       11  */
  {&GPIOE->OEN, GPIO_Pin_12}, /*   34       E       12  */
  {&GPIOB->OEN, GPIO_Pin_8},  /*   35       B       8   */
  {&GPIOB->OEN, GPIO_Pin_9},  /*   36       B       9   */
  {&GPIOB->OEN, GPIO_Pin_10}, /*   37       B       10  */
  {&GPIOB->OEN, GPIO_Pin_11}, /*   38       B       11  */
  {&GPIOB->OEN, GPIO_Pin_12}, /*   39       B       12  */
  {&GPIOB->OEN, GPIO_Pin_13}, /*   40       B       13  */
  {&GPIOB->OEN, GPIO_Pin_14}, /*   41       B       14  */
  {&GPIOB->OEN, GPIO_Pin_15}, /*   42       B       15  */
  {&GPIOB->OEN, GPIO_Pin_0},  /*   43       B       0   */
  {&GPIOB->OEN, GPIO_Pin_6},  /*   44       B       6   */
  {&GPIOB->OEN, GPIO_Pin_1},  /*   45       B       1   */
  {&GPIOB->OEN, GPIO_Pin_7},  /*   46       B       7   */
  {&GPIOA->OEN, GPIO_Pin_11}, /*   47       A       11  */
  {&GPIOA->OEN, GPIO_Pin_10}, /*   48       A       10  */
  {&GPIOA->OEN, GPIO_Pin_9},  /*   49       A       9   */
  {&GPIOA->OEN, GPIO_Pin_8},  /*   50       A       8   */
  {&GPIOA->OEN, GPIO_Pin_3},  /*   51       A       3   */
  {&GPIOA->OEN, GPIO_Pin_2},  /*   52       A       2   */
  {&GPIOA->OEN, GPIO_Pin_1},  /*   53       A       1   */
  {&GPIOA->OEN, GPIO_Pin_0},  /*   54       A       0   */
  {&GPIOE->OEN, GPIO_Pin_13}, /*   55       E       13  */
  {&GPIOE->OEN, GPIO_Pin_14}, /*   56       E       14  */
  {&GPIOE->OEN, GPIO_Pin_15}, /*   57       E       15  */
  {&GPIOE->OEN, GPIO_Pin_9},  /*   58       E       9   */
  {&GPIOE->OEN, GPIO_Pin_8},  /*   59       E       8   */
  {&GPIOE->OEN, GPIO_Pin_7},  /*   60       E       7   */
  {&GPIOE->OEN, GPIO_Pin_6},  /*   61       E       6   */
  {&GPIOE->OEN, GPIO_Pin_5},  /*   62       E       5   */
  {&GPIOE->OEN, GPIO_Pin_4},  /*   63       E       4   */
  {&GPIOE->OEN, 0},           /*   64       NC      NC  */
  {&GPIOE->OEN, 0},           /*   65       NC      NC  */
  {&GPIOA->OEN, GPIO_Pin_4},  /*   66       A       4   */
  {&GPIOA->OEN, GPIO_Pin_5},  /*   67       A       5   */
  {&GPIOA->OEN, GPIO_Pin_6},  /*   68       A       6   */
  {&GPIOA->OEN, GPIO_Pin_7},  /*   69       A       7   */
  {&GPIOB->OEN, GPIO_Pin_2},  /*   70       B       2   */
  {&GPIOA->OEN, GPIO_Pin_12}, /*   71       A       12  */
  {&GPIOB->OEN, GPIO_Pin_3},  /*   72       B       3   */
  {&GPIOA->OEN, GPIO_Pin_13}, /*   73       A       13  */
  {&GPIOE->OEN, GPIO_Pin_0},  /*   74       E       0   */
  {&GPIOE->OEN, GPIO_Pin_1},  /*   75       E       1   */
  {&GPIOE->OEN, GPIO_Pin_2},  /*   76       E       2   */
  {&GPIOE->OEN, GPIO_Pin_3},  /*   77       E       3   */
  {&GPIOE->OEN, 0},           /*   78       NC      NC  */
  {&GPIOE->OEN, 0}            /*   79       NC      NC  */
};

/**
  * @brief  LCD initialization.
  * @param  InitStruct: LCD configuration.
                Type:
                    LCD_TYPE_4COM
                    LCD_TYPE_6COM
                    LCD_TYPE_8COM
                Drv:
                    LCD_DRV_300
                    LCD_DRV_600
                    LCD_DRV_150
                    LCD_DRV_200
                FRQ:
                    LCD_FRQ_64H
                    LCD_FRQ_128H
                    LCD_FRQ_256H
                    LCD_FRQ_512H
                SWPR: Frame buffer switch period(0.5 sec * (SWPR + 1)).
                FBMODE:
                    LCD_FBMODE_BUFA
                    LCD_FBMODE_BUFAB
                    LCD_FBMODE_BUFABLANK
                BKFILL:
                    LCD_BKFILL_1
                    LCD_BKFILL_0
  * @retval None
  */
void LCD_Init(LCD_InitType *InitStruct)
{
  uint32_t tmp_reg1, tmp_reg2;

  /* Check parameters */
  assert_parameters(IS_LCD_TYPE(InitStruct->Type));
  assert_parameters(IS_LCD_DRV(InitStruct->Drv));
  assert_parameters(IS_LCD_FRQ(InitStruct->FRQ));
  assert_parameters(IS_LCD_SWPR(InitStruct->SWPR));
  assert_parameters(IS_LCD_FBMODE(InitStruct->FBMODE));
  assert_parameters(IS_LCD_BKFILL(InitStruct->BKFILL));
  
  tmp_reg1 = LCD->CTRL;
  tmp_reg2 = LCD->CTRL2;
  tmp_reg1 &= ~(LCD_CTRL_TYPE\
               |LCD_CTRL_DRV\
               |LCD_CTRL_FRQ);
  tmp_reg1 |= (InitStruct->Type\
              |InitStruct->Drv\
              |InitStruct->FRQ);
  tmp_reg2 &= ~(LCD_CTRL2_SWPR\
               |LCD_CTRL2_FBMODE\
               |LCD_CTRL2_BKFILL);
  tmp_reg2 |= ((InitStruct->SWPR << 8)\
               |InitStruct->FBMODE\
               |InitStruct->BKFILL);
  LCD->CTRL = tmp_reg1;
  LCD->CTRL2 = tmp_reg2;
}

/**
  * @brief  Fills each LCD_InitStruct member with its default value.
  * @param  LCD_InitStruct: pointer to an LCD_InitType structure which will be initialized.
  * @retval None
  */
void LCD_StructInit(LCD_InitType *LCD_InitStruct)
{
  /*--------------- Reset LCD init structure parameters values ---------------*/
  /* Initialize the BKFILL member */  
  LCD_InitStruct->BKFILL = LCD_BKFILL_0;
  /* Initialize the Drv member */  
  LCD_InitStruct->Drv = LCD_DRV_300;
  /* Initialize the FBMODE member */  
  LCD_InitStruct->FBMODE = LCD_FBMODE_BUFA;
  /* Initialize the FRQ member */  
  LCD_InitStruct->FRQ = LCD_FRQ_64H;
  /* Initialize the SWPR member */  
  LCD_InitStruct->SWPR = 0;
  /* Initialize the Type member */  
  LCD_InitStruct->Type = LCD_TYPE_4COM;
}

/**
  * @brief  Initializes the LCD registers to their default reset values.
  * @param  None
  * @retval None
  */
void LCD_DeInit(void)
{
  LCD->CTRL &= ~LCD_CTRL_EN;
    
  LCD->CTRL = LCD_CTRL_RSTValue;
  LCD->CTRL2 = LCD_CTRL2_RSTValue;
  LCD->SEGCTRL0 = LCD_SEGCTRL0_RSTValue;
  LCD->SEGCTRL1 = LCD_SEGCTRL1_RSTValue;
  LCD->SEGCTRL2 = LCD_SEGCTRL2_RSTValue;
}

/**
  * @brief  LCD controller enable.
  * @param  NewState:
                ENABLE
                DISABLE
  * @retval None
  */
void LCD_Cmd(uint32_t NewState)
{
  /* Check parameters */
  assert_parameters(IS_FUNCTIONAL_STATE(NewState));
  
  if (NewState != DISABLE)
  {
    LCD->CTRL |= LCD_CTRL_EN;
  }
  else
  {
    LCD->CTRL &= ~LCD_CTRL_EN;
  }
}

/**
  * @brief  Configure LCD COMs'/SEGs' IOs.
  * @param  ComMode:
                LCD_COMMOD_4COM : Control the COM0~3 IO configuration
                LCD_COMMOD_6COM : Control the COM0~5 IO configuration
                LCD_COMMOD_8COM : Control the COM0~7 IO configuration
  * @param  SEGVal0 SEGVal1 SEGVal2 : Each bit control the SEGs' IO configuration
  * @param  NewState:
                ENABLE  : The corresponded IOs be set to forbidden mode(disable output/disable input), enable SEGs' output and LCD function.
                DISABLE : LCD be disabled and the corresponded IOs be set to output(low) mode.
  * @retval None
  */
void LCD_IOConfig(uint32_t ComMode, uint32_t SEGVal0, uint32_t SEGVal1, uint16_t SEGVal2, uint32_t NewState)
{
  uint32_t position, segcurrent;
  
  /* Check parameters */
  assert_parameters(IS_LCD_COMMOD(ComMode));
  assert_parameters(IS_FUNCTIONAL_STATE(NewState));

  if (NewState == DISABLE)
  {
    /* Disable LCD */
    LCD->CTRL &= ~LCD_CTRL_EN;

    /* COMs' IO configuration : ouput low */
    *(lcd_comio[0].GPIO+2) &= ~lcd_comio[0].Pin;
    *lcd_comio[0].GPIO &= ~lcd_comio[0].Pin;
    *(lcd_comio[1].GPIO+2) &= ~lcd_comio[1].Pin;
    *lcd_comio[1].GPIO &= ~lcd_comio[1].Pin;
    *(lcd_comio[2].GPIO+2) &= ~lcd_comio[2].Pin;
    *lcd_comio[2].GPIO &= ~lcd_comio[2].Pin;
    *(lcd_comio[3].GPIO+2) &= ~lcd_comio[3].Pin;
    *lcd_comio[3].GPIO &= ~lcd_comio[3].Pin;
    if (ComMode & 2UL)
    {
      *(lcd_comio[4].GPIO+2) &= ~lcd_comio[4].Pin;
      *lcd_comio[4].GPIO &= ~lcd_comio[4].Pin;
      *(lcd_comio[5].GPIO+2) &= ~lcd_comio[5].Pin;
      *lcd_comio[5].GPIO &= ~lcd_comio[5].Pin;
    }
    if (ComMode & 4UL)
    {
      *(lcd_comio[6].GPIO+2) &= ~lcd_comio[6].Pin;
      *lcd_comio[6].GPIO &= ~lcd_comio[6].Pin;
      *(lcd_comio[7].GPIO+2) &= ~lcd_comio[7].Pin;
      *lcd_comio[7].GPIO &= ~lcd_comio[7].Pin;
    }

    /* SEG0~31 IO Configuration : ouput low */
    position = 0;
    while ((SEGVal0 >> position) != 0UL)
    {
      segcurrent = SEGVal0 & (1U << position);
      if (segcurrent)
      {
        *(lcd_segio[position].GPIO + 2) &= ~lcd_segio[position].Pin; 
        *lcd_segio[position].GPIO &= ~lcd_segio[position].Pin;
      }
      position++;
    }
    /* SEG32~63 IO Configuration : ouput low */
    position = 0;
    while ((SEGVal1 >> position) != 0UL)
    {
      segcurrent = SEGVal1 & (1U << position);
      if (segcurrent)
      {
        *(lcd_segio[position + 32].GPIO + 2) &= ~lcd_segio[position + 32].Pin; 
        *lcd_segio[position + 32].GPIO &= ~lcd_segio[position + 32].Pin;
      }
      position++;
    }
    /* SEG64~79 IO Configuration : ouput low  */
    position = 0;
    while ((SEGVal2 >> position) != 0UL)
    {
      segcurrent = SEGVal2 & (1U << position);
      if (segcurrent)
      {
        *(lcd_segio[position + 64].GPIO + 2) &= ~lcd_segio[position + 64].Pin; 
        *lcd_segio[position + 64].GPIO &= ~lcd_segio[position + 64].Pin;
      }
      position++;
    }    
  }
  else
  {
    /* COMs' IO configuration : forbidden */
    *lcd_comio[0].GPIO |= lcd_comio[0].Pin;
    *(lcd_comio[0].GPIO+1) &= ~lcd_comio[0].Pin;
    *lcd_comio[1].GPIO |= lcd_comio[1].Pin;
    *(lcd_comio[1].GPIO+1) &= ~lcd_comio[1].Pin;
    *lcd_comio[2].GPIO |= lcd_comio[2].Pin;
    *(lcd_comio[2].GPIO+1) &= ~lcd_comio[2].Pin;
    *lcd_comio[3].GPIO |= lcd_comio[3].Pin;
    *(lcd_comio[3].GPIO+1) &= ~lcd_comio[3].Pin;
    if (ComMode & 2UL)
    {
      *lcd_comio[4].GPIO |= lcd_comio[4].Pin;
      *(lcd_comio[4].GPIO+1) &= ~lcd_comio[4].Pin;
      *lcd_comio[5].GPIO |= lcd_comio[5].Pin;
      *(lcd_comio[5].GPIO+1) &= ~lcd_comio[5].Pin;
    }
    if (ComMode & 4UL)
    {
      *lcd_comio[6].GPIO |= lcd_comio[6].Pin;
      *(lcd_comio[6].GPIO+1) &= ~lcd_comio[6].Pin;
      *lcd_comio[7].GPIO |= lcd_comio[7].Pin;
      *(lcd_comio[7].GPIO+1) &= ~lcd_comio[7].Pin;
    }

    /* SEG0~31 IO Configuration */
    position = 0;
    while ((SEGVal0 >> position) != 0UL)
    {
      segcurrent = SEGVal0 & (1U << position);
      if (segcurrent)
      {
        /* Disable output */
        *lcd_segio[position].GPIO |= lcd_segio[position].Pin;
        /* Disable input */
        *(lcd_segio[position].GPIO + 1) &= ~lcd_segio[position].Pin; 
      }
      position++;
    }
    /* SEG32~63 IO Configuration */
    position = 0;
    while ((SEGVal1 >> position) != 0UL)
    {
      segcurrent = SEGVal1 & (1U << position);
      if (segcurrent)
      {
        /* Disable output */
        *lcd_segio[position + 32].GPIO |= lcd_segio[position + 32].Pin;
        /* Disable input */
        *(lcd_segio[position + 32].GPIO + 1) &= ~lcd_segio[position + 32].Pin; 
      }
      position++;
    }
    /* SEG64~79 IO Configuration */
    position = 0;
    while ((SEGVal2 >> position) != 0UL)
    {
      segcurrent = SEGVal2 & (1U << position);
      if (segcurrent)
      {
        /* Disable output */
        *lcd_segio[position + 64].GPIO |= lcd_segio[position + 64].Pin;
        /* Disable input */
        *(lcd_segio[position + 64].GPIO + 1) &= ~lcd_segio[position + 64].Pin; 
      }
      position++;
    }

    /* Enable SEGs' function of IOs */
    LCD->SEGCTRL0 = SEGVal0;
    LCD->SEGCTRL1 = SEGVal1;
    LCD->SEGCTRL2 = SEGVal2 & 0xFFFE;

    /* Enable LCD */
    LCD->CTRL |= LCD_CTRL_EN;
  }
}

/**
  * @brief  LCD SEGx enable.
  * @param  SEGVal0 SEGVal1 SEGVal2
  * @retval None
  */
void LCD_SetSEG(uint32_t SEGVal0, uint32_t SEGVal1, uint16_t SEGVal2)
{
  uint32_t position;
  uint32_t segcurrent;
    
  /* SEG0~31 IO Configuration */
  position = 0;
  while ((SEGVal0 >> position) != 0UL)
  {
    segcurrent = SEGVal0 & (1U << position);
    if (segcurrent)
    {
      /* Disable output */
      *lcd_segio[position].GPIO |= lcd_segio[position].Pin;
      /* Disable input */
      *(lcd_segio[position].GPIO + 1) &= ~lcd_segio[position].Pin; 
    }
    position++;
  }
  /* SEG32~63 IO Configuration */
  position = 0;
  while ((SEGVal1 >> position) != 0UL)
  {
    segcurrent = SEGVal1 & (1U << position);
    if (segcurrent)
    {
      /* Disable output */
      *lcd_segio[position + 32].GPIO |= lcd_segio[position + 32].Pin;
      /* Disable input */
      *(lcd_segio[position + 32].GPIO + 1) &= ~lcd_segio[position + 32].Pin; 
    }
    position++;
  }
  /* SEG64~79 IO Configuration */
  position = 0;
  while ((SEGVal2 >> position) != 0UL)
  {
    segcurrent = SEGVal2 & (1U << position);
    if (segcurrent)
    {
      /* Disable output */
      *lcd_segio[position + 64].GPIO |= lcd_segio[position + 64].Pin;
      /* Disable input */
      *(lcd_segio[position + 64].GPIO + 1) &= ~lcd_segio[position + 64].Pin; 
    }
    position++;
  }
  
  LCD->SEGCTRL0 = SEGVal0;
  LCD->SEGCTRL1 = SEGVal1;
  LCD->SEGCTRL2 = SEGVal2 & 0xFFFE;
}

/**
  * @brief  LCD BIAS mode configure.
  * @param  BiasSelection:
                LCD_BMODE_DIV3
                LCD_BMODE_DIV4
  * @retval None
  */
void LCD_BiasModeConfig(uint32_t BiasSelection)
{
  uint32_t tmp;
  
  assert_parameters(IS_LCD_BMODE(BiasSelection));
  
  tmp = ANA->REG6;
  tmp &= ~ANA_REG6_LCD_BMODE;
  tmp |= BiasSelection;
  ANA->REG6 = tmp;
}

/**
  * @brief  LCD driving voltage configure.
  * @note   The LCD driving voltage's configuration in NVR will be load to register
  *         (ANA_REG6[4:1]) in startup_target.s file.
  *         ex:  
  *             The VLCD information in NVR[0x40D94]   10<<1(-300mV)
  *             1. When LCD_VLCD_DEC60MV is selected                 
  *                      11<<1(-360mV) will be configured to ANA_REG6[4:1], return 0
  *             2. When LCD_VLCD_DEC360MV is selected(out of range)  
  *                      15<<1(-600mV) will be configured to ANA_REG6[4:1], return 2
  * @param  VLCDSelection:
                  LCD_VLCD_0      
                  LCD_VLCD_INC60MV 
                  LCD_VLCD_INC120MV   
                  LCD_VLCD_INC180MV 
                  LCD_VLCD_INC240MV 
                  LCD_VLCD_INC300MV 
                  LCD_VLCD_DEC60MV 
                  LCD_VLCD_DEC120MV 
                  LCD_VLCD_DEC180MV
                  LCD_VLCD_DEC240MV 
                  LCD_VLCD_DEC300MV 
                  LCD_VLCD_DEC360MV
                  LCD_VLCD_DEC420MV 
                  LCD_VLCD_DEC480MV
                  LCD_VLCD_DEC540MV
                  LCD_VLCD_DEC600MV
  * @retval 0  Function successed.
            1  NVR LCD information checksum error.
            2  LCD driving voltage's configuration out of range.
  */
uint32_t LCD_VoltageConfig(uint32_t VLCDSelection)
{
  uint32_t lcd_vol;
  uint32_t lcd_vol_tmp;
  uint32_t tmp;
  NVR_LCDINFO LCD_InfoStruct;
  
  assert_parameters(IS_LCD_VLCD(VLCDSelection));
  
  /* Get NVR LCD information */
  if (NVR_GetLCDInfo(&LCD_InfoStruct))
    return (1);
  else
    lcd_vol_tmp = LCD_InfoStruct.MEALCDVol;
  
  tmp = ANA->REG6;
  tmp &= ~ANA_REG6_VLCD;
  lcd_vol = lcd_vol_tmp<<ANA_REG6_VLCD_Pos;

  /*Adjust voltage is postive*/
  if ( (lcd_vol_tmp <= 0x5U) && (VLCDSelection <= 0x5U) )
  {
    /*Adjust voltage is out of range(+300mv)*/
    if ((lcd_vol_tmp + VLCDSelection)>0x5U)
    {
      tmp |= LCD_VLCD_INC300MV << ANA_REG6_VLCD_Pos;
      ANA->REG6 = tmp;
      return (2);
    }
    else
    {
      tmp |= (lcd_vol + (VLCDSelection << ANA_REG6_VLCD_Pos));
      ANA->REG6 = tmp;
      return (0);
    }
  }
  /*Adjust voltage is negtive*/
  else if ( (lcd_vol_tmp > 0x5U) && (VLCDSelection > 0x5U) )
  {
    /*Adjust voltage is out of range(-600mv)*/
    if ((lcd_vol_tmp + VLCDSelection - 5)>0xFU)  
    {
      tmp |= LCD_VLCD_DEC600MV << ANA_REG6_VLCD_Pos;
      ANA->REG6 = tmp;
      return (2);
    }
    else
    {
      tmp |= (lcd_vol + ((VLCDSelection -0x5)<< ANA_REG6_VLCD_Pos));
      ANA->REG6 = tmp;
      return (0);
    }
  }
  else if ( (lcd_vol_tmp > 0x5U) && (VLCDSelection <= 0x5U) )
  {
    /*Adjust voltage is postive or 0*/
     if ((lcd_vol_tmp - 5) <= VLCDSelection)
     {
       tmp |= (((VLCDSelection + 0x5) << ANA_REG6_VLCD_Pos) - lcd_vol);
       ANA->REG6 = tmp;
       return (0);
     }
     /*Adjust voltage is negtive*/
     else
     {
       tmp |= (lcd_vol - ((VLCDSelection) << ANA_REG6_VLCD_Pos));
       ANA->REG6 = tmp;
       return (0);
     }
  }
  else
  {
     /*Adjust voltage is postive or 0*/
     if ((VLCDSelection - 5) <= lcd_vol_tmp)
     {
       tmp |= (lcd_vol - ((VLCDSelection - 0x5) << ANA_REG6_VLCD_Pos));
       ANA->REG6 = tmp;
       return (0);
     }
     /*Adjust voltage is negtive*/
     else
     {
       tmp |= ((VLCDSelection << ANA_REG6_VLCD_Pos) - lcd_vol);
       ANA->REG6 = tmp;
       return (0);
     }
  }
}

/*********************************** END OF FILE ******************************/