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>
27 #include "sigrok-internal.h"
29 /* The list of loaded plugins lives here. */
30 static GSList *plugins;
33 * This enumerates which plugin capabilities correspond to user-settable
36 /* TODO: This shouldn't be a global. */
37 SR_API struct sr_hwcap_option sr_hwcap_options[] = {
38 {SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"},
39 {SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"},
40 {SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "patternmode"},
41 {SR_HWCAP_RLE, SR_T_BOOL, "Run Length Encoding", "rle"},
46 extern struct sr_device_plugin demo_plugin_info;
48 #ifdef HAVE_LA_SALEAE_LOGIC
49 extern struct sr_device_plugin saleae_logic_plugin_info;
52 extern struct sr_device_plugin ols_plugin_info;
54 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
55 extern struct sr_device_plugin zeroplus_logic_cube_plugin_info;
57 #ifdef HAVE_LA_ASIX_SIGMA
58 extern struct sr_device_plugin asix_sigma_plugin_info;
60 #ifdef HAVE_LA_CHRONOVU_LA8
61 extern struct device_plugin chronovu_la8_plugin_info;
63 #ifdef HAVE_LA_LINK_MSO19
64 extern struct sr_device_plugin link_mso19_plugin_info;
67 extern struct sr_device_plugin alsa_plugin_info;
70 /* TODO: No linked list needed, this can be a simple array. */
71 SR_PRIV int load_hwplugins(void)
74 plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info);
76 #ifdef HAVE_LA_SALEAE_LOGIC
78 g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
81 plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
83 #ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
84 plugins = g_slist_append(plugins,
85 (gpointer *)&zeroplus_logic_cube_plugin_info);
87 #ifdef HAVE_LA_ASIX_SIGMA
88 plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info);
90 #ifdef HAVE_LA_CHRONOVU_LA8
91 plugins = g_slist_append(plugins, (gpointer *)&chronovu_la8_plugin_info);
93 #ifdef HAVE_LA_LINK_MSO19
94 plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info);
97 plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info);
103 SR_API GSList *sr_list_hwplugins(void)
108 SR_API int sr_init_hwplugins(struct sr_device_plugin *plugin)
110 int num_devices, num_probes, i, j;
111 int num_initialized_devices = 0;
112 struct sr_device *device;
115 sr_dbg("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 probe_names = (char **)plugin->get_device_info(i,
124 sr_warn("hwplugin: %s: plugin %s does not return a "
125 "list of probe names", __func__, plugin->name);
129 device = sr_device_new(plugin, i);
130 for (j = 0; j < num_probes; j++)
131 sr_device_probe_add(device, probe_names[j]);
132 num_initialized_devices++;
135 return num_initialized_devices;
138 SR_API void sr_cleanup_hwplugins(void)
140 struct sr_device_plugin *plugin;
143 for (l = plugins; l; l = l->next) {
150 SR_API struct sr_device_instance *sr_device_instance_new(int index, int status,
151 const char *vendor, const char *model, const char *version)
153 struct sr_device_instance *sdi;
155 if (!(sdi = g_malloc(sizeof(struct sr_device_instance))))
159 sdi->status = status;
160 sdi->instance_type = -1;
161 sdi->vendor = vendor ? g_strdup(vendor) : NULL;
162 sdi->model = model ? g_strdup(model) : NULL;
163 sdi->version = version ? g_strdup(version) : NULL;
169 SR_API struct sr_device_instance *sr_get_device_instance(
170 GSList *device_instances, int device_index)
172 struct sr_device_instance *sdi;
175 for (l = device_instances; l; l = l->next) {
176 sdi = (struct sr_device_instance *)(l->data);
177 if (sdi->index == device_index)
180 sr_warn("could not find device index %d instance", device_index);
185 SR_API void sr_device_instance_free(struct sr_device_instance *sdi)
190 g_free(sdi->version);
194 #ifdef HAVE_LIBUSB_1_0
196 SR_PRIV struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
197 uint8_t address, struct libusb_device_handle *hdl)
199 struct sr_usb_device_instance *udi;
201 if (!(udi = malloc(sizeof(struct sr_usb_device_instance))))
205 udi->address = address;
206 udi->devhdl = hdl; /* TODO: Check if this is NULL? */
211 SR_PRIV void sr_usb_device_instance_free(struct sr_usb_device_instance *usb)
213 /* Avoid compiler warnings. */
216 /* Nothing to do for this device instance type. */
221 SR_PRIV struct sr_serial_device_instance *sr_serial_device_instance_new(
222 const char *port, int fd)
224 struct sr_serial_device_instance *serial;
226 if (!(serial = malloc(sizeof(struct sr_serial_device_instance))))
229 serial->port = strdup(port);
235 SR_PRIV void sr_serial_device_instance_free(
236 struct sr_serial_device_instance *serial)
241 SR_API int sr_find_hwcap(int *capabilities, int hwcap)
245 for (i = 0; capabilities[i]; i++) {
246 if (capabilities[i] == hwcap)
253 SR_API struct sr_hwcap_option *sr_find_hwcap_option(int hwcap)
257 for (i = 0; sr_hwcap_options[i].capability; i++) {
258 if (sr_hwcap_options[i].capability == hwcap)
259 return &sr_hwcap_options[i];
265 /* unnecessary level of indirection follows. */
267 void sr_source_remove(int fd)
269 sr_session_source_remove(fd);
272 void sr_source_add(int fd, int events, int timeout,
273 sr_receive_data_callback rcv_cb, void *user_data)
275 sr_session_source_add(fd, events, timeout, rcv_cb, user_data);