source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_user_io.c

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 67.3 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2006, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile:  $
11 * $brcm_Revision:  $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log:  $
19 *
20 ***************************************************************************/
21#include "bsettop_user_io.h"
22#include "gist.h"
23#include "bchp_kbd1.h"
24#if (BCHP_CHIP!=7552)
25#include "bchp_irq0.h"
26#include "bchp_int_id_irq0.h"
27#else
28#include "bchp_irq0_aon.h"
29#include "bchp_int_id_irq0_aon.h"
30#define BCHP_INT_ID_kbd1 BCHP_INT_ID_kbd1_irqen
31#endif
32#include "bchp_memc_misc_0.h"
33#include "bstd.h"
34#include "bir_codes.h"
35#include "bgio.h"
36
37#ifdef ACB612
38#define AOV_GPIO_BUTTON
39#endif
40
41
42#ifdef AOV_GPIO_BUTTON
43#include "bsettop_gpio.h"
44#include "bkni_multi.h"
45#include "bchp_sun_top_ctrl.h"
46#endif
47
48
49BDBG_MODULE(user_io);           /* Register software module with debug interface */
50
51#define BUSER_IO_NUM_EVENTS     4
52
53#define BUSER_IO_MSG    BDBG_MSG
54
55#define SCRATCH_CMD_BASE BCHP_MEMC_MISC_0_SCRATCH_0
56
57#ifndef WriteReg32
58        #define WriteReg32(reg,val) BREG_Write32(GetREG(),reg,val)
59#endif
60#ifndef ReadReg32
61        #define ReadReg32(reg) BREG_Read32(GetREG(),reg)
62#endif
63
64/* Convert timeout from milliseconds to ticks */
65#define MAX_TIMEOUT             MS_TO_TICKS(200)
66#define DEFAULT_PEND_TIMEOUT    5
67
68/* See IR State transition diagram in design document */
69
70typedef enum ir_state_t
71{
72        eSTATE_IDLE,
73        eSTATE_WAIT_NEXT,
74        eSTATE_HOLD
75}ir_state_t;     
76
77/* Key code modifier stored in msb of event but this might not work for all protocols */
78
79typedef enum ir_key_type_t
80{
81        eKEY_DOWN = 0x80000000,
82        eKEY_UP = 0x40000000,
83        eKEY_CMD = 0x20000000,
84}ir_key_type_t;     
85
86
87struct buser_input
88{
89        unsigned int    input_device_type;
90        unsigned int    timeout;
91        unsigned int    pend_timeout;
92        unsigned int    start_time;
93        ir_state_t      state;
94        unsigned int    cur_key;
95        unsigned int    last_key;
96        int             event_cnt;
97        b_queue_t       queue;
98        b_event_t       events[BUSER_IO_NUM_EVENTS];
99
100        BINT_CallbackHandle hChnCallback;
101
102        /* for same kind of IR remote but generate diffrent key map, like Comcast ones */
103        unsigned int    input_device_subtype;   /* build intelligent to diffrentiate them */
104        #ifdef AOV_GPIO_BUTTON
105        BGIO_Pin_Handle hPinChU;
106        BGIO_Pin_Handle hPinChD;
107        BGIO_Pin_Handle hPinChP;
108        #endif
109}buser_input;
110
111struct buser_input s_buser_input = { 0, 40,0,eSTATE_IDLE,0,0};
112
113/***************************************************************************
114Summary:
115        Typedef for CIR parameters
116
117Description:
118        This structure typedef is designed for CIR parameters
119
120See Also:
121        None.
122
123****************************************************************************/
124typedef struct user_io_tspec_t
125{
126        unsigned val;   /* value */
127        unsigned char tol;      /* tolerance select code */
128} user_io_tspec_t;
129
130typedef struct user_io_cir_param_t
131{ /* CIR decoder configuration */
132        unsigned countDivisor;  /* count clock divisor */
133        user_io_tspec_t pa[4],          /* preamble A pulse sequence */
134        pb[4];            /* preamble B pulse sequence */
135        unsigned char paCount;  /* number of entries in pa[] */
136        unsigned char pbCount;  /* number of entries in pb[] */
137        int measurePreamblePulse;/* false => even counts specifies pulse off period */
138        /* true => even counts specifies cycle period */
139        int pbRepeat;           /* if true, pb[] matches a repeat sequence */
140        unsigned pulseTol;              /* pulse tolerance */
141        unsigned t0;            /* T0 */
142        unsigned delT;          /* delta T */
143        int fixSymPulseLast;    /* false => fix-width symbol pulse between */
144        /*   edges 0 & 1 */
145        /* true => fix-width symbol pulse between */
146        /*   edges 1 & 2 */
147        int measureSymPulse;    /* false => measure spacing for complete cycle */
148        /* true => measure spacing between 2 consecutive edges */
149        user_io_tspec_t symPulseWidth;  /* data symbol fix-width pulse period */
150        user_io_tspec_t spacingTol;             /* spacing tolerance value and select code */
151        unsigned nSymA,         /* no. of symbols for sequence with preamble A */
152        nSymB;     /* no. of symbols for sequence with preamble B */
153        unsigned bitsPerSym;    /* no. of data bits per symbol */
154        int mostSignifSymRecvFirst;/* true => most significant symbol received */
155        /*   first */
156        /* false => least significant symbol received */
157        /*   first */
158        int leftAdjustRecvData; /* true => resulting received data is left */
159        /* adjusted using '0' to pad LSBs */
160        /* false => resulting received data is right */
161        /* adjusted using '0' to pad MSBs */
162        int biphaseCoded;               /* true => the input signal is bi-phase coded */
163        /* false => the input signal is pulse spacing */
164        /*   coded */
165        int twoSymPerCy;                /* two symbols per cycle, 1 or 0 */
166        int chkStopSym;                 /* check stop symbol, 1 or 0 */
167        int varLenData;                 /* variable length data, 1 or 0. */
168        unsigned timeoutDivisor;        /* time-out clock divisor */
169        unsigned frameTimeout;  /* frame time-out */
170        unsigned edgeTimeout;   /* edge time-out */
171        unsigned faultDeadTime; /* mininmum dead-time after fault */
172        user_io_tspec_t    stop;                        /* stop */
173        unsigned dataSymTimeout;        /* data symbol timeout */
174
175} user_io_cir_param_t;
176
177static const user_io_cir_param_t rcaParam = {
178        270-1, /* count divisor: count unit = 10us */
179        { {400,1}, {400,1}, {0,0}, {0,0}}, /* pa[], preamble A pulse sequence */
180        { {0,0}, {0,0}, {0,0}, {0,0}},  /* pb[], preamble B pulse sequence */
181        2,         /* number of entries in pa[] */
182        0,         /* number of entries in pb[] */
183        1,         /* measure preamble pulse: */
184        /* 0 => even counts specifies cycle period */
185        /* 1 => even counts specifies off pulse period */
186        0,         /* if true, pb[] matches a repeat sequence */
187        50,        /* pulse tolerance */
188        150,   /* T0 */
189        100,   /* delta T */
190        0,         /* symbol pulse position */
191        /*   0 => fix symbol pulse between edges 0 & 1 */
192        /*   1 => fix symbol pulse between edges 1 & 2 */
193        0,         /* spacing measurement selector */
194        /*   0 => measure complete cycle (edge 0 & 2) */
195        /*   1 => measure spacing between 2 consecutive edges */
196        {50,3}, /* data/stop symbol fix-width pulse period */
197        {0,1}, /* spacing tolerance value = 25% */
198        /* spacing tolerance code: 0: ~12.5% */
199        24-1,  /* no. of symbols for sequence with preamble A */
200        0,         /* no. of symbols for sequence with preamble B */
201        1-1,   /* no. of data bits per symbol */
202        1,         /* most/!least significant symbol received first */
203        0,         /* left/!right adjust received data */
204        0,         /* bi-phase/!pulse-spacing coded */
205        0,         /* two symbols per cycle */
206        0,         /* check stop symbol */
207        0,         /* variable length data */
208        50-1,  /* time-out clock divisor: time-out unit = 10us X 50 = 500us */
209        135,   /* frame time-out: (Tf+20%)/500 = 134.4 */
210        11,        /* edge time-out: (4000+25%)/500+1 = 11 */
211        12,        /* minimum dead-time after fault: 6000/500 = 12 */
212        {0,0}, /* stop symbol pulse or cycle period */
213        0          /* data symbol timeout */
214};
215
216static const user_io_cir_param_t rc5Param = {
217        54-1,                   /* count divisor: divide by 54 for 2.000 us period */
218        { {445,1}, {889,1}, {0,0}, {0,0}}, /* pa[], preamble A pulse sequence */
219        { {889,1}, {0,0}, {0,0}, {0,0}},           /* pb[], preamble B pulse sequence */
220        2,                              /* number of entries in pa[] */
221        1,                              /* number of entries in pb[] */
222        0,                              /* measure preamble pulse: */
223        /*      0 => even counts specifies cycle period */
224        /*      1 => even counts specifies off pulse period */
225        0,                              /* if true, pb[] matches a repeat sequence */
226        445,                    /* pulse tolerance = value not used */
227        889,                    /* bit Period = 1.778 ms (PS T0) */
228        0,                              /* not used for bi-phase (PS delta T) */
229        0,                              /*  - " - (symbol pulse position) */
230        0,                              /*  - " - (measure spacing for complete cycle) */
231        {0, 0},                 /*  - " - (data symbol fix-width pulse period) */
232        {0, 1},                 /* bit period tolerance value = 25% */
233        /* and select code = 12.5% */
234        12-1,                   /* no. of symbols for sequence with preamble A */
235        12-1,                           /* no. of symbols for sequence with preamble B */
236        1-1,                    /* no. of data bits per symbol */
237        1,                              /* most/!least significant symbol received first */
238        0,                              /* left/!right adjust received data */
239        1,                              /* bi-phase/!pulse-spacing coded */
240        0,                              /* two symbols per cycle */
241        0,                              /* check stop symbol */
242        0,                              /* variable length data */
243        250-1,                  /* time-out clock divisor: divide by 250 or .5ms */
244        56,                             /* frame time-out = 28 ms */
245        5,                              /* edge time-out = 2.5 ms */
246        3,                              /* minimum dead-time after fault = 1.5 ms */
247        {0, 0},                 /* stop symbol pulse or cycle period */
248        0                               /* data symbol timeout */
249};
250
251static const user_io_cir_param_t necParam = {
252        270-1,                  /* count divisor */
253        { {900,0}, {450,0}, {0,0}, {0,0}}, /* pa[], preamble A pulse sequence */
254        { {900,0}, {225,0}, {0,0}, {0,0}}, /* pb[], preamble B pulse sequence */
255        2,                              /* number of entries in pa[] */
256        2,                              /* number of entries in pb[] */
257        1,                              /* measure preamble pulse: */
258        /*      0 => even counts specifies cycle period */
259        /*      1 => even counts specifies off pulse period */
260        1,                              /* if true, pb[] matches a repeat sequence */
261        50,                             /* pulse tolerance */
262        113,                    /* bit Period = 1.778 ms (PS T0) */
263        113,                    /* delta T */
264        0,                              /*  - " - (symbol pulse position) */
265        0,                              /*  - " - (measure spacing for complete cycle) */
266        {50, 3},                /*  - " - (data symbol fix-width pulse period) */
267        {0, 1},                 /* bit period tolerance value = 25% */
268        /* and select code = 12.5% */
269        32-1,                   /* no. of symbols for sequence with preamble A */
270        0,                              /* no. of symbols for sequence with preamble B */
271        1-1,                    /* no. of data bits per symbol */
272        1,                              /* most/!least significant symbol received first */
273        0,                              /* left/!right adjust received data */
274        0,                              /* bi-phase/!pulse-spacing coded */
275        0,                              /* two symbols per cycle */
276        0,                              /* check stop symbol */
277        0,                              /* variable length data */
278        50-1,                   /* time-out clock divisor */
279        200,                    /* frame time-out */
280        22,                             /* edge time-out */
281        6,                              /* minimum dead-time after fault = 1.5 ms */
282        {0, 0},                 /* stop symbol pulse or cycle period */
283        0                               /* data symbol timeout */
284};
285
286static const user_io_cir_param_t twirpParam = {
287        90-1,                   /* count divisor: divide by 90 for 3.33us period */
288        { {84,1}, {0,0}, {0,0}, {0,0}},    /* pa[], preamble A pulse sequence */
289        { {0,0}, {0,0}, {0,0}, {0,0}},     /* pb[], preamble B pulse sequence */
290        1,                              /* number of entries in pa[] */
291        0,                              /* number of entries in pb[] */
292        0,                              /* measure preamble pulse: */
293        /*      0 => even counts specifies cycle period */
294        /*      1 => even counts specifies off pulse period */
295        0,                              /* if true, pb[] matches a repeat sequence */
296        84,                             /* pulse tolerance = 0.280 ms */
297        300,                    /* T0 = 1.0000 ms */
298        40+(3<<10),             /* delta T = 0.1358 ms (40.75*t) */
299        1,                              /* false => fix symbol pulse between edges 0 & 1 */
300        /* true => fix symbol pulse between edges 1 & 2 */
301        0,                              /* false => measure spacing for complete cycle */
302        /* true => measure spacing between 2 consecutive edges */
303        {84,1},                 /* data symbol fix-width pulse period = 0.280, */
304        /* tolerance = 25% */
305        {20, 3},                /* spacing tolerance value = .5 DeltaT, */
306        /* and select code = value */
307        8-1,                    /* no. of symbols for sequence with preamble A */
308        0,                              /* no. of symbols for sequence with preamble B */
309        4-1,                    /* no. of data bits per symbol */
310        1,                              /* most/!least significant symbol received first */
311        0,                              /* left/!right adjust received data */
312        0,                              /* bi-phase/!pulse-spacing coded */
313        0,                              /* two symbols per cycle */
314        0,                              /* check stop symbol */
315        0,                              /* variable length data */
316        150-1,                  /* time-out clock divisor: divide by 150 or .5ms */
317        52,                             /* frame time-out = 26 ms */
318        8,                              /* edge time-out = 4 ms */
319        8,                              /* minimum dead-time after fault = 4 ms */
320        {0, 0},                 /* stop symbol pulse or cycle period */
321        0                               /* data symbol timeout */
322};
323
324static const user_io_cir_param_t brcmParam = { /* BRCM silver remote's CIR parameter */
325    270-1,          /* count divisor */
326    { {900,0}, {450,0}, {0,0}, {0,0} }, /* pa[], preamble A pulse sequence */
327    { {900,0}, {225,0}, {0,0}, {0,0} }, /* pb[], preamble B pulse sequence */
328    2,              /* number of entries in pa[] */
329    2,              /* number of entries in pb[] */
330    1,              /* measure preamble pulse: */
331                    /*  0 => even counts specifies cycle period */
332                    /*  1 => even counts specifies off pulse period */
333    1,              /* if true, pb[] matches a repeat sequence */
334    50,             /* pulse tolerance */
335    113,            /* bit Period = 1.778 ms (PS T0) */
336    113,            /* delta T */
337    0,              /*  - " - (symbol pulse position) */
338    0,              /*  - " - (measure spacing for complete cycle) */
339    {50, 3},        /*  - " - (data symbol fix-width pulse period) */
340    {0, 0},         /* bit period tolerance value = not applicable, */
341                    /* and select code = 12.5% */
342    48-1,           /* no. of symbols for sequence with preamble A */
343    0,              /* no. of symbols for sequence with preamble B */
344    1-1,            /* no. of data bits per symbol */
345    0,              /* most/!least significant symbol received first */
346    0,              /* left/!right adjust received data */
347    0,              /* bi-phase/!pulse-spacing coded */
348    0,              /* two symbols per cycle */
349    0,              /* check stop symbol */
350    1,              /* variable length data */
351    50-1,           /* time-out clock divisor */
352    255,            /* frame time-out */
353    22,             /* edge time-out */
354    6,              /* minimum dead-time after fault = 1.5 ms */
355    {0, 0},         /* stop symbol pulse or cycle period */
356    256,              /* data symbol timeout */
357};
358       
359#ifdef CONFIG_GPIO_FRONT_PANNEL
360static unsigned int buser_input_map_key(unsigned int button_id);
361#endif
362
363#ifdef AOV_GPIO_BUTTON
364
365#define MAX_SEND_COMMAND 5
366static uint32_t nCommandLinx[MAX_SEND_COMMAND];
367static int nComCoun = 0; 
368static int data_buf_head = 0;
369static int data_buf_tail = 0;
370#ifdef USE_MUTEX
371static BKNI_MutexHandle bPin_Mutex = NULL;
372#endif
373uint32_t GetCommand()
374{
375        static unsigned returncommand;
376        #ifdef USE_MUTEX
377        if(bPin_Mutex == NULL)
378                BKNI_CreateMutex(&bPin_Mutex);
379
380        BKNI_AcquireMutex(bPin_Mutex);
381        #endif
382        if(nComCoun > 0)
383        {
384                returncommand = nCommandLinx[data_buf_head++];
385                //AOV_DBG_PRINT(("returncommand = 0x%x", returncommand));
386                nComCoun--;
387                if (data_buf_head >= MAX_SEND_COMMAND)
388                        data_buf_head = 0;
389        }
390        else
391        {
392                returncommand = 0xFFFF;
393        }
394        #ifdef USE_MUTEX
395        BKNI_ReleaseMutex(bPin_Mutex);
396        #endif 
397        return  returncommand;
398}
399
400void SetCommand(uint32_t command)
401{
402        #ifdef USE_MUTEX
403        if(bPin_Mutex == NULL)
404                BKNI_CreateMutex(&bPin_Mutex);
405       
406        BKNI_AcquireMutex(bPin_Mutex);
407        #endif 
408        if(nComCoun < MAX_SEND_COMMAND)
409        {
410                nCommandLinx[data_buf_tail++] = command;
411                nComCoun++;
412                if (data_buf_tail >= MAX_SEND_COMMAND)
413                        data_buf_tail = 0;
414        }
415        #ifdef USE_MUTEX
416        BKNI_ReleaseMutex(bPin_Mutex);
417        #endif 
418        return;
419}
420#endif
421
422
423/* User Input API */
424
425/*
426        Summary:
427                Handle the input key state transitions for the IR remote
428*/
429static void handle_ir_input( unsigned int input_key, int port)
430{
431
432        BUSER_IO_MSG(("%s state = %d, timeout = %d, start_time = %d, cur_time = %d,  key = 0x%08x\n"
433                                  ,__FUNCTION__,s_buser_input.state,s_buser_input.timeout,s_buser_input.start_time,bos_getticks(),input_key));
434
435        input_key &= 0x00FFFFFF;
436
437        s_buser_input.cur_key = input_key;
438
439        switch (s_buser_input.state)
440        {
441        case eSTATE_IDLE:
442
443                s_buser_input.start_time = bos_getticks();
444                s_buser_input.last_key = input_key;
445                s_buser_input.state = eSTATE_WAIT_NEXT;
446                s_buser_input.timeout = (port + 1) * MAX_TIMEOUT;
447
448                s_buser_input.event_cnt = 1;
449                bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key));
450                break;
451
452        case eSTATE_WAIT_NEXT:
453
454                if ((s_buser_input.start_time + s_buser_input.timeout) >= bos_getticks())
455                {
456                        if (input_key == s_buser_input.last_key)
457                        {
458                                s_buser_input.start_time = bos_getticks();
459                                BUSER_IO_MSG(("%s:%d start_time = %d\n",__FUNCTION__,__LINE__,s_buser_input.start_time));
460                        }
461                        else if (s_buser_input.event_cnt < 2)
462                        {
463                                s_buser_input.event_cnt++;
464                                bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_UP | s_buser_input.last_key));
465                                s_buser_input.last_key = input_key;
466                                s_buser_input.start_time = bos_getticks();
467                                s_buser_input.event_cnt++;
468                                bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key));
469                                s_buser_input.state = eSTATE_WAIT_NEXT;
470                        }
471                }
472                else if (s_buser_input.event_cnt < 3)
473                {
474                        s_buser_input.last_key = input_key;
475                        s_buser_input.start_time = bos_getticks();
476                        s_buser_input.event_cnt++;
477                        bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key));
478                        s_buser_input.state = eSTATE_WAIT_NEXT;
479                }
480
481                break;
482        case eSTATE_HOLD:
483                /* this state should not happen from remote */
484                break;
485        }
486}
487#ifdef CONFIG_GPIO_FRONT_PANNEL
488/*
489Summary:
490        Handle UPG GPIO interrupts.
491*/
492        #define BUTTON_POWER    (1UL << (35 - 32))
493
494static void upg_gpio_isr(void *data)
495{
496        unsigned int status = ReadReg32(BUTTON_STATUS_REG);
497        if (status & BUTTON_IODIR_MASK)
498        {
499                WriteReg32(LED_DATA_REG, ReadReg32( LED_DATA_REG) & ~LED_GREEN_MASK);
500                if (status & CH_DOWN_BUTTON_MASK)
501                {
502                        handle_ir_input(buser_input_map_key(eIR_CH_DOWN),1);
503                }
504                else if (status & CH_UP_BUTTON_MASK)
505                {
506                        handle_ir_input(buser_input_map_key(eIR_CH_UP),1);
507                }
508#if (BCHP_CHIP==3543) || (BCHP_CHIP == 7002)
509                else if (status & SELECT_BUTTON_MASK)
510                {
511                        handle_ir_input(buser_input_map_key(eIR_SELECT),1);
512                }
513                else if (status & MENU_BUTTON_MASK)
514                {
515                        handle_ir_input(buser_input_map_key(eIR_MENU),1);
516                }
517                else if (status & RFM_CH4_MASK)
518                {
519                        BUSER_IO_MSG(("# RFM switch toggled (0x%08x) #\n",ReadReg32(RFM_CH4_REG) & RFM_CH4_MASK));
520                        if (ReadReg32(RFM_CH4_REG) & RFM_CH4_MASK)
521                                handle_ir_input(0x72,1); /* 4 */
522                        else
523                                handle_ir_input(0x71,1); /* 3 */
524                }
525#else
526                else if (status & BUTTON_POWER)
527                {
528                        handle_ir_input(buser_input_map_key(eIR_POWER),1);
529                }
530#endif
531                WriteReg32(BUTTON_STATUS_REG,status); /* Reset status */
532        }
533}
534
535/*
536Summary:
537        Handle SUN CPU interrupts.
538*/
539        #if (BCHP_CHIP == 3543) || (BCHP_CHIP == 7002)
540static void sun_cpu_isr(void *data)
541{
542        unsigned int status = ReadReg32(BCHP_SUN_L2_CPU_STATUS);
543        if (status & BCHP_SUN_L2_CPU_STATUS_AUX_INTR_MASK)
544        {
545                handle_ir_input(0x47,1);
546        }
547        WriteReg32(BCHP_SUN_L2_CPU_CLEAR,status); /* Reset status */
548}
549        #endif
550/*
551Summary:
552        Handle UPG CPU level 1 interrupts.
553*/
554
555static void upg_cpu_isr(void *data)
556{
557        unsigned int status = ReadReg32(BCHP_IRQ0_IRQSTAT);
558        unsigned int key32;
559        static bool signature = false;
560
561        if (status & BCHP_IRQ0_IRQSTAT_kbd1_MASK)
562        {
563                WriteReg32(LED_DATA_REG, ReadReg32( LED_DATA_REG) & ~LED_GREEN_MASK);
564                key32 = ReadReg32(BCHP_KBD1_DATA0);
565                switch (s_buser_input.input_device_type)
566                {
567                case 0x14:      /* Moto IR, GI */
568                        if ((key32 & 0xffff) || (0 == key32))
569                                handle_ir_input(key32, 0);
570                        break;
571
572                case 0x01:      /* XPM or Twirp */
573                        /* currently two type of COMCAST remotes used. So a build in intelligent here
574                           instead of using compile flag unless it doesn't work well */
575                        /* 0x240f4412 and/or 0x170f443e */
576                        if (0x443e == (key32 & 0x7fff) || 0x4412 == (key32 & 0x7fff))
577                        {
578                                if (0x443e == (key32 & 0x7fff))
579                                        s_buser_input.input_device_subtype = 1;
580                                else
581                                        s_buser_input.input_device_subtype = 0;
582                                signature = true;
583                                /* are there any way to notify the applicaiton for low battery status? */
584                                /* since low battery will affect accuricy of key detection */
585                                /* bit 15 is low battery bit so don't check it */
586                                if (key32 & 0x8000)
587                                {
588                                        BUSER_IO_MSG(("%s: low battery",__func__));
589                                }
590                        }
591                        else if (signature)
592                        {
593                                signature = false;
594                                if (key32 & 0xff)
595                                {
596                                        key32 = 0xff;
597                                }
598                                else
599                                {
600                                        key32 = (key32 >> 8) & 0xff;
601                                }
602                                handle_ir_input(key32,0);
603                        }
604                        break;
605
606                case 0x10:
607                        if ((key32 & 0xc0660000) == 0xc0660000)
608                                handle_ir_input(key32,0);
609                        break;
610                case 0x11: /* RCA sat 1 */
611                        if ((key32 & 0x00700800) == 0x00700800)
612                                handle_ir_input(key32,0);
613                        break;
614                case 0x12: /* RCA sat 2 */
615                        if ((key32 & 0x00200d00) == 0x00200d00)
616                                handle_ir_input(key32,0);
617                        break;
618                default:
619                        handle_ir_input(key32,0);
620                        break;
621                }
622                WriteReg32(BCHP_KBD1_STATUS,0); /* Reset status */
623        }
624}
625#else
626
627typedef void (*irCallback)(unsigned int KeyCode, unsigned int repeat);
628
629static irCallback g_irCallback = 0;
630
631void IR_Open(irCallback ircallback)
632{
633        g_irCallback = ircallback;
634}
635
636
637#define receive_data 0x55
638#define receive_repeat 0x37
639unsigned char block_signal = false;
640
641static void buser_HandleInterrupt_Isr
642(
643void *pParam1,                                          /* Device channel handle */
644int parm2                                                       /* not used */
645)
646{
647        uint32_t            lval;
648        unsigned int key32;
649        static unsigned int past_time;
650        static bool signature = false;
651        static bool valid_key;
652
653        BSTD_UNUSED(pParam1);
654        BSTD_UNUSED(parm2);
655
656        /* Get status interrupt */
657        lval = ReadReg32(BCHP_KBD1_STATUS);
658        //printf("\n === lval %x ==== \n",lval);
659
660        /* Handle key processing */
661        key32 = ReadReg32(BCHP_KBD1_DATA0);
662        //printf(" === key32 %x ==== \n",key32);
663
664    if (g_irCallback) g_irCallback(key32, lval); 
665       
666        switch (s_buser_input.input_device_type)
667        {
668        case 0x14:      /* Moto IR, GI */
669                if ((key32 & 0xffff) || (0 == key32))
670                        handle_ir_input(key32, 0);
671                break;
672
673        case 0x01:      /* XPM or Twirp */
674                /* currently two type of COMCAST remotes used. So a build in intelligent here
675                   instead of using compile flag unless it doesn't work well */
676                /* 0x240f4412 and/or 0x170f443e */
677                if (0x443e == (key32 & 0x7fff) || 0x4412 == (key32 & 0x7fff))
678                {
679                        if (0x443e == (key32 & 0x7fff))
680                                s_buser_input.input_device_subtype = 1;
681                        else
682                                s_buser_input.input_device_subtype = 0;
683                        signature = true;
684                        /* are there any way to notify the applicaiton for low battery status? */
685                        /* since low battery will affect accuricy of key detection */
686                        /* bit 15 is low battery bit so don't check it */
687                        if (key32 & 0x8000)
688                        {
689                                BUSER_IO_MSG(("%s: low battery",__func__));
690                        }
691                }
692                else if (signature)
693                {
694                        signature = false;
695                        if (key32 & 0xff)
696                        {
697                                key32 = 0xff;
698                        }
699                        else
700                        {
701                                key32 = (key32 >> 8) & 0xff;
702                        }
703                        handle_ir_input(key32,0);
704                }
705                break;
706
707        case 0x10:
708                if (s_buser_input.input_device_subtype == 4) {
709                        if ((key32 & 0xc0660000) == 0xc0660000)
710                                handle_ir_input(key32,0);
711                }
712                else if (s_buser_input.input_device_subtype == 0x10) 
713                {
714                        /*janzy@20121106,0x01fe0000 -> 0x01F10000*/
715                        if ((key32 & 0x01F10000) == 0x01F10000)/*new*/
716                                handle_ir_input(key32,0);
717                        else {
718                                /* treat Yellow key in the IR remote as a special case */
719                                if (0x1fe58a7 == key32)         
720                                        handle_ir_input(key32,0);
721                        }
722                }
723                else if (s_buser_input.input_device_subtype == 0x11) 
724                {
725                        if ((key32 & 0x00810000) == 0x00810000)
726                                handle_ir_input(key32,0);
727                }
728                /*janzy@20121030,add remote NEW-xxxx*/
729                else if (s_buser_input.input_device_subtype == 0x12) 
730                {
731                        if ((key32 & 0x80BF0000) == 0x80BF0000)
732                                handle_ir_input(key32,0);
733                }
734                else if (0x15 == s_buser_input.input_device_subtype) 
735                {
736                        if(lval == receive_data)
737                        {
738                                past_time = bos_getticks();
739                                valid_key = true;
740                        }
741                       
742                        if(lval == receive_repeat)
743                        {
744                                if(valid_key==true)
745                                {
746                                        if(bos_getticks() - past_time < 40)     //about 200ms
747                                        {
748                                                past_time = bos_getticks();
749                                        }
750                                        else
751                                        {
752                                                valid_key=false;
753                                        }
754                                }
755                        }
756
757                        if(valid_key==true && block_signal==false)
758                        {               
759                                if ((key32 & 0x04100000) == 0x04100000) 
760                                {
761                                        key32 &= 0x0fffffff;            /* take out high 4 bits to aovid conflect with our IR code status bits */
762                                        handle_ir_input(key32,0);
763                                }
764                        }
765                       
766                }
767                else
768                {
769                        if ((key32 & 0x0000FF00) == 0x0000FF00) 
770                                handle_ir_input(key32>>16, 0);
771                }
772                break;
773        case 0x11: /* RCA sat 1 */
774                if ((key32 & 0x00700800) == 0x00700800)
775                        handle_ir_input(key32,0);
776                break;
777        case 0x12: /* RCA sat 2 */
778                if ((key32 & 0x00200d00) == 0x00200d00)
779                        handle_ir_input(key32,0);
780                break;
781        default:
782                handle_ir_input(key32,0);
783                break;
784        }
785
786        /* Clear interrupt */
787        lval &= ~BCHP_KBD1_STATUS_irq_MASK;
788        WriteReg32(BCHP_KBD1_STATUS, lval);
789
790}
791#endif /* CONFIG_GPIO_FRONT_PANNEL */
792
793
794void buser_WriteCirParam (
795                unsigned int  hChn,               /* Device channel handle */
796                uint32_t                addr,
797                uint32_t                data
798                )
799{
800        uint32_t                lval;
801
802        uint32_t                flags;
803
804        flags = bos_enter_critical();
805        WriteReg32(BCHP_KBD1_CIR_ADDR, addr);
806        lval = data& 0xFFF;
807        WriteReg32(BCHP_KBD1_CIR_DATA, lval);
808        bos_exit_critical(flags);
809
810}
811
812void buser_ConfigCir (
813                const user_io_cir_param_t *pCirParam      /* device configuration structure */
814                )
815{
816        uint32_t        ulData;
817        uint32_t        uli, ulj;
818        unsigned int  hChn = 0;
819
820        buser_WriteCirParam (hChn, 0, pCirParam->frameTimeout);
821
822        ulData = (pCirParam->stop.tol << 10) | (pCirParam->stop.val);
823        buser_WriteCirParam (hChn, 1, ulData);
824
825        ulData = (pCirParam->pbCount << 3) | pCirParam->paCount;
826        buser_WriteCirParam (hChn, 2, ulData);
827
828        for (uli=0, ulj=3; uli<4; uli++)
829        {
830                ulData = ((pCirParam->pa)[uli].tol << 10) | (pCirParam->pa)[uli].val;
831                buser_WriteCirParam (hChn, ulj++, ulData);
832                ulData = ((pCirParam->pb)[uli].tol << 10) | (pCirParam->pb)[uli].val;
833                buser_WriteCirParam (hChn, ulj++, ulData);
834        }
835
836        ulData = (pCirParam->nSymB << 5) | (pCirParam->nSymA & 0x1F) | ((pCirParam->nSymA>>5)<<11);
837        buser_WriteCirParam (hChn, 11, ulData);
838
839        ulData = (pCirParam->symPulseWidth.tol << 10) | pCirParam->symPulseWidth.val;
840        buser_WriteCirParam (hChn, 12, ulData);
841
842        ulData = (pCirParam->spacingTol.tol << 10) | pCirParam->spacingTol.val;
843        buser_WriteCirParam (hChn, 13, ulData);
844
845        buser_WriteCirParam (hChn, 14, pCirParam->t0);
846        buser_WriteCirParam (hChn, 15, pCirParam->delT);
847        buser_WriteCirParam (hChn, 16, pCirParam->countDivisor);
848        buser_WriteCirParam (hChn, 17, pCirParam->pulseTol);
849
850        ulData = (pCirParam->varLenData << 11)
851                | (pCirParam->chkStopSym << 10)
852                | (pCirParam->twoSymPerCy << 9)
853                | (pCirParam->biphaseCoded << 8)
854                | (pCirParam->mostSignifSymRecvFirst << 7)
855                | (pCirParam->leftAdjustRecvData << 6)
856                | (pCirParam->pbRepeat << 5)
857                | (pCirParam->measurePreamblePulse << 4)
858                | (pCirParam->measureSymPulse << 3)
859                | (pCirParam->fixSymPulseLast << 2)
860                | (pCirParam->bitsPerSym & 3);
861        buser_WriteCirParam (hChn, 18, ulData);
862
863        buser_WriteCirParam (hChn, 19, pCirParam->timeoutDivisor);
864        buser_WriteCirParam (hChn, 20, pCirParam->edgeTimeout);
865        buser_WriteCirParam (hChn, 21, pCirParam->faultDeadTime);
866        buser_WriteCirParam (hChn, 22, pCirParam->dataSymTimeout);
867}
868
869/*
870Summary:
871Open a user input object for receiving IR remote and keypad input.
872Description:
873For now, the following id's are used:
8740 - remote a
8751 - remote b
8762 - 56 MHz Sejin IR Keyboard
8773 - keypad (TODO implement)
8784 - ARC-xxx (NEC)
8795 - RCA
8808 - Moto remote, device_type = 0x14
881*/
882#ifdef AOV_GPIO_BUTTON
883BGIO_Pin_Handle pinMute;
884
885
886#define BUTTON_KEY_UP                   0
887#define BUTTON_KEY_DOWN         1
888#define BUTTON_KEY_POWER                2
889#define BUTTON_KEY_EXIT                 3/*janzy@20121115,OSD TimeOut*/
890
891void aov_Set_Button_CHUpDown(unsigned int  keyIn)
892{
893        SetCommand(keyIn);
894        return;
895}
896
897static void aov_PowerButton_callback(void *context)
898{
899        BGIO_PinValue PinValue;
900        BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context;
901        if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0)
902        {
903                if(PinValue == BGIO_PinValue_e0)
904                        SetCommand(BUTTON_KEY_POWER);
905        }
906}
907
908static void aov_ChannelUpButton_callback(void *context)
909{
910        BGIO_PinValue PinValue;
911        BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context;
912        if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0)
913        {
914                if(PinValue == BGIO_PinValue_e0)
915                        SetCommand(BUTTON_KEY_UP);
916
917        }
918}
919
920
921static void aov_ChannelDownButton_callback(void *context)
922{
923        BGIO_PinValue PinValue;
924        BGIO_Pin_Handle hPin = (BGIO_Pin_Handle)context;
925        if(BGIO_Pin_GetValue(hPin,&PinValue ) == 0)
926        {
927                if(PinValue == BGIO_PinValue_e0)
928                        SetCommand(BUTTON_KEY_DOWN);
929
930        }
931}
932
933static void Button_task(void *arg)
934{
935        uint32_t key;
936        static int nDropKeyCnt[3] = {0,0,0};
937        bool isdomsg = false;
938        static int cnt = 0;
939
940        while(1)
941        {
942                key = GetCommand();
943                if(key != 0xFFFF)
944                {       
945                        cnt = 0;
946                        isdomsg = false;
947                        if(key == BUTTON_KEY_POWER && nDropKeyCnt[BUTTON_KEY_POWER] == 0)
948                                isdomsg = true;
949                        else    if(key == BUTTON_KEY_UP && nDropKeyCnt[BUTTON_KEY_UP] == 0)
950                                isdomsg = true;
951                        else    if(key == BUTTON_KEY_DOWN && nDropKeyCnt[BUTTON_KEY_DOWN] == 0)
952                                isdomsg = true;
953
954                        nDropKeyCnt[key] ++;
955
956                        if(isdomsg == true || key == BUTTON_KEY_EXIT)/*janzy@20121115,OSD TimeOut*/
957                        {
958                                s_buser_input.start_time = bos_getticks();
959                                if(key == BUTTON_KEY_POWER)
960                                {
961#if(USERIO_ID == 5)
962                                        s_buser_input.last_key = 0x72a8d5;
963#elif (USERIO_ID == 4)
964                                        s_buser_input.last_key = 0x66b847;
965#elif (USERIO_ID == 10)
966                                        s_buser_input.last_key = 0x1fec03f;
967#elif (USERIO_ID == 11)
968                                        s_buser_input.last_key = 0x8118e7;
969#elif (USERIO_ID == 12)
970                                        s_buser_input.last_key = 0x80bf3bc4;
971#elif (USERIO_ID == 15)
972                                        s_buser_input.last_key = 0x082c00ff;    /* 0x482c00ff, take out 4 high bits */
973#else
974                                        BDBG_ERR(("USERIO_ID %d is not supported for BUTTON_KEY_POWER now", USERIO_ID));
975#endif
976                                }
977                                else if(key == BUTTON_KEY_UP)
978                                {
979#if(USERIO_ID == 5)
980                                        s_buser_input.last_key = 0x72c8d3;
981#elif (USERIO_ID == 4)
982                                        s_buser_input.last_key = 0x66a45b;
983#elif (USERIO_ID == 10)
984                                        s_buser_input.last_key = 0x1fe6897;
985#elif (USERIO_ID == 11)
986                                        s_buser_input.last_key = 0x816897;
987#elif (USERIO_ID == 12)
988                                        s_buser_input.last_key = 0x80bfbb44;
989#elif (USERIO_ID == 15)
990                                        s_buser_input.last_key = 0x082c10ef;    /* 0x482c10ef, take out 4 high bits */
991#else
992                                        BDBG_ERR(("USERIO_ID %d is not supported for BUTTON_KEY_UP now", USERIO_ID));
993#endif
994                                }
995                                else if(key == BUTTON_KEY_DOWN)
996                                {
997#if(USERIO_ID == 5)
998                                        s_buser_input.last_key = 0x72d8d2  ;
999#elif (USERIO_ID == 4)
1000                                        s_buser_input.last_key = 0x66e41b  ;
1001#elif (USERIO_ID == 10)
1002                                        s_buser_input.last_key = 0x1fe20df;
1003#elif (USERIO_ID == 11)
1004                                        s_buser_input.last_key = 0x810af5;
1005#elif (USERIO_ID == 12)
1006                                        s_buser_input.last_key = 0x80bf31ce;
1007#elif (USERIO_ID == 15)
1008                                        s_buser_input.last_key = 0x082c906f;    /* 0x482c906f, take out 4 high bits */
1009#else
1010                                        BDBG_ERR(("USERIO_ID %d is not supported for BUTTON_KEY_DOWN now", USERIO_ID));
1011#endif
1012                                }                               
1013                                else if(key == BUTTON_KEY_EXIT)/*janzy@20121115,OSD TimeOut*/
1014                                {
1015#if(USERIO_ID == 5)
1016                                        s_buser_input.last_key = 0x701111  ;
1017#elif (USERIO_ID == 4)
1018                                        s_buser_input.last_key = 0x661111  ;
1019#elif (USERIO_ID == 10)
1020                                        s_buser_input.last_key = 0x1fe1111;
1021#elif (USERIO_ID == 11)
1022                                        s_buser_input.last_key = 0x811111;
1023#elif (USERIO_ID == 12)
1024                                        s_buser_input.last_key = 0x80bf1111;
1025#else
1026                                        BDBG_ERR(("USERIO_ID %d is not supported for BUTTON KEY EXIT now", USERIO_ID));
1027#endif
1028                                }
1029
1030                                s_buser_input.state = eSTATE_WAIT_NEXT;
1031                                s_buser_input.timeout =  MAX_TIMEOUT;
1032
1033                                s_buser_input.event_cnt = 1;
1034                                if(block_signal==false)
1035                                {
1036                                        //bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key));
1037                                        if (g_irCallback) g_irCallback(eKEY_DOWN | s_buser_input.last_key, 85);
1038                                }
1039                        }
1040                        else
1041                        {
1042                                /*
1043                                   if(key == BUTTON_KEY_POWER)
1044                                   {
1045                                   BDBG_MSG(("Drop BUTTON_KEY_POWER "));
1046                                   }
1047                                   else         if(key == BUTTON_KEY_UP)
1048                                   {
1049                                   BDBG_MSG(("Drop BUTTON_KEY_UP "));
1050                                   }
1051                                   else         if(key == BUTTON_KEY_DOWN)
1052                                   {
1053                                   BDBG_MSG(("Drop BUTTON_KEY_DOWN "));
1054                                   }
1055                                   */
1056
1057                                if(nDropKeyCnt[key] >= 3)
1058                                        nDropKeyCnt[key] = 0;
1059                        }
1060                }
1061                else
1062                {
1063                        cnt++;
1064                        if(cnt >= 3)
1065                        {
1066                                nDropKeyCnt[0] = 0;
1067                                nDropKeyCnt[1] = 0;
1068                                nDropKeyCnt[2] = 0;
1069                        }
1070                }
1071                BKNI_Sleep(100);
1072        } 
1073
1074}
1075#endif
1076buser_input_t buser_input_open(
1077                bobject_t user_input_id /* user input object id */
1078                )
1079{
1080#ifdef AOV_GPIO_BUTTON
1081        static bgpio_t gpioHandle_P;
1082        static bgpio_t gpioHandle_CHU;
1083        static bgpio_t gpioHandle_CHD;
1084
1085        bgpio_settings gpio_settings;
1086        b_task_params task_params;
1087        static b_task_t bprint_task;
1088
1089        BERR_Code err;
1090
1091#endif
1092
1093        static int s_init = 0;
1094        BERR_Code               rc = BERR_SUCCESS;
1095        if (!s_init)
1096        {
1097                s_init = 1;
1098                s_buser_input.timeout = MAX_TIMEOUT;
1099                s_buser_input.pend_timeout = DEFAULT_PEND_TIMEOUT;
1100                bos_create_queue(&s_buser_input.queue,s_buser_input.events,BUSER_IO_NUM_EVENTS);
1101        }
1102
1103        // Disable the CIR
1104        WriteReg32(BCHP_KBD1_CMD,0);
1105        WriteReg32(SCRATCH_CMD_BASE,0);/* make sure there are no values in the Command scratch register on start */
1106
1107        switch (user_input_id)
1108        {
1109                case 0: s_buser_input.input_device_type = 0x4; break;/* remote A */
1110                case 1: s_buser_input.input_device_type = 0x1; break;/* Twirp */
1111                case 2: s_buser_input.input_device_type = 0x2; break;/* Sejin IR keyboard (38.4KHz) */
1112                case 3: s_buser_input.input_device_type = 0x8; break;/* Remote B */
1113                case 8: s_buser_input.input_device_type = 0x14; break;/* Moto remote */
1114                case 5: s_buser_input.input_device_type = 0x11; /* RCA sat 1 */
1115                                buser_ConfigCir(&rcaParam);
1116                                break;
1117                case 6: s_buser_input.input_device_type = 0x12; /* RCA sat 2 */
1118                                buser_ConfigCir(&rcaParam);
1119                                break;
1120                case 7: s_buser_input.input_device_type = 0x21; /* RCA sat 2 */
1121                                buser_ConfigCir(&rc5Param);
1122                                break;
1123                case 4:
1124                                s_buser_input.input_device_type = 0x10; /* Aonvision ARC-xxx */
1125                                s_buser_input.input_device_subtype = 0x4;
1126                                buser_ConfigCir(&necParam);
1127                                break;/* Consumer */
1128
1129                                /*janzy@20120924,add remote MA-35K*/
1130                case 10:
1131                                s_buser_input.input_device_type = 0x10; 
1132                                s_buser_input.input_device_subtype = 0x10;
1133                                buser_ConfigCir(&necParam);
1134                                break;/* Consumer */
1135
1136                                /*janzy@20121008,add remote zrc-4502*/
1137                case 11:
1138                                s_buser_input.input_device_type = 0x10; 
1139                                s_buser_input.input_device_subtype = 0x11;
1140                                buser_ConfigCir(&necParam);
1141                                break;/* Consumer */
1142
1143                                /*janzy@20121030,add remote Skyworth_01*/
1144                case 12:
1145                                s_buser_input.input_device_type = 0x10; 
1146                                s_buser_input.input_device_subtype = 0x12;
1147                                buser_ConfigCir(&necParam);
1148                                break;/* Consumer */
1149
1150                                /* DST IR remote */
1151                case 15:
1152                                s_buser_input.input_device_type = 0x10; 
1153                                s_buser_input.input_device_subtype = 0x15;
1154                                buser_ConfigCir(&necParam);
1155                                break;/* Consumer */
1156
1157                case 9:
1158                default:
1159                                s_buser_input.input_device_type = 0x10; 
1160                                s_buser_input.input_device_subtype = 0x9; /* Silver remote */
1161                                buser_ConfigCir(&brcmParam);
1162                                break;
1163        }
1164
1165
1166#ifdef CONFIG_KIR
1167
1168#if (BCHP_CHIP == 3560)
1169        WriteReg32(BCHP_KBD1_SWITCH_CONFIG, 0x00000006UL);
1170#endif
1171        WriteReg32(BCHP_IRQ0_IRQEN, ReadReg32(BCHP_IRQ0_IRQEN) & ~BCHP_IRQ0_IRQEN_kbd1_MASK);
1172        WriteReg32(BCHP_KBD1_CMD, 
1173                        (ReadReg32(BCHP_KBD1_CMD) & ~(BCHP_KBD1_CMD_kbd_irqen_MASK | BCHP_KBD1_CMD_device_en_MASK)) | s_buser_input.input_device_type /* remote A device type */ );
1174        WriteReg32(BCHP_KBD1_STATUS,0); /* Reset status */
1175
1176        /* set up filter */
1177        WriteReg32(BCHP_KBD1_FILTER1, 0x40);
1178
1179        /* Enable Primary VBI interrupts for closed captioning */
1180        bint_set_handler(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_CPU_INTR_SHIFT,upg_cpu_isr,NULL);
1181        WriteReg32(BCHP_IRQ0_IRQEN,ReadReg32(BCHP_IRQ0_IRQEN) |  BCHP_IRQ0_IRQEN_kbd1_MASK);
1182        bint_enable(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_CPU_INTR_SHIFT,1);
1183
1184        /* Enable interrupts */
1185        WriteReg32(BCHP_KBD1_CMD, ReadReg32(BCHP_KBD1_CMD) | BCHP_KBD1_CMD_kbd_irqen_MASK);
1186
1187        /* configure the GPIO pannel inputs (33,34,35) */
1188
1189        WriteReg32(BUTTON_IODIR_REG, ReadReg32(BUTTON_IODIR_REG) | BUTTON_IODIR_MASK );
1190#if (BCHP_CHIP == 3543) || (BCHP_CHIP == 7002)
1191
1192        // WriteReg32(BCHP_GIO_EC_LO, ReadReg32(BCHP_GIO_EC_LO) | (BUTTON_IODIR_MASK & ~RFM_CH4_MASK) );
1193        WriteReg32(BCHP_GIO_EI_LO, ReadReg32(BCHP_GIO_EI_LO) | RFM_CH4_MASK );
1194#endif
1195        bint_set_handler(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_GPIO_INTR_SHIFT,upg_gpio_isr,&s_buser_input);
1196#if (BCHP_CHIP == 3543) || (BCHP_CHIP == 7002)
1197        bint_set_handler(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_SUN_CPU_INTR_SHIFT,sun_cpu_isr,&s_buser_input);
1198        bint_enable(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_SUN_CPU_INTR_SHIFT,1);
1199        WriteReg32(BCHP_SUN_L2_CPU_MASK_CLEAR, BCHP_SUN_L2_CPU_MASK_CLEAR_AUX_INTR_MASK );
1200#endif
1201        WriteReg32(BCHP_IRQ0_GPIO_IRQEN,ReadReg32(BCHP_IRQ0_GPIO_IRQEN) |  BCHP_IRQ0_GPIO_IRQEN_gio_MASK);
1202        WriteReg32(BUTTON_INT_EN_REG,ReadReg32(BUTTON_INT_EN_REG) | BUTTON_IODIR_MASK);
1203        bint_enable(BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_UPG_GPIO_INTR_SHIFT,1);
1204
1205#else /* CONFIG_KIR */
1206#if (BCHP_CHIP!=7552)
1207        WriteReg32(BCHP_IRQ0_IRQEN, ReadReg32(BCHP_IRQ0_IRQEN) & ~BCHP_IRQ0_IRQEN_kbd1_MASK);
1208#else
1209        WriteReg32(BCHP_IRQ0_AON_IRQEN, ReadReg32(BCHP_IRQ0_AON_IRQEN) & ~BCHP_IRQ0_AON_IRQEN_kbd1_irqen_MASK);
1210#endif
1211        WriteReg32(BCHP_KBD1_CMD, 
1212                        (ReadReg32(BCHP_KBD1_CMD) & ~(BCHP_KBD1_CMD_kbd_irqen_MASK | BCHP_KBD1_CMD_device_en_MASK)) | s_buser_input.input_device_type /* remote A device type */ );
1213        WriteReg32(BCHP_KBD1_STATUS,0); /* Reset status */
1214
1215        /* set up filter */
1216        WriteReg32(BCHP_KBD1_FILTER1, 0x00);
1217
1218        /*
1219         * Register and enable L2 interrupt.
1220         */
1221        rc = BINT_CreateCallback( &(s_buser_input.hChnCallback), GetINT(), BCHP_INT_ID_kbd1,
1222                        buser_HandleInterrupt_Isr, (void *) &s_buser_input, 0x00 );
1223
1224        BDBG_ASSERT(rc == BERR_SUCCESS);
1225        rc = BINT_EnableCallback( s_buser_input.hChnCallback );
1226        BDBG_ASSERT(rc == BERR_SUCCESS);
1227
1228        /* Enable interrupts */
1229        WriteReg32(BCHP_KBD1_CMD, ReadReg32(BCHP_KBD1_CMD) | BCHP_KBD1_CMD_kbd_irqen_MASK);
1230
1231
1232#endif /* CONFIG_KIR */
1233
1234#ifdef AOV_GPIO_BUTTON
1235        uint32_t value;
1236
1237        err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eGpio118,&pinMute);
1238        if (err != BERR_SUCCESS)
1239        {       
1240                pinMute = NULL;
1241                BDBG_ERR(("BGIO_PinId_eGpio118 Fail"));
1242        }
1243
1244        BGIO_Pin_SetType(pinMute,BGIO_PinType_ePushPull);
1245        BGIO_Pin_PushPull_SetValue(pinMute,BGIO_PinValue_e1);
1246
1247        value = ReadReg32(BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8);
1248        value &= ~BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_MASK;
1249        value |= (BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_PULL_UP << BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8_gpio_118_pad_ctrl_SHIFT);
1250        WriteReg32(BCHP_SUN_TOP_CTRL_PIN_MUX_PAD_CTRL_8, value);
1251
1252        err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio06,&s_buser_input.hPinChU);
1253        if (err != BERR_SUCCESS)
1254        {       
1255                s_buser_input.hPinChU = NULL;
1256                BDBG_ERR(("BGIO_PinId_eAgpio05 Fail"));
1257        }
1258
1259        err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio05,&s_buser_input.hPinChD);
1260        if (err != BERR_SUCCESS)
1261        {
1262                s_buser_input.hPinChD = NULL;
1263                BDBG_ERR(("BGIO_PinId_eAgpio06 Fail"));
1264        }
1265
1266        err = BGIO_Pin_Create(GetGIO(),BGIO_PinId_eAgpio07,&s_buser_input.hPinChP);
1267        if (err != BERR_SUCCESS)
1268        {
1269                s_buser_input.hPinChP = NULL;
1270                BDBG_ERR(("BGIO_PinId_eAgpio07 Fail"));
1271        }
1272
1273
1274        gpio_settings.type = eGPIO_AStandard;
1275        gpio_settings.mode = eGPIO_Input;
1276        gpio_settings.intMode = eGPIO_Edge;
1277        gpio_settings.user_callback = aov_PowerButton_callback;
1278        gpio_settings.user_callback_context = s_buser_input.hPinChP;
1279        gpioHandle_P = bgpio_open(BGIO_PinId_eAgpio07, &gpio_settings);
1280
1281        gpio_settings.user_callback = aov_ChannelUpButton_callback;
1282        gpio_settings.user_callback_context = s_buser_input.hPinChU;
1283        gpioHandle_CHU = bgpio_open(BGIO_PinId_eAgpio06, &gpio_settings);
1284
1285        gpio_settings.user_callback = aov_ChannelDownButton_callback;
1286        gpio_settings.user_callback_context = s_buser_input.hPinChD;
1287        gpioHandle_CHD = bgpio_open(BGIO_PinId_eAgpio05, &gpio_settings);
1288
1289        task_params.name = "BUTTON_TASK";
1290        task_params.priority = 8;
1291        task_params.stack_size = 256;
1292        task_params.stack = (unsigned int*)BKNI_Malloc(400 * sizeof(unsigned int));
1293        bos_start_task(&bprint_task,&task_params,Button_task,NULL);
1294
1295#endif
1296
1297        return(buser_input_t)&s_buser_input;
1298}
1299
1300/*
1301Summary:
1302Close a user input handle.
1303Description:
1304Releases all resources associated with the user input object
1305*/
1306void buser_input_close(
1307                buser_input_t ui /* user input object */
1308                )
1309{
1310}
1311
1312#ifdef CONFIG_GPIO_FRONT_PANNEL
1313/*
1314Summary:
1315map gpio based buttons to key code based on current IR remote protocol used
1316
1317*/
1318unsigned int buser_input_map_key(unsigned int button_id)
1319{
1320        unsigned int map_key = button_id;
1321
1322        switch (s_buser_input.input_device_type)
1323        {
1324                default:
1325                        break;
1326
1327                case 0x14:
1328                        switch (button_id)
1329                        {
1330                                case eIR_CH_UP:     map_key = 0x000b; break;
1331                                case eIR_CH_DOWN:   map_key = 0x000c; break;
1332                                case eIR_POWER:     map_key = 0x000a; break;
1333                        }
1334                        break;
1335
1336                case 0x01:
1337                        if (s_buser_input.input_device_subtype)
1338                        {
1339                                switch (button_id)
1340                                {
1341                                        case eIR_CH_UP:     map_key = 0x000d; break;
1342                                        case eIR_CH_DOWN:   map_key = 0x000e; break;
1343                                        case eIR_POWER:     map_key = 0x000f; break;
1344                                }
1345                        }
1346                        else
1347                        {
1348                                switch (button_id)
1349                                {
1350                                        case eIR_CH_UP:     map_key = 0x000d; break;
1351                                        case eIR_CH_DOWN:   map_key = 0x000e; break;
1352                                        case eIR_POWER:     map_key = 0x00d5; break;
1353                                }
1354                        }
1355                        break;
1356
1357                case 0x21:
1358                        switch (button_id)
1359                        {
1360                                case eIR_CH_UP:     map_key = 0x0032; break;
1361                                case eIR_CH_DOWN:   map_key = 0x0033; break;
1362                                case eIR_POWER:     map_key = 0x0092; break;
1363                        }
1364                        break;
1365
1366                case 0x10:
1367                        switch (button_id)
1368                        {
1369                                case eIR_CH_UP:     map_key = 0x005b; break;
1370                                case eIR_CH_DOWN:   map_key = 0x001b; break;
1371                                case eIR_POWER:     map_key = 0x0047; break;
1372                                case eIR_SELECT:    map_key = 0x0033; break;
1373                                case eIR_MENU:      map_key = 0x0067; break;
1374                        }
1375                        break;
1376
1377                case 0x11:
1378                case 0x12:
1379                        switch (button_id)
1380                        {
1381                                case eIR_CH_UP:     map_key = 0x00d2; break;
1382                                case eIR_CH_DOWN:   map_key = 0x00d3; break;
1383                                case eIR_POWER:     map_key = 0x00d5; break;
1384                                case eIR_SELECT:    map_key = 0x0033; break;
1385                                case eIR_MENU:      map_key = 0x0067; break;
1386                        }
1387                        break;
1388
1389        }
1390        return map_key;
1391}
1392#endif
1393
1394/*
1395Summary:
1396Map key codes to match type 0
1397*/
1398unsigned int buser_input_map_code(
1399                unsigned int code /* input code */
1400                )
1401{
1402        unsigned int mapped_code = 0xFF;
1403
1404        if ((code == 0x71) || (code == 0x72)) /* RFM */
1405        {
1406                return code;
1407        }
1408
1409        switch (s_buser_input.input_device_type)
1410        {
1411                default:
1412                        return code;
1413
1414                case 0x14: /* Moto IR remote */
1415                        switch (code)
1416                        {
1417                                default: mapped_code = code; break;
1418
1419                                case 0x01: mapped_code = eIR_1; break;
1420                                case 0x02: mapped_code = eIR_2; break;
1421                                case 0x03: mapped_code = eIR_3; break;
1422                                case 0x04: mapped_code = eIR_4; break;
1423                                case 0x05: mapped_code = eIR_5; break;
1424                                case 0x06: mapped_code = eIR_6; break;
1425                                case 0x07: mapped_code = eIR_7; break;
1426                                case 0x08: mapped_code = eIR_8; break;
1427                                case 0x09: mapped_code = eIR_9; break;
1428                                case 0x00: mapped_code = eIR_0; break;
1429
1430                                case 0x0b: mapped_code = eIR_CH_UP; break;
1431                                case 0x0c: mapped_code = eIR_CH_DOWN; break;
1432
1433                                                   /* mute */
1434                                case 0x0f: mapped_code = eIR_MUTE; break;
1435                                                   /* + vol */
1436                                case 0x0d: mapped_code = eIR_VOL_UP; break;
1437                                                   /* - vol */
1438                                case 0x0e: mapped_code = eIR_VOL_DOWN; break;
1439                                                   /* '-' */
1440                                case 0x39: mapped_code = eIR_DOT; break;
1441
1442                                                   /* C */
1443                                case 0x23: mapped_code = eIR_DEBUG1; break;
1444                                                   /* A */
1445                                case 0x26: mapped_code = eIR_DEBUG2; break;
1446                                                   /* B */
1447                                case 0x27: mapped_code = eIR_POWER_SAVING; break;
1448
1449                                                   /* exit */
1450                                case 0x12: mapped_code = eIR_EXIT; break;
1451                                                   /* menu */
1452                                case 0x19:  mapped_code = eIR_MENU; break;
1453
1454                                                        /* arrow buttons */
1455                                case 0x34: mapped_code = eIR_UP; break;
1456                                case 0x35: mapped_code = eIR_DOWN; break;
1457                                case 0x36: mapped_code = eIR_LEFT; break;
1458                                case 0x37: mapped_code = eIR_RIGHT; break;
1459
1460                                                   /* select or OK */
1461                                case 0x11: mapped_code = eIR_SELECT; break;
1462                                case 0x33: mapped_code = eIR_INFO; break;
1463                                case 0x30: mapped_code = eIR_GUIDE; break;
1464                                case 0x13: mapped_code =  eIR_PRECH; break;
1465
1466                                                   /* power */
1467                                case 0x0a: mapped_code = eIR_POWER; break;
1468
1469                                                   /* help */
1470                                case 0x32:  mapped_code = eIR_HELP; break;
1471
1472                                                        /* FAV */
1473                                case 0x15:  mapped_code = eIR_FAV; break;
1474                        }
1475                        break;
1476
1477                case 0x01: /* Twirp or XPM 1/2 */
1478                        if (s_buser_input.input_device_subtype)
1479                        {
1480                                switch (code)
1481                                {
1482                                        default: mapped_code = code; break;
1483
1484                                        case 0x01:  mapped_code = eIR_1; break;
1485                                        case 0x02:  mapped_code = eIR_2; break;
1486                                        case 0x03:  mapped_code = eIR_3; break;
1487                                        case 0x04:  mapped_code = eIR_4; break;
1488                                        case 0x05:  mapped_code = eIR_5; break;
1489                                        case 0x06:  mapped_code = eIR_6; break;
1490                                        case 0x07:  mapped_code = eIR_7; break;
1491                                        case 0x08:  mapped_code = eIR_8; break;
1492                                        case 0x09:  mapped_code = eIR_9; break;
1493                                        case 0x00:  mapped_code = eIR_0; break;
1494
1495                                        case 0x0d:  mapped_code = eIR_CH_UP; break;
1496                                        case 0x0e:  mapped_code = eIR_CH_DOWN; break;
1497
1498                                                                /* mute */
1499                                        case 0x0c:  mapped_code = eIR_MUTE; break;
1500
1501                                                                /* + vol */
1502                                        case 0x0a:  mapped_code = eIR_VOL_UP; break;
1503
1504                                                                /* - vol */
1505                                        case 0x0b:  mapped_code = eIR_VOL_DOWN; break;
1506                                                                /* '-' no corresponding key */
1507                                                                /* no - */
1508                                                                //case 0x9E:  mapped_code = eIR_DOT; break;
1509
1510                                                                /* red C */
1511                                        case 0x62:  mapped_code = eIR_DEBUG1; break;
1512                                                                /* page down */
1513                                        case 0x29:  mapped_code = eIR_DEBUG2; break;
1514                                                                /* page up */
1515                                        case 0x28:  mapped_code = eIR_POWER_SAVING; break;
1516
1517                                                                /* exit */
1518                                        case 0x2a:  mapped_code = eIR_EXIT; break;
1519                                                                /* menu */
1520                                        case 0x20:  mapped_code = eIR_MENU; break;
1521
1522                                        case 0x21:  mapped_code = eIR_UP; break;
1523                                        case 0x23:  mapped_code = eIR_LEFT; break;
1524                                        case 0x25:  mapped_code = eIR_SELECT; break;
1525                                        case 0x24:  mapped_code = eIR_RIGHT; break;
1526                                        case 0x22:  mapped_code = eIR_DOWN; break;
1527
1528                                        case 0x26:  mapped_code = eIR_INFO; break;
1529                                        case 0x27:  mapped_code = eIR_GUIDE; break;
1530                                        case 0x51:  mapped_code =  eIR_PRECH; break;
1531
1532                                                                /* power */
1533                                        case 0x0f:  mapped_code = eIR_POWER; break;
1534
1535                                                                /* help */
1536                                        case 0x56:  mapped_code = eIR_HELP; break;
1537
1538                                                                /* FAV */
1539                                        case 0x52:  mapped_code = eIR_FAV; break;
1540
1541                                        case 0x82:  mapped_code = eIR_LANG; break;
1542                                }
1543                        }
1544                        else
1545                        {
1546                                switch (code)
1547                                {
1548                                        default: mapped_code = code; break;
1549
1550                                        case 0x01:  mapped_code = eIR_1; break;
1551                                        case 0x02:  mapped_code = eIR_2; break;
1552                                        case 0x03:  mapped_code = eIR_3; break;
1553                                        case 0x04:  mapped_code = eIR_4; break;
1554                                        case 0x05:  mapped_code = eIR_5; break;
1555                                        case 0x06:  mapped_code = eIR_6; break;
1556                                        case 0x07:  mapped_code = eIR_7; break;
1557                                        case 0x08:  mapped_code = eIR_8; break;
1558                                        case 0x09:  mapped_code = eIR_9; break;
1559                                        case 0x00:  mapped_code = eIR_0; break;
1560
1561                                        case 0x0d:  mapped_code = eIR_CH_UP; break;
1562                                        case 0x0e:  mapped_code = eIR_CH_DOWN; break;
1563
1564                                                                /* mute */
1565                                        case 0xC0:  mapped_code = eIR_MUTE; break;
1566                                                                /* + vol */
1567                                        case 0xD0:  mapped_code = eIR_VOL_UP; break;
1568                                                                /* - vol */
1569                                        case 0xD1:  mapped_code = eIR_VOL_DOWN; break;
1570                                                                /* '-' no corresponding key */
1571                                        case 0x9E:  mapped_code = eIR_DOT; break;
1572
1573                                                                /* red C */
1574                                        case 0x91:  mapped_code = eIR_DEBUG1; break;
1575                                                                /* page down */
1576                                        case 0x88:  mapped_code = eIR_DEBUG2; break;
1577                                                                /* page up */
1578                                        case 0x87:  mapped_code = eIR_POWER_SAVING; break;
1579
1580                                                                /* exit */
1581                                        case 0x84:  mapped_code = eIR_EXIT; break;
1582                                                                /* menu */
1583                                        case 0x1c:  mapped_code = eIR_MENU; break;
1584
1585                                        case 0x16:  mapped_code = eIR_UP; break;
1586                                        case 0x18:  mapped_code = eIR_LEFT; break;
1587                                        case 0x1a:  mapped_code = eIR_SELECT; break;
1588                                        case 0x19:  mapped_code = eIR_RIGHT; break;
1589                                        case 0x17:  mapped_code = eIR_DOWN; break;
1590
1591                                        case 0x1b:  mapped_code = eIR_INFO; break;
1592                                        case 0x14:  mapped_code = eIR_GUIDE; break;
1593                                        case 0x11:  mapped_code =  eIR_PRECH; break;
1594
1595                                                                /* power */
1596                                                                /* no power */
1597                                                                //case 0xD5:  mapped_code = eIR_POWER; break;
1598
1599                                                                /* help */
1600                                        case 0x89:  mapped_code = eIR_HELP; break;
1601
1602                                                                /* FAV */
1603                                        case 0x86:  mapped_code = eIR_FAV; break;
1604                                }
1605                        }
1606                        return mapped_code;
1607
1608                case 0x21: /* RC5 */
1609                        switch (code & 0x1F)
1610                        {
1611                                case 11: mapped_code =  eIR_INFO; break;
1612                                case 13: mapped_code =  eIR_MUTE; break;
1613                                case 14: mapped_code =  eIR_GUIDE; break;
1614                                case 16: mapped_code =  eIR_VOL_UP; break;
1615                                case 17: mapped_code =  eIR_VOL_DOWN; break;
1616                                case 32: mapped_code =  eIR_CH_UP; break;
1617                                case 33: mapped_code =  eIR_CH_DOWN; break;
1618                                case 80: mapped_code =  eIR_UP; break;
1619                                case 81: mapped_code =  eIR_DOWN; break;
1620                                case 82: mapped_code =  eIR_MENU; break;
1621                                case 30: mapped_code =  eIR_SELECT; break;
1622                                case 83: mapped_code =  eIR_SELECT; break;
1623                                case 87: mapped_code =  eIR_SELECT; break;
1624                                case 85: mapped_code =  eIR_LEFT; break;
1625                                case 86: mapped_code =  eIR_RIGHT; break;
1626                                case 92: mapped_code =  eIR_POWER; break;
1627                                case 100: mapped_code =  eIR_PRECH; break;
1628                                default:
1629                                                  mapped_code = code & 0x1F; break;
1630                        }
1631                        break;
1632                case 0x10:
1633                        if (s_buser_input.input_device_subtype == 4) /* Aonvision ARC-xxx */
1634                        {
1635                                switch (code)
1636                                {
1637                                        case    0x11:  mapped_code =  eIR_EXIT; break;/*janzy@20121115,OSD TimeOut*/
1638
1639                                                                   /* 1 */
1640                                        case    0xff:  mapped_code =  eIR_1; break;
1641                                                                   /* 2 */
1642                                        case    0xef:  mapped_code =  eIR_2; break;
1643                                                                   /* 3 */
1644                                        case    0xf7:  mapped_code =  eIR_3; break;
1645                                                                   /* + ch */
1646                                        case    0x5b:  mapped_code =  eIR_CH_UP; break;
1647                                                                   /* 4 */
1648                                        case    0x7f:  mapped_code =  eIR_4; break;
1649                                                                   /* 5 */
1650                                        case    0x6f:  mapped_code =  eIR_5; break;
1651                                                                   /* 6 */
1652                                        case    0x77:  mapped_code =  eIR_6; break;
1653                                                                   /* - ch */
1654                                        case    0x1b:  mapped_code =  eIR_CH_DOWN; break;
1655                                                                   /* 7 */
1656                                        case    0xbf:  mapped_code =  eIR_7; break;
1657                                                                   /* 8 */
1658                                        case    0xaf:  mapped_code =  eIR_8; break;
1659                                                                   /* 9 */
1660                                        case    0xb7:  mapped_code =  eIR_9; break;
1661                                                                   /* + vol */
1662                                        case    0x2b:  mapped_code =  eIR_VOL_UP; break;
1663                                                                   /* 0 */
1664                                        case    0x8f:  mapped_code =  eIR_0; break;
1665                                                                   /* mute */
1666                                        case    0x5f:  mapped_code =  eIR_MUTE; break;
1667                                                                   /* - vol */
1668                                        case    0xab:  mapped_code =  eIR_VOL_DOWN; break;
1669                                                                   /* red */
1670                                        case    0xA3: /* ARC-008 */
1671                                        case    0x4f:  mapped_code =  eIR_DOT; break;
1672                                                                   /* green */
1673                                        case    0xa7:  mapped_code =  eIR_ENTER; break;
1674                                                                   /* exit */
1675                                        case    0xf3:  mapped_code =  eIR_MENU; break;
1676                                                                   /* up */
1677                                        case    0xd3:  mapped_code =  eIR_UP; break;
1678                                                                   /* menu */
1679                                        case    0x67:  mapped_code =  eIR_MENU; break;
1680                                                                   /* left */
1681                                        case    0x93:  mapped_code =  eIR_LEFT; break;
1682                                                                   /* ok */
1683                                        case    0x33:  mapped_code =  eIR_SELECT; break;
1684                                                                   /* right */
1685                                        case    0x13:  mapped_code =  eIR_RIGHT; break;
1686                                                                   /* info */
1687                                        case    0x6B: /* ARC-008 */
1688                                        case    0xbb:  mapped_code =  eIR_INFO; break;
1689                                                                   /* down */
1690                                        case    0x53:  mapped_code =  eIR_DOWN; break;
1691                                                                   /* epg */
1692                                        case    0xeb:  mapped_code =  eIR_GUIDE;        break;
1693                                                                   /* power */
1694                                        case    0x47: mapped_code =  eIR_POWER; break;
1695                                                                  /* yellow */
1696                                        case    0xb3:   mapped_code = 0x3a; break;
1697                                                                        /* blue */
1698                                                                        /*RLQ*/
1699                                                                        /* for debug only, use the BLUE button on ARC-006 to simulate Zoom button, instead of 0x3b */
1700                                        case    0xc7:   mapped_code = eIR_AR; break;
1701                                                                        /* scan */
1702                                        case    0xd7: mapped_code =  0xd7;      break;
1703
1704                                                                  /* CC */
1705                                        case    0x87: mapped_code =  eIR_CC; break;
1706
1707#ifdef ACB612
1708                                                                  /* pre-ch */
1709                                        case    0xfb:   /* ARC-006 */
1710                                        case    0x8B
1711                                                                  mapped_code = eIR_PRECH; 
1712                                                                  break;
1713#endif
1714                                }
1715                        }
1716                        else if (s_buser_input.input_device_subtype == 9) 
1717                        {
1718                                switch (code)
1719                                {
1720                                        case 0x52: mapped_code = eIR_0; break;
1721                                        case 0x1f: mapped_code = eIR_1; break;
1722                                        case 0x5e: mapped_code = eIR_2; break;
1723                                        case 0x5f: mapped_code = eIR_3; break;
1724                                        case 0x1b: mapped_code = eIR_4; break;
1725                                        case 0x5a: mapped_code = eIR_5; break;
1726                                        case 0x5b: mapped_code = eIR_6; break;
1727                                        case 0x17: mapped_code = eIR_7; break;
1728                                        case 0x56: mapped_code = eIR_8; break;
1729                                        case 0x57: mapped_code = eIR_9; break;
1730                                        case 0x0a: mapped_code = eIR_POWER; break;
1731                                        case 0x09: mapped_code = eIR_CH_UP; break;
1732                                        case 0x0d: mapped_code = eIR_CH_DOWN; break;
1733                                        case 0x48: mapped_code = eIR_VOL_UP; break;
1734                                        case 0x4c: mapped_code = eIR_VOL_DOWN; break;
1735                                        case 0x01: mapped_code = eIR_MUTE; break;
1736                                        case 0x08: mapped_code = eIR_SELECT; break;
1737                                        case 0x53: mapped_code = eIR_DOT; break;
1738                                        case 0x4f: mapped_code = eIR_MENU; break;
1739                                        case 0x0e: mapped_code = eIR_GUIDE; break;
1740                                        case 0x0f: mapped_code = eIR_INFO; break;
1741                                        case 0x4e: mapped_code = eIR_UP; break;
1742                                        case 0x0c: mapped_code = eIR_DOWN; break;
1743                                        case 0x0b: mapped_code = eIR_LEFT; break;
1744                                        case 0x49: mapped_code = eIR_RIGHT; break;
1745                                        case 0x06: mapped_code = eIR_PRECH; break;
1746                                        case 0x4d: mapped_code = eIR_EXIT; break;
1747                                        case 0x02: mapped_code = eIR_FAV; break;
1748                                        case 0x13: mapped_code = eIR_ENTER; break;
1749                                        case 0x41: mapped_code = eIR_SAP; break;
1750                                        case 0x11: mapped_code = eIR_DEBUG1; break; /* yellow */
1751                                        case 0x50: mapped_code = eIR_DEBUG2; break; /* red */
1752                                }
1753                        }
1754                        else    if (s_buser_input.input_device_subtype == 0x10) /*janzy@20120924,add remote MA-35K*/
1755                        {
1756                                //                      aov_dbg_print(("code = 0x%x",code));
1757                                switch (code)
1758                                {
1759                                        case    0x11:  mapped_code =  eIR_EXIT; break;/*janzy@20121115,OSD TimeOut*/
1760                                                                   /* 1 */
1761                                        case    0x1F:  mapped_code =  eIR_1; break;
1762                                                                   /* 2 */
1763                                        case    0x5F:  mapped_code =  eIR_2; break;
1764                                                                   /* 3 */
1765                                        case    0x9F:  mapped_code =  eIR_3; break;
1766                                                                   /* + ch */
1767                                        case    0x97:  mapped_code =  eIR_CH_UP; break;
1768                                                                   /* 4 */
1769                                        case    0x2F:  mapped_code =  eIR_4; break;
1770                                                                   /* 5 */
1771                                        case    0x6F:  mapped_code =  eIR_5; break;
1772                                                                   /* 6 */
1773                                        case    0xAF:  mapped_code =  eIR_6; break;
1774                                                                   /* - ch */
1775                                        case    0xDF:  mapped_code =  eIR_CH_DOWN; break;
1776                                                                   /* 7 */
1777                                        case    0x0F:  mapped_code =  eIR_7; break;
1778                                                                   /* 8 */
1779                                        case    0x4F:  mapped_code =  eIR_8; break;
1780                                                                   /* 9 */
1781                                        case    0x8F:  mapped_code =  eIR_9; break;
1782                                                                   /* + vol */
1783                                        case    0x17:  mapped_code =  eIR_VOL_UP; break;
1784                                                                   /* 0 */
1785                                        case    0x77:  mapped_code =  eIR_0; break;
1786                                                                   /* mute */
1787                                        case    0xBF:  mapped_code =  eIR_MUTE; break;
1788                                                                   /* - vol */
1789                                        case    0xE7:  mapped_code =  eIR_VOL_DOWN; break;
1790                                                                   /* back */
1791                                        case    0xB7:  mapped_code =  eIR_MENU; break;
1792                                                                   /* up */
1793                                        case    0xEF:  mapped_code =  eIR_UP; break;
1794                                                                   /* left */
1795                                        case    0xC7:  mapped_code =  eIR_LEFT; break;
1796                                                                   /* ok */
1797                                        case    0xCF:  mapped_code =  eIR_SELECT; break;
1798                                                                   /* right */
1799                                        case    0xFF:  mapped_code =  eIR_RIGHT; break;
1800                                                                   /* info */
1801                                        case    0xD7:  mapped_code =  eIR_INFO;         break;
1802                                                                   /* down */
1803                                        case    0xF7:  mapped_code =  eIR_DOWN; break;
1804                                                                   /* power */
1805                                        case    0x3F: mapped_code =  eIR_POWER; break;
1806                                                                  /* exit */
1807                                        case    0x37: mapped_code =  eIR_DOT; break;
1808                                                                  /* epg */
1809                                        case    0x57:  mapped_code =  eIR_CC;   break;
1810                                                                   /* scan */
1811                                        case    0x123:  mapped_code =  0xd7; break;
1812#ifdef ACB612
1813                                        case    0x124:  mapped_code = eIR_PRECH; break;
1814#endif
1815                                }
1816                        }                       
1817                        else    if (s_buser_input.input_device_subtype == 0x11) /*janzy@20120924,add remote ZRC-4502*/
1818                        {
1819                                switch (code)
1820                                {
1821                                        case    0x11:  mapped_code =  eIR_EXIT; break;/*janzy@20121115,OSD TimeOut*/
1822                                                                   /* 1 */
1823                                        case    0xCD:  mapped_code =  eIR_1; break;
1824                                                                   /* 2 */
1825                                        case    0x8F:  mapped_code =  eIR_2; break;
1826                                                                   /* 3 */
1827                                        case    0x4F:  mapped_code =  eIR_3; break;
1828                                                                   /* 4 */
1829                                        case    0x3F:  mapped_code =  eIR_4; break;
1830                                                                   /* 5 */
1831                                        case    0xAF:  mapped_code =  eIR_5; break;
1832                                                                   /* 6 */
1833                                        case    0x6F:  mapped_code =  eIR_6; break;
1834                                                                   /* 7 */
1835                                        case    0xDD:  mapped_code =  eIR_7; break;
1836                                                                   /* 8 */
1837                                        case    0x9F:  mapped_code =  eIR_8; break;
1838                                                                   /* 9 */
1839                                        case    0x5F:  mapped_code =  eIR_9; break;
1840                                                                   /* 0 */
1841                                        case    0xBF:  mapped_code =  eIR_0; break;
1842                                                                   /* mute */
1843                                        case    0xC7:  mapped_code =  eIR_MUTE; break;
1844                                                                   /* MENU */
1845                                        case    0x67:  mapped_code =  eIR_MENU; break;
1846                                                                   /* up */
1847                                        case    0x97:  mapped_code =  eIR_UP; break;
1848                                                                   /* left */
1849                                        case    0xD5:  mapped_code =  eIR_LEFT; break;
1850                                                                   /* ok */
1851                                        case    0xb7:  mapped_code =  eIR_SELECT; break;
1852                                                                   /* right */
1853                                        case    0x57:  mapped_code =  eIR_RIGHT; break;
1854                                                                   /* info */
1855                                        case    0x9D:  mapped_code =  eIR_INFO;         break;
1856                                                                   /* down */
1857                                        case    0xF5:  mapped_code =  eIR_DOWN; break;
1858                                                                   /* power */
1859                                        case    0xE7: mapped_code =  eIR_POWER; break;
1860                                                                  /* exit */
1861                                        case    0x7F: mapped_code =  eIR_DOT; break;
1862                                                                  /* CC */
1863                                        case    0x77:  mapped_code =  eIR_CC;   break;
1864                                                                   //                   /* + vol */
1865                                                                   //                   case    0x57:  mapped_code =  eIR_VOL_UP; break;
1866                                                                   //                   /* - vol */
1867                                                                   //                   case    0xD5:  mapped_code =  eIR_VOL_DOWN; break;
1868                                }
1869                        }
1870                        else    if (s_buser_input.input_device_subtype == 0x12) /*janzy@20121030,add remote Skyworth_01*/
1871                        {
1872                                switch (code)
1873                                {
1874                                        case    0x11:  mapped_code =  eIR_EXIT; break;/*janzy@20121115,OSD TimeOut*/
1875
1876                                                                   /* 1 */
1877                                        case    0xB6:  mapped_code =  eIR_1; break;
1878                                                                   /* 2 */
1879                                        case    0x36:  mapped_code =  eIR_2; break;
1880                                                                   /* 3 */
1881                                        case    0xCC:  mapped_code =  eIR_3; break;
1882                                                                   /* 4 */
1883                                        case    0x8E:  mapped_code =  eIR_4; break;
1884                                                                   /* 5 */
1885                                        case    0x0E:  mapped_code =  eIR_5; break;
1886                                                                   /* 6 */
1887                                        case    0xEC:  mapped_code =  eIR_6; break;
1888                                                                   /* 7 */
1889                                        case    0xAE:  mapped_code =  eIR_7; break;
1890                                                                   /* 8 */
1891                                        case    0x2E:  mapped_code =  eIR_8; break;
1892                                                                   /* 9 */
1893                                        case    0xDC:  mapped_code =  eIR_9; break;
1894                                                                   /* 0 */
1895                                        case    0x1E:  mapped_code =  eIR_0; break;
1896                                                                   /* mute */
1897                                        case    0xC6:  mapped_code =  eIR_MUTE; break;
1898                                                                   /* MENU */
1899                                        case    0x56:  mapped_code =  eIR_MENU; break;
1900                                                                   /* up */
1901                                        case    0xAC:  mapped_code =  eIR_UP; break;
1902                                                                   /* left */
1903                                        case    0x66:  mapped_code =  eIR_LEFT; break;
1904                                                                   /* ok */
1905                                        case    0x8C:  mapped_code =  eIR_SELECT; break;
1906                                                                   /* right */
1907                                        case    0x7C:  mapped_code =  eIR_RIGHT; break;
1908                                                                   /* info */
1909                                        case    0xF4:  mapped_code =  eIR_INFO;         break;
1910                                                                   /* down */
1911                                        case    0xB4:  mapped_code =  eIR_DOWN; break;
1912                                                                   /* power */
1913                                        case    0xC4: mapped_code =  eIR_POWER; break;
1914                                                                  /* DOT */
1915                                        case    0xBE: mapped_code =  eIR_DOT; break;
1916                                                                  /* CC */
1917                                        case    0xBC:  mapped_code =  eIR_CC;   break;
1918                                                                   /* + ch */
1919                                        case    0x44:  mapped_code =  eIR_CH_UP; break;
1920                                                                   /* - ch */
1921                                        case    0xCE:  mapped_code =  eIR_CH_DOWN; break;
1922                                                                   /* exit */
1923                                        case    0x5C:  mapped_code =  eIR_EXIT; break;
1924                                        case    0x94:  mapped_code = eIR_GUIDE; break;
1925
1926                                }
1927                        }
1928                        else if (0x15 == s_buser_input.input_device_subtype) 
1929                        {
1930                                switch (code)
1931                                {
1932#if SUPPORT_DST_PLATFORM
1933                                case 0xf7: mapped_code = 0x1e; break;   //      vk_0
1934                                case 0x77: mapped_code = 0x03; break;   //      vk_1
1935                                case 0xb7: mapped_code = 0x13; break;   //      vk_2
1936                                case 0x37: mapped_code = 0x1b; break;   //      vk_3
1937                                case 0xd7: mapped_code = 0x04; break;   //      vk_4
1938                                case 0x57: mapped_code = 0x14; break;   //      vk_5
1939                                case 0x97: mapped_code = 0x1c; break;   //      vk_6
1940                                case 0x17: mapped_code = 0x05; break;   //      vk_7
1941                                case 0xe7: mapped_code = 0x15; break;   //      vk_8
1942                                case 0x67: mapped_code = 0x1d; break;   //      vk_9
1943                                case 0xff: mapped_code = 0x08; break;   //      vk_power_off
1944                                case 0xef: mapped_code = 0x09; break;   //      vk_ch_up
1945                                case 0x6f: mapped_code = 0x0a; break;   //      vk_ch_down
1946                                case 0x9f: mapped_code = 0x02; break;   //      vk_vol_up
1947                                case 0x1f: mapped_code = 0x01; break;   //      vk_vol_down
1948                                case 0xbb: mapped_code = 0x0b; break;   //      mute
1949                                case 0x7f: mapped_code = 0x0f; break;   //      select == info
1950                                case 0xa7: mapped_code = 0x12; break;   //      dot
1951                                case 0x27: mapped_code = 0x45; break;   //      menu
1952                                case 0x87: mapped_code = 0x47; break;   //      epg
1953                                case 0x4f: mapped_code = 0x0f; break;   //      select == info
1954                                case 0xbf: mapped_code = 0x06; break;   //      navi vk_up
1955                                case 0x3f: mapped_code = 0x07; break;   //      navi vk_down
1956                                case 0xdf: mapped_code = 0x0e; break;   //      navi vk_left
1957                                case 0x5f: mapped_code = 0x17; break;   //      navi vk_right
1958                                case 0xfb: mapped_code = 0x1f; break;   //      prev
1959                                //add
1960                                case 0xcb: mapped_code = 0x18; break;   // meter
1961                                case 0xeb: mapped_code = 0x46; break;   // A/D
1962                                case 0x47: mapped_code = 0x48; break;   // back key
1963                                case 0x3b: mapped_code = 0x44; break;   //audio
1964                                case 0xdb: mapped_code = 0x0c; break;   //resoulution
1965                                case 0x5b: mapped_code = 0x4a; break;   //cc
1966#else
1967
1968                                        case 0xf7: mapped_code = eIR_0; break;
1969                                        case 0x77: mapped_code = eIR_1; break;
1970                                        case 0xb7: mapped_code = eIR_2; break;
1971                                        case 0x37: mapped_code = eIR_3; break;
1972                                        case 0xd7: mapped_code = eIR_4; break;
1973                                        case 0x57: mapped_code = eIR_5; break;
1974                                        case 0x97: mapped_code = eIR_6; break;
1975                                        case 0x17: mapped_code = eIR_7; break;
1976                                        case 0xe7: mapped_code = eIR_8; break;
1977                                        case 0x67: mapped_code = eIR_9; break;
1978                                        case 0xff: mapped_code = eIR_POWER; break;
1979                                        case 0xef: mapped_code = eIR_CH_UP; break;
1980                                        case 0x6f: mapped_code = eIR_CH_DOWN; break;
1981                                        case 0x9f: mapped_code = eIR_VOL_UP; break;
1982                                        case 0x1f: mapped_code = eIR_VOL_DOWN; break;
1983                                        case 0xbb: mapped_code = eIR_MUTE; break;
1984                                        case 0x7f: mapped_code = eIR_SELECT; break;
1985                                        case 0xa7: mapped_code = eIR_DOT; break;
1986                                        case 0x27: mapped_code = eIR_MENU; break;
1987                                        case 0x87: mapped_code = eIR_GUIDE; break;
1988                                        case 0x4f: mapped_code = eIR_INFO; break;
1989                                        case 0xbf: mapped_code = eIR_UP; break;
1990                                        case 0x3f: mapped_code = eIR_DOWN; break;
1991                                        case 0xdf: mapped_code = eIR_LEFT; break;
1992                                        case 0x5f: mapped_code = eIR_RIGHT; break;
1993                                        case 0xfb: mapped_code = eIR_PRECH; break;
1994                                        case 0x5b: mapped_code = eIR_CC; break;
1995                                        case 0xdb: mapped_code = eIR_AR; break;
1996                                        case 0xeb: mapped_code = eIR_INFO; break;
1997                                        case 0xfe: mapped_code = eIR_RF3; break;
1998                                        case 0x7e: mapped_code = eIR_RF4; break;
1999#endif
2000                                }
2001                        }
2002                        break;
2003
2004                case 0x11:
2005                case 0x12:
2006                        switch (code)
2007                        {
2008                                /* 1 */
2009                                case    0xCE:  mapped_code =  eIR_1; break;
2010                                                           /* 2 */
2011                                case    0xCD:  mapped_code =  eIR_2; break;
2012                                                           /* 3 */
2013                                case    0xCC:  mapped_code =  eIR_3; break;
2014                                                           /* + ch */
2015                                case    0xD2:  mapped_code =  eIR_CH_UP; break;
2016                                                           /* 4 */
2017                                case    0xCB:  mapped_code =  eIR_4; break;
2018                                                           /* 5 */
2019                                case    0xCA:  mapped_code =  eIR_5; break;
2020                                                           /* 6 */
2021                                case    0xC9:  mapped_code =  eIR_6; break;
2022                                                           /* - ch */
2023                                case    0xD3:  mapped_code =  eIR_CH_DOWN; break;
2024                                                           /* 7 */
2025                                case    0xC8:  mapped_code =  eIR_7; break;
2026                                                           /* 8 */
2027                                case    0xC7:  mapped_code =  eIR_8; break;
2028                                                           /* 9 */
2029                                case    0xC6:  mapped_code =  eIR_9; break;
2030                                                           /* + vol */
2031                                case    0xD0:  mapped_code =  eIR_VOL_UP; break;
2032                                                           /* 0 */
2033                                case    0xCF:  mapped_code =  eIR_0; break;
2034                                                           /* mute */
2035                                case    0xC0:  mapped_code =  eIR_MUTE; break;
2036                                                           /* - vol */
2037                                case    0xD1:  mapped_code =  eIR_VOL_DOWN; break;
2038                                case    0x9E:  mapped_code =  eIR_DOT; break;   /* RCA '-' */
2039                                                           /* red */
2040                                case    0xF9:  mapped_code =  eIR_DOT; break;
2041                                                           /* green */
2042                                case    0xD8:  mapped_code =  eIR_ENTER; break;
2043                                                           /* exit */
2044                                case    0xF7:  mapped_code =  eIR_MENU; break;
2045                                                           /* up */
2046                                case    0xA6:  mapped_code =  eIR_UP; break;
2047                                                           /* left */
2048                                case    0xA9:  mapped_code =  eIR_LEFT; break;
2049                                                           /* ok */
2050                                case    0x0B:  mapped_code =  eIR_SELECT; break;
2051                                                           /* right */
2052                                case    0xA8:  mapped_code =  eIR_RIGHT; break;
2053                                                           /* info */
2054                                case    0xC3:  mapped_code =  eIR_INFO; break;  /* RCA 'INFO' */
2055                                case    0xFA:  mapped_code =  eIR_INFO; break;
2056                                                           /* down */
2057                                case    0xA7:  mapped_code =  eIR_DOWN; break;
2058                                                           /* epg */
2059                                case    0xE5:  mapped_code =  eIR_GUIDE; break;
2060                                                           /* power */
2061                                case    0xD5: mapped_code =  eIR_POWER; break;
2062                                                          /* yellow */
2063                                case    0xF3:
2064                                case    0x1A:   mapped_code = 0x3a; break;
2065                                                                /* blue */
2066                                case    0xaC:
2067                                case    0x3C:   mapped_code = 0x3b; break;
2068                                                                /* + ch */
2069                                case    0x5b:  mapped_code =  eIR_CH_UP; break;
2070                                                           /* - ch */
2071                                case    0x1b:  mapped_code =  eIR_CH_DOWN; break;
2072                                                           /* power */
2073                                case    0x47:  mapped_code =  eIR_POWER; break;
2074                                case    0x33:  mapped_code =  eIR_SELECT; break;
2075                                case    0x67:  mapped_code =  eIR_MENU; break;
2076                                case    0xfb:  mapped_code = 0xfb; break;       /* SAP support */
2077                                case    0x11:  mapped_code =  eIR_EXIT; break;/*janzy@20121115,OSD TimeOut*/
2078
2079                                                           /*RLQ*/
2080                                case    0x5c:  mapped_code = eIR_AR;
2081                        }
2082                        break;
2083        }
2084        return mapped_code;
2085}
2086
2087/*
2088Summary:
2089Read events from a user input device.
2090
2091Description:
2092Because this function does not return a void* to raw data, but an array of structures,
2093it is not called buser_input_read.
2094*/
2095bresult buser_input_get_event(
2096                buser_input_t ui, /* user input object */
2097                buser_input_event *event, /* [out,size_is(nevents)] event from the user */
2098                unsigned nevents, /* number of entries in the event array */
2099                unsigned *result_nevents /* [out] number of entries read */
2100                )
2101{
2102        uint32_t pend_event;
2103        bresult result = berr_not_available;
2104        *result_nevents = 0;
2105
2106        /*janzy@20121101,enable ir Repeatkey begin*/
2107#define IR_REPEAT_TIME 100
2108        static unsigned int Old_Key = 0xFFFF;
2109        static unsigned int old_time;
2110        unsigned int IrKey;
2111        bool isRepeatkey;
2112        /*end*/ 
2113
2114        if (ReadReg32(SCRATCH_CMD_BASE))
2115        {
2116                s_buser_input.start_time = bos_getticks();
2117                s_buser_input.last_key = ReadReg32(SCRATCH_CMD_BASE);
2118                if ((eKEY_DOWN & s_buser_input.last_key) != 0)
2119                {
2120                        s_buser_input.state = eSTATE_HOLD;
2121                }
2122                else
2123                {
2124                        s_buser_input.state = eSTATE_IDLE;
2125                }
2126                s_buser_input.timeout = MAX_TIMEOUT;
2127                WriteReg32(SCRATCH_CMD_BASE,0);
2128                s_buser_input.event_cnt = 1;
2129                bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | eKEY_CMD | s_buser_input.last_key));
2130        }
2131
2132        pend_event = (unsigned int)bos_pend_event(s_buser_input.queue,s_buser_input.pend_timeout);
2133
2134        if (pend_event)
2135        {
2136                /* To match settop api behavior only return key down events and
2137                   throw away key up events */
2138                *result_nevents = 1;
2139                event[0].code = pend_event & 0xFF;/* To provide same key code as settop api */
2140                if (!(pend_event & eKEY_CMD))
2141                {
2142                        event[0].code = buser_input_map_code(event[0].code);
2143                }
2144
2145                if (event[0].code == 0xFF)
2146                        *result_nevents = 0;
2147
2148                if (pend_event & eKEY_UP)
2149                        event[0].code |= eKEY_UP;
2150                result = b_ok;
2151                BUSER_IO_MSG(("%s:%d, event = 0x%08x\n",__FUNCTION__,__LINE__,event[0].code));
2152        }
2153        else if (s_buser_input.state == eSTATE_WAIT_NEXT)
2154        {
2155
2156                /*janzy@20121101,enable ir Repeatkey begin*/
2157                isRepeatkey = false;
2158                IrKey = buser_input_map_code(s_buser_input.last_key & 0xFF);
2159                if(IrKey == eIR_VOL_UP || IrKey == eIR_VOL_DOWN || IrKey == eIR_LEFT || IrKey == eIR_RIGHT)
2160                {
2161                        if(Old_Key != IrKey)
2162                        {
2163                                Old_Key = IrKey;
2164                                old_time = s_buser_input.start_time;
2165                        }
2166                        else
2167                        {
2168                                if(s_buser_input.start_time - old_time >= IR_REPEAT_TIME)
2169                                {
2170                                        isRepeatkey = true;
2171                                        old_time = s_buser_input.start_time;
2172                                }
2173                        }
2174                }
2175                /*end*/
2176
2177
2178                if ((s_buser_input.start_time + s_buser_input.timeout < bos_getticks()) || isRepeatkey)
2179                {
2180                        BUSER_IO_MSG(("%s:%d, timeout %d < %d\n",__FUNCTION__,__LINE__,s_buser_input.start_time + s_buser_input.timeout,bos_getticks()));
2181                        s_buser_input.state = eSTATE_IDLE;
2182                        *result_nevents = 1;
2183                        event[0].code = s_buser_input.last_key & 0xFF;/* To provide same key code as settop api */
2184                        event[0].code = buser_input_map_code(event[0].code);
2185
2186                        if (event[0].code == 0xFF)
2187                                *result_nevents = 0;
2188                        else
2189                                event[0].code |= eKEY_UP; /* add modifier flag to identify as key up */
2190                        result = b_ok;
2191                        BUSER_IO_MSG(("%s:%d, event = 0x%08x\n",__FUNCTION__,__LINE__,event[0].code));
2192                        return result;
2193
2194                }
2195        }
2196
2197        return result;
2198}
2199
2200void buser_input_sim_key(uint32_t code)
2201{
2202        code |= eKEY_UP;
2203        BREG_Write32(GetREG(),SCRATCH_CMD_BASE,code);
2204}
2205
2206int AOV_buser_input_GetButtonfactory(void)
2207{       
2208        int rc = 0;
2209#ifdef ACB612
2210        BGIO_PinValue PinValuePower,PinValueChannelUp,PinValueChannelDown;
2211
2212        if(     s_buser_input.hPinChU == NULL ||        s_buser_input.hPinChD == NULL ||        s_buser_input.hPinChP == NULL)
2213        {
2214                BDBG_MSG(("AOV_buser_input_GetButtonfactory  Faill"));
2215                return rc;
2216        }
2217
2218        if(BGIO_Pin_GetValue(s_buser_input.hPinChP,&PinValuePower ) == 0)
2219        {
2220                if(PinValuePower == BGIO_PinValue_e0)
2221                        rc = 0x001;
2222        }
2223
2224
2225        if(BGIO_Pin_GetValue(s_buser_input.hPinChU,&PinValueChannelUp ) == 0)
2226        {
2227                if(PinValueChannelUp == BGIO_PinValue_e0)
2228                        rc += 0x010;
2229        }
2230
2231
2232        if(BGIO_Pin_GetValue(s_buser_input.hPinChD,&PinValueChannelDown ) == 0)
2233        {
2234                if(PinValueChannelDown == BGIO_PinValue_e0)
2235                        rc += 0x100;
2236        }
2237
2238        //      BDBG_MSG3(("RC = 0x%x",rc));
2239#endif
2240
2241        return rc;
2242
2243}
Note: See TracBrowser for help on using the repository browser.