]> sigrok.org Git - libsigrok.git/blob - src/hardware/pce-322a/protocol.h
uni-t-ut181a: silence compiler warning, use of uninitialized variable
[libsigrok.git] / src / hardware / pce-322a / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2016 George Hopkins <george-hopkins@null.net>
5  * Copyright (C) 2016 Matthieu Guillaumin <matthieu@guillaum.in>
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_PCE_322A_PROTOCOL_H
22 #define LIBSIGROK_HARDWARE_PCE_322A_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 "pce-322a"
30
31 #define BUFFER_SIZE 13
32 #define MEM_USAGE_BUFFER_SIZE 9
33 #define MEM_DATA_BUFFER_SIZE 11
34
35 enum {
36         CMD_CONNECT = 0xacff,
37         CMD_DISCONNECT = 0xcaff,
38         CMD_TOGGLE_WEIGHT_FREQ = 0xaaf1,
39         CMD_TOGGLE_MEAS_RANGE = 0xaaf2,
40         CMD_TOGGLE_HOLD_MAX_MIN = 0xaaf3,
41         CMD_TOGGLE_WEIGHT_TIME = 0xaaf4,
42         CMD_TOGGLE_HOLD = 0xaaf5,
43         CMD_TOGGLE_BACKLIGHT = 0xaaf6,
44         CMD_TOGGLE_DATE_TIME = 0xaaf7,
45         CMD_LOG_START = 0x7e00,
46         CMD_MEMORY_STATUS = 0xadda,
47         CMD_MEMORY_TRANSFER = 0xd3da,
48         CMD_MEMORY_CLEAR = 0xaac1,
49         CMD_POWER_OFF = 0xaaf8,
50 };
51
52 enum {
53         MEAS_RANGE_30_130 = 0,
54         MEAS_RANGE_30_80 = 1,
55         MEAS_RANGE_50_100 = 2,
56         MEAS_RANGE_80_130 = 3,
57 };
58
59 enum {
60         DATA_SOURCE_LIVE,
61         DATA_SOURCE_MEMORY,
62 };
63
64 enum {
65         MEM_STATE_REQUEST_MEMORY_USAGE,
66         MEM_STATE_GET_MEMORY_USAGE,
67         MEM_STATE_REQUEST_MEMORY_BLOCK,
68         MEM_STATE_GET_MEMORY_BLOCK,
69 };
70
71 struct dev_context {
72         uint64_t cur_mqflags;
73         uint8_t cur_meas_range;
74
75         uint8_t cur_data_source;
76         uint64_t limit_samples;
77
78         uint64_t num_samples;
79
80         /* Memory reading state */
81         uint8_t memory_state; /* State for requesting memory usage before memory blocks. */
82         uint16_t memory_block_usage; /* Store number of memory blocks used. */
83         uint8_t memory_last_block_usage; /* Store size of last memory block. */
84         uint16_t memory_block_counter; /* Number of memory blocks retrieved so far. */
85         uint8_t memory_block_cursor; /* Number of bytes retrieved in current memory block. */
86
87         uint8_t buffer[BUFFER_SIZE];
88         int buffer_len;
89         int buffer_skip; /* Number of bytes to skip in memory mode. */
90 };
91
92 SR_PRIV int pce_322a_connect(const struct sr_dev_inst *sdi);
93 SR_PRIV int pce_322a_disconnect(const struct sr_dev_inst *sdi);
94 SR_PRIV int pce_322a_memory_status(const struct sr_dev_inst *sdi);
95 SR_PRIV int pce_322a_memory_clear(const struct sr_dev_inst *sdi);
96 SR_PRIV int pce_322a_memory_block(const struct sr_dev_inst *sdi, uint16_t memblk);
97 SR_PRIV int pce_322a_receive_data(int fd, int revents, void *cb_data);
98 SR_PRIV uint64_t pce_322a_weight_freq_get(const struct sr_dev_inst *sdi);
99 SR_PRIV int pce_322a_weight_freq_set(const struct sr_dev_inst *sdi, uint64_t freqw);
100 SR_PRIV uint64_t pce_322a_weight_time_get(const struct sr_dev_inst *sdi);
101 SR_PRIV int pce_322a_weight_time_set(const struct sr_dev_inst *sdi, uint64_t timew);
102 SR_PRIV int pce_322a_meas_range_get(const struct sr_dev_inst *sdi,
103                 uint64_t *low, uint64_t *high);
104 SR_PRIV int pce_322a_meas_range_set(const struct sr_dev_inst *sdi,
105                 uint64_t low, uint64_t high);
106 SR_PRIV int pce_322a_power_off(const struct sr_dev_inst *sdi);
107
108 #endif