X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds1xx2%2Fapi.c;h=2fd375fbbdba9702abd489743469d8790d492452;hb=4afdfd4628e9955af02a3ea619ecdfe469f9a9e2;hp=93f1fc2a4cf0f81b54bd03802f9210ca183402ec;hpb=1953564a96798bc298d1c94eb90c129adbde1c9e;p=libsigrok.git diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index 93f1fc2a..2fd375fb 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -138,6 +138,7 @@ static int clear_instances(void) continue; g_free(devc->device); + g_slist_free(devc->enabled_probes); close(devc->fd); sr_dev_inst_free(sdi); @@ -151,17 +152,7 @@ static int clear_instances(void) static int hw_init(struct sr_context *sr_ctx) { - struct drv_context *drvc; - (void)sr_ctx; - - 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) @@ -187,10 +178,11 @@ static GSList *hw_scan(GSList *options) (void)options; - devices = NULL; drvc = di->priv; drvc->instances = NULL; + devices = NULL; + dir = g_dir_open("/sys/class/usb/", 0, NULL); if (dir == NULL) @@ -281,11 +273,7 @@ static GSList *hw_scan(GSList *options) 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) @@ -323,36 +311,7 @@ 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) -{ - (void)sdi; - - switch (info_id) { - case SR_DI_HWCAPS: - *data = hwcaps; - break; - case SR_DI_TIMEBASES: - *data = timebases; - break; - case SR_DI_TRIGGER_SOURCES: - *data = trigger_sources; - break; - case SR_DI_VDIVS: - *data = vdivs; - break; - case SR_DI_COUPLING: - *data = coupling; - break; - default: - return SR_ERR_ARG; - } - - 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; uint64_t tmp_u64; @@ -369,7 +328,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, } ret = SR_OK; - switch (hwcap) { + switch (id) { case SR_CONF_LIMIT_FRAMES: devc->limit_frames = *(const uint64_t *)value; break; @@ -432,7 +391,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, ret = SR_ERR_ARG; break; default: - sr_err("Unknown hardware capability: %d.", hwcap); + sr_err("Unknown hardware capability: %d.", id); ret = SR_ERR_ARG; break; } @@ -440,12 +399,38 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap, return ret; } +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_COUPLING: + *data = coupling; + break; + case SR_CONF_VDIV: + *data = vdivs; + break; + case SR_CONF_TIMEBASE: + *data = timebases; + break; + case SR_CONF_TRIGGER_SOURCE: + *data = trigger_sources; + break; + default: + return SR_ERR_ARG; + } + + return SR_OK; +} + 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; char buf[256]; int len; @@ -458,12 +443,10 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi); /* Send header packet to the session bus. */ - packet.type = SR_DF_HEADER; - packet.payload = (unsigned char *)&header; - header.feed_version = 1; - gettimeofday(&header.starttime, NULL); - sr_session_send(cb_data, &packet); + std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); + /* Hardcoded to CH1 only. */ + devc->enabled_probes = g_slist_append(NULL, sdi->probes->data); rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL?\n"); len = read(devc->fd, buf, sizeof(buf)); buf[len] = 0; @@ -506,10 +489,10 @@ SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info = { .scan = hw_scan, .dev_list = hw_dev_list, .dev_clear = clear_instances, + .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,