예제 #1
0
/**************************************************************************//*!
 *
 * @name  USB_Class_Hid_Event
 *
 * @brief The function initializes HID endpoint
 *
 * @param handle          handle to Identify the controller
 * @param event           pointer to event structure
 * @param val             gives the configuration value
 *
 * @return None
 *
 *****************************************************************************/
void USB_Class_Hid_Event(uint8_t event, void* val,void * arg)
{
    uint8_t index;

    USB_EP_STRUCT_PTR ep_struct_ptr;

    HID_DEVICE_STRUCT_PTR  devicePtr;

    devicePtr = (HID_DEVICE_STRUCT_PTR)arg;

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint8_t count = 0;
        uint8_t component;

        /* get the endpoints from the descriptor module */
        USB_ENDPOINTS *ep_desc_data = devicePtr->ep_desc_data;

        /* intialize all non control endpoints */
        while(count < ep_desc_data->count)
        {
            ep_struct_ptr= (USB_EP_STRUCT*) &ep_desc_data->ep[count];
            component = (uint8_t)(ep_struct_ptr->ep_num |
                (ep_struct_ptr->direction << COMPONENT_PREPARE_SHIFT));
            (void)_usb_device_init_endpoint(devicePtr->handle, ep_struct_ptr, TRUE);

            /* register callback service for endpoint 1 */
            (void)_usb_device_register_service(devicePtr->handle,
                (uint8_t)(USB_SERVICE_EP0+ep_struct_ptr->ep_num),
                USB_Service_Hid, arg);
            /* set the EndPoint Status as Idle in the device layer */
            /* (no need to specify direction for this case) */
            (void)_usb_device_set_status(devicePtr->handle,
                  (uint8_t)(USB_STATUS_ENDPOINT|component),
                  (uint16_t)USB_STATUS_IDLE);
            count++;
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
        /* clear producer and consumer */
        for(index = 0; index < devicePtr->hid_endpoint_data.count; index++)
        {
            devicePtr->hid_endpoint_data.ep[index].bin_consumer = 0x00;
            devicePtr->hid_endpoint_data.ep[index].bin_producer = 0x00;
        }
    }

    if(devicePtr->hid_class_callback.callback != NULL)
    {
        devicePtr->hid_class_callback.callback(event,val,
        devicePtr->hid_class_callback.arg);
    }
}
예제 #2
0
 /**************************************************************************//*!
 *
 * @name  USB_Class_PHDC_Event
 *
 * @brief Initializes non control endpoints
 *
 * @param handle
 * @param event          : event notified by the layer below
 * @param value          : additional parameter used by the event
 *
 * @return               : None
 ******************************************************************************
 * Initializes non control endpoints when Enumeration complete event is
 * received.
 *****************************************************************************/
