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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/* automatically generated by rust-bindgen 0.59.1 */

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use std::os::raw;

pub const FALSE: u32 = 0;
pub const TRUE: u32 = 1;
pub const IOWKIT_VENDOR_ID: u32 = 1984;
pub const IOWKIT_VID: u32 = 1984;
pub const IOWKIT_PRODUCT_ID_IOW40: u32 = 5376;
pub const IOWKIT_PID_IOW40: u32 = 5376;
pub const IOWKIT_PRODUCT_ID_IOW24: u32 = 5377;
pub const IOWKIT_PID_IOW24: u32 = 5377;
pub const IOWKIT_PRODUCT_ID_IOW24_SENSI: u32 = 5514;
pub const IOWKIT_PID_IOW24_SENSI: u32 = 5514;
pub const IOWKIT_PRODUCT_ID_IOWPV1: u32 = 5393;
pub const IOWKIT_PID_IOWPV1: u32 = 5393;
pub const IOWKIT_PRODUCT_ID_IOWPV2: u32 = 5394;
pub const IOWKIT_PID_IOWPV2: u32 = 5394;
pub const IOWKIT_PRODUCT_ID_IOW56: u32 = 5379;
pub const IOWKIT_PID_IOW56: u32 = 5379;
pub const IOWKIT_PRODUCT_ID_IOW56_ALPHA: u32 = 5515;
pub const IOWKIT_PID_IOW56_ALPHA: u32 = 5515;
pub const IOWKIT_PRODUCT_ID_IOW28: u32 = 5380;
pub const IOWKIT_PID_IOW28: u32 = 5380;
pub const IOWKIT_PRODUCT_ID_IOW28L: u32 = 5381;
pub const IOWKIT_PID_IOW28L: u32 = 5381;
pub const IOWKIT_PRODUCT_ID_IOW100: u32 = 5382;
pub const IOWKIT_PID_IOW100: u32 = 5382;
pub const IOWKIT_PRODUCT_ID_TW: u32 = 5631;
pub const IOWKIT_PID_TW: u32 = 5631;
pub const IOWKIT_MAX_PIPES: u32 = 4;
pub const IOW_PIPE_IO_PINS: u32 = 0;
pub const IOW_PIPE_SPECIAL_MODE: u32 = 1;
pub const IOW_PIPE_I2C_MODE: u32 = 2;
pub const IOW_PIPE_ADC_MODE: u32 = 3;
pub const IOWKIT_MAX_DEVICES: u32 = 16;
pub const IOW_OPEN_SIMPLE: u32 = 1;
pub const IOW_OPEN_COMPLEX: u32 = 2;
pub const IOW_NON_LEGACY_REVISION: u32 = 4112;
pub type ULONG = raw::c_ulong;
pub type LONG = raw::c_long;
pub type USHORT = raw::c_ushort;
pub type WORD = raw::c_ushort;
pub type UCHAR = raw::c_uchar;
pub type BYTE = raw::c_uchar;
pub type PCHAR = *mut raw::c_char;
pub type PWCHAR = *mut raw::c_ushort;
pub type BOOL = raw::c_int;
pub type BOOLEAN = raw::c_uchar;
pub type DWORD = raw::c_ulong;
pub type PDWORD = *mut DWORD;
pub type PVOID = *mut raw::c_void;
pub type HANDLE = DWORD;
pub type PULONG = *mut ULONG;
pub type PCSTR = *const raw::c_char;
pub type PWCSTR = *const raw::c_ushort;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _IOWKIT_REPORT {
    pub ReportID: UCHAR,
    pub __bindgen_anon_1: _IOWKIT_REPORT__bindgen_ty_1,
}
#[repr(C, packed)]
#[derive(Copy, Clone)]
pub union _IOWKIT_REPORT__bindgen_ty_1 {
    pub Value: DWORD,
    pub Bytes: [BYTE; 4usize],
}
pub type IOWKIT_REPORT = _IOWKIT_REPORT;
pub type PIOWKIT_REPORT = *mut _IOWKIT_REPORT;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _IOWKIT40_IO_REPORT {
    pub ReportID: UCHAR,
    pub __bindgen_anon_1: _IOWKIT40_IO_REPORT__bindgen_ty_1,
}
#[repr(C, packed)]
#[derive(Copy, Clone)]
pub union _IOWKIT40_IO_REPORT__bindgen_ty_1 {
    pub Value: DWORD,
    pub Bytes: [BYTE; 4usize],
}
pub type IOWKIT40_IO_REPORT = _IOWKIT40_IO_REPORT;
pub type PIOWKIT40_IO_REPORT = *mut _IOWKIT40_IO_REPORT;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _IOWKIT24_IO_REPORT {
    pub ReportID: UCHAR,
    pub __bindgen_anon_1: _IOWKIT24_IO_REPORT__bindgen_ty_1,
}
#[repr(C, packed)]
#[derive(Copy, Clone)]
pub union _IOWKIT24_IO_REPORT__bindgen_ty_1 {
    pub Value: WORD,
    pub Bytes: [BYTE; 2usize],
}
pub type IOWKIT24_IO_REPORT = _IOWKIT24_IO_REPORT;
pub type PIOWKIT24_IO_REPORT = *mut _IOWKIT24_IO_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT_SPECIAL_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 7usize],
}
pub type IOWKIT_SPECIAL_REPORT = _IOWKIT_SPECIAL_REPORT;
pub type PIOWKIT_SPECIAL_REPORT = *mut _IOWKIT_SPECIAL_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT56_IO_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 7usize],
}
pub type IOWKIT56_IO_REPORT = _IOWKIT56_IO_REPORT;
pub type PIOWKIT56_IO_REPORT = *mut _IOWKIT56_IO_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT56_SPECIAL_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 63usize],
}
pub type IOWKIT56_SPECIAL_REPORT = _IOWKIT56_SPECIAL_REPORT;
pub type PIOWKIT56_SPECIAL_REPORT = *mut _IOWKIT56_SPECIAL_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT28_IO_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 4usize],
}
pub type IOWKIT28_IO_REPORT = _IOWKIT28_IO_REPORT;
pub type PIOWKIT28_IO_REPORT = *mut _IOWKIT28_IO_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT28_SPECIAL_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 63usize],
}
pub type IOWKIT28_SPECIAL_REPORT = _IOWKIT28_SPECIAL_REPORT;
pub type PIOWKIT28_SPECIAL_REPORT = *mut _IOWKIT28_SPECIAL_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT100_IO_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 12usize],
}
pub type IOWKIT100_IO_REPORT = _IOWKIT100_IO_REPORT;
pub type PIOWKIT100_IO_REPORT = *mut _IOWKIT100_IO_REPORT;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _IOWKIT100_SPECIAL_REPORT {
    pub ReportID: UCHAR,
    pub Bytes: [UCHAR; 63usize],
}
pub type IOWKIT100_SPECIAL_REPORT = _IOWKIT100_SPECIAL_REPORT;
pub type PIOWKIT100_SPECIAL_REPORT = *mut _IOWKIT100_SPECIAL_REPORT;
pub type IOWKIT_HANDLE = PVOID;
extern crate libloading;

