X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Flink-mso19%2Fapi.c;h=6069c71b007d072aeb79f33c4d2c8b45ff4dd383;hp=c35fc718903eb41b202786432250ac1e43460bc5;hb=05199c0ac9f15f229d43e50e86c4c1eadc55deac;hpb=efa9840222f2925c187715377e3646679fd8496c diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index c35fc718..6069c71b 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -22,9 +22,12 @@ #include #include "protocol.h" -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_OSCILLOSCOPE, SR_CONF_LOGIC_ANALYZER, +}; + +static const uint32_t devopts[] = { SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_TYPE | SR_CONF_LIST, @@ -50,46 +53,6 @@ static const uint64_t samplerates[] = { SR_HZ(100), }; -SR_PRIV struct sr_dev_driver link_mso19_driver_info; - -/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */ -static int dev_clear(const struct sr_dev_driver *di) -{ - struct drv_context *drvc = di->context; - GSList *l; - struct sr_dev_inst *sdi; - struct dev_context *devc; - int ret = SR_OK; - - /* Properly close and free all devices. */ - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - if (!(devc = sdi->priv)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi->priv was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - std_serial_dev_close(sdi); - sr_serial_dev_inst_free(devc->serial); - sr_dev_inst_free(sdi); - } - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return ret; -} - -static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) -{ - return std_init(sr_ctx, di, LOG_PREFIX); -} - static GSList *scan(struct sr_dev_driver *di, GSList *options) { int i; @@ -199,30 +162,15 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sdi->vendor = g_strdup(manufacturer); sdi->model = g_strdup(product); sdi->version = g_strdup(hwrev); - - if (!sdi) { - sr_err("Unable to create device instance for %s", - sysname); - sr_dev_inst_free(sdi); - g_free(devc); - return devices; - } - - sdi->driver = di; sdi->priv = devc; for (i = 0; i < ARRAY_SIZE(channel_names); i++) { chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC; sr_channel_new(sdi, i, chtype, TRUE, channel_names[i]); } - - //Add the driver - struct drv_context *drvc = di->context; - drvc->instances = g_slist_append(drvc->instances, sdi); - devices = g_slist_append(devices, sdi); } - return devices; + return std_scan_complete(di, devices); } static int dev_open(struct sr_dev_inst *sdi) @@ -235,8 +183,6 @@ static int dev_open(struct sr_dev_inst *sdi) if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK) return SR_ERR; - sdi->status = SR_ST_ACTIVE; - /* FIXME: discard serial buffer */ mso_check_trigger(devc->serial, &devc->trigger_state); sr_dbg("Trigger state: 0x%x.", devc->trigger_state); @@ -263,13 +209,14 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, (void)cg; + if (!sdi) + return SR_ERR_ARG; + + devc = sdi->priv; + switch (key) { case SR_CONF_SAMPLERATE: - if (sdi) { - devc = sdi->priv; - *data = g_variant_new_uint64(devc->cur_rate); - } else - return SR_ERR; + *data = g_variant_new_uint64(devc->cur_rate); break; default: return SR_ERR_NA; @@ -289,29 +236,24 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, double pos; (void)cg; - devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; + devc = sdi->priv; + ret = SR_OK; switch (key) { case SR_CONF_SAMPLERATE: // FIXME return mso_configure_rate(sdi, g_variant_get_uint64(data)); - ret = SR_OK; - break; case SR_CONF_LIMIT_SAMPLES: num_samples = g_variant_get_uint64(data); if (num_samples != 1024) { sr_err("Only 1024 samples are supported."); ret = SR_ERR_ARG; - } else { - devc->limit_samples = num_samples; - ret = SR_OK; - } + break; + }; + devc->limit_samples = num_samples; break; case SR_CONF_CAPTURE_RATIO: - ret = SR_OK; break; case SR_CONF_TRIGGER_SLOPE: slope = g_variant_get_string(data, NULL); @@ -319,29 +261,25 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, if (!slope || !(slope[0] == 'f' || slope[0] == 'r')) sr_err("Invalid trigger slope"); ret = SR_ERR_ARG; - } else { - devc->trigger_slope = (slope[0] == 'r') - ? SLOPE_POSITIVE : SLOPE_NEGATIVE; - ret = SR_OK; + break; } + devc->trigger_slope = (slope[0] == 'r') + ? SLOPE_POSITIVE : SLOPE_NEGATIVE; break; case SR_CONF_HORIZ_TRIGGERPOS: pos = g_variant_get_double(data); if (pos < 0 || pos > 255) { sr_err("Trigger position (%f) should be between 0 and 255.", pos); ret = SR_ERR_ARG; - } else { - trigger_pos = (int)pos; - devc->trigger_holdoff[0] = trigger_pos & 0xff; - ret = SR_OK; + break; } + trigger_pos = (int)pos; + devc->trigger_holdoff[0] = trigger_pos & 0xff; break; case SR_CONF_RLE: - ret = SR_OK; break; default: ret = SR_ERR_NA; - break; } return ret; @@ -353,14 +291,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, GVariant *gvar; GVariantBuilder gvb; - (void)cg; - (void)sdi; - switch (key) { case SR_CONF_DEVICE_OPTIONS: - *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: g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates, @@ -383,9 +316,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; int ret = SR_ERR; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (mso_configure_channels(sdi) != SR_OK) { @@ -433,7 +363,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Reset trigger state. */ devc->trigger_state = 0x00; - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); /* Our first channel is analog, the other 8 are of type 'logic'. */ /* TODO. */ @@ -452,15 +382,15 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV struct sr_dev_driver link_mso19_driver_info = { +static struct sr_dev_driver link_mso19_driver_info = { .name = "link-mso19", .longname = "Link Instruments MSO-19", .api_version = 1, - .init = init, + .init = std_init, .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_list = config_list, @@ -470,3 +400,4 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; +SR_REGISTER_DEV_DRIVER(link_mso19_driver_info);