static void USB_Class_PHDC_Event(uint8_t event,
                                 void* val,void *arg)
{
    uint8_t ep_count;
    USB_EP_STRUCT ep_struct;
    PHDC_STRUCT_PTR phdc_obj_ptr = (PHDC_STRUCT_PTR)arg;

    if (phdc_obj_ptr == NULL)
    {
        #if _DEBUG
            printf("USB_Class_PHDC_Event:phdc_object_ptr is NULL\n");
        #endif
        return;
    }
    /* if enum is complete initialize non-control endpoints */
    if(event == USB_APP_ENUM_COMPLETE)
    {
        /* initialize all receive endpoints */
        for(ep_count = 0; ep_count < phdc_obj_ptr->ep_data.count_rx; ep_count++)
        {
            uint8_t component = (uint8_t)(phdc_obj_ptr->ep_data.ep_rx[ep_count].endpoint |
                (USB_RECV << COMPONENT_PREPARE_SHIFT));

            /* initialize ep_struct */
            ep_struct.ep_num = phdc_obj_ptr->ep_data.ep_rx[ep_count].endpoint;
            ep_struct.size = phdc_obj_ptr->ep_data.ep_rx[ep_count].size;
            ep_struct.type = phdc_obj_ptr->ep_data.ep_rx[ep_count].type;
            ep_struct.direction = USB_RECV;

            /* initialize endpoint */
            (void)_usb_device_init_endpoint(phdc_obj_ptr->controller_handle,
             &ep_struct,TRUE);

            phdc_obj_ptr->service_buff_ptr = (uint8_t *)USB_mem_alloc_zero(ep_struct.size);
            if (NULL == phdc_obj_ptr->service_buff_ptr)
            {
                #if _DEBUG
                    printf("USB_Class_PHDC_Event: Memalloc failed\n");
                #endif
                return ;
            }

            /* set endpt status as idle in the device layer */
            (void)_usb_device_set_status(phdc_obj_ptr->controller_handle,
                (uint8_t)(USB_STATUS_ENDPOINT |component),
                (uint16_t)USB_STATUS_IDLE);
            phdc_obj_ptr->ep_data.ep_rx[ep_count].buff_ptr = NULL;
            phdc_obj_ptr->ep_data.ep_rx[ep_count].buffer_size = 0;
        }

        /* initialize all transmit endpoints */
        for(ep_count = 0; ep_count < phdc_obj_ptr->ep_data.count_tx; ep_count++)
        {
            uint8_t component = (uint8_t)(phdc_obj_ptr->ep_data.ep_tx[ep_count].endpoint |
                (USB_SEND << COMPONENT_PREPARE_SHIFT));

            /* initialize ep_struct */
            ep_struct.ep_num = phdc_obj_ptr->ep_data.ep_tx[ep_count].endpoint;
            ep_struct.size = phdc_obj_ptr->ep_data.ep_tx[ep_count].size;
            ep_struct.type = phdc_obj_ptr->ep_data.ep_tx[ep_count].type;
            ep_struct.direction = USB_SEND;

            /* initialize endpoint */
            (void)_usb_device_init_endpoint(phdc_obj_ptr->controller_handle,
             &ep_struct, TRUE);

            /* set endpt status as idle in the device layer */
            (void)_usb_device_set_status(phdc_obj_ptr->controller_handle,
                (uint8_t)(USB_STATUS_ENDPOINT |component),
                (uint16_t)USB_STATUS_IDLE);
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
        /* initialize producer and consumer to zero for transmit endpoints */
        for(ep_count = 0; ep_count < phdc_obj_ptr->ep_data.count_tx; ep_count++)
        {
            phdc_obj_ptr->ep_data.ep_tx[ep_count].bin_consumer = (uint8_t)0x00;
            phdc_obj_ptr->ep_data.ep_tx[ep_count].bin_producer = (uint8_t)0x00;
        }
    }

    if(phdc_obj_ptr->phdc_callback.callback != NULL)
    {
        phdc_obj_ptr->phdc_callback.callback(event,
            val,phdc_obj_ptr->phdc_callback.arg);
    }
}
예제 #3
0
파일: usb_mems.c 프로젝트: zhangsaisai/SEMG
/*
** ===================================================================
**     Method      :  USB_Class_Mems_Event (component USB_MEMS_CLASS)
**
**     Description :
**         The funtion initializes Mems endpoint
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void USB_Class_Mems_Event(
uint_8 controller_ID,
uint_8 event,
void* val
)
{
    uint_8 index;

    if(event == USB_APP_ENUM_COMPLETE)
    {
        uint_8 count;
        /* get the endpoints from the descriptor module */
        USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
        USB_Desc_Get_Endpoints(controller_ID);

        count = ep_desc_data->count;
        /* deinitialize all endpoints in case they were initialized */
        while(count > 0)
        {
            USB_EP_STRUCT_PTR ep_struct_ptr=
            (USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count - 1]);
            (void)_usb_device_deinit_endpoint(&controller_ID,
            ep_struct_ptr->ep_num, ep_struct_ptr->direction);
            count--;
        }

        /* intialize all non control endpoints */
        while(count < ep_desc_data->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 */
            switch(ep_struct->type)
            {
            case USB_INTERRUPT_PIPE:
                (void)_usb_device_register_service(controller_ID,
                (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                USB_Service_Mems_Status_Interrupt);
                break;       
                
            case USB_BULK_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_MEMS_Service_Dic_Bulk_Out);
               }
               else
               {
                      (void)_usb_device_register_service(controller_ID,
                      (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
                      USB_Class_MEMS_Service_Dic_Bulk_In);
               }
               break;
                                
            default:
                break;
            }
            /* set the EndPoint Status as Idle in the device layer */
            (void)_usb_device_set_status(&controller_ID,
            (uint_8)(USB_STATUS_ENDPOINT | 1|
            (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
            USB_STATUS_IDLE);
            count++;
        }
    }
    else if(event == USB_APP_BUS_RESET)
    {
        /* clear producer and consumer on reset */
        for(index = 0; index < g_mems_endpoint_data.count; index++)
        {
            g_mems_endpoint_data.ep[index].bin_consumer = 0x00;
            g_mems_endpoint_data.ep[index].bin_producer = 0x00;
            g_mems_endpoint_data.ep[index].queue_num    = 0x00;
        }
    }

    if(g_mems_class_callback != NULL)
    {
        /* notify the event to the application */
        g_mems_class_callback(controller_ID, event, val);
    }
}
예제 #4
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);
    }
}
예제 #5
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Event
 *
 * @brief The funtion initializes CDC endpoints 
 *
 * @param handle   handle to Identify the controller
 * @param event           pointer to event structure
 * @param val             gives the configuration value 
 *
 * @return None       
 *
 *****************************************************************************/
 void USB_Class_CDC_Event(uint_8 event, void* val,pointer arg) 
{  
    CDC_DEVICE_STRUCT_PTR cdc_obj_ptr = (CDC_DEVICE_STRUCT_PTR)arg;
    
    if(event == USB_APP_ENUM_COMPLETE) 
    {
        uint_8 count = 0;
        USB_EP_STRUCT_PTR ep_struct_ptr;
        
        /* get the endpoints from the descriptor module */            
        USB_ENDPOINTS *usb_ep_data = cdc_obj_ptr->usb_ep_data;
        
        /* intialize all non control endpoints */            
        while(count < usb_ep_data->count) 
        {
            ep_struct_ptr = (USB_EP_STRUCT*) &usb_ep_data->ep[count];

            (void)_usb_device_init_endpoint(cdc_obj_ptr->controller_handle,
             ep_struct_ptr,TRUE);
  
            /* register callback service for Non Control EndPoints */
            switch(ep_struct_ptr->type) 
            {
                case USB_INTERRUPT_PIPE :
                    (void)_usb_device_register_service(cdc_obj_ptr->controller_handle,
                        (uint_8)(USB_SERVICE_EP0+ep_struct_ptr->ep_num),
                        USB_Service_Cdc_Notif,(void *)cdc_obj_ptr);
                    break;                              
                case USB_BULK_PIPE :
                    if(ep_struct_ptr->direction == USB_RECV) 
                    {
                        (void)_usb_device_register_service(cdc_obj_ptr->controller_handle,
                            (uint_8)(USB_SERVICE_EP0+ep_struct_ptr->ep_num),
                            USB_Service_Dic_Bulk_Out,(void *)cdc_obj_ptr);
                    } 
                    else
                    {
                        (void)_usb_device_register_service(cdc_obj_ptr->controller_handle,
                            (uint_8)(USB_SERVICE_EP0+ep_struct_ptr->ep_num),
                            USB_Service_Dic_Bulk_In,(void *)cdc_obj_ptr);
                    }
                    break;
                default : break;        
            }
                          
            /* set the EndPoint Status as Idle in the device layer */
            /* (no need to specify direction for this case) */
            (void)_usb_device_set_status(cdc_obj_ptr->controller_handle,
                (uint_8)(USB_STATUS_ENDPOINT|ep_struct_ptr->ep_num),
                (uint_8)USB_STATUS_IDLE);                                                                                                         
            count++;                                                    
        }/* EndWhile */
    }
    #if RNDIS_SUPPORT
    else if(event == USB_APP_BUS_RESET)
    {
        uint_8_ptr data; 
        uint_32 size;
        RNDIS_Reset_Command(cdc_obj_ptr, &data, &size);     
    }
    #endif        
    if(cdc_obj_ptr->cdc_class_cb.callback != NULL) 
    {
        cdc_obj_ptr->cdc_class_cb.callback(event,
            val,cdc_obj_ptr->cdc_class_cb.arg);
    } 
}
예제 #6
0
파일: usb_hid.c 프로젝트: Alexlcb/rt-thread
/**************************************************************************//*!
 *
 * @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);
    }

}