initial commit
[armstart-ibdap] / src / usb_desc.c
1 /*
2  * usb_desc.c
3  *
4  *  Created on: Jun 18, 2015
5  *      Author: yliu
6  */
7
8 #include "compiler.h"
9 #include "app_usbd_cfg.h"
10 #include "DAP_config.h"
11
12 ALIGNED(4) const uint8_t HID_ReportDescriptor[] = {
13         HID_UsagePageVendor(0x00),
14         HID_Usage(0x01),
15         HID_Collection(HID_Application),
16         HID_LogicalMin(0),      /* value range: 0 - 0xFF */
17         HID_LogicalMaxS(0xFF),
18         HID_ReportSize(8),      /* 8 bits */
19         HID_ReportCount(DAP_PACKET_SIZE),
20         HID_Usage(0x01),
21         HID_Input(HID_Data | HID_Variable | HID_Absolute),
22         HID_ReportCount(DAP_PACKET_SIZE),
23         HID_Usage(0x01),
24         HID_Output(HID_Data | HID_Variable | HID_Absolute),
25         HID_ReportCount(1),
26         HID_Usage(0x01),
27         HID_Feature(HID_Data | HID_Variable | HID_Absolute),
28         HID_EndCollection,
29 };
30
31 const uint8_t hid_report_size = sizeof (HID_ReportDescriptor);
32
33
34 /**
35  * USB Standard Device Descriptor
36  */
37 ALIGNED(4) const uint8_t USB_DeviceDescriptor[] = {
38         USB_DEVICE_DESC_SIZE,                   /* bLength */
39         USB_DEVICE_DESCRIPTOR_TYPE,             /* bDescriptorType */
40         WBVAL(0x0200),                                  /* bcdUSB 2.0 */
41         0x00,                                                   /* bDeviceClass */
42         0x00,                                                   /* bDeviceSubClass */
43         0x00,                                                   /* bDeviceProtocol */
44         USB_MAX_PACKET0,                                /* bMaxPacketSize0 */
45         WBVAL(0x1FC9),                                  /* idVendor */
46         WBVAL(0x0081),                                  /* idProduct */
47         WBVAL(0x0100),                                  /* bcdDevice */
48         0x01,                                                   /* iManufacturer */
49         0x02,                                                   /* iProduct */
50         0x03,                                                   /* iSerialNumber */
51         0x01                                                    /* bNumConfigurations */
52 };
53
54 /**
55  * USB FSConfiguration Descriptor
56  * All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
57  */
58 ALIGNED(4) uint8_t USB_FsConfigDescriptor[] = {
59         /* Configuration 1 */
60         USB_CONFIGURATION_DESC_SIZE,                    /* bLength */
61         USB_CONFIGURATION_DESCRIPTOR_TYPE,              /* bDescriptorType */
62         WBVAL(                                                                  /* wTotalLength */
63                 USB_CONFIGURATION_DESC_SIZE   +
64                 USB_INTERFACE_DESC_SIZE       +
65                 HID_DESC_SIZE                 +
66                 USB_ENDPOINT_DESC_SIZE        +
67                 USB_ENDPOINT_DESC_SIZE
68                 ),
69         0x01,                                                   /* bNumInterfaces */
70         0x01,                                                   /* bConfigurationValue */
71         0x00,                                                   /* iConfiguration */
72         USB_CONFIG_SELF_POWERED,                /* bmAttributes */
73         USB_CONFIG_POWER_MA(100),               /* bMaxPower */
74
75         /* Interface 0, Alternate Setting 0, HID Class */
76         USB_INTERFACE_DESC_SIZE,                /* bLength */
77         USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType */
78         0x00,                                                   /* bInterfaceNumber */
79         0x00,                                                   /* bAlternateSetting */
80         0x02,                                                   /* bNumEndpoints */
81         USB_DEVICE_CLASS_HUMAN_INTERFACE,       /* bInterfaceClass */
82         HID_SUBCLASS_NONE,                              /* bInterfaceSubClass */
83         HID_PROTOCOL_NONE,                              /* bInterfaceProtocol */
84         0x04,                                                   /* iInterface */
85         /* HID Class Descriptor */
86         /* HID_DESC_OFFSET = 0x0012 */
87         HID_DESC_SIZE,                                  /* bLength */
88         HID_HID_DESCRIPTOR_TYPE,                /* bDescriptorType */
89         WBVAL(0x0111),                                  /* bcdHID : 1.11*/
90         0x00,                                                   /* bCountryCode */
91         0x01,                                                   /* bNumDescriptors */
92         HID_REPORT_DESCRIPTOR_TYPE,             /* bDescriptorType */
93         WBVAL(sizeof(HID_ReportDescriptor)),    /* wDescriptorLength */
94         /* Endpoint, HID Interrupt In */
95         USB_ENDPOINT_DESC_SIZE,                 /* bLength */
96         USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType */
97         HID_EP_IN,                                              /* bEndpointAddress */
98         USB_ENDPOINT_TYPE_INTERRUPT,    /* bmAttributes */
99         WBVAL(64),                                      /* wMaxPacketSize */
100         0x01,           /* 1ms */           /* bInterval */
101         /* Endpoint, HID Interrupt Out */
102         USB_ENDPOINT_DESC_SIZE,                 /* bLength */
103         USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType */
104         HID_EP_OUT,                                             /* bEndpointAddress */
105         USB_ENDPOINT_TYPE_INTERRUPT,    /* bmAttributes */
106         WBVAL(64),                                      /* wMaxPacketSize */
107         0x01,                                                   /* bInterval: 1ms */
108         /* Terminator */
109         0                                                               /* bLength */
110 };
111
112 /**
113  * USB String Descriptor (optional)
114  */
115 const uint8_t USB_StringDescriptor[] = {
116         /* Index 0x00: LANGID Codes */
117         0x04,                                                   /* bLength */
118         USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType */
119         WBVAL(0x0409),                                  /* wLANGID : US English*/
120         /* Index 0x01: Manufacturer */
121         (8 * 2 + 2),                                    /* bLength (8 Char + Type + lenght) */
122         USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType */
123         'A', 0,
124         'R', 0,
125         'M', 0,
126         'S', 0,
127         'T', 0,
128         'A', 0,
129         'R', 0,
130         'T', 0,
131         /* Index 0x02: Product */
132         (24 * 2 + 2),                                   /* bLength (24 Char + Type + lenght) */
133         USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType */
134         'I', 0,
135         'B', 0,
136         'D', 0,
137         'A', 0,
138         'P', 0,
139         '-', 0,
140         'L', 0,
141         'P', 0,
142         'C', 0,
143         '1', 0,
144         '1', 0,
145         'U', 0,
146         '3', 0,
147         '5', 0,
148         ' ', 0,
149         'C', 0,
150         'M', 0,
151         'S', 0,
152         'I', 0,
153         'S', 0,
154         '-', 0,
155         'D', 0,
156         'A', 0,
157         'P', 0,
158         /* Index 0x03: Serial Number */
159         (11 * 2 + 2),                                   /* bLength (13 Char + Type + lenght) */
160         USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType */
161         'I', 0,
162         'B', 0,
163         'D', 0,
164         'A', 0,
165         'P', 0,
166         '2', 0,
167         '0', 0,
168         '1', 0,
169         '5', 0,
170         '0', 0,
171         '7', 0,
172         /* Index 0x04: Interface 0, Alternate Setting 0 */
173         (3 * 2 + 2),                                    /* bLength (3 Char + Type + lenght) */
174         USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType */
175         'H', 0,
176         'I', 0,
177         'D', 0,
178 };