| 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 1998-2000 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** File: pc_fstore.c |
|---|
| 12 | ** Description: Flash storage manager |
|---|
| 13 | ** |
|---|
| 14 | ****************************************************************/ |
|---|
| 15 | /* include files */ |
|---|
| 16 | |
|---|
| 17 | #include "bsettop_user_io.h" |
|---|
| 18 | |
|---|
| 19 | #define BUSER_IO_NUM_EVENTS 4 |
|---|
| 20 | |
|---|
| 21 | #define BUSER_IO_MSG(x) ((void)0) |
|---|
| 22 | //#define BUSER_IO_MSG(x) printf x |
|---|
| 23 | |
|---|
| 24 | #define MAX_TIMEOUT ((200 * g_ticks_per_second)/ 1000) |
|---|
| 25 | #define DEFAULT_PEND_TIMEOUT 10 /* in milliseconds */ |
|---|
| 26 | |
|---|
| 27 | /* See IR State transition diagram in design document */ |
|---|
| 28 | |
|---|
| 29 | typedef enum ir_state_t |
|---|
| 30 | { |
|---|
| 31 | eSTATE_IDLE, |
|---|
| 32 | eSTATE_WAIT_NEXT |
|---|
| 33 | }ir_state_t; |
|---|
| 34 | |
|---|
| 35 | /* Key code modifier stored in msb of event but this might not work for all protocols */ |
|---|
| 36 | |
|---|
| 37 | typedef enum ir_key_type_t |
|---|
| 38 | { |
|---|
| 39 | eKEY_DOWN = 0x80000000, |
|---|
| 40 | eKEY_UP = 0x40000000, |
|---|
| 41 | eKEY_CMD = 0x20000000, |
|---|
| 42 | }ir_key_type_t; |
|---|
| 43 | struct buser_input |
|---|
| 44 | { |
|---|
| 45 | unsigned int input_device_type; |
|---|
| 46 | unsigned int timeout; |
|---|
| 47 | unsigned int pend_timeout; |
|---|
| 48 | unsigned int start_time; |
|---|
| 49 | ir_state_t state; |
|---|
| 50 | unsigned int cur_key; |
|---|
| 51 | unsigned int last_key; |
|---|
| 52 | int event_cnt; |
|---|
| 53 | b_queue_t queue; |
|---|
| 54 | b_event_t events[BUSER_IO_NUM_EVENTS]; |
|---|
| 55 | |
|---|
| 56 | /* for same kind of IR remote but generate diffrent key map, like Comcast ones */ |
|---|
| 57 | unsigned int input_device_subtype; /* build intelligent to diffrentiate them */ |
|---|
| 58 | |
|---|
| 59 | int repeat; /* repeat key */ |
|---|
| 60 | }buser_input; |
|---|
| 61 | |
|---|
| 62 | struct buser_input s_buser_input = { 0, 40,0,eSTATE_IDLE,0,0 }; |
|---|
| 63 | |
|---|
| 64 | /* |
|---|
| 65 | Summary: |
|---|
| 66 | Handle the input key state transitions for the IR remote |
|---|
| 67 | */ |
|---|
| 68 | static void pc_handle_ir_input( unsigned int input_key, int port) |
|---|
| 69 | { |
|---|
| 70 | |
|---|
| 71 | BUSER_IO_MSG(("%s state = %d, timeout = %d, start_time = %d, cur_time = %d, key = 0x%08x\n" |
|---|
| 72 | ,__FUNCTION__,s_buser_input.state,s_buser_input.timeout,s_buser_input.start_time,bos_getticks(),input_key)); |
|---|
| 73 | |
|---|
| 74 | input_key &= 0x00FFFFFF; |
|---|
| 75 | |
|---|
| 76 | s_buser_input.cur_key = input_key; |
|---|
| 77 | |
|---|
| 78 | switch(s_buser_input.state) |
|---|
| 79 | { |
|---|
| 80 | case eSTATE_IDLE: |
|---|
| 81 | |
|---|
| 82 | s_buser_input.start_time = bos_getticks(); |
|---|
| 83 | s_buser_input.last_key = input_key; |
|---|
| 84 | s_buser_input.state = eSTATE_WAIT_NEXT; |
|---|
| 85 | s_buser_input.timeout = (port + 1) * MAX_TIMEOUT; |
|---|
| 86 | |
|---|
| 87 | s_buser_input.event_cnt = 1; |
|---|
| 88 | bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key)); |
|---|
| 89 | break; |
|---|
| 90 | |
|---|
| 91 | case eSTATE_WAIT_NEXT: |
|---|
| 92 | |
|---|
| 93 | if ((s_buser_input.start_time + s_buser_input.timeout) >= bos_getticks()) |
|---|
| 94 | { |
|---|
| 95 | if (input_key == s_buser_input.last_key) |
|---|
| 96 | { |
|---|
| 97 | s_buser_input.start_time = bos_getticks(); |
|---|
| 98 | } |
|---|
| 99 | else if (s_buser_input.event_cnt < 2) |
|---|
| 100 | { |
|---|
| 101 | s_buser_input.event_cnt++; |
|---|
| 102 | bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_UP | s_buser_input.last_key)); |
|---|
| 103 | s_buser_input.last_key = input_key; |
|---|
| 104 | s_buser_input.start_time = bos_getticks(); |
|---|
| 105 | s_buser_input.event_cnt++; |
|---|
| 106 | bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key)); |
|---|
| 107 | s_buser_input.state = eSTATE_WAIT_NEXT; |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | else if (s_buser_input.event_cnt < 3) |
|---|
| 111 | { |
|---|
| 112 | s_buser_input.last_key = input_key; |
|---|
| 113 | s_buser_input.start_time = bos_getticks(); |
|---|
| 114 | s_buser_input.event_cnt++; |
|---|
| 115 | bos_post_event(s_buser_input.queue,(b_event_t*)(eKEY_DOWN | s_buser_input.last_key)); |
|---|
| 116 | s_buser_input.state = eSTATE_WAIT_NEXT; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | break; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | extern pc_post_user_io_event(char* name,unsigned int id) |
|---|
| 124 | { |
|---|
| 125 | pc_handle_ir_input(id,0); |
|---|
| 126 | } |
|---|
| 127 | buser_input_t buser_input_open( bobject_t user_input_id ) |
|---|
| 128 | { |
|---|
| 129 | static int s_init = 0; |
|---|
| 130 | if (!s_init) |
|---|
| 131 | { |
|---|
| 132 | s_init = 1; |
|---|
| 133 | s_buser_input.timeout = MAX_TIMEOUT; |
|---|
| 134 | s_buser_input.pend_timeout = DEFAULT_PEND_TIMEOUT; |
|---|
| 135 | bos_create_queue(&s_buser_input.queue,s_buser_input.events,BUSER_IO_NUM_EVENTS); |
|---|
| 136 | } |
|---|
| 137 | return (buser_input_t)&s_buser_input; |
|---|
| 138 | } |
|---|
| 139 | void buser_input_close( buser_input_t ui) |
|---|
| 140 | { |
|---|
| 141 | if (s_buser_input.queue) |
|---|
| 142 | { |
|---|
| 143 | bos_delete_queue(&s_buser_input.queue); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | bresult buser_input_get_event( buser_input_t ui, buser_input_event *event, unsigned nevents, unsigned *result_nevents) |
|---|
| 147 | { |
|---|
| 148 | uint32_t pend_event; |
|---|
| 149 | bresult result = berr_not_available; |
|---|
| 150 | *result_nevents = 0; |
|---|
| 151 | |
|---|
| 152 | pend_event = (unsigned int)bos_pend_event(s_buser_input.queue,s_buser_input.pend_timeout); |
|---|
| 153 | |
|---|
| 154 | if (pend_event) |
|---|
| 155 | { |
|---|
| 156 | /* To match settop api behavior only return key down events and |
|---|
| 157 | throw away key up events */ |
|---|
| 158 | *result_nevents = 1; |
|---|
| 159 | event[0].code = pend_event & 0xFF;/* To provide same key code as settop api */ |
|---|
| 160 | if (!(pend_event & eKEY_CMD)) |
|---|
| 161 | { |
|---|
| 162 | event[0].code = buser_input_map_code(event[0].code); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | if (event[0].code == 0xFF) |
|---|
| 166 | *result_nevents = 0; |
|---|
| 167 | |
|---|
| 168 | if (pend_event & eKEY_UP) |
|---|
| 169 | event[0].code |= eKEY_UP; |
|---|
| 170 | result = b_ok; |
|---|
| 171 | BUSER_IO_MSG(("%s, event = 0x%08x\n",__FUNCTION__,event[0].code)); |
|---|
| 172 | } |
|---|
| 173 | else if (s_buser_input.state == eSTATE_WAIT_NEXT) |
|---|
| 174 | { |
|---|
| 175 | if (s_buser_input.start_time + s_buser_input.timeout < bos_getticks() || s_buser_input.repeat) |
|---|
| 176 | { |
|---|
| 177 | s_buser_input.repeat = false; |
|---|
| 178 | s_buser_input.state = eSTATE_IDLE; |
|---|
| 179 | *result_nevents = 1; |
|---|
| 180 | event[0].code = s_buser_input.last_key & 0xFF;/* To provide same key code as settop api */ |
|---|
| 181 | event[0].code = buser_input_map_code(event[0].code); |
|---|
| 182 | |
|---|
| 183 | if (event[0].code == 0xFF) |
|---|
| 184 | *result_nevents = 0; |
|---|
| 185 | else |
|---|
| 186 | event[0].code |= eKEY_UP; /* add modifier flag to identify as key up */ |
|---|
| 187 | result = b_ok; |
|---|
| 188 | BUSER_IO_MSG(("%s, event = 0x%08x\n",__FUNCTION__,event[0].code)); |
|---|
| 189 | return result; |
|---|
| 190 | |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | return result; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | unsigned int buser_input_map_code( unsigned int code ) |
|---|
| 198 | { |
|---|
| 199 | return code; |
|---|
| 200 | } |
|---|
| 201 | void buser_input_sim_key(uint32_t code) |
|---|
| 202 | { |
|---|
| 203 | pc_post_user_io_event(NULL,code); |
|---|
| 204 | } |
|---|
| 205 | |
|---|