今天用STM32CUBEMX 生成USB 的 custom human interface device 模式。
根据网上的教程,很容易地与上位机通信。
我用BUS HOUND 抓数据时,发现每个包都是2byte。
但是项目需要传输多位,我以为修改
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS,sendbuffer , 2 );
后面的2 就可以改变每个包数据位数,但是抓包发现数据 被拆分成多个 2 byte 的包。
我上位机显示HID 是 2 byte。
第二行 input report byte length 2
- /** @defgroup USBD_AUDIO_IF_Private_Variables
- * @{
- */
- __ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
- {
- /* USER CODE BEGIN 0 */
-
- 0x06, 0xFF, 0x00, /* USAGE_PAGE (Vendor Page: 0xFF00) */
- 0x09, 0x01, /* USAGE (Demo Kit) */
- 0xa1, 0x01, /* COLLECTION (Application) */ /* 6 */ /* LED1 */
- 0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
- 0x09, 0x01, /* USAGE (LED 1) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x95, LED1_REPORT_COUNT, /* REPORT_COUNT (1) */
- 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
- 0x09, 0x01, /* USAGE (LED 1) */
- 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 26 */ /* LED2 */
- 0x85, LED2_REPORT_ID, /* REPORT_ID 2 */
- 0x09, 0x02, /* USAGE (LED 2) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x95, LED2_REPORT_COUNT, /* REPORT_COUNT (1) */
- 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x85, LED2_REPORT_ID, /* REPORT_ID (2) */
- 0x09, 0x02, /* USAGE (LED 2) */
- 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */ /* 46 */ /* LED3 */
- 0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
- 0x09, 0x03, /* USAGE (LED 3) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x95, LED3_REPORT_COUNT, /* REPORT_COUNT (1) */
- 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
- 0x09, 0x03, /* USAGE (LED 3) */
- 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
- /* 66 */
- /* LED4 */
- 0x85, LED4_REPORT_ID, /* REPORT_ID 4) */
- 0x09, 0x04, /* USAGE (LED 4) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x95, LED4_REPORT_COUNT, /* REPORT_COUNT (1) */
- 0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x85, LED4_REPORT_ID, /* REPORT_ID (4) */
- 0x09, 0x04, /* USAGE (LED 4) */
- 0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
- /* 86 */
- /* key Push Button */
- 0x85, KEY_REPORT_ID, /* REPORT_ID (5) */
- 0x09, 0x05, /* USAGE (Push Button) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
- 0x09, 0x05, /* USAGE (Push Button) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x75, 0x07, /* REPORT_SIZE (7) */
- 0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
- 0x85, KEY_REPORT_ID, /* REPORT_ID (2) */
- 0x75, 0x07, /* REPORT_SIZE (7) */
- 0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
- /* 114 */
- /* Tamper Push Button */
- 0x85, TAMPER_REPORT_ID,/* REPORT_ID (6) */
- 0x09, 0x06, /* USAGE (Tamper Push Button) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
- 0x09, 0x06, /* USAGE (Tamper Push Button) */
- 0x75, 0x01, /* REPORT_SIZE (1) */
- 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- 0x75, 0x07, /* REPORT_SIZE (7) */
-
- 0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
- 0x85, TAMPER_REPORT_ID,/* REPORT_ID (6) */
- 0x75, 0x07, /* REPORT_SIZE (7) */
- 0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
- /* 142 */
- /* ADC IN */
- 0x85, ADC_REPORT_ID, /* REPORT_ID */
- 0x09, 0x07, /* USAGE (ADC IN) */
- 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
- 0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */
- 0x75, 0x08, /* REPORT_SIZE (8) */
- 0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
- 0x85, ADC_REPORT_ID, /* REPORT_ID (7) */
- 0x09, 0x07, /* USAGE (ADC in) */
- 0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
- /* 161 */
- /* USER CODE END 0 */
- 0xC0 /* END_COLLECTION */
-
- };
复制代码
|