source: svn/trunk/newcon3bcm2_21bu/dta/src/app/bapp_remote.c @ 2

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 7.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2010, 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 "bapp_remote.h"
22#include "bos.h"
23#include "bir_codes.h"
24#include "bsettop_user_io.h"
25
26BDBG_MODULE(app_remote);                /* Register software module with debug interface */
27
28#define BUSER_IO_NUM_EVENTS     16
29
30#define BUSER_IO_MSG    BDBG_ERR
31
32        /* Convert timeout from milliseconds to ticks */
33#define MAX_TIMEOUT             ((300 * g_ticks_per_second)/ 1000)
34#define DEFAULT_PEND_TIMEOUT    10 /* in milliseconds */
35
36
37static bapp_remote_config_t s_config = { 8, false/*rf4ce*/, true/*ir*/ };
38
39struct bapp_remote
40{
41        /* User IO */
42    buser_input_t userio;
43       
44        unsigned int    timeout;
45        unsigned int    pend_timeout;
46
47        b_queue_t               queue;
48        b_event_t               events[BUSER_IO_NUM_EVENTS];
49};
50
51static struct bapp_remote *s_p_remote = NULL;
52
53/* User Input API */
54
55/*
56Summary:
57Open a user input object for receiving IR remote and keypad input.
58Description:
59For now, the following id's are used:
600 - remote a
611 - remote b
622 - 56 MHz Sejin IR Keyboard
633 - keypad (TODO implement)
648 - Moto remote, device_type = 0x14
65 */
66bapp_result_t bapp_remote_open(bapp_remote_t *p_remote)
67{
68        *p_remote = (struct bapp_remote*)BKNI_Malloc(sizeof(struct bapp_remote)); 
69        if (!*p_remote)
70                return eBAPP_RESULT_ALLOC_FAILURE;
71       
72        BKNI_Memset(*p_remote,0,sizeof(struct bapp_remote));
73
74        bos_create_queue(&(*p_remote)->queue,(*p_remote)->events,BUSER_IO_NUM_EVENTS);
75        if (!(*p_remote)->queue)
76        {
77                bapp_remote_close(*p_remote);
78                return eBAPP_RESULT_ALLOC_FAILURE;
79        }
80
81        /* USER IO */
82        (*p_remote)->userio = buser_input_open(B_ID(s_config.user_io_id));
83
84        s_p_remote = *p_remote;
85
86        s_p_remote->pend_timeout = DEFAULT_PEND_TIMEOUT;
87
88        return eBAPP_RESULT_OK;
89}
90
91/*
92Summary:
93Close a user input handle.
94Description:
95Releases all resources associated with the user input object
96 */
97void bapp_remote_close(
98                bapp_remote_t handle /* user input object */
99                )
100{
101        struct bapp_remote *p_remote = (struct bapp_remote*)handle;
102
103        if (p_remote->queue)
104        {
105                bos_delete_queue(&p_remote->queue);
106        }
107
108
109        /* USER IO */
110        if (handle->userio)
111        {
112                buser_input_close(handle->userio);
113        }
114
115        BKNI_Free(p_remote);
116}
117/*
118Summary:
119        Map key codes to match type 0
120 */
121static unsigned int bapp_remote_map( unsigned int code )
122{
123        unsigned int mapped_code = 0xFF;
124        BDBG_ERR(("############### %s, code = 0x%08x\n",__FUNCTION__,code));
125        code &= 0x000000FF;
126        switch (code)
127        {
128                default: mapped_code = code; break;
129
130                case 0x09:  mapped_code = eIR_MENU; break;
131                case 0x37:  mapped_code = eIR_PGUP; break;
132                case 0x38:  mapped_code = eIR_PGDOWN; break;
133                case 0x0d:  mapped_code = eIR_EXIT; break;
134                case 0x4c:  mapped_code = eIR_PRECH; break; /* TODO: */
135#if 0
136                case 0x74:  mapped_code = eIR_A; break;
137                case 0x71:  mapped_code = eIR_B; break;
138                case 0x72:  mapped_code = eIR_C; break;
139                case 0x73:  mapped_code = eIR_D; break;
140#endif
141                case 0x00:  mapped_code = eIR_SELECT; break;
142                case 0x01:  mapped_code = eIR_UP; break;
143                case 0x02:  mapped_code = eIR_DOWN; break;
144                case 0x03:  mapped_code = eIR_LEFT; break;
145                case 0x04:  mapped_code = eIR_RIGHT; break;
146                case 0x0b:  mapped_code = eIR_GUIDE; break;
147                case 0x6b:  mapped_code = eIR_POWER; break;
148
149                case 0x21:  mapped_code = eIR_1; break;
150                case 0x22:  mapped_code = eIR_2; break;
151                case 0x23:  mapped_code = eIR_3; break;
152                case 0x24:  mapped_code = eIR_4; break;
153                case 0x25:  mapped_code = eIR_5; break;
154                case 0x26:  mapped_code = eIR_6; break;
155                case 0x27:  mapped_code = eIR_7; break;
156                case 0x28:  mapped_code = eIR_8; break;
157                case 0x29:  mapped_code = eIR_9; break;
158                case 0x20:  mapped_code = eIR_0; break;
159
160                case 0x30:  mapped_code = eIR_CH_UP; break;
161                case 0x31:  mapped_code = eIR_CH_DOWN; break;
162
163                                /* mute */
164                case 0x43:  mapped_code = eIR_MUTE; break;
165
166                                /* + vol */
167                case 0x41:  mapped_code = eIR_VOL_UP; break;
168
169                                /* - vol */
170                case 0x42:  mapped_code = eIR_VOL_DOWN; break;
171
172                                /* exit */
173                case 0x2a:  mapped_code = eIR_EXIT; break;
174                case 0x2b:  mapped_code = eIR_SELECT; break;
175
176                case 0x35:  mapped_code = eIR_INFO; break;
177                case 0x32:  mapped_code =  eIR_PRECH; break;
178
179                                /* power off/on */
180                case 0x6c:
181                case 0x6d:
182                                 mapped_code = eIR_POWER; break;
183
184                                /* help */
185                case 0x56:  mapped_code = eIR_HELP; break;
186
187                                /* FAV */
188                case 0x52:  mapped_code = eIR_FAV; break;
189                case 0x53:  mapped_code = eIR_GUIDE; break;
190                case 0xfd:  mapped_code = eIR_LANG; break;
191        }
192        return mapped_code;
193}
194
195/*
196Summary:
197map gpio based buttons to key code based on current IR remote protocol used
198
199 */
200static unsigned int bapp_remote_map_code(
201        bapp_remote_t handle, /* user input object */
202        unsigned int button_id)
203{
204        return bapp_remote_map(button_id);
205}
206
207/*
208Summary:
209Read events from a user input device.
210
211Description:
212Because this function does not return a void* to raw data, but an array of structures,
213it is not called buser_input_read.
214 */
215bapp_result_t bapp_remote_get_event(
216                bapp_remote_t handle, /* user input object */
217                bapp_event_t *p_event /* [out] event from the user input device */
218                )
219{
220        uint32_t pend_event;
221        bapp_result_t result = eBAPP_RESULT_BUSY;
222        unsigned int event_cnt;
223        struct bapp_remote *p_remote = (struct bapp_remote*)handle; 
224
225
226        /* check first IR remote  (10ms timeout is consumed) */
227        if (buser_input_get_event(p_remote->userio,(buser_input_event*)p_event,1,&event_cnt) == b_ok)
228        {
229                if (event_cnt > 0) {
230                        if (s_config.use_ir)
231                                return eBAPP_RESULT_OK;
232                        else 
233                                return eBAPP_RESULT_TIMEOUT;
234                }
235                else {
236                        return eBAPP_RESULT_TIMEOUT;
237                }
238        }
239
240        /* for RF4CE remote */
241        pend_event = (unsigned int)bos_pend_event(p_remote->queue,p_remote->pend_timeout);
242
243        if (pend_event)
244        {
245                if (!s_config.use_rf4ce) 
246                        return eBAPP_RESULT_TIMEOUT;
247
248                BDBG_ERR(("%s, pend_event = 0x%08x\n",__FUNCTION__,pend_event));
249               
250                p_event->code = pend_event & 0xFF;
251
252                if (!(pend_event & eKEY_CMD))
253                {
254                        p_event->code = bapp_remote_map_code(handle,p_event->code);
255                }
256
257                if (pend_event & eKEY_UP)
258                        p_event->code |= eKEY_UP;
259                result = eBAPP_RESULT_OK;
260                BUSER_IO_MSG(("%s, event = 0x%08x\n",__FUNCTION__,p_event->code));
261        }
262
263        return result;
264}
265
266void bapp_remote_set_config(
267                                                bapp_remote_config_t *p_config
268                                                )
269{
270        BKNI_Memcpy(&s_config,p_config,sizeof(s_config));
271}
272void bapp_remote_get_config(
273                                                bapp_remote_config_t *p_config
274                                                )
275{
276        BKNI_Memcpy(p_config,&s_config,sizeof(s_config));
277}
278
279void bapp_remote_post_event(uint32_t code,uint8_t modifier)
280{
281        if (s_p_remote && s_p_remote->queue)
282        {
283                if (modifier == 0x01)
284                        bos_post_event(s_p_remote->queue,(b_event_t*)(eKEY_DOWN | code));
285                else
286                        bos_post_event(s_p_remote->queue,(b_event_t*)(eKEY_UP | code));
287        }
288}
289
Note: See TracBrowser for help on using the repository browser.