FreeCalypso > hg > tcs211-fcmodem
comparison chipsetsw/drivers/drv_app/kpd/kpd_virtual_key_table_mgt.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 * @file kpd_virtual_key_table_mgt.c | |
3 * | |
4 * Coding of the access function to configuration keypad table. | |
5 * These functions allows to determine : | |
6 * - the ASCII value associated to a virtual key, | |
7 * - The virtual key ID associated to a physical key Id | |
8 * | |
9 * | |
10 * @author Laurent Sollier (l-sollier@ti.com) | |
11 * @version 0.1 | |
12 */ | |
13 | |
14 /* | |
15 * History: | |
16 * | |
17 * Date Author Modification | |
18 * ---------------------------------------- | |
19 * 10/10/2001 L Sollier Create | |
20 * | |
21 * | |
22 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
23 */ | |
24 | |
25 #include "kpd/kpd_virtual_key_table_mgt.h" | |
26 #include "kpd/kpd_virtual_key_table_def.h" | |
27 | |
28 | |
29 /** | |
30 * @name Virtual keys table management functions | |
31 * | |
32 */ | |
33 /*@{*/ | |
34 | |
35 /** | |
36 * function: kpd_initialize_ascii_table | |
37 */ | |
38 T_RV_RET kpd_initialize_ascii_table(void) | |
39 { | |
40 UINT8 i; | |
41 INT8 position = KPD_POS_NOT_AVAILABLE; | |
42 T_VIRTUAL_ASCII_TABLE table; | |
43 | |
44 /* Copy all the table */ | |
45 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
46 { | |
47 table[i].key_id = virtual_ascii_table[i].key_id; | |
48 table[i].default_value_p = virtual_ascii_table[i].default_value_p; | |
49 table[i].alphanumeric_value_p = virtual_ascii_table[i].alphanumeric_value_p; | |
50 } | |
51 | |
52 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
53 { | |
54 if (table[i].key_id != KPD_KEY_NULL) | |
55 { | |
56 /* Retrieve virtual key position (define in fact the pkysical key Id) */ | |
57 kpd_retrieve_virtual_key_position(table[i].key_id, | |
58 KPD_DEFAULT_MODE, | |
59 &position); | |
60 | |
61 if (position == KPD_POS_NOT_AVAILABLE) | |
62 return RV_INTERNAL_ERR; | |
63 | |
64 /* Update ASCII according to the physical key Id */ | |
65 virtual_ascii_table[position].key_id = position; | |
66 virtual_ascii_table[position].default_value_p = table[i].default_value_p; | |
67 virtual_ascii_table[position].alphanumeric_value_p = table[i].alphanumeric_value_p; | |
68 } | |
69 } | |
70 | |
71 return RV_OK; | |
72 } | |
73 | |
74 | |
75 /** | |
76 * function: kpd_get_virtual_key | |
77 */ | |
78 T_KPD_VIRTUAL_KEY_ID kpd_get_virtual_key( T_KPD_PHYSICAL_KEY_ID key_id, | |
79 T_KPD_MODE mode) | |
80 { | |
81 return vpm_table[key_id][mode]; | |
82 } | |
83 | |
84 | |
85 /** | |
86 * function: kpd_get_ascii_key_value | |
87 */ | |
88 T_RV_RET kpd_get_ascii_key_value(T_KPD_PHYSICAL_KEY_ID key_id, | |
89 T_KPD_MODE mode, | |
90 char** ascii_code_pp) | |
91 { | |
92 /* Retrieve ASCII code according to the mode */ | |
93 if (mode == KPD_DEFAULT_MODE) | |
94 *ascii_code_pp = virtual_ascii_table[key_id].default_value_p; | |
95 else if (mode == KPD_ALPHANUMERIC_MODE) | |
96 *ascii_code_pp = virtual_ascii_table[key_id].alphanumeric_value_p; | |
97 else | |
98 *ascii_code_pp = ""; | |
99 | |
100 return RV_OK; | |
101 } | |
102 | |
103 /** | |
104 * function: kpd_retrieve_virtual_key_position | |
105 */ | |
106 T_RV_RET kpd_retrieve_virtual_key_position( T_KPD_VIRTUAL_KEY_ID key_id, | |
107 T_KPD_MODE mode, | |
108 INT8* position_p) | |
109 { | |
110 T_RV_RET ret = RV_INVALID_PARAMETER; | |
111 INT8 i = 0; | |
112 | |
113 *position_p = KPD_POS_NOT_AVAILABLE; | |
114 | |
115 if (key_id != KPD_KEY_NULL) | |
116 { | |
117 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
118 if (vpm_table[i][mode] == key_id) | |
119 { | |
120 *position_p = i; | |
121 ret = RV_OK; | |
122 break; | |
123 } | |
124 } | |
125 | |
126 return ret; | |
127 } | |
128 | |
129 | |
130 /** | |
131 * function: kpd_get_default_keys | |
132 */ | |
133 T_RV_RET kpd_get_default_keys( T_KPD_VIRTUAL_KEY_TABLE* available_keys_p) | |
134 { | |
135 UINT8 nb_available_keys = 0; | |
136 UINT8 i; | |
137 | |
138 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
139 { | |
140 if (vpm_table[i][KPD_DEFAULT_MODE] != KPD_KEY_NULL) | |
141 { | |
142 available_keys_p->notified_keys[nb_available_keys] = vpm_table[i][KPD_DEFAULT_MODE]; | |
143 nb_available_keys++; | |
144 } | |
145 } | |
146 available_keys_p->nb_notified_keys = nb_available_keys; | |
147 | |
148 return RV_OK; | |
149 } | |
150 | |
151 /** | |
152 * function: kpd_check_key_table | |
153 */ | |
154 T_RV_RET kpd_check_key_table(T_KPD_VIRTUAL_KEY_TABLE* keys_table_p, T_KPD_MODE mode) | |
155 { | |
156 UINT8 i; | |
157 INT8 position; | |
158 T_KPD_VIRTUAL_KEY_ID virtual_key; | |
159 UINT8 nb_notified_keys = 0; | |
160 T_RV_RET ret = RV_OK; | |
161 | |
162 if (keys_table_p->nb_notified_keys == KPD_NB_PHYSICAL_KEYS) | |
163 { | |
164 /* Facility: if number of key is KPD_NB_PHYSICAL_KEYS, table of notified_keys | |
165 is automatically fulfilled */ | |
166 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
167 { | |
168 virtual_key = kpd_get_virtual_key(i, mode); | |
169 if (virtual_key != KPD_KEY_NULL) | |
170 { | |
171 keys_table_p->notified_keys[nb_notified_keys] = virtual_key; | |
172 nb_notified_keys++; | |
173 } | |
174 } | |
175 keys_table_p->nb_notified_keys = nb_notified_keys; | |
176 } | |
177 else | |
178 { | |
179 /* In another case (number of key less than KPD_NB_PHYSICAL_KEYS), verify | |
180 that all the virtual keys are defined in the mode requested by the client */ | |
181 for (i = 0; i < keys_table_p->nb_notified_keys; i++) | |
182 { | |
183 ret = kpd_retrieve_virtual_key_position(keys_table_p->notified_keys[i], | |
184 mode, | |
185 &position); | |
186 if ( (ret != RV_OK) || (keys_table_p->notified_keys[i] == KPD_KEY_NULL) ) | |
187 return RV_INVALID_PARAMETER; | |
188 } | |
189 } | |
190 return RV_OK; | |
191 } | |
192 | |
193 /** | |
194 * function: kpd_define_new_config | |
195 */ | |
196 void kpd_define_new_config(T_KPD_VIRTUAL_KEY_TABLE* reference_keys_p, | |
197 T_KPD_VIRTUAL_KEY_TABLE* new_keys_p) | |
198 { | |
199 UINT8 i; | |
200 INT8 position; | |
201 | |
202 /* Unset old values in the table */ | |
203 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
204 vpm_table[i][KPD_MODE_CONFIG] = KPD_KEY_NULL; | |
205 | |
206 /* Set values in the table */ | |
207 for (i = 0; i < reference_keys_p->nb_notified_keys; i++) | |
208 { | |
209 /* */ | |
210 kpd_retrieve_virtual_key_position(reference_keys_p->notified_keys[i], | |
211 KPD_DEFAULT_MODE, | |
212 &position); | |
213 vpm_table[position][KPD_MODE_CONFIG] = new_keys_p->notified_keys[i]; | |
214 } | |
215 } | |
216 | |
217 /** | |
218 * function: kpd_vpm_table_is_valid | |
219 */ | |
220 BOOL kpd_vpm_table_is_valid(void) | |
221 { | |
222 UINT8 i; | |
223 | |
224 for (i = 0; i < KPD_NB_PHYSICAL_KEYS; i++) | |
225 { | |
226 if (vpm_table[i][0] != i) return FALSE; | |
227 } | |
228 | |
229 return TRUE; | |
230 } | |
231 | |
232 /*@}*/ |