Hi,
I am trying to receive data using USB Custom HID.
Data reception is normal using "app_usbd_hid_generic_out_report_get", but the data size is always 64 bytes.
Is there any way to know the size of the received data?
Use SDK version : 17.0.2
/** * @brief HID generic class interface number. * */ #define HID_GENERIC_INTERFACE 0 /** * @brief HID generic class endpoint number. * */ #define HID_GENERIC_EPIN NRF_DRV_USBD_EPIN1 #define HID_GENERIC_EPOUT NRF_DRV_USBD_EPOUT1 /** * @brief Number of reports defined in report descriptor. */ #define REPORT_IN_QUEUE_SIZE 1 /** * @brief Size of maximum output report. HID generic class will reserve * this buffer size + 1 memory space. * * Maximum value of this define is 63 bytes. Library automatically adds * one byte for report ID. This means that output report size is limited * to 64 bytes. */ #define REPORT_OUT_MAXSIZE 63 //0 /** * @brief Feature report maximum size. HID generic class will reserve * this buffer size + 1 memory space. */ #define REPORT_FEATURE_MAXSIZE 31 /** * @brief HID generic class endpoints count. * */ #define HID_GENERIC_EP_COUNT 2 /** * @brief List of HID generic class endpoints. * */ #define ENDPOINT_LIST() \ ( \ HID_GENERIC_EPIN, \ HID_GENERIC_EPOUT \ ) /** * @brief Mark the ongoing transmission * * Marks that the report buffer is busy and cannot be used until transmission finishes * or invalidates (by USB reset or suspend event). */ #define APP_USBD_HID_REPORT_DSC() { \ 0x06, 0x80, 0xFF, /* USAGE_PAGE | Vender Define */ \ 0x09, 0x01, /* USAGE | Vender Define */ \ 0xa1, 0x01, /* COLLECTION | Application */ \ 0x06, 0xFF, 0xFF, /* Usage Page | Vender Define */ \ 0x19, 0x00, /* Usage Minimum | 0 */ \ 0x29, 0x7F, /* Usage Maximum | 127 */ \ 0x15, 0x00, /* Logical Minimum | 0 */ \ 0x25, 0x7F, /* Logical Maximum | 127 */ \ 0x75, 0x08, /* Report Size | 8�r�b�g */ \ 0x95, 0x40, /* Report Count | 64 */ \ 0x81, 0x02, /* Input | Variable */ \ 0x06, 0xFF, 0xFF, /* Usage Page | Vender Define */ \ 0x19, 0x00, /* Usage Minimum | 0 */ \ 0x29, 0x7F, /* Usage Maximum | 127 */ \ 0x15, 0x00, /* Logical Minimum | 0 */ \ 0x25, 0x7F, /* Logical Maximum | 127 */ \ 0x75, 0x08, /* Report Size | 8�r�b�g */ \ 0x95, 0x40, /* Report Count | 64 */ \ 0x91, 0x02, /* Output | Variable */ \ 0xc0 /* END_COLLECTION */ \ } /** * @brief Reuse HID mouse report descriptor for HID generic class */ APP_USBD_HID_GENERIC_SUBCLASS_REPORT_DESC(meter_desc,APP_USBD_HID_REPORT_DSC()); static void hid_user_ev_handler(app_usbd_class_inst_t const * p_inst, app_usbd_hid_user_event_t event) { switch (event) { case APP_USBD_HID_USER_EVT_OUT_REPORT_READY: { /* No output report defined for this example.*/ NRF_LOG_INFO("APP_USBD_HID_USER_EVT_OUT_REPORT_READY"); size_t recv_size; uint8_t* recv_buf; recv_buf = (uint8_t *)app_usbd_hid_generic_out_report_get(&m_app_hid_generic,&recv_size); NRF_LOG_INFO("received data length:%d", recv_size); NRF_LOG_HEXDUMP_INFO(recv_buf, recv_size); break; } case APP_USBD_HID_USER_EVT_IN_REPORT_DONE: { m_report_pending = false; break; } case APP_USBD_HID_USER_EVT_SET_BOOT_PROTO: { UNUSED_RETURN_VALUE(hid_generic_clear_buffer(p_inst)); NRF_LOG_INFO("SET_BOOT_PROTO"); break; } case APP_USBD_HID_USER_EVT_SET_REPORT_PROTO: { UNUSED_RETURN_VALUE(hid_generic_clear_buffer(p_inst)); NRF_LOG_INFO("SET_REPORT_PROTO"); break; } default: break; } }
I have additional questions when sending data.
If the length of data to be sent is specified, it is not sent. Instead, if the length of the transmission data is set to 64 bytes, the data is transmitted normally. However, since data that is longer than the data to be sent is sent, unnecessary data is also transmitted.
global void USB_SendData( void *apvData, uchar abSize ) { ret_code_t ret; while (app_usbd_event_queue_process()) { /* Nothing to do */ } ret = app_usbd_hid_generic_in_report_set( &m_app_hid_generic, (uint8_t *)apvData, abSize); if(ret == NRF_SUCCESS) { NRF_LOG_INFO("send success"); } }