comparison g23m/condat/ms/src/mfw/mfw_kbd.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 +--------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_kbd.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 18 $|
5 | CREATED: 21.09.98 $Modtime:: 23.03.00 8:24 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_KBD
10
11 PURPOSE : keyboard handling functions
12
13 EXPORT :
14
15 TO DO : adjust PEI/driver interface
16
17 HISTORY :
18
19 xrashmic 22 Aug, 2004 MMI-SPR-32798
20 Adding the support for screen capture using a dynamically assigned key.
21
22 Apr 03, 2005 REF: CRR 29988 - xpradipg
23 Description: Optimisation 2: Reduce the keyboard buffer and the dtmf buffer
24 size
25 Solution : The keyboard buffer is reduced to 20 from 50
26
27 */
28
29 #define ENTITY_MFW
30
31 #include "typedefs.h"
32 #include "vsi.h"
33 #include "pei.h"
34 #include "custom.h"
35 #include "gsm.h"
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "mfw_mfw.h"
41 #include "mfw_sys.h"
42 #include "mfw_tim.h"
43 #include "drv_key.h"
44 #include "mfw_win.h"
45 #include "mfw_kbd.h"
46
47 /* BEGIN ADD: Req ID: : Sumit : 14-Mar-05 */
48 #ifndef NEPTUNE_BOARD
49 /* END ADD: Req ID: : Sumit : 14-Mar-05 */
50 #include "kpd/kpd_api.h"
51 /* BEGIN ADD: Req ID: : Sumit : 14-Mar-05 */
52 #else
53 #include "ti1_key.h"
54 #endif /* NEPTUNE_BOARD*/
55 /* END ADD: Req ID: : Sumit : 14-Mar-05 */
56
57 #include "mfw_ffs.h"
58 #include "mfw_utils.h"
59
60 #include "mfw_mme.h"
61
62
63 static int kbdCommand (U32 cmd, void *h);
64 static int toLong (U32 t, void *h);
65 static int toAuto (U32 t, void *h);
66
67 static MfwCb doAlways; /* all cases handler */
68 static MfwHdr timLongH; /* the long press timer */
69 static MfwTim timLong;
70 static MfwHdr timAutoH; /* the auto repeat timer */
71 static MfwTim timAuto;
72 static U32 valAuto; /* auto start intervall */
73 static U32 valRepeat; /* auto repeat intervall */
74 static U32 curMap; /* current key map */
75 static U8 curKey; /* current key code */
76
77 static int still_processing_flag;
78
79 // PATCH LE 06.06.00
80 // current MFW element needed for multiple instances
81 EXTERN MfwHdr * current_mfw_elem;
82 // END PATCH LE 06.06.00
83
84 /*
85 ** KeyPress Buffer Macros and Limits
86 */
87 // Apr 03, 2005 REF: CRR 29988 - xpradipg
88 // Keyboard buffer reduced from 50 to 20
89 #ifdef FF_MMI_REDUCED_KBD_BUFFER
90 #define MAX_KPRESS_BFR 20
91 #else
92 #define MAX_KPRESS_BFR 50
93 #endif
94 typedef struct keyPressDetailsTag {
95 char make;
96 char key;
97 } keyPressDetails;
98
99 static keyPressDetails keyPressBfr[MAX_KPRESS_BFR];
100 static SHORT mfw_kbd_kpress_buf_id;
101
102 extern void sendKeyInd( T_KPD_VIRTUAL_KEY_ID virtual_key_id,
103 T_KPD_KEY_STATE key_state,
104 T_KPD_PRESS_STATE press_state);
105 extern char drvGetKeyIndex( char key);
106
107 /*
108 +--------------------------------------------------------------------+
109 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
110 | STATE : code ROUTINE : kbdInit |
111 +--------------------------------------------------------------------+
112
113 PURPOSE : initialize keyboard handler
114
115 */
116
117 MfwRes kbdInit (void)
118 {
119 timLong.time = 0; /* setup long press timer */
120 timLong.left = 0;
121 timLong.handler = toLong;
122 timLong.next = 0;
123 timLongH.data = &timLong;
124 timLongH.type = MfwTypTim;
125
126 timAuto.time = 0; /* setup auto repeat timer */
127 timAuto.left = 0;
128 timAuto.handler = toAuto;
129 timAuto.next = 0;
130 timAutoH.data = &timAuto;
131 timAutoH.type = MfwTypTim;
132 valAuto = valRepeat = 0;
133
134 keyInit(kbdSignal); /* init keyboard driver */
135
136 mfwCommand[MfwTypKbd] = (MfwCb) kbdCommand;
137 doAlways = 0;
138
139 mfw_kbd_kpress_buf_id = mfw_cbuf_create(MAX_KPRESS_BFR,
140 sizeof(keyPressDetails),
141 FALSE,
142 0xFF,
143 TRUE,
144 keyPressBfr);
145
146 if (mfw_kbd_kpress_buf_id < 0)
147 TRACE_EVENT_P1("ERROR : mfw_cbuf_create failed with error value %d", mfw_kbd_kpress_buf_id);
148
149 return MfwResOk;
150 }
151
152
153 /*
154 +--------------------------------------------------------------------+
155 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
156 | STATE : code ROUTINE : kbdExit |
157 +--------------------------------------------------------------------+
158
159 PURPOSE : finalize keyboard handler
160
161 */
162
163 MfwRes kbdExit (void)
164 {
165 mfwCommand[MfwTypKbd] = 0;
166 keyExit();
167
168 return MfwResOk;
169 }
170
171
172 /*
173 +--------------------------------------------------------------------+
174 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
175 | STATE : code ROUTINE : kbdAlways |
176 +--------------------------------------------------------------------+
177
178 PURPOSE : create keyboard control for all events
179
180 */
181
182 MfwCb kbdAlways (MfwCb f)
183 {
184 MfwCb always = doAlways;
185
186 doAlways = f;
187 if (!f)
188 {
189 timStop(&timLongH);
190 timStop(&timAutoH);
191 }
192
193 return always;
194 }
195
196
197 /*
198 +--------------------------------------------------------------------+
199 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
200 | STATE : code ROUTINE : kbdTime |
201 +--------------------------------------------------------------------+
202
203 PURPOSE : define keyboard timeouts
204
205 */
206
207 void kbdTime (long tLong, long tAuto, long tRepeat)
208 {
209 timLong.time = tLong; /* setup long press timer */
210 timAuto.time = tAuto; /* setup auto repeat timer */
211 valAuto = tAuto; /* save auto start timeout */
212 valRepeat = tRepeat; /* save repeat intervall */
213 }
214
215
216 /*
217 +--------------------------------------------------------------------+
218 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
219 | STATE : code ROUTINE : kbdCreate |
220 +--------------------------------------------------------------------+
221
222 PURPOSE : create keyboard control
223
224 */
225
226 MfwHnd kbdCreate (MfwHnd w, MfwEvt e, MfwCb f)
227 {
228 MfwHdr *hdr = (MfwHdr *) mfwAlloc(sizeof(MfwHdr));
229 MfwKbd *kbd = (MfwKbd *) mfwAlloc(sizeof(MfwKbd));
230 MfwHdr *insert_status =0;
231
232 if (!hdr || !kbd)
233 {
234 TRACE_ERROR("ERROR: kbdCreate() Mem Alloc Failed.");
235
236 if(hdr)
237 mfwFree((U8*)hdr,sizeof(MfwHdr));
238 if(kbd)
239 mfwFree((U8*)kbd,sizeof(MfwKbd));
240 return 0;
241 }
242
243 kbd->map = e;
244 kbd->key = 0;
245 kbd->handler = f;
246
247 hdr->data = kbd;
248 hdr->type = MfwTypKbd;
249
250 insert_status = mfwInsert(w,hdr);
251
252 if(!insert_status)
253 {
254 TRACE_ERROR("ERROR: kbdCreate() Failed to Install Handler. ");
255 mfwFree((U8*)hdr,sizeof(MfwHdr));
256 mfwFree((U8*)kbd ,sizeof(MfwKbd));
257 return 0;
258 }
259 return insert_status;
260 }
261
262
263 /*
264 +--------------------------------------------------------------------+
265 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
266 | STATE : code ROUTINE : kbdDelete |
267 +--------------------------------------------------------------------+
268
269 PURPOSE : delete keyboard control
270
271 */
272
273 MfwRes kbdDelete (MfwHnd h)
274 {
275 MfwRes res;
276
277 if (!h)
278 return MfwResIllHnd;
279
280 res = (mfwRemove(h)) ? MfwResOk : MfwResIllHnd;
281
282 mfwFree(((MfwHdr *) h)->data,sizeof(MfwKbd));
283 mfwFree(h,sizeof(MfwHdr));
284
285 return res;
286 }
287
288
289 /*
290 +--------------------------------------------------------------------+
291 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
292 | STATE : code ROUTINE : sigExec |
293 +--------------------------------------------------------------------+
294
295 PURPOSE : execute keyboard signal
296 if the registered set of keys match the currently
297 pressed key, the event handler is called, if the
298 registered flags match the current flags according
299 to the following table:
300 M: Make/Break (key release events wanted)
301 L: Long press event (timeout set via kbdTime())
302 A: Auto repeat event (timing defined via kbdTime())
303
304 M 0 0 0 0 1 1 1 1
305 current event flags --------- L 0 0 0 0 0 0 1 1
306 A 0 0 0 0 0 1 0 1
307 M L A .................
308 0 0 0 . 0 0 0 0 1 0 0 0
309 0 0 1 . 0 0 0 0 1 1 0 1
310 registered 0 1 0 . 0 0 0 0 0 0 1 1
311 event ----------- 0 1 1 . 0 0 0 0 0 1 1 1
312 flags 1 0 0 . 1 1 1 1 1 0 0 0
313 1 0 1 . 1 1 1 1 1 1 0 1
314 1 1 0 . 1 1 1 1 0 0 1 1
315 1 1 1 . 1 1 1 1 0 1 1 1
316
317 */
318
319 static int sigExec (MfwHdr *curElem, U32 map, U8 key)
320 {
321 MfwKbd *kc;
322
323 while (curElem)
324 {
325 if (curElem->type == MfwTypKbd)
326 {
327 kc = curElem->data;
328 if (kc->map & map & ~KEY_FLAGS)
329 { /* keys match */
330 kc->code = key; /* set current key code */
331 if (map & KEY_MAKE)
332 {
333 kc->key |= map; /* set key in control block */
334 }
335 else
336 {
337 kc->key &= ~map; /* del key in control block */
338 kc->key &= ~KEY_MAKE; /* del make/break flag */
339 }
340 if ((KEY_MAKE & ~map & kc->map) ||
341 (KEY_MAKE & map &&
342 ((KEY_LONG & map & kc->map) ||
343 (!(KEY_LONG & kc->map)
344 && (KEY_AUTO & kc->map & map)) ||
345 (!(KEY_LONG & map)
346 && !(KEY_AUTO & map)
347 && !(KEY_LONG & kc->map)) ||
348 (!(KEY_LONG & map)
349 && (KEY_AUTO & map)
350 && (KEY_AUTO & kc->map)))))
351 {
352 if (kc->handler) /* handler valid */
353 {
354 // PATCH LE 06.06.00
355 // store current mfw elem
356 current_mfw_elem = curElem;
357 // END PATCH LE 06.06.00
358 if ((*(kc->handler))(map,kc))
359 return 1; /* event consumed */
360 }
361 }
362 }
363 }
364 curElem = curElem->next;
365 }
366
367 return 0;
368 }
369
370
371 /*
372 +--------------------------------------------------------------------+
373 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
374 | STATE : code ROUTINE : sigDistribute |
375 +--------------------------------------------------------------------+
376
377 PURPOSE : distribute keyboard event
378
379 */
380
381 static void sigDistribute (U32 map, U8 key)
382 {
383 int res = 0;
384
385 TRACE_EVENT("sigDistribute");
386
387 if (doAlways)
388 if (doAlways(map,(void*) -1))
389 return; /* event consumed */
390
391 if (mfwSignallingMethod == 0)
392 {
393 if (mfwFocus)
394 res = sigExec(mfwFocus,map,key);
395 if (!res && mfwRoot)
396 res = sigExec(mfwRoot,map,key);
397 }
398 else
399 {
400 MfwHdr *h = mfwFocus;
401 if (!h)
402 h = mfwRoot;
403 while (h)
404 {
405 if ((res = sigExec(h,map,key))) // RAVI - Introduced brackets.
406 break;
407 if (h == mfwRoot)
408 break;
409 h = mfwParent(mfwParent(h));
410 if (h)
411 h = ((MfwWin *)(h->data))->elems;
412 }
413 if (!res && mfwRoot && h != mfwRoot)
414 res = sigExec(mfwRoot,map,key);
415 }
416
417 if (doAlways)
418 doAlways(map,(void*) res);
419
420 return;
421 }
422
423
424 /*
425 +--------------------------------------------------------------------+
426 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
427 | STATE : code ROUTINE : kbdSignal |
428 +--------------------------------------------------------------------+
429
430 PURPOSE : keyboard event (called by driver/PEI)
431
432 */
433
434 #define MAX_CONSEC_KEYS 6 // Maximum number of keys which can be processed before
435 // allowing the protocol stack processing time
436 //xrashmic 22 Aug, 2004 MMI-SPR-32798
437 #ifdef MMI_EM_ENABLED
438 extern U8 screenCaptureKey;
439 void screen_capture(void);
440 #endif
441 void kbdSignal (char make, char key)
442 {
443 U32 map;
444 UBYTE temp ;
445 USHORT numElem;
446
447 int loopNo;
448 int keyNo;
449
450
451 if ((kbd_processKeyInput()== QUEUE_EVERY_KEY) ||
452 (kbd_processKeyInput()== QUEUE_N_KEYS))
453 temp = dspl_Enable(0);
454
455 mme_backlightEvent(BL_KEY_PRESS);
456
457 loopNo = 0;
458 keyNo = 0;
459
460 while (kbd_getMakeAndKey(&make,&key) != -1)
461 {
462 #ifdef MMI_EM_ENABLED
463 //xrashmic 22 Aug, 2004 MMI-SPR-32798
464 //If screen capture is enabled the key pressed is the screen capture key,
465 //we write the LCD buffer into the FFS and and consume the key
466 //event here itself without sending it to BMI
467 // Also the screen capture key will be disabled here
468 if(key== screenCaptureKey && make==1)
469 {
470 TRACE_EVENT("*****Capturing the screen");
471 screenCaptureKey=KCD_NONE;
472 screen_capture();
473 dspl_Enable(temp);
474 return;
475 }
476 #endif
477
478 still_processing_flag = 1;
479 TRACE_EVENT_P2("NDH : KbdSignal - key %d, state %02x", key, make);
480
481 if ((key >= 0) && (key <= KCD_MAX))
482 {
483 loopNo++;
484 keyNo++;
485
486 map = 1L << key;
487
488 if (make)
489 {
490 map |= KEY_MAKE;
491 curMap = map;
492 curKey = key;
493 timStart(&timLongH);
494 timAuto.time = valAuto;
495
496 /*NM, p007a*/
497 if (valAuto)
498 timStart(&timAutoH);
499 /*NM, p007a end*/
500
501 }
502 else
503 {
504 map &= ~KEY_MAKE;
505 curMap = map; //ES!!
506 curKey = key; //ES!!
507 timStop(&timLongH);
508
509 if (valAuto)
510 timStop(&timAutoH);
511 }
512
513 //Select when we update the display
514 switch (kbd_processKeyInput())
515 {
516 case QUEUE_EVERY_KEY:
517 sigDistribute(map,key);
518 break;
519
520 case PROCESS_EVERY_KEY:
521 temp = dspl_Enable(0);
522 sigDistribute(map,key);
523 dspl_Enable(temp);
524 break;
525
526 case QUEUE_N_KEYS:
527 if ((loopNo %(NUM_QUEUE_KEYS*2))==0)
528 {
529 kbd_setDisplayUpdateNeeded(1);
530 sigDistribute(map,key);
531 dspl_Enable(temp);
532 temp = dspl_Enable(0);
533 kbd_setDisplayUpdateNeeded(0);
534 }
535 else
536 sigDistribute(map,key);
537 break;
538 }
539 }
540
541 if (keyNo == MAX_CONSEC_KEYS)
542 {
543 still_processing_flag = FALSE;
544 break;
545 }
546
547 still_processing_flag = FALSE;
548 }
549
550 numElem = mfw_cbuf_num_elements(mfw_kbd_kpress_buf_id);
551 TRACE_EVENT_P2("NDH >>> Kbd :- There are %d elements in the buffer (id : %d)" ,
552 numElem, mfw_kbd_kpress_buf_id);
553
554 if ((keyNo == MAX_CONSEC_KEYS) && (numElem > 0))
555 {
556 sendKeyInd(0, 0, 0); // dummy values to trigger another keypress_ind
557 /*
558 ** This delay is required to slow down the BMI when no trace is being output in order
559 ** to permit the Protocol Stack & other tasks to function correctly
560 */
561 vsi_t_sleep (VSI_CALLER 30);
562 }
563
564 if ((kbd_processKeyInput()== QUEUE_EVERY_KEY) ||
565 (kbd_processKeyInput()== QUEUE_N_KEYS))
566 dspl_Enable(temp);
567
568 return;
569 }
570
571
572 /*
573 +--------------------------------------------------------------------+
574 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
575 | STATE : code ROUTINE : toLong |
576 +--------------------------------------------------------------------+
577
578 PURPOSE : long press timeout handler
579
580 */
581
582 static int toLong (U32 t, void *h)
583 {
584 curMap |= KEY_LONG;
585 sigDistribute(curMap,curKey);
586
587 return 0;
588 }
589
590
591 /*
592 +--------------------------------------------------------------------+
593 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
594 | STATE : code ROUTINE : toAuto |
595 +--------------------------------------------------------------------+
596
597 PURPOSE : auto repeat timeout handler
598
599 */
600
601 static int toAuto (U32 t, void *h)
602 {
603 curMap |= KEY_AUTO;
604 sigDistribute(curMap,curKey);
605 timAuto.time = valRepeat;
606 /* NM p007c*/
607 if (valRepeat)
608 timStart(&timAutoH);
609 /* NM p007c end*/
610 return 0;
611 }
612
613
614 /*
615 +--------------------------------------------------------------------+
616 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
617 | STATE : code ROUTINE : kbdCommand |
618 +--------------------------------------------------------------------+
619
620 PURPOSE : handle mfw windows command
621
622 */
623
624 static int kbdCommand (U32 cmd, void *h)
625 {
626 switch (cmd)
627 {
628 case MfwCmdDelete: /* delete me */
629 if (!h)
630 return 0;
631 kbdDelete(h);
632 return 1;
633 default:
634 break;
635 }
636
637 return 0;
638 }
639
640
641 /*
642 +--------------------------------------------------------------------+
643 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
644 | STATE : code ROUTINE : kbd_putMakeAndKey |
645 +--------------------------------------------------------------------+
646
647 PURPOSE : places 'make' (key up/down) and key index into a queue
648
649 */
650
651 int kbd_putMakeAndKey( char make, char key)
652 {
653 keyPressDetails localKP;
654 SHORT retVal;
655
656 localKP.make = make;
657 localKP.key = key;
658
659 retVal = mfw_cbuf_put(mfw_kbd_kpress_buf_id, &localKP);
660
661 if (retVal < 0)
662 TRACE_EVENT_P1("ERROR : mfw_cbuf_put failed with error value %d", retVal);
663
664 return (retVal);
665 }
666
667 /*
668 +--------------------------------------------------------------------+
669 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
670 | STATE : code ROUTINE : kbd_getMakeAndKey |
671 +--------------------------------------------------------------------+
672
673 PURPOSE : reads 'make' (key up/down) and key index into a queue
674 Return +ve number - keys left in buffer
675 0 - no keys left - last key press returned
676 -1 - no keys and none in buffer
677 */
678
679 int kbd_getMakeAndKey( char* make, char* key)
680 {
681 keyPressDetails localKP;
682 SHORT retVal;
683
684 retVal = mfw_cbuf_get(mfw_kbd_kpress_buf_id, &localKP);
685
686 if (retVal < 0)
687 {
688 *key = 0x7F;
689 *make = 0;
690 return (-1);
691 }
692
693 *make = !(localKP.make);
694 *key = drvGetKeyIndex(localKP.key);
695 return (mfw_cbuf_num_elements(mfw_kbd_kpress_buf_id));
696 }
697
698 /*
699 +--------------------------------------------------------------------+
700 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
701 | STATE : code ROUTINE : kbd_getNumElements |
702 +--------------------------------------------------------------------+
703
704 PURPOSE : returns number of elements in queue
705
706 */
707 int kbd_getNumElements(void)
708 {
709 return ((int)mfw_cbuf_num_elements(mfw_kbd_kpress_buf_id));
710 }
711
712 int kbd_stillProcessingKeys(void)
713 {
714 return (still_processing_flag);
715 }
716
717 int mfwKey_skipDisplay( void )
718 {
719 if ((mfw_cbuf_num_elements(mfw_kbd_kpress_buf_id) > 2) && (still_processing_flag == 1))
720 return (TRUE);
721 else
722 return (FALSE);
723 }
724
725 /*
726 +--------------------------------------------------------------------+
727 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
728 | STATE : code ROUTINE : kbd_displayUpdateNeeded |
729 +--------------------------------------------------------------------+
730
731 PURPOSE : returns TRUE if we need to update the display
732
733 */
734 int displayUpdateNeeded; //used for output every 'n' key presses
735 int kbd_displayUpdateNeeded(void)
736 {
737 if (kbd_processKeyInput()==PROCESS_EVERY_KEY)
738 return (TRUE);//Processing each key press - always update screen
739 else if (displayUpdateNeeded==0)
740 return (TRUE);//need to update the display (1 in 6 output)
741 else if (mfw_cbuf_num_elements(mfw_kbd_kpress_buf_id) > 1)
742 return (FALSE);//keys in queue - do not update
743 else
744 return (TRUE);//only 1 key up/down in queue - update display
745 }
746 /*
747 +--------------------------------------------------------------------+
748 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
749 | STATE : code ROUTINE : kbd_setDisplayUpdateNeeded |
750 +--------------------------------------------------------------------+
751
752 PURPOSE : sets/clears the flag indicating we need to update the display
753
754 */
755 void kbd_setDisplayUpdateNeeded(int set)
756 {
757 displayUpdateNeeded = set;
758 }
759
760 /*
761 +--------------------------------------------------------------------+
762 | PROJECT : MMI-Framework (8417) MODULE : MFW_KBD |
763 | STATE : code ROUTINE : kbd_processEveryKeyInput |
764 +--------------------------------------------------------------------+
765
766 PURPOSE : indicates if the software should process each keypad input individually
767 (TRUE) or if it should process keypad inputs one at a time (FALSE)
768
769 */
770 int kbd_processKeyInput(void)
771 {
772 return (QUEUE_EVERY_KEY);//We buffer multiple key inputs
773
774 }
775
776
777
778
779
780
781