USBDescriptors.h
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------- */
2 /* Atmel Microcontroller Software Support */
3 /* SAM Software Package License */
4 /* ---------------------------------------------------------------------------- */
5 /* Copyright (c) 2015, Atmel Corporation */
6 /* */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without */
10 /* modification, are permitted provided that the following condition is met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, */
13 /* this list of conditions and the disclaimer below. */
14 /* */
15 /* Atmel's name may not be used to endorse or promote products derived from */
16 /* this software without specific prior written permission. */
17 /* */
18 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 /* ---------------------------------------------------------------------------- */
29 
40 #ifndef _USBDESCRIPTORS_H_
41 #define _USBDESCRIPTORS_H_
42 
48 /*---------------------------------------------------------------------------
49  * Headers
50  *---------------------------------------------------------------------------*/
51 
52 /* These headers were introduced in C99 by working group
53  * ISO/IEC JTC1/SC22/WG14.
54  */
55 #include <stdint.h>
56 
57 /*---------------------------------------------------------------------------
58  * Definitions
59  *---------------------------------------------------------------------------*/
60 
61 /*--------- Generic Descriptors --------*/
62 
79 #define USBGenericDescriptor_DEVICE 1
80 
81 #define USBGenericDescriptor_CONFIGURATION 2
82 
83 #define USBGenericDescriptor_STRING 3
84 
85 #define USBGenericDescriptor_INTERFACE 4
86 
87 #define USBGenericDescriptor_ENDPOINT 5
88 
89 #define USBGenericDescriptor_DEVICEQUALIFIER 6
90 
91 #define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7
92 
93 #define USBGenericDescriptor_INTERFACEPOWER 8
94 
95 #define USBGenericDescriptor_OTG 9
96 
97 #define USBGenericDescriptor_DEBUG 10
98 
99 #define USBGenericDescriptor_INTERFACEASSOCIATION 11
100 
101 #define USB_DT_BOS 0x0F
102 
103 #define USBGenericDescriptor_DEVICE_CAPABILITY 0x10
104 
108 #define USB_EP_TYPE_MASK 0x03
109 #define USB_EP_ADDR_MASK 0x0f
110 
113 #define USB_EP_DIR_IN 0x80
114 
118 #define USB_EP_DIR_OUT 0x00
119 
123 #define USB_REQ_DIR_OUT (0<<7)
124 #define USB_REQ_DIR_IN (1<<7)
125 #define USB_REQ_DIR_MASK (1<<7)
126 
127 
130 #define USB_REQ_TYPE_STANDARD (0<<5)
131 #define USB_REQ_TYPE_CLASS (1<<5)
132 #define USB_REQ_TYPE_VENDOR (2<<5)
133 #define USB_REQ_TYPE_MASK (3<<5)
134 
135 
138 #define USB_REQ_RECIP_DEVICE (0<<0)
139 #define USB_REQ_RECIP_INTERFACE (1<<0)
140 #define USB_REQ_RECIP_ENDPOINT (2<<0)
141 #define USB_REQ_RECIP_OTHER (3<<0)
142 #define USB_REQ_RECIP_MASK (0x1F)
143 
144 
147 enum usb_reqid {
159 };
160 
166 };
167 
173  USB_DC_EXT_LPM = 0x00000002,
174  USB_DC_EXT_BESL = 0x00000004,
177 };
178 #define USB_DC_EXT_BESL_DEEP_OFFSET 8
179 #define USB_DC_EXT_BESL_DEEP(besl) ((besl & 0xF) << USB_DC_EXT_BESL_DEEP_OFFSET)
180 #define USB_DC_EXT_BESL_BASELINE_OFFSET 12
181 #define USB_DC_EXT_BESL_BASELINE(besl) ((besl & 0xF) << USB_DC_EXT_BESL_BASELINE_OFFSET)
182 
183 #define BESL_125_US 0
184 #define BESL_150_US 1
185 #define BESL_200_US 2
186 #define BESL_300_US 3
187 #define BESL_400_US 4
188 #define BESL_500_US 5
189 #define BESL_1000_US 6
190 #define BESL_2000_US 7
191 #define BESL_3000_US 8
192 #define BESL_4000_US 9
193 #define BESL_5000_US 10
194 #define BESL_6000_US 11
195 #define BESL_7000_US 12
196 #define BESL_8000_US 13
197 #define BESL_9000_US 14
198 #define BESL_10000_US 15
199 
201 #define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0)
202 #define USB_LPM_ATTRIBUT_BESL_MASK (0xF << 4)
203 #define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8)
204 #define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0)
205 #define USB_LPM_ATTRIBUT_BESL(value) ((value & 0xF) << 4)
206 #define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8)
207 #define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1)
208 
209 
210 /******** END usb protocol */
211 /*--------- Device Descriptors --------*/
212 
220 #define USBDeviceDescriptor_USB2_00 0x0200
221 
223 #define USBDeviceDescriptor_USB2_01 0x0201
224 
227 /*--------- Configuration Descriptors --------*/
228 
239 #define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80
240 
241 #define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0
242 
243 #define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0
244 
245 #define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0
246 
247 #define USBConfigurationDescriptor_REMOTE_WAKEUP 0x20
248 
253 #define USBConfigurationDescriptor_POWER(power) (power / 2)
254 
255 #define USB_HOST_POWER_MAX 500
256 
264 };
265 
272 };
273 
279 };
280 
292 };
293 
294 /*--------- Endpoint Descriptors --------*/
295 
330 #define USBEndpointDescriptor_OUT 0
331 
332 #define USBEndpointDescriptor_IN 1
333 
337 #define USB_EP_DIR_IN 0x80
338 
342 #define USB_EP_DIR_OUT 0x00
343 
354 #define USBEndpointDescriptor_CONTROL 0
355 
356 #define USBEndpointDescriptor_ISOCHRONOUS 1
357 
358 #define USBEndpointDescriptor_BULK 2
359 
360 #define USBEndpointDescriptor_INTERRUPT 3
361 
362 
364 #define USBEndpointDescriptor_Asynchronous_ISOCHRONOUS (1<<2)
365 #define USBEndpointDescriptor_Adaptive_ISOCHRONOUS (2<<2)
366 #define USBEndpointDescriptor_Synchronous_ISOCHRONOUS (3<<2)
367 
369 #define USBEndpointDescriptor_Feedback_ISOCHRONOUS (1<<2)
370 #define USBEndpointDescriptor_Explicit_Feedback_ISOCHRONOUS (2<<2)
371 
386 #define USBEndpointDescriptor_MAXCTRLSIZE_FS 64
387 
388 #define USBEndpointDescriptor_MAXCTRLSIZE_HS 64
389 
390 #define USBEndpointDescriptor_MAXBULKSIZE_FS 64
391 
392 #define USBEndpointDescriptor_MAXBULKSIZE_HS 512
393 
394 #define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64
395 
396 #define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024
397 
398 #define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023
399 
400 #define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024
401 
415 #define USBEndpointDescriptor_ADDRESS(direction, number) \
416  (((direction & 0x01) << 7) | (number & 0xF))
417 
421 /*--------- Generic Descriptors --------*/
422 
437 #define USBStringDescriptor_ENGLISH_US 0x09, 0x04
438 
444 #define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2)
445 
450 #define USBStringDescriptor_UNICODE(ascii) (ascii), 0
451 
454 /*---------------------------------------------------------------------------
455  * Types
456  *---------------------------------------------------------------------------*/
457 
458 /*
459  * Function types
460  */
461 
462 typedef uint32_t (*USBDescriptorParseFunction)(void *descriptor, void *parseArg);
465 /*
466  * Descriptor structs types
467  */
468 #pragma pack(1)
469 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */
470 #elif defined ( __ICCARM__ ) /* IAR Ewarm */
471 #define __attribute__(...)
472 #define __packed__ packed
473 #elif defined ( __GNUC__ ) /* GCC CS3 */
474 #define __packed__ aligned(1)
475 #endif
480 typedef struct _USBGenericDescriptor {
483  uint8_t bLength;
486 
487 } __attribute__ ((__packed__)) USBGenericDescriptor; /* GCC */
488 
493 typedef struct _USBDeviceDescriptor {
494 
496  uint8_t bLength;
500  uint16_t bcdUSB;
502  uint8_t bDeviceClass;
510  uint16_t idVendor;
512  uint16_t idProduct;
514  uint16_t bcdDevice;
516  uint8_t iManufacturer;
518  uint8_t iProduct;
520  uint8_t iSerialNumber;
523 
524 } __attribute__ ((__packed__)) USBDeviceDescriptor; /* GCC */
525 
530 typedef struct _USBOtgDescriptor {
531 
533  uint8_t bLength;
537  uint8_t bmAttributes;
538 
539 } __attribute__ ((__packed__)) USBOtgDescriptor; /* GCC */
540 
549 
551  uint8_t bLength;
555  uint16_t bcdUSB;
557  uint8_t bDeviceClass;
567  uint8_t bReserved;
568 
569 } __attribute__ ((__packed__)) USBDeviceQualifierDescriptor; /* GCC */
570 
576 
578  uint8_t bLength;
584  uint16_t wTotalLength;
586  uint8_t bNumInterfaces;
590  uint8_t iConfiguration;
592  uint8_t bmAttributes;
594  uint8_t bMaxPower;
595 
596 } __attribute__ ((__packed__)) USBConfigurationDescriptor; /* GCC*/
597 
611 typedef struct _USBDeviceBOSDescriptor{
612  uint8_t bLength;
614  uint16_t wTotalLength;
615  uint8_t bNumDeviceCaps;
616 } __attribute__ ((__packed__)) USBDeviceBOSDescriptor;
617 
618 
625 typedef struct _USBDeviceCapabilities{
626  uint8_t bLength;
629  uint32_t bmAttributes;
630 } __attribute__ ((__packed__)) USBDeviceCapabilities;
631 
638  USBDeviceBOSDescriptor bos;
639  USBDeviceCapabilities capa_ext;
640 }__attribute__ ((__packed__)) USB_DeviceLPMDescriptor;
641 
647 
649  uint8_t bLength;
657  uint8_t bFunctionClass;
663  uint8_t iFunction;
664 } __attribute__ ((__packed__)) USBInterfaceAssociationDescriptor; /* GCC*/
665 
670 typedef struct _USBInterfaceDescriptor {
671 
673  uint8_t bLength;
681  uint8_t bNumEndpoints;
689  uint8_t iInterface;
690 
691 } __attribute__ ((__packed__)) USBInterfaceDescriptor; /* GCC */
692 
697 typedef struct _USBEndpointDescriptor {
698 
700  uint8_t bLength;
707  uint8_t bmAttributes;
709  uint16_t wMaxPacketSize;
711  uint8_t bInterval;
712 
713 } __attribute__ ((__packed__)) USBEndpointDescriptor; /* GCC*/
714 
715 
719 typedef struct {
720  uint8_t bLength;
722 }__attribute__ ((__packed__)) USBStringDescriptor;
723 
724 typedef struct {
725  USBStringDescriptor desc;
726  uint16_t string[1];
727 } __attribute__ ((__packed__))USBStringLangIdDescriptor;
728 
729 
730 #pragma pack()
731 
732 /*---------------------------------------------------------------------------
733  * Exported Functions
734  *---------------------------------------------------------------------------*/
735 
736 extern uint32_t USBGenericDescriptor_GetLength(
737  const USBGenericDescriptor *descriptor);
738 
739 extern uint8_t USBGenericDescriptor_GetType(
740  const USBGenericDescriptor *descriptor);
741 
742 extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor(
743  const USBGenericDescriptor *descriptor);
744 
745 extern USBGenericDescriptor *USBGenericDescriptor_Parse(
746  const USBGenericDescriptor * descriptor,
747  uint32_t totalLength,
748  USBDescriptorParseFunction parseFunction,
749  void * parseArg);
750 
751 
753  const USBConfigurationDescriptor *configuration);
754 
756  const USBConfigurationDescriptor *configuration);
757 
759  const USBConfigurationDescriptor *configuration);
760 
762  const USBConfigurationDescriptor *configuration,
763  USBInterfaceDescriptor **interfaces,
764  USBEndpointDescriptor **endpoints,
765  USBGenericDescriptor **others);
766 
767 extern uint8_t USBEndpointDescriptor_GetNumber(
768  const USBEndpointDescriptor *endpoint);
769 
771  const USBEndpointDescriptor *endpoint);
772 
773 extern uint8_t USBEndpointDescriptor_GetType(
774  const USBEndpointDescriptor *endpoint);
775 
777  const USBEndpointDescriptor *endpoint);
778 
779 extern uint8_t USBEndpointDescriptor_GetInterval(
780  const USBEndpointDescriptor *endpoint);
781 
782 
785 #endif /* #ifndef _USBDESCRIPTORS_H_ */
786 
usb_interface_status
Standard USB Interface status flags.
Definition: usb_protocol.h:130
usb_endpoint_feature
Standard USB endpoint feature/status flags.
Definition: usb_protocol.h:171
USBStringDescriptor desc
uint8_t USBGenericDescriptor_GetType(const USBGenericDescriptor *descriptor)
usb_device_feature
Standard USB device feature flags.
Definition: usb_protocol.h:147
void USBConfigurationDescriptor_Parse(const USBConfigurationDescriptor *configuration, USBInterfaceDescriptor **interfaces, USBEndpointDescriptor **endpoints, USBGenericDescriptor **others)
usb_capability_extension_attr
USB Device Capability - USB 2.0 Extension To fill bmAttributes field of usb_capa_ext_desc_t structure...
Definition: usb_protocol.h:215
static Endpoint endpoints[CHIP_USB_NUMENDPOINTS]
Definition: USBD_HAL.c:207
unsigned char USBConfigurationDescriptor_GetNumInterfaces(const USBConfigurationDescriptor *configuration)
usb_reqid
Standard USB requests (bRequest)
Definition: usb_protocol.h:102
uint32_t USBGenericDescriptor_GetLength(const USBGenericDescriptor *descriptor)
uint8_t USBEndpointDescriptor_GetNumber(const USBEndpointDescriptor *endpoint)
uint16_t USBEndpointDescriptor_GetMaxPacketSize(const USBEndpointDescriptor *endpoint)
uint8_t USBEndpointDescriptor_GetType(const USBEndpointDescriptor *endpoint)
uint8_t bDescriptorType
uint32_t(* USBDescriptorParseFunction)(void *descriptor, void *parseArg)
typedef __attribute__
USB Device LPM Descriptor structure.
Definition: d_usartDMA.c:1064
USBConfigurationDescriptor configuration
unsigned char USBConfigurationDescriptor_IsSelfPowered(const USBConfigurationDescriptor *configuration)
USBGenericDescriptor * USBGenericDescriptor_GetNextDescriptor(const USBGenericDescriptor *descriptor)
USB Device LPM Descriptor structure.
usb_endpoint_status
Standard USB endpoint status flags.
Definition: usb_protocol.h:138
Remote wakeup enabled.
USBDeviceCapabilities capa_ext
USBDeviceBOSDescriptor bos
uint8_t USBEndpointDescriptor_GetDirection(const USBEndpointDescriptor *endpoint)
uint32_t USBConfigurationDescriptor_GetTotalLength(const USBConfigurationDescriptor *configuration)
usb_capability_type
USB Device Capability types.
Definition: usb_protocol.h:207
USBGenericDescriptor * USBGenericDescriptor_Parse(const USBGenericDescriptor *descriptor, uint32_t totalLength, USBDescriptorParseFunction parseFunction, void *parseArg)
uint8_t USBEndpointDescriptor_GetInterval(const USBEndpointDescriptor *endpoint)


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58