#include <inttypes.h>
#include <glib.h>
#include <libusb.h>
-#include "config.h"
#include "libsigrok.h"
#include "libsigrok-internal.h"
#include "analyzer.h"
static const int hwcaps[] = {
SR_HWCAP_LOGIC_ANALYZER,
SR_HWCAP_SAMPLERATE,
- SR_HWCAP_PROBECONFIG,
SR_HWCAP_CAPTURE_RATIO,
/* These are really implemented in the driver, not the hardware. */
supported_samplerates,
};
-/* Private driver context. */
-struct drv_context {
- GSList *instances;
-};
-
/* Private, per-device-instance driver context. */
struct dev_context {
uint64_t cur_samplerate;
return 0;
}
-static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
+static int configure_probes(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
const struct sr_probe *probe;
}
stage = -1;
- for (l = probes; l; l = l->next) {
+ for (l = sdi->probes; l; l = l->next) {
probe = (struct sr_probe *)l->data;
if (probe->enabled == FALSE)
continue;
return SR_OK;
}
-static void clear_instances(void)
+static int clear_instances(void)
{
GSList *l;
struct sr_dev_inst *sdi;
struct drv_context *drvc;
+ struct dev_context *devc;
drvc = zdi->priv;
for (l = drvc->instances; l; l = l->next) {
sdi = l->data;
+ if (!(devc = sdi->priv)) {
+ /* Log error, but continue cleaning up the rest. */
+ sr_err("zeroplus: %s: sdi->priv was NULL, continuing", __func__);
+ continue;
+ }
+ sr_usb_dev_inst_free(devc->usb);
/* Properly close all devices... */
hw_dev_close(sdi);
/* ...and free all their memory. */
g_slist_free(drvc->instances);
drvc->instances = NULL;
+ return SR_OK;
}
/*
if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
sr_err("zeroplus: driver context malloc failed.");
- return SR_ERR;
+ return SR_ERR_MALLOC;
}
zdi->priv = drvc;
/* Allocate memory for our private driver context. */
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("zp: %s: devc malloc failed", __func__);
- return 0;
+ return NULL;
}
sdi->priv = devc;
devc->num_channels = prof->channels;
return devices;
}
+static GSList *hw_dev_list(void)
+{
+ struct drv_context *drvc;
+
+ drvc = zdi->priv;
+
+ return drvc->instances;
+}
+
static int hw_dev_open(struct sr_dev_inst *sdi)
{
struct dev_context *devc;
switch (hwcap) {
case SR_HWCAP_SAMPLERATE:
return set_samplerate(sdi, *(const uint64_t *)value);
- case SR_HWCAP_PROBECONFIG:
- return configure_probes(sdi, (const GSList *)value);
case SR_HWCAP_LIMIT_SAMPLES:
devc->limit_samples = *(const uint64_t *)value;
return SR_OK;
return SR_ERR_ARG;
}
+ if (configure_probes(sdi) != SR_OK) {
+ sr_err("zp: failed to configured probes");
+ return SR_ERR;
+ }
+
/* push configured settings to device */
analyzer_configure(devc->usb->devhdl);
.init = hw_init,
.cleanup = hw_cleanup,
.scan = hw_scan,
+ .dev_list = hw_dev_list,
+ .dev_clear = hw_cleanup,
.dev_open = hw_dev_open,
.dev_close = hw_dev_close,
.info_get = hw_info_get,