1 /*************************************************************************************
2 * Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
3 *
4 * This software is owned and published by:
5 * Huada Semiconductor Co.,Ltd ("HDSC").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with HDSC
11 * components. This software is licensed by HDSC to be adapted only
12 * for use in systems utilizing HDSC components. HDSC shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. HDSC is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * Disclaimer:
19 * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
20 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
21 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
22 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
23 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
24 * WARRANTY OF NONINFRINGEMENT.
25 * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
26 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
27 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
28 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
29 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
31 * SAVINGS OR PROFITS,
32 * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
34 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
35 * FROM, THE SOFTWARE.
36 *
37 * This software may be replicated in part or whole for the licensed use,
38 * with the restriction that this Disclaimer and Copyright notice must be
39 * included with each copy of this software, whether used in part or whole,
40 * at all times.
41 */
42 /******************************************************************************/
43 /** \file lcd.c
44 **
45 ** WDT function driver API.
46 ** @link SampleGroup Some description @endlink
47 **
48 ** - 2018-5-3 1.0 CJ First version for Device Driver Library of Module.
49 **
50 ******************************************************************************/
51
52 /******************************************************************************/
53 /* Include files */
54 /******************************************************************************/
55 #include "lcd.h"
56
57 /**
58 *******************************************************************************
59 ** \addtogroup I2cGroup
60 ******************************************************************************/
61 //@{
62
63 /******************************************************************************/
64 /* Local function prototypes ('static') */
65 /******************************************************************************/
LCD_SetClkSrc(en_lcd_clk_t enLcdClk)66 en_result_t LCD_SetClkSrc(en_lcd_clk_t enLcdClk)
67 {
68 en_result_t enRet = Error;
69 M0P_LCD->CR1_f.CLKSRC = enLcdClk;
70 enRet = Ok;
71 return enRet;
72 }
73 /**
74 ******************************************************************************
75 ** \brief LCD Bias源选择函数
76 **
77 ** \param [in] enBiasSrc偏置源选择
78 **
79 ** \retval enRet 成功或失败
80 **
81 ******************************************************************************/
LCD_SelBiasSrc(en_lcd_biassrc_t enBiasSrc)82 en_result_t LCD_SelBiasSrc(en_lcd_biassrc_t enBiasSrc)
83 {
84 en_result_t enRet = Error;
85 switch(enBiasSrc)
86 {
87 case LcdInRes_High:
88 case LcdInRes_Low:
89 case LcdInRes_Mid:
90 case LcdExtCap:
91 case LcdExtRes:
92 M0P_LCD->CR0_f.BSEL = enBiasSrc;
93 break;
94 default:
95 return ErrorInvalidParameter;
96 }
97 enRet = Ok;
98 return enRet;
99 }
100 /**
101 ******************************************************************************
102 ** \brief LCD 占空比选择函数
103 **
104 ** \param [in] enDuty占空比
105 **
106 ** \retval enRet 成功或失败
107 **
108 ******************************************************************************/
LCD_SetDuty(en_lcd_duty_t enDuty)109 en_result_t LCD_SetDuty(en_lcd_duty_t enDuty)
110 {
111 en_result_t enRet = Error;
112 switch(enDuty)
113 {
114 case LcdStatic:
115 case LcdDuty2:
116 case LcdDuty3:
117 case LcdDuty4:
118 case LcdDuty6:
119 case LcdDuty8:
120 M0P_LCD->CR0_f.DUTY = enDuty;
121 break;
122 default:
123 return ErrorInvalidParameter;
124 }
125 enRet = Ok;
126 return enRet;
127 }
128 /**
129 ******************************************************************************
130 ** \brief LCD bias设置函数
131 **
132 ** \param [in] enBias 偏置
133 **
134 ** \retval enRet 成功或失败
135 **
136 ******************************************************************************/
LCD_SetBias(en_lcd_bias_t enBias)137 en_result_t LCD_SetBias(en_lcd_bias_t enBias)
138 {
139 en_result_t enRet = Error;
140 switch(enBias)
141 {
142 case LcdBias3:
143 case LcdBias2:
144 M0P_LCD->CR0_f.BIAS = enBias;
145 break;
146 default:
147 return ErrorInvalidParameter;
148 }
149 enRet = Ok;
150 return enRet;
151 }
152 /**
153 ******************************************************************************
154 ** \brief LCD 电压泵时钟频率选择函数
155 **
156 ** \param [in] enCpClk 电压泵频率
157 **
158 ** \retval enRet 成功或失败
159 **
160 ******************************************************************************/
LCD_SelCpClk(en_lcd_cpclk_t enCpClk)161 en_result_t LCD_SelCpClk(en_lcd_cpclk_t enCpClk)
162 {
163 en_result_t enRet = Error;
164 switch(enCpClk)
165 {
166 case LcdClk2k:
167 case LcdClk4k:
168 case LcdClk8k:
169 case LcdClk16k:
170 M0P_LCD->CR0_f.CPCLK = enCpClk;
171 break;
172 default:
173 return ErrorInvalidParameter;
174 }
175 enRet = Ok;
176 return enRet;
177 }
178 /**
179 ******************************************************************************
180 ** \brief LCD 扫描时钟频率选择函数
181 **
182 ** \param [in] enScanClk 扫描时钟频率
183 **
184 ** \retval enRet 成功或失败
185 **
186 ******************************************************************************/
LCD_SelScanClk(en_lcd_scanclk_t enScanClk)187 en_result_t LCD_SelScanClk(en_lcd_scanclk_t enScanClk)
188 {
189 en_result_t enRet = Error;
190 switch(enScanClk)
191 {
192 case LcdClk64hz:
193 case LcdClk128hz:
194 case LcdClk256hz:
195 case LcdClk512hz:
196 M0P_LCD->CR0_f.LCDCLK = enScanClk;
197 break;
198 default:
199 return ErrorInvalidParameter;
200 }
201 enRet = Ok;
202 return enRet;
203 }
204 /**
205 ******************************************************************************
206 ** \brief LCD 模块使能或闪屏使能禁止函数
207 **
208 ** \param [in] enFunc功能,bFlag使能或禁止
209 **
210 ** \retval enRet 成功或失败
211 **
212 ******************************************************************************/
LCD_EnFunc(en_lcd_func_t enFunc,boolean_t bFlag)213 en_result_t LCD_EnFunc(en_lcd_func_t enFunc,boolean_t bFlag)
214 {
215 en_result_t enRet = Error;
216 switch(enFunc)
217 {
218 case LcdEn:
219 M0P_LCD->CR0_f.EN = bFlag;
220 break;
221 case LcdBlinkEn:
222 M0P_LCD->CR1_f.BLINKEN = bFlag;
223 break;
224 default:
225 return ErrorInvalidParameter;
226 }
227 enRet = Ok;
228 return enRet;
229 }
230 /**
231 ******************************************************************************
232 ** \brief LCD 显示模式0/1设置
233 **
234 ** \param [in] enDispMode模式
235 **
236 ** \retval enRet 成功或失败
237 **
238 ******************************************************************************/
LCD_SetDispMode(en_lcd_dispmode_t enDispMode)239 en_result_t LCD_SetDispMode(en_lcd_dispmode_t enDispMode)
240 {
241 en_result_t enRet = Error;
242 switch(enDispMode)
243 {
244 case LcdMode0:
245 case LcdMode1:
246 M0P_LCD->CR1_f.MODE = enDispMode;
247 break;
248 default:
249 return ErrorInvalidParameter;
250 }
251 enRet = Ok;
252 return enRet;
253 }
254 /**
255 ******************************************************************************
256 ** \brief LCD 对比度设置
257 **
258 ** \param [in] u8Contrast对比度
259 **
260 ** \retval enRet 成功或失败
261 **
262 ******************************************************************************/
LCD_SetContrast(uint8_t u8Contrast)263 en_result_t LCD_SetContrast(uint8_t u8Contrast)
264 {
265 en_result_t enRet = Error;
266 M0P_LCD->CR0_f.CONTRAST = u8Contrast;
267 enRet = Ok;
268 return enRet;
269 }
270 /**
271 ******************************************************************************
272 ** \brief LCD 闪屏计数器设置
273 **
274 ** \param [in] u8BlinkCnt计数器
275 **
276 ** \retval enRet 成功或失败
277 **
278 ******************************************************************************/
LCD_SetBlinkCnt(uint8_t u8BlinkCnt)279 en_result_t LCD_SetBlinkCnt(uint8_t u8BlinkCnt)
280 {
281 en_result_t enRet = Error;
282 M0P_LCD->CR1_f.BLINKCNT = u8BlinkCnt;
283 enRet = Ok;
284 return enRet;
285 }
286 /**
287 ******************************************************************************
288 ** \brief LCD 中断标记清除
289 **
290 ** \param [in] 无
291 **
292 ** \retval enRet 成功或失败
293 **
294 ******************************************************************************/
LCD_ClrIntState(void)295 en_result_t LCD_ClrIntState(void)
296 {
297 en_result_t enRet = Error;
298 M0P_LCD->INTCLR_f.INTF = 0;
299 enRet = Ok;
300 return enRet;
301 }
302 /**
303 ******************************************************************************
304 ** \brief 根据LCD显示模式获取端口配置
305 **
306 ** \param [in]enLcdRunMode:显示方式, stcSegCom获取端口参数
307 **
308 ** \retval enRet 成功或失败
309 **
310 ******************************************************************************/
LCD_GetSegCom(stc_lcd_segcompara_t * pstcSegComPara,stc_lcd_segcom_t * pstcSegCom)311 en_result_t LCD_GetSegCom(stc_lcd_segcompara_t *pstcSegComPara,stc_lcd_segcom_t *pstcSegCom)
312 {
313 en_result_t enRet = Error;
314 if(pstcSegComPara->u8MaxSeg>40)
315 {
316 return ErrorInvalidParameter;
317 }
318 switch(pstcSegComPara->enBiasSrc)//seg32_35
319 {
320 case LcdInRes_High:
321 case LcdInRes_Low:
322 case LcdInRes_Mid:
323 pstcSegCom->bMux = 1;
324 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom = 0xff;
325 break;
326 case LcdExtCap:
327 case LcdExtRes:
328 //VLCD模拟端口配置
329 if(pstcSegComPara->u8MaxSeg>36)
330 {
331 return ErrorInvalidParameter;
332 }
333 pstcSegCom->bMux = 0;
334 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom = 0x0f;//seg32_35置0
335 break;
336 default:
337 return ErrorInvalidParameter;
338 }
339 switch(pstcSegComPara->enDuty)//COM0_7
340 {
341 case LcdStatic:
342 pstcSegCom->u8Com0_3 = 0xfe;
343 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
344 break;
345 case LcdDuty2:
346 pstcSegCom->u8Com0_3 = 0xfc;//COM口配置,默认按顺序进行配置com0/com1
347 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
348 break;
349 case LcdDuty3:
350 pstcSegCom->u8Com0_3 = 0xf8;//只取低4bit
351 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
352 break;
353 case LcdDuty4:
354 pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
355 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
356 break;
357 case LcdDuty6:
358 if(pstcSegComPara->u8MaxSeg>38)
359 {
360 return ErrorInvalidParameter;
361 }
362 pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
363 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xfc;
364 break;
365 case LcdDuty8:
366 if(pstcSegComPara->u8MaxSeg>36)
367 {
368 return ErrorInvalidParameter;
369 }
370 pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
371 pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xf0;
372 break;
373 default:
374 return ErrorInvalidParameter;
375 }
376 return enRet;
377 }
378 /**
379 ******************************************************************************
380 ** \brief LCD COMSEG端口配置
381 **
382 ** \param [in] pstcSegCom端口配置结构体
383 **
384 ** \retval enRet 成功或失败
385 **
386 ******************************************************************************/
LCD_SetSegCom(stc_lcd_segcom_t * pstcSegCom)387 en_result_t LCD_SetSegCom(stc_lcd_segcom_t *pstcSegCom)
388 {
389 en_result_t enRet = Error;
390 M0P_LCD->POEN0 = pstcSegCom->u32Seg0_31;
391 M0P_LCD->POEN1 = (uint32_t)(pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom);
392 M0P_LCD->POEN1_f.MUX = pstcSegCom->bMux;
393 M0P_LCD->POEN1_f.C0 = pstcSegCom->u8Com0_3&0x01;
394 M0P_LCD->POEN1_f.C1 = pstcSegCom->u8Com0_3&0x02;
395 M0P_LCD->POEN1_f.C2 = pstcSegCom->u8Com0_3&0x04;
396 M0P_LCD->POEN1_f.C3 = pstcSegCom->u8Com0_3&0x08;
397 enRet = Ok;
398 return enRet;
399 }
400 /**
401 ******************************************************************************
402 ** \brief 液晶全显
403 **
404 ** \param [in] 无
405 **
406 ** \retval enRet 成功或失败
407 **
408 ******************************************************************************/
LCD_FullDisp(void)409 en_result_t LCD_FullDisp(void)
410 {
411 en_result_t enRet=Error;
412 uint8_t i;
413 uint32_t volatile *p = NULL;
414 p = &M0P_LCD->RAM0;
415 for(i=0;i<8;i++)
416 {
417 *p = 0xffffffffu;
418 p++;
419 }
420 for(i=0;i<8;i++)
421 {
422 *p = 0xffu;
423 p++;
424 }
425 enRet = Ok;
426 return enRet;
427 }
428 /**
429 ******************************************************************************
430 ** \brief 液晶全清
431 **
432 ** \param [in] 无
433 **
434 ** \retval enRet 成功或失败
435 **
436 ******************************************************************************/
LCD_ClearDisp(void)437 en_result_t LCD_ClearDisp(void)
438 {
439 en_result_t enRet=Error;
440 uint8_t i;
441 uint32_t volatile *p = NULL;
442 p = &M0P_LCD->RAM0;
443 for(i=0;i<16;i++)
444 {
445 *p = 0x00;
446 p++;
447 }
448 enRet = Ok;
449 return enRet;
450 }
451 /**
452 ******************************************************************************
453 ** \brief LCD RAM bit设置函数
454 **
455 ** \param [in] u16Row RAM地址索引,u32List bit位索引,bData写入0或1
456 **
457 ** \retval enRet 成功或失败
458 **
459 ******************************************************************************/
LCD_WriteRam(uint16_t u16Row,uint32_t u32List,boolean_t bData)460 en_result_t LCD_WriteRam(uint16_t u16Row, uint32_t u32List, boolean_t bData)
461 {
462 en_result_t enRet = Error;
463 uint8_t RamListSize = 0;
464 volatile uint32_t *ptemp = NULL;
465 ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
466 if(u16Row>=8)
467 {
468 RamListSize = LCDRAM8_FSIZE;
469 }
470 else
471 {
472 RamListSize = LCDRAM0_7SIZE;
473 }
474 if ((u16Row > LCDRAMSIZE) || (u32List > RamListSize))
475 {
476 enRet = ErrorInvalidParameter;
477 return enRet;
478 }
479
480 ptemp += u16Row;
481
482 if (bData == TRUE)
483 {
484 *ptemp |= (uint32_t)(1 << u32List);
485 }
486 else
487 {
488 *ptemp &= (uint32_t)(0 << u32List);
489 }
490 enRet = Ok;
491 return enRet;
492 }
493 /**
494 ******************************************************************************
495 ** \brief LCD RAM 0-7寄存器设置函数
496 **
497 ** \param [in] u8Row RAM地址索引,u32Data写入寄存器数值
498 **
499 ** \retval enRet 成功或失败
500 **
501 ******************************************************************************/
LCD_WriteRam0_7Int32(uint8_t u8Row,uint32_t u32Data)502 en_result_t LCD_WriteRam0_7Int32(uint8_t u8Row,uint32_t u32Data)
503 {
504 en_result_t enRet = Error;
505 volatile uint32_t *ptemp = NULL;
506 ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
507
508 if (u8Row > LCDRAMSIZE)
509 {
510 enRet = ErrorInvalidParameter;
511 return enRet;
512 }
513
514 ptemp += u8Row;
515 *ptemp = u32Data;
516 enRet = Ok;
517 return enRet;
518 }
519 /**
520 ******************************************************************************
521 ** \brief LCD RAM 8-f寄存器设置函数
522 **
523 ** \param [in] u8Row RAM地址索引,u8Data写入寄存器数值
524 **
525 ** \retval enRet 成功或失败
526 **
527 ******************************************************************************/
LCD_WriteRam8_FInt8(uint8_t u8Row,uint8_t u8Data)528 en_result_t LCD_WriteRam8_FInt8(uint8_t u8Row,uint8_t u8Data)
529 {
530 en_result_t enRet = Error;
531 volatile uint32_t *ptemp = NULL;
532 ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
533
534 if (u8Row > LCDRAMSIZE)
535 {
536 enRet = ErrorInvalidParameter;
537 return enRet;
538 }
539
540 ptemp += u8Row;
541 *ptemp = u8Data;
542 enRet = Ok;
543 return enRet;
544 }
545 /**
546 ******************************************************************************
547 ** \brief LCD模块初始化函数
548 **
549 ** \param [in] stcLcdCfg配置结构体
550 **
551 ** \retval enRet 成功或失败
552 **
553 ******************************************************************************/
LCD_Init(stc_lcd_config_t * pstcLcdCfg)554 en_result_t LCD_Init(stc_lcd_config_t *pstcLcdCfg)
555 {
556 en_result_t enRet = Error;
557 enRet = LCD_SelBiasSrc(pstcLcdCfg->enBiasSrc);
558 enRet = LCD_SetDuty(pstcLcdCfg->enDuty);
559 enRet = LCD_SetBias(pstcLcdCfg->enBias);
560 enRet = LCD_SelCpClk(pstcLcdCfg->enCpClk);
561 enRet = LCD_SelScanClk(pstcLcdCfg->enScanClk);
562 enRet = LCD_SetDispMode(pstcLcdCfg->enDispMode);
563 enRet = LCD_SetClkSrc(pstcLcdCfg->enClk);
564 if(Ok!=enRet)
565 {
566 return ErrorInvalidParameter;
567 }
568 if(pstcLcdCfg->bTouchNvic)
569 {
570 M0P_LCD->CR1_f.IE = 1;
571 EnableNvic(LCD_IRQn,IrqLevel3,TRUE);
572 }
573 else
574 {
575 EnableNvic(LCD_IRQn,IrqLevel3,FALSE);
576 }
577 return Ok;
578 }
579 //@} // LCDGroup
580