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 */
35 /* this enumerates which plugin capabilities correspond to user-settable options */
36 struct hwcap_option hwcap_options[] = {
37 { HWCAP_SAMPLERATE, T_UINT64, "Sample rate", "samplerate" },
41 extern struct device_plugin saleae_logic_plugin_info;
42 extern struct device_plugin ols_plugin_info;
43 extern struct device_plugin zeroplus_logic_cube_plugin_info;
45 int load_hwplugins(void)
47 plugins = g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
48 plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
49 plugins = g_slist_append(plugins, (gpointer *)&zeroplus_logic_cube_plugin_info);
55 GSList *list_hwplugins(void)
62 struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
63 char *vendor, char *model, char *version)
65 struct sigrok_device_instance *sdi;
67 sdi = malloc(sizeof(struct sigrok_device_instance));
73 sdi->instance_type = -1;
74 sdi->vendor = strdup(vendor);
75 sdi->model = strdup(model);
76 sdi->version = strdup(version);
83 struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index)
85 struct sigrok_device_instance *sdi;
89 for(l = device_instances; l; l = l->next) {
90 sdi = (struct sigrok_device_instance *) (l->data);
91 if(sdi->index == device_index)
94 g_warning("could not find device index %d instance", device_index);
100 void sigrok_device_instance_free(struct sigrok_device_instance *sdi)
103 switch(sdi->instance_type) {
105 usb_device_instance_free(sdi->usb);
107 case SERIAL_INSTANCE:
108 serial_device_instance_free(sdi->serial);
110 /* no specific type, nothing extra to free */
121 struct usb_device_instance *usb_device_instance_new(uint8_t bus, uint8_t address,
122 struct libusb_device_handle *hdl)
124 struct usb_device_instance *udi;
126 udi = malloc(sizeof(struct usb_device_instance));
131 udi->address = address;
138 void usb_device_instance_free(struct usb_device_instance *usb)
141 /* nothing to do for this device instance type */
146 struct serial_device_instance *serial_device_instance_new(char *port, int fd)
148 struct serial_device_instance *serial;
150 serial = malloc(sizeof(struct serial_device_instance));
154 serial->port = strdup(port);
161 void serial_device_instance_free(struct serial_device_instance *serial)
169 int find_hwcap(int *capabilities, int hwcap)
173 for(i = 0; capabilities[i]; i++)
174 if(capabilities[i] == hwcap)
181 struct hwcap_option *find_hwcap_option(int hwcap)
183 struct hwcap_option *hwo;
187 for(i = 0; hwcap_options[i].capability; i++)
189 if(hwcap_options[i].capability == hwcap)
191 hwo = &hwcap_options[i];
200 void source_remove(int fd)
204 source_cb_remove(fd);
209 void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data)
213 source_cb_add(fd, events, timeout, rcv_cb, user_data);