]> sigrok.org Git - libsigrok.git/blame_incremental - hwplugin.c
Disable Link Instruments MSO-19 for 0.1.
[libsigrok.git] / hwplugin.c
... / ...
CommitLineData
1/*
2 * This file is part of the sigrok project.
3 *
4 * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <stdlib.h>
21#include <stdio.h>
22#include <sys/types.h>
23#include <dirent.h>
24#include <string.h>
25#include <glib.h>
26#include <sigrok.h>
27#include "config.h"
28
29source_callback_add source_cb_add = NULL;
30source_callback_remove source_cb_remove = NULL;
31
32/* The list of loaded plugins lives here. */
33GSList *plugins;
34
35/*
36 * This enumerates which plugin capabilities correspond to user-settable
37 * options.
38 */
39struct hwcap_option hwcap_options[] = {
40 {HWCAP_SAMPLERATE, T_UINT64, "Sample rate", "samplerate"},
41 {HWCAP_CAPTURE_RATIO, T_UINT64, "Pre-trigger capture ratio", "captureratio"},
42 {HWCAP_PATTERN_MODE, T_CHAR, "Pattern generator mode", "patternmode"},
43 {0, 0, NULL, NULL},
44};
45
46#ifdef HAVE_LA_DEMO
47extern struct device_plugin demo_plugin_info;
48#endif
49#ifdef HAVE_LA_SALEAE_LOGIC
50extern struct device_plugin saleae_logic_plugin_info;
51#endif
52#ifdef HAVE_LA_OLS
53extern struct device_plugin ols_plugin_info;
54#endif
55#ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
56extern struct device_plugin zeroplus_logic_cube_plugin_info;
57#endif
58#ifdef HAVE_LA_ASIX_SIGMA
59extern struct device_plugin asix_sigma_plugin_info;
60#endif
61// #ifdef HAVE_LA_LINK_MSO19
62// extern struct device_plugin link_mso19_plugin_info;
63// #endif
64
65/* TODO: No linked list needed, this can be a simple array. */
66int load_hwplugins(void)
67{
68#ifdef HAVE_LA_DEMO
69 plugins = g_slist_append(plugins, (gpointer *)&demo_plugin_info);
70#endif
71#ifdef HAVE_LA_SALEAE_LOGIC
72 plugins =
73 g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
74#endif
75#ifdef HAVE_LA_OLS
76 plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
77#endif
78#ifdef HAVE_LA_ZEROPLUS_LOGIC_CUBE
79 plugins = g_slist_append(plugins,
80 (gpointer *)&zeroplus_logic_cube_plugin_info);
81#endif
82#ifdef HAVE_LA_ASIX_SIGMA
83 plugins = g_slist_append(plugins, (gpointer *)&asix_sigma_plugin_info);
84#endif
85// #ifdef HAVE_LA_LINK_MSO19
86// plugins = g_slist_append(plugins, (gpointer *)&link_mso19_plugin_info);
87// #endif
88
89 return SIGROK_OK;
90}
91
92GSList *list_hwplugins(void)
93{
94 return plugins;
95}
96
97struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
98 const char *vendor, const char *model, const char *version)
99{
100 struct sigrok_device_instance *sdi;
101
102 if (!(sdi = malloc(sizeof(struct sigrok_device_instance))))
103 return NULL;
104
105 sdi->index = index;
106 sdi->status = status;
107 sdi->instance_type = -1;
108 sdi->vendor = vendor ? strdup(vendor) : strdup("(unknown)");
109 sdi->model = model ? strdup(model) : NULL;
110 sdi->version = version ? strdup(version) : NULL;
111 sdi->priv = NULL;
112 sdi->usb = NULL;
113
114 return sdi;
115}
116
117struct sigrok_device_instance *get_sigrok_device_instance(
118 GSList *device_instances, int device_index)
119{
120 struct sigrok_device_instance *sdi;
121 GSList *l;
122
123 for (l = device_instances; l; l = l->next) {
124 sdi = (struct sigrok_device_instance *)(l->data);
125 if (sdi->index == device_index)
126 return sdi;
127 }
128 g_warning("could not find device index %d instance", device_index);
129
130 return NULL;
131}
132
133void sigrok_device_instance_free(struct sigrok_device_instance *sdi)
134{
135 switch (sdi->instance_type) {
136 case USB_INSTANCE:
137 usb_device_instance_free(sdi->usb);
138 break;
139 case SERIAL_INSTANCE:
140 serial_device_instance_free(sdi->serial);
141 break;
142 default:
143 /* No specific type, nothing extra to free. */
144 break;
145 }
146
147 free(sdi->vendor);
148 free(sdi->model);
149 free(sdi->version);
150 free(sdi);
151}
152
153struct usb_device_instance *usb_device_instance_new(uint8_t bus,
154 uint8_t address, struct libusb_device_handle *hdl)
155{
156 struct usb_device_instance *udi;
157
158 if (!(udi = malloc(sizeof(struct usb_device_instance))))
159 return NULL;
160
161 udi->bus = bus;
162 udi->address = address;
163 udi->devhdl = hdl; /* TODO: Check if this is NULL? */
164
165 return udi;
166}
167
168void usb_device_instance_free(struct usb_device_instance *usb)
169{
170 /* Avoid compiler warnings. */
171 usb = usb;
172
173 /* Nothing to do for this device instance type. */
174}
175
176struct serial_device_instance *serial_device_instance_new(
177 const char *port, int fd)
178{
179 struct serial_device_instance *serial;
180
181 if (!(serial = malloc(sizeof(struct serial_device_instance))))
182 return NULL;
183
184 serial->port = strdup(port);
185 serial->fd = fd;
186
187 return serial;
188}
189
190void serial_device_instance_free(struct serial_device_instance *serial)
191{
192 free(serial->port);
193}
194
195int find_hwcap(int *capabilities, int hwcap)
196{
197 int i;
198
199 for (i = 0; capabilities[i]; i++) {
200 if (capabilities[i] == hwcap)
201 return TRUE;
202 }
203
204 return FALSE;
205}
206
207struct hwcap_option *find_hwcap_option(int hwcap)
208{
209 int i;
210
211 for (i = 0; hwcap_options[i].capability; i++) {
212 if (hwcap_options[i].capability == hwcap)
213 return &hwcap_options[i];
214 }
215
216 return NULL;
217}
218
219void source_remove(int fd)
220{
221 if (source_cb_remove)
222 source_cb_remove(fd);
223}
224
225void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
226 void *user_data)
227{
228 if (source_cb_add)
229 source_cb_add(fd, events, timeout, rcv_cb, user_data);
230}