]> sigrok.org Git - libsigrok.git/blob - src/hardware/maynuo-m97/protocol.h
a2e39f585bde5a2ef0560135c350ae5ec625e3e4
[libsigrok.git] / src / hardware / maynuo-m97 / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2015 Aurelien Jacobs <aurel@gnuage.org>
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_MAYNUO_M97_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_MAYNUO_M97_PROTOCOL_H
22
23 #include <stdint.h>
24 #include <libsigrok/libsigrok.h>
25 #include "libsigrok-internal.h"
26
27 #define LOG_PREFIX "maynuo-m97"
28
29 struct maynuo_m97_model {
30         unsigned int id;
31         const char *name;
32         unsigned int max_current;
33         unsigned int max_voltage;
34         unsigned int max_power;
35 };
36
37 /** Private, per-device-instance driver context. */
38 struct dev_context {
39         /* Model-specific information */
40         const struct maynuo_m97_model *model;
41
42         /* Acquisition settings */
43         struct sr_sw_limits limits;
44
45         /* Operational state */
46         int expecting_registers;
47 };
48
49 enum maynuo_m97_coil {
50         PC1        = 0x0500,
51         PC2        = 0X0501,
52         TRIG       = 0x0502,
53         REMOTE     = 0x0503,
54         ISTATE     = 0x0510,
55         TRACK      = 0x0511,
56         MEMORY     = 0x0512,
57         VOICEEN    = 0x0513,
58         CONNECT    = 0x0514,
59         ATEST      = 0x0515,
60         ATESTUN    = 0x0516,
61         ATESTPASS  = 0x0517,
62         IOVER      = 0x0520,
63         UOVER      = 0x0521,
64         POVER      = 0x0522,
65         HEAT       = 0x0523,
66         REVERSE    = 0x0524,
67         UNREG      = 0x0525,
68         ERREP      = 0x0526,
69         ERRCAL     = 0x0527,
70 };
71
72 enum maynuo_m97_register {
73         CMD        = 0x0A00,
74         IFIX       = 0x0A01,
75         UFIX       = 0x0A03,
76         PFIX       = 0x0A05,
77         RFIX       = 0x0A07,
78         TMCCS      = 0x0A09,
79         TMCVS      = 0x0A0B,
80         UCCONSET   = 0x0A0D,
81         UCCOFFSET  = 0x0A0F,
82         UCVONSET   = 0x0A11,
83         UCVOFFSET  = 0x0A13,
84         UCPONSET   = 0x0A15,
85         UCPOFFSET  = 0x0A17,
86         UCRONSET   = 0x0A19,
87         UCROFFSET  = 0x0A1B,
88         UCCCV      = 0x0A1D,
89         UCRCV      = 0x0A1F,
90         IA         = 0x0A21,
91         IB         = 0x0A23,
92         TMAWD      = 0x0A25,
93         TMBWD      = 0x0A27,
94         TMTRANSRIS = 0x0A29,
95         TMTRANSFAL = 0x0A2B,
96         MODETRAN   = 0x0A2D,
97         UBATTEND   = 0x0A2E,
98         BATT       = 0x0A30,
99         SERLIST    = 0x0A32,
100         SERATEST   = 0x0A33,
101         IMAX       = 0x0A34,
102         UMAX       = 0x0A36,
103         PMAX       = 0x0A38,
104         ILCAL      = 0x0A3A,
105         IHCAL      = 0x0A3C,
106         ULCAL      = 0x0A3E,
107         UHCAL      = 0x0A40,
108         TAGSCAL    = 0x0A42,
109         U          = 0x0B00,
110         I          = 0x0B02,
111         SETMODE    = 0x0B04,
112         INPUTMODE  = 0x0B05,
113         MODEL      = 0x0B06,
114         EDITION    = 0x0B07,
115 };
116
117 enum maynuo_m97_mode {
118         CC            =  1,
119         CV            =  2,
120         CW            =  3,
121         CR            =  4,
122         CC_SOFT_START = 20,
123         DYNAMIC       = 25,
124         SHORT_CIRCUIT = 26,
125         LIST          = 27,
126         CC_L_AND_UL   = 30,
127         CV_L_AND_UL   = 31,
128         CW_L_AND_UL   = 32,
129         CR_L_AND_UL   = 33,
130         CC_TO_CV      = 34,
131         CR_TO_CV      = 36,
132         BATTERY_TEST  = 38,
133         CV_SOFT_START = 39,
134         SYSTEM_PARAM  = 41,
135         INPUT_ON      = 42,
136         INPUT_OFF     = 43,
137 };
138
139 SR_PRIV int maynuo_m97_get_bit(struct sr_modbus_dev_inst *modbus,
140                 enum maynuo_m97_coil address, int *value);
141 SR_PRIV int maynuo_m97_set_bit(struct sr_modbus_dev_inst *modbus,
142                 enum maynuo_m97_coil address, int value);
143 SR_PRIV int maynuo_m97_get_float(struct sr_modbus_dev_inst *modbus,
144                 enum maynuo_m97_register address, float *value);
145 SR_PRIV int maynuo_m97_set_float(struct sr_modbus_dev_inst *modbus,
146                 enum maynuo_m97_register address, float value);
147
148 SR_PRIV int maynuo_m97_get_mode(struct sr_modbus_dev_inst *modbus,
149                 enum maynuo_m97_mode *mode);
150 SR_PRIV int maynuo_m97_set_mode(struct sr_modbus_dev_inst *modbus,
151                 enum maynuo_m97_mode mode);
152 SR_PRIV int maynuo_m97_set_input(struct sr_modbus_dev_inst *modbus, int enable);
153 SR_PRIV int maynuo_m97_get_model_version(struct sr_modbus_dev_inst *modbus,
154                 uint16_t *model, uint16_t *version);
155
156 SR_PRIV const char *maynuo_m97_mode_to_str(enum maynuo_m97_mode mode);
157
158 SR_PRIV int maynuo_m97_capture_start(const struct sr_dev_inst *sdi);
159 SR_PRIV int maynuo_m97_receive_data(int fd, int revents, void *cb_data);
160
161 #endif