]> sigrok.org Git - libsigrok.git/blob - src/hardware/greatfet/protocol.h
greatfet: first operational GreatFET One driver implementation
[libsigrok.git] / src / hardware / greatfet / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2019 Katherine J. Temkin <k@ktemkin.com>
5  * Copyright (C) 2019 Mikaela Szekely <qyriad@gmail.com>
6  * Copyright (C) 2023 Gerhard Sittig <gerhard.sittig@gmx.net>
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_GREATFET_PROTOCOL_H
23 #define LIBSIGROK_HARDWARE_GREATFET_PROTOCOL_H
24
25 #include <glib.h>
26 #include <libsigrok/libsigrok.h>
27 #include <stdint.h>
28
29 #include "libsigrok-internal.h"
30
31 #define LOG_PREFIX "greatfet"
32
33 struct dev_context {
34         struct sr_dev_inst *sdi;
35         GString *usb_comm_buffer;
36         char *firmware_version;
37         char *serial_number;
38         size_t channel_count;
39         char **channel_names;
40         struct sr_sw_limits sw_limits;
41         uint64_t samplerate;
42         struct dev_acquisition_t {
43                 uint64_t bandwidth_threshold;
44                 size_t unit_size;
45                 struct feed_queue_logic *feed_queue;
46                 size_t capture_channels;
47                 size_t channel_shift;
48                 size_t points_per_byte;
49                 uint64_t capture_samplerate;
50                 size_t firmware_bufsize;
51                 uint8_t samples_endpoint;
52                 uint8_t control_interface;
53                 uint8_t samples_interface;
54                 enum {
55                         ACQ_IDLE,
56                         ACQ_PREPARE,
57                         ACQ_RECEIVE,
58                         ACQ_SHUTDOWN,
59                 } acquisition_state;
60                 gboolean frame_begin_sent;
61                 gboolean control_interface_claimed;
62                 gboolean samples_interface_claimed;
63                 gboolean start_req_sent;
64         } acquisition;
65         struct dev_transfers_t {
66                 size_t transfer_bufsize;
67                 size_t transfers_count;
68                 uint8_t *transfer_buffer;
69                 struct libusb_transfer **transfers;
70                 size_t active_transfers;
71                 size_t capture_bufsize;
72         } transfers;
73 };
74
75 SR_PRIV int greatfet_get_serial_number(const struct sr_dev_inst *sdi);
76 SR_PRIV int greatfet_get_version_number(const struct sr_dev_inst *sdi);
77
78 SR_PRIV int greatfet_setup_acquisition(const struct sr_dev_inst *sdi);
79 SR_PRIV int greatfet_start_acquisition(const struct sr_dev_inst *sdi);
80 SR_PRIV void greatfet_abort_acquisition(const struct sr_dev_inst *sdi);
81 SR_PRIV int greatfet_stop_acquisition(const struct sr_dev_inst *sdi);
82 SR_PRIV void greatfet_release_resources(const struct sr_dev_inst *sdi);
83
84 SR_PRIV int greatfet_receive_data(int fd, int revents, void *cb_data);
85
86 #endif