android usb hid 空sd卡,关于使用STM32F103xx用作USBHID设备时的问题

关于使用STM32F103xx用作USBHID设备时的问题

[复制链接]

我使用stm32F103RBT6,用来作一个读卡器。发现报告描述符的配置会影响产品的适应性。我开始时把报告描述符中的输入输出报告长度定义为64字节,基本上在所有电脑上都能正确识别,并能正确操作。但为了提高传传输速度,我把输入和输出的报告长度定义为280字节后,发现计算机都能识别,但有几台新的电脑虽然能识别,但不能正常读写。不知道是何原因。请高手解答,谢谢!!!源码如下:

/* Includes ------------------------------------------------------------------*/

#include "usb_lib.h"

#include "usb_desc.h"

#include "usb_config.h"

#include "hw_config.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* Extern variables ----------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/* USB Standard Device Descriptor */

const u8 DeviceDescriptor[SIZ_DEVICE_DESC] =

{

0x12,                       /*bLength */

USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/

0x10,                       /*bcdUSB USB1.1 */

0x01,

0x00,                       /*bDeviceClass*/

0x00,                       /*bDeviceSubClass*/

0x00,                       /*bDeviceProtocol*/

0x40,                       /*bMaxPacketSize40*/

ID_VENDOR_L,                /*idVendor (0x0483)这个是需要跟USB组织申请的ID号,表示厂商代号*/

ID_VENDOR_H,

ID_PRODUCT_L,               /*idProduct = 0x1010该产品的编号,跟厂商编号一起配合使用,让主机注册该设备并加载相应的驱动程序*/

ID_PRODUCT_H,

0x00,                       /*bcdDevice rel. 1.00*/

0x01,

1,                          /*Index of string descriptor describing

manufacturer */

2,                          /*Index of string descriptor describing

product*/

3,                          /*Index of string descriptor describing the

device serial number */

0x01                        /*bNumConfigurations*/

}

; /* DeviceDescriptor */

/* USB Configuration Descriptor */

/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */

const u8 ConfigDescriptor[SIZ_CONFIG_DESC] =

{

0x09, /* bLength: Configuation Descriptor size */

USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */

SIZ_CONFIG_DESC,

/* wTotalLength: Bytes returned */

0x00,

0x01,         /*bNumInterfaces: 1 interface*/

0x01,         /*bConfigurationValue: Configuration value*/

0x00,         /*iConfiguration: Index of string descriptor describing

the configuration*/

0xA0,         /*bmAttributes: 总线供电,支持远程唤醒 */

0xC8,         /*MaxPower 400 mA: this current is used for detecting Vbus*/

/************** Descriptor of interface ****************/

/* 09 */

0x09,         /*bLength: Interface Descriptor size*/

USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/

0x00,         /*bInterfaceNumber: Number of Interface*/

0x00,         /*bAlternateSetting: Alternate setting*/

0x02,         /*bNumEndpoints*/

0x03,         /*bInterfaceClass: HID*/

0x00,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/

0x00,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/

0,            /*iInterface: Index of string descriptor*/

/******************** Descriptor of HID ********************/

/* 18 */

0x09,         /*bLength: HID Descriptor size*/

HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/

0x00,         /*bcdHID: HID Class Spec release number*/

0x01,

0x00,         /*bCountryCode: Hardware target country*/

0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/

0x22,         /*bDescriptorType*/

SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/

0x00,

/******************** Descriptor of  endpoint ********************/

/* 27 */

0x07,          /*bLength: Endpoint Descriptor size*/

USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

0x81,          /*bEndpointAddress: Endpoint Address (IN)*/

0x03,          /*bmAttributes: Interrupt endpoint*/

SEND_BUFFER_SIZE_L,          /*wMaxPacketSize: 280 Byte max */

SEND_BUFFER_SIZE_H,

0x0A,          /*bInterval: Polling Interval (10 ms)*/

/* 34 */

/******************** Descriptor of  endpoint ********************/

/* 27 */

0x07,          /*bLength: Endpoint Descriptor size*/

USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

0x01,          /*bEndpointAddress: Endpoint Address (OUT)*/

0x03,          /*bmAttributes: Interrupt endpoint*/

REC_BUFFER_SIZE_L,    /*wMaxPacketSize: 280 Byte max */

REC_BUFFER_SIZE_H,

0x0A,          /*bInterval: Polling Interval (10 ms)*/

/* 34 */

}

; /* ConfigDescriptor */

const u8 ReportDescriptor[SIZ_REPORT_DESC] =

{

0x05, 0xFF,                    // USAGE_PAGE(User define) Device Use=USAGE_PAGE*255+USAGE=0xff*255+USAGE

0x09, 0x30,                    // USAGE(User define)

0xa1, 0x01,                    // COLLECTION (Application)

0x05, 0x01,                    // USAGE_PAGE(1)

0x19, 0x00,                    //   USAGE_MINIMUM(0)

0x29, 0xFF,                    //   USAGE_MAXIMUM(255)

0x15, 0x00,                    //   LOGICAL_MINIMUM (0)

0x25, 0xFF,                    //   LOGICAL_MAXIMUM (255)

0x75, 0x10,                    //   REPORT_SIZE (16) (280 bytes=16*140 bits)

0x95, SEND_BUFFER_SIZE_REP,        //   REPORT_COUNT (140)

0x81, 0x02,                    //   INPUT (Data,Var,Abs)

0x05, 0x02,                    // USAGE_PAGE(2)

0x19, 0x00,                    //   USAGE_MINIMUM (0)

0x29, 0xFF,                    //   USAGE_MAXIMUM (255)

0x15, 0x00,                    //   LOGICAL_MINIMUM (0)

0x25, 0xFF,                    //   LOGICAL_MAXIMUM (255)

0x95, 0x10,                    //   REPORT_COUNT (16)   (280 bytes=16*140 bits)

0x75, REC_BUFFER_SIZE_REP,         //   REPORT_SIZE (140)

0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)

0xc0                           // END_COLLECTION

}; /* ReportDescriptor */

/* USB String Descriptors (optional) */

const u8 StringLangID[SIZ_STRING_LANGID] =

{

SIZ_STRING_LANGID,

USB_STRING_DESCRIPTOR_TYPE,

0x09,

0x04

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值