Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: hid: move hid definitions to usb_hid_def.h

Change-Id: I5883d27b96dcedfc0d0149961228a170b8d8e744

mojyack 13194267 97dce282

+189 -164
+97 -164
firmware/usbstack/usb_hid.c
··· 25 25 #include "kernel.h" 26 26 #include "powermgmt.h" 27 27 #include "usb_hid.h" 28 + #include "usb_hid_def.h" 28 29 #include "usb_class_driver.h" 29 30 /*#define LOGF_ENABLE*/ 30 31 #include "logf.h" 31 32 32 - /* Documents avaiable here: http://www.usb.org/developers/devclass_docs/ */ 33 - 34 - #define HID_VER 0x0110 /* 1.1 */ 35 - /* Subclass Codes (HID1_11.pdf, page 18) */ 36 - #define SUBCLASS_NONE 0 37 - #define SUBCLASS_BOOT_INTERFACE 1 38 - /* Protocol Codes (HID1_11.pdf, page 19) */ 39 - #define PROTOCOL_CODE_NONE 0 40 - #define PROTOCOL_CODE_KEYBOARD 1 41 - #define PROTOCOL_CODE_MOUSE 2 42 - /* HID main items (HID1_11.pdf, page 38) */ 43 - #define INPUT 0x80 44 - #define OUTPUT 0x90 45 - #define FEATURE 0xB0 46 - #define COLLECTION 0xA0 47 - #define COLLECTION_PHYSICAL 0x00 48 - #define COLLECTION_APPLICATION 0x01 49 - #define END_COLLECTION 0xC0 50 - /* Parts (HID1_11.pdf, page 40) */ 51 - #define MAIN_ITEM_CONSTANT BIT_N(0) /* 0x01 */ 52 - #define MAIN_ITEM_VARIABLE BIT_N(1) /* 0x02 */ 53 - #define MAIN_ITEM_RELATIVE BIT_N(2) /* 0x04 */ 54 - #define MAIN_ITEM_WRAP BIT_N(3) /* 0x08 */ 55 - #define MAIN_ITEM_NONLINEAR BIT_N(4) /* 0x10 */ 56 - #define MAIN_ITEM_NO_PREFERRED BIT_N(5) /* 0x20 */ 57 - #define MAIN_ITEM_NULL_STATE BIT_N(6) /* 0x40 */ 58 - #define MAIN_ITEM_VOLATILE BIT_N(7) /* 0x80 */ 59 - #define MAIN_ITEM_BUFFERED_BYTES BIT_N(8) /* 0x0100 */ 60 - /* HID global items (HID1_11.pdf, page 45) */ 61 - #define USAGE_PAGE 0x04 62 - #define LOGICAL_MINIMUM 0x14 63 - #define LOGICAL_MAXIMUM 0x24 64 - #define REPORT_SIZE 0x74 65 - #define REPORT_ID 0x84 66 - #define REPORT_COUNT 0x94 67 - /* HID local items (HID1_11.pdf, page 50) */ 68 - #define USAGE_MINIMUM 0x18 69 - #define USAGE_MAXIMUM 0x28 70 - /* Types of class descriptors (HID1_11.pdf, page 59) */ 71 - #define USB_DT_HID 0x21 72 - #define USB_DT_REPORT 0x22 73 - 74 - #define CONSUMER_USAGE 0x09 75 - 76 - /* HID-only class specific requests (HID1_11.pdf, page 61) */ 77 - #define USB_HID_GET_REPORT 0x01 78 - #define USB_HID_GET_IDLE 0x02 79 - #define USB_HID_GET_PROTOCOL 0x03 80 - #define USB_HID_SET_REPORT 0x09 81 - #define USB_HID_SET_IDLE 0x0A 82 - #define USB_HID_SET_PROTOCOL 0x0B 83 - 84 - /* Get_Report and Set_Report Report Type field (HID1_11.pdf, page 61) */ 85 - #define REPORT_TYPE_INPUT 0x01 86 - #define REPORT_TYPE_OUTPUT 0x02 87 - #define REPORT_TYPE_FEATURE 0x03 88 - 89 - #define HID_BUF_SIZE_MSG 16 90 - #define HID_BUF_SIZE_CMD 16 91 - #define HID_BUF_SIZE_REPORT 160 92 - #define HID_NUM_BUFFERS 5 93 - #define SET_REPORT_BUF_LEN 2 94 - #define GET_REPORT_BUF_LEN 2 33 + #define HID_BUF_SIZE_MSG 16 34 + #define HID_BUF_SIZE_CMD 16 35 + #define HID_BUF_SIZE_REPORT 160 36 + #define HID_NUM_BUFFERS 5 37 + #define SET_REPORT_BUF_LEN 2 38 + #define GET_REPORT_BUF_LEN 2 95 39 96 40 #ifdef LOGF_ENABLE 97 - 98 41 #define BUF_DUMP_BUF_LEN HID_BUF_SIZE_REPORT 99 42 #define BUF_DUMP_PREFIX_SIZE 5 100 43 #define BUF_DUMP_ITEMS_IN_LINE 8 ··· 127 70 .bAlternateSetting = 0, 128 71 .bNumEndpoints = 1, 129 72 .bInterfaceClass = USB_CLASS_HID, 130 - .bInterfaceSubClass = SUBCLASS_BOOT_INTERFACE, 131 - .bInterfaceProtocol = PROTOCOL_CODE_KEYBOARD, 73 + .bInterfaceSubClass = USB_HID_SUBCLASS_BOOT_INTERFACE, 74 + .bInterfaceProtocol = USB_HID_PROTOCOL_CODE_KEYBOARD, 132 75 .iInterface = 0 133 76 }; 134 77 135 - struct usb_hid_descriptor { 136 - uint8_t bLength; 137 - uint8_t bDescriptorType; 138 - uint16_t wBcdHID; 139 - uint8_t bCountryCode; 140 - uint8_t bNumDescriptors; 141 - uint8_t bDescriptorType0; 142 - uint16_t wDescriptorLength0; 143 - } __attribute__ ((packed)); 144 - 145 78 static struct usb_hid_descriptor __attribute__((aligned(2))) hid_descriptor = 146 79 { 147 80 .bLength = sizeof(struct usb_hid_descriptor), 148 81 .bDescriptorType = USB_DT_HID, 149 - .wBcdHID = HID_VER, 82 + .wBcdHID = USB_HID_VER, 150 83 .bCountryCode = 0, 151 84 .bNumDescriptors = 1, 152 85 .bDescriptorType0 = USB_DT_REPORT, ··· 462 395 usb_hid_report->buf_set = buf_set_keyboard; 463 396 usb_hid_report->is_key_released = 1; 464 397 465 - pack_parameter(&report, 0, 1, USAGE_PAGE, 398 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, 466 399 HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS); 467 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_KEYBOARD); 468 - pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_APPLICATION); 469 - pack_parameter(&report, 0, 1, REPORT_ID, REPORT_ID_KEYBOARD); 470 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_GENERIC_DESKTOP_KEYPAD); 471 - pack_parameter(&report, 0, 1, USAGE_MINIMUM, HID_KEYBOARD_LEFT_CONTROL); 472 - pack_parameter(&report, 0, 1, USAGE_MAXIMUM, HID_KEYBOARD_RIGHT_GUI); 473 - pack_parameter(&report, 1, 1, LOGICAL_MINIMUM, 0); 474 - pack_parameter(&report, 1, 1, LOGICAL_MAXIMUM, 1); 475 - pack_parameter(&report, 0, 1, REPORT_SIZE, 1); 476 - pack_parameter(&report, 0, 1, REPORT_COUNT, 8); 477 - pack_parameter(&report, 0, 1, INPUT, MAIN_ITEM_VARIABLE); 478 - pack_parameter(&report, 0, 1, REPORT_SIZE, 1); 479 - pack_parameter(&report, 0, 1, REPORT_COUNT, 5); 480 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_LEDS); 481 - pack_parameter(&report, 0, 1, USAGE_MINIMUM, HID_LED_NUM_LOCK); 482 - pack_parameter(&report, 0, 1, USAGE_MAXIMUM, HID_LED_KANA); 483 - pack_parameter(&report, 0, 1, OUTPUT, MAIN_ITEM_VARIABLE); 484 - pack_parameter(&report, 0, 1, REPORT_SIZE, 3); 485 - pack_parameter(&report, 0, 1, REPORT_COUNT, 1); 486 - pack_parameter(&report, 0, 1, OUTPUT, MAIN_ITEM_CONSTANT); 487 - pack_parameter(&report, 0, 1, REPORT_SIZE, 8); 488 - pack_parameter(&report, 0, 1, REPORT_COUNT, 6); 489 - pack_parameter(&report, 1, 1, LOGICAL_MINIMUM, 0); 490 - pack_parameter(&report, 1, 1, LOGICAL_MAXIMUM, HID_KEYBOARD_EX_SEL); 491 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_KEYBOARD_KEYPAD); 492 - pack_parameter(&report, 0, 1, USAGE_MINIMUM, 0); 493 - pack_parameter(&report, 0, 1, USAGE_MAXIMUM, HID_KEYBOARD_EX_SEL); 494 - pack_parameter(&report, 0, 1, INPUT, 0); 495 - PACK_VAL(report, END_COLLECTION); 400 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_KEYBOARD); 401 + pack_parameter(&report, 0, 1, USB_HID_COLLECTION, USB_HID_COLLECTION_APPLICATION); 402 + pack_parameter(&report, 0, 1, USB_HID_REPORT_ID, REPORT_ID_KEYBOARD); 403 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_GENERIC_DESKTOP_KEYPAD); 404 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MINIMUM, HID_KEYBOARD_LEFT_CONTROL); 405 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MAXIMUM, HID_KEYBOARD_RIGHT_GUI); 406 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MINIMUM, 0); 407 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MAXIMUM, 1); 408 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 1); 409 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 8); 410 + pack_parameter(&report, 0, 1, USB_HID_INPUT, USB_HID_MAIN_ITEM_VARIABLE); 411 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 1); 412 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 5); 413 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_USAGE_PAGE_LEDS); 414 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MINIMUM, HID_LED_NUM_LOCK); 415 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MAXIMUM, HID_LED_KANA); 416 + pack_parameter(&report, 0, 1, USB_HID_OUTPUT, USB_HID_MAIN_ITEM_VARIABLE); 417 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 3); 418 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 1); 419 + pack_parameter(&report, 0, 1, USB_HID_OUTPUT, USB_HID_MAIN_ITEM_CONSTANT); 420 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 8); 421 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 6); 422 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MINIMUM, 0); 423 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MAXIMUM, HID_KEYBOARD_EX_SEL); 424 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_USAGE_PAGE_KEYBOARD_KEYPAD); 425 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MINIMUM, 0); 426 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MAXIMUM, HID_KEYBOARD_EX_SEL); 427 + pack_parameter(&report, 0, 1, USB_HID_INPUT, 0); 428 + PACK_VAL(report, USB_HID_END_COLLECTION); 496 429 497 430 /* Consumer usage controls - play/pause, stop, etc. */ 498 431 usb_hid_report = &usb_hid_reports[REPORT_ID_CONSUMER]; ··· 500 433 usb_hid_report->buf_set = buf_set_consumer; 501 434 usb_hid_report->is_key_released = 1; 502 435 503 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_CONSUMER); 504 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, 436 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_USAGE_PAGE_CONSUMER); 437 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, 505 438 HID_CONSUMER_USAGE_CONSUMER_CONTROL); 506 - pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_APPLICATION); 507 - pack_parameter(&report, 0, 1, REPORT_ID, REPORT_ID_CONSUMER); 508 - pack_parameter(&report, 0, 1, REPORT_SIZE, 16); 509 - pack_parameter(&report, 0, 1, REPORT_COUNT, 2); 510 - pack_parameter(&report, 1, 1, LOGICAL_MINIMUM, 1); 511 - pack_parameter(&report, 1, 1, LOGICAL_MAXIMUM, 652); 512 - pack_parameter(&report, 0, 1, USAGE_MINIMUM, 439 + pack_parameter(&report, 0, 1, USB_HID_COLLECTION, USB_HID_COLLECTION_APPLICATION); 440 + pack_parameter(&report, 0, 1, USB_HID_REPORT_ID, REPORT_ID_CONSUMER); 441 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 16); 442 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 2); 443 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MINIMUM, 1); 444 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MAXIMUM, 652); 445 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MINIMUM, 513 446 HID_CONSUMER_USAGE_CONSUMER_CONTROL); 514 - pack_parameter(&report, 0, 1, USAGE_MAXIMUM, HID_CONSUMER_USAGE_AC_SEND); 515 - pack_parameter(&report, 0, 1, INPUT, MAIN_ITEM_NO_PREFERRED | 516 - MAIN_ITEM_NULL_STATE); 517 - PACK_VAL(report, END_COLLECTION); 447 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MAXIMUM, HID_CONSUMER_USAGE_AC_SEND); 448 + pack_parameter(&report, 0, 1, USB_HID_INPUT, USB_HID_MAIN_ITEM_NO_PREFERRED | 449 + USB_HID_MAIN_ITEM_NULL_STATE); 450 + PACK_VAL(report, USB_HID_END_COLLECTION); 518 451 519 452 #ifdef HAVE_USB_HID_MOUSE 520 453 /* Mouse control */ ··· 523 456 usb_hid_report->buf_set = buf_set_mouse; 524 457 usb_hid_report->is_key_released = 0; 525 458 526 - pack_parameter(&report, 0, 1, USAGE_PAGE, 459 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, 527 460 HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS); 528 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_MOUSE); 529 - pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_APPLICATION); 530 - pack_parameter(&report, 0, 1, REPORT_ID, REPORT_ID_MOUSE); 531 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_POINTER); 532 - pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_PHYSICAL); 533 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_BUTTON); 534 - pack_parameter(&report, 0, 1, USAGE_MINIMUM, 1); 535 - pack_parameter(&report, 0, 1, USAGE_MAXIMUM, 8); 536 - pack_parameter(&report, 1, 1, LOGICAL_MINIMUM, 0); 537 - pack_parameter(&report, 1, 1, LOGICAL_MAXIMUM, 1); 538 - pack_parameter(&report, 0, 1, REPORT_SIZE, 1); 539 - pack_parameter(&report, 0, 1, REPORT_COUNT, 8); 540 - pack_parameter(&report, 0, 1, INPUT, MAIN_ITEM_VARIABLE); 541 - pack_parameter(&report, 0, 1, USAGE_PAGE, 461 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_MOUSE); 462 + pack_parameter(&report, 0, 1, USB_HID_COLLECTION, USB_HID_COLLECTION_APPLICATION); 463 + pack_parameter(&report, 0, 1, USB_HID_REPORT_ID, REPORT_ID_MOUSE); 464 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_POINTER); 465 + pack_parameter(&report, 0, 1, USB_HID_COLLECTION, USB_HID_COLLECTION_PHYSICAL); 466 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_USAGE_PAGE_BUTTON); 467 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MINIMUM, 1); 468 + pack_parameter(&report, 0, 1, USB_HID_USAGE_MAXIMUM, 8); 469 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MINIMUM, 0); 470 + pack_parameter(&report, 1, 1, USB_HID_LOGICAL_MAXIMUM, 1); 471 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 1); 472 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 8); 473 + pack_parameter(&report, 0, 1, USB_HID_INPUT, USB_HID_MAIN_ITEM_VARIABLE); 474 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, 542 475 HID_USAGE_PAGE_GENERIC_DESKTOP_CONTROLS); 543 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_X); 544 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_Y); 545 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DESKTOP_WHEEL); 546 - pack_parameter(&report, 0, 1, LOGICAL_MINIMUM, -127 & 0xFF); 547 - pack_parameter(&report, 0, 1, LOGICAL_MAXIMUM, 127); 548 - pack_parameter(&report, 0, 1, REPORT_SIZE, 8); 549 - pack_parameter(&report, 0, 1, REPORT_COUNT, 3); 550 - pack_parameter(&report, 0, 1, INPUT, MAIN_ITEM_VARIABLE | MAIN_ITEM_RELATIVE); 551 - PACK_VAL(report, END_COLLECTION); 552 - PACK_VAL(report, END_COLLECTION); 476 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_X); 477 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_Y); 478 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DESKTOP_WHEEL); 479 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MINIMUM, -127 & 0xFF); 480 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MAXIMUM, 127); 481 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 8); 482 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 3); 483 + pack_parameter(&report, 0, 1, USB_HID_INPUT, USB_HID_MAIN_ITEM_VARIABLE | USB_HID_MAIN_ITEM_RELATIVE); 484 + PACK_VAL(report, USB_HID_END_COLLECTION); 485 + PACK_VAL(report, USB_HID_END_COLLECTION); 553 486 #endif /* HAVE_USB_HID_MOUSE */ 554 487 555 488 /* Background reports */ 556 - pack_parameter(&report, 0, 1, USAGE_PAGE, HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS); 557 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DEVICE_BACKGROUND_CONTROLS); 558 - pack_parameter(&report, 0, 1, COLLECTION, COLLECTION_APPLICATION); 559 - pack_parameter(&report, 0, 1, REPORT_ID, REPORT_ID_BACKGROUND); 489 + pack_parameter(&report, 0, 1, USB_HID_USAGE_PAGE, HID_USAGE_PAGE_GENERIC_DEVICE_CONTROLS); 490 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DEVICE_BACKGROUND_CONTROLS); 491 + pack_parameter(&report, 0, 1, USB_HID_COLLECTION, USB_HID_COLLECTION_APPLICATION); 492 + pack_parameter(&report, 0, 1, USB_HID_REPORT_ID, REPORT_ID_BACKGROUND); 560 493 /* Padding */ 561 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DEVICE_UNDEFINED); 562 - pack_parameter(&report, 0, 1, LOGICAL_MINIMUM, 0); 563 - pack_parameter(&report, 0, 1, LOGICAL_MAXIMUM, 255); 564 - pack_parameter(&report, 0, 1, REPORT_SIZE, 8); 565 - pack_parameter(&report, 0, 1, REPORT_COUNT, 1); 566 - pack_parameter(&report, 0, 1, FEATURE, MAIN_ITEM_CONSTANT); 494 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DEVICE_UNDEFINED); 495 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MINIMUM, 0); 496 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MAXIMUM, 255); 497 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 8); 498 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 1); 499 + pack_parameter(&report, 0, 1, USB_HID_FEATURE, USB_HID_MAIN_ITEM_CONSTANT); 567 500 /* Battery percentage */ 568 - pack_parameter(&report, 0, 0, CONSUMER_USAGE, HID_GENERIC_DEVICE_BATTERY_STRENGTH); 569 - pack_parameter(&report, 0, 1, LOGICAL_MINIMUM, 0); 570 - pack_parameter(&report, 0, 1, LOGICAL_MAXIMUM, 100); 571 - pack_parameter(&report, 0, 1, REPORT_SIZE, 8); 572 - pack_parameter(&report, 0, 1, REPORT_COUNT, 1); 573 - pack_parameter(&report, 0, 1, FEATURE, MAIN_ITEM_VARIABLE); 574 - PACK_VAL(report, END_COLLECTION); 501 + pack_parameter(&report, 0, 0, USB_HID_CONSUMER_USAGE, HID_GENERIC_DEVICE_BATTERY_STRENGTH); 502 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MINIMUM, 0); 503 + pack_parameter(&report, 0, 1, USB_HID_LOGICAL_MAXIMUM, 100); 504 + pack_parameter(&report, 0, 1, USB_HID_REPORT_SIZE, 8); 505 + pack_parameter(&report, 0, 1, USB_HID_REPORT_COUNT, 1); 506 + pack_parameter(&report, 0, 1, USB_HID_FEATURE, USB_HID_MAIN_ITEM_VARIABLE); 507 + PACK_VAL(report, USB_HID_END_COLLECTION); 575 508 576 509 return (size_t)(report - dest); 577 510 } ··· 665 598 static unsigned char buf[64] USB_DEVBSS_ATTR __attribute__((aligned(32))); 666 599 int length; 667 600 668 - if ((req->wValue >> 8) != REPORT_TYPE_OUTPUT) 601 + if ((req->wValue >> 8) != USB_HID_REPORT_TYPE_OUTPUT) 669 602 { 670 603 logf("Unsupported report type"); 671 604 return 1; ··· 714 647 715 648 static int usb_hid_get_report(struct usb_ctrlrequest *req, unsigned char* dest) 716 649 { 717 - if ((req->wValue >> 8) != REPORT_TYPE_FEATURE) 650 + if ((req->wValue >> 8) != USB_HID_REPORT_TYPE_FEATURE) 718 651 { 719 652 logf("Unsupported report type"); 720 653 return 1;
+92
firmware/usbstack/usb_hid_def.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id: $ 9 + * 10 + * Copyright (C) 2010 by Amaury Pouly 11 + * 12 + * All files in this archive are subject to the GNU General Public License. 13 + * See the file COPYING in the source tree root for full license agreement. 14 + * 15 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 16 + * KIND, either express or implied. 17 + * 18 + ****************************************************************************/ 19 + 20 + #ifndef USB_HID_DEF_H 21 + #define USB_HID_DEF_H 22 + 23 + #include "usb_ch9.h" 24 + 25 + /* Documents avaiable here: http://www.usb.org/developers/devclass_docs/ */ 26 + 27 + #define USB_HID_VER 0x0110 /* 1.1 */ 28 + /* Subclass Codes (HID1_11.pdf, page 18) */ 29 + #define USB_HID_SUBCLASS_NONE 0 30 + #define USB_HID_SUBCLASS_BOOT_INTERFACE 1 31 + /* Protocol Codes (HID1_11.pdf, page 19) */ 32 + #define USB_HID_PROTOCOL_CODE_NONE 0 33 + #define USB_HID_PROTOCOL_CODE_KEYBOARD 1 34 + #define USB_HID_PROTOCOL_CODE_MOUSE 2 35 + /* HID main items (HID1_11.pdf, page 38) */ 36 + #define USB_HID_INPUT 0x80 37 + #define USB_HID_OUTPUT 0x90 38 + #define USB_HID_FEATURE 0xB0 39 + #define USB_HID_COLLECTION 0xA0 40 + #define USB_HID_COLLECTION_PHYSICAL 0x00 41 + #define USB_HID_COLLECTION_APPLICATION 0x01 42 + #define USB_HID_END_COLLECTION 0xC0 43 + /* Parts (HID1_11.pdf, page 40) */ 44 + #define USB_HID_MAIN_ITEM_CONSTANT BIT_N(0) /* 0x01 */ 45 + #define USB_HID_MAIN_ITEM_VARIABLE BIT_N(1) /* 0x02 */ 46 + #define USB_HID_MAIN_ITEM_RELATIVE BIT_N(2) /* 0x04 */ 47 + #define USB_HID_MAIN_ITEM_WRAP BIT_N(3) /* 0x08 */ 48 + #define USB_HID_MAIN_ITEM_NONLINEAR BIT_N(4) /* 0x10 */ 49 + #define USB_HID_MAIN_ITEM_NO_PREFERRED BIT_N(5) /* 0x20 */ 50 + #define USB_HID_MAIN_ITEM_NULL_STATE BIT_N(6) /* 0x40 */ 51 + #define USB_HID_MAIN_ITEM_VOLATILE BIT_N(7) /* 0x80 */ 52 + #define USB_HID_MAIN_ITEM_BUFFERED_BYTES BIT_N(8) /* 0x0100 */ 53 + /* HID global items (HID1_11.pdf, page 45) */ 54 + #define USB_HID_USAGE_PAGE 0x04 55 + #define USB_HID_LOGICAL_MINIMUM 0x14 56 + #define USB_HID_LOGICAL_MAXIMUM 0x24 57 + #define USB_HID_REPORT_SIZE 0x74 58 + #define USB_HID_REPORT_ID 0x84 59 + #define USB_HID_REPORT_COUNT 0x94 60 + /* HID local items (HID1_11.pdf, page 50) */ 61 + #define USB_HID_USAGE_MINIMUM 0x18 62 + #define USB_HID_USAGE_MAXIMUM 0x28 63 + /* Types of class descriptors (HID1_11.pdf, page 59) */ 64 + #define USB_DT_HID 0x21 65 + #define USB_DT_REPORT 0x22 66 + 67 + #define USB_HID_CONSUMER_USAGE 0x09 68 + 69 + /* HID-only class specific requests (HID1_11.pdf, page 61) */ 70 + #define USB_HID_GET_REPORT 0x01 71 + #define USB_HID_GET_IDLE 0x02 72 + #define USB_HID_GET_PROTOCOL 0x03 73 + #define USB_HID_SET_REPORT 0x09 74 + #define USB_HID_SET_IDLE 0x0A 75 + #define USB_HID_SET_PROTOCOL 0x0B 76 + 77 + /* Get_Report and Set_Report Report Type field (HID1_11.pdf, page 61) */ 78 + #define USB_HID_REPORT_TYPE_INPUT 0x01 79 + #define USB_HID_REPORT_TYPE_OUTPUT 0x02 80 + #define USB_HID_REPORT_TYPE_FEATURE 0x03 81 + 82 + struct usb_hid_descriptor { 83 + uint8_t bLength; 84 + uint8_t bDescriptorType; 85 + uint16_t wBcdHID; 86 + uint8_t bCountryCode; 87 + uint8_t bNumDescriptors; 88 + uint8_t bDescriptorType0; 89 + uint16_t wDescriptorLength0; 90 + } __attribute__ ((packed)); 91 + 92 + #endif