Movd back to libusb for full support on windows
This commit is contained in:
parent
586813b150
commit
d8b879a4ee
|
@ -1,384 +0,0 @@
|
||||||
/*******************************************************
|
|
||||||
HIDAPI - Multi-Platform library for
|
|
||||||
communication with HID devices.
|
|
||||||
|
|
||||||
Alan Ott
|
|
||||||
Signal 11 Software
|
|
||||||
|
|
||||||
8/22/2009
|
|
||||||
|
|
||||||
Copyright 2009, All Rights Reserved.
|
|
||||||
|
|
||||||
At the discretion of the user of this library,
|
|
||||||
this software may be licensed under the terms of the
|
|
||||||
GNU Public License v3, a BSD-Style license, or the
|
|
||||||
original HIDAPI license as outlined in the LICENSE.txt,
|
|
||||||
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
|
|
||||||
files located at the root of the source distribution.
|
|
||||||
These files may also be found in the public source
|
|
||||||
code repository located at:
|
|
||||||
http://github.com/signal11/hidapi .
|
|
||||||
********************************************************/
|
|
||||||
|
|
||||||
/** @file
|
|
||||||
* @defgroup API hidapi API
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef HIDAPI_H__
|
|
||||||
#define HIDAPI_H__
|
|
||||||
|
|
||||||
#include <wchar.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define HID_API_EXPORT __declspec(dllexport)
|
|
||||||
#define HID_API_CALL
|
|
||||||
#else
|
|
||||||
#define HID_API_EXPORT /**< API export macro */
|
|
||||||
#define HID_API_CALL /**< API call macro */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
struct hid_device_;
|
|
||||||
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
|
|
||||||
|
|
||||||
/** hidapi info structure */
|
|
||||||
struct hid_device_info {
|
|
||||||
/** Platform-specific device path */
|
|
||||||
char *path;
|
|
||||||
/** Device Vendor ID */
|
|
||||||
unsigned short vendor_id;
|
|
||||||
/** Device Product ID */
|
|
||||||
unsigned short product_id;
|
|
||||||
/** Serial Number */
|
|
||||||
wchar_t *serial_number;
|
|
||||||
/** Device Release Number in binary-coded decimal,
|
|
||||||
also known as Device Version Number */
|
|
||||||
unsigned short release_number;
|
|
||||||
/** Manufacturer String */
|
|
||||||
wchar_t *manufacturer_string;
|
|
||||||
/** Product string */
|
|
||||||
wchar_t *product_string;
|
|
||||||
/** Usage Page for this Device/Interface
|
|
||||||
(Windows/Mac only). */
|
|
||||||
unsigned short usage_page;
|
|
||||||
/** Usage for this Device/Interface
|
|
||||||
(Windows/Mac only).*/
|
|
||||||
unsigned short usage;
|
|
||||||
/** The USB interface which this logical device
|
|
||||||
represents. Valid on both Linux implementations
|
|
||||||
in all cases, and valid on the Windows implementation
|
|
||||||
only if the device contains more than one interface. */
|
|
||||||
int interface_number;
|
|
||||||
|
|
||||||
/** Pointer to the next device */
|
|
||||||
struct hid_device_info *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/** @brief Initialize the HIDAPI library.
|
|
||||||
|
|
||||||
This function initializes the HIDAPI library. Calling it is not
|
|
||||||
strictly necessary, as it will be called automatically by
|
|
||||||
hid_enumerate() and any of the hid_open_*() functions if it is
|
|
||||||
needed. This function should be called at the beginning of
|
|
||||||
execution however, if there is a chance of HIDAPI handles
|
|
||||||
being opened by different threads simultaneously.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_init(void);
|
|
||||||
|
|
||||||
/** @brief Finalize the HIDAPI library.
|
|
||||||
|
|
||||||
This function frees all of the static data associated with
|
|
||||||
HIDAPI. It should be called at the end of execution to avoid
|
|
||||||
memory leaks.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_exit(void);
|
|
||||||
|
|
||||||
/** @brief Enumerate the HID Devices.
|
|
||||||
|
|
||||||
This function returns a linked list of all the HID devices
|
|
||||||
attached to the system which match vendor_id and product_id.
|
|
||||||
If @p vendor_id and @p product_id are both set to 0, then
|
|
||||||
all HID devices will be returned.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param vendor_id The Vendor ID (VID) of the types of device
|
|
||||||
to open.
|
|
||||||
@param product_id The Product ID (PID) of the types of
|
|
||||||
device to open.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns a pointer to a linked list of type
|
|
||||||
struct #hid_device, containing information about the HID devices
|
|
||||||
attached to the system, or NULL in the case of failure. Free
|
|
||||||
this linked list by calling hid_free_enumeration().
|
|
||||||
*/
|
|
||||||
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
|
|
||||||
|
|
||||||
/** @brief Free an enumeration Linked List
|
|
||||||
|
|
||||||
This function frees a linked list created by hid_enumerate().
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param devs Pointer to a list of struct_device returned from
|
|
||||||
hid_enumerate().
|
|
||||||
*/
|
|
||||||
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
|
|
||||||
|
|
||||||
/** @brief Open a HID device using a Vendor ID (VID), Product ID
|
|
||||||
(PID) and optionally a serial number.
|
|
||||||
|
|
||||||
If @p serial_number is NULL, the first device with the
|
|
||||||
specified VID and PID is opened.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param vendor_id The Vendor ID (VID) of the device to open.
|
|
||||||
@param product_id The Product ID (PID) of the device to open.
|
|
||||||
@param serial_number The Serial Number of the device to open
|
|
||||||
(Optionally NULL).
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns a pointer to a #hid_device object on
|
|
||||||
success or NULL on failure.
|
|
||||||
*/
|
|
||||||
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.
|
|
||||||
|
|
||||||
The path name be determined by calling hid_enumerate(), or a
|
|
||||||
platform-specific path name can be used (eg: /dev/hidraw0 on
|
|
||||||
Linux).
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param path The path name of the device to open
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns a pointer to a #hid_device object on
|
|
||||||
success or NULL on failure.
|
|
||||||
*/
|
|
||||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
|
|
||||||
|
|
||||||
/** @brief Write an Output report to a HID device.
|
|
||||||
|
|
||||||
The first byte of @p data[] must contain the Report ID. For
|
|
||||||
devices which only support a single report, this must be set
|
|
||||||
to 0x0. The remaining bytes contain the report data. Since
|
|
||||||
the Report ID is mandatory, calls to hid_write() will always
|
|
||||||
contain one more byte than the report contains. For example,
|
|
||||||
if a hid report is 16 bytes long, 17 bytes must be passed to
|
|
||||||
hid_write(), the Report ID (or 0x0, for devices with a
|
|
||||||
single report), followed by the report data (16 bytes). In
|
|
||||||
this example, the length passed in would be 17.
|
|
||||||
|
|
||||||
hid_write() will send the data on the first OUT endpoint, if
|
|
||||||
one exists. If it does not, it will send the data through
|
|
||||||
the Control Endpoint (Endpoint 0).
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param data The data to send, including the report number as
|
|
||||||
the first byte.
|
|
||||||
@param length The length in bytes of the data to send.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns the actual number of bytes written and
|
|
||||||
-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_report(hid_device *device, const unsigned char *data, size_t length);
|
|
||||||
|
|
||||||
/** @brief Read an Input report from a HID device with timeout.
|
|
||||||
|
|
||||||
Input reports are returned
|
|
||||||
to the host through the INTERRUPT IN endpoint. The first byte will
|
|
||||||
contain the Report number if the device uses numbered reports.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param data A buffer to put the read data into.
|
|
||||||
@param length The number of bytes to read. For devices with
|
|
||||||
multiple reports, make sure to read an extra byte for
|
|
||||||
the report number.
|
|
||||||
@param milliseconds timeout in milliseconds or -1 for blocking wait.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns the actual number of bytes read and
|
|
||||||
-1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
|
|
||||||
|
|
||||||
/** @brief Read an Input report from a HID device.
|
|
||||||
|
|
||||||
Input reports are returned
|
|
||||||
to the host through the INTERRUPT IN endpoint. The first byte will
|
|
||||||
contain the Report number if the device uses numbered reports.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param data A buffer to put the read data into.
|
|
||||||
@param length The number of bytes to read. For devices with
|
|
||||||
multiple reports, make sure to read an extra byte for
|
|
||||||
the report number.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns the actual number of bytes read and
|
|
||||||
-1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
|
|
||||||
|
|
||||||
/** @brief Set the device handle to be non-blocking.
|
|
||||||
|
|
||||||
In non-blocking mode calls to hid_read() will return
|
|
||||||
immediately with a value of 0 if there is no data to be
|
|
||||||
read. In blocking mode, hid_read() will wait (block) until
|
|
||||||
there is data to read before returning.
|
|
||||||
|
|
||||||
Nonblocking can be turned on and off at any time.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param nonblock enable or not the nonblocking reads
|
|
||||||
- 1 to enable nonblocking
|
|
||||||
- 0 to disable nonblocking.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
|
|
||||||
|
|
||||||
/** @brief Send a Feature report to the device.
|
|
||||||
|
|
||||||
Feature reports are sent over the Control endpoint as a
|
|
||||||
Set_Report transfer. The first byte of @p data[] must
|
|
||||||
contain the Report ID. For devices which only support a
|
|
||||||
single report, this must be set to 0x0. The remaining bytes
|
|
||||||
contain the report data. Since the Report ID is mandatory,
|
|
||||||
calls to hid_send_feature_report() will always contain one
|
|
||||||
more byte than the report contains. For example, if a hid
|
|
||||||
report is 16 bytes long, 17 bytes must be passed to
|
|
||||||
hid_send_feature_report(): the Report ID (or 0x0, for
|
|
||||||
devices which do not use numbered reports), followed by the
|
|
||||||
report data (16 bytes). In this example, the length passed
|
|
||||||
in would be 17.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param data The data to send, including the report number as
|
|
||||||
the first byte.
|
|
||||||
@param length The length in bytes of the data to send, including
|
|
||||||
the report number.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns the actual number of bytes written and
|
|
||||||
-1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
|
|
||||||
|
|
||||||
/** @brief Get a feature report from a HID device.
|
|
||||||
|
|
||||||
Make sure to set the first byte of @p data[] to the Report
|
|
||||||
ID of the report to be read. Make sure to allow space for
|
|
||||||
this extra byte in @p data[].
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param data A buffer to put the read data into, including
|
|
||||||
the Report ID. Set the first byte of @p data[] to the
|
|
||||||
Report ID of the report to be read.
|
|
||||||
@param length The number of bytes to read, including an
|
|
||||||
extra byte for the report ID. The buffer can be longer
|
|
||||||
than the actual report.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns the number of bytes read and
|
|
||||||
-1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
|
|
||||||
|
|
||||||
/** @brief Close a HID device.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
*/
|
|
||||||
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);
|
|
||||||
|
|
||||||
/** @brief Get The Manufacturer String from a HID device.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param string A wide string buffer to put the data into.
|
|
||||||
@param maxlen The length of the buffer in multiples of wchar_t.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
|
|
||||||
|
|
||||||
/** @brief Get The Product String from a HID device.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param string A wide string buffer to put the data into.
|
|
||||||
@param maxlen The length of the buffer in multiples of wchar_t.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
|
|
||||||
|
|
||||||
/** @brief Get The Serial Number String from a HID device.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param string A wide string buffer to put the data into.
|
|
||||||
@param maxlen The length of the buffer in multiples of wchar_t.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
|
|
||||||
|
|
||||||
/** @brief Get a string from a HID device, based on its string index.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
@param string_index The index of the string to get.
|
|
||||||
@param string A wide string buffer to put the data into.
|
|
||||||
@param maxlen The length of the buffer in multiples of wchar_t.
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns 0 on success and -1 on error.
|
|
||||||
*/
|
|
||||||
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
|
|
||||||
|
|
||||||
/** @brief Get a string describing the last error which occurred.
|
|
||||||
|
|
||||||
@ingroup API
|
|
||||||
@param device A device handle returned from hid_open().
|
|
||||||
|
|
||||||
@returns
|
|
||||||
This function returns a string containing the last error
|
|
||||||
which occurred or NULL if none has occurred.
|
|
||||||
*/
|
|
||||||
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -101,7 +101,7 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
|
||||||
#define MAX_LOGLEVEL DEBUG_LEVEL
|
#define MAX_LOGLEVEL DEBUG_LEVEL
|
||||||
#else
|
#else
|
||||||
#ifndef MAX_LOGLEVEL
|
#ifndef MAX_LOGLEVEL
|
||||||
#define MAX_LOGLEVEL WARNING_LEVEL
|
#define MAX_LOGLEVEL DEBUG_LEVEL
|
||||||
#endif // loglevel
|
#endif // loglevel
|
||||||
#endif // logging
|
#endif // logging
|
||||||
|
|
||||||
|
|
|
@ -21,31 +21,29 @@
|
||||||
#include "WII_IPC_HLE.h"
|
#include "WII_IPC_HLE.h"
|
||||||
#include "WII_IPC_HLE_Device_hid.h"
|
#include "WII_IPC_HLE_Device_hid.h"
|
||||||
#include "lusb0_usb.h"
|
#include "lusb0_usb.h"
|
||||||
#include "hidapi.h"
|
#include "errno.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();
|
for ( std::map<u32,usb_dev_handle*>::const_iterator iter = open_devices.begin(); iter != open_devices.end(); ++iter )
|
||||||
|
{
|
||||||
|
usb_close(iter->second);
|
||||||
|
}
|
||||||
|
open_devices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWII_IPC_HLE_Device_hid::Open(u32 _CommandAddress, u32 _Mode)
|
bool CWII_IPC_HLE_Device_hid::Open(u32 _CommandAddress, u32 _Mode)
|
||||||
{
|
{
|
||||||
Dolphin_Debugger::PrintCallstack(LogTypes::WII_IPC_HID, LogTypes::LWARNING);
|
|
||||||
DEBUG_LOG(WII_IPC_HID, "HID::Open");
|
DEBUG_LOG(WII_IPC_HID, "HID::Open");
|
||||||
|
m_Active = true;
|
||||||
Memory::Write_U32(GetDeviceID(), _CommandAddress + 4);
|
Memory::Write_U32(GetDeviceID(), _CommandAddress + 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +51,48 @@ bool CWII_IPC_HLE_Device_hid::Open(u32 _CommandAddress, u32 _Mode)
|
||||||
bool CWII_IPC_HLE_Device_hid::Close(u32 _CommandAddress, bool _bForce)
|
bool CWII_IPC_HLE_Device_hid::Close(u32 _CommandAddress, bool _bForce)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(WII_IPC_HID, "HID::Close");
|
DEBUG_LOG(WII_IPC_HID, "HID::Close");
|
||||||
|
m_Active = false;
|
||||||
if (!_bForce)
|
if (!_bForce)
|
||||||
Memory::Write_U32(0, _CommandAddress + 4);
|
Memory::Write_U32(0, _CommandAddress + 4);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 CWII_IPC_HLE_Device_hid::Update()
|
||||||
|
{
|
||||||
|
u32 work_done = 0;
|
||||||
|
int ret = -4;
|
||||||
|
|
||||||
|
std::list<_hidevent>::iterator ev = event_list.begin();
|
||||||
|
while (ev != event_list.end()) {
|
||||||
|
|
||||||
|
bool ev_finished = false;
|
||||||
|
|
||||||
|
|
||||||
|
switch (ev->type)
|
||||||
|
{
|
||||||
|
case IOCTL_HID_INTERRUPT_OUT:
|
||||||
|
case IOCTL_HID_INTERRUPT_IN:
|
||||||
|
{
|
||||||
|
ret = usb_reap_async_nocancel(ev->context, 0);
|
||||||
|
if(ret >= 0)
|
||||||
|
{
|
||||||
|
Memory::Write_U32(ret, ev->enq_address + 4);
|
||||||
|
WII_IPC_HLE_Interface::EnqReply(ev->enq_address);
|
||||||
|
work_done = ev_finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev_finished)
|
||||||
|
event_list.erase(ev++);
|
||||||
|
else
|
||||||
|
ev++;
|
||||||
|
}
|
||||||
|
return work_done;
|
||||||
|
}
|
||||||
|
|
||||||
bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
static u32 replyAddress = 0;
|
static u32 replyAddress = 0;
|
||||||
|
@ -75,6 +110,7 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Get Attached) (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Get Attached) (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
||||||
BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
||||||
|
//Memory::Write_U32(0xFFFFFFFF, BufferOut);
|
||||||
if(!hasRun)
|
if(!hasRun)
|
||||||
{
|
{
|
||||||
FillOutDevices(BufferOut, BufferOutSize);
|
FillOutDevices(BufferOut, BufferOutSize);
|
||||||
|
@ -133,7 +169,6 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
ERROR CODES:
|
ERROR CODES:
|
||||||
-4 Cant find device specified
|
-4 Cant find device specified
|
||||||
*/
|
*/
|
||||||
|
|
||||||
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
|
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
|
||||||
u8 requesttype = Memory::Read_U8(BufferIn+0x14);
|
u8 requesttype = Memory::Read_U8(BufferIn+0x14);
|
||||||
u8 request = Memory::Read_U8(BufferIn+0x15);
|
u8 request = Memory::Read_U8(BufferIn+0x15);
|
||||||
|
@ -142,11 +177,8 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
u16 size = Memory::Read_U16(BufferIn+0x1A);
|
u16 size = Memory::Read_U16(BufferIn+0x1A);
|
||||||
u32 data = Memory::Read_U32(BufferIn+0x1C);
|
u32 data = Memory::Read_U32(BufferIn+0x1C);
|
||||||
|
|
||||||
/* //libusb way
|
usb_find_busses(); /* find all busses */
|
||||||
static int upto = 0;
|
usb_find_devices(); /* find all connected devices */
|
||||||
int i;
|
|
||||||
usb_find_busses();
|
|
||||||
usb_find_devices();
|
|
||||||
|
|
||||||
struct usb_dev_handle * dev_handle = GetDeviceByDevNum(dev_num);
|
struct usb_dev_handle * dev_handle = GetDeviceByDevNum(dev_num);
|
||||||
|
|
||||||
|
@ -155,7 +187,7 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
ReturnValue = -4;
|
ReturnValue = -4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue = usb_control_msg(dev_handle, requesttype, request,
|
ReturnValue = usb_control_msg(dev_handle, requesttype, request,
|
||||||
value, index, (char*)Memory::GetPointer(data), size,
|
value, index, (char*)Memory::GetPointer(data), size,
|
||||||
0);
|
0);
|
||||||
|
@ -164,113 +196,68 @@ bool CWII_IPC_HLE_Device_hid::IOCtl(u32 _CommandAddress)
|
||||||
{
|
{
|
||||||
ReturnValue += sizeof(usb_ctrl_setup);
|
ReturnValue += 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 (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
||||||
requesttype, request, ReturnValue);
|
requesttype, request, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
||||||
|
|
||||||
usb_close(dev_handle);
|
|
||||||
|
|
||||||
u8 test_out[0x20];
|
|
||||||
Memory::ReadBigEData(test_out, BufferIn, BufferInSize);
|
|
||||||
char file[0x50];
|
|
||||||
snprintf(file, 0x50, "ctrl_ctrlprotocol_%d.bin", upto);
|
|
||||||
FILE* test = fopen (file, "wb");
|
|
||||||
for(i=0;i<0x20;i++)
|
|
||||||
fwrite(&test_out[i], 1, 1, test);
|
|
||||||
if (size > 0)
|
|
||||||
fwrite((char*)Memory::GetPointer(data), 1, size, test);
|
|
||||||
fclose(test);
|
|
||||||
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);
|
|
||||||
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Control)(%02X, %02X) = %d",
|
|
||||||
requesttype, request, ReturnValue);
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IOCTL_HID_INTERRUPT_IN:
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
|
|
||||||
u32 end_point = Memory::Read_U32(BufferIn+0x14);
|
|
||||||
u32 length = Memory::Read_U32(BufferIn+0x18);
|
|
||||||
|
|
||||||
u32 data = Memory::Read_U32(BufferIn+0x1C);
|
|
||||||
|
|
||||||
hid_device * dev_handle = GetDeviceByDevNumHidLib(dev_num);
|
|
||||||
|
|
||||||
if (dev_handle == NULL)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ReturnValue = -5;
|
|
||||||
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)",
|
|
||||||
end_point, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IOCTL_HID_INTERRUPT_OUT:
|
case IOCTL_HID_INTERRUPT_OUT:
|
||||||
|
case IOCTL_HID_INTERRUPT_IN:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
|
u32 dev_num = Memory::Read_U32(BufferIn+0x10);
|
||||||
u32 end_point = Memory::Read_U32(BufferIn+0x14);
|
u32 end_point = Memory::Read_U32(BufferIn+0x14);
|
||||||
u32 length = Memory::Read_U32(BufferIn+0x18);
|
u32 length = Memory::Read_U32(BufferIn+0x18);
|
||||||
|
|
||||||
u32 data = Memory::Read_U32(BufferIn+0x1C);
|
u32 data = Memory::Read_U32(BufferIn+0x1C);
|
||||||
|
int ret = 0;
|
||||||
hid_device * dev_handle = GetDeviceByDevNumHidLib(dev_num);
|
void * context = NULL;
|
||||||
|
|
||||||
|
struct usb_dev_handle * dev_handle = GetDeviceByDevNum(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)",
|
goto int_in_end_print;
|
||||||
ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue = -5;
|
usb_claim_interface(dev_handle,0);
|
||||||
//ReturnValue = usb_interrupt_write(dev_handle, end_point, (char*)Memory::GetPointer(data), length, 0);
|
|
||||||
|
ret = usb_interrupt_setup_async(dev_handle, &context, end_point);
|
||||||
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt Out) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
if (ret< 0)
|
||||||
ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
{
|
||||||
|
ReturnValue = -4;
|
||||||
|
goto int_in_end_print;
|
||||||
|
}
|
||||||
|
ret = usb_submit_async(context, (char*)Memory::GetPointer(data), length);
|
||||||
|
if (ret< 0)
|
||||||
|
{
|
||||||
|
ReturnValue = -4;
|
||||||
|
goto int_in_end_print;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = usb_reap_async_nocancel(context, 0);
|
||||||
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
ReturnValue = ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_hidevent ev;
|
||||||
|
ev.enq_address = _CommandAddress;
|
||||||
|
ev.type = Parameter;
|
||||||
|
ev.context = context;
|
||||||
|
event_list.push_back(ev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int_in_end_print:
|
||||||
|
DEBUG_LOG(WII_IPC_HID, "HID::IOCtl(Interrupt %s)(%d,%d,%p) = %d (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
|
||||||
|
Parameter == IOCTL_HID_INTERRUPT_IN ? "In" : "Out", end_point, length, data, ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -294,16 +281,24 @@ bool CWII_IPC_HLE_Device_hid::IOCtlV(u32 _CommandAddress)
|
||||||
u32 ReturnValue = 0;
|
u32 ReturnValue = 0;
|
||||||
SIOCtlVBuffer CommandBuffer(_CommandAddress);
|
SIOCtlVBuffer CommandBuffer(_CommandAddress);
|
||||||
|
|
||||||
DEBUG_LOG(WII_IPC_HID, "%s - IOCtlV:", GetDeviceName().c_str());
|
switch (CommandBuffer.Parameter)
|
||||||
DEBUG_LOG(WII_IPC_HID, " Parameter: 0x%x", CommandBuffer.Parameter);
|
{
|
||||||
DEBUG_LOG(WII_IPC_HID, " NumberIn: 0x%08x", CommandBuffer.NumberInBuffer);
|
|
||||||
DEBUG_LOG(WII_IPC_HID, " NumberOut: 0x%08x", CommandBuffer.NumberPayloadBuffer);
|
default:
|
||||||
DEBUG_LOG(WII_IPC_HID, " BufferVector: 0x%08x", CommandBuffer.BufferVector);
|
{
|
||||||
DEBUG_LOG(WII_IPC_HID, " PayloadAddr: 0x%08x", CommandBuffer.PayloadBuffer[0].m_Address);
|
DEBUG_LOG(WII_IPC_HID, "%s - IOCtlV:", GetDeviceName().c_str());
|
||||||
DEBUG_LOG(WII_IPC_HID, " PayloadSize: 0x%08x", CommandBuffer.PayloadBuffer[0].m_Size);
|
DEBUG_LOG(WII_IPC_HID, " Parameter: 0x%x", CommandBuffer.Parameter);
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
DEBUG_LOG(WII_IPC_HID, " NumberIn: 0x%08x", CommandBuffer.NumberInBuffer);
|
||||||
DumpAsync(CommandBuffer.BufferVector, CommandBuffer.NumberInBuffer, CommandBuffer.NumberPayloadBuffer);
|
DEBUG_LOG(WII_IPC_HID, " NumberOut: 0x%08x", CommandBuffer.NumberPayloadBuffer);
|
||||||
#endif
|
DEBUG_LOG(WII_IPC_HID, " BufferVector: 0x%08x", CommandBuffer.BufferVector);
|
||||||
|
DEBUG_LOG(WII_IPC_HID, " PayloadAddr: 0x%08x", CommandBuffer.PayloadBuffer[0].m_Address);
|
||||||
|
DEBUG_LOG(WII_IPC_HID, " PayloadSize: 0x%08x", CommandBuffer.PayloadBuffer[0].m_Size);
|
||||||
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
|
DumpAsync(CommandBuffer.BufferVector, CommandBuffer.NumberInBuffer, CommandBuffer.NumberPayloadBuffer);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Memory::Write_U32(ReturnValue, _CommandAddress + 4);
|
Memory::Write_U32(ReturnValue, _CommandAddress + 4);
|
||||||
return true;
|
return true;
|
||||||
|
@ -337,137 +332,15 @@ void CWII_IPC_HLE_Device_hid::ConvertEndpointToWii(WiiHIDEndpointDescriptor *des
|
||||||
dest->wMaxPacketSize = Common::swap16(dest->wMaxPacketSize);
|
dest->wMaxPacketSize = Common::swap16(dest->wMaxPacketSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x = 0;
|
|
||||||
u32 CWII_IPC_HLE_Device_hid::GetAvailableID(char* path)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
void CWII_IPC_HLE_Device_hid::FillOutDevicesHidApi(u32 BufferOut, u32 BufferOutSize)
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
// Enumerate and print the HID devices on the system
|
|
||||||
struct hid_device_info *devs, *cur_dev;
|
|
||||||
|
|
||||||
int OffsetBuffer = BufferOut;
|
|
||||||
int OffsetStart = 0;
|
|
||||||
int c,i,e; // config, interface container, interface, endpoint
|
|
||||||
|
|
||||||
devs = hid_enumerate(0x0, 0x0);
|
|
||||||
cur_dev = devs;
|
|
||||||
while (cur_dev) {
|
|
||||||
|
|
||||||
OffsetStart = OffsetBuffer;
|
|
||||||
OffsetBuffer += 4; // skip length for now, fill at end
|
|
||||||
|
|
||||||
Memory::Write_U32(GetAvailableID(cur_dev->path), OffsetBuffer); //write device num
|
|
||||||
OffsetBuffer += 4;
|
|
||||||
|
|
||||||
WiiHIDDeviceDescriptor wii_device;
|
|
||||||
|
|
||||||
wii_device.bLength = Common::swap8(0x12);
|
|
||||||
wii_device.bDescriptorType = Common::swap8(0x1);
|
|
||||||
wii_device.bcdUSB = Common::swap16(0x0200);
|
|
||||||
wii_device.bDeviceClass = Common::swap8(0);
|
|
||||||
wii_device.bDeviceSubClass = Common::swap8(0);
|
|
||||||
wii_device.bDeviceProtocol = Common::swap8(0);
|
|
||||||
wii_device.bMaxPacketSize0 = Common::swap8(0x20);
|
|
||||||
wii_device.idVendor = Common::swap16(cur_dev->vendor_id);
|
|
||||||
wii_device.idProduct = Common::swap16(cur_dev->product_id);
|
|
||||||
wii_device.bcdDevice = Common::swap16(cur_dev->release_number);
|
|
||||||
wii_device.iManufacturer = Common::swap8(0x1);
|
|
||||||
wii_device.iProduct = Common::swap8(0x2);
|
|
||||||
wii_device.iSerialNumber = Common::swap8(0);
|
|
||||||
wii_device.bNumConfigurations = Common::swap8(0x1);
|
|
||||||
|
|
||||||
Memory::WriteBigEData((const u8*)&wii_device, OffsetBuffer, Align(wii_device.bLength, 4));
|
|
||||||
|
|
||||||
OffsetBuffer += Align(wii_device.bLength, 4);
|
|
||||||
|
|
||||||
|
|
||||||
for (c = 0; c < Common::swap8(wii_device.bNumConfigurations); c++)
|
|
||||||
{
|
|
||||||
|
|
||||||
WiiHIDConfigDescriptor wii_config;
|
|
||||||
wii_config.bLength = Common::swap8(0x9);
|
|
||||||
wii_config.bDescriptorType = Common::swap8(0x2);
|
|
||||||
wii_config.wTotalLength = Common::swap16(0x29);
|
|
||||||
wii_config.bNumInterfaces = Common::swap8(0x1);
|
|
||||||
wii_config.bConfigurationValue = Common::swap8(0x1);
|
|
||||||
wii_config.iConfiguration = Common::swap8(0);
|
|
||||||
wii_config.bmAttributes = Common::swap8(0x80);
|
|
||||||
wii_config.MaxPower = Common::swap8(0x96);
|
|
||||||
|
|
||||||
Memory::WriteBigEData((const u8*)&wii_config, OffsetBuffer, Align(Common::swap8(wii_config.bLength), 4));
|
|
||||||
OffsetBuffer += Align(Common::swap8(wii_config.bLength), 4);
|
|
||||||
|
|
||||||
for (i = 0; i < wii_config.bNumInterfaces; i++)
|
|
||||||
{
|
|
||||||
WiiHIDInterfaceDescriptor wii_interface;
|
|
||||||
|
|
||||||
wii_interface.bLength = Common::swap8(0x9);
|
|
||||||
wii_interface.bDescriptorType = Common::swap8(0x4);
|
|
||||||
wii_interface.bInterfaceNumber = Common::swap8(i);
|
|
||||||
wii_interface.bAlternateSetting = Common::swap8(0);
|
|
||||||
wii_interface.bNumEndpoints = Common::swap8(0x2);
|
|
||||||
wii_interface.bInterfaceClass = Common::swap8(0x3);
|
|
||||||
wii_interface.bInterfaceSubClass = Common::swap8(0);
|
|
||||||
wii_interface.bInterfaceProtocol = Common::swap8(0);
|
|
||||||
wii_interface.iInterface = Common::swap8(0);
|
|
||||||
|
|
||||||
Memory::WriteBigEData((const u8*)&wii_interface, OffsetBuffer, Align(Common::swap8(wii_interface.bLength), 4));
|
|
||||||
OffsetBuffer += Align(Common::swap8(wii_interface.bLength), 4);
|
|
||||||
|
|
||||||
for (e = 0; e < Common::swap8(wii_interface.bNumEndpoints); e++)
|
|
||||||
{
|
|
||||||
WiiHIDEndpointDescriptor wii_endpoint;
|
|
||||||
wii_endpoint.bLength = Common::swap8(0x7);
|
|
||||||
wii_endpoint.bDescriptorType = Common::swap8(0x5);
|
|
||||||
wii_endpoint.bEndpointAddress = Common::swap8(e == 0 ? 0x1 : 0x81);
|
|
||||||
wii_endpoint.bmAttributes = Common::swap8(0x3);
|
|
||||||
wii_endpoint.wMaxPacketSize = Common::swap16(0x20);
|
|
||||||
wii_endpoint.bInterval = Common::swap8(0x1);
|
|
||||||
|
|
||||||
Memory::WriteBigEData((const u8*)&wii_endpoint, OffsetBuffer, Align(Common::swap8(wii_endpoint.bLength), 4));
|
|
||||||
OffsetBuffer += Align(Common::swap8(wii_endpoint.bLength), 4);
|
|
||||||
|
|
||||||
} //endpoints
|
|
||||||
} // interfaces
|
|
||||||
} // configs
|
|
||||||
|
|
||||||
Memory::Write_U32(OffsetBuffer-OffsetStart, OffsetStart); // fill in length
|
|
||||||
|
|
||||||
NOTICE_LOG(WII_IPC_HID, "Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls",
|
|
||||||
cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
|
|
||||||
NOTICE_LOG(WII_IPC_HID, "\n");
|
|
||||||
NOTICE_LOG(WII_IPC_HID, " Manufacturer: %ls\n", cur_dev->manufacturer_string);
|
|
||||||
NOTICE_LOG(WII_IPC_HID, " Product: %ls\n", cur_dev->product_string);
|
|
||||||
NOTICE_LOG(WII_IPC_HID, "\n");
|
|
||||||
cur_dev = cur_dev->next;
|
|
||||||
}
|
|
||||||
Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices
|
|
||||||
|
|
||||||
hid_free_enumeration(devs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// libusb version
|
|
||||||
void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
|
void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
|
||||||
{
|
{
|
||||||
FillOutDevicesHidApi(BufferOut, BufferOutSize);
|
usb_find_busses(); /* find all busses */
|
||||||
/*usb_find_busses(); // find all busses
|
usb_find_devices(); /* find all connected devices */
|
||||||
usb_find_devices(); // find all connected devices
|
|
||||||
struct usb_bus *bus;
|
struct usb_bus *bus;
|
||||||
struct usb_device *dev;
|
struct usb_device *dev;
|
||||||
int OffsetBuffer = BufferOut;
|
int OffsetBuffer = BufferOut;
|
||||||
int OffsetStart = 0;
|
int OffsetStart = 0;
|
||||||
int c,ic,i,e; // config, interface container, interface, endpoint
|
int c,ic,i,e; /* config, interface container, interface, endpoint */
|
||||||
for (bus = usb_get_busses(); bus; bus = bus->next)
|
for (bus = usb_get_busses(); bus; bus = bus->next)
|
||||||
{
|
{
|
||||||
for (dev = bus->devices; dev; dev = dev->next)
|
for (dev = bus->devices; dev; dev = dev->next)
|
||||||
|
@ -527,38 +400,34 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize)
|
||||||
} // buses
|
} // buses
|
||||||
|
|
||||||
Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices
|
Memory::Write_U32(0xFFFFFFFF, OffsetBuffer); // no more devices
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int CWII_IPC_HLE_Device_hid::Align(int num, int alignment)
|
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (open_devices.find(devNum) != open_devices.end())
|
||||||
|
return open_devices[devNum];
|
||||||
|
|
||||||
|
usb_dev_handle * device = NULL;
|
||||||
|
|
||||||
for (struct usb_bus *bus = usb_get_busses(); bus; bus = bus->next)
|
for (struct usb_bus *bus = usb_get_busses(); bus; bus = bus->next)
|
||||||
{
|
{
|
||||||
for (struct usb_device *dev = bus->devices; dev; dev = dev->next)
|
for (struct usb_device *dev = bus->devices; dev; dev = dev->next)
|
||||||
{
|
{
|
||||||
if(dev->devnum == devNum){
|
if(dev->devnum == devNum){
|
||||||
return usb_open(dev);
|
open_devices[devNum] = device = usb_open(dev);
|
||||||
|
|
||||||
|
return device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return device;
|
||||||
}
|
}
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
#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"
|
#include <list>
|
||||||
|
|
||||||
|
/* Connection timed out */ #define ETRANSFER_TIMEDOUT -116
|
||||||
|
|
||||||
class CWII_IPC_HLE_Device_hid : public IWII_IPC_HLE_Device
|
class CWII_IPC_HLE_Device_hid : public IWII_IPC_HLE_Device
|
||||||
{
|
{
|
||||||
|
@ -30,13 +32,12 @@ public:
|
||||||
|
|
||||||
virtual bool Open(u32 _CommandAddress, u32 _Mode);
|
virtual bool Open(u32 _CommandAddress, u32 _Mode);
|
||||||
virtual bool Close(u32 _CommandAddress, bool _bForce);
|
virtual bool Close(u32 _CommandAddress, bool _bForce);
|
||||||
|
virtual u32 Update();
|
||||||
|
|
||||||
virtual bool IOCtlV(u32 _CommandAddress);
|
virtual bool IOCtlV(u32 _CommandAddress);
|
||||||
virtual bool IOCtl(u32 _CommandAddress);
|
virtual bool IOCtl(u32 _CommandAddress);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
std::map<u32, std::string> deviceList;
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -112,10 +113,7 @@ private:
|
||||||
} WiiHIDEndpointDescriptor;
|
} WiiHIDEndpointDescriptor;
|
||||||
|
|
||||||
|
|
||||||
u32 GetAvailableID(char* path);
|
void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize);
|
||||||
|
|
||||||
void FillOutDevices(u32 BufferOut, u32 BufferOutSize);
|
|
||||||
void FillOutDevicesHidApi(u32 BufferOut, u32 BufferOutSize);
|
|
||||||
|
|
||||||
void ConvertDeviceToWii(WiiHIDDeviceDescriptor *dest, struct usb_device_descriptor *src);
|
void ConvertDeviceToWii(WiiHIDDeviceDescriptor *dest, struct usb_device_descriptor *src);
|
||||||
void ConvertConfigToWii(WiiHIDConfigDescriptor *dest, struct usb_config_descriptor *src);
|
void ConvertConfigToWii(WiiHIDConfigDescriptor *dest, struct usb_config_descriptor *src);
|
||||||
|
@ -123,8 +121,17 @@ 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);
|
||||||
|
std::map<u32,usb_dev_handle*> open_devices;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 enq_address;
|
||||||
|
u32 type;
|
||||||
|
void * context;
|
||||||
|
} _hidevent;
|
||||||
|
|
||||||
|
std::list<_hidevent> event_list;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalLibraryDirectories>..\..\..\Externals\SDL\$(PlatformName);..\..\..\Externals\GLew;..\..\..\Externals\Cg64;..\..\..\Externals\portaudio\$(PlatformName)\$(ConfigurationName);..\..\..\Externals\libusb\$(PlatformName)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>..\..\..\Externals\SDL\$(PlatformName);..\..\..\Externals\GLew;..\..\..\Externals\Cg64;..\..\..\Externals\portaudio\$(PlatformName)\$(ConfigurationName);..\..\..\Externals\libusb\$(PlatformName)</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>portaudio.lib;dsound.lib;dxerr.lib;iphlpapi.lib;winmm.lib;setupapi.lib;xinput.lib;vfw32.lib;cg.lib;cgGL.lib;opengl32.lib;glew64s.lib;glu32.lib;rpcrt4.lib;comctl32.lib;libusb.lib;hidapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>portaudio.lib;dsound.lib;dxerr.lib;iphlpapi.lib;winmm.lib;setupapi.lib;xinput.lib;vfw32.lib;cg.lib;cgGL.lib;opengl32.lib;glew64s.lib;glu32.lib;rpcrt4.lib;comctl32.lib;libusb.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
|
|
Loading…
Reference in New Issue