SDDC_Driver
Loading...
Searching...
No Matches
usb_device.h
1/*
2 * usb_device.h - Basic USB and USB control functions
3 *
4 * Copyright (C) 2020 by Franco Venturi
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 <https://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GPL-3.0-or-later
20 */
21
22#pragma once
23
24#include <libusb.h>
25#include <vector>
26#include <string>
27
28typedef struct USBDeviceInfo {
29 uint8_t index;
30 uint16_t usb_vendor_id;
31 uint16_t usb_product_id;
32 bool need_firmware;
33 std::string manufacturer;
34 std::string product;
35 std::string serial_number;
37
38typedef struct streaming streaming_t;
39
40typedef void (*streaming_read_async_cb_t)(uint32_t data_size, uint8_t *data,
41 void *context);
42
43
44std::vector<USBDeviceInfo> usb_device_get_device_list();
45
47{
48 public:
49 USBDevice();
50 ~USBDevice();
51
52 std::vector<USBDeviceInfo> getDeviceList();
53
54 void open(USBDeviceInfo dev_select, const char* image, uint32_t size);
55 void close();
56 int control(uint8_t request, uint16_t value, uint16_t index, uint8_t *data, uint16_t length, bool read);
57 int handleEvents();
58
59 int streaming_open_sync();
60 int streaming_open_async(uint32_t frame_size,
61 uint32_t num_frames, streaming_read_async_cb_t callback,
62 void *callback_context);
63 int streaming_framesize();
64 void streaming_close();
65 int streaming_set_random(int random);
66 int streaming_start();
67 int streaming_stop();
68 int streaming_reset_status();
69 int streaming_read_sync(uint8_t *data, int length,
70 int *transferred);
71
72 private:
73 libusb_context *usb_ctx = nullptr;
74 streaming_t *streaming_obj = nullptr;
75
76 libusb_device_handle *dev_handle = nullptr;
77 int completed = 0;
78 uint8_t bulk_in_endpoint_address = 0;
79 uint16_t bulk_in_max_packet_size = 0;
80 uint8_t bulk_in_max_burst = 0;
81
82 int list_endpoints(struct libusb_endpoint_descriptor endpoints[],
83 struct libusb_ss_endpoint_companion_descriptor ss_endpoints[],
84 libusb_device *device);
85 libusb_device_handle *find_usb_device(USBDeviceInfo,
86 libusb_device **device, int *needs_firmware);
87
88 // --- Streaming --- //
89 struct libusb_transfer **transfers = nullptr;
90};
Definition usb_device.h:47
int control(uint8_t request, uint16_t value, uint16_t index, uint8_t *data, uint16_t length, bool read)
Send a request to the USB device.
Definition usb_device.cpp:323
Definition usb_device.h:28
Definition streaming.cpp:67