From 36f83d18951d96da2e36c1148f69f67a691c9989 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 11 Apr 2020 23:28:05 +0200 Subject: [PATCH] Nocturn: Rename non-generic usb_* to noct_* --- nocturn.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/nocturn.c b/nocturn.c index 96cda66..7dd7888 100644 --- a/nocturn.c +++ b/nocturn.c @@ -20,8 +20,8 @@ #include "ursaryd.h" #include "usb.h" -static libusb_device_handle *usb_dev; -static bool usb_iface_claimed; +static libusb_device_handle *noct_dev; +static bool noct_iface_claimed; static void noct_error(int usb_err, char *text); @@ -41,7 +41,7 @@ static void noct_read_done(struct libusb_transfer *xfer) { byte *pkt = xfer->buffer; int len = xfer->actual_length; - DBG("USB: Read done: status %d, length %d", xfer->status, len); + DBG("Noct: Read done: status %d, length %d", xfer->status, len); noct_read_pending = 0; if (xfer->status != LIBUSB_TRANSFER_COMPLETED) @@ -50,7 +50,7 @@ static void noct_read_done(struct libusb_transfer *xfer) #ifdef LOCAL_DEBUG char buf[256]; mem_to_hex(buf, pkt, len, ' '); - DBG("USB: Read <%s>", buf); + DBG("Noct: Read <%s>", buf); #endif int i = 0; @@ -162,7 +162,7 @@ static void noct_read_init(void) DBG("Noct: Read init"); noct_read_xfer = libusb_alloc_transfer(0); - libusb_fill_interrupt_transfer(noct_read_xfer, usb_dev, 0x81, xmalloc(8), 8, noct_read_done, NULL, 0); + libusb_fill_interrupt_transfer(noct_read_xfer, noct_dev, 0x81, xmalloc(8), 8, noct_read_done, NULL, 0); int err; if ((err = libusb_submit_transfer(noct_read_xfer)) < 0) @@ -186,7 +186,7 @@ static void noct_sched_write(void); static void noct_write_done(struct libusb_transfer *xfer) { int len = xfer->actual_length; - DBG("USB: Write done: status %d, length %d", xfer->status, len); + DBG("Noct: Write done: status %d, length %d", xfer->status, len); if (xfer->status != LIBUSB_TRANSFER_COMPLETED) return noct_error(0, stk_printf("USB write failed with status %d", xfer->status)); @@ -199,7 +199,7 @@ static void noct_write_done(struct libusb_transfer *xfer) static void noct_do_write(uint cmd, uint arg) { - DBG("USB: Submitting write %02x %02x", cmd, arg); + DBG("Noct: Submitting write %02x %02x", cmd, arg); ASSERT(!noct_write_pending); noct_write_pending = 1; @@ -216,7 +216,7 @@ static void noct_do_write(uint cmd, uint arg) static void noct_sched_write(void) { - if (!usb_dev || noct_write_pending) + if (!noct_dev || noct_write_pending) return; if (noct_dirty_button) @@ -287,7 +287,7 @@ static void noct_write_init(void) DBG("Noct: Write init"); noct_write_xfer = libusb_alloc_transfer(0); - libusb_fill_interrupt_transfer(noct_write_xfer, usb_dev, 0x02, xmalloc(8), 0, noct_write_done, NULL, 1000); + libusb_fill_interrupt_transfer(noct_write_xfer, noct_dev, 0x02, xmalloc(8), 0, noct_write_done, NULL, 1000); bzero(noct_button_pressed, sizeof(noct_button_pressed)); bzero(noct_rotary_touched, sizeof(noct_rotary_touched)); @@ -337,24 +337,24 @@ static void noct_connect(struct main_timer *t) DBG("Initializing Nocturn"); - if ((err = libusb_open(found_dev, &usb_dev)) < 0) + if ((err = libusb_open(found_dev, &noct_dev)) < 0) return noct_error(err, "libusb_open failed"); // In newer kernels, Nocturn is claimed by snd-usb-audio. Tell it to surrender the device. - libusb_detach_kernel_driver(usb_dev, 0); + libusb_detach_kernel_driver(noct_dev, 0); // There exist configurations 1 (high brightness) and 2 (power-save) - if ((err = libusb_set_configuration(usb_dev, 2)) < 0) + if ((err = libusb_set_configuration(noct_dev, 2)) < 0) return noct_error(err, "libusb_set_configuration failed"); - if ((err = libusb_claim_interface(usb_dev, 0)) < 0) + if ((err = libusb_claim_interface(noct_dev, 0)) < 0) return noct_error(err, "libusb_claim_interface failed"); - usb_iface_claimed = 1; + noct_iface_claimed = 1; for (int i=0; i<4; i++) { int done; - if ((err = libusb_interrupt_transfer(usb_dev, 0x02, (byte *) noct_magic[i] + 1, noct_magic[i][0], &done, 5000)) < 0) + if ((err = libusb_interrupt_transfer(noct_dev, 0x02, (byte *) noct_magic[i] + 1, noct_magic[i][0], &done, 5000)) < 0) return noct_error(err, "Cannot send init packets"); if (done != noct_magic[i][0]) return noct_error(err, stk_printf("Partial send of init packet (%d < %d)", done, noct_magic[i][0])); @@ -370,7 +370,7 @@ static int noct_error_handler(struct main_hook *h) DBG("Noct: Entered error handling hook"); hook_del(h); - if (usb_dev) + if (noct_dev) { if (noct_read_xfer) { @@ -398,16 +398,16 @@ static int noct_error_handler(struct main_hook *h) libusb_free_transfer(noct_write_xfer); noct_write_xfer = NULL; } - if (usb_iface_claimed) + if (noct_iface_claimed) { DBG("Noct: Unclaiming interface"); - libusb_release_interface(usb_dev, 0); - usb_iface_claimed = 0; + libusb_release_interface(noct_dev, 0); + noct_iface_claimed = 0; } DBG("Noct: Resetting device"); - libusb_reset_device(usb_dev); - libusb_close(usb_dev); - usb_dev = NULL; + libusb_reset_device(noct_dev); + libusb_close(noct_dev); + noct_dev = NULL; } DBG("Noct: Scheduling rescan after error"); @@ -429,7 +429,7 @@ static void noct_error(int usb_err, char *text) bool noct_is_ready(void) { - return !!usb_dev; + return !!noct_dev; } void noct_init(void) -- 2.39.5