1 //<MStar Software> 2 //****************************************************************************** 3 // MStar Software 4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5 // All software, firmware and related documentation herein ("MStar Software") are 6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7 // law, including, but not limited to, copyright law and international treaties. 8 // Any use, modification, reproduction, retransmission, or republication of all 9 // or part of MStar Software is expressly prohibited, unless prior written 10 // permission has been granted by MStar. 11 // 12 // By accessing, browsing and/or using MStar Software, you acknowledge that you 13 // have read, understood, and agree, to be bound by below terms ("Terms") and to 14 // comply with all applicable laws and regulations: 15 // 16 // 1. MStar shall retain any and all right, ownership and interest to MStar 17 // Software and any modification/derivatives thereof. 18 // No right, ownership, or interest to MStar Software and any 19 // modification/derivatives thereof is transferred to you under Terms. 20 // 21 // 2. You understand that MStar Software might include, incorporate or be 22 // supplied together with third party`s software and the use of MStar 23 // Software may require additional licenses from third parties. 24 // Therefore, you hereby agree it is your sole responsibility to separately 25 // obtain any and all third party right and license necessary for your use of 26 // such third party`s software. 27 // 28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29 // MStar`s confidential information and you agree to keep MStar`s 30 // confidential information in strictest confidence and not disclose to any 31 // third party. 32 // 33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34 // kind. Any warranties are hereby expressly disclaimed by MStar, including 35 // without limitation, any warranties of merchantability, non-infringement of 36 // intellectual property rights, fitness for a particular purpose, error free 37 // and in conformity with any international standard. You agree to waive any 38 // claim against MStar for any loss, damage, cost or expense that you may 39 // incur related to your use of MStar Software. 40 // In no event shall MStar be liable for any direct, indirect, incidental or 41 // consequential damages, including without limitation, lost of profit or 42 // revenues, lost or damage of data, and unauthorized system use. 43 // You agree that this Section 4 shall still apply without being affected 44 // even if MStar Software has been modified by MStar in accordance with your 45 // request or instruction for your use, except otherwise agreed by both 46 // parties in writing. 47 // 48 // 5. If requested, MStar may from time to time provide technical supports or 49 // services in relation with MStar Software to you for your use of 50 // MStar Software in conjunction with your or your customer`s product 51 // ("Services"). 52 // You understand and agree that, except otherwise agreed by both parties in 53 // writing, Services are provided on an "AS IS" basis and the warranty 54 // disclaimer set forth in Section 4 above shall apply. 55 // 56 // 6. Nothing contained herein shall be construed as by implication, estoppels 57 // or otherwise: 58 // (a) conferring any license or right to use MStar name, trademark, service 59 // mark, symbol or any other identification; 60 // (b) obligating MStar or any of its affiliates to furnish any person, 61 // including without limitation, you and your customers, any assistance 62 // of any kind whatsoever, or any information; or 63 // (c) conferring any license or right under any intellectual property right. 64 // 65 // 7. These terms shall be governed by and construed in accordance with the laws 66 // of Taiwan, R.O.C., excluding its conflict of law rules. 67 // Any and all dispute arising out hereof or related hereto shall be finally 68 // settled by arbitration referred to the Chinese Arbitration Association, 69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70 // Rules of the Association by three (3) arbitrators appointed in accordance 71 // with the said Rules. 72 // The place of arbitration shall be in Taipei, Taiwan and the language shall 73 // be English. 74 // The arbitration award shall be final and binding to both parties. 75 // 76 //****************************************************************************** 77 //<MStar Software> 78 typedef U8 __u8; // 1 byte 79 typedef S8 __s8; // 1 byte 80 81 /// data type unsigned short, data length 2 byte 82 typedef U16 __u16; // 2 bytes 83 typedef S16 __s16; // 2 bytes 84 85 /// data type unsigned int, data length 4 byte 86 typedef U32 __u32; // 4 bytes 87 typedef S32 __s32; // 4 bytes 88 89 /// data type signed char, data length 1 byte 90 91 92 /* 93 * HID report item format 94 */ 95 96 #define HID_ITEM_FORMAT_SHORT 0 97 #define HID_ITEM_FORMAT_LONG 1 98 99 /* 100 * Special tag indicating long items 101 */ 102 103 #define HID_ITEM_TAG_LONG 15 104 105 /* 106 * HID report descriptor item type (prefix bit 2,3) 107 */ 108 109 #define HID_ITEM_TYPE_MAIN 0 110 #define HID_ITEM_TYPE_GLOBAL 1 111 #define HID_ITEM_TYPE_LOCAL 2 112 #define HID_ITEM_TYPE_RESERVED 3 113 114 /* 115 * HID report descriptor main item tags 116 */ 117 118 #define HID_MAIN_ITEM_TAG_INPUT 8 119 #define HID_MAIN_ITEM_TAG_OUTPUT 9 120 #define HID_MAIN_ITEM_TAG_FEATURE 11 121 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10 122 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12 123 124 /* 125 * HID report descriptor main item contents 126 */ 127 128 #define HID_MAIN_ITEM_CONSTANT 0x001 129 #define HID_MAIN_ITEM_VARIABLE 0x002 130 #define HID_MAIN_ITEM_RELATIVE 0x004 131 #define HID_MAIN_ITEM_WRAP 0x008 132 #define HID_MAIN_ITEM_NONLINEAR 0x010 133 #define HID_MAIN_ITEM_NO_PREFERRED 0x020 134 #define HID_MAIN_ITEM_NULL_STATE 0x040 135 #define HID_MAIN_ITEM_VOLATILE 0x080 136 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100 137 138 /* 139 * HID report descriptor collection item types 140 */ 141 142 #define HID_COLLECTION_PHYSICAL 0 143 #define HID_COLLECTION_APPLICATION 1 144 #define HID_COLLECTION_LOGICAL 2 145 146 /* 147 * HID report descriptor global item tags 148 */ 149 150 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0 151 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1 152 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2 153 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3 154 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4 155 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5 156 #define HID_GLOBAL_ITEM_TAG_UNIT 6 157 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7 158 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8 159 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9 160 #define HID_GLOBAL_ITEM_TAG_PUSH 10 161 #define HID_GLOBAL_ITEM_TAG_POP 11 162 163 /* 164 * HID report descriptor local item tags 165 */ 166 167 #define HID_LOCAL_ITEM_TAG_USAGE 0 168 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1 169 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2 170 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3 171 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4 172 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5 173 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7 174 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8 175 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9 176 #define HID_LOCAL_ITEM_TAG_DELIMITER 10 177 178 /* 179 * HID usage tables 180 */ 181 182 #define HID_USAGE_PAGE 0xffff0000 183 184 #define HID_UP_GENDESK 0x00010000 185 #define HID_UP_KEYBOARD 0x00070000 186 #define HID_UP_LED 0x00080000 187 #define HID_UP_BUTTON 0x00090000 188 #define HID_UP_CONSUMER 0x000c0000 189 #define HID_UP_DIGITIZER 0x000d0000 190 #define HID_UP_PID 0x000f0000 191 192 #define HID_USAGE 0x0000ffff 193 194 #define HID_GD_POINTER 0x00010001 195 #define HID_GD_MOUSE 0x00010002 196 #define HID_GD_JOYSTICK 0x00010004 197 #define HID_GD_GAMEPAD 0x00010005 198 #define HID_GD_HATSWITCH 0x00010039 199 200 /* 201 * HID report types --- Ouch! HID spec says 1 2 3! 202 */ 203 204 #define HID_INPUT_REPORT 0 205 #define HID_OUTPUT_REPORT 1 206 #define HID_FEATURE_REPORT 2 207 208 /* 209 * HID device quirks. 210 */ 211 212 #define HID_QUIRK_INVERT 0x01 213 #define HID_QUIRK_NOTOUCH 0x02 214 #define HID_QUIRK_IGNORE 0x04 215 #define HID_QUIRK_NOGET 0x08 216 217 #define USEAGE_X 0x30 218 #define USEAGE_Y 0x31 219 #define USEAGE_Z 0x32 220 #define USEAGE_UNDEFINED 0 221 #define MAX_AXIS_NUM 6 222 223 #define USEAGE_PAGE_BUTTON 9 224 /* 225 * We parse each description item into this structure. Short items data 226 * values are expanded to 32-bit signed int, long items contain a pointer 227 * into the data area. 228 */ 229 230 struct hid_item { 231 __u8 format; 232 __u8 size; 233 __u8 type; 234 __u8 tag; 235 union { 236 __u8 u8; 237 __s8 s8; 238 __u16 u16; 239 __s16 s16; 240 __u32 u32; 241 __s32 s32; 242 __u8 *longdata; 243 } zdata; 244 }; 245 struct hid_global { 246 __u32 usage_page; 247 __s32 logical_minimum; 248 __s32 logical_maximum; 249 __s32 physical_minimum; 250 __s32 physical_maximum; 251 __u8 unit_exponent; 252 __u8 unit; 253 __u8 report_id; 254 __u8 report_size; 255 __u8 report_count; 256 }; 257 /* 258 * This is the collection stack. We climb up the stack to determine 259 * application and function of each field. 260 */ 261 262 struct hid_collection { 263 __u8 type; 264 __u8 usage; 265 }; 266 267 268 /* 269 * This is the local enviroment. It is resistent up the next main-item. 270 */ 271 272 #define HID_MAX_DESCRIPTOR_SIZE 4096 273 #define HID_MAX_USAGES 16 274 #define HID_MAX_APPLICATIONS 16 275 276 struct hid_local { 277 __u8 usage[HID_MAX_USAGES]; /* usage array */ 278 __u8 usage_index; 279 __u8 usage_minimum; 280 __u8 delimiter_depth; 281 __u8 delimiter_branch; 282 }; 283 284 #define HID_GLOBAL_STACK_SIZE 4 285 #define HID_COLLECTION_STACK_SIZE 4 286 struct hid_parser { 287 struct hid_global global; 288 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; 289 unsigned global_stack_ptr; 290 struct hid_local local; 291 struct hid_collection collection_stack[HID_COLLECTION_STACK_SIZE]; 292 unsigned collection_stack_ptr; 293 //struct hid_device *device; 294 }; 295 #define TYPE_NOEVENT 0 296 #define TYPE_AXIS_X 1 297 #define TYPE_AXIS_Y 2 298 #define TYPE_BUTTON 3 299 300 struct axis_struct{ 301 __u8 size; 302 __u8 val; 303 __u16 startbit; 304 __u8 type; 305 }; 306 struct button_struct { //for all one bit button 307 __u8 count; 308 __u16 val; 309 __u16 startbit; 310 }; 311 312 __u32 GetValue(__u8 *buf, __u16 offset,__u8 size); 313 314