[bf2063e9] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[976f546] | 29 | /** @addtogroup libusb
|
---|
[bf2063e9] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[57d9c05e] | 33 | * HID report descriptor and report data parser implementation.
|
---|
[bf2063e9] | 34 | */
|
---|
| 35 | #include <usb/classes/hidparser.h>
|
---|
| 36 | #include <errno.h>
|
---|
[976f546] | 37 | #include <stdio.h>
|
---|
[e24e7b1] | 38 | #include <malloc.h>
|
---|
| 39 | #include <mem.h>
|
---|
[b7d9606] | 40 | #include <usb/debug.h>
|
---|
[681f24b3] | 41 | #include <assert.h>
|
---|
[976f546] | 42 |
|
---|
[a694a58] | 43 | /** The new report item flag. Used to determine when the item is completly
|
---|
| 44 | * configured and should be added to the report structure
|
---|
| 45 | */
|
---|
[b7d9606] | 46 | #define USB_HID_NEW_REPORT_ITEM 1
|
---|
[57d9c05e] | 47 |
|
---|
[a694a58] | 48 | /** No special action after the report descriptor tag is processed should be
|
---|
| 49 | * done
|
---|
| 50 | */
|
---|
| 51 | #define USB_HID_NO_ACTION 2
|
---|
[976f546] | 52 |
|
---|
[175ad13e] | 53 | #define USB_HID_RESET_OFFSET 3
|
---|
| 54 |
|
---|
[a694a58] | 55 | /** Unknown tag was founded in report descriptor data*/
|
---|
[57d9c05e] | 56 | #define USB_HID_UNKNOWN_TAG -99
|
---|
[976f546] | 57 |
|
---|
[57d9c05e] | 58 | /*
|
---|
| 59 | * Private descriptor parser functions
|
---|
| 60 | */
|
---|
[175ad13e] | 61 | int usb_hid_report_init(usb_hid_report_t *report);
|
---|
| 62 | int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item);
|
---|
| 63 | usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type);
|
---|
[b7d9606] | 64 | int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 65 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
|
---|
[c7a2e7e] | 66 | int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 67 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
|
---|
[c7a2e7e] | 68 | int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 69 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
|
---|
[c7a2e7e] | 70 | int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 71 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
|
---|
[976f546] | 72 |
|
---|
[175ad13e] | 73 | void usb_hid_print_usage_path(usb_hid_report_path_t *path);
|
---|
[e24e7b1] | 74 | void usb_hid_descriptor_print_list(link_t *head);
|
---|
[976f546] | 75 | int usb_hid_report_reset_local_items();
|
---|
[e24e7b1] | 76 | void usb_hid_free_report_list(link_t *head);
|
---|
[64dbc83] | 77 | usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
|
---|
[57d9c05e] | 78 | /*
|
---|
| 79 | * Data translation private functions
|
---|
| 80 | */
|
---|
[c7a2e7e] | 81 | int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size);
|
---|
[b7d9606] | 82 | inline size_t usb_hid_count_item_offset(usb_hid_report_item_t * report_item, size_t offset);
|
---|
[cfbbe1d3] | 83 | int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data);
|
---|
[175ad13e] | 84 | uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int32_t value);
|
---|
[fad14d7] | 85 | int usb_pow(int a, int b);
|
---|
| 86 |
|
---|
[57d9c05e] | 87 | // TODO: tohle ma bejt asi jinde
|
---|
[fad14d7] | 88 | int usb_pow(int a, int b)
|
---|
| 89 | {
|
---|
| 90 | switch(b) {
|
---|
| 91 | case 0:
|
---|
| 92 | return 1;
|
---|
| 93 | break;
|
---|
| 94 | case 1:
|
---|
| 95 | return a;
|
---|
| 96 | break;
|
---|
| 97 | default:
|
---|
| 98 | return a * usb_pow(a, b-1);
|
---|
| 99 | break;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[976f546] | 103 | /**
|
---|
[57d9c05e] | 104 | * Initialize the report descriptor parser structure
|
---|
[976f546] | 105 | *
|
---|
[57d9c05e] | 106 | * @param parser Report descriptor parser structure
|
---|
| 107 | * @return Error code
|
---|
[976f546] | 108 | */
|
---|
[175ad13e] | 109 | int usb_hid_report_init(usb_hid_report_t *report)
|
---|
[976f546] | 110 | {
|
---|
[175ad13e] | 111 | if(report == NULL) {
|
---|
[57d9c05e] | 112 | return EINVAL;
|
---|
| 113 | }
|
---|
[976f546] | 114 |
|
---|
[175ad13e] | 115 | memset(report, 0, sizeof(usb_hid_report_t));
|
---|
| 116 | list_initialize(&report->reports);
|
---|
| 117 | list_initialize(&report->collection_paths);
|
---|
[64dbc83] | 118 |
|
---|
[175ad13e] | 119 | report->use_report_ids = 0;
|
---|
[da3965e] | 120 | return EOK;
|
---|
[976f546] | 121 | }
|
---|
| 122 |
|
---|
[175ad13e] | 123 | int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
|
---|
| 124 | {
|
---|
| 125 | usb_hid_report_field_t *field;
|
---|
| 126 | int i;
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | /* find or append current collection path to the list */
|
---|
| 130 | link_t *path_it = report->collection_paths.next;
|
---|
| 131 | usb_hid_report_path_t *path = NULL;
|
---|
| 132 | while(path_it != &report->collection_paths) {
|
---|
| 133 | path = list_get_instance(path_it, usb_hid_report_path_t, link);
|
---|
| 134 |
|
---|
| 135 | if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
|
---|
| 136 | break;
|
---|
| 137 | }
|
---|
| 138 | path_it = path_it->next;
|
---|
| 139 | }
|
---|
| 140 | if(path_it == &report->collection_paths) {
|
---|
| 141 | path = usb_hid_report_path_clone(report_item->usage_path);
|
---|
[681f24b3] | 142 | list_append(&path->link, &report->collection_paths);
|
---|
[175ad13e] | 143 | report->collection_paths_count++;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | for(i=0; i<report_item->count; i++){
|
---|
| 148 |
|
---|
| 149 | field = malloc(sizeof(usb_hid_report_field_t));
|
---|
| 150 | memset(field, 0, sizeof(usb_hid_report_field_t));
|
---|
| 151 | list_initialize(&field->link);
|
---|
| 152 |
|
---|
[cfbbe1d3] | 153 | /* fill the attributes */
|
---|
[175ad13e] | 154 | field->collection_path = path;
|
---|
| 155 | field->logical_minimum = report_item->logical_minimum;
|
---|
| 156 | field->logical_maximum = report_item->logical_maximum;
|
---|
| 157 | field->physical_minimum = report_item->physical_minimum;
|
---|
| 158 | field->physical_maximum = report_item->physical_maximum;
|
---|
[cfbbe1d3] | 159 |
|
---|
[175ad13e] | 160 | field->usage_minimum = report_item->usage_minimum;
|
---|
| 161 | field->usage_maximum = report_item->usage_maximum;
|
---|
| 162 | if(report_item->extended_usage_page != 0){
|
---|
| 163 | field->usage_page = report_item->extended_usage_page;
|
---|
| 164 | }
|
---|
| 165 | else {
|
---|
| 166 | field->usage_page = report_item->usage_page;
|
---|
| 167 | }
|
---|
[cfbbe1d3] | 168 |
|
---|
| 169 | if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
|
---|
[175ad13e] | 170 | if(i < report_item->usages_count){
|
---|
[cfbbe1d3] | 171 | if((report_item->usages[i] & 0xFF00) != 0){
|
---|
[175ad13e] | 172 | field->usage_page = (report_item->usages[i] >> 16);
|
---|
| 173 | field->usage = (report_item->usages[i] & 0xFF);
|
---|
| 174 | }
|
---|
| 175 | else {
|
---|
| 176 | field->usage = report_item->usages[i];
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | else {
|
---|
| 180 | field->usage = report_item->usages[report_item->usages_count - 1];
|
---|
| 181 | }
|
---|
[cfbbe1d3] | 182 | }
|
---|
| 183 |
|
---|
| 184 | if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
|
---|
| 185 | if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
|
---|
| 186 | field->usage = report_item->usage_maximum - i;
|
---|
| 187 | }
|
---|
| 188 | else {
|
---|
| 189 | field->usage = report_item->usage_minimum + i;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | }
|
---|
[175ad13e] | 193 |
|
---|
| 194 | field->size = report_item->size;
|
---|
| 195 | field->offset = report_item->offset + (i * report_item->size);
|
---|
| 196 | if(report_item->id != 0) {
|
---|
| 197 | field->offset += 8;
|
---|
| 198 | report->use_report_ids = 1;
|
---|
| 199 | }
|
---|
| 200 | field->item_flags = report_item->item_flags;
|
---|
| 201 |
|
---|
| 202 | /* find the right report list*/
|
---|
| 203 | usb_hid_report_description_t *report_des;
|
---|
| 204 | report_des = usb_hid_report_find_description(report, report_item->id, report_item->type);
|
---|
| 205 | if(report_des == NULL){
|
---|
| 206 | report_des = malloc(sizeof(usb_hid_report_description_t));
|
---|
| 207 | memset(report_des, 0, sizeof(usb_hid_report_description_t));
|
---|
| 208 |
|
---|
| 209 | report_des->type = report_item->type;
|
---|
| 210 | report_des->report_id = report_item->id;
|
---|
| 211 | list_initialize (&report_des->link);
|
---|
| 212 | list_initialize (&report_des->report_items);
|
---|
| 213 |
|
---|
| 214 | list_append(&report_des->link, &report->reports);
|
---|
| 215 | report->report_count++;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | /* append this field to the end of founded report list */
|
---|
| 219 | list_append (&field->link, &report_des->report_items);
|
---|
| 220 |
|
---|
| 221 | /* update the sizes */
|
---|
| 222 | report_des->bit_length += field->size;
|
---|
| 223 | report_des->item_length++;
|
---|
| 224 |
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | return EOK;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | usb_hid_report_description_t * usb_hid_report_find_description(const usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
|
---|
| 232 | {
|
---|
| 233 | link_t *report_it = report->reports.next;
|
---|
| 234 | usb_hid_report_description_t *report_des = NULL;
|
---|
| 235 |
|
---|
| 236 | while(report_it != &report->reports) {
|
---|
| 237 | report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
|
---|
[dc9f122] | 238 |
|
---|
[175ad13e] | 239 | if((report_des->report_id == report_id) && (report_des->type == type)){
|
---|
[dc9f122] | 240 | return report_des;
|
---|
[175ad13e] | 241 | }
|
---|
[dc9f122] | 242 |
|
---|
[175ad13e] | 243 | report_it = report_it->next;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[dc9f122] | 246 | return NULL;
|
---|
[175ad13e] | 247 | }
|
---|
[bf2063e9] | 248 |
|
---|
| 249 | /** Parse HID report descriptor.
|
---|
| 250 | *
|
---|
| 251 | * @param parser Opaque HID report parser structure.
|
---|
| 252 | * @param data Data describing the report.
|
---|
| 253 | * @return Error code.
|
---|
| 254 | */
|
---|
[175ad13e] | 255 | int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
|
---|
[b7d9606] | 256 | const uint8_t *data, size_t size)
|
---|
[bf2063e9] | 257 | {
|
---|
[976f546] | 258 | size_t i=0;
|
---|
| 259 | uint8_t tag=0;
|
---|
| 260 | uint8_t item_size=0;
|
---|
| 261 | int class=0;
|
---|
| 262 | int ret;
|
---|
| 263 | usb_hid_report_item_t *report_item=0;
|
---|
[b53d3b7] | 264 | usb_hid_report_item_t *new_report_item;
|
---|
| 265 | usb_hid_report_path_t *usage_path;
|
---|
[c7a2e7e] | 266 |
|
---|
[60a228f] | 267 | size_t offset_input=0;
|
---|
| 268 | size_t offset_output=0;
|
---|
| 269 | size_t offset_feature=0;
|
---|
[175ad13e] | 270 |
|
---|
| 271 | link_t stack;
|
---|
| 272 | list_initialize(&stack);
|
---|
[55e388a1] | 273 |
|
---|
[b53d3b7] | 274 | /* parser structure initialization*/
|
---|
[175ad13e] | 275 | if(usb_hid_report_init(report) != EOK) {
|
---|
[55e388a1] | 276 | return EINVAL;
|
---|
| 277 | }
|
---|
[976f546] | 278 |
|
---|
[b53d3b7] | 279 | /*report item initialization*/
|
---|
[976f546] | 280 | if(!(report_item=malloc(sizeof(usb_hid_report_item_t)))){
|
---|
| 281 | return ENOMEM;
|
---|
| 282 | }
|
---|
[60a228f] | 283 | memset(report_item, 0, sizeof(usb_hid_report_item_t));
|
---|
[b53d3b7] | 284 | list_initialize(&(report_item->link));
|
---|
[8bec4d1] | 285 |
|
---|
[b53d3b7] | 286 | /* usage path context initialization */
|
---|
| 287 | if(!(usage_path=usb_hid_report_path())){
|
---|
| 288 | return ENOMEM;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[b7d9606] | 291 | while(i<size){
|
---|
[976f546] | 292 | if(!USB_HID_ITEM_IS_LONG(data[i])){
|
---|
[b7d9606] | 293 |
|
---|
[8bec4d1] | 294 | if((i+USB_HID_ITEM_SIZE(data[i]))>= size){
|
---|
[175ad13e] | 295 | return EINVAL;
|
---|
[b7d9606] | 296 | }
|
---|
| 297 |
|
---|
[976f546] | 298 | tag = USB_HID_ITEM_TAG(data[i]);
|
---|
| 299 | item_size = USB_HID_ITEM_SIZE(data[i]);
|
---|
| 300 | class = USB_HID_ITEM_TAG_CLASS(data[i]);
|
---|
[b7d9606] | 301 |
|
---|
| 302 | ret = usb_hid_report_parse_tag(tag,class,data+i+1,
|
---|
[b53d3b7] | 303 | item_size,report_item, usage_path);
|
---|
[976f546] | 304 | switch(ret){
|
---|
| 305 | case USB_HID_NEW_REPORT_ITEM:
|
---|
| 306 | // store report item to report and create the new one
|
---|
[175ad13e] | 307 | // store current collection path
|
---|
[b53d3b7] | 308 | report_item->usage_path = usage_path;
|
---|
| 309 |
|
---|
[bda06a3] | 310 | usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);
|
---|
| 311 | if(report_item->id != 0){
|
---|
[175ad13e] | 312 | report->use_report_ids = 1;
|
---|
[bda06a3] | 313 | }
|
---|
[fad14d7] | 314 |
|
---|
[976f546] | 315 | switch(tag) {
|
---|
| 316 | case USB_HID_REPORT_TAG_INPUT:
|
---|
[175ad13e] | 317 | report_item->type = USB_HID_REPORT_TYPE_INPUT;
|
---|
[60a228f] | 318 | report_item->offset = offset_input;
|
---|
| 319 | offset_input += report_item->count * report_item->size;
|
---|
[976f546] | 320 | break;
|
---|
| 321 | case USB_HID_REPORT_TAG_OUTPUT:
|
---|
[175ad13e] | 322 | report_item->type = USB_HID_REPORT_TYPE_OUTPUT;
|
---|
[60a228f] | 323 | report_item->offset = offset_output;
|
---|
| 324 | offset_output += report_item->count * report_item->size;
|
---|
[976f546] | 325 |
|
---|
| 326 | break;
|
---|
| 327 | case USB_HID_REPORT_TAG_FEATURE:
|
---|
[175ad13e] | 328 | report_item->type = USB_HID_REPORT_TYPE_FEATURE;
|
---|
[60a228f] | 329 | report_item->offset = offset_feature;
|
---|
| 330 | offset_feature += report_item->count * report_item->size;
|
---|
[976f546] | 331 | break;
|
---|
| 332 | default:
|
---|
[b7d9606] | 333 | usb_log_debug("\tjump over - tag %X\n", tag);
|
---|
[976f546] | 334 | break;
|
---|
| 335 | }
|
---|
[a9974ef] | 336 |
|
---|
[175ad13e] | 337 | /*
|
---|
| 338 | * append new fields to the report
|
---|
| 339 | * structure
|
---|
| 340 | */
|
---|
| 341 | usb_hid_report_append_fields(report, report_item);
|
---|
| 342 |
|
---|
[c32688d] | 343 | /* reset local items */
|
---|
[175ad13e] | 344 | while(report_item->usages_count > 0){
|
---|
| 345 | report_item->usages[--(report_item->usages_count)] = 0;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | report_item->extended_usage_page = 0;
|
---|
| 349 | report_item->usage_minimum = 0;
|
---|
| 350 | report_item->usage_maximum = 0;
|
---|
| 351 | report_item->designator_index = 0;
|
---|
| 352 | report_item->designator_minimum = 0;
|
---|
| 353 | report_item->designator_maximum = 0;
|
---|
| 354 | report_item->string_index = 0;
|
---|
| 355 | report_item->string_minimum = 0;
|
---|
| 356 | report_item->string_maximum = 0;
|
---|
| 357 |
|
---|
[976f546] | 358 | break;
|
---|
[175ad13e] | 359 |
|
---|
| 360 | case USB_HID_RESET_OFFSET:
|
---|
| 361 | offset_input = 0;
|
---|
| 362 | offset_output = 0;
|
---|
| 363 | offset_feature = 0;
|
---|
[c7c0984a] | 364 | usb_hid_report_path_set_report_id (usage_path, report_item->id);
|
---|
[175ad13e] | 365 | break;
|
---|
| 366 |
|
---|
[976f546] | 367 | case USB_HID_REPORT_TAG_PUSH:
|
---|
| 368 | // push current state to stack
|
---|
[64dbc83] | 369 | new_report_item = usb_hid_report_item_clone(report_item);
|
---|
[c156c2d] | 370 | usb_hid_report_path_t *tmp_path = usb_hid_report_path_clone(usage_path);
|
---|
| 371 | new_report_item->usage_path = tmp_path;
|
---|
| 372 |
|
---|
[175ad13e] | 373 | list_prepend (&new_report_item->link, &stack);
|
---|
[976f546] | 374 | break;
|
---|
| 375 | case USB_HID_REPORT_TAG_POP:
|
---|
| 376 | // restore current state from stack
|
---|
[175ad13e] | 377 | if(list_empty (&stack)) {
|
---|
[64dbc83] | 378 | return EINVAL;
|
---|
| 379 | }
|
---|
[c156c2d] | 380 | free(report_item);
|
---|
| 381 |
|
---|
[175ad13e] | 382 | report_item = list_get_instance(stack.next, usb_hid_report_item_t, link);
|
---|
[64dbc83] | 383 |
|
---|
[c156c2d] | 384 | usb_hid_report_usage_path_t *tmp_usage_path;
|
---|
| 385 | tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
|
---|
| 386 |
|
---|
| 387 | usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
|
---|
| 388 |
|
---|
| 389 | usb_hid_report_path_free(report_item->usage_path);
|
---|
| 390 | list_initialize(&report_item->usage_path->link);
|
---|
[175ad13e] | 391 | list_remove (stack.next);
|
---|
[64dbc83] | 392 |
|
---|
[976f546] | 393 | break;
|
---|
| 394 |
|
---|
| 395 | default:
|
---|
[b7d9606] | 396 | // nothing special to do
|
---|
[976f546] | 397 | break;
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | /* jump over the processed block */
|
---|
| 401 | i += 1 + USB_HID_ITEM_SIZE(data[i]);
|
---|
| 402 | }
|
---|
| 403 | else{
|
---|
| 404 | // TBD
|
---|
| 405 | i += 3 + USB_HID_ITEM_SIZE(data[i+1]);
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 |
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | return EOK;
|
---|
[bf2063e9] | 412 | }
|
---|
| 413 |
|
---|
[2f60e57d] | 414 |
|
---|
[976f546] | 415 | /**
|
---|
[57d9c05e] | 416 | * Parse one tag of the report descriptor
|
---|
[976f546] | 417 | *
|
---|
| 418 | * @param Tag to parse
|
---|
| 419 | * @param Report descriptor buffer
|
---|
| 420 | * @param Size of data belongs to this tag
|
---|
| 421 | * @param Current report item structe
|
---|
| 422 | * @return Code of action to be done next
|
---|
| 423 | */
|
---|
[b7d9606] | 424 | int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 425 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
|
---|
[976f546] | 426 | {
|
---|
[b7d9606] | 427 | int ret;
|
---|
| 428 |
|
---|
[976f546] | 429 | switch(class){
|
---|
| 430 | case USB_HID_TAG_CLASS_MAIN:
|
---|
| 431 |
|
---|
[b53d3b7] | 432 | if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) {
|
---|
[976f546] | 433 | return USB_HID_NEW_REPORT_ITEM;
|
---|
| 434 | }
|
---|
| 435 | else {
|
---|
| 436 | /*TODO process the error */
|
---|
[b7d9606] | 437 | return ret;
|
---|
[976f546] | 438 | }
|
---|
| 439 | break;
|
---|
| 440 |
|
---|
| 441 | case USB_HID_TAG_CLASS_GLOBAL:
|
---|
[b53d3b7] | 442 | return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path);
|
---|
[976f546] | 443 | break;
|
---|
| 444 |
|
---|
| 445 | case USB_HID_TAG_CLASS_LOCAL:
|
---|
[b53d3b7] | 446 | return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path);
|
---|
[976f546] | 447 | break;
|
---|
| 448 | default:
|
---|
[b7d9606] | 449 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 450 | }
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | /**
|
---|
| 454 | * Parse main tags of report descriptor
|
---|
| 455 | *
|
---|
| 456 | * @param Tag identifier
|
---|
| 457 | * @param Data buffer
|
---|
| 458 | * @param Length of data buffer
|
---|
| 459 | * @param Current state table
|
---|
| 460 | * @return Error code
|
---|
| 461 | */
|
---|
| 462 |
|
---|
[c7a2e7e] | 463 | int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 464 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
|
---|
| 465 | {
|
---|
[976f546] | 466 | switch(tag)
|
---|
| 467 | {
|
---|
| 468 | case USB_HID_REPORT_TAG_INPUT:
|
---|
| 469 | case USB_HID_REPORT_TAG_OUTPUT:
|
---|
| 470 | case USB_HID_REPORT_TAG_FEATURE:
|
---|
[b7d9606] | 471 | report_item->item_flags = *data;
|
---|
| 472 | return EOK;
|
---|
[976f546] | 473 | break;
|
---|
| 474 |
|
---|
| 475 | case USB_HID_REPORT_TAG_COLLECTION:
|
---|
[175ad13e] | 476 | // TODO usage_path->flags = *data;
|
---|
| 477 | usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
|
---|
[8bec4d1] | 478 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 479 | break;
|
---|
| 480 |
|
---|
| 481 | case USB_HID_REPORT_TAG_END_COLLECTION:
|
---|
[b53d3b7] | 482 | usb_hid_report_remove_last_item(usage_path);
|
---|
[8bec4d1] | 483 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 484 | break;
|
---|
| 485 | default:
|
---|
[b7d9606] | 486 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 487 | }
|
---|
| 488 |
|
---|
[8bec4d1] | 489 | return EOK;
|
---|
[976f546] | 490 | }
|
---|
| 491 |
|
---|
| 492 | /**
|
---|
| 493 | * Parse global tags of report descriptor
|
---|
| 494 | *
|
---|
| 495 | * @param Tag identifier
|
---|
| 496 | * @param Data buffer
|
---|
| 497 | * @param Length of data buffer
|
---|
| 498 | * @param Current state table
|
---|
| 499 | * @return Error code
|
---|
| 500 | */
|
---|
[c7a2e7e] | 501 | int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 502 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
|
---|
[976f546] | 503 | {
|
---|
| 504 | // TODO take care about the bit length of data
|
---|
| 505 | switch(tag)
|
---|
| 506 | {
|
---|
| 507 | case USB_HID_REPORT_TAG_USAGE_PAGE:
|
---|
[175ad13e] | 508 | report_item->usage_page = usb_hid_report_tag_data_int32(data, item_size);
|
---|
[976f546] | 509 | break;
|
---|
| 510 | case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
|
---|
| 511 | report_item->logical_minimum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 512 | break;
|
---|
| 513 | case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
|
---|
| 514 | report_item->logical_maximum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 515 | break;
|
---|
| 516 | case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
|
---|
| 517 | report_item->physical_minimum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 518 | break;
|
---|
| 519 | case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
|
---|
| 520 | report_item->physical_maximum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 521 | break;
|
---|
| 522 | case USB_HID_REPORT_TAG_UNIT_EXPONENT:
|
---|
| 523 | report_item->unit_exponent = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 524 | break;
|
---|
| 525 | case USB_HID_REPORT_TAG_UNIT:
|
---|
| 526 | report_item->unit = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 527 | break;
|
---|
| 528 | case USB_HID_REPORT_TAG_REPORT_SIZE:
|
---|
| 529 | report_item->size = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 530 | break;
|
---|
| 531 | case USB_HID_REPORT_TAG_REPORT_COUNT:
|
---|
| 532 | report_item->count = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 533 | break;
|
---|
| 534 | case USB_HID_REPORT_TAG_REPORT_ID:
|
---|
| 535 | report_item->id = usb_hid_report_tag_data_int32(data,item_size);
|
---|
[175ad13e] | 536 | return USB_HID_RESET_OFFSET;
|
---|
[976f546] | 537 | break;
|
---|
| 538 | case USB_HID_REPORT_TAG_PUSH:
|
---|
| 539 | case USB_HID_REPORT_TAG_POP:
|
---|
[175ad13e] | 540 | /*
|
---|
| 541 | * stack operations are done in top level parsing
|
---|
| 542 | * function
|
---|
| 543 | */
|
---|
[976f546] | 544 | return tag;
|
---|
| 545 | break;
|
---|
| 546 |
|
---|
| 547 | default:
|
---|
[b7d9606] | 548 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 549 | }
|
---|
[da3965e] | 550 |
|
---|
| 551 | return EOK;
|
---|
[976f546] | 552 | }
|
---|
| 553 |
|
---|
| 554 | /**
|
---|
| 555 | * Parse local tags of report descriptor
|
---|
| 556 | *
|
---|
| 557 | * @param Tag identifier
|
---|
| 558 | * @param Data buffer
|
---|
| 559 | * @param Length of data buffer
|
---|
| 560 | * @param Current state table
|
---|
| 561 | * @return Error code
|
---|
| 562 | */
|
---|
[c7a2e7e] | 563 | int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
|
---|
[b53d3b7] | 564 | usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
|
---|
[976f546] | 565 | {
|
---|
| 566 | switch(tag)
|
---|
| 567 | {
|
---|
| 568 | case USB_HID_REPORT_TAG_USAGE:
|
---|
[175ad13e] | 569 | report_item->usages[report_item->usages_count++] = usb_hid_report_tag_data_int32(data,item_size);
|
---|
[976f546] | 570 | break;
|
---|
| 571 | case USB_HID_REPORT_TAG_USAGE_MINIMUM:
|
---|
[175ad13e] | 572 | if (item_size == 3) {
|
---|
| 573 | // usage extended usages
|
---|
| 574 | report_item->extended_usage_page = (usb_hid_report_tag_data_int32(data,item_size) & 0xFF00) >> 16;
|
---|
| 575 | report_item->usage_minimum = usb_hid_report_tag_data_int32(data,item_size) & 0xFF;
|
---|
| 576 | }
|
---|
| 577 | else {
|
---|
| 578 | report_item->usage_minimum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 579 | }
|
---|
[976f546] | 580 | break;
|
---|
| 581 | case USB_HID_REPORT_TAG_USAGE_MAXIMUM:
|
---|
[175ad13e] | 582 | if (item_size == 3) {
|
---|
| 583 | // usage extended usages
|
---|
| 584 | report_item->extended_usage_page = (usb_hid_report_tag_data_int32(data,item_size) & 0xFF00) >> 16;
|
---|
| 585 | report_item->usage_maximum = usb_hid_report_tag_data_int32(data,item_size) & 0xFF;
|
---|
| 586 | }
|
---|
| 587 | else {
|
---|
| 588 | report_item->usage_maximum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 589 | }
|
---|
[976f546] | 590 | break;
|
---|
| 591 | case USB_HID_REPORT_TAG_DESIGNATOR_INDEX:
|
---|
| 592 | report_item->designator_index = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 593 | break;
|
---|
| 594 | case USB_HID_REPORT_TAG_DESIGNATOR_MINIMUM:
|
---|
| 595 | report_item->designator_minimum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 596 | break;
|
---|
| 597 | case USB_HID_REPORT_TAG_DESIGNATOR_MAXIMUM:
|
---|
| 598 | report_item->designator_maximum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 599 | break;
|
---|
| 600 | case USB_HID_REPORT_TAG_STRING_INDEX:
|
---|
| 601 | report_item->string_index = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 602 | break;
|
---|
| 603 | case USB_HID_REPORT_TAG_STRING_MINIMUM:
|
---|
| 604 | report_item->string_minimum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 605 | break;
|
---|
| 606 | case USB_HID_REPORT_TAG_STRING_MAXIMUM:
|
---|
| 607 | report_item->string_maximum = usb_hid_report_tag_data_int32(data,item_size);
|
---|
[3de529c] | 608 | break;
|
---|
[976f546] | 609 | case USB_HID_REPORT_TAG_DELIMITER:
|
---|
[175ad13e] | 610 | //report_item->delimiter = usb_hid_report_tag_data_int32(data,item_size);
|
---|
| 611 | //TODO:
|
---|
| 612 | // DELIMITER STUFF
|
---|
[976f546] | 613 | break;
|
---|
[3de529c] | 614 |
|
---|
[976f546] | 615 | default:
|
---|
[b7d9606] | 616 | return USB_HID_NO_ACTION;
|
---|
[976f546] | 617 | }
|
---|
[da3965e] | 618 |
|
---|
| 619 | return EOK;
|
---|
[976f546] | 620 | }
|
---|
| 621 |
|
---|
| 622 | /**
|
---|
| 623 | * Converts raw data to int32 (thats the maximum length of short item data)
|
---|
| 624 | *
|
---|
| 625 | * @param Data buffer
|
---|
| 626 | * @param Size of buffer
|
---|
| 627 | * @return Converted int32 number
|
---|
| 628 | */
|
---|
[c7a2e7e] | 629 | int32_t usb_hid_report_tag_data_int32(const uint8_t *data, size_t size)
|
---|
[976f546] | 630 | {
|
---|
[da3965e] | 631 | unsigned int i;
|
---|
[976f546] | 632 | int32_t result;
|
---|
| 633 |
|
---|
| 634 | result = 0;
|
---|
| 635 | for(i=0; i<size; i++) {
|
---|
| 636 | result = (result | (data[i]) << (i*8));
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | return result;
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 |
|
---|
| 643 |
|
---|
| 644 | /**
|
---|
| 645 | * Prints content of given list of report items.
|
---|
| 646 | *
|
---|
[57d9c05e] | 647 | * @param List of report items (usb_hid_report_item_t)
|
---|
[976f546] | 648 | * @return void
|
---|
| 649 | */
|
---|
| 650 | void usb_hid_descriptor_print_list(link_t *head)
|
---|
| 651 | {
|
---|
[175ad13e] | 652 | usb_hid_report_field_t *report_item;
|
---|
[976f546] | 653 | link_t *item;
|
---|
[175ad13e] | 654 |
|
---|
| 655 |
|
---|
[976f546] | 656 | if(head == NULL || list_empty(head)) {
|
---|
[60a228f] | 657 | usb_log_debug("\tempty\n");
|
---|
[976f546] | 658 | return;
|
---|
| 659 | }
|
---|
[b7d9606] | 660 |
|
---|
[976f546] | 661 | for(item = head->next; item != head; item = item->next) {
|
---|
| 662 |
|
---|
[175ad13e] | 663 | report_item = list_get_instance(item, usb_hid_report_field_t, link);
|
---|
| 664 |
|
---|
| 665 | usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
|
---|
| 666 | usb_log_debug("\t\tSIZE: %X\n", report_item->size);
|
---|
| 667 | usb_log_debug("\t\tLOGMIN: %X\n", report_item->logical_minimum);
|
---|
| 668 | usb_log_debug("\t\tLOGMAX: %X\n", report_item->logical_maximum);
|
---|
| 669 | usb_log_debug("\t\tPHYMIN: %X\n", report_item->physical_minimum);
|
---|
| 670 | usb_log_debug("\t\tPHYMAX: %X\n", report_item->physical_maximum);
|
---|
| 671 | usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
|
---|
| 672 | usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
|
---|
| 673 |
|
---|
[ef354b6] | 674 | usb_log_debug("\t\tVALUE: %X\n", report_item->value);
|
---|
[175ad13e] | 675 | usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
|
---|
| 676 | usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
|
---|
| 677 |
|
---|
[ef354b6] | 678 | // usb_log_debug("\n");
|
---|
[976f546] | 679 |
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 |
|
---|
| 683 | }
|
---|
| 684 | /**
|
---|
[57d9c05e] | 685 | * Prints content of given report descriptor in human readable format.
|
---|
[976f546] | 686 | *
|
---|
[57d9c05e] | 687 | * @param parser Parsed descriptor to print
|
---|
[976f546] | 688 | * @return void
|
---|
| 689 | */
|
---|
[175ad13e] | 690 | void usb_hid_descriptor_print(usb_hid_report_t *report)
|
---|
[976f546] | 691 | {
|
---|
[175ad13e] | 692 | if(report == NULL) {
|
---|
[55e388a1] | 693 | return;
|
---|
| 694 | }
|
---|
[976f546] | 695 |
|
---|
[175ad13e] | 696 | link_t *report_it = report->reports.next;
|
---|
| 697 | usb_hid_report_description_t *report_des;
|
---|
| 698 |
|
---|
| 699 | while(report_it != &report->reports) {
|
---|
| 700 | report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
|
---|
| 701 | usb_log_debug("Report ID: %d\n", report_des->report_id);
|
---|
| 702 | usb_log_debug("\tType: %d\n", report_des->type);
|
---|
| 703 | usb_log_debug("\tLength: %d\n", report_des->bit_length);
|
---|
| 704 | usb_log_debug("\tItems: %d\n", report_des->item_length);
|
---|
| 705 |
|
---|
| 706 | usb_hid_descriptor_print_list(&report_des->report_items);
|
---|
| 707 |
|
---|
| 708 |
|
---|
| 709 | link_t *path_it = report->collection_paths.next;
|
---|
| 710 | while(path_it != &report->collection_paths) {
|
---|
| 711 | usb_hid_print_usage_path (list_get_instance(path_it, usb_hid_report_path_t, link));
|
---|
| 712 | path_it = path_it->next;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | report_it = report_it->next;
|
---|
| 716 | }
|
---|
[976f546] | 717 | }
|
---|
| 718 |
|
---|
| 719 | /**
|
---|
| 720 | * Releases whole linked list of report items
|
---|
| 721 | *
|
---|
[57d9c05e] | 722 | * @param head Head of list of report descriptor items (usb_hid_report_item_t)
|
---|
| 723 | * @return void
|
---|
[976f546] | 724 | */
|
---|
[e24e7b1] | 725 | void usb_hid_free_report_list(link_t *head)
|
---|
[976f546] | 726 | {
|
---|
[e24e7b1] | 727 | return;
|
---|
[e259d95] | 728 |
|
---|
[976f546] | 729 | usb_hid_report_item_t *report_item;
|
---|
[e259d95] | 730 | link_t *next;
|
---|
[976f546] | 731 |
|
---|
| 732 | if(head == NULL || list_empty(head)) {
|
---|
[e24e7b1] | 733 | return;
|
---|
[976f546] | 734 | }
|
---|
[e259d95] | 735 |
|
---|
| 736 | next = head->next;
|
---|
| 737 | while(next != head) {
|
---|
| 738 |
|
---|
| 739 | report_item = list_get_instance(next, usb_hid_report_item_t, link);
|
---|
[b53d3b7] | 740 |
|
---|
| 741 | while(!list_empty(&report_item->usage_path->link)) {
|
---|
| 742 | usb_hid_report_remove_last_item(report_item->usage_path);
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 |
|
---|
[e259d95] | 746 | next = next->next;
|
---|
[976f546] | 747 |
|
---|
[e259d95] | 748 | free(report_item);
|
---|
[976f546] | 749 | }
|
---|
[e259d95] | 750 |
|
---|
[e24e7b1] | 751 | return;
|
---|
[e259d95] | 752 |
|
---|
[976f546] | 753 | }
|
---|
| 754 |
|
---|
[57d9c05e] | 755 | /** Frees the HID report descriptor parser structure
|
---|
[19a1800] | 756 | *
|
---|
| 757 | * @param parser Opaque HID report parser structure
|
---|
[57d9c05e] | 758 | * @return void
|
---|
[976f546] | 759 | */
|
---|
[175ad13e] | 760 | void usb_hid_free_report(usb_hid_report_t *report)
|
---|
[976f546] | 761 | {
|
---|
[175ad13e] | 762 | if(report == NULL){
|
---|
[976f546] | 763 | return;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
[175ad13e] | 766 | // free collection paths
|
---|
| 767 | usb_hid_report_path_t *path;
|
---|
| 768 | while(!list_empty(&report->collection_paths)) {
|
---|
| 769 | path = list_get_instance(report->collection_paths.next, usb_hid_report_path_t, link);
|
---|
| 770 | usb_hid_report_path_free(path);
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 | // free report items
|
---|
| 774 | usb_hid_report_description_t *report_des;
|
---|
| 775 | usb_hid_report_field_t *field;
|
---|
| 776 | while(!list_empty(&report->reports)) {
|
---|
| 777 | report_des = list_get_instance(report->reports.next, usb_hid_report_description_t, link);
|
---|
| 778 | list_remove(&report_des->link);
|
---|
| 779 |
|
---|
| 780 | while(!list_empty(&report_des->report_items)) {
|
---|
| 781 | field = list_get_instance(report_des->report_items.next, usb_hid_report_field_t, link);
|
---|
| 782 | list_remove(&field->link);
|
---|
[bda06a3] | 783 |
|
---|
[175ad13e] | 784 | free(field);
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | free(report_des);
|
---|
| 788 | }
|
---|
| 789 |
|
---|
[976f546] | 790 | return;
|
---|
| 791 | }
|
---|
[c7a2e7e] | 792 |
|
---|
[fad14d7] | 793 | /** Parse and act upon a HID report.
|
---|
| 794 | *
|
---|
| 795 | * @see usb_hid_parse_report_descriptor
|
---|
| 796 | *
|
---|
| 797 | * @param parser Opaque HID report parser structure.
|
---|
| 798 | * @param data Data for the report.
|
---|
| 799 | * @return Error code.
|
---|
| 800 | */
|
---|
[175ad13e] | 801 | int usb_hid_parse_report(const usb_hid_report_t *report,
|
---|
[cfbbe1d3] | 802 | const uint8_t *data, size_t size, uint8_t *report_id)
|
---|
[fad14d7] | 803 | {
|
---|
| 804 | link_t *list_item;
|
---|
[175ad13e] | 805 | usb_hid_report_field_t *item;
|
---|
| 806 |
|
---|
| 807 | usb_hid_report_description_t *report_des;
|
---|
| 808 | usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
|
---|
[fad14d7] | 809 |
|
---|
[175ad13e] | 810 | if(report == NULL) {
|
---|
[55e388a1] | 811 | return EINVAL;
|
---|
| 812 | }
|
---|
[c156c2d] | 813 |
|
---|
[175ad13e] | 814 | if(report->use_report_ids != 0) {
|
---|
[cfbbe1d3] | 815 | *report_id = data[0];
|
---|
| 816 | }
|
---|
| 817 | else {
|
---|
| 818 | *report_id = 0;
|
---|
[c156c2d] | 819 | }
|
---|
| 820 |
|
---|
[cfbbe1d3] | 821 |
|
---|
| 822 | report_des = usb_hid_report_find_description(report, *report_id, type);
|
---|
[c156c2d] | 823 |
|
---|
[175ad13e] | 824 | /* read data */
|
---|
| 825 | list_item = report_des->report_items.next;
|
---|
| 826 | while(list_item != &(report_des->report_items)) {
|
---|
[fad14d7] | 827 |
|
---|
[175ad13e] | 828 | item = list_get_instance(list_item, usb_hid_report_field_t, link);
|
---|
[fad14d7] | 829 |
|
---|
[cfbbe1d3] | 830 | if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
|
---|
[175ad13e] | 831 |
|
---|
[cfbbe1d3] | 832 | if(USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
|
---|
[175ad13e] | 833 |
|
---|
[cfbbe1d3] | 834 | // array
|
---|
| 835 | item->value = usb_hid_translate_data(item, data);
|
---|
| 836 | item->usage = (item->value - item->physical_minimum) + item->usage_minimum;
|
---|
[fad14d7] | 837 | }
|
---|
[175ad13e] | 838 | else {
|
---|
[cfbbe1d3] | 839 | // variable item
|
---|
| 840 | item->value = usb_hid_translate_data(item, data);
|
---|
| 841 | }
|
---|
[fad14d7] | 842 | }
|
---|
| 843 | list_item = list_item->next;
|
---|
| 844 | }
|
---|
| 845 |
|
---|
| 846 | return EOK;
|
---|
| 847 |
|
---|
| 848 | }
|
---|
| 849 |
|
---|
[57d9c05e] | 850 | /**
|
---|
[c156c2d] | 851 | * Translate data from the report as specified in report descriptor item
|
---|
[57d9c05e] | 852 | *
|
---|
| 853 | * @param item Report descriptor item with definition of translation
|
---|
| 854 | * @param data Data to translate
|
---|
| 855 | * @param j Index of processed field in report descriptor item
|
---|
| 856 | * @return Translated data
|
---|
| 857 | */
|
---|
[cfbbe1d3] | 858 | int usb_hid_translate_data(usb_hid_report_field_t *item, const uint8_t *data)
|
---|
[c7a2e7e] | 859 | {
|
---|
[fad14d7] | 860 | int resolution;
|
---|
| 861 | int offset;
|
---|
| 862 | int part_size;
|
---|
| 863 |
|
---|
[175ad13e] | 864 | int32_t value=0;
|
---|
[fad14d7] | 865 | int32_t mask;
|
---|
| 866 | const uint8_t *foo;
|
---|
[bda06a3] | 867 |
|
---|
[c156c2d] | 868 | // now only shot tags are allowed
|
---|
[fad14d7] | 869 | if(item->size > 32) {
|
---|
| 870 | return 0;
|
---|
| 871 | }
|
---|
| 872 |
|
---|
[cfbbe1d3] | 873 | if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
|
---|
[fad14d7] | 874 | item->physical_minimum = item->logical_minimum;
|
---|
[cfbbe1d3] | 875 | item->physical_maximum = item->logical_maximum;
|
---|
[fad14d7] | 876 | }
|
---|
[cfbbe1d3] | 877 |
|
---|
[fad14d7] | 878 |
|
---|
[60a228f] | 879 | if(item->physical_maximum == item->physical_minimum){
|
---|
| 880 | resolution = 1;
|
---|
| 881 | }
|
---|
| 882 | else {
|
---|
| 883 | resolution = (item->logical_maximum - item->logical_minimum) /
|
---|
| 884 | ((item->physical_maximum - item->physical_minimum) *
|
---|
| 885 | (usb_pow(10,(item->unit_exponent))));
|
---|
| 886 | }
|
---|
[bda06a3] | 887 |
|
---|
[cfbbe1d3] | 888 | offset = item->offset;
|
---|
[fad14d7] | 889 | // FIXME
|
---|
[175ad13e] | 890 | if((size_t)(offset/8) != (size_t)((offset+item->size-1)/8)) {
|
---|
[fad14d7] | 891 |
|
---|
| 892 | part_size = ((offset+item->size)%8);
|
---|
| 893 |
|
---|
[175ad13e] | 894 | size_t i=0;
|
---|
| 895 | for(i=(size_t)(offset/8); i<=(size_t)(offset+item->size-1)/8; i++){
|
---|
| 896 | if(i == (size_t)(offset/8)) {
|
---|
| 897 | // the higher one
|
---|
| 898 | foo = data + i;
|
---|
| 899 | mask = ((1 << (item->size-part_size))-1);
|
---|
| 900 | value = (*foo & mask) << part_size;
|
---|
| 901 | }
|
---|
| 902 | else if(i == ((offset+item->size-1)/8)){
|
---|
| 903 | // the lower one
|
---|
| 904 | foo = data + i;
|
---|
| 905 | mask = ((1 << part_size)-1) << (8-part_size);
|
---|
| 906 | value += ((*foo & mask) >> (8-part_size));
|
---|
| 907 | }
|
---|
| 908 | else {
|
---|
| 909 | value = value << 8;
|
---|
| 910 | value += *(data + 1);
|
---|
| 911 | }
|
---|
| 912 | }
|
---|
[fad14d7] | 913 | }
|
---|
| 914 | else {
|
---|
| 915 | foo = data+(offset/8);
|
---|
| 916 | mask = ((1 << item->size)-1) << (8-((offset%8)+item->size));
|
---|
| 917 | value = (*foo & mask) >> (8-((offset%8)+item->size));
|
---|
[175ad13e] | 918 | }
|
---|
[fad14d7] | 919 |
|
---|
[175ad13e] | 920 | if(!(item->logical_minimum >= 0 && item->logical_maximum >= 0)){
|
---|
| 921 | value = (int32_t)value;
|
---|
| 922 | }
|
---|
| 923 | else {
|
---|
| 924 | value = (uint32_t)value;
|
---|
[fad14d7] | 925 | }
|
---|
| 926 |
|
---|
[767da0a] | 927 | return (int)(((value - item->logical_minimum) / resolution) + item->physical_minimum);
|
---|
[fad14d7] | 928 |
|
---|
[c7a2e7e] | 929 | }
|
---|
[0bd4810c] | 930 |
|
---|
[57d9c05e] | 931 | /**
|
---|
[a694a58] | 932 | * Returns number of items in input report which are accessible by given usage path
|
---|
[57d9c05e] | 933 | *
|
---|
[a694a58] | 934 | * @param parser Opaque report descriptor structure
|
---|
| 935 | * @param path Usage path specification
|
---|
| 936 | * @param flags Usage path comparison flags
|
---|
| 937 | * @return Number of items in input report
|
---|
[57d9c05e] | 938 | */
|
---|
[175ad13e] | 939 | size_t usb_hid_report_input_length(const usb_hid_report_t *report,
|
---|
[b53d3b7] | 940 | usb_hid_report_path_t *path, int flags)
|
---|
[55e388a1] | 941 | {
|
---|
[175ad13e] | 942 |
|
---|
[57d9c05e] | 943 | size_t ret = 0;
|
---|
[0bd4810c] | 944 |
|
---|
[175ad13e] | 945 | if(report == NULL) {
|
---|
[57d9c05e] | 946 | return 0;
|
---|
[55e388a1] | 947 | }
|
---|
[0bd4810c] | 948 |
|
---|
[175ad13e] | 949 | usb_hid_report_description_t *report_des;
|
---|
| 950 | report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_INPUT);
|
---|
| 951 | if(report_des == NULL) {
|
---|
| 952 | return 0;
|
---|
| 953 | }
|
---|
| 954 |
|
---|
| 955 | link_t *field_it = report_des->report_items.next;
|
---|
| 956 | usb_hid_report_field_t *field;
|
---|
| 957 | while(field_it != &report_des->report_items) {
|
---|
| 958 |
|
---|
| 959 | field = list_get_instance(field_it, usb_hid_report_field_t, link);
|
---|
| 960 | if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
|
---|
[dc9f122] | 961 |
|
---|
| 962 | usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
|
---|
| 963 | if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
|
---|
[175ad13e] | 964 | ret++;
|
---|
| 965 | }
|
---|
[dc9f122] | 966 | usb_hid_report_remove_last_item (field->collection_path);
|
---|
[175ad13e] | 967 | }
|
---|
| 968 |
|
---|
| 969 | field_it = field_it->next;
|
---|
| 970 | }
|
---|
[0bd4810c] | 971 |
|
---|
| 972 | return ret;
|
---|
[175ad13e] | 973 | }
|
---|
[0bd4810c] | 974 |
|
---|
| 975 |
|
---|
[b53d3b7] | 976 | /**
|
---|
[a694a58] | 977 | * Appends one item (couple of usage_path and usage) into the usage path
|
---|
| 978 | * structure
|
---|
| 979 | *
|
---|
| 980 | * @param usage_path Usage path structure
|
---|
| 981 | * @param usage_page Usage page constant
|
---|
| 982 | * @param usage Usage constant
|
---|
| 983 | * @return Error code
|
---|
[b53d3b7] | 984 | */
|
---|
| 985 | int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
|
---|
| 986 | int32_t usage_page, int32_t usage)
|
---|
| 987 | {
|
---|
| 988 | usb_hid_report_usage_path_t *item;
|
---|
| 989 |
|
---|
| 990 | if(!(item=malloc(sizeof(usb_hid_report_usage_path_t)))) {
|
---|
| 991 | return ENOMEM;
|
---|
| 992 | }
|
---|
| 993 | list_initialize(&item->link);
|
---|
| 994 |
|
---|
| 995 | item->usage = usage;
|
---|
| 996 | item->usage_page = usage_page;
|
---|
[175ad13e] | 997 | item->flags = 0;
|
---|
[b53d3b7] | 998 |
|
---|
[dc9f122] | 999 | list_append (&item->link, &usage_path->head);
|
---|
[b53d3b7] | 1000 | usage_path->depth++;
|
---|
| 1001 | return EOK;
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
| 1004 | /**
|
---|
[a694a58] | 1005 | * Removes last item from the usage path structure
|
---|
| 1006 | * @param usage_path
|
---|
| 1007 | * @return void
|
---|
[b53d3b7] | 1008 | */
|
---|
| 1009 | void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
|
---|
| 1010 | {
|
---|
| 1011 | usb_hid_report_usage_path_t *item;
|
---|
| 1012 |
|
---|
[dc9f122] | 1013 | if(!list_empty(&usage_path->head)){
|
---|
| 1014 | item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
|
---|
| 1015 | list_remove(usage_path->head.prev);
|
---|
[b53d3b7] | 1016 | usage_path->depth--;
|
---|
| 1017 | free(item);
|
---|
| 1018 | }
|
---|
| 1019 | }
|
---|
| 1020 |
|
---|
| 1021 | /**
|
---|
[a694a58] | 1022 | * Nulls last item of the usage path structure.
|
---|
[b53d3b7] | 1023 | *
|
---|
[57d9c05e] | 1024 | * @param usage_path
|
---|
[a694a58] | 1025 | * @return void
|
---|
[b53d3b7] | 1026 | */
|
---|
| 1027 | void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
|
---|
| 1028 | {
|
---|
| 1029 | usb_hid_report_usage_path_t *item;
|
---|
| 1030 |
|
---|
[dc9f122] | 1031 | if(!list_empty(&usage_path->head)){
|
---|
| 1032 | item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
|
---|
[b53d3b7] | 1033 | memset(item, 0, sizeof(usb_hid_report_usage_path_t));
|
---|
| 1034 | }
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 | /**
|
---|
[a694a58] | 1038 | * Modifies last item of usage path structure by given usage page or usage
|
---|
[b53d3b7] | 1039 | *
|
---|
[a694a58] | 1040 | * @param usage_path Opaque usage path structure
|
---|
| 1041 | * @param tag Class of currently processed tag (Usage page tag falls into Global
|
---|
| 1042 | * class but Usage tag into the Local)
|
---|
| 1043 | * @param data Value of the processed tag
|
---|
| 1044 | * @return void
|
---|
[b53d3b7] | 1045 | */
|
---|
| 1046 | void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
|
---|
| 1047 | {
|
---|
| 1048 | usb_hid_report_usage_path_t *item;
|
---|
| 1049 |
|
---|
[dc9f122] | 1050 | if(!list_empty(&usage_path->head)){
|
---|
| 1051 | item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
|
---|
[b53d3b7] | 1052 |
|
---|
| 1053 | switch(tag) {
|
---|
| 1054 | case USB_HID_TAG_CLASS_GLOBAL:
|
---|
| 1055 | item->usage_page = data;
|
---|
| 1056 | break;
|
---|
| 1057 | case USB_HID_TAG_CLASS_LOCAL:
|
---|
| 1058 | item->usage = data;
|
---|
| 1059 | break;
|
---|
| 1060 | }
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
[175ad13e] | 1065 |
|
---|
| 1066 | void usb_hid_print_usage_path(usb_hid_report_path_t *path)
|
---|
| 1067 | {
|
---|
| 1068 | usb_log_debug("USAGE_PATH FOR RId(%d):\n", path->report_id);
|
---|
| 1069 | usb_log_debug("\tLENGTH: %d\n", path->depth);
|
---|
| 1070 |
|
---|
[dc9f122] | 1071 | link_t *item = path->head.next;
|
---|
[175ad13e] | 1072 | usb_hid_report_usage_path_t *path_item;
|
---|
[dc9f122] | 1073 | while(item != &path->head) {
|
---|
[175ad13e] | 1074 |
|
---|
| 1075 | path_item = list_get_instance(item, usb_hid_report_usage_path_t, link);
|
---|
| 1076 | usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
|
---|
| 1077 | usb_log_debug("\tUSAGE: %X\n", path_item->usage);
|
---|
| 1078 | usb_log_debug("\tFLAGS: %d\n", path_item->flags);
|
---|
| 1079 |
|
---|
| 1080 | item = item->next;
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
[b53d3b7] | 1084 | /**
|
---|
[a694a58] | 1085 | * Compares two usage paths structures
|
---|
[b53d3b7] | 1086 | *
|
---|
[dc9f122] | 1087 | * If USB_HID_PATH_COMPARE_COLLECTION_ONLY flag is given, the last item in report_path structure is forgotten
|
---|
| 1088 | *
|
---|
[a694a58] | 1089 | * @param report_path usage path structure to compare
|
---|
| 1090 | * @param path usage patrh structure to compare
|
---|
| 1091 | * @param flags Flags determining the mode of comparison
|
---|
| 1092 | * @return EOK if both paths are identical, non zero number otherwise
|
---|
[b53d3b7] | 1093 | */
|
---|
| 1094 | int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
|
---|
| 1095 | usb_hid_report_path_t *path,
|
---|
| 1096 | int flags)
|
---|
| 1097 | {
|
---|
| 1098 | usb_hid_report_usage_path_t *report_item;
|
---|
| 1099 | usb_hid_report_usage_path_t *path_item;
|
---|
| 1100 |
|
---|
| 1101 | link_t *report_link;
|
---|
| 1102 | link_t *path_link;
|
---|
| 1103 |
|
---|
| 1104 | int only_page;
|
---|
| 1105 |
|
---|
[bda06a3] | 1106 | if(report_path->report_id != path->report_id) {
|
---|
| 1107 | return 1;
|
---|
| 1108 | }
|
---|
| 1109 |
|
---|
[b53d3b7] | 1110 | if(path->depth == 0){
|
---|
| 1111 | return EOK;
|
---|
| 1112 | }
|
---|
| 1113 |
|
---|
| 1114 |
|
---|
| 1115 | if((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0){
|
---|
| 1116 | flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY;
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | switch(flags){
|
---|
| 1120 | /* path must be completly identical */
|
---|
| 1121 | case USB_HID_PATH_COMPARE_STRICT:
|
---|
| 1122 | if(report_path->depth != path->depth){
|
---|
| 1123 | return 1;
|
---|
| 1124 | }
|
---|
| 1125 |
|
---|
[681f24b3] | 1126 | report_link = report_path->head.next;
|
---|
| 1127 | path_link = path->head.next;
|
---|
[b53d3b7] | 1128 |
|
---|
[681f24b3] | 1129 | while((report_link != &report_path->head) && (path_link != &path->head)) {
|
---|
[b53d3b7] | 1130 | report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
|
---|
| 1131 | path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
|
---|
| 1132 |
|
---|
| 1133 | if((report_item->usage_page != path_item->usage_page) ||
|
---|
| 1134 | ((only_page == 0) && (report_item->usage != path_item->usage))) {
|
---|
| 1135 | return 1;
|
---|
| 1136 | } else {
|
---|
| 1137 | report_link = report_link->next;
|
---|
| 1138 | path_link = path_link->next;
|
---|
| 1139 | }
|
---|
| 1140 |
|
---|
| 1141 | }
|
---|
| 1142 |
|
---|
[dc9f122] | 1143 | if(((report_link == &report_path->head) && (path_link == &path->head)) ||
|
---|
| 1144 | (((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) && (path_link = &path->head) && (report_link == report_path->head.prev))) {
|
---|
[b53d3b7] | 1145 | return EOK;
|
---|
| 1146 | }
|
---|
| 1147 | else {
|
---|
| 1148 | return 1;
|
---|
| 1149 | }
|
---|
| 1150 | break;
|
---|
| 1151 |
|
---|
[96bfe76] | 1152 | /* compare with only the end of path*/
|
---|
[b53d3b7] | 1153 | case USB_HID_PATH_COMPARE_END:
|
---|
[dc9f122] | 1154 |
|
---|
| 1155 | if((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) {
|
---|
| 1156 | report_link = report_path->head.prev->prev;
|
---|
| 1157 | }
|
---|
| 1158 | else {
|
---|
| 1159 | report_link = report_path->head.prev;
|
---|
| 1160 | }
|
---|
[681f24b3] | 1161 | path_link = path->head.prev;
|
---|
[b53d3b7] | 1162 |
|
---|
[681f24b3] | 1163 | if(list_empty(&path->head)){
|
---|
[b53d3b7] | 1164 | return EOK;
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
[681f24b3] | 1167 | while((report_link != &report_path->head) && (path_link != &path->head)) {
|
---|
[b53d3b7] | 1168 | report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
|
---|
| 1169 | path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
|
---|
| 1170 |
|
---|
| 1171 | if((report_item->usage_page != path_item->usage_page) ||
|
---|
| 1172 | ((only_page == 0) && (report_item->usage != path_item->usage))) {
|
---|
| 1173 | return 1;
|
---|
| 1174 | } else {
|
---|
| 1175 | report_link = report_link->prev;
|
---|
| 1176 | path_link = path_link->prev;
|
---|
| 1177 | }
|
---|
| 1178 |
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
[681f24b3] | 1181 | if(path_link == &path->head) {
|
---|
[b53d3b7] | 1182 | return EOK;
|
---|
| 1183 | }
|
---|
| 1184 | else {
|
---|
| 1185 | return 1;
|
---|
| 1186 | }
|
---|
| 1187 |
|
---|
| 1188 | break;
|
---|
| 1189 |
|
---|
| 1190 | default:
|
---|
| 1191 | return EINVAL;
|
---|
| 1192 | }
|
---|
| 1193 |
|
---|
| 1194 |
|
---|
| 1195 |
|
---|
| 1196 |
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | /**
|
---|
[a694a58] | 1200 | * Allocates and initializes new usage path structure.
|
---|
[b53d3b7] | 1201 | *
|
---|
[a694a58] | 1202 | * @return Initialized usage path structure
|
---|
[b53d3b7] | 1203 | */
|
---|
| 1204 | usb_hid_report_path_t *usb_hid_report_path(void)
|
---|
| 1205 | {
|
---|
| 1206 | usb_hid_report_path_t *path;
|
---|
| 1207 | path = malloc(sizeof(usb_hid_report_path_t));
|
---|
[175ad13e] | 1208 | if(path == NULL){
|
---|
[b53d3b7] | 1209 | return NULL;
|
---|
| 1210 | }
|
---|
| 1211 | else {
|
---|
| 1212 | path->depth = 0;
|
---|
[bda06a3] | 1213 | path->report_id = 0;
|
---|
[b53d3b7] | 1214 | list_initialize(&path->link);
|
---|
[dc9f122] | 1215 | list_initialize(&path->head);
|
---|
[b53d3b7] | 1216 | return path;
|
---|
| 1217 | }
|
---|
| 1218 | }
|
---|
| 1219 |
|
---|
| 1220 | /**
|
---|
[a694a58] | 1221 | * Releases given usage path structure.
|
---|
[b53d3b7] | 1222 | *
|
---|
[a694a58] | 1223 | * @param path usage path structure to release
|
---|
[57d9c05e] | 1224 | * @return void
|
---|
[b53d3b7] | 1225 | */
|
---|
| 1226 | void usb_hid_report_path_free(usb_hid_report_path_t *path)
|
---|
| 1227 | {
|
---|
[dc9f122] | 1228 | while(!list_empty(&path->head)){
|
---|
[b53d3b7] | 1229 | usb_hid_report_remove_last_item(path);
|
---|
| 1230 | }
|
---|
[175ad13e] | 1231 |
|
---|
| 1232 | list_remove(&path->link);
|
---|
| 1233 | free(path);
|
---|
[b53d3b7] | 1234 | }
|
---|
| 1235 |
|
---|
| 1236 |
|
---|
| 1237 | /**
|
---|
[96bfe76] | 1238 | * Clone content of given usage path to the new one
|
---|
[b53d3b7] | 1239 | *
|
---|
[a694a58] | 1240 | * @param usage_path Usage path structure to clone
|
---|
| 1241 | * @return New copy of given usage path structure
|
---|
[b53d3b7] | 1242 | */
|
---|
[96bfe76] | 1243 | usb_hid_report_path_t *usb_hid_report_path_clone(usb_hid_report_path_t *usage_path)
|
---|
[b53d3b7] | 1244 | {
|
---|
| 1245 | link_t *path_link;
|
---|
[175ad13e] | 1246 | usb_hid_report_usage_path_t *path_item;
|
---|
| 1247 | usb_hid_report_usage_path_t *new_path_item;
|
---|
[96bfe76] | 1248 | usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
|
---|
[b53d3b7] | 1249 |
|
---|
[96bfe76] | 1250 | if(new_usage_path == NULL){
|
---|
| 1251 | return NULL;
|
---|
| 1252 | }
|
---|
[c7c0984a] | 1253 |
|
---|
| 1254 | new_usage_path->report_id = usage_path->report_id;
|
---|
[b53d3b7] | 1255 |
|
---|
[dc9f122] | 1256 | if(list_empty(&usage_path->head)){
|
---|
[96bfe76] | 1257 | return new_usage_path;
|
---|
[b53d3b7] | 1258 | }
|
---|
| 1259 |
|
---|
[dc9f122] | 1260 | path_link = usage_path->head.next;
|
---|
| 1261 | while(path_link != &usage_path->head) {
|
---|
[b53d3b7] | 1262 | path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
|
---|
[175ad13e] | 1263 | new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
|
---|
| 1264 | if(new_path_item == NULL) {
|
---|
| 1265 | return NULL;
|
---|
| 1266 | }
|
---|
[dc9f122] | 1267 |
|
---|
| 1268 | list_initialize (&new_path_item->link);
|
---|
[175ad13e] | 1269 | new_path_item->usage_page = path_item->usage_page;
|
---|
| 1270 | new_path_item->usage = path_item->usage;
|
---|
| 1271 | new_path_item->flags = path_item->flags;
|
---|
| 1272 |
|
---|
[dc9f122] | 1273 | list_append(&new_path_item->link, &new_usage_path->head);
|
---|
[175ad13e] | 1274 | new_usage_path->depth++;
|
---|
[b53d3b7] | 1275 |
|
---|
| 1276 | path_link = path_link->next;
|
---|
| 1277 | }
|
---|
| 1278 |
|
---|
[96bfe76] | 1279 | return new_usage_path;
|
---|
[b53d3b7] | 1280 | }
|
---|
| 1281 |
|
---|
[0bd4810c] | 1282 |
|
---|
[57d9c05e] | 1283 | /*** OUTPUT API **/
|
---|
| 1284 |
|
---|
[a694a58] | 1285 | /**
|
---|
| 1286 | * Allocates output report buffer for output report
|
---|
[57d9c05e] | 1287 | *
|
---|
[a694a58] | 1288 | * @param parser Report parsed structure
|
---|
| 1289 | * @param size Size of returned buffer
|
---|
| 1290 | * @param report_id Report id of created output report
|
---|
| 1291 | * @return Returns allocated output buffer for specified output
|
---|
[57d9c05e] | 1292 | */
|
---|
[175ad13e] | 1293 | uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, uint8_t report_id)
|
---|
[57d9c05e] | 1294 | {
|
---|
[175ad13e] | 1295 | if(report == NULL) {
|
---|
[57d9c05e] | 1296 | *size = 0;
|
---|
| 1297 | return NULL;
|
---|
| 1298 | }
|
---|
| 1299 |
|
---|
[175ad13e] | 1300 | link_t *report_it = report->reports.next;
|
---|
| 1301 | usb_hid_report_description_t *report_des = NULL;
|
---|
| 1302 | while(report_it != &report->reports) {
|
---|
| 1303 | report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
|
---|
[dc9f122] | 1304 | if((report_des->report_id == report_id) && (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)){
|
---|
[a694a58] | 1305 | break;
|
---|
[c156c2d] | 1306 | }
|
---|
| 1307 |
|
---|
[175ad13e] | 1308 | report_it = report_it->next;
|
---|
| 1309 | }
|
---|
[841e6e5] | 1310 |
|
---|
[175ad13e] | 1311 | if(report_des == NULL){
|
---|
| 1312 | *size = 0;
|
---|
| 1313 | return NULL;
|
---|
[57d9c05e] | 1314 | }
|
---|
| 1315 | else {
|
---|
[175ad13e] | 1316 | *size = (report_des->bit_length + (8 - 1))/8;
|
---|
| 1317 | uint8_t *ret = malloc((*size) * sizeof(uint8_t));
|
---|
| 1318 | memset(ret, 0, (*size) * sizeof(uint8_t));
|
---|
| 1319 | return ret;
|
---|
[57d9c05e] | 1320 | }
|
---|
| 1321 | }
|
---|
| 1322 |
|
---|
| 1323 |
|
---|
| 1324 | /** Frees output report buffer
|
---|
| 1325 | *
|
---|
| 1326 | * @param output Output report buffer
|
---|
[a694a58] | 1327 | * @return void
|
---|
[57d9c05e] | 1328 | */
|
---|
| 1329 | void usb_hid_report_output_free(uint8_t *output)
|
---|
[841e6e5] | 1330 |
|
---|
[57d9c05e] | 1331 | {
|
---|
| 1332 | if(output != NULL) {
|
---|
| 1333 | free (output);
|
---|
| 1334 | }
|
---|
| 1335 | }
|
---|
| 1336 |
|
---|
| 1337 | /** Returns size of output for given usage path
|
---|
| 1338 | *
|
---|
[a694a58] | 1339 | * @param parser Opaque report parser structure
|
---|
| 1340 | * @param path Usage path specified which items will be thought for the output
|
---|
| 1341 | * @param flags Flags of usage path structure comparison
|
---|
| 1342 | * @return Number of items matching the given usage path
|
---|
[57d9c05e] | 1343 | */
|
---|
[175ad13e] | 1344 | size_t usb_hid_report_output_size(usb_hid_report_t *report,
|
---|
[57d9c05e] | 1345 | usb_hid_report_path_t *path, int flags)
|
---|
| 1346 | {
|
---|
[175ad13e] | 1347 | size_t ret = 0;
|
---|
| 1348 | usb_hid_report_description_t *report_des;
|
---|
[57d9c05e] | 1349 |
|
---|
[175ad13e] | 1350 | if(report == NULL) {
|
---|
[57d9c05e] | 1351 | return 0;
|
---|
| 1352 | }
|
---|
[bda06a3] | 1353 |
|
---|
[175ad13e] | 1354 | report_des = usb_hid_report_find_description (report, path->report_id, USB_HID_REPORT_TYPE_OUTPUT);
|
---|
| 1355 | if(report_des == NULL){
|
---|
| 1356 | return 0;
|
---|
| 1357 | }
|
---|
[dc9f122] | 1358 |
|
---|
[175ad13e] | 1359 | link_t *field_it = report_des->report_items.next;
|
---|
| 1360 | usb_hid_report_field_t *field;
|
---|
| 1361 | while(field_it != &report_des->report_items) {
|
---|
| 1362 |
|
---|
| 1363 | field = list_get_instance(field_it, usb_hid_report_field_t, link);
|
---|
[e50cd7f] | 1364 | if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0){
|
---|
| 1365 | usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
|
---|
| 1366 | if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK) {
|
---|
| 1367 | ret++;
|
---|
| 1368 | }
|
---|
| 1369 | usb_hid_report_remove_last_item (field->collection_path);
|
---|
[175ad13e] | 1370 | }
|
---|
| 1371 |
|
---|
| 1372 | field_it = field_it->next;
|
---|
[c156c2d] | 1373 | }
|
---|
[57d9c05e] | 1374 |
|
---|
| 1375 | return ret;
|
---|
| 1376 |
|
---|
| 1377 | }
|
---|
| 1378 |
|
---|
[175ad13e] | 1379 | /** Makes the output report buffer for data given in the report structure
|
---|
[57d9c05e] | 1380 | *
|
---|
[a694a58] | 1381 | * @param parser Opaque report parser structure
|
---|
| 1382 | * @param path Usage path specifing which parts of output will be set
|
---|
| 1383 | * @param flags Usage path structure comparison flags
|
---|
| 1384 | * @param buffer Output buffer
|
---|
| 1385 | * @param size Size of output buffer
|
---|
| 1386 | * @return Error code
|
---|
[57d9c05e] | 1387 | */
|
---|
[175ad13e] | 1388 | int usb_hid_report_output_translate(usb_hid_report_t *report, uint8_t report_id,
|
---|
| 1389 | uint8_t *buffer, size_t size)
|
---|
[57d9c05e] | 1390 | {
|
---|
| 1391 | link_t *item;
|
---|
| 1392 | int32_t value=0;
|
---|
[841e6e5] | 1393 | int offset;
|
---|
| 1394 | int length;
|
---|
| 1395 | int32_t tmp_value;
|
---|
[57d9c05e] | 1396 |
|
---|
[175ad13e] | 1397 | if(report == NULL) {
|
---|
[57d9c05e] | 1398 | return EINVAL;
|
---|
| 1399 | }
|
---|
| 1400 |
|
---|
[175ad13e] | 1401 | if(report->use_report_ids != 0) {
|
---|
| 1402 | buffer[0] = report_id;
|
---|
[bda06a3] | 1403 | }
|
---|
| 1404 |
|
---|
[70a71e5] | 1405 | usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
|
---|
[cfbbe1d3] | 1406 |
|
---|
[175ad13e] | 1407 | usb_hid_report_description_t *report_des;
|
---|
| 1408 | report_des = usb_hid_report_find_description (report, report_id, USB_HID_REPORT_TYPE_OUTPUT);
|
---|
| 1409 | if(report_des == NULL){
|
---|
| 1410 | return EINVAL;
|
---|
| 1411 | }
|
---|
[57d9c05e] | 1412 |
|
---|
[175ad13e] | 1413 | usb_hid_report_field_t *report_item;
|
---|
| 1414 | item = report_des->report_items.next;
|
---|
| 1415 | while(item != &report_des->report_items) {
|
---|
| 1416 | report_item = list_get_instance(item, usb_hid_report_field_t, link);
|
---|
[841e6e5] | 1417 |
|
---|
[cfbbe1d3] | 1418 | if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
|
---|
[d012590] | 1419 |
|
---|
[cfbbe1d3] | 1420 | // array
|
---|
[175ad13e] | 1421 | value = usb_hid_translate_data_reverse(report_item, report_item->value);
|
---|
| 1422 | offset = report_item->offset;
|
---|
[841e6e5] | 1423 | length = report_item->size;
|
---|
| 1424 | }
|
---|
| 1425 | else {
|
---|
[cfbbe1d3] | 1426 | // variable item
|
---|
| 1427 | value = usb_hid_translate_data_reverse(report_item, report_item->value);
|
---|
[175ad13e] | 1428 | offset = report_item->offset;
|
---|
| 1429 | length = report_item->size;
|
---|
[841e6e5] | 1430 | }
|
---|
| 1431 |
|
---|
[d012590] | 1432 | if((offset/8) == ((offset+length-1)/8)) {
|
---|
[841e6e5] | 1433 | // je to v jednom bytu
|
---|
[d012590] | 1434 | if(((size_t)(offset/8) >= size) || ((size_t)(offset+length-1)/8) >= size) {
|
---|
[841e6e5] | 1435 | break; // TODO ErrorCode
|
---|
| 1436 | }
|
---|
| 1437 |
|
---|
[2f4b3a4] | 1438 | size_t shift = offset%8;
|
---|
[841e6e5] | 1439 |
|
---|
[d012590] | 1440 | value = value << shift;
|
---|
| 1441 | value = value & (((1 << length)-1) << shift);
|
---|
[70a71e5] | 1442 |
|
---|
| 1443 | uint8_t mask = 0;
|
---|
| 1444 | mask = 0xff - (((1 << length) - 1) << shift);
|
---|
| 1445 | buffer[offset/8] = (buffer[offset/8] & mask) | value;
|
---|
[841e6e5] | 1446 | }
|
---|
| 1447 | else {
|
---|
[175ad13e] | 1448 | int i = 0;
|
---|
[70a71e5] | 1449 | uint8_t mask = 0;
|
---|
[175ad13e] | 1450 | for(i = (offset/8); i <= ((offset+length-1)/8); i++) {
|
---|
| 1451 | if(i == (offset/8)) {
|
---|
| 1452 | tmp_value = value;
|
---|
| 1453 | tmp_value = tmp_value & ((1 << (8-(offset%8)))-1);
|
---|
| 1454 | tmp_value = tmp_value << (offset%8);
|
---|
| 1455 |
|
---|
| 1456 | mask = ~(((1 << (8-(offset%8)))-1) << (offset%8));
|
---|
| 1457 | buffer[i] = (buffer[i] & mask) | tmp_value;
|
---|
| 1458 | }
|
---|
| 1459 | else if (i == ((offset + length -1)/8)) {
|
---|
| 1460 |
|
---|
| 1461 | value = value >> (length - ((offset + length) % 8));
|
---|
| 1462 | value = value & ((1 << (length - ((offset + length) % 8))) - 1);
|
---|
[d012590] | 1463 |
|
---|
[175ad13e] | 1464 | mask = (1 << (length - ((offset + length) % 8))) - 1;
|
---|
| 1465 | buffer[i] = (buffer[i] & mask) | value;
|
---|
| 1466 | }
|
---|
| 1467 | else {
|
---|
| 1468 | buffer[i] = value & (0xFF << i);
|
---|
| 1469 | }
|
---|
| 1470 | }
|
---|
[841e6e5] | 1471 | }
|
---|
[57d9c05e] | 1472 |
|
---|
[841e6e5] | 1473 |
|
---|
[cfbbe1d3] | 1474 | // reset value
|
---|
| 1475 | report_item->value = 0;
|
---|
| 1476 |
|
---|
[841e6e5] | 1477 | item = item->next;
|
---|
[57d9c05e] | 1478 | }
|
---|
[cfbbe1d3] | 1479 |
|
---|
[70a71e5] | 1480 | usb_log_debug("OUTPUT BUFFER: %s\n", usb_debug_str_buffer(buffer,size, 0));
|
---|
[841e6e5] | 1481 |
|
---|
[57d9c05e] | 1482 | return EOK;
|
---|
| 1483 | }
|
---|
| 1484 |
|
---|
[841e6e5] | 1485 | /**
|
---|
[a694a58] | 1486 | * Translate given data for putting them into the outoput report
|
---|
| 1487 | * @param item Report item structure
|
---|
| 1488 | * @param value Value to translate
|
---|
| 1489 | * @return ranslated value
|
---|
[841e6e5] | 1490 | */
|
---|
[175ad13e] | 1491 | uint32_t usb_hid_translate_data_reverse(usb_hid_report_field_t *item, int value)
|
---|
[841e6e5] | 1492 | {
|
---|
| 1493 | int ret=0;
|
---|
| 1494 | int resolution;
|
---|
| 1495 |
|
---|
[70a71e5] | 1496 | if(USB_HID_ITEM_FLAG_CONSTANT(item->item_flags)) {
|
---|
| 1497 | ret = item->logical_minimum;
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
[cfbbe1d3] | 1500 | if((item->physical_minimum == 0) && (item->physical_maximum == 0)){
|
---|
| 1501 | item->physical_minimum = item->logical_minimum;
|
---|
| 1502 | item->physical_maximum = item->logical_maximum;
|
---|
| 1503 | }
|
---|
| 1504 |
|
---|
| 1505 |
|
---|
[d012590] | 1506 | if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0)) {
|
---|
[841e6e5] | 1507 |
|
---|
| 1508 | // variable item
|
---|
| 1509 | if(item->physical_maximum == item->physical_minimum){
|
---|
| 1510 | resolution = 1;
|
---|
| 1511 | }
|
---|
| 1512 | else {
|
---|
| 1513 | resolution = (item->logical_maximum - item->logical_minimum) /
|
---|
| 1514 | ((item->physical_maximum - item->physical_minimum) *
|
---|
| 1515 | (usb_pow(10,(item->unit_exponent))));
|
---|
| 1516 | }
|
---|
| 1517 |
|
---|
| 1518 | ret = ((value - item->physical_minimum) * resolution) + item->logical_minimum;
|
---|
| 1519 | }
|
---|
| 1520 | else {
|
---|
| 1521 | // bitmapa
|
---|
| 1522 | if(value == 0) {
|
---|
| 1523 | ret = 0;
|
---|
| 1524 | }
|
---|
| 1525 | else {
|
---|
| 1526 | size_t bitmap_idx = (value - item->usage_minimum);
|
---|
| 1527 | ret = 1 << bitmap_idx;
|
---|
| 1528 | }
|
---|
| 1529 | }
|
---|
| 1530 |
|
---|
| 1531 |
|
---|
[175ad13e] | 1532 | return (uint32_t)ret;
|
---|
[841e6e5] | 1533 | }
|
---|
| 1534 |
|
---|
[a694a58] | 1535 | /**
|
---|
| 1536 | * Sets report id in usage path structure
|
---|
| 1537 | *
|
---|
| 1538 | * @param path Usage path structure
|
---|
| 1539 | * @param report_id Report id to set
|
---|
| 1540 | * @return Error code
|
---|
| 1541 | */
|
---|
[bda06a3] | 1542 | int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
|
---|
| 1543 | {
|
---|
| 1544 | if(path == NULL){
|
---|
| 1545 | return EINVAL;
|
---|
| 1546 | }
|
---|
| 1547 |
|
---|
| 1548 | path->report_id = report_id;
|
---|
| 1549 | return EOK;
|
---|
| 1550 | }
|
---|
| 1551 |
|
---|
[175ad13e] | 1552 | /**
|
---|
| 1553 | *
|
---|
| 1554 | *
|
---|
| 1555 | *
|
---|
| 1556 | *
|
---|
| 1557 | *
|
---|
| 1558 | */
|
---|
| 1559 | int usb_hid_report_output_set_data(usb_hid_report_t *report,
|
---|
| 1560 | usb_hid_report_path_t *path, int flags,
|
---|
| 1561 | int *data, size_t data_size)
|
---|
| 1562 | {
|
---|
| 1563 | size_t data_idx = 0;
|
---|
| 1564 | if(report == NULL){
|
---|
| 1565 | return EINVAL;
|
---|
| 1566 | }
|
---|
| 1567 |
|
---|
| 1568 | usb_hid_report_description_t *report_des;
|
---|
| 1569 | report_des = usb_hid_report_find_description (report, path->report_id,
|
---|
| 1570 | USB_HID_REPORT_TYPE_OUTPUT);
|
---|
| 1571 | if(report_des == NULL){
|
---|
| 1572 | return EINVAL;
|
---|
| 1573 | }
|
---|
| 1574 |
|
---|
| 1575 | usb_hid_report_field_t *field;
|
---|
| 1576 | link_t *field_it = report_des->report_items.next;
|
---|
| 1577 | while(field_it != &report_des->report_items){
|
---|
| 1578 |
|
---|
| 1579 | field = list_get_instance(field_it, usb_hid_report_field_t, link);
|
---|
| 1580 | if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
|
---|
[dc9f122] | 1581 | usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
|
---|
| 1582 | if(usb_hid_report_compare_usage_path (field->collection_path, path,
|
---|
[175ad13e] | 1583 | flags) == EOK) {
|
---|
| 1584 | if(data_idx < data_size) {
|
---|
[cfbbe1d3] | 1585 | if((data[data_idx] >= field->physical_minimum) && (data[data_idx] >= field->physical_minimum)) {
|
---|
| 1586 | field->value = data[data_idx];
|
---|
| 1587 | }
|
---|
| 1588 | else {
|
---|
| 1589 | return ERANGE;
|
---|
| 1590 | }
|
---|
| 1591 |
|
---|
| 1592 | data_idx++;
|
---|
[175ad13e] | 1593 | }
|
---|
| 1594 | else {
|
---|
| 1595 | field->value = 0;
|
---|
| 1596 | }
|
---|
| 1597 | }
|
---|
[dc9f122] | 1598 | usb_hid_report_remove_last_item (field->collection_path);
|
---|
[175ad13e] | 1599 | }
|
---|
| 1600 |
|
---|
| 1601 | field_it = field_it->next;
|
---|
| 1602 | }
|
---|
| 1603 |
|
---|
| 1604 | return EOK;
|
---|
| 1605 | }
|
---|
| 1606 |
|
---|
[64dbc83] | 1607 |
|
---|
| 1608 | usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
|
---|
| 1609 | {
|
---|
| 1610 | usb_hid_report_item_t *new_report_item;
|
---|
| 1611 |
|
---|
| 1612 | if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
|
---|
| 1613 | return NULL;
|
---|
| 1614 | }
|
---|
| 1615 | memcpy(new_report_item,item, sizeof(usb_hid_report_item_t));
|
---|
| 1616 | link_initialize(&(new_report_item->link));
|
---|
| 1617 |
|
---|
| 1618 | return new_report_item;
|
---|
| 1619 | }
|
---|
| 1620 |
|
---|
[e50cd7f] | 1621 |
|
---|
| 1622 | usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
|
---|
| 1623 | usb_hid_report_field_t *field,
|
---|
| 1624 | usb_hid_report_path_t *path, int flags,
|
---|
| 1625 | usb_hid_report_type_t type)
|
---|
| 1626 | {
|
---|
| 1627 | usb_hid_report_description_t *report_des = usb_hid_report_find_description (report, path->report_id, type);
|
---|
| 1628 | link_t *field_it;
|
---|
| 1629 |
|
---|
| 1630 | if(report_des == NULL){
|
---|
| 1631 | return NULL;
|
---|
| 1632 | }
|
---|
| 1633 |
|
---|
| 1634 | if(field == NULL){
|
---|
| 1635 | // vezmu prvni co mathuje podle path!!
|
---|
| 1636 | field_it = report_des->report_items.next;
|
---|
| 1637 | }
|
---|
| 1638 | else {
|
---|
| 1639 | field_it = field->link.next;
|
---|
| 1640 | }
|
---|
| 1641 |
|
---|
| 1642 | while(field_it != &report_des->report_items) {
|
---|
| 1643 | field = list_get_instance(field_it, usb_hid_report_field_t, link);
|
---|
[c7c0984a] | 1644 |
|
---|
| 1645 | if(USB_HID_ITEM_FLAG_CONSTANT(field->item_flags) == 0) {
|
---|
| 1646 | usb_hid_report_path_append_item (field->collection_path, field->usage_page, field->usage);
|
---|
| 1647 | if(usb_hid_report_compare_usage_path (field->collection_path, path, flags) == EOK){
|
---|
| 1648 | usb_hid_report_remove_last_item (field->collection_path);
|
---|
| 1649 | return field;
|
---|
| 1650 | }
|
---|
[e50cd7f] | 1651 | usb_hid_report_remove_last_item (field->collection_path);
|
---|
| 1652 | }
|
---|
| 1653 | field_it = field_it->next;
|
---|
| 1654 | }
|
---|
| 1655 |
|
---|
| 1656 | return NULL;
|
---|
| 1657 | }
|
---|
[cfbbe1d3] | 1658 |
|
---|
| 1659 | uint8_t usb_hid_report_get_report_id(usb_hid_report_t *report, uint8_t report_id, usb_hid_report_type_t type)
|
---|
| 1660 | {
|
---|
| 1661 | if(report == NULL){
|
---|
| 1662 | return 0;
|
---|
| 1663 | }
|
---|
| 1664 |
|
---|
| 1665 | usb_hid_report_description_t *report_des;
|
---|
| 1666 | link_t *report_it;
|
---|
| 1667 |
|
---|
| 1668 | if(report_id == 0) {
|
---|
| 1669 | report_it = usb_hid_report_find_description (report, report_id, type)->link.next;
|
---|
| 1670 | }
|
---|
| 1671 | else {
|
---|
| 1672 | report_it = report->reports.next;
|
---|
| 1673 | }
|
---|
| 1674 |
|
---|
| 1675 | while(report_it != &report->reports) {
|
---|
| 1676 | report_des = list_get_instance(report_it, usb_hid_report_description_t, link);
|
---|
| 1677 | if(report_des->type == type){
|
---|
| 1678 | return report_des->report_id;
|
---|
| 1679 | }
|
---|
| 1680 | }
|
---|
| 1681 |
|
---|
| 1682 | return 0;
|
---|
| 1683 | }
|
---|
| 1684 |
|
---|
| 1685 |
|
---|
[976f546] | 1686 | /**
|
---|
| 1687 | * @}
|
---|
[c7a2e7e] | 1688 | */
|
---|