Skip to content

Commit

Permalink
removed unnecessary submodules and makefile cleanup, macos claim bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tschiemer committed Mar 22, 2021
1 parent ed4d308 commit e7ad492
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 56 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "deps/pd-lib-builder"]
path = deps/pd-lib-builder
url = https://github.com/pure-data/pd-lib-builder/
[submodule "deps/libusb"]
path = deps/libusb
url = https://github.com/libusb/libusb
[submodule "deps/hidapi"]
path = deps/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
Expand Down
6 changes: 3 additions & 3 deletions Makefile.linux
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PDLIBBUILDER_DIR=${CURDIR}/deps/pd-lib-builder
LIBUSB_DIR=/usr/include/libusb-1.0
HIDAPI_DIR=/usr/include/hidapi
LIBUSB_DIR=/usr/include
HIDAPI_DIR=/usr/include
HIDMAP_DIR=${CURDIR}/deps/USB-HID-Report-Parser

# using invasive detaching.... ahem.

cflags += -I${LIBUSB_DIR} -I${HIDAPI_DIR} -I${HIDMAP_DIR} -DDETACH_KERNEL_DRIVER
cflags += -I${HIDMAP_DIR} -DDETACH_KERNEL_DRIVER
ldflags += -lusb-1.0 -lhidapi-libusb -L${HIDMAP_DIR} -lusbhid_map

export PDDIR
Expand Down
41 changes: 3 additions & 38 deletions Makefile.macos
Original file line number Diff line number Diff line change
@@ -1,56 +1,21 @@

PDLIBBUILDER_DIR=${CURDIR}/deps/pd-lib-builder
LIBUSB_DIR=${CURDIR}/deps/libusb
HIDAPI_DIR=${CURDIR}/deps/hidapi
HIDMAP_DIR=${CURDIR}/deps/USB-HID-Report-Parser

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 -L${HIDMAP_DIR} #-lusbhid_map
cflags += -I${HIDMAP_DIR}
ldflags += -lusb-1.0 -lhidapi

export PDDIR
export PDLIBBUILDER_DIR
export LIBUSB_DIR
export HIDAPI_DIR
export HIDMAP_DIR
export cflags
export ldflags


all: libusb hidapi #usbhid_map
all:
$(MAKE) -C src/hid

install:
$(MAKE) -C src/hid install

clean:
$(MAKE) -C src/hid clean
$(MAKE) -C ${LIBUSB_DIR} clean
$(MAKE) -C ${HIDAPI_DIR} clean


### libusbb

libusb: ${LIBUSB_DIR}/libusb/.libs/libusb-1.0.a

${LIBUSB_DIR}/libusb/.libs/libusb-1.0.a: ${LIBUSB_DIR}/Makefile
$(MAKE) -C ${LIBUSB_DIR}

${LIBUSB_DIR}/Makefile: ${LIBUSB_DIR}/configure
cd ${LIBUSB_DIR}; ./configure

${LIBUSB_DIR}/configure:
cd ${LIBUSB_DIR}; ./autogen.sh

### hidapi

hidapi: ${HIDAPI_DIR}/local-install/libhidapi.la

${HIDAPI_DIR}/local-install/libhidapi.la: ${HIDAPI_DIR}/Makefile
$(MAKE) -C ${HIDAPI_DIR}
$(MAKE) -C ${HIDAPI_DIR} install

${HIDAPI_DIR}/Makefile: ${HIDAPI_DIR}/configure
cd ${HIDAPI_DIR}; ./configure --prefix=${HIDAPI_DIR}/local-install

${HIDAPI_DIR}/configure:
cd ${HIDAPI_DIR}; ./bootstrap
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ Tested RPi 4 (5.10.17-v7l+), in principle works but is suboptimal.

### macos

*Should* work as is..
Install dependencies:
```bash
brew install libusb hidapi
```

Compile:
```bash
git clone --recursive https://github.com/tschiemer/hid-pd-external
cd hid-pd-external/
Expand All @@ -31,8 +35,6 @@ make -f Makefile.macos && make -f Makefile.macos install

### linux (Raspberry Pi)

A bit more troublesome.. these instructions might not get you all the way, but should be a start.

*NOTE* as it is, using libusb (in this external) on linux is somewhat invasive on USB devices as kernel
drivers might be detached for this to work. Using hidraw (as offered by hidapi) this seems to work without
further problem, but this is something that remains to be done.
Expand Down
2 changes: 1 addition & 1 deletion deps/USB-HID-Report-Parser
1 change: 0 additions & 1 deletion deps/hidapi
Submodule hidapi deleted from 6a01f3
1 change: 0 additions & 1 deletion deps/libusb
Submodule libusb deleted from bda234
11 changes: 8 additions & 3 deletions src/hid/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#include "m_pd.h"
#include "usbhid_map.h"

#include <libusb.h>
#include <hidapi.h>
//#include "report_item.h"
//#include "report_usage.h"

#include <libusb-1.0/libusb.h>
#include <hidapi/hidapi.h>

#include <stdlib.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -391,10 +392,13 @@ static int hid_filter_device_list(libusb_device **devs, ssize_t count, hid_devic
}
#endif

#if !__APPLE__
r = libusb_claim_interface(handle, interface_num);
if (r < 0) {
error("claim_interface(): %d", r);
} else {
} else
#endif
{

uint8_t report_desc[256];
r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE,
Expand Down Expand Up @@ -490,6 +494,7 @@ static int hid_filter_device_list(libusb_device **devs, ssize_t count, hid_devic
// post("usage (page) = %d (%d)", report_desc[3], report_desc[1]);
}
}

} // claimed

#ifdef DETACH_KERNEL_DRIVER
Expand Down

0 comments on commit e7ad492

Please sign in to comment.