00001 /* Name: hiddata.h 00002 * Author: Christian Starkjohann 00003 * Creation Date: 2008-04-11 00004 * Tabsize: 4 00005 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH 00006 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 00007 */ 00008 00009 #ifndef __HIDDATA_H_INCLUDED__ 00010 #define __HIDDATA_H_INCLUDED__ 00011 00012 /* 00013 General Description: 00014 This module implements an abstraction layer for data transfer over HID feature 00015 requests. The implementation uses native Windows functions on Windows so that 00016 no driver installation is required and libusb on Unix. You must link the 00017 appropriate libraries in either case: "-lhid -lusb -lsetupapi" on Windows and 00018 `libusb-config --libs` on Unix. 00019 */ 00020 00021 /* ------------------------------------------------------------------------ */ 00022 00023 #define USBOPEN_SUCCESS 0 /* no error */ 00024 #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ 00025 #define USBOPEN_ERR_IO 2 /* I/O error */ 00026 #define USBOPEN_ERR_NOTFOUND 3 /* device not found */ 00027 00028 /* ------------------------------------------------------------------------ */ 00029 00030 typedef struct usbDevice usbDevice_t; 00031 /* Opaque data type representing the USB device. This can be a Windows handle 00032 * or a libusb handle, depending on the backend implementation. 00033 */ 00034 00035 /* ------------------------------------------------------------------------ */ 00036 00037 int usbhidOpenDevice(usbDevice_t **device, int vendorID, char *vendorName, int productID, char *productName, int usesReportIDs); 00038 /* This function opens a USB device. 'vendorID' and 'productID' are the numeric 00039 * Vendor-ID and Product-ID of the device we want to open. If 'vendorName' and 00040 * 'productName' are both not NULL, only devices with matching manufacturer- 00041 * and product name strings are accepted. If the device uses report IDs, 00042 * 'usesReportIDs' must be set to a non-zero value. 00043 * Returns: If a matching device has been found, USBOPEN_SUCCESS is returned 00044 * and '*device' is set to an opaque pointer representing the device. The 00045 * device must be closed with usbhidCloseDevice(). If the device has not been 00046 * found or opening failed, an error code is returned. 00047 */ 00048 void usbhidCloseDevice(usbDevice_t *device); 00049 /* Every device opened with usbhidOpenDevice() must be closed with this function. 00050 */ 00051 int usbhidSetReport(usbDevice_t *device, char *buffer, int len); 00052 /* This function sends a feature report to the device. The report ID must be 00053 * in the first byte of buffer and the length 'len' of the report is specified 00054 * including this report ID. If no report IDs are used, buffer[0] must be set 00055 * to 0 (dummy report ID). 00056 * Returns: 0 on success, an error code otherwise. 00057 */ 00058 int usbhidGetReport(usbDevice_t *device, int reportID, char *buffer, int *len); 00059 /* This function obtains a feature report from the device. The requested 00060 * report-ID is passed in 'reportID'. The caller must pass a buffer of the size 00061 * of the expected report in 'buffer' and initialize the variable pointed to by 00062 * 'len' to the total size of this buffer. Upon successful return, the report 00063 * (prefixed with the report-ID) is in 'buffer' and the actual length of the 00064 * report is returned in '*len'. 00065 * Returns: 0 on success, an error code otherwise. 00066 */ 00067 00068 /* ------------------------------------------------------------------------ */ 00069 00070 #endif /* __HIDDATA_H_INCLUDED__ */