update hid open()
This commit is contained in:
		| @@ -158,11 +158,12 @@ void hidd_reset(uint8_t rhport) | ||||
|   tu_memclr(_hidd_itf, sizeof(_hidd_itf)); | ||||
| } | ||||
|  | ||||
| bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len) | ||||
| uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len) | ||||
| { | ||||
|   TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass); | ||||
|   TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass, 0); | ||||
|  | ||||
|   uint8_t const *p_desc = (uint8_t const *) desc_itf; | ||||
|   // max length is at least interface + hid descriptor + 1 endpoint | ||||
|   TU_ASSERT(max_len >= sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t), 0); | ||||
|  | ||||
|   // Find available interface | ||||
|   hidd_interface_t * p_hid = NULL; | ||||
| @@ -175,16 +176,18 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   TU_ASSERT(p_hid); | ||||
|   TU_ASSERT(p_hid, 0); | ||||
|  | ||||
|   uint8_t const *p_desc = (uint8_t const *) desc_itf; | ||||
|  | ||||
|   //------------- HID descriptor -------------// | ||||
|   p_desc = tu_desc_next(p_desc); | ||||
|   p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc; | ||||
|   TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType); | ||||
|   TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType, 0); | ||||
|  | ||||
|   //------------- Endpoint Descriptor -------------// | ||||
|   p_desc = tu_desc_next(p_desc); | ||||
|   TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in)); | ||||
|   TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in), 0); | ||||
|  | ||||
|   if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->boot_protocol = desc_itf->bInterfaceProtocol; | ||||
|  | ||||
| @@ -192,12 +195,10 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t | ||||
|   p_hid->itf_num   = desc_itf->bInterfaceNumber; | ||||
|   memcpy(&p_hid->report_desc_len, &(p_hid->hid_descriptor->wReportLength), 2); | ||||
|  | ||||
|   *p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t); | ||||
|  | ||||
|   // Prepare for output endpoint | ||||
|   if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf))); | ||||
|   if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)), 0); | ||||
|  | ||||
|   return true; | ||||
|   return sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t); | ||||
| } | ||||
|  | ||||
| // Handle class control request | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach