scanalogic2: Shorten a few function name prefixes.

The driver-private helper functions in protocol.c can have a shorter
prefix to make the code look nicer.
This commit is contained in:
Uwe Hermann 2013-06-11 18:55:47 +02:00
parent c824eb6323
commit 79914b3a62
3 changed files with 52 additions and 83 deletions

View File

@ -27,7 +27,7 @@ static const int hwcaps[] = {
SR_CONF_CAPTURE_RATIO, 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(1.25),
SR_KHZ(10), SR_KHZ(10),
SR_KHZ(50), SR_KHZ(50),
@ -81,9 +81,8 @@ static GSList *scan(GSList *options)
for (l = usb_devices; l; l = l->next) { for (l = usb_devices; l; l = l->next) {
usb = l->data; usb = l->data;
ret = ikalogic_scanalogic2_get_device_info(*usb, &dev_info); if ((ret = sl2_get_device_info(*usb, &dev_info)) < 0) {
if (ret != SR_OK) { sr_warn("Failed to get device information: %d.", ret);
sr_warn("Failed to get device information.");
sr_usb_dev_inst_free(usb); sr_usb_dev_inst_free(usb);
continue; continue;
} }
@ -148,7 +147,7 @@ static GSList *scan(GSList *options)
devc->next_state = STATE_IDLE; devc->next_state = STATE_IDLE;
/* Set default samplerate. */ /* Set default samplerate. */
ikalogic_scanalogic2_set_samplerate(sdi, DEFAULT_SAMPLERATE); sl2_set_samplerate(sdi, DEFAULT_SAMPLERATE);
/* Set default capture ratio. */ /* Set default capture ratio. */
devc->capture_ratio = 0; 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 = libusb_claim_interface(usb->devhdl, USB_INTERFACE)) < 0) {
if (ret) {
sr_err("Failed to claim interface: %s.", sr_err("Failed to claim interface: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
libusb_fill_control_transfer(devc->xfer_in, usb->devhdl, 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); sdi, USB_TIMEOUT);
libusb_fill_control_transfer(devc->xfer_out, usb->devhdl, 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); sdi, USB_TIMEOUT);
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
buffer[0] = CMD_RESET; buffer[0] = CMD_RESET;
ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); if ((ret = sl2_transfer_out(usb->devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Device reset failed: %s.", libusb_error_name(ret)); sr_err("Device reset failed: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
@ -271,8 +268,7 @@ static int dev_open(struct sr_dev_inst *sdi)
* and thereby close the connection. * and thereby close the connection.
*/ */
buffer[0] = CMD_IDLE; buffer[0] = CMD_IDLE;
ret = ikalogic_scanalogic2_transfer_out(usb->devhdl, buffer); if ((ret = sl2_transfer_out(usb->devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Failed to set device in idle state: %s.", sr_err("Failed to set device in idle state: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
return SR_ERR; return SR_ERR;
@ -346,17 +342,15 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
switch (key) { switch (key) {
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
limit_samples = g_variant_get_uint64(data); limit_samples = g_variant_get_uint64(data);
ret = ikalogic_scanalogic2_set_limit_samples(sdi, ret = sl2_set_limit_samples(sdi, limit_samples);
limit_samples);
break; break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
samplerate = g_variant_get_uint64(data); samplerate = g_variant_get_uint64(data);
ret = ikalogic_scanalogic2_set_samplerate(sdi, samplerate); ret = sl2_set_samplerate(sdi, samplerate);
break; break;
case SR_CONF_CAPTURE_RATIO: case SR_CONF_CAPTURE_RATIO:
capture_ratio = g_variant_get_uint64(data); capture_ratio = g_variant_get_uint64(data);
ret = ikalogic_scanalogic2_set_capture_ratio(sdi, ret = sl2_set_capture_ratio(sdi, capture_ratio);
capture_ratio);
break; break;
default: default:
return SR_ERR_NA; 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: case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
ikalogic_scanalogic2_samplerates, sl2_samplerates, ARRAY_SIZE(sl2_samplerates),
ARRAY_SIZE(ikalogic_scanalogic2_samplerates),
sizeof(uint64_t)); sizeof(uint64_t));
g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
*data = g_variant_builder_end(&gvb); *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 * The trigger must be configured first because the calculation of the
* pre and post trigger samples depends on a configured trigger. * pre and post trigger samples depends on a configured trigger.
*/ */
ikalogic_scanalogic2_configure_trigger(sdi); sl2_configure_trigger(sdi);
ikalogic_scanalogic2_calculate_trigger_samples(sdi); sl2_calculate_trigger_samples(sdi);
trigger_bytes = devc->pre_trigger_bytes + devc->post_trigger_bytes; trigger_bytes = devc->pre_trigger_bytes + devc->post_trigger_bytes;

View File

@ -22,7 +22,7 @@
extern struct sr_dev_driver ikalogic_scanalogic2_driver_info; extern struct sr_dev_driver ikalogic_scanalogic2_driver_info;
static struct sr_dev_driver *di = &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) 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, SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data)
void *cb_data)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct dev_context *devc; struct dev_context *devc;
@ -264,8 +263,7 @@ SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents,
return TRUE; return TRUE;
} }
SR_PRIV void ikalogic_scanalogic2_receive_transfer_in( SR_PRIV void sl2_receive_transfer_in( struct libusb_transfer *transfer)
struct libusb_transfer *transfer)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct dev_context *devc; struct dev_context *devc;
@ -394,8 +392,7 @@ SR_PRIV void ikalogic_scanalogic2_receive_transfer_in(
} }
} }
SR_PRIV void ikalogic_scanalogic2_receive_transfer_out( SR_PRIV void sl2_receive_transfer_out( struct libusb_transfer *transfer)
struct libusb_transfer *transfer)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct dev_context *devc; 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) uint64_t samplerate)
{ {
struct dev_context *devc; struct dev_context *devc;
@ -451,7 +448,7 @@ SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi,
devc = sdi->priv; devc = sdi->priv;
for (i = 0; i < NUM_SAMPLERATES; i++) { for (i = 0; i < NUM_SAMPLERATES; i++) {
if (ikalogic_scanalogic2_samplerates[i] == samplerate) { if (sl2_samplerates[i] == samplerate) {
devc->samplerate = samplerate; devc->samplerate = samplerate;
devc->samplerate_id = NUM_SAMPLERATES - i - 1; devc->samplerate_id = NUM_SAMPLERATES - i - 1;
return SR_OK; return SR_OK;
@ -461,8 +458,8 @@ SR_PRIV int ikalogic_scanalogic2_set_samplerate(const struct sr_dev_inst *sdi,
return SR_ERR_ARG; return SR_ERR_ARG;
} }
SR_PRIV int ikalogic_scanalogic2_set_limit_samples( SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi,
const struct sr_dev_inst *sdi, uint64_t limit_samples) uint64_t limit_samples)
{ {
struct dev_context *devc; struct dev_context *devc;
@ -484,8 +481,7 @@ SR_PRIV int ikalogic_scanalogic2_set_limit_samples(
return SR_OK; return SR_OK;
} }
SR_PRIV void ikalogic_scanalogic2_configure_trigger( SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi)
const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_probe *probe; struct sr_probe *probe;
@ -541,8 +537,8 @@ SR_PRIV void ikalogic_scanalogic2_configure_trigger(
devc->trigger_channel, devc->trigger_type); devc->trigger_channel, devc->trigger_type);
} }
SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi,
const struct sr_dev_inst *sdi, uint64_t capture_ratio) uint64_t capture_ratio)
{ {
struct dev_context *devc; struct dev_context *devc;
@ -560,8 +556,8 @@ SR_PRIV int ikalogic_scanalogic2_set_capture_ratio(
return SR_OK; return SR_OK;
} }
SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay( SR_PRIV int sl2_set_after_trigger_delay(const struct sr_dev_inst *sdi,
const struct sr_dev_inst *sdi, uint64_t after_trigger_delay) uint64_t after_trigger_delay)
{ {
struct dev_context *devc; struct dev_context *devc;
@ -581,8 +577,7 @@ SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay(
return SR_OK; return SR_OK;
} }
SR_PRIV void ikalogic_scanalogic2_calculate_trigger_samples( SR_PRIV void sl2_calculate_trigger_samples(const struct sr_dev_inst *sdi)
const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
uint64_t pre_trigger_samples, post_trigger_samples; 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; 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 device_info *dev_info)
{ {
struct drv_context *drvc; struct drv_context *drvc;
@ -683,9 +678,7 @@ SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb,
* device information. * device information.
*/ */
buffer[0] = CMD_RESET; buffer[0] = CMD_RESET;
ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Resetting of device failed: %s.", sr_err("Resetting of device failed: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
libusb_release_interface(usb.devhdl, USB_INTERFACE); 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; buffer[0] = CMD_INFO;
ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Requesting of device information failed: %s.", sr_err("Requesting of device information failed: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
libusb_release_interface(usb.devhdl, USB_INTERFACE); 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; return SR_ERR;
} }
ret = ikalogic_scanalogic2_transfer_in(usb.devhdl, buffer); if ((ret = sl2_transfer_in(usb.devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Receiving of device information failed: %s.", sr_err("Receiving of device information failed: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
libusb_release_interface(usb.devhdl, USB_INTERFACE); 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]; dev_info->fw_ver_minor = buffer[6];
buffer[0] = CMD_RESET; buffer[0] = CMD_RESET;
ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Device reset failed: %s.", libusb_error_name(ret)); sr_err("Device reset failed: %s.", libusb_error_name(ret));
libusb_release_interface(usb.devhdl, USB_INTERFACE); libusb_release_interface(usb.devhdl, USB_INTERFACE);
libusb_close(usb.devhdl); 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. * and thereby close the connection.
*/ */
buffer[0] = CMD_IDLE; buffer[0] = CMD_IDLE;
ret = ikalogic_scanalogic2_transfer_out(usb.devhdl, buffer); if ((ret = sl2_transfer_out(usb.devhdl, buffer)) != PACKET_LENGTH) {
if (ret != PACKET_LENGTH) {
sr_err("Failed to set device in idle state: %s.", sr_err("Failed to set device in idle state: %s.",
libusb_error_name(ret)); libusb_error_name(ret));
libusb_release_interface(usb.devhdl, USB_INTERFACE); 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; return SR_OK;
} }
SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, SR_PRIV int sl2_transfer_in(libusb_device_handle *dev_handle, uint8_t *data)
uint8_t *data)
{ {
return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN, return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN,
USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE,
(unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT); (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT);
} }
SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle, SR_PRIV int sl2_transfer_out(libusb_device_handle *dev_handle, uint8_t *data)
uint8_t *data)
{ {
return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT, return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT,
USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE,

View File

@ -227,29 +227,22 @@ struct dev_context {
gboolean transfer_error; gboolean transfer_error;
}; };
SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, SR_PRIV int ikalogic_scanalogic2_receive_data(int fd, int revents, void *cb_data);
void *cb_data); SR_PRIV void sl2_receive_transfer_in(struct libusb_transfer *transfer);
SR_PRIV void ikalogic_scanalogic2_receive_transfer_in( SR_PRIV void sl2_receive_transfer_out(struct libusb_transfer *transfer);
struct libusb_transfer *transfer); SR_PRIV int sl2_set_samplerate(const struct sr_dev_inst *sdi,
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,
uint64_t samplerate); uint64_t samplerate);
SR_PRIV int ikalogic_scanalogic2_set_limit_samples( SR_PRIV int sl2_set_limit_samples(const struct sr_dev_inst *sdi,
const struct sr_dev_inst *sdi, uint64_t limit_samples); uint64_t limit_samples);
SR_PRIV void ikalogic_scanalogic2_configure_trigger( SR_PRIV void sl2_configure_trigger(const struct sr_dev_inst *sdi);
const struct sr_dev_inst *sdi); SR_PRIV int sl2_set_capture_ratio(const struct sr_dev_inst *sdi,
SR_PRIV int ikalogic_scanalogic2_set_capture_ratio( uint64_t 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,
SR_PRIV int ikalogic_scanalogic2_set_after_trigger_delay( uint64_t 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 void ikalogic_scanalogic2_calculate_trigger_samples( SR_PRIV int sl2_get_device_info(struct sr_usb_dev_inst usb,
const struct sr_dev_inst *sdi);
SR_PRIV int ikalogic_scanalogic2_get_device_info(struct sr_usb_dev_inst usb,
struct device_info *dev_info); struct device_info *dev_info);
SR_PRIV int ikalogic_scanalogic2_transfer_in(libusb_device_handle *dev_handle, SR_PRIV int sl2_transfer_in(libusb_device_handle *dev_handle, uint8_t *data);
uint8_t *data); SR_PRIV int sl2_transfer_out(libusb_device_handle *dev_handle, uint8_t *data);
SR_PRIV int ikalogic_scanalogic2_transfer_out(libusb_device_handle *dev_handle,
uint8_t *data);
#endif #endif