]> sigrok.org Git - libsigrok.git/blob - src/hardware/hameg-hmo/protocol.h
b251bc823b3aadfe147af3070c7a2637d5bfb3ec
[libsigrok.git] / src / 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/libsigrok.h>
27 #include "libsigrok-internal.h"
28
29 #define LOG_PREFIX "hameg-hmo"
30
31 #define MAX_INSTRUMENT_VERSIONS 10
32 #define MAX_COMMAND_SIZE 48
33 #define MAX_DIGITAL_GROUP_COUNT 2
34
35 struct scope_config {
36         const char *name[MAX_INSTRUMENT_VERSIONS];
37         const uint8_t analog_channels;
38         const uint8_t digital_channels;
39         const uint8_t digital_pods;
40
41         const char *(*analog_names)[];
42         const char *(*digital_names)[];
43
44         const uint32_t (*devopts)[];
45         const uint8_t num_devopts;
46
47         const uint32_t (*analog_devopts)[];
48         const uint8_t num_analog_devopts;
49
50         const char *(*coupling_options)[];
51         const uint8_t num_coupling_options;
52
53         const char *(*trigger_sources)[];
54         const uint8_t num_trigger_sources;
55
56         const char *(*trigger_slopes)[];
57
58         const uint64_t (*timebases)[][2];
59         const uint8_t num_timebases;
60
61         const uint64_t (*vdivs)[][2];
62         const uint8_t num_vdivs;
63
64         const uint8_t num_xdivs;
65         const uint8_t num_ydivs;
66
67         const char *(*scpi_dialect)[];
68 };
69
70 struct analog_channel_state {
71         int coupling;
72
73         int vdiv;
74         float vertical_offset;
75
76         gboolean state;
77         char probe_unit;
78 };
79
80 struct scope_state {
81         struct analog_channel_state *analog_channels;
82         gboolean *digital_channels;
83         gboolean *digital_pods;
84
85         int timebase;
86         float horiz_triggerpos;
87
88         int trigger_source;
89         int trigger_slope;
90         uint64_t sample_rate;
91 };
92
93 /** Private, per-device-instance driver context. */
94 struct dev_context {
95         const void *model_config;
96         void *model_state;
97
98         struct sr_channel_group **analog_groups;
99         struct sr_channel_group **digital_groups;
100
101         GSList *enabled_channels;
102         GSList *current_channel;
103         uint64_t num_frames;
104
105         uint64_t frame_limit;
106
107         size_t pod_count;
108         GByteArray *logic_data;
109 };
110
111 SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi);
112 SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi);
113 SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data);
114
115 SR_PRIV struct scope_state *hmo_scope_state_new(struct scope_config *config);
116 SR_PRIV void hmo_scope_state_free(struct scope_state *state);
117 SR_PRIV int hmo_scope_state_get(struct sr_dev_inst *sdi);
118 SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi);
119
120 #endif