1 /******************************************************************************
2 * Copyright (C) 2019, 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 ** lcd driver API.
46 **
47 ** - 2019-04-02 First Version
48 **
49 ******************************************************************************/
50
51 /******************************************************************************
52 * Include files
53 ******************************************************************************/
54 #include "hc32l196_lcd.h"
55
56
57 /**
58 ******************************************************************************
59 ** \addtogroup AdcGroup
60 ******************************************************************************/
61 //@{
62
63 /******************************************************************************
64 * Local pre-processor symbols/macros ('#define')
65 ******************************************************************************/
66
67 /******************************************************************************
68 * Global variable definitions (declared in header file with 'extern')
69 ******************************************************************************/
70
71 /******************************************************************************
72 * Local type definitions ('typedef')
73 ******************************************************************************/
74
75 /******************************************************************************
76 * Local function prototypes ('static')
77 ******************************************************************************/
78
79 /******************************************************************************
80 * Local variable definitions ('static')
81 ******************************************************************************/
82
83 /*****************************************************************************
84 * Function implementation - global ('extern') and local ('static')
85 *****************************************************************************/
86
87 /**
88 ******************************************************************************
89 ** \brief 获取LCD中断标志位INTF
90 **
91 ** @param 无
92 ** \retval 无
93 **
94 ******************************************************************************/
Lcd_GetItStatus(void)95 boolean_t Lcd_GetItStatus(void)
96 {
97 return (((M0P_LCD->CR1)>>11)&0x01)? TRUE : FALSE;
98 }
99
100 /**
101 ******************************************************************************
102 ** \brief 清除中断标志位INTF
103 **
104 ** @param 无
105 ** \retval 无
106 **
107 ******************************************************************************/
Lcd_ClearItPendingBit(void)108 void Lcd_ClearItPendingBit(void)
109 {
110 SetBit((uint32_t)(&(M0P_LCD->INTCLR)), 10, 0);
111 }
112
113 /**
114 ******************************************************************************
115 ** \brief 根据LCD显示模式获取端口配置
116 **
117 ** \param pstcSegComPara:显示方式, stcSegCom获取端口参数
118 **
119 ** \retval enRet 成功或失败
120 **
121 ******************************************************************************/
Lcd_GetSegCom(stc_lcd_segcompara_t * pstcSegComPara,stc_lcd_segcom_t * pstcSegCom)122 en_result_t Lcd_GetSegCom(stc_lcd_segcompara_t *pstcSegComPara,stc_lcd_segcom_t *pstcSegCom)
123 {
124 en_result_t enRet = Error;
125 pstcSegCom->stc_seg32_51_com0_8_t.seg32_51_com0_8 = 0xffffffffu;
126 pstcSegCom->u32Seg0_31 = 0xffffffffu;
127 if(pstcSegComPara->u8MaxSeg>51)
128 {
129 return ErrorInvalidParameter;
130 }
131 switch(pstcSegComPara->LcdBiasSrc)
132 {
133 case LcdInResHighPower:
134 case LcdInResLowPower:
135 case LcdInResMidPower:
136 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Mux = 1;
137 break;
138 case LcdExtCap:
139 case LcdExtRes:
140 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Mux = 0;
141 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg32_35 = 0;
142 break;
143 default:
144 return ErrorInvalidParameter;
145 }
146 switch(pstcSegComPara->LcdDuty)
147 {
148 case LcdStatic:
149 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~1u)&0x0fu;
150 break;
151 case LcdDuty2:
152 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~3u)&0x0fu;
153 break;
154 case LcdDuty3:
155 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~7u)&0x0fu;
156 break;
157 case LcdDuty4:
158 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~15u)&0x0fu;
159 break;
160 case LcdDuty6:
161 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = 0;
162 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg39Com4 = 0;
163 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg38Com5 = 0;
164 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg37Com6 = 1;
165 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg36Com7 = 1;
166 break;
167 case LcdDuty8:
168 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = 0;
169 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg39Com4 = 0;
170 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg38Com5 = 0;
171 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg37Com6 = 0;
172 pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg36Com7 = 0;
173 break;
174 default:
175 return ErrorInvalidParameter;
176 }
177 enRet = Ok;
178 return enRet;
179 }
180
181 /**
182 ******************************************************************************
183 ** \brief LCD COMSEG端口配置,使用该函数之前需要先使能相应的Seg
184 **
185 ** \param [in] pstcSegCom端口配置结构体
186 **
187 ** \retval enRet 成功或失败
188 **
189 ******************************************************************************/
Lcd_SetSegCom(stc_lcd_segcom_t * pstcSegCom)190 void Lcd_SetSegCom(stc_lcd_segcom_t *pstcSegCom)
191 {
192 M0P_LCD->POEN0 = pstcSegCom->u32Seg0_31;
193 M0P_LCD->POEN1 = pstcSegCom->stc_seg32_51_com0_8_t.seg32_51_com0_8;
194 }
195
196 /**
197 ******************************************************************************
198 ** \brief LCD模块初始化函数
199 **
200 ** \param stcLcdCfg配置初始化结构体
201 **
202 ** \retval 无
203 **
204 ******************************************************************************/
Lcd_Init(stc_lcd_cfg_t * pstcLcdCfg)205 void Lcd_Init(stc_lcd_cfg_t *pstcLcdCfg)
206 {
207 M0P_LCD->CR0_f.BSEL = pstcLcdCfg->LcdBiasSrc;
208 M0P_LCD->CR0_f.DUTY = pstcLcdCfg->LcdDuty;
209 M0P_LCD->CR0_f.BIAS = pstcLcdCfg->LcdBias;
210 M0P_LCD->CR0_f.CPCLK = pstcLcdCfg->LcdCpClk;
211 M0P_LCD->CR0_f.LCDCLK = pstcLcdCfg->LcdScanClk;
212 M0P_LCD->CR1_f.MODE = pstcLcdCfg->LcdMode;
213 M0P_LCD->CR1_f.CLKSRC = pstcLcdCfg->LcdClkSrc;
214 M0P_LCD->CR0_f.EN = pstcLcdCfg->LcdEn;
215 }
216
217 /**
218 ******************************************************************************
219 ** \brief 液晶全显
220 **
221 ** \param 无
222 **
223 ** \retval 无
224 **
225 ******************************************************************************/
Lcd_FullDisp(void)226 void Lcd_FullDisp(void)
227 {
228 uint8_t tmp;
229 volatile uint32_t *ram = NULL;
230 ram = &M0P_LCD->RAM0;
231 for(tmp=0;tmp<16;tmp++)
232 {
233 *ram = 0xffffffffu;
234 ram++;
235 }
236 }
237
238 /**
239 ******************************************************************************
240 ** \brief 清屏
241 **
242 ** \param 无
243 **
244 ** \retval 无
245 **
246 ******************************************************************************/
Lcd_ClearDisp(void)247 void Lcd_ClearDisp(void)
248 {
249 uint8_t tmp;
250 volatile uint32_t *ram = NULL;
251 ram = &M0P_LCD->RAM0;
252 for(tmp=0;tmp<16;tmp++)
253 {
254 *ram = 0;
255 ram++;
256 }
257 }
258
259 /**
260 ******************************************************************************
261 ** \brief LCD RAM 0-f寄存器设置函数
262 **
263 ** \param u8Row RAM地址索引,范围:0-15,u8Data写入寄存器数值
264 **
265 ** \retval enRet 成功或失败
266 **
267 ******************************************************************************/
Lcd_WriteRam(uint8_t u8Row,uint32_t u32Data)268 en_result_t Lcd_WriteRam(uint8_t u8Row,uint32_t u32Data)
269 {
270 en_result_t enRet = Error;
271 volatile uint32_t *ram = NULL;
272 ram = (volatile uint32_t*)&M0P_LCD->RAM0;
273
274 if (u8Row > 15)
275 {
276 enRet = ErrorInvalidParameter;
277 return enRet;
278 }
279
280 ram += u8Row;
281 *ram = u32Data;
282 enRet = Ok;
283 return enRet;
284 }
285
286 /******************************************************************************
287 * EOF (not truncated)
288 ******************************************************************************/
289
290