]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/profiles.c
scpi-pps: Fix driver options.
[libsigrok.git] / src / hardware / scpi-pps / profiles.c
CommitLineData
d4eabea8
BV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 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
22c18b03 20#include <string.h>
d4eabea8
BV
21#include "protocol.h"
22
23#define CH_IDX(x) (1 << x)
24
22c18b03
BV
25const char *pps_vendors[][2] = {
26 { "RIGOL TECHNOLOGIES", "Rigol" },
bc4a2a46 27 { "HEWLETT-PACKARD", "HP" },
c3eadb07 28 { "PHILIPS", "Philips" },
d4eabea8
BV
29};
30
22c18b03
BV
31const char *get_vendor(const char *raw_vendor)
32{
33 unsigned int i;
34
35 for (i = 0; i < ARRAY_SIZE(pps_vendors); i++) {
36 if (!strcasecmp(raw_vendor, pps_vendors[i][0]))
37 return pps_vendors[i][1];
38 }
39
40 return raw_vendor;
41}
42
584560f1 43static const uint32_t devopts_none[] = { };
bfc86799 44
d4eabea8 45/* Rigol DP800 series */
584560f1 46static const uint32_t rigol_dp800_devopts[] = {
9d9cf1c4 47 SR_CONF_CONTINUOUS | SR_CONF_SET,
5827f61b 48 SR_CONF_OVER_TEMPERATURE_PROTECTION | SR_CONF_GET | SR_CONF_SET,
d4eabea8
BV
49};
50
584560f1 51static const uint32_t rigol_dp800_devopts_cg[] = {
5827f61b
BV
52 SR_CONF_OUTPUT_REGULATION | SR_CONF_GET,
53 SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
54 SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
55 SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
56 SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
57 SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
58 SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
59 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
ca95e90f 60 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
5827f61b 61 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
ca95e90f 62 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
5827f61b 63 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
d4eabea8
BV
64};
65
3222ee10
BV
66struct channel_spec rigol_dp831_ch[] = {
67 { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 } },
68 { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 } },
69 { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 } },
d4eabea8
BV
70};
71
3222ee10
BV
72struct channel_spec rigol_dp832_ch[] = {
73 { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 } },
74 { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 } },
75 { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 } },
76};
77
78struct channel_group_spec rigol_dp800_cg[] = {
d4eabea8
BV
79 { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
80 { "2", CH_IDX(1), PPS_OVP | PPS_OCP },
81 { "3", CH_IDX(2), PPS_OVP | PPS_OCP },
82};
83
3222ee10 84struct scpi_command rigol_dp800_cmd[] = {
60475cd7
BV
85 { SCPI_CMD_REMOTE, "SYST:REMOTE" },
86 { SCPI_CMD_LOCAL, "SYST:LOCAL" },
ee2860ee
BV
87 { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" },
88 { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" },
89 { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" },
60475cd7
BV
90 { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
91 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
92 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
93 { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" },
94 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
95 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
96 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
97 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
98 { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
99 { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
100 { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
101 { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" },
d4eabea8 102 { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, ":SYST:OTP?" },
53a81803
BV
103 { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, ":SYST:OTP ON" },
104 { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, ":SYST:OTP OFF" },
60475cd7
BV
105 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" },
106 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" },
107 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" },
108 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" },
109 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" },
110 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" },
111 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" },
112 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" },
113 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" },
114 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" },
115 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" },
116 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" },
d4eabea8
BV
117};
118
bfc86799 119/* HP 663xx series */
584560f1 120static const uint32_t hp_6632b_devopts[] = {
9d9cf1c4 121 SR_CONF_CONTINUOUS | SR_CONF_SET,
5827f61b
BV
122 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
123 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
124 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
ca95e90f
BV
125 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
126 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
bc4a2a46
BV
127};
128
129struct channel_spec hp_6632b_ch[] = {
130 { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 } },
131};
132
133struct channel_group_spec hp_6632b_cg[] = {
134 { "1", CH_IDX(0), 0 },
135};
136
137struct scpi_command hp_6632b_cmd[] = {
138 { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP:STAT?" },
53a81803
BV
139 { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP:STAT ON" },
140 { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP:STAT OFF" },
bc4a2a46
BV
141 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
142 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
ca95e90f
BV
143 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
144 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
145 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
146 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
bc4a2a46
BV
147};
148
c3eadb07 149/* Philips/Fluke PM2800 series */
9d9cf1c4
BV
150static const uint32_t philips_pm2800_devopts[] = {
151 SR_CONF_CONTINUOUS | SR_CONF_SET,
152};
153
c3eadb07
BV
154static const uint32_t philips_pm2800_devopts_cg[] = {
155 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
156 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
157 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
158 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
159 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
160 SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
161 SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
162 SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
163 SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
164 SR_CONF_OUTPUT_REGULATION | SR_CONF_GET,
165};
166
167enum philips_pm2800_modules {
168 PM2800_MOD_30V_10A = 1,
169 PM2800_MOD_60V_5A,
170 PM2800_MOD_60V_10A,
171 PM2800_MOD_8V_15A,
172 PM2800_MOD_60V_2A,
173 PM2800_MOD_120V_1A,
174};
175
176static struct philips_pm2800_module_spec {
177 /* Min, max, programming resolution. */
178 float voltage[3];
179 float current[3];
180} philips_pm2800_module_specs[] = {
181 /* Autoranging modules. */
182 [PM2800_MOD_30V_10A] = { { 0, 30, 0.0075 }, { 0, 10, 0.0025 } },
183 [PM2800_MOD_60V_5A] = { { 0, 60, 0.015 }, { 0, 5, 0.00125 } },
184 [PM2800_MOD_60V_10A] = { { 0, 60, 0.015 }, { 0, 10, 0.0025 } },
185 /* Linear modules. */
186 [PM2800_MOD_8V_15A] = { { 0, 8, 0.002 }, { -15, 15, 0.00375 } },
187 [PM2800_MOD_60V_2A] = { { 0, 60, 0.015 }, { -2, 2, 0.0005 } },
188 [PM2800_MOD_120V_1A] = { { 0, 120, 0.030 }, { -1, 1, 0.00025 } },
189};
190
191static struct philips_pm2800_model {
192 unsigned int chassis;
193 unsigned int num_modules;
194 unsigned int set;
195 unsigned int modules[3];
196} philips_pm2800_matrix[] = {
197 /* Autoranging chassis. */
198 { 1, 1, 0, { PM2800_MOD_30V_10A, 0, 0 } },
199 { 1, 1, 1, { PM2800_MOD_60V_5A, 0, 0 } },
200 { 1, 2, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, 0 } },
201 { 1, 2, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, 0 } },
202 { 1, 2, 2, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, 0 } },
203 { 1, 2, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_10A, 0 } },
204 { 1, 2, 4, { PM2800_MOD_60V_5A, PM2800_MOD_60V_10A, 0 } },
205 { 1, 3, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_30V_10A } },
206 { 1, 3, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
207 { 1, 3, 2, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_60V_5A } },
208 { 1, 3, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
209 /* Linear chassis. */
210 { 3, 1, 0, { PM2800_MOD_60V_2A, 0, 0 } },
211 { 3, 1, 1, { PM2800_MOD_120V_1A, 0, 0 } },
212 { 3, 1, 2, { PM2800_MOD_8V_15A, 0, 0 } },
213 { 3, 2, 0, { PM2800_MOD_60V_2A, 0, 0 } },
214 { 3, 2, 1, { PM2800_MOD_120V_1A, 0, 0 } },
215 { 3, 2, 2, { PM2800_MOD_60V_2A, PM2800_MOD_120V_1A, 0 } },
216 { 3, 2, 3, { PM2800_MOD_8V_15A, PM2800_MOD_8V_15A, 0 } },
217};
218
219static char *philips_pm2800_names[] = { "1", "2", "3" };
220
221static int philips_pm2800_probe_channels(struct sr_dev_inst *sdi,
222 struct sr_scpi_hw_info *hw_info,
223 struct channel_spec **channels, unsigned int *num_channels,
224 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups)
225{
226 struct philips_pm2800_model *model;
227 struct philips_pm2800_module_spec *spec;
228 unsigned int chassis, num_modules, set, module, m, i;
229
230 (void)sdi;
231
232 /*
233 * The model number as reported by *IDN? looks like e.g. PM2813/11,
234 * Where "PM28" is fixed, followed by the chassis code (1 = autoranging,
235 * 3 = linear series) and the number of modules: 1-3 for autoranging,
236 * 1-2 for linear.
237 * After the slash, the first digit denotes the module set. The
238 * digit after that denotes front (5) or rear (1) binding posts.
239 */
240 chassis = hw_info->model[4] - 0x30;
241 num_modules = hw_info->model[5] - 0x30;
242 set = hw_info->model[7] - 0x30;
243 for (m = 0; m < ARRAY_SIZE(philips_pm2800_matrix); m++) {
244 model = &philips_pm2800_matrix[m];
245 if (model->chassis == chassis && model->num_modules == num_modules
246 && model->set == set)
247 break;
248 }
249 if (m == ARRAY_SIZE(philips_pm2800_matrix)) {
250 sr_dbg("Model %s not found in matrix.", hw_info->model);
251 return SR_ERR;
252 }
253
254 sr_dbg("Found %d output channel%s:", num_modules, num_modules > 1 ? "s" : "");
255 *channels = g_malloc0(sizeof(struct channel_spec) * num_modules);
256 *channel_groups = g_malloc0(sizeof(struct channel_group_spec) * num_modules);
257 for (i = 0; i < num_modules; i++) {
258 module = model->modules[i];
259 spec = &philips_pm2800_module_specs[module];
260 sr_dbg("output %d: %.0f - %.0fV, %.0f - %.0fA", i + 1,
261 spec->voltage[0], spec->voltage[1],
262 spec->current[0], spec->current[1]);
263 (*channels)[i].name = philips_pm2800_names[i];
264 memcpy(&((*channels)[i].voltage), spec, sizeof(float) * 6);
265 (*channel_groups)[i].name = philips_pm2800_names[i];
266 (*channel_groups)[i].channel_index_mask = 1 << i;
267 (*channel_groups)[i].features = PPS_OTP | PPS_OVP | PPS_OCP;
268 }
269 *num_channels = *num_channel_groups = num_modules;
270
271 return SR_OK;
272}
273
274struct scpi_command philips_pm2800_cmd[] = {
275 { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
276 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
277 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
278 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
279 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
280 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
281 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
282 { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
283 { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
284 { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
285 { SCPI_CMD_GET_OUTPUT_REGULATION, ":SOUR:FUNC:MODE?" },
286 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":SOUR:VOLT:PROT:TRIP?" },
287 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV?" },
288 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV %.6f" },
289 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":SOUR:CURR:PROT:STAT?" },
290 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":SOUR:CURR:PROT:STAT ON" },
291 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":SOUR:CURR:PROT:STAT OFF" },
292 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":SOUR:CURR:PROT:TRIP?" },
293};
294
bc4a2a46 295
d4eabea8 296SR_PRIV const struct scpi_pps pps_profiles[] = {
bc4a2a46
BV
297 /* HP 6632B */
298 { "HP", "6632B", 0,
299 ARRAY_AND_SIZE(hp_6632b_devopts),
bfc86799 300 ARRAY_AND_SIZE(devopts_none),
bc4a2a46
BV
301 ARRAY_AND_SIZE(hp_6632b_ch),
302 ARRAY_AND_SIZE(hp_6632b_cg),
303 ARRAY_AND_SIZE(hp_6632b_cmd),
c3eadb07 304 .probe_channels = NULL,
bc4a2a46
BV
305 },
306
d4eabea8 307 /* Rigol DP800 series */
3222ee10
BV
308 { "Rigol", "^DP831A$", PPS_OTP,
309 ARRAY_AND_SIZE(rigol_dp800_devopts),
310 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
311 ARRAY_AND_SIZE(rigol_dp831_ch),
312 ARRAY_AND_SIZE(rigol_dp800_cg),
313 ARRAY_AND_SIZE(rigol_dp800_cmd),
c3eadb07 314 .probe_channels = NULL,
3222ee10
BV
315 },
316 { "Rigol", "^(DP832|DP832A)$", PPS_OTP,
317 ARRAY_AND_SIZE(rigol_dp800_devopts),
318 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
319 ARRAY_AND_SIZE(rigol_dp832_ch),
320 ARRAY_AND_SIZE(rigol_dp800_cg),
321 ARRAY_AND_SIZE(rigol_dp800_cmd),
c3eadb07
BV
322 .probe_channels = NULL,
323 },
324
325 /* Philips/Fluke PM2800 series */
326 { "Philips", "^PM28[13][123]/[01234]{1,2}$", 0,
9d9cf1c4 327 ARRAY_AND_SIZE(philips_pm2800_devopts),
c3eadb07
BV
328 ARRAY_AND_SIZE(philips_pm2800_devopts_cg),
329 NULL, 0,
330 NULL, 0,
331 ARRAY_AND_SIZE(philips_pm2800_cmd),
332 philips_pm2800_probe_channels,
d4eabea8
BV
333 },
334};
335SR_PRIV unsigned int num_pps_profiles = ARRAY_SIZE(pps_profiles);
336