int board_tsc_setup(int minor) { static bool initialized = false; int ret; idbg("minor %d\n", minor); DEBUGASSERT(minor == 0); /* Have we already initialized? Since we never uninitialize we must prevent * multiple initializations. This is necessary, for example, when the * touchscreen example is used as a built-in application in NSH and can be * called numerous time. It will attempt to initialize each time. */ if (!initialized) { /* Initialize and register the USB HID mouse device class */ ret = usbhost_mouse_init(); if (ret < 0) { idbg("Failed to register USB HID mouse device class\n"); return -ENODEV; } /* Now we are initialized */ initialized = true; } return OK; }
int stm32l4_usbhost_initialize(void) { int pid; #if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \ defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE) int ret; #endif /* First, register all of the class drivers needed to support the drivers * that we care about: */ uvdbg("Register class drivers\n"); #ifdef CONFIG_USBHOST_HUB /* Initialize USB hub class support */ ret = usbhost_hub_initialize(); if (ret < 0) { udbg("ERROR: usbhost_hub_initialize failed: %d\n", ret); } #endif #ifdef CONFIG_USBHOST_MSC /* Register the USB mass storage class class */ ret = usbhost_msc_initialize(); if (ret != OK) { udbg("ERROR: Failed to register the mass storage class: %d\n", ret); } #endif #ifdef CONFIG_USBHOST_CDCACM /* Register the CDC/ACM serial class */ ret = usbhost_cdcacm_initialize(); if (ret != OK) { udbg("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret); } #endif #ifdef CONFIG_USBHOST_HIDKBD /* Initialize the HID keyboard class */ ret = usbhost_kbdinit(); if (ret != OK) { udbg("Failed to register the HID keyboard class\n"); } #endif #ifdef CONFIG_USBHOST_HIDMOUSE /* Initialize the HID mouse class */ ret = usbhost_mouse_init(); if (ret != OK) { udbg("Failed to register the HID mouse class\n"); } #endif /* Then get an instance of the USB host interface */ uvdbg("Initialize USB host\n"); g_usbconn = stm32l4_otgfshost_initialize(0); if (g_usbconn) { /* Start a thread to handle device connection. */ uvdbg("Start usbhost_waiter\n"); pid = task_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO, CONFIG_STM32L4DISCO_USBHOST_STACKSIZE, (main_t)usbhost_waiter, (FAR char * const *)NULL); return pid < 0 ? -ENOEXEC : OK; } return -ENODEV; }
int stm32_usbhost_initialize(void) { int rv; #ifdef CONFIG_USBHOST_MSC uinfo("INFO: Initializing USB MSC class\n"); if ((rv = usbhost_msc_initialize()) < 0) { uerr("ERROR: Failed to register mass storage class: %d\n", rv); } #endif #ifdef CONFIG_USBHOST_CDACM uinfo("INFO: Initializing CDCACM usb class\n"); if ((rv = usbhost_cdacm_initialize()) < 0) { uerr("ERROR: Failed to register CDC/ACM serial class: %d\n", rv); } #endif #ifdef CONFIG_USBHOST_HIDKBD uinfo("INFO: Initializing HID Keyboard usb class\n"); if ((rv = usbhost_kbdinit()) < 0) { uerr("ERROR: Failed to register the KBD class: %d\n", rv); } #endif #ifdef CONFIG_USBHOST_HIDMOUSE uinfo("INFO: Initializing HID Mouse usb class\n"); if ((rv = usbhost_mouse_init()) < 0) { uerr("ERROR: Failed to register the mouse class: %d\n", rv); } #endif #ifdef CONFIG_USBHOST_HUB uinfo("INFO: Initializing USB HUB class\n"); if ((rv = usbhost_hub_initialize()) < 0) { uerr("ERROR: Failed to register hub class: %d\n", rv); } #endif if ((g_usbconn = stm32_otgfshost_initialize(0))) { pthread_attr_t pattr; struct sched_param schparam; pthread_attr_init(&pattr); pthread_attr_setstacksize(&pattr, 2048); schparam.sched_priority = 50; pthread_attr_setschedparam(&pattr, &schparam); return pthread_create(NULL, &pattr, usbhost_detect, NULL); } return -ENODEV; }