X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fchronovu-la8%2Fapi.c;h=b1f889198d13ed99cb56eed95db3c2433ea30685;hb=063e7aef6d41d4c44591ff93672079998bf9622f;hp=048c950fb2bdb2430872148c0725a1f502edf911;hpb=45e080b60b2526fd9723dd822215294f973bff2a;p=libsigrok.git diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 048c950f..b1f88919 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -38,8 +38,7 @@ static const uint16_t usb_pids[] = { }; /* Function prototypes. */ -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data); +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); static int clear_instances(void) { @@ -69,18 +68,9 @@ static int clear_instances(void) return SR_OK; } -static int hw_init(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; - } - - 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. */ @@ -160,7 +151,7 @@ static GSList *hw_scan(GSList *options) sdi->priv = devc; for (i = 0; probe_names[i]; i++) { - if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, + if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, probe_names[i]))) return NULL; sdi->probes = g_slist_append(sdi->probes, probe); @@ -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. */ @@ -179,7 +168,7 @@ static GSList *hw_scan(GSList *options) err_close_ftdic: (void) la8_close(devc); /* Log, but ignore errors. */ err_free_ftdic: - free(devc->ftdic); /* NOT g_free()! */ + ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ err_free_final_buf: g_free(devc->final_buf); err_free_devc: @@ -279,45 +268,21 @@ static int hw_dev_close(struct sr_dev_inst *sdi) static int hw_cleanup(void) { - if (!di->priv) { - sr_err("%s: di->priv was NULL.", __func__); - return SR_ERR_BUG; - } + if (!di->priv) + /* Can get called on an unused driver, doesn't matter. */ + return SR_OK; clear_instances(); 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_NUM_PROBES: - *data = GINT_TO_POINTER(NUM_PROBES); - sr_spew("%s: Returning number of probes: %d.", __func__, - NUM_PROBES); - break; - case SR_DI_PROBE_NAMES: - *data = probe_names; - sr_spew("%s: Returning probenames.", __func__); - 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; @@ -333,8 +298,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; @@ -343,15 +307,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; @@ -359,7 +323,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; @@ -369,7 +333,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; } @@ -377,6 +341,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; @@ -431,7 +418,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_header header; - struct sr_datafeed_meta_logic meta; uint8_t buf[4]; int bytes_written; @@ -487,13 +473,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, gettimeofday(&header.starttime, NULL); sr_session_send(devc->session_dev_id, &packet); - /* Send metadata about the SR_DF_LOGIC packets to come. */ - packet.type = SR_DF_META_LOGIC; - packet.payload = &meta; - meta.samplerate = devc->cur_samplerate; - meta.num_probes = NUM_PROBES; - sr_session_send(devc->session_dev_id, &packet); - /* Time when we should be done (for detecting trigger timeouts). */ devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL) + devc->trigger_timeout; @@ -506,8 +485,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; @@ -533,10 +511,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,