diff options
| author | hathach <[email protected]> | 2013-09-28 01:01:44 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-09-28 01:01:44 +0700 |
| commit | cb600ed9887224b6e0b4904f66442eef2900fd2d (patch) | |
| tree | 9b9a823caf8ffdbd475594fd97c68d843fcbc501 /tinyusb/class | |
| parent | bfa96ae9dade22ce8773bece9a7d8e39c6a94232 (diff) | |
clean up hid host (temp let test failed)
Diffstat (limited to 'tinyusb/class')
| -rw-r--r-- | tinyusb/class/hid_host.c | 56 | ||||
| -rw-r--r-- | tinyusb/class/hid_host.h | 8 |
2 files changed, 23 insertions, 41 deletions
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index 5dc450fa9..b968c4454 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -54,20 +54,6 @@ //--------------------------------------------------------------------+ // HID Interface common functions //--------------------------------------------------------------------+ -tusb_interface_status_t hidh_interface_status(uint8_t dev_addr, hidh_interface_info_t *p_hid) ATTR_PURE ATTR_ALWAYS_INLINE; -tusb_interface_status_t hidh_interface_status(uint8_t dev_addr, hidh_interface_info_t *p_hid) -{ - switch( tusbh_device_get_state(dev_addr) ) - { - case TUSB_DEVICE_STATE_UNPLUG: - case TUSB_DEVICE_STATE_INVALID_PARAMETER: - return TUSB_INTERFACE_STATUS_INVALID_PARA; - - default: - return p_hid->status; - } -} - static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) ATTR_ALWAYS_INLINE; static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) { @@ -93,14 +79,12 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int { //------------- parameters validation -------------// // TODO change to use is configured function - ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); - ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA); - ASSERT(TUSB_INTERFACE_STATUS_BUSY != p_hid->status, TUSB_ERROR_INTERFACE_IS_BUSY); + ASSERT_INT (TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); + ASSERT_PTR (report, TUSB_ERROR_INVALID_PARA); + ASSERT_FALSE(hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); ASSERT_STATUS( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ; - p_hid->status = TUSB_INTERFACE_STATUS_BUSY; - return TUSB_ERROR_NONE; } @@ -132,9 +116,10 @@ tusb_error_t tusbh_hid_keyboard_get_report(uint8_t dev_addr, void* report) return hidh_interface_get_report(dev_addr, report, &keyboardh_data[dev_addr-1]); } -tusb_interface_status_t tusbh_hid_keyboard_status(uint8_t dev_addr) +bool tusbh_hid_keyboard_is_busy(uint8_t dev_addr) { - return hidh_interface_status(dev_addr, &keyboardh_data[dev_addr-1]); + return tusbh_hid_keyboard_is_mounted(dev_addr) && + hcd_pipe_is_busy( keyboardh_data[dev_addr-1].pipe_hdl ); } #endif @@ -152,14 +137,15 @@ bool tusbh_hid_mouse_is_mounted(uint8_t dev_addr) return tusbh_device_is_configured(dev_addr) && pipehandle_is_valid(mouseh_data[dev_addr-1].pipe_hdl); } -tusb_error_t tusbh_hid_mouse_get_report(uint8_t dev_addr, void * report) +bool tusbh_hid_mouse_is_busy(uint8_t dev_addr) { - return hidh_interface_get_report(dev_addr, report, &mouseh_data[dev_addr-1]); + return tusbh_hid_mouse_is_mounted(dev_addr) && + hcd_pipe_is_busy( mouseh_data[dev_addr-1].pipe_hdl ); } -tusb_interface_status_t tusbh_hid_mouse_status(uint8_t dev_addr) +tusb_error_t tusbh_hid_mouse_get_report(uint8_t dev_addr, void * report) { - return hidh_interface_status(dev_addr, &mouseh_data[dev_addr-1]); + return hidh_interface_get_report(dev_addr, report, &mouseh_data[dev_addr-1]); } #endif @@ -214,17 +200,13 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con OSAL_SUBTASK_BEGIN -#if 1 - //------------- SET IDLE request -------------// - // TODO this request can be stalled by device (indicate not supported), - // until we have clear stall handler, temporarily disable it. - OSAL_SUBTASK_INVOKED_AND_WAIT( - usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE), - HID_REQUEST_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber, - 0, NULL ), - error - ); -#endif + //------------- SET IDLE (0) request -------------// + OSAL_SUBTASK_INVOKED_AND_WAIT( + usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQUEST_TYPE_CLASS, TUSB_REQUEST_RECIPIENT_INTERFACE), + HID_REQUEST_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber, + 0, NULL ), + error + ); #if 0 //------------- Get Report Descriptor TODO HID parser -------------// @@ -276,7 +258,6 @@ void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes #if TUSB_CFG_HOST_HID_KEYBOARD if ( pipehandle_is_equal(pipe_hdl, keyboardh_data[pipe_hdl.dev_addr-1].pipe_hdl) ) { - keyboardh_data[pipe_hdl.dev_addr-1].status = (event == TUSB_EVENT_XFER_COMPLETE) ? TUSB_INTERFACE_STATUS_COMPLETE : TUSB_INTERFACE_STATUS_ERROR; tusbh_hid_keyboard_isr(pipe_hdl.dev_addr, event); return; } @@ -285,7 +266,6 @@ void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes #if TUSB_CFG_HOST_HID_MOUSE if ( pipehandle_is_equal(pipe_hdl, mouseh_data[pipe_hdl.dev_addr-1].pipe_hdl) ) { - mouseh_data[pipe_hdl.dev_addr-1].status = (event == TUSB_EVENT_XFER_COMPLETE) ? TUSB_INTERFACE_STATUS_COMPLETE : TUSB_INTERFACE_STATUS_ERROR; tusbh_hid_mouse_isr(pipe_hdl.dev_addr, event); return; } diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index 6a8dc8a0d..d0179a9bc 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -60,8 +60,9 @@ extern uint8_t const hid_keycode_to_ascii_tbl[2][128]; // TODO used weak attr if build failed without KEYBOARD enabled bool tusbh_hid_keyboard_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tusbh_hid_keyboard_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; tusb_error_t tusbh_hid_keyboard_get_report(uint8_t dev_addr, void * report) /*ATTR_WARN_UNUSED_RESULT*/; -tusb_interface_status_t tusbh_hid_keyboard_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; + //------------- Application Callback -------------// void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); @@ -71,8 +72,9 @@ void tusbh_hid_keyboard_unmounted_isr(uint8_t dev_addr); // MOUSE Application API //--------------------------------------------------------------------+ bool tusbh_hid_mouse_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; +bool tusbh_hid_mouse_is_busy(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT; tusb_error_t tusbh_hid_mouse_get_report(uint8_t dev_addr, void* report) /*ATTR_WARN_UNUSED_RESULT*/; -tusb_interface_status_t tusbh_hid_mouse_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; + //------------- Application Callback -------------// void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); @@ -86,6 +88,7 @@ tusb_error_t tusbh_hid_generic_get_report(uint8_t dev_addr, void* report, bool tusb_error_t tusbh_hid_generic_set_report(uint8_t dev_addr, void* report, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; tusb_interface_status_t tusbh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; tusb_interface_status_t tusbh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; + //------------- Application Callback -------------// void tusbh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event); @@ -98,7 +101,6 @@ typedef struct { pipe_handle_t pipe_hdl; uint16_t report_size; uint8_t interface_number; - volatile tusb_interface_status_t status; }hidh_interface_info_t; void hidh_init(void); |
