2 * This file is part of the libsigrok project.
4 * Copyright (C) 2020 Florian Schmidt <schmidt_florian@gmx.de>
5 * Copyright (C) 2013 Marcus Comstedt <marcus@mc.pp.se>
6 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
7 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef LIBSIGROK_HARDWARE_KINGST_LA2016_PROTOCOL_H
24 #define LIBSIGROK_HARDWARE_KINGST_LA2016_PROTOCOL_H
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
31 #define LOG_PREFIX "kingst-la2016"
33 /* device is little endian */
35 #define LA2016_VID 0x77a1
36 #define LA2016_PID 0x01a2
37 #define USB_INTERFACE 0
38 #define USB_CONFIGURATION 1
40 #define LA2016_BULK_MAX 8388608
42 #define MAX_RENUM_DELAY_MS 3000
43 #define DEFAULT_TIMEOUT_MS 200
45 #define LA2016_THR_VOLTAGE_MIN 0.40
46 #define LA2016_THR_VOLTAGE_MAX 4.00
48 #define LA2016_NUM_SAMPLES_MIN 256
49 #define LA2016_NUM_SAMPLES_MAX (10UL * 1000 * 1000 * 1000)
51 typedef struct pwm_setting_dev {
54 } __attribute__((__packed__)) pwm_setting_dev_t;
56 typedef struct trigger_cfg {
60 uint32_t high_or_falling;
61 } __attribute__((__packed__)) trigger_cfg_t;
63 typedef struct sample_config {
64 uint32_t sample_depth;
68 uint16_t clock_divisor;
69 } __attribute__((__packed__)) sample_config_t;
71 typedef struct capture_info {
72 uint32_t n_rep_packets;
73 uint32_t n_rep_packets_before_trigger;
75 } __attribute__((__packed__)) capture_info_t;
77 typedef struct acq_packet {
80 } __attribute__((__packed__)) acq_packet_t;
82 typedef struct transfer_packet {
83 acq_packet_t packet[5];
85 } __attribute__((__packed__)) transfer_packet_t;
87 typedef struct pwm_setting {
91 pwm_setting_dev_t dev;
95 struct sr_context *ctx;
98 pwm_setting_t pwm_setting[2];
99 unsigned int threshold_voltage_idx;
100 float threshold_voltage;
101 uint64_t cur_samplerate;
102 uint64_t limit_samples;
103 uint64_t capture_ratio;
104 uint16_t cur_channels;
107 uint32_t bitstream_size;
110 uint64_t pre_trigger_size;
112 /* state after sampling */
113 int had_triggers_configured;
115 int transfer_finished;
117 unsigned int n_transfer_packets_to_read; /* each with 5 acq packets */
118 unsigned int n_bytes_to_read;
119 unsigned int n_reps_until_trigger;
120 unsigned int reading_behind_trigger;
121 uint64_t total_samples;
124 unsigned int convbuffer_size;
126 struct libusb_transfer *transfer;
129 SR_PRIV int la2016_upload_firmware(struct sr_context *sr_ctx, libusb_device *dev, uint16_t product_id);
130 SR_PRIV int la2016_setup_acquisition(const struct sr_dev_inst *sdi);
131 SR_PRIV int la2016_start_acquisition(const struct sr_dev_inst *sdi);
132 SR_PRIV int la2016_stop_acquisition(const struct sr_dev_inst *sdi);
133 SR_PRIV int la2016_abort_acquisition(const struct sr_dev_inst *sdi);
134 SR_PRIV int la2016_has_triggered(const struct sr_dev_inst *sdi);
135 SR_PRIV int la2016_start_retrieval(const struct sr_dev_inst *sdi, libusb_transfer_cb_fn cb);
136 SR_PRIV int la2016_init_device(const struct sr_dev_inst *sdi);
137 SR_PRIV int la2016_deinit_device(const struct sr_dev_inst *sdi);
139 #ifndef WORDS_BIGENDIAN
140 /* this host is big-endian, need to swap from/to device inplace */
141 #define inplace_WL32(obj) do { uint32_t tmp = obj; WL32(&(obj), tmp); } while (0)
142 #define inplace_RL32(obj) obj = RL32(&(obj))
143 #define inplace_WL16(obj) do { uint16_t tmp = obj; WL16(&(obj), tmp); } while (0)
144 #define inplace_RL16(obj) obj = RL16(&(obj))
146 #define pwm_setting_dev_le(obj) do { \
147 inplace_WL32((obj).period); \
148 inplace_WL32((obj).duty); \
150 #define trigger_cfg_le(obj) do { \
151 inplace_WL32((obj).channels); \
152 inplace_WL32((obj).enabled); \
153 inplace_WL32((obj).level); \
154 inplace_WL32((obj).high_or_falling); \
156 #define sample_config_le(obj) do { \
157 inplace_WL32((obj).sample_depth); \
158 inplace_WL32((obj).psa); \
159 inplace_WL16((obj).u1); \
160 inplace_WL32((obj).u2); \
161 inplace_WL16((obj).clock_divisor); \
164 #define capture_info_host(obj) do { \
165 inplace_RL32((obj).n_rep_packets); \
166 inplace_RL32((obj).n_rep_packets_before_trigger); \
167 inplace_RL32((obj).write_pos); \
169 #define acq_packet_host(obj) \
170 inplace_RL16((obj).state)
171 #define transfer_packet_host(obj) do { \
172 acq_packet_host((obj).packet[0]); \
173 acq_packet_host((obj).packet[1]); \
174 acq_packet_host((obj).packet[2]); \
175 acq_packet_host((obj).packet[3]); \
176 acq_packet_host((obj).packet[4]); \
180 /* this host is little-endian, same as device */
181 #define pwm_setting_dev_le(obj) (void)obj
182 #define trigger_cfg_le(obj) (void)obj
183 #define sample_config_le(obj) (void)obj
185 #define capture_info_host(obj) (void)obj
186 #define acq_packet_host(obj) (void)obj
187 #define transfer_packet_host(obj) (void)obj