Example #1
0
/* 
    usb_init
*/
void usb_init(void)
{
    
    usb_status           status = USB_OK;
    
    status = usb_host_init(CONTROLLER_ID, &g_video_camera.host_handle);
    if (status != USB_OK) 
    {
        USB_PRINTF("\r\nUSB Host Initialization failed! STATUS: 0x%x", status);
        return;
    }
    /*
     ** since we are going to act as the host driver, register the driver
     ** information for wanted class/subclass/protocols
     */
    status = usb_host_register_driver_info(g_video_camera.host_handle, (void *)DriverInfoTable);
    if (status != USB_OK) 
    {         
        USB_PRINTF("\r\nUSB Initialization driver info failed! STATUS: 0x%x", status);
          return;
    }

    status = usb_host_register_unsupported_device_notify(g_video_camera.host_handle, usb_host_video_unsupported_device_event);
    if (status != USB_OK) 
    {         
        USB_PRINTF("\r\nUSB Initialization driver info failed! STATUS: 0x%x", status);
          return;
    }
    
    g_video_camera.video_camera_control_event = OS_Event_create(0);/* manually clear */
    if (g_video_camera.video_camera_control_event == NULL)
    {
        USB_PRINTF("\r\nOS_Event_create failed!\r\n");
        return;
    }
    
    g_video_camera.video_camera_stream_event = OS_Event_create(0);/* manually clear */
    if (g_video_camera.video_camera_stream_event == NULL)
    {
        USB_PRINTF("\r\nOS_Event_create failed!\r\n");
        return;
    }
    g_video_camera.video_command_ptr = (video_command_t*)OS_Mem_alloc_zero(sizeof(video_command_t));
    if (g_video_camera.video_command_ptr == NULL)
    {
        USB_PRINTF("\r\nOS_Mem_alloc_zero failed!\r\n");
        return;
    }
    g_video_camera.stream_interface_alternate = 0;
   
    time_init();

    USB_PRINTF("Video camera starting...\r\n");
}
Example #2
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : OTG_App_Init
* Returned Value : none
* Comments       :
*
*
*END*--------------------------------------------------------------------*/
void OTG_App_Init()
{
    /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */
    OS_Lock();
    g_otg_handle  = NULL;
    g_otg_state = 0;
    g_dev_type = dev_b;
    g_sess_vld = FALSE;
    g_vbus_err = FALSE;

    g_otg_app_event_handle = OS_Event_create(0);
    printf("\n\r otg module is initilalizing:");
    _usb_otg_init(USBCFG_DEFAULT_OTG_CONTROLLER, (otg_int_struct_t *)&g_otg_init, &g_otg_handle);
    printf("\n\rPress P to print the menu:");
    OS_Unlock();
}
Example #3
0
/*FUNCTION*-------------------------------------------------------------------
 *
 * Function Name    : usb_otg_init
 * Returned Value   : initialization message
 * Comments         : Initializes OTG stack 
 *    
 *
 *END*----------------------------------------------------------------------*/
usb_status usb_otg_init
(
    /* [IN] the USB device controller to initialize */
    uint8_t controller_id,
    /*[IN] address of the OTG initialization  structure */
    otg_int_struct_t * init_struct_ptr,
    /* [IN] the USB otg board init handle */
    otg_board_init  board_init_callback,   
    /* [OUT] the USB host handle */
    usb_otg_handle * handle
)
{
    usb_status error = USB_OK;
    const usb_otg_api_functions_struct_t * otg_api = NULL;
    usb_otg_state_struct_t * usb_otg_ptr = NULL;
    if ((init_struct_ptr == NULL) || (handle == NULL))
    {
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("usb_otg_init invalid parameters");
#endif

        return USBERR_ERROR;
    }
    _usb_otg_get_api(controller_id, &otg_api);
    if (otg_api == NULL)
    {
        return USBERR_ERROR;
    }
    /* Initialize the USB interface. */
    if (otg_api->otg_preinit != NULL)
    {
        error = otg_api->otg_preinit((usb_otg_handle *) (&(usb_otg_ptr)));
        if (error || (usb_otg_ptr == NULL))
        {
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
            DEBUG_LOG_TRACE ("usb_OTG_init preinit failure");
#endif
            return USBERR_ALLOC;
        }
    }
    g_usb_otg_handle = usb_otg_ptr;
    usb_otg_ptr->otg_controller_api = otg_api; 
    if( NULL !=board_init_callback )
    {
        error = (uint32_t)board_init_callback(controller_id);
    }
    else
    {
        error = USB_OK;
    }
    if(USB_OK == error)
    {
        error = usb_otg_soc_init(controller_id);
    }
    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            error = otg_api->otg_shutdown(usb_otg_ptr);
        }
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("_usb_host_init: BSP-specific USB initialization failure");
#endif
        return USB_log_error(__FILE__, __LINE__, USBERR_UNKNOWN_ERROR);
    }

    usb_otg_ptr->init_struct = init_struct_ptr;
    /* initialize the event used for application signaling and for ISR*/
    usb_otg_ptr->otg_app_event = OS_Event_create(0);
    usb_otg_ptr->otg_isr_event = OS_Event_create(0);
    usb_otg_ptr->device_state = USB_OTG_DEVSTATE_UNDEFINED;
    usb_otg_ptr->sub_state = USB_OTG_SM_UNDEFINED;
    usb_otg_ptr->power_up = TRUE;

    if (otg_api->otg_init != NULL)
    {
        error = otg_api->otg_init(controller_id, usb_otg_ptr);
    }

    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            error = otg_api->otg_shutdown(usb_otg_ptr);
        }
