]>
Commit | Line | Data |
---|---|---|
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 | ||
20 | #ifndef LIBSIGROK_HARDWARE_ATTEN_PPS3XXX_PROTOCOL_H | |
21 | #define LIBSIGROK_HARDWARE_ATTEN_PPS3XXX_PROTOCOL_H | |
22 | ||
23 | #include <stdint.h> | |
24 | #include <glib.h> | |
25 | #include <libsigrok/libsigrok.h> | |
26 | #include "libsigrok-internal.h" | |
27 | ||
28 | #define LOG_PREFIX "atten-pps3xxx" | |
29 | ||
30 | /* Packets to/from the device. */ | |
31 | #define PACKET_SIZE 24 | |
32 | ||
33 | enum { | |
34 | PPS_3203T_3S, | |
35 | PPS_3203T_2S, | |
36 | PPS_3205T_3S, | |
37 | PPS_3205T_2S, | |
38 | PPS_3003S, | |
39 | PPS_3005S, | |
40 | }; | |
41 | ||
42 | /* Maximum number of output channels handled by this driver. */ | |
43 | #define MAX_CHANNELS 3 | |
44 | ||
45 | #define CHANMODE_INDEPENDENT 1 << 0 | |
46 | #define CHANMODE_SERIES 1 << 1 | |
47 | #define CHANMODE_PARALLEL 1 << 2 | |
48 | ||
49 | struct channel_spec { | |
50 | /* Min, max, step. */ | |
51 | gdouble voltage[3]; | |
52 | gdouble current[3]; | |
53 | }; | |
54 | ||
55 | struct pps_model { | |
56 | int modelid; | |
57 | char *name; | |
58 | int channel_modes; | |
59 | int num_channels; | |
60 | struct channel_spec channels[MAX_CHANNELS]; | |
61 | }; | |
62 | ||
63 | struct per_channel_config { | |
64 | /* Received from device. */ | |
65 | gdouble output_voltage_last; | |
66 | gdouble output_current_last; | |
67 | gboolean output_enabled; | |
68 | /* Set by frontend. */ | |
69 | gdouble output_voltage_max; | |
70 | gdouble output_current_max; | |
71 | gboolean output_enabled_set; | |
72 | }; | |
73 | ||
74 | /** Private, per-device-instance driver context. */ | |
75 | struct dev_context { | |
76 | /* Model-specific information */ | |
77 | const struct pps_model *model; | |
78 | ||
79 | /* Acquisition state */ | |
80 | gboolean acquisition_running; | |
81 | ||
82 | /* Operational state */ | |
83 | gboolean config_dirty; | |
84 | struct per_channel_config *config; | |
85 | /* Blocking write timeout for packet. */ | |
86 | int delay_ms; | |
87 | /* Received from device. */ | |
88 | int channel_mode; | |
89 | gboolean over_current_protection; | |
90 | /* Set by frontend. */ | |
91 | int channel_mode_set; | |
92 | gboolean over_current_protection_set; | |
93 | ||
94 | /* Temporary state across callbacks */ | |
95 | uint8_t packet[PACKET_SIZE]; | |
96 | int packet_size; | |
97 | ||
98 | }; | |
99 | ||
100 | SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data); | |
101 | SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet); | |
102 | SR_PRIV void send_config(const struct sr_dev_inst *sdi); | |
103 | ||
104 | #endif |