From 65a378a469efb435d6f5949a67b1f7ed1b1f5082 Mon Sep 17 00:00:00 2001 From: surkeh Date: Mon, 17 Aug 2020 18:06:07 -0700 Subject: [PATCH] Prototyping, dig into libusb to figure out asnyc data handling --- .gitignore | 95 ++++++++++++++++++++++++++++++++ Makefile | 5 +- hanvon-libusb.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 hanvon-libusb.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3e6aea --- /dev/null +++ b/.gitignore @@ -0,0 +1,95 @@ +# +# NOTE! Don't add files that are generated in specific +# subdirectories here. Add them in the ".gitignore" file +# in that subdirectory instead. +# +# NOTE! Please use 'git ls-files -i --exclude-standard' +# command after changing this file, to see if there are +# any tracked files which get ignored after the change. +# +# Normal rules +# +.* +*.o +*.o.* +*.a +*.s +*.ko +*.so +*.so.dbg +*.mod.c +*.i +*.lst +*.symtypes +*.order +modules.builtin +*.elf +*.bin +*.gz +*.bz2 +*.lzma +*.xz +*.lzo +*.patch +*.gcno +a.out + +# +# Top-level generic files +# +/tags +/TAGS +/linux +/vmlinux +/vmlinuz +/System.map +/Module.markers +Module.symvers + +# +# Debian directory (make deb-pkg) +# +/debian/ + +# +# git files that we don't want to ignore even it they are dot-files +# +!.gitignore +!.mailmap + +# +# Generated include files +# +include/config +include/linux/version.h +include/generated +arch/*/include/generated + +# stgit generated dirs +patches-* + +# quilt's files +patches +series + +# cscope files +cscope.* +ncscope.* + +# gnu global files +GPATH +GRTAGS +GSYMS +GTAGS + +*.orig +*~ +\#*# + +# +# Leavings from module signing +# +extra_certificates +signing_key.priv +signing_key.x509 +x509.genkey diff --git a/Makefile b/Makefile index 8b178f8..113861b 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,7 @@ obj-m += hanvon.o all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + gcc -L/usr/local/lib -lusb-1.0 hanvon-libusb.c -g -clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean - archive: tar f - --exclude=.git -C ../ -c hanvon | gzip -c9 > ../hanvon-`date +%Y%m%d`.tgz diff --git a/hanvon-libusb.c b/hanvon-libusb.c new file mode 100644 index 0000000..88aec2c --- /dev/null +++ b/hanvon-libusb.c @@ -0,0 +1,143 @@ +/* + * ===================================================================================== + * + * Filename: hanvon-libusb.c + * + * Description: Libusb GP0504 handler prototype + * + * Version: 0.1 + * Created: 08/17/2020 04:05:14 PM + * Revision: none + * Compiler: gcc + * + * Author: surkeh@protonmail.com + * + * ===================================================================================== + */ + +#include +#include +#include + +#define STATE_SUCCESS 0 +#define STATE_NOT_FOUND 1 + +#define UNREF_DEVICE 1 +#define KEEP_DEVICE_REF 0 + +#define VENDOR_ID_HANVON 0x0b57 +#define PRODUCT_ID_AM3M 0x8528 +#define PRODUCT_ID_AM0806 0x8502 +#define PRODUCT_ID_AM0605 0x8503 +#define PRODUCT_ID_AM1107 0x8505 +#define PRODUCT_ID_AM1209 0x8501 +#define PRODUCT_ID_RL0604 0x851f +#define PRODUCT_ID_RL0504 0x851d +#define PRODUCT_ID_GP0806 0x8039 +#define PRODUCT_ID_GP0806B 0x8511 +#define PRODUCT_ID_GP0605 0x8512 +#define PRODUCT_ID_GP0605A 0x803a +#define PRODUCT_ID_GP0504 0x8037 +#define PRODUCT_ID_NXS1513 0x8030 +#define PRODUCT_ID_GP0906 0x8521 +#define PRODUCT_ID_APPIV0906 0x8532 + +#define AM_PACKET_LEN 10 + +//static int lbuttons[]={BTN_0,BTN_1,BTN_2,BTN_3}; /* reported on all AMs */ +//static int rbuttons[]={BTN_4,BTN_5,BTN_6,BTN_7}; /* reported on AM1107+ */ + +#define AM_WHEEL_THRESHOLD 4 + +#define AM_MAX_TILT_X 0x3f +#define AM_MAX_TILT_Y 0x7f +#define AM_MAX_PRESSURE 0x400 + + + +struct hanvon { + unsigned char *data; + //dma_addr_t data_dma; + struct input_dev *dev; + struct usb_device *usbdev; + struct urb *irq; + int old_wheel_pos; + char phys[32]; +}; + + + +libusb_device *FindHanvon( libusb_context **context); +int HandleData( void ); + + + +int main() +{ + libusb_context **context; + libusb_device *device; + libusb_device_handle *handle; + + int state = libusb_init( &context ); + if( state != STATE_SUCCESS ) + return state; + + device = FindHanvon( context ); + if( device == NULL ) + return STATE_NOT_FOUND; + + state = libusb_open( device, &handle ); + if( state != STATE_SUCCESS ) + return state; + + + // Wait and handle interrupts? + + return state; +} + + + +libusb_device *FindHanvon( libusb_context **context) +{ + libusb_device **deviceList; + libusb_device *found = NULL; + ssize_t nDevices = libusb_get_device_list( context[0], &deviceList); + if( nDevices > 0 ) + { + struct libusb_device_descriptor description; + + for( ssize_t i = 0; i < nDevices; i++ ) + { + libusb_device *device = deviceList[i]; + libusb_get_device_descriptor(device, &description); + printf( "Dev%u ID %04x:%04x\n", (i + 1), description.idVendor, description.idProduct ); + if( description.idVendor == VENDOR_ID_HANVON ) + { + switch( description.idProduct ) + case PRODUCT_ID_AM0806: + case PRODUCT_ID_AM0605: + case PRODUCT_ID_AM1107: + case PRODUCT_ID_AM1209: + case PRODUCT_ID_RL0604: + case PRODUCT_ID_RL0504: + case PRODUCT_ID_GP0806: + case PRODUCT_ID_GP0806B: + case PRODUCT_ID_GP0605: + case PRODUCT_ID_GP0605A: + case PRODUCT_ID_GP0504: + case PRODUCT_ID_NXS1513: + case PRODUCT_ID_GP0906: + case PRODUCT_ID_APPIV0906: + found = device; + break; + } + } + printf( "\n\n" ); + } + + libusb_free_device_list( deviceList, UNREF_DEVICE ); + return found; +} + +