mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-28 16:20:26 +00:00
wrap up usbd control transfer update
This commit is contained in:
parent
ce2fc0470c
commit
c1f6013ac4
@ -57,8 +57,8 @@
|
|||||||
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64
|
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64
|
||||||
|
|
||||||
//------------- CLASS -------------//
|
//------------- CLASS -------------//
|
||||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD 0
|
#define TUSB_CFG_DEVICE_HID_KEYBOARD 1
|
||||||
#define TUSB_CFG_DEVICE_HID_MOUSE 0
|
#define TUSB_CFG_DEVICE_HID_MOUSE 1
|
||||||
#define TUSB_CFG_DEVICE_HID_GENERIC 0 // not supported yet
|
#define TUSB_CFG_DEVICE_HID_GENERIC 0 // not supported yet
|
||||||
#define TUSB_CFG_DEVICE_MSC 1
|
#define TUSB_CFG_DEVICE_MSC 1
|
||||||
#define TUSB_CFG_DEVICE_CDC 1
|
#define TUSB_CFG_DEVICE_CDC 1
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#include "common/tusb_common.h"
|
#include "common/tusb_common.h"
|
||||||
#include "hid_device.h"
|
#include "hid_device.h"
|
||||||
|
#include "device/usbd_pvt.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF
|
// MACRO CONSTANT TYPEDEF
|
||||||
@ -184,11 +185,15 @@ tusb_error_t hidd_control_request_subtask(uint8_t port, tusb_control_request_t c
|
|||||||
if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) ) break;
|
if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
|
TU_ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
|
||||||
|
|
||||||
hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
|
hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
|
||||||
hidd_interface_t* const p_hid = p_driver->p_interface;
|
hidd_interface_t* const p_hid = p_driver->p_interface;
|
||||||
|
|
||||||
|
OSAL_SUBTASK_BEGIN
|
||||||
|
|
||||||
|
tusb_error_t err;
|
||||||
|
|
||||||
//------------- STD Request -------------//
|
//------------- STD Request -------------//
|
||||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
||||||
{
|
{
|
||||||
@ -197,18 +202,22 @@ tusb_error_t hidd_control_request_subtask(uint8_t port, tusb_control_request_t c
|
|||||||
|
|
||||||
(void) desc_index;
|
(void) desc_index;
|
||||||
|
|
||||||
ASSERT ( p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
|
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||||
TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
|
{
|
||||||
ASSERT ( p_hid->report_length <= HIDD_BUFFER_SIZE, TUSB_ERROR_NOT_ENOUGH_MEMORY);
|
SUBTASK_ASSERT ( p_hid->report_length <= HIDD_BUFFER_SIZE );
|
||||||
|
|
||||||
memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length); // to allow report descriptor not to be in USBRAM
|
// copy to allow report descriptor not to be in USBRAM
|
||||||
tusb_dcd_control_xfer(port, TUSB_DIR_IN, m_hid_buffer, p_hid->report_length, false);
|
memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length);
|
||||||
|
|
||||||
|
SUBTASK_INVOKE( usbd_control_xfer_stask(port, p_request->bmRequestType_bit.direction, m_hid_buffer, p_hid->report_length), err );
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
usbd_control_stall(port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------- Class Specific Request -------------//
|
//------------- Class Specific Request -------------//
|
||||||
else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
|
else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
|
||||||
{
|
{
|
||||||
OSAL_SUBTASK_BEGIN
|
|
||||||
|
|
||||||
if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
|
if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
|
||||||
{
|
{
|
||||||
// wValue = Report Type | Report ID
|
// wValue = Report Type | Report ID
|
||||||
@ -218,40 +227,34 @@ tusb_error_t hidd_control_request_subtask(uint8_t port, tusb_control_request_t c
|
|||||||
&p_buffer, p_request->wLength);
|
&p_buffer, p_request->wLength);
|
||||||
SUBTASK_ASSERT( p_buffer != NULL && actual_length > 0 );
|
SUBTASK_ASSERT( p_buffer != NULL && actual_length > 0 );
|
||||||
|
|
||||||
tusb_dcd_control_xfer(port, (tusb_dir_t) p_request->bmRequestType_bit.direction, p_buffer, actual_length, false);
|
SUBTASK_INVOKE( usbd_control_xfer_stask(port, p_request->bmRequestType_bit.direction, p_buffer, actual_length), err );
|
||||||
}
|
}
|
||||||
else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
|
else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
|
||||||
{
|
{
|
||||||
// return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
|
// return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
|
||||||
// wValue = Report Type | Report ID
|
// wValue = Report Type | Report ID
|
||||||
tusb_error_t error;
|
SUBTASK_INVOKE( usbd_control_xfer_stask(port, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength), err );
|
||||||
|
SUBTASK_ASSERT_STATUS(err);
|
||||||
|
|
||||||
tusb_dcd_control_xfer(port, (tusb_dir_t) p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength, true);
|
p_driver->set_report_cb(port, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength);
|
||||||
|
|
||||||
osal_semaphore_wait(usbd_control_xfer_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // wait for control xfer complete
|
|
||||||
SUBTASK_ASSERT_STATUS(error);
|
|
||||||
|
|
||||||
p_driver->set_report_cb(port, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
|
|
||||||
m_hid_buffer, p_request->wLength);
|
|
||||||
}
|
}
|
||||||
else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
|
else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
|
||||||
{
|
{
|
||||||
// uint8_t idle_rate = u16_high_u8(p_request->wValue);
|
// uint8_t idle_rate = u16_high_u8(p_request->wValue);
|
||||||
|
usbd_control_status(port, p_request->bmRequestType_bit.direction);
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
// HID_REQUEST_CONTROL_GET_IDLE:
|
// HID_REQUEST_CONTROL_GET_IDLE:
|
||||||
// HID_REQUEST_CONTROL_GET_PROTOCOL:
|
// HID_REQUEST_CONTROL_GET_PROTOCOL:
|
||||||
// HID_REQUEST_CONTROL_SET_PROTOCOL:
|
// HID_REQUEST_CONTROL_SET_PROTOCOL:
|
||||||
return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
|
usbd_control_stall(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSAL_SUBTASK_END
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
|
usbd_control_stall(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TUSB_ERROR_NONE;
|
OSAL_SUBTASK_END
|
||||||
}
|
}
|
||||||
|
|
||||||
tusb_error_t hidd_open(uint8_t port, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
tusb_error_t hidd_open(uint8_t port, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user