usbd_enum.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. \file usbd_enum.h
  3. \brief USB enumeration definitions
  4. \version 2019-6-5, V1.0.0, firmware for GD32 USBFS&USBHS
  5. */
  6. /*
  7. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #ifndef __USBD_ENUM_H
  30. #define __USBD_ENUM_H
  31. #include "usbd_core.h"
  32. #include "usbd_conf.h"
  33. #include <wchar.h>
  34. #ifndef NULL
  35. #define NULL 0U
  36. #endif
  37. typedef enum _usb_reqsta {
  38. REQ_SUPP = 0x0U, /* request support */
  39. REQ_NOTSUPP = 0x1U /* request not support */
  40. } usb_reqsta;
  41. /* string descriptor index */
  42. enum _str_index {
  43. STR_IDX_LANGID = 0x0U, /* language ID string index */
  44. STR_IDX_MFC = 0x1U, /* manufacturer string index */
  45. STR_IDX_PRODUCT = 0x2U, /* product string index */
  46. STR_IDX_SERIAL = 0x3U, /* serial string index */
  47. STR_IDX_CONFIG = 0x4U, /* configuration string index */
  48. STR_IDX_ITF = 0x5U, /* interface string index */
  49. STR_IDX_MAX = 0x6U /* string maximum index */
  50. };
  51. typedef enum _usb_pwrsta {
  52. USB_PWRSTA_SELF_POWERED = 0x1U, /* USB is in self powered status */
  53. USB_PWRSTA_REMOTE_WAKEUP = 0x2U, /* USB is in remote wakeup status */
  54. } usb_pwrsta;
  55. typedef enum _usb_feature {
  56. USB_FEATURE_EP_HALT = 0x0U, /* USB has endpoint halt feature */
  57. USB_FEATURE_REMOTE_WAKEUP = 0x1U, /* USB has endpoint remote wakeup feature */
  58. USB_FEATURE_TEST_MODE = 0x2U /* USB has endpoint test mode feature */
  59. } usb_feature;
  60. #define ENG_LANGID 0x0409U /* english language ID */
  61. #define CHN_LANGID 0x0804U /* chinese language ID */
  62. /* USB device exported macros */
  63. #define CTL_EP(ep) (((ep) == 0x00U) || ((ep) == 0x80U))
  64. #define WIDE_STRING(string) _WIDE_STRING(string)
  65. #define _WIDE_STRING(string) L##string
  66. #define USBD_STRING_DESC(string) \
  67. (void *)&(const struct { \
  68. uint8_t _len; \
  69. uint8_t _type; \
  70. wchar_t _data[sizeof(string)]; \
  71. }) { \
  72. sizeof(WIDE_STRING(string)) + 2U - 2U, \
  73. USB_DESCTYPE_STR, \
  74. WIDE_STRING(string) \
  75. }
  76. /* function declarations */
  77. /* handle USB standard device request */
  78. usb_reqsta usbd_standard_request(usb_core_driver* udev, usb_req* req);
  79. /* handle USB device class request */
  80. usb_reqsta usbd_class_request(usb_core_driver* udev, usb_req* req);
  81. /* handle USB vendor request */
  82. usb_reqsta usbd_vendor_request(usb_core_driver* udev, usb_req* req);
  83. /* handle USB enumeration error */
  84. void usbd_enum_error(usb_core_driver* udev, usb_req* req);
  85. /* convert hex 32bits value into unicode char */
  86. void int_to_unicode(uint32_t value, uint8_t* pbuf, uint8_t len);
  87. #endif /* __USBD_ENUM_H */