Exemplo n.º 1
0
/**************************************************************************//*!
 *
 * @name  USB_Composite_Event
 *
 * @brief The funtion initializes composite endpoint
 *
 * @param controller_ID     : Controller ID
 * @param event             : Event Type
 * @param val               : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 * 
 *****************************************************************************/
void USB_Composite_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [IN] Pointer to configuration Value */
)
{   
    uint_8 count;
    
    DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
    CLASS_ARC_STRUCT_PTR dev_class_ptr;  
    
    dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);

    for(count = 0; count < dev_arc_ptr->cl_count; count++)
    {
        /* Initializes sub_classes */
        dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
        switch(dev_class_ptr->class_type)  
        {
#ifdef USE_HID_CLASS
            case HID_COMP_CC:
                USB_Class_Hid_Event(controller_ID,event,val);
            break;
#endif
#ifdef USE_AUDIO_CLASS    
            case AUDIO_COMP_CC:
                USB_Class_Audio_Event(controller_ID,event,val);
            break;
#endif
#ifdef USE_VIDEO_CLASS     
            case VIDEO_COMP_CC:
                USB_Class_Video_Event(controller_ID,event,val);
            break;
#endif
#ifdef USE_CDC_CLASS    
            case CDC_COMP_CC:
                USB_Class_CDC_Event(controller_ID,event,val);
                break;
#endif
#ifdef USE_MSD_CLASS    
            case MSD_COMP_CC:
                USB_Class_MSC_Event(controller_ID,event,val);
                break;
#endif
#ifdef USE_PHDC_CLASS
            case PHDC_COMP_CC:
                USB_Class_PHDC_Event(controller_ID,event,val);
                break;
#endif
#ifdef USE_DFU_CLASS
            case DFU_COMP_CC:
                USB_Class_Hid_Event(controller_ID,event,val);
                break;
        #endif
        }
    }
}
Exemplo n.º 2
0
 /**************************************************************************//*!
 *
 * @name  USB_Composite_Init
 *
 * @brief   The funtion initializes the Device and Controller layer
 *
 * @param   controller_ID               : Controller ID
 * @param   composite_callback_ptr      : Pointer to app callback  
 *
 * @return status:
 *                        USB_OK        : When Successfull
 *                        Others        : When Error
 *
 ******************************************************************************
 *This function initializes the Composite layer
 *****************************************************************************/ 
uint_8 USB_Composite_Init(
    uint_8    controller_ID,                            /* [IN] Controller ID */
    COMPOSITE_CALLBACK_STRUCT * composite_callback_ptr   /* [IN] Pointer to class info */
)
{    
    uint_8 count,status;
    DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
    CLASS_ARC_STRUCT_PTR dev_class_ptr;   
    
    /* Get device architecture */
    dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
    
    /* Device init */
    status = _usb_device_init(controller_ID, NULL,
        (uint_8)(dev_arc_ptr->ep_count+1), TRUE);
        
    if(status == USB_OK)
    {
        /* Initialize the generic class functions */
        status = USB_Class_Init(controller_ID,USB_Composite_Event,
            USB_Composite_Other_Requests);
        if(status == USB_OK)
        {   
            for(count = 0; count < dev_arc_ptr->cl_count; count++)
            {
                dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
                /* Initializes sub_classes */
                switch(dev_class_ptr->class_type)  
                {
#ifdef USE_HID_CLASS 
                    case HID_COMP_CC:
                        (void)USB_Class_HID_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_specific_callback);   
                        break;
#endif
#ifdef USE_AUDIO_CLASS
                    case AUDIO_COMP_CC:
                        (void)USB_Class_Audio_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_callback);   

                        break;
                    #endif
#ifdef USE_VIDEO_CLASS
                    case VIDEO_COMP_CC:
                        (void)USB_Class_Video_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_callback);  

                        break;
#endif
#ifdef USE_CDC_CLASS
                    case CDC_COMP_CC:                            
                        (void)USB_Class_CDC_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_callback, TRUE);      
                        break;
#endif
#ifdef USE_MSD_CLASS
                    case MSD_COMP_CC:
                        (void)USB_Class_MSC_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_callback); 
                        break;
#endif
#ifdef USE_PHDC_CLASS
                    case PHDC_COMP_CC:
                        (void)USB_Class_PHDC_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback); 
                        break;
