2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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/>.
28 #include "sigrok-internal.h"
31 static struct fx2lafw_profile supported_fx2[] = {
33 { 0x08a9, 0x0014, "CWAV", "USBee AX", NULL, 8 },
37 static int fx2lafw_capabilities[] = {
38 SR_HWCAP_LOGIC_ANALYZER,
41 /* These are really implemented in the driver, not the hardware. */
42 SR_HWCAP_LIMIT_SAMPLES,
47 static const char *fx2lafw_probe_names[] = {
59 static uint64_t fx2lafw_supported_samplerates[] = {
71 static struct sr_samplerates fx2lafw_samplerates = {
75 fx2lafw_supported_samplerates
78 static GSList *device_instances = NULL;
79 static libusb_context *usb_context = NULL;
81 static struct fx2lafw_device* fx2lafw_device_new(void)
83 struct fx2lafw_device *fx2lafw;
85 if (!(fx2lafw = g_try_malloc0(sizeof(struct fx2lafw_device)))) {
86 sr_err("fx2lafw: %s: fx2lafw_device malloc failed", __func__);
97 static int hw_init(const char *deviceinfo)
99 struct sr_dev_inst *sdi;
100 struct libusb_device_descriptor des;
101 struct fx2lafw_profile *fx2lafw_prof;
102 struct fx2lafw_device *fx2lafw_dev;
103 libusb_device **devlist;
108 /* Avoid compiler warnings. */
111 if (libusb_init(&usb_context) != 0) {
112 sr_warn("Failed to initialize USB.");
116 /* Find all fx2lafw compatible devices and upload firware to all of them. */
117 libusb_get_device_list(usb_context, &devlist);
118 for (i = 0; devlist[i]; i++) {
120 if ((err = libusb_get_device_descriptor(
121 devlist[i], &des)) != 0) {
122 sr_warn("failed to get device descriptor: %d", err);
127 for (j = 0; supported_fx2[j].vid; j++) {
128 if (des.idVendor == supported_fx2[j].vid &&
129 des.idProduct == supported_fx2[j].pid) {
130 fx2lafw_prof = &supported_fx2[j];
134 /* Skip if the device was not found */
138 sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING,
139 fx2lafw_prof->vendor, fx2lafw_prof->model,
140 fx2lafw_prof->model_version);
144 fx2lafw_dev = fx2lafw_device_new();
145 fx2lafw_dev->profile = fx2lafw_prof;
146 sdi->priv = fx2lafw_dev;
147 device_instances = g_slist_append(device_instances, sdi);
151 libusb_free_device_list(devlist, 1);
156 static int hw_dev_open(int device_index)
162 static int hw_dev_close(int device_index)
168 static int hw_cleanup(void)
171 struct sr_dev_inst *sdi;
173 for(l = device_instances; l; l = l->next) {
175 sr_dev_inst_free(sdi);
178 g_slist_free(device_instances);
179 device_instances = NULL;
182 libusb_exit(usb_context);
188 static void *hw_dev_info_get(int device_index, int device_info_id)
190 struct sr_dev_inst *sdi;
191 struct fx2lafw_device *fx2lafw_dev;
193 if (!(sdi = sr_dev_inst_get(device_instances, device_index)))
195 fx2lafw_dev = sdi->priv;
197 switch (device_info_id) {
200 case SR_DI_NUM_PROBES:
201 return GINT_TO_POINTER(fx2lafw_dev->profile->num_probes);
202 case SR_DI_PROBE_NAMES:
203 return fx2lafw_probe_names;
204 case SR_DI_SAMPLERATES:
205 return &fx2lafw_samplerates;
206 case SR_DI_TRIGGER_TYPES:
207 return TRIGGER_TYPES;
213 static int hw_dev_status_get(int device_index)
216 return SR_ST_NOT_FOUND;
219 static int *hw_hwcap_get_all(void)
221 return fx2lafw_capabilities;
224 static int hw_dev_config_set(int dev_index, int capability, void *value)
232 static int hw_dev_acquisition_start(int dev_index, gpointer session_data)
239 /* This stops acquisition on ALL devices, ignoring device_index. */
240 static int hw_dev_acquisition_stop(int dev_index, gpointer session_data)
247 SR_PRIV struct sr_dev_plugin fx2lafw_plugin_info = {
249 .longname = "fx2lafw",
252 .cleanup = hw_cleanup,
253 .dev_open = hw_dev_open,
254 .dev_close = hw_dev_close,
255 .dev_info_get = hw_dev_info_get,
256 .dev_status_get = hw_dev_status_get,
257 .hwcap_get_all = hw_hwcap_get_all,
258 .dev_config_set = hw_dev_config_set,
259 .dev_acquisition_start = hw_dev_acquisition_start,
260 .dev_acquisition_stop = hw_dev_acquisition_stop,