#if ((defined _OTG_DEBUG_) && (_OTG_DEBUG))
        DEBUG_LOG_TRACE ("_usb_host_init: BSP-specific USB initialization failure");
#endif
        return USB_log_error(__FILE__, __LINE__, USBERR_UNKNOWN_ERROR);
    }

    error = _usb_otg_task_create(usb_otg_ptr);

    if (error != USB_OK)
    {
        if (otg_api->otg_shutdown != NULL)
        {
            otg_api->otg_shutdown(usb_otg_ptr);
        }
        (void) OS_Event_destroy(usb_otg_ptr->otg_app_event);
        (void) OS_Event_destroy(usb_otg_ptr->otg_isr_event);
        OS_Mem_free(usb_otg_ptr);
        usb_otg_ptr = NULL;

        OS_Unlock();
        return error;
    }
    *handle = (usb_otg_handle) usb_otg_ptr;
    return USB_OK;
}
Example #4
0
void APP_init(void)
{
    usb_status status = USB_OK;
    uint32_t opt = 0;

    status = usb_host_init(CONTROLLER_ID, usb_host_board_init, &g_host_handle);
    if (status != USB_OK)
    {
        USB_PRINTF("\r\nUSB Host Initialization failed! STATUS: 0x%x", status);
        return;
    }
    /*
     ** since we are going to act as the host driver, register the driver
     ** information for wanted class/subclass/protocols
     */
    status = usb_host_register_driver_info(g_host_handle, (void *) DriverInfoTable);
    if (status != USB_OK)
    {
        USB_PRINTF("\r\nUSB Initialization driver info failed! STATUS: 0x%x", status);
        return;
    }

    status = usb_host_register_unsupported_device_notify(g_host_handle, usb_host_hid_unsupported_device_event);
    if (status != USB_OK)
    {
        USB_PRINTF("\r\nUSB Initialization driver info failed! STATUS: 0x%x", status);
        return;
    }

    mouse_usb_event = OS_Event_create(0);/* manually clear */
    if (mouse_usb_event == NULL)
    {
        USB_PRINTF("mouse_usb_event create failed\r\n");
        return;
    }
    mouse_hid_com = (hid_command_t*) OS_Mem_alloc_zero(sizeof(hid_command_t));
    if (mouse_hid_com == NULL)
    {
        USB_PRINTF("mouse_hid_com create failed\r\n");
        return;
    }

    kbd_usb_event = OS_Event_create(0);/* manually clear */
    if (kbd_usb_event == NULL)
    {
        USB_PRINTF("kbd_usb_event create failed\r\n");
        return;
    }
    OS_Event_set(kbd_usb_event, USB_EVEN_INIT);
    kbd_hid_com = (hid_command_t*) OS_Mem_alloc_zero(sizeof(hid_command_t));
    if (kbd_hid_com == NULL)
    {
        USB_PRINTF("kbd_hid_com create failed\r\n");
        return;
    }

    if ((uint32_t) OS_TASK_ERROR == OS_Task_create(USB_KEYBOARD_TASK_ADDRESS, (void*) g_host_handle, (uint32_t) USB_KEYBOARD_TASK_PRIORITY, USB_KEYBOARD_TASK_STACKSIZE, USB_KEYBOARD_TASK_NAME, &opt))
    {
        USB_PRINTF("keyboard task create failed\r\n");
        return;
    }

    if ((uint32_t) OS_TASK_ERROR == OS_Task_create(USB_MOUSE_TASK_ADDRESS, (void*) g_host_handle, (uint32_t) USB_MOUSE_TASK_PRIORITY, USB_MOUSE_TASK_STACKSIZE, USB_MOUSE_TASK_NAME, &opt))
    {
        USB_PRINTF("mouse task create failed\r\n");
        return;
    }
    time_init();
    USB_PRINTF("\fUSB HID Mouse+Keyboard\r\nWaiting for USB Mouse or Keyboard to be attached...\r\n");
}