From c2ae875a8269cd3a1529938d3ab3b418d5a69239 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Tue, 19 Sep 2023 15:06:41 +0200 Subject: [PATCH] Proof-of-concept driver added --- Makefile | 8 ++++++-- drivers/Makefile | 12 ++++++++++++ drivers/g-wolves/Makefile | 7 +++++++ drivers/g-wolves/htx/Makefile | 10 ++++++++++ drivers/g-wolves/htx/htx.c | 26 ++++++++++++++++++++++++++ src/device/device.c | 2 +- src/device/usb/usb.c | 22 +++++++++++----------- 7 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 drivers/Makefile create mode 100644 drivers/g-wolves/Makefile create mode 100644 drivers/g-wolves/htx/Makefile create mode 100644 drivers/g-wolves/htx/htx.c diff --git a/Makefile b/Makefile index fd6217d..30df0e3 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ NAME=ginput CC=gcc -CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1 libusb-1.0) -O3 -I src +CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1 libusb-1.0) -O3 -Wall -I src LDFLAGS=$(shell pkg-config --libs gtk4 libadwaita-1 libusb-1.0) BUILD_DIR=build UI := $(shell find ui/ -name '*.ui') C_FILES := $(shell find src/ -name '*.c') -all: resources $(BUILD_DIR)/$(NAME) +all: resources $(BUILD_DIR)/$(NAME) $(BUILD_DIR)/drivers # Top-level targets resources: $(BUILD_DIR)/glib-2.0/schemas/gschemas.compiled @@ -29,6 +29,10 @@ $(BUILD_DIR)/glib-2.0/schemas/gschemas.compiled: v.ginput.gschema.xml | $(BUILD_ mkdir -p $(BUILD_DIR)/glib-2.0/schemas glib-compile-schemas . --targetdir=$(BUILD_DIR)/glib-2.0/schemas +# Drivers +$(BUILD_DIR)/drivers: + cd drivers && make + # Phony targets .PHONY: clean clean: diff --git a/drivers/Makefile b/drivers/Makefile new file mode 100644 index 0000000..c8dc9ce --- /dev/null +++ b/drivers/Makefile @@ -0,0 +1,12 @@ +SUBDIRS := $(wildcard */.) +BUILD_DIR=../build/ + +all: $(BUILD_DIR)/drivers/ $(SUBDIRS) + +$(SUBDIRS): + $(MAKE) -C $@ + +.PHONY: all $(SUBDIRS) + +$(BUILD_DIR)/drivers/: + mkdir -p $(BUILD_DIR)/drivers/ diff --git a/drivers/g-wolves/Makefile b/drivers/g-wolves/Makefile new file mode 100644 index 0000000..61533ed --- /dev/null +++ b/drivers/g-wolves/Makefile @@ -0,0 +1,7 @@ +SUBDIRS := $(wildcard */.) + +all: $(SUBDIRS) +$(SUBDIRS): + $(MAKE) -C $@ + +.PHONY: all $(SUBDIRS) diff --git a/drivers/g-wolves/htx/Makefile b/drivers/g-wolves/htx/Makefile new file mode 100644 index 0000000..d9f97a2 --- /dev/null +++ b/drivers/g-wolves/htx/Makefile @@ -0,0 +1,10 @@ +CC=gcc +CFLAGS=$(shell pkg-config --cflags libusb-1.0) -O3 -Wall -shared +LDFLAGS=$(shell pkg-config --libs libusb-1.0) + +BUILD_DIR=../../../build/ + +all: $(BUILD_DIR)/drivers/gwolves-htx.so + +$(BUILD_DIR)/drivers/gwolves-htx.so: htx.c | $(BUILD_DIR)/drivers/ + gcc $(CFLAGS) -o $@ $^ diff --git a/drivers/g-wolves/htx/htx.c b/drivers/g-wolves/htx/htx.c new file mode 100644 index 0000000..acc8d0a --- /dev/null +++ b/drivers/g-wolves/htx/htx.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#define DEVICE_NAME "HTX 4K" + +void driver_init(void) +{ + printf("Hello from G-Wolves HTX driver !\n"); +} + +uint32_t driver_getkey(void) +{ + return 0; +} + +char* driver_get_name(void) +{ + return DEVICE_NAME; +} + +char* driver_get_image(void) +{ + return "g-wolves/htx/htx_0.png"; +} diff --git a/src/device/device.c b/src/device/device.c index afae99d..eafa08e 100644 --- a/src/device/device.c +++ b/src/device/device.c @@ -4,7 +4,7 @@ struct DEVICE { - + void* driver; }; array_t* device_array; diff --git a/src/device/usb/usb.c b/src/device/usb/usb.c index 80fcfc4..22ed29b 100644 --- a/src/device/usb/usb.c +++ b/src/device/usb/usb.c @@ -89,16 +89,16 @@ 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); + // 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); } }