mikroSDK Reference Manual
ftdi_sio.h
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/PID for matching FTDI devices
29
#define TU_FTDI_VID 0x0403
30
#define TU_FTDI_PID_LIST \
31
0x6001, 0x6006, 0x6010, 0x6011, 0x6014, 0x6015, 0x8372, 0xFBFA, \
32
0xcd18
33
34
// Commands
35
#define FTDI_SIO_RESET 0
/* Reset the port */
36
#define FTDI_SIO_MODEM_CTRL 1
/* Set the modem control register */
37
#define FTDI_SIO_SET_FLOW_CTRL 2
/* Set flow control register */
38
#define FTDI_SIO_SET_BAUD_RATE 3
/* Set baud rate */
39
#define FTDI_SIO_SET_DATA 4
/* Set the data characteristics of the port */
40
#define FTDI_SIO_GET_MODEM_STATUS 5
/* Retrieve current value of modem status register */
41
#define FTDI_SIO_SET_EVENT_CHAR 6
/* Set the event character */
42
#define FTDI_SIO_SET_ERROR_CHAR 7
/* Set the error character */
43
#define FTDI_SIO_SET_LATENCY_TIMER 9
/* Set the latency timer */
44
#define FTDI_SIO_GET_LATENCY_TIMER 0x0a
/* Get the latency timer */
45
#define FTDI_SIO_SET_BITMODE 0x0b
/* Set bitbang mode */
46
#define FTDI_SIO_READ_PINS 0x0c
/* Read immediate value of pins */
47
#define FTDI_SIO_READ_EEPROM 0x90
/* Read EEPROM */
48
49
/* FTDI_SIO_RESET */
50
#define FTDI_SIO_RESET_SIO 0
51
#define FTDI_SIO_RESET_PURGE_RX 1
52
#define FTDI_SIO_RESET_PURGE_TX 2
53
54
/*
55
* BmRequestType: 0100 0000B
56
* bRequest: FTDI_SIO_RESET
57
* wValue: Control Value
58
* 0 = Reset SIO
59
* 1 = Purge RX buffer
60
* 2 = Purge TX buffer
61
* wIndex: Port
62
* wLength: 0
63
* Data: None
64
*
65
* The Reset SIO command has this effect:
66
*
67
* Sets flow control set to 'none'
68
* Event char = $0D
69
* Event trigger = disabled
70
* Purge RX buffer
71
* Purge TX buffer
72
* Clear DTR
73
* Clear RTS
74
* baud and data format not reset
75
*
76
* The Purge RX and TX buffer commands affect nothing except the buffers
77
*
78
*/
79
80
/* FTDI_SIO_MODEM_CTRL */
81
/*
82
* BmRequestType: 0100 0000B
83
* bRequest: FTDI_SIO_MODEM_CTRL
84
* wValue: ControlValue (see below)
85
* wIndex: Port
86
* wLength: 0
87
* Data: None
88
*
89
* NOTE: If the device is in RTS/CTS flow control, the RTS set by this
90
* command will be IGNORED without an error being returned
91
* Also - you can not set DTR and RTS with one control message
92
*/
93
94
#define FTDI_SIO_SET_DTR_MASK 0x1
95
#define FTDI_SIO_SET_DTR_HIGH ((FTDI_SIO_SET_DTR_MASK << 8) | 1)
96
#define FTDI_SIO_SET_DTR_LOW ((FTDI_SIO_SET_DTR_MASK << 8) | 0)
97
#define FTDI_SIO_SET_RTS_MASK 0x2
98
#define FTDI_SIO_SET_RTS_HIGH ((FTDI_SIO_SET_RTS_MASK << 8) | 2)
99
#define FTDI_SIO_SET_RTS_LOW ((FTDI_SIO_SET_RTS_MASK << 8) | 0)
100
101
/*
102
* ControlValue
103
* B0 DTR state
104
* 0 = reset
105
* 1 = set
106
* B1 RTS state
107
* 0 = reset
108
* 1 = set
109
* B2..7 Reserved
110
* B8 DTR state enable
111
* 0 = ignore
112
* 1 = use DTR state
113
* B9 RTS state enable
114
* 0 = ignore
115
* 1 = use RTS state
116
* B10..15 Reserved
117
*/
118
119
/* FTDI_SIO_SET_FLOW_CTRL */
120
#define FTDI_SIO_DISABLE_FLOW_CTRL 0x0
121
#define FTDI_SIO_RTS_CTS_HS (0x1 << 8)
122
#define FTDI_SIO_DTR_DSR_HS (0x2 << 8)
123
#define FTDI_SIO_XON_XOFF_HS (0x4 << 8)
124
125
/*
126
* BmRequestType: 0100 0000b
127
* bRequest: FTDI_SIO_SET_FLOW_CTRL
128
* wValue: Xoff/Xon
129
* wIndex: Protocol/Port - hIndex is protocol / lIndex is port
130
* wLength: 0
131
* Data: None
132
*
133
* hIndex protocol is:
134
* B0 Output handshaking using RTS/CTS
135
* 0 = disabled
136
* 1 = enabled
137
* B1 Output handshaking using DTR/DSR
138
* 0 = disabled
139
* 1 = enabled
140
* B2 Xon/Xoff handshaking
141
* 0 = disabled
142
* 1 = enabled
143
*
144
* A value of zero in the hIndex field disables handshaking
145
*
146
* If Xon/Xoff handshaking is specified, the hValue field should contain the
147
* XOFF character and the lValue field contains the XON character.
148
*/
149
150
/* FTDI_SIO_SET_BAUD_RATE */
151
/*
152
* BmRequestType: 0100 0000B
153
* bRequest: FTDI_SIO_SET_BAUDRATE
154
* wValue: BaudDivisor value - see below
155
* wIndex: Port
156
* wLength: 0
157
* Data: None
158
* The BaudDivisor values are calculated as follows (too complicated):
159
*/
160
161
/* FTDI_SIO_SET_DATA */
162
#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
163
#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
164
#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
165
#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
166
#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
167
#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
168
#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
169
#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
170
#define FTDI_SIO_SET_BREAK (0x1 << 14)
171
172
/*
173
* BmRequestType: 0100 0000B
174
* bRequest: FTDI_SIO_SET_DATA
175
* wValue: Data characteristics (see below)
176
* wIndex: Port
177
* wLength: 0
178
* Data: No
179
*
180
* Data characteristics
181
*
182
* B0..7 Number of data bits
183
* B8..10 Parity
184
* 0 = None
185
* 1 = Odd
186
* 2 = Even
187
* 3 = Mark
188
* 4 = Space
189
* B11..13 Stop Bits
190
* 0 = 1
191
* 1 = 1.5
192
* 2 = 2
193
* B14
194
* 1 = TX ON (break)
195
* 0 = TX OFF (normal state)
196
* B15 Reserved
197
*
198
*/
199
200
/*
201
* DATA FORMAT
202
*
203
* IN Endpoint
204
*
205
* The device reserves the first two bytes of data on this endpoint to contain
206
* the current values of the modem and line status registers. In the absence of
207
* data, the device generates a message consisting of these two status bytes
208
* every 40 ms
209
*
210
* Byte 0: Modem Status
211
*
212
* Offset Description
213
* B0 Reserved - must be 1
214
* B1 Reserved - must be 0
215
* B2 Reserved - must be 0
216
* B3 Reserved - must be 0
217
* B4 Clear to Send (CTS)
218
* B5 Data Set Ready (DSR)
219
* B6 Ring Indicator (RI)
220
* B7 Receive Line Signal Detect (RLSD)
221
*
222
* Byte 1: Line Status
223
*
224
* Offset Description
225
* B0 Data Ready (DR)
226
* B1 Overrun Error (OE)
227
* B2 Parity Error (PE)
228
* B3 Framing Error (FE)
229
* B4 Break Interrupt (BI)
230
* B5 Transmitter Holding Register (THRE)
231
* B6 Transmitter Empty (TEMT)
232
* B7 Error in RCVR FIFO
233
*
234
*/
235
#define FTDI_RS0_CTS (1 << 4)
236
#define FTDI_RS0_DSR (1 << 5)
237
#define FTDI_RS0_RI (1 << 6)
238
#define FTDI_RS0_RLSD (1 << 7)
239
240
#define FTDI_RS_DR 1
241
#define FTDI_RS_OE (1<<1)
242
#define FTDI_RS_PE (1<<2)
243
#define FTDI_RS_FE (1<<3)
244
#define FTDI_RS_BI (1<<4)
245
#define FTDI_RS_THRE (1<<5)
246
#define FTDI_RS_TEMT (1<<6)
247
#define FTDI_RS_FIFO (1<<7)
248
249
#endif
//TUSB_FTDI_SIO_H