]>
Commit | Line | Data |
---|---|---|
6a25fa42 AZ |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
5089a143 AZ |
4 | * Copyright (C) 2016 Andreas Zschunke <andreas.zschunke@gmx.net> |
5 | * Copyright (C) 2017 Andrej Valek <andy@skyrain.eu> | |
6 | * Copyright (C) 2017 Uwe Hermann <uwe@hermann-uwe.de> | |
6a25fa42 AZ |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #ifndef LIBSIGROK_HARDWARE_HANTEK_4032L_PROTOCOL_H | |
23 | #define LIBSIGROK_HARDWARE_HANTEK_4032L_PROTOCOL_H | |
24 | ||
25 | #include <stdint.h> | |
26 | #include <glib.h> | |
5089a143 | 27 | #include <string.h> |
6a25fa42 AZ |
28 | #include <libsigrok/libsigrok.h> |
29 | #include "libsigrok-internal.h" | |
30 | ||
31 | #define LOG_PREFIX "hantek-4032l" | |
32 | ||
5089a143 AZ |
33 | #define H4032L_USB_VENDOR 0x04b5 |
34 | #define H4032L_USB_PRODUCT 0x4032 | |
35 | ||
36 | #define H4032L_CMD_PKT_MAGIC 0x017f | |
37 | #define H4032L_STATUS_PACKET_MAGIC 0x2B1A037F | |
38 | #define H4032L_START_PACKET_MAGIC 0x2B1A027F | |
39 | #define H4032L_END_PACKET_MAGIC 0x4D3C037F | |
40 | ||
41 | enum h4032l_trigger_edge_type { | |
42 | H4032L_TRIGGER_EDGE_TYPE_RISE = 0, | |
43 | H4032L_TRIGGER_EDGE_TYPE_FALL, | |
44 | H4032L_TRIGGER_EDGE_TYPE_TOGGLE, | |
45 | H4032L_TRIGGER_EDGE_TYPE_DISABLED | |
46 | }; | |
47 | ||
48 | enum h4032l_trigger_data_range_type { | |
49 | H4032L_TRIGGER_DATA_RANGE_TYPE_MAX = 0, | |
50 | H4032L_TRIGGER_DATA_RANGE_TYPE_MIN_OR_MAX, | |
51 | H4032L_TRIGGER_DATA_RANGE_TYPE_OUT_OF_RANGE, | |
52 | H4032L_TRIGGER_DATA_RANGE_TYPE_WITHIN_RANGE | |
53 | }; | |
54 | ||
55 | enum h4032l_trigger_time_range_type { | |
56 | H4032L_TRIGGER_TIME_RANGE_TYPE_MAX = 0, | |
57 | H4032L_TRIGGER_TIME_RANGE_TYPE_MIN_OR_MAX, | |
58 | H4032L_TRIGGER_TIME_RANGE_TYPE_OUT_OF_RANGE, | |
59 | H4032L_TRIGGER_TIME_RANGE_TYPE_WITHIN_RANGE | |
60 | }; | |
6a25fa42 | 61 | |
5089a143 AZ |
62 | enum h4032l_trigger_data_selection { |
63 | H4032L_TRIGGER_DATA_SELECTION_NEXT = 0, | |
64 | H4032L_TRIGGER_DATA_SELECTION_CURRENT, | |
65 | H4032L_TRIGGER_DATA_SELECTION_PREV | |
66 | }; | |
6a25fa42 | 67 | |
5089a143 AZ |
68 | enum h4032l_status { |
69 | H4032L_STATUS_IDLE, | |
70 | H4032L_STATUS_CMD_CONFIGURE, | |
71 | H4032L_STATUS_CMD_STATUS, | |
72 | H4032L_STATUS_RESPONSE_STATUS, | |
73 | H4032L_STATUS_RESPONSE_STATUS_RETRY, | |
74 | H4032L_STATUS_RESPONSE_STATUS_CONTINUE, | |
75 | H4032L_STATUS_CMD_GET, | |
76 | H4032L_STATUS_FIRST_TRANSFER, | |
77 | H4032L_STATUS_TRANSFER, | |
78 | }; | |
6a25fa42 | 79 | |
5089a143 AZ |
80 | struct __attribute__((__packed__)) h4032l_trigger { |
81 | struct { | |
82 | uint32_t edge_signal:5; | |
83 | uint32_t edge_type:2; | |
84 | uint32_t :1; | |
85 | uint32_t data_range_type:2; | |
86 | uint32_t time_range_type:2; | |
87 | uint32_t data_range_enabled:1; | |
88 | uint32_t time_range_enabled:1; | |
89 | uint32_t :2; | |
90 | uint32_t data_sel:2; | |
91 | uint32_t combined_enabled:1; | |
92 | } flags; | |
93 | uint32_t data_range_min; | |
94 | uint32_t data_range_max; | |
95 | uint32_t time_range_min; | |
96 | uint32_t time_range_max; | |
97 | uint32_t data_range_mask; | |
98 | uint32_t combine_mask; | |
99 | uint32_t combine_data; | |
100 | }; | |
6a25fa42 | 101 | |
5089a143 AZ |
102 | struct __attribute__((__packed__)) h4032l_cmd_pkt { |
103 | uint16_t magic; /* 0x017f */ | |
104 | uint8_t sample_rate; | |
105 | struct { | |
106 | uint8_t enable_trigger1:1; | |
107 | uint8_t enable_trigger2:1; | |
108 | uint8_t trigger_and_logic:1; | |
109 | } trig_flags; | |
110 | uint16_t pwm_a; | |
111 | uint16_t pwm_b; | |
112 | uint16_t reserved; | |
113 | uint32_t sample_size; /* Sample depth in bits per channel, 2k-64M, must be multiple of 512. */ | |
114 | uint32_t pre_trigger_size; /* Pretrigger buffer depth in bits, must be < sample_size. */ | |
115 | struct h4032l_trigger trigger[2]; | |
116 | uint16_t cmd; | |
117 | }; | |
118 | ||
119 | struct dev_context { | |
120 | enum h4032l_status status; | |
121 | uint32_t remaining_samples; | |
122 | struct h4032l_cmd_pkt cmd_pkt; | |
123 | struct libusb_transfer *usb_transfer; | |
124 | uint8_t buffer[512]; | |
125 | uint64_t capture_ratio; | |
6a25fa42 AZ |
126 | }; |
127 | ||
5089a143 AZ |
128 | SR_PRIV int h4032l_receive_data(int fd, int revents, void *cb_data); |
129 | SR_PRIV uint16_t h4032l_voltage2pwm(double voltage); | |
130 | SR_PRIV void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer); | |
131 | SR_PRIV int h4032l_start(const struct sr_dev_inst *sdi); | |
132 | SR_PRIV int h4032l_dev_open(struct sr_dev_inst *sdi); | |
6a25fa42 AZ |
133 | |
134 | #endif |