Basic HID works on windows! I had to customise HIDAPI.

This commit is contained in:
Matthew Parlane 2012-11-13 00:14:47 +13:00
parent 0caf693d1c
commit 586813b150
5 changed files with 69 additions and 19 deletions

View File

@ -155,7 +155,7 @@ extern "C" {
This function returns a pointer to a #hid_device object on This function returns a pointer to a #hid_device object on
success or NULL on failure. success or NULL on failure.
*/ */
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, wchar_t *serial_number); HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name. /** @brief Open a HID device by its path name.
@ -199,8 +199,8 @@ extern "C" {
-1 on error. -1 on error.
*/ */
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length); int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_write_report(hid_device *device, const unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_set_output_report(hid_device *dev, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout. /** @brief Read an Input report from a HID device with timeout.
Input reports are returned Input reports are returned

Binary file not shown.

Binary file not shown.

View File

@ -23,17 +23,23 @@
#include "lusb0_usb.h" #include "lusb0_usb.h"
#include "hidapi.h" #include "hidapi.h"
static std::map<std::string, int> loaded_devices;
static std::map<int, std::string> loaded_devices_rev;
static std::map<int, hid_device *> opened_devices;
CWII_IPC_HLE_Device_hid::CWII_IPC_HLE_Device_hid(u32 _DeviceID, const std::string& _rDeviceName) CWII_IPC_HLE_Device_hid::CWII_IPC_HLE_Device_hid(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
{ {
usb_init(); /* initialize the library */ //usb_init(); /* initialize the library */
hid_init();
} }
CWII_IPC_HLE_Device_hid::~CWII_IPC_HLE_Device_hid() CWII_IPC_HLE_Device_hid::~CWII_IPC_HLE_Device_hid()
{ {
hid_exit();
} }
bool CWII_IPC_HLE_Device_hid::Open(u32 _CommandAddress, u32 _Mode) bool CWII_IPC_HLE_Device_hid::Open(u32 _CommandAddress, u32 _Mode)
@ -176,6 +182,28 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
upto++; upto++;
*/ */
hid_device * dev_handle = GetDeviceByDevNumHidLib(dev_num);
if (dev_handle == NULL)
{
ReturnValue = -4;
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Control)(%02X, %02X) = %d",
requesttype, request, ReturnValue);
break;
}
// this is our write request
if(request == 0x09)
{
#define rw_buf_size 0x21
unsigned char buf[rw_buf_size];
memset(&buf[0], 0, rw_buf_size);
memcpy(&buf[1], (unsigned char*)Memory::GetPointer(data), size);
int success = hid_write_report(dev_handle, buf, size+1);
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Control) success = %d", success);
}
ReturnValue = size + sizeof(usb_ctrl_setup); ReturnValue = size + sizeof(usb_ctrl_setup);
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Control)(%02X, %02X) = %d", DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Control)(%02X, %02X) = %d",
requesttype, request, ReturnValue); requesttype, request, ReturnValue);
@ -193,21 +221,29 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
u32 data = Memory::Read_U32(BufferIn+0x1C); u32 data = Memory::Read_U32(BufferIn+0x1C);
struct usb_dev_handle * dev_handle = GetDeviceByDevNum(dev_num); hid_device * dev_handle = GetDeviceByDevNumHidLib(dev_num);
if (dev_handle == NULL) if (dev_handle == NULL)
{ {
ReturnValue = -4; ReturnValue = -4;
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt In)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
end_point, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
break; break;
} }
usb_claim_interface(dev_handle,0); //ReturnValue = -5;
ReturnValue = usb_interrupt_read(dev_handle, end_point, (char*)Memory::GetPointer(data), length, 1000); ReturnValue = hid_read(dev_handle, (unsigned char*)Memory::GetPointer(data), length);
//ReturnValue = usb_interrupt_read(dev_handle, end_point, (char*)Memory::GetPointer(data), length, 1000);
FILE* test = fopen ("readdata.bin", "wb");
fwrite(Memory::GetPointer(data), ReturnValue, 1, test);
fclose(test);
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt In)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)", DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt In)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
end_point, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize); end_point, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
usb_close(dev_handle);
break; break;
} }
case IOCTL_HID_INTERRUPT_OUT: case IOCTL_HID_INTERRUPT_OUT:
@ -220,21 +256,22 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
u32 data = Memory::Read_U32(BufferIn+0x1C); u32 data = Memory::Read_U32(BufferIn+0x1C);
struct usb_dev_handle * dev_handle = GetDeviceByDevNum(dev_num); hid_device * dev_handle = GetDeviceByDevNumHidLib(dev_num);
if (dev_handle == NULL) if (dev_handle == NULL)
{ {
ReturnValue = -4; ReturnValue = -4;
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt Out) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
break; break;
} }
usb_claim_interface(dev_handle,0); ReturnValue = -5;
ReturnValue = usb_interrupt_write(dev_handle, end_point, (char*)Memory::GetPointer(data), length, 0); //ReturnValue = usb_interrupt_write(dev_handle, end_point, (char*)Memory::GetPointer(data), length, 0);
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt Out) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)", DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt Out) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize); ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
usb_close(dev_handle);
break; break;
} }
default: default:
@ -303,7 +340,12 @@ void CWII_IPC_HLE_Device_hid::ConvertEndpointToWii(WiiHIDEndpointDescriptor *des
static int x = 0; static int x = 0;
u32 CWII_IPC_HLE_Device_hid::GetAvailableID(char* path) u32 CWII_IPC_HLE_Device_hid::GetAvailableID(char* path)
{ {
return x++; std::string dev_path = path;
if(loaded_devices.find(dev_path) == loaded_devices.end()){
loaded_devices_rev[x] = dev_path;
loaded_devices[dev_path] = x++;
}
return loaded_devices[dev_path];
} }
// hidapi version // hidapi version
@ -411,9 +453,6 @@ void CWII_IPC_HLE_Device_hid::FillOutDevicesHidApi(u32 BufferOut, u32 BufferOutS
} }
Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices
FILE* test = fopen ("mattsbin.bin", "wb");
fwrite(Memory::GetPointer(BufferOut), BufferOutSize, 1, test);
fclose(test);
hid_free_enumeration(devs); hid_free_enumeration(devs);
} }
@ -499,6 +538,16 @@ int CWII_IPC_HLE_Device_hid::Align(int num, int alignment)
return (num + (alignment-1)) & ~(alignment-1); return (num + (alignment-1)) & ~(alignment-1);
} }
hid_device * CWII_IPC_HLE_Device_hid::GetDeviceByDevNumHidLib(u32 devNum)
{
if (loaded_devices_rev.find(devNum) == loaded_devices_rev.end())
return NULL;
if (opened_devices.find(devNum) != opened_devices.end())
return opened_devices[devNum];
hid_device * phPortalHandle = opened_devices[devNum] = hid_open_path(loaded_devices_rev[devNum].c_str());
return phPortalHandle;
}
struct usb_dev_handle * CWII_IPC_HLE_Device_hid::GetDeviceByDevNum(u32 devNum) struct usb_dev_handle * CWII_IPC_HLE_Device_hid::GetDeviceByDevNum(u32 devNum)
{ {

View File

@ -19,6 +19,7 @@
#include "WII_IPC_HLE.h" #include "WII_IPC_HLE.h"
#include "WII_IPC_HLE_Device.h" #include "WII_IPC_HLE_Device.h"
#include "hidapi.h"
class CWII_IPC_HLE_Device_hid : public IWII_IPC_HLE_Device class CWII_IPC_HLE_Device_hid : public IWII_IPC_HLE_Device
{ {
@ -122,7 +123,7 @@ private:
void ConvertEndpointToWii(WiiHIDEndpointDescriptor *dest, struct usb_endpoint_descriptor *src); void ConvertEndpointToWii(WiiHIDEndpointDescriptor *dest, struct usb_endpoint_descriptor *src);
int Align(int num, int alignment); int Align(int num, int alignment);
hid_device * GetDeviceByDevNumHidLib(u32 devNum);
struct usb_dev_handle * GetDeviceByDevNum(u32 devNum); struct usb_dev_handle * GetDeviceByDevNum(u32 devNum);