comparison g23m/condat/ms/src/mfw/ti1_key.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:: ti1_key.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 13 $|
5 | CREATED: 28.01.99 $Modtime:: 21.01.00 15:05 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : TI1_KEY
10
11 PURPOSE : keyboard driver interface (TI1 VERSION)
12
13 EXPORT :
14
15 TO DO :
16 */
17
18 #define ENTITY_MFW
19
20 #include "typedefs.h"
21 #include "vsi.h"
22 #include "custom.h"
23 #include "gsm.h"
24 #include "prim.h"
25
26 #include <string.h>
27
28 #include "mfw_mfw.h"
29 #include "mfw_sys.h"
30 #include "mfw_kbd.h"
31 #include "gdi.h"
32 #include "kbd.h"
33
34 #include "drv_key.h"
35 #include "ti1_key.h"
36
37 #ifndef NEPTUNE_BOARD
38 #include "kpd/kpd_api.h"
39 #else
40 #define PLATFORM_ARCH_ARM
41 #define PLATFORM_ENDIAN_LITTLE
42 #define PLATFORM tcs3100Evm
43 #include "bspSystem.h"
44 #include "bspKeypad_Gsp.h"
45 #endif
46
47 BOOL powered_on=FALSE;
48
49 #define POWER_KEY 25
50
51 extern void mmiInit(void);
52
53
54 /*
55 * Marcus: Issue 811: 05:09/2002:
56 * Moved kbd_map, simkbd_map and config_map to \g23m\Condat\COM\SRC\DRIVER\keypad.c
57 */
58 /* driver callback */
59 static void kbdCb (drv_SignalID_Type *signal_params);
60
61 UBYTE keypad_initialize (void);
62
63 void sendKeyInd( T_KPD_VIRTUAL_KEY_ID virtual_key_id,
64 T_KPD_KEY_STATE key_state,
65 T_KPD_PRESS_STATE press_state);
66
67 static void (*sig) (char,char) = 0; /* kbd signaling function */
68 static char *keyMap = (char *) kbd_map; /* current keyboard mapping */
69
70 T_KPD_SUBSCRIBER subscriber_p; /* keep the subscription indentification value */
71
72
73
74 typedef struct
75 {
76 U32 msg_id;
77 void (*callback_func)(void *);
78 U16 src_addr_id;
79 U16 dest_addr_id;
80 } T_RV_CHECK;
81
82
83
84 /* JVJ #1874 - new function to initialize the power key*/
85
86
87 /*
88 +--------------------------------------------------------------------+
89 | PROJECT : MMI-Framework (8417) MODULE : key_power_init |
90 | STATE : code ROUTINE : key_power_init |
91 +--------------------------------------------------------------------+
92
93 PURPOSE : initialize the power key handler in the TI driver
94
95 */
96
97
98
99 void key_power_init()
100 {
101 kbd_Init(kbdCb);
102 }
103
104
105
106 /*
107 +--------------------------------------------------------------------+
108 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
109 | STATE : code ROUTINE : keyInit |
110 +--------------------------------------------------------------------+
111
112 PURPOSE : initialize keyboard driver
113
114 */
115
116 void keyInit (void (*s)(char,char))
117 {
118 sig = s;
119 /*
120 * read keyboard mapping from EEPROM.
121 * if this fails set keyboard mapping with default values.
122 *
123 * EEPROM reading not now !!!
124 */
125 keyMap = (char *) kbd_map;
126
127
128 //new keypad driver
129 #ifdef NEPTUNE_BOARD
130 // Commented by Nitin for Neptune Platfrom. 05/04/2005
131 //keypad_initialize ();
132 #else
133 keypad_initialize ();
134 #endif
135
136
137 }
138
139
140 /*
141 +--------------------------------------------------------------------+
142 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
143 | STATE : code ROUTINE : keyExit |
144 +--------------------------------------------------------------------+
145
146 PURPOSE : finalize keyboard driver
147
148 */
149
150 void keyExit (void)
151 {
152 sig = 0;
153
154 // by Nitin 05/04/2004
155 #ifndef NEPTUNE_BOARD
156 //unsubscribe the client from the keypad driver
157 #ifndef _SIMULATION_
158 kpd_unsubscribe (&subscriber_p);
159 #endif
160 // Added by Nitin 05/04/2004
161 #else /* NOT defined NEPTUNE_BOARD */
162 kpdMgr_unsubscribe(); // Sumit; commented for time being
163 #endif
164
165 }
166
167 /*
168 +--------------------------------------------------------------------+
169 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
170 | STATE : code ROUTINE : getKeyIndex |
171 +--------------------------------------------------------------------+
172
173 PURPOSE : returns the index to the key provided (or -1 if no match)
174
175 */
176 char drvGetKeyIndex( char key)
177 {
178 int i;
179
180 #ifndef _SIMULATION_
181 for (i = 0; i < 32; i++)
182 {
183 if (keyMap[i] == key)
184 {
185 return (i);
186 }
187 }
188
189 #else
190 /* TEST only ES!! */
191 for (i = 0; i < NUM_KPD_KEYS; i++)
192 {
193 if (simkbd_map[i] == key)
194 {
195 return (i);
196 }
197 }
198 #endif
199
200 return (-1); //No match.
201
202
203 }
204
205
206 /*
207 +--------------------------------------------------------------------+
208 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
209 | STATE : code ROUTINE : drvKeyUpDown |
210 +--------------------------------------------------------------------+
211
212 PURPOSE : handle key event (called from keyboard)
213
214 */
215
216 void drvKeyUpDown (char upDown, char key)
217 {
218 TRACE_EVENT_P2("drvKeyUpDown : key = %d : state = %x", key, upDown);
219 /* JVJ #1705 The first KEY event can only be the Power Key*/
220 /* This will start MMI */
221 if ((!powered_on))
222 {
223 powered_on =TRUE;
224
225 // ADDED BY RAVI - 22-11-2005 - OMAPS00056702 FIX
226 #if (BOARD == 61)
227 #ifdef FF_MMI_MULTIMEDIA
228 /* JVJ #1705 MMI will be started here */
229 mmiInit();
230 return;
231 #endif
232 #else
233 /* JVJ #1705 MMI will be started here */
234 mmiInit();
235 return;
236 #endif
237 // END RAVI - 22-11-2005
238 }
239
240 if (key != (char)0)
241 {
242 if ((key >= 48) && (key <=57))
243 {
244 key -= 47;
245 }
246 else
247 {
248 switch(key)
249 {
250 case 35:
251 key = (char)18;
252 break;
253
254 case 42:
255 key = (char)17;
256 break;
257
258 case 45:
259 key = (char)11;
260 break;
261
262 case 67:
263 key = (char)13;
264 break;
265
266 case 69:
267 key = (char)25;
268 break;
269
270 case 86:
271 key = (char)16;
272 break;
273
274 case 94:
275 key = (char)14;
276 break;
277
278 case 97:
279 key = (char)15;
280 break;
281
282 case 98:
283 key = (char)12;
284 break;
285
286 default:
287 key = (char)0;
288 break;
289 }
290 }
291
292 kbd_putMakeAndKey( upDown, key);
293 }
294
295 if (!sig) return; /* no event handler */
296
297 sig((char)(!upDown),0);
298
299 return;
300
301 }
302
303
304
305 /*
306 +--------------------------------------------------------------------+
307 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
308 | STATE : code ROUTINE : mfw_keystroke |
309 +--------------------------------------------------------------------+
310
311 PURPOSE : handle keystroke primitive (called from aci-pei)
312 keystroke sent via 'PEI-CONFIG'-primitive
313 used in Test cases and by RT;
314
315 */
316
317 void mfw_keystroke (char * key)
318 {
319 char i; //, number; // RAVI
320
321 if (!sig) return; /* no event handler */
322 if (!key) return; /* no valid key */
323
324 // number = 0; // RAVI
325 while (*key)
326 {
327 if (!strcmp(key,"#*43*1#"))
328 {
329 // EF we need to place the key code into the buffer
330 // together with the inverse of the key status, and then call sig
331 kbd_putMakeAndKey(0,19); /* simulate HUP */
332 sig(0,0);
333 kbd_putMakeAndKey(1,19);
334 sig(0,0);
335 key += 7;
336 continue;
337 }
338
339 if (!strcmp(key,"#*43*0#"))
340 {
341 kbd_putMakeAndKey(0,18); /* simulate CALL */
342 sig(0,0);
343 kbd_putMakeAndKey(1,18);
344 sig(0,0);
345 key += 7;
346 continue;
347 }
348
349 for (i = 0; i < NUM_KPD_KEYS; i++)
350 {
351 if (!strncmp(key, config_map[i], strlen(config_map[i])))
352 {
353 kbd_putMakeAndKey(0,i); /* add key down event */
354 sig(0,0);
355 kbd_putMakeAndKey(1,i); /* assume key down event */
356 sig(0,0);
357 key += strlen(config_map[i]);
358 break;
359 }
360 }
361 if (i < NUM_KPD_KEYS)
362 continue; /* found config code */
363
364 key++;
365 }
366 }
367
368 void mfw_keystroke_long (char * key, UBYTE mode) /* long pressed key */
369 {
370 char i; // , number; // RAVI
371
372 if (!sig) return; /* no event handler */
373 if (!key) return; /* no valid key */
374
375 // number = 0; // RAVI
376 while (strlen(key))
377 {
378 for (i = 0; i < NUM_KPD_KEYS; i++)
379 {
380 if (!strcmp(key,config_map[i]))
381 {
382 if (mode)
383 {
384 kbd_putMakeAndKey(0,i); /* assume key down event */
385 sig(0,0);
386 }
387 else
388 {
389 kbd_putMakeAndKey(1,i); /* assume key up event */
390 sig(0,0);
391 }
392 return;
393 }
394 }
395 return;
396 }
397 }
398
399
400 /*
401 +--------------------------------------------------------------------+
402 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
403 | STATE : code ROUTINE : kbd_callback |
404 +--------------------------------------------------------------------+
405
406 PURPOSE : Called by keyboard driver
407
408 */
409
410 #define hCommACI _ENTITY_PREFIXED(hCommACI)
411
412 static void kbdCb (drv_SignalID_Type *signal_params)
413 {
414 #if defined (NEW_FRAME)
415 ULONG signal_raw;
416
417 #endif
418
419 U16 signal_high;
420 U16 signal_low;
421 U8 key_code;
422 U8 key_state;
423
424 int nPresses; //Number of key presses still in the queue
425
426
427
428
429
430 #if defined (NEW_FRAME)
431 signal_raw = (ULONG)signal_params->UserData;
432 signal_high = (U16) (signal_raw >> 16);
433 signal_low = (U16) (signal_raw & 0xFFFF);
434 #else
435 signal_high = (U16) (signal_params->UserData >> 16);
436 signal_low = (U16) (signal_params->UserData & 0xFFFF);
437 #endif
438
439 key_code = (U8) (signal_low & 0xFF);
440 if (signal_high == 1)
441 key_state = KEY_STAT_PRS;
442 else
443 key_state = KEY_STAT_REL;
444
445 /*JVJ #1705 When the first POWER KEY event arrives, an event is sent to MMI */
446 /*to start it */
447 if ((!powered_on)&&(key_code==POWER_KEY))
448 {
449 sendKeyInd(key_code, key_state, 0);
450 return;
451 }
452
453
454 //Add keypress to queue of key presses
455 nPresses = kbd_getNumElements();
456
457
458 kbd_putMakeAndKey( (char)key_state, (char)key_code);
459
460 if ((!kbd_stillProcessingKeys()) && (nPresses == 0))
461 { //Only this element present - create and send message.
462 sendKeyInd(key_code, key_state, 0);
463
464 }
465
466 }
467
468 /*
469 +--------------------------------------------------------------------+
470 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
471 | STATE : code ROUTINE : keypad_cb |
472 +--------------------------------------------------------------------+
473
474 PURPOSE : This CB function is called by the driver when a key is pressed/released
475 or a status of an asynch. process is requested.
476
477 */
478 void keypad_cb (void* parameter)
479 {
480 // NITIN
481 #ifndef NEPTUNE_BOARD
482 T_KPD_KEY_EVENT_MSG* event;
483 T_KPD_STATUS_MSG* status;
484 T_RV_CHECK* check;
485 int k,m;
486
487
488
489
490
491 check = (T_RV_CHECK*)parameter;
492
493 if (check->msg_id EQ KPD_STATUS_MSG)
494 {
495 //status message is used
496 status = (T_KPD_STATUS_MSG*) parameter;
497
498
499
500 if (status->status_value EQ KPD_PROCESS_OK)
501 {
502 //ok
503 }
504 else
505 {
506 //failed !
507 return;
508 }
509 }
510 else
511 {
512 int nPresses; //Number of key presses still in the queue
513 //event message is used
514 event = (T_KPD_KEY_EVENT_MSG*) parameter;
515
516
517 //Add keypress to queue of key presses
518 nPresses = kbd_getNumElements();
519
520 if (event->key_info.press_state EQ KPD_INSIGNIFICANT_VALUE)
521 {
522 kbd_putMakeAndKey( (char)event->key_info.state, (char)event->key_info.virtual_key_id );
523 }
524 else
525 {
526
527 //key_ind->key_stat (U8):
528 // 00xx 0000 = KEY_PRESSED
529 // 00xx 0001 = KEY_RELEASED
530 // 0000 00xx = KPD_FIRST_PRESS
531 // 0001 00xx = KPD_LONG_PRESS
532 // 0010 00xx = KPD_REPEAT_PRESS
533 //
534 // x = anystate
535
536 kbd_putMakeAndKey( (char)(event->key_info.state | (event->key_info.press_state << 4)),
537 (char)event->key_info.virtual_key_id );
538 }
539
540 if ((!kbd_stillProcessingKeys()) && (nPresses == 0))
541
542 { //Only this element present - create and send message.
543
544
545
546 sendKeyInd(event->key_info.virtual_key_id, event->key_info.state, event->key_info.press_state);
547
548 }
549
550 }
551 #endif // NEPTUNE_BOARD
552 return;
553
554 }
555
556
557 /*
558 +--------------------------------------------------------------------+
559 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
560 | STATE : code ROUTINE : keypad_initialize |
561 +--------------------------------------------------------------------+
562
563 PURPOSE : initialize keyboard driver
564
565 */
566 // Commented by Nitin for Neptune Platfrom. 05/04/2005
567 #ifndef NEPTUNE_BOARD
568 UBYTE keypad_initialize (void)
569 {
570 T_KPD_MODE mode;
571 T_KPD_VIRTUAL_KEY_TABLE notified_keys;
572 T_RV_RETURN return_path;
573 T_RV_RET return_value;
574
575 U16 long_press_time = 30; // 3.0s
576 U16 repeat_time = 50; // 5.0s <not used>
577
578 T_KPD_NOTIF_LEVEL notif_level;
579 mode = KPD_DEFAULT_MODE;
580
581 return_path.callback_func = keypad_cb;
582 return_path.addr_id = 0;
583
584 notified_keys.nb_notified_keys = KPD_NB_PHYSICAL_KEYS;
585
586 notified_keys.notified_keys [0] = KPD_KEY_0;
587 notified_keys.notified_keys [1] = KPD_KEY_1;
588 notified_keys.notified_keys [2] = KPD_KEY_2;
589 notified_keys.notified_keys [3] = KPD_KEY_3;
590 notified_keys.notified_keys [4] = KPD_KEY_4;
591 notified_keys.notified_keys [5] = KPD_KEY_5;
592 notified_keys.notified_keys [6] = KPD_KEY_6;
593 notified_keys.notified_keys [7] = KPD_KEY_7;
594 notified_keys.notified_keys [8] = KPD_KEY_8;
595 notified_keys.notified_keys [9] = KPD_KEY_9;
596 notified_keys.notified_keys [10] = KPD_KEY_UP;
597 notified_keys.notified_keys [11] = KPD_KEY_DOWN;
598 notified_keys.notified_keys [12] = KPD_KEY_LEFT;
599 notified_keys.notified_keys [13] = KPD_KEY_RIGHT;
600 notified_keys.notified_keys [14] = KPD_KEY_CONNECT;
601 notified_keys.notified_keys [15] = KPD_KEY_DISCONNECT;
602 notified_keys.notified_keys [16] = KPD_KEY_STAR;
603 notified_keys.notified_keys [17] = KPD_KEY_DIESE;
604
605 if (KPD_NB_PHYSICAL_KEYS > 22)
606 {
607 notified_keys.notified_keys [18] = KPD_KEY_SOFT_LEFT;
608 notified_keys.notified_keys [19] = KPD_KEY_SOFT_RIGHT;
609 notified_keys.notified_keys [20] = KPD_KEY_VOL_UP;
610 notified_keys.notified_keys [21] = KPD_KEY_VOL_DOWN;
611 notified_keys.notified_keys [22] = KPD_KEY_ENTER;
612 //? #define KPD_KEY_RECORD (24)
613 }
614
615 #ifndef _SIMULATION_
616 return_value = kpd_subscribe (&subscriber_p, mode, &notified_keys, return_path);
617 #else
618 return_value = RV_OK; /* do some faking here, to get it compileable */
619 #endif
620
621 if (return_value EQ RV_INTERNAL_ERR ||
622 return_value EQ RV_INVALID_PARAMETER ||
623 return_value EQ RV_MEMORY_ERR)
624 {
625 //failed
626
627 //- RV_INTERNAL_ERR if
628 // - the max of subscriber is reached,
629 // - the software entity is not started, not yet initialized or initialization has
630 // failed
631 //- RV_INVALID_PARAMETER if number of virtual keys is not correct.
632 //- RV_MEMORY_ERR if memory reach its size limit.
633
634 return 1;
635 }
636
637 //Subscribe to key press and key release (at the moment)
638 //subscribe to KPD_LONG_KEY_PRESS_NOTIF once implemented.
639 notif_level = KPD_FIRST_PRESS_NOTIF | KPD_RELEASE_NOTIF;
640
641 #ifndef _SIMULATION_
642 return_value = kpd_define_key_notification( subscriber_p, &notified_keys, notif_level,
643 long_press_time, repeat_time );
644 #else
645 return_value = RV_OK;
646 #endif
647
648 if (return_value EQ RV_INVALID_PARAMETER ||
649 return_value EQ RV_MEMORY_ERR)
650 { //failed
651 return 1;
652 }
653 return 0;
654 }
655 // Commented by Nitin for Neptune Platfrom. 05/04/2005
656 #endif /* NEPTUNE_BOARD*/
657
658
659 /*
660 +--------------------------------------------------------------------+
661 | PROJECT : MMI-Framework (8417) MODULE : ti1_key |
662 | STATE : code ROUTINE : sendKeyInd |
663 +--------------------------------------------------------------------+
664
665 PURPOSE : Sends an MMI_KEYPAD_IND to the protocol stack
666 */
667 void sendKeyInd( T_KPD_VIRTUAL_KEY_ID virtual_key_id,
668 T_KPD_KEY_STATE key_state,
669 T_KPD_PRESS_STATE press_state)
670 {
671 #if defined (NEW_FRAME)
672 EXTERN T_HANDLE hCommACI;
673
674
675
676
677 // ULONG signal_raw; // RAVI
678 #else
679 EXTERN T_VSI_CHANDLE hCommACI;
680 #endif
681
682 PALLOC(key_ind,MMI_KEYPAD_IND);
683
684 key_ind->key_code = (U8)0;
685
686 key_ind->key_stat = 0;
687
688 #if defined (NEW_FRAME)
689 PSENDX(ACI,key_ind);
690 #else
691 #if defined (_TMS470)
692 vsi_c_send("",hCommACI,D2P(key_ind),
693 sizeof(T_PRIM_HEADER)+sizeof(T_MMI_KEYPAD_IND));
694 #else
695 PSEND(ACI,key_ind);
696 #endif
697 #endif
698
699 return;
700
701 }
702
703
704
705
706
707
708