Contiki-NG
Loading...
Searching...
No Matches
usb.h
1#ifndef USB_H_6PFTDPIMZM__
2#define USB_H_6PFTDPIMZM__
3#include <stdint.h>
4
5/* Adapted from usb_kbd_enum.h in c5131-usb-kbd-light-1_0_2 package from
6 Atmel */
7
8/* These definitions assume a little endian architecture */
9
10#ifdef __GNUC__
11#define BYTE_ALIGNED __attribute__ ((__packed__))
12#else
13#define BYTE_ALIGNED
14#endif
15
16#define LOW_BYTE(x) ((unsigned char)x)
17#define HIGH_BYTE(x) ((unsigned char)(x>>8))
18
19typedef uint8_t Uchar;
20typedef uint16_t Uint16;
21typedef uint32_t Uint32;
22
23/*_____ S T A N D A R D R E Q U E S T S __________________________________*/
24
25#define GET_STATUS 0x00
26#define GET_DEVICE 0x01
27#define CLEAR_FEATURE 0x01 /* see FEATURES below */
28#define GET_STRING 0x03
29#define SET_FEATURE 0x03 /* see FEATURES below */
30#define SET_ADDRESS 0x05
31#define GET_DESCRIPTOR 0x06
32#define SET_DESCRIPTOR 0x07
33#define GET_CONFIGURATION 0x08
34#define SET_CONFIGURATION 0x09
35#define GET_INTERFACE 0x0A
36#define SET_INTERFACE 0x0B
37#define SYNCH_FRAME 0x0C
38
39#define GET_DEVICE_DESCRIPTOR 1
40#define GET_CONFIGURATION_DESCRIPTOR 4
41
42#define REQUEST_DEVICE_STATUS 0x80
43#define REQUEST_INTERFACE_STATUS 0x81
44#define REQUEST_ENDPOINT_STATUS 0x82
45#define ZERO_TYPE 0x00
46#define INTERFACE_TYPE 0x01
47#define ENDPOINT_TYPE 0x02
48
49/*_____ D E S C R I P T O R T Y P E S ____________________________________*/
50
51#define DEVICE 0x01
52#define CONFIGURATION 0x02
53#define STRING 0x03
54#define INTERFACE 0x04
55#define ENDPOINT 0x05
56
57/* HID specific */
58#define HID 0x21
59#define REPORT 0x22
60/* *** */
61
62/*_____ S T A N D A R D F E A T U R E S __________________________________*/
63
64#define DEVICE_REMOTE_WAKEUP_FEATURE 0x01
65#define ENDPOINT_HALT_FEATURE 0x00
66
67/*_____ D E V I C E S T A T U S ___________________________________________*/
68
69#define SELF_POWERED 1
70
71/*_____ D E V I C E S T A T E _____________________________________________*/
72
73#define ATTACHED 0
74#define POWERED 1
75#define DEFAULT 2
76#define ADDRESSED 3
77#define CONFIGURED 4
78#define SUSPENDED 5
79
80#define USB_CONFIG_BUSPOWERED 0x80
81#define USB_CONFIG_SELFPOWERED 0x40
82#define USB_CONFIG_REMOTEWAKEUP 0x20
83
84/* Class specific */
85#define CS_INTERFACE 0x24
86#define CS_ENDPOINT 0x25
87
88/*_________________________________________________________ S T R U C T _____*/
89/*_____ U S B D E V I C E R E Q U E S T _________________________________*/
90
91struct USB_request_st
92{
93 Uchar bmRequestType; /* Characteristics of the request */
94 Uchar bRequest; /* Specific request */
95 Uint16 wValue;
96 Uint16 wIndex; /* field that varies according to request */
97 Uint16 wLength; /* Number of bytes to transfer if Data */
98};
99
100
101/*_____ U S B D E V I C E D E S C R I P T O R ___________________________*/
102
103struct usb_st_device_descriptor
104{
105 Uchar bLength; /* Size of this descriptor in bytes */
106 Uchar bDescriptorType; /* DEVICE descriptor type */
107 Uint16 bscUSB; /* Binay Coded Decimal Spec. release */
108 Uchar bDeviceClass; /* Class code assigned by the USB */
109 Uchar bDeviceSubClass; /* Sub-class code assigned by the USB */
110 Uchar bDeviceProtocol; /* Protocol code assigned by the USB */
111 Uchar bMaxPacketSize0; /* Max packet size for EP0 */
112 Uint16 idVendor; /* Vendor ID. ATMEL = 0x03EB */
113 Uint16 idProduct; /* Product ID assigned by the manufacturer */
114 Uint16 bcdDevice; /* Device release number */
115 Uchar iManufacturer; /* Index of manu. string descriptor */
116 Uchar iProduct; /* Index of prod. string descriptor */
117 Uchar iSerialNumber; /* Index of S.N. string descriptor */
118 Uchar bNumConfigurations; /* Number of possible configurations */
119} BYTE_ALIGNED;
120
121
122/*_____ U S B C O N F I G U R A T I O N D E S C R I P T O R _____________*/
123
124struct usb_st_configuration_descriptor
125{
126 Uchar bLength; /* size of this descriptor in bytes */
127 Uchar bDescriptorType; /* CONFIGURATION descriptor type */
128 Uint16 wTotalLength; /* total length of data returned */
129 Uchar bNumInterfaces; /* number of interfaces for this conf. */
130 Uchar bConfigurationValue; /* value for SetConfiguration resquest */
131 Uchar iConfiguration; /* index of string descriptor */
132 Uchar bmAttibutes; /* Configuration characteristics */
133 Uchar MaxPower; /* maximum power consumption */
134} BYTE_ALIGNED;
135
136
137/*_____ U S B I N T E R F A C E D E S C R I P T O R _____________________*/
138
139struct usb_st_interface_descriptor
140{
141 Uchar bLength; /* size of this descriptor in bytes */
142 Uchar bDescriptorType; /* INTERFACE descriptor type */
143 Uchar bInterfaceNumber; /* Number of interface */
144 Uchar bAlternateSetting; /* value to select alternate setting */
145 Uchar bNumEndpoints; /* Number of EP except EP 0 */
146 Uchar bInterfaceClass; /* Class code assigned by the USB */
147 Uchar bInterfaceSubClass; /* Sub-class code assigned by the USB */
148 Uchar bInterfaceProtocol; /* Protocol code assigned by the USB */
149 Uchar iInterface; /* Index of string descriptor */
150} BYTE_ALIGNED;
151
152
153/*_____ U S B E N D P O I N T D E S C R I P T O R _______________________*/
154
155struct usb_st_endpoint_descriptor
156{
157 Uchar bLength; /* Size of this descriptor in bytes */
158 Uchar bDescriptorType; /* ENDPOINT descriptor type */
159 Uchar bEndpointAddress; /* Address of the endpoint */
160 Uchar bmAttributes; /* Endpoint's attributes */
161 Uint16 wMaxPacketSize; /* Maximum packet size for this EP */
162 Uchar bInterval; /* Interval for polling EP in ms */
163/* Uchar bRefresh; */
164/* Uchar bSynchAddress; */
165} BYTE_ALIGNED;
166
167
168/*_____ U S B S T R I N G D E S C R I P T O R _______________*/
169
170struct usb_st_string_descriptor
171{
172 Uchar bLength; /* size of this descriptor in bytes */
173 Uchar bDescriptorType; /* STRING descriptor type */
174 Uint16 wstring[1];/* unicode characters */
175} BYTE_ALIGNED;
176
177
178struct usb_st_language_descriptor
179{
180 Uchar bLength; /* size of this descriptor in bytes */
181 Uchar bDescriptorType; /* STRING descriptor type */
182 Uint16 wlangid[1]; /* language id */
183} BYTE_ALIGNED;
184
185#endif /* USB_H_6PFTDPIMZM__ */