I'm trying to add an OUT endpoint to the keyboard example project. I can't seem to get it to detect the USB_DEV_EVENT_DATA_RECEIVED. I'm writing 1 byte of USB data from Perisoft's Bus Hound application. Then endpoints are detected by it, but when I do a write the flag USB_DEV_EVENT_DATA_RECIEVED is never set. Is this the correct way to detect reads? What else should I do?
/******************************************************************************
*
* @name USB_App_Class_Callback
*
* @brief This function handles USB-HID Class callback
*
* @param request : request type
* @param value : give report type and id
* @param data : pointer to the data
* @param size : size of the transfer
*
* @return status
* USB_OK : if successful
* else return error
*
*****************************************************************************
* This function is called whenever a HID class request is received. This
* function handles these class requests.
*****************************************************************************/
uint8_t USB_App_Class_Callback(uint8_t request, uint16_t value, uint8_t ** data, uint32_t* size, void* arg)
{
uint8_t error = USB_OK;
uint8_t index = (uint8_t)((request - 2) & USB_HID_REQUEST_TYPE_MASK);
if ((request == USB_DEV_EVENT_SEND_COMPLETE) && (value == USB_REQ_VAL_INVALID))
{
if ((g_keyboard.keyboard_init) && (arg != NULL))
{
KeyBoard_Events_Process(); /* run the cursor movement code */
}
return error;
}
if ((request == USB_DEV_EVENT_DATA_RECEIVED) && (value == USB_REQ_VAL_INVALID))
{
if((g_keyboard.keyboard_init) && (arg != NULL))
{
KeyBoard_Events_Set();
}
return error;
}
/* index == 0 for get/set idle, index == 1 for get/set protocol */
/* handle the class request */
switch(request)
{
case USB_HID_GET_REPORT_REQUEST:
*data = &g_keyboard.rpt_buf[0]; /* point to the report to send */
*size = KEYBOARD_BUFF_SIZE; /* report size */
break;
case USB_HID_SET_REPORT_REQUEST:
for (index = 0; index < (*size); index++)
{
/* copy the report sent by the host */
//g_keyboard.rpt_buf[index] = *(*data + index);
}
*size = 0;
break;
case USB_HID_GET_IDLE_REQUEST:
/* point to the current idle rate */
*data = &g_keyboard.app_request_params[index];
*size = REQ_DATA_SIZE;
break;
case USB_HID_SET_IDLE_REQUEST:
/* set the idle rate sent by the host */
g_keyboard.app_request_params[index] = (uint8_t)((value & MSB_MASK) >> HIGH_BYTE_SHIFT);
*size = 0;
break;
case USB_HID_GET_PROTOCOL_REQUEST:
/* point to the current protocol code
0 = Boot Protocol
1 = Report Protocol*/
*data = &g_keyboard.app_request_params[index];
*size = REQ_DATA_SIZE;
break;
case USB_HID_SET_PROTOCOL_REQUEST:
/* set the protocol sent by the host
0 = Boot Protocol
1 = Report Protocol*/
g_keyboard.app_request_params[index] = (uint8_t)(value);
*size = 0;
break;
}
return error;
}