]> 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 c7e1e687c9018ab7f1d7213dc3a4fe86609ffb58..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,17 +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)
@@ -85,7 +75,9 @@ static GSList *hw_scan(GSList *options)
        char buf[8];
 
        (void)options;
+
        drvc = di->priv;
+
        devices = NULL;
 
        conn = serialcomm = NULL;
@@ -181,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)