diff --git a/hardware/ikalogic-scanalogic2/api.c b/hardware/ikalogic-scanalogic2/api.c index a9bb456f..501a58fe 100644 --- a/hardware/ikalogic-scanalogic2/api.c +++ b/hardware/ikalogic-scanalogic2/api.c @@ -27,7 +27,7 @@ static const int hwcaps[] = { SR_CONF_CAPTURE_RATIO, }; -SR_PRIV const uint64_t ikalogic_scanalogic2_samplerates[NUM_SAMPLERATES] = { +SR_PRIV const uint64_t sl2_samplerates[NUM_SAMPLERATES] = { SR_KHZ(1.25), SR_KHZ(10), SR_KHZ(50), @@ -81,9 +81,8 @@ static GSList *scan(GSList *options) for (l = usb_devices; l; l = l->next) { usb = l->data; - ret = ikalogic_scanalogic2_get_device_info(*usb, &dev_info); - if (ret != SR_OK) { - sr_warn("Failed to get device information."); + if ((ret = sl2_get_device_info(*usb, &dev_info)) < 0) { + sr_warn("Failed to get device information: %d.", ret); sr_usb_dev_inst_free(usb); continue; } @@ -148,7 +147,7 @@ static GSList *scan(GSList *options) devc->next_state = STATE_IDLE; /* Set default samplerate. */ - ikalogic_scanalogic2_set_samplerate(sdi, DEFAULT_SAMPLERATE); + sl2_set_samplerate(sdi, DEFAULT_SAMPLERATE); /* Set default capture ratio. */ devc->capture_ratio = 0; @@ -241,26 +240,24 @@ static int dev_open(struct sr_dev_inst *sdi) } } - ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); - if (ret) { + if ((ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE)) < 0) { sr_err("Failed to claim interface: %s.", libusb_error_name(ret)); return SR_ERR; } libusb_fill_control_transfer(devc->xfer_in, usb->devhdl, - devc->xfer_buf_in, ikalogic_scanalogic2_receive_transfer_in, + devc->xfer_buf_in, sl2_receive_transfer_in, sdi, USB_TIMEOUT); libusb_fill_control_transfer(devc->xfer_out, usb->devhdl, - devc->xfer_buf_out, ikalogic_scanalogic2_receive_transfer_out, + devc->xfer_buf_out, sl2_receive_transfer_out, sdi, USB_TIMEOUT); memset(buffer, 0, sizeof(buffer)); buffer[0] = CMD_RESET; - ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb->devhdl, buffer)) != PACKET_LENGTH) { sr_err("Device reset failed: %s.", libusb_error_name(ret)); return SR_ERR; } @@ -271,8 +268,7 @@ static int dev_open(struct sr_dev_inst *sdi) * and thereby close the connection. */ buffer[0] = CMD_IDLE; - ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb->devhdl, buffer)) != PACKET_LENGTH) { sr_err("Failed to set device in idle state: %s.", libusb_error_name(ret)); return SR_ERR; @@ -346,17 +342,15 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi) switch (key) { case SR_CONF_LIMIT_SAMPLES: limit_samples = g_variant_get_uint64(data); - ret = ikalogic_scanalogic2_set_limit_samples(sdi, - limit_samples); + ret = sl2_set_limit_samples(sdi, limit_samples); break; case SR_CONF_SAMPLERATE: samplerate = g_variant_get_uint64(data); - ret = ikalogic_scanalogic2_set_samplerate(sdi, samplerate); + ret = sl2_set_samplerate(sdi, samplerate); break; case SR_CONF_CAPTURE_RATIO: capture_ratio = g_variant_get_uint64(data); - ret = ikalogic_scanalogic2_set_capture_ratio(sdi, - capture_ratio); + ret = sl2_set_capture_ratio(sdi, capture_ratio); break; default: return SR_ERR_NA; @@ -383,8 +377,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) case SR_CONF_SAMPLERATE: g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), - ikalogic_scanalogic2_samplerates, - ARRAY_SIZE(ikalogic_scanalogic2_samplerates), + sl2_samplerates, ARRAY_SIZE(sl2_samplerates), sizeof(uint64_t)); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); *data = g_variant_builder_end(&gvb); @@ -426,8 +419,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) * The trigger must be configured first because the calculation of the * pre and post trigger samples depends on a configured trigger. */ - ikalogic_scanalogic2_configure_trigger(sdi); - ikalogic_scanalogic2_calculate_trigger_samples(sdi); + sl2_configure_trigger(sdi); + sl2_calculate_trigger_samples(sdi); trigger_bytes = devc->pre_trigger_bytes + devc->post_trigger_bytes; diff --git a/hardware/ikalogic-scanalogic2/protocol.c b/hardware/ikalogic-scanalogic2/protocol.c index 47f69cb0..75c78aca 100644 --- a/hardware/ikalogic-scanalogic2/protocol.c +++ b/hardware/ikalogic-scanalogic2/protocol.c @@ -22,7 +22,7 @@ extern struct sr_dev_driver ikalogic_scanalogic2_driver_info; static struct sr_dev_driver *di = &ikalogic_scanalogic2_driver_info; -extern uint64_t ikalogic_scanalogic2_samplerates[NUM_SAMPLERATES]; +extern uint64_t sl2_samplerates[NUM_SAMPLERATES]; static void stop_acquisition(struct sr_dev_inst *sdi) { @@ -202,8 +202,7 @@ static void process_sample_data(const struct sr_dev_inst *sdi) } } -SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, - void *cb_data) +SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -264,8 +263,7 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, return TRUE; } -SR_PRIV void ikalogic_scanalogic2_receive_transfer_in( - struct libusb_transfer *transfer) +SR_PRIV void sl2_receive_transfer_in( struct libusb_transfer *transfer) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -394,8 +392,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in( } } -SR_PRIV void ikalogic_scanalogic2_receive_transfer_out( - struct libusb_transfer *transfer) +SR_PRIV void sl2_receive_transfer_out( struct libusb_transfer *transfer) { struct sr_dev_inst *sdi; struct dev_context *devc; @@ -442,7 +439,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_out( } } -SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi, +SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct dev_context *devc; @@ -451,7 +448,7 @@ SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi, devc = sdi->priv; for (i = 0; i < NUM_SAMPLERATES; i++) { - if (ikalogic_scanalogic2_samplerates[i] == samplerate) { + if (sl2_samplerates[i] == samplerate) { devc->samplerate = samplerate; devc->samplerate_id = NUM_SAMPLERATES - i - 1; return SR_OK; @@ -461,8 +458,8 @@ SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi, return SR_ERR_ARG; } -SR_PRIV int ikalogic_scanalogic2_set_limit_samples( - const struct sr_dev_inst *sdi, uint64_t limit_samples) +SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi, + uint64_t limit_samples) { struct dev_context *devc; @@ -484,8 +481,7 @@ SR_PRIV int ikalogic_scanalogic2_set_limit_samples( return SR_OK; } -SR_PRIV void ikalogic_scanalogic2_configure_trigger( - const struct sr_dev_inst *sdi) +SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_probe *probe; @@ -541,8 +537,8 @@ SR_PRIV void ikalogic_scanalogic2_configure_trigger( devc->trigger_channel, devc->trigger_type); } -SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( - const struct sr_dev_inst *sdi, uint64_t capture_ratio) +SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, + uint64_t capture_ratio) { struct dev_context *devc; @@ -560,8 +556,8 @@ SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( return SR_OK; } -SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay( - const struct sr_dev_inst *sdi, uint64_t after_trigger_delay) +SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi, + uint64_t after_trigger_delay) { struct dev_context *devc; @@ -581,8 +577,7 @@ SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay( return SR_OK; } -SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples( - const struct sr_dev_inst *sdi) +SR_PRIV void sl2_calculate_trigger_samples(const struct sr_dev_inst *sdi) { struct dev_context *devc; uint64_t pre_trigger_samples, post_trigger_samples; @@ -636,7 +631,7 @@ SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples( devc->post_trigger_bytes = post_trigger_bytes; } -SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, +SR_PRIV int sl2_get_device_info(struct sr_usb_dev_inst usb, struct device_info *dev_info) { struct drv_context *drvc; @@ -683,9 +678,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, * device information. */ buffer[0] = CMD_RESET; - ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); - - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) { sr_err("Resetting of device failed: %s.", libusb_error_name(ret)); libusb_release_interface(usb.devhdl, USB_INTERFACE); @@ -694,9 +687,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, } buffer[0] = CMD_INFO; - ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); - - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) { sr_err("Requesting of device information failed: %s.", libusb_error_name(ret)); libusb_release_interface(usb.devhdl, USB_INTERFACE); @@ -704,9 +695,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, return SR_ERR; } - ret = ikalogic_scanalogic2_transfer_in(usb.devhdl, buffer); - - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_in(usb.devhdl, buffer)) != PACKET_LENGTH) { sr_err("Receiving of device information failed: %s.", libusb_error_name(ret)); libusb_release_interface(usb.devhdl, USB_INTERFACE); @@ -721,9 +710,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, dev_info->fw_ver_minor = buffer[6]; buffer[0] = CMD_RESET; - ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); - - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) { sr_err("Device reset failed: %s.", libusb_error_name(ret)); libusb_release_interface(usb.devhdl, USB_INTERFACE); libusb_close(usb.devhdl); @@ -736,9 +723,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, * and thereby close the connection. */ buffer[0] = CMD_IDLE; - ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); - - if (ret != PACKET_LENGTH) { + if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) { sr_err("Failed to set device in idle state: %s.", libusb_error_name(ret)); libusb_release_interface(usb.devhdl, USB_INTERFACE); @@ -760,16 +745,14 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, return SR_OK; } -SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, - uint8_t *data) +SR_PRIV int sl2_transfer_in(libusb_device_handle *dev_handle, uint8_t *data) { return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT); } -SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle, - uint8_t *data) +SR_PRIV int sl2_transfer_out(libusb_device_handle *dev_handle, uint8_t *data) { return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, diff --git a/hardware/ikalogic-scanalogic2/protocol.h b/hardware/ikalogic-scanalogic2/protocol.h index 54a5719e..1756ed96 100644 --- a/hardware/ikalogic-scanalogic2/protocol.h +++ b/hardware/ikalogic-scanalogic2/protocol.h @@ -227,29 +227,22 @@ struct dev_context { gboolean transfer_error; }; -SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, - void *cb_data); -SR_PRIV void ikalogic_scanalogic2_receive_transfer_in( - struct libusb_transfer *transfer); -SR_PRIV void ikalogic_scanalogic2_receive_transfer_out( - struct libusb_transfer *transfer); -SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi, +SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data); +SR_PRIV void sl2_receive_transfer_in(struct libusb_transfer *transfer); +SR_PRIV void sl2_receive_transfer_out(struct libusb_transfer *transfer); +SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate); -SR_PRIV int ikalogic_scanalogic2_set_limit_samples( - const struct sr_dev_inst *sdi, uint64_t limit_samples); -SR_PRIV void ikalogic_scanalogic2_configure_trigger( - const struct sr_dev_inst *sdi); -SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( - const struct sr_dev_inst *sdi, uint64_t capture_ratio); -SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay( - const struct sr_dev_inst *sdi, uint64_t after_trigger_delay); -SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples( - const struct sr_dev_inst *sdi); -SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb, +SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi, + uint64_t limit_samples); +SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi); +SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi, + uint64_t capture_ratio); +SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi, + uint64_t after_trigger_delay); +SR_PRIV void sl2_calculate_trigger_samples(const struct sr_dev_inst *sdi); +SR_PRIV int sl2_get_device_info(struct sr_usb_dev_inst usb, struct device_info *dev_info); -SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, - uint8_t *data); -SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle, - uint8_t *data); +SR_PRIV int sl2_transfer_in(libusb_device_handle *dev_handle, uint8_t *data); +SR_PRIV int sl2_transfer_out(libusb_device_handle *dev_handle, uint8_t *data); #endif