This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to transmit BULK via USB HID?

How to realize the USB HID interface and PC data transmission?

I want to connect my computer via USB hid protocol for communication

This is my code, but can only send data, can not receive, send data will enter "APP_USBD_HID_USER_EVT_IN_REPORT_DONE" interrupt, but PC to nrf52840 send data, will not enter "APP_USBD_HID_USER_EVT_OUT_REPORT_READY" interrupt, but can pass nrf_usbd_epout_size_get(nrf_drv_usb_epout3);Gets the size of the data sent to the PC.

# define APP_USBD_HID_BULK_REPORT_DSC () {\
X06 0, 0 xa0, 0 XFF, / * usage page (FFA0h, vendor defined) * / \
0x09, 0x01, /* usage (vendor defined) */ \
0xA1, 0x01, /* collection (Application) */ \
0x09, 0x02, /* usage (vendor defined) */ \
0xA1, 0x00, /* set (Physical) */ \
0 x06, xa1 0, 0 XFF, / * usage page (vendor defined) * / \
/* input report */ \
0x09, 0x03, /* usage (vendor defined) */ \
0x09, 0x04, /* usage (vendor defined) */ \
0x15, 0x80, /* logical minimum value (0x80 or -128) */ \
0x25, 0x7F, /* logical maximum (0x7F or 127) */ \
0x35, 0x00, /* physical minimum value (0) */ \
0x45, 0xFF, /* physical maximum (255) */ \
0 x75, 0 x08, / * Report length Report size (8) * / \
0x95, 0x40, /* reports the value (64 fields) */ \
0 x81, 0 x02, / * input (data, variable, absolute) * / \
/* output report */ \
0x09, 0x05, /* usage (vendor defined) */ \
0x09, 0x06, /* usage (vendor defined) */ \
0x15, 0x80, /* logical minimum value (0x80 or -128) */ \
0x25, 0x7F, /* logical maximum (0x7F or 127) */ \
0x35, 0x00, /* physical minimum value (0) */ \
0x45, 0xFF, /* physical maximum (255) */ \
0x75, 0x08, /* report length (8 bits) */ \
0x95, 0x40, /* reports the value (64 fields) */ \
0 x91, 0 x02, / * output (data, variable, absolute) * / \
0xC0, /* end of set (Physical) */ \
0xC0, /* end of collection (Application) */ \
}

#define ENDPOINT_LIST2()                                      \
(                                                             \
        NRF_DRV_USBD_EPIN3,                                   \
		NRF_DRV_USBD_EPOUT3                                   \
)

APP_USBD_HID_GENERIC_SUBCLASS_REPORT_DESC(custom_bulk_desc,APP_USBD_HID_BULK_REPORT_DSC());

static const app_usbd_hid_subclass_desc_t * reps2[] = {&custom_bulk_desc};
APP_USBD_HID_GENERIC_GLOBAL_DEF(m_app_hid_bulk,
                                APP_USBD_INTERFACE_BULK,
                                hid_bulk_ev_handler,
                                ENDPOINT_LIST2(),
                                reps2,
                                0x40,
                                0x40,
                                APP_USBD_HID_SUBCLASS_BOOT,
                                APP_USBD_HID_PROTO_GENERIC);


static void hid_bulk_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:
        {
            NRF_LOG_INFO("hid_bulk_ev_handler : APP_USBD_HID_USER_EVT_OUT_REPORT_READY");
            break;
        }
        case APP_USBD_HID_USER_EVT_IN_REPORT_DONE:
        {
			NRF_LOG_INFO("hid_bulk_ev_handler : APP_USBD_HID_USER_EVT_IN_REPORT_DONE");
            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;
    }
}
int main(void)
{
...
	app_usbd_class_inst_t const * class_inst_generic2;
	class_inst_generic2 = app_usbd_hid_generic_class_inst_get(&m_app_hid_bulk);
	ret = app_usbd_class_append(class_inst_generic2);
	APP_ERROR_CHECK(ret);
...
}

Related