-
Notifications
You must be signed in to change notification settings - Fork 3
/
D2XX.sbp
303 lines (258 loc) · 14.2 KB
/
D2XX.sbp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
' ===========================
'CLASSIC INTERFACE
' ===========================
Declare Function FT_ListDevices Lib "FTD2XX.DLL" (arg1 As Long, arg2 As BytePtr, dwFlags As Long) As Long
Declare Function FT_GetNumDevices Lib "FTD2XX.DLL" Alias "FT_ListDevices" (ByRef DeviceCount As Long, rsv As BytePtr, dwFlags As Long) As Long
Declare Function FT_Open Lib "FTD2XX.DLL" (intDeviceNumber As Long, ByRef lngHandle As FT_HANDLE) As Long
Declare Function FT_OpenEx Lib "FTD2XX.DLL" (arg1 As BytePtr, arg2 As Long, ByRef lngHandle As FT_HANDLE) As Long
Declare Function FT_Close Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_Read Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lpszBuffer As BytePtr, lngBufferSize As Long, ByRef lngBytesReturned As DWord) As Long
Declare Function FT_Write Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lpszBuffer As BytePtr, lngBufferSize As Long, ByRef lngBytesWritten As DWord) As Long
Declare Function FT_WriteByte Lib "FTD2XX.DLL" Alias "FT_Write" (lngHandle As FT_HANDLE, ByRef lpszBuffer As Any, lngBufferSize As Long, ByRef lngBytesWritten As Long) As Long
Declare Function FT_SetBaudRate Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lngBaudRate As Long) As Long
Declare Function FT_SetDataCharacteristics Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, byWordLength As Byte, byStopBits As Byte, byParity As Byte) As Long
Declare Function FT_SetFlowControl Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, intFlowControl As Integer, byXonChar As Byte, byXoffChar As Byte) As Long
Declare Function FT_SetDtr Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_ClrDtr Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_SetRts Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_ClrRts Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_GetModemStatus Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lngModemStatus As Long) As Long
Declare Function FT_SetChars Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, byEventChar As Byte, byEventCharEnabled As Byte, byErrorChar As Byte, byErrorCharEnabled As Byte) As Long
Declare Function FT_Purge Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lngMask As Long) As Long
Declare Function FT_SetTimeouts Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lngReadTimeout As Long, lngWriteTimeout As Long) As Long
Declare Function FT_SetDivisor Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lngReadTimeout As Long) As Long
Declare Function FT_GetQueueStatus Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lngRxBytes As DWord) As Long
Declare Function FT_SetBreakOn Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_SetBreakOff Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
Declare Function FT_GetStatus Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lngRxBytes As Long, ByRef lngTxBytes As Long, ByRef lngEventsDWord As DWord) As Long
Declare Function FT_SetEventNotification Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, dwEventMask As Long, pVoid As Long) As Long
Declare Function FT_ResetDevice Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE) As Long
'Declare Function FT_SetDivisor Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, shDivisor) As Short
'Declare Function FT_GetEventStatus Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lngEventsDWord As Long) As Long
Declare Function FT_GetBitMode Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef intData As Any) As Long
Declare Function FT_SetBitMode Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, intMask As Byte, intMode As Byte) As Long
Declare Function FT_SetLatencyTimer Lib "FTD2XX.DLL" (Handle As Long, pucTimer As Byte) As Long
Declare Function FT_GetLatencyTimer Lib "FTD2XX.DLL" (Handle As Long, ByRef ucTimer As Long) As Long
Declare Function FT_SetUSBParameters Lib "FTD2XX.DLL" (Handle As Long, ulInTransferSize As DWord, ulOutTransferSize As DWord) As Long
' =============================
'FT_W32 API
' =============================
Declare Function FT_W32_CreateFile Lib "FTD2XX.DLL" (lpszName As BytePtr, dwAccess As Long, dwShareMode As Long, ByRef lpSecurityAttributes As LPSECURITY_ATTRIBUTES, dwCreate As Long, dwAttrsAndFlags As Long, hTemplate As Long) As Long
Declare Function FT_W32_CloseHandle Lib "FTD2XX.DLL" (ftHandle As Long) As Long
Declare Function FT_W32_ReadFile Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lpszBuffer As BytePtr, lngBufferSize As Long, ByRef lngBytesReturned As Long, ByRef lpftOverlapped As lpOverlapped) As Long
Declare Function FT_W32_WriteFile Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, lpszBuffer As BytePtr, lngBufferSize As Long, ByRef lngBytesWritten As Long, ByRef lpftOverlapped As lpOverlapped) As Long
Declare Function FT_W32_GetOverlappedResult Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpftOverlapped As lpOverlapped, ByRef lpdwBytesTransferred As Long, bWait As Long) As Long
Declare Function FT_W32_GetCommState Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpftDCB As FTDCB) As Long
Declare Function FT_W32_SetCommState Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpftDCB As FTDCB) As Long
/*Declare Sub Sleep Lib "kernel32" (dwMilliseconds As Long)
Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" (lpEventAttributes As Long, bManualReset As Long, bInitialState As Long, lpName As BytePtr) As Long
Declare Function WaitForSingleObject Lib "kernel32" (hHandle As Long, dwMilliseconds As Long) As Long
Declare Function SetEvent Lib "kernel32" (hHandle As Long) As Long
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (hThread As Long, dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Long
*/
' ====================================================================
'APIGID32.DLL by DESAWARE Inc. (www.desaware.com), see Dan Appleman's
'"Visual Basic Programmer's Guide to the WIN32-API"; here used to get
'the addresses of the VB-bytearrays:
' ====================================================================
'Declare Function agGetAddressForObject& Lib "apigid32.dll" (object As Any)
' ==============================================================
'Declarations for the EEPROM-accessing functions in FTD2XX.dll:
' ==============================================================
Declare Function FT_EE_Program Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpData As FT_PROGRAM_DATA) As Long
Declare Function FT_EE_Read Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpData As FT_PROGRAM_DATA) As Long
Declare Function FT_EE_UASize Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, ByRef lpdwSize As Long) As Long
Declare Function FT_EE_UAWrite Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, pucData As BytePtr, dwDataLen As Long) As Long
Declare Function FT_EE_UARead Lib "FTD2XX.DLL" (lngHandle As FT_HANDLE, pucData As BytePtr, dwDataLen As Long, ByRef lpdwBytesRead As Long) As Long
Type LPSECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Type lpOverlapped
Internal As Long
InternalHigh As Long
Offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Type FTDCB
DCBlength As Long 'sizeof (FTDCB)
BaudRate As Long '9600
' fBinary As Long ' = 1 Binary mode (skip EOF check)
' fParity As Long ' = 1 Enable parity checking
' fOutxCtsFlow As Long ' = 1 CTS handshaking on output
' fOutxDsrFlow As Long ' = 1 DSR handshaking on output
' fDtrControl As Long ' = 2 DTR flow control
' fDsrSensitivity As Long ' = 1 DSR Sensitivity
' fTXContinueOnXoff As Long ' = 1 Continue TX when Xoff sent
' fOutX As Long ' = 1 Enable output X-on/X-off
' fInX As Long ' = 1 Enable input X-on/X-off
' fErrorChar As Long ' = 1 Enable error replacement
' fNull As Long ' = 1 Enable null stripping
' fRtsControl As Long ' = 2 RTS flow control
' fAbortOnError As Long ' = 1 Abort all reads and writes on error
' fDummy2 As Long ' = 17 Reserved
' wReserved As Integer 'Not currently used
' XonLim As Integer 'Transmit X-on threshold
' XoffLim As Integer 'Transmit X-off threshold
' ByteSize As Byte 'Number of bits/ byte, 7-8
' Parity As Byte '0-4 = None, Odd, Even, Mark, Space
' StopBits As Byte '0, 2 = 1, 2
' XonChar As Byte 'TX and RX X-ON character
' XoffChar As Byte 'TX and RX X-OFF character
' ErrorChar As Byte 'Eror replacement char
' EofChar As Byte 'End of input Character
' EvtChar As Byte 'Received event character
' wReserved1 As Integer 'BCD (0x0200 >= USB2)
End Type
' ====================================================================
'Type definition As equivalent for C-structure "ft_program_data" used
'in FT_EE_READ and FT_EE_WRITE;
'ATTENTION! The variables "Manufacturer", "ManufacturerID",
'"Description" and "SerialNumber" are passed As POINTERS to
'locations of Bytearrays. Each Byte in these arrays will be
'filled with one character of the whole BytePtr.
'(See below, calls to "agGetAddressForObject")
' =====================================================================
Type FT_PROGRAM_DATA
signature1 As Long '0x00000000
signature2 As Long '0xFFFFFFFF
version As Long '0
VendorId As Integer '0x0403
ProductId As Integer '0x6001
Manufacturer As Long '32 "FTDI"
ManufacturerId As Long '16 "FT"
Description As Long '64 "USB HS Serial Converter"
SerialNumber As Long '16 "FT000001" if fixed, or NULL
MaxPower As Integer ' // 0 < MaxPower <= 500
PnP As Integer ' // 0 = disabled, 1 = enabled
SelfPowered As Integer ' // 0 = bus powered, 1 = self powered
RemoteWakeup As Integer ' // 0 = not capable, 1 = capable
'Rev4 extensions:
Rev4 As Byte ' // true if Rev4 chip, false otherwise
IsoIn As Byte ' // true if in endpoint is isochronous
IsoOut As Byte ' // true if out endpoint is isochronous
PullDownEnable As Byte ' // true if pull down enabled
SerNumEnable As Byte ' // true if serial number to be used
USBVersionEnable As Byte ' // true if chip uses USBVersion
USBVersion As Integer ' // BCD (0x0200 >= USB2)
'FT2232C extensions:
Rev5 As Byte 'non-zero if Rev5 chip, zero otherwise
IsoInA As Byte 'non-zero if in endpoint is isochronous
IsoInB As Byte 'non-zero if in endpoint is isochronous
IsoOutA As Byte 'non-zero if out endpoint is isochronous
IsoOutB As Byte 'non-zero if out endpoint is isochronous
PullDownEnable5 As Byte 'non-zero if pull down enabled
SerNumEnable5 As Byte 'non-zero if serial number to be used
USBVersionEnable5 As Byte 'non-zero if chip uses USBVersion
USBVersion5 As Integer 'BCD 0x110 = USB 1.1, BCD 0x200 = USB 2.0
AlsHighCurrent As Byte 'non-zero if interface is high current
BlsHighCurrent As Byte 'non-zero if interface is high current
IFAlsFifo As Byte 'non-zero if interface is 245 FIFO
IFAlsFifoTar As Byte 'non-zero if interface is 245 FIFO CPU target
IFAlsFastSer As Byte 'non-zero if interface is Fast Serial
AlsVCP As Byte 'non-zero if interface is to use VCP drivers
IFBlsFifo As Byte 'non-zero if interface is 245 FIFO
IFBlsFifoTar As Byte 'non-zero if interface is 245 FIFO CPU target
IFBlsFastSer As Byte 'non-zero if interface is Fast Serial
BlsVCP As Byte 'non-zero if interface is to use VCP drivers
'FT232R extensions
UseExtOSC As Byte 'non-zero use ext osc
HighDriveIOs As Byte 'non-zero to use High Drive IO's
EndPointSize As Byte '64 Do not change
PullDownEnableR As Byte 'non-zeero if pull down enabled
SerNumEnableR As Byte 'non-zero if pull serial number enabled
InvertTXD As Byte 'non-zero if invert TXD
InvertRXD As Byte 'non-zero if invert RXD
InvertRTS As Byte 'non-zero if invert RTS
InvertCTS As Byte 'non-zero if invert CTS
InvertDTR As Byte 'non-zero if invert DTR
InvertDSR As Byte 'non-zero if invert DSR
InvertDCD As Byte 'non-zero if invert DCD
InvertRI As Byte 'non-zero if invert RI
Cbus0 As Byte 'Cbus Mux control
Cbus1 As Byte 'Cbus Mux control
Cbus2 As Byte 'Cbus Mux control
Cbus3 As Byte 'Cbus Mux control
Cbus4 As Byte 'Cbus Mux control
RIsVCP As Byte 'non-zero if using VCP driver
End Type
' Return codes
Const FT_OK = 0
Const FT_INVALID_HANDLE = 1
Const FT_DEVICE_NOT_FOUND = 2
Const FT_DEVICE_NOT_OPENED = 3
Const FT_IO_ERROR = 4
Const FT_INSUFFICIENT_RESOURCES = 5
Const FT_INVALID_PARAMETER = 6
Const FT_INVALID_BAUD_RATE = 7
Const FT_DEVICE_NOT_OPENED_FOR_ERASE = 8
Const FT_DEVICE_NOT_OPENED_FOR_WRITE = 9
Const FT_FAILED_TO_WRITE_DEVICE = 10
Const FT_EEPROM_READ_FAILED = 11
Const FT_EEPROM_WRITE_FAILED = 12
Const FT_EEPROM_ERASE_FAILED = 13
Const FT_EEPROM_NOT_PRESENT = 14
Const FT_EEPROM_NOT_PROGRAMMED = 15
Const FT_INVALID_ARGS = 16
Const FT_NOT_SUPPORTED = 17
Const FT_OTHER_ERROR = 18
' Word Lengths
Const FT_BITS_8 = 8
Const FT_BITS_7 = 7
' Stop Bits
Const FT_STOP_BITS_1 = 0
Const FT_STOP_BITS_1_5 = 1
Const FT_STOP_BITS_2 = 2
' Parity
Const FT_PARITY_NONE = 0
Const FT_PARITY_ODD = 1
Const FT_PARITY_EVEN = 2
Const FT_PARITY_MARK = 3
Const FT_PARITY_SPACE = 4
' Flow Control
Const FT_FLOW_NONE = &H0
Const FT_FLOW_RTS_CTS = &H100
Const FT_FLOW_DTR_DSR = &H200
Const FT_FLOW_XON_XOFF = &H400
' Purge rx and tx buffers
Const FT_PURGE_RX = 1
Const FT_PURGE_TX = 2
' Modem Status
Const FT_MODEM_STATUS_CTS = &H10
Const FT_MODEM_STATUS_DSR = &H20
Const FT_MODEM_STATUS_RI = &H40
Const FT_MODEM_STATUS_DCD = &H80
Const FT_EVENT_RXCHAR As Long = 1
Const FT_EVENT_MODEM_STATUS = 2
Const WAIT_ABANDONED As Long = &H80
Const WAIT_FAILD As Long = &HFFFFFFFF
Const WAIT_OBJECT_0 As Long = &H0
Const WAIT_TIMEOUT As Long = &H102
' Flags for FT_ListDevices
Const FT_LIST_BY_NUMBER_ONLY = &H80000000
Const FT_LIST_BY_INDEX = &H40000000
Const FT_LIST_ALL = &H20000000
' Flags for FT_OpenEx
Const FT_OPEN_BY_SERIAL_NUMBER = 1
Const FT_OPEN_BY_DESCRIPTION = 2
'Const INFINITE As Long = 1000 '&HFFFFFFFF
TypeDef FT_HANDLE = Long
Const FT_BITMODE_RESET = &H00
Const FT_BITMODE_ASYNC_BITBANG = &H01
Const FT_BITMODE_MPSSE = &H02
Const FT_BITMODE_SYNC_BITBANG = &H04
Const FT_BITMODE_MCU_HOST = &H08
Const FT_BITMODE_FAST_SERIAL = &H10
Const FT_BITMODE_CBUS_BITBANG = &H20
Const FT_BITMODE_SYNC_FIFO = &H40
Enum FTDI_MPSSE_COMMANDS
MPSSE_SET_TCK = &H86
MPSSE_SET_LOBYTE = &H80
MPSSE_SET_HIBYTE = &H82
MPSSE_READ_LOBYTE = &H81
MPSSE_READ_HIBYTE = &H83
End Enum