]> sigrok.org Git - libsigrok.git/blame - src/hardware/rdtech-dps/protocol.h
hp-59306a: Initial HP 59306A driver.
[libsigrok.git] / src / hardware / rdtech-dps / protocol.h
CommitLineData
0549416e
JC
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2018 James Churchill <pelrun@gmail.com>
7c0891b0 5 * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
0549416e
JC
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H
22#define LIBSIGROK_HARDWARE_RDTECH_DPS_PROTOCOL_H
23
24#include <stdint.h>
25#include <glib.h>
26#include <libsigrok/libsigrok.h>
27#include "libsigrok-internal.h"
28
29#define LOG_PREFIX "rdtech-dps"
30
69b05583
JC
31struct rdtech_dps_model {
32 unsigned int id;
33 const char *name;
34 unsigned int max_current;
35 unsigned int max_voltage;
36 unsigned int max_power;
cce6a8a1
FS
37 unsigned int current_digits;
38 unsigned int voltage_digits;
69b05583
JC
39};
40
0549416e 41struct dev_context {
69b05583
JC
42 const struct rdtech_dps_model *model;
43 struct sr_sw_limits limits;
7c0891b0 44 GMutex rw_mutex;
cce6a8a1
FS
45 double current_multiplier;
46 double voltage_multiplier;
dfdf4c83
FS
47 gboolean actual_ovp_state;
48 gboolean actual_ocp_state;
49 uint16_t actual_regulation_state;
50 uint16_t actual_output_state;
69b05583
JC
51};
52
53enum rdtech_dps_register {
54 REG_USET = 0x00, /* Mirror of 0x50 */
55 REG_ISET = 0x01, /* Mirror of 0x51 */
56 REG_UOUT = 0x02,
57 REG_IOUT = 0x03,
58 REG_POWER = 0x04,
59 REG_UIN = 0x05,
60 REG_LOCK = 0x06,
61 REG_PROTECT = 0x07,
62 REG_CV_CC = 0x08,
63 REG_ENABLE = 0x09,
64 REG_BACKLIGHT = 0x0A, /* Mirror of 0x55 */
65 REG_MODEL = 0x0B,
66 REG_VERSION = 0x0C,
67
68 REG_PRESET = 0x23, /* Loads a preset into preset 0. */
69
70/*
71 * Add (preset * 0x10) to each of the following, for preset 1-9.
72 * Preset 0 regs below are the active output settings.
73 */
74 PRE_USET = 0x50,
75 PRE_ISET = 0x51,
76 PRE_OVPSET = 0x52,
77 PRE_OCPSET = 0x53,
78 PRE_OPPSET = 0x54,
79 PRE_BACKLIGHT = 0x55,
80 PRE_DISABLE = 0x56, /* Disable output if 0 is copied here from a preset (1 is no change). */
81 PRE_BOOT = 0x57, /* Enable output at boot if 1. */
82};
83
84enum rdtech_dps_state {
85 STATE_NORMAL = 0,
86 STATE_OVP = 1,
87 STATE_OCP = 2,
88 STATE_OPP = 3,
0549416e
JC
89};
90
69b05583
JC
91enum rdtech_dps_mode {
92 MODE_CV = 0,
93 MODE_CC = 1,
94};
95
aff20941
FS
96SR_PRIV int rdtech_dps_read_holding_registers(struct sr_modbus_dev_inst *modbus,
97 int address, int nb_registers, uint16_t *registers);
98
7c0891b0
FS
99SR_PRIV int rdtech_dps_get_reg(const struct sr_dev_inst *sdi, uint16_t address, uint16_t *value);
100SR_PRIV int rdtech_dps_set_reg(const struct sr_dev_inst *sdi, uint16_t address, uint16_t value);
69b05583
JC
101
102SR_PRIV int rdtech_dps_get_model_version(struct sr_modbus_dev_inst *modbus,
103 uint16_t *model, uint16_t *version);
104
0549416e
JC
105SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data);
106
107#endif