]> sigrok.org Git - libsigrok.git/blobdiff - hardware/ikalogic-scanalogic2/api.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / hardware / ikalogic-scanalogic2 / api.c
index 915120825a885f04c8f434216b09397cd0ec8e73..0443bc9f7908dbf46af8ec4299152da9eca35674 100644 (file)
@@ -41,7 +41,7 @@ SR_PRIV const uint64_t sl2_samplerates[NUM_SAMPLERATES] = {
        SR_MHZ(20),
 };
 
-static const char *probe_names[NUM_PROBES + 1] = {
+static const char *channel_names[NUM_PROBES + 1] = {
        "0", "1", "2", "3",
        NULL,
 };
@@ -59,7 +59,7 @@ static GSList *scan(GSList *options)
        GSList *usb_devices, *devices, *l;
        struct drv_context *drvc;
        struct sr_dev_inst *sdi;
-       struct sr_probe *probe;
+       struct sr_channel *ch;
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
        struct device_info dev_info;
@@ -136,11 +136,11 @@ static GSList *scan(GSList *options)
                sdi->inst_type = SR_INST_USB;
                sdi->conn = usb;
 
-               for (i = 0; probe_names[i]; i++) {
-                       probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
-                               probe_names[i]);
-                       sdi->probes = g_slist_append(sdi->probes, probe);
-                       devc->probes[i] = probe;
+               for (i = 0; channel_names[i]; i++) {
+                       ch = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
+                               channel_names[i]);
+                       sdi->channels = g_slist_append(sdi->channels, ch);
+                       devc->channels[i] = ch;
                }
 
                devc->state = STATE_IDLE;
@@ -161,7 +161,7 @@ static GSList *scan(GSList *options)
                        PACKET_LENGTH);
 
                libusb_fill_control_setup(devc->xfer_buf_in,
-                       USB_REQUEST_TYPE_IN, USB_HID_SET_REPORT,
+                       USB_REQUEST_TYPE_IN, USB_HID_GET_REPORT,
                        USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE,
                        PACKET_LENGTH);
                libusb_fill_control_setup(devc->xfer_buf_out,
@@ -307,11 +307,14 @@ static int cleanup(void)
        return dev_clear();
 }
 
-static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
+               const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
        int ret;
 
+       (void)cg;
+
        ret = SR_OK;
        devc = sdi->priv;
 
@@ -329,11 +332,14 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
        return ret;
 }
 
-static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
+static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
+               const struct sr_channel_group *cg)
 {
        uint64_t samplerate, limit_samples, capture_ratio;
        int ret;
 
+       (void)cg;
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
@@ -359,13 +365,15 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
        return ret;
 }
 
-static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
+               const struct sr_channel_group *cg)
 {
-       GVariant *gvar;
+       GVariant *gvar, *grange[2];
        GVariantBuilder gvb;
        int ret;
 
        (void)sdi;
+       (void)cg;
 
        ret = SR_OK;
 
@@ -385,6 +393,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        case SR_CONF_TRIGGER_TYPE:
                *data = g_variant_new_string(TRIGGER_TYPES);
                break;
+       case SR_CONF_LIMIT_SAMPLES:
+               grange[0] = g_variant_new_uint64(0);
+               grange[1] = g_variant_new_uint64(MAX_SAMPLES);
+               *data = g_variant_new_tuple(grange, 2);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -394,7 +407,6 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 {
-       const struct libusb_pollfd **pfd;
        struct drv_context *drvc;
        struct dev_context *devc;
        uint16_t trigger_bytes, tmp;
@@ -431,21 +443,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        if (trigger_bytes % PACKET_NUM_SAMPLE_BYTES != 0)
                devc->num_sample_packets++;
 
-       devc->num_enabled_probes = 0;
+       devc->num_enabled_channels = 0;
 
        /*
-        * Count the number of enabled probes and number them for a sequential
+        * Count the number of enabled channels and number them for a sequential
         * access.
         */
        for (i = 0, j = 0; i < NUM_PROBES; i++) {
-               if (devc->probes[i]->enabled) {
-                       devc->num_enabled_probes++;
-                       devc->probe_map[j] = i;
+               if (devc->channels[i]->enabled) {
+                       devc->num_enabled_channels++;
+                       devc->channel_map[j] = i;
                        j++;
                }
        }
 
-       sr_dbg("Number of enabled probes: %i.", devc->num_enabled_probes);
+       sr_dbg("Number of enabled channels: %i.", devc->num_enabled_channels);
 
        /* Set up the transfer buffer for the acquisition. */
        devc->xfer_data_out[0] = CMD_SAMPLE;
@@ -465,34 +477,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        tmp = GUINT16_TO_LE(devc->after_trigger_delay);
        memcpy(devc->xfer_data_out + 10, &tmp, sizeof(tmp));
 
-       if (!(pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx))) {
-               sr_err("libusb_get_pollfds failed.");
-               return SR_ERR;
-       }
-
-       /* Count the number of file descriptors. */
-       for (devc->num_usbfd = 0; pfd[devc->num_usbfd]; devc->num_usbfd++);
-
-       if (!(devc->usbfd = g_try_malloc(devc->num_usbfd * sizeof(int)))) {
-               sr_err("File descriptor array malloc failed.");
-               free(pfd);
-               return SR_ERR_MALLOC;
-       }
-
        if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) {
                sr_err("Submit transfer failed: %s.", libusb_error_name(ret));
-               g_free(devc->usbfd);
                return SR_ERR;
        }
 
-       for (i = 0; i < devc->num_usbfd; i++) {
-               sr_source_add(pfd[i]->fd, pfd[i]->events, 100,
-                       ikalogic_scanalogic2_receive_data, (void *)sdi);
-
-               devc->usbfd[i] = pfd[i]->fd;
-       }
-
-       free(pfd);
+       usb_source_add(drvc->sr_ctx, 100, ikalogic_scanalogic2_receive_data, (void *)sdi);
 
        sr_dbg("Acquisition started successfully.");