Beispiel #1
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Init
 *
 * @brief The function initializes the Class Module
 *
 * @param handle             :handle to Identify the controller
 * @param class_callback     :event callback      
 * @param other_req_callback :call back for class/vendor specific requests on 
 *                            CONTROL ENDPOINT
 *
 * @return status       
 *         USB_OK           : When Successfully
 *         Others           : Errors
 *
 *****************************************************************************/
class_handle_t USB_Class_Init
(
usb_device_handle handle, /* [IN] the USB device controller to initialize */
usb_device_notify_t class_callback,/*[IN]*/
usb_request_notify_t other_req_callback,/*[IN]*/
void* user_arg,/*[IN]*/
usb_desc_request_notify_struct_t* desc_callback_ptr/*[IN]*/
)
{
    usb_class_object_struct_t* class_object_ptr = NULL;
    usb_status ret;

    ret = USB_Class_Allocate_Handle(&class_object_ptr);
    if (USBERR_DEVICE_BUSY == ret)
    {
        return USBERR_DEVICE_BUSY;
    }

    class_object_ptr->controller_handle = handle;
    class_object_ptr->class_callback = class_callback;
    class_object_ptr->arg = user_arg;

    usb_device_register_application_notify(handle, class_callback, user_arg);
    usb_device_register_vendor_class_request_notify(handle, other_req_callback, user_arg);
    usb_device_register_desc_request_notify(handle, desc_callback_ptr, user_arg);

#ifdef USBCFG_OTG
    {
        descriptor_union_t desc;
        uint32_t config_size;
        usb_status error;
        uint8_t i;
        uint8_t bm_attributes = 0;
        error = desc_callback_ptr->get_desc(desc_callback_ptr->handle,USB_DESC_TYPE_CFG,0,0,(uint8_t **)&desc,&config_size);
        if(error == USB_OK)
        {
            config_size = USB_SHORT_LE_TO_HOST(*(uint16_t*)&desc.cfig->wTotalLength[0]);
            i= desc.cfig->bLength;
            desc.word += desc.cfig->bLength;
            while(i<config_size)
            {
                if (desc.otg->bDescriptorType == USB_DESC_TYPE_OTG)
                {
                    /* Found the OTG descriptor */
                    bm_attributes = desc.otg->bmAttributes;
                    break;
                } /* Endif */
                i += desc.otg->bLength;
                desc.word += desc.otg->bLength;
            }
        }
        usb_device_otg_init(handle, bm_attributes);
    }
#endif    
#if USBCFG_DEV_COMPOSITE
    /* Suppose only one class handle can be assigned */
    s_class_handle = (class_handle_t)class_object_ptr;
#endif
    return (class_handle_t)class_object_ptr;
}
Beispiel #2
0
usb_status usb_class_cdc_get_acm_descriptors
(
      /* [IN] pointer to device instance */
      usb_device_instance_handle      dev_handle,

      /* [IN] pointer to interface descriptor */
      usb_interface_descriptor_handle intf_handle,

      usb_cdc_desc_acm_t * *       acm_desc,
      usb_cdc_desc_cm_t * *        cm_desc,
      usb_cdc_desc_header_t * *    header_desc,
      usb_cdc_desc_union_t * *     union_desc
) 
{
    dev_instance_t*                 dev_ptr;
    descriptor_union_t                 ptr1, ptr2;
    usb_device_interface_struct_t*   intf_ptr =
        (usb_device_interface_struct_t*)intf_handle;
    usb_status                 status;
    //int32_t i;
    usb_cdc_func_desc_t *      fd;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_class_cdc_get_acm_descriptors");
    #endif

    status = USB_OK;
    
    dev_ptr = (dev_instance_t*)dev_handle;
    ptr1.pntr = dev_ptr->lpConfiguration; /* offset for alignment */
	ptr2.word = ptr1.word + USB_SHORT_UNALIGNED_LE_TO_HOST(ptr1.cfig->wTotalLength);
	
	while (ptr1.word < ptr2.word)
	{
		if (USB_DESC_TYPE_CS_INTERFACE == (ptr1.common->bDescriptorType))
		{
			fd = (usb_cdc_func_desc_t *)ptr1.pntr;
			
			switch (fd->header.bDescriptorSubtype) {
				case USB_DESC_SUBTYPE_CS_HEADER:
					*header_desc = &fd->header;
					if (USB_SHORT_LE_TO_HOST(*(uint16_t*)((*header_desc)->bcdCDC)) > 0x0110)
						status = USBERR_INIT_FAILED;
					break;
				case USB_DESC_SUBTYPE_CS_UNION:
					/* Check if this union descriptor describes master for this interface */
					if (fd->uni.bMasterInterface == intf_ptr->lpinterfaceDesc->bInterfaceNumber) {
						/* Check if another union descriptor has not been already assigned */
						if (*union_desc == NULL)
							*union_desc = &fd->uni;
						else
							status = USBERR_INIT_FAILED;
				  }
				  break;
				case USB_DESC_SUBTYPE_CS_ACM:
					*acm_desc = &fd->acm;
					break;
				case USB_DESC_SUBTYPE_CS_CM:
					*cm_desc = &fd->cm;
					break;
			}
		}
        if (status != USB_OK)
            break;
		ptr1.word += ptr1.common->bLength;
	}

    #ifdef _HOST_DEBUG_
    if (!status) {
        DEBUG_LOG_TRACE("usb_class_cdc_get_acm_descriptors, SUCCESSFULL");
    }
    else {
        DEBUG_LOG_TRACE("usb_class_cdc_get_acm_descriptors, FAILED");
    }
    #endif

    return status;
}