X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fikalogic-scanaplus%2Fapi.c;h=456eb58cd6279520928ef858761a222f13bb2ae6;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=3f8276305bbfcaa4688a0569b25ca459307c730f;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 3f827630..456eb58c 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -28,25 +28,22 @@ #define SAMPLE_BUF_SIZE (8 * 1024 * 1024) -static const int32_t hwcaps[] = { +static const uint32_t devopts[] = { SR_CONF_LOGIC_ANALYZER, - SR_CONF_SAMPLERATE, - SR_CONF_LIMIT_MSEC, - SR_CONF_LIMIT_SAMPLES, - SR_CONF_CONTINUOUS, // TODO? + SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, + SR_CONF_LIMIT_MSEC | SR_CONF_SET, + SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, }; /* Channels are numbered 1-9. */ static const char *channel_names[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", - NULL, }; /* Note: The IKALOGIC ScanaPLUS always samples at 100MHz. */ -static uint64_t samplerates[1] = { SR_MHZ(100) }; +static const uint64_t samplerates[1] = { SR_MHZ(100) }; SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info; -static struct sr_dev_driver *di = &ikalogic_scanaplus_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); @@ -59,22 +56,22 @@ static void clear_helper(void *priv) ftdi_free(devc->ftdic); g_free(devc->compressed_buf); g_free(devc->sample_buf); + g_free(devc); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; - struct sr_channel *ch; struct drv_context *drvc; struct dev_context *devc; GSList *devices; @@ -83,15 +80,12 @@ static GSList *scan(GSList *options) (void)options; - drvc = di->priv; + drvc = di->context; devices = NULL; /* Allocate memory for our private device context. */ - if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { - sr_err("Device context malloc failed."); - goto err_free_nothing; - } + devc = g_malloc0(sizeof(struct dev_context)); /* Allocate memory for the incoming compressed samples. */ if (!(devc->compressed_buf = g_try_malloc0(COMPRESSED_BUF_SIZE))) { @@ -123,21 +117,15 @@ static GSList *scan(GSList *options) } /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, - USB_VENDOR_NAME, USB_MODEL_NAME, NULL); - if (!sdi) { - sr_err("Failed to create device instance."); - goto err_close_ftdic; - } + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->status = SR_ST_INITIALIZING; + sdi->vendor = g_strdup(USB_VENDOR_NAME); + sdi->model = g_strdup(USB_MODEL_NAME); sdi->driver = di; sdi->priv = devc; - for (i = 0; channel_names[i]; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - channel_names[i]))) - return NULL; - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); @@ -147,7 +135,6 @@ static GSList *scan(GSList *options) return devices; -err_close_ftdic: scanaplus_close(devc); err_free_ftdic: ftdi_free(devc->ftdic); /* NOT free() or g_free()! */ @@ -157,14 +144,13 @@ err_free_compressed_buf: g_free(devc->compressed_buf); err_free_devc: g_free(devc); -err_free_nothing: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } static int dev_open(struct sr_dev_inst *sdi) @@ -274,18 +260,18 @@ static int dev_close(struct sr_dev_inst *sdi) return ret; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, +static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { (void)sdi; (void)cg; - switch (id) { + switch (key) { case SR_CONF_SAMPLERATE: /* The ScanaPLUS samplerate is 100MHz and can't be changed. */ *data = g_variant_new_uint64(SR_MHZ(100)); @@ -297,7 +283,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, +static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -309,7 +295,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, devc = sdi->priv; - switch (id) { + switch (key) { case SR_CONF_SAMPLERATE: if (g_variant_get_uint64(data) != SR_MHZ(100)) { sr_err("ScanaPLUS only supports samplerate = 100MHz."); @@ -334,7 +320,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, +static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { GVariant *gvar; @@ -345,8 +331,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; case SR_CONF_SAMPLERATE: g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}")); @@ -434,5 +420,5 @@ SR_PRIV struct sr_dev_driver ikalogic_scanaplus_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };