]>
Commit | Line | Data |
---|---|---|
41b7bd01 MH |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz> | |
1c3d002b | 5 | * Copyright (C) 2014 Bert Vermeulen <bert@biot.com> (code from atten-pps3xxx) |
41b7bd01 MH |
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 | ||
d9251a2c UH |
21 | /** |
22 | * @file | |
23 | * | |
24 | * <em>Motech LPS-30x series</em> power supply driver | |
25 | * | |
26 | * @internal | |
1c3d002b MH |
27 | */ |
28 | ||
1c3d002b MH |
29 | #ifndef LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H |
30 | #define LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H | |
41b7bd01 MH |
31 | |
32 | #include <stdint.h> | |
33 | #include <glib.h> | |
c1aae900 | 34 | #include <libsigrok/libsigrok.h> |
41b7bd01 MH |
35 | #include "libsigrok-internal.h" |
36 | ||
c442ffda UH |
37 | SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat); |
38 | SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...); | |
1c3d002b MH |
39 | |
40 | #define LOG_PREFIX "motech-lps-30x" | |
41 | ||
42 | #define LINELEN_MAX 50 /**< Max. line length for requests */ | |
43 | ||
44 | #define REQ_TIMEOUT_MS 250 /**< Timeout [ms] for single request. */ | |
45 | ||
46 | #define MAX_CHANNELS 3 | |
47 | ||
48 | typedef enum { | |
49 | LPS_UNKNOWN = 0,/**< Unknown model (used during detection process) */ | |
50 | LPS_301, /**< Motech/Amrel LPS-301, 1 output */ | |
51 | LPS_302, /**< Motech/Amrel LPS-302, 1 output */ | |
52 | LPS_303, /**< Motech/Amrel LPS-303, 1 output */ | |
53 | LPS_304, /**< Motech/Amrel LPS-304, 3 outputs */ | |
54 | LPS_305, /**< Motech/Amrel LPS-305, 3 outputs */ | |
55 | } lps_modelid; | |
56 | ||
57 | /** Channel specification */ | |
58 | struct channel_spec { | |
59 | /* Min, max, step. */ | |
60 | gdouble voltage[3]; | |
61 | gdouble current[3]; | |
62 | }; | |
63 | ||
64 | /** Model properties specification */ | |
65 | struct lps_modelspec { | |
66 | lps_modelid modelid; | |
c442ffda | 67 | const char *modelstr; |
1c3d002b MH |
68 | uint8_t num_channels; |
69 | struct channel_spec channels[3]; | |
70 | }; | |
71 | ||
72 | /** Used to implement a little state machine to query all required values in a row. */ | |
73 | typedef enum { | |
74 | AQ_NONE, | |
75 | AQ_U1, | |
76 | AQ_I1, | |
77 | AQ_I2, | |
78 | AQ_U2, | |
79 | AQ_STATUS, | |
80 | } acquisition_req; | |
81 | ||
82 | /** Status of a single channel. */ | |
83 | struct channel_status { | |
84 | /* Channel information (struct channel_info*). data (struct) owned by sdi, just a reference to address a single channel. */ | |
c442ffda | 85 | GSList *info; |
1c3d002b MH |
86 | /* Received from device. */ |
87 | gdouble output_voltage_last; | |
88 | gdouble output_current_last; | |
89 | gboolean output_enabled; /**< Also used when set. */ | |
90 | gboolean cc_mode; /**< Constant current mode. If false, constant voltage mode. */ | |
91 | /* Set by frontend. */ | |
92 | gdouble output_voltage_max; | |
93 | gdouble output_current_max; | |
94 | }; | |
41b7bd01 MH |
95 | |
96 | /** Private, per-device-instance driver context. */ | |
97 | struct dev_context { | |
98 | /* Model-specific information */ | |
c442ffda | 99 | const struct lps_modelspec *model; |
41b7bd01 | 100 | |
1c3d002b | 101 | /* Acquisition status */ |
f3f19d11 | 102 | gboolean acq_running; /**< Acquisition is running. */ |
8aafc5e6 | 103 | struct sr_sw_limits limits; |
1c3d002b MH |
104 | acquisition_req acq_req; /**< Current request. */ |
105 | uint8_t acq_req_pending; /**< Request pending. 0=none, 1=reply, 2=OK */ | |
41b7bd01 MH |
106 | |
107 | /* Operational state */ | |
1c3d002b MH |
108 | struct channel_status channel_status[MAX_CHANNELS]; |
109 | guint8 tracking_mode; /**< 0=off, 1=Tracking from CH1, 2=Tracking from CH2. */ | |
41b7bd01 MH |
110 | |
111 | /* Temporary state across callbacks */ | |
1c3d002b | 112 | int64_t req_sent_at; /**< Request sent. */ |
1c3d002b MH |
113 | gchar buf[LINELEN_MAX]; /**< Buffer for read callback */ |
114 | int buflen; /**< Data len in buf */ | |
41b7bd01 MH |
115 | }; |
116 | ||
1c3d002b | 117 | SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data); |
41b7bd01 MH |
118 | |
119 | #endif |