usb_device.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "usb_device.h"
  2. #include "usbd_core.h"
  3. #include "usbd_desc.h"
  4. #include "usbd_vendor.h"
  5. #include "usbd_usbtmc.h"
  6. /* USB Device Core handle declaration. */
  7. static USBD_HandleTypeDef hUsbDeviceFS;
  8. /**
  9. * Init USB device Library, add supported class and start the library
  10. * @retval None
  11. */
  12. void USB_Device_Init( eUSBDeviceInterface_t ifaceId )
  13. {
  14. // Init Device Library, add supported class and start the library
  15. // Only one interface can be registered at the same time!
  16. switch( ifaceId )
  17. {
  18. default:
  19. case eUSBIfaceVendor:
  20. USBD_Init(&hUsbDeviceFS, &USBD_COMMON_Desc, DEVICE_FS);
  21. USBD_RegisterClass(&hUsbDeviceFS, &USBD_VENDOR);
  22. USBD_COMMON_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_Vendor_UsbInterface);
  23. USBD_Start(&hUsbDeviceFS);
  24. break;
  25. #if CONFIG_USB_USBTMC_ENABLE
  26. case eUSBIfaceTMC:
  27. USBD_Init(&hUsbDeviceFS, &USBD_COMMON_Desc, DEVICE_FS);
  28. USBD_RegisterClass(&hUsbDeviceFS, &USBD_USBTMC);
  29. USBD_COMMON_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_Usbtmc_UsbInterface);
  30. USBD_Start(&hUsbDeviceFS);
  31. break;
  32. #endif
  33. }
  34. }
  35. void USB_Device_DeInit()
  36. {
  37. USBD_Stop( &hUsbDeviceFS );
  38. USBD_DeInit( &hUsbDeviceFS );
  39. }