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