/**************************************************************************//*! * * @name USB_Class_Video_Init * * @brief The funtion initializes the Device and Controller layer * * @param controller_ID : Controller ID * @param video_class_callback : Video Class Callback * @param vendor_req_callback : Vendor Request Callback * @param param_callback : Class requests Callback * * @return status: * USB_OK : When Successfull * Others : When Error * ****************************************************************************** *This function initializes the Video Class layer and layers it is dependent on *****************************************************************************/ uint_8 USB_Class_Video_Init ( uint_8 controller_ID, /* [IN] Controller ID */ USB_CLASS_CALLBACK video_class_callback, /* [IN] Video Class Callback */ USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */ USB_CLASS_CALLBACK param_callback /* [ IN] Video Class requests Callback */ ) { uint_8 index; uint_8 status = USB_OK; USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *) USB_Desc_Get_Endpoints(controller_ID); #ifndef COMPOSITE_DEV /* Initialize the device layer*/ status = _usb_device_init(controller_ID,NULL, (uint_8)(ep_desc_data->count+1), TRUE); if(status == USB_OK) { /* Initialize the generic class functions */ status = USB_Class_Init(controller_ID,USB_Class_Video_Event, USB_Other_Requests); if(status == USB_OK) { #endif g_video_endpoint_data.count = ep_desc_data->count; for(index = 0; index < ep_desc_data->count; index++) { g_video_endpoint_data.ep[index].endpoint = ep_desc_data->ep[index].ep_num; g_video_endpoint_data.ep[index].type = ep_desc_data->ep[index].type; g_video_endpoint_data.ep[index].bin_consumer = 0x00; g_video_endpoint_data.ep[index].bin_producer = 0x00; g_video_endpoint_data.ep[index].queue_num = 0x00; } /* save the video class callback pointer */ g_video_class_callback = video_class_callback; /* save the vendor request callback pointer */ g_vendor_req_callback = vendor_req_callback; /* Save the callback to ask application for class specific params*/ g_param_callback = param_callback; #ifndef COMPOSITE_DEV } } #endif return status; }
/**************************************************************************//*! * * @name USB_Class_CDC_Init * * @brief The function initializes the Device and Controller layer * * @param controller_ID: Controller ID * @param cdc_class_callback: CDC Class Callback * @param vendor_req_callback: vendor specific class request callback * @param param_callback: PSTN Callback * * @return status * USB_OK : When Successfull * Others : Errors ****************************************************************************** * This function initializes the CDC Class layer and layers it is dependent upon *****************************************************************************/ uint_8 USB_Class_CDC_Init ( uint_8 controller_ID, /* [IN] Controller ID */ USB_CLASS_CALLBACK cdc_class_callback, /* [IN] CDC Class Callback */ USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */ USB_CLASS_CALLBACK pstn_callback, /* [IN] PSTN Callback */ uint_8 bVregEn /* Enables or disables internal regulator */ ) { uint_8 index,status = USB_OK; USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID); #ifndef COMPOSITE_DEV /* Initialize the device layer*/ status = _usb_device_init(controller_ID, NULL, (uint_8)(usb_ep_data->count+1), bVregEn); /* +1 is for Control Endpoint */ if(status == USB_OK) { /* Initialize the generic class functions */ status = USB_Class_Init(controller_ID,USB_Class_CDC_Event, USB_Other_Requests); #endif #if IMPLEMENT_QUEUING for(index = 0; index < usb_ep_data->count; index++) { g_cdc_ep[index].endpoint = usb_ep_data->ep[index].ep_num; g_cdc_ep[index].type = usb_ep_data->ep[index].type; g_cdc_ep[index].bin_consumer = 0x00; g_cdc_ep[index].bin_producer = 0x00; } #endif #if PSTN_SUBCLASS_NOTIF_SUPPORT /* Initialize the pstn subclass functions */ status = USB_Class_CDC_Pstn_Init(controller_ID,pstn_callback); #endif if(status == USB_OK) { /* save the callback pointer */ g_cdc_class_callback = cdc_class_callback; /* save the callback pointer */ g_vendor_req_callback = vendor_req_callback; } #ifndef COMPOSITE_DEV } #endif return status; }
/* ** =================================================================== ** Method : USB_Class_Mems_Init (component USB_MEMS_CLASS) ** Description : ** The funtion initializes the Device and Controller layer ** Parameters : ** NAME - DESCRIPTION ** controller_ID - ** mems_class_callback - ** vendor_req_callback - ** param_callback - ** Returns : ** --- - Error code ** =================================================================== */ uint_8 USB_Class_Mems_Init( uint_8 controller_ID, USB_CLASS_CALLBACK mems_class_callback, USB_REQ_FUNC vendor_req_callback, USB_CLASS_CALLBACK param_callback ) { uint_8 index; USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *) USB_Desc_Get_Endpoints(controller_ID); /* Initialize the device layer*/ uint_8 status = _usb_device_init(controller_ID, NULL, (uint_8)(ep_desc_data->count+1)); if(status == USB_OK) { /* Initialize the generic class functions */ status = USB_Class_Init(controller_ID,USB_Class_Mems_Event, USB_Other_Requests); if(status == USB_OK) { g_mems_endpoint_data.count = ep_desc_data->count; for(index = 0; index < ep_desc_data->count; index++) { g_mems_endpoint_data.ep[index].endpoint = ep_desc_data->ep[index].ep_num; g_mems_endpoint_data.ep[index].type = ep_desc_data->ep[index].type; 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; } /* save the Mems class callback pointer */ g_mems_class_callback = mems_class_callback; /* save the vendor request callback pointer */ g_vendor_req_callback = vendor_req_callback; /* Save the callback to ask application for class specific params*/ g_param_callback = param_callback; } } return status; }
/**************************************************************************//*! * * @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; }
/**************************************************************************//*! * * @name USB_Class_CDC_Init * * @brief The funtion initializes the Device and Controller layer * * @param *cdc_config_ptr[IN]: This structure contians configuration parameter * send by APP to configure CDC class. * * @return status * USB_OK : When Successfull * Others : Errors ****************************************************************************** * *This function initializes the CDC Class layer and layers it is dependednt on * *****************************************************************************/ uint_32 USB_Class_CDC_Init ( CDC_CONFIG_STRUCT_PTR cdc_config_ptr ) { #if IMPLEMENT_QUEUING uint_8 index; #endif uint_8 error; CDC_HANDLE cdc_handle; CDC_DEVICE_STRUCT_PTR devicePtr = NULL; USB_ENDPOINTS *usb_ep_data; if (NULL == (void *)cdc_config_ptr) return USBERR_ERROR; devicePtr = (CDC_DEVICE_STRUCT_PTR)USB_mem_alloc_zero(sizeof(CDC_DEVICE_STRUCT)); if (NULL == devicePtr) { #if _DEBUG printf("memalloc failed in USB_Class_CDC_Init\n"); #endif return USBERR_ALLOC; } cdc_handle = USB_Cdc_Allocate_Handle(); if (USBERR_DEVICE_BUSY == cdc_handle) { USB_mem_free(devicePtr); devicePtr = NULL; return USBERR_INIT_FAILED; } /* initialize the Global Variable Structure */ USB_mem_zero(devicePtr, sizeof(CDC_DEVICE_STRUCT)); devicePtr->ep = cdc_config_ptr->ep; usb_ep_data = cdc_config_ptr->usb_ep_data; devicePtr->max_supported_interfaces = cdc_config_ptr->max_supported_interfaces; #if RNDIS_SUPPORT USB_mem_copy(cdc_config_ptr->mac_address, devicePtr->mac_address, sizeof(_enet_address)); devicePtr->ip_address = cdc_config_ptr->ip_address; devicePtr->rndis_max_frame_size = cdc_config_ptr->rndis_max_frame_size; #endif /* Initialize the device layer*/ error = _usb_device_init(USBCFG_DEFAULT_DEVICE_CONTROLLER, &devicePtr->controller_handle, (uint_8)(usb_ep_data->count+1)); /* +1 is for Control Endpoint */ if(error != USB_OK) { goto error1; } cdc_config_ptr->desc_callback_ptr->handle = cdc_handle; /* Initialize the generic class functions */ devicePtr->class_handle = USB_Class_Init(devicePtr->controller_handle, USB_Class_CDC_Event,USB_CDC_Other_Requests,(void *)devicePtr, cdc_config_ptr->desc_callback_ptr); /* Initialize the generic class functions */ #if PSTN_SUBCLASS_NOTIF_SUPPORT /* Initialize the pstn subclass functions */ error = USB_Pstn_Init(devicePtr,&cdc_config_ptr->param_callback); if(error != USB_OK) { goto error2; } #endif devicePtr->usb_ep_data = usb_ep_data; #if IMPLEMENT_QUEUING for(index = 0; index < usb_ep_data->count; index++) { devicePtr->ep[index].endpoint = usb_ep_data->ep[index].ep_num; devicePtr->ep[index].type = usb_ep_data->ep[index].type; devicePtr->ep[index].bin_consumer = 0x00; devicePtr->ep[index].bin_producer = 0x00; } #endif /* save the callback pointer */ devicePtr->cdc_class_cb.callback = cdc_config_ptr->cdc_class_cb.callback; devicePtr->cdc_class_cb.arg = cdc_config_ptr->cdc_class_cb.arg; /* save the callback pointer */ devicePtr->vendor_req_callback.callback = cdc_config_ptr->vendor_req_callback.callback; devicePtr->vendor_req_callback.arg = cdc_config_ptr->vendor_req_callback.arg; /* save the callback pointer */ devicePtr->param_callback.callback = cdc_config_ptr->param_callback.callback; devicePtr->param_callback.arg = cdc_config_ptr->param_callback.arg; devicePtr->comm_feature_data_size = cdc_config_ptr->comm_feature_data_size; devicePtr->cic_send_endpoint = cdc_config_ptr->cic_send_endpoint; devicePtr->cic_recv_endpoint = USB_CONTROL_ENDPOINT; devicePtr->dic_send_endpoint = cdc_config_ptr->dic_send_endpoint; devicePtr->dic_recv_endpoint = cdc_config_ptr->dic_recv_endpoint; devicePtr->dic_recv_pkt_size = cdc_config_ptr->dic_recv_pkt_size; devicePtr->dic_send_pkt_size = cdc_config_ptr->dic_send_pkt_size; devicePtr->cic_send_pkt_size = cdc_config_ptr->cic_send_pkt_size; devicePtr->cdc_handle = cdc_handle; cdc_device_array[cdc_handle] = devicePtr; return cdc_handle; error2: /* Implement Denit class and invoke here*/ error1: USB_Cdc_Free_Handle(cdc_handle); USB_mem_free(devicePtr); devicePtr = NULL; return error; }