#endif
#ifdef USE_DFU_CLASS
                    case DFU_COMP_CC:
                        (void)USB_Class_Dfu_Init(
                            controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback,
                            composite_callback_ptr->class_app_callback[count]->vendor_req_callback,
                            composite_callback_ptr->class_app_callback[count]->param_callback); 
                        break;
#endif
                    default:
                        break;
                }
            }
        }
    }
    return status;   
}
Exemplo n.º 3
0
/**************************************************************************//*!
 *
 * @name  USB_Composite_Other_Requests
 *
 * @brief   The funtion provides flexibilty to add class and vendor specific
 *              requests
 *
 * @param controller_ID     : Controller ID
 * @param setup_packet      : Setup packet received
 * @param data              : Data to be send back
 * @param size              : Size to be returned
 *
 * @return status:
 *                        USB_OK        : When Successfull
 *                        Others        : When Error
 *
 ******************************************************************************
 * Handles Class requests and forwards vendor specific request to the
 * application
 *****************************************************************************/
uint_8 USB_Composite_Other_Requests (
    uint_8 controller_ID,               /* [IN] Controller ID */
    USB_SETUP_STRUCT * setup_packet,    /* [IN] Setup packet received */
    uint_8_ptr *data,                   /* [OUT] Data to be send back */
    USB_PACKET_SIZE *size               /* [OUT] Size to be returned*/
)
{
    DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
    CLASS_ARC_STRUCT_PTR dev_class_ptr;  
    INTERFACE_ARC_STRUCT_PTR intf_arc_ptr; 
    uint_8 status = USBERR_INVALID_REQ_TYPE;
    uint_8 itf_num = 0xFF,count,index,offset = 0;
    uint_8 ep_num = 0;
    
    *data = ((uint_8*)setup_packet)+USB_SETUP_PKT_SIZE;
    if(size == NULL)
    {
        return USBERR_GET_MEMORY_FAILED;
    }
    
    /* request is for an Interface */
    if(setup_packet->request_type & 0x01)
        itf_num = (uint_8)(setup_packet->index);
    /* request is for an Endpoint */
    else if(setup_packet->request_type & 0x02)
        ep_num = (uint_8)(setup_packet->index);
    
    
    /* Get device architecture */
    dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
    for(count=0;count<dev_arc_ptr->cl_count;count++) 
    {
        dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count]; 
        if(dev_class_ptr->class_type == PHDC_COMP_CC)
            offset = (uint_8)(sizeof(dev_class_ptr->class_type) + dev_class_ptr->value[0]*(sizeof(USB_EP_STRUCT)+1));
        else
            offset = (uint_8)(sizeof(dev_class_ptr->class_type) + dev_class_ptr->value[0]*sizeof(USB_EP_STRUCT));
        intf_arc_ptr = (INTERFACE_ARC_STRUCT_PTR)&dev_class_ptr->value[offset];
        switch(dev_class_ptr->class_type)  
        {
#ifdef USE_HID_CLASS
            /* Call Hid other request */
            case HID_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_HID_Other_Requests(controller_ID,setup_packet,data,size); 
                }
            break;
#endif
#ifdef USE_AUDIO_CLASS   
            /* Call Audio other request */
            case AUDIO_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_Audio_Other_Requests(controller_ID,setup_packet,data,size);
                }
            break;
#endif
#ifdef USE_VIDEO_CLASS   
            /* Call Video other request */
            case VIDEO_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_Video_Other_Requests(controller_ID,setup_packet,data,size);
                }
            break;
#endif
#ifdef USE_CDC_CLASS    
            /* Call Cdc other request */ 
            case CDC_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_CDC_Other_Requests(controller_ID,setup_packet,data,size);
                }
                break;
#endif
#ifdef USE_MSD_CLASS     
            /* Call Msd other request */
            case MSD_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_MSC_Other_Requests(controller_ID,setup_packet,data,size);
                }
                break;
#endif
#ifdef USE_PHDC_CLASS
            /* Call Phdc other request */
            case PHDC_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_Phdc_Other_Requests(controller_ID,setup_packet,data,size); 
                }
                break;
#endif
#ifdef USE_DFU_CLASS
            /* Call Dfu other request */
            case DFU_COMP_CC:
                for(index = 0;index<intf_arc_ptr->interface_count;index++)
                {
                    if(itf_num == intf_arc_ptr->value[index] || ep_num != 0xFF)
                        status = USB_HID_Other_Requests(controller_ID,setup_packet,data,size);
                }
                break;
