]> sigrok.org Git - libsigrok.git/blob - hardware/hameg-hmo/protocol.h
hameg-hmo: Add initial working driver version.
[libsigrok.git] / hardware / hameg-hmo / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 poljar (Damir Jelić) <poljarinho@gmail.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 #ifndef LIBSIGROK_HARDWARE_HAMEG_HMO_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_HAMEG_HMO_PROTOCOL_H
22
23 #include <glib.h>
24 #include <stdint.h>
25 #include <string.h>
26 #include "libsigrok.h"
27 #include "libsigrok-internal.h"
28
29 /* Message logging helpers with subsystem-specific prefix string. */
30 #define LOG_PREFIX "hameg-hmo: "
31 #define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
32 #define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
33 #define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
34 #define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
35 #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
36 #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
37
38 #define MAX_INSTRUMENT_VERSIONS 10
39 #define MAX_COMMAND_SIZE 31
40
41 SR_PRIV struct sr_dev_driver hameg_hmo_driver_info;
42 static struct sr_dev_driver *di = &hameg_hmo_driver_info;
43
44 enum {
45         PG_INVALID = -1,
46         PG_NONE,
47         PG_ANALOG,
48         PG_DIGITAL,
49 };
50
51 struct scope_config {
52         const char *name[MAX_INSTRUMENT_VERSIONS];
53         const uint8_t analog_channels;
54         const uint8_t digital_channels;
55         const uint8_t digital_pods;
56
57         const char *(*analog_names)[];
58         const char *(*digital_names)[];
59
60         const int32_t (*hw_caps)[];
61         const uint8_t num_hwcaps;
62
63         const int32_t (*analog_hwcaps)[];
64         const uint8_t num_analog_hwcaps;
65
66         const char *(*coupling_options)[];
67         const uint8_t num_coupling_options;
68
69         const char *(*trigger_sources)[];
70         const uint8_t num_trigger_sources;
71
72         const char *(*trigger_slopes)[];
73
74         const uint64_t (*timebases)[][2];
75         const uint8_t num_timebases;
76
77         const uint64_t (*vdivs)[][2];
78         const uint8_t num_vdivs;
79
80         const uint8_t num_xdivs;
81         const uint8_t num_ydivs;
82
83         const char *(*scpi_dialect)[];
84 };
85
86 struct analog_channel_state {
87         int coupling;
88
89         float vdiv;
90         float vertical_offset;
91
92         gboolean state;
93 };
94
95 struct scope_state {
96         struct analog_channel_state *analog_channels;
97         gboolean *digital_channels;
98         gboolean *digital_pods;
99
100         float timebase;
101         float horiz_triggerpos;
102
103         int trigger_source;
104         int trigger_slope;
105 };
106
107 /** Private, per-device-instance driver context. */
108 struct dev_context {
109         void *model_config;
110         void *model_state;
111
112         struct sr_probe_group *analog_groups;
113         struct sr_probe_group *digital_groups;
114
115         GSList *enabled_probes;
116         GSList *current_probe;
117         uint64_t num_frames;
118
119         uint64_t frame_limit;
120 };
121
122 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi);
123 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi);
124 SR_PRIV int hameg_hmo_receive_data(int fd, int revents, void *cb_data);
125 SR_PRIV struct sr_dev_inst *hameg_probe_serial_device(const char *serial_device,
126                                                       const char *serial_options);
127
128 SR_PRIV struct scope_state *scope_state_new(struct scope_config *config);
129 SR_PRIV void scope_state_free(struct scope_state *state);
130 SR_PRIV int scope_state_get(struct sr_dev_inst *sdi);
131
132 #endif