]> sigrok.org Git - libsigrok.git/commitdiff
saleae-logic16: Detect the hardware.
authorMarcus Comstedt <redacted>
Wed, 31 Jul 2013 14:53:35 +0000 (16:53 +0200)
committerUwe Hermann <redacted>
Tue, 20 Aug 2013 17:55:57 +0000 (19:55 +0200)
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.h

index 7930c175677b6f99e53d9d7ee7ae05d6f3a67ba2..5f0fd1c09d83b8448b383741959b7eaac193abe3 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <glib.h>
+#include <libusb.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
 #include "protocol.h"
 
+#define LOGIC16_VID 0x21a9
+#define LOGIC16_PID 0x1001
+#define NUM_PROBES  16
+
 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info;
 static struct sr_dev_driver *di = &saleae_logic16_driver_info;
 
+static const char *probe_names[NUM_PROBES + 1] = {
+       "0", "1", "2", "3", "4", "5", "6", "7", "8",
+       "9", "10", "11", "12", "13", "14", "15",
+       NULL,
+};
 
 static int init(struct sr_context *sr_ctx)
 {
@@ -31,16 +46,56 @@ static int init(struct sr_context *sr_ctx)
 static GSList *scan(GSList *options)
 {
        struct drv_context *drvc;
+       struct dev_context *devc;
+       struct sr_dev_inst *sdi;
+       struct sr_probe *probe;
+       struct libusb_device_descriptor des;
+       libusb_device **devlist;
        GSList *devices;
+       int ret, devcnt, i, j;
 
        (void)options;
 
-       devices = NULL;
        drvc = di->priv;
-       drvc->instances = NULL;
 
-       /* TODO: scan for devices, either based on a SR_CONF_CONN option
-        * or on a USB scan. */
+       devices = NULL;
+       libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
+       for (i = 0; devlist[i]; i++) {
+               if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
+                       sr_warn("Failed to get device descriptor: %s",
+                                       libusb_error_name(ret));
+                       continue;
+               }
+
+               if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
+                       continue;
+
+               devcnt = g_slist_length(drvc->instances);
+               if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
+                                           "Saleae", "Logic16", NULL)))
+                       return NULL;
+               sdi->driver = di;
+
+               if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
+                       return NULL;
+               sdi->priv = devc;
+
+               for (j = 0; probe_names[j]; j++) {
+                       if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
+                                                  probe_names[j])))
+                               return NULL;
+                       sdi->probes = g_slist_append(sdi->probes, probe);
+               }
+
+               if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
+                                                     libusb_get_device_address(devlist[i]), NULL)))
+                       return NULL;
+               sdi->inst_type = SR_INST_USB;
+
+               drvc->instances = g_slist_append(drvc->instances, sdi);
+               devices = g_slist_append(devices, sdi);
+       }
+       libusb_free_device_list(devlist, 1);
 
        return devices;
 }
@@ -83,11 +138,18 @@ static int dev_close(struct sr_dev_inst *sdi)
 
 static int cleanup(void)
 {
-       dev_clear();
+       int ret;
+       struct drv_context *drvc;
 
-       /* TODO: free other driver resources, if any. */
+       if (!(drvc = di->priv))
+               /* Can get called on an unused driver, doesn't matter. */
+               return SR_OK;
 
-       return SR_OK;
+       ret = dev_clear();
+       g_free(drvc);
+       di->priv = NULL;
+
+       return ret;
 }
 
 static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
index a3ae1f82146e2d6372c685ff88d90d9ce229781a..0551712f1bdafab7ac0d4c2064ca7501e99fb675 100644 (file)
 
 /** Private, per-device-instance driver context. */
 struct dev_context {
-       /* Model-specific information */
-
-       /* Acquisition settings */
-
-       /* Operational state */
-
-       /* Temporary state across callbacks */
-
+       /** The currently configured samplerate of the device. */
+       uint64_t cur_samplerate;
 };
 
 SR_PRIV int saleae_logic16_receive_data(int fd, int revents, void *cb_data);