2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 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 <sys/types.h>
29 source_callback_add source_cb_add = NULL;
30 source_callback_remove source_cb_remove = NULL;
32 /* The list of loaded plugins lives here. */
36 * This enumerates which plugin capabilities correspond to user-settable
39 struct hwcap_option hwcap_options[] = {
40 {HWCAP_SAMPLERATE, T_UINT64, "Sample rate", "samplerate"},
41 {HWCAP_CAPTURE_RATIO, T_UINT64, "Pre-trigger capture ratio", "captureratio"},
45 #ifdef HAVE_LA_SALEAE_LOGIC
46 extern struct device_plugin saleae_logic_plugin_info;
49 extern struct device_plugin ols_plugin_info;
51 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
52 extern struct device_plugin zeroplus_logic_cube_plugin_info;
54 #ifdef HAVE_LA_ASIX_SIGMA
55 extern struct device_plugin asix_sigma_plugin_info;
58 /* TODO: No linked list needed, this can be a simple array. */
59 int load_hwplugins(void)
61 #ifdef HAVE_LA_SALEAE_LOGIC
63 g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
66 plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
68 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
69 plugins = g_slist_append(plugins,
70 (gpointer *)&zeroplus_logic_cube_plugin_info);
72 #ifdef HAVE_LA_ASIX_SIGMA
73 plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info);
79 GSList *list_hwplugins(void)
84 struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
85 const char *vendor, const char *model, const char *version)
87 struct sigrok_device_instance *sdi;
89 if (!(sdi = malloc(sizeof(struct sigrok_device_instance))))
94 sdi->instance_type = -1;
95 sdi->vendor = strdup(vendor);
96 sdi->model = strdup(model);
97 sdi->version = strdup(version);
103 struct sigrok_device_instance *get_sigrok_device_instance(
104 GSList *device_instances, int device_index)
106 struct sigrok_device_instance *sdi;
109 for (l = device_instances; l; l = l->next) {
110 sdi = (struct sigrok_device_instance *)(l->data);
111 if (sdi->index == device_index)
114 g_warning("could not find device index %d instance", device_index);
119 void sigrok_device_instance_free(struct sigrok_device_instance *sdi)
121 switch (sdi->instance_type) {
123 usb_device_instance_free(sdi->usb);
125 case SERIAL_INSTANCE:
126 serial_device_instance_free(sdi->serial);
129 /* No specific type, nothing extra to free. */
139 struct usb_device_instance *usb_device_instance_new(uint8_t bus,
140 uint8_t address, struct libusb_device_handle *hdl)
142 struct usb_device_instance *udi;
144 if (!(udi = malloc(sizeof(struct usb_device_instance))))
148 udi->address = address;
149 udi->devhdl = hdl; /* TODO: Check if this is NULL? */
154 void usb_device_instance_free(struct usb_device_instance *usb)
159 /* Nothing to do for this device instance type. */
162 struct serial_device_instance *serial_device_instance_new(
163 const char *port, int fd)
165 struct serial_device_instance *serial;
167 if (!(serial = malloc(sizeof(struct serial_device_instance))))
170 serial->port = strdup(port);
176 void serial_device_instance_free(struct serial_device_instance *serial)
181 int find_hwcap(int *capabilities, int hwcap)
185 for (i = 0; capabilities[i]; i++) {
186 if (capabilities[i] == hwcap)
193 struct hwcap_option *find_hwcap_option(int hwcap)
197 for (i = 0; hwcap_options[i].capability; i++) {
198 if (hwcap_options[i].capability == hwcap)
199 return &hwcap_options[i];
205 void source_remove(int fd)
207 if (source_cb_remove)
208 source_cb_remove(fd);
211 void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
215 source_cb_add(fd, events, timeout, rcv_cb, user_data);