usb_cdc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*!
  2. \file usb_cdc.h
  3. \brief the header file of communication device class standard
  4. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2023, 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 __USB_CDC_H
  30. #define __USB_CDC_H
  31. #include "usb_ch9_std.h"
  32. /* communications device class code */
  33. #define USB_CLASS_CDC 0x02U
  34. /* communications interface class control protocol codes */
  35. #define USB_CDC_PROTOCOL_NONE 0x00U
  36. #define USB_CDC_PROTOCOL_AT 0x01U
  37. #define USB_CDC_PROTOCOL_VENDOR 0xFFU
  38. /* data interface class code */
  39. #define USB_CLASS_DATA 0x0AU
  40. #define USB_DESCTYPE_CDC_ACM 0x21U
  41. #define USB_DESCTYPE_CS_INTERFACE 0x24U
  42. #define USB_CDC_ACM_CONFIG_DESC_SIZE 0x43U
  43. /* class-specific notification codes for pstn subclasses */
  44. #define USB_CDC_NOTIFY_SERIAL_STATE 0x20U
  45. /* class-specific request codes */
  46. #define SEND_ENCAPSULATED_COMMAND 0x00U
  47. #define GET_ENCAPSULATED_RESPONSE 0x01U
  48. #define SET_COMM_FEATURE 0x02U
  49. #define GET_COMM_FEATURE 0x03U
  50. #define CLEAR_COMM_FEATURE 0x04U
  51. #define SET_AUX_LINE_STATE 0x10U
  52. #define SET_HOOK_STATE 0x11U
  53. #define PULSE_SETUP 0x12U
  54. #define SEND_PULSE 0x13U
  55. #define SET_PULSE_TIME 0x14U
  56. #define RING_AUX_JACK 0x15U
  57. #define SET_LINE_CODING 0x20U
  58. #define GET_LINE_CODING 0x21U
  59. #define SET_CONTROL_LINE_STATE 0x22U
  60. #define SEND_BREAK 0x23U
  61. #define NO_CMD 0xFFU
  62. #define SET_RINGER_PARMS 0x30U
  63. #define GET_RINGER_PARMS 0x31U
  64. #define SET_OPERATION_PARMS 0x32U
  65. #define GET_OPERATION_PARMS 0x33U
  66. #define SET_LINE_PARMS 0x34U
  67. #define GET_LINE_PARMS 0x35U
  68. #define DIAL_DIGITS 0x36U
  69. #define SET_UNIT_PARAMETER 0x37U
  70. #define GET_UNIT_PARAMETER 0x38U
  71. #define CLEAR_UNIT_PARAMETER 0x39U
  72. #define GET_PROFILE 0x3AU
  73. #define SET_ETHERNET_MULTICAST_FILTERS 0x40U
  74. #define SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41U
  75. #define GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42U
  76. #define SET_ETHERNET_PACKET_FILTER 0x43U
  77. #define GET_ETHERNET_STATISTIC 0x44U
  78. #define SET_ATM_DATA_FORMAT 0x50U
  79. #define GET_ATM_DEVICE_STATISTICS 0x51U
  80. #define SET_ATM_DEFAULT_VC 0x52U
  81. #define GET_ATM_VC_STATISTICS 0x53U
  82. /* wValue for set control line state */
  83. #define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002U
  84. #define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000U
  85. #define CDC_ACTIVATE_SIGNAL_DTR 0x0001U
  86. #define CDC_DEACTIVATE_SIGNAL_DTR 0x0000U
  87. /* CDC subclass code */
  88. enum usb_cdc_subclass {
  89. USB_CDC_SUBCLASS_RESERVED = 0U, /*!< reserved */
  90. USB_CDC_SUBCLASS_DLCM, /*!< direct line control mode */
  91. USB_CDC_SUBCLASS_ACM, /*!< abstract control mode */
  92. USB_CDC_SUBCLASS_TCM, /*!< telephone control mode */
  93. USB_CDC_SUBCLASS_MCM, /*!< multichannel control model */
  94. USB_CDC_SUBCLASS_CCM, /*!< CAPI control model */
  95. USB_CDC_SUBCLASS_ENCM, /*!< ethernet networking control model */
  96. USB_CDC_SUBCLASS_ANCM /*!< ATM networking control model */
  97. };
  98. #pragma pack(1)
  99. /* cdc acm line coding structure */
  100. typedef struct {
  101. uint32_t dwDTERate; /*!< data terminal rate */
  102. uint8_t bCharFormat; /*!< stop bits */
  103. uint8_t bParityType; /*!< parity */
  104. uint8_t bDataBits; /*!< data bits */
  105. } acm_line;
  106. /* notification structure */
  107. typedef struct {
  108. uint8_t bmRequestType; /*!< type of request */
  109. uint8_t bNotification; /*!< communication interface class notifications */
  110. uint16_t wValue; /*!< value of notification */
  111. uint16_t wIndex; /*!< index of interface */
  112. uint16_t wLength; /*!< length of notification data */
  113. } acm_notification;
  114. typedef struct {
  115. usb_desc_header header; /*!< descriptor header, including type and size. */
  116. uint8_t bDescriptorSubtype; /*!< bDescriptorSubtype: header function descriptor */
  117. uint16_t bcdCDC; /*!< bcdCDC: low byte of spec release number (CDC1.10) */
  118. } usb_desc_header_func;
  119. typedef struct {
  120. usb_desc_header header; /*!< descriptor header, including type and size. */
  121. uint8_t bDescriptorSubtype; /*!< bDescriptorSubtype: call management function descriptor */
  122. uint8_t bmCapabilities; /*!< bmCapabilities: D0 is reset, D1 is ignored */
  123. uint8_t bDataInterface; /*!< bDataInterface: 1 interface used for call management */
  124. } usb_desc_call_managment_func;
  125. typedef struct {
  126. usb_desc_header header; /*!< descriptor header, including type and size. */
  127. uint8_t bDescriptorSubtype; /*!< bDescriptorSubtype: abstract control management descriptor */
  128. uint8_t bmCapabilities; /*!< bmCapabilities: D1 */
  129. } usb_desc_acm_func;
  130. typedef struct {
  131. usb_desc_header header; /*!< descriptor header, including type and size. */
  132. uint8_t bDescriptorSubtype; /*!< bDescriptorSubtype: union function descriptor */
  133. uint8_t bMasterInterface; /*!< bMasterInterface: communication class interface */
  134. uint8_t bSlaveInterface0; /*!< bSlaveInterface0: data class interface */
  135. } usb_desc_union_func;
  136. #pragma pack()
  137. typedef struct {
  138. usb_desc_config config;
  139. usb_desc_itf cmd_itf;
  140. usb_desc_header_func cdc_header;
  141. usb_desc_call_managment_func cdc_call_managment;
  142. usb_desc_acm_func cdc_acm;
  143. usb_desc_union_func cdc_union;
  144. usb_desc_ep cdc_cmd_endpoint;
  145. usb_desc_itf cdc_data_interface;
  146. usb_desc_ep cdc_out_endpoint;
  147. usb_desc_ep cdc_in_endpoint;
  148. } usb_cdc_desc_config_set;
  149. #endif /* __USB_CDC_H */