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