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 int32_t hwopts[] = {
37 static const int32_t hwcaps[] = {
39 SR_CONF_LIMIT_SAMPLES,
45 static const uint64_t timebases[][2] = {
92 static const char *probe_names[] = {
97 static const uint64_t vdivs[][2] = {
105 SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info;
106 static struct sr_dev_driver *di = &nexus_osciprime_driver_info;
108 static int clear_instances(void)
110 return std_dev_clear(di, NULL);
113 static int init(struct sr_context *sr_ctx)
115 return std_hw_init(sr_ctx, di, LOG_PREFIX);
118 static GSList *scan(GSList *options)
120 struct drv_context *drvc;
121 struct dev_context *devc;
122 struct sr_dev_inst *sdi;
123 struct sr_usb_dev_inst *usb;
124 struct sr_config *src;
125 struct sr_probe *probe;
127 GSList *usb_devices, *devices, *l;
134 for (l = options; l; l = l->next) {
138 conn = g_variant_get_string(src->data, NULL);
146 if ((usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) {
147 for (l = usb_devices; l; l = l->next) {
149 if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
150 OSCI_VENDOR, OSCI_MODEL, OSCI_VERSION)))
153 for (i = 0; probe_names[i]; i++) {
154 if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
157 sdi->probes = g_slist_append(sdi->probes, probe);
160 if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
165 if (strcmp(conn, OSCI_VIDPID)) {
166 if (sr_usb_open(drvc->sr_ctx->libusb_ctx, usb) != SR_OK)
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();
173 sr_err("Firmware upload failed for device "
174 "at bus %d address %d.", usb->bus, usb->address);
177 drvc->instances = g_slist_append(drvc->instances, sdi);
178 devices = g_slist_append(devices, sdi);
180 g_slist_free(usb_devices);
182 g_slist_free_full(usb_devices, g_free);
187 static GSList *dev_list(void)
189 return ((struct drv_context *)(di->priv))->instances;
192 static int dev_open(struct sr_dev_inst *sdi)
196 sdi->status = SR_ST_ACTIVE;
201 static int dev_close(struct sr_dev_inst *sdi)
205 sdi->status = SR_ST_INACTIVE;
210 static int cleanup(void)
212 return clear_instances();
215 static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
222 if (sdi->status != SR_ST_ACTIVE)
223 return SR_ERR_DEV_CLOSED;
235 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
248 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
253 if (sdi->status != SR_ST_ACTIVE)
254 return SR_ERR_DEV_CLOSED;
259 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
263 if (sdi->status != SR_ST_ACTIVE) {
264 sr_err("Device inactive, can't stop acquisition.");
273 SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info = {
274 .name = "nexus-osciprime",
275 .longname = "Nexus OsciPrime",
280 .dev_list = dev_list,
281 .dev_clear = clear_instances,
283 .config_set = config_set,
284 .config_list = config_list,
285 .dev_open = dev_open,
286 .dev_close = dev_close,
287 .dev_acquisition_start = dev_acquisition_start,
288 .dev_acquisition_stop = dev_acquisition_stop,