/* 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"); }
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"); }