Changeset df6ded8 in mainline for uspace/lib/usbhid/src/hidpath.c
- Timestamp:
- 2018-02-28T16:37:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b20da0
- Parents:
- f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
- git-committer:
- Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidpath.c
rf5e5f73 rdf6ded8 73 73 * @return Error code 74 74 */ 75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 76 77 { 78 usb_hid_report_usage_path_t *item 79 =malloc(sizeof(usb_hid_report_usage_path_t));75 errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 76 int32_t usage_page, int32_t usage) 77 { 78 usb_hid_report_usage_path_t *item = 79 malloc(sizeof(usb_hid_report_usage_path_t)); 80 80 81 81 if (item == NULL) { … … 87 87 item->usage_page = usage_page; 88 88 item->flags = 0; 89 89 90 90 list_append (&item->rpath_items_link, &usage_path->items); 91 91 usage_path->depth++; … … 96 96 /** 97 97 * Removes last item from the usage path structure 98 * @param usage_path 98 * @param usage_path 99 99 * @return void 100 100 */ … … 103 103 link_t *item_link; 104 104 usb_hid_report_usage_path_t *item; 105 106 if (!list_empty(&usage_path->items)){105 106 if (!list_empty(&usage_path->items)) { 107 107 item_link = list_last(&usage_path->items); 108 108 item = list_get_instance(item_link, … … 124 124 { 125 125 usb_hid_report_usage_path_t *item; 126 127 if (!list_empty(&usage_path->items)){126 127 if (!list_empty(&usage_path->items)) { 128 128 item = list_get_instance(list_last(&usage_path->items), 129 129 usb_hid_report_usage_path_t, rpath_items_link); 130 130 131 131 memset(item, 0, sizeof(usb_hid_report_usage_path_t)); … … 143 143 * @return void 144 144 */ 145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 146 145 void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 146 int32_t tag, int32_t data) 147 147 { 148 148 usb_hid_report_usage_path_t *item; 149 150 if (!list_empty(&usage_path->items)){149 150 if (!list_empty(&usage_path->items)) { 151 151 item = list_get_instance(list_last(&usage_path->items), 152 152 usb_hid_report_usage_path_t, rpath_items_link); 153 153 154 switch(tag) { 155 case USB_HID_TAG_CLASS_GLOBAL: 156 item->usage_page = data; 157 break; 158 case USB_HID_TAG_CLASS_LOCAL: 159 item->usage = data; 160 break; 161 } 162 } 163 164 } 165 166 167 /** 168 * 169 * 170 * 171 * 172 */ 154 switch (tag) { 155 case USB_HID_TAG_CLASS_GLOBAL: 156 item->usage_page = data; 157 break; 158 case USB_HID_TAG_CLASS_LOCAL: 159 item->usage = data; 160 break; 161 } 162 } 163 } 164 173 165 void usb_hid_print_usage_path(usb_hid_report_path_t *path) 174 166 { 175 usb_log_debug("USAGE_PATH FOR RId(%d): \n", path->report_id);176 usb_log_debug("\tLENGTH: %d \n", path->depth);167 usb_log_debug("USAGE_PATH FOR RId(%d):", path->report_id); 168 usb_log_debug("\tLENGTH: %d", path->depth); 177 169 178 170 list_foreach(path->items, rpath_items_link, 179 171 usb_hid_report_usage_path_t, path_item) { 180 172 181 usb_log_debug("\tUSAGE_PAGE: %X \n", path_item->usage_page);182 usb_log_debug("\tUSAGE: %X \n", path_item->usage);183 usb_log_debug("\tFLAGS: %d \n", path_item->flags);173 usb_log_debug("\tUSAGE_PAGE: %X", path_item->usage_page); 174 usb_log_debug("\tUSAGE: %X", path_item->usage); 175 usb_log_debug("\tFLAGS: %d", path_item->flags); 184 176 } 185 177 } … … 199 191 usb_hid_report_usage_path_t *report_item; 200 192 usb_hid_report_usage_path_t *path_item; 201 193 202 194 link_t *report_link; 203 195 link_t *path_link; 204 196 205 197 int only_page; 206 198 207 199 if (report_path->report_id != path->report_id) { 208 200 if (path->report_id != 0) { … … 210 202 } 211 203 } 212 204 213 205 // Empty path match all others 214 206 if (path->depth == 0) { 215 207 return 0; 216 208 } 217 209 218 210 if ((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0) { 219 211 flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY; 220 212 } 221 213 222 214 switch (flags) { 223 215 /* Path is somewhere in report_path */ … … 226 218 return 1; 227 219 } 228 220 229 221 path_link = list_first(&path->items); 230 222 path_item = list_get_instance(path_link, 231 223 usb_hid_report_usage_path_t, rpath_items_link); 232 224 233 225 list_foreach(report_path->items, rpath_items_link, 234 226 usb_hid_report_usage_path_t, report_item) { 235 227 if (USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 236 228 path_item->usage_page)) { 237 229 238 230 if (only_page == 0) { 239 231 if (USB_HID_SAME_USAGE(report_item->usage, … … 245 237 } 246 238 } 247 239 248 240 return 1; 249 241 break; 250 242 251 243 /* The paths must be identical */ 252 244 case USB_HID_PATH_COMPARE_STRICT: … … 255 247 } 256 248 /* Fallthrough */ 257 249 258 250 /* Path is prefix of the report_path */ 259 251 case USB_HID_PATH_COMPARE_BEGIN: 260 252 report_link = report_path->items.head.next; 261 253 path_link = path->items.head.next; 262 254 263 255 while ((report_link != &report_path->items.head) && 264 256 (path_link != &path->items.head)) { 265 257 266 258 report_item = list_get_instance(report_link, 267 259 usb_hid_report_usage_path_t, rpath_items_link); 268 260 269 261 path_item = list_get_instance(path_link, 270 262 usb_hid_report_usage_path_t, rpath_items_link); 271 263 272 264 if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 273 265 path_item->usage_page) || ((only_page == 0) && … … 280 272 } 281 273 } 282 274 283 275 if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && 284 276 (path_link == &path->items.head)) || … … 290 282 } 291 283 break; 292 284 293 285 /* Path is suffix of report_path */ 294 286 case USB_HID_PATH_COMPARE_END: 295 287 report_link = report_path->items.head.prev; 296 288 path_link = path->items.head.prev; 297 289 298 290 if (list_empty(&path->items)) { 299 291 return 0; 300 292 } 301 293 302 294 while ((report_link != &report_path->items.head) && 303 295 (path_link != &path->items.head)) { 304 296 report_item = list_get_instance(report_link, 305 297 usb_hid_report_usage_path_t, rpath_items_link); 306 298 307 299 path_item = list_get_instance(path_link, 308 300 usb_hid_report_usage_path_t, rpath_items_link); 309 301 310 302 if (!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, 311 303 path_item->usage_page) || ((only_page == 0) && … … 318 310 } 319 311 } 320 312 321 313 if (path_link == &path->items.head) { 322 314 return 0; … … 325 317 } 326 318 break; 327 319 328 320 default: 329 321 return -1; … … 340 332 usb_hid_report_path_t *path; 341 333 path = malloc(sizeof(usb_hid_report_path_t)); 342 if (path == NULL){334 if (path == NULL) { 343 335 return NULL; 344 336 } … … 363 355 if (path == NULL) 364 356 return; 365 while (!list_empty(&path->items)){357 while (!list_empty(&path->items)) { 366 358 usb_hid_report_remove_last_item(path); 367 359 } … … 379 371 */ 380 372 usb_hid_report_path_t *usb_hid_report_path_clone( 381 373 usb_hid_report_path_t *usage_path) 382 374 { 383 375 usb_hid_report_usage_path_t *new_path_item; 384 376 usb_hid_report_path_t *new_usage_path = usb_hid_report_path (); 385 377 386 if (new_usage_path == NULL){378 if (new_usage_path == NULL) { 387 379 return NULL; 388 380 } 389 381 390 382 new_usage_path->report_id = usage_path->report_id; 391 392 if (list_empty(&usage_path->items)){383 384 if (list_empty(&usage_path->items)) { 393 385 return new_usage_path; 394 386 } … … 398 390 399 391 new_path_item = malloc(sizeof(usb_hid_report_usage_path_t)); 400 if (new_path_item == NULL) {392 if (new_path_item == NULL) { 401 393 return NULL; 402 394 } 403 395 404 396 link_initialize(&new_path_item->rpath_items_link); 405 397 new_path_item->usage_page = path_item->usage_page; 406 new_path_item->usage = path_item->usage; 407 new_path_item->flags = path_item->flags; 408 398 new_path_item->usage = path_item->usage; 399 new_path_item->flags = path_item->flags; 400 409 401 list_append(&new_path_item->rpath_items_link, 410 402 &new_usage_path->items); … … 423 415 * @return Error code 424 416 */ 425 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 426 427 { 428 if (path == NULL){417 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, 418 uint8_t report_id) 419 { 420 if (path == NULL) { 429 421 return EINVAL; 430 422 }
Note:
See TracChangeset
for help on using the changeset viewer.