adept2_sys/dpcdecl.rs
1use std::os::raw::{c_char, c_int};
2
3pub type BOOL = c_int;
4
5/* ------------------------------------------------------------ */
6/* Miscellaneous Declarations */
7/* ------------------------------------------------------------ */
8
9pub const MAX_PATH: usize = 260; // this is the current windows definition
10
11/* ------------------------------------------------------------ */
12/* General Type Declarations */
13/* ------------------------------------------------------------ */
14
15/* These symbols define the maximum allowed length for various
16** strings used by the interfaces.
17*/
18pub const cchAliasMax: usize = 16; //max length of device table alias string
19pub const cchUsrNameMax: usize = 16; //max length of user settable device name
20pub const cchProdNameMax: usize = 28; //max length of product name string
21pub const cchSnMax: usize = 15; //length of a serial number string
22pub const cchVersionMax: usize = 256; //max length returned for DLL version string
23pub const cchDvcNameMax: usize = 64; //size of name field in DVC structure
24pub const cchDtpStringMax: usize = 16; //maximum length of DTP name string
25pub const cchErcMax: usize = 48; //maximum length of error code symbolic name
26pub const cchErcMsgMax: usize = 128; //maximum length of error message descriptive string
27
28/* The device management capabilities value indicates which device
29** management function sets are supported by the device. Device
30** management function sets apply to a device as a whole. For example,
31** the mgtcapPower capability indicates that the device supports the
32** power on/off capability.
33*/
34pub type MGTCAP = u32; // management capabilities
35
36/* The device interface capabilties value indicates which interface types
37** are supported by the device or being requested by the application.
38*/
39pub type DCAP = u32; //capabilities bitfield
40
41pub const dcapJtag: DCAP = 0x00000001; //this symbol is deprecated
42pub const dcapJtg: DCAP = 0x00000001;
43pub const dcapPio: DCAP = 0x00000002;
44pub const dcapEpp: DCAP = 0x00000004;
45pub const dcapStm: DCAP = 0x00000008;
46pub const dcapSpi: DCAP = 0x00000010;
47pub const dcapTwi: DCAP = 0x00000020;
48pub const dcapAci: DCAP = 0x00000040;
49pub const dcapAio: DCAP = 0x00000080;
50pub const dcapEmc: DCAP = 0x00000100;
51pub const dcapDci: DCAP = 0x00000200;
52pub const dcapGio: DCAP = 0x00000400;
53pub const dcapPti: DCAP = 0x00000800;
54
55pub const dcapAll: DCAP = 0xFFFFFFFF;
56
57/* The port properties values are used by each protocol type to
58** indicate details about the features supported by each individual
59** port. The type is declared here. The properties values are
60** defined in the protocol specific header files.
61*/
62pub type DPRP = u32;
63
64/* Device type indicates which physical transport and protocol are used to
65** access the device. The lower 16 bits are interpreted as a bitfield that
66** is used to specify the type of transport used by the device. The upper
67** 16 bits are interpreted as the protocol used to communicate with a
68** device of the specified transport type. Please note that specification
69** of the protocol is optional and if no protocol is specified then
70** communication with all devices of a particular transport type will be
71** attempted.
72*/
73pub type DTP = u32;
74
75pub const dtpUSB: DTP = 0x00000001;
76pub const dtpEthernet: DTP = 0x00000002;
77pub const dtpParallel: DTP = 0x00000004;
78pub const dtpSerial: DTP = 0x00000008;
79
80pub const dtpNone: DTP = 0x00000000;
81pub const dtpAll: DTP = 0xFFFFFFFF;
82pub const dtpNil: DTP = 0;
83
84pub type TPT = u16;
85
86pub const tptUSB: TPT = 0x0001;
87pub const tptEthernet: TPT = 0x0002;
88pub const tptParallel: TPT = 0x0004;
89pub const tptSerial: TPT = 0x0008;
90
91pub const tptNone: TPT = 0x0000;
92pub const tptAll: TPT = 0xFFFF;
93pub const tptNil: TPT = 0x0000;
94
95pub type PTC = u16;
96
97pub const ptcProtocol1: PTC = 0x0001;
98pub const ptcProtocol2: PTC = 0x0002;
99pub const ptcProtocol3: PTC = 0x0004;
100pub const ptcProtocol4: PTC = 0x0008;
101
102pub const ptcProtocol5: PTC = 0x0010;
103pub const ptcProtocol6: PTC = 0x0020;
104pub const ptcProtocol7: PTC = 0x0040;
105pub const ptcProtocol8: PTC = 0x0080;
106
107pub const ptcProtocol9: PTC = 0x0100;
108pub const ptcProtocol10: PTC = 0x0200;
109pub const ptcProtocol11: PTC = 0x0400;
110pub const ptcProtocol12: PTC = 0x0800;
111
112pub const ptcProtocol13: PTC = 0x1000;
113pub const ptcProtocol14: PTC = 0x2000;
114pub const ptcProtocol15: PTC = 0x4000;
115pub const ptcProtocol16: PTC = 0x8000;
116
117pub const ptcAll: PTC = 0x0000;
118pub const ptcNil: PTC = 0x0000;
119
120#[inline]
121pub unsafe fn TptFromDtp(dtp: DTP) -> TPT {
122 (dtp & 0xFFFF) as TPT
123}
124
125#[inline]
126pub unsafe fn PtcFromDtp(dtp: DTP) -> PTC {
127 ((dtp >> 16) & 0xFFFF) as PTC
128}
129
130#[inline]
131pub unsafe fn DtpFromTptPtc(tpt: TPT, ptc: PTC) -> DTP {
132 tpt as DTP | (ptc as DTP) << 16
133}
134
135/* Device interface handle.
136*/
137pub type HIF = u32;
138pub const hifInvalid: HIF = 0;
139
140/* These values are used to report various attributes of a device.
141*/
142pub type PDID = u32; // device product id
143pub type FWTYPE = u16;
144pub type FWVER = u16; // device firmware version number
145pub type FWID = u8; // device firmware identifier
146
147#[inline]
148pub unsafe fn ProductFromPdid(pdid: PDID) -> c_int {
149 ((pdid >> 20) & 0xFFF) as c_int
150}
151
152#[inline]
153pub unsafe fn VariantFromPdid(pdid: PDID) -> c_int {
154 ((pdid >> 8) & 0xFFF) as c_int
155}
156
157#[inline]
158pub unsafe fn FwidFromPdid(pdid: PDID) -> FWID {
159 (pdid & 0xFF) as FWID
160}
161
162/* These values are used to retrieve or set various information about
163** a device.
164*/
165pub type DINFO = u32;
166
167// public
168pub const dinfoNone: DINFO = 0;
169pub const dinfoAlias: DINFO = 1;
170pub const dinfoUsrName: DINFO = 2;
171pub const dinfoProdName: DINFO = 3;
172pub const dinfoPDID: DINFO = 4;
173pub const dinfoSN: DINFO = 5;
174pub const dinfoIP: DINFO = 6;
175pub const dinfoMAC: DINFO = 7; //Ethernet MAC and SN are the same
176pub const dinfoDCAP: DINFO = 9;
177pub const dinfoSerParam: DINFO = 10;
178pub const dinfoParAddr: DINFO = 11;
179pub const dinfoUsbPath: DINFO = 12;
180pub const dinfoProdID: DINFO = 13; // the ProductID from PDID
181pub const dinfoOpenCount: DINFO = 14; // how many times a device is opened
182pub const dinfoFWVER: DINFO = 15;
183
184/* Error codes
185*/
186pub type ERC = c_int;
187
188pub const ercNoErc: ERC = 0; // No error occurred
189
190// The following error codes can be directly mapped to the device error codes.
191pub const ercNotSupported: ERC = 1; // Capability or function not supported by the device
192pub const ercTransferCancelled: ERC = 2; // The transfer was cancelled or timeout occured
193pub const ercCapabilityConflict: ERC = 3; // Tried to enable capabilities that use shared resources, check device datasheet
194pub const ercCapabilityNotEnabled: ERC = 4; // The protocol is not enabled
195pub const ercEppAddressTimeout: ERC = 5; // EPP Address strobe timeout
196pub const ercEppDataTimeout: ERC = 6; // EPP Data strobe timeout
197pub const ercDataSndLess: ERC = 7; // Data send failed or peripheral did not received all the sent data
198pub const ercDataRcvLess: ERC = 8; // Data receive failed or peripheral sent less data
199pub const ercDataRcvMore: ERC = 9; // Peripheral sent more data
200pub const ercDataSndLessRcvLess: ERC = 10; // Two errors: ercDataSndLess and ercDataRcvLess
201pub const ercDataSndLessRcvMore: ERC = 11; // Two errors: ercDataSndLess and ercDataSndFailRcvMore
202pub const ercInvalidPort: ERC = 12; // Attempt to enable port when another port is already enabled
203pub const ercBadParameter: ERC = 13; // Command parameter out of range
204
205// ACI error codes, directly mapped to device error codes.
206pub const ercAciFifoFull: ERC = 0x20; // Transmit FIFO overflow
207
208// TWI error codes, directly mapped to device error codes.
209pub const ercTwiBadBatchCmd: ERC = 0x20; // Bad command in TWI batch buffer
210pub const ercTwiBusBusy: ERC = 0x21; // Timed out waiting for TWI bus
211pub const ercTwiAdrNak: ERC = 0x22; // TWI address not ack'd
212pub const ercTwiDataNak: ERC = 0x23; // TWI data not ack'd
213pub const ercTwiSmbPecError: ERC = 0x24; // Packet error when using packet error checking
214
215// Most likely the user did something wrong.
216pub const ercAlreadyOpened: ERC = 1024; // Device already opened
217pub const ercInvalidHif: ERC = 1025; // Invalid interface handle provided, fist call DmgrOpen(Ex)
218pub const ercInvalidParameter: ERC = 1026; // Invalid parameter sent in API call
219pub const ercTransferPending: ERC = 1031; // The last API called in overlapped mode was not finished. Use DmgrGetTransStat or DmgrCancelTrans
220pub const ercApiLockTimeout: ERC = 1032; // API waiting on pending API timed out
221pub const ercPortConflict: ERC = 1033; // Attempt to enable port when another port is already enabled
222
223// Not the user's fault.
224pub const ercConnectionFailed: ERC = 3072; // Unknown fail of connection
225pub const ercControlTransferFailed: ERC = 3075; // Control transfer failed
226pub const ercCmdSendFailed: ERC = 3076; // Command sending failed
227pub const ercStsReceiveFailed: ERC = 3077; // Status receiving failed
228pub const ercInsufficientResources: ERC = 3078; // Memory allocation failed, insufficient system resources
229pub const ercInvalidTFP: ERC = 3079; // Internal protocol error, DVT rejected the transfer strcuture sent by public API
230pub const ercInternalError: ERC = 3080; // Internal error
231pub const ercTooManyOpenedDevices: ERC = 3081; // Internal error
232pub const ercConfigFileError: ERC = 3082; // Processing of configuration file failed
233pub const ercDeviceNotConnected: ERC = 3083; // Device not connected
234
235pub const ercEnumNotFree: ERC = 3084; // Device Enumeration failed because another enumeration is still running.
236pub const ercEnumFreeFail: ERC = 3085; // Device Enumeration list could not be freed
237
238pub const ercInvalidDevice: ERC = 3086; // OEM ID check failed
239
240pub const ercDeviceBusy: ERC = 3087; // The device is currently claimed by another process.
241
242pub const ercCorruptInstallation: ERC = 3088; // One or more critical file is missing from the system.
243
244pub const ercDabsInitFailed: ERC = 3089; // Initialization of the DABS library failed
245pub const ercDpcommInitFailed: ERC = 3090; // Initialization of the DPCOMM library failed
246
247//ENUM errors
248
249//DVTBL errors
250
251/* ------------------------------------------------------------ */
252/* Data Structure Declarations */
253/* ------------------------------------------------------------ */
254
255#[repr(C)]
256pub struct DVC {
257 pub szName: [c_char; cchDvcNameMax],
258 //in dvctable: Alias
259 //not in dvctable: user assigned name in device
260 //not in dvctable, no user defined name: device type with identifier
261 pub szConn: [c_char; MAX_PATH + 1],
262 //in dvctable: connection string in dvctable
263 //not in dvctable: USB: PATHNAME
264 // Eth: IP:192.168.1.1
265 // Ser: COM1:9600,N,8,1
266 // EPP: EPP:0x378
267 pub dtp: DTP,
268}