]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/api.c
Add and use std_session_send_df_header().
[libsigrok.git] / hardware / chronovu-la8 / api.c
index 9267ca7b7c32f0446e4019fc90bd655a5ce2009e..66cbdb6ecdfa83393d409b55dc222f945ccdd5e3 100644 (file)
@@ -70,17 +70,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("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)
@@ -96,6 +86,7 @@ static GSList *hw_scan(GSList *options)
        (void)options;
 
        drvc = di->priv;
+
        devices = NULL;
 
        /* Allocate memory for our private device context. */
@@ -169,8 +160,6 @@ static GSList *hw_scan(GSList *options)
        devices = g_slist_append(devices, sdi);
        drvc->instances = g_slist_append(drvc->instances, sdi);
 
-       sr_spew("Device init successful.");
-
        /* Close device. We'll reopen it again when we need it. */
        (void) la8_close(devc); /* Log, but ignore errors. */
 
@@ -191,11 +180,7 @@ err_free_nothing:
 
 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,12 +240,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (!(devc = sdi->priv)) {
-               sr_err("%s: sdi->priv was NULL.", __func__);
-               return SR_ERR_BUG;
-       }
-
-       sr_dbg("Closing device.");
+       devc = sdi->priv;
 
        if (sdi->status == SR_ST_ACTIVE) {
                sr_dbg("Status ACTIVE, closing device.");
@@ -271,7 +251,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
        sdi->status = SR_ST_INACTIVE;
 
-       sr_dbg("Freeing sample buffer.");
        g_free(devc->final_buf);
 
        return SR_OK;
@@ -288,26 +267,12 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int hw_info_get(int info_id, const void **data,
-                      const struct sr_dev_inst *sdi)
+static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       switch (info_id) {
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       case SR_DI_SAMPLERATES:
-               fill_supported_samplerates_if_needed();
-               *data = &samplerates;
-               sr_spew("%s: Returning samplerates.", __func__);
-               break;
-       case SR_DI_TRIGGER_TYPES:
-               *data = (char *)TRIGGER_TYPES;
-               sr_spew("%s: Returning trigger types: %s.", __func__,
-                       TRIGGER_TYPES);
-               break;
-       case SR_DI_CUR_SAMPLERATE:
+       switch (id) {
+       case SR_CONF_SAMPLERATE:
                if (sdi) {
                        devc = sdi->priv;
                        *data = &devc->cur_samplerate;
@@ -323,8 +288,7 @@ static int hw_info_get(int info_id, const void **data,
        return SR_OK;
 }
 
-static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
-               const void *value)
+static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
@@ -333,15 +297,15 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                return SR_ERR_BUG;
        }
 
-       switch (hwcap) {
-       case SR_HWCAP_SAMPLERATE:
+       switch (id) {
+       case SR_CONF_SAMPLERATE:
                if (set_samplerate(sdi, *(const uint64_t *)value) == SR_ERR) {
                        sr_err("%s: setting samplerate failed.", __func__);
                        return SR_ERR;
                }
                sr_dbg("SAMPLERATE = %" PRIu64, devc->cur_samplerate);
                break;
-       case SR_HWCAP_LIMIT_MSEC:
+       case SR_CONF_LIMIT_MSEC:
                if (*(const uint64_t *)value == 0) {
                        sr_err("%s: LIMIT_MSEC can't be 0.", __func__);
                        return SR_ERR;
@@ -349,7 +313,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                devc->limit_msec = *(const uint64_t *)value;
                sr_dbg("LIMIT_MSEC = %" PRIu64, devc->limit_msec);
                break;
-       case SR_HWCAP_LIMIT_SAMPLES:
+       case SR_CONF_LIMIT_SAMPLES:
                if (*(const uint64_t *)value < MIN_NUM_SAMPLES) {
                        sr_err("%s: LIMIT_SAMPLES too small.", __func__);
                        return SR_ERR;
@@ -359,7 +323,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
                break;
        default:
                /* Unknown capability, return SR_ERR. */
-               sr_err("%s: Unknown capability: %d.", __func__, hwcap);
+               sr_err("%s: Unknown capability: %d.", __func__, id);
                return SR_ERR;
                break;
        }
@@ -367,6 +331,29 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
        return SR_OK;
 }
 
+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:
+               fill_supported_samplerates_if_needed();
+               *data = &samplerates;
+               break;
+       case SR_CONF_TRIGGER_TYPE:
+               *data = (char *)TRIGGER_TYPE;
+               break;
+       default:
+               return SR_ERR_ARG;
+       }
+
+       return SR_OK;
+}
+
 static int receive_data(int fd, int revents, void *cb_data)
 {
        int i, ret;
@@ -419,8 +406,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data)
 {
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
        uint8_t buf[4];
        int bytes_written;
 
@@ -445,8 +430,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       sr_dbg("Starting acquisition.");
-
        /* Fill acquisition parameters into buf[]. */
        buf[0] = devc->divcount;
        buf[1] = 0xff; /* This byte must always be 0xff. */
@@ -464,17 +447,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       sr_dbg("Acquisition started successfully.");
+       sr_dbg("Hardware acquisition started successfully.");
 
        devc->session_dev_id = cb_data;
 
        /* Send header packet to the session bus. */
-       sr_dbg("Sending SR_DF_HEADER.");
-       packet.type = SR_DF_HEADER;
-       packet.payload = &header;
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       sr_session_send(devc->session_dev_id, &packet);
+       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        /* Time when we should be done (for detecting trigger timeouts). */
        devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL)
@@ -514,10 +492,11 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
        .scan = hw_scan,
        .dev_list = hw_dev_list,
        .dev_clear = clear_instances,
+       .config_get = config_get,
+       .config_set = config_set,
+       .config_list = config_list,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
-       .info_get = hw_info_get,
-       .dev_config_set = hw_dev_config_set,
        .dev_acquisition_start = hw_dev_acquisition_start,
        .dev_acquisition_stop = hw_dev_acquisition_stop,
        .priv = NULL,