mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-30 04:20:26 +00:00
change device driver init to open (when configured)
fix HID_REQUEST_CONTROL_SET_REPORT handle
This commit is contained in:
parent
5ab195a73d
commit
cb0a02f8c9
@ -151,7 +151,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
|
||||
.bLength = sizeof(tusb_descriptor_configuration_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_CONFIGURATION,
|
||||
|
||||
.wTotalLength = sizeof(app_descriptor_configuration_t) - 1, // exclude termination
|
||||
.wTotalLength = sizeof(app_descriptor_configuration_t),
|
||||
.bNumInterfaces = TOTAL_INTEFACES,
|
||||
|
||||
.bConfigurationValue = 1,
|
||||
|
@ -97,7 +97,6 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||
tusb_descriptor_endpoint_t msc_endpoint_out;
|
||||
#endif
|
||||
|
||||
uint8_t null_termination; // NXP rom driver requires this to work
|
||||
} app_descriptor_configuration_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -59,7 +59,7 @@ static device_class_driver_t const usbd_class_drivers[TUSB_CLASS_MAPPED_INDEX_ST
|
||||
{
|
||||
#if DEVICE_CLASS_HID
|
||||
[TUSB_CLASS_HID] = {
|
||||
.init = hidd_init,
|
||||
.open = hidd_open,
|
||||
.control_request = hidd_control_request,
|
||||
},
|
||||
#endif
|
||||
@ -99,7 +99,7 @@ void std_get_descriptor(uint8_t coreid, tusb_control_request_t * p_request)
|
||||
|
||||
case TUSB_DESC_TYPE_CONFIGURATION:
|
||||
dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, &app_tusb_desc_configuration,
|
||||
min16_of( p_request->wLength, sizeof(app_tusb_desc_configuration)-1) );
|
||||
min16_of( p_request->wLength, sizeof(app_tusb_desc_configuration)) );
|
||||
break;
|
||||
|
||||
case TUSB_DESC_TYPE_STRING:
|
||||
@ -128,12 +128,16 @@ tusb_error_t usbh_set_configure_received(uint8_t coreid, uint8_t config_number)
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
tusb_descriptor_interface_t const * p_interface = &app_tusb_desc_configuration.keyboard_interface;
|
||||
ASSERT_STATUS( hidd_init(0, p_interface, &length) );
|
||||
usbd_devices[0].interface2class[p_interface->bInterfaceNumber] = p_interface->bInterfaceClass;
|
||||
usbd_devices[coreid].interface2class[p_interface->bInterfaceNumber] = p_interface->bInterfaceClass;
|
||||
|
||||
if (usbd_class_drivers[p_interface->bInterfaceClass].open )
|
||||
{
|
||||
usbd_class_drivers[p_interface->bInterfaceClass].open(coreid, p_interface, &length);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE
|
||||
ASSERT_STATUS( hidd_init(0, &app_tusb_desc_configuration.mouse_interface, &length) );
|
||||
ASSERT_STATUS( hidd_open(0, &app_tusb_desc_configuration.mouse_interface, &length) );
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -170,7 +174,15 @@ void usbd_setup_received_isr(uint8_t coreid, tusb_control_request_t * p_request)
|
||||
|
||||
//------------- Class/Interface Specific Reqequest -------------//
|
||||
case TUSB_REQUEST_RECIPIENT_INTERFACE:
|
||||
hidd_control_request(coreid, p_request);
|
||||
{
|
||||
tusb_std_class_code_t class_code = p_device->interface2class[ u16_low_u8(p_request->wIndex) ];
|
||||
ASSERT_INT_WITHIN(TUSB_CLASS_AUDIO, TUSB_CLASS_AUDIO_VIDEO, class_code, VOID_RETURN);
|
||||
|
||||
if ( usbd_class_drivers[class_code].control_request )
|
||||
{
|
||||
usbd_class_drivers[class_code].control_request(coreid, p_request);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: ASSERT(false, VOID_RETURN); break;
|
||||
@ -188,8 +200,6 @@ tusb_error_t usbd_init (void)
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS API
|
||||
//--------------------------------------------------------------------+
|
||||
@ -199,8 +209,13 @@ tusb_error_t usbd_pipe_open(uint8_t coreid, tusb_descriptor_interface_t const *
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// callback from DCD ISR
|
||||
// USBD-DCD API
|
||||
//--------------------------------------------------------------------+
|
||||
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
usbd_device_info_t *p_device = &usbd_devices[edpt_hdl.coreid];
|
||||
|
||||
}
|
||||
//void usbd_isr(uint8_t coreid, tusb_event_t event)
|
||||
//{
|
||||
// switch(event)
|
||||
|
@ -65,7 +65,7 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
tusb_error_t (* const init)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
|
||||
tusb_error_t (* const open)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
|
||||
tusb_error_t (* const control_request) (uint8_t, tusb_control_request_t const *);
|
||||
// void (* const isr) (pipe_handle_t, tusb_event_t);
|
||||
// void (* const close) (uint8_t);
|
||||
|
@ -68,7 +68,7 @@ extern usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
|
||||
//--------------------------------------------------------------------+
|
||||
// callback from DCD ISR
|
||||
//--------------------------------------------------------------------+
|
||||
void usbd_isr(uint8_t coreid, tusb_event_t event);
|
||||
void usbd_xfer_isr(endpoint_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user