]> sigrok.org Git - libsigrok.git/blobdiff - hardware/zeroplus-logic-cube/zeroplus.c
Factor out common hw_init() driver code.
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.c
index b8f9fb1a7a8d1ca98c7144218e732d91a8f64b0c..9d9e227d1b1ecf8120b4e1284ca67de03815768b 100644 (file)
@@ -38,7 +38,7 @@
 #define USB_INTERFACE                  0
 #define USB_CONFIGURATION              1
 #define NUM_TRIGGER_STAGES             4
-#define TRIGGER_TYPES                  "01"
+#define TRIGGER_TYPE                   "01"
 
 #define PACKET_SIZE                    2048    /* ?? */
 
@@ -289,16 +289,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("zeroplus: 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, "zeroplus: ");
 }
 
 static GSList *hw_scan(GSList *options)
@@ -316,6 +307,7 @@ static GSList *hw_scan(GSList *options)
        (void)options;
 
        drvc = di->priv;
+
        devices = NULL;
 
        clear_instances();
@@ -534,14 +526,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_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_TRIGGER_TYPES:
-               *data = TRIGGER_TYPES;
-               sr_spew("zp: %s: Returning triggertypes: %s.", __func__, TRIGGER_TYPES);
-               break;
-       case SR_DI_CUR_SAMPLERATE:
+       case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
                        *data = &devc->cur_samplerate;
@@ -651,9 +636,15 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
        (void)sdi;
 
        switch (key) {
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
        case SR_CONF_SAMPLERATE:
                *data = &samplerates;
                break;
+       case SR_CONF_TRIGGER_TYPE:
+               *data = TRIGGER_TYPE;
+               break;
        default:
                return SR_ERR_ARG;
        }