usb_descr.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // -----------------------------------------------------------------------------
  2. // USB Library "usblib"
  3. // Target: for lpc17xx
  4. // Author: Sychov A.
  5. // Date: 12/10/2018
  6. // Version: 1.0
  7. // -----------------------------------------------------------------------------
  8. // File: USB-descriptors utility functions header
  9. // Version: 1.0
  10. // -----------------------------------------------------------------------------
  11. #ifndef __USB_DESC_STRUCTS_H__
  12. #define __USB_DESC_STRUCTS_H__
  13. #if !defined(__USER_USB_HEADER__) && !defined(__CORE_USB_HEADER__) && !defined(_USB_DESCR_C_)
  14. #warning Do not include 'usb_descr.h' header directly. The 'usb.h' should be used instead.
  15. #endif
  16. #include <string.h> // NULL
  17. #include "uboot/usb_config.h"
  18. #include "uboot/usb_spec.h"
  19. #include "uboot/usb_transfers.h"
  20. typedef struct
  21. {
  22. sUSBTransfer_t * pTransfer; // user-defined user-created transfer object
  23. void * pBuf; // user-created buffer for transfer object, size = EP-size
  24. }
  25. sUsrUsbEndpointService_t;
  26. // User Usb Endpoint Descriptor
  27. typedef struct
  28. {
  29. const sUSBEndpointDescriptor_t * pUsbEpDesc;
  30. #if USB_WRAP_ENDPOINTS > 0
  31. const sUsrUsbEndpointService_t * pUsbEpSvc;
  32. #else
  33. const void * pUsbEpSvc;
  34. #endif
  35. }
  36. sUsrUsbEndpoint_t;
  37. // User Usb Interface Descriptor
  38. typedef struct
  39. {
  40. const sUSBInterfaceDescriptor_t * pUsbIntDesc; // pointer to USB INTERFACE DESCRIPTOR
  41. const sUsrUsbEndpoint_t * pUsbEpDescList; // pointer to USB ENDPOINT DESCRIPTORs list
  42. }
  43. sUsrUsbInterface_t;
  44. // User Usb Configuration Descriptor
  45. typedef struct
  46. {
  47. const sUSBConfigurationDescriptor_t * pUsbConfDesc; // pointer to USB CONFIGURATION DESCRIPTOR
  48. const sUsrUsbInterface_t * pUsbIntDescList; // pointer to User Usb Interface list
  49. }
  50. sUsrUsbConfiguration_t;
  51. // User Usb String
  52. typedef struct
  53. {
  54. const uint8_t * pUsbStrDesc; // pointer to USB STRING DESCRIPTOR
  55. uint16_t langId; // lang ID for this string descriptor
  56. }
  57. sUsrUsbString_t;
  58. // User Usb Device Descriptor
  59. typedef struct
  60. {
  61. const sUSBDeviceDescriptor_t * pUsbDevDesc; // pointer to sUSBDeviceDescriptor_t
  62. const sUsrUsbConfiguration_t * pUsrUsbConfigList; // pointer to User Usb Configuration list
  63. const sUsrUsbString_t * pUsrUsbStringList; // pointer to User Usb Strings list
  64. }
  65. sUsrUsbDevice_t;
  66. extern const sUsrUsbDevice_t UserUsbDevice_Default;
  67. // usb_search_interface()
  68. // Searches specified interface in the specified configuration
  69. // @conf - the configuration to search in
  70. // @bInterfaceNumber - interface number to search
  71. // @altSetting - alternate setting value to match to
  72. // Returns the interface pointer if found, and NULL otherwise
  73. const sUsrUsbConfiguration_t * usb_search_configuration( const sUsrUsbDevice_t * pUserUsbDevice, uint8_t bConfigurationValue );
  74. // usb_search_configuration_byIndex()
  75. // Retireves the configuration by specified index
  76. // @pUserUsbDevice - full device configuration set
  77. // @index - configuration index
  78. // Returns the configuration pointer if found, and NULL otherwise
  79. const sUsrUsbConfiguration_t * usb_search_configuration_byIndex( const sUsrUsbDevice_t * pUserUsbDevice, size_t index );
  80. // usb_search_interface()
  81. // Searches specified interface in the specified configuration
  82. // @conf - the configuration to search in
  83. // @bInterfaceNumber - interface number to search
  84. // @altSetting - alternate setting value to match to
  85. // Returns the interface pointer if found, and NULL otherwise
  86. const sUsrUsbInterface_t * usb_search_interface( const sUsrUsbConfiguration_t * conf, uint8_t bInterfaceNumber, uint8_t altSetting );
  87. // usb_search_interface()
  88. // Searches specified string in the string descriptors list
  89. // @pUserUsbDevice - full device configuration set
  90. // @iString - string index
  91. // @lang - string language ID
  92. // Returns the string descriptor pointer if found, and NULL otherwise
  93. const sUsrUsbString_t * usb_search_string( const sUsrUsbDevice_t * pUserUsbDevice, size_t iString, uint16_t lang );
  94. #endif