]> sigrok.org Git - libsigrok.git/blob - hardware/genericdmm/genericdmm.h
genericdmm: use driver-private storage for instances
[libsigrok.git] / hardware / genericdmm / genericdmm.h
1 /*
2  * This file is part of the sigrok 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
20
21 #ifndef LIBSIGROK_GENERICDMM_H
22 #define LIBSIGROK_GENERICDMM_H
23
24 /* SR_HWCAP_CONN takes one of these: */
25 #define DMM_CONN_USB_VIDPID    "^([0-9a-z]{1,4})\\.([0-9a-z]{1,4})$"
26 #define DMM_CONN_USB_BUSADDR   "^(\\d+)\\.(\\d+)$"
27 #define DMM_CONN_SERIALPORT    "^([a-z0-9/\\-_]+)$"
28
29 /* SR_HWCAP_SERIALCOMM like 2400/8n1 */
30 #define DMM_CONN_SERIALCOMM    "^(\\d+)/(\\d)([neo])(\\d)$"
31
32 enum {
33         DMM_TRANSPORT_SERIAL,
34         DMM_TRANSPORT_USBHID,
35 };
36
37
38 struct dev_profile {
39         char *modelid;
40         char *vendor;
41         char *model;
42         struct dmmchip *chip;
43         int transport;
44         struct sr_hwopt *defaults_opts;
45 };
46
47 /* Private driver context. */
48 struct drv_context {
49         GSList *instances;
50 };
51
52 /* Private, per-device-instance driver context. */
53 struct dev_context {
54         struct dev_profile *profile;
55         uint64_t limit_samples;
56         uint64_t limit_msec;
57
58         /* Opaque pointer passed in by the frontend. */
59         void *cb_data;
60
61         /* Only used for USB-connected devices. */
62         struct sr_usb_dev_inst *usb;
63
64         /* Only used for serial-connected devices. */
65         struct sr_serial_dev_inst *serial;
66         int serial_speed;
67         int serial_databits;
68         int serial_parity;
69         int serial_stopbits;
70
71         /* Runtime. */
72         uint64_t num_samples;
73
74         /* DMM chip-specific data, if needed. */
75         void *priv;
76 };
77
78 struct dmmchip {
79         /* Optional, called once before measurement starts. */
80         int (*init) (void);
81
82         /* Scan for devices with the given options. */
83         GSList *(*scan) (GSList *options);
84
85         /* Called whenever a chunk of data arrives. */
86         int (*data) (struct sr_dev_inst *sdi, unsigned char *data);
87 };
88
89
90 #endif /* LIBSIGROK_GENERICDMM_H */