FreeCalypso > hg > fc-magnetite
comparison src/cs/drivers/drv_app/kpd/kpd_api.c @ 0:945cf7f506b2
src/cs: chipsetsw import from tcs211-fcmodem
binary blobs and LCD demo files have been excluded,
all line endings are LF only
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Sep 2016 22:50:11 +0000 (2016-09-25) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:945cf7f506b2 |
---|---|
1 /** | |
2 * @file kpd_api.c | |
3 * | |
4 * Implementation of bridge functions. | |
5 * | |
6 * @author Laurent Sollier (l-sollier@ti.com) | |
7 * @version 0.1 | |
8 */ | |
9 | |
10 /* | |
11 * History: | |
12 * | |
13 * Date Author Modification | |
14 * ---------------------------------------- | |
15 * 10/10/2001 L Sollier Create | |
16 * | |
17 * | |
18 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
19 */ | |
20 | |
21 | |
22 #include "kpd/kpd_api.h" | |
23 #include "kpd/kpd_virtual_key_table_mgt.h" | |
24 #include "kpd/kpd_messages_i.h" | |
25 #include "kpd/kpd_process_internal_msg.h" | |
26 #include "kpd/kpd_env.h" | |
27 | |
28 #include "rvm/rvm_use_id_list.h" | |
29 | |
30 /* Include file to delete when Kp global variable will be useless */ | |
31 /* Delete variable Kp below */ | |
32 #include "kpd/kpd_power_api.h" | |
33 | |
34 | |
35 /** External declaration */ | |
36 extern T_KPD_ENV_CTRL_BLK* kpd_env_ctrl_blk; | |
37 extern T_KPD_KEYPAD Kp; | |
38 | |
39 | |
40 /** | |
41 * @name Bridge functions implementation | |
42 * | |
43 */ | |
44 /*@{*/ | |
45 | |
46 | |
47 /** | |
48 * function: kpd_subscribe | |
49 */ | |
50 T_RV_RET kpd_subscribe(T_KPD_SUBSCRIBER* subscriber_p, | |
51 T_KPD_MODE mode, | |
52 T_KPD_VIRTUAL_KEY_TABLE* notified_keys_p, | |
53 T_RV_RETURN return_path) | |
54 { | |
55 T_RVF_MB_STATUS mb_status; | |
56 T_KPD_SUBSCRIBE_MSG* msg_subscribe_p; | |
57 T_SUBSCRIBER* subscriber_struct_p; | |
58 T_RV_RET ret = RV_OK; | |
59 UINT8 i; | |
60 | |
61 /* Initialization of parameter "subscriber" in order to be sure that client will | |
62 not use later the parameter with an non initialized value */ | |
63 *subscriber_p = 0; | |
64 | |
65 /* Check if initialization has been correctly done */ | |
66 if ( (kpd_env_ctrl_blk == 0) || (kpd_env_ctrl_blk->swe_is_initialized == FALSE) ) | |
67 { | |
68 KPD_SEND_TRACE("KPD: Initialization is not yet done or failed", RV_TRACE_LEVEL_ERROR); | |
69 return RV_INTERNAL_ERR; | |
70 } | |
71 | |
72 /* Allocate memory to save subscriber Id */ | |
73 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_SUBSCRIBER), (void **) &subscriber_struct_p); | |
74 if (mb_status == RVF_RED) | |
75 return RV_MEMORY_ERR; | |
76 | |
77 if ( (notified_keys_p != 0) | |
78 && (notified_keys_p->nb_notified_keys > 0) | |
79 && (notified_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) ) | |
80 { | |
81 /* Reserve subscriber Id */ | |
82 ret = kpd_add_subscriber(&(subscriber_struct_p->subscriber_id)); | |
83 if (ret != RV_OK) | |
84 rvf_free_buf(subscriber_struct_p); | |
85 } | |
86 else | |
87 { | |
88 rvf_free_buf(subscriber_struct_p); | |
89 ret = RV_INVALID_PARAMETER; | |
90 } | |
91 | |
92 | |
93 if (ret == RV_OK) | |
94 { | |
95 /* Reserve memory for message */ | |
96 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_SUBSCRIBE_MSG), (void **) &msg_subscribe_p); | |
97 | |
98 if (mb_status != RVF_RED) /* Memory allocation success */ | |
99 { | |
100 /* Fill the message */ | |
101 msg_subscribe_p->hdr.msg_id = KPD_SUBSCRIBE_MSG; | |
102 msg_subscribe_p->subscription_info.subscriber_id = subscriber_struct_p->subscriber_id; | |
103 msg_subscribe_p->subscription_info.mode = mode; | |
104 msg_subscribe_p->subscription_info.return_path = return_path; | |
105 msg_subscribe_p->subscription_info.notified_keys.nb_notified_keys = notified_keys_p->nb_notified_keys; | |
106 for (i = 0; i < notified_keys_p->nb_notified_keys; i++) | |
107 msg_subscribe_p->subscription_info.notified_keys.notified_keys[i] = notified_keys_p->notified_keys[i]; | |
108 | |
109 /* Send message to the keypad task */ | |
110 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_subscribe_p); | |
111 | |
112 /* Save subscriber id */ | |
113 *subscriber_p = (void*)subscriber_struct_p; | |
114 } | |
115 else | |
116 { | |
117 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
118 kpd_remove_subscriber(subscriber_struct_p->subscriber_id); | |
119 rvf_free_buf(subscriber_struct_p); | |
120 ret = RV_MEMORY_ERR; | |
121 } | |
122 } | |
123 | |
124 return ret; | |
125 } | |
126 | |
127 | |
128 /** | |
129 * function: kpd_unsubscribe | |
130 */ | |
131 T_RV_RET kpd_unsubscribe(T_KPD_SUBSCRIBER* subscriber_p) | |
132 { | |
133 T_RVF_MB_STATUS mb_status; | |
134 T_KPD_UNSUBSCRIBE_MSG* msg_unsubscribe_p; | |
135 T_RV_RET ret = RV_INVALID_PARAMETER; | |
136 T_SUBSCRIBER_ID subscriber_id; | |
137 | |
138 /* Check if subscriber id is correct */ | |
139 if ( kpd_subscriber_id_used(*subscriber_p, &subscriber_id) == TRUE) | |
140 { | |
141 /* Reserve memory for message */ | |
142 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_UNSUBSCRIBE_MSG), (void **) &msg_unsubscribe_p); | |
143 | |
144 if (mb_status != RVF_RED) /* Memory allocation success */ | |
145 { | |
146 /* Free subscriber Id */ | |
147 ret = kpd_remove_subscriber(subscriber_id); | |
148 | |
149 if (ret == RV_OK) | |
150 { | |
151 /* Fill the message */ | |
152 msg_unsubscribe_p->hdr.msg_id = KPD_UNSUBSCRIBE_MSG; | |
153 msg_unsubscribe_p->subscriber_id = subscriber_id; | |
154 | |
155 /* Send message to the keypad task */ | |
156 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_unsubscribe_p); | |
157 | |
158 rvf_free_buf(*subscriber_p); | |
159 *subscriber_p = 0; | |
160 } | |
161 else | |
162 { | |
163 rvf_free_buf(msg_unsubscribe_p); | |
164 } | |
165 } | |
166 else | |
167 { | |
168 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
169 ret = RV_MEMORY_ERR; | |
170 } | |
171 } | |
172 | |
173 return ret; | |
174 } | |
175 | |
176 | |
177 /** | |
178 * function: kpd_define_key_notification | |
179 */ | |
180 T_RV_RET kpd_define_key_notification(T_KPD_SUBSCRIBER subscriber, | |
181 T_KPD_VIRTUAL_KEY_TABLE* notif_key_table_p, | |
182 T_KPD_NOTIF_LEVEL notif_level, | |
183 UINT16 long_press_time, | |
184 UINT16 repeat_time) | |
185 { | |
186 T_RV_RET ret = RV_INVALID_PARAMETER; | |
187 T_RVF_MB_STATUS mb_status; | |
188 T_KPD_NOTIF_KEYS_MSG* msg_notif_key_p; | |
189 UINT8 i; | |
190 T_SUBSCRIBER_ID subscriber_id; | |
191 | |
192 /* Check if subscriber id is correct */ | |
193 if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE) | |
194 { | |
195 if ( (notif_key_table_p != 0) | |
196 && (notif_key_table_p->nb_notified_keys > 0) | |
197 && (notif_key_table_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) ) | |
198 { | |
199 if ( (notif_level == KPD_NO_NOTIF ) | |
200 ||(notif_level & KPD_FIRST_PRESS_NOTIF ) | |
201 ||(notif_level & KPD_RELEASE_NOTIF ) | |
202 ||( (notif_level & KPD_LONG_PRESS_NOTIF) && (long_press_time != 0) ) | |
203 ||( (notif_level & KPD_INFINITE_REPEAT_NOTIF) && (long_press_time != 0) && (repeat_time != 0) ) ) | |
204 { | |
205 /* Reserve memory for message */ | |
206 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_NOTIF_KEYS_MSG), (void **) &msg_notif_key_p); | |
207 | |
208 if (mb_status != RVF_RED) /* Memory allocation success */ | |
209 { | |
210 /* Fill the message */ | |
211 msg_notif_key_p->hdr.msg_id = KPD_NOTIF_KEYS_MSG; | |
212 msg_notif_key_p->subscriber_id = subscriber_id; | |
213 msg_notif_key_p->notif_level = notif_level; | |
214 msg_notif_key_p->long_press_time = long_press_time; | |
215 msg_notif_key_p->repeat_time = repeat_time; | |
216 msg_notif_key_p->notif_key_table.nb_notified_keys = notif_key_table_p->nb_notified_keys; | |
217 for (i = 0; i < notif_key_table_p->nb_notified_keys; i++) | |
218 msg_notif_key_p->notif_key_table.notified_keys[i] = notif_key_table_p->notified_keys[i]; | |
219 | |
220 /* Send message to the keypad task */ | |
221 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_notif_key_p); | |
222 | |
223 ret = RV_OK; | |
224 } | |
225 else | |
226 { | |
227 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
228 ret = RV_MEMORY_ERR; | |
229 } | |
230 } | |
231 } | |
232 } | |
233 | |
234 return ret; | |
235 } | |
236 | |
237 | |
238 /** | |
239 * function: kpd_change_mode | |
240 */ | |
241 T_RV_RET kpd_change_mode( T_KPD_SUBSCRIBER subscriber, | |
242 T_KPD_VIRTUAL_KEY_TABLE* notified_keys_p, | |
243 T_KPD_MODE new_mode) | |
244 { | |
245 T_RV_RET ret = RV_INVALID_PARAMETER; | |
246 T_RVF_MB_STATUS mb_status; | |
247 T_KPD_CHANGE_MODE_MSG* msg_change_mode_p; | |
248 T_SUBSCRIBER_ID subscriber_id; | |
249 UINT8 i; | |
250 | |
251 /* Check if subscriber id is correct */ | |
252 if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE) | |
253 { | |
254 if ( (notified_keys_p != 0) | |
255 && (notified_keys_p->nb_notified_keys > 0) | |
256 && (notified_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) ) | |
257 { | |
258 /* Reserve memory for message */ | |
259 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_CHANGE_MODE_MSG), (void **) &msg_change_mode_p); | |
260 | |
261 if (mb_status != RVF_RED) /* Memory allocation success */ | |
262 { | |
263 /* Fill the message */ | |
264 msg_change_mode_p->hdr.msg_id = KPD_CHANGE_MODE_MSG; | |
265 msg_change_mode_p->subscriber_id = subscriber_id; | |
266 msg_change_mode_p->new_mode = new_mode; | |
267 msg_change_mode_p->notified_keys.nb_notified_keys = notified_keys_p->nb_notified_keys; | |
268 for (i = 0; i < notified_keys_p->nb_notified_keys; i++) | |
269 msg_change_mode_p->notified_keys.notified_keys[i] = notified_keys_p->notified_keys[i]; | |
270 | |
271 /* Send message to the keypad task */ | |
272 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_change_mode_p); | |
273 | |
274 ret = RV_OK; | |
275 } | |
276 else | |
277 { | |
278 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
279 ret = RV_MEMORY_ERR; | |
280 } | |
281 } | |
282 } | |
283 | |
284 return ret; | |
285 } | |
286 | |
287 /** | |
288 * function: kpd_own_keypad | |
289 */ | |
290 T_RV_RET kpd_own_keypad( T_KPD_SUBSCRIBER subscriber, | |
291 BOOL is_keypad_owner, | |
292 T_KPD_VIRTUAL_KEY_TABLE* keys_owner_p) | |
293 { | |
294 T_RV_RET ret = RV_INVALID_PARAMETER; | |
295 T_RVF_MB_STATUS mb_status; | |
296 T_KPD_OWN_KEYPAD_MSG* msg_own_keypad_p; | |
297 T_SUBSCRIBER_ID subscriber_id; | |
298 UINT8 i; | |
299 | |
300 /* Check if subscriber id is correct */ | |
301 if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE) | |
302 { | |
303 /* If subscriber want to be the owner of the keypad, list of keys is checked | |
304 else, subscriber want to release the keypad, check list of key is useless */ | |
305 if (is_keypad_owner == TRUE) | |
306 { | |
307 if ( (keys_owner_p != 0) | |
308 && (keys_owner_p->nb_notified_keys > 0) | |
309 && (keys_owner_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) ) | |
310 ret = RV_OK; | |
311 } | |
312 else | |
313 ret = RV_OK; | |
314 | |
315 if (ret == RV_OK) | |
316 { | |
317 /* Reserve memory for message */ | |
318 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_OWN_KEYPAD_MSG), (void **) &msg_own_keypad_p); | |
319 | |
320 if (mb_status != RVF_RED) /* Memory allocation success */ | |
321 { | |
322 /* Fill the message */ | |
323 msg_own_keypad_p->hdr.msg_id = KPD_OWN_KEYPAD_MSG; | |
324 msg_own_keypad_p->subscriber_id = subscriber_id; | |
325 msg_own_keypad_p->is_keypad_owner = is_keypad_owner; | |
326 msg_own_keypad_p->keys_owner.nb_notified_keys = keys_owner_p->nb_notified_keys; | |
327 for (i = 0; i < keys_owner_p->nb_notified_keys; i++) | |
328 msg_own_keypad_p->keys_owner.notified_keys[i] = keys_owner_p->notified_keys[i]; | |
329 | |
330 /* Send message to the keypad task */ | |
331 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_own_keypad_p); | |
332 } | |
333 else | |
334 { | |
335 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
336 ret = RV_MEMORY_ERR; | |
337 } | |
338 } | |
339 } | |
340 | |
341 return ret; | |
342 } | |
343 | |
344 /** | |
345 * function: kpd_set_key_config | |
346 */ | |
347 T_RV_RET kpd_set_key_config(T_KPD_SUBSCRIBER subscriber, | |
348 T_KPD_VIRTUAL_KEY_TABLE* reference_keys_p, | |
349 T_KPD_VIRTUAL_KEY_TABLE* new_keys_p) | |
350 { | |
351 #ifdef KPD_MODE_CONFIG | |
352 T_RVF_MB_STATUS mb_status; | |
353 T_KPD_SET_CONFIG_MODE_MSG* msg_set_config_mode_p; | |
354 T_RV_RET ret = RV_INVALID_PARAMETER; | |
355 T_SUBSCRIBER_ID subscriber_id; | |
356 UINT8 i; | |
357 INT8 position; | |
358 | |
359 /* Check if subscriber id is correct */ | |
360 if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE) | |
361 { | |
362 if ( (reference_keys_p != 0) | |
363 && (reference_keys_p->nb_notified_keys > 0) | |
364 && (reference_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) | |
365 && (new_keys_p != 0) | |
366 && (new_keys_p->nb_notified_keys > 0) | |
367 && (new_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) | |
368 && (reference_keys_p->nb_notified_keys == new_keys_p->nb_notified_keys) ) | |
369 { | |
370 /* Check if all keys of reference_keys_p are defined in default mode */ | |
371 for (i = 0; i < reference_keys_p->nb_notified_keys; i++) | |
372 { | |
373 ret = kpd_retrieve_virtual_key_position(reference_keys_p->notified_keys[i], | |
374 KPD_DEFAULT_MODE,&position); | |
375 if (ret == RV_INVALID_PARAMETER) | |
376 return ret; | |
377 } | |
378 | |
379 if (ret == RV_OK) | |
380 { | |
381 /* Reserve memory for message */ | |
382 mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_SET_CONFIG_MODE_MSG), (void **) &msg_set_config_mode_p); | |
383 | |
384 if (mb_status != RVF_RED) /* Memory allocation success */ | |
385 { | |
386 /* Fill the message */ | |
387 msg_set_config_mode_p->hdr.msg_id = KPD_SET_CONFIG_MODE_MSG; | |
388 msg_set_config_mode_p->subscriber_id = subscriber_id; | |
389 msg_set_config_mode_p->reference_keys.nb_notified_keys = reference_keys_p->nb_notified_keys; | |
390 for (i = 0; i < reference_keys_p->nb_notified_keys; i++) | |
391 msg_set_config_mode_p->reference_keys.notified_keys[i] = reference_keys_p->notified_keys[i]; | |
392 msg_set_config_mode_p->new_keys.nb_notified_keys = new_keys_p->nb_notified_keys; | |
393 for (i = 0; i < new_keys_p->nb_notified_keys; i++) | |
394 msg_set_config_mode_p->new_keys.notified_keys[i] = new_keys_p->notified_keys[i]; | |
395 | |
396 /* Send message to the keypad task */ | |
397 rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_set_config_mode_p); | |
398 } | |
399 else | |
400 { | |
401 KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR); | |
402 ret = RV_MEMORY_ERR; | |
403 } | |
404 } | |
405 } | |
406 } | |
407 return ret; | |
408 | |
409 #else | |
410 return RV_NOT_SUPPORTED; | |
411 #endif | |
412 } | |
413 | |
414 /** | |
415 * function: kpd_get_available_keys | |
416 */ | |
417 T_RV_RET kpd_get_available_keys( T_KPD_VIRTUAL_KEY_TABLE* available_keys_p) | |
418 { | |
419 kpd_get_default_keys(available_keys_p); | |
420 return RV_OK; | |
421 } | |
422 | |
423 /** | |
424 * function: kpd_get_ascii_key_code | |
425 */ | |
426 T_RV_RET kpd_get_ascii_key_code( T_KPD_VIRTUAL_KEY_ID key, | |
427 T_KPD_MODE mode, | |
428 char** ascii_code_pp) | |
429 { | |
430 INT8 position; | |
431 | |
432 /* Check if mode is authorized */ | |
433 if ( (mode != KPD_DEFAULT_MODE) && (mode != KPD_ALPHANUMERIC_MODE) ) | |
434 return RV_INVALID_PARAMETER; | |
435 | |
436 /* Check if key exist in the defined mode */ | |
437 kpd_retrieve_virtual_key_position(key, mode, &position); | |
438 if (position == KPD_POS_NOT_AVAILABLE) | |
439 return RV_INVALID_PARAMETER; | |
440 | |
441 /* Retrieve ASCII key value */ | |
442 kpd_get_ascii_key_value(position, mode, ascii_code_pp); | |
443 return RV_OK; | |
444 } | |
445 | |
446 /** | |
447 * function: KP_Init | |
448 */ | |
449 void KP_Init( void(pressed(T_KPD_VIRTUAL_KEY_ID)), void(released(void)) ) | |
450 { | |
451 Kp.pressed = pressed; | |
452 Kp.released = released; | |
453 } | |
454 | |
455 | |
456 /*@}*/ |