📄 libusb.h
字号:
/*
* Public libusb header file
* Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __LIBUSB_H__
#define __LIBUSB_H__
#include <endian.h>
#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#define bswap16(x) (((x & 0xff) << 8) | (x >> 8))
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define libusb_cpu_to_le16(x) (x)
#define libusb_le16_to_cpu(x) (x)
#elif __BYTE_ORDER == __BIG_ENDIAN
#define libusb_le16_to_cpu(x) bswap16(x)
#define libusb_cpu_to_le16(x) bswap16(x)
#else
#error "Unrecognized endianness"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* standard USB stuff */
enum libusb_class_code {
LIBUSB_CLASS_PER_INTERFACE = 0,
LIBUSB_CLASS_AUDIO = 1,
LIBUSB_CLASS_COMM = 2,
LIBUSB_CLASS_HID = 3,
LIBUSB_CLASS_PRINTER = 7,
LIBUSB_CLASS_PTP = 6,
LIBUSB_CLASS_MASS_STORAGE = 8,
LIBUSB_CLASS_HUB = 9,
LIBUSB_CLASS_DATA = 10,
LIBUSB_CLASS_VENDOR_SPEC = 0xff,
};
enum libusb_descriptor_type {
LIBUSB_DT_DEVICE = 0x01,
LIBUSB_DT_CONFIG = 0x02,
LIBUSB_DT_STRING = 0x03,
LIBUSB_DT_INTERFACE = 0x04,
LIBUSB_DT_HID = 0x21,
LIBUSB_DT_REPORT = 0x22,
LIBUSB_DT_PHYSICAL = 0x23,
LIBUSB_DT_HUB = 0x29,
};
/* Descriptor sizes per descriptor type */
#define LIBUSB_DT_DEVICE_SIZE 18
#define LIBUSB_DT_CONFIG_SIZE 9
#define LIBUSB_DT_INTERFACE_SIZE 9
#define LIBUSB_DT_ENDPOINT_SIZE 7
#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
#define LIBUSB_DT_HUB_NONVAR_SIZE 7
#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
#define LIBUSB_ENDPOINT_DIR_MASK 0x80
enum libusb_endpoint_direction {
LIBUSB_ENDPOINT_IN = 0x80,
LIBUSB_ENDPOINT_OUT = 0x00,
};
#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
enum libusb_transfer_type {
LIBUSB_TRANSFER_TYPE_CONTROL = 0,
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
LIBUSB_TRANSFER_TYPE_BULK = 2,
LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
};
enum libusb_standard_request {
LIBUSB_REQUEST_GET_STATUS = 0x00,
LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
/* 0x02 is reserved */
LIBUSB_REQUEST_SET_FEATURE = 0x03,
/* 0x04 is reserved */
LIBUSB_REQUEST_SET_ADDRESS = 0x05,
LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
};
enum libusb_request_type {
LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
};
enum libusb_request_recipient {
LIBUSB_RECIPIENT_DEVICE = 0x00,
LIBUSB_RECIPIENT_INTERFACE = 0x01,
LIBUSB_RECIPIENT_ENDPOINT = 0x02,
LIBUSB_RECIPIENT_OTHER = 0x03,
};
#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
enum libusb_iso_sync_type {
LIBUSB_ISO_SYNC_TYPE_NONE = 0,
LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
};
#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
enum libusb_iso_usage_type {
LIBUSB_ISO_USAGE_TYPE_DATA = 0,
LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
};
struct libusb_device_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
};
struct libusb_endpoint_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
uint8_t bRefresh;
uint8_t bSynchAddress;
const unsigned char *extra;
int extra_length;
};
struct libusb_interface_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
const struct libusb_endpoint_descriptor *endpoint;
const unsigned char *extra;
int extra_length;
};
struct libusb_interface {
const struct libusb_interface_descriptor *altsetting;
int num_altsetting;
};
struct libusb_config_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t MaxPower;
const struct libusb_interface *interface;
const unsigned char *extra;
int extra_length;
};
struct libusb_control_setup {
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
};
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
/* libusb */
struct libusb_context;
struct libusb_device;
struct libusb_device_handle;
typedef struct libusb_context libusb_context;
typedef struct libusb_device libusb_device;
typedef struct libusb_device_handle libusb_device_handle;
enum libusb_error {
LIBUSB_SUCCESS = 0,
LIBUSB_ERROR_IO = -1,
LIBUSB_ERROR_INVALID_PARAM = -2,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -