ref: f80e89b8eccdea0815e9f93be667c5aa95d01db8
parent: 3aefa632b813b36869384d1639f38f63ce99349e
author: Maido Käära <maido@producement.com>
date: Mon Dec 12 07:20:15 EST 2022
Claim interface
--- a/serial.c
+++ b/serial.c
@@ -65,19 +65,18 @@
}
int handle_from_file_descriptor(int fileDescriptor) {- libusb_context *ctx = NULL;
int r;
- r = libusb_set_option(ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
+ r = libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
if (r != LIBUSB_SUCCESS) { SDL_Log("libusb_init failed: %d\n", r);return r;
}
- r = libusb_init(&ctx);
+ r = libusb_init(NULL);
if (r < 0) { SDL_Log("libusb_init failed: %d\n", r);return r;
}
- r = libusb_wrap_sys_device(ctx, (intptr_t) fileDescriptor, &devh);
+ r = libusb_wrap_sys_device(NULL, (intptr_t) fileDescriptor, &devh);
if (r < 0) { SDL_Log("libusb_wrap_sys_device failed: %d\n", r);return r;
@@ -111,6 +110,18 @@
if (rc < 0) {return rc;
+ }
+
+ for (int if_num = 0; if_num < 2; if_num++) {+ if (libusb_kernel_driver_active(devh, if_num)) {+ libusb_detach_kernel_driver(devh, if_num);
+ }
+ rc = libusb_claim_interface(devh, if_num);
+ if (rc < 0) {+ fprintf(stderr, "Error claiming interface: %s\n",
+ libusb_error_name(rc));
+ return rc;
+ }
}
/* Start configuring the device:
--
⑨