X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Fapi.c;h=3d8f0979606c40178de1cab84e3c3bc2bf89e779;hb=463160cbca37367ef94dfead0c64531d82b83ab8;hp=bb1e9e0b48719c1fa98eb3a36ac762e36a7e74d5;hpb=7e463623382e1f574fde150b3fc88a65eaebb578;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index bb1e9e0b..3d8f0979 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -26,20 +26,14 @@ #include #include "protocol.h" -/* Supported device scan options. - */ static const uint32_t scanopts[] = { SR_CONF_CONN, }; -/* Driver capabilities. - */ static const uint32_t drvopts[] = { SR_CONF_LOGIC_ANALYZER, }; -/* Supported trigger match conditions. - */ static const int32_t trigger_matches[] = { SR_TRIGGER_ZERO, SR_TRIGGER_ONE, @@ -47,22 +41,16 @@ static const int32_t trigger_matches[] = { SR_TRIGGER_FALLING, }; -/* Names assigned to available trigger sources. - */ static const char *const trigger_source_names[] = { [TRIGGER_CHANNELS] = "CH", [TRIGGER_EXT_TRG] = "TRG", }; -/* Names assigned to available edge slope choices. - */ static const char *const signal_edge_names[] = { [EDGE_POSITIVE] = "r", [EDGE_NEGATIVE] = "f", }; -/* Create a new sigrok device instance for the indicated LWLA model. - */ static struct sr_dev_inst *dev_inst_new(const struct model_info *model) { struct sr_dev_inst *sdi; @@ -70,7 +58,6 @@ static struct sr_dev_inst *dev_inst_new(const struct model_info *model) int i; char name[8]; - /* Initialize private device context. */ devc = g_malloc0(sizeof(struct dev_context)); devc->model = model; devc->active_fpga_config = FPGA_NOCONF; @@ -78,16 +65,13 @@ static struct sr_dev_inst *dev_inst_new(const struct model_info *model) devc->samplerate = model->samplerates[0]; devc->channel_mask = (UINT64_C(1) << model->num_channels) - 1; - /* Create sigrok device instance. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(VENDOR_NAME); sdi->model = g_strdup(model->name); sdi->priv = devc; - /* Generate list of logic channels. */ for (i = 0; i < model->num_channels; i++) { - /* The LWLA series simply number channels from CH1 to CHxx. */ g_snprintf(name, sizeof(name), "CH%d", i + 1); sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, name); } @@ -148,8 +132,6 @@ static struct sr_dev_inst *dev_inst_new_matching(GSList *conn_matches, return sdi; } -/* Scan for SysClk LWLA devices and create a device instance for each one. - */ static GSList *scan(struct sr_dev_driver *di, GSList *options) { GSList *conn_devices, *devices, *node; @@ -203,30 +185,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) return std_scan_complete(di, devices); } -/* Destroy the private device context. - */ -static void clear_dev_context(void *priv) -{ - struct dev_context *devc; - - devc = priv; - - if (devc->acquisition) { - sr_err("Cannot clear device context during acquisition!"); - return; /* Leak and pray. */ - } - sr_dbg("Device context cleared."); - - g_free(devc); -} - -/* Destroy all device instances. - */ -static int dev_clear(const struct sr_dev_driver *di) -{ - return std_dev_clear(di, &clear_dev_context); -} - /* Drain any pending data from the USB transfer buffers on the device. * This may be necessary e.g. after a crash or generally to clean up after * an abnormal condition. @@ -260,8 +218,6 @@ static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint) return SR_OK; } -/* Open and initialize device. - */ static int dev_open(struct sr_dev_inst *sdi) { struct drv_context *drvc; @@ -324,8 +280,6 @@ static int dev_open(struct sr_dev_inst *sdi) return ret; } -/* Shutdown and close device. - */ static int dev_close(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -342,17 +296,16 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_ERR_BUG; } - sdi->status = SR_ST_INACTIVE; - /* Download of the shutdown bitstream, if any. */ ret = (*devc->model->apply_fpga_config)(sdi); if (ret != SR_OK) sr_warn("Unable to shut down device."); libusb_release_interface(usb->devhdl, USB_INTERFACE); + sr_usb_close(usb); - return ret; + return SR_OK; } /* Check whether the device options contain a specific key. @@ -370,8 +323,6 @@ static int has_devopt(const struct model_info *model, uint32_t key) return FALSE; } -/* Read device configuration setting. - */ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -452,8 +403,6 @@ static int lookup_index(GVariant *value, const char *const *table, int len) return -1; } -/* Write device configuration setting. - */ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { @@ -527,8 +476,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd return SR_OK; } -/* Apply channel configuration change. - */ static int config_channel_set(const struct sr_dev_inst *sdi, struct sr_channel *ch, unsigned int changes) { @@ -558,8 +505,7 @@ static int config_channel_set(const struct sr_dev_inst *sdi, return SR_OK; } -/* Derive trigger masks from the session's trigger configuration. - */ +/* Derive trigger masks from the session's trigger configuration. */ static int prepare_trigger_masks(const struct sr_dev_inst *sdi) { uint64_t trigger_mask, trigger_values, trigger_edge_mask; @@ -624,8 +570,6 @@ static int prepare_trigger_masks(const struct sr_dev_inst *sdi) return SR_OK; } -/* Apply current device configuration to the hardware. - */ static int config_commit(const struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -651,41 +595,22 @@ static int config_commit(const struct sr_dev_inst *sdi) return SR_OK; } -/* List available choices for a configuration setting. - */ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; - GVariant *gvar; - GVariantBuilder gvb; - - (void)cg; - if (key == SR_CONF_SCAN_OPTIONS) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0])); - return SR_OK; - } - if (!sdi) { - if (key != SR_CONF_DEVICE_OPTIONS) - return SR_ERR_ARG; - - /* List driver capabilities. */ - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0])); - return SR_OK; - } + devc = (sdi) ? sdi->priv : NULL; - devc = sdi->priv; - - /* List the model's device options. */ - if (key == SR_CONF_DEVICE_OPTIONS) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devc->model->devopts, devc->model->num_devopts, - sizeof(devc->model->devopts[0])); - return SR_OK; + switch (key) { + case SR_CONF_SCAN_OPTIONS: + case SR_CONF_DEVICE_OPTIONS: + return std_opts_config_list(key, data, sdi, cg, + scanopts, ARRAY_SIZE(scanopts), + drvopts, ARRAY_SIZE(drvopts), + (devc) ? devc->model->devopts : NULL, + (devc) ? devc->model->num_devopts : 0); } if (!has_devopt(devc->model, key | SR_CONF_LIST)) @@ -693,12 +618,7 @@ static int config_list(uint32_t key, GVariant **data, switch (key) { case SR_CONF_SAMPLERATE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT); - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, - devc->model->samplerates, devc->model->num_samplerates, - sizeof(devc->model->samplerates[0])); - g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); - *data = g_variant_builder_end(&gvb); + *data = std_gvar_samplerates(devc->model->samplerates, devc->model->num_samplerates); break; case SR_CONF_TRIGGER_MATCH: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, @@ -731,8 +651,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return lwla_start_acquisition(sdi); } -/* Request that a running capture operation be stopped. - */ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; @@ -747,8 +665,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) return SR_OK; } -/* SysClk LWLA driver descriptor. - */ static struct sr_dev_driver sysclk_lwla_driver_info = { .name = "sysclk-lwla", .longname = "SysClk LWLA series", @@ -757,7 +673,7 @@ static struct sr_dev_driver sysclk_lwla_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = dev_clear, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_channel_set = config_channel_set,