//------------------------------------------------------------------------ // Open() // // dwDevice : position of device description string in the registry // // Get the description strings for a device and copy the linkname into // m_DeviceName. Call OpenUSBfile() to create the file handle. //------------------------------------------------------------------------ HANDLE CUsbIF::Open(DWORD dwDevice) { CDeviceListEntry dev; GetDeviceStrings(dwDevice, dev); // first set the device by setting the devicename strcpy(m_DeviceName, dev.m_linkname.c_str()); // next get a handle and return it return OpenUSBfile(NULL); }
/**************************************************************************//** * @brief main - the entrypoint after reset. *****************************************************************************/ int main(void) { int connectionResult; USBH_Init_TypeDef is = USBH_INIT_DEFAULT; BSP_Init(BSP_INIT_DEFAULT); /* Initialize DK board register access */ /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); ConsoleDebugInit(); /* Initialize DK UART port. */ printf("\n\nEFM32 USB Host device enumeration example.\n"); USBH_Init(&is); /* Initialize USB HOST stack */ for (;;) { /* Wait for device connection */ printf("\nWaiting for USB device plug-in...\n"); /* Wait for maximum 10 seconds. */ connectionResult = USBH_WaitForDeviceConnectionB( tmpBuf, 10 ); if ( connectionResult == USB_STATUS_OK ) { printf("\nA device was attached...\n"); if (USBH_QueryDeviceB(tmpBuf, sizeof(tmpBuf), USBH_GetPortSpeed()) == USB_STATUS_OK) { USBH_InitDeviceData(&device, tmpBuf, NULL, 0, USBH_GetPortSpeed()); printf( "\nDevice VID/PID is 0x%04X/0x%04X, device bus speed is %s", device.devDesc.idVendor, device.devDesc.idProduct, USBH_GetPortSpeed() == PORT_FULL_SPEED ? "FULL" : "LOW" ); GetDeviceStrings(); } else { printf("\nDevice enumeration failure, please unplug device...\n"); } while ( USBH_DeviceConnected() ){} printf("\n\nDevice removal detected..."); } else if ( connectionResult == USB_STATUS_DEVICE_MALFUNCTION ) { printf("\nA malfunctioning device was attached, please remove...\n"); } else if ( connectionResult == USB_STATUS_PORT_OVERCURRENT ) { printf( "\nVBUS overcurrent condition, please remove device.\n" ); } else if ( connectionResult == USB_STATUS_TIMEOUT ) { printf("\nNo device was attached...\n"); } USBH_Stop(); } }