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 <sigrok-internal.h>
25 extern struct sr_global *global;
27 GSList *devices = NULL;
30 void sr_device_scan(void)
33 struct sr_device_plugin *plugin;
35 plugins = sr_list_hwplugins();
38 * Initialize all plugins first. Since the init() call may involve
39 * a firmware upload and associated delay, we may as well get all
40 * of these out of the way first.
42 for (l = plugins; l; l = l->next) {
44 sr_init_hwplugins(plugin);
49 GSList *sr_device_list(void)
58 struct sr_device *sr_device_new(struct sr_device_plugin *plugin, int plugin_index,
61 struct sr_device *device;
64 if (!(device = g_try_malloc0(sizeof(struct sr_device)))) {
65 sr_err("dev: %s: device malloc failed", __func__);
69 device->plugin = plugin;
70 device->plugin_index = plugin_index;
71 devices = g_slist_append(devices, device);
73 for (i = 0; i < num_probes; i++)
74 sr_device_probe_add(device, NULL);
79 void sr_device_clear(struct sr_device *device)
86 for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
87 sr_device_probe_clear(device, pnum);
90 void sr_device_probe_clear(struct sr_device *device, int probenum)
94 p = sr_device_probe_find(device, probenum);
109 void sr_device_probe_add(struct sr_device *device, const char *name)
115 probenum = g_slist_length(device->probes) + 1;
117 if (!(p = g_try_malloc0(sizeof(struct sr_probe)))) {
118 sr_err("dev: %s: p malloc failed", __func__);
119 // return SR_ERR_MALLOC;
120 return; /* FIXME: should return int. */
126 p->name = g_strdup(name);
128 snprintf(probename, 16, "%d", probenum);
129 p->name = g_strdup(probename);
132 device->probes = g_slist_append(device->probes, p);
135 struct sr_probe *sr_device_probe_find(struct sr_device *device, int probenum)
138 struct sr_probe *p, *found_probe;
141 for (l = device->probes; l; l = l->next) {
143 if (p->index == probenum) {
152 /* TODO: return SR_ERR if probenum not found */
153 void sr_device_probe_name(struct sr_device *device, int probenum,
158 p = sr_device_probe_find(device, probenum);
164 p->name = g_strdup(name);
167 /* TODO: return SR_ERR if probenum not found */
168 void sr_device_trigger_clear(struct sr_device *device)
176 for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
177 p = sr_device_probe_find(device, pnum);
178 if (p && p->trigger) {
185 /* TODO: return SR_ERR if probenum not found */
186 void sr_device_trigger_set(struct sr_device *device, int probenum,
191 p = sr_device_probe_find(device, probenum);
198 p->trigger = g_strdup(trigger);
202 gboolean sr_device_has_hwcap(struct sr_device *device, int hwcap)
204 int *capabilities, i;
206 if (!device || !device->plugin)
209 if ((capabilities = device->plugin->get_capabilities()))
210 for (i = 0; capabilities[i]; i++)
211 if (capabilities[i] == hwcap)