+
+void hmcfgusb_enter_bootloader(struct hmcfgusb_dev *dev)
+{
+ uint8_t out[ASYNC_SIZE];
+
+ if (dev->bootloader) {
+ fprintf(stderr, "request for bootloader mode, but device already in bootloader!\n");
+ return;
+ }
+
+ memset(out, 0, sizeof(out));
+ out[0] = 'B';
+ hmcfgusb_send(dev, out, sizeof(out), 1);
+
+ return;
+}
+
+void hmcfgusb_leave_bootloader(struct hmcfgusb_dev *dev)
+{
+ uint8_t out[ASYNC_SIZE];
+
+ if (!dev->bootloader) {
+ fprintf(stderr, "request for leaving bootloader mode, but device already in normal mode!\n");
+ return;
+ }
+
+ memset(out, 0, sizeof(out));
+ out[0] = 'K';
+ hmcfgusb_send(dev, out, sizeof(out), 1);
+
+ return;
+}
+
+void hmcfgusb_close(struct hmcfgusb_dev *dev)
+{
+ int err;
+
+ if (dev->transfer) {
+ libusb_cancel_transfer(dev->transfer);
+ libusb_handle_events(NULL);
+ }
+
+ err = libusb_release_interface(dev->usb_devh, INTERFACE);
+ if ((err != 0)) {
+ fprintf(stderr, "Can't release interface: %s\n", usb_strerror(err));
+ }
+
+ libusb_close(dev->usb_devh);
+#ifdef NEED_LIBUSB_EXIT
+ hmcfgusb_exit();
+#endif
+ free(dev->pfd);
+ free(dev);
+}
+
+void hmcfgusb_exit(void)
+{
+ if (libusb_initialized) {
+ libusb_exit(NULL);
+ libusb_initialized = 0;
+ }
+}
+
+void hmcfgusb_set_debug(int d)
+{
+ debug = d;
+}