Open FFBoard
Open source force feedback firmware
usbtmc.h
Go to the documentation of this file.
1
2/*
3 * The MIT License (MIT)
4 *
5 * Copyright (c) 2019 N Conrad
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _TUSB_USBTMC_H__
29#define _TUSB_USBTMC_H__
30
31#include "common/tusb_common.h"
32
33
34/* Implements USBTMC Revision 1.0, April 14, 2003
35
36 String descriptors must have a "LANGID=0x409"/US English string.
37 Characters must be 0x20 (' ') to 0x7E ('~') ASCII,
38 But MUST not contain: "/:?\*
39 Also must not have leading or trailing space (' ')
40 Device descriptor must state USB version 0x0200 or greater
41
42 If USB488DeviceCapabilites.D2 = 1 (SR1), then there must be a INT endpoint.
43*/
44
45#define USBTMC_VERSION 0x0100
46#define USBTMC_488_VERSION 0x0100
47
48typedef enum {
55
57typedef struct TU_ATTR_PACKED
58{
59 uint8_t MsgID ;
60 uint8_t bTag ;
61 uint8_t bTagInverse ;
62 uint8_t _reserved ;
64
65typedef struct TU_ATTR_PACKED
66{
68 uint8_t data[8];
70
71/* Uses on the bulk-out endpoint: */
72// Next 8 bytes are message-specific
73typedef struct TU_ATTR_PACKED {
75 uint32_t TransferSize ;
76 struct TU_ATTR_PACKED
77 {
78 unsigned int EOM : 1 ;
80 uint8_t _reserved[3];
82
83TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_out) == 12u, "struct wrong length");
84
85// Next 8 bytes are message-specific
86typedef struct TU_ATTR_PACKED
87{
89 uint32_t TransferSize ;
90 struct TU_ATTR_PACKED
91 {
92 unsigned int TermCharEnabled : 1 ;
94 uint8_t TermChar;
95 uint8_t _reserved[2];
97
98TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_in) == 12u, "struct wrong length");
99
100/* Bulk-in headers */
101
102typedef struct TU_ATTR_PACKED
103{
105 uint32_t TransferSize;
106 struct TU_ATTR_PACKED
107 {
108 uint8_t EOM: 1;
109 uint8_t UsingTermChar: 1;
111 uint8_t _reserved[3];
113
114TU_VERIFY_STATIC(sizeof(usbtmc_msg_dev_dep_msg_in_header_t) == 12u, "struct wrong length");
115
116/* Unsupported vendor things.... Are these ever used?*/
117
118typedef struct TU_ATTR_PACKED
119{
121 uint32_t TransferSize ;
122 uint8_t _reserved[4];
124
125
126TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_out) == 12u, "struct wrong length");
127
128typedef struct TU_ATTR_PACKED
129{
131 uint32_t TransferSize ;
132 uint8_t _reserved[4];
134
135TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_in) == 12u, "struct wrong length");
136
137// Control request type should use tusb_control_request_t
138
139/*
140typedef struct TU_ATTR_PACKED {
141 struct {
142 unsigned int Recipient : 5 ; ///< EOM set on last byte
143 unsigned int Type : 2 ; ///< EOM set on last byte
144 unsigned int DirectionToHost : 1 ; ///< 0 is OUT, 1 is IN
145 } bmRequestType;
146 uint8_t bRequest ; ///< If bmRequestType.Type = Class, see usmtmc_request_type_enum
147 uint16_t wValue ;
148 uint16_t wIndex ;
149 uint16_t wLength ; // Number of bytes in data stage
150} usbtmc_class_specific_control_req;
151
152*/
153// bulk-in protocol errors
154enum {
160};
161// built-in halt errors
162enum {
163 USBTMC_BULK_IN_ERR = 1u,
165};
166
167typedef enum {
175
177
178 /****** USBTMC 488 *************/
183
185
186typedef enum {
187 // The last and first valid bNotify1 for use by the USBTMC class specification.
190
191 // The last and first valid bNotify1 for use by vendors.
194
195 // The last and first valid bNotify1 for use by USBTMC subclass specifications.
198
199 // From the USB488 Subclass Specification, Section 3.4.
202
203typedef enum {
210
211 /****** USBTMC 488 *************/
214
215/************************************************************
216 * Control Responses
217 */
218
219typedef struct TU_ATTR_PACKED {
221 uint8_t _reserved;
223
224 struct TU_ATTR_PACKED
225 {
226 unsigned int listenOnly :1;
227 unsigned int talkOnly :1;
228 unsigned int supportsIndicatorPulse :1;
230 struct TU_ATTR_PACKED
231 {
232 unsigned int canEndBulkInOnTermChar :1;
234 uint8_t _reserved2[6];
235 uint8_t _reserved3[12];
237
238TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_t) == 0x18, "struct wrong length");
239
240typedef struct TU_ATTR_PACKED
241{
242 uint8_t USBTMC_status;
243 struct TU_ATTR_PACKED
244 {
245 unsigned int BulkInFifoBytes :1;
248
249TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
250
251// Used for both abort bulk IN and bulk OUT
252typedef struct TU_ATTR_PACKED
253{
254 uint8_t USBTMC_status;
255 uint8_t bTag;
257
258TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
259
260// Used for both check_abort_bulk_in_status and check_abort_bulk_out_status
261typedef struct TU_ATTR_PACKED
262{
263 uint8_t USBTMC_status;
264 struct TU_ATTR_PACKED
265 {
266 unsigned int BulkInFifoBytes : 1;
268 uint8_t _reserved[2];
271
272TU_VERIFY_STATIC(sizeof(usbtmc_check_abort_bulk_rsp_t) == 8u, "struct wrong length");
273
274typedef struct TU_ATTR_PACKED
275{
276 uint8_t USBTMC_status;
277 uint8_t _reserved;
279
280 struct TU_ATTR_PACKED
281 {
282 uint8_t listenOnly :1;
283 uint8_t talkOnly :1;
286
287 struct TU_ATTR_PACKED
288 {
291
292 uint8_t _reserved2[6];
294
295 struct TU_ATTR_PACKED
296 {
297 uint8_t supportsTrigger :1;
299 uint8_t is488_2 :1;
301
302 struct TU_ATTR_PACKED
303 {
304 uint8_t DT1 :1;
305 uint8_t RL1 :1;
306 uint8_t SR1 :1;
307 uint8_t SCPI :1;
309 uint8_t _reserved3[8];
311
312TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_488_t) == 0x18, "struct wrong length");
313
314typedef struct TU_ATTR_PACKED
315{
316 uint8_t USBTMC_status;
317 uint8_t bTag;
318 uint8_t statusByte;
320
321TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_rsp_488_t) == 3u, "struct wrong length");
322
323typedef struct TU_ATTR_PACKED
324{
325 uint8_t bNotify1; // Must be USB488_bNOTIFY1_SRQ
326 uint8_t StatusByte;
328
329TU_VERIFY_STATIC(sizeof(usbtmc_srq_interrupt_488_t) == 2u, "struct wrong length");
330
331typedef struct TU_ATTR_PACKED
332{
333 struct TU_ATTR_PACKED
334 {
335 unsigned int bTag : 7;
336 unsigned int one : 1;
338 uint8_t StatusByte;
340
341TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_interrupt_488_t) == 2u, "struct wrong length");
342
343#endif
uint8_t UsingTermChar
Support TermChar && Request.TermCharEnabled && last char in transfer is TermChar.
Definition: usbtmc.h:109
unsigned int supportsIndicatorPulse
Definition: usbtmc.h:228
uint8_t EOM
Last byte of transfer is the end of the message.
Definition: usbtmc.h:108
unsigned int BulkInFifoBytes
Has queued data or a short packet that is queued.
Definition: usbtmc.h:245
unsigned int TermCharEnabled
"The Bulk-IN transfer must terminate on the specified TermChar."; CAPABILITIES must list TermChar
Definition: usbtmc.h:92
unsigned int canEndBulkInOnTermChar
Definition: usbtmc.h:232
unsigned int EOM
EOM set on last byte.
Definition: usbtmc.h:78
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint8_t USBTMC_status
usbtmc_status_enum
Definition: usbtmc.h:220
uint8_t _reserved3[12]
Definition: usbtmc.h:235
uint8_t bNotify1
Definition: usbtmc.h:325
uint16_t bcdUSB488
Definition: usbtmc.h:293
uint8_t MsgID
Message type ID (usbtmc_msgid_enum)
Definition: usbtmc.h:59
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmDevCapabilities
uint8_t _reserved2[6]
Definition: usbtmc.h:234
uint8_t TermChar
Definition: usbtmc.h:94
uint8_t data[CFG_TUD_NCM_IN_NTB_MAX_SIZE]
Definition: ncm.h:147
uint8_t statusByte
Definition: usbtmc.h:318
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmDevCapabilities488
uint32_t NBYTES_RXD_TXD
Definition: usbtmc.h:269
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmIntfcCapabilities488
volatile uint16_t
Definition: hcd_rusb2.c:58
uint32_t TransferSize
Transfer size; LSB first.
Definition: usbtmc.h:75
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmIntfcCapabilities
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmClear
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmAbortBulkIn
usbtmc_msg_header_t header
Header.
Definition: usbtmc.h:67
uint8_t bTagInverse
Complement of the tag.
Definition: usbtmc.h:61
uint8_t bTag
Transfer ID 1<=bTag<=255.
Definition: usbtmc.h:60
uint16_t bcdUSBTMC
USBTMC_VERSION.
Definition: usbtmc.h:222
struct TU_ATTR_PACKED::TU_ATTR_PACKED bmTransferAttributes
uint8_t StatusByte
Definition: usbtmc.h:326
uint8_t _reserved
Must be 0x00.
Definition: usbtmc.h:62
struct TU_ATTR_PACKED usbtmc_check_abort_bulk_rsp_t
struct TU_ATTR_PACKED usbtmc_msg_dev_dep_msg_in_header_t
struct TU_ATTR_PACKED usbtmc_msg_request_dev_dep_in
struct TU_ATTR_PACKED usbtmc_response_capabilities_488_t
struct TU_ATTR_PACKED usbtmc_response_capabilities_t
struct TU_ATTR_PACKED usbtmc_msg_request_vendor_specific_in
struct TU_ATTR_PACKED usbtmc_msg_header_t
Message header (For BULK OUT and BULK IN); 4 bytes.
usbtmc_int_in_payload_format
Definition: usbtmc.h:186
@ USBTMC_bNOTIFY1_USBTMC_FIRST
Definition: usbtmc.h:188
@ USBTMC_bNOTIFY1_SUBCLASS_LAST
Definition: usbtmc.h:197
@ USBTMC_bNOTIFY1_VENDOR_SPECIFIC_FIRST
Definition: usbtmc.h:192
@ USB488_bNOTIFY1_SRQ
Definition: usbtmc.h:200
@ USBTMC_bNOTIFY1_VENDOR_SPECIFIC_LAST
Definition: usbtmc.h:193
@ USBTMC_bNOTIFY1_SUBCLASS_FIRST
Definition: usbtmc.h:196
@ USBTMC_bNOTIFY1_USBTMC_LAST
Definition: usbtmc.h:189
struct TU_ATTR_PACKED usbtmc_read_stb_interrupt_488_t
struct TU_ATTR_PACKED usbtmc_msg_request_dev_dep_out
struct TU_ATTR_PACKED usbtmc_srq_interrupt_488_t
struct TU_ATTR_PACKED usbtmc_msg_generic_t
struct TU_ATTR_PACKED usbtmc_initiate_abort_rsp_t
struct TU_ATTR_PACKED usbtmc_get_clear_status_rsp_t
struct TU_ATTR_PACKED usbtmc_read_stb_rsp_488_t
struct TU_ATTR_PACKED usbtmc_msg_request_vendor_specific_out
usbtmc_status_enum
Definition: usbtmc.h:203
@ USBTMC_STATUS_SPLIT_IN_PROGRESS
Definition: usbtmc.h:209
@ USBTMC_STATUS_SUCCESS
Definition: usbtmc.h:204
@ USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS
Definition: usbtmc.h:208
@ USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS
Definition: usbtmc.h:207
@ USBTMC_STATUS_PENDING
Definition: usbtmc.h:205
@ USBTMC_STATUS_FAILED
Definition: usbtmc.h:206
@ USB488_STATUS_INTERRUPT_IN_BUSY
Definition: usbtmc.h:212
usbtmc_msgid_enum
Definition: usbtmc.h:48
@ USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT
Definition: usbtmc.h:51
@ USBTMC_MSGID_USB488_TRIGGER
Definition: usbtmc.h:53
@ USBTMC_MSGID_DEV_DEP_MSG_OUT
Definition: usbtmc.h:49
@ USBTMC_MSGID_DEV_DEP_MSG_IN
Definition: usbtmc.h:50
@ USBTMC_MSGID_VENDOR_SPECIFIC_IN
Definition: usbtmc.h:52
usmtmc_request_type_enum
Definition: usbtmc.h:167
@ USBTMC_bREQUEST_INDICATOR_PULSE
Definition: usbtmc.h:176
@ USB488_bREQUEST_GO_TO_LOCAL
Definition: usbtmc.h:181
@ USBTMC_bREQUEST_GET_CAPABILITIES
Definition: usbtmc.h:174
@ USBTMC_bREQUEST_CHECK_CLEAR_STATUS
Definition: usbtmc.h:173
@ USB488_bREQUEST_REN_CONTROL
Definition: usbtmc.h:180
@ USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT
Definition: usbtmc.h:168
@ USB488_bREQUEST_LOCAL_LOCKOUT
Definition: usbtmc.h:182
@ USBTMC_bREQUEST_INITIATE_CLEAR
Definition: usbtmc.h:172
@ USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS
Definition: usbtmc.h:169
@ USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN
Definition: usbtmc.h:170
@ USB488_bREQUEST_READ_STATUS_BYTE
Definition: usbtmc.h:179
@ USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS
Definition: usbtmc.h:171
TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_out)==12u, "struct wrong length")
@ USBTMC_BULK_IN_ERR_INCOMPLETE_HEADER
Definition: usbtmc.h:155
@ USBTMC_BULK_IN_ERR_DATA_TOO_SHORT
Definition: usbtmc.h:158
@ USBTMC_BULK_IN_ERR_UNSUPPORTED
Definition: usbtmc.h:156
@ USBTMC_BULK_IN_ERR_BAD_PARAMETER
Definition: usbtmc.h:157
@ USBTMC_BULK_IN_ERR_DATA_TOO_LONG
Definition: usbtmc.h:159
@ USBTMC_BULK_IN_ERR
Definition: usbtmc.h:163