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/>.
23 #include <sys/types.h>
28 #include <sigrok-internal.h>
30 /* The list of loaded plugins lives here. */
34 * This enumerates which plugin capabilities correspond to user-settable
37 /* TODO: This shouldn't be a global. */
38 struct sr_hwcap_option sr_hwcap_options[] = {
39 {SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"},
40 {SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"},
41 {SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "patternmode"},
42 {SR_HWCAP_RLE, SR_T_BOOL, "Run Length Encoding", "rle"},
47 extern struct sr_device_plugin demo_plugin_info;
49 #ifdef HAVE_LA_SALEAE_LOGIC
50 extern struct sr_device_plugin saleae_logic_plugin_info;
53 extern struct sr_device_plugin ols_plugin_info;
55 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
56 extern struct sr_device_plugin zeroplus_logic_cube_plugin_info;
58 #ifdef HAVE_LA_ASIX_SIGMA
59 extern struct sr_device_plugin asix_sigma_plugin_info;
61 #ifdef HAVE_LA_CHRONOVU_LA8
62 extern struct device_plugin chronovu_la8_plugin_info;
64 #ifdef HAVE_LA_LINK_MSO19
65 extern struct sr_device_plugin link_mso19_plugin_info;
68 extern struct sr_device_plugin alsa_plugin_info;
72 /* TODO: No linked list needed, this can be a simple array. */
73 int load_hwplugins(void)
76 plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info);
78 #ifdef HAVE_LA_SALEAE_LOGIC
80 g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
83 plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
85 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
86 plugins = g_slist_append(plugins,
87 (gpointer *)&zeroplus_logic_cube_plugin_info);
89 #ifdef HAVE_LA_ASIX_SIGMA
90 plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info);
92 #ifdef HAVE_LA_CHRONOVU_LA8
93 plugins = g_slist_append(plugins, (gpointer *)&chronovu_la8_plugin_info);
95 #ifdef HAVE_LA_LINK_MSO19
96 plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info);
99 plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info);
106 GSList *sr_list_hwplugins(void)
111 int sr_init_hwplugins(struct sr_device_plugin *plugin)
113 int num_devices, num_probes, i;
115 g_message("initializing %s plugin", plugin->name);
116 num_devices = plugin->init(NULL);
117 for (i = 0; i < num_devices; i++) {
118 num_probes = GPOINTER_TO_INT(
119 plugin->get_device_info(i, SR_DI_NUM_PROBES));
120 sr_device_new(plugin, i, num_probes);
126 void sr_cleanup_hwplugins(void)
128 struct sr_device_plugin *plugin;
131 for (l = plugins; l; l = l->next) {
139 struct sr_device_instance *sr_device_instance_new(int index, int status,
140 const char *vendor, const char *model, const char *version)
142 struct sr_device_instance *sdi;
144 if (!(sdi = g_malloc(sizeof(struct sr_device_instance))))
148 sdi->status = status;
149 sdi->instance_type = -1;
150 sdi->vendor = vendor ? g_strdup(vendor) : NULL;
151 sdi->model = model ? g_strdup(model) : NULL;
152 sdi->version = version ? g_strdup(version) : NULL;
159 struct sr_device_instance *sr_get_device_instance(GSList *device_instances,
162 struct sr_device_instance *sdi;
165 for (l = device_instances; l; l = l->next) {
166 sdi = (struct sr_device_instance *)(l->data);
167 if (sdi->index == device_index)
170 sr_warn("could not find device index %d instance", device_index);
175 void sr_device_instance_free(struct sr_device_instance *sdi)
177 switch (sdi->instance_type) {
178 #ifdef HAVE_LIBUSB_1_0
179 case SR_USB_INSTANCE:
180 sr_usb_device_instance_free(sdi->usb);
183 case SR_SERIAL_INSTANCE:
184 sr_serial_device_instance_free(sdi->serial);
187 /* No specific type, nothing extra to free. */
196 g_free(sdi->version);
201 #ifdef HAVE_LIBUSB_1_0
203 struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
204 uint8_t address, struct libusb_device_handle *hdl)
206 struct sr_usb_device_instance *udi;
208 if (!(udi = malloc(sizeof(struct sr_usb_device_instance))))
212 udi->address = address;
213 udi->devhdl = hdl; /* TODO: Check if this is NULL? */
218 void sr_usb_device_instance_free(struct sr_usb_device_instance *usb)
220 /* Avoid compiler warnings. */
223 /* Nothing to do for this device instance type. */
228 struct sr_serial_device_instance *sr_serial_device_instance_new(
229 const char *port, int fd)
231 struct sr_serial_device_instance *serial;
233 if (!(serial = malloc(sizeof(struct sr_serial_device_instance))))
236 serial->port = strdup(port);
242 void sr_serial_device_instance_free(struct sr_serial_device_instance *serial)
247 int sr_find_hwcap(int *capabilities, int hwcap)
251 for (i = 0; capabilities[i]; i++) {
252 if (capabilities[i] == hwcap)
259 struct sr_hwcap_option *sr_find_hwcap_option(int hwcap)
263 for (i = 0; sr_hwcap_options[i].capability; i++) {
264 if (sr_hwcap_options[i].capability == hwcap)
265 return &sr_hwcap_options[i];
271 /* unnecessary level of indirection follows. */
273 void sr_source_remove(int fd)
275 sr_session_source_remove(fd);
278 void sr_source_add(int fd, int events, int timeout,
279 sr_receive_data_callback rcv_cb, void *user_data)
281 sr_session_source_add(fd, events, timeout, rcv_cb, user_data);