blob: 2193f7f9581636d40d0aaa4bd2a6060cd9fe4f22 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * keypad_sw.h
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This file is intends for keypad driver and adaption.
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 *
66 * removed!
67 * removed!
68 * removed!
69 *
70 * removed!
71 * removed!
72 * removed!
73 *
74 * removed!
75 * removed!
76 * removed!
77 *
78 * removed!
79 * removed!
80 * removed!
81 *
82 * removed!
83 * removed!
84 * removed!
85 *
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 *
94 * removed!
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 * removed!
105 * removed!
106 * removed!
107 * removed!
108 *
109 * removed!
110 * removed!
111 * removed!
112 * removed!
113 * removed!
114 *
115 * removed!
116 * removed!
117 * removed!
118 * removed!
119 *
120 * removed!
121 * removed!
122 * removed!
123 *
124 * removed!
125 * removed!
126 * removed!
127 *
128 * removed!
129 * removed!
130 * removed!
131 *
132 * removed!
133 * removed!
134 * removed!
135 *
136 * removed!
137 * removed!
138 * removed!
139 *
140 * removed!
141 * removed!
142 * removed!
143 *
144 * removed!
145 * removed!
146 * removed!
147 *
148 * removed!
149 * removed!
150 * removed!
151 *
152 * removed!
153 * removed!
154 * removed!
155 *
156 * removed!
157 * removed!
158 * removed!
159 *
160 * removed!
161 * removed!
162 * removed!
163 *
164 * removed!
165 * removed!
166 * removed!
167 *
168 * removed!
169 * removed!
170 * removed!
171 *
172 * removed!
173 * removed!
174 * removed!
175 *
176 * removed!
177 * removed!
178 * removed!
179 *
180 * removed!
181 * removed!
182 * removed!
183 *
184 * removed!
185 * removed!
186 * removed!
187 *
188 * removed!
189 * removed!
190 * removed!
191 *
192 * removed!
193 * removed!
194 * removed!
195 *
196 * removed!
197 * removed!
198 * removed!
199 *
200 * removed!
201 * removed!
202 * removed!
203 *
204 * removed!
205 * removed!
206 * removed!
207 *
208 * removed!
209 * removed!
210 * removed!
211 *
212 * removed!
213 * removed!
214 * removed!
215 *
216 * removed!
217 * removed!
218 * removed!
219 *
220 * removed!
221 * removed!
222 * removed!
223 *
224 * removed!
225 * removed!
226 * removed!
227 *
228 * removed!
229 * removed!
230 * removed!
231 *
232 * removed!
233 * removed!
234 * removed!
235 *
236 * removed!
237 * removed!
238 * removed!
239 *
240 * removed!
241 * removed!
242 * removed!
243 *
244 * removed!
245 * removed!
246 * removed!
247 * removed!
248 * removed!
249 * removed!
250 * removed!
251 * removed!
252 * removed!
253 * removed!
254 *
255 * removed!
256 * removed!
257 * removed!
258 *
259 * removed!
260 * removed!
261 * removed!
262 *
263 * removed!
264 * removed!
265 * removed!
266 *
267 * removed!
268 * removed!
269 * removed!
270 *
271 * removed!
272 * removed!
273 * removed!
274 *
275 * removed!
276 * removed!
277 * removed!
278 *
279 * removed!
280 * removed!
281 * removed!
282 *
283 * removed!
284 * removed!
285 * removed!
286 *
287 * removed!
288 * removed!
289 * removed!
290 *
291 * removed!
292 * removed!
293 * removed!
294 *
295 * removed!
296 * removed!
297 * removed!
298 *
299 * removed!
300 * removed!
301 * removed!
302 * removed!
303 * removed!
304 * removed!
305 * removed!
306 * removed!
307 * removed!
308 * removed!
309 * removed!
310 * removed!
311 * removed!
312 * removed!
313 * removed!
314 * removed!
315 * removed!
316 * removed!
317 * removed!
318 * removed!
319 * removed!
320 * removed!
321 * removed!
322 * removed!
323 * removed!
324 * removed!
325 * removed!
326 * removed!
327 * removed!
328 * removed!
329 * removed!
330 * removed!
331 * removed!
332 * removed!
333 * removed!
334 * removed!
335 * removed!
336 * removed!
337 * removed!
338 * removed!
339 * removed!
340 * removed!
341 * removed!
342 * removed!
343 * removed!
344 * removed!
345 * removed!
346 * removed!
347 * removed!
348 * removed!
349 * removed!
350 * removed!
351 * removed!
352 * removed!
353 * removed!
354 * removed!
355 * removed!
356 * removed!
357 * removed!
358 * removed!
359 * removed!
360 * removed!
361 * removed!
362 * removed!
363 * removed!
364 * removed!
365 * removed!
366 * removed!
367 * removed!
368 * removed!
369 * removed!
370 * removed!
371 * removed!
372 * removed!
373 * removed!
374 * removed!
375 * removed!
376 * removed!
377 * removed!
378 * removed!
379 * removed!
380 * removed!
381 * removed!
382 * removed!
383 * removed!
384 *------------------------------------------------------------------------------
385 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
386 *============================================================================
387 ****************************************************************************/
388#ifndef _KEYPAD_H
389#define _KEYPAD_H
390
391#include "drv_features.h"
392#include "intrCtrl.h"
393#include "drv_comm.h"
394#include "kal_general_types.h"
395#include "kal_public_defs.h"
396#include "kal_public_api.h"
397#include "keypad_sw.h"
398#include "dcl.h"
399
400
401typedef enum {
402 kbd_1_key_det_mode = 0,
403 kbd_2_keys_det_mode,
404 kbd_3_keys_det_mode
405} kbd_key_det_mode;
406
407
408
409
410
411#define __DCL_KBD_SUPPORT__
412
413#if defined(__EXTEND_QWERTY_KEYPAD__)
414
415#define KBD_MASKIRQ SetINTMask(IRQ_KPAD_CODE)
416#define KBD_UNMASKIRQ RestoreINTMask(IRQ_KPAD_CODE)
417#else
418
419#define KBD_MASKIRQ IRQMask(IRQ_KPAD_CODE)
420#define KBD_UNMASKIRQ IRQUnmask(IRQ_KPAD_CODE)
421
422#endif //#if defined(__EXTEND_QWERTY_KEYPAD__)
423
424#ifdef __EXTRA_A_B_KEY_SUPPORT__
425#define KBD_EX_GPT_HDL_CNT 2
426#else
427#define KBD_EX_GPT_HDL_CNT 0
428#endif
429
430#if defined(__TWO_KEY_DETECTION_SWITCHABLE__)
431 #define KBD_KEY_DETECTION_CNT 2
432#elif defined(__THREE_KEY_DETECTION_SWITCHABLE__)
433 #define KBD_KEY_DETECTION_CNT 3
434#else
435 #define KBD_KEY_DETECTION_CNT 1
436#endif
437
438#define KBD_GPT_HDL_CNT (KBD_EX_GPT_HDL_CNT + KBD_KEY_DETECTION_CNT)
439
440#define EVENT_REQUESTED (KBD_STATUS_CHANGE_EVENT|KBD_SWITCH_DETCTION_MODE_EVENT |KEY_UP_EVENT| KEY_DOWN_EVENT| KEY_RIGHT_EVENT | KEY_LEFT_EVENT)
441
442#if defined(TWO_KEY_ENABLE)
443 #if defined(__TWO_KEY_DETECTION_SWITCHABLE__) || defined(__THREE_KEY_DETECTION_SWITCHABLE__)
444 #error " kbd config conflicts!!"
445 #endif
446#endif
447
448
449typedef struct
450{
451 kal_uint32 kbdmap_reg;
452 kal_uint32 kbdmap_reg1;
453 kal_uint32 kbdmap_reg2;
454}kbd_map_reg_struct;
455
456typedef enum
457{
458 KEY_DIRECTION_EVENT_NUll,
459 KBD_STATUS_CHANGE_EVENT = 0x01, /*keypad status changes event id */
460 KBD_SWITCH_DETCTION_MODE_EVENT = 0x02, /*keypad switch detection mode event id*/
461
462 KEY_UP_EVENT = 0x10,
463 KEY_DOWN_EVENT = 0x20,
464 KEY_LEFT_EVENT = 0x40,
465 KEY_RIGHT_EVENT = 0x80,
466 KEY_DIRECTION_EVENT_ALL = 0xF0
467}kbd_task_event;
468
469
470typedef struct
471{
472 kal_eventgrpid event;
473 DCL_HANDLE gpthandle[KBD_GPT_HDL_CNT];
474
475#ifdef __EXTRA_A_B_KEY_SUPPORT__
476 kal_bool ext_status[2];
477#endif/*__EXTRA_A_B_KEY_SUPPORT__*/
478
479#ifdef __KBD_2STEP_KEY_SUPPORT__
480DCL_HANDLE kbd_2key_handle;
481#endif
482#if defined(__EXTEND_QWERTY_KEYPAD__)
483 DCL_HANDLE kbd_extend_gpthandle;
484 kal_uint32 polling_timeout;
485#endif //#if defined(__EXTEND_QWERTY_KEYPAD__)
486 kal_uint32 longpress_timeout;
487 kal_uint32 repeat_time;
488} kbd_struct;
489
490
491#if defined(__EXTEND_QWERTY_KEYPAD__)
492
493typedef struct
494{
495 kal_bool key_column_all_low_GND[KBD_COLUMN]; //column all low cause by GND_ROW
496 kal_bool key_column_all_low_GPO[KBD_COLUMN]; //column all low cause by GPO_ROW
497}keypad_Ext_QwertyKey_Status;
498 typedef struct
499 {
500 kal_bool key_column_all_low_GND[KBD_COLUMN]; //column all low cause by GND_ROW
501 kal_bool key_column_all_low_GPO[KBD_COLUMN]; //column all low cause by GPO_ROW
502
503 kal_uint8 kbd_press_GND_column[KBD_KEY_DETECTION_CNT]; // which column pressed
504 kal_uint8 kbd_press_GPO_column[KBD_KEY_DETECTION_CNT]; // which column pressed
505 }keypad_Ext_QwertyKey_detect_info_struct;
506
507#endif
508
509 /*keypad detect keys result during one key event*/
510 typedef struct
511 {
512 #if defined(__EXTEND_QWERTY_KEYPAD__)
513 keypad_Ext_QwertyKey_detect_info_struct kbd_Ext_Qwerty_key_info;
514#endif
515 kal_uint8 key_presscount;
516 kal_uint8 key_releasecount;
517 kal_uint8 key_total_count;
518
519 kal_uint8 kbd_press_key[KBD_KEY_DETECTION_CNT];
520 kal_uint8 kbd_release_key[KBD_KEY_DETECTION_CNT];
521
522 } keypad_detect_info_struct;
523
524typedef enum
525{
526 Normal_ROW = 0,
527 Ext_GPO_ROW,
528 Ext_GND_ROW
529}Keypad_ROW_Type;
530
531/*every key information*/
532 typedef struct
533 {
534 kal_bool bKeyStatus; /*0: press; 1: release */
535 kal_uint16 key_index; /*key index defined during customization*/
536
537#if defined(__EXTEND_QWERTY_KEYPAD__)
538 kal_uint8 key_column; /*extend keys in which column*/
539 Keypad_ROW_Type Row_Type;
540#endif
541 }keypad_key_info;
542
543typedef struct
544{
545 kbd_map_reg_struct kbd_map_reg;
546#if defined(__EXTEND_QWERTY_KEYPAD__)
547 kal_bool key_column_all_low_GND[KBD_COLUMN]; //column all low cause by GND_ROW
548 kal_bool key_column_all_low_GPO[KBD_COLUMN]; //column all low cause by GPO_ROW
549 kal_bool extend_switch_mode_key;//when switch mode, the extend key is pressed
550 kal_uint8 extend_key_switch_pressed_num;
551 kal_uint8 kbd_switch_mode_extend_press_key[KBD_KEY_DETECTION_CNT];
552
553#endif
554
555}keypad_status_struct;
556
557#if !defined(KBD_DETECT_ONLY_ONE_KEY) && defined(__EXTRA_A_B_KEY_SUPPORT__)
558 extern const kal_uint8 EXTRA_A_KEY_EINT_NO;
559 extern const kal_uint8 EXTRA_B_KEY_EINT_NO;
560 #define EINT_A_KEY EXTRA_A_KEY_EINT_NO
561 #define EINT_B_KEY EXTRA_B_KEY_EINT_NO
562#endif
563
564#if defined(__TC01__)
565#define kbd_push_time_stamp() \
566{\
567 kal_get_time(&(kbd_buffer.kbd_data_buffer[kbd_buffer.kbd_data_buffer_windex].keytimestamp));\
568}
569
570#define kbd_pop_time_stamp(_key_data) \
571{\
572kbd_data* key_data = (kbd_data*)(_key_data);\
573key_data->keytimestamp = kbd_buffer.kbd_data_buffer[kbd_buffer.kbd_data_buffer_rindex].keytimestamp;\
574}
575
576#else
577#define kbd_push_time_stamp() ;
578#define kbd_pop_time_stamp(_key_data) ;
579#endif
580
581extern void kbdbuffer_get_roomleft_(kal_uint8* pleft);
582
583#define kbdbuffer_get_roomleft(_left) \
584{\
585 kbdbuffer_get_roomleft_(&(_left));\
586}
587
588
589extern void Kbd_Initiaze(void);
590extern kal_bool Kbd_GetDetectionMode(kal_uint8 *pmode);
591extern kal_bool kbd_SetDetectionMode(kbd_key_det_mode mode);
592extern kal_bool kbd_IsKeySupported(kal_uint8 key);
593extern kal_bool kbd_IsKeymutiple(kal_uint8 key);
594extern kal_uint32 Kbd_GetKeyCount(void);
595extern kal_bool Kbd_GetKeyDatas(kbd_data *keydata);
596extern kal_bool Kbd_PeekKeyDatas(kbd_data *keydata, kal_bool specify_read,
597 kal_uint32 read_pointer,kal_uint32* current_read_pointer);
598extern kal_uint32 kbd_SendKey(kal_uint8 key);
599extern void Kbd_SetLongPreTime(kal_uint32 ticks);
600extern void Kbd_SetRepeatPreTime(kal_uint32 ticks);
601
602
603//#include "us_timer.h"
604extern kal_uint32 L1I_GetTimeStamp(void);
605#define KBD_GetTimeStamp L1I_GetTimeStamp
606#if defined(__MTK_INTERNAL__) && !defined(__MAUI_BASIC__) && defined(__DRV_DBG_MEMORY_TRACE_SUPPORT__) && defined(__EXTEND_QWERTY_KEYPAD__)
607#define DRV_KBD_MEMORY_TRACE
608typedef struct{
609 kal_uint16 tag;
610 kal_uint32 time;
611 kal_uint32 data1;
612 kal_uint32 data2;
613}KBD_DRV_DBG_DATA;
614#define MAX_KBD_DRV_DBG_INFO_SIZE 512
615typedef struct{
616 KBD_DRV_DBG_DATA dbg_data[MAX_KBD_DRV_DBG_INFO_SIZE];
617 kal_uint16 dbg_data_idx;
618}KBD_DRV_DBG_STRUCT;
619extern void kbd_drv_dbg_trace(kal_uint16 index, kal_uint32 time, kal_uint32 data1, kal_uint32 data2);
620#define KBD_DBG(a,b,c,d) kbd_drv_dbg_trace(a,b,c,d);
621#else //#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
622#define KBD_DBG(a,b,c,d) ;
623#endif //#if defined(__MTK_INTERNAL__) && !defined(LOW_COST_SUPPORT)
624
625
626#if defined(__DRV_COMM_REG_DBG__) && defined(__DRV_KBD_REG_DBG__)
627#define DRV_KBD_WriteReg(addr,data) DRV_DBG_WriteReg(addr,data)
628#define DRV_KBD_Reg(addr) DRV_DBG_Reg(addr)
629#define DRV_KBD_WriteReg32(addr,data) DRV_DBG_WriteReg32(addr,data)
630#define DRV_KBD_Reg32(addr) DRV_DBG_Reg32(addr)
631#define DRV_KBD_WriteReg8(addr,data) DRV_DBG_WriteReg8(addr,data)
632#define DRV_KBD_Reg8(addr) DRV_DBG_Reg8(addr)
633#define DRV_KBD_ClearBits(addr,data) DRV_DBG_ClearBits(addr,data)
634#define DRV_KBD_SetBits(addr,data) DRV_DBG_SetBits(addr,data)
635#define DRV_KBD_SetData(addr, bitmask, value) DRV_DBG_SetData(addr, bitmask, value)
636#define DRV_KBD_ClearBits32(addr,data) DRV_DBG_ClearBits32(addr,data)
637#define DRV_KBD_SetBits32(addr,data) DRV_DBG_SetBits32(addr,data)
638#define DRV_KBD_SetData32(addr, bitmask, value) DRV_DBG_SetData32(addr, bitmask, value)
639#define DRV_KBD_ClearBits8(addr,data) DRV_DBG_ClearBits8(addr,data)
640#define DRV_KBD_SetBits8(addr,data) DRV_DBG_SetBits8(addr,data)
641#define DRV_KBD_SetData8(addr, bitmask, value) DRV_DBG_SetData8(addr, bitmask, value)
642#else
643#define DRV_KBD_WriteReg(addr,data) DRV_WriteReg(addr,data)
644#define DRV_KBD_Reg(addr) DRV_Reg(addr)
645#define DRV_KBD_WriteReg32(addr,data) DRV_WriteReg32(addr,data)
646#define DRV_KBD_Reg32(addr) DRV_Reg32(addr)
647#define DRV_KBD_WriteReg8(addr,data) DRV_WriteReg8(addr,data)
648#define DRV_KBD_Reg8(addr) DRV_Reg8(addr)
649#define DRV_KBD_ClearBits(addr,data) DRV_ClearBits(addr,data)
650#define DRV_KBD_SetBits(addr,data) DRV_SetBits(addr,data)
651#define DRV_KBD_SetData(addr, bitmask, value) DRV_SetData(addr, bitmask, value)
652#define DRV_KBD_ClearBits32(addr,data) DRV_ClearBits32(addr,data)
653#define DRV_KBD_SetBits32(addr,data) DRV_SetBits32(addr,data)
654#define DRV_KBD_SetData32(addr, bitmask, value) DRV_SetData32(addr, bitmask, value)
655#define DRV_KBD_ClearBits8(addr,data) DRV_ClearBits8(addr,data)
656#define DRV_KBD_SetBits8(addr,data) DRV_SetBits8(addr,data)
657#define DRV_KBD_SetData8(addr, bitmask, value) DRV_SetData8(addr, bitmask, value)
658#endif //#if defined(__DRV_COMM_REG_DBG__) && defined(__DRV_KBD_REG_DBG__)
659
660#endif
661
662
663
664
665