⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libusb.h

📁 最新的libusb库
💻 H
📖 第 1 页 / 共 3 页
字号:
 * Calling this function only makes sense from a transfer callback function, * or situations where you have already allocated a suitably sized buffer at * transfer->buffer. * * \param transfer a transfer * \returns pointer to the first byte of the data section */static inline unsigned char *libusb_control_transfer_get_data(	struct libusb_transfer *transfer){	return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;}/** \ingroup asyncio * Get the control setup packet of a control transfer. This convenience * function is here to remind you that the control setup occupies the first * 8 bytes of the transfer data buffer. * * Calling this function only makes sense from a transfer callback function, * or situations where you have already allocated a suitably sized buffer at * transfer->buffer. * * \param transfer a transfer * \returns a casted pointer to the start of the transfer data buffer */static inline struct libusb_control_setup *libusb_control_transfer_get_setup(	struct libusb_transfer *transfer){	return (struct libusb_control_setup *) transfer->buffer;}/** \ingroup asyncio * Helper function to populate the setup packet (first 8 bytes of the data * buffer) for a control transfer. The wIndex, wValue and wLength values should * be given in host-endian byte order. *  * \param buffer buffer to output the setup packet into * \param bmRequestType see the * \ref libusb_control_setup::bmRequestType "bmRequestType" field of * \ref libusb_control_setup * \param bRequest see the * \ref libusb_control_setup::bRequest "bRequest" field of  * \ref libusb_control_setup * \param wValue see the * \ref libusb_control_setup::wValue "wValue" field of  * \ref libusb_control_setup * \param wIndex see the * \ref libusb_control_setup::wIndex "wIndex" field of  * \ref libusb_control_setup * \param wLength see the * \ref libusb_control_setup::wLength "wLength" field of  * \ref libusb_control_setup */static inline void libusb_fill_control_setup(unsigned char *buffer,	uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,	uint16_t wLength){	struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;	setup->bmRequestType = bmRequestType;	setup->bRequest = bRequest;	setup->wValue = libusb_cpu_to_le16(wValue);	setup->wIndex = libusb_cpu_to_le16(wIndex);	setup->wLength = libusb_cpu_to_le16(wLength);}struct libusb_transfer *libusb_alloc_transfer(int iso_packets);int libusb_submit_transfer(struct libusb_transfer *transfer);int libusb_cancel_transfer(struct libusb_transfer *transfer);void libusb_free_transfer(struct libusb_transfer *transfer);/** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields * for a control transfer. * * If you pass a transfer buffer to this function, the first 8 bytes will * be interpreted as a control setup packet, and the wLength field will be * used to automatically populate the \ref libusb_transfer::length "length" * field of the transfer. Therefore the recommended approach is: * -# Allocate a suitably sized data buffer (including space for control setup) * -# Call libusb_fill_control_setup() * -# If this is a host-to-device transfer with a data stage, put the data *    in place after the setup packet * -# Call this function * -# Call libusb_submit_transfer() * * It is also legal to pass a NULL buffer to this function, in which case this * function will not attempt to populate the length field. Remember that you * must then populate the buffer and length fields later. * * \param transfer the transfer to populate * \param dev_handle handle of the device that will handle the transfer * \param buffer data buffer. If provided, this function will interpret the * first 8 bytes as a setup packet and infer the transfer length from that. * \param callback callback function to be invoked on transfer completion * \param user_data user data to pass to callback function * \param timeout timeout for the transfer in milliseconds */static inline void libusb_fill_control_transfer(	struct libusb_transfer *transfer, libusb_device_handle *dev_handle,	unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,	unsigned int timeout){	struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;	transfer->dev_handle = dev_handle;	transfer->endpoint = 0;	transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;	transfer->timeout = timeout;	transfer->buffer = buffer;	if (setup)		transfer->length = LIBUSB_CONTROL_SETUP_SIZE			+ libusb_le16_to_cpu(setup->wLength);	transfer->user_data = user_data;	transfer->callback = callback;}/** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields * for a bulk transfer. * * \param transfer the transfer to populate * \param dev_handle handle of the device that will handle the transfer * \param endpoint address of the endpoint where this transfer will be sent * \param buffer data buffer * \param length length of data buffer * \param callback callback function to be invoked on transfer completion * \param user_data user data to pass to callback function * \param timeout timeout for the transfer in milliseconds */static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,	libusb_device_handle *dev_handle, unsigned char endpoint,	unsigned char *buffer, int length, libusb_transfer_cb_fn callback,	void *user_data, unsigned int timeout){	transfer->dev_handle = dev_handle;	transfer->endpoint = endpoint;	transfer->type = LIBUSB_TRANSFER_TYPE_BULK;	transfer->timeout = timeout;	transfer->buffer = buffer;	transfer->length = length;	transfer->user_data = user_data;	transfer->callback = callback;}/** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields * for an interrupt transfer. * * \param transfer the transfer to populate * \param dev_handle handle of the device that will handle the transfer * \param endpoint address of the endpoint where this transfer will be sent * \param buffer data buffer * \param length length of data buffer * \param callback callback function to be invoked on transfer completion * \param user_data user data to pass to callback function * \param timeout timeout for the transfer in milliseconds */static inline void libusb_fill_interrupt_transfer(	struct libusb_transfer *transfer, libusb_device_handle *dev_handle,	unsigned char endpoint, unsigned char *buffer, int length,	libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout){	transfer->dev_handle = dev_handle;	transfer->endpoint = endpoint;	transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;	transfer->timeout = timeout;	transfer->buffer = buffer;	transfer->length = length;	transfer->user_data = user_data;	transfer->callback = callback;}/** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields * for an isochronous transfer. * * \param transfer the transfer to populate * \param dev_handle handle of the device that will handle the transfer * \param endpoint address of the endpoint where this transfer will be sent * \param buffer data buffer * \param length length of data buffer * \param num_iso_packets the number of isochronous packets * \param callback callback function to be invoked on transfer completion * \param user_data user data to pass to callback function * \param timeout timeout for the transfer in milliseconds */static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,	libusb_device_handle *dev_handle, unsigned char endpoint,	unsigned char *buffer, int length, int num_iso_packets,	libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout){	transfer->dev_handle = dev_handle;	transfer->endpoint = endpoint;	transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;	transfer->timeout = timeout;	transfer->buffer = buffer;	transfer->length = length;	transfer->num_iso_packets = num_iso_packets;	transfer->user_data = user_data;	transfer->callback = callback;}/** \ingroup asyncio * Convenience function to set the length of all packets in an isochronous * transfer, based on the num_iso_packets field in the transfer structure. * * \param transfer a transfer * \param length the length to set in each isochronous packet descriptor * \see libusb_get_max_packet_size() */static inline void libusb_set_iso_packet_lengths(	struct libusb_transfer *transfer, unsigned int length){	int i;	for (i = 0; i < transfer->num_iso_packets; i++)		transfer->iso_packet_desc[i].length = length;}/** \ingroup asyncio * Convenience function to locate the position of an isochronous packet * within the buffer of an isochronous transfer. * * This is a thorough function which loops through all preceding packets, * accumulating their lengths to find the position of the specified packet. * Typically you will assign equal lengths to each packet in the transfer, * and hence the above method is sub-optimal. You may wish to use * libusb_get_iso_packet_buffer_simple() instead. *  * \param transfer a transfer * \param packet the packet to return the address of * \returns the base address of the packet buffer inside the transfer buffer, * or NULL if the packet does not exist. * \see libusb_get_iso_packet_buffer_simple() */static inline unsigned char *libusb_get_iso_packet_buffer(	struct libusb_transfer *transfer, unsigned int packet){	int i;	size_t offset = 0;	if (packet >= transfer->num_iso_packets)		return NULL;	for (i = 0; i < packet; i++)		offset += transfer->iso_packet_desc[i].length;	return transfer->buffer + offset;}/** \ingroup asyncio * Convenience function to locate the position of an isochronous packet * within the buffer of an isochronous transfer, for transfers where each * packet is of identical size. * * This function relies on the assumption that every packet within the transfer * is of identical size to the first packet. Calculating the location of * the packet buffer is then just a simple calculation: * <tt>buffer + (packet_size * packet)</tt> * * Do not use this function on transfers other than those that have identical * packet lengths for each packet. * * \param transfer a transfer * \param packet the packet to return the address of * \returns the base address of the packet buffer inside the transfer buffer, * or NULL if the packet does not exist. * \see libusb_get_iso_packet_buffer() */static inline unsigned char *libusb_get_iso_packet_buffer_simple(	struct libusb_transfer *transfer, unsigned int packet){	if (packet >= transfer->num_iso_packets)		return NULL;		return transfer->buffer + (transfer->iso_packet_desc[0].length * packet);}/* sync I/O */int libusb_control_transfer(libusb_device_handle *dev_handle,	uint8_t request_type, uint8_t request, uint16_t value, uint16_t index,	unsigned char *data, uint16_t length, unsigned int timeout);int libusb_bulk_transfer(libusb_device_handle *dev_handle,	unsigned char endpoint, unsigned char *data, int length,	int *actual_length, unsigned int timeout);int libusb_interrupt_transfer(libusb_device_handle *dev_handle,	unsigned char endpoint, unsigned char *data, int length,	int *actual_length, unsigned int timeout);/** \ingroup desc * Retrieve a descriptor from the default control pipe. * This is a convenience function which formulates the appropriate control * message to retrieve the descriptor. * * \param dev a device handle * \param desc_type the descriptor type, see \ref libusb_descriptor_type * \param desc_index the index of the descriptor to retrieve * \param data output buffer for descriptor * \param length size of data buffer * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure */static inline int libusb_get_descriptor(libusb_device_handle *dev,	uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length){	return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,		LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,		length, 1000);}/** \ingroup desc * Retrieve a descriptor from a device. * This is a convenience function which formulates the appropriate control * message to retrieve the descriptor. The string returned is Unicode, as * detailed in the USB specifications. * * \param dev a device handle * \param desc_index the index of the descriptor to retrieve * \param langid the language ID for the string descriptor * \param data output buffer for descriptor * \param length size of data buffer * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure * \see libusb_get_string_descriptor_ascii() */static inline int libusb_get_string_descriptor(libusb_device_handle *dev,	uint8_t desc_index, uint16_t langid, unsigned char *data, int length){	return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,		LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,		langid, data, length, 1000);}int libusb_get_string_descriptor_ascii(libusb_device_handle *dev,	uint8_t index, unsigned char *data, int length);/* polling and timeouts */int libusb_try_lock_events(libusb_context *ctx);void libusb_lock_events(libusb_context *ctx);void libusb_unlock_events(libusb_context *ctx);int libusb_event_handler_active(libusb_context *ctx);void libusb_lock_event_waiters(libusb_context *ctx);void libusb_unlock_event_waiters(libusb_context *ctx);int libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);int libusb_handle_events_timeout(libusb_context *ctx, struct timeval *tv);int libusb_handle_events(libusb_context *ctx);int libusb_handle_events_locked(libusb_context *ctx, struct timeval *tv);int libusb_get_next_timeout(libusb_context *ctx, struct timeval *tv);/** \ingroup poll * File descriptor for polling */struct libusb_pollfd {	/** Numeric file descriptor */	int fd;	/** Event flags to poll for from <poll.h>. POLLIN indicates that you	 * should monitor this file descriptor for becoming ready to read from,	 * and POLLOUT indicates that you should monitor this file descriptor for	 * nonblocking write readiness. */	short events;};/** \ingroup poll * Callback function, invoked when a new file descriptor should be added * to the set of file descriptors monitored for events. * \param fd the new file descriptor * \param events events to monitor for, see \ref libusb_pollfd for a * description * \param user_data User data pointer specified in * libusb_set_pollfd_notifiers() call * \see libusb_set_pollfd_notifiers() */typedef void (*libusb_pollfd_added_cb)(int fd, short events, void *user_data);/** \ingroup poll * Callback function, invoked when a file descriptor should be removed from * the set of file descriptors being monitored for events. After returning * from this callback, do not use that file descriptor again. * \param fd the file descriptor to stop monitoring * \param user_data User data pointer specified in * libusb_set_pollfd_notifiers() call * \see libusb_set_pollfd_notifiers() */typedef void (*libusb_pollfd_removed_cb)(int fd, void *user_data);const struct libusb_pollfd **libusb_get_pollfds(libusb_context *ctx);void libusb_set_pollfd_notifiers(libusb_context *ctx,	libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,	void *user_data);#ifdef __cplusplus}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -