FreeCalypso > hg > fc-tourmaline
comparison src/cs/drivers/drv_app/kpd/kpd_process_internal_msg.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /** | |
2 * @file kpd_process_internal_msg.c | |
3 * | |
4 * Implementation of Keypad functions. | |
5 * These functions implement the keypad processing for all the messages the | |
6 * keypad task can receive. | |
7 * | |
8 * @author Laurent Sollier (l-sollier@ti.com) | |
9 * @version 0.1 | |
10 */ | |
11 | |
12 /* | |
13 * History: | |
14 * | |
15 * Date Author Modification | |
16 * ---------------------------------------- | |
17 * 10/10/2001 L Sollier Create | |
18 * | |
19 * | |
20 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
21 */ | |
22 | |
23 #include "kpd/kpd_api.h" | |
24 #include "kpd/kpd_env.h" | |
25 #include "kpd/kpd_i.h" | |
26 #include "kpd/kpd_virtual_key_table_mgt.h" | |
27 #include "kpd/kpd_physical_key_def.h" | |
28 | |
29 #include "rvf/rvf_api.h" | |
30 #include "rvm/rvm_use_id_list.h" | |
31 | |
32 #include <string.h> | |
33 | |
34 /* External declaration */ | |
35 extern T_KPD_ENV_CTRL_BLK* kpd_env_ctrl_blk; | |
36 | |
37 | |
38 /* Definition of the wait time in the loop */ | |
39 #ifdef _WINDOWS | |
40 #define WAIT_TIME_LOOP (50) | |
41 #else | |
42 #define WAIT_TIME_LOOP (10) | |
43 #endif | |
44 | |
45 | |
46 /* This structure gathers informations about one physical key Id. | |
47 It define if subscriber is notified for this physical key */ | |
48 typedef struct { UINT32 subscriber_mask; | |
49 } T_PHYSICAL_KEY_MASK; | |
50 | |
51 | |
52 /** Definition of a set of keys with repeat keys parameters. */ | |
53 typedef struct { UINT8 nb_notified_keys; | |
54 UINT16 long_press_time; /* in ms */ | |
55 UINT16 repeat_time; /* in ms */ | |
56 T_KPD_NOTIF_LEVEL notif_level[KPD_NB_PHYSICAL_KEYS]; | |
57 } T_PHYSICAL_KEY_PARAM_TABLE; | |
58 | |
59 | |
60 /* This structure gather general informations about subscriber id */ | |
61 typedef struct { T_RV_RETURN return_path; | |
62 T_KPD_MODE mode; | |
63 T_PHYSICAL_KEY_PARAM_TABLE notified_keys; | |
64 } T_SUBSCRIBER_INFOS; | |
65 | |
66 | |
67 /* Informations for all the physical keys Id. | |
68 This variable is updated each time a client subscribe to the keypad driver, | |
69 unsubscribe, or change notification key level. | |
70 Warn that position of the physical key Id is implicit cause of the rule | |
71 used to define the vpm table */ | |
72 static T_PHYSICAL_KEY_MASK physical_key_mask[KPD_NB_PHYSICAL_KEYS] = {0}; | |
73 | |
74 /* Informations for all the subscribers */ | |
75 static T_SUBSCRIBER_INFOS* subscriber_infos[KPD_MAX_SUBSCRIBER] = {0}; | |
76 | |
77 | |
78 | |
79 /** | |
80 * @name Functions implementation | |
81 * | |
82 */ | |
83 /*@{*/ | |
84 | |
85 /** | |
86 * function: kpd_return_path_already_defined | |
87 */ | |
88 static BOOL kpd_return_path_already_defined(T_RV_RETURN return_path) | |
89 { | |
90 UINT8 i; | |
91 BOOL ret = FALSE; | |
92 | |
93 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
94 if ( subscriber_infos[i] != 0 ) | |
95 if (subscriber_infos[i]->return_path.callback_func != 0) | |
96 { | |
97 if (subscriber_infos[i]->return_path.callback_func == return_path.callback_func) | |
98 { | |
99 ret = TRUE; | |
100 break; | |
101 } | |
102 } | |
103 else | |
104 { | |
105 if (subscriber_infos[i]->return_path.addr_id == return_path.addr_id) | |
106 { | |
107 ret = TRUE; | |
108 break; | |
109 } | |
110 } | |
111 | |
112 return ret; | |
113 } | |
114 | |
115 /** | |
116 * function: kpd_subscribe_i | |
117 */ | |
118 T_RV_RET kpd_subscribe_i(T_SUBSCRIBER_ID subscriber_id, | |
119 T_KPD_MODE mode, | |
120 T_KPD_VIRTUAL_KEY_TABLE* notified_keys, | |
121 T_RV_RETURN return_path) | |
122 { | |
123 INT8 i, position; | |
124 T_RVF_MB_STATUS mb_status; | |
125 T_RV_RET ret; | |
126 | |
127 /* Check the validity of the key table */ | |
128 ret = kpd_check_key_table(notified_keys, mode); | |
129 | |
130 if (ret != RV_OK) | |
131 { | |
132 /* Remove subscriber id because id was reserved */ | |
133 kpd_remove_subscriber(subscriber_id); | |
134 | |
135 /* Send error message */ | |
136 kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_KEYS_TABLE, return_path); | |
137 } | |
138 else | |
139 { | |
140 if (kpd_return_path_already_defined(return_path) == TRUE) | |
141 { | |
142 /* Remove subscriber id because id was reserved */ | |
143 kpd_remove_subscriber(subscriber_id); | |
144 | |
145 /* Send error message */ | |
146 kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_RETURN_PATH_EXISTING, return_path); | |
147 | |
148 ret = RV_INVALID_PARAMETER; | |
149 } | |
150 else | |
151 { | |
152 /* Update subscriber informations */ | |
153 /* ------------------------------ */ | |
154 | |
155 /* Reserve memory for subscriber informations */ | |
156 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, | |
157 sizeof(T_SUBSCRIBER_INFOS), | |
158 (void **) &subscriber_infos[subscriber_id]); | |
159 | |
160 if (mb_status != RVF_RED) /* Memory allocation success */ | |
161 { | |
162 /* Initialize structure */ | |
163 memset(subscriber_infos[subscriber_id], 0, sizeof(T_SUBSCRIBER_INFOS)); | |
164 | |
165 /* Fill the subscriber structure */ | |
166 subscriber_infos[subscriber_id]->mode = mode; | |
167 subscriber_infos[subscriber_id]->return_path = return_path; | |
168 subscriber_infos[subscriber_id]->notified_keys.nb_notified_keys = notified_keys->nb_notified_keys; | |
169 subscriber_infos[subscriber_id]->notified_keys.long_press_time = 0; | |
170 subscriber_infos[subscriber_id]->notified_keys.repeat_time = 0; | |
171 for (i = 0; i < notified_keys->nb_notified_keys; i++) | |
172 { | |
173 /* Retrieve physical key Id from virtual key_id */ | |
174 kpd_retrieve_virtual_key_position( notified_keys->notified_keys[i], | |
175 mode, | |
176 &position); | |
177 | |
178 subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = KPD_RELEASE_NOTIF; | |
179 } | |
180 | |
181 /* Update link (ID <-> key) */ | |
182 /* ------------------------ */ | |
183 for (i = 0; i < notified_keys->nb_notified_keys; i++) | |
184 { | |
185 /* Retrieve position in vpm table */ | |
186 kpd_retrieve_virtual_key_position(notified_keys->notified_keys[i], | |
187 mode, | |
188 &position); | |
189 | |
190 /* Update subscriber mask for the physical key */ | |
191 physical_key_mask[position].subscriber_mask |= (1<<subscriber_id); | |
192 | |
193 } | |
194 | |
195 /* Send success message to suscriber */ | |
196 kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_PROCESS_OK, return_path); | |
197 } | |
198 else | |
199 { | |
200 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
201 | |
202 /* Remove subscriber id because id was reserved */ | |
203 kpd_remove_subscriber(subscriber_id); | |
204 | |
205 /* Send error message to suscriber */ | |
206 kpd_send_status_message(KPD_SUBSCRIBE_OP, KPD_ERR_INTERNAL, return_path); | |
207 } | |
208 } | |
209 } | |
210 | |
211 return RV_OK; | |
212 } | |
213 | |
214 | |
215 /** | |
216 * function: kpd_unsubscribe_i | |
217 */ | |
218 T_RV_RET kpd_unsubscribe_i(T_SUBSCRIBER_ID subscriber_id) | |
219 { | |
220 UINT8 i; | |
221 | |
222 /* Delete subscriber informations */ | |
223 rvf_free_buf(subscriber_infos[subscriber_id]); | |
224 subscriber_infos[subscriber_id] = 0; | |
225 | |
226 /* Delete link (ID <-> key) */ | |
227 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
228 { | |
229 physical_key_mask[i].subscriber_mask &= ~(1<<subscriber_id); | |
230 } | |
231 | |
232 /* If the subscriber is the keypad owner, this privilege is unset */ | |
233 if (kpd_is_owner_keypad(subscriber_id) == TRUE) | |
234 kpd_set_keypad_mode(MN_MODE); | |
235 | |
236 return RV_OK; | |
237 } | |
238 | |
239 | |
240 /** | |
241 * function: kpd_define_key_notification_i | |
242 */ | |
243 T_RV_RET kpd_define_key_notification_i(T_SUBSCRIBER_ID subscriber_id, | |
244 T_KPD_VIRTUAL_KEY_TABLE* notif_key_table, | |
245 T_KPD_NOTIF_LEVEL notif_level, | |
246 UINT16 long_press_time, | |
247 UINT16 repeat_time) | |
248 { | |
249 T_RV_RET ret = RV_OK; | |
250 UINT8 i; | |
251 INT8 position; | |
252 | |
253 /* Check the validity of the key table */ | |
254 ret = kpd_check_key_table(notif_key_table, subscriber_infos[subscriber_id]->mode); | |
255 | |
256 if (ret != RV_OK) | |
257 { | |
258 /* Send error message */ | |
259 kpd_send_status_message(KPD_REPEAT_KEYS_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path); | |
260 | |
261 } | |
262 else | |
263 { | |
264 /* Update subscriber informations */ | |
265 /* ------------------------------ */ | |
266 subscriber_infos[subscriber_id]->notified_keys.long_press_time = long_press_time*100; | |
267 subscriber_infos[subscriber_id]->notified_keys.repeat_time = repeat_time*100; | |
268 | |
269 for (i = 0; i < notif_key_table->nb_notified_keys; i++) | |
270 { | |
271 /* Retrieve physical key Id from virtual key_id */ | |
272 kpd_retrieve_virtual_key_position( notif_key_table->notified_keys[i], | |
273 subscriber_infos[subscriber_id]->mode, | |
274 &position); | |
275 | |
276 /* Check if subscriber have asked notification for this key at subscription */ | |
277 if ( physical_key_mask[position].subscriber_mask & (1<<subscriber_id) ) | |
278 subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = notif_level; | |
279 } | |
280 | |
281 /* Send success message to suscriber */ | |
282 kpd_send_status_message(KPD_REPEAT_KEYS_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path); | |
283 } | |
284 | |
285 return ret; | |
286 } | |
287 | |
288 | |
289 /** | |
290 * function: kpd_change_mode_i | |
291 */ | |
292 T_RV_RET kpd_change_mode_i(T_SUBSCRIBER_ID subscriber_id, | |
293 T_KPD_VIRTUAL_KEY_TABLE* notified_keys, | |
294 T_KPD_MODE new_mode) | |
295 { | |
296 UINT8 i; | |
297 INT8 position; | |
298 T_RV_RET ret; | |
299 | |
300 /* Check the validity of the key table */ | |
301 ret = kpd_check_key_table(notified_keys, new_mode); | |
302 | |
303 if (ret != RV_OK) | |
304 { | |
305 /* Send error message */ | |
306 kpd_send_status_message(KPD_CHANGE_MODE_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path); | |
307 } | |
308 else | |
309 { | |
310 /* Delete link (ID <-> key) for old mode*/ | |
311 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
312 { | |
313 physical_key_mask[i].subscriber_mask &= ~(1<<subscriber_id); | |
314 subscriber_infos[subscriber_id]->notified_keys.notif_level[i] = KPD_NO_NOTIF; | |
315 } | |
316 | |
317 /* Update subscriber structure */ | |
318 subscriber_infos[subscriber_id]->mode = new_mode; | |
319 subscriber_infos[subscriber_id]->notified_keys.nb_notified_keys = notified_keys->nb_notified_keys; | |
320 subscriber_infos[subscriber_id]->notified_keys.long_press_time = 0; | |
321 subscriber_infos[subscriber_id]->notified_keys.repeat_time = 0; | |
322 for (i = 0; i < notified_keys->nb_notified_keys; i++) | |
323 { | |
324 /* Retrieve physical key Id from virtual key_id */ | |
325 kpd_retrieve_virtual_key_position( notified_keys->notified_keys[i], | |
326 new_mode, | |
327 &position); | |
328 | |
329 subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = KPD_RELEASE_NOTIF; | |
330 | |
331 /* Update link (ID <-> key) for new mode */ | |
332 physical_key_mask[position].subscriber_mask |= (1<<subscriber_id); | |
333 } | |
334 | |
335 /* If the subscriber is the keypad owner, this privilege is unset */ | |
336 if (kpd_is_owner_keypad(subscriber_id) == TRUE) | |
337 kpd_set_keypad_mode(MN_MODE); | |
338 | |
339 /* Send success message to suscriber */ | |
340 kpd_send_status_message(KPD_CHANGE_MODE_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path); | |
341 } | |
342 | |
343 return RV_OK; | |
344 } | |
345 | |
346 /** | |
347 * function: kpd_own_keypad_i | |
348 */ | |
349 T_RV_RET kpd_own_keypad_i(T_SUBSCRIBER_ID subscriber_id, | |
350 BOOL is_keypad_owner, | |
351 T_KPD_VIRTUAL_KEY_TABLE* keys_owner) | |
352 { | |
353 INT8 position; | |
354 UINT8 i; | |
355 | |
356 if (is_keypad_owner == FALSE) | |
357 { | |
358 /* Check if subscriber Id own the keypad */ | |
359 if (kpd_is_owner_keypad(subscriber_id)) | |
360 { | |
361 kpd_set_keypad_mode(MN_MODE); | |
362 | |
363 /* Send success message to suscriber */ | |
364 kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path); | |
365 | |
366 } | |
367 else | |
368 kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_ID_OWNER_KEYPAD, subscriber_infos[subscriber_id]->return_path); | |
369 } | |
370 else | |
371 { | |
372 /* Check if keypad driver is already in single-notified mode */ | |
373 if (kpd_get_keypad_mode() == SN_MODE) | |
374 { | |
375 /* Send error message to suscriber */ | |
376 kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_SN_MODE, subscriber_infos[subscriber_id]->return_path); | |
377 } | |
378 else | |
379 { | |
380 /* Check if all the keys defined in keys_owner are notified to the subsciber */ | |
381 for (i = 0; i < keys_owner->nb_notified_keys; i++) | |
382 { | |
383 /* Retrieve physical key Id from virtual key_id */ | |
384 kpd_retrieve_virtual_key_position( keys_owner->notified_keys[i], | |
385 subscriber_infos[subscriber_id]->mode, | |
386 &position); | |
387 | |
388 if ( subscriber_infos[subscriber_id]->notified_keys.notif_level == KPD_NO_NOTIF ) | |
389 { | |
390 /* Send error message to suscriber */ | |
391 kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path); | |
392 return RV_INTERNAL_ERR; | |
393 } | |
394 } | |
395 | |
396 /* Set keypad driver in single-notified mode */ | |
397 kpd_set_keypad_mode(SN_MODE); | |
398 | |
399 /* Set owner keypad Id */ | |
400 kpd_set_owner_keypad_id(subscriber_id); | |
401 | |
402 /* Set list of keys used by the keypad owner. Thsi list is is a sub-list | |
403 of the keys defined at subscription. For these keys, the keypad owner will | |
404 be the only notified. */ | |
405 kpd_set_keys_in_sn_mode(keys_owner, subscriber_infos[subscriber_id]->mode); | |
406 | |
407 /* Send success message to suscriber */ | |
408 kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path); | |
409 } | |
410 } | |
411 | |
412 return RV_OK; | |
413 } | |
414 | |
415 /** | |
416 * function: kpd_set_key_config_i | |
417 */ | |
418 T_RV_RET kpd_set_key_config_i(T_SUBSCRIBER_ID subscriber_id, | |
419 T_KPD_VIRTUAL_KEY_TABLE* reference_keys, | |
420 T_KPD_VIRTUAL_KEY_TABLE* new_keys) | |
421 { | |
422 #ifdef KPD_MODE_CONFIG | |
423 UINT8 i; | |
424 | |
425 /* Check if some subscriber use the configurable mode */ | |
426 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
427 { | |
428 if ( (subscriber_infos[i] != 0) && (subscriber_infos[i]->mode == KPD_MODE_CONFIG) ) | |
429 { | |
430 /* Send error message to suscriber */ | |
431 kpd_send_status_message(KPD_SET_CONFIG_MODE_OP, | |
432 KPD_ERR_CONFIG_MODE_USED, | |
433 subscriber_infos[subscriber_id]->return_path); | |
434 return RV_OK; | |
435 } | |
436 } | |
437 | |
438 /* Set keys in configurable mode */ | |
439 kpd_define_new_config(reference_keys, new_keys); | |
440 | |
441 /* Send success message to suscriber */ | |
442 kpd_send_status_message(KPD_SET_CONFIG_MODE_OP, | |
443 KPD_PROCESS_OK, | |
444 subscriber_infos[subscriber_id]->return_path); | |
445 | |
446 #endif | |
447 | |
448 return RV_OK; | |
449 } | |
450 | |
451 | |
452 /** | |
453 * function: kpd_process_key_pressed_i | |
454 */ | |
455 void kpd_process_key_pressed_i(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id) | |
456 { | |
457 UINT8 i; | |
458 UINT32 loop_counter = 0; | |
459 UINT16 counter[KPD_MAX_SUBSCRIBER] = {0}; | |
460 T_KPD_PHYSICAL_KEY_ID key_id = physical_key_pressed_id; | |
461 | |
462 KPD_SEND_TRACE_PARAM("KPD: kpd_process_key_pressed_i ", key_id, RV_TRACE_LEVEL_DEBUG_LOW); | |
463 | |
464 /* Notify subscribers of the key pressed */ | |
465 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) /* To do : Loop on the real number of subscribers */ | |
466 { /* To do : Test on the physical_key_mask (to ensure subscriber is subscribed for this key) */ | |
467 if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_FIRST_PRESS_NOTIF) ) | |
468 { | |
469 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
470 KPD_FIRST_PRESS, subscriber_infos[i]->mode, | |
471 subscriber_infos[i]->return_path); | |
472 } | |
473 } | |
474 | |
475 /* If key pressed is the PWR key, the message "Released key" is immediately sent */ | |
476 if (key_id != KPD_SHORT_PRESS_PWR_KEY) | |
477 { | |
478 /* Loop infinitely until key is released */ | |
479 do | |
480 { | |
481 rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP)); | |
482 physical_key_pressed_id = kpd_scan_keypad(); | |
483 loop_counter++; | |
484 | |
485 /* Send message for repeat key */ | |
486 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
487 { | |
488 if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & (KPD_LONG_PRESS_NOTIF|KPD_INFINITE_REPEAT_NOTIF)) ) | |
489 { | |
490 if ((counter[i] == 0) && (WAIT_TIME_LOOP*loop_counter >= subscriber_infos[i]->notified_keys.long_press_time) ) | |
491 { | |
492 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
493 KPD_LONG_PRESS, subscriber_infos[i]->mode, | |
494 subscriber_infos[i]->return_path); | |
495 counter[i] ++; | |
496 } | |
497 else if (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_INFINITE_REPEAT_NOTIF) | |
498 { | |
499 if (WAIT_TIME_LOOP*loop_counter >= (UINT32)((counter[i]*subscriber_infos[i]->notified_keys.repeat_time + subscriber_infos[i]->notified_keys.long_press_time)) ) | |
500 { | |
501 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
502 KPD_REPEAT_PRESS, subscriber_infos[i]->mode, | |
503 subscriber_infos[i]->return_path); | |
504 counter[i] ++; | |
505 } | |
506 } | |
507 } | |
508 } | |
509 | |
510 } while (physical_key_pressed_id != KPD_PKEY_NULL); | |
511 } | |
512 | |
513 /* Notify subscribers of the key released */ | |
514 for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) | |
515 { | |
516 if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_RELEASE_NOTIF) ) | |
517 { | |
518 kpd_send_key_event_message(key_id, KPD_KEY_RELEASED, | |
519 KPD_INSIGNIFICANT_VALUE, subscriber_infos[i]->mode, | |
520 subscriber_infos[i]->return_path); | |
521 } | |
522 } | |
523 | |
524 /* On board,this function unmask keypad interrupt | |
525 On Riviera tool, this function is empty */ | |
526 if (key_id != KPD_SHORT_PRESS_PWR_KEY) | |
527 { | |
528 #if (CHIPSET == 12) | |
529 kpd_software_reset(); | |
530 kpd_init_ctrl_reg(1, HARDWARE_DECODING, KPD_CLK_DIV32, | |
531 KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED, | |
532 KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED); | |
533 #endif | |
534 | |
535 kpd_acknowledge_key_pressed(); | |
536 } | |
537 } | |
538 | |
539 | |
540 /** | |
541 * function: kpd_process_key_pressed_sn_mode_i | |
542 */ | |
543 void kpd_process_key_pressed_sn_mode_i(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id) | |
544 { | |
545 T_SUBSCRIBER_ID owner_keypad_id = kpd_get_owner_keypad_id(); | |
546 T_KPD_PHYSICAL_KEY_ID key_id = physical_key_pressed_id; | |
547 UINT32 loop_counter = 0; | |
548 UINT16 counter = 0; | |
549 | |
550 if ( subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_FIRST_PRESS_NOTIF ) | |
551 { | |
552 /* Notify subscribers of the key pressed */ | |
553 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
554 KPD_FIRST_PRESS, subscriber_infos[owner_keypad_id]->mode, | |
555 subscriber_infos[owner_keypad_id]->return_path); | |
556 } | |
557 | |
558 /* If key pressed is the PWR key, the message "Released key" is immediately sent */ | |
559 if (key_id != KPD_SHORT_PRESS_PWR_KEY) | |
560 { | |
561 /* Loop infinitely until key is released */ | |
562 do | |
563 { | |
564 rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP)); | |
565 physical_key_pressed_id = kpd_scan_keypad(); | |
566 loop_counter++; | |
567 | |
568 /* Send message for repeat key */ | |
569 if (subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & (KPD_LONG_PRESS_NOTIF|KPD_INFINITE_REPEAT_NOTIF)) | |
570 { | |
571 if ((counter == 0) && (WAIT_TIME_LOOP*loop_counter >= subscriber_infos[owner_keypad_id]->notified_keys.long_press_time) ) | |
572 { | |
573 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
574 KPD_LONG_PRESS, subscriber_infos[owner_keypad_id]->mode, | |
575 subscriber_infos[owner_keypad_id]->return_path); | |
576 counter ++; | |
577 } | |
578 else if (subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_INFINITE_REPEAT_NOTIF) | |
579 { | |
580 if (WAIT_TIME_LOOP*loop_counter >= (UINT32)((counter*subscriber_infos[owner_keypad_id]->notified_keys.repeat_time + subscriber_infos[owner_keypad_id]->notified_keys.long_press_time)) ) | |
581 { | |
582 kpd_send_key_event_message(key_id, KPD_KEY_PRESSED, | |
583 KPD_REPEAT_PRESS, subscriber_infos[owner_keypad_id]->mode, | |
584 subscriber_infos[owner_keypad_id]->return_path); | |
585 counter ++; | |
586 } | |
587 } | |
588 } | |
589 | |
590 } while (physical_key_pressed_id != KPD_PKEY_NULL); | |
591 } | |
592 | |
593 if ( subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_RELEASE_NOTIF ) | |
594 { | |
595 /* Notify subscribers of the key released */ | |
596 kpd_send_key_event_message(key_id, KPD_KEY_RELEASED, | |
597 KPD_INSIGNIFICANT_VALUE, subscriber_infos[owner_keypad_id]->mode, | |
598 subscriber_infos[owner_keypad_id]->return_path); | |
599 } | |
600 | |
601 /* On board,this function unmask keypad interrupt | |
602 On Riviera tool, this function authorize to send new messages to keypad task */ | |
603 if (key_id != KPD_SHORT_PRESS_PWR_KEY) | |
604 { | |
605 #if (CHIPSET == 12) | |
606 kpd_software_reset(); | |
607 kpd_init_ctrl_reg(1, HARDWARE_DECODING, KPD_CLK_DIV32, | |
608 KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED, | |
609 KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED); | |
610 #endif | |
611 kpd_acknowledge_key_pressed(); | |
612 } | |
613 } | |
614 | |
615 /** | |
616 * function: kpd_wait_for_key_release | |
617 */ | |
618 void kpd_wait_for_key_release(void) | |
619 { | |
620 T_KPD_PHYSICAL_KEY_ID key_id;; | |
621 | |
622 do | |
623 { | |
624 rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP)); | |
625 key_id = kpd_scan_keypad(); | |
626 | |
627 } while (key_id != KPD_PKEY_NULL); | |
628 | |
629 kpd_acknowledge_key_pressed(); | |
630 } | |
631 | |
632 /*@}*/ |