SkyPulse UAV V0.1
Loading...
Searching...
No Matches
pigpio.h
Go to the documentation of this file.
1/*
2This is free and unencumbered software released into the public domain.
3
4Anyone is free to copy, modify, publish, use, compile, sell, or
5distribute this software, either in source code form or as a compiled
6binary, for any purpose, commercial or non-commercial, and by any
7means.
8
9In jurisdictions that recognize copyright laws, the author or authors
10of this software dedicate any and all copyright interest in the
11software to the public domain. We make this dedication for the benefit
12of the public at large and to the detriment of our heirs and
13successors. We intend this dedication to be an overt act of
14relinquishment in perpetuity of all present and future rights to this
15software under copyright law.
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23
24For more information, please refer to <http://unlicense.org/>
25*/
26
27#ifndef PIGPIO_H
28#define PIGPIO_H
29
30#include <stddef.h>
31#include <stdint.h>
32#include <pthread.h>
33
34#define PIGPIO_VERSION 79
35
36/*TEXT
37
38pigpio is a C library for the Raspberry which allows control of the GPIO.
39
40*Features*
41
42o hardware timed PWM on any of GPIO 0-31
43
44o hardware timed servo pulses on any of GPIO 0-31
45
46o callbacks when any of GPIO 0-31 change state
47
48o callbacks at timed intervals
49
50o reading/writing all of the GPIO in a bank as one operation
51
52o individually setting GPIO modes, reading and writing
53
54o notifications when any of GPIO 0-31 change state
55
56o the construction of output waveforms with microsecond timing
57
58o rudimentary permission control over GPIO
59
60o a simple interface to start and stop new threads
61
62o I2C, SPI, and serial link wrappers
63
64o creating and running scripts
65
66*GPIO*
67
68ALL GPIO are identified by their Broadcom number.
69
70*Credits*
71
72The PWM and servo pulses are timed using the DMA and PWM peripherals.
73
74This use was inspired by Richard Hirst's servoblaster kernel module.
75
76*Usage*
77
78Include <pigpio.h> in your source files.
79
80Assuming your source is in prog.c use the following command to build and
81run the executable.
82
83. .
84gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
85sudo ./prog
86. .
87
88For examples of usage see the C programs within the pigpio archive file.
89
90*Notes*
91
92All the functions which return an int return < 0 on error.
93
94[*gpioInitialise*] must be called before all other library functions
95with the following exceptions:
96
97. .
98[*gpioCfg**]
99[*gpioVersion*]
100[*gpioHardwareRevision*]
101. .
102
103If the library is not initialised all but the [*gpioCfg**],
104[*gpioVersion*], and [*gpioHardwareRevision*] functions will
105return error PI_NOT_INITIALISED.
106
107If the library is initialised the [*gpioCfg**] functions will return
108error PI_INITIALISED.
109
110If you intend to rely on signals sent to your application, you should
111turn off the internal signal handling as shown in this example:
112
113. .
114int cfg = gpioCfgGetInternals();
115cfg |= PI_CFG_NOSIGHANDLER; // (1<<10)
116gpioCfgSetInternals(cfg);
117int status = gpioInitialise();
118. .
119
120TEXT*/
121
122/*OVERVIEW
123
124ESSENTIAL
125
126gpioInitialise Initialise library
127gpioTerminate Stop library
128
129BASIC
130
131gpioSetMode Set a GPIO mode
132gpioGetMode Get a GPIO mode
133
134gpioSetPullUpDown Set/clear GPIO pull up/down resistor
135
136gpioRead Read a GPIO
137gpioWrite Write a GPIO
138
139PWM_(overrides_servo_commands_on_same_GPIO)
140
141gpioPWM Start/stop PWM pulses on a GPIO
142gpioSetPWMfrequency Configure PWM frequency for a GPIO
143gpioSetPWMrange Configure PWM range for a GPIO
144
145gpioGetPWMdutycycle Get dutycycle setting on a GPIO
146gpioGetPWMfrequency Get configured PWM frequency for a GPIO
147gpioGetPWMrange Get configured PWM range for a GPIO
148
149gpioGetPWMrealRange Get underlying PWM range for a GPIO
150
151Servo_(overrides_PWM_commands_on_same_GPIO)
152
153gpioServo Start/stop servo pulses on a GPIO
154
155gpioGetServoPulsewidth Get pulsewidth setting on a GPIO
156
157INTERMEDIATE
158
159gpioTrigger Send a trigger pulse to a GPIO
160
161gpioSetWatchdog Set a watchdog on a GPIO
162
163gpioRead_Bits_0_31 Read all GPIO in bank 1
164gpioRead_Bits_32_53 Read all GPIO in bank 2
165
166gpioWrite_Bits_0_31_Clear Clear selected GPIO in bank 1
167gpioWrite_Bits_32_53_Clear Clear selected GPIO in bank 2
168
169gpioWrite_Bits_0_31_Set Set selected GPIO in bank 1
170gpioWrite_Bits_32_53_Set Set selected GPIO in bank 2
171
172gpioSetAlertFunc Request a GPIO level change callback
173gpioSetAlertFuncEx Request a GPIO change callback, extended
174
175gpioSetTimerFunc Request a regular timed callback
176gpioSetTimerFuncEx Request a regular timed callback, extended
177
178gpioStartThread Start a new thread
179gpioStopThread Stop a previously started thread
180
181ADVANCED
182
183gpioNotifyOpen Request a notification handle
184gpioNotifyClose Close a notification
185gpioNotifyOpenWithSize Request a notification with sized pipe
186gpioNotifyBegin Start notifications for selected GPIO
187gpioNotifyPause Pause notifications
188
189gpioHardwareClock Start hardware clock on supported GPIO
190
191gpioHardwarePWM Start hardware PWM on supported GPIO
192
193gpioGlitchFilter Set a glitch filter on a GPIO
194gpioNoiseFilter Set a noise filter on a GPIO
195
196gpioSetPad Sets a pads drive strength
197gpioGetPad Gets a pads drive strength
198
199shell Executes a shell command
200
201gpioSetISRFunc Request a GPIO interrupt callback
202gpioSetISRFuncEx Request a GPIO interrupt callback, extended
203
204gpioSetSignalFunc Request a signal callback
205gpioSetSignalFuncEx Request a signal callback, extended
206
207gpioSetGetSamplesFunc Requests a GPIO samples callback
208gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended
209
210Custom
211
212gpioCustom1 User custom function 1
213gpioCustom2 User custom function 2
214
215Events
216
217eventMonitor Sets the events to monitor
218eventSetFunc Request an event callback
219eventSetFuncEx Request an event callback, extended
220
221eventTrigger Trigger an event
222
223Scripts
224
225gpioStoreScript Store a script
226gpioRunScript Run a stored script
227gpioUpdateScript Set a scripts parameters
228gpioScriptStatus Get script status and parameters
229gpioStopScript Stop a running script
230gpioDeleteScript Delete a stored script
231
232I2C
233
234i2cOpen Opens an I2C device
235i2cClose Closes an I2C device
236
237i2cWriteQuick SMBus write quick
238
239i2cReadByte SMBus read byte
240i2cWriteByte SMBus write byte
241
242i2cReadByteData SMBus read byte data
243i2cWriteByteData SMBus write byte data
244
245i2cReadWordData SMBus read word data
246i2cWriteWordData SMBus write word data
247
248i2cReadBlockData SMBus read block data
249i2cWriteBlockData SMBus write block data
250
251i2cReadI2CBlockData SMBus read I2C block data
252i2cWriteI2CBlockData SMBus write I2C block data
253
254i2cReadDevice Reads the raw I2C device
255i2cWriteDevice Writes the raw I2C device
256
257i2cProcessCall SMBus process call
258i2cBlockProcessCall SMBus block process call
259
260i2cSwitchCombined Sets or clears the combined flag
261
262i2cSegments Performs multiple I2C transactions
263
264i2cZip Performs multiple I2C transactions
265
266I2C_BIT_BANG
267
268bbI2COpen Opens GPIO for bit banging I2C
269bbI2CClose Closes GPIO for bit banging I2C
270
271bbI2CZip Performs bit banged I2C transactions
272
273I2C/SPI_SLAVE
274
275bscXfer I2C/SPI as slave transfer
276
277SERIAL
278
279serOpen Opens a serial device
280serClose Closes a serial device
281
282serReadByte Reads a byte from a serial device
283serWriteByte Writes a byte to a serial device
284
285serRead Reads bytes from a serial device
286serWrite Writes bytes to a serial device
287
288serDataAvailable Returns number of bytes ready to be read
289
290SERIAL_BIT_BANG_(read_only)
291
292gpioSerialReadOpen Opens a GPIO for bit bang serial reads
293gpioSerialReadClose Closes a GPIO for bit bang serial reads
294
295gpioSerialReadInvert Configures normal/inverted for serial reads
296
297gpioSerialRead Reads bit bang serial data from a GPIO
298
299SPI
300
301spiOpen Opens a SPI device
302spiClose Closes a SPI device
303
304spiRead Reads bytes from a SPI device
305spiWrite Writes bytes to a SPI device
306spiXfer Transfers bytes with a SPI device
307
308SPI_BIT_BANG
309
310bbSPIOpen Opens GPIO for bit banging SPI
311bbSPIClose Closes GPIO for bit banging SPI
312
313bbSPIXfer Performs bit banged SPI transactions
314
315FILES
316
317fileOpen Opens a file
318fileClose Closes a file
319
320fileRead Reads bytes from a file
321fileWrite Writes bytes to a file
322
323fileSeek Seeks to a position within a file
324
325fileList List files which match a pattern
326
327WAVES
328
329gpioWaveClear Deletes all waveforms
330
331gpioWaveAddNew Starts a new waveform
332gpioWaveAddGeneric Adds a series of pulses to the waveform
333gpioWaveAddSerial Adds serial data to the waveform
334
335gpioWaveCreate Creates a waveform from added data
336gpioWaveCreatePad Creates a waveform of fixed size from added data
337gpioWaveDelete Deletes a waveform
338
339gpioWaveTxSend Transmits a waveform
340
341gpioWaveChain Transmits a chain of waveforms
342
343gpioWaveTxAt Returns the current transmitting waveform
344
345gpioWaveTxBusy Checks to see if the waveform has ended
346
347gpioWaveTxStop Aborts the current waveform
348
349gpioWaveGetCbs Length in CBs of the current waveform
350gpioWaveGetHighCbs Length of longest waveform so far
351gpioWaveGetMaxCbs Absolute maximum allowed CBs
352
353gpioWaveGetMicros Length in micros of the current waveform
354gpioWaveGetHighMicros Length of longest waveform so far
355gpioWaveGetMaxMicros Absolute maximum allowed micros
356
357gpioWaveGetPulses Length in pulses of the current waveform
358gpioWaveGetHighPulses Length of longest waveform so far
359gpioWaveGetMaxPulses Absolute maximum allowed pulses
360
361UTILITIES
362
363gpioDelay Delay for a number of microseconds
364
365gpioTick Get current tick (microseconds)
366
367gpioHardwareRevision Get hardware revision
368gpioVersion Get the pigpio version
369
370getBitInBytes Get the value of a bit
371putBitInBytes Set the value of a bit
372
373gpioTime Get current time
374gpioSleep Sleep for specified time
375
376time_sleep Sleeps for a float number of seconds
377time_time Float number of seconds since the epoch
378
379CONFIGURATION
380
381gpioCfgBufferSize Configure the GPIO sample buffer size
382gpioCfgClock Configure the GPIO sample rate
383gpioCfgDMAchannel Configure the DMA channel (DEPRECATED)
384gpioCfgDMAchannels Configure the DMA channels
385gpioCfgPermissions Configure the GPIO access permissions
386gpioCfgInterfaces Configure user interfaces
387gpioCfgSocketPort Configure socket port
388gpioCfgMemAlloc Configure DMA memory allocation mode
389gpioCfgNetAddr Configure allowed network addresses
390
391gpioCfgGetInternals Get internal configuration settings
392gpioCfgSetInternals Set internal configuration settings
393
394EXPERT
395
396rawWaveAddSPI Not intended for general use
397rawWaveAddGeneric Not intended for general use
398rawWaveCB Not intended for general use
399rawWaveCBAdr Not intended for general use
400rawWaveGetOOL Not intended for general use
401rawWaveSetOOL Not intended for general use
402rawWaveGetOut Not intended for general use
403rawWaveSetOut Not intended for general use
404rawWaveGetIn Not intended for general use
405rawWaveSetIn Not intended for general use
406rawWaveInfo Not intended for general use
407rawDumpWave Not intended for general use
408rawDumpScript Not intended for general use
409
410OVERVIEW*/
411
412#define PI_INPFIFO "/dev/pigpio"
413#define PI_OUTFIFO "/dev/pigout"
414#define PI_ERRFIFO "/dev/pigerr"
415
416#define PI_ENVPORT "PIGPIO_PORT"
417#define PI_ENVADDR "PIGPIO_ADDR"
418
419#define PI_LOCKFILE "/var/run/pigpio.pid"
420
421#define PI_I2C_COMBINED "/sys/module/i2c_bcm2708/parameters/combined"
422
423#ifdef __cplusplus
424extern "C" {
425#endif
426
427typedef struct
428{
429 uint16_t func;
430 uint16_t size;
432
433typedef struct
434{
435 size_t size;
436 void *ptr;
437 uint32_t data;
439
440typedef struct
441{
442 uint32_t tick;
443 uint32_t level;
445
446typedef struct
447{
448 uint16_t seqno;
449 uint16_t flags;
450 uint32_t tick;
451 uint32_t level;
453
454typedef struct
455{
456 uint32_t gpioOn;
457 uint32_t gpioOff;
458 uint32_t usDelay;
460
461#define WAVE_FLAG_READ 1
462#define WAVE_FLAG_TICK 2
463
464typedef struct
465{
466 uint32_t gpioOn;
467 uint32_t gpioOff;
468 uint32_t usDelay;
469 uint32_t flags;
470} rawWave_t;
471
472/*
473CBs are used in order from the lowest numbered CB up to
474the maximum NUM_WAVE_CBS.
475
476OOLS are used from the bottom climbing up and from
477the top climbing down.
478
479The GPIO on and off settings climb up from the bottom (botOOL/numBOOL).
480
481The level and tick read values are stored in descending locations
482from the top (topOOL/numTOOL).
483*/
484
485typedef struct
486{
487 uint16_t botCB; /* first CB used by wave */
488 uint16_t topCB; /* last CB used by wave */
489 uint16_t botOOL; /* first bottom OOL used by wave */
490 /* botOOL to botOOL + numBOOL - 1 are in use */
491 uint16_t topOOL; /* last top OOL used by wave */
492 /* topOOL - numTOOL to topOOL are in use.*/
493 uint16_t deleted;
494 uint16_t numCB;
495 uint16_t numBOOL;
496 uint16_t numTOOL;
498
499typedef struct
500{
501 int clk; /* GPIO for clock */
502 int mosi; /* GPIO for MOSI */
503 int miso; /* GPIO for MISO */
504 int ss_pol; /* slave select off state */
505 int ss_us; /* delay after slave select */
506 int clk_pol; /* clock off state */
507 int clk_pha; /* clock phase */
508 int clk_us; /* clock micros */
509} rawSPI_t;
510
511typedef struct { /* linux/arch/arm/mach-bcm2708/include/mach/dma.h */
512 uint32_t info;
513 uint32_t src;
514 uint32_t dst;
515 uint32_t length;
516 uint32_t stride;
517 uint32_t next;
518 uint32_t pad[2];
519} rawCbs_t;
520
521typedef struct
522{
523 uint16_t addr; /* slave address */
524 uint16_t flags;
525 uint16_t len; /* msg length */
526 uint8_t *buf; /* pointer to msg data */
528
529/* BSC FIFO size */
530
531#define BSC_FIFO_SIZE 512
532
533typedef struct
534{
535 uint32_t control; /* Write */
536 int rxCnt; /* Read only */
537 char rxBuf[BSC_FIFO_SIZE]; /* Read only */
538 int txCnt; /* Write */
539 char txBuf[BSC_FIFO_SIZE]; /* Write */
540} bsc_xfer_t;
541
542
543typedef void (*gpioAlertFunc_t) (int gpio,
544 int level,
545 uint32_t tick);
546
547typedef void (*gpioAlertFuncEx_t) (int gpio,
548 int level,
549 uint32_t tick,
550 void *userdata);
551
552typedef void (*eventFunc_t) (int event,
553 uint32_t tick);
554
555typedef void (*eventFuncEx_t) (int event,
556 uint32_t tick,
557 void *userdata);
558
559typedef void (*gpioISRFunc_t) (int gpio,
560 int level,
561 uint32_t tick);
562
563typedef void (*gpioISRFuncEx_t) (int gpio,
564 int level,
565 uint32_t tick,
566 void *userdata);
567
568typedef void (*gpioTimerFunc_t) (void);
569
570typedef void (*gpioTimerFuncEx_t) (void *userdata);
571
572typedef void (*gpioSignalFunc_t) (int signum);
573
574typedef void (*gpioSignalFuncEx_t) (int signum,
575 void *userdata);
576
577typedef void (*gpioGetSamplesFunc_t) (const gpioSample_t *samples,
578 int numSamples);
579
580typedef void (*gpioGetSamplesFuncEx_t) (const gpioSample_t *samples,
581 int numSamples,
582 void *userdata);
583
584typedef void *(gpioThreadFunc_t) (void *);
585
586
587/* gpio: 0-53 */
588
589#define PI_MIN_GPIO 0
590#define PI_MAX_GPIO 53
591
592/* user_gpio: 0-31 */
593
594#define PI_MAX_USER_GPIO 31
595
596/* level: 0-1 */
597
598#define PI_OFF 0
599#define PI_ON 1
600
601#define PI_CLEAR 0
602#define PI_SET 1
603
604#define PI_LOW 0
605#define PI_HIGH 1
606
607/* level: only reported for GPIO time-out, see gpioSetWatchdog */
608
609#define PI_TIMEOUT 2
610
611/* mode: 0-7 */
612
613#define PI_INPUT 0
614#define PI_OUTPUT 1
615#define PI_ALT0 4
616#define PI_ALT1 5
617#define PI_ALT2 6
618#define PI_ALT3 7
619#define PI_ALT4 3
620#define PI_ALT5 2
621
622/* pud: 0-2 */
623
624#define PI_PUD_OFF 0
625#define PI_PUD_DOWN 1
626#define PI_PUD_UP 2
627
628/* dutycycle: 0-range */
629
630#define PI_DEFAULT_DUTYCYCLE_RANGE 255
631
632/* range: 25-40000 */
633
634#define PI_MIN_DUTYCYCLE_RANGE 25
635#define PI_MAX_DUTYCYCLE_RANGE 40000
636
637/* pulsewidth: 0, 500-2500 */
638
639#define PI_SERVO_OFF 0
640#define PI_MIN_SERVO_PULSEWIDTH 500
641#define PI_MAX_SERVO_PULSEWIDTH 2500
642
643/* hardware PWM */
644
645#define PI_HW_PWM_MIN_FREQ 1
646#define PI_HW_PWM_MAX_FREQ 125000000
647#define PI_HW_PWM_MAX_FREQ_2711 187500000
648#define PI_HW_PWM_RANGE 1000000
649
650/* hardware clock */
651
652#define PI_HW_CLK_MIN_FREQ 4689
653#define PI_HW_CLK_MIN_FREQ_2711 13184
654#define PI_HW_CLK_MAX_FREQ 250000000
655#define PI_HW_CLK_MAX_FREQ_2711 375000000
656
657#define PI_NOTIFY_SLOTS 32
658
659#define PI_NTFY_FLAGS_EVENT (1 <<7)
660#define PI_NTFY_FLAGS_ALIVE (1 <<6)
661#define PI_NTFY_FLAGS_WDOG (1 <<5)
662#define PI_NTFY_FLAGS_BIT(x) (((x)<<0)&31)
663
664#define PI_WAVE_BLOCKS 4
665#define PI_WAVE_MAX_PULSES (PI_WAVE_BLOCKS * 3000)
666#define PI_WAVE_MAX_CHARS (PI_WAVE_BLOCKS * 300)
667
668#define PI_BB_I2C_MIN_BAUD 50
669#define PI_BB_I2C_MAX_BAUD 500000
670
671#define PI_BB_SPI_MIN_BAUD 50
672#define PI_BB_SPI_MAX_BAUD 250000
673
674#define PI_BB_SER_MIN_BAUD 50
675#define PI_BB_SER_MAX_BAUD 250000
676
677#define PI_BB_SER_NORMAL 0
678#define PI_BB_SER_INVERT 1
679
680#define PI_WAVE_MIN_BAUD 50
681#define PI_WAVE_MAX_BAUD 1000000
682
683#define PI_SPI_MIN_BAUD 32000
684#define PI_SPI_MAX_BAUD 125000000
685
686#define PI_MIN_WAVE_DATABITS 1
687#define PI_MAX_WAVE_DATABITS 32
688
689#define PI_MIN_WAVE_HALFSTOPBITS 2
690#define PI_MAX_WAVE_HALFSTOPBITS 8
691
692#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
693
694#define PI_MAX_WAVES 250
695
696#define PI_MAX_WAVE_CYCLES 65535
697#define PI_MAX_WAVE_DELAY 65535
698
699#define PI_WAVE_COUNT_PAGES 10
700
701/* wave tx mode */
702
703#define PI_WAVE_MODE_ONE_SHOT 0
704#define PI_WAVE_MODE_REPEAT 1
705#define PI_WAVE_MODE_ONE_SHOT_SYNC 2
706#define PI_WAVE_MODE_REPEAT_SYNC 3
707
708/* special wave at return values */
709
710#define PI_WAVE_NOT_FOUND 9998 /* Transmitted wave not found. */
711#define PI_NO_TX_WAVE 9999 /* No wave being transmitted. */
712
713/* Files, I2C, SPI, SER */
714
715#define PI_FILE_SLOTS 16
716#define PI_I2C_SLOTS 512
717#define PI_SPI_SLOTS 32
718#define PI_SER_SLOTS 16
719
720#define PI_MAX_I2C_ADDR 0x7F
721
722#define PI_NUM_AUX_SPI_CHANNEL 3
723#define PI_NUM_STD_SPI_CHANNEL 2
724
725#define PI_MAX_I2C_DEVICE_COUNT (1<<16)
726#define PI_MAX_SPI_DEVICE_COUNT (1<<16)
727
728/* max pi_i2c_msg_t per transaction */
729
730#define PI_I2C_RDRW_IOCTL_MAX_MSGS 42
731
732/* flags for i2cTransaction, pi_i2c_msg_t */
733
734#define PI_I2C_M_WR 0x0000 /* write data */
735#define PI_I2C_M_RD 0x0001 /* read data */
736#define PI_I2C_M_TEN 0x0010 /* ten bit chip address */
737#define PI_I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
738#define PI_I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
739#define PI_I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
740#define PI_I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
741#define PI_I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
742
743/* bbI2CZip and i2cZip commands */
744
745#define PI_I2C_END 0
746#define PI_I2C_ESC 1
747#define PI_I2C_START 2
748#define PI_I2C_COMBINED_ON 2
749#define PI_I2C_STOP 3
750#define PI_I2C_COMBINED_OFF 3
751#define PI_I2C_ADDR 4
752#define PI_I2C_FLAGS 5
753#define PI_I2C_READ 6
754#define PI_I2C_WRITE 7
755
756/* SPI */
757
758#define PI_SPI_FLAGS_BITLEN(x) ((x&63)<<16)
759#define PI_SPI_FLAGS_RX_LSB(x) ((x&1)<<15)
760#define PI_SPI_FLAGS_TX_LSB(x) ((x&1)<<14)
761#define PI_SPI_FLAGS_3WREN(x) ((x&15)<<10)
762#define PI_SPI_FLAGS_3WIRE(x) ((x&1)<<9)
763#define PI_SPI_FLAGS_AUX_SPI(x) ((x&1)<<8)
764#define PI_SPI_FLAGS_RESVD(x) ((x&7)<<5)
765#define PI_SPI_FLAGS_CSPOLS(x) ((x&7)<<2)
766#define PI_SPI_FLAGS_MODE(x) ((x&3))
767
768/* BSC registers */
769
770#define BSC_DR 0
771#define BSC_RSR 1
772#define BSC_SLV 2
773#define BSC_CR 3
774#define BSC_FR 4
775#define BSC_IFLS 5
776#define BSC_IMSC 6
777#define BSC_RIS 7
778#define BSC_MIS 8
779#define BSC_ICR 9
780#define BSC_DMACR 10
781#define BSC_TDR 11
782#define BSC_GPUSTAT 12
783#define BSC_HCTRL 13
784#define BSC_DEBUG_I2C 14
785#define BSC_DEBUG_SPI 15
786
787#define BSC_CR_TESTFIFO 2048
788#define BSC_CR_RXE 512
789#define BSC_CR_TXE 256
790#define BSC_CR_BRK 128
791#define BSC_CR_CPOL 16
792#define BSC_CR_CPHA 8
793#define BSC_CR_I2C 4
794#define BSC_CR_SPI 2
795#define BSC_CR_EN 1
796
797#define BSC_FR_RXBUSY 32
798#define BSC_FR_TXFE 16
799#define BSC_FR_RXFF 8
800#define BSC_FR_TXFF 4
801#define BSC_FR_RXFE 2
802#define BSC_FR_TXBUSY 1
803
804/* BSC GPIO */
805
806#define BSC_SDA 18
807#define BSC_MOSI 20
808#define BSC_SCL_SCLK 19
809#define BSC_MISO 18
810#define BSC_CE_N 21
811
812#define BSC_SDA_2711 10
813#define BSC_MOSI_2711 9
814#define BSC_SCL_SCLK_2711 11
815#define BSC_MISO_2711 10
816#define BSC_CE_N_2711 8
817
818/* Longest busy delay */
819
820#define PI_MAX_BUSY_DELAY 100
821
822/* timeout: 0-60000 */
823
824#define PI_MIN_WDOG_TIMEOUT 0
825#define PI_MAX_WDOG_TIMEOUT 60000
826
827/* timer: 0-9 */
828
829#define PI_MIN_TIMER 0
830#define PI_MAX_TIMER 9
831
832/* millis: 10-60000 */
833
834#define PI_MIN_MS 10
835#define PI_MAX_MS 60000
836
837#define PI_MAX_SCRIPTS 32
838
839#define PI_MAX_SCRIPT_TAGS 50
840#define PI_MAX_SCRIPT_VARS 150
841#define PI_MAX_SCRIPT_PARAMS 10
842
843/* script status */
844
845#define PI_SCRIPT_INITING 0
846#define PI_SCRIPT_HALTED 1
847#define PI_SCRIPT_RUNNING 2
848#define PI_SCRIPT_WAITING 3
849#define PI_SCRIPT_FAILED 4
850
851/* signum: 0-63 */
852
853#define PI_MIN_SIGNUM 0
854#define PI_MAX_SIGNUM 63
855
856/* timetype: 0-1 */
857
858#define PI_TIME_RELATIVE 0
859#define PI_TIME_ABSOLUTE 1
860
861#define PI_MAX_MICS_DELAY 1000000 /* 1 second */
862#define PI_MAX_MILS_DELAY 60000 /* 60 seconds */
863
864/* cfgMillis */
865
866#define PI_BUF_MILLIS_MIN 100
867#define PI_BUF_MILLIS_MAX 10000
868
869/* cfgMicros: 1, 2, 4, 5, 8, or 10 */
870
871/* cfgPeripheral: 0-1 */
872
873#define PI_CLOCK_PWM 0
874#define PI_CLOCK_PCM 1
875
876/* DMA channel: 0-15, 15 is unset */
877
878#define PI_MIN_DMA_CHANNEL 0
879#define PI_MAX_DMA_CHANNEL 15
880
881/* port */
882
883#define PI_MIN_SOCKET_PORT 1024
884#define PI_MAX_SOCKET_PORT 32000
885
886
887/* ifFlags: */
888
889#define PI_DISABLE_FIFO_IF 1
890#define PI_DISABLE_SOCK_IF 2
891#define PI_LOCALHOST_SOCK_IF 4
892#define PI_DISABLE_ALERT 8
893
894/* memAllocMode */
895
896#define PI_MEM_ALLOC_AUTO 0
897#define PI_MEM_ALLOC_PAGEMAP 1
898#define PI_MEM_ALLOC_MAILBOX 2
899
900/* filters */
901
902#define PI_MAX_STEADY 300000
903#define PI_MAX_ACTIVE 1000000
904
905/* gpioCfgInternals */
906
907#define PI_CFG_DBG_LEVEL 0 /* bits 0-3 */
908#define PI_CFG_ALERT_FREQ 4 /* bits 4-7 */
909#define PI_CFG_RT_PRIORITY (1<<8)
910#define PI_CFG_STATS (1<<9)
911#define PI_CFG_NOSIGHANDLER (1<<10)
912
913#define PI_CFG_ILLEGAL_VAL (1<<11)
914
915
916/* gpioISR */
917
918#define RISING_EDGE 0
919#define FALLING_EDGE 1
920#define EITHER_EDGE 2
921
922
923/* pads */
924
925#define PI_MAX_PAD 2
926
927#define PI_MIN_PAD_STRENGTH 1
928#define PI_MAX_PAD_STRENGTH 16
929
930/* files */
931
932#define PI_FILE_NONE 0
933#define PI_FILE_MIN 1
934#define PI_FILE_READ 1
935#define PI_FILE_WRITE 2
936#define PI_FILE_RW 3
937#define PI_FILE_APPEND 4
938#define PI_FILE_CREATE 8
939#define PI_FILE_TRUNC 16
940#define PI_FILE_MAX 31
941
942#define PI_FROM_START 0
943#define PI_FROM_CURRENT 1
944#define PI_FROM_END 2
945
946/* Allowed socket connect addresses */
947
948#define MAX_CONNECT_ADDRESSES 256
949
950/* events */
951
952#define PI_MAX_EVENT 31
953
954/* Event auto generated on BSC slave activity */
955
956#define PI_EVENT_BSC 31
957
958/*F*/
960/*D
961Initialises the library.
962
963Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
964
965gpioInitialise must be called before using the other library functions
966with the following exceptions:
967
968. .
969[*gpioCfg**]
970[*gpioVersion*]
971[*gpioHardwareRevision*]
972. .
973
974...
975if (gpioInitialise() < 0)
976{
977 // pigpio initialisation failed.
978}
979else
980{
981 // pigpio initialised okay.
982}
983...
984D*/
985
986
987/*F*/
988void gpioTerminate(void);
989/*D
990Terminates the library.
991
992Returns nothing.
993
994Call before program exit.
995
996This function resets the used DMA channels, releases memory, and
997terminates any running threads.
998
999...
1000gpioTerminate();
1001...
1002D*/
1003
1004
1005/*F*/
1006int gpioSetMode(unsigned gpio, unsigned mode);
1007/*D
1008Sets the GPIO mode, typically input or output.
1009
1010. .
1011gpio: 0-53
1012mode: 0-7
1013. .
1014
1015Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE.
1016
1017Arduino style: pinMode.
1018
1019...
1020gpioSetMode(17, PI_INPUT); // Set GPIO17 as input.
1021
1022gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output.
1023
1024gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0.
1025...
1026
1027See [[http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf]] page 102 for an overview of the modes.
1028D*/
1029
1030
1031/*F*/
1032int gpioGetMode(unsigned gpio);
1033/*D
1034Gets the GPIO mode.
1035
1036. .
1037gpio: 0-53
1038. .
1039
1040Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
1041
1042...
1043if (gpioGetMode(17) != PI_ALT0)
1044{
1045 gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0
1046}
1047...
1048D*/
1049
1050
1051/*F*/
1052int gpioSetPullUpDown(unsigned gpio, unsigned pud);
1053/*D
1054Sets or clears resistor pull ups or downs on the GPIO.
1055
1056. .
1057gpio: 0-53
1058 pud: 0-2
1059. .
1060
1061Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD.
1062
1063...
1064gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up.
1065
1066gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.
1067
1068gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs.
1069...
1070D*/
1071
1072
1073/*F*/
1074int gpioRead (unsigned gpio);
1075/*D
1076Reads the GPIO level, on or off.
1077
1078. .
1079gpio: 0-53
1080. .
1081
1082Returns the GPIO level if OK, otherwise PI_BAD_GPIO.
1083
1084Arduino style: digitalRead.
1085
1086...
1087printf("GPIO24 is level %d", gpioRead(24));
1088...
1089D*/
1090
1091
1092/*F*/
1093int gpioWrite(unsigned gpio, unsigned level);
1094/*D
1095Sets the GPIO level, on or off.
1096
1097. .
1098 gpio: 0-53
1099level: 0-1
1100. .
1101
1102Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL.
1103
1104If PWM or servo pulses are active on the GPIO they are switched off.
1105
1106Arduino style: digitalWrite
1107
1108...
1109gpioWrite(24, 1); // Set GPIO24 high.
1110...
1111D*/
1112
1113
1114/*F*/
1115int gpioPWM(unsigned user_gpio, unsigned dutycycle);
1116/*D
1117Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on).
1118Range defaults to 255.
1119
1120. .
1121user_gpio: 0-31
1122dutycycle: 0-range
1123. .
1124
1125Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE.
1126
1127Arduino style: analogWrite
1128
1129This and the servo functionality use the DMA and PWM or PCM peripherals
1130to control and schedule the pulse lengths and dutycycles.
1131
1132The [*gpioSetPWMrange*] function may be used to change the default
1133range of 255.
1134
1135...
1136gpioPWM(17, 255); // Sets GPIO17 full on.
1137
1138gpioPWM(18, 128); // Sets GPIO18 half on.
1139
1140gpioPWM(23, 0); // Sets GPIO23 full off.
1141...
1142D*/
1143
1144
1145/*F*/
1146int gpioGetPWMdutycycle(unsigned user_gpio);
1147/*D
1148Returns the PWM dutycycle setting for the GPIO.
1149
1150. .
1151user_gpio: 0-31
1152. .
1153
1154Returns between 0 (off) and range (fully on) if OK, otherwise
1155PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
1156
1157For normal PWM the dutycycle will be out of the defined range
1158for the GPIO (see [*gpioGetPWMrange*]).
1159
1160If a hardware clock is active on the GPIO the reported dutycycle
1161will be 500000 (500k) out of 1000000 (1M).
1162
1163If hardware PWM is active on the GPIO the reported dutycycle
1164will be out of a 1000000 (1M).
1165
1166Normal PWM range defaults to 255.
1167D*/
1168
1169
1170/*F*/
1171int gpioSetPWMrange(unsigned user_gpio, unsigned range);
1172/*D
1173Selects the dutycycle range to be used for the GPIO. Subsequent calls
1174to gpioPWM will use a dutycycle between 0 (off) and range (fully on).
1175
1176. .
1177user_gpio: 0-31
1178 range: 25-40000
1179. .
1180
1181Returns the real range for the given GPIO's frequency if OK,
1182otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE.
1183
1184If PWM is currently active on the GPIO its dutycycle will be scaled
1185to reflect the new range.
1186
1187The real range, the number of steps between fully off and fully
1188on for each frequency, is given in the following table.
1189
1190. .
1191 25, 50, 100, 125, 200, 250, 400, 500, 625,
1192 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000
1193. .
1194
1195The real value set by [*gpioPWM*] is (dutycycle * real range) / range.
1196
1197...
1198gpioSetPWMrange(24, 2000); // Now 2000 is fully on
1199 // 1000 is half on
1200 // 500 is quarter on, etc.
1201...
1202D*/
1203
1204
1205/*F*/
1206int gpioGetPWMrange(unsigned user_gpio);
1207/*D
1208Returns the dutycycle range used for the GPIO if OK, otherwise
1209PI_BAD_USER_GPIO.
1210
1211. .
1212user_gpio: 0-31
1213. .
1214
1215If a hardware clock or hardware PWM is active on the GPIO
1216the reported range will be 1000000 (1M).
1217
1218...
1219r = gpioGetPWMrange(23);
1220...
1221D*/
1222
1223
1224/*F*/
1225int gpioGetPWMrealRange(unsigned user_gpio);
1226/*D
1227Returns the real range used for the GPIO if OK, otherwise
1228PI_BAD_USER_GPIO.
1229
1230. .
1231user_gpio: 0-31
1232. .
1233
1234If a hardware clock is active on the GPIO the reported real
1235range will be 1000000 (1M).
1236
1237If hardware PWM is active on the GPIO the reported real range
1238will be approximately 250M divided by the set PWM frequency.
1239
1240...
1241rr = gpioGetPWMrealRange(17);
1242...
1243D*/
1244
1245
1246/*F*/
1247int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency);
1248/*D
1249Sets the frequency in hertz to be used for the GPIO.
1250
1251. .
1252user_gpio: 0-31
1253frequency: >=0
1254. .
1255
1256Returns the numerically closest frequency if OK, otherwise
1257PI_BAD_USER_GPIO.
1258
1259If PWM is currently active on the GPIO it will be
1260switched off and then back on at the new frequency.
1261
1262Each GPIO can be independently set to one of 18 different PWM
1263frequencies.
1264
1265The selectable frequencies depend upon the sample rate which
1266may be 1, 2, 4, 5, 8, or 10 microseconds (default 5).
1267
1268The frequencies for each sample rate are:
1269
1270. .
1271 Hertz
1272
1273 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
1274 1250 1000 800 500 400 250 200 100 50
1275
1276 2: 20000 10000 5000 4000 2500 2000 1250 1000 800
1277 625 500 400 250 200 125 100 50 25
1278
1279 4: 10000 5000 2500 2000 1250 1000 625 500 400
1280 313 250 200 125 100 63 50 25 13
1281sample
1282 rate
1283 (us) 5: 8000 4000 2000 1600 1000 800 500 400 320
1284 250 200 160 100 80 50 40 20 10
1285
1286 8: 5000 2500 1250 1000 625 500 313 250 200
1287 156 125 100 63 50 31 25 13 6
1288
1289 10: 4000 2000 1000 800 500 400 250 200 160
1290 125 100 80 50 40 25 20 10 5
1291. .
1292
1293...
1294gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.
1295
1296gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.
1297
1298gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.
1299...
1300D*/
1301
1302
1303/*F*/
1304int gpioGetPWMfrequency(unsigned user_gpio);
1305/*D
1306Returns the frequency (in hertz) used for the GPIO if OK, otherwise
1307PI_BAD_USER_GPIO.
1308
1309. .
1310user_gpio: 0-31
1311. .
1312
1313For normal PWM the frequency will be that defined for the GPIO by
1314[*gpioSetPWMfrequency*].
1315
1316If a hardware clock is active on the GPIO the reported frequency
1317will be that set by [*gpioHardwareClock*].
1318
1319If hardware PWM is active on the GPIO the reported frequency
1320will be that set by [*gpioHardwarePWM*].
1321
1322...
1323f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.
1324...
1325D*/
1326
1327
1328/*F*/
1329int gpioServo(unsigned user_gpio, unsigned pulsewidth);
1330/*D
1331Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to
13322500 (most clockwise).
1333
1334. .
1335 user_gpio: 0-31
1336pulsewidth: 0, 500-2500
1337. .
1338
1339Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH.
1340
1341The range supported by servos varies and should probably be determined
1342by experiment. A value of 1500 should always be safe and represents
1343the mid-point of rotation. You can DAMAGE a servo if you command it
1344to move beyond its limits.
1345
1346The following causes an on pulse of 1500 microseconds duration to be
1347transmitted on GPIO 17 at a rate of 50 times per second. This will
1348command a servo connected to GPIO 17 to rotate to its mid-point.
1349
1350...
1351gpioServo(17, 1000); // Move servo to safe position anti-clockwise.
1352
1353gpioServo(23, 1500); // Move servo to centre position.
1354
1355gpioServo(25, 2000); // Move servo to safe position clockwise.
1356...
1357
1358OTHER UPDATE RATES:
1359
1360This function updates servos at 50Hz. If you wish to use a different
1361update frequency you will have to use the PWM functions.
1362
1363. .
1364PWM Hz 50 100 200 400 500
13651E6/Hz 20000 10000 5000 2500 2000
1366. .
1367
1368Firstly set the desired PWM frequency using [*gpioSetPWMfrequency*].
1369
1370Then set the PWM range using [*gpioSetPWMrange*] to 1E6/frequency.
1371Doing this allows you to use units of microseconds when setting
1372the servo pulsewidth.
1373
1374E.g. If you want to update a servo connected to GPIO25 at 400Hz
1375
1376. .
1377gpioSetPWMfrequency(25, 400);
1378
1379gpioSetPWMrange(25, 2500);
1380. .
1381
1382Thereafter use the PWM command to move the servo,
1383e.g. gpioPWM(25, 1500) will set a 1500 us pulse.
1384D*/
1385
1386
1387/*F*/
1388int gpioGetServoPulsewidth(unsigned user_gpio);
1389/*D
1390Returns the servo pulsewidth setting for the GPIO.
1391
1392. .
1393user_gpio: 0-31
1394. .
1395
1396Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise)
1397if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO.
1398D*/
1399
1400
1401/*F*/
1402int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f);
1403/*D
1404Registers a function to be called (a callback) when the specified
1405GPIO changes state.
1406
1407. .
1408user_gpio: 0-31
1409 f: the callback function
1410. .
1411
1412Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
1413
1414One callback may be registered per GPIO.
1415
1416The callback is passed the GPIO, the new level, and the tick.
1417
1418. .
1419Parameter Value Meaning
1420
1421GPIO 0-31 The GPIO which has changed state
1422
1423level 0-2 0 = change to low (a falling edge)
1424 1 = change to high (a rising edge)
1425 2 = no level change (a watchdog timeout)
1426
1427tick 32 bit The number of microseconds since boot
1428 WARNING: this wraps around from
1429 4294967295 to 0 roughly every 72 minutes
1430. .
1431
1432The alert may be cancelled by passing NULL as the function.
1433
1434The GPIO are sampled at a rate set when the library is started.
1435
1436If a value isn't specifically set the default of 5 us is used.
1437
1438The number of samples per second is given in the following table.
1439
1440. .
1441 samples
1442 per sec
1443
1444 1 1,000,000
1445 2 500,000
1446sample 4 250,000
1447rate 5 200,000
1448(us) 8 125,000
1449 10 100,000
1450. .
1451
1452Level changes shorter than the sample rate may be missed.
1453
1454The thread which calls the alert functions is triggered nominally
14551000 times per second. The active alert functions will be called
1456once per level change since the last time the thread was activated.
1457i.e. The active alert functions will get all level changes but there
1458will be a latency.
1459
1460If you want to track the level of more than one GPIO do so by
1461maintaining the state in the callback. Do not use [*gpioRead*].
1462Remember the event that triggered the callback may have
1463happened several milliseconds before and the GPIO may have
1464changed level many times since then.
1465
1466The tick value is the time stamp of the sample in microseconds, see
1467[*gpioTick*] for more details.
1468
1469...
1470void aFunction(int gpio, int level, uint32_t tick)
1471{
1472 printf("GPIO %d became %d at %d", gpio, level, tick);
1473}
1474
1475// call aFunction whenever GPIO 4 changes state
1476
1477gpioSetAlertFunc(4, aFunction);
1478...
1479D*/
1480
1481
1482/*F*/
1484 unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata);
1485/*D
1486Registers a function to be called (a callback) when the specified
1487GPIO changes state.
1488
1489. .
1490user_gpio: 0-31
1491 f: the callback function
1492 userdata: pointer to arbitrary user data
1493. .
1494
1495Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
1496
1497One callback may be registered per GPIO.
1498
1499The callback is passed the GPIO, the new level, the tick, and
1500the userdata pointer.
1501
1502. .
1503Parameter Value Meaning
1504
1505GPIO 0-31 The GPIO which has changed state
1506
1507level 0-2 0 = change to low (a falling edge)
1508 1 = change to high (a rising edge)
1509 2 = no level change (a watchdog timeout)
1510
1511tick 32 bit The number of microseconds since boot
1512 WARNING: this wraps around from
1513 4294967295 to 0 roughly every 72 minutes
1514
1515userdata pointer Pointer to an arbitrary object
1516. .
1517
1518See [*gpioSetAlertFunc*] for further details.
1519
1520Only one of [*gpioSetAlertFunc*] or [*gpioSetAlertFuncEx*] can be
1521registered per GPIO.
1522D*/
1523
1524
1525/*F*/
1527 unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f);
1528/*D
1529Registers a function to be called (a callback) whenever the specified
1530GPIO interrupt occurs.
1531
1532. .
1533 gpio: 0-53
1534 edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
1535timeout: interrupt timeout in milliseconds (<=0 to cancel)
1536 f: the callback function
1537. .
1538
1539Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
1540or PI_BAD_ISR_INIT.
1541
1542One function may be registered per GPIO.
1543
1544The function is passed the GPIO, the current level, and the
1545current tick. The level will be PI_TIMEOUT if the optional
1546interrupt timeout expires.
1547
1548. .
1549Parameter Value Meaning
1550
1551GPIO 0-53 The GPIO which has changed state
1552
1553level 0-2 0 = change to low (a falling edge)
1554 1 = change to high (a rising edge)
1555 2 = no level change (interrupt timeout)
1556
1557tick 32 bit The number of microseconds since boot
1558 WARNING: this wraps around from
1559 4294967295 to 0 roughly every 72 minutes
1560. .
1561
1562The underlying Linux sysfs GPIO interface is used to provide
1563the interrupt services.
1564
1565The first time the function is called, with a non-NULL f, the
1566GPIO is exported, set to be an input, and set to interrupt
1567on the given edge and timeout.
1568
1569Subsequent calls, with a non-NULL f, can vary one or more of the
1570edge, timeout, or function.
1571
1572The ISR may be cancelled by passing a NULL f, in which case the
1573GPIO is unexported.
1574
1575The tick is that read at the time the process was informed of
1576the interrupt. This will be a variable number of microseconds
1577after the interrupt occurred. Typically the latency will be of
1578the order of 50 microseconds. The latency is not guaranteed
1579and will vary with system load.
1580
1581The level is that read at the time the process was informed of
1582the interrupt, or PI_TIMEOUT if the optional interrupt timeout
1583expired. It may not be the same as the expected edge as
1584interrupts happening in rapid succession may be missed by the
1585kernel (i.e. this mechanism can not be used to capture several
1586interrupts only a few microseconds apart).
1587D*/
1588
1589
1590/*F*/
1592 unsigned gpio,
1593 unsigned edge,
1594 int timeout,
1596 void *userdata);
1597/*D
1598Registers a function to be called (a callback) whenever the specified
1599GPIO interrupt occurs.
1600
1601. .
1602 gpio: 0-53
1603 edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
1604 timeout: interrupt timeout in milliseconds (<=0 to cancel)
1605 f: the callback function
1606userdata: pointer to arbitrary user data
1607. .
1608
1609Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
1610or PI_BAD_ISR_INIT.
1611
1612The function is passed the GPIO, the current level, the
1613current tick, and the userdata pointer.
1614
1615. .
1616Parameter Value Meaning
1617
1618GPIO 0-53 The GPIO which has changed state
1619
1620level 0-2 0 = change to low (a falling edge)
1621 1 = change to high (a rising edge)
1622 2 = no level change (interrupt timeout)
1623
1624tick 32 bit The number of microseconds since boot
1625 WARNING: this wraps around from
1626 4294967295 to 0 roughly every 72 minutes
1627
1628userdata pointer Pointer to an arbitrary object
1629. .
1630
1631Only one of [*gpioSetISRFunc*] or [*gpioSetISRFuncEx*] can be
1632registered per GPIO.
1633
1634See [*gpioSetISRFunc*] for further details.
1635D*/
1636
1637
1638/*F*/
1640/*D
1641This function requests a free notification handle.
1642
1643Returns a handle greater than or equal to zero if OK,
1644otherwise PI_NO_HANDLE.
1645
1646A notification is a method for being notified of GPIO state changes
1647via a pipe or socket.
1648
1649Pipe notifications for handle x will be available at the pipe
1650named /dev/pigpiox (where x is the handle number). E.g. if the
1651function returns 15 then the notifications must be read
1652from /dev/pigpio15.
1653
1654Socket notifications are returned to the socket which requested the
1655handle.
1656
1657...
1658h = gpioNotifyOpen();
1659
1660if (h >= 0)
1661{
1662 sprintf(str, "/dev/pigpio%d", h);
1663
1664 fd = open(str, O_RDONLY);
1665
1666 if (fd >= 0)
1667 {
1668 // Okay.
1669 }
1670 else
1671 {
1672 // Error.
1673 }
1674}
1675else
1676{
1677 // Error.
1678}
1679...
1680D*/
1681
1682
1683/*F*/
1684int gpioNotifyOpenWithSize(int bufSize);
1685/*D
1686This function requests a free notification handle.
1687
1688It differs from [*gpioNotifyOpen*] in that the pipe size may be
1689specified, whereas [*gpioNotifyOpen*] uses the default pipe size.
1690
1691See [*gpioNotifyOpen*] for further details.
1692D*/
1693
1694
1695/*F*/
1696int gpioNotifyBegin(unsigned handle, uint32_t bits);
1697/*D
1698This function starts notifications on a previously opened handle.
1699
1700. .
1701handle: >=0, as returned by [*gpioNotifyOpen*]
1702 bits: a bit mask indicating the GPIO of interest
1703. .
1704
1705Returns 0 if OK, otherwise PI_BAD_HANDLE.
1706
1707The notification sends state changes for each GPIO whose corresponding
1708bit in bits is set.
1709
1710Each notification occupies 12 bytes in the fifo and has the
1711following structure.
1712
1713. .
1714typedef struct
1715{
1716 uint16_t seqno;
1717 uint16_t flags;
1718 uint32_t tick;
1719 uint32_t level;
1720} gpioReport_t;
1721. .
1722
1723seqno: starts at 0 each time the handle is opened and then increments
1724by one for each report.
1725
1726flags: three flags are defined, PI_NTFY_FLAGS_WDOG,
1727PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT.
1728
1729If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags
1730indicate a GPIO which has had a watchdog timeout.
1731
1732If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive
1733signal on the pipe/socket and is sent once a minute in the absence
1734of other notification activity.
1735
1736If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags
1737indicate an event which has been triggered.
1738
1739tick: the number of microseconds since system boot. It wraps around
1740after 1h12m.
1741
1742level: indicates the level of each GPIO. If bit 1<<x is set then
1743GPIO x is high.
1744
1745...
1746// Start notifications for GPIO 1, 4, 6, 7, 10.
1747
1748// 1
1749// 0 76 4 1
1750// (1234 = 0x04D2 = 0b0000010011010010)
1751
1752gpioNotifyBegin(h, 1234);
1753...
1754D*/
1755
1756
1757/*F*/
1758int gpioNotifyPause(unsigned handle);
1759/*D
1760This function pauses notifications on a previously opened handle.
1761
1762. .
1763handle: >=0, as returned by [*gpioNotifyOpen*]
1764. .
1765
1766Returns 0 if OK, otherwise PI_BAD_HANDLE.
1767
1768Notifications for the handle are suspended until [*gpioNotifyBegin*]
1769is called again.
1770
1771...
1772gpioNotifyPause(h);
1773...
1774D*/
1775
1776
1777/*F*/
1778int gpioNotifyClose(unsigned handle);
1779/*D
1780This function stops notifications on a previously opened handle
1781and releases the handle for reuse.
1782
1783. .
1784handle: >=0, as returned by [*gpioNotifyOpen*]
1785. .
1786
1787Returns 0 if OK, otherwise PI_BAD_HANDLE.
1788
1789...
1790gpioNotifyClose(h);
1791...
1792D*/
1793
1794
1795/*F*/
1797/*D
1798This function clears all waveforms and any data added by calls to the
1799[*gpioWaveAdd**] functions.
1800
1801Returns 0 if OK.
1802
1803...
1804gpioWaveClear();
1805...
1806D*/
1807
1808
1809/*F*/
1811/*D
1812This function starts a new empty waveform.
1813
1814You wouldn't normally need to call this function as it is automatically
1815called after a waveform is created with the [*gpioWaveCreate*] function.
1816
1817Returns 0 if OK.
1818
1819...
1820gpioWaveAddNew();
1821...
1822D*/
1823
1824
1825/*F*/
1826int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses);
1827/*D
1828This function adds a number of pulses to the current waveform.
1829
1830. .
1831numPulses: the number of pulses
1832 pulses: an array of pulses
1833. .
1834
1835Returns the new total number of pulses in the current waveform if OK,
1836otherwise PI_TOO_MANY_PULSES.
1837
1838The pulses are interleaved in time order within the existing waveform
1839(if any).
1840
1841Merging allows the waveform to be built in parts, that is the settings
1842for GPIO#1 can be added, and then GPIO#2 etc.
1843
1844If the added waveform is intended to start after or within the existing
1845waveform then the first pulse should consist of a delay.
1846
1847...
1848// Construct and send a 30 microsecond square wave.
1849
1850gpioSetMode(gpio, PI_OUTPUT);
1851
1852pulse[0].gpioOn = (1<<gpio);
1853pulse[0].gpioOff = 0;
1854pulse[0].usDelay = 15;
1855
1856pulse[1].gpioOn = 0;
1857pulse[1].gpioOff = (1<<gpio);
1858pulse[1].usDelay = 15;
1859
1860gpioWaveAddNew();
1861
1862gpioWaveAddGeneric(2, pulse);
1863
1864wave_id = gpioWaveCreate();
1865
1866if (wave_id >= 0)
1867{
1868 gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);
1869
1870 // Transmit for 30 seconds.
1871
1872 sleep(30);
1873
1874 gpioWaveTxStop();
1875}
1876else
1877{
1878 // Wave create failed.
1879}
1880...
1881D*/
1882
1883
1884/*F*/
1886 (unsigned user_gpio,
1887 unsigned baud,
1888 unsigned data_bits,
1889 unsigned stop_bits,
1890 unsigned offset,
1891 unsigned numBytes,
1892 char *str);
1893/*D
1894This function adds a waveform representing serial data to the
1895existing waveform (if any). The serial data starts offset
1896microseconds from the start of the waveform.
1897
1898. .
1899user_gpio: 0-31
1900 baud: 50-1000000
1901data_bits: 1-32
1902stop_bits: 2-8
1903 offset: >=0
1904 numBytes: >=1
1905 str: an array of chars (which may contain nulls)
1906. .
1907
1908Returns the new total number of pulses in the current waveform if OK,
1909otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS,
1910PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET,
1911or PI_TOO_MANY_PULSES.
1912
1913NOTES:
1914
1915The serial data is formatted as one start bit, data_bits data bits, and
1916stop_bits/2 stop bits.
1917
1918It is legal to add serial data streams with different baud rates to
1919the same waveform.
1920
1921numBytes is the number of bytes of data in str.
1922
1923The bytes required for each character depend upon data_bits.
1924
1925For data_bits 1-8 there will be one byte per character.
1926For data_bits 9-16 there will be two bytes per character.
1927For data_bits 17-32 there will be four bytes per character.
1928
1929...
1930#define MSG_LEN 8
1931
1932int i;
1933char *str;
1934char data[MSG_LEN];
1935
1936str = "Hello world!";
1937
1938gpioWaveAddSerial(4, 9600, 8, 2, 0, strlen(str), str);
1939
1940for (i=0; i<MSG_LEN; i++) data[i] = i;
1941
1942// Data added is offset 1 second from the waveform start.
1943gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);
1944...
1945D*/
1946
1947
1948/*F*/
1950/*D
1951This function creates a waveform from the data provided by the prior
1952calls to the [*gpioWaveAdd**] functions. Upon success a wave id
1953greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM,
1954PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
1955
1956The data provided by the [*gpioWaveAdd**] functions is consumed by this
1957function.
1958
1959As many waveforms may be created as there is space available. The
1960wave id is passed to [*gpioWaveTxSend*] to specify the waveform to transmit.
1961
1962Normal usage would be
1963
1964Step 1. [*gpioWaveClear*] to clear all waveforms and added data.
1965
1966Step 2. [*gpioWaveAdd**] calls to supply the waveform data.
1967
1968Step 3. [*gpioWaveCreate*] to create the waveform and get a unique id
1969
1970Repeat steps 2 and 3 as needed.
1971
1972Step 4. [*gpioWaveTxSend*] with the id of the waveform to transmit.
1973
1974A waveform comprises one of more pulses. Each pulse consists of a
1975[*gpioPulse_t*] structure.
1976
1977. .
1978typedef struct
1979{
1980 uint32_t gpioOn;
1981 uint32_t gpioOff;
1982 uint32_t usDelay;
1983} gpioPulse_t;
1984. .
1985
1986The fields specify
1987
19881) the GPIO to be switched on at the start of the pulse.
19892) the GPIO to be switched off at the start of the pulse.
19903) the delay in microseconds before the next pulse.
1991
1992Any or all the fields can be zero. It doesn't make any sense to
1993set all the fields to zero (the pulse will be ignored).
1994
1995When a waveform is started each pulse is executed in order with the
1996specified delay between the pulse and the next.
1997
1998Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
1999PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
2000D*/
2001
2002
2003/*F*/
2004int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL);
2005/*D
2006Similar to [*gpioWaveCreate*], this function creates a waveform but pads the consumed
2007resources. Padded waves of equal dimension can be re-cycled efficiently allowing
2008newly created waves to re-use the resources of deleted waves of the same dimension.
2009
2010. .
2011pctCB: 0-100, the percent of all DMA control blocks to consume.
2012pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
2013pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).
2014. .
2015
2016Upon success a wave id greater than or equal to 0 is returned, otherwise
2017PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
2018
2019Waveform data provided by [*gpioWaveAdd**] and [*rawWaveAdd**] functions are
2020consumed by this function.
2021
2022A usage would be the creation of two waves where one is filled while the other
2023is being transmitted. Each wave is assigned 50% of the resources.
2024This buffer structure allows the transmission of infinite wave sequences.
2025
2026...
2027 // get firstWaveChunk, somehow
2028 gpioWaveAddGeneric(firstWaveChunk);
2029 wid = gpioWaveCreatePad(50, 50, 0);
2030 gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
2031 // get nextWaveChunk
2032
2033 while (nextWaveChunk) {
2034 gpioWaveAddGeneric(nextWaveChunk);
2035 nextWid = gpioWaveCreatePad(50, 50, 0);
2036 gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
2037 while(gpioWaveTxAt() == wid) time_sleep(0.1);
2038 gpioWaveDelete(wid);
2039 wid = nextWid;
2040 // get nextWaveChunk
2041 }
2042...
2043
2044D*/
2045
2046/*F*/
2047int gpioWaveDelete(unsigned wave_id);
2048/*D
2049This function deletes the waveform with id wave_id.
2050
2051The wave is flagged for deletion. The resources used by the wave
2052will only be reused when either of the following apply.
2053
2054- all waves with higher numbered wave ids have been deleted or have
2055been flagged for deletion.
2056
2057- a new wave is created which uses exactly the same resources as
2058the current wave (see the C source for gpioWaveCreate for details).
2059
2060. .
2061wave_id: >=0, as returned by [*gpioWaveCreate*]
2062. .
2063
2064Wave ids are allocated in order, 0, 1, 2, etc.
2065
2066Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
2067D*/
2068
2069
2070/*F*/
2071int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode);
2072/*D
2073This function transmits the waveform with id wave_id. The mode
2074determines whether the waveform is sent once or cycles endlessly.
2075The SYNC variants wait for the current waveform to reach the
2076end of a cycle or finish before starting the new waveform.
2077
2078WARNING: bad things may happen if you delete the previous
2079waveform before it has been synced to the new waveform.
2080
2081NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled.
2082
2083. .
2084 wave_id: >=0, as returned by [*gpioWaveCreate*]
2085wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
2086 PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC
2087. .
2088
2089Returns the number of DMA control blocks in the waveform if OK,
2090otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
2091D*/
2092
2093
2094/*F*/
2095int gpioWaveChain(char *buf, unsigned bufSize);
2096/*D
2097This function transmits a chain of waveforms.
2098
2099NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled.
2100
2101The waves to be transmitted are specified by the contents of buf
2102which contains an ordered list of [*wave_id*]s and optional command
2103codes and related data.
2104
2105. .
2106 buf: pointer to the wave_ids and optional command codes
2107bufSize: the number of bytes in buf
2108. .
2109
2110Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
2111PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
2112
2113Each wave is transmitted in the order specified. A wave may
2114occur multiple times per chain.
2115
2116A blocks of waves may be transmitted multiple times by using
2117the loop commands. The block is bracketed by loop start and
2118end commands. Loops may be nested.
2119
2120Delays between waves may be added with the delay command.
2121
2122The following command codes are supported:
2123
2124Name @ Cmd & Data @ Meaning
2125Loop Start @ 255 0 @ Identify start of a wave block
2126Loop Repeat @ 255 1 x y @ loop x + y*256 times
2127Delay @ 255 2 x y @ delay x + y*256 microseconds
2128Loop Forever @ 255 3 @ loop forever
2129
2130If present Loop Forever must be the last entry in the chain.
2131
2132The code is currently dimensioned to support a chain with roughly
2133600 entries and 20 loop counters.
2134
2135...
2136#include <stdio.h>
2137#include <pigpio.h>
2138
2139#define WAVES 5
2140#define GPIO 4
2141
2142int main(int argc, char *argv[])
2143{
2144 int i, wid[WAVES];
2145
2146 if (gpioInitialise()<0) return -1;
2147
2148 gpioSetMode(GPIO, PI_OUTPUT);
2149
2150 printf("start piscope, press return"); getchar();
2151
2152 for (i=0; i<WAVES; i++)
2153 {
2154 gpioWaveAddGeneric(2, (gpioPulse_t[])
2155 {{1<<GPIO, 0, 20},
2156 {0, 1<<GPIO, (i+1)*200}});
2157
2158 wid[i] = gpioWaveCreate();
2159 }
2160
2161 gpioWaveChain((char []) {
2162 wid[4], wid[3], wid[2], // transmit waves 4+3+2
2163 255, 0, // loop start
2164 wid[0], wid[0], wid[0], // transmit waves 0+0+0
2165 255, 0, // loop start
2166 wid[0], wid[1], // transmit waves 0+1
2167 255, 2, 0x88, 0x13, // delay 5000us
2168 255, 1, 30, 0, // loop end (repeat 30 times)
2169 255, 0, // loop start
2170 wid[2], wid[3], wid[0], // transmit waves 2+3+0
2171 wid[3], wid[1], wid[2], // transmit waves 3+1+2
2172 255, 1, 10, 0, // loop end (repeat 10 times)
2173 255, 1, 5, 0, // loop end (repeat 5 times)
2174 wid[4], wid[4], wid[4], // transmit waves 4+4+4
2175 255, 2, 0x20, 0x4E, // delay 20000us
2176 wid[0], wid[0], wid[0], // transmit waves 0+0+0
2177
2178 }, 46);
2179
2180 while (gpioWaveTxBusy()) time_sleep(0.1);
2181
2182 for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);
2183
2184 printf("stop piscope, press return"); getchar();
2185
2186 gpioTerminate();
2187}
2188...
2189D*/
2190
2191
2192/*F*/
2194/*D
2195This function returns the id of the waveform currently being
2196transmitted using [*gpioWaveTxSend*]. Chained waves are not supported.
2197
2198Returns the waveform id or one of the following special values:
2199
2200PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.
2201PI_NO_TX_WAVE (9999) - no wave being transmitted.
2202D*/
2203
2204
2205/*F*/
2207/*D
2208This function checks to see if a waveform is currently being
2209transmitted.
2210
2211Returns 1 if a waveform is currently being transmitted, otherwise 0.
2212D*/
2213
2214
2215/*F*/
2217/*D
2218This function aborts the transmission of the current waveform.
2219
2220Returns 0 if OK.
2221
2222This function is intended to stop a waveform started in repeat mode.
2223D*/
2224
2225
2226/*F*/
2228/*D
2229This function returns the length in microseconds of the current
2230waveform.
2231D*/
2232
2233
2234/*F*/
2236/*D
2237This function returns the length in microseconds of the longest waveform
2238created since [*gpioInitialise*] was called.
2239D*/
2240
2241
2242/*F*/
2244/*D
2245This function returns the maximum possible size of a waveform in
2246microseconds.
2247D*/
2248
2249
2250/*F*/
2252/*D
2253This function returns the length in pulses of the current waveform.
2254D*/
2255
2256
2257/*F*/
2259/*D
2260This function returns the length in pulses of the longest waveform
2261created since [*gpioInitialise*] was called.
2262D*/
2263
2264
2265/*F*/
2267/*D
2268This function returns the maximum possible size of a waveform in pulses.
2269D*/
2270
2271
2272/*F*/
2274/*D
2275This function returns the length in DMA control blocks of the current
2276waveform.
2277D*/
2278
2279
2280/*F*/
2282/*D
2283This function returns the length in DMA control blocks of the longest
2284waveform created since [*gpioInitialise*] was called.
2285D*/
2286
2287
2288/*F*/
2290/*D
2291This function returns the maximum possible size of a waveform in DMA
2292control blocks.
2293D*/
2294
2295
2296/*F*/
2297int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits);
2298/*D
2299This function opens a GPIO for bit bang reading of serial data.
2300
2301. .
2302user_gpio: 0-31
2303 baud: 50-250000
2304data_bits: 1-32
2305. .
2306
2307Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
2308PI_BAD_DATABITS, or PI_GPIO_IN_USE.
2309
2310The serial data is returned in a cyclic buffer and is read using
2311[*gpioSerialRead*].
2312
2313It is the caller's responsibility to read data from the cyclic buffer
2314in a timely fashion.
2315D*/
2316
2317/*F*/
2318int gpioSerialReadInvert(unsigned user_gpio, unsigned invert);
2319/*D
2320This function configures the level logic for bit bang serial reads.
2321
2322Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for
2323normal logic. Default is PI_BB_SER_NORMAL.
2324
2325. .
2326user_gpio: 0-31
2327 invert: 0-1
2328. .
2329
2330Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE,
2331PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT.
2332
2333The GPIO must be opened for bit bang reading of serial data using
2334[*gpioSerialReadOpen*] prior to calling this function.
2335D*/
2336
2337
2338/*F*/
2339int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize);
2340/*D
2341This function copies up to bufSize bytes of data read from the
2342bit bang serial cyclic buffer to the buffer starting at buf.
2343
2344. .
2345user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*]
2346 buf: an array to receive the read bytes
2347 bufSize: >=0
2348. .
2349
2350Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
2351or PI_NOT_SERIAL_GPIO.
2352
2353The bytes returned for each character depend upon the number of
2354data bits [*data_bits*] specified in the [*gpioSerialReadOpen*] command.
2355
2356For [*data_bits*] 1-8 there will be one byte per character.
2357For [*data_bits*] 9-16 there will be two bytes per character.
2358For [*data_bits*] 17-32 there will be four bytes per character.
2359D*/
2360
2361
2362/*F*/
2363int gpioSerialReadClose(unsigned user_gpio);
2364/*D
2365This function closes a GPIO for bit bang reading of serial data.
2366
2367. .
2368user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*]
2369. .
2370
2371Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
2372D*/
2373
2374/*F*/
2375int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags);
2376/*D
2377This returns a handle for the device at the address on the I2C bus.
2378
2379. .
2380 i2cBus: >=0
2381 i2cAddr: 0-0x7F
2382i2cFlags: 0
2383. .
2384
2385No flags are currently defined. This parameter should be set to zero.
2386
2387Physically buses 0 and 1 are available on the Pi. Higher numbered buses
2388will be available if a kernel supported bus multiplexor is being used.
2389
2390The GPIO used are given in the following table.
2391
2392 @ SDA @ SCL
2393I2C 0 @ 0 @ 1
2394I2C 1 @ 2 @ 3
2395
2396Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
2397PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
2398
2399For the SMBus commands the low level transactions are shown at the end
2400of the function description. The following abbreviations are used.
2401
2402. .
2403S (1 bit) : Start bit
2404P (1 bit) : Stop bit
2405Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
2406A, NA (1 bit) : Accept and not accept bit.
2407Addr (7 bits): I2C 7 bit address.
2408i2cReg (8 bits): Command byte, a byte which often selects a register.
2409Data (8 bits): A data byte.
2410Count (8 bits): A byte defining the length of a block operation.
2411
2412[..]: Data sent by the device.
2413. .
2414D*/
2415
2416
2417/*F*/
2418int i2cClose(unsigned handle);
2419/*D
2420This closes the I2C device associated with the handle.
2421
2422. .
2423handle: >=0, as returned by a call to [*i2cOpen*]
2424. .
2425
2426Returns 0 if OK, otherwise PI_BAD_HANDLE.
2427D*/
2428
2429
2430/*F*/
2431int i2cWriteQuick(unsigned handle, unsigned bit);
2432/*D
2433This sends a single bit (in the Rd/Wr bit) to the device associated
2434with handle.
2435
2436. .
2437handle: >=0, as returned by a call to [*i2cOpen*]
2438 bit: 0-1, the value to write
2439. .
2440
2441Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2442PI_I2C_WRITE_FAILED.
2443
2444Quick command. SMBus 2.0 5.5.1
2445. .
2446S Addr bit [A] P
2447. .
2448D*/
2449
2450
2451/*F*/
2452int i2cWriteByte(unsigned handle, unsigned bVal);
2453/*D
2454This sends a single byte to the device associated with handle.
2455
2456. .
2457handle: >=0, as returned by a call to [*i2cOpen*]
2458 bVal: 0-0xFF, the value to write
2459. .
2460
2461Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2462PI_I2C_WRITE_FAILED.
2463
2464Send byte. SMBus 2.0 5.5.2
2465. .
2466S Addr Wr [A] bVal [A] P
2467. .
2468D*/
2469
2470
2471/*F*/
2472int i2cReadByte(unsigned handle);
2473/*D
2474This reads a single byte from the device associated with handle.
2475
2476. .
2477handle: >=0, as returned by a call to [*i2cOpen*]
2478. .
2479
2480Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
2481or PI_I2C_READ_FAILED.
2482
2483Receive byte. SMBus 2.0 5.5.3
2484. .
2485S Addr Rd [A] [Data] NA P
2486. .
2487D*/
2488
2489
2490/*F*/
2491int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal);
2492/*D
2493This writes a single byte to the specified register of the device
2494associated with handle.
2495
2496. .
2497handle: >=0, as returned by a call to [*i2cOpen*]
2498i2cReg: 0-255, the register to write
2499 bVal: 0-0xFF, the value to write
2500. .
2501
2502Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2503PI_I2C_WRITE_FAILED.
2504
2505Write byte. SMBus 2.0 5.5.4
2506. .
2507S Addr Wr [A] i2cReg [A] bVal [A] P
2508. .
2509D*/
2510
2511
2512/*F*/
2513int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal);
2514/*D
2515This writes a single 16 bit word to the specified register of the device
2516associated with handle.
2517
2518. .
2519handle: >=0, as returned by a call to [*i2cOpen*]
2520i2cReg: 0-255, the register to write
2521 wVal: 0-0xFFFF, the value to write
2522. .
2523
2524Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2525PI_I2C_WRITE_FAILED.
2526
2527Write word. SMBus 2.0 5.5.4
2528. .
2529S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P
2530. .
2531D*/
2532
2533
2534/*F*/
2535int i2cReadByteData(unsigned handle, unsigned i2cReg);
2536/*D
2537This reads a single byte from the specified register of the device
2538associated with handle.
2539
2540. .
2541handle: >=0, as returned by a call to [*i2cOpen*]
2542i2cReg: 0-255, the register to read
2543. .
2544
2545Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
2546PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2547
2548Read byte. SMBus 2.0 5.5.5
2549. .
2550S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P
2551. .
2552D*/
2553
2554
2555/*F*/
2556int i2cReadWordData(unsigned handle, unsigned i2cReg);
2557/*D
2558This reads a single 16 bit word from the specified register of the device
2559associated with handle.
2560
2561. .
2562handle: >=0, as returned by a call to [*i2cOpen*]
2563i2cReg: 0-255, the register to read
2564. .
2565
2566Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
2567PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2568
2569Read word. SMBus 2.0 5.5.5
2570. .
2571S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
2572. .
2573D*/
2574
2575
2576/*F*/
2577int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal);
2578/*D
2579This writes 16 bits of data to the specified register of the device
2580associated with handle and reads 16 bits of data in return.
2581
2582. .
2583handle: >=0, as returned by a call to [*i2cOpen*]
2584i2cReg: 0-255, the register to write/read
2585 wVal: 0-0xFFFF, the value to write
2586. .
2587
2588Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
2589PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2590
2591Process call. SMBus 2.0 5.5.6
2592. .
2593S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
2594 S Addr Rd [A] [DataLow] A [DataHigh] NA P
2595. .
2596D*/
2597
2598
2599/*F*/
2601unsigned handle, unsigned i2cReg, char *buf, unsigned count);
2602/*D
2603This writes up to 32 bytes to the specified register of the device
2604associated with handle.
2605
2606. .
2607handle: >=0, as returned by a call to [*i2cOpen*]
2608i2cReg: 0-255, the register to write
2609 buf: an array with the data to send
2610 count: 1-32, the number of bytes to write
2611. .
2612
2613Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2614PI_I2C_WRITE_FAILED.
2615
2616Block write. SMBus 2.0 5.5.7
2617. .
2618S Addr Wr [A] i2cReg [A] count [A]
2619 buf0 [A] buf1 [A] ... [A] bufn [A] P
2620. .
2621D*/
2622
2623
2624/*F*/
2625int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf);
2626/*D
2627This reads a block of up to 32 bytes from the specified register of
2628the device associated with handle.
2629
2630. .
2631handle: >=0, as returned by a call to [*i2cOpen*]
2632i2cReg: 0-255, the register to read
2633 buf: an array to receive the read data
2634. .
2635
2636The amount of returned data is set by the device.
2637
2638Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
2639PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2640
2641Block read. SMBus 2.0 5.5.7
2642. .
2643S Addr Wr [A] i2cReg [A]
2644 S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P
2645. .
2646D*/
2647
2648
2649/*F*/
2651unsigned handle, unsigned i2cReg, char *buf, unsigned count);
2652/*D
2653This writes data bytes to the specified register of the device
2654associated with handle and reads a device specified number
2655of bytes of data in return.
2656
2657. .
2658handle: >=0, as returned by a call to [*i2cOpen*]
2659i2cReg: 0-255, the register to write/read
2660 buf: an array with the data to send and to receive the read data
2661 count: 1-32, the number of bytes to write
2662. .
2663
2664Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
2665PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2666
2667The SMBus 2.0 documentation states that a minimum of 1 byte may be
2668sent and a minimum of 1 byte may be received. The total number of
2669bytes sent/received must be 32 or less.
2670
2671Block write-block read. SMBus 2.0 5.5.8
2672. .
2673S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
2674 S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P
2675. .
2676D*/
2677
2678
2679/*F*/
2681unsigned handle, unsigned i2cReg, char *buf, unsigned count);
2682/*D
2683This reads count bytes from the specified register of the device
2684associated with handle . The count may be 1-32.
2685
2686. .
2687handle: >=0, as returned by a call to [*i2cOpen*]
2688i2cReg: 0-255, the register to read
2689 buf: an array to receive the read data
2690 count: 1-32, the number of bytes to read
2691. .
2692
2693Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
2694PI_BAD_PARAM, or PI_I2C_READ_FAILED.
2695
2696. .
2697S Addr Wr [A] i2cReg [A]
2698 S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
2699. .
2700D*/
2701
2702
2703/*F*/
2705unsigned handle, unsigned i2cReg, char *buf, unsigned count);
2706/*D
2707This writes 1 to 32 bytes to the specified register of the device
2708associated with handle.
2709
2710. .
2711handle: >=0, as returned by a call to [*i2cOpen*]
2712i2cReg: 0-255, the register to write
2713 buf: the data to write
2714 count: 1-32, the number of bytes to write
2715. .
2716
2717Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2718PI_I2C_WRITE_FAILED.
2719
2720. .
2721S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
2722. .
2723D*/
2724
2725/*F*/
2726int i2cReadDevice(unsigned handle, char *buf, unsigned count);
2727/*D
2728This reads count bytes from the raw device into buf.
2729
2730. .
2731handle: >=0, as returned by a call to [*i2cOpen*]
2732 buf: an array to receive the read data bytes
2733 count: >0, the number of bytes to read
2734. .
2735
2736Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2737PI_I2C_READ_FAILED.
2738
2739. .
2740S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
2741. .
2742D*/
2743
2744
2745/*F*/
2746int i2cWriteDevice(unsigned handle, char *buf, unsigned count);
2747/*D
2748This writes count bytes from buf to the raw device.
2749
2750. .
2751handle: >=0, as returned by a call to [*i2cOpen*]
2752 buf: an array containing the data bytes to write
2753 count: >0, the number of bytes to write
2754. .
2755
2756Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
2757PI_I2C_WRITE_FAILED.
2758
2759. .
2760S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
2761. .
2762D*/
2763
2764/*F*/
2765void i2cSwitchCombined(int setting);
2766/*D
2767This sets the I2C (i2c-bcm2708) module "use combined transactions"
2768parameter on or off.
2769
2770. .
2771setting: 0 to set the parameter off, non-zero to set it on
2772. .
2773
2774
2775NOTE: when the flag is on a write followed by a read to the same
2776slave address will use a repeated start (rather than a stop/start).
2777D*/
2778
2779/*F*/
2780int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs);
2781/*D
2782This function executes multiple I2C segments in one transaction by
2783calling the I2C_RDWR ioctl.
2784
2785. .
2786 handle: >=0, as returned by a call to [*i2cOpen*]
2787 segs: an array of I2C segments
2788numSegs: >0, the number of I2C segments
2789. .
2790
2791Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG.
2792D*/
2793
2794/*F*/
2796 unsigned handle,
2797 char *inBuf,
2798 unsigned inLen,
2799 char *outBuf,
2800 unsigned outLen);
2801/*D
2802This function executes a sequence of I2C operations. The
2803operations to be performed are specified by the contents of inBuf
2804which contains the concatenated command codes and associated data.
2805
2806. .
2807handle: >=0, as returned by a call to [*i2cOpen*]
2808 inBuf: pointer to the concatenated I2C commands, see below
2809 inLen: size of command buffer
2810outBuf: pointer to buffer to hold returned data
2811outLen: size of output buffer
2812. .
2813
2814Returns >= 0 if OK (the number of bytes read), otherwise
2815PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN.
2816PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG.
2817
2818The following command codes are supported:
2819
2820Name @ Cmd & Data @ Meaning
2821End @ 0 @ No more commands
2822Escape @ 1 @ Next P is two bytes
2823On @ 2 @ Switch combined flag on
2824Off @ 3 @ Switch combined flag off
2825Address @ 4 P @ Set I2C address to P
2826Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8)
2827Read @ 6 P @ Read P bytes of data
2828Write @ 7 P ... @ Write P bytes of data
2829
2830The address, read, and write commands take a parameter P.
2831Normally P is one byte (0-255). If the command is preceded by
2832the Escape command then P is two bytes (0-65535, least significant
2833byte first).
2834
2835The address defaults to that associated with the handle.
2836The flags default to 0. The address and flags maintain their
2837previous value until updated.
2838
2839The returned I2C data is stored in consecutive locations of outBuf.
2840
2841...
2842Set address 0x53, write 0x32, read 6 bytes
2843Set address 0x1E, write 0x03, read 6 bytes
2844Set address 0x68, write 0x1B, read 8 bytes
2845End
2846
28470x04 0x53 0x07 0x01 0x32 0x06 0x06
28480x04 0x1E 0x07 0x01 0x03 0x06 0x06
28490x04 0x68 0x07 0x01 0x1B 0x06 0x08
28500x00
2851...
2852D*/
2853
2854/*F*/
2855int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud);
2856/*D
2857This function selects a pair of GPIO for bit banging I2C at a
2858specified baud rate.
2859
2860Bit banging I2C allows for certain operations which are not possible
2861with the standard I2C driver.
2862
2863o baud rates as low as 50
2864o repeated starts
2865o clock stretching
2866o I2C on any pair of spare GPIO
2867
2868. .
2869 SDA: 0-31
2870 SCL: 0-31
2871baud: 50-500000
2872. .
2873
2874Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or
2875PI_GPIO_IN_USE.
2876
2877NOTE:
2878
2879The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As
2880a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value.
2881D*/
2882
2883/*F*/
2884int bbI2CClose(unsigned SDA);
2885/*D
2886This function stops bit banging I2C on a pair of GPIO previously
2887opened with [*bbI2COpen*].
2888
2889. .
2890SDA: 0-31, the SDA GPIO used in a prior call to [*bbI2COpen*]
2891. .
2892
2893Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
2894D*/
2895
2896/*F*/
2898 unsigned SDA,
2899 char *inBuf,
2900 unsigned inLen,
2901 char *outBuf,
2902 unsigned outLen);
2903/*D
2904This function executes a sequence of bit banged I2C operations. The
2905operations to be performed are specified by the contents of inBuf
2906which contains the concatenated command codes and associated data.
2907
2908. .
2909 SDA: 0-31 (as used in a prior call to [*bbI2COpen*])
2910 inBuf: pointer to the concatenated I2C commands, see below
2911 inLen: size of command buffer
2912outBuf: pointer to buffer to hold returned data
2913outLen: size of output buffer
2914. .
2915
2916Returns >= 0 if OK (the number of bytes read), otherwise
2917PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER,
2918PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN,
2919PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED.
2920
2921The following command codes are supported:
2922
2923Name @ Cmd & Data @ Meaning
2924End @ 0 @ No more commands
2925Escape @ 1 @ Next P is two bytes
2926Start @ 2 @ Start condition
2927Stop @ 3 @ Stop condition
2928Address @ 4 P @ Set I2C address to P
2929Flags @ 5 lsb msb @ Set I2C flags to lsb + (msb << 8)
2930Read @ 6 P @ Read P bytes of data
2931Write @ 7 P ... @ Write P bytes of data
2932
2933The address, read, and write commands take a parameter P.
2934Normally P is one byte (0-255). If the command is preceded by
2935the Escape command then P is two bytes (0-65535, least significant
2936byte first).
2937
2938The address and flags default to 0. The address and flags maintain
2939their previous value until updated.
2940
2941No flags are currently defined.
2942
2943The returned I2C data is stored in consecutive locations of outBuf.
2944
2945...
2946Set address 0x53
2947start, write 0x32, (re)start, read 6 bytes, stop
2948Set address 0x1E
2949start, write 0x03, (re)start, read 6 bytes, stop
2950Set address 0x68
2951start, write 0x1B, (re)start, read 8 bytes, stop
2952End
2953
29540x04 0x53
29550x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03
2956
29570x04 0x1E
29580x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03
2959
29600x04 0x68
29610x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03
2962
29630x00
2964...
2965D*/
2966
2967/*F*/
2968int bscXfer(bsc_xfer_t *bsc_xfer);
2969/*D
2970This function provides a low-level interface to the SPI/I2C Slave
2971peripheral on the BCM chip.
2972
2973This peripheral allows the Pi to act as a hardware slave device
2974on an I2C or SPI bus.
2975
2976This is not a bit bang version and as such is OS timing
2977independent. The bus timing is handled directly by the chip.
2978
2979The output process is simple. You simply append data to the FIFO
2980buffer on the chip. This works like a queue, you add data to the
2981queue and the master removes it.
2982
2983The function sets the BSC mode, writes any data in
2984the transmit buffer to the BSC transmit FIFO, and
2985copies any data in the BSC receive FIFO to the
2986receive buffer.
2987
2988. .
2989bsc_xfer:= a structure defining the transfer
2990
2991typedef struct
2992{
2993 uint32_t control; // Write
2994 int rxCnt; // Read only
2995 char rxBuf[BSC_FIFO_SIZE]; // Read only
2996 int txCnt; // Write
2997 char txBuf[BSC_FIFO_SIZE]; // Write
2998} bsc_xfer_t;
2999. .
3000
3001To start a transfer set control (see below), copy the bytes to
3002be added to the transmit FIFO (if any) to txBuf and set txCnt to
3003the number of copied bytes.
3004
3005Upon return rxCnt will be set to the number of received bytes placed
3006in rxBuf.
3007
3008Note that the control word sets the BSC mode. The BSC will stay in
3009that mode until a different control word is sent.
3010
3011GPIO used for models other than those based on the BCM2711.
3012
3013 @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE
3014I2C @ 18 @ 19 @ - @ - @ - @ -
3015SPI @ - @ - @ 20 @ 19 @ 18 @ 21
3016
3017GPIO used for models based on the BCM2711 (e.g. the Pi4B).
3018
3019 @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE
3020I2C @ 10 @ 11 @ - @ - @ - @ -
3021SPI @ - @ - @ 9 @ 11 @ 10 @ 8
3022
3023When a zero control word is received the used GPIO will be reset
3024to INPUT mode.
3025
3026The returned function value is the status of the transfer (see below).
3027
3028If there was an error the status will be less than zero
3029(and will contain the error code).
3030
3031The most significant word of the returned status contains the number
3032of bytes actually copied from txBuf to the BSC transmit FIFO (may be
3033less than requested if the FIFO already contained untransmitted data).
3034
3035control consists of the following bits.
3036
3037. .
303822 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3039 a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN
3040. .
3041
3042Bits 0-13 are copied unchanged to the BSC CR register. See
3043pages 163-165 of the Broadcom peripherals document for full
3044details.
3045
3046aaaaaaa @ defines the I2C slave address (only relevant in I2C mode)
3047IT @ invert transmit status flags
3048HC @ enable host control
3049TF @ enable test FIFO
3050IR @ invert receive status flags
3051RE @ enable receive
3052TE @ enable transmit
3053BK @ abort operation and clear FIFOs
3054EC @ send control register as first I2C byte
3055ES @ send status register as first I2C byte
3056PL @ set SPI polarity high
3057PH @ set SPI phase high
3058I2 @ enable I2C mode
3059SP @ enable SPI mode
3060EN @ enable BSC peripheral
3061
3062The returned status has the following format
3063
3064. .
306520 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3066 S S S S S R R R R R T T T T T RB TE RF TF RE TB
3067. .
3068
3069Bits 0-15 are copied unchanged from the BSC FR register. See
3070pages 165-166 of the Broadcom peripherals document for full
3071details.
3072
3073SSSSS @ number of bytes successfully copied to transmit FIFO
3074RRRRR @ number of bytes in receive FIFO
3075TTTTT @ number of bytes in transmit FIFO
3076RB @ receive busy
3077TE @ transmit FIFO empty
3078RF @ receive FIFO full
3079TF @ transmit FIFO full
3080RE @ receive FIFO empty
3081TB @ transmit busy
3082
3083The following example shows how to configure the BSC peripheral as
3084an I2C slave with address 0x13 and send four bytes.
3085
3086...
3087bsc_xfer_t xfer;
3088
3089xfer.control = (0x13<<16) | 0x305;
3090
3091memcpy(xfer.txBuf, "ABCD", 4);
3092xfer.txCnt = 4;
3093
3094status = bscXfer(&xfer);
3095
3096if (status >= 0)
3097{
3098 // process transfer
3099}
3100...
3101
3102The BSC slave in SPI mode deserializes data from the MOSI pin into its
3103receiver/FIFO when the LSB of the first byte is a 0. No data is output on
3104the MISO pin. When the LSB of the first byte on MOSI is a 1, the
3105transmitter/FIFO data is serialized onto the MISO pin while all other data
3106on the MOSI pin is ignored.
3107
3108The BK bit of the BSC control register is non-functional when in the SPI
3109mode. The transmitter along with its FIFO can be dequeued by successively
3110disabling and re-enabling the TE bit on the BSC control register while in
3111SPI mode.
3112D*/
3113
3114/*F*/
3116 unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK,
3117 unsigned baud, unsigned spiFlags);
3118/*D
3119This function selects a set of GPIO for bit banging SPI with
3120a specified baud rate and mode.
3121
3122. .
3123 CS: 0-31
3124 MISO: 0-31
3125 MOSI: 0-31
3126 SCLK: 0-31
3127 baud: 50-250000
3128spiFlags: see below
3129. .
3130
3131spiFlags consists of the least significant 22 bits.
3132
3133. .
313421 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3135 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
3136. .
3137
3138mm defines the SPI mode, defaults to 0
3139
3140. .
3141Mode CPOL CPHA
3142 0 0 0
3143 1 0 1
3144 2 1 0
3145 3 1 1
3146. .
3147
3148p is 0 if CS is active low (default) and 1 for active high.
3149
3150T is 1 if the least significant bit is transmitted on MOSI first, the
3151default (0) shifts the most significant bit out first.
3152
3153R is 1 if the least significant bit is received on MISO first, the
3154default (0) receives the most significant bit first.
3155
3156The other bits in flags should be set to zero.
3157
3158Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
3159PI_GPIO_IN_USE.
3160
3161If more than one device is connected to the SPI bus (defined by
3162SCLK, MOSI, and MISO) each must have its own CS.
3163
3164...
3165bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
3166bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2
3167...
3168D*/
3169
3170/*F*/
3171int bbSPIClose(unsigned CS);
3172/*D
3173This function stops bit banging SPI on a set of GPIO
3174opened with [*bbSPIOpen*].
3175
3176. .
3177CS: 0-31, the CS GPIO used in a prior call to [*bbSPIOpen*]
3178. .
3179
3180Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
3181D*/
3182
3183/*F*/
3185 unsigned CS,
3186 char *inBuf,
3187 char *outBuf,
3188 unsigned count);
3189/*D
3190This function executes a bit banged SPI transfer.
3191
3192. .
3193 CS: 0-31 (as used in a prior call to [*bbSPIOpen*])
3194 inBuf: pointer to buffer to hold data to be sent
3195outBuf: pointer to buffer to hold returned data
3196 count: size of data transfer
3197. .
3198
3199Returns >= 0 if OK (the number of bytes read), otherwise
3200PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
3201
3202...
3203// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
3204// sudo ./bbSPIx_test
3205
3206
3207#include <stdio.h>
3208
3209#include "pigpio.h"
3210
3211#define CE0 5
3212#define CE1 6
3213#define MISO 13
3214#define MOSI 19
3215#define SCLK 12
3216
3217int main(int argc, char *argv[])
3218{
3219 int i, count, set_val, read_val;
3220 unsigned char inBuf[3];
3221 char cmd1[] = {0, 0};
3222 char cmd2[] = {12, 0};
3223 char cmd3[] = {1, 128, 0};
3224
3225 if (gpioInitialise() < 0)
3226 {
3227 fprintf(stderr, "pigpio initialisation failed.\n");
3228 return 1;
3229 }
3230
3231 bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
3232 bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
3233
3234 for (i=0; i<256; i++)
3235 {
3236 cmd1[1] = i;
3237
3238 count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC
3239
3240 if (count == 2)
3241 {
3242 count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC
3243
3244 if (count == 2)
3245 {
3246 set_val = inBuf[1];
3247
3248 count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC
3249
3250 if (count == 3)
3251 {
3252 read_val = ((inBuf[1]&3)<<8) | inBuf[2];
3253 printf("%d %d\n", set_val, read_val);
3254 }
3255 }
3256 }
3257 }
3258
3259 bbSPIClose(CE0);
3260 bbSPIClose(CE1);
3261
3262 gpioTerminate();
3263
3264 return 0;
3265}
3266...
3267D*/
3268
3269/*F*/
3270int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags);
3271/*D
3272This function returns a handle for the SPI device on the channel.
3273Data will be transferred at baud bits per second. The flags may
3274be used to modify the default behaviour of 4-wire operation, mode 0,
3275active low chip select.
3276
3277The Pi has two SPI peripherals: main and auxiliary.
3278
3279The main SPI has two chip selects (channels), the auxiliary has
3280three.
3281
3282The auxiliary SPI is available on all models but the A and B.
3283
3284The GPIO used are given in the following table.
3285
3286 @ MISO @ MOSI @ SCLK @ CE0 @ CE1 @ CE2
3287Main SPI @ 9 @ 10 @ 11 @ 8 @ 7 @ -
3288Aux SPI @ 19 @ 20 @ 21 @ 18 @ 17 @ 16
3289
3290. .
3291 spiChan: 0-1 (0-2 for the auxiliary SPI)
3292 baud: 32K-125M (values above 30M are unlikely to work)
3293spiFlags: see below
3294. .
3295
3296Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
3297PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED.
3298
3299spiFlags consists of the least significant 22 bits.
3300
3301. .
330221 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
3303 b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m
3304. .
3305
3306mm defines the SPI mode.
3307
3308Warning: modes 1 and 3 do not appear to work on the auxiliary SPI.
3309
3310. .
3311Mode POL PHA
3312 0 0 0
3313 1 0 1
3314 2 1 0
3315 3 1 1
3316. .
3317
3318px is 0 if CEx is active low (default) and 1 for active high.
3319
3320ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise.
3321
3322A is 0 for the main SPI, 1 for the auxiliary SPI.
3323
3324W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Main
3325SPI only.
3326
3327nnnn defines the number of bytes (0-15) to write before switching
3328the MOSI line to MISO to read data. This field is ignored
3329if W is not set. Main SPI only.
3330
3331T is 1 if the least significant bit is transmitted on MOSI first, the
3332default (0) shifts the most significant bit out first. Auxiliary SPI
3333only.
3334
3335R is 1 if the least significant bit is received on MISO first, the
3336default (0) receives the most significant bit first. Auxiliary SPI
3337only.
3338
3339bbbbbb defines the word size in bits (0-32). The default (0)
3340sets 8 bits per word. Auxiliary SPI only.
3341
3342The [*spiRead*], [*spiWrite*], and [*spiXfer*] functions
3343transfer data packed into 1, 2, or 4 bytes according to
3344the word size in bits.
3345
3346For bits 1-8 there will be one byte per word.
3347For bits 9-16 there will be two bytes per word.
3348For bits 17-32 there will be four bytes per word.
3349
3350Multi-byte transfers are made in least significant byte first order.
3351
3352E.g. to transfer 32 11-bit words buf should contain 64 bytes
3353and count should be 64.
3354
3355E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
3356by 0x1A.
3357
3358The other bits in flags should be set to zero.
3359D*/
3360
3361/*F*/
3362int spiClose(unsigned handle);
3363/*D
3364This functions closes the SPI device identified by the handle.
3365
3366. .
3367handle: >=0, as returned by a call to [*spiOpen*]
3368. .
3369
3370Returns 0 if OK, otherwise PI_BAD_HANDLE.
3371D*/
3372
3373
3374/*F*/
3375int spiRead(unsigned handle, char *buf, unsigned count);
3376/*D
3377This function reads count bytes of data from the SPI
3378device associated with the handle.
3379
3380. .
3381handle: >=0, as returned by a call to [*spiOpen*]
3382 buf: an array to receive the read data bytes
3383 count: the number of bytes to read
3384. .
3385
3386Returns the number of bytes transferred if OK, otherwise
3387PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
3388D*/
3389
3390
3391/*F*/
3392int spiWrite(unsigned handle, char *buf, unsigned count);
3393/*D
3394This function writes count bytes of data from buf to the SPI
3395device associated with the handle.
3396
3397. .
3398handle: >=0, as returned by a call to [*spiOpen*]
3399 buf: the data bytes to write
3400 count: the number of bytes to write
3401. .
3402
3403Returns the number of bytes transferred if OK, otherwise
3404PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
3405D*/
3406
3407/*F*/
3408int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count);
3409/*D
3410This function transfers count bytes of data from txBuf to the SPI
3411device associated with the handle. Simultaneously count bytes of
3412data are read from the device and placed in rxBuf.
3413
3414. .
3415handle: >=0, as returned by a call to [*spiOpen*]
3416 txBuf: the data bytes to write
3417 rxBuf: the received data bytes
3418 count: the number of bytes to transfer
3419. .
3420
3421Returns the number of bytes transferred if OK, otherwise
3422PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
3423D*/
3424
3425
3426/*F*/
3427int serOpen(char *sertty, unsigned baud, unsigned serFlags);
3428/*D
3429This function opens a serial device at a specified baud rate
3430and with specified flags. The device name must start with
3431/dev/tty or /dev/serial.
3432
3433. .
3434 sertty: the serial device to open
3435 baud: the baud rate in bits per second, see below
3436serFlags: 0
3437. .
3438
3439Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
3440PI_SER_OPEN_FAILED.
3441
3442The baud rate must be one of 50, 75, 110, 134, 150,
3443200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200,
344438400, 57600, 115200, or 230400.
3445
3446No flags are currently defined. This parameter should be set to zero.
3447D*/
3448
3449
3450/*F*/
3451int serClose(unsigned handle);
3452/*D
3453This function closes the serial device associated with handle.
3454
3455. .
3456handle: >=0, as returned by a call to [*serOpen*]
3457. .
3458
3459Returns 0 if OK, otherwise PI_BAD_HANDLE.
3460D*/
3461
3462/*F*/
3463int serWriteByte(unsigned handle, unsigned bVal);
3464/*D
3465This function writes bVal to the serial port associated with handle.
3466
3467. .
3468handle: >=0, as returned by a call to [*serOpen*]
3469. .
3470
3471Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
3472PI_SER_WRITE_FAILED.
3473D*/
3474
3475/*F*/
3476int serReadByte(unsigned handle);
3477/*D
3478This function reads a byte from the serial port associated with handle.
3479
3480. .
3481handle: >=0, as returned by a call to [*serOpen*]
3482. .
3483
3484Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
3485PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
3486
3487If no data is ready PI_SER_READ_NO_DATA is returned.
3488D*/
3489
3490/*F*/
3491int serWrite(unsigned handle, char *buf, unsigned count);
3492/*D
3493This function writes count bytes from buf to the the serial port
3494associated with handle.
3495
3496. .
3497handle: >=0, as returned by a call to [*serOpen*]
3498 buf: the array of bytes to write
3499 count: the number of bytes to write
3500. .
3501
3502Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
3503PI_SER_WRITE_FAILED.
3504D*/
3505
3506
3507/*F*/
3508int serRead(unsigned handle, char *buf, unsigned count);
3509/*D
3510This function reads up count bytes from the the serial port
3511associated with handle and writes them to buf.
3512
3513. .
3514handle: >=0, as returned by a call to [*serOpen*]
3515 buf: an array to receive the read data
3516 count: the maximum number of bytes to read
3517. .
3518
3519Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE,
3520PI_BAD_PARAM, or PI_SER_READ_NO_DATA.
3521
3522If no data is ready zero is returned.
3523D*/
3524
3525
3526/*F*/
3527int serDataAvailable(unsigned handle);
3528/*D
3529This function returns the number of bytes available
3530to be read from the device associated with handle.
3531
3532. .
3533handle: >=0, as returned by a call to [*serOpen*]
3534. .
3535
3536Returns the number of bytes of data available (>=0) if OK,
3537otherwise PI_BAD_HANDLE.
3538D*/
3539
3540
3541/*F*/
3542int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level);
3543/*D
3544This function sends a trigger pulse to a GPIO. The GPIO is set to
3545level for pulseLen microseconds and then reset to not level.
3546
3547. .
3548user_gpio: 0-31
3549 pulseLen: 1-100
3550 level: 0,1
3551. .
3552
3553Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
3554or PI_BAD_PULSELEN.
3555D*/
3556
3557
3558/*F*/
3559int gpioSetWatchdog(unsigned user_gpio, unsigned timeout);
3560/*D
3561Sets a watchdog for a GPIO.
3562
3563. .
3564user_gpio: 0-31
3565 timeout: 0-60000
3566. .
3567
3568Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT.
3569
3570The watchdog is nominally in milliseconds.
3571
3572One watchdog may be registered per GPIO.
3573
3574The watchdog may be cancelled by setting timeout to 0.
3575
3576Until cancelled a timeout will be reported every timeout milliseconds
3577after the last GPIO activity.
3578
3579In particular:
3580
35811) any registered alert function for the GPIO will be called with
3582 the level set to PI_TIMEOUT.
3583
35842) any notification for the GPIO will have a report written to the
3585 fifo with the flags set to indicate a watchdog timeout.
3586
3587...
3588void aFunction(int gpio, int level, uint32_t tick)
3589{
3590 printf("GPIO %d became %d at %d", gpio, level, tick);
3591}
3592
3593// call aFunction whenever GPIO 4 changes state
3594gpioSetAlertFunc(4, aFunction);
3595
3596// or approximately every 5 millis
3597gpioSetWatchdog(4, 5);
3598...
3599D*/
3600
3601
3602/*F*/
3603int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active);
3604/*D
3605Sets a noise filter on a GPIO.
3606
3607Level changes on the GPIO are ignored until a level which has
3608been stable for [*steady*] microseconds is detected. Level changes
3609on the GPIO are then reported for [*active*] microseconds after
3610which the process repeats.
3611
3612. .
3613user_gpio: 0-31
3614 steady: 0-300000
3615 active: 0-1000000
3616. .
3617
3618Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
3619
3620This filter affects the GPIO samples returned to callbacks set up
3621with [*gpioSetAlertFunc*], [*gpioSetAlertFuncEx*], [*gpioSetGetSamplesFunc*],
3622and [*gpioSetGetSamplesFuncEx*].
3623
3624It does not affect interrupts set up with [*gpioSetISRFunc*],
3625[*gpioSetISRFuncEx*], or levels read by [*gpioRead*],
3626[*gpioRead_Bits_0_31*], or [*gpioRead_Bits_32_53*].
3627
3628Level changes before and after the active period may
3629be reported. Your software must be designed to cope with
3630such reports.
3631D*/
3632
3633
3634/*F*/
3635int gpioGlitchFilter(unsigned user_gpio, unsigned steady);
3636/*D
3637Sets a glitch filter on a GPIO.
3638
3639Level changes on the GPIO are not reported unless the level
3640has been stable for at least [*steady*] microseconds. The
3641level is then reported. Level changes of less than [*steady*]
3642microseconds are ignored.
3643
3644. .
3645user_gpio: 0-31
3646 steady: 0-300000
3647. .
3648
3649Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
3650
3651This filter affects the GPIO samples returned to callbacks set up
3652with [*gpioSetAlertFunc*], [*gpioSetAlertFuncEx*], [*gpioSetGetSamplesFunc*],
3653and [*gpioSetGetSamplesFuncEx*].
3654
3655It does not affect interrupts set up with [*gpioSetISRFunc*],
3656[*gpioSetISRFuncEx*], or levels read by [*gpioRead*],
3657[*gpioRead_Bits_0_31*], or [*gpioRead_Bits_32_53*].
3658
3659Each (stable) edge will be timestamped [*steady*] microseconds
3660after it was first detected.
3661D*/
3662
3663
3664/*F*/
3666/*D
3667Registers a function to be called (a callback) every millisecond
3668with the latest GPIO samples.
3669
3670. .
3671 f: the function to call
3672bits: the GPIO of interest
3673. .
3674
3675Returns 0 if OK.
3676
3677The function is passed a pointer to the samples (an array of
3678[*gpioSample_t*]), and the number of samples.
3679
3680Only one function can be registered.
3681
3682The callback may be cancelled by passing NULL as the function.
3683
3684The samples returned will be the union of bits, plus any active alerts,
3685plus any active notifications.
3686
3687e.g. if there are alerts for GPIO 7, 8, and 9, notifications for GPIO
36888, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for GPIO
36897, 8, 9, 10, 17, 23, and 24 will be reported.
3690D*/
3691
3692
3693/*F*/
3695 gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata);
3696/*D
3697Registers a function to be called (a callback) every millisecond
3698with the latest GPIO samples.
3699
3700. .
3701 f: the function to call
3702 bits: the GPIO of interest
3703userdata: a pointer to arbitrary user data
3704. .
3705
3706Returns 0 if OK.
3707
3708The function is passed a pointer to the samples (an array of
3709[*gpioSample_t*]), the number of samples, and the userdata pointer.
3710
3711Only one of [*gpioGetSamplesFunc*] or [*gpioGetSamplesFuncEx*] can be
3712registered.
3713
3714See [*gpioSetGetSamplesFunc*] for further details.
3715D*/
3716
3717
3718/*F*/
3719int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f);
3720/*D
3721Registers a function to be called (a callback) every millis milliseconds.
3722
3723. .
3724 timer: 0-9
3725millis: 10-60000
3726 f: the function to call
3727. .
3728
3729Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
3730
373110 timers are supported numbered 0 to 9.
3732
3733One function may be registered per timer.
3734
3735The timer may be cancelled by passing NULL as the function.
3736
3737...
3738void bFunction(void)
3739{
3740 printf("two seconds have elapsed");
3741}
3742
3743// call bFunction every 2000 milliseconds
3744gpioSetTimerFunc(0, 2000, bFunction);
3745...
3746D*/
3747
3748
3749/*F*/
3751 unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata);
3752/*D
3753Registers a function to be called (a callback) every millis milliseconds.
3754
3755. .
3756 timer: 0-9.
3757 millis: 10-60000
3758 f: the function to call
3759userdata: a pointer to arbitrary user data
3760. .
3761
3762Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
3763
3764The function is passed the userdata pointer.
3765
3766Only one of [*gpioSetTimerFunc*] or [*gpioSetTimerFuncEx*] can be
3767registered per timer.
3768
3769See [*gpioSetTimerFunc*] for further details.
3770D*/
3771
3772
3773/*F*/
3774pthread_t *gpioStartThread(gpioThreadFunc_t f, void *userdata);
3775/*D
3776Starts a new thread of execution with f as the main routine.
3777
3778. .
3779 f: the main function for the new thread
3780userdata: a pointer to arbitrary user data
3781. .
3782
3783Returns a pointer to pthread_t if OK, otherwise NULL.
3784
3785The function is passed the single argument arg.
3786
3787The thread can be cancelled by passing the pointer to pthread_t to
3788[*gpioStopThread*].
3789
3790...
3791#include <stdio.h>
3792#include <pigpio.h>
3793
3794void *myfunc(void *arg)
3795{
3796 while (1)
3797 {
3798 printf("%s", arg);
3799 sleep(1);
3800 }
3801}
3802
3803int main(int argc, char *argv[])
3804{
3805 pthread_t *p1, *p2, *p3;
3806
3807 if (gpioInitialise() < 0) return 1;
3808
3809 p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);
3810
3811 p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);
3812
3813 p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);
3814
3815 gpioStopThread(p3); sleep(3);
3816
3817 gpioStopThread(p2); sleep(3);
3818
3819 gpioStopThread(p1); sleep(3);
3820
3821 gpioTerminate();
3822}
3823...
3824D*/
3825
3826
3827/*F*/
3828void gpioStopThread(pthread_t *pth);
3829/*D
3830Cancels the thread pointed at by pth.
3831
3832. .
3833pth: a thread pointer returned by [*gpioStartThread*]
3834. .
3835
3836No value is returned.
3837
3838The thread to be stopped should have been started with [*gpioStartThread*].
3839D*/
3840
3841
3842/*F*/
3843int gpioStoreScript(char *script);
3844/*D
3845This function stores a null terminated script for later execution.
3846
3847See [[http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts]] for details.
3848
3849. .
3850script: the text of the script
3851. .
3852
3853The function returns a script id if the script is valid,
3854otherwise PI_BAD_SCRIPT.
3855D*/
3856
3857
3858/*F*/
3859int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param);
3860/*D
3861This function runs a stored script.
3862
3863. .
3864script_id: >=0, as returned by [*gpioStoreScript*]
3865 numPar: 0-10, the number of parameters
3866 param: an array of parameters
3867. .
3868
3869The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
3870PI_TOO_MANY_PARAM.
3871
3872param is an array of up to 10 parameters which may be referenced in
3873the script as p0 to p9.
3874D*/
3875
3876
3877
3878/*F*/
3879int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param);
3880/*D
3881This function sets the parameters of a script. The script may or
3882may not be running. The first numPar parameters of the script are
3883overwritten with the new values.
3884
3885. .
3886script_id: >=0, as returned by [*gpioStoreScript*]
3887 numPar: 0-10, the number of parameters
3888 param: an array of parameters
3889. .
3890
3891The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
3892PI_TOO_MANY_PARAM.
3893
3894param is an array of up to 10 parameters which may be referenced in
3895the script as p0 to p9.
3896D*/
3897
3898
3899/*F*/
3900int gpioScriptStatus(unsigned script_id, uint32_t *param);
3901/*D
3902This function returns the run status of a stored script as well as
3903the current values of parameters 0 to 9.
3904
3905. .
3906script_id: >=0, as returned by [*gpioStoreScript*]
3907 param: an array to hold the returned 10 parameters
3908. .
3909
3910The function returns greater than or equal to 0 if OK,
3911otherwise PI_BAD_SCRIPT_ID.
3912
3913The run status may be
3914
3915. .
3916PI_SCRIPT_INITING
3917PI_SCRIPT_HALTED
3918PI_SCRIPT_RUNNING
3919PI_SCRIPT_WAITING
3920PI_SCRIPT_FAILED
3921. .
3922
3923The current value of script parameters 0 to 9 are returned in param.
3924D*/
3925
3926
3927/*F*/
3928int gpioStopScript(unsigned script_id);
3929/*D
3930This function stops a running script.
3931
3932. .
3933script_id: >=0, as returned by [*gpioStoreScript*]
3934. .
3935
3936The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
3937D*/
3938
3939
3940/*F*/
3941int gpioDeleteScript(unsigned script_id);
3942/*D
3943This function deletes a stored script.
3944
3945. .
3946script_id: >=0, as returned by [*gpioStoreScript*]
3947. .
3948
3949The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
3950D*/
3951
3952
3953/*F*/
3954int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f);
3955/*D
3956Registers a function to be called (a callback) when a signal occurs.
3957
3958. .
3959signum: 0-63
3960 f: the callback function
3961. .
3962
3963Returns 0 if OK, otherwise PI_BAD_SIGNUM.
3964
3965The function is passed the signal number.
3966
3967One function may be registered per signal.
3968
3969The callback may be cancelled by passing NULL.
3970
3971By default all signals are treated as fatal and cause the library
3972to call gpioTerminate and then exit.
3973D*/
3974
3975
3976/*F*/
3978 unsigned signum, gpioSignalFuncEx_t f, void *userdata);
3979/*D
3980Registers a function to be called (a callback) when a signal occurs.
3981
3982. .
3983 signum: 0-63
3984 f: the callback function
3985userdata: a pointer to arbitrary user data
3986. .
3987
3988Returns 0 if OK, otherwise PI_BAD_SIGNUM.
3989
3990The function is passed the signal number and the userdata pointer.
3991
3992Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be
3993registered per signal.
3994
3995See gpioSetSignalFunc for further details.
3996D*/
3997
3998
3999/*F*/
4000uint32_t gpioRead_Bits_0_31(void);
4001/*D
4002Returns the current level of GPIO 0-31.
4003D*/
4004
4005
4006/*F*/
4007uint32_t gpioRead_Bits_32_53(void);
4008/*D
4009Returns the current level of GPIO 32-53.
4010D*/
4011
4012
4013/*F*/
4014int gpioWrite_Bits_0_31_Clear(uint32_t bits);
4015/*D
4016Clears GPIO 0-31 if the corresponding bit in bits is set.
4017
4018. .
4019bits: a bit mask of GPIO to clear
4020. .
4021
4022Returns 0 if OK.
4023
4024...
4025// To clear (set to 0) GPIO 4, 7, and 15
4026gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );
4027...
4028D*/
4029
4030
4031/*F*/
4033/*D
4034Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
4035
4036. .
4037bits: a bit mask of GPIO to clear
4038. .
4039
4040Returns 0 if OK.
4041D*/
4042
4043
4044/*F*/
4045int gpioWrite_Bits_0_31_Set(uint32_t bits);
4046/*D
4047Sets GPIO 0-31 if the corresponding bit in bits is set.
4048
4049. .
4050bits: a bit mask of GPIO to set
4051. .
4052
4053Returns 0 if OK.
4054D*/
4055
4056
4057/*F*/
4058int gpioWrite_Bits_32_53_Set(uint32_t bits);
4059/*D
4060Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
4061
4062. .
4063bits: a bit mask of GPIO to set
4064. .
4065
4066Returns 0 if OK.
4067
4068...
4069// To set (set to 1) GPIO 32, 40, and 53
4070gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));
4071...
4072D*/
4073
4074/*F*/
4075int gpioHardwareClock(unsigned gpio, unsigned clkfreq);
4076/*D
4077Starts a hardware clock on a GPIO at the specified frequency.
4078Frequencies above 30MHz are unlikely to work.
4079
4080. .
4081 gpio: see description
4082clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)
4083. .
4084
4085Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO,
4086PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS.
4087
4088The same clock is available on multiple GPIO. The latest
4089frequency setting will be used by all GPIO which share a clock.
4090
4091The GPIO must be one of the following.
4092
4093. .
40944 clock 0 All models
40955 clock 1 All models but A and B (reserved for system use)
40966 clock 2 All models but A and B
409720 clock 0 All models but A and B
409821 clock 1 All models but A and Rev.2 B (reserved for system use)
4099
410032 clock 0 Compute module only
410134 clock 0 Compute module only
410242 clock 1 Compute module only (reserved for system use)
410343 clock 2 Compute module only
410444 clock 1 Compute module only (reserved for system use)
4105. .
4106
4107Access to clock 1 is protected by a password as its use will likely
4108crash the Pi. The password is given by or'ing 0x5A000000 with the
4109GPIO number.
4110D*/
4111
4112/*F*/
4113int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty);
4114/*D
4115Starts hardware PWM on a GPIO at the specified frequency and dutycycle.
4116Frequencies above 30MHz are unlikely to work.
4117
4118NOTE: Any waveform started by [*gpioWaveTxSend*], or
4119[*gpioWaveChain*] will be cancelled.
4120
4121This function is only valid if the pigpio main clock is PCM. The
4122main clock defaults to PCM but may be overridden by a call to
4123[*gpioCfgClock*].
4124
4125. .
4126 gpio: see description
4127PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
4128PWMduty: 0 (off) to 1000000 (1M)(fully on)
4129. .
4130
4131Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO,
4132PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL.
4133
4134The same PWM channel is available on multiple GPIO. The latest
4135frequency and dutycycle setting will be used by all GPIO which
4136share a PWM channel.
4137
4138The GPIO must be one of the following.
4139
4140. .
414112 PWM channel 0 All models but A and B
414213 PWM channel 1 All models but A and B
414318 PWM channel 0 All models
414419 PWM channel 1 All models but A and B
4145
414640 PWM channel 0 Compute module only
414741 PWM channel 1 Compute module only
414845 PWM channel 1 Compute module only
414952 PWM channel 0 Compute module only
415053 PWM channel 1 Compute module only
4151. .
4152
4153The actual number of steps beween off and fully on is the
4154integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711).
4155
4156The actual frequency set is 250M/steps (375M/steps for the BCM2711).
4157
4158There will only be a million steps for a PWMfreq of 250 (375 for
4159the BCM2711). Lower frequencies will have more steps and higher
4160frequencies will have fewer steps. PWMduty is
4161automatically scaled to take this into account.
4162D*/
4163
4164/*F*/
4165int gpioTime(unsigned timetype, int *seconds, int *micros);
4166/*D
4167Updates the seconds and micros variables with the current time.
4168
4169. .
4170timetype: 0 (relative), 1 (absolute)
4171 seconds: a pointer to an int to hold seconds
4172 micros: a pointer to an int to hold microseconds
4173. .
4174
4175Returns 0 if OK, otherwise PI_BAD_TIMETYPE.
4176
4177If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the
4178number of seconds and microseconds since the epoch (1st January 1970).
4179
4180If timetype is PI_TIME_RELATIVE updates seconds and micros with the
4181number of seconds and microseconds since the library was initialised.
4182
4183...
4184int secs, mics;
4185
4186// print the number of seconds since the library was started
4187gpioTime(PI_TIME_RELATIVE, &secs, &mics);
4188printf("library started %d.%03d seconds ago", secs, mics/1000);
4189...
4190D*/
4191
4192
4193/*F*/
4194int gpioSleep(unsigned timetype, int seconds, int micros);
4195/*D
4196Sleeps for the number of seconds and microseconds specified by seconds
4197and micros.
4198
4199. .
4200timetype: 0 (relative), 1 (absolute)
4201 seconds: seconds to sleep
4202 micros: microseconds to sleep
4203. .
4204
4205Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS,
4206or PI_BAD_MICROS.
4207
4208If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds
4209and microseconds since the epoch (1st January 1970) has elapsed. System
4210clock changes are taken into account.
4211
4212If timetype is PI_TIME_RELATIVE the sleep is for the specified number
4213of seconds and microseconds. System clock changes do not effect the
4214sleep length.
4215
4216For short delays (say, 50 microseonds or less) use [*gpioDelay*].
4217
4218...
4219gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds
4220
4221gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds
4222
4223gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute
4224...
4225D*/
4226
4227
4228/*F*/
4229uint32_t gpioDelay(uint32_t micros);
4230/*D
4231Delays for at least the number of microseconds specified by micros.
4232
4233. .
4234micros: the number of microseconds to sleep
4235. .
4236
4237Returns the actual length of the delay in microseconds.
4238
4239Delays of 100 microseconds or less use busy waits.
4240D*/
4241
4242
4243/*F*/
4244uint32_t gpioTick(void);
4245/*D
4246Returns the current system tick.
4247
4248Tick is the number of microseconds since system boot.
4249
4250As tick is an unsigned 32 bit quantity it wraps around after
42512^32 microseconds, which is approximately 1 hour 12 minutes.
4252
4253You don't need to worry about the wrap around as long as you
4254take a tick (uint32_t) from another tick, i.e. the following
4255code will always provide the correct difference.
4256
4257...
4258uint32_t startTick, endTick;
4259int diffTick;
4260
4261startTick = gpioTick();
4262
4263// do some processing
4264
4265endTick = gpioTick();
4266
4267diffTick = endTick - startTick;
4268
4269printf("some processing took %d microseconds", diffTick);
4270...
4271D*/
4272
4273
4274/*F*/
4276/*D
4277Returns the hardware revision.
4278
4279If the hardware revision can not be found or is not a valid hexadecimal
4280number the function returns 0.
4281
4282The hardware revision is the last few characters on the Revision line of
4283/proc/cpuinfo.
4284
4285The revision number can be used to determine the assignment of GPIO
4286to pins (see [*gpio*]).
4287
4288There are at least three types of board.
4289
4290Type 1 boards have hardware revision numbers of 2 and 3.
4291
4292Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
4293
4294Type 3 boards have hardware revision numbers of 16 or greater.
4295
4296for "Revision : 0002" the function returns 2.
4297for "Revision : 000f" the function returns 15.
4298for "Revision : 000g" the function returns 0.
4299D*/
4300
4301
4302/*F*/
4303unsigned gpioVersion(void);
4304/*D
4305Returns the pigpio version.
4306D*/
4307
4308
4309/*F*/
4310int gpioGetPad(unsigned pad);
4311/*D
4312This function returns the pad drive strength in mA.
4313
4314. .
4315pad: 0-2, the pad to get
4316. .
4317
4318Returns the pad drive strength if OK, otherwise PI_BAD_PAD.
4319
4320Pad @ GPIO
43210 @ 0-27
43221 @ 28-45
43232 @ 46-53
4324
4325...
4326strength = gpioGetPad(1); // get pad 1 strength
4327...
4328D*/
4329
4330
4331/*F*/
4332int gpioSetPad(unsigned pad, unsigned padStrength);
4333/*D
4334This function sets the pad drive strength in mA.
4335
4336. .
4337 pad: 0-2, the pad to set
4338padStrength: 1-16 mA
4339. .
4340
4341Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH.
4342
4343Pad @ GPIO
43440 @ 0-27
43451 @ 28-45
43462 @ 46-53
4347
4348...
4349gpioSetPad(0, 16); // set pad 0 strength to 16 mA
4350...
4351D*/
4352
4353/*F*/
4354int eventMonitor(unsigned handle, uint32_t bits);
4355/*D
4356This function selects the events to be reported on a previously
4357opened handle.
4358
4359. .
4360handle: >=0, as returned by [*gpioNotifyOpen*]
4361 bits: a bit mask indicating the events of interest
4362. .
4363
4364Returns 0 if OK, otherwise PI_BAD_HANDLE.
4365
4366A report is sent each time an event is triggered providing the
4367corresponding bit in bits is set.
4368
4369See [*gpioNotifyBegin*] for the notification format.
4370
4371...
4372// Start reporting events 3, 6, and 7.
4373
4374// bit 76543210
4375// (0xC8 = 0b11001000)
4376
4377eventMonitor(h, 0xC8);
4378...
4379
4380D*/
4381
4382/*F*/
4383int eventSetFunc(unsigned event, eventFunc_t f);
4384/*D
4385Registers a function to be called (a callback) when the specified
4386event occurs.
4387
4388. .
4389event: 0-31
4390 f: the callback function
4391. .
4392
4393Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
4394
4395One function may be registered per event.
4396
4397The function is passed the event, and the tick.
4398
4399The callback may be cancelled by passing NULL as the function.
4400D*/
4401
4402/*F*/
4403int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata);
4404/*D
4405Registers a function to be called (a callback) when the specified
4406event occurs.
4407
4408. .
4409 event: 0-31
4410 f: the callback function
4411userdata: pointer to arbitrary user data
4412. .
4413
4414Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
4415
4416One function may be registered per event.
4417
4418The function is passed the event, the tick, and the ueserdata pointer.
4419
4420The callback may be cancelled by passing NULL as the function.
4421
4422Only one of [*eventSetFunc*] or [*eventSetFuncEx*] can be
4423registered per event.
4424D*/
4425
4426/*F*/
4427int eventTrigger(unsigned event);
4428/*D
4429This function signals the occurrence of an event.
4430
4431. .
4432event: 0-31, the event
4433. .
4434
4435Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
4436
4437An event is a signal used to inform one or more consumers
4438to start an action. Each consumer which has registered an interest
4439in the event (e.g. by calling [*eventSetFunc*]) will be informed by
4440a callback.
4441
4442One event, PI_EVENT_BSC (31) is predefined. This event is
4443auto generated on BSC slave activity.
4444
4445The meaning of other events is arbitrary.
4446
4447Note that other than its id and its tick there is no data associated
4448with an event.
4449D*/
4450
4451
4452/*F*/
4453int shell(char *scriptName, char *scriptString);
4454/*D
4455This function uses the system call to execute a shell script
4456with the given string as its parameter.
4457
4458. .
4459 scriptName: the name of the script, only alphanumeric characters,
4460 '-' and '_' are allowed in the name
4461scriptString: the string to pass to the script
4462. .
4463
4464The exit status of the system call is returned if OK, otherwise
4465PI_BAD_SHELL_STATUS.
4466
4467scriptName must exist in /opt/pigpio/cgi and must be executable.
4468
4469The returned exit status is normally 256 times that set by the
4470shell script exit function. If the script can't be found 32512 will
4471be returned.
4472
4473The following table gives some example returned statuses.
4474
4475Script exit status @ Returned system call status
44761 @ 256
44775 @ 1280
447810 @ 2560
4479200 @ 51200
4480script not found @ 32512
4481
4482...
4483// pass two parameters, hello and world
4484status = shell("scr1", "hello world");
4485
4486// pass three parameters, hello, string with spaces, and world
4487status = shell("scr1", "hello 'string with spaces' world");
4488
4489// pass one parameter, hello string with spaces world
4490status = shell("scr1", "\"hello string with spaces world\"");
4491...
4492D*/
4493
4494#pragma GCC diagnostic push
4495
4496#pragma GCC diagnostic ignored "-Wcomment"
4497
4498/*F*/
4499int fileOpen(char *file, unsigned mode);
4500/*D
4501This function returns a handle to a file opened in a specified mode.
4502
4503. .
4504file: the file to open
4505mode: the file open mode
4506. .
4507
4508Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS,
4509PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR.
4510
4511File
4512
4513A file may only be opened if permission is granted by an entry in
4514/opt/pigpio/access. This is intended to allow remote access to files
4515in a more or less controlled manner.
4516
4517Each entry in /opt/pigpio/access takes the form of a file path
4518which may contain wildcards followed by a single letter permission.
4519The permission may be R for read, W for write, U for read/write,
4520and N for no access.
4521
4522Where more than one entry matches a file the most specific rule
4523applies. If no entry matches a file then access is denied.
4524
4525Suppose /opt/pigpio/access contains the following entries
4526
4527. .
4528/home/* n
4529/home/pi/shared/dir_1/* w
4530/home/pi/shared/dir_2/* r
4531/home/pi/shared/dir_3/* u
4532/home/pi/shared/dir_1/file.txt n
4533. .
4534
4535Files may be written in directory dir_1 with the exception
4536of file.txt.
4537
4538Files may be read in directory dir_2.
4539
4540Files may be read and written in directory dir_3.
4541
4542If a directory allows read, write, or read/write access then files may
4543be created in that directory.
4544
4545In an attempt to prevent risky permissions the following paths are
4546ignored in /opt/pigpio/access.
4547
4548. .
4549a path containing ..
4550a path containing only wildcards (*?)
4551a path containing less than two non-wildcard parts
4552. .
4553
4554Mode
4555
4556The mode may have the following values.
4557
4558Macro @ Value @ Meaning
4559PI_FILE_READ @ 1 @ open file for reading
4560PI_FILE_WRITE @ 2 @ open file for writing
4561PI_FILE_RW @ 3 @ open file for reading and writing
4562
4563The following values may be or'd into the mode.
4564
4565Macro @ Value @ Meaning
4566PI_FILE_APPEND @ 4 @ Writes append data to the end of the file
4567PI_FILE_CREATE @ 8 @ The file is created if it doesn't exist
4568PI_FILE_TRUNC @ 16 @ The file is truncated
4569
4570Newly created files are owned by root with permissions owner read and write.
4571
4572...
4573#include <stdio.h>
4574#include <pigpio.h>
4575
4576int main(int argc, char *argv[])
4577{
4578 int handle, c;
4579 char buf[60000];
4580
4581 if (gpioInitialise() < 0) return 1;
4582
4583 // assumes /opt/pigpio/access contains the following line
4584 // /ram/*.c r
4585
4586 handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);
4587
4588 if (handle >= 0)
4589 {
4590 while ((c=fileRead(handle, buf, sizeof(buf)-1)))
4591 {
4592 buf[c] = 0;
4593 printf("%s", buf);
4594 }
4595
4596 fileClose(handle);
4597 }
4598
4599 gpioTerminate();
4600}
4601...
4602D*/
4603
4604#pragma GCC diagnostic pop
4605
4606/*F*/
4607int fileClose(unsigned handle);
4608/*D
4609This function closes the file associated with handle.
4610
4611. .
4612handle: >=0, as returned by a call to [*fileOpen*]
4613. .
4614
4615Returns 0 if OK, otherwise PI_BAD_HANDLE.
4616
4617...
4618fileClose(h);
4619...
4620D*/
4621
4622
4623/*F*/
4624int fileWrite(unsigned handle, char *buf, unsigned count);
4625/*D
4626This function writes count bytes from buf to the the file
4627associated with handle.
4628
4629. .
4630handle: >=0, as returned by a call to [*fileOpen*]
4631 buf: the array of bytes to write
4632 count: the number of bytes to write
4633. .
4634
4635Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM,
4636PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE.
4637
4638...
4639status = fileWrite(h, buf, count);
4640if (status == 0)
4641{
4642 // okay
4643}
4644else
4645{
4646 // error
4647}
4648...
4649D*/
4650
4651
4652/*F*/
4653int fileRead(unsigned handle, char *buf, unsigned count);
4654/*D
4655This function reads up to count bytes from the the file
4656associated with handle and writes them to buf.
4657
4658. .
4659handle: >=0, as returned by a call to [*fileOpen*]
4660 buf: an array to receive the read data
4661 count: the maximum number of bytes to read
4662. .
4663
4664Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE.
4665
4666...
4667if (fileRead(h, buf, sizeof(buf)) > 0)
4668{
4669 // process read data
4670}
4671...
4672D*/
4673
4674
4675/*F*/
4676int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom);
4677/*D
4678This function seeks to a position within the file associated
4679with handle.
4680
4681. .
4682 handle: >=0, as returned by a call to [*fileOpen*]
4683seekOffset: the number of bytes to move. Positive offsets
4684 move forward, negative offsets backwards.
4685 seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
4686 or PI_FROM_END (2)
4687. .
4688
4689Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK.
4690
4691...
4692fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20
4693
4694size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size
4695
4696pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position
4697...
4698D*/
4699
4700#pragma GCC diagnostic push
4701
4702#pragma GCC diagnostic ignored "-Wcomment"
4703
4704/*F*/
4705int fileList(char *fpat, char *buf, unsigned count);
4706/*D
4707This function returns a list of files which match a pattern. The
4708pattern may contain wildcards.
4709
4710. .
4711 fpat: file pattern to match
4712 buf: an array to receive the matching file names
4713count: the maximum number of bytes to read
4714. .
4715
4716Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS,
4717or PI_NO_FILE_MATCH.
4718
4719The pattern must match an entry in /opt/pigpio/access. The pattern
4720may contain wildcards. See [*fileOpen*].
4721
4722NOTE
4723
4724The returned value is not the number of files, it is the number
4725of bytes in the buffer. The file names are separated by newline
4726characters.
4727
4728...
4729#include <stdio.h>
4730#include <pigpio.h>
4731
4732int main(int argc, char *argv[])
4733{
4734 int c;
4735 char buf[1000];
4736
4737 if (gpioInitialise() < 0) return 1;
4738
4739 // assumes /opt/pigpio/access contains the following line
4740 // /ram/*.c r
4741
4742 c = fileList("/ram/p*.c", buf, sizeof(buf));
4743
4744 if (c >= 0)
4745 {
4746 // terminate string
4747 buf[c] = 0;
4748 printf("%s", buf);
4749 }
4750
4751 gpioTerminate();
4752}
4753...
4754D*/
4755
4756#pragma GCC diagnostic pop
4757
4758
4759/*F*/
4760int gpioCfgBufferSize(unsigned cfgMillis);
4761/*D
4762Configures pigpio to buffer cfgMillis milliseconds of GPIO samples.
4763
4764This function is only effective if called before [*gpioInitialise*].
4765
4766. .
4767cfgMillis: 100-10000
4768. .
4769
4770The default setting is 120 milliseconds.
4771
4772The intention is to allow for bursts of data and protection against
4773other processes hogging cpu time.
4774
4775I haven't seen a process locked out for more than 100 milliseconds.
4776
4777Making the buffer bigger uses a LOT of memory at the more frequent
4778sampling rates as shown in the following table in MBs.
4779
4780. .
4781 buffer milliseconds
4782 120 250 500 1sec 2sec 4sec 8sec
4783
4784 1 16 31 55 107 --- --- ---
4785 2 10 18 31 55 107 --- ---
4786sample 4 8 12 18 31 55 107 ---
4787 rate 5 8 10 14 24 45 87 ---
4788 (us) 8 6 8 12 18 31 55 107
4789 10 6 8 10 14 24 45 87
4790. .
4791D*/
4792
4793
4794/*F*/
4796 unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource);
4797/*D
4798Configures pigpio to use a particular sample rate timed by a specified
4799peripheral.
4800
4801This function is only effective if called before [*gpioInitialise*].
4802
4803. .
4804 cfgMicros: 1, 2, 4, 5, 8, 10
4805cfgPeripheral: 0 (PWM), 1 (PCM)
4806 cfgSource: deprecated, value is ignored
4807. .
4808
4809The timings are provided by the specified peripheral (PWM or PCM).
4810
4811The default setting is 5 microseconds using the PCM peripheral.
4812
4813The approximate CPU percentage used for each sample rate is:
4814
4815. .
4816sample cpu
4817 rate %
4818
4819 1 25
4820 2 16
4821 4 11
4822 5 10
4823 8 15
4824 10 14
4825. .
4826
4827A sample rate of 5 microseconds seeems to be the sweet spot.
4828D*/
4829
4830
4831/*F*/
4832int gpioCfgDMAchannel(unsigned DMAchannel); /* DEPRECATED */
4833/*D
4834Configures pigpio to use the specified DMA channel.
4835
4836This function is only effective if called before [*gpioInitialise*].
4837
4838. .
4839DMAchannel: 0-14
4840. .
4841
4842The default setting is to use channel 14.
4843D*/
4844
4845
4846/*F*/
4847int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel);
4848/*D
4849Configures pigpio to use the specified DMA channels.
4850
4851This function is only effective if called before [*gpioInitialise*].
4852
4853. .
4854 primaryChannel: 0-14
4855secondaryChannel: 0-14
4856. .
4857
4858The default setting depends on whether the Pi has a BCM2711 chip or
4859not (currently only the Pi4B has a BCM2711).
4860
4861The default setting for a non-BCM2711 is to use channel 14 for the
4862primary channel and channel 6 for the secondary channel.
4863
4864The default setting for a BCM2711 is to use channel 7 for the
4865primary channel and channel 6 for the secondary channel.
4866
4867The secondary channel is only used for the transmission of waves.
4868
4869If possible use one of channels 0 to 6 for the secondary channel
4870(a full channel).
4871
4872A full channel only requires one DMA control block regardless of the
4873length of a pulse delay. Channels 7 to 14 (lite channels) require
4874one DMA control block for each 16383 microseconds of delay. I.e.
4875a 10 second pulse delay requires one control block on a full channel
4876and 611 control blocks on a lite channel.
4877D*/
4878
4879
4880/*F*/
4881int gpioCfgPermissions(uint64_t updateMask);
4882/*D
4883Configures pigpio to restrict GPIO updates via the socket or pipe
4884interfaces to the GPIO specified by the mask. Programs directly
4885calling the pigpio library (i.e. linked with -lpigpio are not
4886affected). A GPIO update is a write to a GPIO or a GPIO mode
4887change or any function which would force such an action.
4888
4889This function is only effective if called before [*gpioInitialise*].
4890
4891. .
4892updateMask: bit (1<<n) is set for each GPIO n which may be updated
4893. .
4894
4895The default setting depends upon the Pi model. The user GPIO are
4896added to the mask.
4897
4898If the board revision is not recognised then GPIO 2-27 are allowed.
4899
4900Unknown board @ PI_DEFAULT_UPDATE_MASK_UNKNOWN @ 0x0FFFFFFC
4901Type 1 board @ PI_DEFAULT_UPDATE_MASK_B1 @ 0x03E6CF93
4902Type 2 board @ PI_DEFAULT_UPDATE_MASK_A_B2 @ 0xFBC6CF9C
4903Type 3 board @ PI_DEFAULT_UPDATE_MASK_R3 @ 0x0FFFFFFC
4904D*/
4905
4906
4907/*F*/
4908int gpioCfgSocketPort(unsigned port);
4909/*D
4910Configures pigpio to use the specified socket port.
4911
4912This function is only effective if called before [*gpioInitialise*].
4913
4914. .
4915port: 1024-32000
4916. .
4917
4918The default setting is to use port 8888.
4919D*/
4920
4921
4922/*F*/
4923int gpioCfgInterfaces(unsigned ifFlags);
4924/*D
4925Configures pigpio support of the fifo and socket interfaces.
4926
4927This function is only effective if called before [*gpioInitialise*].
4928
4929. .
4930ifFlags: 0-7
4931. .
4932
4933The default setting (0) is that both interfaces are enabled.
4934
4935Or in PI_DISABLE_FIFO_IF to disable the pipe interface.
4936
4937Or in PI_DISABLE_SOCK_IF to disable the socket interface.
4938
4939Or in PI_LOCALHOST_SOCK_IF to disable remote socket
4940access (this means that the socket interface is only
4941usable from the local Pi).
4942D*/
4943
4944
4945/*F*/
4946int gpioCfgMemAlloc(unsigned memAllocMode);
4947/*D
4948Selects the method of DMA memory allocation.
4949
4950This function is only effective if called before [*gpioInitialise*].
4951
4952. .
4953memAllocMode: 0-2
4954. .
4955
4956There are two methods of DMA memory allocation. The original method
4957uses the /proc/self/pagemap file to allocate bus memory. The new
4958method uses the mailbox property interface to allocate bus memory.
4959
4960Auto will use the mailbox method unless a larger than default buffer
4961size is requested with [*gpioCfgBufferSize*].
4962D*/
4963
4964
4965/*F*/
4966int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr);
4967/*D
4968Sets the network addresses which are allowed to talk over the
4969socket interface.
4970
4971This function is only effective if called before [*gpioInitialise*].
4972
4973. .
4974numSockAddr: 0-256 (0 means all addresses allowed)
4975 sockAddr: an array of permitted network addresses.
4976. .
4977D*/
4978
4979
4980/*F*/
4981uint32_t gpioCfgGetInternals(void);
4982/*D
4983This function returns the current library internal configuration
4984settings.
4985D*/
4986
4987/*F*/
4988int gpioCfgSetInternals(uint32_t cfgVal);
4989/*D
4990This function sets the current library internal configuration
4991settings.
4992
4993. .
4994cfgVal: see source code
4995. .
4996
4997D*/
4998
4999
5000/*F*/
5001int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc);
5002/*D
5003This function is available for user customisation.
5004
5005It returns a single integer value.
5006
5007. .
5008arg1: >=0
5009arg2: >=0
5010argx: extra (byte) arguments
5011argc: number of extra arguments
5012. .
5013
5014Returns >= 0 if OK, less than 0 indicates a user defined error.
5015D*/
5016
5017
5018/*F*/
5019int gpioCustom2(unsigned arg1, char *argx, unsigned argc,
5020 char *retBuf, unsigned retMax);
5021/*D
5022This function is available for user customisation.
5023
5024It differs from gpioCustom1 in that it returns an array of bytes
5025rather than just an integer.
5026
5027The returned value is an integer indicating the number of returned bytes.
5028. .
5029 arg1: >=0
5030 argx: extra (byte) arguments
5031 argc: number of extra arguments
5032retBuf: buffer for returned bytes
5033retMax: maximum number of bytes to return
5034. .
5035
5036Returns >= 0 if OK, less than 0 indicates a user defined error.
5037
5038The number of returned bytes must be retMax or less.
5039D*/
5040
5041
5042/*F*/
5044 rawSPI_t *spi,
5045 unsigned offset,
5046 unsigned spiSS,
5047 char *buf,
5048 unsigned spiTxBits,
5049 unsigned spiBitFirst,
5050 unsigned spiBitLast,
5051 unsigned spiBits);
5052/*D
5053This function adds a waveform representing SPI data to the
5054existing waveform (if any).
5055
5056. .
5057 spi: a pointer to a spi object
5058 offset: microseconds from the start of the waveform
5059 spiSS: the slave select GPIO
5060 buf: the bits to transmit, most significant bit first
5061 spiTxBits: the number of bits to write
5062spiBitFirst: the first bit to read
5063 spiBitLast: the last bit to read
5064 spiBits: the number of bits to transfer
5065. .
5066
5067Returns the new total number of pulses in the current waveform if OK,
5068otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
5069
5070Not intended for general use.
5071D*/
5072
5073/*F*/
5074int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses);
5075/*D
5076This function adds a number of pulses to the current waveform.
5077
5078. .
5079numPulses: the number of pulses
5080 pulses: the array containing the pulses
5081. .
5082
5083Returns the new total number of pulses in the current waveform if OK,
5084otherwise PI_TOO_MANY_PULSES.
5085
5086The advantage of this function over gpioWaveAddGeneric is that it
5087allows the setting of the flags field.
5088
5089The pulses are interleaved in time order within the existing waveform
5090(if any).
5091
5092Merging allows the waveform to be built in parts, that is the settings
5093for GPIO#1 can be added, and then GPIO#2 etc.
5094
5095If the added waveform is intended to start after or within the existing
5096waveform then the first pulse should consist of a delay.
5097
5098Not intended for general use.
5099D*/
5100
5101/*F*/
5102unsigned rawWaveCB(void);
5103/*D
5104Returns the number of the cb being currently output.
5105
5106Not intended for general use.
5107D*/
5108
5109/*F*/
5111/*D
5112Return the (Linux) address of contol block cbNum.
5113
5114. .
5115cbNum: the cb of interest
5116. .
5117
5118Not intended for general use.
5119D*/
5120
5121/*F*/
5122uint32_t rawWaveGetOOL(int pos);
5123/*D
5124Gets the OOL parameter stored at pos.
5125
5126. .
5127pos: the position of interest.
5128. .
5129
5130Not intended for general use.
5131D*/
5132
5133
5134/*F*/
5135void rawWaveSetOOL(int pos, uint32_t lVal);
5136/*D
5137Sets the OOL parameter stored at pos to value.
5138
5139. .
5140 pos: the position of interest
5141lVal: the value to write
5142. .
5143
5144Not intended for general use.
5145D*/
5146
5147/*F*/
5148uint32_t rawWaveGetOut(int pos);
5149/*D
5150Gets the wave output parameter stored at pos.
5151
5152DEPRECATED: use rawWaveGetOOL instead.
5153
5154. .
5155pos: the position of interest.
5156. .
5157
5158Not intended for general use.
5159D*/
5160
5161
5162/*F*/
5163void rawWaveSetOut(int pos, uint32_t lVal);
5164/*D
5165Sets the wave output parameter stored at pos to value.
5166
5167DEPRECATED: use rawWaveSetOOL instead.
5168
5169. .
5170 pos: the position of interest
5171lVal: the value to write
5172. .
5173
5174Not intended for general use.
5175D*/
5176
5177/*F*/
5178uint32_t rawWaveGetIn(int pos);
5179/*D
5180Gets the wave input value parameter stored at pos.
5181
5182DEPRECATED: use rawWaveGetOOL instead.
5183
5184. .
5185pos: the position of interest
5186. .
5187
5188Not intended for general use.
5189D*/
5190
5191
5192/*F*/
5193void rawWaveSetIn(int pos, uint32_t lVal);
5194/*D
5195Sets the wave input value stored at pos to value.
5196
5197DEPRECATED: use rawWaveSetOOL instead.
5198
5199. .
5200 pos: the position of interest
5201lVal: the value to write
5202. .
5203
5204Not intended for general use.
5205D*/
5206
5207/*F*/
5209/*D
5210Gets details about the wave with id wave_id.
5211
5212. .
5213wave_id: the wave of interest
5214. .
5215
5216Not intended for general use.
5217D*/
5218
5219/*F*/
5220int getBitInBytes(int bitPos, char *buf, int numBits);
5221/*D
5222Returns the value of the bit bitPos bits from the start of buf. Returns
52230 if bitPos is greater than or equal to numBits.
5224
5225. .
5226 bitPos: bit index from the start of buf
5227 buf: array of bits
5228numBits: number of valid bits in buf
5229. .
5230
5231D*/
5232
5233/*F*/
5234void putBitInBytes(int bitPos, char *buf, int bit);
5235/*D
5236Sets the bit bitPos bits from the start of buf to bit.
5237
5238. .
5239bitPos: bit index from the start of buf
5240 buf: array of bits
5241 bit: 0-1, value to set
5242. .
5243
5244D*/
5245
5246/*F*/
5247double time_time(void);
5248/*D
5249Return the current time in seconds since the Epoch.
5250D*/
5251
5252
5253/*F*/
5254void time_sleep(double seconds);
5255/*D
5256Delay execution for a given number of seconds
5257
5258. .
5259seconds: the number of seconds to sleep
5260. .
5261D*/
5262
5263
5264/*F*/
5265void rawDumpWave(void);
5266/*D
5267Used to print a readable version of the current waveform to stderr.
5268
5269Not intended for general use.
5270D*/
5271
5272
5273/*F*/
5274void rawDumpScript(unsigned script_id);
5275/*D
5276Used to print a readable version of a script to stderr.
5277
5278. .
5279script_id: >=0, a script_id returned by [*gpioStoreScript*]
5280. .
5281
5282Not intended for general use.
5283D*/
5284
5285
5286#ifdef __cplusplus
5287}
5288#endif
5289
5290/*PARAMS
5291
5292active :: 0-1000000
5293
5294The number of microseconds level changes are reported for once
5295a noise filter has been triggered (by [*steady*] microseconds of
5296a stable level).
5297
5298arg1::
5299
5300An unsigned argument passed to a user customised function. Its
5301meaning is defined by the customiser.
5302
5303arg2::
5304
5305An unsigned argument passed to a user customised function. Its
5306meaning is defined by the customiser.
5307
5308argc::
5309The count of bytes passed to a user customised function.
5310
5311*argx::
5312A pointer to an array of bytes passed to a user customised function.
5313Its meaning and content is defined by the customiser.
5314
5315baud::
5316The speed of serial communication (I2C, SPI, serial link, waves) in
5317bits per second.
5318
5319bit::
5320A value of 0 or 1.
5321
5322bitPos::
5323A bit position within a byte or word. The least significant bit is
5324position 0.
5325
5326bits::
5327A value used to select GPIO. If bit n of bits is set then GPIO n is
5328selected.
5329
5330A convenient way to set bit n is to or in (1<<n).
5331
5332e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23).
5333
5334*bsc_xfer::
5335A pointer to a [*bsc_xfer_t*] object used to control a BSC transfer.
5336
5337bsc_xfer_t::
5338
5339. .
5340typedef struct
5341{
5342 uint32_t control; // Write
5343 int rxCnt; // Read only
5344 char rxBuf[BSC_FIFO_SIZE]; // Read only
5345 int txCnt; // Write
5346 char txBuf[BSC_FIFO_SIZE]; // Write
5347} bsc_xfer_t;
5348. .
5349
5350*buf::
5351
5352A buffer to hold data being sent or being received.
5353
5354bufSize::
5355
5356The size in bytes of a buffer.
5357
5358bVal::0-255 (Hex 0x0-0xFF, Octal 0-0377)
5359
5360An 8-bit byte value.
5361
5362cbNum::
5363
5364A number identifying a DMA contol block.
5365
5366cfgMicros::
5367
5368The GPIO sample rate in microseconds. The default is 5us, or 200 thousand
5369samples per second.
5370
5371cfgMillis:: 100-10000
5372
5373The size of the sample buffer in milliseconds. Generally this should be
5374left at the default of 120ms. If you expect intense bursts of signals it
5375might be necessary to increase the buffer size.
5376
5377cfgPeripheral::
5378
5379One of the PWM or PCM peripherals used to pace DMA transfers for timing
5380purposes.
5381
5382cfgSource::
5383
5384Deprecated.
5385
5386cfgVal::
5387
5388A number specifying the value of a configuration item. See [*cfgWhat*].
5389
5390cfgWhat::
5391
5392A number specifying a configuration item.
5393
5394562484977: print enhanced statistics at termination.
5395984762879: set the initial debug level.
5396
5397char::
5398
5399A single character, an 8 bit quantity able to store 0-255.
5400
5401clkfreq::4689-250M (13184-375M for the BCM2711)
5402
5403The hardware clock frequency.
5404
5405. .
5406PI_HW_CLK_MIN_FREQ 4689
5407PI_HW_CLK_MAX_FREQ 250000000
5408PI_HW_CLK_MAX_FREQ_2711 375000000
5409. .
5410
5411count::
5412The number of bytes to be transferred in an I2C, SPI, or Serial
5413command.
5414
5415CS::
5416The GPIO used for the slave select signal when bit banging SPI.
5417
5418data_bits::1-32
5419
5420The number of data bits to be used when adding serial data to a
5421waveform.
5422
5423. .
5424PI_MIN_WAVE_DATABITS 1
5425PI_MAX_WAVE_DATABITS 32
5426. .
5427
5428DMAchannel::0-15
5429. .
5430PI_MIN_DMA_CHANNEL 0
5431PI_MAX_DMA_CHANNEL 15
5432. .
5433
5434double::
5435
5436A floating point number.
5437
5438dutycycle::0-range
5439
5440A number representing the ratio of on time to off time for PWM.
5441
5442The number may vary between 0 and range (default 255) where
54430 is off and range is fully on.
5444
5445edge::0-2
5446The type of GPIO edge to generate an interrupt. See [*gpioSetISRFunc*]
5447and [*gpioSetISRFuncEx*].
5448
5449. .
5450RISING_EDGE 0
5451FALLING_EDGE 1
5452EITHER_EDGE 2
5453. .
5454
5455event::0-31
5456An event is a signal used to inform one or more consumers
5457to start an action.
5458
5459eventFunc_t::
5460. .
5461typedef void (*eventFunc_t) (int event, uint32_t tick);
5462. .
5463
5464eventFuncEx_t::
5465. .
5466typedef void (*eventFuncEx_t)
5467 (int event, uint32_t tick, void *userdata);
5468. .
5469
5470f::
5471
5472A function.
5473
5474*file::
5475A full file path. To be accessible the path must match an entry in
5476/opt/pigpio/access.
5477
5478*fpat::
5479A file path which may contain wildcards. To be accessible the path
5480must match an entry in /opt/pigpio/access.
5481
5482frequency::>=0
5483
5484The number of times a GPIO is swiched on and off per second. This
5485can be set per GPIO and may be as little as 5Hz or as much as
548640KHz. The GPIO will be on for a proportion of the time as defined
5487by its dutycycle.
5488
5489gpio::
5490
5491A Broadcom numbered GPIO, in the range 0-53.
5492
5493There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through
5494GPIO53.
5495
5496They are split into two banks. Bank 1 consists of GPIO0 through
5497GPIO31. Bank 2 consists of GPIO32 through GPIO53.
5498
5499All the GPIO which are safe for the user to read and write are in
5500bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards
5501have 17 safe GPIO. Type 2 boards have 21. Type 3 boards have 26.
5502
5503See [*gpioHardwareRevision*].
5504
5505The user GPIO are marked with an X in the following table.
5506
5507. .
5508 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
5509Type 1 X X - - X - - X X X X X - - X X
5510Type 2 - - X X X - - X X X X X - - X X
5511Type 3 X X X X X X X X X X X X X X
5512
5513 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
5514Type 1 - X X - - X X X X X - - - - - -
5515Type 2 - X X - - - X X X X - X X X X X
5516Type 3 X X X X X X X X X X X X - - - -
5517. .
5518
5519gpioAlertFunc_t::
5520. .
5521typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);
5522. .
5523
5524gpioAlertFuncEx_t::
5525. .
5526typedef void (*eventFuncEx_t)
5527 (int event, int level, uint32_t tick, void *userdata);
5528. .
5529
5530gpioCfg*::
5531
5532These functions are only effective if called before [*gpioInitialise*].
5533
5534[*gpioCfgBufferSize*]
5535[*gpioCfgClock*]
5536[*gpioCfgDMAchannel*]
5537[*gpioCfgDMAchannels*]
5538[*gpioCfgPermissions*]
5539[*gpioCfgInterfaces*]
5540[*gpioCfgSocketPort*]
5541[*gpioCfgMemAlloc*]
5542
5543gpioGetSamplesFunc_t::
5544. .
5545typedef void (*gpioGetSamplesFunc_t)
5546 (const gpioSample_t *samples, int numSamples);
5547. .
5548
5549gpioGetSamplesFuncEx_t::
5550. .
5551typedef void (*gpioGetSamplesFuncEx_t)
5552 (const gpioSample_t *samples, int numSamples, void *userdata);
5553. .
5554
5555gpioISRFunc_t::
5556. .
5557typedef void (*gpioISRFunc_t)
5558 (int gpio, int level, uint32_t tick);
5559. .
5560
5561gpioISRFuncEx_t::
5562. .
5563typedef void (*gpioISRFuncEx_t)
5564 (int gpio, int level, uint32_t tick, void *userdata);
5565. .
5566
5567gpioPulse_t::
5568. .
5569typedef struct
5570{
5571 uint32_t gpioOn;
5572 uint32_t gpioOff;
5573 uint32_t usDelay;
5574} gpioPulse_t;
5575. .
5576
5577gpioSample_t::
5578. .
5579typedef struct
5580{
5581 uint32_t tick;
5582 uint32_t level;
5583} gpioSample_t;
5584. .
5585
5586gpioSignalFunc_t::
5587. .
5588typedef void (*gpioSignalFunc_t) (int signum);
5589. .
5590
5591gpioSignalFuncEx_t::
5592. .
5593typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);
5594. .
5595
5596gpioThreadFunc_t::
5597. .
5598typedef void *(gpioThreadFunc_t) (void *);
5599. .
5600
5601gpioTimerFunc_t::
5602. .
5603typedef void (*gpioTimerFunc_t) (void);
5604. .
5605
5606gpioTimerFuncEx_t::
5607. .
5608typedef void (*gpioTimerFuncEx_t) (void *userdata);
5609. .
5610
5611gpioWaveAdd*::
5612
5613One of
5614
5615[*gpioWaveAddNew*]
5616[*gpioWaveAddGeneric*]
5617[*gpioWaveAddSerial*]
5618
5619handle::>=0
5620
5621A number referencing an object opened by one of
5622
5623[*fileOpen*]
5624[*gpioNotifyOpen*]
5625[*i2cOpen*]
5626[*serOpen*]
5627[*spiOpen*]
5628
5629i2cAddr:: 0-0x7F
5630The address of a device on the I2C bus.
5631
5632i2cBus::>=0
5633
5634An I2C bus number.
5635
5636i2cFlags::0
5637
5638Flags which modify an I2C open command. None are currently defined.
5639
5640i2cReg:: 0-255
5641
5642A register of an I2C device.
5643
5644ifFlags::0-3
5645. .
5646PI_DISABLE_FIFO_IF 1
5647PI_DISABLE_SOCK_IF 2
5648. .
5649
5650*inBuf::
5651A buffer used to pass data to a function.
5652
5653inLen::
5654The number of bytes of data in a buffer.
5655
5656int::
5657A whole number, negative or positive.
5658
5659int32_t::
5660A 32-bit signed value.
5661
5662invert::
5663A flag used to set normal or inverted bit bang serial data level logic.
5664
5665level::
5666The level of a GPIO. Low or High.
5667
5668. .
5669PI_OFF 0
5670PI_ON 1
5671
5672PI_CLEAR 0
5673PI_SET 1
5674
5675PI_LOW 0
5676PI_HIGH 1
5677. .
5678
5679There is one exception. If a watchdog expires on a GPIO the level will be
5680reported as PI_TIMEOUT. See [*gpioSetWatchdog*].
5681
5682. .
5683PI_TIMEOUT 2
5684. .
5685
5686
5687lVal::0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)
5688
5689A 32-bit word value.
5690
5691memAllocMode:: 0-2
5692
5693The DMA memory allocation mode.
5694
5695. .
5696PI_MEM_ALLOC_AUTO 0
5697PI_MEM_ALLOC_PAGEMAP 1
5698PI_MEM_ALLOC_MAILBOX 2
5699. .
5700
5701*micros::
5702
5703A value representing microseconds.
5704
5705micros::
5706
5707A value representing microseconds.
5708
5709millis::
5710
5711A value representing milliseconds.
5712
5713MISO::
5714The GPIO used for the MISO signal when bit banging SPI.
5715
5716mode::
5717
57181. The operational mode of a GPIO, normally INPUT or OUTPUT.
5719
5720. .
5721PI_INPUT 0
5722PI_OUTPUT 1
5723PI_ALT0 4
5724PI_ALT1 5
5725PI_ALT2 6
5726PI_ALT3 7
5727PI_ALT4 3
5728PI_ALT5 2
5729. .
5730
57312. A file open mode.
5732
5733. .
5734PI_FILE_READ 1
5735PI_FILE_WRITE 2
5736PI_FILE_RW 3
5737. .
5738
5739The following values can be or'd into the mode.
5740
5741. .
5742PI_FILE_APPEND 4
5743PI_FILE_CREATE 8
5744PI_FILE_TRUNC 16
5745. .
5746
5747MOSI::
5748The GPIO used for the MOSI signal when bit banging SPI.
5749
5750numBits::
5751
5752The number of bits stored in a buffer.
5753
5754numBytes::
5755The number of bytes used to store characters in a string. Depending
5756on the number of bits per character there may be 1, 2, or 4 bytes
5757per character.
5758
5759numPar:: 0-10
5760The number of parameters passed to a script.
5761
5762numPulses::
5763The number of pulses to be added to a waveform.
5764
5765numSegs::
5766The number of segments in a combined I2C transaction.
5767
5768numSockAddr::
5769The number of network addresses allowed to use the socket interface.
5770
57710 means all addresses allowed.
5772
5773offset::
5774The associated data starts this number of microseconds from the start of
5775the waveform.
5776
5777*outBuf::
5778A buffer used to return data from a function.
5779
5780outLen::
5781The size in bytes of an output buffer.
5782
5783pad:: 0-2
5784A set of GPIO which share common drivers.
5785
5786Pad @ GPIO
57870 @ 0-27
57881 @ 28-45
57892 @ 46-53
5790
5791padStrength:: 1-16
5792The mA which may be drawn from each GPIO whilst still guaranteeing the
5793high and low levels.
5794
5795*param::
5796An array of script parameters.
5797
5798pctBOOL:: 0-100
5799percent On-Off-Level (OOL) buffer to consume for wave output.
5800
5801pctCB:: 0-100
5802the percent of all DMA control blocks to consume.
5803
5804pctTOOL:: 0-100
5805the percent of OOL buffer to consume for wave input (flags).
5806
5807pi_i2c_msg_t::
5808. .
5809typedef struct
5810{
5811 uint16_t addr; // slave address
5812 uint16_t flags;
5813 uint16_t len; // msg length
5814 uint8_t *buf; // pointer to msg data
5815} pi_i2c_msg_t;
5816. .
5817
5818port:: 1024-32000
5819The port used to bind to the pigpio socket. Defaults to 8888.
5820
5821pos::
5822The position of an item.
5823
5824primaryChannel:: 0-15
5825The DMA channel used to time the sampling of GPIO and to time servo and
5826PWM pulses.
5827
5828*pth::
5829
5830A thread identifier, returned by [*gpioStartThread*].
5831
5832pthread_t::
5833
5834A thread identifier.
5835
5836pud::0-2
5837
5838The setting of the pull up/down resistor for a GPIO, which may be off,
5839pull-up, or pull-down.
5840
5841. .
5842PI_PUD_OFF 0
5843PI_PUD_DOWN 1
5844PI_PUD_UP 2
5845. .
5846
5847pulseLen::
5848
58491-100, the length of a trigger pulse in microseconds.
5850
5851*pulses::
5852
5853An array of pulses to be added to a waveform.
5854
5855pulsewidth::0, 500-2500
5856. .
5857PI_SERVO_OFF 0
5858PI_MIN_SERVO_PULSEWIDTH 500
5859PI_MAX_SERVO_PULSEWIDTH 2500
5860. .
5861
5862PWMduty::0-1000000 (1M)
5863The hardware PWM dutycycle.
5864
5865. .
5866PI_HW_PWM_RANGE 1000000
5867. .
5868
5869PWMfreq::1-125M (1-187.5M for the BCM2711)
5870The hardware PWM frequency.
5871
5872. .
5873PI_HW_PWM_MIN_FREQ 1
5874PI_HW_PWM_MAX_FREQ 125000000
5875PI_HW_PWM_MAX_FREQ_2711 187500000
5876. .
5877
5878range::25-40000
5879. .
5880PI_MIN_DUTYCYCLE_RANGE 25
5881PI_MAX_DUTYCYCLE_RANGE 40000
5882. .
5883
5884rawCbs_t::
5885. .
5886typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
5887{
5888 unsigned long info;
5889 unsigned long src;
5890 unsigned long dst;
5891 unsigned long length;
5892 unsigned long stride;
5893 unsigned long next;
5894 unsigned long pad[2];
5895} rawCbs_t;
5896. .
5897
5898rawSPI_t::
5899. .
5900typedef struct
5901{
5902 int clk; // GPIO for clock
5903 int mosi; // GPIO for MOSI
5904 int miso; // GPIO for MISO
5905 int ss_pol; // slave select off state
5906 int ss_us; // delay after slave select
5907 int clk_pol; // clock off state
5908 int clk_pha; // clock phase
5909 int clk_us; // clock micros
5910} rawSPI_t;
5911. .
5912
5913rawWave_t::
5914. .
5915typedef struct
5916{
5917 uint32_t gpioOn;
5918 uint32_t gpioOff;
5919 uint32_t usDelay;
5920 uint32_t flags;
5921} rawWave_t;
5922. .
5923
5924rawWaveInfo_t::
5925. .
5926typedef struct
5927{
5928 uint16_t botCB; // first CB used by wave
5929 uint16_t topCB; // last CB used by wave
5930 uint16_t botOOL; // last OOL used by wave
5931 uint16_t topOOL; // first OOL used by wave
5932 uint16_t deleted;
5933 uint16_t numCB;
5934 uint16_t numBOOL;
5935 uint16_t numTOOL;
5936} rawWaveInfo_t;
5937. .
5938
5939*retBuf::
5940
5941A buffer to hold a number of bytes returned to a used customised function,
5942
5943retMax::
5944
5945The maximum number of bytes a user customised function should return.
5946
5947*rxBuf::
5948
5949A pointer to a buffer to receive data.
5950
5951SCL::
5952The user GPIO to use for the clock when bit banging I2C.
5953
5954SCLK::
5955The GPIO used for the SCLK signal when bit banging SPI.
5956
5957*script::
5958A pointer to the text of a script.
5959
5960script_id::
5961An id of a stored script as returned by [*gpioStoreScript*].
5962
5963*scriptName::
5964The name of a [*shell*] script to be executed. The script must be present in
5965/opt/pigpio/cgi and must have execute permission.
5966
5967*scriptString::
5968The string to be passed to a [*shell*] script to be executed.
5969
5970SDA::
5971The user GPIO to use for data when bit banging I2C.
5972
5973secondaryChannel:: 0-6
5974
5975The DMA channel used to time output waveforms.
5976
5977*seconds::
5978
5979A pointer to a uint32_t to store the second component of
5980a returned time.
5981
5982seconds::
5983The number of seconds.
5984
5985seekFrom::
5986
5987. .
5988PI_FROM_START 0
5989PI_FROM_CURRENT 1
5990PI_FROM_END 2
5991. .
5992
5993seekOffset::
5994The number of bytes to move forward (positive) or backwards (negative)
5995from the seek position (start, current, or end of file).
5996
5997*segs::
5998An array of segments which make up a combined I2C transaction.
5999
6000serFlags::
6001Flags which modify a serial open command. None are currently defined.
6002
6003*sertty::
6004The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
6005
6006setting::
6007A value used to set a flag, 0 for false, non-zero for true.
6008
6009signum::0-63
6010. .
6011PI_MIN_SIGNUM 0
6012PI_MAX_SIGNUM 63
6013. .
6014
6015size_t::
6016
6017A standard type used to indicate the size of an object in bytes.
6018
6019*sockAddr::
6020An array of network addresses allowed to use the socket interface encoded
6021as 32 bit numbers.
6022
6023E.g. address 192.168.1.66 would be encoded as 0x4201a8c0.
6024
6025*spi::
6026A pointer to a [*rawSPI_t*] structure.
6027
6028spiBitFirst::
6029GPIO reads are made from spiBitFirst to spiBitLast.
6030
6031spiBitLast::
6032
6033GPIO reads are made from spiBitFirst to spiBitLast.
6034
6035spiBits::
6036The number of bits to transfer in a raw SPI transaction.
6037
6038spiChan::
6039A SPI channel, 0-2.
6040
6041spiFlags::
6042See [*spiOpen*] and [*bbSPIOpen*].
6043
6044spiSS::
6045The SPI slave select GPIO in a raw SPI transaction.
6046
6047spiTxBits::
6048The number of bits to transfer dring a raw SPI transaction
6049
6050steady :: 0-300000
6051
6052The number of microseconds level changes must be stable for
6053before reporting the level changed ([*gpioGlitchFilter*]) or triggering
6054the active part of a noise filter ([*gpioNoiseFilter*]).
6055
6056stop_bits::2-8
6057The number of (half) stop bits to be used when adding serial data
6058to a waveform.
6059
6060. .
6061PI_MIN_WAVE_HALFSTOPBITS 2
6062PI_MAX_WAVE_HALFSTOPBITS 8
6063. .
6064
6065*str::
6066An array of characters.
6067
6068timeout::
6069A GPIO level change timeout in milliseconds.
6070
6071[*gpioSetWatchdog*]
6072. .
6073PI_MIN_WDOG_TIMEOUT 0
6074PI_MAX_WDOG_TIMEOUT 60000
6075. .
6076
6077[*gpioSetISRFunc*] and [*gpioSetISRFuncEx*]
6078. .
6079<=0 cancel timeout
6080>0 timeout after specified milliseconds
6081. .
6082
6083timer::
6084. .
6085PI_MIN_TIMER 0
6086PI_MAX_TIMER 9
6087. .
6088
6089timetype::
6090. .
6091PI_TIME_RELATIVE 0
6092PI_TIME_ABSOLUTE 1
6093. .
6094
6095*txBuf::
6096
6097An array of bytes to transmit.
6098
6099uint32_t::0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)
6100
6101A 32-bit unsigned value.
6102
6103uint64_t::0-(2^64)-1
6104
6105A 64-bit unsigned value.
6106
6107unsigned::
6108
6109A whole number >= 0.
6110
6111updateMask::
6112
6113A 64 bit mask indicating which GPIO may be written to by the user.
6114
6115If GPIO#n may be written then bit (1<<n) is set.
6116
6117user_gpio::
6118
61190-31, a Broadcom numbered GPIO.
6120
6121See [*gpio*].
6122
6123*userdata::
6124A pointer to arbitrary user data. This may be used to identify the instance.
6125
6126You must ensure that the pointer is in scope at the time it is processed. If
6127it is a pointer to a global this is automatic. Do not pass the address of a
6128local variable. If you want to pass a transient object then use the
6129following technique.
6130
6131In the calling function:
6132
6133. .
6134user_type *userdata;
6135user_type my_userdata;
6136
6137userdata = malloc(sizeof(user_type));
6138*userdata = my_userdata;
6139. .
6140
6141In the receiving function:
6142
6143. .
6144user_type my_userdata = *(user_type*)userdata;
6145
6146free(userdata);
6147. .
6148
6149void::
6150
6151Denoting no parameter is required
6152
6153wave_id::
6154
6155A number identifying a waveform created by [*gpioWaveCreate*].
6156
6157wave_mode::
6158
6159The mode determines if the waveform is sent once or cycles
6160repeatedly. The SYNC variants wait for the current waveform
6161to reach the end of a cycle or finish before starting the new
6162waveform.
6163
6164. .
6165PI_WAVE_MODE_ONE_SHOT 0
6166PI_WAVE_MODE_REPEAT 1
6167PI_WAVE_MODE_ONE_SHOT_SYNC 2
6168PI_WAVE_MODE_REPEAT_SYNC 3
6169. .
6170
6171wVal::0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)
6172
6173A 16-bit word value.
6174
6175PARAMS*/
6176
6177/*DEF_S Socket Command Codes*/
6178
6179#define PI_CMD_MODES 0
6180#define PI_CMD_MODEG 1
6181#define PI_CMD_PUD 2
6182#define PI_CMD_READ 3
6183#define PI_CMD_WRITE 4
6184#define PI_CMD_PWM 5
6185#define PI_CMD_PRS 6
6186#define PI_CMD_PFS 7
6187#define PI_CMD_SERVO 8
6188#define PI_CMD_WDOG 9
6189#define PI_CMD_BR1 10
6190#define PI_CMD_BR2 11
6191#define PI_CMD_BC1 12
6192#define PI_CMD_BC2 13
6193#define PI_CMD_BS1 14
6194#define PI_CMD_BS2 15
6195#define PI_CMD_TICK 16
6196#define PI_CMD_HWVER 17
6197#define PI_CMD_NO 18
6198#define PI_CMD_NB 19
6199#define PI_CMD_NP 20
6200#define PI_CMD_NC 21
6201#define PI_CMD_PRG 22
6202#define PI_CMD_PFG 23
6203#define PI_CMD_PRRG 24
6204#define PI_CMD_HELP 25
6205#define PI_CMD_PIGPV 26
6206#define PI_CMD_WVCLR 27
6207#define PI_CMD_WVAG 28
6208#define PI_CMD_WVAS 29
6209#define PI_CMD_WVGO 30
6210#define PI_CMD_WVGOR 31
6211#define PI_CMD_WVBSY 32
6212#define PI_CMD_WVHLT 33
6213#define PI_CMD_WVSM 34
6214#define PI_CMD_WVSP 35
6215#define PI_CMD_WVSC 36
6216#define PI_CMD_TRIG 37
6217#define PI_CMD_PROC 38
6218#define PI_CMD_PROCD 39
6219#define PI_CMD_PROCR 40
6220#define PI_CMD_PROCS 41
6221#define PI_CMD_SLRO 42
6222#define PI_CMD_SLR 43
6223#define PI_CMD_SLRC 44
6224#define PI_CMD_PROCP 45
6225#define PI_CMD_MICS 46
6226#define PI_CMD_MILS 47
6227#define PI_CMD_PARSE 48
6228#define PI_CMD_WVCRE 49
6229#define PI_CMD_WVDEL 50
6230#define PI_CMD_WVTX 51
6231#define PI_CMD_WVTXR 52
6232#define PI_CMD_WVNEW 53
6233
6234#define PI_CMD_I2CO 54
6235#define PI_CMD_I2CC 55
6236#define PI_CMD_I2CRD 56
6237#define PI_CMD_I2CWD 57
6238#define PI_CMD_I2CWQ 58
6239#define PI_CMD_I2CRS 59
6240#define PI_CMD_I2CWS 60
6241#define PI_CMD_I2CRB 61
6242#define PI_CMD_I2CWB 62
6243#define PI_CMD_I2CRW 63
6244#define PI_CMD_I2CWW 64
6245#define PI_CMD_I2CRK 65
6246#define PI_CMD_I2CWK 66
6247#define PI_CMD_I2CRI 67
6248#define PI_CMD_I2CWI 68
6249#define PI_CMD_I2CPC 69
6250#define PI_CMD_I2CPK 70
6251
6252#define PI_CMD_SPIO 71
6253#define PI_CMD_SPIC 72
6254#define PI_CMD_SPIR 73
6255#define PI_CMD_SPIW 74
6256#define PI_CMD_SPIX 75
6257
6258#define PI_CMD_SERO 76
6259#define PI_CMD_SERC 77
6260#define PI_CMD_SERRB 78
6261#define PI_CMD_SERWB 79
6262#define PI_CMD_SERR 80
6263#define PI_CMD_SERW 81
6264#define PI_CMD_SERDA 82
6265
6266#define PI_CMD_GDC 83
6267#define PI_CMD_GPW 84
6268
6269#define PI_CMD_HC 85
6270#define PI_CMD_HP 86
6271
6272#define PI_CMD_CF1 87
6273#define PI_CMD_CF2 88
6274
6275#define PI_CMD_BI2CC 89
6276#define PI_CMD_BI2CO 90
6277#define PI_CMD_BI2CZ 91
6278
6279#define PI_CMD_I2CZ 92
6280
6281#define PI_CMD_WVCHA 93
6282
6283#define PI_CMD_SLRI 94
6284
6285#define PI_CMD_CGI 95
6286#define PI_CMD_CSI 96
6287
6288#define PI_CMD_FG 97
6289#define PI_CMD_FN 98
6290
6291#define PI_CMD_NOIB 99
6292
6293#define PI_CMD_WVTXM 100
6294#define PI_CMD_WVTAT 101
6295
6296#define PI_CMD_PADS 102
6297#define PI_CMD_PADG 103
6298
6299#define PI_CMD_FO 104
6300#define PI_CMD_FC 105
6301#define PI_CMD_FR 106
6302#define PI_CMD_FW 107
6303#define PI_CMD_FS 108
6304#define PI_CMD_FL 109
6305
6306#define PI_CMD_SHELL 110
6307
6308#define PI_CMD_BSPIC 111
6309#define PI_CMD_BSPIO 112
6310#define PI_CMD_BSPIX 113
6311
6312#define PI_CMD_BSCX 114
6313
6314#define PI_CMD_EVM 115
6315#define PI_CMD_EVT 116
6316
6317#define PI_CMD_PROCU 117
6318#define PI_CMD_WVCAP 118
6319
6320/*DEF_E*/
6321
6322/*
6323PI CMD_NOIB only works on the socket interface.
6324It returns a spare notification handle. Notifications for
6325that handle will be sent to the socket (rather than a
6326/dev/pigpiox pipe).
6327
6328The socket should be dedicated to receiving notifications
6329after this command is issued.
6330*/
6331
6332/* pseudo commands */
6333
6334#define PI_CMD_SCRIPT 800
6335
6336#define PI_CMD_ADD 800
6337#define PI_CMD_AND 801
6338#define PI_CMD_CALL 802
6339#define PI_CMD_CMDR 803
6340#define PI_CMD_CMDW 804
6341#define PI_CMD_CMP 805
6342#define PI_CMD_DCR 806
6343#define PI_CMD_DCRA 807
6344#define PI_CMD_DIV 808
6345#define PI_CMD_HALT 809
6346#define PI_CMD_INR 810
6347#define PI_CMD_INRA 811
6348#define PI_CMD_JM 812
6349#define PI_CMD_JMP 813
6350#define PI_CMD_JNZ 814
6351#define PI_CMD_JP 815
6352#define PI_CMD_JZ 816
6353#define PI_CMD_TAG 817
6354#define PI_CMD_LD 818
6355#define PI_CMD_LDA 819
6356#define PI_CMD_LDAB 820
6357#define PI_CMD_MLT 821
6358#define PI_CMD_MOD 822
6359#define PI_CMD_NOP 823
6360#define PI_CMD_OR 824
6361#define PI_CMD_POP 825
6362#define PI_CMD_POPA 826
6363#define PI_CMD_PUSH 827
6364#define PI_CMD_PUSHA 828
6365#define PI_CMD_RET 829
6366#define PI_CMD_RL 830
6367#define PI_CMD_RLA 831
6368#define PI_CMD_RR 832
6369#define PI_CMD_RRA 833
6370#define PI_CMD_STA 834
6371#define PI_CMD_STAB 835
6372#define PI_CMD_SUB 836
6373#define PI_CMD_SYS 837
6374#define PI_CMD_WAIT 838
6375#define PI_CMD_X 839
6376#define PI_CMD_XA 840
6377#define PI_CMD_XOR 841
6378#define PI_CMD_EVTWT 842
6379
6380/*DEF_S Error Codes*/
6381
6382#define PI_INIT_FAILED -1 // gpioInitialise failed
6383#define PI_BAD_USER_GPIO -2 // GPIO not 0-31
6384#define PI_BAD_GPIO -3 // GPIO not 0-53
6385#define PI_BAD_MODE -4 // mode not 0-7
6386#define PI_BAD_LEVEL -5 // level not 0-1
6387#define PI_BAD_PUD -6 // pud not 0-2
6388#define PI_BAD_PULSEWIDTH -7 // pulsewidth not 0 or 500-2500
6389#define PI_BAD_DUTYCYCLE -8 // dutycycle outside set range
6390#define PI_BAD_TIMER -9 // timer not 0-9
6391#define PI_BAD_MS -10 // ms not 10-60000
6392#define PI_BAD_TIMETYPE -11 // timetype not 0-1
6393#define PI_BAD_SECONDS -12 // seconds < 0
6394#define PI_BAD_MICROS -13 // micros not 0-999999
6395#define PI_TIMER_FAILED -14 // gpioSetTimerFunc failed
6396#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
6397#define PI_NO_ALERT_FUNC -16 // DEPRECATED
6398#define PI_BAD_CLK_PERIPH -17 // clock peripheral not 0-1
6399#define PI_BAD_CLK_SOURCE -18 // DEPRECATED
6400#define PI_BAD_CLK_MICROS -19 // clock micros not 1, 2, 4, 5, 8, or 10
6401#define PI_BAD_BUF_MILLIS -20 // buf millis not 100-10000
6402#define PI_BAD_DUTYRANGE -21 // dutycycle range not 25-40000
6403#define PI_BAD_DUTY_RANGE -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
6404#define PI_BAD_SIGNUM -22 // signum not 0-63
6405#define PI_BAD_PATHNAME -23 // can't open pathname
6406#define PI_NO_HANDLE -24 // no handle available
6407#define PI_BAD_HANDLE -25 // unknown handle
6408#define PI_BAD_IF_FLAGS -26 // ifFlags > 4
6409#define PI_BAD_CHANNEL -27 // DMA channel not 0-15
6410#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
6411#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000
6412#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
6413#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-15
6414#define PI_NOT_INITIALISED -31 // function called before gpioInitialise
6415#define PI_INITIALISED -32 // function called after gpioInitialise
6416#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-3
6417#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
6418#define PI_BAD_WAVE_BAUD -35 // baud rate not 50-250K(RX)/50-1M(TX)
6419#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses
6420#define PI_TOO_MANY_CHARS -37 // waveform has too many chars
6421#define PI_NOT_SERIAL_GPIO -38 // no bit bang serial read on GPIO
6422#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
6423#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter
6424#define PI_NOT_PERMITTED -41 // GPIO operation not permitted
6425#define PI_SOME_PERMITTED -42 // one or more GPIO not permitted
6426#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand
6427#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand
6428#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand
6429#define PI_BAD_PULSELEN -46 // trigger pulse length not 1-100
6430#define PI_BAD_SCRIPT -47 // invalid script
6431#define PI_BAD_SCRIPT_ID -48 // unknown script id
6432#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes
6433#define PI_GPIO_IN_USE -50 // GPIO already in use
6434#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
6435#define PI_BAD_PARAM_NUM -52 // script parameter id not 0-9
6436#define PI_DUP_TAG -53 // script has duplicate tag
6437#define PI_TOO_MANY_TAGS -54 // script has too many tags
6438#define PI_BAD_SCRIPT_CMD -55 // illegal script command
6439#define PI_BAD_VAR_NUM -56 // script variable id not 0-149
6440#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts
6441#define PI_NO_MEMORY -58 // can't allocate temporary memory
6442#define PI_SOCK_READ_FAILED -59 // socket read failed
6443#define PI_SOCK_WRIT_FAILED -60 // socket write failed
6444#define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10)
6445#define PI_NOT_HALTED -62 // DEPRECATED
6446#define PI_SCRIPT_NOT_READY -62 // script initialising
6447#define PI_BAD_TAG -63 // script has unresolved tag
6448#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large)
6449#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large)
6450#define PI_BAD_WAVE_ID -66 // non existent wave id
6451#define PI_TOO_MANY_CBS -67 // No more CBs for waveform
6452#define PI_TOO_MANY_OOL -68 // No more OOL for waveform
6453#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform
6454#define PI_NO_WAVEFORM_ID -70 // no more waveforms
6455#define PI_I2C_OPEN_FAILED -71 // can't open I2C device
6456#define PI_SER_OPEN_FAILED -72 // can't open serial device
6457#define PI_SPI_OPEN_FAILED -73 // can't open SPI device
6458#define PI_BAD_I2C_BUS -74 // bad I2C bus
6459#define PI_BAD_I2C_ADDR -75 // bad I2C address
6460#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel
6461#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags
6462#define PI_BAD_SPI_SPEED -78 // bad SPI speed
6463#define PI_BAD_SER_DEVICE -79 // bad serial device name
6464#define PI_BAD_SER_SPEED -80 // bad serial baud rate
6465#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter
6466#define PI_I2C_WRITE_FAILED -82 // i2c write failed
6467#define PI_I2C_READ_FAILED -83 // i2c read failed
6468#define PI_BAD_SPI_COUNT -84 // bad SPI count
6469#define PI_SER_WRITE_FAILED -85 // ser write failed
6470#define PI_SER_READ_FAILED -86 // ser read failed
6471#define PI_SER_READ_NO_DATA -87 // ser read no data available
6472#define PI_UNKNOWN_COMMAND -88 // unknown command
6473#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed
6474#define PI_BAD_POINTER -90 // bad (NULL) pointer
6475#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B
6476#define PI_NOT_PWM_GPIO -92 // GPIO is not in use for PWM
6477#define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses
6478#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock
6479#define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM
6480#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency
6481#define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M
6482#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency
6483#define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1
6484#define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock
6485#define PI_BAD_DATABITS -101 // serial data bits not 1-32
6486#define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8
6487#define PI_MSG_TOOBIG -103 // socket/pipe message too big
6488#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
6489#define PI_TOO_MANY_SEGS -105 // too many I2C transaction segments
6490#define PI_BAD_I2C_SEG -106 // an I2C transaction segment failed
6491#define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver
6492#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO
6493#define PI_BAD_I2C_WLEN -109 // bad I2C write length
6494#define PI_BAD_I2C_RLEN -110 // bad I2C read length
6495#define PI_BAD_I2C_CMD -111 // bad I2C command
6496#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k
6497#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
6498#define PI_BAD_CHAIN_LOOP -114 // empty chain loop
6499#define PI_CHAIN_COUNTER -115 // too many chain counters
6500#define PI_BAD_CHAIN_CMD -116 // bad chain command
6501#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
6502#define PI_CHAIN_NESTING -118 // chain counters nested too deeply
6503#define PI_CHAIN_TOO_BIG -119 // chain is too long
6504#define PI_DEPRECATED -120 // deprecated function removed
6505#define PI_BAD_SER_INVERT -121 // bit bang serial invert not 0 or 1
6506#define PI_BAD_EDGE -122 // bad ISR edge value, not 0-2
6507#define PI_BAD_ISR_INIT -123 // bad ISR initialisation
6508#define PI_BAD_FOREVER -124 // loop forever must be last command
6509#define PI_BAD_FILTER -125 // bad filter parameter
6510#define PI_BAD_PAD -126 // bad pad number
6511#define PI_BAD_STRENGTH -127 // bad pad drive strength
6512#define PI_FIL_OPEN_FAILED -128 // file open failed
6513#define PI_BAD_FILE_MODE -129 // bad file mode
6514#define PI_BAD_FILE_FLAG -130 // bad file flag
6515#define PI_BAD_FILE_READ -131 // bad file read
6516#define PI_BAD_FILE_WRITE -132 // bad file write
6517#define PI_FILE_NOT_ROPEN -133 // file not open for read
6518#define PI_FILE_NOT_WOPEN -134 // file not open for write
6519#define PI_BAD_FILE_SEEK -135 // bad file seek
6520#define PI_NO_FILE_MATCH -136 // no files match pattern
6521#define PI_NO_FILE_ACCESS -137 // no permission to access file
6522#define PI_FILE_IS_A_DIR -138 // file is a directory
6523#define PI_BAD_SHELL_STATUS -139 // bad shell return status
6524#define PI_BAD_SCRIPT_NAME -140 // bad script name
6525#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k
6526#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO
6527#define PI_BAD_EVENT_ID -143 // bad event id
6528#define PI_CMD_INTERRUPTED -144 // Used by Python
6529#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711
6530#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711
6531
6532#define PI_PIGIF_ERR_0 -2000
6533#define PI_PIGIF_ERR_99 -2099
6534
6535#define PI_CUSTOM_ERR_0 -3000
6536#define PI_CUSTOM_ERR_999 -3999
6537
6538/*DEF_E*/
6539
6540/*DEF_S Defaults*/
6541
6542#define PI_DEFAULT_BUFFER_MILLIS 120
6543#define PI_DEFAULT_CLK_MICROS 5
6544#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM
6545#define PI_DEFAULT_IF_FLAGS 0
6546#define PI_DEFAULT_FOREGROUND 0
6547#define PI_DEFAULT_DMA_CHANNEL 14
6548#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14
6549#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6
6550#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7
6551#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6
6552#define PI_DEFAULT_DMA_NOT_SET 15
6553#define PI_DEFAULT_SOCKET_PORT 8888
6554#define PI_DEFAULT_SOCKET_PORT_STR "8888"
6555#define PI_DEFAULT_SOCKET_ADDR_STR "localhost"
6556#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL
6557#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93
6558#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C
6559#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
6560#define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL
6561#define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL
6562#define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL
6563#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL
6564#define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL
6565#define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO
6566
6567#define PI_DEFAULT_CFG_INTERNALS 0
6568
6569/*DEF_E*/
6570
6571#endif
6572
void * gpioThreadFunc_t(void *)
Definition pigpio.h:584
int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)
int gpioSetISRFunc(unsigned gpio, unsigned edge, int timeout, gpioISRFunc_t f)
int gpioSleep(unsigned timetype, int seconds, int micros)
int i2cWriteQuick(unsigned handle, unsigned bit)
int serWrite(unsigned handle, char *buf, unsigned count)
void(* gpioISRFuncEx_t)(int gpio, int level, uint32_t tick, void *userdata)
Definition pigpio.h:563
int i2cSegments(unsigned handle, pi_i2c_msg_t *segs, unsigned numSegs)
int gpioWaveGetMaxCbs(void)
int gpioSetISRFuncEx(unsigned gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)
rawWaveInfo_t rawWaveInfo(int wave_id)
uint32_t rawWaveGetOOL(int pos)
int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)
int gpioNotifyBegin(unsigned handle, uint32_t bits)
int gpioGetPWMrealRange(unsigned user_gpio)
int gpioNotifyClose(unsigned handle)
unsigned gpioVersion(void)
int gpioGlitchFilter(unsigned user_gpio, unsigned steady)
int gpioWrite(unsigned gpio, unsigned level)
int gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)
int i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)
uint32_t rawWaveGetOut(int pos)
void(* gpioAlertFuncEx_t)(int gpio, int level, uint32_t tick, void *userdata)
Definition pigpio.h:547
int gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)
void(* eventFunc_t)(int event, uint32_t tick)
Definition pigpio.h:552
int gpioSerialReadOpen(unsigned user_gpio, unsigned baud, unsigned data_bits)
int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)
void rawWaveSetIn(int pos, uint32_t lVal)
void time_sleep(double seconds)
int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)
int gpioSetWatchdog(unsigned user_gpio, unsigned timeout)
int gpioNotifyOpenWithSize(int bufSize)
int rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)
int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)
uint32_t rawWaveGetIn(int pos)
int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)
void rawWaveSetOut(int pos, uint32_t lVal)
int i2cWriteDevice(unsigned handle, char *buf, unsigned count)
int serRead(unsigned handle, char *buf, unsigned count)
void(* gpioTimerFuncEx_t)(void *userdata)
Definition pigpio.h:570
void gpioTerminate(void)
int gpioSetPad(unsigned pad, unsigned padStrength)
int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)
int gpioWaveGetHighCbs(void)
int serClose(unsigned handle)
int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)
int gpioWaveGetMaxMicros(void)
int gpioDeleteScript(unsigned script_id)
int gpioCustom1(unsigned arg1, unsigned arg2, char *argx, unsigned argc)
int gpioWaveChain(char *buf, unsigned bufSize)
int serWriteByte(unsigned handle, unsigned bVal)
int gpioWaveDelete(unsigned wave_id)
unsigned rawWaveCB(void)
int bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)
void(* gpioGetSamplesFunc_t)(const gpioSample_t *samples, int numSamples)
Definition pigpio.h:577
uint32_t gpioDelay(uint32_t micros)
int gpioWaveTxBusy(void)
void(* eventFuncEx_t)(int event, uint32_t tick, void *userdata)
Definition pigpio.h:555
int gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)
int gpioSerialReadInvert(unsigned user_gpio, unsigned invert)
int gpioScriptStatus(unsigned script_id, uint32_t *param)
int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)
int gpioCfgSetInternals(uint32_t cfgVal)
int spiRead(unsigned handle, char *buf, unsigned count)
void(* gpioSignalFuncEx_t)(int signum, void *userdata)
Definition pigpio.h:574
void rawWaveSetOOL(int pos, uint32_t lVal)
void gpioStopThread(pthread_t *pth)
int i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)
int i2cReadDevice(unsigned handle, char *buf, unsigned count)
int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)
int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)
void(* gpioSignalFunc_t)(int signum)
Definition pigpio.h:572
int fileList(char *fpat, char *buf, unsigned count)
int gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)
int gpioRead(unsigned gpio)
int gpioWaveTxStop(void)
int gpioGetPad(unsigned pad)
int gpioWaveGetHighMicros(void)
void(* gpioTimerFunc_t)(void)
Definition pigpio.h:568
int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active)
int gpioInitialise(void)
int bbSPIClose(unsigned CS)
int i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)
void rawDumpScript(unsigned script_id)
int i2cReadByteData(unsigned handle, unsigned i2cReg)
int gpioTime(unsigned timetype, int *seconds, int *micros)
int gpioGetPWMfrequency(unsigned user_gpio)
int i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)
uint32_t gpioTick(void)
uint32_t gpioRead_Bits_32_53(void)
rawCbs_t * rawWaveCBAdr(int cbNum)
int gpioWrite_Bits_32_53_Set(uint32_t bits)
int gpioSetPullUpDown(unsigned gpio, unsigned pud)
int getBitInBytes(int bitPos, char *buf, int numBits)
int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)
int gpioWaveGetMicros(void)
int gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)
int gpioUpdateScript(unsigned script_id, unsigned numPar, uint32_t *param)
int gpioCfgInterfaces(unsigned ifFlags)
int i2cReadByte(unsigned handle)
void(* gpioISRFunc_t)(int gpio, int level, uint32_t tick)
Definition pigpio.h:559
int fileRead(unsigned handle, char *buf, unsigned count)
int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)
int serReadByte(unsigned handle)
int spiClose(unsigned handle)
int gpioPWM(unsigned user_gpio, unsigned dutycycle)
int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)
int gpioGetMode(unsigned gpio)
int i2cWriteByte(unsigned handle, unsigned bVal)
int gpioWaveAddSerial(unsigned user_gpio, unsigned baud, unsigned data_bits, unsigned stop_bits, unsigned offset, unsigned numBytes, char *str)
int gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)
int fileWrite(unsigned handle, char *buf, unsigned count)
int gpioGetPWMrange(unsigned user_gpio)
void putBitInBytes(int bitPos, char *buf, int bit)
void rawDumpWave(void)
int i2cClose(unsigned handle)
unsigned gpioHardwareRevision(void)
int gpioSerialReadClose(unsigned user_gpio)
int bbI2CClose(unsigned SDA)
int gpioSetMode(unsigned gpio, unsigned mode)
int spiWrite(unsigned handle, char *buf, unsigned count)
int gpioWaveTxAt(void)
int serOpen(char *sertty, unsigned baud, unsigned serFlags)
int gpioWaveGetMaxPulses(void)
int gpioWaveGetCbs(void)
int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)
int gpioWrite_Bits_0_31_Clear(uint32_t bits)
int gpioCfgBufferSize(unsigned cfgMillis)
int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)
int eventSetFuncEx(unsigned event, eventFuncEx_t f, void *userdata)
int gpioWrite_Bits_0_31_Set(uint32_t bits)
int gpioWaveClear(void)
int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)
int gpioServo(unsigned user_gpio, unsigned pulsewidth)
int gpioGetServoPulsewidth(unsigned user_gpio)
int gpioGetPWMdutycycle(unsigned user_gpio)
int gpioHardwareClock(unsigned gpio, unsigned clkfreq)
int eventSetFunc(unsigned event, eventFunc_t f)
int fileOpen(char *file, unsigned mode)
int i2cZip(unsigned handle, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)
int gpioCfgMemAlloc(unsigned memAllocMode)
int shell(char *scriptName, char *scriptString)
int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)
int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)
int gpioStoreScript(char *script)
int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)
int gpioSetPWMrange(unsigned user_gpio, unsigned range)
int gpioWaveGetHighPulses(void)
void(* gpioAlertFunc_t)(int gpio, int level, uint32_t tick)
Definition pigpio.h:543
int serDataAvailable(unsigned handle)
int gpioWaveGetPulses(void)
int i2cReadWordData(unsigned handle, unsigned i2cReg)
int gpioCfgDMAchannel(unsigned DMAchannel)
uint32_t gpioRead_Bits_0_31(void)
int fileClose(unsigned handle)
int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)
int eventTrigger(unsigned event)
void(* gpioGetSamplesFuncEx_t)(const gpioSample_t *samples, int numSamples, void *userdata)
Definition pigpio.h:580
double time_time(void)
int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)
int gpioWaveCreatePad(int pctCB, int pctBOOL, int pctTOOL)
void i2cSwitchCombined(int setting)
int gpioWaveAddNew(void)
int gpioNotifyPause(unsigned handle)
int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)
int gpioCfgPermissions(uint64_t updateMask)
int gpioCfgSocketPort(unsigned port)
pthread_t * gpioStartThread(gpioThreadFunc_t f, void *userdata)
int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)
int bbI2CZip(unsigned SDA, char *inBuf, unsigned inLen, char *outBuf, unsigned outLen)
int bscXfer(bsc_xfer_t *bsc_xfer)
#define BSC_FIFO_SIZE
Definition pigpio.h:531
int gpioWaveCreate(void)
int eventMonitor(unsigned handle, uint32_t bits)
int gpioWrite_Bits_32_53_Clear(uint32_t bits)
int gpioStopScript(unsigned script_id)
uint32_t gpioCfgGetInternals(void)
int gpioNotifyOpen(void)
Definition pigpio.h:534
int txCnt
Definition pigpio.h:538
uint32_t control
Definition pigpio.h:535
int rxCnt
Definition pigpio.h:536
Definition pigpio.h:434
uint32_t data
Definition pigpio.h:437
void * ptr
Definition pigpio.h:436
size_t size
Definition pigpio.h:435
Definition pigpio.h:428
uint16_t size
Definition pigpio.h:430
uint16_t func
Definition pigpio.h:429
Definition pigpio.h:455
uint32_t usDelay
Definition pigpio.h:458
uint32_t gpioOn
Definition pigpio.h:456
uint32_t gpioOff
Definition pigpio.h:457
Definition pigpio.h:447
uint16_t seqno
Definition pigpio.h:448
uint32_t level
Definition pigpio.h:451
uint16_t flags
Definition pigpio.h:449
uint32_t tick
Definition pigpio.h:450
Definition pigpio.h:441
uint32_t level
Definition pigpio.h:443
uint32_t tick
Definition pigpio.h:442
Definition pigpio.h:522
uint16_t flags
Definition pigpio.h:524
uint8_t * buf
Definition pigpio.h:526
uint16_t addr
Definition pigpio.h:523
uint16_t len
Definition pigpio.h:525
Definition pigpio.h:511
uint32_t stride
Definition pigpio.h:516
uint32_t next
Definition pigpio.h:517
uint32_t src
Definition pigpio.h:513
uint32_t info
Definition pigpio.h:512
uint32_t length
Definition pigpio.h:515
uint32_t dst
Definition pigpio.h:514
Definition pigpio.h:500
int clk_us
Definition pigpio.h:508
int mosi
Definition pigpio.h:502
int ss_pol
Definition pigpio.h:504
int miso
Definition pigpio.h:503
int clk
Definition pigpio.h:501
int ss_us
Definition pigpio.h:505
int clk_pol
Definition pigpio.h:506
int clk_pha
Definition pigpio.h:507
Definition pigpio.h:486
uint16_t botCB
Definition pigpio.h:487
uint16_t topOOL
Definition pigpio.h:491
uint16_t topCB
Definition pigpio.h:488
uint16_t numCB
Definition pigpio.h:494
uint16_t numTOOL
Definition pigpio.h:496
uint16_t numBOOL
Definition pigpio.h:495
uint16_t botOOL
Definition pigpio.h:489
uint16_t deleted
Definition pigpio.h:493
Definition pigpio.h:465
uint32_t usDelay
Definition pigpio.h:468
uint32_t flags
Definition pigpio.h:469
uint32_t gpioOff
Definition pigpio.h:467
uint32_t gpioOn
Definition pigpio.h:466