资源简介
STM32 自定义HID 设备, 通过快传输接收上位机发来的数据。上位机使用Libusb库函数实现,接口简单。程序中添加了上位机接收数据的接口,USB 设备端的IN 接口也做好了,用户只要将需要发送给HOST的数据添加进去就可以了。博文地址: http://blog.csdn.net/chengwenyang/article/details/51039741
代码片段和文件信息
#include
#include
#include
#include
#include “libusb.h“
#define VID 0x8888
#define PID 0x0088
#define edp2in 0x82
#define edp2out 0x02
int main(void)
{
libusb_device **devs *dev;
int ret i;
ssize_t cnt;
usb_pro_t usb_pro;
struct libusb_device_handle *handle = NULL;
libusb_context *ctx = NULL;
ret = libusb_init(&ctx);
if (ret < 0)
return -1;
libusb_set_debug(ctx 3);
cnt = libusb_get_device_list(NULL &devs);
if (cnt < 0) {
printf(“no usb dev on bus\r\n“);
return -1;
}
i = 0;
while((dev = devs[i++]) != NULL) {
ret = libusb_get_device_descriptor(dev&desc);
if (ret < 0) {
printf(“failed to get device descriptor“);
goto error;
}
if ((desc.idVendor == VID) && (desc.idProduct == PID)) {
printf(“bLength: 0x%04x\r\n“ desc.bLength);
printf(“bDescriptorType: 0x%04x\r\n“ desc.bDescriptorType);
printf(“bcdUSB: 0x%04x\r\n“ desc.bcdUSB);
printf(“bDeviceClass: 0x%04x\r\n“ desc.bDeviceClass);
printf(“bDeviceSubClass: 0x%04x\r\n“ desc.bDeviceSubClass);
printf(“bDeviceProtocol: 0x%04x\r\n“ desc.bDeviceProtocol);
printf(“bMaxPacketSize0: 0x%04x\r\n“ desc.bMaxPacketSize0);
printf(“vendor id: 0x%04x\r\n“ desc.idVendor);
printf(“product id: 0x%04x\r\n“ desc.idProduct);
printf(“bcdDevice: 0x%04x\r\n“ desc.bcdDevice);
printf(“iManufacturer: 0x%04x\r\n“ desc.iManufacturer);
printf(“iProduct: 0x%04x\r\n“ desc.iProduct);
printf(“iSerialNumber: 0x%04x\r\n“ desc.iSerialNumber);
printf(“bNumConfigurations: 0x%04x\r\n“ desc.bNumConfigurations);
}
}
handle = libusb_open_device_with_vid_pid(ctx VID PID);
if (handle == NULL) {
printf(“cant‘t open device\r\n“);
goto error;
} else {
printf(“open device\r\n“);
}
libusb_free_device_list(devs 1);
if (libusb_kernel_driver_active(handle 0) ==1) {
printf(“kernel driver active detach it \r\n“);
if (libusb_detach_kernel_driver(handle 0) == 0) {
printf(“detached kernel driver\r\n“);
}
else {
goto error;
}
}
ret = libusb_claim_interface(handle 0);
if (ret < 0) {
printf(“can‘t claim interface\r\n“);
goto error;
} else {
printf(“claimed interface\r\n“);
}
char data[64];
int actual_len = 0;
int didi = 1000;
for (int i = 0; i< 1000; i++) {
memset(data 0 sizeof(data));
/* receive data from device */
/*
ret = libusb_bulk_transfer(handle edp2in data 64 &actual_len 0);
if (actual_len = 0) {
printf(“received nothing\r\n“);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-04-02 11:20 libsub_app\
文件 3584 2016-04-02 12:44 libsub_app\main.c
文件 469 2016-04-02 12:43 libsub_app\makefile
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\
文件 51511 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\CMSIS END USER LICENCE AGREEMENT.pdf
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Include\
文件 637870 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Include\stm32f10x.h
文件 2220 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Include\system_stm32f10x.h
文件 34574 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Release_Notes.html
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TASKING\
文件 3675 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TASKING\cstart_thumb2.asm
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\
文件 12739 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_cl.s
文件 12727 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_hd.s
文件 12374 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_hd_vl.s
文件 9961 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_ld.s
文件 10410 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_ld_vl.s
文件 10410 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_md.s
文件 10892 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_md_vl.s
文件 13387 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\TrueSTUDIO\startup_stm32f10x_xl.s
目录 0 2016-04-02 11:21 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\arm\
文件 15896 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\arm\startup_stm32f10x_cl.s
文件 15633 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\arm\startup_stm32f10x_hd.s
文件 15822 2012-03-22 22:44 stm32usb_bulk_transfer\Libraries\CMSIS\Device\ST\STM32F10x\Source\Templates\arm\startup_stm32f10x_hd_vl.s
............此处省略488个文件信息
相关资源
- STM32 TCS34725程序
- STM32的CC1101手法程序
- stm32 产生的pwm的硬件电路
- 基于STM32的NRF多机通信三台STM32的源码
- STM32按键中断+串口回显
- 基于STM32和AD9850的波形发生器2012
- stm32f407VET6数据手册.pdf中文资料
- STM32 18B20完整程序
- STM32F103驱动ILI9341DS18B20RTCADCIRED
- STM32汉字系统菜单
- STM32F4 EMWIN开发手册_V3.1.pdf
- STM32F103RB最小系统原理图+PCB
- STM32 四通道4-20mA模拟量采集板485接口
- STM32F746串口收发
- STM32 RS232串口控制
- 基于stm32的单相逆变代码可调压调频
- 基于STM32C8t6实现的温度控制系统
- stm32GPIO模拟spi驱动NRF2401
- STM32程序。多串口。DMA方式。C代码
- STM32F407+LWIP+DP83848+多端口
- 基于stm32的lcd1602
- STM32F103C8舵机控制程序,原创支持12舵
- STM32驱动8位并口ILI9225G彩屏
- stm32f429+FATFS+SD卡项目模版
- STM32F746工程模板
- keil 4 stm32 液晶显示正弦波
- stm32f4 dcmi连接OV2640串口发送
- lcd STM32 SPI三线通信驱动
- STM32F1读取SBUS接收机数据
- 基于STM32F103的循迹避障智能小车.zip
评论
共有 条评论