X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fzeroplus-logic-cube%2Fapi.c;h=e8cdefdb18cf8555994a7aa019a137672ba65458;hb=463160cbca37367ef94dfead0c64531d82b83ab8;hp=7803407a21ce9c5d6bbacfd6ff747a34a20412eb;hpb=093e1cba6b7bf14cfb77fa36f59b0c16e6fca7cc;p=libsigrok.git diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 7803407a..e8cdefdb 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -203,12 +203,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) prof = &zeroplus_models[j]; } } - /* Skip if the device was not found. */ + if (!prof) continue; sr_info("Found ZEROPLUS %s.", prof->model_name); - /* Register the device with libsigrok. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup(VENDOR_NAME); @@ -216,7 +215,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->serial_num = g_strdup(serial_num); sdi->connection_id = g_strdup(connection_id); - /* Allocate memory for our private driver context. */ devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; devc->prof = prof; @@ -232,7 +230,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devc->memory_size = MEMORY_SIZE_8K; // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES); - /* Fill in channellist according to this device's profile. */ for (j = 0; j < devc->num_channels; j++) sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); @@ -264,8 +261,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (ret != SR_OK) return ret; - sdi->status = SR_ST_ACTIVE; - ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION); if (ret < 0) { sr_err("Unable to set USB configuration %d: %s.", @@ -321,7 +316,7 @@ static int dev_close(struct sr_dev_inst *sdi) usb = sdi->conn; if (!usb->devhdl) - return SR_ERR; + return SR_ERR_BUG; sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.", usb->bus, usb->address, sdi->connection_id, USB_INTERFACE); @@ -329,7 +324,6 @@ static int dev_close(struct sr_dev_inst *sdi) libusb_reset_device(usb->devhdl); libusb_close(usb->devhdl); usb->devhdl = NULL; - sdi->status = SR_ST_INACTIVE; return SR_OK; } @@ -402,36 +396,20 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * double v; GVariant *range[2]; - (void)cg; - switch (key) { case SR_CONF_DEVICE_OPTIONS: - if (!sdi) { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); - } else { - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - } - break; + return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts); case SR_CONF_SAMPLERATE: devc = sdi->priv; - g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); - if (devc->prof->max_sampling_freq == 100) { - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), - samplerates_100, ARRAY_SIZE(samplerates_100), - sizeof(uint64_t)); - } else if (devc->prof->max_sampling_freq == 200) { - gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), - samplerates_200, ARRAY_SIZE(samplerates_200), - sizeof(uint64_t)); - } else { + if (devc->prof->max_sampling_freq == 100) + *data = std_gvar_samplerates(samplerates_100, ARRAY_SIZE(samplerates_100)); + else if (devc->prof->max_sampling_freq == 200) + *data = std_gvar_samplerates(samplerates_200, ARRAY_SIZE(samplerates_200)); + else { sr_err("Internal error: Unknown max. samplerate: %d.", devc->prof->max_sampling_freq); return SR_ERR_ARG; } - g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); - *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_MATCH: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, @@ -639,7 +617,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_OK; } -/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct sr_usb_dev_inst *usb; @@ -661,7 +638,7 @@ static struct sr_dev_driver zeroplus_logic_cube_driver_info = { .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, - .dev_clear = NULL, + .dev_clear = std_dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list,