-
Notifications
You must be signed in to change notification settings - Fork 585
/
FtFunction.cs
680 lines (600 loc) · 33.2 KB
/
FtFunction.cs
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.InteropServices;
using Iot.Device.FtCommon;
namespace Iot.Device.Ft4222
{
/// <summary>
/// Imports for the ftd2xx.dll as well as libft4222
/// </summary>
internal class FtFunction
{
#region ftd2xx wrapper
/// <summary>
/// Create Device Information List
/// </summary>
/// <param name="numdevs">number of devices</param>
/// <returns>The status</returns>
public static FtStatus FT_CreateDeviceInfoList(out uint numdevs)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return FT_CreateDeviceInfoListLinux(out numdevs);
}
return FT_CreateDeviceInfoListWin(out numdevs);
}
/// <summary>
/// Get Device Information Detail
/// </summary>
/// <param name="index">Index of the device</param>
/// <param name="flags">Flags</param>
/// <param name="chiptype">Device type</param>
/// <param name="id">ID</param>
/// <param name="locid">Location ID</param>
/// <param name="serialnumber">Serial Number</param>
/// <param name="description">Description</param>
/// <param name="ftHandle">Handle</param>
/// <returns>The status</returns>
public static FtStatus FT_GetDeviceInfoDetail(uint index, out uint flags, out FtDeviceType chiptype, out uint id, out uint locid, in byte serialnumber, in byte description, out IntPtr ftHandle)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return FT_GetDeviceInfoDetailLinux(index, out flags, out chiptype, out id, out locid, in serialnumber, in description, out ftHandle);
}
return FT_GetDeviceInfoDetailWin(index, out flags, out chiptype, out id, out locid, in serialnumber, in description, out ftHandle);
}
/// <summary>
/// Open a device
/// </summary>
/// <param name="pvArg1">The device element identifying the device, depends on the flag</param>
/// <param name="dwFlags">The flag how to open the device</param>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
public static FtStatus FT_OpenEx(uint pvArg1, FtOpenType dwFlags, out SafeFtHandle ftHandle)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return FT_OpenExLinux(pvArg1, dwFlags, out ftHandle);
}
return FT_OpenExWin(pvArg1, dwFlags, out ftHandle);
}
/// <summary>
/// Close the device
/// </summary>
/// <param name="ftHandle">The device handle</param>
/// <returns>The status</returns>
public static FtStatus FT_Close(IntPtr ftHandle)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
return FT_CloseLinux(ftHandle);
}
return FT_CloseWin(ftHandle);
}
#endregion
#region Linux ftd2xx
/// <summary>
/// Create Device Information List
/// </summary>
/// <param name="numdevs">number of devices</param>
/// <returns>The status</returns>
[DllImport("libft4222", EntryPoint = "FT_CreateDeviceInfoList")]
private static extern FtStatus FT_CreateDeviceInfoListLinux(out uint numdevs);
/// <summary>
/// Get Device Information Detail
/// </summary>
/// <param name="index">Index of the device</param>
/// <param name="flags">Flags</param>
/// <param name="chiptype">Device type</param>
/// <param name="id">ID</param>
/// <param name="locid">Location ID</param>
/// <param name="serialnumber">Serial Number</param>
/// <param name="description">Description</param>
/// <param name="ftHandle">Handle</param>
/// <returns>The status</returns>
[DllImport("libft4222", EntryPoint = "FT_GetDeviceInfoDetail")]
private static extern FtStatus FT_GetDeviceInfoDetailLinux(uint index, out uint flags, out FtDeviceType chiptype, out uint id, out uint locid, in byte serialnumber, in byte description, out IntPtr ftHandle);
/// <summary>
/// Open a device
/// </summary>
/// <param name="pvArg1">The device element identifying the device, depends on the flag</param>
/// <param name="dwFlags">The flag how to open the device</param>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", EntryPoint = "FT_OpenEx")]
private static extern FtStatus FT_OpenExLinux(uint pvArg1, FtOpenType dwFlags, out SafeFtHandle ftHandle);
/// <summary>
/// Close the device
/// </summary>
/// <param name="ftHandle">The device handle</param>
/// <returns>The status</returns>
[DllImport("libft4222", EntryPoint = "FT_Close")]
private static extern FtStatus FT_CloseLinux(IntPtr ftHandle);
#endregion
#region Windows ftd2xx
/// <summary>
/// Create Device Information List
/// </summary>
/// <param name="numdevs">number of devices</param>
/// <returns>The status</returns>
[DllImport("ftd2xx", EntryPoint = "FT_CreateDeviceInfoList")]
private static extern FtStatus FT_CreateDeviceInfoListWin(out uint numdevs);
/// <summary>
/// Get Device Information Detail
/// </summary>
/// <param name="index">Index of the device</param>
/// <param name="flags">Flags</param>
/// <param name="chiptype">Device type</param>
/// <param name="id">ID</param>
/// <param name="locid">Location ID</param>
/// <param name="serialnumber">Serial Number</param>
/// <param name="description">Description</param>
/// <param name="ftHandle">Handle</param>
/// <returns>The status</returns>
[DllImport("ftd2xx", EntryPoint = "FT_GetDeviceInfoDetail")]
private static extern FtStatus FT_GetDeviceInfoDetailWin(uint index, out uint flags, out FtDeviceType chiptype, out uint id, out uint locid, in byte serialnumber, in byte description, out IntPtr ftHandle);
/// <summary>
/// Open a device
/// </summary>
/// <param name="pvArg1">The device element identifying the device, depends on the flag</param>
/// <param name="dwFlags">The flag how to open the device</param>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("ftd2xx", EntryPoint = "FT_OpenEx")]
private static extern FtStatus FT_OpenExWin(uint pvArg1, FtOpenType dwFlags, out SafeFtHandle ftHandle);
/// <summary>
/// Close the device
/// </summary>
/// <param name="ftHandle">The device handle</param>
/// <returns>The status</returns>
[DllImport("ftd2xx", EntryPoint = "FT_Close")]
private static extern FtStatus FT_CloseWin(IntPtr ftHandle);
#endregion
#region libft4222 common functions
/// <summary>
/// Uninitialize a device, call before closing the device
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_UnInitialize(IntPtr ftHandle);
/// <summary>
/// Set the device system clock
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="clk">The system clock rate</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SetClock(SafeFtHandle ftHandle, FtClockRate clk);
/// <summary>
/// Get the system clock
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="clk">The system clock rate</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GetClock(SafeFtHandle ftHandle, out FtClockRate clk);
/// <summary>
/// Set the Wake Up Interrupt
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="enable">True to enable, false to disable</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SetWakeUpInterrupt(SafeFtHandle ftHandle, bool enable);
/// <summary>
/// Set Interrupt Trigger
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="trigger">The trigger type</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SetInterruptTrigger(SafeFtHandle ftHandle, GpioTrigger trigger);
/// <summary>
/// Set Suspend Out
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="enable">True to enable, false to disable</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SetSuspendOut(SafeFtHandle ftHandle, bool enable);
/// <summary>
/// Get the maximum transfer buffer size thru USB
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="pMaxSize">the maximum size in bytes</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GetMaxTransferSize(SafeFtHandle ftHandle, out ushort pMaxSize);
/// <summary>
/// Set event notification
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="mask">Event mask</param>
/// <param name="param">Event Parameter</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SetEventNotification(SafeFtHandle ftHandle, ulong mask, IntPtr param);
/// <summary>
/// Get the version of the chip and dll
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="pVersion">A version structure</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GetVersion(SafeFtHandle ftHandle, out FtVersion pVersion);
/// <summary>
/// Reset the chipset
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_ChipReset(SafeFtHandle ftHandle);
#endregion
#region SPI
/// <summary>
/// Initialize the chip SPI as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="ioLine">The operation mode, none, single, dual or quad</param>
/// <param name="clock">The SPI clock divider of the system clock</param>
/// <param name="cpol">The clock polarity</param>
/// <param name="cpha">The clock phase</param>
/// <param name="ssoMap">The chip select starting by 0x01</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_Init(SafeFtHandle ftHandle, SpiOperatingMode ioLine, SpiClock clock, SpiClockPolarity cpol, SpiClockPhase cpha, byte ssoMap);
/// <summary>
/// Set the operation mode for SPI as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="spiMode">The operation mode, none, single, dual or quad</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_SetLines(SafeFtHandle ftHandle, SpiOperatingMode spiMode);
/// <summary>
/// Operate a single SPI read as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The output read buffer</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeOfRead">Number of bytes read</param>
/// <param name="isEndTransaction">True if this is the final SPI transaction</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_SingleRead(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeOfRead, bool isEndTransaction);
/// <summary>
/// Operate a single SPI write as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the buffer</param>
/// <param name="isEndTransaction">True if this is the final SPI transaction</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_SingleWrite(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeTransferred, bool isEndTransaction);
/// <summary>
/// Operate a single read and write SPI operation as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="readBuffer">The output read buffer</param>
/// <param name="writeBuffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of buffer to transfer</param>
/// <param name="isEndTransaction">True if this is the final SPI transaction</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_SingleReadWrite(SafeFtHandle ftHandle, in byte readBuffer, in byte writeBuffer, ushort bufferSize, out ushort sizeTransferred, bool isEndTransaction);
/// <summary>
/// Operate multiple read and write SPI operations as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="readBuffer">The output read buffer</param>
/// <param name="writeBuffer">The buffer to write</param>
/// <param name="singleWriteBytes">singleWriteBytes</param>
/// <param name="multiWriteBytes">multiWriteBytes</param>
/// <param name="multiReadBytes">multiReadBytes</param>
/// <param name="sizeOfRead">The size of the read buffer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPIMaster_MultiReadWrite(SafeFtHandle ftHandle, in byte readBuffer, in byte writeBuffer, byte singleWriteBytes, ushort multiWriteBytes, ushort multiReadBytes, out uint sizeOfRead);
/// <summary>
/// Initialize the chipset as a SPI replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_Init(SafeFtHandle ftHandle);
/// <summary>
/// Initialize the chipset as a SPI replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="protocolOpt">Initialize with, without protocol or never send the acknowledge</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_InitEx(SafeFtHandle ftHandle, SpiReplicaProtocol protocolOpt);
/// <summary>
/// Set SPI as replica clock modes
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="cpol">The clock polarity</param>
/// <param name="cpha">The clock phase</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_SetMode(SafeFtHandle ftHandle, SpiClockPolarity cpol, SpiClockPhase cpha);
/// <summary>
/// Get the SPI as salve RX status
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="pRxSize">The RX size</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_GetRxStatus(SafeFtHandle ftHandle, out ushort pRxSize);
/// <summary>
/// Operate a SPI read as replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The output read buffer</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeOfRead">The size of the read buffer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_Read(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeOfRead);
/// <summary>
/// Operate a SPI write as a replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size what has been sent</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_Write(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Get or set the SPI as replica Rx quick response
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="enable">True to enable it, false to disable it</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPISlave_RxQuickResponse(SafeFtHandle ftHandle, bool enable);
/// <summary>
/// Reset the SPI
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPI_Reset(SafeFtHandle ftHandle);
/// <summary>
/// Reset a specific SPI transaction ID
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="spiIdx">The SPI ID</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPI_ResetTransaction(SafeFtHandle ftHandle, byte spiIdx);
/// <summary>
/// Set the intensity of the pin out on SPI
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="clkStrength">The intensity of the clock pin</param>
/// <param name="ioStrength">The intensity of the SDO and SDI pins</param>
/// <param name="ssoStrength">The intensity of the chip select pin</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_SPI_SetDrivingStrength(SafeFtHandle ftHandle, PinDrivingStrength clkStrength, PinDrivingStrength ioStrength, PinDrivingStrength ssoStrength);
#endregion
#region I2C
/// <summary>
/// Initialize the chip as an I2C master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="kbps">ency in kilo Hertz</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_Init(SafeFtHandle ftHandle, uint kbps);
/// <summary>
/// Operate an I2C read as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="deviceAddress">The device address</param>
/// <param name="buffer">The output read buffer</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_Read(SafeFtHandle ftHandle, ushort deviceAddress, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Operate an I2C write as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="deviceAddress">The device address</param>
/// <param name="buffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_Write(SafeFtHandle ftHandle, ushort deviceAddress, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Operate an I2C read as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="deviceAddress">The device address to read</param>
/// <param name="flag">flag</param>
/// <param name="buffer">The output read buffer</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_ReadEx(SafeFtHandle ftHandle, ushort deviceAddress, byte flag, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Operate an I2C write as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="deviceAddress">The device address to read</param>
/// <param name="flag">flag</param>
/// <param name="buffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_WriteEx(SafeFtHandle ftHandle, ushort deviceAddress, byte flag, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Reset I2C as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_Reset(SafeFtHandle ftHandle);
/// <summary>
/// Get the I2C status as a master
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="controllerStatus">Returns the controller status byte</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CMaster_GetStatus(SafeFtHandle ftHandle, out byte controllerStatus);
/// <summary>
/// Initialize the chip as an I2C replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_Init(SafeFtHandle ftHandle);
/// <summary>
/// Reset the I2C as a replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_Reset(SafeFtHandle ftHandle);
/// <summary>
/// Get the I2C address as a replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="addr">The I2C device address</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_GetAddress(SafeFtHandle ftHandle, out byte addr);
/// <summary>
/// Get the I2C address as a replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="addr">The I2C device address</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_SetAddress(SafeFtHandle ftHandle, byte addr);
/// <summary>
/// Get the I2C as a replica RX status
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="pRxSize">the RX size</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_GetRxStatus(SafeFtHandle ftHandle, out ushort pRxSize);
/// <summary>
/// Operate an I2C read as a replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The output read buffer</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_Read(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Write on the I2C device as replica
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="buffer">The buffer to write</param>
/// <param name="bufferSize">The size of the buffer</param>
/// <param name="sizeTransferred">The size of the transfer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_Write(SafeFtHandle ftHandle, in byte buffer, ushort bufferSize, out ushort sizeTransferred);
/// <summary>
/// Set I2C as a replica clock stretch
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="enable">True to enable, false to disable</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_SetClockStretch(SafeFtHandle ftHandle, bool enable);
/// <summary>
/// Set I2C as a replica response word
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="responseWord">The response word</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_I2CSlave_SetRespWord(SafeFtHandle ftHandle, byte responseWord);
#endregion
#region GPIO
/// <summary>
/// Initialize the chip as GPIO
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="gpioDir">Array of pin configuration</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_Init(SafeFtHandle ftHandle, GpioPinMode[] gpioDir);
/// <summary>
/// Operate a GPIO read
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="portNum">The pin port</param>
/// <param name="value">True if high, false if low</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_Read(SafeFtHandle ftHandle, GpioPort portNum, out GpioPinValue value);
/// <summary>
/// Operate a GPIO write
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="portNum">The pin port</param>
/// <param name="bValue">True if high, false if low</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_Write(SafeFtHandle ftHandle, GpioPort portNum, GpioPinValue bValue);
/// <summary>
/// Set the GPIO input trigger
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="portNum">The pin port</param>
/// <param name="trigger">The trigger type</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_SetInputTrigger(SafeFtHandle ftHandle, GpioPort portNum, GpioTrigger trigger);
/// <summary>
/// Get the GPIO trigger status
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="portNum">The pin port</param>
/// <param name="queueSize">The queue size</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_GetTriggerStatus(SafeFtHandle ftHandle, GpioPort portNum, out ushort queueSize);
/// <summary>
/// Read the GPIO Trigger queue
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="portNum">The pin port</param>
/// <param name="events">Type of event</param>
/// <param name="readSize">The number of events read</param>
/// <param name="sizeofRead">The size of the read buffer</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_ReadTriggerQueue(SafeFtHandle ftHandle, GpioPort portNum, in GpioTrigger events, ushort readSize, out ushort sizeofRead);
/// <summary>
/// Set the GPIO in wave form
/// </summary>
/// <param name="ftHandle">The handle of the open device</param>
/// <param name="enable">True to enable, false to disable</param>
/// <returns>The status</returns>
[DllImport("libft4222", CallingConvention = CallingConvention.Cdecl)]
public static extern FtStatus FT4222_GPIO_SetWaveFormMode(SafeFtHandle ftHandle, bool enable);
#endregion
}
}