From 10d037819eb6eb87dc260b20514e7cbd346a9e85 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Tue, 12 Sep 2023 13:58:29 +0200 Subject: [PATCH] Added basic usb capabilities --- Makefile | 4 ++-- src/device/usb/usb.c | 28 ++++++++++++++++++++++++++++ src/device/usb/usb.h | 6 ++++++ src/main.c | 3 +++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/device/usb/usb.c create mode 100644 src/device/usb/usb.h diff --git a/Makefile b/Makefile index 7505c6b..8a9f984 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ NAME=ginput CC=gcc CAMBALACHE=cambalache -CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1) -O3 -I src -LDFLAGS=$(shell pkg-config --libs gtk4 libadwaita-1) +CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1 libusb-1.0) -O3 -I src +LDFLAGS=$(shell pkg-config --libs gtk4 libadwaita-1 libusb-1.0) BUILD_DIR=build CMB := $(wildcard ui/*.cmb) diff --git a/src/device/usb/usb.c b/src/device/usb/usb.c new file mode 100644 index 0000000..c62cf25 --- /dev/null +++ b/src/device/usb/usb.c @@ -0,0 +1,28 @@ +#include +#include +#include + +void usb_init() +{ + // List all usb devices obtaining 'vendor:product' + // Call corresponding driver if it exists, so + // that we get a peripheral handle + if(libusb_init(NULL)) + { + fprintf(stderr, "Error: Could not initialize libusb\n"); + return; + } + + libusb_device** list; + ssize_t device_count = libusb_get_device_list(NULL, &list); + if(device_count <= 0) return; + + for(ssize_t i = 0; i < device_count; i++) + { + libusb_device* current = list[i]; + struct libusb_device_descriptor desc; + libusb_get_device_descriptor(current, &desc); + + printf("Found usb device %04x:%04x\n", desc.idVendor, desc.idProduct); + } +} diff --git a/src/device/usb/usb.h b/src/device/usb/usb.h new file mode 100644 index 0000000..f56f1f9 --- /dev/null +++ b/src/device/usb/usb.h @@ -0,0 +1,6 @@ +#ifndef USB_H +#define USB_H + +void usb_init(); + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 5d4edc0..112dafd 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,10 @@ #include "ui/ginput-application.h" +#include "device/usb/usb.h" int main(gint argc, gchar** argv) { + usb_init(); + AdwApplication* application = ginput_application_new(); return g_application_run(G_APPLICATION(application), argc, argv); }