/**************************************************************************//*! * * @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); } }
/* ** =================================================================== ** Method : usb_device_USB_Framework_Init (component USB_DEVICE_STACK) ** Description : ** This fuction registers the service on the control endpoint ** Parameters : ** NAME - DESCRIPTION ** controller_ID - [IN] Controller ID ** class_callback - Class Callback ** other_req_callback - Other ** Request Callback ** Returns : ** --- - Error code ** =================================================================== */ uint_8 USB_Framework_Init(uint_8 controller_ID, USB_CLASS_CALLBACK class_callback, USB_REQ_FUNC other_req_callback) { uint_8 error=USB_OK; /* save input parameters */ g_framework_callback = class_callback; g_other_req_callback = other_req_callback; /* Register CONTROL service */ error = _usb_device_register_service(controller_ID, USB_SERVICE_EP0, USB_Control_Service ); return error; }
/**************************************************************************//*! * * @name USB_Framework_Init * * @brief The function initializes the Class Module * * @param controller_ID : Controller ID * @param class_callback : Class callback pointer * @param other_req_callback: Other Request Callback * * @return status * USB_OK : When Successfull * Others : Errors * ****************************************************************************** * This function registers the service on the control endpoint *****************************************************************************/ uint_8 USB_Framework_Init ( uint_8 controller_ID, /* [IN] Controller ID */ USB_CLASS_CALLBACK class_callback, /* Class Callback */ USB_REQ_FUNC other_req_callback /* Other Request Callback */ ) { uint_8 error=USB_OK; /* save input parameters */ g_framework_callback = class_callback; g_other_req_callback = other_req_callback; /* Register CONTROL service */ error = _usb_device_register_service(controller_ID, USB_SERVICE_EP0, #ifdef DELAYED_PROCESSING USB_Control_Service_Callback #else USB_Control_Service #endif ); return error; }
/* ** =================================================================== ** 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); } }
/**************************************************************************//*! * * @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); } }
/**************************************************************************//*! * * @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); } }
/**************************************************************************//*! * * @name USB_Framework_Init * * @brief The funtion initializes the Class Module * * @param handle : handle to Identify the controller * @param class_callback: event callback * @param other_req_callback: callback for vendor or usb framework class req * * @return status * USB_OK : When Successfull * Others : Errors * *****************************************************************************/ USB_CLASS_FW_HANDLE USB_Framework_Init ( _usb_device_handle handle, /*[IN]*/ USB_CLASS_CALLBACK class_callback,/*[IN]*/ USB_REQ_FUNC other_req_callback,/*[IN]*/ pointer callback_data,/*[IN]*/ int_32 data,/*[IN]*/ DESC_CALLBACK_FUNCTIONS_STRUCT_PTR desc_callback_ptr /*[IN]*/ ) { USB_CLASS_FW_OBJECT_STRUCT_PTR usb_fw_ptr = NULL; USB_CLASS_FW_HANDLE fw_handle; uint_8 error=USB_OK; usb_fw_ptr = (USB_CLASS_FW_OBJECT_STRUCT_PTR)USB_mem_alloc_zero( sizeof(USB_CLASS_FW_OBJECT_STRUCT)); if (NULL == usb_fw_ptr) { #ifdef _DEV_DEBUG printf("USB_Framework_Init: Memalloc failed\n"); #endif return USBERR_ALLOC; } if (USBERR_DEVICE_BUSY == USB_Class_Fw_Allocate_Handle(&fw_handle)) { USB_mem_free((void *)usb_fw_ptr); usb_fw_ptr = NULL; return USBERR_ERROR; } /* save input parameters */ usb_fw_ptr->class_handle = data; usb_fw_ptr->ext_req_to_host = NULL; /* reserve memory for setup token and data received */ usb_fw_ptr->ext_req_to_host = (uint_8*)USB_mem_alloc_zero(MAX_EXPECTED_CONTROL_OUT_SIZE); if (NULL == usb_fw_ptr->ext_req_to_host) { #ifdef _DEV_DEBUG printf("ext_req_to_host malloc failed: USB_Framework_Init\n"); #endif return USBERR_ALLOC; } usb_fw_ptr->controller_handle = handle; usb_fw_ptr->other_req_callback.callback = other_req_callback; usb_fw_ptr->other_req_callback.arg = callback_data; usb_fw_ptr->class_callback.callback = class_callback; usb_fw_ptr->class_callback.arg = callback_data; USB_mem_copy( desc_callback_ptr,&usb_fw_ptr->desc, sizeof(DESC_CALLBACK_FUNCTIONS_STRUCT)); /* Register CONTROL service */ error = _usb_device_register_service(handle, USB_SERVICE_EP0, #ifdef DELAYED_PROCESSING USB_Control_Service_Callback, #else USB_Control_Service, #endif (pointer)usb_fw_ptr ); usb_class_fw_object[fw_handle] = usb_fw_ptr; return fw_handle; }
/**************************************************************************//*! * * @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); } }