2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 Marcus Comstedt <marcus@mc.pp.se>
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/>.
24 #include "libsigrok.h"
25 #include "libsigrok-internal.h"
28 #define LOGIC16_VID 0x21a9
29 #define LOGIC16_PID 0x1001
32 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info;
33 static struct sr_dev_driver *di = &saleae_logic16_driver_info;
35 static const char *probe_names[NUM_PROBES + 1] = {
36 "0", "1", "2", "3", "4", "5", "6", "7", "8",
37 "9", "10", "11", "12", "13", "14", "15",
41 static int init(struct sr_context *sr_ctx)
43 return std_init(sr_ctx, di, LOG_PREFIX);
46 static GSList *scan(GSList *options)
48 struct drv_context *drvc;
49 struct dev_context *devc;
50 struct sr_dev_inst *sdi;
51 struct sr_probe *probe;
52 struct libusb_device_descriptor des;
53 libusb_device **devlist;
55 int ret, devcnt, i, j;
62 libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
63 for (i = 0; devlist[i]; i++) {
64 if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
65 sr_warn("Failed to get device descriptor: %s",
66 libusb_error_name(ret));
70 if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
73 devcnt = g_slist_length(drvc->instances);
74 if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
75 "Saleae", "Logic16", NULL)))
79 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
83 for (j = 0; probe_names[j]; j++) {
84 if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
87 sdi->probes = g_slist_append(sdi->probes, probe);
90 if (!(sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
91 libusb_get_device_address(devlist[i]), NULL)))
93 sdi->inst_type = SR_INST_USB;
95 drvc->instances = g_slist_append(drvc->instances, sdi);
96 devices = g_slist_append(devices, sdi);
98 libusb_free_device_list(devlist, 1);
103 static GSList *dev_list(void)
105 struct drv_context *drvc;
109 return drvc->instances;
112 static int dev_clear(void)
114 return std_dev_clear(di, NULL);
117 static int dev_open(struct sr_dev_inst *sdi)
121 /* TODO: get handle from sdi->conn and open it. */
123 sdi->status = SR_ST_ACTIVE;
128 static int dev_close(struct sr_dev_inst *sdi)
132 /* TODO: get handle from sdi->conn and close it. */
134 sdi->status = SR_ST_INACTIVE;
139 static int cleanup(void)
142 struct drv_context *drvc;
144 if (!(drvc = di->priv))
145 /* Can get called on an unused driver, doesn't matter. */
155 static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
172 static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
178 if (sdi->status != SR_ST_ACTIVE)
179 return SR_ERR_DEV_CLOSED;
191 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
208 static int dev_acquisition_start(const struct sr_dev_inst *sdi,
214 if (sdi->status != SR_ST_ACTIVE)
215 return SR_ERR_DEV_CLOSED;
217 /* TODO: configure hardware, reset acquisition state, set up
218 * callbacks and send header packet. */
223 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
227 if (sdi->status != SR_ST_ACTIVE)
228 return SR_ERR_DEV_CLOSED;
230 /* TODO: stop acquisition. */
235 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info = {
236 .name = "saleae-logic16",
237 .longname = "Saleae Logic16",
242 .dev_list = dev_list,
243 .dev_clear = dev_clear,
244 .config_get = config_get,
245 .config_set = config_set,
246 .config_list = config_list,
247 .dev_open = dev_open,
248 .dev_close = dev_close,
249 .dev_acquisition_start = dev_acquisition_start,
250 .dev_acquisition_stop = dev_acquisition_stop,