SeaBreeze
NativeUSB.h
Go to the documentation of this file.
1 /***************************************************/
37 #ifndef NATIVEUSB_H
38 #define NATIVEUSB_H
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif /* cplusplus */
43 
44 #define OPEN_OK 0
45 #define NO_DEVICE_FOUND -1
46 #define NO_DEVICE_MATCH -2
47 #define CLAIM_INTERFACE_FAILED -3
48 #define CLOSE_OK 0
49 #define CLOSE_ERROR -1
50 #define WRITE_FAILED -1
51 #define READ_FAILED -1
52 #define ABORT_OK 0
53 #define ABORT_FAILED -1
54 #define RESET_OK 0
55 #define RESET_FAILED -1
56 
58  unsigned char bLength;
59  unsigned char bDescriptorType;
60  unsigned short wTotalLength;
61  unsigned char bNumInterfaces;
62  unsigned char bConfigurationValue;
63  unsigned char iConfiguration;
64  unsigned char bmAttributes;
65  unsigned char MaxPower;
66 };
67 
69  unsigned char bLength;
70  unsigned char bDescriptorType;
71  unsigned short bcdUSB;
72  unsigned char bDeviceClass;
73  unsigned char bDeviceSubClass;
74  unsigned char bDeviceProtocol;
75  unsigned char bMaxPacketSize0;
76  unsigned short idVendor;
77  unsigned short idProduct;
78  unsigned short bcdDevice;
79  unsigned char iManufacturer;
80  unsigned char iProduct;
81  unsigned char iSerialNumber;
82  unsigned char bNumConfigurations;
83 };
84 
86  unsigned char bLength;
87  unsigned char bDescriptorType;
88  unsigned char bInterfaceNumber;
89  unsigned char bAlternateSetting;
90  unsigned char bNumEndpoints;
91  unsigned char bInterfaceClass;
92  unsigned char bInterfaceSubClass;
93  unsigned char bInterfaceProtocol;
94  unsigned char iInterface;
95 };
96 
98  unsigned char bLength;
99  unsigned char bDescriptorType;
100  unsigned char bEndpointAddress;
101  unsigned char bmAttributes;
102  unsigned short wMaxPacketSize;
103  unsigned char bInterval;
104 };
105 
106 //------------------------------------------------------------------------------
107 // This function attempts to discover all devices with the given product
108 // and vendor IDs. Descriptors for each found device will be placed in the
109 // provided long buffer.
110 //
111 // PARAMETERS:
112 // vendorID: The vendor ID to match with devices on the bus
113 // productID: The product ID to match with devices on the bus
114 // output: A buffer of longs that will be populated with unique IDs for each
115 // device found that matches the VID and PID
116 // max_devices: A limit on how many IDs can be put into the output buffer
117 //
118 // RETURN VALUE:
119 // The number of devices successfully found, or -1 if there was an error.
120 int
121 USBProbeDevices(int vendorID, int productID, unsigned long *output,
122  int max_devices);
123 
124 //------------------------------------------------------------------------------
125 // This function attempts to open a device with the given product and vendor
126 // ID's at the specified index.
127 //
128 // PARAMETERS:
129 // deviceID: The ID of a device that has been provided by probeDevices().
130 // errorCode: A pointer to an integer that will be set to an error code of
131 // either NO_DEVICE_FOUND or NO_DEVICE_MATCH if an error occured
132 // while trying to open the device or OPEN_OK if the device was
133 // found and opened.
134 //
135 // RETURN VALUE:
136 // Returns a void pointer which equals a handle to the device if the device was
137 // found and opened successfully, or NULL if the device was not opened
138 // successfully. The value of the 'errorCode' parameter should be checked
139 // against the following before using the handle:
140 // - NO_DEVICE_FOUND signifying that no device was found with the specified ID
141 // or that the device with the specified ID could not be opened
142 //------------------------------------------------------------------------------
143 void *
144 USBOpen(unsigned long deviceID, int *errorCode);
145 
146 //------------------------------------------------------------------------------
147 // This function attempts to close the device attached to the given handle.
148 //
149 // PARAMETERS:
150 // handle: The device handle obtained via the open() function.
151 //
152 // RETURN VALUE:
153 // Returns an integer which will be equal to either:
154 // - CLOSE_OK if the device was closed successfully
155 // - CLOSE_ERROR if some error occured
156 //------------------------------------------------------------------------------
157 int
158 USBClose(void *handle);
159 
160 //------------------------------------------------------------------------------
161 // This function writes the given data to the device attached to the given
162 // handle.
163 //
164 // PARAMETERS:
165 // handle: The device handle obtained via the open() function.
166 // endpoint: The endpoint on the device to write the data to.
167 // data: A pointer to the dynamically allocated byte array of data to be written
168 // size: The number of bytes to be written
169 //
170 // RETURN VALUE:
171 // Returns an integer which will be equal to either:
172 // - The number of bytes written to the endpoint if the write was successful
173 // - WRITE_FAILED if the data was not written to the device
174 //------------------------------------------------------------------------------
175 int
176 USBWrite(void *handle, unsigned char endpoint, char * data, int numberOfBytes);
177 
178 //------------------------------------------------------------------------------
179 // This function reads data from the device attached to the given handle into
180 // the specified byte array.
181 //
182 // PARAMETERS:
183 // handle: The device handle obtained via the open() function.
184 // endpoint: The endpoint on the device to read the data from.
185 // data: A pointer to the dynamically allocated byte array to store the data.
186 // size: The number of bytes to be read.
187 //
188 // RETURN VALUE:
189 // Returns an integer which will be equal to either:
190 // - The number of bytes read from the endpoint if the read was successful
191 // - READ_FAILED if the data was not successfully read from the device
192 //------------------------------------------------------------------------------
193 int
194 USBRead(void *handle, unsigned char endpoint, char * data, int numberOfBytes);
195 
196 //------------------------------------------------------------------------------
197 // This function attempts to clear any stall on the given endpoint.
198 //
199 // PARAMETERS:
200 // handle: The device handle obtained via the open() function.
201 // endpoint: The endpoint on the device to clear a stall condition on.
202 //
203 // RETURN VALUE:
204 // No value is returned (void).
205 //------------------------------------------------------------------------------
206 void
207 USBClearStall(void *handle, unsigned char endpoint);
208 
209 int
210 USBGetDeviceDescriptor(void *handle, struct USBDeviceDescriptor *desc);
211 
212 int
213 USBGetInterfaceDescriptor(void *handle, struct USBInterfaceDescriptor *desc);
214 
215 int
216 USBGetEndpointDescriptor(void *handle, int endpoint_index, struct USBEndpointDescriptor *desc);
217 
218 int
219 USBGetStringDescriptor(void *handle, unsigned int string_index, char *buffer, int maxLength);
220 
221 
222 #ifdef __cplusplus
223 }
224 #endif /* _cplusplus */
225 
226 #endif /* NATIVEUSB_H */
Definition: NativeUSB.h:97
Definition: NativeUSB.h:68
Definition: NativeUSB.h:57
Definition: NativeUSB.h:85