#[derive(Debug)]
pub struct Iowkit {
    __library: ::libloading::Library,
    pub IowKitOpenDevice: Result<unsafe extern "C" fn() -> IOWKIT_HANDLE, ::libloading::Error>,
    pub IowKitCloseDevice:
        Result<unsafe extern "C" fn(devHandle: IOWKIT_HANDLE), ::libloading::Error>,
    pub IowKitWrite: Result<
        unsafe extern "C" fn(
            devHandle: IOWKIT_HANDLE,
            numPipe: ULONG,
            buffer: PCHAR,
            length: ULONG,
        ) -> ULONG,
        ::libloading::Error,
    >,
    pub IowKitRead: Result<
        unsafe extern "C" fn(
            devHandle: IOWKIT_HANDLE,
            numPipe: ULONG,
            buffer: PCHAR,
            length: ULONG,
        ) -> ULONG,
        ::libloading::Error,
    >,
    pub IowKitReadNonBlocking: Result<
        unsafe extern "C" fn(
            devHandle: IOWKIT_HANDLE,
            numPipe: ULONG,
            buffer: PCHAR,
            length: ULONG,
        ) -> ULONG,
        ::libloading::Error,
    >,
    pub IowKitReadImmediate: Result<
        unsafe extern "C" fn(devHandle: IOWKIT_HANDLE, value: PDWORD) -> BOOL,
        ::libloading::Error,
    >,
    pub IowKitGetNumDevs: Result<unsafe extern "C" fn() -> ULONG, ::libloading::Error>,
    pub IowKitGetDeviceHandle:
        Result<unsafe extern "C" fn(numDevice: ULONG) -> IOWKIT_HANDLE, ::libloading::Error>,
    pub IowKitSetLegacyOpenMode:
        Result<unsafe extern "C" fn(legacyOpenMode: ULONG) -> BOOL, ::libloading::Error>,
    pub IowKitGetProductId:
        Result<unsafe extern "C" fn(devHandle: IOWKIT_HANDLE) -> ULONG, ::libloading::Error>,
    pub IowKitGetRevision:
        Result<unsafe extern "C" fn(devHandle: IOWKIT_HANDLE) -> ULONG, ::libloading::Error>,
    pub IowKitGetThreadHandle:
        Result<unsafe extern "C" fn(devHandle: IOWKIT_HANDLE) -> HANDLE, ::libloading::Error>,
    pub IowKitGetSerialNumber: Result<
        unsafe extern "C" fn(devHandle: IOWKIT_HANDLE, serialNumber: PWCHAR) -> BOOL,
        ::libloading::Error,
    >,
    pub IowKitSetTimeout: Result<
        unsafe extern "C" fn(devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL,
        ::libloading::Error,
    >,
    pub IowKitSetWriteTimeout: Result<
        unsafe extern "C" fn(devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL,
        ::libloading::Error,
    >,
    pub IowKitCancelIo: Result<
        unsafe extern "C" fn(devHandle: IOWKIT_HANDLE, numPipe: ULONG) -> BOOL,
        ::libloading::Error,
    >,
    pub IowKitVersion: Result<unsafe extern "C" fn() -> PCSTR, ::libloading::Error>,
}
impl Iowkit {
    pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
    where
        P: AsRef<::std::ffi::OsStr>,
    {
        let library = ::libloading::Library::new(path)?;
        Self::from_library(library)
    }
    pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
    where
        L: Into<::libloading::Library>,
    {
        let __library = library.into();
        let IowKitOpenDevice = __library.get(b"IowKitOpenDevice\0").map(|sym| *sym);
        let IowKitCloseDevice = __library.get(b"IowKitCloseDevice\0").map(|sym| *sym);
        let IowKitWrite = __library.get(b"IowKitWrite\0").map(|sym| *sym);
        let IowKitRead = __library.get(b"IowKitRead\0").map(|sym| *sym);
        let IowKitReadNonBlocking = __library.get(b"IowKitReadNonBlocking\0").map(|sym| *sym);
        let IowKitReadImmediate = __library.get(b"IowKitReadImmediate\0").map(|sym| *sym);
        let IowKitGetNumDevs = __library.get(b"IowKitGetNumDevs\0").map(|sym| *sym);
        let IowKitGetDeviceHandle = __library.get(b"IowKitGetDeviceHandle\0").map(|sym| *sym);
        let IowKitSetLegacyOpenMode = __library.get(b"IowKitSetLegacyOpenMode\0").map(|sym| *sym);
        let IowKitGetProductId = __library.get(b"IowKitGetProductId\0").map(|sym| *sym);
        let IowKitGetRevision = __library.get(b"IowKitGetRevision\0").map(|sym| *sym);
        let IowKitGetThreadHandle = __library.get(b"IowKitGetThreadHandle\0").map(|sym| *sym);
        let IowKitGetSerialNumber = __library.get(b"IowKitGetSerialNumber\0").map(|sym| *sym);
        let IowKitSetTimeout = __library.get(b"IowKitSetTimeout\0").map(|sym| *sym);
        let IowKitSetWriteTimeout = __library.get(b"IowKitSetWriteTimeout\0").map(|sym| *sym);
        let IowKitCancelIo = __library.get(b"IowKitCancelIo\0").map(|sym| *sym);
        let IowKitVersion = __library.get(b"IowKitVersion\0").map(|sym| *sym);
        Ok(Iowkit {
            __library,
            IowKitOpenDevice,
            IowKitCloseDevice,
            IowKitWrite,
            IowKitRead,
            IowKitReadNonBlocking,
            IowKitReadImmediate,
            IowKitGetNumDevs,
            IowKitGetDeviceHandle,
            IowKitSetLegacyOpenMode,
            IowKitGetProductId,
            IowKitGetRevision,
            IowKitGetThreadHandle,
            IowKitGetSerialNumber,
            IowKitSetTimeout,
            IowKitSetWriteTimeout,
            IowKitCancelIo,
            IowKitVersion,
        })
    }
    pub unsafe fn IowKitOpenDevice(&self) -> IOWKIT_HANDLE {
        (self
            .IowKitOpenDevice
            .as_ref()
            .expect("Expected function, got error."))()
    }
    pub unsafe fn IowKitCloseDevice(&self, devHandle: IOWKIT_HANDLE) -> () {
        (self
            .IowKitCloseDevice
            .as_ref()
            .expect("Expected function, got error."))(devHandle)
    }
    pub unsafe fn IowKitWrite(
        &self,
        devHandle: IOWKIT_HANDLE,
        numPipe: ULONG,
        buffer: PCHAR,
        length: ULONG,
    ) -> ULONG {
        (self
            .IowKitWrite
            .as_ref()
            .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
    }
    pub unsafe fn IowKitRead(
        &self,
        devHandle: IOWKIT_HANDLE,
        numPipe: ULONG,
        buffer: PCHAR,
        length: ULONG,
    ) -> ULONG {
        (self
            .IowKitRead
            .as_ref()
            .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
    }
    pub unsafe fn IowKitReadNonBlocking(
        &self,
        devHandle: IOWKIT_HANDLE,
        numPipe: ULONG,
        buffer: PCHAR,
        length: ULONG,
    ) -> ULONG {
        (self
            .IowKitReadNonBlocking
            .as_ref()
            .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
    }
    pub unsafe fn IowKitReadImmediate(&self, devHandle: IOWKIT_HANDLE, value: PDWORD) -> BOOL {
        (self
            .IowKitReadImmediate
            .as_ref()
            .expect("Expected function, got error."))(devHandle, value)
    }
    pub unsafe fn IowKitGetNumDevs(&self) -> ULONG {
        (self
            .IowKitGetNumDevs
            .as_ref()
            .expect("Expected function, got error."))()
    }
    pub unsafe fn IowKitGetDeviceHandle(&self, numDevice: ULONG) -> IOWKIT_HANDLE {
        (self
            .IowKitGetDeviceHandle
            .as_ref()
            .expect("Expected function, got error."))(numDevice)
    }
    pub unsafe fn IowKitSetLegacyOpenMode(&self, legacyOpenMode: ULONG) -> BOOL {
        (self
            .IowKitSetLegacyOpenMode
            .as_ref()
            .expect("Expected function, got error."))(legacyOpenMode)
    }
    pub unsafe fn IowKitGetProductId(&self, devHandle: IOWKIT_HANDLE) -> ULONG {
        (self
            .IowKitGetProductId
            .as_ref()
            .expect("Expected function, got error."))(devHandle)
    }
    pub unsafe fn IowKitGetRevision(&self, devHandle: IOWKIT_HANDLE) -> ULONG {
        (self
            .IowKitGetRevision
            .as_ref()
            .expect("Expected function, got error."))(devHandle)
    }
    pub unsafe fn IowKitGetThreadHandle(&self, devHandle: IOWKIT_HANDLE) -> HANDLE {
        (self
            .IowKitGetThreadHandle
            .as_ref()
            .expect("Expected function, got error."))(devHandle)
    }
    pub unsafe fn IowKitGetSerialNumber(
        &self,
        devHandle: IOWKIT_HANDLE,
        serialNumber: PWCHAR,
    ) -> BOOL {
        (self
            .IowKitGetSerialNumber
            .as_ref()
            .expect("Expected function, got error."))(devHandle, serialNumber)
    }
    pub unsafe fn IowKitSetTimeout(&self, devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL {
        (self
            .IowKitSetTimeout
            .as_ref()
            .expect("Expected function, got error."))(devHandle, timeout)
    }
    pub unsafe fn IowKitSetWriteTimeout(&self, devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL {
        (self
            .IowKitSetWriteTimeout
            .as_ref()
            .expect("Expected function, got error."))(devHandle, timeout)
    }
    pub unsafe fn IowKitCancelIo(&self, devHandle: IOWKIT_HANDLE, numPipe: ULONG) -> BOOL {
        (self
            .IowKitCancelIo
            .as_ref()
            .expect("Expected function, got error."))(devHandle, numPipe)
    }
    pub unsafe fn IowKitVersion(&self) -> PCSTR {
        (self
            .IowKitVersion
            .as_ref()
            .expect("Expected function, got error."))()
    }
}