Added basic usb capabilities

master
vhaudiquet 1 year ago
parent b5d79ed77a
commit 10d037819e
  1. 4
      Makefile
  2. 28
      src/device/usb/usb.c
  3. 6
      src/device/usb/usb.h
  4. 3
      src/main.c

@ -1,8 +1,8 @@
NAME=ginput NAME=ginput
CC=gcc CC=gcc
CAMBALACHE=cambalache CAMBALACHE=cambalache
CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1) -O3 -I src CFLAGS=$(shell pkg-config --cflags gtk4 libadwaita-1 libusb-1.0) -O3 -I src
LDFLAGS=$(shell pkg-config --libs gtk4 libadwaita-1) LDFLAGS=$(shell pkg-config --libs gtk4 libadwaita-1 libusb-1.0)
BUILD_DIR=build BUILD_DIR=build
CMB := $(wildcard ui/*.cmb) CMB := $(wildcard ui/*.cmb)

@ -0,0 +1,28 @@
#include <libusb.h>
#include <stdio.h>
#include <stdlib.h>
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);
}
}

@ -0,0 +1,6 @@
#ifndef USB_H
#define USB_H
void usb_init();
#endif

@ -1,7 +1,10 @@
#include "ui/ginput-application.h" #include "ui/ginput-application.h"
#include "device/usb/usb.h"
int main(gint argc, gchar** argv) int main(gint argc, gchar** argv)
{ {
usb_init();
AdwApplication* application = ginput_application_new(); AdwApplication* application = ginput_application_new();
return g_application_run(G_APPLICATION(application), argc, argv); return g_application_run(G_APPLICATION(application), argc, argv);
} }

Loading…
Cancel
Save