1
0

usb_tmc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers
  2. *
  3. * Copyright ©2020 Alexander Voronov <avv.0@ya.ru>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _USB_TMC_H_
  16. #define _USB_TMC_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdint.h>
  21. /**@addtogroup USB_MODULE_TMC USB TMC class
  22. * @brief This module contains USB Device Test and Measurement Class definitions.
  23. * @details This module based on
  24. * [USB Device Test and Measurement Class Specification, Revision 1.0]
  25. * (https://www.usb.org/sites/default/files/USBTMC_1_006a.zip)
  26. * @{*/
  27. /**@name USB TMC class, subclass and protocol definitions
  28. * @{*/
  29. #define USB_CLASS_TMC 0xFE
  30. #define USB_TMC_SUBCLASS_TMC 0x03
  31. #define USB_TMC_PROTO_NONE 0x00 /**< No subclass specification applies. */
  32. #define USB_TMC_PROTO_USB488 0x01 /**< USBTMC USB488 subclass interface. */
  33. /** @}*/
  34. /**@name USBTMC requests
  35. * @{*/
  36. #define USB_TMC_REQ_INITIATE_ABORT_BULK_OUT 1
  37. #define USB_TMC_REQ_CHECK_ABORT_BULK_OUT_STATUS 2
  38. #define USB_TMC_REQ_INITIATE_ABORT_BULK_IN 3
  39. #define USB_TMC_REQ_CHECK_ABORT_BULK_IN_STATUS 4
  40. #define USB_TMC_REQ_INITIATE_CLEAR 5
  41. #define USB_TMC_REQ_CHECK_CLEAR_STATUS 6
  42. #define USB_TMC_REQ_GET_CAPABILITIES 7
  43. #define USB_TMC_REQ_INDICATOR_PULSE 64
  44. /**@}*/
  45. /**@name USBTMC status values
  46. * @{*/
  47. #define USB_TMC_STATUS_SUCCESS 0x01
  48. #define USB_TMC_STATUS_PENDING 0x02
  49. #define USB_TMC_STATUS_FAILED 0x80
  50. #define USB_TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81
  51. #define USB_TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82
  52. #define USB_TMC_STATUS_SPLIT_IN_PROGRESS 0x83
  53. /**@}*/
  54. /** GET_CAPABILITIES request response */
  55. struct usb_tmc_get_capabilities_response {
  56. uint8_t USBTMC_status;
  57. uint8_t Reserved0;
  58. uint16_t bcdUSBTMC;
  59. uint8_t InterfaceCapabilities;
  60. uint8_t DeviceCapabilities;
  61. uint8_t Reserved1[18];
  62. } __attribute__((packed));
  63. /**@name MsgId values
  64. * @{*/
  65. #define USB_TMC_DEV_DEP_MSG_OUT 1
  66. #define USB_TMC_REQUEST_DEV_DEP_MSG_IN 2
  67. #define USB_TMC_DEV_DEP_MSG_IN 2
  68. #define USB_TMC_VENDOR_SPECIFIC_OUT 126
  69. #define USB_TMC_REQUEST_VENDOR_SPECIFIC_IN 127
  70. #define USB_TMC_VENDOR_SPECIFIC_IN 127
  71. /**@}*/
  72. /**@name Transfer Attributes
  73. * @{*/
  74. /** The last USBTMC message data byte in the transfer is the last byte of the
  75. * USBTMC message. */
  76. #define USB_TMC_TRANSFER_ATTR_EOM 0x01
  77. /** The Bulk-IN transfer must terminate on the specified TermChar. The Host may
  78. * only set this bit if the USBTMC interface indicates it supports TermChar in
  79. * the GET_CAPABILITIES response packet */
  80. #define USB_TMC_TRANSFER_ATTR_TERM_CHAR 0x02
  81. /**@}*/
  82. /** Message specific part of bulk header */
  83. union usb_tmc_bulk_header_specific {
  84. struct {
  85. uint32_t TransferSize;
  86. uint8_t bmTransferAttributes;
  87. uint8_t Reserved[3];
  88. } dev_dep_msg_out;
  89. struct {
  90. uint32_t TransferSize;
  91. uint8_t bmTransferAttributes;
  92. uint8_t TermChar;
  93. uint8_t Reserved[2];
  94. } request_dev_dep_msg_in;
  95. struct {
  96. uint32_t TransferSize;
  97. uint8_t bmTransferAttributes;
  98. uint8_t Reserved[3];
  99. } dev_dep_msg_in;
  100. struct {
  101. uint32_t TransferSize;
  102. uint8_t Reserved[4];
  103. } vendor_specific_out;
  104. struct {
  105. uint32_t TransferSize;
  106. uint8_t Reserved[4];
  107. } request_vendor_specific_in;
  108. struct {
  109. uint32_t TransferSize;
  110. uint8_t Reserved[4];
  111. } vendor_specific_in;
  112. };
  113. /** Host must begin the first USB transaction in each Bulk transfer of
  114. * command message content with a Bulk Header. */
  115. struct usb_tmc_bulk_header {
  116. /** Specifies the USBTMC message and the type of the USBTMC message. */
  117. uint8_t MsgId;
  118. /** A transfer identifier. The Host must set bTag different than the
  119. * bTag used in the previous Bulk-OUT Header. The Host should increment
  120. * the bTag by 1 each time it sends a new Bulk-OUT Header. */
  121. uint8_t bTag;
  122. /** The inverse (one's complement) of the bTag */
  123. uint8_t bTagInverse;
  124. uint8_t Reserved;
  125. /** USBTMC command message specific */
  126. union usb_tmc_bulk_header_specific MsgSpecific;
  127. } __attribute__((packed));
  128. /** @}*/
  129. #if defined(__cplusplus)
  130. }
  131. #endif
  132. #endif /* _USB_TMC_H_ */