X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmanson-hcs-3xxx%2Fapi.c;h=b9e6524b482b139d4a840abcb57205b1fcbad09a;hb=4f840ce965b1c30c5ab75afecc56193cbaf5c1b3;hp=6355d004fc2eb2565f19d2d27a5923d142b4bf5b;hpb=c368e6f3d248a73d69cd0c2c4a7c88a92def55e3;p=libsigrok.git diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 6355d004..b9e6524b 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -73,26 +73,24 @@ static struct hcs_model models[] = { }; SR_PRIV struct sr_dev_driver manson_hcs_3xxx_driver_info; -static struct sr_dev_driver *di = &manson_hcs_3xxx_driver_info; -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, NULL); } -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) { int i, model_id; struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_config *src; - struct sr_channel *ch; GSList *devices, *l; const char *conn, *serialcomm; struct sr_serial_dev_inst *serial; @@ -125,8 +123,7 @@ static GSList *scan(GSList *options) if (!serialcomm) serialcomm = "9600/8n1"; - if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) - return NULL; + serial = sr_serial_dev_inst_new(conn, serialcomm); if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; @@ -163,8 +160,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1"); devc = g_malloc0(sizeof(struct dev_context)); devc->model = &models[model_id]; @@ -206,14 +202,14 @@ exit_err: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { return ((struct drv_context *)(di->priv))->instances; } -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, @@ -331,21 +327,26 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * (void)cg; + /* Always available (with or without sdi). */ + if (key == SR_CONF_SCAN_OPTIONS) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); + return SR_OK; + } + + /* Return drvopts without sdi (and devopts with sdi, see below). */ if (key == SR_CONF_DEVICE_OPTIONS && !sdi) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); return SR_OK; } + /* Every other key needs an sdi. */ if (!sdi) return SR_ERR_ARG; devc = sdi->priv; switch (key) { - case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, - scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); - break; case SR_CONF_DEVICE_OPTIONS: *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));