#endif
            default:
                break;
        }
        
    }
    return status;  
}
Exemplo n.º 4
0
 /**************************************************************************//*!
 *
 * @name  USB_Composite_DeInit
 *
 * @brief   The funtion De-initializes the Device and Controller layer
 *
 * @param   controller_ID               : Controller ID
 * @param   composite_callback_ptr      : Pointer to app callback  
 *
 * @return status:
 *                        USB_OK        : When Successfull
 *                        Others        : When Error
 *
 ******************************************************************************
 *This function De-initializes the Composite layer
 *****************************************************************************/ 
uint_8 USB_Composite_DeInit(
    uint_8    controller_ID                           /* [IN] Controller ID */
)
{    
    uint_8 count,status = USB_OK;
    DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
    CLASS_ARC_STRUCT_PTR dev_class_ptr;   
    
     /* Call common class deinit function */
    status = USB_Class_DeInit(controller_ID);
    
    if(status == USB_OK)
    /* Call device deinit function */
    	status = _usb_device_deinit();
    
    /* Get device architecture */
    dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
    for(count = 0; count < dev_arc_ptr->cl_count; count++)
    {
        /* Initializes sub_classes */
        dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
        switch(dev_class_ptr->class_type)  
        {
#ifdef USE_HID_CLASS
            case HID_COMP_CC:
                status = USB_Class_HID_DeInit(controller_ID);
            break;
#endif
#ifdef USE_AUDIO_CLASS    
            case AUDIO_COMP_CC:
               status = USB_Class_Audio_DeInit(controller_ID);
            break;
#endif
#ifdef USE_VIDEO_CLASS     
            case VIDEO_COMP_CC:
                status = USB_Class_Video_DeInit(controller_ID);
            break;
#endif
#ifdef USE_CDC_CLASS    
            case CDC_COMP_CC:
                status = USB_Class_CDC_DeInit(controller_ID);
                break;
#endif
#ifdef USE_MSD_CLASS    
            case MSD_COMP_CC:
                status = USB_Class_MSC_DeInit(controller_ID);
                break;
#endif
#ifdef USE_PHDC_CLASS
            case PHDC_COMP_CC:
                status = USB_Class_PHDC_DeInit(controller_ID);
                break;
#endif
#ifdef USE_DFU_CLASS
            case DFU_COMP_CC:
                status = USB_Class_HID_DeInit(controller_ID);
                break;
        #endif
        }
    }
    return status;    
}
Exemplo n.º 5
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Event
 *
 * @brief The function initializes CDC endpoints
 *
 * @param controller_ID : Controller ID
 * @param event         : Event Type
 * @param val           : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 *
 *****************************************************************************/
void USB_Class_CDC_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [OUT] Pointer to configuration Value */
)
{
    uint_8 index;
    USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 count = 0,ep_count = 0;
        uint_8 index_num = 0;

#ifdef COMPOSITE_DEV
        DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
        CLASS_ARC_STRUCT_PTR dev_class_ptr;
        dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
        for(count = 0; count < dev_arc_ptr->cl_count; count++)
        {
            dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
            /* Initializes sub_classes */
            ep_count = dev_class_ptr->value[0];
            if(dev_class_ptr->class_type == 0x02/*CDC_CC*/)
                break;
            index_num +=dev_class_ptr->value[0];
        }
#else
                ep_count = usb_ep_data->count;
#endif

                for(count=index_num; count<ep_count+index_num; count++)
                {
                        USB_EP_STRUCT_PTR ep_struct_ptr=
                                (USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count]);
                        (void)_usb_device_deinit_endpoint(&controller_ID,
                                ep_struct_ptr->ep_num, ep_struct_ptr->direction);
                }

        /* intialize all non control endpoints */
        for(count=index_num; count<ep_count+index_num; count++)
        {
            USB_EP_STRUCT_PTR ep_struct=
                (USB_EP_STRUCT_PTR) (&usb_ep_data->ep[count]);

            (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
                        ep_struct->size, ep_struct->direction, ep_struct->type, FALSE);

            /* register callback service for Non Control EndPoints */
            switch(ep_struct->type)
            {
#if CIC_NOTIF_ELEM_SUPPORT
                case USB_INTERRUPT_PIPE :
                    (void)_usb_device_register_service(controller_ID,
                        (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                        USB_Class_CDC_Service_Cic_Notify);
                    break;
#endif
#if !DIC_ISOCHRONOUS_SETTING
                case USB_BULK_PIPE :
#ifdef MULTIPLE_DEVICES
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_Out);
                    }
                    else
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Bulk_In);
                    }
