Advertisement
blackswords

HID descriptor

Oct 9th, 2012
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.58 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * @file    usb_desc.c
  4.   * @author  MCD Application Team
  5.   * @version V3.4.0
  6.   * @date    29-June-2012
  7.   * @brief   Descriptors for Custom HID Demo
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  12.   *
  13.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14.   * You may not use this file except in compliance with the License.
  15.   * You may obtain a copy of the License at:
  16.   *
  17.   *        http://www.st.com/software_license_agreement_liberty_v2
  18.   *
  19.   * Unless required by applicable law or agreed to in writing, software
  20.   * distributed under the License is distributed on an "AS IS" BASIS,
  21.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22.   * See the License for the specific language governing permissions and
  23.   * limitations under the License.
  24.   *
  25.   ******************************************************************************
  26.   */
  27.  
  28.  
  29. /* Includes ------------------------------------------------------------------*/
  30. #include "usb_lib.h"
  31. #include "usb_desc.h"
  32.  
  33. /* Private typedef -----------------------------------------------------------*/
  34. /* Private define ------------------------------------------------------------*/
  35. /* Private macro -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Extern variables ----------------------------------------------------------*/
  38. /* Private function prototypes -----------------------------------------------*/
  39. /* Private functions ---------------------------------------------------------*/
  40.  
  41. /* USB Standard Device Descriptor */
  42. const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =
  43.   {
  44.     0x12,                       /*bLength */
  45.     USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
  46.     0x00,                       /*bcdUSB */
  47.     0x02,
  48.     0x00,                       /*bDeviceClass*/
  49.     0x00,                       /*bDeviceSubClass*/
  50.     0x00,                       /*bDeviceProtocol*/
  51.     0x40,                       /*bMaxPacketSize40*/
  52.     0x83,                       /*idVendor (0x0483)*/
  53.     0x04,
  54.     0x50,                       /*idProduct = 0x5750*/
  55.     0x57,
  56.     0x00,                       /*bcdDevice rel. 2.00*/
  57.     0x02,
  58.     1,                          /*Index of string descriptor describing
  59.                                               manufacturer */
  60.     2,                          /*Index of string descriptor describing
  61.                                              product*/
  62.     3,                          /*Index of string descriptor describing the
  63.                                              device serial number */
  64.     0x01                        /*bNumConfigurations*/
  65.   }
  66.   ; /* CustomHID_DeviceDescriptor */
  67.  
  68.  
  69. /* USB Configuration Descriptor */
  70. /*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
  71. const uint8_t CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
  72.   {
  73.     0x09, /* bLength: Configuration Descriptor size */
  74.     USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
  75.     CUSTOMHID_SIZ_CONFIG_DESC,
  76.     /* wTotalLength: Bytes returned */
  77.     0x00,
  78.     0x01,         /* bNumInterfaces: 1 interface */
  79.     0x01,         /* bConfigurationValue: Configuration value */
  80.     0x00,         /* iConfiguration: Index of string descriptor describing
  81.                                  the configuration*/
  82.     0xC0,         /* bmAttributes: Bus powered */
  83.     0x32,         /* MaxPower 100 mA: this current is used for detecting Vbus */
  84.  
  85.     /************** Descriptor of Custom HID interface ****************/
  86.     /* 09 */
  87.     0x09,         /* bLength: Interface Descriptor size */
  88.     USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
  89.     0x00,         /* bInterfaceNumber: Number of Interface */
  90.     0x00,         /* bAlternateSetting: Alternate setting */
  91.     0x02,         /* bNumEndpoints */
  92.     0x03,         /* bInterfaceClass: HID */
  93.     0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
  94.     0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
  95.     0,            /* iInterface: Index of string descriptor */
  96.     /******************** Descriptor of Custom HID HID ********************/
  97.     /* 18 */
  98.     0x09,         /* bLength: HID Descriptor size */
  99.     HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
  100.     0x10,         /* bcdHID: HID Class Spec release number */
  101.     0x01,
  102.     0x00,         /* bCountryCode: Hardware target country */
  103.     0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
  104.     0x22,         /* bDescriptorType */
  105.     CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
  106.     0x00,
  107.     /******************** Descriptor of Custom HID endpoints ******************/
  108.     /* 27 */
  109.     0x07,          /* bLength: Endpoint Descriptor size */
  110.     USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
  111.  
  112.     0x81,          /* bEndpointAddress: Endpoint Address (IN) */
  113.     0x03,          /* bmAttributes: Interrupt endpoint */
  114.     0x08,          /* wMaxPacketSize: 8 Bytes max */
  115.     0x00,
  116.     0x01,          /* bInterval: Polling Interval (32 ms) */
  117.     /* 34 */
  118.  
  119.     0x07,   /* bLength: Endpoint Descriptor size */
  120.     USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: */
  121.             /*  Endpoint descriptor type */
  122.     0x01,   /* bEndpointAddress: */
  123.             /*  Endpoint Address (OUT) */
  124.     0x03,   /* bmAttributes: Interrupt endpoint */
  125.     0x08,   /* wMaxPacketSize: 8 Bytes max  */
  126.     0x00,
  127.     0x01,   /* bInterval: Polling Interval (32 ms) */
  128.     /* 41 */
  129.   }
  130.   ; /* CustomHID_ConfigDescriptor */
  131. const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
  132.   {
  133.     0x06, 0xFF, 0x00,      /* USAGE_PAGE (Vendor Page: 0xFF00) */
  134.     0x09, 0x01,            /* USAGE (Demo Kit)               */
  135.     0xa1, 0x01,            /* COLLECTION (Application)       */
  136.     /* 7 */
  137.  
  138.     /* COMMAND */
  139.     0x85, 0x01,            /*     REPORT_ID (1)              */
  140.     0x09, 0x01,            /*     USAGE (COMMAND)            */
  141.     0x15, 0x00,            /*     LOGICAL_MINIMUM (0)        */
  142.     0x25, 0xFF,            /*     LOGICAL_MAXIMUM (255)      */
  143.     0x75, 0x08,            /*     REPORT_SIZE (8)            */
  144.     0x95, 0x08,            /*     REPORT_COUNT (8)           */
  145.     0xB1, 0x82,            /*     FEATURE (Data,Var,Abs,Vol) */
  146.     0x85, 0x01,            /*     REPORT_ID (1)              */
  147.     0x09, 0x01,            /*     USAGE (COMMAND)            */
  148.     0x91, 0x82,            /*     OUTPUT (Data,Var,Abs,Vol)  */
  149.     /* 27 */
  150.  
  151.     /* ADC */
  152.     0x85, 0x07,            /*     REPORT_ID (7)              */
  153.     0x09, 0x07,            /*     USAGE (ADC)                */
  154.     0x15, 0x00,            /*     LOGICAL_MINIMUM (0)        */
  155.     0x26, 0xff, 0x00,      /*     LOGICAL_MAXIMUM (255)      */
  156.     0x75, 0x08,            /*     REPORT_SIZE (8)            */
  157.     0x95, 0x08,            /*     REPORT_COUNT (8)           */
  158.     0x81, 0x82,            /*     INPUT (Data,Var,Abs,Vol)   */
  159.     0x85, 0x07,            /*     REPORT_ID (7)              */
  160.     0x09, 0x07,            /*     USAGE (ADC)                */
  161.     0xb1, 0x82,            /*     FEATURE (Data,Var,Abs,Vol) */
  162.     /* 48 */
  163.  
  164.     0xc0              /*     END_COLLECTION              */
  165.   }; /* CustomHID_ReportDescriptor */
  166.  
  167. /* USB String Descriptors (optional) */
  168. const uint8_t CustomHID_StringLangID[CUSTOMHID_SIZ_STRING_LANGID] =
  169.   {
  170.     CUSTOMHID_SIZ_STRING_LANGID,
  171.     USB_STRING_DESCRIPTOR_TYPE,
  172.     0x09,
  173.     0x04
  174.   }
  175.   ; /* LangID = 0x0409: U.S. English */
  176.  
  177. const uint8_t CustomHID_StringVendor[CUSTOMHID_SIZ_STRING_VENDOR] =
  178.   {
  179.     CUSTOMHID_SIZ_STRING_VENDOR, /* Size of Vendor string */
  180.     USB_STRING_DESCRIPTOR_TYPE,  /* bDescriptorType*/
  181.     /* Manufacturer: "STMicroelectronics" */
  182.     'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0,
  183.     'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0,
  184.     'c', 0, 's', 0
  185.   };
  186.  
  187. const uint8_t CustomHID_StringProduct[CUSTOMHID_SIZ_STRING_PRODUCT] =
  188.   {
  189.     CUSTOMHID_SIZ_STRING_PRODUCT,          /* bLength */
  190.     USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  191.     'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'C', 0,
  192.     'u', 0, 's', 0, 't', 0, 'o', 0, 'm', 0, ' ', 0, 'H', 0,
  193.     'I', 0, 'D', 0
  194.   };
  195. uint8_t CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL] =
  196.   {
  197.     CUSTOMHID_SIZ_STRING_SERIAL,           /* bLength */
  198.     USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
  199.     'S', 0, 'T', 0, 'M', 0,'3', 0,'2', 0, '1', 0, '0', 0
  200.   };
  201.  
  202. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement