X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fpipistrello-ols%2Fapi.c;h=f16b659e1aabad0bdc66e605e9e22a249874f3c1;hb=05199c0ac9f15f229d43e50e86c4c1eadc55deac;hp=c4d0cf370ec4d7559b00a0bf1bccdc95d30a7a1e;hpb=1f8f5bc08e0f684156baac513431b40d79ab4ea1;p=libsigrok.git diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index c4d0cf37..f16b659e 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -20,8 +20,11 @@ #include #include "protocol.h" -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_LOGIC_ANALYZER, +}; + +static const uint32_t devopts[] = { SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_MATCH | SR_CONF_LIST, @@ -75,17 +78,9 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; -SR_PRIV struct sr_dev_driver p_ols_driver_info; - -static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) -{ - return std_init(di, sr_ctx, LOG_PREFIX); -} - static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; - struct drv_context *drvc; struct dev_context *devc; GSList *devices; int ret, i; @@ -94,8 +89,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) (void)options; - drvc = di->context; - devices = NULL; /* Allocate memory for our private device context. */ @@ -123,7 +116,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (p_ols_open(devc) != SR_OK) { goto err_free_ftdic; } - + /* The discovery procedure is like this: first send the Reset * command (0x00) 5 times, since the device could be anywhere * in a 5-byte command. Then send the ID command (0x02). @@ -184,10 +177,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) sr_dbg("Failed to set default samplerate (%"PRIu64").", DEFAULT_SAMPLERATE); - drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); - return devices; + return std_scan_complete(di, devices); err_close_ftdic: p_ols_close(devc); @@ -200,19 +192,15 @@ err_free_ftdi_buf: return NULL; } -static void clear_helper(void *priv) +static void clear_helper(struct dev_context *devc) { - struct dev_context *devc; - - devc = priv; - ftdi_free(devc->ftdic); g_free(devc->ftdi_buf); } static int dev_clear(const struct sr_dev_driver *di) { - return std_dev_clear(di, clear_helper); + return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -268,9 +256,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; switch (key) { @@ -361,13 +346,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariantBuilder gvb; int num_pols_changrp, i; - (void)cg; - 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, @@ -425,32 +406,16 @@ static int dev_open(struct sr_dev_inst *sdi) devc = sdi->priv; - if (p_ols_open(devc) != SR_OK) { - return SR_ERR; - } else { - sdi->status = SR_ST_ACTIVE; - return SR_OK; - } + return p_ols_open(devc); } static int dev_close(struct sr_dev_inst *sdi) { - int ret; struct dev_context *devc; - ret = SR_OK; devc = sdi->priv; - if (sdi->status == SR_ST_ACTIVE) { - sr_dbg("Status ACTIVE, closing device."); - ret = p_ols_close(devc); - } else { - sr_spew("Status not ACTIVE, nothing to do."); - } - - sdi->status = SR_ST_INACTIVE; - - return ret; + return p_ols_close(devc); } static int set_trigger(const struct sr_dev_inst *sdi, int stage) @@ -534,9 +499,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int num_pols_changrp, samplespercount; int ret, i; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; pols_channel_mask(sdi); @@ -653,8 +615,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) sr_dbg("flag_reg = %x", devc->flag_reg); /* - * In demux mode the OLS is processing two 8-bit or 16-bit samples - * in parallel and for this to work the lower two bits of the four + * In demux mode the OLS is processing two 8-bit or 16-bit samples + * in parallel and for this to work the lower two bits of the four * "channel_disable" bits must be replicated to the upper two bits. */ flag_tmp = devc->flag_reg; @@ -678,7 +640,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->cnt_bytes = devc->cnt_samples = devc->cnt_samples_rle = 0; memset(devc->sample, 0, 4); - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); /* Hook up a dummy handler to receive data from the device. */ sr_session_source_add(sdi->session, -1, 0, 10, p_ols_receive_data, @@ -693,7 +655,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) devc = sdi->priv; - sr_dbg("Stopping acquisition."); write_shortcommand(devc, CMD_RESET); write_shortcommand(devc, CMD_RESET); write_shortcommand(devc, CMD_RESET); @@ -702,7 +663,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) sr_session_source_remove(sdi->session, -1); - std_session_send_df_end(sdi, LOG_PREFIX); + std_session_send_df_end(sdi); return SR_OK; } @@ -711,7 +672,7 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = { .name = "p-ols", .longname = "Pipistrello OLS", .api_version = 1, - .init = init, + .init = std_init, .cleanup = std_cleanup, .scan = scan, .dev_list = std_dev_list, @@ -725,3 +686,4 @@ SR_PRIV struct sr_dev_driver p_ols_driver_info = { .dev_acquisition_stop = dev_acquisition_stop, .context = NULL, }; +SR_REGISTER_DEV_DRIVER(p_ols_driver_info);