#endif
                    break;
#else
                case USB_ISOCHRONOUS_PIPE :
                    if(ep_struct->direction == USB_RECV)
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_Out);
                    }
                    else
                    {
                        (void)_usb_device_register_service(controller_ID,
                            (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                            USB_Class_CDC_Service_Dic_Iso_In);
                    }
                    break;
#endif
                default:
                    break;
            }
            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
                (uint_8)(USB_STATUS_ENDPOINT | ep_struct->ep_num |
                (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
                (uint_8)USB_STATUS_IDLE);
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
#if IMPLEMENT_QUEUING
        for(index = 0; index < usb_ep_data->count; index++)
        {
            g_cdc_ep[index].bin_consumer = 0x00;
            g_cdc_ep[index].bin_producer = 0x00;
        }
#endif
    }
    if(g_cdc_class_callback != NULL)
    {
        g_cdc_class_callback(controller_ID, event, val);
    }
}
Exemplo n.º 6
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Hid_Event
 *
 * @brief The function initializes HID endpoint
 *
 * @param controller_ID     : Controller ID
 * @param event             : Event Type
 * @param val               : Pointer to configuration Value
 *
 * @return None
 *
 ******************************************************************************
 * The funtion initializes the HID endpoints when Enumeration complete event is
 * received
 *****************************************************************************/
 void USB_Class_Hid_Event (
    uint_8 controller_ID,   /* [IN] Controller ID */
    uint_8 event,           /* [IN] Event Type */
    void* val               /* [IN] Pointer to configuration Value */
)
{
    uint_8 index;

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 index_num = 0;
        uint_8 count = 0,ep_count = 0;
        USB_ENDPOINTS *ep_desc_data;  
        
#ifdef COMPOSITE_DEV
        DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
        CLASS_ARC_STRUCT_PTR dev_class_ptr;   
        dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);    
        for(count = 0; count < dev_arc_ptr->cl_count; count++)
        {
            dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
            /* Initializes sub_classes */
            ep_count = dev_class_ptr->value[0];
            if(dev_class_ptr->class_type == 0x03/*HID_CC*/)
                break;
            index_num +=dev_class_ptr->value[0];
        }
        /* get the endpoints from the descriptor module */
        ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID); 
#else
        /* get the endpoints from the descriptor module */
        ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID); 
                    		    
		ep_count = ep_desc_data->count; 
#endif
		/* deinitialize all endpoints in case they were initialized */
		for(count=index_num;count<ep_count+index_num;count++) 
		{   
			USB_EP_STRUCT_PTR ep_struct_ptr= 
				(USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count]);
			(void)_usb_device_deinit_endpoint(&controller_ID,
				ep_struct_ptr->ep_num, ep_struct_ptr->direction);  
		}

        /* intialize all non control endpoints */
        for(count=index_num;count<ep_count+index_num;count++)
        {
            USB_EP_STRUCT_PTR ep_struct=
                (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];

            (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
            		ep_struct->size, ep_struct->direction, ep_struct->type,
            		TRUE);

            /* register callback service for the endpoint */
            (void)_usb_device_register_service(controller_ID,
                                  (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                                                             USB_Service_Hid);


            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
                (uint_8)(USB_STATUS_ENDPOINT | HID_ENDPOINT |
                (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
                USB_STATUS_IDLE);
        }

    }
    else if((event == USB_APP_BUS_RESET) || (event == USB_APP_CONFIG_CHANGED))
    {
        /* clear producer and consumer on reset */
        for(index = 0; index < g_hid_endpoint_data.count; index++)
        {
            g_hid_endpoint_data.ep[index].bin_consumer = 0x00;
            g_hid_endpoint_data.ep[index].bin_producer = 0x00;
            g_hid_endpoint_data.ep[index].queue_num    = 0x00;
        }
    }

    if(g_hid_class_callback != NULL)
    {
        /* notify the application of the event */
        g_hid_class_callback(controller_ID, event, val);
    }

}