Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CDCClassCommon.h 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Common definitions and declarations for the library USB CDC Class driver.
  28. *
  29. * Common definitions and declarations for the library USB CDC Class driver.
  30. *
  31. * \note This file should not be included directly. It is automatically included as needed by the USB module driver
  32. * dispatch header located in LUFA/Drivers/USB.h.
  33. */
  34. /** \ingroup Group_USBClassCDC
  35. * \defgroup Group_USBClassCDCCommon Common Class Definitions
  36. *
  37. * \section Sec_USBClassCDCCommon_ModDescription Module Description
  38. * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
  39. * CDC Class.
  40. *
  41. * @{
  42. */
  43. #ifndef _CDC_CLASS_COMMON_H_
  44. #define _CDC_CLASS_COMMON_H_
  45. /* Includes: */
  46. #include "../../Core/StdDescriptors.h"
  47. /* Enable C linkage for C++ Compilers: */
  48. #if defined(__cplusplus)
  49. extern "C" {
  50. #endif
  51. /* Preprocessor Checks: */
  52. #if !defined(__INCLUDE_FROM_CDC_DRIVER)
  53. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  54. #endif
  55. /* Macros: */
  56. /** \name Virtual Control Line Masks */
  57. //@{
  58. /** Mask for the DTR handshake line for use with the \ref CDC_REQ_SetControlLineState class-specific request
  59. * from the host, to indicate that the DTR line state should be high.
  60. */
  61. #define CDC_CONTROL_LINE_OUT_DTR (1 << 0)
  62. /** Mask for the RTS handshake line for use with the \ref CDC_REQ_SetControlLineState class-specific request
  63. * from the host, to indicate that the RTS line state should be high.
  64. */
  65. #define CDC_CONTROL_LINE_OUT_RTS (1 << 1)
  66. /** Mask for the DCD handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
  67. * from the device to the host, to indicate that the DCD line state is currently high.
  68. */
  69. #define CDC_CONTROL_LINE_IN_DCD (1 << 0)
  70. /** Mask for the DSR handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
  71. * from the device to the host, to indicate that the DSR line state is currently high.
  72. */
  73. #define CDC_CONTROL_LINE_IN_DSR (1 << 1)
  74. /** Mask for the BREAK handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
  75. * from the device to the host, to indicate that the BREAK line state is currently high.
  76. */
  77. #define CDC_CONTROL_LINE_IN_BREAK (1 << 2)
  78. /** Mask for the RING handshake line for use with the \ref CDC_NOTIF_SerialState class-specific notification
  79. * from the device to the host, to indicate that the RING line state is currently high.
  80. */
  81. #define CDC_CONTROL_LINE_IN_RING (1 << 3)
  82. /** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
  83. * to indicate that a framing error has occurred on the virtual serial port.
  84. */
  85. #define CDC_CONTROL_LINE_IN_FRAMEERROR (1 << 4)
  86. /** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
  87. * to indicate that a parity error has occurred on the virtual serial port.
  88. */
  89. #define CDC_CONTROL_LINE_IN_PARITYERROR (1 << 5)
  90. /** Mask for use with the \ref CDC_NOTIF_SerialState class-specific notification from the device to the host,
  91. * to indicate that a data overrun error has occurred on the virtual serial port.
  92. */
  93. #define CDC_CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
  94. //@}
  95. /** Macro to define a CDC class-specific functional descriptor. CDC functional descriptors have a
  96. * uniform structure but variable sized data payloads, thus cannot be represented accurately by
  97. * a single \c typedef \c struct. A macro is used instead so that functional descriptors can be created
  98. * easily by specifying the size of the payload. This allows \c sizeof() to work correctly.
  99. *
  100. * \param[in] DataSize Size in bytes of the CDC functional descriptor's data payload.
  101. */
  102. #define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \
  103. struct \
  104. { \
  105. USB_Descriptor_Header_t Header; \
  106. uint8_t SubType; \
  107. uint8_t Data[DataSize]; \
  108. }
  109. /* Enums: */
  110. /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the CDC
  111. * device class.
  112. */
  113. enum CDC_Descriptor_ClassSubclassProtocol_t
  114. {
  115. CDC_CSCP_CDCClass = 0x02, /**< Descriptor Class value indicating that the device or interface
  116. * belongs to the CDC class.
  117. */
  118. CDC_CSCP_NoSpecificSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
  119. * belongs to no specific subclass of the CDC class.
  120. */
  121. CDC_CSCP_ACMSubclass = 0x02, /**< Descriptor Subclass value indicating that the device or interface
  122. * belongs to the Abstract Control Model CDC subclass.
  123. */
  124. CDC_CSCP_ATCommandProtocol = 0x01, /**< Descriptor Protocol value indicating that the device or interface
  125. * belongs to the AT Command protocol of the CDC class.
  126. */
  127. CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
  128. * belongs to no specific protocol of the CDC class.
  129. */
  130. CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device or interface
  131. * belongs to a vendor-specific protocol of the CDC class.
  132. */
  133. CDC_CSCP_CDCDataClass = 0x0A, /**< Descriptor Class value indicating that the device or interface
  134. * belongs to the CDC Data class.
  135. */
  136. CDC_CSCP_NoDataSubclass = 0x00, /**< Descriptor Subclass value indicating that the device or interface
  137. * belongs to no specific subclass of the CDC data class.
  138. */
  139. CDC_CSCP_NoDataProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface
  140. * belongs to no specific protocol of the CDC data class.
  141. */
  142. };
  143. /** Enum for the CDC class specific control requests that can be issued by the USB bus host. */
  144. enum CDC_ClassRequests_t
  145. {
  146. CDC_REQ_SendEncapsulatedCommand = 0x00, /**< CDC class-specific request to send an encapsulated command to the device. */
  147. CDC_REQ_GetEncapsulatedResponse = 0x01, /**< CDC class-specific request to retrieve an encapsulated command response from the device. */
  148. CDC_REQ_SetLineEncoding = 0x20, /**< CDC class-specific request to set the current virtual serial port configuration settings. */
  149. CDC_REQ_GetLineEncoding = 0x21, /**< CDC class-specific request to get the current virtual serial port configuration settings. */
  150. CDC_REQ_SetControlLineState = 0x22, /**< CDC class-specific request to set the current virtual serial port handshake line states. */
  151. CDC_REQ_SendBreak = 0x23, /**< CDC class-specific request to send a break to the receiver via the carrier channel. */
  152. };
  153. /** Enum for the CDC class specific notification requests that can be issued by a CDC device to a host. */
  154. enum CDC_ClassNotifications_t
  155. {
  156. CDC_NOTIF_SerialState = 0x20, /**< Notification type constant for a change in the virtual serial port
  157. * handshake line states, for use with a \ref USB_Request_Header_t
  158. * notification structure when sent to the host via the CDC notification
  159. * endpoint.
  160. */
  161. };
  162. /** Enum for the CDC class specific interface descriptor subtypes. */
  163. enum CDC_DescriptorSubtypes_t
  164. {
  165. CDC_DSUBTYPE_CSInterface_Header = 0x00, /**< CDC class-specific Header functional descriptor. */
  166. CDC_DSUBTYPE_CSInterface_CallManagement = 0x01, /**< CDC class-specific Call Management functional descriptor. */
  167. CDC_DSUBTYPE_CSInterface_ACM = 0x02, /**< CDC class-specific Abstract Control Model functional descriptor. */
  168. CDC_DSUBTYPE_CSInterface_DirectLine = 0x03, /**< CDC class-specific Direct Line functional descriptor. */
  169. CDC_DSUBTYPE_CSInterface_TelephoneRinger = 0x04, /**< CDC class-specific Telephone Ringer functional descriptor. */
  170. CDC_DSUBTYPE_CSInterface_TelephoneCall = 0x05, /**< CDC class-specific Telephone Call functional descriptor. */
  171. CDC_DSUBTYPE_CSInterface_Union = 0x06, /**< CDC class-specific Union functional descriptor. */
  172. CDC_DSUBTYPE_CSInterface_CountrySelection = 0x07, /**< CDC class-specific Country Selection functional descriptor. */
  173. CDC_DSUBTYPE_CSInterface_TelephoneOpModes = 0x08, /**< CDC class-specific Telephone Operation Modes functional descriptor. */
  174. CDC_DSUBTYPE_CSInterface_USBTerminal = 0x09, /**< CDC class-specific USB Terminal functional descriptor. */
  175. CDC_DSUBTYPE_CSInterface_NetworkChannel = 0x0A, /**< CDC class-specific Network Channel functional descriptor. */
  176. CDC_DSUBTYPE_CSInterface_ProtocolUnit = 0x0B, /**< CDC class-specific Protocol Unit functional descriptor. */
  177. CDC_DSUBTYPE_CSInterface_ExtensionUnit = 0x0C, /**< CDC class-specific Extension Unit functional descriptor. */
  178. CDC_DSUBTYPE_CSInterface_MultiChannel = 0x0D, /**< CDC class-specific Multi-Channel Management functional descriptor. */
  179. CDC_DSUBTYPE_CSInterface_CAPI = 0x0E, /**< CDC class-specific Common ISDN API functional descriptor. */
  180. CDC_DSUBTYPE_CSInterface_Ethernet = 0x0F, /**< CDC class-specific Ethernet functional descriptor. */
  181. CDC_DSUBTYPE_CSInterface_ATM = 0x10, /**< CDC class-specific Asynchronous Transfer Mode functional descriptor. */
  182. };
  183. /** Enum for the possible line encoding formats of a virtual serial port. */
  184. enum CDC_LineEncodingFormats_t
  185. {
  186. CDC_LINEENCODING_OneStopBit = 0, /**< Each frame contains one stop bit. */
  187. CDC_LINEENCODING_OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits. */
  188. CDC_LINEENCODING_TwoStopBits = 2, /**< Each frame contains two stop bits. */
  189. };
  190. /** Enum for the possible line encoding parity settings of a virtual serial port. */
  191. enum CDC_LineEncodingParity_t
  192. {
  193. CDC_PARITY_None = 0, /**< No parity bit mode on each frame. */
  194. CDC_PARITY_Odd = 1, /**< Odd parity bit mode on each frame. */
  195. CDC_PARITY_Even = 2, /**< Even parity bit mode on each frame. */
  196. CDC_PARITY_Mark = 3, /**< Mark parity bit mode on each frame. */
  197. CDC_PARITY_Space = 4, /**< Space parity bit mode on each frame. */
  198. };
  199. /* Type Defines: */
  200. /** \brief CDC class-specific Functional Header Descriptor (LUFA naming conventions).
  201. *
  202. * Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
  203. * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
  204. * See the CDC class specification for more details.
  205. *
  206. * \see \ref USB_CDC_StdDescriptor_FunctionalHeader_t for the version of this type with standard element names.
  207. *
  208. * \note Regardless of CPU architecture, these values should be stored as little endian.
  209. */
  210. typedef struct
  211. {
  212. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  213. uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  214. * must be \ref CDC_DSUBTYPE_CSInterface_Header.
  215. */
  216. uint16_t CDCSpecification; /**< Version number of the CDC specification implemented by the device,
  217. * encoded in BCD format.
  218. *
  219. * \see \ref VERSION_BCD() utility macro.
  220. */
  221. } ATTR_PACKED USB_CDC_Descriptor_FunctionalHeader_t;
  222. /** \brief CDC class-specific Functional Header Descriptor (USB-IF naming conventions).
  223. *
  224. * Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
  225. * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
  226. * See the CDC class specification for more details.
  227. *
  228. * \see \ref USB_CDC_Descriptor_FunctionalHeader_t for the version of this type with non-standard LUFA specific
  229. * element names.
  230. *
  231. * \note Regardless of CPU architecture, these values should be stored as little endian.
  232. */
  233. typedef struct
  234. {
  235. uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
  236. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  237. * given by the specific class.
  238. */
  239. uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  240. * must be \ref CDC_DSUBTYPE_CSInterface_Header.
  241. */
  242. uint16_t bcdCDC; /**< Version number of the CDC specification implemented by the device, encoded in BCD format.
  243. *
  244. * \see \ref VERSION_BCD() utility macro.
  245. */
  246. } ATTR_PACKED USB_CDC_StdDescriptor_FunctionalHeader_t;
  247. /** \brief CDC class-specific Functional ACM Descriptor (LUFA naming conventions).
  248. *
  249. * Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
  250. * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
  251. *
  252. * \see \ref USB_CDC_StdDescriptor_FunctionalACM_t for the version of this type with standard element names.
  253. *
  254. * \note Regardless of CPU architecture, these values should be stored as little endian.
  255. */
  256. typedef struct
  257. {
  258. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  259. uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  260. * must be \ref CDC_DSUBTYPE_CSInterface_ACM.
  261. */
  262. uint8_t Capabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
  263. * this should be set to a fixed value of \c 0x06 - for other capabilities, refer
  264. * to the CDC ACM specification.
  265. */
  266. } ATTR_PACKED USB_CDC_Descriptor_FunctionalACM_t;
  267. /** \brief CDC class-specific Functional ACM Descriptor (USB-IF naming conventions).
  268. *
  269. * Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
  270. * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
  271. *
  272. * \see \ref USB_CDC_Descriptor_FunctionalACM_t for the version of this type with non-standard LUFA specific
  273. * element names.
  274. *
  275. * \note Regardless of CPU architecture, these values should be stored as little endian.
  276. */
  277. typedef struct
  278. {
  279. uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
  280. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  281. * given by the specific class.
  282. */
  283. uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  284. * must be \ref CDC_DSUBTYPE_CSInterface_ACM.
  285. */
  286. uint8_t bmCapabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
  287. * this should be set to a fixed value of 0x06 - for other capabilities, refer
  288. * to the CDC ACM specification.
  289. */
  290. } ATTR_PACKED USB_CDC_StdDescriptor_FunctionalACM_t;
  291. /** \brief CDC class-specific Functional Union Descriptor (LUFA naming conventions).
  292. *
  293. * Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
  294. * CDC control and data interfaces are related. See the CDC class specification for more details.
  295. *
  296. * \see \ref USB_CDC_StdDescriptor_FunctionalUnion_t for the version of this type with standard element names.
  297. *
  298. * \note Regardless of CPU architecture, these values should be stored as little endian.
  299. */
  300. typedef struct
  301. {
  302. USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
  303. uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  304. * must be \ref CDC_DSUBTYPE_CSInterface_Union.
  305. */
  306. uint8_t MasterInterfaceNumber; /**< Interface number of the CDC Control interface. */
  307. uint8_t SlaveInterfaceNumber; /**< Interface number of the CDC Data interface. */
  308. } ATTR_PACKED USB_CDC_Descriptor_FunctionalUnion_t;
  309. /** \brief CDC class-specific Functional Union Descriptor (USB-IF naming conventions).
  310. *
  311. * Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
  312. * CDC control and data interfaces are related. See the CDC class specification for more details.
  313. *
  314. * \see \ref USB_CDC_Descriptor_FunctionalUnion_t for the version of this type with non-standard LUFA specific
  315. * element names.
  316. *
  317. * \note Regardless of CPU architecture, these values should be stored as little endian.
  318. */
  319. typedef struct
  320. {
  321. uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
  322. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
  323. * given by the specific class.
  324. */
  325. uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
  326. * must be \ref CDC_DSUBTYPE_CSInterface_Union.
  327. */
  328. uint8_t bMasterInterface; /**< Interface number of the CDC Control interface. */
  329. uint8_t bSlaveInterface0; /**< Interface number of the CDC Data interface. */
  330. } ATTR_PACKED USB_CDC_StdDescriptor_FunctionalUnion_t;
  331. /** \brief CDC Virtual Serial Port Line Encoding Settings Structure.
  332. *
  333. * Type define for a CDC Line Encoding structure, used to hold the various encoding parameters for a virtual
  334. * serial port.
  335. *
  336. * \note Regardless of CPU architecture, these values should be stored as little endian.
  337. */
  338. typedef struct
  339. {
  340. uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second. */
  341. uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
  342. * \ref CDC_LineEncodingFormats_t enum.
  343. */
  344. uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
  345. * \ref CDC_LineEncodingParity_t enum.
  346. */
  347. uint8_t DataBits; /**< Bits of data per character of the virtual serial port. */
  348. } ATTR_PACKED CDC_LineEncoding_t;
  349. /* Disable C linkage for C++ Compilers: */
  350. #if defined(__cplusplus)
  351. }
  352. #endif
  353. #endif
  354. /** @} */