]> sigrok.org Git - libsigrok.git/blame - src/hardware/hp-59306a/api.c
hp-59306a: Enable/disable all outputs at once.
[libsigrok.git] / src / hardware / hp-59306a / api.c
CommitLineData
12e7abe2
FS
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2021 Frank Stettner <frank-stettner@gmx.net>
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#include <config.h>
584269fd 21#include "scpi.h"
12e7abe2
FS
22#include "protocol.h"
23
584269fd
FS
24static const uint32_t scanopts[] = {
25 SR_CONF_CONN,
26};
12e7abe2 27
584269fd
FS
28static const uint32_t drvopts[] = {
29 SR_CONF_MULTIPLEXER,
30};
12e7abe2 31
584269fd 32static const uint32_t devopts[] = {
97c3c869 33 SR_CONF_ENABLED | SR_CONF_SET,
584269fd 34};
12e7abe2 35
584269fd
FS
36static const uint32_t devopts_cg[] = {
37 SR_CONF_ENABLED | SR_CONF_SET,
38};
12e7abe2 39
584269fd 40static struct sr_dev_driver hp_59306a_driver_info;
12e7abe2 41
584269fd 42static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
12e7abe2 43{
584269fd
FS
44 struct sr_dev_inst *sdi;
45 struct dev_context *devc;
46 struct channel_group_context *cgc;
47 size_t idx, nr;
48 struct sr_channel_group *cg;
49
d008c027
GS
50 /*
51 * The device cannot get identified by means of SCPI queries.
52 * Neither shall non-SCPI requests get emitted before reliable
53 * identification of the device. Assume that we only get here
54 * when user specs led us to believe it's safe to communicate
55 * to the expected kind of device.
56 */
57
584269fd
FS
58 sdi = g_malloc0(sizeof(*sdi));
59 sdi->vendor = g_strdup("Hewlett-Packard");
60 sdi->model = g_strdup("59306A");
61 sdi->conn = scpi;
62 sdi->driver = &hp_59306a_driver_info;
63 sdi->inst_type = SR_INST_SCPI;
64
65 devc = g_malloc0(sizeof(*devc));
66 sdi->priv = devc;
67
68 devc->channel_count = 6;
69 for (idx = 0; idx < devc->channel_count; idx++) {
70 nr = idx + 1;
71
72 cg = g_malloc0(sizeof(*cg));
73 cg->name = g_strdup_printf("CH%zu", nr);
74
75 cgc = g_malloc0(sizeof(*cgc));
76 cgc->number = nr;
77 cg->priv = cgc;
78
79 sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
80 }
12e7abe2 81
584269fd 82 return sdi;
12e7abe2
FS
83}
84
584269fd 85static GSList *scan(struct sr_dev_driver *di, GSList *options)
12e7abe2 86{
d008c027
GS
87 const char *conn;
88
89 /* Only scan for a device when conn= was specified. */
90 conn = NULL;
91 (void)sr_serial_extract_options(options, &conn, NULL);
92 if (!conn)
93 return NULL;
94
584269fd 95 return sr_scpi_scan(di->context, options, probe_device);
12e7abe2
FS
96}
97
584269fd 98static int dev_open(struct sr_dev_inst *sdi)
12e7abe2 99{
584269fd
FS
100 return sr_scpi_open(sdi->conn);
101}
12e7abe2 102
584269fd
FS
103static int dev_close(struct sr_dev_inst *sdi)
104{
105 return sr_scpi_close(sdi->conn);
12e7abe2
FS
106}
107
108static int config_set(uint32_t key, GVariant *data,
109 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
110{
584269fd
FS
111 gboolean on;
112
113 if (!cg) {
114 switch (key) {
584269fd 115 case SR_CONF_ENABLED:
97c3c869
FS
116 /* Enable/disable all channels at the same time. */
117 on = g_variant_get_boolean(data);
118 return hp_59306a_switch_cg(sdi, cg, on);
584269fd
FS
119 default:
120 return SR_ERR_NA;
121 }
122 } else {
123 switch (key) {
124 case SR_CONF_ENABLED:
125 on = g_variant_get_boolean(data);
126 return hp_59306a_switch_cg(sdi, cg, on);
127 default:
128 return SR_ERR_NA;
129 }
12e7abe2
FS
130 }
131
584269fd 132 return SR_OK;
12e7abe2
FS
133}
134
135static int config_list(uint32_t key, GVariant **data,
136 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
137{
584269fd
FS
138 if (!cg) {
139 switch (key) {
140 case SR_CONF_SCAN_OPTIONS:
141 case SR_CONF_DEVICE_OPTIONS:
142 return STD_CONFIG_LIST(key, data, sdi, cg,
143 scanopts, drvopts, devopts);
144 default:
145 return SR_ERR_NA;
146 }
147 } else {
148 switch (key) {
149 case SR_CONF_DEVICE_OPTIONS:
150 *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg));
151 break;
152 default:
153 return SR_ERR_NA;
154 }
12e7abe2
FS
155 }
156
12e7abe2
FS
157 return SR_OK;
158}
159
160static struct sr_dev_driver hp_59306a_driver_info = {
161 .name = "hp-59306a",
162 .longname = "hp-59306a",
163 .api_version = 1,
164 .init = std_init,
165 .cleanup = std_cleanup,
166 .scan = scan,
167 .dev_list = std_dev_list,
168 .dev_clear = std_dev_clear,
584269fd 169 .config_get = NULL,
12e7abe2
FS
170 .config_set = config_set,
171 .config_list = config_list,
172 .dev_open = dev_open,
173 .dev_close = dev_close,
584269fd
FS
174 .dev_acquisition_start = std_dummy_dev_acquisition_start,
175 .dev_acquisition_stop = std_dummy_dev_acquisition_stop,
12e7abe2
FS
176 .context = NULL,
177};
178SR_REGISTER_DEV_DRIVER(hp_59306a_driver_info);