]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/api.c
Shorten/simplify hw_dev_list() implementations.
[libsigrok.git] / hardware / openbench-logic-sniffer / api.c
index dc86960b2f49eb18b16cfa03116b15ae38d21a52..6511e67852d768c9eeadfb04fe6156e7e9e460c1 100644 (file)
@@ -44,12 +44,12 @@ SR_PRIV const char *ols_probe_names[NUM_PROBES + 1] = {
        NULL,
 };
 
-/* default supported samplerates, can be overridden by device metadata */
+/* Default supported samplerates, can be overridden by device metadata. */
 static const struct sr_samplerates samplerates = {
-       SR_HZ(10),
-       SR_MHZ(200),
-       SR_HZ(1),
-       NULL,
+       .low  = SR_HZ(10),
+       .high = SR_MHZ(200),
+       .step = SR_HZ(1),
+       .list = NULL,
 };
 
 SR_PRIV struct sr_dev_driver ols_driver_info;
@@ -57,16 +57,7 @@ static struct sr_dev_driver *di = &ols_driver_info;
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-       drvc->sr_ctx = sr_ctx;
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -84,7 +75,9 @@ static GSList *hw_scan(GSList *options)
        char buf[8];
 
        (void)options;
+
        drvc = di->priv;
+
        devices = NULL;
 
        conn = serialcomm = NULL;
@@ -180,11 +173,7 @@ static GSList *hw_scan(GSList *options)
 
 static GSList *hw_dev_list(void)
 {
-       struct drv_context *drvc;
-
-       drvc = di->priv;
-
-       return drvc->instances;
+       return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
@@ -255,19 +244,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        switch (id) {
-       case SR_DI_HWOPTS:
-               *data = hwopts;
-               break;
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_SAMPLERATES:
-               *data = &samplerates;
-               break;
-       case SR_DI_TRIGGER_TYPES:
-               *data = (char *)TRIGGER_TYPES;
-               break;
-       case SR_DI_CUR_SAMPLERATE:
+       case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
                        *data = &devc->cur_samplerate;
@@ -329,6 +306,31 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
        return ret;
 }
 
+static int config_list(int key, const void **data, const struct sr_dev_inst *sdi)
+{
+
+       (void)sdi;
+
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+               *data = hwopts;
+               break;
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
+       case SR_CONF_SAMPLERATE:
+               *data = &samplerates;
+               break;
+       case SR_CONF_TRIGGER_TYPE:
+               *data = (char *)TRIGGER_TYPE;
+               break;
+       default:
+               return SR_ERR_ARG;
+       }
+
+       return SR_OK;
+}
+
 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
@@ -504,6 +506,7 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
        .dev_clear = hw_cleanup,
        .config_get = config_get,
        .config_set = config_set,
+       .config_list = config_list,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .dev_acquisition_start = hw_dev_acquisition_start,