Wasatch.VCPP 1.0.19
Visual C++ driver for Wasatch Photonics spectrometers
libusb.h
1#ifndef __USB_H__
2#define __USB_H__
3
4#include <stdlib.h>
5#include <windows.h>
6
7/*
8 * 'interface' is defined somewhere in the Windows header files. This macro
9 * is deleted here to avoid conflicts and compile errors.
10 */
11
12#ifdef interface
13#undef interface
14#endif
15
16/*
17 * PATH_MAX from limits.h can't be used on Windows if the dll and
18 * import libraries are build/used by different compilers
19 */
20
21#define LIBUSB_PATH_MAX 512
22
23
24/*
25 * USB spec information
26 *
27 * This is all stuff grabbed from various USB specs and is pretty much
28 * not subject to change
29 */
30
31/*
32 * Device and/or Interface Class codes
33 */
34#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
35#define USB_CLASS_AUDIO 1
36#define USB_CLASS_COMM 2
37#define USB_CLASS_HID 3
38#define USB_CLASS_PRINTER 7
39#define USB_CLASS_MASS_STORAGE 8
40#define USB_CLASS_HUB 9
41#define USB_CLASS_DATA 10
42#define USB_CLASS_VENDOR_SPEC 0xff
43
44/*
45 * Descriptor types
46 */
47#define USB_DT_DEVICE 0x01
48#define USB_DT_CONFIG 0x02
49#define USB_DT_STRING 0x03
50#define USB_DT_INTERFACE 0x04
51#define USB_DT_ENDPOINT 0x05
52
53#define USB_DT_HID 0x21
54#define USB_DT_REPORT 0x22
55#define USB_DT_PHYSICAL 0x23
56#define USB_DT_HUB 0x29
57
58/*
59 * Descriptor sizes per descriptor type
60 */
61#define USB_DT_DEVICE_SIZE 18
62#define USB_DT_CONFIG_SIZE 9
63#define USB_DT_INTERFACE_SIZE 9
64#define USB_DT_ENDPOINT_SIZE 7
65#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
66#define USB_DT_HUB_NONVAR_SIZE 7
67
68/* ensure byte-packed structures */
69#include <pshpack1.h>
70
71/* All standard descriptors have these 2 fields in common */
73{
74 unsigned char bLength;
75 unsigned char bDescriptorType;
76};
77
78/* String descriptor */
80{
81 unsigned char bLength;
82 unsigned char bDescriptorType;
83 unsigned short wData[1];
84};
85
86/* HID descriptor */
88{
89 unsigned char bLength;
90 unsigned char bDescriptorType;
91 unsigned short bcdHID;
92 unsigned char bCountryCode;
93 unsigned char bNumDescriptors;
94};
95
96/* Endpoint descriptor */
97#define USB_MAXENDPOINTS 32
99{
100 unsigned char bLength;
101 unsigned char bDescriptorType;
102 unsigned char bEndpointAddress;
103 unsigned char bmAttributes;
104 unsigned short wMaxPacketSize;
105 unsigned char bInterval;
106 unsigned char bRefresh;
107 unsigned char bSynchAddress;
108
109 unsigned char *extra; /* Extra descriptors */
110 int extralen;
111};
112
113#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
114#define USB_ENDPOINT_DIR_MASK 0x80
115
116#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
117#define USB_ENDPOINT_TYPE_CONTROL 0
118#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
119#define USB_ENDPOINT_TYPE_BULK 2
120#define USB_ENDPOINT_TYPE_INTERRUPT 3
121
122/* Interface descriptor */
123#define USB_MAXINTERFACES 32
125{
126 unsigned char bLength;
127 unsigned char bDescriptorType;
128 unsigned char bInterfaceNumber;
129 unsigned char bAlternateSetting;
130 unsigned char bNumEndpoints;
131 unsigned char bInterfaceClass;
132 unsigned char bInterfaceSubClass;
133 unsigned char bInterfaceProtocol;
134 unsigned char iInterface;
135
136 struct usb_endpoint_descriptor *endpoint;
137
138 unsigned char *extra; /* Extra descriptors */
139 int extralen;
140};
141
142#define USB_MAXALTSETTING 128 /* Hard limit */
143
145{
146 struct usb_interface_descriptor *altsetting;
147
148 int num_altsetting;
149};
150
151/* Configuration descriptor information.. */
152#define USB_MAXCONFIG 8
154{
155 unsigned char bLength;
156 unsigned char bDescriptorType;
157 unsigned short wTotalLength;
158 unsigned char bNumInterfaces;
159 unsigned char bConfigurationValue;
160 unsigned char iConfiguration;
161 unsigned char bmAttributes;
162 unsigned char MaxPower;
163
164 struct usb_interface *interface;
165
166 unsigned char *extra; /* Extra descriptors */
167 int extralen;
168};
169
170/* Device descriptor */
172{
173 unsigned char bLength;
174 unsigned char bDescriptorType;
175 unsigned short bcdUSB;
176 unsigned char bDeviceClass;
177 unsigned char bDeviceSubClass;
178 unsigned char bDeviceProtocol;
179 unsigned char bMaxPacketSize0;
180 unsigned short idVendor;
181 unsigned short idProduct;
182 unsigned short bcdDevice;
183 unsigned char iManufacturer;
184 unsigned char iProduct;
185 unsigned char iSerialNumber;
186 unsigned char bNumConfigurations;
187};
188
190{
191 unsigned char bRequestType;
192 unsigned char bRequest;
193 unsigned short wValue;
194 unsigned short wIndex;
195 unsigned short wLength;
196};
197
198/*
199 * Standard requests
200 */
201#define USB_REQ_GET_STATUS 0x00
202#define USB_REQ_CLEAR_FEATURE 0x01
203/* 0x02 is reserved */
204#define USB_REQ_SET_FEATURE 0x03
205/* 0x04 is reserved */
206#define USB_REQ_SET_ADDRESS 0x05
207#define USB_REQ_GET_DESCRIPTOR 0x06
208#define USB_REQ_SET_DESCRIPTOR 0x07
209#define USB_REQ_GET_CONFIGURATION 0x08
210#define USB_REQ_SET_CONFIGURATION 0x09
211#define USB_REQ_GET_INTERFACE 0x0A
212#define USB_REQ_SET_INTERFACE 0x0B
213#define USB_REQ_SYNCH_FRAME 0x0C
214
215#define USB_TYPE_STANDARD (0x00 << 5)
216#define USB_TYPE_CLASS (0x01 << 5)
217#define USB_TYPE_VENDOR (0x02 << 5)
218#define USB_TYPE_RESERVED (0x03 << 5)
219
220#define USB_RECIP_DEVICE 0x00
221#define USB_RECIP_INTERFACE 0x01
222#define USB_RECIP_ENDPOINT 0x02
223#define USB_RECIP_OTHER 0x03
224
225/*
226 * Various libusb API related stuff
227 */
228
229#define USB_ENDPOINT_IN 0x80
230#define USB_ENDPOINT_OUT 0x00
231
232/* Error codes */
233#define USB_ERROR_BEGIN 500000
234
235/*
236 * This is supposed to look weird. This file is generated from autoconf
237 * and I didn't want to make this too complicated.
238 */
239#define USB_LE16_TO_CPU(x)
240
241/*
242 * Device reset types for usb_reset_ex.
243 * http://msdn.microsoft.com/en-us/library/ff537269%28VS.85%29.aspx
244 * http://msdn.microsoft.com/en-us/library/ff537243%28v=vs.85%29.aspx
245 */
246#define USB_RESET_TYPE_RESET_PORT (1 << 0)
247#define USB_RESET_TYPE_CYCLE_PORT (1 << 1)
248#define USB_RESET_TYPE_FULL_RESET (USB_RESET_TYPE_CYCLE_PORT | USB_RESET_TYPE_RESET_PORT)
249
250
251/* Data types */
252/* struct usb_device; */
253/* struct usb_bus; */
254
256{
257 struct usb_device *next, *prev;
258
259 char filename[LIBUSB_PATH_MAX];
260
261 struct usb_bus *bus;
262
263 struct usb_device_descriptor descriptor;
264 struct usb_config_descriptor *config;
265
266 void *dev; /* Darwin support */
267
268 unsigned char devnum;
269
270 unsigned char num_children;
271 struct usb_device **children;
272};
273
275{
276 struct usb_bus *next, *prev;
277
278 char dirname[LIBUSB_PATH_MAX];
279
280 struct usb_device *devices;
281 unsigned long location;
282
283 struct usb_device *root_dev;
284};
285
286/* Version information, Windows specific */
288{
289 struct
290 {
291 int major;
292 int minor;
293 int micro;
294 int nano;
295 } dll;
296
297 struct
298 {
299 int major;
300 int minor;
301 int micro;
302 int nano;
303 } driver;
304};
305
306
307struct usb_dev_handle;
308typedef struct usb_dev_handle usb_dev_handle;
309
310/* Variables */
311#ifndef __USB_C__
312#define usb_busses usb_get_busses()
313#endif
314
315#include <poppack.h>
316
317#ifdef __cplusplus
318extern "C"
319{
320#endif
321
322 /* Function prototypes */
323
324 /* usb.c */
325 usb_dev_handle *usb_open(struct usb_device *dev);
326 int usb_close(usb_dev_handle *dev);
327 int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
328 size_t buflen);
329 int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
330 size_t buflen);
331
332 /* descriptors.c */
333 int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
334 unsigned char type, unsigned char index,
335 void *buf, int size);
336 int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
337 unsigned char index, void *buf, int size);
338
339 /* <arch>.c */
340 int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
341 int timeout);
342 int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
343 int timeout);
344 int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
345 int timeout);
346 int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
347 int timeout);
348 int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
349 int value, int index, char *bytes, int size,
350 int timeout);
351 int usb_set_configuration(usb_dev_handle *dev, int configuration);
352 int usb_claim_interface(usb_dev_handle *dev, int interface);
353 int usb_release_interface(usb_dev_handle *dev, int interface);
354 int usb_set_altinterface(usb_dev_handle *dev, int alternate);
355 int usb_resetep(usb_dev_handle *dev, unsigned int ep);
356 int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
357 int usb_reset(usb_dev_handle *dev);
358 int usb_reset_ex(usb_dev_handle *dev, unsigned int reset_type);
359
360 char *usb_strerror(void);
361
362 void usb_init(void);
363 void usb_set_debug(int level);
364 int usb_find_busses(void);
365 int usb_find_devices(void);
366 struct usb_device *usb_device(usb_dev_handle *dev);
367 struct usb_bus *usb_get_busses(void);
368
369 /* Windows specific functions */
370
371#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
372 int usb_install_service_np(void);
373 void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
374 LPSTR cmd_line, int cmd_show);
375
376#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
377 int usb_uninstall_service_np(void);
378 void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
379 LPSTR cmd_line, int cmd_show);
380
381#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
382 int usb_install_driver_np(const char *inf_file);
383 void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
384 LPSTR cmd_line, int cmd_show);
385
386#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
387 int usb_touch_inf_file_np(const char *inf_file);
388 void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
389 LPSTR cmd_line, int cmd_show);
390
391#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
392 int usb_install_needs_restart_np(void);
393
394#define LIBUSB_HAS_INSTALL_NP 1
395 int usb_install_npW(HWND hwnd, HINSTANCE instance, LPCWSTR cmd_line, int starg_arg);
396 int usb_install_npA(HWND hwnd, HINSTANCE instance, LPCSTR cmd_line, int starg_arg);
397 #define usb_install_np usb_install_npA
398 void CALLBACK usb_install_np_rundll(HWND wnd, HINSTANCE instance,
399 LPSTR cmd_line, int cmd_show);
400
401 const struct usb_version *usb_get_version(void);
402
403 int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
404 unsigned char ep, int pktsize);
405 int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
406 unsigned char ep);
407 int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
408 unsigned char ep);
409
410 int usb_submit_async(void *context, char *bytes, int size);
411 int usb_reap_async(void *context, int timeout);
412 int usb_reap_async_nocancel(void *context, int timeout);
413 int usb_cancel_async(void *context);
414 int usb_free_async(void **context);
415
416#ifdef __cplusplus
417}
418#endif
419
420#endif /* __USB_H__ */
Definition: libusb.h:275
Definition: libusb.h:154
Definition: libusb.h:190
Definition: libusb.h:73
Definition: libusb.h:172
Definition: libusb.h:256
Definition: libusb.h:99
Definition: libusb.h:88
Definition: libusb.h:125
Definition: libusb.h:145
Definition: libusb.h:80
Definition: libusb.h:288