From b293ceeb0d43a6bf1de781c3169ee367e0f0787f Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Tue, 19 Sep 2023 15:33:46 +0200 Subject: [PATCH] Basic driver name/image interaction --- Makefile | 1 + drivers/g-wolves/htx/htx.c | 13 +++++++++---- src/device/device.c | 22 ++++++++++++++++++++-- src/device/device.h | 1 + src/device/usb/usb.c | 18 +++++++----------- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 30df0e3..8b7cde0 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ $(BUILD_DIR)/glib-2.0/schemas/gschemas.compiled: v.ginput.gschema.xml | $(BUILD_ glib-compile-schemas . --targetdir=$(BUILD_DIR)/glib-2.0/schemas # Drivers +.PHONY: $(BUILD_DIR)/drivers $(BUILD_DIR)/drivers: cd drivers && make diff --git a/drivers/g-wolves/htx/htx.c b/drivers/g-wolves/htx/htx.c index acc8d0a..7604e30 100644 --- a/drivers/g-wolves/htx/htx.c +++ b/drivers/g-wolves/htx/htx.c @@ -4,14 +4,19 @@ #include #define DEVICE_NAME "HTX 4K" +#define DEVICE_VENDOR_ID 0x33e4 +#define DEVICE_PRODUCT_ID_WIRELESS 0x5707 -void driver_init(void) -{ - printf("Hello from G-Wolves HTX driver !\n"); -} +void driver_init(void) {} uint32_t driver_getkey(void) { + static int count = 0; + count++; + + if(count == 1) + return (DEVICE_VENDOR_ID << 16) | DEVICE_PRODUCT_ID_WIRELESS; + return 0; } diff --git a/src/device/device.c b/src/device/device.c index eafa08e..58cca78 100644 --- a/src/device/device.c +++ b/src/device/device.c @@ -1,10 +1,15 @@ #include "device.h" #include "utils/array.h" #include "usb/usb.h" +#include struct DEVICE { + // Device driver void* driver; + + // Physical device handle + void* handle; }; array_t* device_array; @@ -20,12 +25,25 @@ array_t* device_get_array() return device_array; } +device_t* device_register(void* driver, void* handle) +{ + device_t* tr = malloc(sizeof(device_t)); + tr->driver = driver; + tr->handle = handle; + + array_add(device_array, tr); + + return tr; +} + char* device_get_image(device_t* device) { - return "/home/valentin/Documents/prjs/ginput/drivers/g-wolves/htx/htx_0.png"; + char* (*getimage_fn)(void) = dlsym(device->driver, "driver_get_image"); + return getimage_fn(); } char* device_get_name(device_t* device) { - return "G-Wolves HTX 4K"; + char* (*getname_fn)(void) = dlsym(device->driver, "driver_get_name"); + return getname_fn(); } diff --git a/src/device/device.h b/src/device/device.h index a147f76..37f35f3 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -11,6 +11,7 @@ void device_init(); array_t* device_get_array(); // Handling a single device +device_t* device_register(void* driver, void* handle); char* device_get_image(device_t* device); char* device_get_name(device_t* device); diff --git a/src/device/usb/usb.c b/src/device/usb/usb.c index 22ed29b..d9ac22f 100644 --- a/src/device/usb/usb.c +++ b/src/device/usb/usb.c @@ -89,16 +89,12 @@ void usb_init() struct libusb_device_descriptor desc; libusb_get_device_descriptor(current, &desc); - // printf("Found usb device %04x:%04x\n", desc.idVendor, desc.idProduct); - // array_t* array = device_get_array(); - // array_add(array, 0); - - // libusb_device_handle* handle; - // libusb_open(current, &handle); - // char buf[4096] = {0}; - // libusb_get_string_descriptor_ascii(handle, 1, buf, 4096); - // printf("Device desc (1): %s\n", buf); - // libusb_get_string_descriptor_ascii(handle, 2, buf, 4096); - // printf("Device desc (2): %s\n", buf); + uint32_t key = (desc.idVendor << 16) | desc.idProduct; + void* driver = hashmap_get(usb_drivers, key); + if(!driver) continue; + + printf("Found driver for usb device %04x:%04x\n", desc.idVendor, desc.idProduct); + + device_register(driver, current); } }