change device driver init to open (when configured)

fix HID_REQUEST_CONTROL_SET_REPORT handle
This commit is contained in:
hathach
2013-10-29 16:29:48 +07:00
parent 5ab195a73d
commit cb0a02f8c9
7 changed files with 73 additions and 26 deletions

View File

@@ -59,6 +59,8 @@ typedef struct {
endpoint_handle_t ept_handle;
uint8_t interface_number;
uint8_t idle_rate; // need to be in usb ram
hid_keyboard_report_t report;
}hidd_interface_t;
#if TUSB_CFG_DEVICE_HID_KEYBOARD
@@ -163,7 +165,7 @@ tusb_error_t hidd_configured(void)
return TUSB_ERROR_NONE;
}
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
@@ -400,17 +402,16 @@ tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const *
dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, NULL, 0);
break;
case HID_REQUEST_CONTROL_GET_IDLE:
dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, &p_kbd->idle_rate, 1); // idle_rate need to be in usb ram
break;
case HID_REQUEST_CONTROL_SET_REPORT:
// TODO hidd set report, has data phase
// TODO verify data read from control pipe
// ; uint8_t hehe[10]= { 0 };
// dcd_pipe_control_read(coreid, hehe, p_request->wLength);
{
hid_request_report_type_t report_type = u16_high_u8(p_request->wValue);
uint8_t report_id = u16_low_u8(p_request->wValue);
dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, &p_kbd->report, p_request->wLength);
}
break;
case HID_REQUEST_CONTROL_GET_IDLE:
case HID_REQUEST_CONTROL_GET_REPORT:
case HID_REQUEST_CONTROL_GET_PROTOCOL:
case HID_REQUEST_CONTROL_SET_PROTOCOL:
@@ -428,7 +429,7 @@ tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const *
return TUSB_ERROR_NONE;
}
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
@@ -448,6 +449,9 @@ tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_int
{
#if TUSB_CFG_DEVICE_HID_KEYBOARD
case HID_PROTOCOL_KEYBOARD:
// memclr_(&keyboardd_data, sizeof(hidd_interface_t));
keyboardd_data.interface_number = p_interface_desc->bInterfaceNumber;
keyboardd_data.ept_handle = dcd_pipe_open(coreid, p_desc_endpoint);
ASSERT( endpointhandle_is_valid(keyboardd_data.ept_handle), TUSB_ERROR_DCD_FAILED);
break;

View File

@@ -56,8 +56,38 @@
/** \defgroup Keyboard_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \param[in] coreid USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_keyboard_send.
*/
bool tusbd_hid_keyboard_is_busy(uint8_t coreid);
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_kbd_report);
/** \brief Perform transfer queuing
* \param[in] coreid USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref TUSB_CFG_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
* \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
* \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
* \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_report);
//------------- Application Callback -------------//
/** \brief Callback function that is invoked when an transferring event occurred
* \param[in] coreid USB Controller ID
* \param[in] event an value from \ref tusb_event_t
* \note event can be one of following
* - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
* - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
* - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
* \note Application should schedule the next report by calling \ref tusbh_hid_keyboard_get_report within this callback
*/
void tusbd_hid_keyboard_isr(uint8_t coreid, tusb_event_t event);
/** @} */
/** @} */
@@ -82,9 +112,8 @@ tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_mo
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const * p_request);
tusb_error_t hidd_configured(void);
#endif