Commit 9d27df8c authored by phil's avatar phil
Browse files

added usbhid_map

parent 36b0e96e
...@@ -7,3 +7,7 @@ ...@@ -7,3 +7,7 @@
[submodule "deps/hidapi"] [submodule "deps/hidapi"]
path = deps/hidapi path = deps/hidapi
url = https://github.com/libusb/hidapi url = https://github.com/libusb/hidapi
[submodule "deps/USB-HID-Report-Parser"]
path = deps/USB-HID-Report-Parser
url = https://github.com/tschiemer/USB-HID-Report-Parser
branch = usbhid_map
...@@ -2,19 +2,21 @@ ...@@ -2,19 +2,21 @@
PDLIBBUILDER_DIR=${CURDIR}/deps/pd-lib-builder PDLIBBUILDER_DIR=${CURDIR}/deps/pd-lib-builder
LIBUSB_DIR=${CURDIR}/deps/libusb LIBUSB_DIR=${CURDIR}/deps/libusb
HIDAPI_DIR=${CURDIR}/deps/hidapi HIDAPI_DIR=${CURDIR}/deps/hidapi
HIDMAP_DIR=${CURDIR}/deps/USB-HID-Report-Parser
cflags += -I${LIBUSB_DIR}/libusb -I${HIDAPI_DIR}/hidapi cflags += -I${LIBUSB_DIR}/libusb -I${HIDAPI_DIR}/hidapi -I${HIDMAP_DIR}
ldflags += -L${LIBUSB_DIR}/libusb -lusb -L${HIDAPI_DIR}/local-install/lib -lhidapi ldflags += -L${LIBUSB_DIR}/libusb -lusb -L${HIDAPI_DIR}/local-install/lib -lhidapi -L${HIDMAP_DIR} -lusbhid_map
export PDDIR export PDDIR
export PDLIBBUILDER_DIR export PDLIBBUILDER_DIR
export LIBUSB_DIR export LIBUSB_DIR
export HIDAPI_DIR export HIDAPI_DIR
export HIDMAP_DIR
export cflags export cflags
export ldflags export ldflags
all: libusb hidapi all: libusb hidapi usbhid_map
$(MAKE) -C src/hid $(MAKE) -C src/hid
install: install:
...@@ -51,4 +53,15 @@ ${HIDAPI_DIR}/Makefile: ${HIDAPI_DIR}/configure ...@@ -51,4 +53,15 @@ ${HIDAPI_DIR}/Makefile: ${HIDAPI_DIR}/configure
cd ${HIDAPI_DIR}; ./configure --prefix=${HIDAPI_DIR}/local-install cd ${HIDAPI_DIR}; ./configure --prefix=${HIDAPI_DIR}/local-install
${HIDAPI_DIR}/configure: ${HIDAPI_DIR}/configure:
cd ${HIDAPI_DIR}; ./bootstrap cd ${HIDAPI_DIR}; ./bootstrap
\ No newline at end of file
### usbhid_map
usbhid_map: ${HIDMAP_DIR}/libusbhid_map.a
${HIDMAP_DIR}/libusbhid_map.a: ${HIDMAP_DIR}/Makefile
$(MAKE) -C ${HIDMAP_DIR}
${HIDMAP_DIR}/Makefile:
cd ${HIDMAP_DIR}; cmake .
Subproject commit 5385005bd871fac599767c6af6104d797fe7f736
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include "m_pd.h" #include "m_pd.h"
#include "libusb.h" #include "libusb.h"
#include "hidapi.h" #include "hidapi.h"
#include "usbhid_map.h"
//#include "report_item.h"
//#include "report_usage.h"
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -33,6 +36,7 @@ typedef struct { ...@@ -33,6 +36,7 @@ typedef struct {
wchar_t * manufacturer_string; wchar_t * manufacturer_string;
wchar_t * product_string; wchar_t * product_string;
size_t report_desc_len;
uint8_t report_desc[]; uint8_t report_desc[];
#define hid_usage_page report_desc[1] #define hid_usage_page report_desc[1]
#define hid_usage report_desc[3] #define hid_usage report_desc[3]
...@@ -44,12 +48,19 @@ typedef struct { ...@@ -44,12 +48,19 @@ typedef struct {
libusb_context * usb_context; libusb_context * usb_context;
// currently open device //// currently open device
// local type
hid_device_t * hiddev; hid_device_t * hiddev;
// hidapi type
hid_device * handle; hid_device * handle;
// parsed hid report
usbhid_map_ref_t hid_map;
// option
uint8_t report_id; uint8_t report_id;
// polling option/logic
volatile int poll_ms; volatile int poll_ms;
pthread_t polling_thread; pthread_t polling_thread;
...@@ -240,6 +251,11 @@ static void hid_shutdown(hid_t *hid) ...@@ -240,6 +251,11 @@ static void hid_shutdown(hid_t *hid)
hid_free_device(hid->hiddev); hid_free_device(hid->hiddev);
hid->hiddev = NULL; hid->hiddev = NULL;
} }
if (hid->hid_map){
usbhid_map_free(hid->hid_map);
hid->hid_map = NULL;
}
} }
...@@ -373,12 +389,13 @@ static int hid_filter_device_list(libusb_device **devs, ssize_t count, hid_devic ...@@ -373,12 +389,13 @@ static int hid_filter_device_list(libusb_device **devs, ssize_t count, hid_devic
memcpy(&hiddev->desc, &desc, sizeof(struct libusb_device_descriptor)); memcpy(&hiddev->desc, &desc, sizeof(struct libusb_device_descriptor));
// on macos causes a fault...
// hiddev->config = config; // hiddev->config = config;
// config = NULL; // config = NULL;
post("if = %d", interface_num);
hiddev->interface_num = interface_num; hiddev->interface_num = interface_num;
hiddev->report_desc_len = r;
memcpy(hiddev->report_desc, report_desc, r); memcpy(hiddev->report_desc, report_desc, r);
/* Serial Number */ /* Serial Number */
...@@ -687,8 +704,21 @@ static void hid_cmd_open(hid_t *hid, t_symbol *s, int argc, t_atom *argv) ...@@ -687,8 +704,21 @@ static void hid_cmd_open(hid_t *hid, t_symbol *s, int argc, t_atom *argv)
} }
hid->poll_ms = 0;
hid->report_id = 0;
if (usbhid_map_parse_desc(&hid->hid_map, hiddevs[0]->report_desc, hiddevs[0]->report_desc_len)){
error("failed to parse HID descriptor");
hid_free_device_list(hiddevs);
return;
}
// TODO get default / validate report id
if (usbhid_map_get_report_ids(hid->hid_map, Input(0), &hid->report_id, 1) == 0){
error("no input reports");
}
post("report_id = %d", hid->report_id);
hid->handle = hid_open(hiddevs[0]->desc.idVendor, hiddevs[0]->desc.idProduct, hiddevs[0]->serial_string); hid->handle = hid_open(hiddevs[0]->desc.idVendor, hiddevs[0]->desc.idProduct, hiddevs[0]->serial_string);
...@@ -698,6 +728,8 @@ static void hid_cmd_open(hid_t *hid, t_symbol *s, int argc, t_atom *argv) ...@@ -698,6 +728,8 @@ static void hid_cmd_open(hid_t *hid, t_symbol *s, int argc, t_atom *argv)
return; return;
} }
hid->poll_ms = 0;
hid->hiddev = hiddevs[0]; hid->hiddev = hiddevs[0];
// just free list (not found device) // just free list (not found device)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment