forked from joan2937/pigpio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pigpio.h
6461 lines (4746 loc) · 150 KB
/
pigpio.h
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
#ifndef PIGPIO_H
#define PIGPIO_H
#include <stdint.h>
#include <pthread.h>
#define PIGPIO_VERSION 68
/*TEXT
pigpio is a C library for the Raspberry which allows control of the GPIO.
*Features*
o hardware timed PWM on any of GPIO 0-31
o hardware timed servo pulses on any of GPIO 0-31
o callbacks when any of GPIO 0-31 change state
o callbacks at timed intervals
o reading/writing all of the GPIO in a bank as one operation
o individually setting GPIO modes, reading and writing
o notifications when any of GPIO 0-31 change state
o the construction of output waveforms with microsecond timing
o rudimentary permission control over GPIO
o a simple interface to start and stop new threads
o I2C, SPI, and serial link wrappers
o creating and running scripts
*GPIO*
ALL GPIO are identified by their Broadcom number.
*Credits*
The PWM and servo pulses are timed using the DMA and PWM peripherals.
This use was inspired by Richard Hirst's servoblaster kernel module.
See [[https://github.com/richardghirst/PiBits/tree/master/ServoBlaster]]
*Usage*
Include <pigpio.h> in your source files.
Assuming your source is in prog.c use the following command to build and
run the executable.
. .
gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog
. .
For examples of usage see the C programs within the pigpio archive file.
*Notes*
All the functions which return an int return < 0 on error.
[*gpioInitialise*] must be called before all other library functions
with the following exceptions:
. .
[*gpioCfg**]
[*gpioVersion*]
[*gpioHardwareRevision*]
. .
If the library is not initialised all but the [*gpioCfg**],
[*gpioVersion*], and [*gpioHardwareRevision*] functions will
return error PI_NOT_INITIALISED.
If the library is initialised the [*gpioCfg**] functions will return
error PI_INITIALISED.
TEXT*/
/*OVERVIEW
ESSENTIAL
gpioInitialise Initialise library
gpioTerminate Stop library
BEGINNER
gpioSetMode Set a GPIO mode
gpioGetMode Get a GPIO mode
gpioSetPullUpDown Set/clear GPIO pull up/down resistor
gpioRead Read a GPIO
gpioWrite Write a GPIO
gpioPWM Start/stop PWM pulses on a GPIO
gpioGetPWMdutycycle Get dutycycle setting on a GPIO
gpioServo Start/stop servo pulses on a GPIO
gpioGetServoPulsewidth Get pulsewidth setting on a GPIO
gpioDelay Delay for a number of microseconds
gpioSetAlertFunc Request a GPIO level change callback
gpioSetTimerFunc Request a regular timed callback
INTERMEDIATE
gpioTrigger Send a trigger pulse to a GPIO.
gpioSetWatchdog Set a watchdog on a GPIO.
gpioSetPWMrange Configure PWM range for a GPIO
gpioGetPWMrange Get configured PWM range for a GPIO
gpioSetPWMfrequency Configure PWM frequency for a GPIO
gpioGetPWMfrequency Get configured PWM frequency for a GPIO
gpioRead_Bits_0_31 Read all GPIO in bank 1
gpioRead_Bits_32_53 Read all GPIO in bank 2
gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1
gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2
gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1
gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2
gpioStartThread Start a new thread
gpioStopThread Stop a previously started thread
ADVANCED
gpioGetPWMrealRange Get underlying PWM range for a GPIO
gpioSetAlertFuncEx Request a GPIO change callback, extended
gpioSetISRFunc Request a GPIO interrupt callback
gpioSetISRFuncEx Request a GPIO interrupt callback, extended
gpioSetSignalFunc Request a signal callback
gpioSetSignalFuncEx Request a signal callback, extended
gpioSetGetSamplesFunc Requests a GPIO samples callback
gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended
gpioSetTimerFuncEx Request a regular timed callback, extended
gpioNotifyOpen Request a notification handle
gpioNotifyOpenWithSize Request a notification handle with sized pipe
gpioNotifyBegin Start notifications for selected GPIO
gpioNotifyPause Pause notifications
gpioNotifyClose Close a notification
gpioSerialReadOpen Opens a GPIO for bit bang serial reads
gpioSerialReadInvert Configures normal/inverted for serial reads
gpioSerialRead Reads bit bang serial data from a GPIO
gpioSerialReadClose Closes a GPIO for bit bang serial reads
gpioHardwareClock Start hardware clock on supported GPIO
gpioHardwarePWM Start hardware PWM on supported GPIO
gpioGlitchFilter Set a glitch filter on a GPIO
gpioNoiseFilter Set a noise filter on a GPIO
gpioGetPad Gets a pads drive strength
gpioSetPad Sets a pads drive strength
shell Executes a shell command
SCRIPTS
gpioStoreScript Store a script
gpioRunScript Run a stored script
gpioUpdateScript Set a scripts parameters
gpioScriptStatus Get script status and parameters
gpioStopScript Stop a running script
gpioDeleteScript Delete a stored script
WAVES
gpioWaveClear Deletes all waveforms
gpioWaveAddNew Starts a new waveform
gpioWaveAddGeneric Adds a series of pulses to the waveform
gpioWaveAddSerial Adds serial data to the waveform
gpioWaveCreate Creates a waveform from added data
gpioWaveDelete Deletes a waveform
gpioWaveTxSend Transmits a waveform
gpioWaveChain Transmits a chain of waveforms
gpioWaveTxAt Returns the current transmitting waveform
gpioWaveTxBusy Checks to see if the waveform has ended
gpioWaveTxStop Aborts the current waveform
gpioWaveGetMicros Length in microseconds of the current waveform
gpioWaveGetHighMicros Length of longest waveform so far
gpioWaveGetMaxMicros Absolute maximum allowed micros
gpioWaveGetPulses Length in pulses of the current waveform
gpioWaveGetHighPulses Length of longest waveform so far
gpioWaveGetMaxPulses Absolute maximum allowed pulses
gpioWaveGetCbs Length in control blocks of the current waveform
gpioWaveGetHighCbs Length of longest waveform so far
gpioWaveGetMaxCbs Absolute maximum allowed control blocks
I2C
i2cOpen Opens an I2C device
i2cClose Closes an I2C device
i2cWriteQuick SMBus write quick
i2cWriteByte SMBus write byte
i2cReadByte SMBus read byte
i2cWriteByteData SMBus write byte data
i2cWriteWordData SMBus write word data
i2cReadByteData SMBus read byte data
i2cReadWordData SMBus read word data
i2cProcessCall SMBus process call
i2cWriteBlockData SMBus write block data
i2cReadBlockData SMBus read block data
i2cBlockProcessCall SMBus block process call
i2cWriteI2CBlockData SMBus write I2C block data
i2cReadI2CBlockData SMBus read I2C block data
i2cReadDevice Reads the raw I2C device
i2cWriteDevice Writes the raw I2C device
i2cSwitchCombined Sets or clears the combined flag
i2cSegments Performs multiple I2C transactions
i2cZip Performs multiple I2C transactions
bbI2COpen Opens GPIO for bit banging I2C
bbI2CClose Closes GPIO for bit banging I2C
bbI2CZip Performs multiple bit banged I2C transactions
SPI
spiOpen Opens a SPI device
spiClose Closes a SPI device
spiRead Reads bytes from a SPI device
spiWrite Writes bytes to a SPI device
spiXfer Transfers bytes with a SPI device
bbSPIOpen Opens GPIO for bit banging SPI
bbSPIClose Closes GPIO for bit banging SPI
bbSPIXfer Performs multiple bit banged SPI transactions
I2C/SPI_SLAVE
bscXfer I2C/SPI as slave transfer
SERIAL
serOpen Opens a serial device
serClose Closes a serial device
serReadByte Reads a byte from a serial device
serWriteByte Writes a byte to a serial device
serRead Reads bytes from a serial device
serWrite Writes bytes to a serial device
serDataAvailable Returns number of bytes ready to be read
FILES
fileOpen Opens a file
fileClose Closes a file
fileRead Reads bytes from a file
fileWrite Writes bytes to a file
fileSeek Seeks to a position within a file
fileList List files which match a pattern
EVENTS
eventMonitor Sets the events to monitor
eventSetFunc Request an event callback
eventSetFuncEx Request an event callback, extended
eventTrigger Trigger an event
CONFIGURATION
gpioCfgBufferSize Configure the GPIO sample buffer size
gpioCfgClock Configure the GPIO sample rate
gpioCfgDMAchannel Configure the DMA channel (DEPRECATED)
gpioCfgDMAchannels Configure the DMA channels
gpioCfgPermissions Configure the GPIO access permissions
gpioCfgInterfaces Configure user interfaces
gpioCfgSocketPort Configure socket port
gpioCfgMemAlloc Configure DMA memory allocation mode
gpioCfgNetAddr Configure allowed network addresses
gpioCfgInternals Configure miscellaneous internals (DEPRECATED)
gpioCfgGetInternals Get internal configuration settings
gpioCfgSetInternals Set internal configuration settings
CUSTOM
gpioCustom1 User custom function 1
gpioCustom2 User custom function 2
UTILITIES
gpioTick Get current tick (microseconds)
gpioHardwareRevision Get hardware revision
gpioVersion Get the pigpio version
getBitInBytes Get the value of a bit
putBitInBytes Set the value of a bit
gpioTime Get current time
gpioSleep Sleep for specified time
time_sleep Sleeps for a float number of seconds
time_time Float number of seconds since the epoch
EXPERT
rawWaveAddSPI Not intended for general use
rawWaveAddGeneric Not intended for general use
rawWaveCB Not intended for general use
rawWaveCBAdr Not intended for general use
rawWaveGetOOL Not intended for general use
rawWaveSetOOL Not intended for general use
rawWaveGetOut Not intended for general use
rawWaveSetOut Not intended for general use
rawWaveGetIn Not intended for general use
rawWaveSetIn Not intended for general use
rawWaveInfo Not intended for general use
rawDumpWave Not intended for general use
rawDumpScript Not intended for general use
OVERVIEW*/
#define PI_INPFIFO "/dev/pigpio"
#define PI_OUTFIFO "/dev/pigout"
#define PI_ERRFIFO "/dev/pigerr"
#define PI_ENVPORT "PIGPIO_PORT"
#define PI_ENVADDR "PIGPIO_ADDR"
#define PI_LOCKFILE "/var/run/pigpio.pid"
#define PI_I2C_COMBINED "/sys/module/i2c_bcm2708/parameters/combined"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
uint16_t func;
uint16_t size;
} gpioHeader_t;
typedef struct
{
size_t size;
void *ptr;
uint32_t data;
} gpioExtent_t;
typedef struct
{
uint32_t tick;
uint32_t level;
} gpioSample_t;
typedef struct
{
uint16_t seqno;
uint16_t flags;
uint32_t tick;
uint32_t level;
} gpioReport_t;
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;
#define WAVE_FLAG_READ 1
#define WAVE_FLAG_TICK 2
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
uint32_t flags;
} rawWave_t;
/*
CBs are used in order from the lowest numbered CB up to
the maximum NUM_WAVE_CBS.
OOLS are used from the bottom climbing up and from
the top climbing down.
The GPIO on and off settings climb up from the bottom (botOOL/numBOOL).
The level and tick read values are stored in descending locations
from the top (topOOL/numTOOL).
*/
typedef struct
{
uint16_t botCB; /* first CB used by wave */
uint16_t topCB; /* last CB used by wave */
uint16_t botOOL; /* first bottom OOL used by wave */
/* botOOL to botOOL + numBOOL - 1 are in use */
uint16_t topOOL; /* last top OOL used by wave */
/* topOOL - numTOOL to topOOL are in use.*/
uint16_t deleted;
uint16_t numCB;
uint16_t numBOOL;
uint16_t numTOOL;
} rawWaveInfo_t;
typedef struct
{
int clk; /* GPIO for clock */
int mosi; /* GPIO for MOSI */
int miso; /* GPIO for MISO */
int ss_pol; /* slave select off state */
int ss_us; /* delay after slave select */
int clk_pol; /* clock off state */
int clk_pha; /* clock phase */
int clk_us; /* clock micros */
} rawSPI_t;
typedef struct { /* linux/arch/arm/mach-bcm2708/include/mach/dma.h */
uint32_t info;
uint32_t src;
uint32_t dst;
uint32_t length;
uint32_t stride;
uint32_t next;
uint32_t pad[2];
} rawCbs_t;
typedef struct
{
uint16_t addr; /* slave address */
uint16_t flags;
uint16_t len; /* msg length */
uint8_t *buf; /* pointer to msg data */
} pi_i2c_msg_t;
/* BSC FIFO size */
#define BSC_FIFO_SIZE 512
typedef struct
{
uint32_t control; /* Write */
int rxCnt; /* Read only */
char rxBuf[BSC_FIFO_SIZE]; /* Read only */
int txCnt; /* Write */
char txBuf[BSC_FIFO_SIZE]; /* Write */
} bsc_xfer_t;
typedef void (*gpioAlertFunc_t) (int gpio,
int level,
uint32_t tick);
typedef void (*gpioAlertFuncEx_t) (int gpio,
int level,
uint32_t tick,
void *userdata);
typedef void (*eventFunc_t) (int event,
uint32_t tick);
typedef void (*eventFuncEx_t) (int event,
uint32_t tick,
void *userdata);
typedef void (*gpioISRFunc_t) (int gpio,
int level,
uint32_t tick);
typedef void (*gpioISRFuncEx_t) (int gpio,
int level,
uint32_t tick,
void *userdata);
typedef void (*gpioTimerFunc_t) (void);
typedef void (*gpioTimerFuncEx_t) (void *userdata);
typedef void (*gpioSignalFunc_t) (int signum);
typedef void (*gpioSignalFuncEx_t) (int signum,
void *userdata);
typedef void (*gpioGetSamplesFunc_t) (const gpioSample_t *samples,
int numSamples);
typedef void (*gpioGetSamplesFuncEx_t) (const gpioSample_t *samples,
int numSamples,
void *userdata);
typedef void *(gpioThreadFunc_t) (void *);
/* gpio: 0-53 */
#define PI_MIN_GPIO 0
#define PI_MAX_GPIO 53
/* user_gpio: 0-31 */
#define PI_MAX_USER_GPIO 31
/* level: 0-1 */
#define PI_OFF 0
#define PI_ON 1
#define PI_CLEAR 0
#define PI_SET 1
#define PI_LOW 0
#define PI_HIGH 1
/* level: only reported for GPIO time-out, see gpioSetWatchdog */
#define PI_TIMEOUT 2
/* mode: 0-7 */
#define PI_INPUT 0
#define PI_OUTPUT 1
#define PI_ALT0 4
#define PI_ALT1 5
#define PI_ALT2 6
#define PI_ALT3 7
#define PI_ALT4 3
#define PI_ALT5 2
/* pud: 0-2 */
#define PI_PUD_OFF 0
#define PI_PUD_DOWN 1
#define PI_PUD_UP 2
/* dutycycle: 0-range */
#define PI_DEFAULT_DUTYCYCLE_RANGE 255
/* range: 25-40000 */
#define PI_MIN_DUTYCYCLE_RANGE 25
#define PI_MAX_DUTYCYCLE_RANGE 40000
/* pulsewidth: 0, 500-2500 */
#define PI_SERVO_OFF 0
#define PI_MIN_SERVO_PULSEWIDTH 500
#define PI_MAX_SERVO_PULSEWIDTH 2500
/* hardware PWM */
#define PI_HW_PWM_MIN_FREQ 1
#define PI_HW_PWM_MAX_FREQ 125000000
#define PI_HW_PWM_RANGE 1000000
/* hardware clock */
#define PI_HW_CLK_MIN_FREQ 4689
#define PI_HW_CLK_MAX_FREQ 250000000
#define PI_NOTIFY_SLOTS 32
#define PI_NTFY_FLAGS_EVENT (1 <<7)
#define PI_NTFY_FLAGS_ALIVE (1 <<6)
#define PI_NTFY_FLAGS_WDOG (1 <<5)
#define PI_NTFY_FLAGS_BIT(x) (((x)<<0)&31)
#define PI_WAVE_BLOCKS 4
#define PI_WAVE_MAX_PULSES (PI_WAVE_BLOCKS * 3000)
#define PI_WAVE_MAX_CHARS (PI_WAVE_BLOCKS * 300)
#define PI_BB_I2C_MIN_BAUD 50
#define PI_BB_I2C_MAX_BAUD 500000
#define PI_BB_SPI_MIN_BAUD 50
#define PI_BB_SPI_MAX_BAUD 250000
#define PI_BB_SER_MIN_BAUD 50
#define PI_BB_SER_MAX_BAUD 250000
#define PI_BB_SER_NORMAL 0
#define PI_BB_SER_INVERT 1
#define PI_WAVE_MIN_BAUD 50
#define PI_WAVE_MAX_BAUD 1000000
#define PI_SPI_MIN_BAUD 32000
#define PI_SPI_MAX_BAUD 125000000
#define PI_MIN_WAVE_DATABITS 1
#define PI_MAX_WAVE_DATABITS 32
#define PI_MIN_WAVE_HALFSTOPBITS 2
#define PI_MAX_WAVE_HALFSTOPBITS 8
#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
#define PI_MAX_WAVES 250
#define PI_MAX_WAVE_CYCLES 65535
#define PI_MAX_WAVE_DELAY 65535
#define PI_WAVE_COUNT_PAGES 10
/* wave tx mode */
#define PI_WAVE_MODE_ONE_SHOT 0
#define PI_WAVE_MODE_REPEAT 1
#define PI_WAVE_MODE_ONE_SHOT_SYNC 2
#define PI_WAVE_MODE_REPEAT_SYNC 3
/* special wave at return values */
#define PI_WAVE_NOT_FOUND 9998 /* Transmitted wave not found. */
#define PI_NO_TX_WAVE 9999 /* No wave being transmitted. */
/* Files, I2C, SPI, SER */
#define PI_FILE_SLOTS 16
#define PI_I2C_SLOTS 64
#define PI_SPI_SLOTS 32
#define PI_SER_SLOTS 16
#define PI_MAX_I2C_ADDR 0x7F
#define PI_NUM_AUX_SPI_CHANNEL 3
#define PI_NUM_STD_SPI_CHANNEL 2
#define PI_MAX_I2C_DEVICE_COUNT (1<<16)
#define PI_MAX_SPI_DEVICE_COUNT (1<<16)
/* max pi_i2c_msg_t per transaction */
#define PI_I2C_RDRW_IOCTL_MAX_MSGS 42
/* flags for i2cTransaction, pi_i2c_msg_t */
#define PI_I2C_M_WR 0x0000 /* write data */
#define PI_I2C_M_RD 0x0001 /* read data */
#define PI_I2C_M_TEN 0x0010 /* ten bit chip address */
#define PI_I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
#define PI_I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define PI_I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define PI_I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define PI_I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
/* bbI2CZip and i2cZip commands */
#define PI_I2C_END 0
#define PI_I2C_ESC 1
#define PI_I2C_START 2
#define PI_I2C_COMBINED_ON 2
#define PI_I2C_STOP 3
#define PI_I2C_COMBINED_OFF 3
#define PI_I2C_ADDR 4
#define PI_I2C_FLAGS 5
#define PI_I2C_READ 6
#define PI_I2C_WRITE 7
/* SPI */
#define PI_SPI_FLAGS_BITLEN(x) ((x&63)<<16)
#define PI_SPI_FLAGS_RX_LSB(x) ((x&1)<<15)
#define PI_SPI_FLAGS_TX_LSB(x) ((x&1)<<14)
#define PI_SPI_FLAGS_3WREN(x) ((x&15)<<10)
#define PI_SPI_FLAGS_3WIRE(x) ((x&1)<<9)
#define PI_SPI_FLAGS_AUX_SPI(x) ((x&1)<<8)
#define PI_SPI_FLAGS_RESVD(x) ((x&7)<<5)
#define PI_SPI_FLAGS_CSPOLS(x) ((x&7)<<2)
#define PI_SPI_FLAGS_MODE(x) ((x&3))
/* BSC registers */
#define BSC_DR 0
#define BSC_RSR 1
#define BSC_SLV 2
#define BSC_CR 3
#define BSC_FR 4
#define BSC_IFLS 5
#define BSC_IMSC 6
#define BSC_RIS 7
#define BSC_MIS 8
#define BSC_ICR 9
#define BSC_DMACR 10
#define BSC_TDR 11
#define BSC_GPUSTAT 12
#define BSC_HCTRL 13
#define BSC_DEBUG_I2C 14
#define BSC_DEBUG_SPI 15
#define BSC_CR_TESTFIFO 2048
#define BSC_CR_RXE 512
#define BSC_CR_TXE 256
#define BSC_CR_BRK 128
#define BSC_CR_CPOL 16
#define BSC_CR_CPHA 8
#define BSC_CR_I2C 4
#define BSC_CR_SPI 2
#define BSC_CR_EN 1
#define BSC_FR_RXBUSY 32
#define BSC_FR_TXFE 16
#define BSC_FR_RXFF 8
#define BSC_FR_TXFF 4
#define BSC_FR_RXFE 2
#define BSC_FR_TXBUSY 1
/* BSC GPIO */
#define BSC_SDA_MOSI 18
#define BSC_SCL_SCLK 19
#define BSC_MISO 20
#define BSC_CE_N 21
/* Longest busy delay */
#define PI_MAX_BUSY_DELAY 100
/* timeout: 0-60000 */
#define PI_MIN_WDOG_TIMEOUT 0
#define PI_MAX_WDOG_TIMEOUT 60000
/* timer: 0-9 */
#define PI_MIN_TIMER 0
#define PI_MAX_TIMER 9
/* millis: 10-60000 */
#define PI_MIN_MS 10
#define PI_MAX_MS 60000
#define PI_MAX_SCRIPTS 32
#define PI_MAX_SCRIPT_TAGS 50
#define PI_MAX_SCRIPT_VARS 150
#define PI_MAX_SCRIPT_PARAMS 10
/* script status */
#define PI_SCRIPT_INITING 0
#define PI_SCRIPT_HALTED 1
#define PI_SCRIPT_RUNNING 2
#define PI_SCRIPT_WAITING 3
#define PI_SCRIPT_FAILED 4
/* signum: 0-63 */
#define PI_MIN_SIGNUM 0
#define PI_MAX_SIGNUM 63
/* timetype: 0-1 */
#define PI_TIME_RELATIVE 0
#define PI_TIME_ABSOLUTE 1
#define PI_MAX_MICS_DELAY 1000000 /* 1 second */
#define PI_MAX_MILS_DELAY 60000 /* 60 seconds */
/* cfgMillis */
#define PI_BUF_MILLIS_MIN 100
#define PI_BUF_MILLIS_MAX 10000
/* cfgMicros: 1, 2, 4, 5, 8, or 10 */
/* cfgPeripheral: 0-1 */
#define PI_CLOCK_PWM 0
#define PI_CLOCK_PCM 1
/* DMA channel: 0-14 */
#define PI_MIN_DMA_CHANNEL 0
#define PI_MAX_DMA_CHANNEL 14
/* port */
#define PI_MIN_SOCKET_PORT 1024
#define PI_MAX_SOCKET_PORT 32000
/* ifFlags: */
#define PI_DISABLE_FIFO_IF 1
#define PI_DISABLE_SOCK_IF 2
#define PI_LOCALHOST_SOCK_IF 4
#define PI_DISABLE_ALERT 8
/* memAllocMode */
#define PI_MEM_ALLOC_AUTO 0
#define PI_MEM_ALLOC_PAGEMAP 1
#define PI_MEM_ALLOC_MAILBOX 2
/* filters */
#define PI_MAX_STEADY 300000
#define PI_MAX_ACTIVE 1000000
/* gpioCfgInternals */
#define PI_CFG_DBG_LEVEL 0 /* bits 0-3 */
#define PI_CFG_ALERT_FREQ 4 /* bits 4-7 */
#define PI_CFG_RT_PRIORITY (1<<8)
#define PI_CFG_STATS (1<<9)
#define PI_CFG_NOSIGHANDLER (1<<10)
#define PI_CFG_ILLEGAL_VAL (1<<11)
/* gpioISR */
#define RISING_EDGE 0
#define FALLING_EDGE 1
#define EITHER_EDGE 2
/* pads */
#define PI_MAX_PAD 2
#define PI_MIN_PAD_STRENGTH 1
#define PI_MAX_PAD_STRENGTH 16
/* files */
#define PI_FILE_NONE 0
#define PI_FILE_MIN 1
#define PI_FILE_READ 1
#define PI_FILE_WRITE 2
#define PI_FILE_RW 3
#define PI_FILE_APPEND 4
#define PI_FILE_CREATE 8
#define PI_FILE_TRUNC 16
#define PI_FILE_MAX 31
#define PI_FROM_START 0
#define PI_FROM_CURRENT 1
#define PI_FROM_END 2
/* Allowed socket connect addresses */
#define MAX_CONNECT_ADDRESSES 256
/* events */
#define PI_MAX_EVENT 31
/* Event auto generated on BSC slave activity */
#define PI_EVENT_BSC 31
/*F*/
int gpioInitialise(void);
/*D
Initialises the library.
Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
gpioInitialise must be called before using the other library functions
with the following exceptions:
. .
[*gpioCfg**]
[*gpioVersion*]
[*gpioHardwareRevision*]
. .
...
if (gpioInitialise() < 0)
{
// pigpio initialisation failed.
}
else
{
// pigpio initialised okay.
}
...
D*/
/*F*/
void gpioTerminate(void);
/*D
Terminates the library.
Returns nothing.
Call before program exit.
This function resets the used DMA channels, releases memory, and
terminates any running threads.
...
gpioTerminate();
...
D*/
/*F*/
int gpioSetMode(unsigned gpio, unsigned mode);
/*D
Sets the GPIO mode, typically input or output.
. .
gpio: 0-53
mode: 0-7
. .
Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE.
Arduino style: pinMode.
...
gpioSetMode(17, PI_INPUT); // Set GPIO17 as input.
gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.
gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0.
...
See [[http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf]] page 102 for an overview of the modes.
D*/
/*F*/
int gpioGetMode(unsigned gpio);
/*D
Gets the GPIO mode.
. .
gpio: 0-53
. .
Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
...