Esempio n. 1
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_class_hub_deinit
* Returned Value : None
* Comments       :
*     This function is called by common class to deinitialize the class driver. It
*     is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
usb_status usb_class_hub_deinit
    (
        /* [IN]  the class driver handle */
        class_handle      handle
     )
{
    usb_hub_class_struct_t*      hub_class = (usb_hub_class_struct_t*)handle;
    usb_status                    status = USB_OK;
    if (hub_class == NULL)
    {
        USB_PRINTF("usb_class_hid_deinit fail\n");
        return USBERR_ERROR;
    }
    
    if (hub_class->interrupt_pipe != NULL)
    {
        status = usb_host_close_pipe(hub_class->host_handle, hub_class->interrupt_pipe);
        if (status != USB_OK)
        {
            USB_PRINTF("error in usb_class_hid_deinit to close pipe\n");
        }
    }
    
    OS_Mem_free(handle);
    //USB_PRINTF("HID class driver de-initialized\n");
    return USB_OK;
} /* Endbody */
Esempio n. 2
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_class_video_control_deinit
* Returned Value : None
* Comments       :
*     This function is called by common class to initialize the class driver. It
*     is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
usb_status usb_class_video_control_deinit
(
    /* [IN]  the class driver handle */
    class_handle      handle
)
{
    usb_video_control_struct_t*      video_control_ptr = (usb_video_control_struct_t*)handle;
    usb_status                    status = USB_OK;
    if (video_control_ptr == NULL)
    {
#ifdef _DEBUG
        USB_PRINTF("usb_class_video_control_deinit fail\n");
#endif
        return USBERR_ERROR;
    }

    if (video_control_ptr->control_interrupt_in_pipe != NULL)
    {
        status = usb_host_close_pipe(video_control_ptr->host_handle, video_control_ptr->control_interrupt_in_pipe);
        if (status != USB_OK)
        {
#ifdef _DEBUG
            USB_PRINTF("error in usb_class_video_control_deinit to close pipe\n");
#endif
        }
    }
    
    OS_Mem_free(handle);
    //USB_PRINTF("Video class driver de-initialized\n");
    return USB_OK;
} /* Endbody */
Esempio n. 3
0
usb_status usb_class_cdc_acm_deinit
   (
      /* [IN] acm call struct pointer */
	  class_handle		handle
   )
{
    usb_acm_class_intf_struct_t * acm_class_intf = (usb_acm_class_intf_struct_t *)handle;
    usb_status                    status = USB_OK;

    if (acm_class_intf == NULL)
    {
        printf("usb_class_cdc_acm_deinit fail\n");
        return USBERR_ERROR;
    }
    
    if (acm_class_intf->interrupt_pipe != NULL)
    {
        status = usb_host_close_pipe(acm_class_intf->host_handle, acm_class_intf->interrupt_pipe);
        if (status != USB_OK)
        {
            printf("error in usb_class_cdc_acm_deinit to close pipe\n");
        }
    }
    
    if (acm_class_intf->acm_event != NULL) {
        OS_Event_set(acm_class_intf->acm_event, USB_ACM_DETACH); /* mark we are not using input pipe */
    }
    
	OS_Mutex_destroy(acm_class_intf->mutex);
    OS_Mem_free(handle);
    return USB_OK;
    /* destroying lwevent is up to application */
}
Esempio n. 4
0
usb_status usb_class_cdc_data_deinit
   (
      /* [IN] data call struct pointer */
	  class_handle		handle
   )
{
    usb_data_class_intf_struct_t * data_class_intf = (usb_data_class_intf_struct_t *)handle;
    usb_status                    status = USB_OK;
    if (data_class_intf == NULL)
    {
        printf("usb_class_cdc_data_deinit fail\n");
        return USBERR_ERROR;
    }
    
    if (data_class_intf->in_pipe != NULL)
    {
        status = usb_host_close_pipe(data_class_intf->host_handle, data_class_intf->in_pipe);
        if (status != USB_OK)
        {
            printf("error in usb_class_cdc_data_deinit to close pipe\n");
        }
    }
    if (data_class_intf->out_pipe != NULL)
    {
        status = usb_host_close_pipe(data_class_intf->host_handle, data_class_intf->out_pipe);
        if (status != USB_OK)
        {
            printf("error in usb_class_cdc_data_deinit to close pipe\n");
        }
    }
    
    if ((data_class_intf->in_pipe != NULL) && (data_class_intf->data_event != NULL))
        OS_Event_set(data_class_intf->data_event, USB_DATA_DETACH); /* mark we are not using input pipe */

    if (data_class_intf->rx_buffer != NULL) {
        OS_Mem_free(data_class_intf->rx_buffer);
    }
	OS_Mutex_destroy(data_class_intf->mutex);
    OS_Mem_free(handle);
    return status;

    /* destroying lwevent is up to application */
} /* Endbody */
Esempio n. 5
0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : usb_host_dev_mng_pre_detach
* Returned Value : 
* Comments       :
*     This function will be called when detach interrupt happens.
* 
*END*--------------------------------------------------------------------*/
usb_status  usb_host_dev_mng_pre_detach
(
    usb_host_handle    handle,
    uint8_t            hub_no,
    uint8_t            port_no
)
{ /* Body */
    usb_host_state_struct_t*            usb_host_ptr = (usb_host_state_struct_t*)handle;
    dev_instance_t*                     dev_instance_ptr;
    uint8_t                              interface_index;
    interface_descriptor_t*             intf = NULL;
    usb_device_interface_info_struct_t* lpinterface_info = NULL;
    class_map_t*                        class_map;

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

    /* search device list for the one being detached */
    USB_Host_lock();
    dev_instance_ptr = (dev_instance_t*)usb_host_dev_get_instance(handle, hub_no, port_no, (uint8_t)0);
    
    if (dev_instance_ptr == NULL)
    {
    #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("usb_host_dev_mng_pre_detach NULL device pointer");
    #endif
        USB_Host_unlock();
        return  USBERR_ERROR; /* No match, abandon ship! */
    }

    if (dev_instance_ptr->pre_detached == (uint8_t)TRUE)
    {
        USB_Host_unlock();
        return  USB_OK;
    }

    if (NULL != dev_instance_ptr->control_pipe)
    {
        /* Close control pipe */
        usb_host_cancel(handle, (pipe_struct_t*)dev_instance_ptr->control_pipe, (tr_struct_t*)NULL);
    }

    for (interface_index = 0; interface_index < dev_instance_ptr->configuration.interface_count; interface_index++)
    {
        intf = dev_instance_ptr->configuration.interface[interface_index].lpinterfaceDesc;
        lpinterface_info = usb_host_dev_mng_get_interface_info(dev_instance_ptr, intf);
        if (lpinterface_info == NULL)
        {
            continue;
        }

        class_map = lpinterface_info->lpClassDriverMap;
        if (class_map != NULL)
        {
            class_map->class_pre_deinit(lpinterface_info->lpClassHandle);
        }
    }
    dev_instance_ptr->pre_detached = (uint8_t)TRUE;

    USB_Host_unlock();
    if (dev_instance_ptr->state <= DEVSTATE_SET_CFG)
    {
        if (dev_instance_ptr->control_pipe != NULL)
        {
            usb_host_close_pipe(dev_instance_ptr->host, dev_instance_ptr->control_pipe);
            dev_instance_ptr->control_pipe = NULL;
        }
        if (dev_instance_ptr->lpConfiguration != NULL)
        {
            OS_Mem_free(dev_instance_ptr->lpConfiguration);
            dev_instance_ptr->lpConfiguration = NULL;
        }
    }
#ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_host_dev_mng_pre_detach SUCCESSFUL");
#endif

    return USB_OK;
} /* EndBody */
Esempio n. 6
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_class_video_set_stream_inf
* Returned Value : None
* Comments       :
*     This function is called by common class to initialize the class driver. It
*     is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
usb_status usb_class_video_set_stream_inf
(
    class_handle                    class_handle,
    uint8_t                          inf_alternate
)
{ /* Body */
    usb_video_stream_struct_t*      video_stream_ptr = NULL;
    endpoint_descriptor_t*          ep_desc = NULL;
    uint8_t                         ep_num = 0;
    pipe_init_struct_t              pipe_init;
    usb_status                      status;
    
    video_stream_ptr = (usb_video_stream_struct_t*)class_handle;
    if (video_stream_ptr == NULL)
    {
        return USBERR_ERROR;
    }

    if(video_stream_ptr->current_stream_interface_ptr->bAlternateSetting == inf_alternate)
    {
        return USBERR_ERROR;
    }

    if(video_stream_ptr->stream_interface_ptr->alternate_setting_num < inf_alternate)
    {
        return USBERR_ERROR;
    }

    if (video_stream_ptr->stream_iso_in_pipe != NULL)
    {
        usb_host_cancel(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_in_pipe, NULL);
        usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_in_pipe);
    }
    if (video_stream_ptr->stream_iso_out_pipe != NULL)
    {
        usb_host_cancel(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_out_pipe, NULL);
        usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_out_pipe);
    }
    if (video_stream_ptr->stream_bulk_in_pipe != NULL)
    {
        usb_host_cancel(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_in_pipe, NULL);
        usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_in_pipe);
    }
    if (video_stream_ptr->stream_bulk_out_pipe != NULL)
    {
        usb_host_cancel(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_out_pipe, NULL);
        usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_out_pipe);
    }
    usb_class_video_fill_endpoint_descriptor(video_stream_ptr, inf_alternate);

    for (ep_num = 0; ep_num < video_stream_ptr->altrnate_if_ep_num; ep_num++)
    {
        ep_desc = video_stream_ptr->altrnate_if_ep_descriptor_list[ep_num].lpEndpointDesc;
        if ((ep_desc->bEndpointAddress & IN_ENDPOINT) && ((ep_desc->bmAttributes & EP_TYPE_MASK) == ISOCH_ENDPOINT))
        {
            pipe_init.endpoint_number  = (ep_desc->bEndpointAddress & ENDPOINT_MASK);
            pipe_init.direction        = USB_RECV;
            pipe_init.pipetype         = USB_ISOCHRONOUS_PIPE;
            pipe_init.max_packet_size  = (uint16_t)(USB_SHORT_UNALIGNED_LE_TO_HOST(ep_desc->wMaxPacketSize) & PACKET_SIZE_MASK);
            pipe_init.interval         = ep_desc->iInterval;
            pipe_init.flags            = 0;
            pipe_init.dev_instance     = video_stream_ptr->dev_handle;
            pipe_init.nak_count        = USBCFG_HOST_DEFAULT_MAX_NAK_COUNT;
            status = usb_host_open_pipe(video_stream_ptr->host_handle, &video_stream_ptr->stream_iso_in_pipe, &pipe_init);
            if (status != USB_OK)
            {
#ifdef _DEBUG
                USB_PRINTF("usb_class_video_set_stream_inf fail to open in pipe\n");
#endif
                return USBERR_ERROR;
            }
        }
        else if ((ep_desc->bEndpointAddress & OUT_ENDPOINT) && ((ep_desc->bmAttributes & EP_TYPE_MASK) == ISOCH_ENDPOINT))
        {
            pipe_init.endpoint_number  = (ep_desc->bEndpointAddress & ENDPOINT_MASK);
            pipe_init.direction        = USB_SEND;
            pipe_init.pipetype         = USB_ISOCHRONOUS_PIPE;
            pipe_init.max_packet_size  = (uint16_t)(USB_SHORT_UNALIGNED_LE_TO_HOST(ep_desc->wMaxPacketSize) & PACKET_SIZE_MASK);
            pipe_init.interval         = ep_desc->iInterval;
            pipe_init.flags            = 0;
            pipe_init.dev_instance     = video_stream_ptr->dev_handle;
            pipe_init.nak_count        = USBCFG_HOST_DEFAULT_MAX_NAK_COUNT;
            status = usb_host_open_pipe(video_stream_ptr->host_handle, &video_stream_ptr->stream_iso_out_pipe, &pipe_init);
            if (status != USB_OK)
            {
#ifdef _DEBUG
                USB_PRINTF("usb_class_video_set_stream_inf fail to open in pipe\n");
#endif
                return USBERR_ERROR;
            }
        }
    }
    //USB_PRINTF("usb_class_video_set_stream_inf\n");
    
    return USB_OK;
   
} /* Endbody */
Esempio n. 7
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_class_video_stream_deinit
* Returned Value : None
* Comments       :
*     This function is called by common class to initialize the class driver. It
*     is called in response to a select interface call by application
*
*END*--------------------------------------------------------------------*/
usb_status usb_class_video_stream_deinit
(
    /* [IN]  the class driver handle */
    class_handle      handle
)
{
    usb_video_stream_struct_t*      video_stream_ptr = (usb_video_stream_struct_t*)handle;
    usb_status                    status = USB_OK;
    if (video_stream_ptr == NULL)
    {
#ifdef _DEBUG
        USB_PRINTF("usb_class_video_stream_deinit fail\n");
#endif
        return USBERR_ERROR;
    }

    if (video_stream_ptr->stream_iso_in_pipe != NULL)
    {
        status = usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_in_pipe);
        if (status != USB_OK)
        {
#ifdef _DEBUG
            USB_PRINTF("error in usb_class_video_stream_deinit to close pipe\n");
#endif
        }
    }
    if (video_stream_ptr->stream_iso_out_pipe != NULL)
    {
        status = usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_iso_out_pipe);
        if (status != USB_OK)
        {
#ifdef _DEBUG
            USB_PRINTF("error in usb_class_video_stream_deinit to close pipe\n");
#endif
        }
    }
    if (video_stream_ptr->stream_bulk_in_pipe != NULL)
    {
        status = usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_in_pipe);
        if (status != USB_OK)
        {
#ifdef _DEBUG
            USB_PRINTF("error in usb_class_video_stream_deinit to close pipe\n");
#endif
        }
    }
    if (video_stream_ptr->stream_bulk_out_pipe != NULL)
    {
        status = usb_host_close_pipe(video_stream_ptr->host_handle, video_stream_ptr->stream_bulk_out_pipe);
        if (status != USB_OK)
        {
#ifdef _DEBUG
            USB_PRINTF("error in usb_class_video_stream_deinit to close pipe\n");
#endif
        }
    }
    OS_Mem_free(video_stream_ptr->altrnate_if_ep_descriptor_list);
    OS_Mem_free(handle);
    //USB_PRINTF("Video class driver de-initialized\n");
    return USB_OK;
} /* Endbody */