2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libsigrok.h"
23 #include "libsigrok-internal.h"
26 SR_PRIV struct sr_dev_inst *lascar_scan(int bus, int address);
27 SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info;
28 static struct sr_dev_driver *di = &lascar_el_usb_driver_info;
29 static int hw_dev_close(struct sr_dev_inst *sdi);
30 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data);
32 static const int hwopts[] = {
37 static const int hwcaps[] = {
40 SR_HWCAP_LIMIT_SAMPLES,
44 static const char *probe_names[] = {
49 /* Properly close and free all devices. */
50 static int clear_instances(void)
52 struct sr_dev_inst *sdi;
53 struct drv_context *drvc;
54 struct dev_context *devc;
57 if (!(drvc = di->priv))
60 for (l = drvc->instances; l; l = l->next) {
63 if (!(devc = sdi->priv))
67 sr_usb_dev_inst_free(devc->usb);
68 sr_dev_inst_free(sdi);
71 g_slist_free(drvc->instances);
72 drvc->instances = NULL;
77 static int hw_init(struct sr_context *sr_ctx)
79 struct drv_context *drvc;
81 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
82 sr_err("Driver context malloc failed.");
86 drvc->sr_ctx = sr_ctx;
92 static GSList *hw_scan(GSList *options)
94 struct drv_context *drvc;
95 struct dev_context *devc;
96 struct sr_dev_inst *sdi;
97 struct sr_usb_dev_inst *usb;
98 struct sr_probe *probe;
100 GSList *usb_devices, *devices, *l;
105 if (!(drvc = di->priv)) {
106 sr_err("Driver was not initialized.");
110 /* USB scan is always authoritative. */
114 for (l = options; l; l = l->next) {
116 switch (opt->hwopt) {
126 if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) {
127 /* We have a list of sr_usb_dev_inst matching the connection
128 * string. Wrap them in sr_dev_inst and we're done. */
129 for (l = usb_devices; l; l = l->next) {
131 if (!(sdi = lascar_scan(usb->bus, usb->address))) {
132 /* Not a Lascar EL-USB. */
136 if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
137 sr_err("Device context malloc failed.");
142 if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
144 sdi->probes = g_slist_append(sdi->probes, probe);
145 drvc->instances = g_slist_append(drvc->instances, sdi);
146 devices = g_slist_append(devices, sdi);
148 g_slist_free(usb_devices);
150 g_slist_free_full(usb_devices, g_free);
155 static GSList *hw_dev_list(void)
157 struct drv_context *drvc;
161 return drvc->instances;
164 static int hw_dev_open(struct sr_dev_inst *sdi)
171 static int hw_dev_close(struct sr_dev_inst *sdi)
178 static int hw_cleanup(void)
187 static int hw_info_get(int info_id, const void **data,
188 const struct sr_dev_inst *sdi)
193 sr_err("Unknown info_id: %d.", info_id);
200 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
205 if (sdi->status != SR_ST_ACTIVE) {
206 sr_err("Device inactive, can't set config options.");
214 sr_err("Unknown hardware capability: %d.", hwcap);
221 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
229 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
233 if (sdi->status != SR_ST_ACTIVE) {
234 sr_err("Device inactive, can't stop acquisition.");
243 SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info = {
244 .name = "lascar-el-usb",
245 .longname = "Lascar EL-USB",
248 .cleanup = hw_cleanup,
250 .dev_list = hw_dev_list,
251 .dev_clear = clear_instances,
252 .dev_open = hw_dev_open,
253 .dev_close = hw_dev_close,
254 .info_get = hw_info_get,
255 .dev_config_set = hw_dev_config_set,
256 .dev_acquisition_start = hw_dev_acquisition_start,
257 .dev_acquisition_stop = hw_dev_acquisition_stop,