]>
Commit | Line | Data |
---|---|---|
35a078bc BV |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 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 | ||
523dfc24 | 20 | #include <string.h> |
35a078bc BV |
21 | #include <glib.h> |
22 | #include "libsigrok.h" | |
23 | #include "libsigrok-internal.h" | |
24 | #include "protocol.h" | |
25 | ||
523dfc24 BV |
26 | #define OSCI_VENDOR "Nexus Computing" |
27 | #define OSCI_MODEL "OsciPrime" | |
28 | #define OSCI_VERSION "1.0" | |
29 | #define OSCI_FIRMWARE FIRMWARE_DIR "/nexus-osciprime.fw" | |
30 | #define OSCI_VIDPID "04b4.1004" | |
31 | ||
c8733a2b | 32 | static const int32_t hwopts[] = { |
1953564a BV |
33 | SR_CONF_CONN, |
34 | SR_CONF_SERIALCOMM, | |
523dfc24 BV |
35 | }; |
36 | ||
c8733a2b | 37 | static const int32_t hwcaps[] = { |
1953564a BV |
38 | SR_CONF_OSCILLOSCOPE, |
39 | SR_CONF_LIMIT_SAMPLES, | |
40 | SR_CONF_CONTINUOUS, | |
41 | SR_CONF_TIMEBASE, | |
42 | SR_CONF_VDIV, | |
523dfc24 BV |
43 | }; |
44 | ||
b9470914 | 45 | static const uint64_t timebases[][2] = { |
523dfc24 BV |
46 | /* 24 MHz */ |
47 | { 42, 1e9 }, | |
48 | /* 12 MHz */ | |
49 | { 83, 1e9 }, | |
50 | /* 6 MHz */ | |
51 | { 167, 1e9 }, | |
52 | /* 3 MHz */ | |
53 | { 333, 1e9 }, | |
54 | /* 1.5 MHz */ | |
55 | { 667, 1e9 }, | |
56 | /* 750 kHz */ | |
57 | { 1333, 1e9 }, | |
58 | /* 375 kHz */ | |
59 | { 2667, 1e9 }, | |
60 | /* 187.5 kHz */ | |
61 | { 5333, 1e9 }, | |
62 | /* 93.25 kHz */ | |
63 | { 10724, 1e9 }, | |
64 | /* 46.875 kHz */ | |
65 | { 21333, 1e9 }, | |
66 | /* 23.4375 kHz */ | |
67 | { 42666, 1e9 }, | |
68 | /* 11.718 kHz */ | |
69 | { 85339, 1e9 }, | |
70 | /* 5.859 kHz */ | |
71 | { 170678, 1e9 }, | |
72 | /* 2.929 kHz */ | |
73 | { 341413, 1e9 }, | |
74 | /* 1.465 kHz */ | |
75 | { 682594, 1e9 }, | |
76 | /* 732 Hz */ | |
77 | { 1366, 1e6 }, | |
78 | /* 366 Hz */ | |
79 | { 2732, 1e6 }, | |
80 | /* 183 Hz */ | |
81 | { 5464, 1e6 }, | |
82 | /* 91 Hz */ | |
83 | { 10989, 1e6 }, | |
84 | /* 46 Hz */ | |
85 | { 21739, 1e6 }, | |
86 | /* 23 Hz */ | |
87 | { 43478, 1e6 }, | |
88 | /* 12 Hz */ | |
89 | { 83333, 1e6 }, | |
90 | }; | |
91 | ||
92 | static const char *probe_names[] = { | |
78693401 | 93 | "CHA", "CHB", |
523dfc24 BV |
94 | NULL, |
95 | }; | |
96 | ||
b9470914 | 97 | static const uint64_t vdivs[][2] = { |
523dfc24 BV |
98 | { 1, 1 }, |
99 | { 2, 1 }, | |
100 | { 5, 2 }, | |
101 | { 5, 1 }, | |
102 | { 10, 1 }, | |
103 | }; | |
104 | ||
35a078bc BV |
105 | SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info; |
106 | static struct sr_dev_driver *di = &nexus_osciprime_driver_info; | |
107 | ||
3b412e3a | 108 | static int dev_clear(void) |
35a078bc | 109 | { |
658636f1 | 110 | return std_dev_clear(di, NULL); |
35a078bc BV |
111 | } |
112 | ||
6078d2c9 | 113 | static int init(struct sr_context *sr_ctx) |
35a078bc | 114 | { |
f6beaac5 | 115 | return std_init(sr_ctx, di, LOG_PREFIX); |
35a078bc BV |
116 | } |
117 | ||
6078d2c9 | 118 | static GSList *scan(GSList *options) |
35a078bc BV |
119 | { |
120 | struct drv_context *drvc; | |
523dfc24 BV |
121 | struct dev_context *devc; |
122 | struct sr_dev_inst *sdi; | |
123 | struct sr_usb_dev_inst *usb; | |
1987b8d6 | 124 | struct sr_config *src; |
523dfc24 BV |
125 | struct sr_probe *probe; |
126 | libusb_device *dev; | |
127 | GSList *usb_devices, *devices, *l; | |
128 | int i; | |
129 | const char *conn; | |
35a078bc | 130 | |
4b97c74e | 131 | drvc = di->priv; |
35a078bc | 132 | |
523dfc24 BV |
133 | conn = NULL; |
134 | for (l = options; l; l = l->next) { | |
1987b8d6 BV |
135 | src = l->data; |
136 | switch (src->key) { | |
1953564a | 137 | case SR_CONF_CONN: |
c8733a2b | 138 | conn = g_variant_get_string(src->data, NULL); |
523dfc24 BV |
139 | break; |
140 | } | |
141 | } | |
142 | if (!conn) | |
143 | conn = OSCI_VIDPID; | |
144 | ||
145 | devices = NULL; | |
146 | if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) { | |
147 | for (l = usb_devices; l; l = l->next) { | |
148 | usb = l->data; | |
149 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, | |
150 | OSCI_VENDOR, OSCI_MODEL, OSCI_VERSION))) | |
151 | return NULL; | |
152 | sdi->driver = di; | |
153 | for (i = 0; probe_names[i]; i++) { | |
154 | if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, | |
155 | probe_names[i]))) | |
156 | return NULL; | |
157 | sdi->probes = g_slist_append(sdi->probes, probe); | |
158 | } | |
159 | ||
160 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) | |
161 | return NULL; | |
162 | sdi->priv = devc; | |
163 | devc->usb = usb; | |
164 | ||
165 | if (strcmp(conn, OSCI_VIDPID)) { | |
166 | if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK) | |
167 | break; | |
168 | dev = libusb_get_device(usb->devhdl); | |
169 | if (ezusb_upload_firmware(dev, 0, OSCI_FIRMWARE) == SR_OK) | |
170 | /* Remember when the firmware on this device was updated */ | |
171 | devc->fw_updated = g_get_monotonic_time(); | |
172 | else | |
173 | sr_err("Firmware upload failed for device " | |
174 | "at bus %d address %d.", usb->bus, usb->address); | |
175 | } | |
176 | ||
177 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
178 | devices = g_slist_append(devices, sdi); | |
179 | } | |
180 | g_slist_free(usb_devices); | |
181 | } else | |
182 | g_slist_free_full(usb_devices, g_free); | |
35a078bc BV |
183 | |
184 | return devices; | |
185 | } | |
186 | ||
6078d2c9 | 187 | static GSList *dev_list(void) |
35a078bc | 188 | { |
0e94d524 | 189 | return ((struct drv_context *)(di->priv))->instances; |
35a078bc BV |
190 | } |
191 | ||
6078d2c9 | 192 | static int dev_open(struct sr_dev_inst *sdi) |
35a078bc | 193 | { |
df36acb3 | 194 | |
35a078bc | 195 | /* TODO */ |
e73ffd42 | 196 | sdi->status = SR_ST_ACTIVE; |
35a078bc BV |
197 | |
198 | return SR_OK; | |
199 | } | |
200 | ||
6078d2c9 | 201 | static int dev_close(struct sr_dev_inst *sdi) |
35a078bc | 202 | { |
df36acb3 | 203 | |
35a078bc | 204 | /* TODO */ |
e73ffd42 | 205 | sdi->status = SR_ST_INACTIVE; |
35a078bc BV |
206 | |
207 | return SR_OK; | |
208 | } | |
209 | ||
6078d2c9 | 210 | static int cleanup(void) |
35a078bc | 211 | { |
3b412e3a | 212 | return dev_clear(); |
35a078bc BV |
213 | } |
214 | ||
c8733a2b | 215 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) |
35a078bc BV |
216 | { |
217 | int ret; | |
218 | ||
df36acb3 | 219 | /* TODO */ |
c8733a2b | 220 | (void)data; |
df36acb3 | 221 | |
e73ffd42 BV |
222 | if (sdi->status != SR_ST_ACTIVE) |
223 | return SR_ERR_DEV_CLOSED; | |
35a078bc BV |
224 | |
225 | ret = SR_OK; | |
035a1078 | 226 | switch (id) { |
df36acb3 | 227 | |
35a078bc | 228 | default: |
bd6fbf62 | 229 | ret = SR_ERR_NA; |
35a078bc BV |
230 | } |
231 | ||
232 | return ret; | |
233 | } | |
234 | ||
c8733a2b | 235 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) |
a1c743fc | 236 | { |
a1c743fc | 237 | (void)sdi; |
ff08a52a | 238 | (void)data; |
a1c743fc BV |
239 | |
240 | switch (key) { | |
241 | default: | |
bd6fbf62 | 242 | return SR_ERR_NA; |
a1c743fc BV |
243 | } |
244 | ||
245 | return SR_OK; | |
246 | } | |
247 | ||
6078d2c9 | 248 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) |
35a078bc BV |
249 | { |
250 | /* TODO */ | |
df36acb3 | 251 | (void)cb_data; |
35a078bc | 252 | |
e73ffd42 BV |
253 | if (sdi->status != SR_ST_ACTIVE) |
254 | return SR_ERR_DEV_CLOSED; | |
255 | ||
35a078bc BV |
256 | return SR_OK; |
257 | } | |
258 | ||
6078d2c9 | 259 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
35a078bc BV |
260 | { |
261 | (void)cb_data; | |
262 | ||
263 | if (sdi->status != SR_ST_ACTIVE) { | |
264 | sr_err("Device inactive, can't stop acquisition."); | |
265 | return SR_ERR; | |
266 | } | |
267 | ||
268 | /* TODO */ | |
269 | ||
270 | return SR_OK; | |
271 | } | |
272 | ||
273 | SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info = { | |
274 | .name = "nexus-osciprime", | |
523dfc24 | 275 | .longname = "Nexus OsciPrime", |
35a078bc | 276 | .api_version = 1, |
6078d2c9 UH |
277 | .init = init, |
278 | .cleanup = cleanup, | |
279 | .scan = scan, | |
280 | .dev_list = dev_list, | |
3b412e3a | 281 | .dev_clear = dev_clear, |
6fab7b8f | 282 | .config_get = NULL, |
035a1078 | 283 | .config_set = config_set, |
a1c743fc | 284 | .config_list = config_list, |
6078d2c9 UH |
285 | .dev_open = dev_open, |
286 | .dev_close = dev_close, | |
287 | .dev_acquisition_start = dev_acquisition_start, | |
288 | .dev_acquisition_stop = dev_acquisition_stop, | |
35a078bc BV |
289 | .priv = NULL, |
290 | }; |