FreeCalypso > hg > tcs211-c139
comparison chipsetsw/drivers/drv_app/r2d/lcds/E_Sample/lcd_if.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /****************************************************************************** | |
2 * WIRELESS COMMUNICATION SYSTEM DEVELOPMENT | |
3 * | |
4 * (C) 2002 Texas Instruments France. All rights reserved | |
5 * | |
6 * Author : Philippe MARTINEZ | |
7 * | |
8 * | |
9 * Important Note | |
10 * -------------- | |
11 * | |
12 * This S/W is a preliminary version. It contains information on a product | |
13 * under development and is issued for evaluation purposes only. Features | |
14 * characteristics, data and other information are subject to change. | |
15 * | |
16 * The S/W is furnished under Non Disclosure Agreement and may be used or | |
17 * copied only in accordance with the terms of the agreement. It is an offence | |
18 * to copy the software in any way except as specifically set out in the | |
19 * agreement. No part of this document may be reproduced or transmitted in any | |
20 * form or by any means, electronic or mechanical, including photocopying and | |
21 * recording, for any purpose without the express written permission of Texas | |
22 * Instruments Inc. | |
23 * | |
24 ****************************************************************************** | |
25 * | |
26 * FILE NAME: lcd_if.c | |
27 * | |
28 * | |
29 * PURPOSE: LCD Interface driver compiled in 16-bits mode (thumb mode) | |
30 * | |
31 * | |
32 * FILE REFERENCES: | |
33 * | |
34 * Name IO Description | |
35 * ------------- -- --------------------------------------------- | |
36 * | |
37 * | |
38 * | |
39 * EXTERNAL VARIABLES: | |
40 * | |
41 * Source: | |
42 * | |
43 * Name Type IO Description | |
44 * ------------- --------------- -- ------------------------------ | |
45 * | |
46 * | |
47 * | |
48 * EXTERNAL REFERENCES: | |
49 * | |
50 * Name Description | |
51 * ------------------ ------------------------------------------------------- | |
52 * | |
53 * | |
54 * | |
55 * ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES: | |
56 * | |
57 * | |
58 * | |
59 * ASSUMPTION, CONSTRAINTS, RESTRICTIONS: | |
60 * | |
61 * | |
62 * | |
63 * NOTES: | |
64 * | |
65 * | |
66 * | |
67 * REQUIREMENTS/FUNCTIONAL SPECIFICATION REFERENCES: | |
68 * | |
69 * | |
70 * | |
71 * | |
72 * DEVELOPMENT HISTORY: | |
73 * | |
74 * Date Name(s) Version Description | |
75 * ----------- -------------- ------- ------------------------------------- | |
76 * 30-Oct-2002 Philippe MARTINEZ 0.0.1 First implementation | |
77 * | |
78 * ALGORITHM: | |
79 * | |
80 * | |
81 *****************************************************************************/ | |
82 | |
83 #include "r2d/lcds/e_sample/lcd_if.h" | |
84 #include "memif/mem.h" | |
85 | |
86 | |
87 /**************************************************************************** | |
88 * GLOBAL VARIABLES | |
89 ***************************************************************************/ | |
90 | |
91 /* internal structure instance */ | |
92 | |
93 T_LCD_IF_INTERNAL d_lcd_if_internal; | |
94 | |
95 /**************************************************************************** | |
96 * INTERNAL FUNCTION PROTOTYPE | |
97 ***************************************************************************/ | |
98 | |
99 void f_lcd_if_set_cs_and_data_type( E_LCD_IF_CS d_cs, | |
100 E_LCD_IF_DATA_TYPE d_type, | |
101 E_LCD_IF_DATA_ACCESS d_access ); | |
102 | |
103 static E_LCD_IF_CALLBACK_RET f_lcd_if_dummy_callback( void ); | |
104 | |
105 | |
106 | |
107 /****************************************************************************** | |
108 * | |
109 * FUNCTION NAME: f_lcd_if_init | |
110 * | |
111 * Initialize the internal initialization structure. | |
112 * | |
113 * | |
114 * ARGUMENT LIST: | |
115 * | |
116 * Argument Type IO Description | |
117 * ------------ ------------------- -- --------------------------------- | |
118 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
119 * p_init T_LCD_IF_INIT* I Pointer on the external initialization | |
120 * structure | |
121 * RETURN VALUE: None | |
122 * | |
123 *****************************************************************************/ | |
124 | |
125 void f_lcd_if_init( E_LCD_IF_CS d_cs, T_LCD_IF_INIT *p_init ) | |
126 { | |
127 | |
128 /* reset internal state to IDLE */ | |
129 | |
130 d_lcd_if_internal.d_interrupt_state = C_LCD_IF_IDLE; | |
131 | |
132 /* What is the chip select value ? */ | |
133 | |
134 if( d_cs == C_LCD_IF_CS_NOT_SELECTED ) | |
135 { | |
136 /* not a valid CS */ | |
137 return; | |
138 } // End if | |
139 | |
140 /* update current struct pointer */ | |
141 | |
142 //d_lcd_if_internal.p_current_struct = &d_lcd_if_internal.d_cs_struct[d_cs]; | |
143 | |
144 /* Copy the LCD manager init structure to the internal structure */ | |
145 /* and initialize the internal structure */ | |
146 | |
147 d_lcd_if_internal.d_cs_struct[d_cs].d_mode = p_init->d_mode; | |
148 d_lcd_if_internal.d_cs_struct[d_cs].b_flip_bytes = p_init->b_flip_bytes; | |
149 d_lcd_if_internal.d_cs_struct[d_cs].d_isll = p_init->d_isll; | |
150 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.d_clock_divider = p_init->d_tx_init.d_clock_divider; | |
151 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_callback = f_lcd_if_dummy_callback; | |
152 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_buffer = (SYS_UWORD16*) NULL; | |
153 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.d_buffer_size = 0; | |
154 d_lcd_if_internal.d_cs_struct[d_cs].d_rx.d_clock_divider = p_init->d_rx_init.d_clock_divider; | |
155 d_lcd_if_internal.d_cs_struct[d_cs].d_rx.d_dummy_cycles = p_init->d_rx_init.d_dummy_cycles; | |
156 | |
157 /* compose the CNTL_REG and LCD_CNTL_REG bit fields */ | |
158 | |
159 d_lcd_if_internal.d_cs_struct[d_cs].d_cntl_reg = | |
160 (C_LCD_IF_CNTL_REG_SOFT_NRST_INIT << C_LCD_IF_CNTL_REG_SOFT_NRST_POS) | | |
161 (C_LCD_IF_CNTL_REG_CLOCK13_EN_INIT << C_LCD_IF_CNTL_REG_CLOCK13_EN_POS) | | |
162 (d_lcd_if_internal.d_cs_struct[d_cs].d_tx.d_clock_divider << C_LCD_IF_CNTL_REG_TX_CLOCK_DIV_POS) | | |
163 (d_lcd_if_internal.d_cs_struct[d_cs].d_rx.d_clock_divider << C_LCD_IF_CNTL_REG_RX_CLOCK_DIV_POS) | | |
164 (C_LCD_IF_CNTL_REG_FIFO_EMPTY_IT_EN_INIT << C_LCD_IF_CNTL_REG_FIFO_EMPTY_IT_EN_POS) | | |
165 (C_LCD_IF_CNTL_REG_LCD_READ_EVENT_IT_EN_INIT << C_LCD_IF_CNTL_REG_LCD_READ_EVENT_IT_EN_POS) | | |
166 (C_LCD_IF_CNTL_REG_DMA_EN_INIT << C_LCD_IF_CNTL_REG_DMA_EN_POS) | | |
167 (d_lcd_if_internal.d_cs_struct[d_cs].d_mode << C_LCD_IF_CNTL_REG_MODE_POS) | | |
168 (d_lcd_if_internal.d_cs_struct[d_cs].b_flip_bytes << C_LCD_IF_CNTL_REG_FLIP_BYTES_POS) | | |
169 (C_LCD_IF_CNTL_REG_SUSPEND_EN_INIT << C_LCD_IF_CNTL_REG_SUSPEND_EN_POS) | | |
170 (C_LCD_IF_CNTL_REG_MIN_FRAME_SIZE_INIT << C_LCD_IF_CNTL_REG_MIN_FRAME_SIZE_POS) | | |
171 (d_lcd_if_internal.d_cs_struct[d_cs].d_rx.d_dummy_cycles << C_LCD_IF_CNTL_REG_N_DUMMY_POS); | |
172 | |
173 d_lcd_if_internal.d_cs_struct[d_cs].d_lcd_cntl_reg = | |
174 (d_cs << C_LCD_IF_LCD_CNTL_REG_LCD_NCS0_POS) | | |
175 (C_LCD_IF_LCD_CNTL_REG_LCD_RS_INIT << C_LCD_IF_LCD_CNTL_REG_LCD_RS_POS) | | |
176 (C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_INIT << C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_POS) | | |
177 (C_LCD_IF_LCD_CNTL_REG_LCD_NRESET_INIT << C_LCD_IF_LCD_CNTL_REG_LCD_NRESET_POS) | | |
178 (~d_cs << C_LCD_IF_LCD_CNTL_REG_LCD_NCS1_POS); | |
179 | |
180 /* Force Switch to Chip select */ | |
181 | |
182 d_lcd_if_internal.d_current_cs = C_LCD_IF_CS_NOT_SELECTED; | |
183 | |
184 /* Switch to chip select */ | |
185 /* Set data type and access to instruction (arbitrary) and write */ | |
186 | |
187 f_lcd_if_set_cs_and_data_type( d_cs, C_LCD_IF_INSTRUCTION, C_LCD_IF_WRITE ); | |
188 | |
189 } /* f_lcd_if_init */ | |
190 | |
191 /****************************************************************************** | |
192 * | |
193 * FUNCTION NAME: f_lcd_if_reset | |
194 * | |
195 * Reset the LCD Interface Hardware. | |
196 * | |
197 * | |
198 * ARGUMENT LIST: | |
199 * | |
200 * Argument Type IO Description | |
201 * ------------ ------------------- -- --------------------------------- | |
202 * None | |
203 * | |
204 * RETURN VALUE: None | |
205 * | |
206 *****************************************************************************/ | |
207 | |
208 void f_lcd_if_reset( void ) | |
209 { | |
210 /* Reset CNTL_REG:SOFT_NRST bit */ | |
211 | |
212 (*(volatile SYS_UWORD16*) C_LCD_IF_CNTL_REG) &= ~(C_LCD_IF_CNTL_REG_SOFT_NRST_MASK); | |
213 | |
214 /* loop to wait for CNTL_REG:SOFT_NRST bit return back to 1 */ | |
215 | |
216 F_LCD_IF_WAIT_LCD_IF_RESET; | |
217 | |
218 } /* f_lcd_if_reset */ | |
219 | |
220 /****************************************************************************** | |
221 * | |
222 * FUNCTION NAME: f_lcd_if_get_version | |
223 * | |
224 * Return the LCD Interface driver version. | |
225 * | |
226 * | |
227 * ARGUMENT LIST: | |
228 * | |
229 * Argument Type IO Description | |
230 * ------------ ------------------- -- --------------------------------- | |
231 * None | |
232 * | |
233 * RETURN VALUE: SYS_UWORD16 : Version number. | |
234 * | |
235 *****************************************************************************/ | |
236 | |
237 SYS_UWORD16 f_lcd_if_get_version( void ) | |
238 { | |
239 return ((SYS_UWORD16) C_LCD_IF_DRIVER_VERSION); | |
240 } /* f_lcd_if_get_version */ | |
241 | |
242 /****************************************************************************** | |
243 * | |
244 * FUNCTION NAME: f_lcd_if_reset_lcd_controller | |
245 * | |
246 * Resets the LCD Controller hardware. | |
247 * | |
248 * | |
249 * ARGUMENT LIST: | |
250 * | |
251 * Argument Type IO Description | |
252 * ------------ ------------------- -- --------------------------------- | |
253 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
254 * d_reset E_LCD_IF_RESET I ON => reset state | |
255 * | |
256 * RETURN VALUE: None | |
257 * | |
258 *****************************************************************************/ | |
259 | |
260 void f_lcd_if_reset_lcd_controller( E_LCD_IF_CS d_cs, | |
261 E_LCD_IF_RESET d_reset ) | |
262 { | |
263 /* Switch to chip select */ | |
264 /* Set data type and access to instruction (arbitrary) and write */ | |
265 | |
266 f_lcd_if_set_cs_and_data_type( d_cs, C_LCD_IF_INSTRUCTION, C_LCD_IF_WRITE ); | |
267 | |
268 /* Apply the LCD Controller reset on the LCD Interface line (LCD_CNTL_REG:LCD_nRESET bit) */ | |
269 if( d_reset == C_LCD_IF_OFF) | |
270 { | |
271 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) |= (d_reset << C_LCD_IF_LCD_CNTL_REG_LCD_NRESET_POS); | |
272 } | |
273 else | |
274 { | |
275 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) &= ~(d_reset << C_LCD_IF_LCD_CNTL_REG_LCD_NRESET_POS); | |
276 } // End if | |
277 | |
278 } /* f_lcd_if_reset_lcd_controller */ | |
279 | |
280 /****************************************************************************** | |
281 * | |
282 * FUNCTION NAME: f_lcd_if_clock | |
283 * | |
284 * Enable/disable the LCD Interface 13 MHx clock in. | |
285 * | |
286 * | |
287 * ARGUMENT LIST: | |
288 * | |
289 * Argument Type IO Description | |
290 * ------------ ------------------- -- --------------------------------- | |
291 * d_clock_switch E_LCD_IF_CLOCK I CLOCK_ON/CLOCK_OFF state | |
292 * | |
293 * RETURN VALUE: None | |
294 * | |
295 *****************************************************************************/ | |
296 | |
297 void f_lcd_if_clock( E_LCD_IF_CLOCK d_clock_switch ) | |
298 { | |
299 /* write argument into CNTL_REG:CLOCK13_EN bit */ | |
300 | |
301 if( d_clock_switch == C_LCD_IF_CLOCK_ON ) | |
302 { | |
303 (*(volatile SYS_UWORD16*) C_LCD_IF_CNTL_REG) |= (d_clock_switch << C_LCD_IF_CNTL_REG_CLOCK13_EN_POS); | |
304 } | |
305 else | |
306 { | |
307 (*(volatile SYS_UWORD16*) C_LCD_IF_CNTL_REG) &= ~(d_clock_switch << C_LCD_IF_CNTL_REG_CLOCK13_EN_POS); | |
308 } // End if | |
309 | |
310 } /* f_lcd_if_clock */ | |
311 | |
312 /****************************************************************************** | |
313 * | |
314 * FUNCTION NAME: f_lcd_if_poll_write | |
315 * | |
316 * LCD Controller write procedure in polling mode. | |
317 * | |
318 * | |
319 * ARGUMENT LIST: | |
320 * | |
321 * Argument Type IO Description | |
322 * ------------ ------------------- -- --------------------------------- | |
323 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
324 * p_data SYS_UWORD16* I pointer on data buffer | |
325 * d_size SYS_UWORD32 I data buffe size | |
326 * d_type E_LCD_IF_DATA_TYPE I Instruction / Data type selector | |
327 * | |
328 * RETURN VALUE: None | |
329 * | |
330 *****************************************************************************/ | |
331 | |
332 void f_lcd_if_poll_write( E_LCD_IF_CS d_cs, | |
333 SYS_UWORD16 *p_data, | |
334 SYS_UWORD32 d_size, | |
335 E_LCD_IF_DATA_TYPE d_type ) | |
336 { | |
337 | |
338 SYS_UWORD32 d_nb_words_to_copy = d_size; | |
339 SYS_UWORD32 d_nb_words_in_loop = 0; | |
340 SYS_UWORD16 *p_buffer = p_data; | |
341 SYS_UWORD8 d_data_type = 0; | |
342 SYS_UWORD8 i = 0; | |
343 | |
344 /* Switch to chip select */ | |
345 /* Set data type and access */ | |
346 | |
347 f_lcd_if_set_cs_and_data_type( d_cs, d_type, C_LCD_IF_WRITE ); | |
348 | |
349 /* infinite loop : exit loop when no words to copy and Tx FIFO empty */ | |
350 | |
351 while( C_LCD_IF_INFINITE_LOOP ) | |
352 { | |
353 | |
354 /* Wait for the LCD Interface Tx FIFO is empty LCD_IF_STS_REG:FIFO_EMPTY_STATUS_BIT */ | |
355 | |
356 F_LCD_IF_WAIT_TX_FIFO_EMPTY; | |
357 | |
358 /* Check if all data have been copied */ | |
359 | |
360 if( d_nb_words_to_copy == 0 ) | |
361 { | |
362 return; | |
363 } // End if | |
364 | |
365 /* Copy up to C_LCD_IF_TX_FIFO_SIZE words into the TX FIFO. */ | |
366 | |
367 if( d_nb_words_to_copy >= C_LCD_IF_TX_FIFO_SIZE) | |
368 { | |
369 d_nb_words_in_loop = C_LCD_IF_TX_FIFO_SIZE; | |
370 } | |
371 else | |
372 { | |
373 d_nb_words_in_loop = d_nb_words_to_copy; | |
374 } // End if | |
375 | |
376 for( i=0; i<d_nb_words_in_loop ;i++ ) | |
377 { | |
378 F_LCD_IF_WRITE_IN_FIFO( p_buffer[i] ); | |
379 } // End for | |
380 | |
381 /* update d_nb_words_to copy and p_buffer */ | |
382 d_nb_words_to_copy -= d_nb_words_in_loop; | |
383 p_buffer += d_nb_words_in_loop; | |
384 | |
385 } // End while | |
386 | |
387 } /* f_lcd_if_poll_write */ | |
388 | |
389 /****************************************************************************** | |
390 * | |
391 * FUNCTION NAME: f_lcd_if_poll_read | |
392 * | |
393 * LCD Controller read procedure in polling mode. | |
394 * | |
395 * | |
396 * ARGUMENT LIST: | |
397 * | |
398 * Argument Type IO Description | |
399 * ------------ ------------------- -- --------------------------------- | |
400 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
401 * d_type E_LCD_IF_DATA_TYPE I Instruction / Data type selector | |
402 * | |
403 * RETURN VALUE: SYS_UWORD16 : read data word | |
404 * | |
405 *****************************************************************************/ | |
406 | |
407 SYS_UWORD16 f_lcd_if_poll_read( E_LCD_IF_CS d_cs, | |
408 E_LCD_IF_DATA_TYPE d_type ) | |
409 { | |
410 | |
411 SYS_UWORD8 d_data_type = 0; | |
412 | |
413 /* Switch to chip select */ | |
414 /* Set data type and access */ | |
415 | |
416 f_lcd_if_set_cs_and_data_type( d_cs, d_type, C_LCD_IF_READ ); | |
417 | |
418 /* Wait for data received from the LCD Controller hardware */ | |
419 | |
420 F_LCD_IF_WAIT_READ_STATUS; | |
421 | |
422 /* retrieve data read */ | |
423 | |
424 return (*(volatile SYS_UWORD16*) C_LCD_IF_RD_REG); | |
425 | |
426 } /* f_lcd_if_poll_read */ | |
427 | |
428 /****************************************************************************** | |
429 * | |
430 * FUNCTION NAME: f_lcd_if_it_write | |
431 * | |
432 * LCD Controller write procedure in interrupt mode. | |
433 * Direct access to the data buffer | |
434 * | |
435 * ARGUMENT LIST: | |
436 * | |
437 * Argument Type IO Description | |
438 * ------------ ------------------- -- --------------------------------- | |
439 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
440 * p_buffer SYS_UWORD16 I Pointer to the data buffer | |
441 * d_size SYS_UWORD32 I Data buffer size | |
442 * d_type E_LCD_IF_DATA_TYPE I Instruction / Data type selector | |
443 * pf_callback_sts T_LCD_IF_CALLBACK I Status callback function pointer. | |
444 * | |
445 * RETURN VALUE: E_LCD_IF_RET function status. | |
446 * | |
447 *****************************************************************************/ | |
448 | |
449 E_LCD_IF_RET f_lcd_if_it_write( E_LCD_IF_CS d_cs, | |
450 SYS_UWORD16 *p_buffer, | |
451 SYS_UWORD32 d_size, | |
452 E_LCD_IF_DATA_TYPE d_type, | |
453 T_LCD_IF_CALLBACK pf_callback_sts ) | |
454 { | |
455 | |
456 SYS_UWORD8 d_data_type = 0; | |
457 | |
458 /* Check the callback function argument */ | |
459 | |
460 if( pf_callback_sts == (T_LCD_IF_CALLBACK) NULL ) | |
461 return( C_LCD_IF_RET_ERR ); | |
462 | |
463 /* Switch to chip select */ | |
464 /* Set data type and access */ | |
465 | |
466 f_lcd_if_set_cs_and_data_type( d_cs, d_type, C_LCD_IF_WRITE ); | |
467 | |
468 /* save buffer references and install status callback function */ | |
469 | |
470 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_callback = pf_callback_sts; | |
471 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_buffer = p_buffer; | |
472 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.d_buffer_size = d_size; | |
473 | |
474 /* set d_interrupt_state to C_LCD_IF_IT_BUFF */ | |
475 | |
476 d_lcd_if_internal.d_interrupt_state = C_LCD_IF_IT_BUFF; | |
477 | |
478 /* Enable LCD Interface TX FIFO Empty interrupt */ | |
479 | |
480 F_LCD_IF_ENABLE_TX_FIFO_EMPTY_IT; | |
481 | |
482 return( C_LCD_IF_RET_OK ); | |
483 | |
484 } /* f_lcd_if_it_write */ | |
485 | |
486 /****************************************************************************** | |
487 * | |
488 * FUNCTION NAME: f_lcd_if_it_write_cust | |
489 * | |
490 * LCD Controller write procedure in interrupt mode. | |
491 * LCD Controller Tx FIFO copy done by transmit callback function. | |
492 * | |
493 * ARGUMENT LIST: | |
494 * | |
495 * Argument Type IO Description | |
496 * ------------ ------------------- -- --------------------------------- | |
497 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
498 * d_type E_LCD_IF_DATA_TYPE I Instruction / Data type selector | |
499 * pf_callback_tx T_LCD_IF_CALLBACK I Transmit callback function pointer. | |
500 * | |
501 * RETURN VALUE: E_LCD_IF_RET function status. | |
502 * | |
503 *****************************************************************************/ | |
504 | |
505 E_LCD_IF_RET f_lcd_if_it_write_cust( E_LCD_IF_CS d_cs, | |
506 E_LCD_IF_DATA_TYPE d_type, | |
507 T_LCD_IF_CALLBACK pf_callback_tx ) | |
508 { | |
509 | |
510 SYS_UWORD8 d_data_type = 0; | |
511 | |
512 /* Check the callback function argument */ | |
513 | |
514 if( pf_callback_tx == (T_LCD_IF_CALLBACK) NULL ) | |
515 return( C_LCD_IF_RET_ERR ); | |
516 | |
517 /* Switch to chip select */ | |
518 /* Set data type and access */ | |
519 | |
520 f_lcd_if_set_cs_and_data_type( d_cs, d_type, C_LCD_IF_WRITE ); | |
521 | |
522 /* install transmit callback function */ | |
523 | |
524 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_callback = pf_callback_tx; | |
525 | |
526 /* set d_interrupt_state to C_LCD_IF_IT_CUST */ | |
527 | |
528 d_lcd_if_internal.d_interrupt_state = C_LCD_IF_IT_CUST; | |
529 | |
530 /* Enable LCD Interface TX FIFO Empty interrupt */ | |
531 | |
532 F_LCD_IF_ENABLE_TX_FIFO_EMPTY_IT; | |
533 | |
534 return( C_LCD_IF_RET_OK ); | |
535 | |
536 } /* f_lcd_if_it_write_cust */ | |
537 | |
538 /****************************************************************************** | |
539 * | |
540 * FUNCTION NAME: f_lcd_if_dma_enable | |
541 * | |
542 * LCD Controller write procedure start in DMA mode. | |
543 * | |
544 * ARGUMENT LIST: | |
545 * | |
546 * Argument Type IO Description | |
547 * ------------ ------------------- -- --------------------------------- | |
548 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
549 * d_min_frame_sz E_LCD_IF_FRAME_SZ I LCD Interface Minimum frame size | |
550 * d_type E_LCD_IF_DATA_TYPE I Instruction / Data type selector | |
551 * | |
552 * RETURN VALUE: None. | |
553 * | |
554 *****************************************************************************/ | |
555 | |
556 void f_lcd_if_dma_enable( E_LCD_IF_CS d_cs, | |
557 E_LCD_IF_FRAME_SZ d_min_frame_sz, | |
558 E_LCD_IF_DATA_TYPE d_type ) | |
559 { | |
560 | |
561 SYS_UWORD8 d_data_type = 0; | |
562 | |
563 /* Switch to chip select */ | |
564 /* Set data type and access */ | |
565 | |
566 f_lcd_if_set_cs_and_data_type( d_cs, d_type, C_LCD_IF_WRITE ); | |
567 | |
568 /* enables DMA capabilities */ | |
569 | |
570 F_LCD_IF_ENABLE_DMA; | |
571 | |
572 } /* f_lcd_if_dma_enable */ | |
573 | |
574 /****************************************************************************** | |
575 * | |
576 * FUNCTION NAME: f_lcd_if_dma_disable | |
577 * | |
578 * LCD Controller write procedure stop in DMA mode. | |
579 * | |
580 * ARGUMENT LIST: | |
581 * | |
582 * Argument Type IO Description | |
583 * ------------ ------------------- -- --------------------------------- | |
584 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
585 * pf_callback_sts T_LCD_IF_CALLBACK I Status Callback function pointer | |
586 * | |
587 * RETURN VALUE: E_LCD_IF_RET function status. | |
588 * | |
589 *****************************************************************************/ | |
590 | |
591 | |
592 E_LCD_IF_RET f_lcd_if_dma_disable( E_LCD_IF_CS d_cs, | |
593 T_LCD_IF_CALLBACK pf_callback_sts ) | |
594 { | |
595 | |
596 /* Check the callback function argument */ | |
597 | |
598 if( pf_callback_sts == (T_LCD_IF_CALLBACK) NULL ) | |
599 return( C_LCD_IF_RET_ERR ); | |
600 | |
601 /* disable DMA capabilities */ | |
602 | |
603 F_LCD_IF_DISABLE_DMA; | |
604 | |
605 /* install status callback function */ | |
606 | |
607 d_lcd_if_internal.d_cs_struct[d_cs].d_tx.p_callback = pf_callback_sts; | |
608 | |
609 /* set d_interrupt_state to C_LCD_IF_IT_CUST */ | |
610 | |
611 d_lcd_if_internal.d_interrupt_state = C_LCD_IF_IT_CUST; | |
612 | |
613 /* Enable LCD Interface TX FIFO Empty interrupt */ | |
614 | |
615 F_LCD_IF_ENABLE_TX_FIFO_EMPTY_IT; | |
616 | |
617 return( C_LCD_IF_RET_OK ); | |
618 | |
619 } /* f_lcd_if_dma_disable */ | |
620 | |
621 /****************************************************************************** | |
622 * | |
623 * FUNCTION NAME: f_lcd_if_set_cs_and_data_type | |
624 * | |
625 * Updates CNTL_REG and LCD_CNTL_REG to change LCD Controller addressing. | |
626 * Updates LCD_CNTL_REG to set data type and read or write access | |
627 * | |
628 * ARGUMENT LIST: | |
629 * | |
630 * Argument Type IO Description | |
631 * ------------ ------------------- -- --------------------------------- | |
632 * d_cs E_LCD_IF_CS I LCD Controller Chip select | |
633 * d_type E_LCD_IF_DATA_TYPE I data type | |
634 * d_access E_LCD_IF_DATA_ACCESS I Data access | |
635 * | |
636 * RETURN VALUE: None | |
637 * | |
638 *****************************************************************************/ | |
639 | |
640 void f_lcd_if_set_cs_and_data_type( E_LCD_IF_CS d_cs, E_LCD_IF_DATA_TYPE d_type, E_LCD_IF_DATA_ACCESS d_access ) | |
641 { | |
642 | |
643 SYS_UWORD8 d_data_type; | |
644 | |
645 /* if the argument equals the current chip select, nothing to do */ | |
646 | |
647 if( d_lcd_if_internal.d_current_cs != d_cs ) | |
648 { | |
649 /* What is the chip select value ? */ | |
650 | |
651 if( d_cs == C_LCD_IF_CS_NOT_SELECTED ) | |
652 { | |
653 /* not a valid CS */ | |
654 return; | |
655 } // End if | |
656 | |
657 /* update current struct pointer */ | |
658 | |
659 //d_lcd_if_internal.p_current_struct = &d_lcd_if_internal.d_cs_struct[d_cs]; | |
660 | |
661 | |
662 /* Update CNTL_REG register and LCD_CNTL_REG to the new chip select */ | |
663 /* The CNTL_REG:CLOCK_EN bit is set to Clock enable */ | |
664 | |
665 (*(volatile SYS_UWORD16*) C_LCD_IF_CNTL_REG) = d_lcd_if_internal.d_cs_struct[d_cs].d_cntl_reg; | |
666 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) = d_lcd_if_internal.d_cs_struct[d_cs].d_lcd_cntl_reg; | |
667 | |
668 /* update d_current_cs */ | |
669 | |
670 d_lcd_if_internal.d_current_cs = d_cs; | |
671 | |
672 } // End if | |
673 | |
674 /* Sets LCD_CNTL_REG:LCD_RS to type defined in argument and start read */ | |
675 | |
676 if( d_type == C_LCD_IF_INSTRUCTION ) | |
677 { | |
678 d_data_type = (SYS_UWORD8) d_lcd_if_internal.d_cs_struct[d_cs].d_isll; | |
679 } | |
680 else | |
681 { | |
682 d_data_type = (SYS_UWORD8) ~d_lcd_if_internal.d_cs_struct[d_cs].d_isll; | |
683 } // End if | |
684 | |
685 if( d_data_type == 0 ) | |
686 { | |
687 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) &= ~( 0x01 << C_LCD_IF_LCD_CNTL_REG_LCD_RS_POS ); | |
688 } | |
689 else | |
690 { | |
691 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) |= ( 0x01 << C_LCD_IF_LCD_CNTL_REG_LCD_RS_POS ); | |
692 } // End if | |
693 | |
694 // Set access type | |
695 | |
696 if( d_access == C_LCD_IF_READ ) | |
697 { | |
698 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) |= | |
699 (C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_EN << C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_POS); | |
700 } | |
701 else | |
702 { | |
703 (*(volatile SYS_UWORD16*) C_LCD_IF_LCD_CNTL_REG) &= | |
704 ~(C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_EN << C_LCD_IF_LCD_CNTL_REG_LCD_START_READ_POS); | |
705 } // End if | |
706 | |
707 } /* f_lcd_if_set_cs_and_data_type */ | |
708 | |
709 /****************************************************************************** | |
710 * | |
711 * FUNCTION NAME: f_lcd_if_dummy_callback | |
712 * | |
713 * Dummy callback function for Internal structure initialization. | |
714 * | |
715 * | |
716 * ARGUMENT LIST: | |
717 * | |
718 * Argument Type IO Description | |
719 * ------------ ------------------- -- --------------------------------- | |
720 * None. | |
721 * | |
722 * RETURN VALUE: E_LCD_IF_CALLBACK_RET | |
723 * | |
724 *****************************************************************************/ | |
725 | |
726 static E_LCD_IF_CALLBACK_RET f_lcd_if_dummy_callback( void ) | |
727 { | |
728 /* EMPTY DUMMY FUNCTION */ | |
729 | |
730 } /* f_lcd_if_dummy_callback */ | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 /****************************************************************************** | |
737 * | |
738 * FUNCTION NAME: f_lcd_if_initialization | |
739 * | |
740 * | |
741 * | |
742 * ARGUMENT LIST: | |
743 * | |
744 * Argument Type IO Description | |
745 * ------------ ------------------- -- --------------------------------- | |
746 * None. | |
747 * | |
748 * RETURN VALUE: | |
749 * | |
750 *****************************************************************************/ | |
751 | |
752 void f_lcd_if_initialization( void ) | |
753 { | |
754 T_LCD_IF_INIT init_struct_ptr; | |
755 volatile SYS_UWORD8 i; | |
756 | |
757 init_struct_ptr.d_mode = C_LCD_IF_8086_MODE; | |
758 init_struct_ptr.b_flip_bytes = C_LCD_IF_LSB_FIRST; | |
759 init_struct_ptr.d_isll = C_LCD_IF_LOW; | |
760 init_struct_ptr.d_tx_init.d_clock_divider = C_LCD_IF_DIV8; | |
761 init_struct_ptr.d_rx_init.d_clock_divider = C_LCD_IF_DIV8; | |
762 init_struct_ptr.d_rx_init.d_dummy_cycles = C_LCD_IF_0_CYCLE; | |
763 | |
764 | |
765 f_lcd_if_reset(); | |
766 f_lcd_if_clock(C_LCD_IF_CLOCK_ON); | |
767 f_lcd_if_init(C_LCD_IF_CS0, &(init_struct_ptr) ); | |
768 f_lcd_if_reset_lcd_controller(C_LCD_IF_CS0, C_LCD_IF_ON); | |
769 for(i=0;i<10;i++); | |
770 f_lcd_if_reset_lcd_controller(C_LCD_IF_CS0, C_LCD_IF_OFF); | |
771 | |
772 } |