1#![allow(non_upper_case_globals)]
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6#![allow(dead_code)]
7use std::os::raw;
8
9pub const FALSE: u32 = 0;
10pub const TRUE: u32 = 1;
11pub const IOWKIT_VENDOR_ID: u32 = 1984;
12pub const IOWKIT_VID: u32 = 1984;
13pub const IOWKIT_PRODUCT_ID_IOW40: u32 = 5376;
14pub const IOWKIT_PID_IOW40: u32 = 5376;
15pub const IOWKIT_PRODUCT_ID_IOW24: u32 = 5377;
16pub const IOWKIT_PID_IOW24: u32 = 5377;
17pub const IOWKIT_PRODUCT_ID_IOW24_SENSI: u32 = 5514;
18pub const IOWKIT_PID_IOW24_SENSI: u32 = 5514;
19pub const IOWKIT_PRODUCT_ID_IOWPV1: u32 = 5393;
20pub const IOWKIT_PID_IOWPV1: u32 = 5393;
21pub const IOWKIT_PRODUCT_ID_IOWPV2: u32 = 5394;
22pub const IOWKIT_PID_IOWPV2: u32 = 5394;
23pub const IOWKIT_PRODUCT_ID_IOW56: u32 = 5379;
24pub const IOWKIT_PID_IOW56: u32 = 5379;
25pub const IOWKIT_PRODUCT_ID_IOW56_ALPHA: u32 = 5515;
26pub const IOWKIT_PID_IOW56_ALPHA: u32 = 5515;
27pub const IOWKIT_PRODUCT_ID_IOW28: u32 = 5380;
28pub const IOWKIT_PID_IOW28: u32 = 5380;
29pub const IOWKIT_PRODUCT_ID_IOW28L: u32 = 5381;
30pub const IOWKIT_PID_IOW28L: u32 = 5381;
31pub const IOWKIT_PRODUCT_ID_IOW100: u32 = 5382;
32pub const IOWKIT_PID_IOW100: u32 = 5382;
33pub const IOWKIT_PRODUCT_ID_TW: u32 = 5631;
34pub const IOWKIT_PID_TW: u32 = 5631;
35pub const IOWKIT_MAX_PIPES: u32 = 4;
36pub const IOW_PIPE_IO_PINS: u32 = 0;
37pub const IOW_PIPE_SPECIAL_MODE: u32 = 1;
38pub const IOW_PIPE_I2C_MODE: u32 = 2;
39pub const IOW_PIPE_ADC_MODE: u32 = 3;
40pub const IOWKIT_MAX_DEVICES: u32 = 16;
41pub const IOW_OPEN_SIMPLE: u32 = 1;
42pub const IOW_OPEN_COMPLEX: u32 = 2;
43pub const IOW_NON_LEGACY_REVISION: u32 = 4112;
44pub type ULONG = raw::c_ulong;
45pub type LONG = raw::c_long;
46pub type USHORT = raw::c_ushort;
47pub type WORD = raw::c_ushort;
48pub type UCHAR = raw::c_uchar;
49pub type BYTE = raw::c_uchar;
50pub type PCHAR = *mut raw::c_char;
51pub type PWCHAR = *mut raw::c_ushort;
52pub type BOOL = raw::c_int;
53pub type BOOLEAN = raw::c_uchar;
54pub type DWORD = raw::c_ulong;
55pub type PDWORD = *mut DWORD;
56pub type PVOID = *mut raw::c_void;
57pub type HANDLE = DWORD;
58pub type PULONG = *mut ULONG;
59pub type PCSTR = *const raw::c_char;
60pub type PWCSTR = *const raw::c_ushort;
61#[repr(C)]
62#[derive(Copy, Clone)]
63pub struct _IOWKIT_REPORT {
64 pub ReportID: UCHAR,
65 pub __bindgen_anon_1: _IOWKIT_REPORT__bindgen_ty_1,
66}
67#[repr(C, packed)]
68#[derive(Copy, Clone)]
69pub union _IOWKIT_REPORT__bindgen_ty_1 {
70 pub Value: DWORD,
71 pub Bytes: [BYTE; 4usize],
72}
73pub type IOWKIT_REPORT = _IOWKIT_REPORT;
74pub type PIOWKIT_REPORT = *mut _IOWKIT_REPORT;
75#[repr(C)]
76#[derive(Copy, Clone)]
77pub struct _IOWKIT40_IO_REPORT {
78 pub ReportID: UCHAR,
79 pub __bindgen_anon_1: _IOWKIT40_IO_REPORT__bindgen_ty_1,
80}
81#[repr(C, packed)]
82#[derive(Copy, Clone)]
83pub union _IOWKIT40_IO_REPORT__bindgen_ty_1 {
84 pub Value: DWORD,
85 pub Bytes: [BYTE; 4usize],
86}
87pub type IOWKIT40_IO_REPORT = _IOWKIT40_IO_REPORT;
88pub type PIOWKIT40_IO_REPORT = *mut _IOWKIT40_IO_REPORT;
89#[repr(C)]
90#[derive(Copy, Clone)]
91pub struct _IOWKIT24_IO_REPORT {
92 pub ReportID: UCHAR,
93 pub __bindgen_anon_1: _IOWKIT24_IO_REPORT__bindgen_ty_1,
94}
95#[repr(C, packed)]
96#[derive(Copy, Clone)]
97pub union _IOWKIT24_IO_REPORT__bindgen_ty_1 {
98 pub Value: WORD,
99 pub Bytes: [BYTE; 2usize],
100}
101pub type IOWKIT24_IO_REPORT = _IOWKIT24_IO_REPORT;
102pub type PIOWKIT24_IO_REPORT = *mut _IOWKIT24_IO_REPORT;
103#[repr(C)]
104#[derive(Debug, Copy, Clone)]
105pub struct _IOWKIT_SPECIAL_REPORT {
106 pub ReportID: UCHAR,
107 pub Bytes: [UCHAR; 7usize],
108}
109pub type IOWKIT_SPECIAL_REPORT = _IOWKIT_SPECIAL_REPORT;
110pub type PIOWKIT_SPECIAL_REPORT = *mut _IOWKIT_SPECIAL_REPORT;
111#[repr(C)]
112#[derive(Debug, Copy, Clone)]
113pub struct _IOWKIT56_IO_REPORT {
114 pub ReportID: UCHAR,
115 pub Bytes: [UCHAR; 7usize],
116}
117pub type IOWKIT56_IO_REPORT = _IOWKIT56_IO_REPORT;
118pub type PIOWKIT56_IO_REPORT = *mut _IOWKIT56_IO_REPORT;
119#[repr(C)]
120#[derive(Debug, Copy, Clone)]
121pub struct _IOWKIT56_SPECIAL_REPORT {
122 pub ReportID: UCHAR,
123 pub Bytes: [UCHAR; 63usize],
124}
125pub type IOWKIT56_SPECIAL_REPORT = _IOWKIT56_SPECIAL_REPORT;
126pub type PIOWKIT56_SPECIAL_REPORT = *mut _IOWKIT56_SPECIAL_REPORT;
127#[repr(C)]
128#[derive(Debug, Copy, Clone)]
129pub struct _IOWKIT28_IO_REPORT {
130 pub ReportID: UCHAR,
131 pub Bytes: [UCHAR; 4usize],
132}
133pub type IOWKIT28_IO_REPORT = _IOWKIT28_IO_REPORT;
134pub type PIOWKIT28_IO_REPORT = *mut _IOWKIT28_IO_REPORT;
135#[repr(C)]
136#[derive(Debug, Copy, Clone)]
137pub struct _IOWKIT28_SPECIAL_REPORT {
138 pub ReportID: UCHAR,
139 pub Bytes: [UCHAR; 63usize],
140}
141pub type IOWKIT28_SPECIAL_REPORT = _IOWKIT28_SPECIAL_REPORT;
142pub type PIOWKIT28_SPECIAL_REPORT = *mut _IOWKIT28_SPECIAL_REPORT;
143#[repr(C)]
144#[derive(Debug, Copy, Clone)]
145pub struct _IOWKIT100_IO_REPORT {
146 pub ReportID: UCHAR,
147 pub Bytes: [UCHAR; 12usize],
148}
149pub type IOWKIT100_IO_REPORT = _IOWKIT100_IO_REPORT;
150pub type PIOWKIT100_IO_REPORT = *mut _IOWKIT100_IO_REPORT;
151#[repr(C)]
152#[derive(Debug, Copy, Clone)]
153pub struct _IOWKIT100_SPECIAL_REPORT {
154 pub ReportID: UCHAR,
155 pub Bytes: [UCHAR; 63usize],
156}
157pub type IOWKIT100_SPECIAL_REPORT = _IOWKIT100_SPECIAL_REPORT;
158pub type PIOWKIT100_SPECIAL_REPORT = *mut _IOWKIT100_SPECIAL_REPORT;
159pub type IOWKIT_HANDLE = PVOID;
160extern crate libloading;
161
162#[derive(Debug)]
163pub struct Iowkit {
164 __library: ::libloading::Library,
165 pub IowKitOpenDevice: Result<unsafe extern "system" fn() -> IOWKIT_HANDLE, ::libloading::Error>,
166 pub IowKitCloseDevice:
167 Result<unsafe extern "system" fn(devHandle: IOWKIT_HANDLE), ::libloading::Error>,
168 pub IowKitWrite: Result<
169 unsafe extern "system" fn(
170 devHandle: IOWKIT_HANDLE,
171 numPipe: ULONG,
172 buffer: PCHAR,
173 length: ULONG,
174 ) -> ULONG,
175 ::libloading::Error,
176 >,
177 pub IowKitRead: Result<
178 unsafe extern "system" fn(
179 devHandle: IOWKIT_HANDLE,
180 numPipe: ULONG,
181 buffer: PCHAR,
182 length: ULONG,
183 ) -> ULONG,
184 ::libloading::Error,
185 >,
186 pub IowKitReadNonBlocking: Result<
187 unsafe extern "system" fn(
188 devHandle: IOWKIT_HANDLE,
189 numPipe: ULONG,
190 buffer: PCHAR,
191 length: ULONG,
192 ) -> ULONG,
193 ::libloading::Error,
194 >,
195 pub IowKitReadImmediate: Result<
196 unsafe extern "system" fn(devHandle: IOWKIT_HANDLE, value: PDWORD) -> BOOL,
197 ::libloading::Error,
198 >,
199 pub IowKitGetNumDevs: Result<unsafe extern "system" fn() -> ULONG, ::libloading::Error>,
200 pub IowKitGetDeviceHandle:
201 Result<unsafe extern "system" fn(numDevice: ULONG) -> IOWKIT_HANDLE, ::libloading::Error>,
202 pub IowKitSetLegacyOpenMode:
203 Result<unsafe extern "system" fn(legacyOpenMode: ULONG) -> BOOL, ::libloading::Error>,
204 pub IowKitGetProductId:
205 Result<unsafe extern "system" fn(devHandle: IOWKIT_HANDLE) -> ULONG, ::libloading::Error>,
206 pub IowKitGetRevision:
207 Result<unsafe extern "system" fn(devHandle: IOWKIT_HANDLE) -> ULONG, ::libloading::Error>,
208 pub IowKitGetThreadHandle:
209 Result<unsafe extern "system" fn(devHandle: IOWKIT_HANDLE) -> HANDLE, ::libloading::Error>,
210 pub IowKitGetSerialNumber: Result<
211 unsafe extern "system" fn(devHandle: IOWKIT_HANDLE, serialNumber: PWCHAR) -> BOOL,
212 ::libloading::Error,
213 >,
214 pub IowKitSetTimeout: Result<
215 unsafe extern "system" fn(devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL,
216 ::libloading::Error,
217 >,
218 pub IowKitSetWriteTimeout: Result<
219 unsafe extern "system" fn(devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL,
220 ::libloading::Error,
221 >,
222 pub IowKitCancelIo: Result<
223 unsafe extern "system" fn(devHandle: IOWKIT_HANDLE, numPipe: ULONG) -> BOOL,
224 ::libloading::Error,
225 >,
226 pub IowKitVersion: Result<unsafe extern "system" fn() -> PCSTR, ::libloading::Error>,
227}
228impl Iowkit {
229 pub unsafe fn new<P>(path: P) -> Result<Self, ::libloading::Error>
230 where
231 P: AsRef<::std::ffi::OsStr>,
232 {
233 let library = ::libloading::Library::new(path)?;
234 Self::from_library(library)
235 }
236 pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
237 where
238 L: Into<::libloading::Library>,
239 {
240 let __library = library.into();
241 let IowKitOpenDevice = __library.get(b"IowKitOpenDevice\0").map(|sym| *sym);
242 let IowKitCloseDevice = __library.get(b"IowKitCloseDevice\0").map(|sym| *sym);
243 let IowKitWrite = __library.get(b"IowKitWrite\0").map(|sym| *sym);
244 let IowKitRead = __library.get(b"IowKitRead\0").map(|sym| *sym);
245 let IowKitReadNonBlocking = __library.get(b"IowKitReadNonBlocking\0").map(|sym| *sym);
246 let IowKitReadImmediate = __library.get(b"IowKitReadImmediate\0").map(|sym| *sym);
247 let IowKitGetNumDevs = __library.get(b"IowKitGetNumDevs\0").map(|sym| *sym);
248 let IowKitGetDeviceHandle = __library.get(b"IowKitGetDeviceHandle\0").map(|sym| *sym);
249 let IowKitSetLegacyOpenMode = __library.get(b"IowKitSetLegacyOpenMode\0").map(|sym| *sym);
250 let IowKitGetProductId = __library.get(b"IowKitGetProductId\0").map(|sym| *sym);
251 let IowKitGetRevision = __library.get(b"IowKitGetRevision\0").map(|sym| *sym);
252 let IowKitGetThreadHandle = __library.get(b"IowKitGetThreadHandle\0").map(|sym| *sym);
253 let IowKitGetSerialNumber = __library.get(b"IowKitGetSerialNumber\0").map(|sym| *sym);
254 let IowKitSetTimeout = __library.get(b"IowKitSetTimeout\0").map(|sym| *sym);
255 let IowKitSetWriteTimeout = __library.get(b"IowKitSetWriteTimeout\0").map(|sym| *sym);
256 let IowKitCancelIo = __library.get(b"IowKitCancelIo\0").map(|sym| *sym);
257 let IowKitVersion = __library.get(b"IowKitVersion\0").map(|sym| *sym);
258 Ok(Iowkit {
259 __library,
260 IowKitOpenDevice,
261 IowKitCloseDevice,
262 IowKitWrite,
263 IowKitRead,
264 IowKitReadNonBlocking,
265 IowKitReadImmediate,
266 IowKitGetNumDevs,
267 IowKitGetDeviceHandle,
268 IowKitSetLegacyOpenMode,
269 IowKitGetProductId,
270 IowKitGetRevision,
271 IowKitGetThreadHandle,
272 IowKitGetSerialNumber,
273 IowKitSetTimeout,
274 IowKitSetWriteTimeout,
275 IowKitCancelIo,
276 IowKitVersion,
277 })
278 }
279 pub unsafe fn IowKitOpenDevice(&self) -> IOWKIT_HANDLE {
280 (self
281 .IowKitOpenDevice
282 .as_ref()
283 .expect("Expected function, got error."))()
284 }
285 pub unsafe fn IowKitCloseDevice(&self, devHandle: IOWKIT_HANDLE) -> () {
286 (self
287 .IowKitCloseDevice
288 .as_ref()
289 .expect("Expected function, got error."))(devHandle)
290 }
291 pub unsafe fn IowKitWrite(
292 &self,
293 devHandle: IOWKIT_HANDLE,
294 numPipe: ULONG,
295 buffer: PCHAR,
296 length: ULONG,
297 ) -> ULONG {
298 (self
299 .IowKitWrite
300 .as_ref()
301 .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
302 }
303 pub unsafe fn IowKitRead(
304 &self,
305 devHandle: IOWKIT_HANDLE,
306 numPipe: ULONG,
307 buffer: PCHAR,
308 length: ULONG,
309 ) -> ULONG {
310 (self
311 .IowKitRead
312 .as_ref()
313 .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
314 }
315 pub unsafe fn IowKitReadNonBlocking(
316 &self,
317 devHandle: IOWKIT_HANDLE,
318 numPipe: ULONG,
319 buffer: PCHAR,
320 length: ULONG,
321 ) -> ULONG {
322 (self
323 .IowKitReadNonBlocking
324 .as_ref()
325 .expect("Expected function, got error."))(devHandle, numPipe, buffer, length)
326 }
327 pub unsafe fn IowKitReadImmediate(&self, devHandle: IOWKIT_HANDLE, value: PDWORD) -> BOOL {
328 (self
329 .IowKitReadImmediate
330 .as_ref()
331 .expect("Expected function, got error."))(devHandle, value)
332 }
333 pub unsafe fn IowKitGetNumDevs(&self) -> ULONG {
334 (self
335 .IowKitGetNumDevs
336 .as_ref()
337 .expect("Expected function, got error."))()
338 }
339 pub unsafe fn IowKitGetDeviceHandle(&self, numDevice: ULONG) -> IOWKIT_HANDLE {
340 (self
341 .IowKitGetDeviceHandle
342 .as_ref()
343 .expect("Expected function, got error."))(numDevice)
344 }
345 pub unsafe fn IowKitSetLegacyOpenMode(&self, legacyOpenMode: ULONG) -> BOOL {
346 (self
347 .IowKitSetLegacyOpenMode
348 .as_ref()
349 .expect("Expected function, got error."))(legacyOpenMode)
350 }
351 pub unsafe fn IowKitGetProductId(&self, devHandle: IOWKIT_HANDLE) -> ULONG {
352 (self
353 .IowKitGetProductId
354 .as_ref()
355 .expect("Expected function, got error."))(devHandle)
356 }
357 pub unsafe fn IowKitGetRevision(&self, devHandle: IOWKIT_HANDLE) -> ULONG {
358 (self
359 .IowKitGetRevision
360 .as_ref()
361 .expect("Expected function, got error."))(devHandle)
362 }
363 pub unsafe fn IowKitGetThreadHandle(&self, devHandle: IOWKIT_HANDLE) -> HANDLE {
364 (self
365 .IowKitGetThreadHandle
366 .as_ref()
367 .expect("Expected function, got error."))(devHandle)
368 }
369 pub unsafe fn IowKitGetSerialNumber(
370 &self,
371 devHandle: IOWKIT_HANDLE,
372 serialNumber: PWCHAR,
373 ) -> BOOL {
374 (self
375 .IowKitGetSerialNumber
376 .as_ref()
377 .expect("Expected function, got error."))(devHandle, serialNumber)
378 }
379 pub unsafe fn IowKitSetTimeout(&self, devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL {
380 (self
381 .IowKitSetTimeout
382 .as_ref()
383 .expect("Expected function, got error."))(devHandle, timeout)
384 }
385 pub unsafe fn IowKitSetWriteTimeout(&self, devHandle: IOWKIT_HANDLE, timeout: ULONG) -> BOOL {
386 (self
387 .IowKitSetWriteTimeout
388 .as_ref()
389 .expect("Expected function, got error."))(devHandle, timeout)
390 }
391 pub unsafe fn IowKitCancelIo(&self, devHandle: IOWKIT_HANDLE, numPipe: ULONG) -> BOOL {
392 (self
393 .IowKitCancelIo
394 .as_ref()
395 .expect("Expected function, got error."))(devHandle, numPipe)
396 }
397 pub unsafe fn IowKitVersion(&self) -> PCSTR {
398 (self
399 .IowKitVersion
400 .as_ref()
401 .expect("Expected function, got error."))()
402 }
403}