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