diff options
author | Jenna Fox <a@creativepony.com> | 2012-09-30 10:00:17 +1000 |
---|---|---|
committer | Jenna Fox <a@creativepony.com> | 2012-09-30 10:00:17 +1000 |
commit | 2d6072e4b4f365297da2d1cc933ebc8e71f92d30 (patch) | |
tree | c3d79ed1e424effb85fd7f70a275e28a0a24555f /commandline/usb-windows.c | |
parent | 1c867a4733cbf3a8de8f746c50171c977520766a (diff) | |
parent | 35cc54629ade1abfb801b832534f6c7f45eff20c (diff) | |
download | micronucleus-2d6072e4b4f365297da2d1cc933ebc8e71f92d30.tar.gz micronucleus-2d6072e4b4f365297da2d1cc933ebc8e71f92d30.tar.bz2 micronucleus-2d6072e4b4f365297da2d1cc933ebc8e71f92d30.zip |
Merge branch 'master' of github.com:Bluebie/micronucleus-t85 into heavy-squeeze
Diffstat (limited to 'commandline/usb-windows.c')
-rwxr-xr-x | commandline/usb-windows.c | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/commandline/usb-windows.c b/commandline/usb-windows.c deleted file mode 100755 index fac3b02..0000000 --- a/commandline/usb-windows.c +++ /dev/null @@ -1,180 +0,0 @@ -/* Name: usb-windows.c - * Project: usbcalls library - * Author: Christian Starkjohann - * Creation Date: 2006-02-02 - * Tabsize: 4 - * Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH - * License: Proprietary, free under certain conditions. See Documentation. - * This Revision: $Id: usb-windows.c 281 2007-03-20 13:22:10Z cs $ - */ - -/* -General Description: -This module implements USB HID report receiving and sending with native -Windows API functions. If you compile with MinGW, no software from Microsoft -(no DDK) is needed. We supply the missing types and function prototypes in -hidsdi.h. -*/ - -#include <stdio.h> -#include <windows.h> -#include <setupapi.h> -#include "hidsdi.h" -#include <ddk/hidpi.h> - -#include "usbcalls.h" - -#ifdef DEBUG -#define DEBUG_PRINT(arg) printf arg -#else -#define DEBUG_PRINT(arg) -#endif - -/* ------------------------------------------------------------------------ */ - -static void convertUniToAscii(char *buffer) -{ -unsigned short *uni = (void *)buffer; -char *ascii = buffer; - - while(*uni != 0){ - if(*uni >= 256){ - *ascii++ = '?'; - }else{ - *ascii++ = *uni++; - } - } - *ascii++ = 0; -} - -int usbOpenDevice(usbDevice_t **device, int vendor, char *vendorName, int product, char *productName, int usesReportIDs) -{ -GUID hidGuid; /* GUID for HID driver */ -HDEVINFO deviceInfoList; -SP_DEVICE_INTERFACE_DATA deviceInfo; -SP_DEVICE_INTERFACE_DETAIL_DATA *deviceDetails = NULL; -DWORD size; -int i, openFlag = 0; /* may be FILE_FLAG_OVERLAPPED */ -int errorCode = USB_ERROR_NOTFOUND; -HANDLE handle = INVALID_HANDLE_VALUE; -HIDD_ATTRIBUTES deviceAttributes; - - HidD_GetHidGuid(&hidGuid); - deviceInfoList = SetupDiGetClassDevs(&hidGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); - deviceInfo.cbSize = sizeof(deviceInfo); - for(i=0;;i++){ - if(handle != INVALID_HANDLE_VALUE){ - CloseHandle(handle); - handle = INVALID_HANDLE_VALUE; - } - if(!SetupDiEnumDeviceInterfaces(deviceInfoList, 0, &hidGuid, i, &deviceInfo)) - break; /* no more entries */ - /* first do a dummy call just to determine the actual size required */ - SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, NULL, 0, &size, NULL); - if(deviceDetails != NULL) - free(deviceDetails); - deviceDetails = malloc(size); - deviceDetails->cbSize = sizeof(*deviceDetails); - /* this call is for real: */ - SetupDiGetDeviceInterfaceDetail(deviceInfoList, &deviceInfo, deviceDetails, size, &size, NULL); - DEBUG_PRINT(("checking HID path \"%s\"\n", deviceDetails->DevicePath)); - /* attempt opening for R/W -- we don't care about devices which can't be accessed */ - handle = CreateFile(deviceDetails->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL); - if(handle == INVALID_HANDLE_VALUE){ - DEBUG_PRINT(("opening failed: %d\n", (int)GetLastError())); - /* errorCode = USB_ERROR_ACCESS; opening will always fail for mouse -- ignore */ - continue; - } - deviceAttributes.Size = sizeof(deviceAttributes); - HidD_GetAttributes(handle, &deviceAttributes); - DEBUG_PRINT(("device attributes: vid=%d pid=%d\n", deviceAttributes.VendorID, deviceAttributes.ProductID)); - if(deviceAttributes.VendorID != vendor || deviceAttributes.ProductID != product) - continue; /* ignore this device */ - errorCode = USB_ERROR_NOTFOUND; - if(vendorName != NULL && productName != NULL){ - char buffer[512]; - if(!HidD_GetManufacturerString(handle, buffer, sizeof(buffer))){ - DEBUG_PRINT(("error obtaining vendor name\n")); - errorCode = USB_ERROR_IO; - continue; - } - convertUniToAscii(buffer); - DEBUG_PRINT(("vendorName = \"%s\"\n", buffer)); - if(strcmp(vendorName, buffer) != 0) - continue; - if(!HidD_GetProductString(handle, buffer, sizeof(buffer))){ - DEBUG_PRINT(("error obtaining product name\n")); - errorCode = USB_ERROR_IO; - continue; - } - convertUniToAscii(buffer); - DEBUG_PRINT(("productName = \"%s\"\n", buffer)); - if(strcmp(productName, buffer) != 0) - continue; - } - break; /* we have found the device we are looking for! */ - } - SetupDiDestroyDeviceInfoList(deviceInfoList); - if(deviceDetails != NULL) - free(deviceDetails); - if(handle != INVALID_HANDLE_VALUE){ - *device = (usbDevice_t *)handle; - errorCode = 0; - } - return errorCode; -} - -/* ------------------------------------------------------------------------ */ - -void usbCloseDevice(usbDevice_t *device) -{ - CloseHandle((HANDLE)device); -} - -/* ------------------------------------------------------------------------ */ - -int usbSetReport(usbDevice_t *device, int reportType, char *buffer, int len) -{ -HANDLE handle = (HANDLE)device; -BOOLEAN rval = 0; -DWORD bytesWritten; - - switch(reportType){ - case USB_HID_REPORT_TYPE_INPUT: - break; - case USB_HID_REPORT_TYPE_OUTPUT: - rval = WriteFile(handle, buffer, len, &bytesWritten, NULL); - break; - case USB_HID_REPORT_TYPE_FEATURE: - rval = HidD_SetFeature(handle, buffer, len); - break; - } - return rval == 0 ? USB_ERROR_IO : 0; -} - -/* ------------------------------------------------------------------------ */ - -int usbGetReport(usbDevice_t *device, int reportType, int reportNumber, char *buffer, int *len) -{ -HANDLE handle = (HANDLE)device; -BOOLEAN rval = 0; -DWORD bytesRead; - - switch(reportType){ - case USB_HID_REPORT_TYPE_INPUT: - buffer[0] = reportNumber; - rval = ReadFile(handle, buffer, *len, &bytesRead, NULL); - if(rval) - *len = bytesRead; - break; - case USB_HID_REPORT_TYPE_OUTPUT: - break; - case USB_HID_REPORT_TYPE_FEATURE: - buffer[0] = reportNumber; - rval = HidD_GetFeature(handle, buffer, *len); - break; - } - return rval == 0 ? USB_ERROR_IO : 0; -} - -/* ------------------------------------------------------------------------ */ |