驱动开发之libusb函数

一、libusb常用数据结构

  • libusb_device *list:设备列表
  • libusb_device_handle *handle:设备句柄
  • struct libusb_device_descriptor desc:设备描述符
  • struct libusb_config_descriptor conf:配置描述符

二、libusb常用API函数

1 会话的开启和结束

  • int libusb_init(libusb_context **ctx);
  • void libusb_exit(libusb_context *ctx);
 2 设备列表的获取和释放
  • ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list);
  • void libusb_free_device_list(libusb_device **list, int unref_devices);

3 设备的打开和关闭

  • int libusb_open(libusb_device *dev, libusb_device_handle **dev_handle);
  • libusb_device_handle * libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
  • void libusb_close(libusb_device_handle *dev_handle);

4 描述符的获取和释放

  • int libusb_get_device_descriptor(libusb_device *dev, struct libusb_device_descriptor *desc);
  • int libusb_get_config_descriptor(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config);
  • void libusb_free_config_descriptor(struct libusb_config_descriptor *config);

5 接口

  • int libusb_claim_interface(libusb_device_handle *dev_handle, int interface_number);
  • int libusb_release_interface(libusb_device_handle *dev_handle, int interface_number);

6 传输方式:Control、Interrupt、Bulk

  • int libusb_control_transfer(libusb_device_handle *dev_handle, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, 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);
  • int libusb_bulk_transfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout);

 7 内核设备

  • int libusb_kernel_driver_active(libusb_device_handle *dev_handle, int interface_number);
  • int libusb_attach_kernel_driver(libusb_device_handle *dev_handle, int interface_number);
  • int libusb_detach_kernel_driver(libusb_device_handle *dev_handle, int interface_number);
  • int libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev_handle, int enable);

8 热插拔

  • int libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class,                            libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *callback_handle);
  • void libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle callback_handle);

9 其他

  • uint8_t libusb_get_bus_number(libusb_device *dev); //获取USB设备总线号
  • uint8_t libusb_get_port_number(libusb_device *dev);
  • uint8_t libusb_get_device_address(libusb_device *dev); //获取USB设备端口号
  • int libusb_get_device_speed(libusb_device *dev);
  • int libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint);
  • int libusb_reset_device(libusb_device_handle *dev_handle);
  • int libusb_has_capability(uint32_t capability);

10 未完待续~

转载于:https://www.cnblogs.com/bo1990/p/11424779.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值