2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 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 "libsigrok.h"
23 #include "libsigrok-internal.h"
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"
32 static const int hwopts[] = {
38 static const int hwcaps[] = {
39 SR_HWCAP_OSCILLOSCOPE,
40 SR_HWCAP_LIMIT_SAMPLES,
47 static const struct sr_rational timebases[] = {
94 static const char *probe_names[] = {
100 static const struct sr_rational vdivs[] = {
109 SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info;
110 static struct sr_dev_driver *di = &nexus_osciprime_driver_info;
111 static int hw_dev_close(struct sr_dev_inst *sdi);
113 /* Properly close and free all devices. */
114 static int clear_instances(void)
116 struct sr_dev_inst *sdi;
117 struct drv_context *drvc;
118 struct dev_context *devc;
121 if (!(drvc = di->priv))
124 for (l = drvc->instances; l; l = l->next) {
125 if (!(sdi = l->data))
127 if (!(devc = sdi->priv))
131 sr_usb_dev_inst_free(devc->usb);
132 sr_dev_inst_free(sdi);
135 g_slist_free(drvc->instances);
136 drvc->instances = NULL;
141 static int hw_init(struct sr_context *sr_ctx)
143 struct drv_context *drvc;
145 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
146 sr_err("Driver context malloc failed.");
147 return SR_ERR_MALLOC;
150 drvc->sr_ctx = sr_ctx;
156 static GSList *hw_scan(GSList *options)
158 struct drv_context *drvc;
159 struct dev_context *devc;
160 struct sr_dev_inst *sdi;
161 struct sr_usb_dev_inst *usb;
162 struct sr_hwopt *opt;
163 struct sr_probe *probe;
165 GSList *usb_devices, *devices, *l;
171 if (!(drvc = di->priv)) {
172 sr_err("Driver was not initialized.");
176 /* USB scan is always authoritative. */
180 for (l = options; l; l = l->next) {
182 switch (opt->hwopt) {
192 if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) {
193 for (l = usb_devices; l; l = l->next) {
195 if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
196 OSCI_VENDOR, OSCI_MODEL, OSCI_VERSION)))
199 for (i = 0; probe_names[i]; i++) {
200 if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
203 sdi->probes = g_slist_append(sdi->probes, probe);
206 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
211 if (strcmp(conn, OSCI_VIDPID)) {
212 if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK)
214 dev = libusb_get_device(usb->devhdl);
215 if (ezusb_upload_firmware(dev, 0, OSCI_FIRMWARE) == SR_OK)
216 /* Remember when the firmware on this device was updated */
217 devc->fw_updated = g_get_monotonic_time();
219 sr_err("Firmware upload failed for device "
220 "at bus %d address %d.", usb->bus, usb->address);
223 drvc->instances = g_slist_append(drvc->instances, sdi);
224 devices = g_slist_append(devices, sdi);
226 g_slist_free(usb_devices);
228 g_slist_free_full(usb_devices, g_free);
233 static GSList *hw_dev_list(void)
235 struct drv_context *drvc;
239 return drvc->instances;
242 static int hw_dev_open(struct sr_dev_inst *sdi)
251 static int hw_dev_close(struct sr_dev_inst *sdi)
260 static int hw_cleanup(void)
269 static int hw_info_get(int info_id, const void **data,
270 const struct sr_dev_inst *sdi)
279 sr_err("Unknown info_id: %d.", info_id);
286 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
294 if (sdi->status != SR_ST_ACTIVE) {
295 sr_err("Device inactive, can't set config options.");
303 sr_err("Unknown hardware capability: %d.", hwcap);
310 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
320 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
324 if (sdi->status != SR_ST_ACTIVE) {
325 sr_err("Device inactive, can't stop acquisition.");
334 SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info = {
335 .name = "nexus-osciprime",
336 .longname = "Nexus OsciPrime",
339 .cleanup = hw_cleanup,
341 .dev_list = hw_dev_list,
342 .dev_clear = clear_instances,
343 .dev_open = hw_dev_open,
344 .dev_close = hw_dev_close,
345 .info_get = hw_info_get,
346 .dev_config_set = hw_dev_config_set,
347 .dev_acquisition_start = hw_dev_acquisition_start,
348 .dev_acquisition_stop = hw_dev_acquisition_stop,