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
|
/**
*********************************************************************************
*
* @file ald_lcd.c
* @brief LCD module driver.
*
* @version V1.0
* @date 29 Nov 2017
* @author AE Team
* @note
*
* Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
*
*********************************************************************************
*/
#include "ald_lcd.h"
/** @addtogroup ES32FXXX_ALD
* @{
*/
/** @defgroup LCD LCD
* @brief LCD module library
* @{
*/
#ifdef ALD_LCD
/** @defgroup LCD_Public_Functions LCD Public Functions
* @{
*/
/** @defgroup LCD_Public_Functions_Group1 Initialize and Enable functions
* @brief Initialize and Enable Functions
* @{
*/
/**
* @brief Initializes the LCD Peripheral according to the specified parameters.
* @note This function can be used only when the LCD is disabled.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_init(lcd_handle_t *hperh)
{
uint16_t delay = 0;
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_VCHPS_TYPE(hperh->init.lcd_vchps));
assert_param(IS_LCD_VSEL_TYPE(hperh->init.lcd_vsel));
assert_param(IS_LCD_FUNC_TYPE(hperh->init.lcd_vbufld));
assert_param(IS_LCD_FUNC_TYPE(hperh->init.lcd_vbufhd));
assert_param(IS_LCD_LEVEL_TYPE(hperh->init.lcd_dsld));
assert_param(IS_LCD_LEVEL_TYPE(hperh->init.lcd_dshd));
assert_param(IS_LCD_RES_TYPE(hperh->init.lcd_resld));
assert_param(IS_LCD_RES_TYPE(hperh->init.lcd_reshd));
assert_param(IS_LCD_BIAS_TYPE(hperh->init.lcd_bias));
assert_param(IS_LCD_DUTY_TYPE(hperh->init.lcd_duty));
assert_param(IS_LCD_WFS_TYPE(hperh->init.lcd_wfs));
assert_param(IS_LCD_PRS_TYPE(hperh->init.lcd_prs));
assert_param(IS_LCD_DIV_TYPE(hperh->init.lcd_div));
assert_param(IS_LCD_DEAD_TYPE(hperh->init.lcd_dead));
assert_param(IS_LCD_PON_TYPE(hperh->init.lcd_pon));
assert_param(IS_LCD_VGS_TYPE(hperh->init.lcd_vgs));
__LOCK(hperh);
cmu_lcd_clock_select(hperh->init.clock);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_WFS_MSK, hperh->init.lcd_wfs << LCD_FCR_WFS_POS);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_PRS_MSK, hperh->init.lcd_prs << LCD_FCR_PRS_POSS);
for (delay = 0; delay < 3000; delay++);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_DIV_MSK, hperh->init.lcd_div << LCD_FCR_DIV_POSS);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_DEAD_MSK, hperh->init.lcd_dead << LCD_FCR_DEAD_POSS);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_PON_MSK, hperh->init.lcd_pon << LCD_FCR_PON_POSS);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_VGS_MSK, hperh->init.lcd_vgs << LCD_FCR_VGS_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_DUTY_MSK, hperh->init.lcd_duty << LCD_CR_DUTY_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_BIAS_MSK, hperh->init.lcd_bias << LCD_CR_BIAS_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_VBUFHD_MSK, hperh->init.lcd_vbufhd << LCD_CR_VBUFHD_POS);
MODIFY_REG(hperh->perh->CR, LCD_CR_VBUFLD_MSK, hperh->init.lcd_vbufld << LCD_CR_VBUFLD_POS);
MODIFY_REG(hperh->perh->CR, LCD_CR_DSHD_MSK, hperh->init.lcd_dshd << LCD_CR_DSHD_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_DSLD_MSK, hperh->init.lcd_dsld << LCD_CR_DSLD_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_RESHD_MSK, hperh->init.lcd_reshd << LCD_CR_RESHD_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_RESLD_MSK, hperh->init.lcd_resld << LCD_CR_RESLD_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_VSEL_MSK, hperh->init.lcd_vsel << LCD_CR_VSEL_POSS);
MODIFY_REG(hperh->perh->CR, LCD_CR_VCHPS_MSK, hperh->init.lcd_vchps << LCD_CR_VCHPS_POSS);
__UNLOCK(hperh);
return OK;
}
/**
* @brief Enables or disables the LCD controller.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param state: This parameter can be: ENABLE or DISABLE.
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_cmd(lcd_handle_t *hperh, type_func_t state)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_FUNC_STATE(state));
__LOCK(hperh);
MODIFY_REG(hperh->perh->CR, LCD_CR_OE_MSK, state << LCD_CR_OE_POS);
MODIFY_REG(hperh->perh->CR, LCD_CR_EN_MSK, state << LCD_CR_EN_POS);
__UNLOCK(hperh);
return OK;
}
/**
* @}
*/
/** @defgroup LCD_Public_Functions_Group2 Config output functions
* @brief Config output and blink functions
* @{
*/
/**
* @brief Configures the LCD blink mode and blink frequency.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param blink_mode: Specifies the LCD blink mode.
* @param blink_freq: Specifies the LCD blink frequency.
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_blink_config(lcd_handle_t *hperh, lcd_blink_t blink_mode, lcd_blfrq_t blink_freq)
{
uint16_t delay = 0;
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_BLINK_MODE(blink_mode));
assert_param(IS_LCD_BLFRQ_TYPE(blink_freq));
__LOCK(hperh);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_BLMOD_MSK, blink_mode << LCD_FCR_BLMOD_POSS);
for (delay = 0; delay < 3000; delay++);
MODIFY_REG(hperh->perh->FCR, LCD_FCR_BLFRQ_MSK, blink_freq << LCD_FCR_BLFRQ_POSS);
__UNLOCK(hperh);
return OK;
}
/**
* @brief Control segment port enable or disable
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param seg: Specifies the LCD segment index
* @param seg_data: Specifies LCD segment data to be written to control segment output enable.
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_write_seg(lcd_handle_t *hperh, lcd_seg_t seg, uint32_t seg_data)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_SEG_TYPE(seg));
__LOCK(hperh);
if (seg == SEG_0_TO_31)
WRITE_REG(hperh->perh->SEGCR0, seg_data);
else
WRITE_REG(hperh->perh->SEGCR1, seg_data);
__UNLOCK(hperh);
return OK;
}
/**
* @brief Writes a word in the specific LCD buffer to determine display.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param buf: Specifies the LCD buffer index.
* @param buf_data: Specifies LCD buffer data to be written to control display.
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_write(lcd_handle_t *hperh, uint8_t buf, uint32_t buf_data)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_BUFFER_TYPE(buf));
__LOCK(hperh);
WRITE_REG(hperh->perh->BUF[buf], buf_data);
__UNLOCK(hperh);
return OK;
}
/**
* @}
*/
/** @defgroup LCD_Public_Functions_Group3 Peripheral State functions
* @brief LCD State functions
* @{
*/
/**
* @brief Checks whether the specified LCD flag is set or not.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param lcd_status: Specifies the flag to check.
* @retval The new state of LCD_STATUS
*/
uint32_t lcd_get_status(lcd_handle_t *hperh, lcd_status_t lcd_status)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_STATUS_TYPE(lcd_status));
if (lcd_status == LCD_STATUS_ALL)
return hperh->perh->SR;
else
return hperh->perh->SR & lcd_status ? 1 : 0;
}
/**
* @}
*/
/** @defgroup LCD_Public_Functions_Group4 Interrupt functions
* @brief LCD Interrupt functions
* @{
*/
/**
* @brief Enable or disable the specified interrupt
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param it: Specifies the interrupt type to be enabled or disabled
* @arg @ref LCD_IT_SOF Start of frame interrupt enable
* @arg @ref LCD_IT_UDD Update display done interrupt
* @param state: New state of the specified interrupt.
* This parameter can be: ENABLE or DISABLE
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_interrupt_config(lcd_handle_t *hperh, lcd_it_t it, type_func_t state)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_IT_TYPE(it));
assert_param(IS_FUNC_STATE(state));
__LOCK(hperh);
if (state)
SET_BIT(hperh->perh->IE, it);
else
CLEAR_BIT(hperh->perh->IE, it);
__UNLOCK(hperh);
return OK;
}
/**
* @brief Checks whether the specified interrupt has set or not.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param it: Specifies the interrupt type to check
* This parameter can be one of the following values:
* @arg @ref LCD_IT_SOF Start of frame interrupt enable
* @arg @ref LCD_IT_UDD Update display done interrupt
* @retval The new state of the LCD_IT
*/
flag_status_t lcd_get_it_status(lcd_handle_t *hperh, lcd_it_t it)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_IT_TYPE(it));
return hperh->perh->IE & it ? SET : RESET;
}
/**
* @brief Checks whether the specified interrupt has occurred or not.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param flag: Specifies the interrupt type to check
* This parameter can be one of the following values:
* @arg @ref LCD_FLAG_SOF Start of frame interrupt enable
* @arg @ref LCD_FLAG_UDD Update display done interrupt
* @retval The new state of the LCD_IT
*/
it_status_t lcd_get_flag_status(lcd_handle_t *hperh, lcd_flag_t flag)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_FLAG_TYPE(flag));
return hperh->perh->IF & flag ? SET : RESET;
}
/**
* @brief Clear interrupt state flag
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @param flag: Specifies the interrupt type to clear
* This parameter can be one of the following values:
* @arg @ref LCD_FLAG_SOF Start of frame interrupt enable
* @arg @ref LCD_FLAG_UDD Update display done interrupt
* @retval Status, see @ref ald_status_t.
*/
ald_status_t lcd_clear_flag_status(lcd_handle_t *hperh, lcd_flag_t flag)
{
assert_param(IS_LCD_PERH_TYPE(hperh->perh));
assert_param(IS_LCD_FLAG_TYPE(flag));
__LOCK(hperh);
WRITE_REG(hperh->perh->IFCR, flag);
__UNLOCK(hperh);
return OK;
}
/**
* @brief This function handles LCD event interrupt request.
* @param hperh: Pointer to a lcd_handle_t structure that contains
* the configuration information for the specified LCD.
* @retval None
*/
void lcd_irq_handler(lcd_handle_t *hperh)
{
if (lcd_get_flag_status(hperh, LCD_FLAG_UDD)) {
lcd_clear_flag_status(hperh, LCD_FLAG_UDD);
if (hperh->display_cplt_cbk)
hperh->display_cplt_cbk(hperh);
}
if (lcd_get_flag_status(hperh, LCD_FLAG_SOF)) {
lcd_clear_flag_status(hperh, LCD_FLAG_SOF);
if (hperh->frame_start_cbk)
hperh->frame_start_cbk(hperh);
}
return;
}
/**
* @}
*/
/**
* @}
*/
#endif /* ALD_LCD */
/**
* @}
*/
/**
* @}
*/
|