X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fikalogic-scanaplus%2Fapi.c;h=dd457c8045ceef62191a10059896593008bb0512;hb=1c47e0da8f2571bc34dbdc368c3c1f55318c3aa0;hp=95bd3c1a1e4b13e6ca291f09fee046715d47ec34;hpb=aed4ad0beaf64062752039a13f9a95326aa1df87;p=libsigrok.git diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 95bd3c1a..dd457c80 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "protocol.h" #define USB_VENDOR_ID 0x0403 @@ -38,14 +39,12 @@ static const uint32_t devopts[] = { /* 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); @@ -61,20 +60,19 @@ static void clear_helper(void *priv) 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 +81,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 +118,15 @@ static GSList *scan(GSList *options) } /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(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 +136,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 +145,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,9 +261,9 @@ 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(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -392,28 +379,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if ((ret = scanaplus_start_acquisition(devc)) < 0) return ret; - /* Send header packet to the session bus. */ std_session_send_df_header(sdi, LOG_PREFIX); /* Hook up a dummy handler to receive data from the device. */ - sr_session_source_add(sdi->session, -1, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi); + sr_session_source_add(sdi->session, -1, 0, 0, scanaplus_receive_data, (void *)sdi); return SR_OK; } static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { - struct sr_datafeed_packet packet; - (void)cb_data; sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); - - /* Send end packet to the session bus. */ - sr_dbg("Sending SR_DF_END."); - packet.type = SR_DF_END; - sr_session_send(sdi, &packet); + std_session_send_df_end(sdi, LOG_PREFIX); return SR_OK; } @@ -434,5 +414,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, };