X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fchronovu-la%2Fapi.c;h=d735e1e1729a910c5dc3c7bf55d69e702e49e68d;hb=4d6a50085ea9ea4f25850b22737f621a3e13d953;hp=3dc0598ec30aba688b00c712012dff6c3cb31029;hpb=0af636bed97c174bea46e61e961eaa1b0b162e0f;p=libsigrok.git diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 3dc0598e..d735e1e1 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -39,7 +39,7 @@ static const int32_t trigger_matches[] = { }; /* The ChronoVu LA8/LA16 can have multiple VID/PID pairs. */ -static struct { +static const struct { uint16_t vid; uint16_t pid; int model; @@ -63,12 +63,12 @@ static void clear_helper(void *priv) g_free(devc->final_buf); } -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); } @@ -80,14 +80,13 @@ static int add_device(int idx, int model, GSList **devices) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; ret = SR_OK; - drvc = di->priv; + drvc = di->context; /* Allocate memory for our private device context. */ - devc = g_try_malloc(sizeof(struct dev_context)); + devc = g_malloc0(sizeof(struct dev_context)); /* Set some sane defaults. */ devc->prof = &cv_profiles[model]; @@ -120,21 +119,16 @@ static int add_device(int idx, int model, GSList **devices) devc->cur_samplerate = devc->prof->max_samplerate; /* Register the device with libsigrok. */ - sdi = sr_dev_inst_new(); + sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INITIALIZING; sdi->vendor = g_strdup("ChronoVu"); sdi->model = g_strdup(devc->prof->modelname); sdi->driver = di; sdi->priv = devc; - for (i = 0; i < devc->prof->num_channels; i++) { - if (!(ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - cv_channel_names[i]))) { - ret = SR_ERR; - goto err_free_dev_inst; - } - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (i = 0; i < devc->prof->num_channels; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, + cv_channel_names[i]); *devices = g_slist_append(*devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); @@ -142,22 +136,20 @@ static int add_device(int idx, int model, GSList **devices) if (ret == SR_OK) return SR_OK; -err_free_dev_inst: - sr_dev_inst_free(sdi); - g_free(devc->final_buf); err_free_devc: g_free(devc); return ret; } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { int ret; unsigned int i; GSList *devices; struct ftdi_context *ftdic; + (void)di; (void)options; devices = NULL; @@ -197,9 +189,9 @@ static GSList *scan(GSList *options) return devices; } -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) @@ -276,9 +268,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -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, @@ -512,7 +504,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->trigger_found = 0; /* Hook up a dummy handler to receive data from the device. */ - sr_session_source_add(sdi->session, -1, G_IO_IN, 0, receive_data, (void *)sdi); + sr_session_source_add(sdi->session, -1, 0, 0, receive_data, (void *)sdi); return SR_OK; } @@ -550,5 +542,5 @@ SR_PRIV struct sr_dev_driver chronovu_la_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };