Open FFBoard
Open source force feedback firmware
ftdi_sio.h
Go to the documentation of this file.
1
/*
2
* The MIT License (MIT)
3
*
4
* Copyright (c) 2023 Ha Thach (thach@tinyusb.org) for Adafruit Industries
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
* THE SOFTWARE.
23
*/
24
25
#ifndef TUSB_FTDI_SIO_H
26
#define TUSB_FTDI_SIO_H
27
28
// VID for matching FTDI devices
29
#define TU_FTDI_VID 0x0403
30
31
// Commands
32
#define FTDI_SIO_RESET 0
/* Reset the port */
33
#define FTDI_SIO_MODEM_CTRL 1
/* Set the modem control register */
34
#define FTDI_SIO_SET_FLOW_CTRL 2
/* Set flow control register */
35
#define FTDI_SIO_SET_BAUD_RATE 3
/* Set baud rate */
36
#define FTDI_SIO_SET_DATA 4
/* Set the data characteristics of the port */
37
#define FTDI_SIO_GET_MODEM_STATUS 5
/* Retrieve current value of modem status register */
38
#define FTDI_SIO_SET_EVENT_CHAR 6
/* Set the event character */
39
#define FTDI_SIO_SET_ERROR_CHAR 7
/* Set the error character */
40
#define FTDI_SIO_SET_LATENCY_TIMER 9
/* Set the latency timer */
41
#define FTDI_SIO_GET_LATENCY_TIMER 0x0a
/* Get the latency timer */
42
#define FTDI_SIO_SET_BITMODE 0x0b
/* Set bitbang mode */
43
#define FTDI_SIO_READ_PINS 0x0c
/* Read immediate value of pins */
44
#define FTDI_SIO_READ_EEPROM 0x90
/* Read EEPROM */
45
46
/* FTDI_SIO_RESET */
47
#define FTDI_SIO_RESET_SIO 0
48
#define FTDI_SIO_RESET_PURGE_RX 1
49
#define FTDI_SIO_RESET_PURGE_TX 2
50
51
/*
52
* BmRequestType: 0100 0000B
53
* bRequest: FTDI_SIO_RESET
54
* wValue: Control Value
55
* 0 = Reset SIO
56
* 1 = Purge RX buffer
57
* 2 = Purge TX buffer
58
* wIndex: Port
59
* wLength: 0
60
* Data: None
61
*
62
* The Reset SIO command has this effect:
63
*
64
* Sets flow control set to 'none'
65
* Event char = $0D
66
* Event trigger = disabled
67
* Purge RX buffer
68
* Purge TX buffer
69
* Clear DTR
70
* Clear RTS
71
* baud and data format not reset
72
*
73
* The Purge RX and TX buffer commands affect nothing except the buffers
74
*
75
*/
76
77
/* FTDI_SIO_MODEM_CTRL */
78
/*
79
* BmRequestType: 0100 0000B
80
* bRequest: FTDI_SIO_MODEM_CTRL
81
* wValue: ControlValue (see below)
82
* wIndex: Port
83
* wLength: 0
84
* Data: None
85
*
86
* NOTE: If the device is in RTS/CTS flow control, the RTS set by this
87
* command will be IGNORED without an error being returned
88
* Also - you can not set DTR and RTS with one control message
89
*/
90
91
#define FTDI_SIO_SET_DTR_MASK 0x1
92
#define FTDI_SIO_SET_DTR_HIGH ((FTDI_SIO_SET_DTR_MASK << 8) | 1)
93
#define FTDI_SIO_SET_DTR_LOW ((FTDI_SIO_SET_DTR_MASK << 8) | 0)
94
#define FTDI_SIO_SET_RTS_MASK 0x2
95
#define FTDI_SIO_SET_RTS_HIGH ((FTDI_SIO_SET_RTS_MASK << 8) | 2)
96
#define FTDI_SIO_SET_RTS_LOW ((FTDI_SIO_SET_RTS_MASK << 8) | 0)
97
98
/*
99
* ControlValue
100
* B0 DTR state
101
* 0 = reset
102
* 1 = set
103
* B1 RTS state
104
* 0 = reset
105
* 1 = set
106
* B2..7 Reserved
107
* B8 DTR state enable
108
* 0 = ignore
109
* 1 = use DTR state
110
* B9 RTS state enable
111
* 0 = ignore
112
* 1 = use RTS state
113
* B10..15 Reserved
114
*/
115
116
/* FTDI_SIO_SET_FLOW_CTRL */
117
#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
118
#define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
119
#define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
120
#define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
121
122
/*
123
* BmRequestType: 0100 0000b
124
* bRequest: FTDI_SIO_SET_FLOW_CTRL
125
* wValue: Xoff/Xon
126
* wIndex: Protocol/Port - hIndex is protocol / lIndex is port
127
* wLength: 0
128
* Data: None
129
*
130
* hIndex protocol is:
131
* B0 Output handshaking using RTS/CTS
132
* 0 = disabled
133
* 1 = enabled
134
* B1 Output handshaking using DTR/DSR
135
* 0 = disabled
136
* 1 = enabled
137
* B2 Xon/Xoff handshaking
138
* 0 = disabled
139
* 1 = enabled
140
*
141
* A value of zero in the hIndex field disables handshaking
142
*
143
* If Xon/Xoff handshaking is specified, the hValue field should contain the
144
* XOFF character and the lValue field contains the XON character.
145
*/
146
147
/* FTDI_SIO_SET_BAUD_RATE */
148
/*
149
* BmRequestType: 0100 0000B
150
* bRequest: FTDI_SIO_SET_BAUDRATE
151
* wValue: BaudDivisor value - see below
152
* wIndex: Port
153
* wLength: 0
154
* Data: None
155
* The BaudDivisor values are calculated as follows (too complicated):
156
*/
157
158
/* FTDI_SIO_SET_DATA */
159
#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
160
#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
161
#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
162
#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
163
#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
164
#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
165
#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
166
#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
167
#define FTDI_SIO_SET_BREAK (0x1 << 14)
168
169
/*
170
* BmRequestType: 0100 0000B
171
* bRequest: FTDI_SIO_SET_DATA
172
* wValue: Data characteristics (see below)
173
* wIndex: Port
174
* wLength: 0
175
* Data: No
176
*
177
* Data characteristics
178
*
179
* B0..7 Number of data bits
180
* B8..10 Parity
181
* 0 = None
182
* 1 = Odd
183
* 2 = Even
184
* 3 = Mark
185
* 4 = Space
186
* B11..13 Stop Bits
187
* 0 = 1
188
* 1 = 1.5
189
* 2 = 2
190
* B14
191
* 1 = TX ON (break)
192
* 0 = TX OFF (normal state)
193
* B15 Reserved
194
*
195
*/
196
197
/*
198
* DATA FORMAT
199
*
200
* IN Endpoint
201
*
202
* The device reserves the first two bytes of data on this endpoint to contain
203
* the current values of the modem and line status registers. In the absence of
204
* data, the device generates a message consisting of these two status bytes
205
* every 40 ms
206
*
207
* Byte 0: Modem Status
208
*
209
* Offset Description
210
* B0 Reserved - must be 1
211
* B1 Reserved - must be 0
212
* B2 Reserved - must be 0
213
* B3 Reserved - must be 0
214
* B4 Clear to Send (CTS)
215
* B5 Data Set Ready (DSR)
216
* B6 Ring Indicator (RI)
217
* B7 Receive Line Signal Detect (RLSD)
218
*
219
* Byte 1: Line Status
220
*
221
* Offset Description
222
* B0 Data Ready (DR)
223
* B1 Overrun Error (OE)
224
* B2 Parity Error (PE)
225
* B3 Framing Error (FE)
226
* B4 Break Interrupt (BI)
227
* B5 Transmitter Holding Register (THRE)
228
* B6 Transmitter Empty (TEMT)
229
* B7 Error in RCVR FIFO
230
*
231
*/
232
#define FTDI_RS0_CTS (1 << 4)
233
#define FTDI_RS0_DSR (1 << 5)
234
#define FTDI_RS0_RI (1 << 6)
235
#define FTDI_RS0_RLSD (1 << 7)
236
237
#define FTDI_RS_DR 1
238
#define FTDI_RS_OE (1<<1)
239
#define FTDI_RS_PE (1<<2)
240
#define FTDI_RS_FE (1<<3)
241
#define FTDI_RS_BI (1<<4)
242
#define FTDI_RS_THRE (1<<5)
243
#define FTDI_RS_TEMT (1<<6)
244
#define FTDI_RS_FIFO (1<<7)
245
246
#endif
//TUSB_FTDI_SIO_H
Firmware
FFBoard
USB
class
cdc
serial
ftdi_sio.h
Generated by
1.9.2