hiddata.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Name: hiddata.h
  2. * Author: Christian Starkjohann
  3. * Creation Date: 2008-04-11
  4. * Tabsize: 4
  5. * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
  6. * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
  7. * This Revision: $Id: hiddata.h 692 2008-11-07 15:07:40Z cs $
  8. */
  9. #ifndef __HIDDATA_H_INCLUDED__
  10. #define __HIDDATA_H_INCLUDED__
  11. /*
  12. General Description:
  13. This module implements an abstraction layer for data transfer over HID feature
  14. requests. The implementation uses native Windows functions on Windows so that
  15. no driver installation is required and libusb on Unix. You must link the
  16. appropriate libraries in either case: "-lhid -lusb -lsetupapi" on Windows and
  17. `libusb-config --libs` on Unix.
  18. */
  19. /* ------------------------------------------------------------------------ */
  20. #define USBOPEN_SUCCESS 0 /* no error */
  21. #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */
  22. #define USBOPEN_ERR_IO 2 /* I/O error */
  23. #define USBOPEN_ERR_NOTFOUND 3 /* device not found */
  24. /* ------------------------------------------------------------------------ */
  25. typedef struct usbDevice usbDevice_t;
  26. /* Opaque data type representing the USB device. This can be a Windows handle
  27. * or a libusb handle, depending on the backend implementation.
  28. */
  29. /* ------------------------------------------------------------------------ */
  30. int usbhidOpenDevice(usbDevice_t **device, int vendorID, char *vendorName, int productID, char *productName, int usesReportIDs);
  31. /* This function opens a USB device. 'vendorID' and 'productID' are the numeric
  32. * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and
  33. * 'productName' are both not NULL, only devices with matching manufacturer-
  34. * and product name strings are accepted. If the device uses report IDs,
  35. * 'usesReportIDs' must be set to a non-zero value.
  36. * Returns: If a matching device has been found, USBOPEN_SUCCESS is returned
  37. * and '*device' is set to an opaque pointer representing the device. The
  38. * device must be closed with usbhidCloseDevice(). If the device has not been
  39. * found or opening failed, an error code is returned.
  40. */
  41. void usbhidCloseDevice(usbDevice_t *device);
  42. /* Every device opened with usbhidOpenDevice() must be closed with this function.
  43. */
  44. int usbhidSetReport(usbDevice_t *device, char *buffer, int len);
  45. /* This function sends a feature report to the device. The report ID must be
  46. * in the first byte of buffer and the length 'len' of the report is specified
  47. * including this report ID. If no report IDs are used, buffer[0] must be set
  48. * to 0 (dummy report ID).
  49. * Returns: 0 on success, an error code otherwise.
  50. */
  51. int usbhidGetReport(usbDevice_t *device, int reportID, char *buffer, int *len);
  52. /* This function obtains a feature report from the device. The requested
  53. * report-ID is passed in 'reportID'. The caller must pass a buffer of the size
  54. * of the expected report in 'buffer' and initialize the variable pointed to by
  55. * 'len' to the total size of this buffer. Upon successful return, the report
  56. * (prefixed with the report-ID) is in 'buffer' and the actual length of the
  57. * report is returned in '*len'.
  58. * Returns: 0 on success, an error code otherwise.
  59. */
  60. /* ------------------------------------------------------------------------ */
  61. #endif /* __HIDDATA_H_INCLUDED__ */