summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MakeRemote6
-rw-r--r--Makefile6
-rw-r--r--README19
-rw-r--r--command.c30
-rw-r--r--pig2vcd.1249
-rw-r--r--pigpio.36134
-rw-r--r--pigpio.c172
-rw-r--r--pigpio.h2671
-rw-r--r--pigpio.py342
-rw-r--r--pigpiod.1179
-rw-r--r--pigpiod.c3
-rw-r--r--pigpiod_if.33345
-rw-r--r--pigpiod_if.c84
-rw-r--r--pigpiod_if.h2419
-rw-r--r--pigs.13486
-rw-r--r--pigs.c34
-rw-r--r--setup.py6
-rwxr-xr-xtarball18
-rw-r--r--x_pigpio.c17
-rwxr-xr-xx_pigpio.py27
-rw-r--r--x_pigpiod_if.c21
-rwxr-xr-xx_pigs23
-rwxr-xr-xx_pipe17
23 files changed, 17422 insertions, 1886 deletions
diff --git a/MakeRemote b/MakeRemote
index 0e3f83a..96388d6 100644
--- a/MakeRemote
+++ b/MakeRemote
@@ -24,11 +24,17 @@ install: $(LIB)
sudo install -m 0755 -d /usr/local/bin
sudo install -m 0755 pigs /usr/local/bin
sudo python setup.py install
+ sudo install -m 0755 -d /usr/local/man/man1
+ sudo install -m 0644 *.1 /usr/local/man/man1
+ sudo install -m 0755 -d /usr/local/man/man3
+ sudo install -m 0644 *.3 /usr/local/man/man3
uninstall:
sudo rm -f /usr/local/include/pigpio.h
sudo rm -f /usr/local/lib/libpigpiod_if.a
sudo rm -f /usr/local/bin/pigs
+ sudo rm -f /usr/local/man/man1/pig*.1
+ sudo rm -f /usr/local/man/man3/pig*.3
LIB = libpigpiod_if.a
OBJ = pigpiod_if.o command.o
diff --git a/Makefile b/Makefile
index bfb0beb..d2811f6 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,10 @@ install: $(LIB)
sudo install -m 0755 pigpiod /usr/local/bin
sudo install -m 0755 pigs /usr/local/bin
sudo python setup.py install
+ sudo install -m 0755 -d /usr/local/man/man1
+ sudo install -m 0644 *.1 /usr/local/man/man1
+ sudo install -m 0755 -d /usr/local/man/man3
+ sudo install -m 0644 *.3 /usr/local/man/man3
uninstall:
sudo rm -f /usr/local/include/pigpio.h
@@ -61,6 +65,8 @@ uninstall:
sudo rm -f /usr/local/bin/pig2vcd
sudo rm -f /usr/local/bin/pigpiod
sudo rm -f /usr/local/bin/pigs
+ sudo rm -f /usr/local/man/man1/pig*.1
+ sudo rm -f /usr/local/man/man3/pig*.3
$(LIB1): $(OBJ1)
$(AR) rcs $(LIB1) $(OBJ1)
diff --git a/README b/README
index a9993b5..e7dc4fa 100644
--- a/README
+++ b/README
@@ -18,13 +18,14 @@ o the header file (pigpiod_if.h) in /usr/local/include
o the daemon (pigpiod) in /usr/local/bin
o the socket interface (pigs) in /usr/local/bin
o the utility pig2vcd in /usr/local/bin
+o man pages in /usr/local/man/man1 and man3
o the Python module pigpio.py
TEST (optional)
*** WARNING ************************************************
* *
-* All the tests make extensive use of gpio 4 (pin P1-7). *
+* All the tests make extensive use of gpio 4 (pin P1/J8-7).*
* Ensure that either nothing or just a LED is connected to *
* gpio 4 before running any of the tests. *
************************************************************
@@ -123,6 +124,7 @@ o the library (libpigpiod_if.a) in /usr/local/lib
o the header file (pigpio.h) in /usr/local/include
o the header file (pigpiod_if.h) in /usr/local/include
o the socket interface (pigs) in /usr/local/bin
+o man pages in /usr/local/man/man1 and man3
o the Python module pigpio.py
On Windows machines (and possibly Macs)
@@ -134,3 +136,18 @@ python setup.py install
pigs and pigpiod_if.c will need minor mods to reflect the
Window's/Mac's socket interface.
+DOCUMENTATION
+
+The most up to date should be http://abyz.co.uk/rpi/pigpio/
+
+On the Pi try
+
+man pigs
+man pigpiod
+man pig2vcd
+
+man pigpio
+man pigpiod_if
+
+pydoc pigpio
+
diff --git a/command.c b/command.c
index a2bc7c4..5bdf55e 100644
--- a/command.c
+++ b/command.c
@@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
-This version is for pigpio version 16+
+This version is for pigpio version 17+
*/
#include <stdio.h>
@@ -91,20 +91,20 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_NO, "NO", 101, 2}, // gpioNotifyOpen
{PI_CMD_NP, "NP", 112, 0}, // gpioNotifyPause
- {PI_CMD_PARSE, "PARSE", 115, 2}, // cmdParseScript
+ {PI_CMD_PARSE, "PARSE", 115, 0}, // cmdParseScript
{PI_CMD_PFG, "PFG", 112, 2}, // gpioGetPWMfrequency
{PI_CMD_PFS, "PFS", 121, 2}, // gpioSetPWMfrequency
{PI_CMD_PIGPV, "PIGPV", 101, 4}, // gpioVersion
- {PI_CMD_PRG, "PRG", 112, 2}, // gpioGetPWMrangeg
+ {PI_CMD_PRG, "PRG", 112, 2}, // gpioGetPWMrange
{PI_CMD_PROC, "PROC", 115, 2}, // gpioStoreScript
- {PI_CMD_PROCD, "PROCD", 112, 2}, // gpioDeleteScript
+ {PI_CMD_PROCD, "PROCD", 112, 0}, // gpioDeleteScript
{PI_CMD_PROCP, "PROCP", 112, 7}, // gpioScriptStatus
- {PI_CMD_PROCR, "PROCR", 191, 2}, // gpioRunScript
- {PI_CMD_PROCS, "PROCS", 112, 2}, // gpioStopScript
+ {PI_CMD_PROCR, "PROCR", 191, 0}, // gpioRunScript
+ {PI_CMD_PROCS, "PROCS", 112, 0}, // gpioStopScript
{PI_CMD_PRRG, "PRRG", 112, 2}, // gpioGetPWMrealRange
{PI_CMD_PRS, "PRS", 121, 2}, // gpioSetPWMrange
@@ -129,13 +129,13 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_SERVO, "SERVO", 121, 0}, // gpioServo
{PI_CMD_SLR, "SLR", 121, 6}, // gpioSerialRead
- {PI_CMD_SLRC, "SLRC", 112, 2}, // gpioSerialReadClose
- {PI_CMD_SLRO, "SLRO", 121, 2}, // gpioSerialReadOpen
+ {PI_CMD_SLRC, "SLRC", 112, 0}, // gpioSerialReadClose
+ {PI_CMD_SLRO, "SLRO", 121, 0}, // gpioSerialReadOpen
{PI_CMD_SPIC, "SPIC", 112, 0}, // spiClose
{PI_CMD_SPIO, "SPIO", 131, 2}, // spiOpen
{PI_CMD_SPIR, "SPIR", 121, 6}, // spiRead
- {PI_CMD_SPIW, "SPIW", 193, 2}, // spiWrite
+ {PI_CMD_SPIW, "SPIW", 193, 0}, // spiWrite
{PI_CMD_SPIX, "SPIX", 193, 6}, // spiXfer
{PI_CMD_TICK, "T", 101, 4}, // gpioTick
@@ -153,11 +153,11 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_WVBSY, "WVBSY", 101, 2}, // gpioWaveTxBusy
{PI_CMD_WVCLR, "WVCLR", 101, 0}, // gpioWaveClear
{PI_CMD_WVCRE, "WVCRE", 101, 2}, // gpioWaveCreate
- {PI_CMD_WVDEL, "WVDEL", 112, 2}, // gpioWaveDelete
+ {PI_CMD_WVDEL, "WVDEL", 112, 0}, // gpioWaveDelete
{PI_CMD_WVGO, "WVGO" , 101, 2}, // gpioWaveTxStart
{PI_CMD_WVGOR, "WVGOR", 101, 2}, // gpioWaveTxStart
- {PI_CMD_WVHLT, "WVHLT", 101, 2}, // gpioWaveTxStop
- {PI_CMD_WVNEW, "WVNEW", 101, 2}, // gpioWaveAddNew
+ {PI_CMD_WVHLT, "WVHLT", 101, 0}, // gpioWaveTxStop
+ {PI_CMD_WVNEW, "WVNEW", 101, 0}, // gpioWaveAddNew
{PI_CMD_WVSC, "WVSC", 112, 2}, // gpioWaveGet*Cbs
{PI_CMD_WVSM, "WVSM", 112, 2}, // gpioWaveGet*Micros
{PI_CMD_WVSP, "WVSP", 112, 2}, // gpioWaveGet*Pulses
@@ -237,7 +237,7 @@ I2CRW h r smb Read Word Data: read word from register.\n\
\n\
I2CWB h r bv smb Write Byte Data: write byte to register.\n\
I2CWD h bvs i2c Write data.\n\
-I2CWI h smb Write I2C Block Data.\n\
+I2CWI h r bvs smb Write I2C Block Data.\n\
I2CWK h r bvs smb Write Block Data: write data to register.\n\
I2CWQ h bit smb Write Quick: write bit.\n\
I2CWS h bv smb Write Byte: write byte.\n\
@@ -373,7 +373,7 @@ static errInfo_t errInfo[]=
{PI_BAD_LEVEL , "level not 0-1"},
{PI_BAD_PUD , "pud not 0-2"},
{PI_BAD_PULSEWIDTH , "pulsewidth not 0 or 500-2500"},
- {PI_BAD_DUTYCYCLE , "dutycycle outside set range"},
+ {PI_BAD_DUTYCYCLE , "dutycycle not 0-range (default 255)"},
{PI_BAD_TIMER , "timer not 0-9"},
{PI_BAD_MS , "ms not 10-60000"},
{PI_BAD_TIMETYPE , "timetype not 0-1"},
@@ -390,7 +390,7 @@ static errInfo_t errInfo[]=
{PI_BAD_SIGNUM , "signum not 0-63"},
{PI_BAD_PATHNAME , "can't open pathname"},
{PI_NO_HANDLE , "no handle available"},
- {PI_BAD_HANDLE , "unknown notify handle"},
+ {PI_BAD_HANDLE , "unknown handle"},
{PI_BAD_IF_FLAGS , "ifFlags > 3"},
{PI_BAD_CHANNEL , "DMA channel not 0-14"},
{PI_BAD_SOCKET_PORT , "socket port not 1024-30000"},
diff --git a/pig2vcd.1 b/pig2vcd.1
new file mode 100644
index 0000000..52c5a93
--- /dev/null
+++ b/pig2vcd.1
@@ -0,0 +1,249 @@
+
+." Process this file with
+." groff -man -Tascii pig2vcd.1
+."
+.TH pig2vcd 1 2012-2014 Linux "pigpio archive"
+.SH NAME
+pig2vd - A utility to convert pigpio notifications to VCD.
+
+.SH SYNOPSIS
+
+pig2vcd </dev/pigpioXX >file.VCD
+.SH DESCRIPTION
+
+pig2vcd is a utility which reads notifications on stdin and writes the
+output as a Value Change Dump (VCD) file on stdout.
+
+.br
+
+.br
+The VCD file can be viewed using GTKWave.
+
+.br
+
+.br
+.SS Notifications
+.br
+
+.br
+Notifications consist of 12 bytes with the following binary format.
+
+.br
+
+.br
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint16_t seqno;
+.br
+ uint16_t flags;
+.br
+ uint32_t tick;
+.br
+ uint32_t level;
+.br
+} gpioReport_t;
+.br
+
+.EE
+
+.br
+
+.br
+seqno starts at 0 each time the handle is opened and then increments
+by one for each report.
+
+.br
+
+.br
+flags, if bit 5 is set then bits 0-4 of the flags indicate a gpio which
+has had a watchdog timeout.
+
+.br
+
+.br
+tick is the number of microseconds since system boot.
+
+.br
+
+.br
+level indicates the level of each gpio.
+
+.br
+
+.br
+pig2vcd takes these notifications and outputs a text format VCD.
+
+.br
+
+.br
+.SS VCD format
+.br
+
+.br
+The VCD starts with a header.
+
+.br
+
+.br
+
+.EX
+$date 2013-05-31 18:49:36 $end
+.br
+$version pig2vcd V1 $end
+.br
+$timescale 1 us $end
+.br
+$scope module top $end
+.br
+$var wire 1 A 0 $end
+.br
+$var wire 1 B 1 $end
+.br
+$var wire 1 C 2 $end
+.br
+$var wire 1 D 3 $end
+.br
+$var wire 1 E 4 $end
+.br
+$var wire 1 F 5 $end
+.br
+$var wire 1 G 6 $end
+.br
+$var wire 1 H 7 $end
+.br
+$var wire 1 I 8 $end
+.br
+$var wire 1 J 9 $end
+.br
+$var wire 1 K 10 $end
+.br
+$var wire 1 L 11 $end
+.br
+$var wire 1 M 12 $end
+.br
+$var wire 1 N 13 $end
+.br
+$var wire 1 O 14 $end
+.br
+$var wire 1 P 15 $end
+.br
+$var wire 1 Q 16 $end
+.br
+$var wire 1 R 17 $end
+.br
+$var wire 1 S 18 $end
+.br
+$var wire 1 T 19 $end
+.br
+$var wire 1 U 20 $end
+.br
+$var wire 1 V 21 $end
+.br
+$var wire 1 W 22 $end
+.br
+$var wire 1 X 23 $end
+.br
+$var wire 1 Y 24 $end
+.br
+$var wire 1 Z 25 $end
+.br
+$var wire 1 a 26 $end
+.br
+$var wire 1 b 27 $end
+.br
+$var wire 1 c 28 $end
+.br
+$var wire 1 d 29 $end
+.br
+$var wire 1 e 30 $end
+.br
+$var wire 1 f 31 $end
+.br
+$upscope $end
+.br
+$enddefinitions $end
+.br
+
+.EE
+
+.br
+
+.br
+The header defines gpio identifiers and their name. Each gpio identifier
+must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0
+through 25, and 'a' through 'f' for gpios 26 through 31.
+The corresponding names are 0 through 31.
+.br
+
+.br
+
+.br
+The VCD file may be edited to give a frendlier name, e.g. 8 could be
+changed to ENCODER_A if an encoder switch A is connected to gpio 8.
+
+.br
+
+.br
+Following the header pig2vcd takes notifications and outputs a timestamp
+followed by a list of one or more gpios which have changed state.
+The timestamp consists of a '#' followed by the microsecond tick.
+The state lines contain the new state followed by the gpio identifier.
+
+.br
+
+.br
+
+.EX
+#1058747
+.br
+0H
+.br
+0I
+.br
+#1059012
+.br
+1H
+.br
+#1079777
+.br
+1I
+.br
+#1079782
+.br
+0I
+.br
+#1079852
+.br
+1I
+.br
+#1079857
+.br
+0I
+.br
+0H
+.br
+#1165113
+.br
+1H
+.br
+#1165118
+.br
+0H
+.br
+#1165153
+.br
+1H
+.br
+
+.EE
+
+.SH SEE ALSO
+
+pigpiod(1), pigs(1), pigpio(3), pigpiod_if(3)
+.SH AUTHOR
+
+joan@abyz.co.uk
diff --git a/pigpio.3 b/pigpio.3
new file mode 100644
index 0000000..533bb46
--- /dev/null
+++ b/pigpio.3
@@ -0,0 +1,6134 @@
+
+." Process this file with
+." groff -man -Tascii pigpio.3
+."
+.TH pigpio 3 2012-2014 Linux "pigpio archive"
+.SH NAME
+pigpio - A C library to manipulate the Pi's gpios.
+
+.SH SYNOPSIS
+
+gcc -o prog prog.c -lpigpio -lrt -lpthread
+
+sudo ./prog
+.SH DESCRIPTION
+
+
+.br
+
+.br
+pigpio is a C library for the Raspberry which allows control of the gpios.
+
+.br
+
+.br
+.SS Features
+.br
+
+.br
+o PWM on any of gpios 0-31
+
+.br
+
+.br
+o servo pulses on any of gpios 0-31
+
+.br
+
+.br
+o callbacks when any of gpios 0-31 change state
+
+.br
+
+.br
+o callbacks at timed intervals
+
+.br
+
+.br
+o reading/writing all of the gpios in a bank as one operation
+
+.br
+
+.br
+o individually setting gpio modes, reading and writing
+
+.br
+
+.br
+o notifications when any of gpios 0-31 change state
+
+.br
+
+.br
+o the construction of output waveforms with microsecond timing
+
+.br
+
+.br
+o rudimentary permission control over gpios
+
+.br
+
+.br
+o a simple interface to start and stop new threads
+
+.br
+
+.br
+o I2C, SPI, and serial link wrappers
+
+.br
+
+.br
+o creating and running scripts
+
+.br
+
+.br
+.SS gpios
+.br
+
+.br
+ALL gpios are identified by their Broadcom number.
+
+.br
+
+.br
+.SS Credits
+.br
+
+.br
+The PWM and servo pulses are timed using the DMA and PWM peripherals.
+
+.br
+
+.br
+This use was inspired by Richard Hirst's servoblaster kernel module.
+
+.br
+
+.br
+https://github.com/richardghirst/PiBits/tree/master/ServoBlaster
+.br
+
+.br
+.SS Usage
+.br
+
+.br
+Include <pigpio.h> in your source files.
+
+.br
+
+.br
+Assuming your source is in prog.c use the following command to build and
+run the executable.
+
+.br
+
+.br
+
+.EX
+gcc -o prog prog.c -lpigpio -lpthread -lrt
+.br
+sudo ./prog
+.br
+
+.EE
+
+.br
+
+.br
+For examples of usage see the C programs within the pigpio archive file.
+
+.br
+
+.br
+.SS Notes
+.br
+
+.br
+All the functions which return an int return < 0 on error.
+
+.br
+
+.br
+If the library isn't initialised all but the \fBgpioCfg*\fP, \fBgpioVersion\fP,
+and \fBgpioHardwareRevision\fP functions will return PI_NOT_INITIALISED.
+
+.br
+
+.br
+If the library is initialised the \fBgpioCfg*\fP functions will
+return PI_INITIALISED.
+
+.br
+
+.br
+.SH FUNCTIONS
+
+.IP "\fBint gpioInitialise(void)\fP"
+.IP "" 4
+Initialises the library.
+
+.br
+
+.br
+Call before using the other library functions.
+
+.br
+
+.br
+Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
+
+.br
+
+.br
+The only exception is the optional \fBgpioCfg*\fP functions, see later.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+if (gpioInitialise() < 0)
+.br
+{
+.br
+ // pigpio initialisation failed.
+.br
+}
+.br
+else
+.br
+{
+.br
+ // pigpio initialised okay.
+.br
+}
+.br
+
+.EE
+
+.IP "\fBvoid gpioTerminate(void)\fP"
+.IP "" 4
+Terminates the library.
+
+.br
+
+.br
+Returns nothing.
+
+.br
+
+.br
+Call before program exit.
+
+.br
+
+.br
+This function resets the DMA and PWM peripherals, releases memory, and
+terminates any running threads.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioTerminate();
+.br
+
+.EE
+
+.IP "\fBint gpioSetMode(unsigned gpio, unsigned mode)\fP"
+.IP "" 4
+Sets the gpio mode, typically input or output.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53
+.br
+mode: 0-7
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE.
+
+.br
+
+.br
+Arduino style: pinMode.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioSetMode(17, PI_INPUT); // Set gpio17 as input.
+.br
+
+.br
+gpioSetMode(18, PI_OUTPUT); // Set gpio18 as output.
+.br
+
+.br
+gpioSetMode(22,PI_ALT0); // Set gpio22 to alternative mode 0.
+.br
+
+.EE
+
+.IP "\fBint gpioGetMode(unsigned gpio)\fP"
+.IP "" 4
+Gets the gpio mode.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53
+.br
+
+.EE
+
+.br
+
+.br
+Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+if (gpioGetMode(17) != PI_ALT0)
+.br
+{
+.br
+ gpioSetMode(17, PI_ALT0); // set gpio17 to ALT0
+.br
+}
+.br
+
+.EE
+
+.IP "\fBint gpioSetPullUpDown(unsigned gpio, unsigned pud)\fP"
+.IP "" 4
+Sets or clears resistor pull ups or downs on the gpio.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53
+.br
+ pud: 0-2
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up.
+.br
+
+.br
+gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.
+.br
+
+.br
+gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs.
+.br
+
+.EE
+
+.IP "\fBint gpioRead(unsigned gpio)\fP"
+.IP "" 4
+Reads the gpio level, on or off.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53
+.br
+
+.EE
+
+.br
+
+.br
+Returns the gpio level if OK, otherwise PI_BAD_GPIO.
+
+.br
+
+.br
+Arduino style: digitalRead.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+printf("gpio24 is level %d\n", gpioRead(24));
+.br
+
+.EE
+
+.IP "\fBint gpioWrite(unsigned gpio, unsigned level)\fP"
+.IP "" 4
+Sets the gpio level, on or off.
+
+.br
+
+.br
+
+.EX
+ gpio: 0-53
+.br
+level: 0,1
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL.
+
+.br
+
+.br
+If PWM or servo pulses are active on the gpio they are switched off.
+
+.br
+
+.br
+Arduino style: digitalWrite
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioWrite(24, 1); // Set gpio24 high.
+.br
+
+.EE
+
+.IP "\fBint gpioPWM(unsigned user_gpio, unsigned dutycycle)\fP"
+.IP "" 4
+Starts PWM on the gpio, dutycycle between 0 (off) and range (fully on).
+Range defaults to 255.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+dutycycle: 0-range
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE.
+
+.br
+
+.br
+Arduino style: analogWrite
+
+.br
+
+.br
+This and the servo functionality use the DMA and PWM or PCM peripherals
+to control and schedule the pulse lengths and duty cycles.
+
+.br
+
+.br
+The \fBgpioSetPWMrange\fP function may be used to change the default
+range of 255.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioPWM(17, 255); // Sets gpio17 full on.
+.br
+
+.br
+gpioPWM(18, 128); // Sets gpio18 half on.
+.br
+
+.br
+gpioPWM(23, 0); // Sets gpio23 full off.
+.br
+
+.EE
+
+.IP "\fBint gpioSetPWMrange(unsigned user_gpio, unsigned range)\fP"
+.IP "" 4
+Selects the dutycycle range to be used for the gpio. Subsequent calls
+to gpioPWM will use a dutycycle between 0 (off) and range (fully on).
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ range: 25-40000
+.br
+
+.EE
+
+.br
+
+.br
+Returns the real range for the given gpio's frequency if OK,
+otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE.
+
+.br
+
+.br
+If PWM is currently active on the gpio its dutycycle will be scaled
+to reflect the new range.
+
+.br
+
+.br
+The real range, the number of steps between fully off and fully
+on for each frequency, is given in the following table.
+
+.br
+
+.br
+
+.EX
+ 25, 50, 100, 125, 200, 250, 400, 500, 625,
+.br
+ 800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000
+.br
+
+.EE
+
+.br
+
+.br
+The real value set by \fBgpioPWM\fP is (dutycycle * real range) / range.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioSetPWMrange(24, 2000); // Now 2000 is fully on
+.br
+ // 1000 is half on
+.br
+ // 500 is quarter on, etc.
+.br
+
+.EE
+
+.IP "\fBint gpioGetPWMrange(unsigned user_gpio)\fP"
+.IP "" 4
+Returns the dutycycle range used for the gpio if OK, otherwise
+PI_BAD_USER_GPIO.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+
+.EE
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+r = gpioGetPWMrange(23);
+.br
+
+.EE
+
+.IP "\fBint gpioGetPWMrealRange(unsigned user_gpio)\fP"
+.IP "" 4
+Returns the real range used for the gpio if OK, otherwise
+PI_BAD_USER_GPIO.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+
+.EE
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+rr = gpioGetPWMrealRange(17);
+.br
+
+.EE
+
+.IP "\fBint gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)\fP"
+.IP "" 4
+Sets the frequency in hertz to be used for the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+frequency: >=0
+.br
+
+.EE
+
+.br
+
+.br
+Returns the numerically closest frequency if OK, otherwise
+PI_BAD_USER_GPIO.
+
+.br
+
+.br
+The selectable frequencies depend upon the sample rate which
+may be 1, 2, 4, 5, 8, or 10 microseconds (default 5).
+
+.br
+
+.br
+Each gpio can be independently set to one of 18 different PWM
+frequencies.
+
+.br
+
+.br
+If PWM is currently active on the gpio it will be
+switched off and then back on at the new frequency.
+
+.br
+
+.br
+The frequencies for each sample rate are:
+
+.br
+
+.br
+
+.EX
+ Hertz
+.br
+
+.br
+ 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
+.br
+ 1250 1000 800 500 400 250 200 100 50
+.br
+
+.br
+ 2: 20000 10000 5000 4000 2500 2000 1250 1000 800
+.br
+ 625 500 400 250 200 125 100 50 25
+.br
+
+.br
+ 4: 10000 5000 2500 2000 1250 1000 625 500 400
+.br
+ 313 250 200 125 100 63 50 25 13
+.br
+sample
+.br
+ rate
+.br
+ (us) 5: 8000 4000 2000 1600 1000 800 500 400 320
+.br
+ 250 200 160 100 80 50 40 20 10
+.br
+
+.br
+ 8: 5000 2500 1250 1000 625 500 313 250 200
+.br
+ 156 125 100 63 50 31 25 13 6
+.br
+
+.br
+ 10: 4000 2000 1000 800 500 400 250 200 160
+.br
+ 125 100 80 50 40 25 20 10 5
+.br
+
+.EE
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioSetPWMfrequency(23, 0); // Set gpio23 to lowest frequency.
+.br
+
+.br
+gpioSetPWMfrequency(24, 500); // Set gpio24 to 500Hz.
+.br
+
+.br
+gpioSetPWMfrequency(25, 100000); // Set gpio25 to highest frequency.
+.br
+
+.EE
+
+.IP "\fBint gpioGetPWMfrequency(unsigned user_gpio)\fP"
+.IP "" 4
+Returns the frequency (in hertz) used for the gpio if OK, otherwise
+PI_BAD_USER_GPIO.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+
+.EE
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+f = gpioGetPWMfrequency(23); // Get frequency used for gpio23.
+.br
+
+.EE
+
+.IP "\fBint gpioServo(unsigned user_gpio, unsigned pulsewidth)\fP"
+.IP "" 4
+Starts servo pulses on the gpio, 0 (off), 500 (most anti-clockwise) to
+2500 (most clockwise).
+
+.br
+
+.br
+
+.EX
+ user_gpio: 0-31
+.br
+pulsewidth: 0, 500-2500
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH.
+
+.br
+
+.br
+The range supported by servos varies and should probably be determined
+by experiment. A value of 1500 should always be safe and represents
+the mid-point of rotation. You can DAMAGE a servo if you command it
+to move beyond its limits.
+
+.br
+
+.br
+The following causes an on pulse of 1500 microseconds duration to be
+transmitted on gpio 17 at a rate of 50 times per second. This will
+command a servo connected to gpio 17 to rotate to its mid-point.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioServo(17, 1000); // Move servo to safe position anti-clockwise.
+.br
+
+.br
+gpioServo(23, 1500); // Move servo to centre position.
+.br
+
+.br
+gpioServo(25, 2000); // Move servo to safe position clockwise.
+.br
+
+.EE
+
+.br
+
+.br
+OTHER UPDATE RATES:
+
+.br
+
+.br
+This function updates servos at 50Hz. If you wish to use a different
+update frequency you will have to use the PWM functions.
+
+.br
+
+.br
+
+.EX
+PWM Hz 50 100 200 400 500
+.br
+1E6/Hz 20000 10000 5000 2500 2000
+.br
+
+.EE
+
+.br
+
+.br
+Firstly set the desired PWM frequency using \fBgpioSetPWMfrequency\fP.
+
+.br
+
+.br
+Then set the PWM range using \fBgpioSetPWMrange\fP to 1E6/frequency.
+Doing this allows you to use units of microseconds when setting
+the servo pulse width.
+
+.br
+
+.br
+E.g. If you want to update a servo connected to gpio25 at 400Hz
+
+.br
+
+.br
+
+.EX
+gpioSetPWMfrequency(25, 400);
+.br
+
+.br
+gpioSetPWMrange(25, 2500);
+.br
+
+.EE
+
+.br
+
+.br
+Thereafter use the PWM command to move the servo,
+e.g. gpioPWM(25, 1500) will set a 1500 us pulse.
+
+.IP "\fBint gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f)\fP"
+.IP "" 4
+Registers a function to be called (a callback) when the specified
+gpio changes state.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ f: the callback function
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
+
+.br
+
+.br
+One function may be registered per gpio.
+
+.br
+
+.br
+The function is passed the gpio, the new level, and the tick.
+
+.br
+
+.br
+The alert may be cancelled by passing NULL as the function.
+
+.br
+
+.br
+The gpios are sampled at a rate set when the library is started.
+
+.br
+
+.br
+If a value isn't specifically set the default of 5 us is used.
+
+.br
+
+.br
+The number of samples per second is given in the following table.
+
+.br
+
+.br
+
+.EX
+ samples
+.br
+ per sec
+.br
+
+.br
+ 1 1,000,000
+.br
+ 2 500,000
+.br
+sample 4 250,000
+.br
+rate 5 200,000
+.br
+(us) 8 125,000
+.br
+ 10 100,000
+.br
+
+.EE
+
+.br
+
+.br
+Level changes shorter than the sample rate may be missed.
+
+.br
+
+.br
+The thread which calls the alert functions is triggered nominally
+1000 times per second. The active alert functions will be called
+once per level change since the last time the thread was activated.
+i.e. The active alert functions will get all level changes but there
+will be a latency.
+
+.br
+
+.br
+The tick value is the time stamp of the sample in microseconds, see
+\fBgpioTick\fP for more details.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+void aFunction(int gpio, int level, uint32_t tick)
+.br
+{
+.br
+ printf("gpio %d became %d at %d\n", gpio, level, tick);
+.br
+}
+.br
+
+.br
+// call aFunction whenever gpio 4 changes state
+.br
+
+.br
+gpioSetAlertFunc(4, aFunction);
+.br
+
+.EE
+
+.IP "\fBint gpioSetAlertFuncEx(unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata)\fP"
+.IP "" 4
+Registers a function to be called (a callback) when the specified
+gpio changes state.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ f: the callback function
+.br
+ userdata: pointer to arbitrary user data
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
+
+.br
+
+.br
+One function may be registered per gpio.
+
+.br
+
+.br
+The function is passed the gpio, the new level, the tick, and
+the userdata pointer.
+
+.br
+
+.br
+Only one of \fBgpioSetAlertFunc\fP or \fBgpioSetAlertFuncEx\fP can be
+registered per gpio.
+
+.br
+
+.br
+See \fBgpioSetAlertFunc\fP for further details.
+
+.IP "\fBint gpioNotifyOpen(void)\fP"
+.IP "" 4
+This function requests a free notification handle.
+
+.br
+
+.br
+Returns a handle greater than or equal to zero if OK,
+otherwise PI_NO_HANDLE.
+
+.br
+
+.br
+A notification is a method for being notified of gpio state changes
+via a pipe or socket.
+
+.br
+
+.br
+Pipe notifications for handle x will be available at the pipe
+named /dev/pigpiox (where x is the handle number). E.g. if the
+function returns 15 then the notifications must be read
+from /dev/pigpio15.
+
+.br
+
+.br
+Socket notifications are returned to the socket which requested the
+handle.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+h = gpioNotifyOpen();
+.br
+
+.br
+if (h >= 0)
+.br
+{
+.br
+ sprintf(str, "/dev/pigpio%d", h);
+.br
+
+.br
+ fd = open(str, "r");
+.br
+
+.br
+ if (fd >= 0)
+.br
+ {
+.br
+ // Okay.
+.br
+ }
+.br
+ else
+.br
+ {
+.br
+ // Error.
+.br
+ }
+.br
+}
+.br
+else
+.br
+{
+.br
+ // Error.
+.br
+}
+.br
+
+.EE
+
+.IP "\fBint gpioNotifyBegin(unsigned handle, uint32_t bits)\fP"
+.IP "" 4
+This function starts notifications on a previously opened handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by \fBgpioNotifyOpen\fP
+.br
+ bits: a bit mask indicating the gpios of interest
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.br
+
+.br
+The notification sends state changes for each gpio whose corresponding
+bit in bits is set.
+
+.br
+
+.br
+Each notification occupies 12 bytes in the fifo and has the
+following structure.
+
+.br
+
+.br
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint16_t seqno;
+.br
+ uint16_t flags;
+.br
+ uint32_t tick;
+.br
+ uint32_t level;
+.br
+} gpioReport_t;
+.br
+
+.EE
+
+.br
+
+.br
+seqno starts at 0 each time the handle is opened and then increments
+by one for each report.
+
+.br
+
+.br
+flags, if bit 5 is set then bits 0-4 of the flags indicate a gpio
+which has had a watchdog timeout.
+
+.br
+
+.br
+tick is the number of microseconds since system boot.
+
+.br
+
+.br
+level indicates the level of each gpio.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+// Start notifications for gpios 1, 4, 6, 7, 10.
+.br
+
+.br
+// 1
+.br
+// 0 76 4 1
+.br
+// (1234 = 0x04D2 = 0b0000010011010010)
+.br
+
+.br
+gpioNotifyBegin(h, 1234);
+.br
+
+.EE
+
+.IP "\fBint gpioNotifyPause(unsigned handle)\fP"
+.IP "" 4
+This function pauses notifications on a previously opened handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by \fBgpioNotifyOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.br
+
+.br
+Notifications for the handle are suspended until \fBgpioNotifyBegin\fP
+is called again.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioNotifyPause(h);
+.br
+
+.EE
+
+.IP "\fBint gpioNotifyClose(unsigned handle)\fP"
+.IP "" 4
+This function stops notifications on a previously opened handle
+and releases the handle for reuse.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by \fBgpioNotifyOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioNotifyClose(h);
+.br
+
+.EE
+
+.IP "\fBint gpioWaveClear(void)\fP"
+.IP "" 4
+This function clears all waveforms and any data added by calls to the
+\fBgpioWaveAdd*\fP functions.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioWaveClear();
+.br
+
+.EE
+
+.IP "\fBint gpioWaveAddNew(void)\fP"
+.IP "" 4
+This function starts a new empty waveform.
+
+.br
+
+.br
+You wouldn't normally need to call this function as it is automatically
+called after a waveform is created with the \fBgpioWaveCreate\fP function.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioWaveAddNew();
+.br
+
+.EE
+
+.IP "\fBint gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)\fP"
+.IP "" 4
+This function adds a number of pulses to the current waveform.
+
+.br
+
+.br
+
+.EX
+numPulses: the number of pulses
+.br
+ pulses: an array of pulses
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+The pulses are interleaved in time order within the existing waveform
+(if any).
+
+.br
+
+.br
+Merging allows the waveform to be built in parts, that is the settings
+for gpio#1 can be added, and then gpio#2 etc.
+
+.br
+
+.br
+If the added waveform is intended to start after or within the existing
+waveform then the first pulse should consist of a delay.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+// Construct and send a 30 microsecond square wave.
+.br
+
+.br
+gpioSetMode(gpio, PI_OUTPUT);
+.br
+
+.br
+pulse[0].gpioOn = (1<<gpio);
+.br
+pulse[0].gpioOff = 0;
+.br
+pulse[0].usDelay = 15;
+.br
+
+.br
+pulse[1].gpioOn = 0;
+.br
+pulse[1].gpioOff = (1<<gpio);
+.br
+pulse[1].usDelay = 15;
+.br
+
+.br
+gpioWaveAddNew();
+.br
+
+.br
+gpioWaveAddGeneric(2, pulse);
+.br
+
+.br
+wave_id = gpioWaveCreate();
+.br
+
+.br
+if (wave_id >= 0)
+.br
+{
+.br
+ gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);
+.br
+
+.br
+ // Transmit for 30 seconds.
+.br
+
+.br
+ sleep(30);
+.br
+
+.br
+ gpioWaveTxStop();
+.br
+}
+.br
+else
+.br
+{
+.br
+ // Wave create failed.
+.br
+}
+.br
+
+.EE
+
+.IP "\fBint gpioWaveAddSerial(unsigned user_gpio, unsigned bbBaud, unsigned offset, unsigned numChar, char *str)\fP"
+.IP "" 4
+This function adds a waveform representing serial data to the
+existing waveform (if any). The serial data starts offset microseconds
+from the start of the waveform.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ bbBaud: 100-250000
+.br
+ offset: 0-
+.br
+ numChar: 1-
+.br
+ str: an array of chars (which may contain nulls)
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS,
+PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+The serial data is formatted as one start bit, eight data bits, and one
+stop bit.
+
+.br
+
+.br
+It is legal to add serial data streams with different baud rates to
+the same waveform.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+#define MSG_LEN 8
+.br
+
+.br
+int i;
+.br
+char *str;
+.br
+char data[MSG_LEN];
+.br
+
+.br
+str = "Hello world!";
+.br
+
+.br
+gpioWaveAddSerial(4, 9600, 0, strlen(str), str);
+.br
+
+.br
+for (i=0; i<MSG_LEN; i++) data[i] = i;
+.br
+
+.br
+// Data added is offset 1 second from the waveform start.
+.br
+gpioWaveAddSerial(4, 9600, 1000000, MSG_LEN, data);
+.br
+
+.EE
+
+.IP "\fBint gpioWaveCreate(void)\fP"
+.IP "" 4
+This function creates a waveform from the data provided by the prior
+calls to the \fBgpioWaveAdd*\fP functions. Upon success a positive wave id
+is returned.
+
+.br
+
+.br
+The data provided by the \fBgpioWaveAdd*\fP functions is consumed by this
+function.
+
+.br
+
+.br
+As many waveforms may be created as there is space available. The
+wave id is passed to \fBgpioWaveTxSend\fP to specify the waveform to transmit.
+
+.br
+
+.br
+Normal usage would be
+
+.br
+
+.br
+Step 1. \fBgpioWaveClear\fP to clear all waveforms and added data.
+
+.br
+
+.br
+Step 2. \fBgpioWaveAdd*\fP calls to supply the waveform data.
+
+.br
+
+.br
+Step 3. \fBgpioWaveCreate\fP to create the waveform and get a unique id
+
+.br
+
+.br
+Repeat steps 2 and 3 as needed.
+
+.br
+
+.br
+Step 4. \fBgpioWaveTxSend\fP with the id of the waveform to transmit.
+
+.br
+
+.br
+A waveform comprises one of more pulses. Each pulse consists of a
+\fBgpioPulse_t\fP structure.
+
+.br
+
+.br
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint32_t gpioOn;
+.br
+ uint32_t gpioOff;
+.br
+ uint32_t usDelay;
+.br
+} gpioPulse_t;
+.br
+
+.EE
+
+.br
+
+.br
+The fields specify
+
+.br
+
+.br
+1) the gpios to be switched on at the start of the pulse.
+.br
+2) the gpios to be switched off at the start of the pulse.
+.br
+3) the delay in microseconds before the next pulse.
+
+.br
+
+.br
+Any or all the fields can be zero. It doesn't make any sense to
+set all the fields to zero (the pulse will be ignored).
+
+.br
+
+.br
+When a waveform is started each pulse is executed in order with the
+specified delay between the pulse and the next.
+
+.br
+
+.br
+Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
+PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
+
+.IP "\fBint gpioWaveDelete(unsigned wave_id)\fP"
+.IP "" 4
+This function deletes all created waveforms with ids greater than or
+equal to wave_id.
+
+.br
+
+.br
+
+.EX
+wave_id: >=0, as returned by \fBgpioWaveCreate\fP
+.br
+
+.EE
+
+.br
+
+.br
+Wave ids are allocated in order, 0, 1, 2, etc.
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
+
+.IP "\fBint gpioWaveTxStart(unsigned wave_mode)\fP"
+.IP "" 4
+This function creates and then transmits a waveform. The mode
+determines whether the waveform is sent once or cycles endlessly.
+
+.br
+
+.br
+
+.EX
+wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
+.br
+
+.EE
+
+.br
+
+.br
+This function is deprecated and should no longer be used. Use
+\fBgpioWaveCreate\fP and \fBgpioWaveTxSend\fP instead.
+
+.br
+
+.br
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_MODE.
+
+.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP"
+.IP "" 4
+This function transmits the waveform with id wave_id. The mode
+determines whether the waveform is sent once or cycles endlessly.
+
+.br
+
+.br
+
+.EX
+ wave_id: >=0, as returned by \fBgpioWaveCreate\fP
+.br
+wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
+
+.IP "\fBint gpioWaveTxBusy(void)\fP"
+.IP "" 4
+This function checks to see if a waveform is currently being
+transmitted.
+
+.br
+
+.br
+Returns 1 if a waveform is currently being transmitted, otherwise 0.
+
+.IP "\fBint gpioWaveTxStop(void)\fP"
+.IP "" 4
+This function aborts the transmission of the current waveform.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+This function is intended to stop a waveform started in repeat mode.
+
+.IP "\fBint gpioWaveGetMicros(void)\fP"
+.IP "" 4
+This function returns the length in microseconds of the current
+waveform.
+
+.IP "\fBint gpioWaveGetHighMicros(void)\fP"
+.IP "" 4
+This function returns the length in microseconds of the longest waveform
+created since \fBgpioInitialise\fP was called.
+
+.IP "\fBint gpioWaveGetMaxMicros(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in
+microseconds.
+
+.IP "\fBint gpioWaveGetPulses(void)\fP"
+.IP "" 4
+This function returns the length in pulses of the current waveform.
+
+.IP "\fBint gpioWaveGetHighPulses(void)\fP"
+.IP "" 4
+This function returns the length in pulses of the longest waveform
+created since \fBgpioInitialise\fP was called.
+
+.IP "\fBint gpioWaveGetMaxPulses(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in pulses.
+
+.IP "\fBint gpioWaveGetCbs(void)\fP"
+.IP "" 4
+This function returns the length in DMA control blocks of the current
+waveform.
+
+.IP "\fBint gpioWaveGetHighCbs(void)\fP"
+.IP "" 4
+This function returns the length in DMA control blocks of the longest
+waveform created since \fBgpioInitialise\fP was called.
+
+.IP "\fBint gpioWaveGetMaxCbs(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in DMA
+control blocks.
+
+.IP "\fBint gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud)\fP"
+.IP "" 4
+This function opens a gpio for bit bang reading of serial data.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ bbBaud: 100-250000
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
+or PI_GPIO_IN_USE.
+
+.br
+
+.br
+The serial data is returned in a cyclic buffer and is read using
+\fBgpioSerialRead\fP.
+
+.br
+
+.br
+It is the caller's responsibility to read data from the cyclic buffer
+in a timely fashion.
+
+.IP "\fBint gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize)\fP"
+.IP "" 4
+This function copies up to bufSize bytes of data read from the
+bit bang serial cyclic buffer to the buffer starting at buf.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP
+.br
+ buf: an array to receive the read bytes
+.br
+ bufSize: 0-
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
+or PI_NOT_SERIAL_GPIO.
+
+.IP "\fBint gpioSerialReadClose(unsigned user_gpio)\fP"
+.IP "" 4
+This function closes a gpio for bit bang reading of serial data.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
+
+.IP "\fBint i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags)\fP"
+.IP "" 4
+This returns a handle for the device at the address on the I2C bus.
+
+.br
+
+.br
+
+.EX
+ i2cBus: 0-1
+.br
+ i2cAddr: 0x08-0x77
+.br
+i2cFlags: 0
+.br
+
+.EE
+
+.br
+
+.br
+No flags are currently defined. This parameter should be set to zero.
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
+PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
+
+.IP "\fBint i2cClose(unsigned handle)\fP"
+.IP "" 4
+This closes the I2C device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint i2cReadDevice(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This reads count bytes from the raw device into buf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+ buf: an array to receive the read data bytes
+.br
+ count: >0, the number of bytes to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_READ_FAILED.
+
+.IP "\fBint i2cWriteDevice(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes count bytes from buf to the raw device.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+ buf: an array containing the data bytes to write
+.br
+ count: >0, the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.IP "\fBint i2cWriteQuick(unsigned handle, unsigned bit)\fP"
+.IP "" 4
+This sends a single bit (in the Rd/Wr bit) to the device associated
+with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+ bit: 0-1, the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Quick command. smbus 2.0 5.5.1
+
+.IP "\fBint i2cWriteByte(unsigned handle, unsigned bVal)\fP"
+.IP "" 4
+This sends a single byte to the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+ bVal: 0-0xFF, the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Send byte. smbus 2.0 5.5.2
+
+.IP "\fBint i2cReadByte(unsigned handle)\fP"
+.IP "" 4
+This reads a single byte from the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Receive byte. smbus 2.0 5.5.3
+
+.IP "\fBint i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal)\fP"
+.IP "" 4
+This writes a single byte to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write
+.br
+ bVal: 0-0xFF, the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Write byte. smbus 2.0 5.5.4
+
+.IP "\fBint i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal)\fP"
+.IP "" 4
+This writes a single 16 bit word to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write
+.br
+ wVal: 0-0xFFFF, the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Write word. smbus 2.0 5.5.4
+
+.IP "\fBint i2cReadByteData(unsigned handle, unsigned i2cReg)\fP"
+.IP "" 4
+This reads a single byte from the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Read byte. smbus 2.0 5.5.5
+
+.IP "\fBint i2cReadWordData(unsigned handle, unsigned i2cReg)\fP"
+.IP "" 4
+This reads a single 16 bit word from the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Read word. smbus 2.0 5.5.5
+
+.IP "\fBint i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal)\fP"
+.IP "" 4
+This writes 16 bits of data to the specified register of the device
+associated with handle and and reads 16 bits of data in return.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write/read
+.br
+ wVal: 0-0xFFFF, the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Process call. smbus 2.0 5.5.6
+
+.IP "\fBint i2cWriteBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes up to 32 bytes to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write
+.br
+ buf: an array with the data to send
+.br
+ count: 1-32, the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Block write. smbus 2.0 5.5.7
+
+.IP "\fBint i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf)\fP"
+.IP "" 4
+This reads a block of up to 32 bytes from the specified register of
+the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to read
+.br
+ buf: an array to receive the read data
+.br
+
+.EE
+
+.br
+
+.br
+The amount of returned data is set by the device.
+
+.br
+
+.br
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Block read. smbus 2.0 5.5.7
+
+.IP "\fBint i2cBlockProcessCall(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes data bytes to the specified register of the device
+associated with handle and reads a device specified number
+of bytes of data in return.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write/read
+.br
+ buf: an array with the data to send and to receive the read data
+.br
+ count: 1-32, the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+The smbus 2.0 documentation states that a minimum of 1 byte may be
+sent and a minimum of 1 byte may be received. The total number of
+bytes sent/received must be 32 or less.
+
+.br
+
+.br
+Block write-block read. smbus 2.0 5.5.8
+
+.IP "\fBint i2cReadI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP"
+.IP "" 4
+This reads count bytes from the specified register of the device
+associated with handle . The count may be 1-32.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to read
+.br
+ buf: an array to receive the read data
+.br
+ count: 1-32, the number of bytes to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.IP "\fBint i2cWriteI2CBlockData(unsigned handle, unsigned i2cReg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes 1 to 32 bytes to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2cOpen\fP
+.br
+i2cReg: 0-255, the register to write
+.br
+ buf: the data to write
+.br
+ count: 1-32, the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.IP "\fBint spiOpen(unsigned spiChan, unsigned spiBaud, unsigned spiFlags)\fP"
+.IP "" 4
+This function returns a handle for the SPI device on the channel
+Data will be transferred at baud bits per second.
+
+.br
+
+.br
+
+.EX
+ spiChan: 0-1
+.br
+ spiBaud: >1
+.br
+spiFlags: 0-3
+.br
+
+.EE
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
+PI_BAD_SPI_SPEED, PI_BAD_FLAGS, or PI_SPI_OPEN_FAILED.
+
+.br
+
+.br
+The least significant two bits of flags define the SPI mode.
+
+.br
+
+.br
+
+.EX
+Mode POL PHA
+.br
+ 0 0 0
+.br
+ 1 0 1
+.br
+ 2 1 0
+.br
+ 3 1 1
+.br
+
+.EE
+
+.br
+
+.br
+The other bits in flags should be set to zero.
+
+.IP "\fBint spiClose(unsigned handle)\fP"
+.IP "" 4
+This functions closes the SPI device identified by the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspiOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint spiRead(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function reads count bytes of data from the SPI
+device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspiOpen\fP
+.br
+ buf: an array to receive the read data bytes
+.br
+ count: the number of bytes to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint spiWrite(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function writes count bytes of data from buf to the SPI
+device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspiOpen\fP
+.br
+ buf: the data bytes to write
+.br
+ count: the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP"
+.IP "" 4
+This function transfers count bytes of data from txBuf to the SPI
+device associated with the handle. Simultaneously count bytes of
+data are read from the device and placed in rxBuf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspiOpen\fP
+.br
+ txBuf: the data bytes to write
+.br
+ rxBuf: the received data bytes
+.br
+ count: the number of bytes to transfer
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint serOpen(char *sertty, unsigned serBaud, unsigned serFlags)\fP"
+.IP "" 4
+This function opens a serial device at a specified baud rate
+with specified flags.
+
+.br
+
+.br
+
+.EX
+ sertty: the serial device to open, /dev/tty*
+.br
+ serBaud: the baud rate to use
+.br
+serFlags: 0
+.br
+
+.EE
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
+PI_SER_OPEN_FAILED.
+
+.br
+
+.br
+No flags are currently defined. This parameter should be set to zero.
+
+.IP "\fBint serClose(unsigned handle)\fP"
+.IP "" 4
+This function closes the serial device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint serWriteByte(unsigned handle, unsigned bVal)\fP"
+.IP "" 4
+This function writes bVal to the serial port associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+
+.IP "\fBint serReadByte(unsigned handle)\fP"
+.IP "" 4
+This function reads a byte from the serial port associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
+
+.IP "\fBint serWrite(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function writes count bytes from buf to the the serial port
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserOpen\fP
+.br
+ buf: the array of bytes to write
+.br
+ count: the number of bytes to write
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+
+.IP "\fBint serRead(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function reads up count bytes from the the serial port
+associated with handle and writes them to buf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to serial_open
+.br
+ buf: an array to receive the read data
+.br
+ count: the maximum number of bytes to read
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
+
+.IP "\fBint serDataAvailable(unsigned handle)\fP"
+.IP "" 4
+This function returns the number of bytes available
+to be read from the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserOpen\fP
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes of data available (>=0) if OK,
+otherwise PI_BAD_HANDLE.
+
+.IP "\fBint gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP"
+.IP "" 4
+This function sends a trigger pulse to a gpio. The gpio is set to
+level for pulseLen microseconds and then reset to not level.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ pulseLen: 1-50
+.br
+ level: 0,1
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
+or PI_BAD_PULSELEN.
+
+.IP "\fBint gpioSetWatchdog(unsigned user_gpio, unsigned timeout)\fP"
+.IP "" 4
+Sets a watchdog for a gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31
+.br
+ timeout: 0-60000
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT.
+
+.br
+
+.br
+The watchdog is nominally in milliseconds.
+
+.br
+
+.br
+One watchdog may be registered per gpio.
+
+.br
+
+.br
+The watchdog may be cancelled by setting timeout to 0.
+
+.br
+
+.br
+If no level change has been detected for the gpio for timeout
+milliseconds:-
+
+.br
+
+.br
+1) any registered alert function for the gpio is called with
+ the level set to PI_TIMEOUT.
+.br
+2) any notification for the gpio has a report written to the
+ fifo with the flags set to indicate a watchdog timeout.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+void aFunction(int gpio, int level, uint32_t tick)
+.br
+{
+.br
+ printf("gpio %d became %d at %d\n", gpio, level, tick);
+.br
+}
+.br
+
+.br
+// call aFunction whenever gpio 4 changes state
+.br
+gpioSetAlertFunc(4, aFunction);
+.br
+
+.br
+// or approximately every 5 millis
+.br
+gpioSetWatchdog(4, 5);
+.br
+
+.EE
+
+.IP "\fBint gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits)\fP"
+.IP "" 4
+Registers a function to be called (a callback) every millisecond
+with the latest gpio samples.
+
+.br
+
+.br
+
+.EX
+ f: the function to call
+.br
+bits: the gpios of interest
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+The function is passed a pointer to the samples and the number
+of samples.
+
+.br
+
+.br
+Only one function can be registered.
+
+.br
+
+.br
+The callback may be cancelled by passing NULL as the function.
+
+.br
+
+.br
+The samples returned will be the union of bits, plus any active alerts,
+plus any active notifications.
+
+.br
+
+.br
+e.g. if there are alerts for gpios 7, 8, and 9, notifications for gpios
+8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for gpios
+7, 8, 9, 10, 17, 23, and 24 will be reported.
+
+.IP "\fBint gpioSetGetSamplesFuncEx(gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata)\fP"
+.IP "" 4
+Registers a function to be called (a callback) every millisecond
+with the latest gpio samples.
+
+.br
+
+.br
+
+.EX
+ f: the function to call
+.br
+ bits: the gpios of interest
+.br
+userdata: a pointer to arbitrary user data
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+The function is passed a pointer to the samples, the number
+of samples, and the userdata pointer.
+
+.br
+
+.br
+Only one of \fBgpioGetSamplesFunc\fP or \fBgpioGetSamplesFuncEx\fP can be
+registered.
+
+.br
+
+.br
+See \fBgpioSetGetSamplesFunc\fP for further details.
+
+.IP "\fBint gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f)\fP"
+.IP "" 4
+Registers a function to be called (a callback) every millis milliseconds.
+
+.br
+
+.br
+
+.EX
+ timer: 0-9
+.br
+millis: 10-60000
+.br
+ f: the function to call
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
+
+.br
+
+.br
+10 timers are supported numbered 0 to 9.
+
+.br
+
+.br
+One function may be registered per timer.
+
+.br
+
+.br
+The timer may be cancelled by passing NULL as the function.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+void bFunction(void)
+.br
+{
+.br
+ printf("two seconds have elapsed\n");
+.br
+}
+.br
+
+.br
+// call bFunction every 2000 milliseconds
+.br
+gpioSetTimerFunc(0, 2000, bFunction);
+.br
+
+.EE
+
+.IP "\fBint gpioSetTimerFuncEx(unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata)\fP"
+.IP "" 4
+Registers a function to be called (a callback) every millis milliseconds.
+
+.br
+
+.br
+
+.EX
+ timer: 0-9.
+.br
+ millis: 10-60000
+.br
+ f: the function to call
+.br
+userdata: a pointer to arbitrary user data
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
+
+.br
+
+.br
+The function is passed the userdata pointer.
+
+.br
+
+.br
+Only one of \fBgpioSetTimerFunc\fP or \fBgpioSetTimerFuncEx\fP can be
+registered per timer.
+
+.br
+
+.br
+See \fBgpioSetTimerFunc\fP for further details.
+
+.IP "\fBpthread_t *gpioStartThread(gpioThreadFunc_t f, void *arg)\fP"
+.IP "" 4
+Starts a new thread of execution with f as the main routine.
+
+.br
+
+.br
+
+.EX
+ f: the main function for the new thread
+.br
+arg: a pointer to arbitrary user data
+.br
+
+.EE
+
+.br
+
+.br
+Returns a pointer to pthread_t if OK, otherwise NULL.
+
+.br
+
+.br
+The function is passed the single argument arg.
+
+.br
+
+.br
+The thread can be cancelled by passing the pointer to pthread_t to
+\fBgpioStopThread\fP.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+#include <stdio.h>
+.br
+#include <pigpio.h>
+.br
+
+.br
+void *myfunc(void *arg)
+.br
+{
+.br
+ while (1)
+.br
+ {
+.br
+ printf("%s\n", arg);
+.br
+ sleep(1);
+.br
+ }
+.br
+}
+.br
+
+.br
+int main(int argc, char *argv[])
+.br
+{
+.br
+ pthread_t *p1, *p2, *p3;
+.br
+
+.br
+ if (gpioInitialise() < 0) return 1;
+.br
+
+.br
+ p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);
+.br
+
+.br
+ p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);
+.br
+
+.br
+ p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);
+.br
+
+.br
+ gpioStopThread(p3); sleep(3);
+.br
+
+.br
+ gpioStopThread(p2); sleep(3);
+.br
+
+.br
+ gpioStopThread(p1); sleep(3);
+.br
+
+.br
+ gpioTerminate();
+.br
+}
+.br
+
+.EE
+
+.IP "\fBvoid gpioStopThread(pthread_t *pth)\fP"
+.IP "" 4
+Cancels the thread pointed at by pth.
+
+.br
+
+.br
+
+.EX
+pth: a thread pointer returned by \fBgpioStartThread\fP
+.br
+
+.EE
+
+.br
+
+.br
+No value is returned.
+
+.br
+
+.br
+The thread to be stopped should have been started with \fBgpioStartThread\fP.
+
+.IP "\fBint gpioStoreScript(char *script)\fP"
+.IP "" 4
+This function stores a null terminated script for later execution.
+
+.br
+
+.br
+
+.EX
+script: the text of the script
+.br
+
+.EE
+
+.br
+
+.br
+The function returns a script id if the script is valid,
+otherwise PI_BAD_SCRIPT.
+
+.IP "\fBint gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param)\fP"
+.IP "" 4
+This function runs a stored script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+ numPar: 0-10, the number of parameters
+.br
+ param: an array of parameters
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM.
+
+.br
+
+.br
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+
+.IP "\fBint gpioScriptStatus(unsigned script_id, uint32_t *param)\fP"
+.IP "" 4
+This function returns the run status of a stored script as well as
+the current values of parameters 0 to 9.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+ param: an array to hold the returned 10 parameters
+.br
+
+.EE
+
+.br
+
+.br
+The function returns greater than or equal to 0 if OK,
+otherwise PI_BAD_SCRIPT_ID.
+
+.br
+
+.br
+The run status may be
+
+.br
+
+.br
+
+.EX
+PI_SCRIPT_INITING
+.br
+PI_SCRIPT_HALTED
+.br
+PI_SCRIPT_RUNNING
+.br
+PI_SCRIPT_WAITING
+.br
+PI_SCRIPT_FAILED
+.br
+
+.EE
+
+.br
+
+.br
+The current value of script parameters 0 to 9 are returned in param.
+
+.IP "\fBint gpioStopScript(unsigned script_id)\fP"
+.IP "" 4
+This function stops a running script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+
+.IP "\fBint gpioDeleteScript(unsigned script_id)\fP"
+.IP "" 4
+This function deletes a stored script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBgpioStoreScript\fP
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+
+.IP "\fBint gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f)\fP"
+.IP "" 4
+Registers a function to be called (a callback) when a signal occurs.
+
+.br
+
+.br
+
+.EX
+signum: 0-63
+.br
+ f: the callback function
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_SIGNUM.
+
+.br
+
+.br
+The function is passed the signal number.
+
+.br
+
+.br
+One function may be registered per signal.
+
+.br
+
+.br
+The callback may be cancelled by passing NULL.
+
+.br
+
+.br
+By default all signals are treated as fatal and cause the library
+to call gpioTerminate and then exit.
+
+.IP "\fBint gpioSetSignalFuncEx(unsigned signum, gpioSignalFuncEx_t f, void *userdata)\fP"
+.IP "" 4
+Registers a function to be called (a callback) when a signal occurs.
+
+.br
+
+.br
+
+.EX
+ signum: 0-63
+.br
+ f: the callback function
+.br
+userdata: a pointer to arbitrary user data
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_SIGNUM.
+
+.br
+
+.br
+The function is passed the signal number and the userdata pointer.
+
+.br
+
+.br
+Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be
+registered per signal.
+
+.br
+
+.br
+See gpioSetSignalFunc for further details.
+
+.IP "\fBuint32_t gpioRead_Bits_0_31(void)\fP"
+.IP "" 4
+Returns the current level of gpios 0-31.
+
+.IP "\fBuint32_t gpioRead_Bits_32_53(void)\fP"
+.IP "" 4
+Returns the current level of gpios 32-53.
+
+.IP "\fBint gpioWrite_Bits_0_31_Clear(uint32_t bits)\fP"
+.IP "" 4
+Clears gpios 0-31 if the corresponding bit in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask of gpios to clear
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+// To clear (set to 0) gpios 4, 7, and 15
+.br
+gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );
+.br
+
+.EE
+
+.IP "\fBint gpioWrite_Bits_32_53_Clear(uint32_t bits)\fP"
+.IP "" 4
+Clears gpios 32-53 if the corresponding bit (0-21) in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask of gpios to clear
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.IP "\fBint gpioWrite_Bits_0_31_Set(uint32_t bits)\fP"
+.IP "" 4
+Sets gpios 0-31 if the corresponding bit in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask of gpios to set
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.IP "\fBint gpioWrite_Bits_32_53_Set(uint32_t bits)\fP"
+.IP "" 4
+Sets gpios 32-53 if the corresponding bit (0-21) in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask of gpios to set
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+// To set (set to 1) gpios 32, 40, and 53
+.br
+gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));
+.br
+
+.EE
+
+.IP "\fBint gpioTime(unsigned timetype, int *seconds, int *micros)\fP"
+.IP "" 4
+Updates the seconds and micros variables with the current time.
+
+.br
+
+.br
+
+.EX
+timetype: 0 (relative), 1 (absolute)
+.br
+ seconds: a pointer to an int to hold seconds
+.br
+ micros: a pointer to an int to hold microseconds
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_TIMETYPE.
+
+.br
+
+.br
+If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the
+number of seconds and microseconds since the epoch (1st January 1970).
+
+.br
+
+.br
+If timetype is PI_TIME_RELATIVE updates seconds and micros with the
+number of seconds and microseconds since the library was initialised.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+int secs, mics;
+.br
+
+.br
+// print the number of seconds since the library was started
+.br
+gpioTime(PI_TIME_RELATIVE, &secs, &mics);
+.br
+printf("library started %d.%03d seconds ago\n", secs, mics/1000);
+.br
+
+.EE
+
+.IP "\fBint gpioSleep(unsigned timetype, int seconds, int micros)\fP"
+.IP "" 4
+Sleeps for the number of seconds and microseconds specified by seconds
+and micros.
+
+.br
+
+.br
+
+.EX
+timetype: 0 (relative), 1 (absolute)
+.br
+ seconds: seconds to sleep
+.br
+ micros: microseconds to sleep
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS,
+or PI_BAD_MICROS.
+
+.br
+
+.br
+If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds
+and microseconds since the epoch (1st January 1970) has elapsed. System
+clock changes are taken into account.
+
+.br
+
+.br
+If timetype is PI_TIME_RELATIVE the sleep is for the specified number
+of seconds and microseconds. System clock changes do not effect the
+sleep length.
+
+.br
+
+.br
+For short delays (say, 50 microseonds or less) use \fBgpioDelay\fP.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds
+.br
+
+.br
+gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds
+.br
+
+.br
+gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute
+.br
+
+.EE
+
+.IP "\fBuint32_t gpioDelay(uint32_t micros)\fP"
+.IP "" 4
+Delays for at least the number of microseconds specified by micros.
+
+.br
+
+.br
+
+.EX
+micros: the number of microseconds to sleep
+.br
+
+.EE
+
+.br
+
+.br
+Returns the actual length of the delay in microseconds.
+
+.br
+
+.br
+Delays of 50 microseconds or less use busy waits.
+
+.IP "\fBuint32_t gpioTick(void)\fP"
+.IP "" 4
+Returns the current system tick.
+
+.br
+
+.br
+Tick is the number of microseconds since system boot.
+
+.br
+
+.br
+As tick is an unsigned 32 bit quantity it wraps around after
+2^32 microseconds, which is approximately 1 hour 12 minutes.
+
+.br
+
+.br
+You don't need to worry about the wrap around as long as you
+take a tick (uint32_t) from another tick, i.e. the following
+code will always provide the correct difference.
+
+.br
+
+.br
+\fBExample\fP
+.br
+
+.EX
+uint32_t startTick, endTick;
+.br
+int diffTick;
+.br
+
+.br
+startTick = gpioTick();
+.br
+
+.br
+// do some processing
+.br
+
+.br
+endTick = gpioTick();
+.br
+
+.br
+diffTick = endTick - startTick;
+.br
+
+.br
+printf("some processing took %d microseconds\n", diffTick);
+.br
+
+.EE
+
+.IP "\fBunsigned gpioHardwareRevision(void)\fP"
+.IP "" 4
+Returns the hardware revision.
+
+.br
+
+.br
+If the hardware revision can not be found or is not a valid hexadecimal
+number the function returns 0.
+
+.br
+
+.br
+The hardware revision is the last 4 characters on the Revision line of
+/proc/cpuinfo.
+
+.br
+
+.br
+The revision number can be used to determine the assignment of gpios
+to pins.
+
+.br
+
+.br
+There are at least three types of board.
+
+.br
+
+.br
+Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
+
+.br
+
+.br
+Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
+gpios 28-31 on P5.
+
+.br
+
+.br
+Type 3 has a 40 pin connector rather than the 26 pin connector of
+the earlier boards. Gpios 0 to 27 are brought out to the connector.
+
+.br
+
+.br
+Type 1 boards have hardware revision numbers of 2 and 3.
+
+.br
+
+.br
+Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+
+.br
+
+.br
+Type 3 boards have hardware revision number 16.
+
+.br
+
+.br
+for "Revision : 0002" the function returns 2.
+.br
+for "Revision : 000f" the function returns 15.
+.br
+for "Revision : 000g" the function returns 0.
+
+.IP "\fBunsigned gpioVersion(void)\fP"
+.IP "" 4
+Returns the pigpio version.
+
+.IP "\fBint gpioCfgBufferSize(unsigned cfgMillis)\fP"
+.IP "" 4
+Configures pigpio to buffer cfgMillis milliseconds of gpio samples.
+
+.br
+
+.br
+
+.EX
+cfgMillis: 100-10000
+.br
+
+.EE
+
+.br
+
+.br
+The default setting is 120 milliseconds.
+
+.br
+
+.br
+The intention is to allow for bursts of data and protection against
+other processes hogging cpu time.
+
+.br
+
+.br
+I haven't seen a process locked out for more than 100 milliseconds.
+
+.br
+
+.br
+Making the buffer bigger uses a LOT of memory at the more frequent
+sampling rates as shown in the following table in MBs.
+
+.br
+
+.br
+
+.EX
+ buffer milliseconds
+.br
+ 120 250 500 1sec 2sec 4sec 8sec
+.br
+
+.br
+ 1 16 31 55 107 --- --- ---
+.br
+ 2 10 18 31 55 107 --- ---
+.br
+sample 4 8 12 18 31 55 107 ---
+.br
+ rate 5 8 10 14 24 45 87 ---
+.br
+ (us) 8 6 8 12 18 31 55 107
+.br
+ 10 6 8 10 14 24 45 87
+.br
+
+.EE
+
+.IP "\fBint gpioCfgClock(unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource)\fP"
+.IP "" 4
+Configures pigpio to use a particualar sample rate timed by a specified
+peripheral and clock source.
+
+.br
+
+.br
+
+.EX
+ cfgMicros: 1, 2, 4, 5, 8, 10
+.br
+cfgPeripheral: 0 (PWM), 1 (PCM)
+.br
+ cfgSource: 0 (OSC), 1 (PLLD)
+.br
+
+.EE
+
+.br
+
+.br
+The timings are provided by the specified peripheral (PWM or PCM)
+using the frequency source (OSC or PLLD).
+
+.br
+
+.br
+The default setting is 5 microseconds using the PCM peripheral
+with the PLLD source.
+
+.br
+
+.br
+The approximate CPU percentage used for each sample rate is:
+
+.br
+
+.br
+
+.EX
+sample cpu
+.br
+ rate %
+.br
+
+.br
+ 1 25
+.br
+ 2 16
+.br
+ 4 11
+.br
+ 5 10
+.br
+ 8 15
+.br
+ 10 14
+.br
+
+.EE
+
+.br
+
+.br
+A sample rate of 5 microseconds seeems to be the sweet spot.
+
+.IP "\fBint gpioCfgDMAchannel(unsigned DMAchannel)\fP"
+.IP "" 4
+Configures pigpio to use the specified DMA channel.
+
+.br
+
+.br
+
+.EX
+DMAchannel: 0-14
+.br
+
+.EE
+
+.br
+
+.br
+The default setting is to use channel 14.
+
+.IP "\fBint gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel)\fP"
+.IP "" 4
+Configures pigpio to use the specified DMA channels.
+
+.br
+
+.br
+
+.EX
+ primaryChannel: 0-14
+.br
+secondaryChannel: 0-6
+.br
+
+.EE
+
+.br
+
+.br
+The default setting is to use channel 14 for the primary channel and
+channel 5 for the secondary channel.
+
+.IP "\fBint gpioCfgPermissions(uint64_t updateMask)\fP"
+.IP "" 4
+Configures pigpio to only allow updates (writes or mode changes) for the
+gpios specified by the mask.
+
+.br
+
+.br
+
+.EX
+updateMask: bit (1<<n) is set for each gpio n which may be updated
+.br
+
+.EE
+
+.br
+
+.br
+The default setting depends upon the board revision (Type 1, 2, or 3).
+The user gpios are added to the mask. If the board revision is not
+recognised then gpios 0-31 are allowed.
+
+.br
+
+.br
+Unknown board PI_DEFAULT_UPDATE_MASK_R0 0xFFFFFFFF
+.br
+
+.br
+Type 1 board PI_DEFAULT_UPDATE_MASK_R1 0x03E6CF93
+.br
+
+.br
+Type 2 board PI_DEFAULT_UPDATE_MASK_R2 0xFBC6CF9C
+
+.br
+Type 3 board PI_DEFAULT_UPDATE_MASK_R3 0x0FFFFFFC
+
+.br
+
+.IP "\fBint gpioCfgSocketPort(unsigned port)\fP"
+.IP "" 4
+Configures pigpio to use the specified socket port.
+
+.br
+
+.br
+
+.EX
+port: 1024-32000
+.br
+
+.EE
+
+.br
+
+.br
+The default setting is to use port 8888.
+
+.IP "\fBint gpioCfgInterfaces(unsigned ifFlags)\fP"
+.IP "" 4
+Configures pigpio support of the fifo and socket interfaces.
+
+.br
+
+.br
+
+.EX
+ifFlags: 0-3
+.br
+
+.EE
+
+.br
+
+.br
+The default setting (0) is that both interfaces are enabled.
+
+.br
+
+.br
+Or in PI_DISABLE_FIFO_IF to disable the pipe interface.
+Or in PI_DISABLE_SOCK_IF to disable the socket interface.
+
+.IP "\fBint gpioCfgInternals(unsigned cfgWhat, int cfgVal)\fP"
+.IP "" 4
+Used to tune internal settings.
+
+.br
+
+.br
+
+.EX
+cfgWhat: see source code
+.br
+ cfgVal: see source code
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBint rawWaveAddSPI(rawSPI_t *spi, unsigned offset, unsigned spiSS, char *buf, unsigned spiTxBits, unsigned spiBitFirst, unsigned spiBitLast, unsigned spiBits)\fP"
+.IP "" 4
+This function adds a waveform representing SPI data to the
+existing waveform (if any).
+
+.br
+
+.br
+
+.EX
+ spi: a pointer to a spi object
+.br
+ offset: microseconds from the start of the waveform
+.br
+ spiSS: the slave select gpio
+.br
+ buf: the bits to transmit, most significant bit first
+.br
+ spiTxBits: the number of bits to write
+.br
+spiBitFirst: the first bit to read
+.br
+ spiBitLast: the last bit to read
+.br
+ spiBits: the number of bits to transfer
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBint rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses)\fP"
+.IP "" 4
+This function adds a number of pulses to the current waveform.
+
+.br
+
+.br
+
+.EX
+numPulses: the number of pulses
+.br
+ pulses: the array containing the pulses
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+The advantage of this function over gpioWaveAddGeneric is that it
+allows the setting of the flags field.
+
+.br
+
+.br
+The pulses are interleaved in time order within the existing waveform
+(if any).
+
+.br
+
+.br
+Merging allows the waveform to be built in parts, that is the settings
+for gpio#1 can be added, and then gpio#2 etc.
+
+.br
+
+.br
+If the added waveform is intended to start after or within the existing
+waveform then the first pulse should consist of a delay.
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBunsigned rawWaveCB(void)\fP"
+.IP "" 4
+Returns the number of the cb being currently output.
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP"
+.IP "" 4
+Return the Linux address of contol block cbNum.
+
+.br
+
+.br
+
+.EX
+cbNum: the cb of interest
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBuint32_t rawWaveGetOut(int pos)\fP"
+.IP "" 4
+Gets the wave output parameter stored at pos.
+
+.br
+
+.br
+
+.EX
+pos: the position of interest.
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBvoid rawWaveSetOut(int pos, uint32_t lVal)\fP"
+.IP "" 4
+Sets the wave output parameter stored at pos to value.
+
+.br
+
+.br
+
+.EX
+ pos: the position of interest
+.br
+lVal: the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBuint32_t rawWaveGetIn(int pos)\fP"
+.IP "" 4
+Gets the wave input value parameter stored at pos.
+
+.br
+
+.br
+
+.EX
+pos: the position of interest
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBvoid rawWaveSetIn(int pos, uint32_t lVal)\fP"
+.IP "" 4
+Sets the wave input value stored at pos to value.
+
+.br
+
+.br
+
+.EX
+ pos: the position of interest
+.br
+lVal: the value to write
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBint getBitInBytes(int bitPos, char *buf, int numBits)\fP"
+.IP "" 4
+Returns the value of the bit bitPos bits from the start of buf. Returns
+0 if bitPos is greater than or equal to numBits.
+
+.br
+
+.br
+
+.EX
+ bitPos: bit index from the start of buf
+.br
+ buf: array of bits
+.br
+numBits: number of valid bits in buf
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBvoid putBitInBytes(int bitPos, char *buf, int bit)\fP"
+.IP "" 4
+Sets the bit bitPos bits from the start of buf to bit.
+
+.br
+
+.br
+
+.EX
+bitPos: bit index from the start of buf
+.br
+ buf: array of bits
+.br
+ bit: 0-1, value to set
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBdouble time_time(void)\fP"
+.IP "" 4
+Return the current time in seconds since the Epoch.
+
+.IP "\fBvoid time_sleep(double seconds)\fP"
+.IP "" 4
+Delay execution for a given number of seconds
+
+.br
+
+.br
+
+.EX
+seconds: the number of seconds to sleep
+.br
+
+.EE
+
+.IP "\fBvoid rawDumpWave(void)\fP"
+.IP "" 4
+Used to print a readable version of the current waveform to stderr.
+
+.br
+
+.br
+Not intended for general use.
+
+.IP "\fBvoid rawDumpScript(unsigned script_id)\fP"
+.IP "" 4
+Used to print a readable version of a script to stderr.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, a script_id returned by \fBgpioStoreScript\fP
+.br
+
+.EE
+
+.br
+
+.br
+Not intended for general use.
+.SH PARAMETERS
+
+.br
+
+.br
+
+.IP "\fB*arg\fP" 0
+
+.br
+
+.br
+A pointer to a void object passed to a thread started by gpioStartThread.
+
+.br
+
+.br
+
+.IP "\fBbbBaud\fP" 0
+
+.br
+
+.br
+The baud rate used for the transmission and reception of bit banged
+serial data.
+
+.br
+
+.br
+
+.EX
+PI_WAVE_MIN_BAUD 100
+.br
+PI_WAVE_MAX_BAUD 250000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBbit\fP" 0
+
+.br
+
+.br
+A value of 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBbitPos\fP" 0
+
+.br
+
+.br
+A bit position within a byte or word. The least significant bit is
+position 0.
+
+.br
+
+.br
+
+.IP "\fBbits\fP" 0
+
+.br
+
+.br
+A value used to select gpios. If bit n of bits is set then gpio n is
+selected.
+
+.br
+
+.br
+A convenient way to set bit n is to or in (1<<n).
+
+.br
+
+.br
+e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23).
+
+.br
+
+.br
+
+.IP "\fB*buf\fP" 0
+
+.br
+
+.br
+A buffer to hold data being sent or being received.
+
+.br
+
+.br
+
+.IP "\fBbufSize\fP" 0
+
+.br
+
+.br
+The size in bytes of a buffer.
+
+.br
+
+.br
+
+.IP "\fBbVal\fP: 0-255 (Hex 0x0-0xFF, Octal 0-0377)" 0
+
+.br
+
+.br
+An 8-bit byte value.
+
+.br
+
+.br
+
+.IP "\fBcbNum\fP" 0
+
+.br
+
+.br
+A number identifying a DMA contol block.
+
+.br
+
+.br
+
+.IP "\fBcfgMicros\fP" 0
+
+.br
+
+.br
+The gpio sample rate in microseconds. The default is 5us, or 200 thousand
+samples per second.
+
+.br
+
+.br
+
+.IP "\fBcfgMillis\fP: 100-10000" 0
+
+.br
+
+.br
+The size of the sample buffer in milliseconds. Gnerally this should be
+left at the default of 120ms. If you expect intense bursts of signals it
+might be necessary to increase the buffer size.
+
+.br
+
+.br
+
+.IP "\fBcfgPeripheral\fP" 0
+
+.br
+
+.br
+One of the PWM or PCM peripherals used to pace DMA transfers for timing
+purposes.
+
+.br
+
+.br
+
+.IP "\fBcfgSource\fP" 0
+
+.br
+
+.br
+The clock source used for the timing of DMA transfers. May be the 19.2MHz
+crystal or the 500MHz PLL.
+
+.EX
+PI_CLOCK_OSC 0
+.br
+PI_CLOCK_PLLD 1
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBcfgVal\fP" 0
+
+.br
+
+.br
+A number specifying the value of a configuration item. See \fBcfgWhat\fP.
+
+.br
+
+.br
+
+.IP "\fBcfgWhat\fP" 0
+
+.br
+
+.br
+A number specifying a configuration item.
+
+.br
+
+.br
+562484977: print enhanced statistics at termination.
+.br
+984762879: set the initial debug level.
+
+.br
+
+.br
+
+.IP "\fBchar\fP" 0
+
+.br
+
+.br
+A single character, an 8 bit quantity able to store 0-255.
+
+.br
+
+.br
+
+.IP "\fBcount\fP" 0
+
+.br
+
+.br
+The number of bytes to be transferred in an I2C, SPI, or Serial
+command.
+
+.br
+
+.br
+
+.IP "\fBDMAchannel\fP: 0-14" 0
+
+.EX
+PI_MIN_DMA_CHANNEL 0
+.br
+PI_MAX_DMA_CHANNEL 14
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBdouble\fP" 0
+
+.br
+
+.br
+A floating point number.
+
+.br
+
+.br
+
+.IP "\fBdutycycle\fP: 0-range" 0
+
+.br
+
+.br
+A number representing the ratio of on time to off time for PWM.
+
+.br
+
+.br
+The number may vary between 0 and range (default 255) where
+0 is off and range is fully on.
+
+.br
+
+.br
+
+.IP "\fBf\fP" 0
+
+.br
+
+.br
+A function.
+
+.br
+
+.br
+
+.IP "\fBfrequency\fP: 0-" 0
+
+.br
+
+.br
+The number of times a gpio is swiched on and off per second. This
+can be set per gpio and may be as little as 5Hz or as much as
+40KHz. The gpio will be on for a proportion of the time as defined
+by its dutycycle.
+
+.br
+
+.br
+
+.IP "\fBgpio\fP" 0
+
+.br
+
+.br
+A Broadcom numbered gpio, in the range 0-53.
+
+.br
+
+.br
+
+.IP "\fBgpioAlertFunc_t\fP" 0
+
+.EX
+typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioAlertFuncEx_t\fP" 0
+
+.EX
+typedef void (*gpioAlertFuncEx_t)
+.br
+ (int gpio, int level, uint32_t tick, void *userdata);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioCfg*\fP" 0
+
+.br
+
+.br
+One of
+
+.br
+
+.br
+\fBgpioCfgBufferSize\fP
+.br
+\fBgpioCfgClock\fP
+.br
+\fBgpioCfgDMAchannel\fP
+.br
+\fBgpioCfgDMAchannels\fP
+.br
+\fBgpioCfgPermissions\fP
+.br
+\fBgpioCfgInterfaces\fP
+.br
+\fBgpioCfgInternals\fP
+.br
+\fBgpioCfgSocketPort\fP
+
+.br
+
+.br
+
+.IP "\fBgpioGetSamplesFunc_t\fP" 0
+
+.EX
+typedef void (*gpioGetSamplesFunc_t)
+.br
+ (const gpioSample_t *samples, int numSamples);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioGetSamplesFuncEx_t\fP" 0
+
+.EX
+typedef void (*gpioGetSamplesFuncEx_t)
+.br
+ (const gpioSample_t *samples, int numSamples, void *userdata);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioPulse_t\fP" 0
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint32_t gpioOn;
+.br
+ uint32_t gpioOff;
+.br
+ uint32_t usDelay;
+.br
+} gpioPulse_t;
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioSignalFunc_t\fP" 0
+
+.EX
+typedef void (*gpioSignalFunc_t) (int signum);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioSignalFuncEx_t\fP" 0
+
+.EX
+typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioThreadFunc_t\fP" 0
+
+.EX
+typedef void *(gpioThreadFunc_t) (void *);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioTimerFunc_t\fP" 0
+
+.EX
+typedef void (*gpioTimerFunc_t) (void);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioTimerFuncEx_t\fP" 0
+
+.EX
+typedef void (*gpioTimerFuncEx_t) (void *userdata);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioWaveAdd*\fP" 0
+
+.br
+
+.br
+One of
+
+.br
+
+.br
+\fBgpioWaveAddNew\fP
+.br
+\fBgpioWaveAddGeneric\fP
+.br
+\fBgpioWaveAddSerial\fP
+
+.br
+
+.br
+
+.IP "\fBhandle\fP: 0-" 0
+
+.br
+
+.br
+A number referencing an object opened by one of
+
+.br
+
+.br
+\fBi2cOpen\fP
+.br
+\fBgpioNotifyOpen\fP
+.br
+\fBserOpen\fP
+.br
+\fBspiOpen\fP
+
+.br
+
+.br
+
+.IP "\fBi2cAddr\fP: 0x08-0x77" 0
+
+.br
+
+.br
+The address of a device on the I2C bus (0x08 - 0x77)
+
+.br
+
+.br
+
+.IP "\fBi2cBus\fP: 0-1" 0
+
+.br
+
+.br
+An I2C bus, 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBi2cFlags\fP: 0" 0
+
+.br
+
+.br
+Flags which modify an I2C open command. None are currently defined.
+
+.br
+
+.br
+
+.IP "\fBi2cReg\fP: 0-255" 0
+
+.br
+
+.br
+A register of an I2C device.
+
+.br
+
+.br
+
+.IP "\fBifFlags\fP: 0-3" 0
+
+.EX
+PI_DISABLE_FIFO_IF 1
+.br
+PI_DISABLE_SOCK_IF 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBint\fP" 0
+
+.br
+
+.br
+A whole number, negative or positive.
+
+.br
+
+.br
+
+.IP "\fBlevel\fP" 0
+
+.br
+
+.br
+The level of a gpio. Low or High.
+
+.br
+
+.br
+
+.EX
+PI_OFF 0
+.br
+PI_ON 1
+.br
+
+.br
+PI_CLEAR 0
+.br
+PI_SET 1
+.br
+
+.br
+PI_LOW 0
+.br
+PI_HIGH 1
+.br
+
+.EE
+
+.br
+
+.br
+There is one exception. If a watchdog expires on a gpio the level will be
+reported as PI_TIMEOUT. See \fBgpioSetWatchdog\fP.
+
+.br
+
+.br
+
+.EX
+PI_TIMEOUT 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBlVal\fP: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)" 0
+
+.br
+
+.br
+A 32-bit word value.
+
+.br
+
+.br
+
+.IP "\fB*micros\fP" 0
+
+.br
+
+.br
+A value representing microseconds.
+
+.br
+
+.br
+
+.IP "\fBmicros\fP" 0
+
+.br
+
+.br
+A value representing microseconds.
+
+.br
+
+.br
+
+.IP "\fBmillis\fP" 0
+
+.br
+
+.br
+A value representing milliseconds.
+
+.br
+
+.br
+
+.IP "\fBmode\fP: 0-7" 0
+
+.br
+
+.br
+The operational mode of a gpio, normally INPUT or OUTPUT.
+
+.br
+
+.br
+
+.EX
+PI_INPUT 0
+.br
+PI_OUTPUT 1
+.br
+PI_ALT0 4
+.br
+PI_ALT1 5
+.br
+PI_ALT2 6
+.br
+PI_ALT3 7
+.br
+PI_ALT4 3
+.br
+PI_ALT5 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBnumBits\fP" 0
+
+.br
+
+.br
+The number of bits stored in a buffer.
+
+.br
+
+.br
+
+.IP "\fBnumChar\fP" 0
+
+.br
+
+.br
+The number of characters in a string (used when the string might contain
+null characters, which would normally terminate the string).
+
+.br
+
+.br
+
+.IP "\fBnumPar\fP: 0-10" 0
+
+.br
+
+.br
+The number of parameters passed to a script.
+
+.br
+
+.br
+
+.IP "\fBnumPulses\fP" 0
+
+.br
+
+.br
+The number of pulses to be added to a waveform.
+
+.br
+
+.br
+
+.IP "\fBoffset\fP" 0
+
+.br
+
+.br
+The associated data starts this number of microseconds from the start of
+tghe waveform.
+
+.br
+
+.br
+
+.IP "\fB*param\fP" 0
+
+.br
+
+.br
+An array of script parameters.
+
+.br
+
+.br
+
+.IP "\fBport\fP: 1024-32000" 0
+
+.br
+
+.br
+The port used to bind to the pigpio socket. Defaults to 8888.
+
+.br
+
+.br
+
+.IP "\fBpos\fP" 0
+
+.br
+
+.br
+The position of an item.
+
+.br
+
+.br
+
+.IP "\fBprimaryChannel\fP: 0-14" 0
+
+.br
+
+.br
+The DMA channel used to time the sampling of gpios and to time servo and
+PWM pulses.
+
+.br
+
+.br
+
+.IP "\fB*pth\fP" 0
+
+.br
+
+.br
+A thread identifier, returned by \fBgpioStartThread\fP.
+
+.br
+
+.br
+
+.IP "\fBpthread_t\fP" 0
+
+.br
+
+.br
+A thread identifier.
+
+.br
+
+.br
+
+.IP "\fBpud\fP: 0-2" 0
+
+.br
+
+.br
+The setting of the pull up/down resistor for a gpio, which may be off,
+pull-up, or pull-down.
+
+.EX
+PI_PUD_OFF 0
+.br
+PI_PUD_DOWN 1
+.br
+PI_PUD_UP 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBpulseLen\fP" 0
+
+.br
+
+.br
+1-50, the length of a trigger pulse in microseconds.
+
+.br
+
+.br
+
+.IP "\fB*pulses\fP" 0
+
+.br
+
+.br
+An array of pulsed to be added to a waveform.
+
+.br
+
+.br
+
+.IP "\fBpulsewidth\fP: 0, 500-2500" 0
+
+.EX
+PI_SERVO_OFF 0
+.br
+PI_MIN_SERVO_PULSEWIDTH 500
+.br
+PI_MAX_SERVO_PULSEWIDTH 2500
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBrange\fP: 25-40000" 0
+
+.EX
+PI_MIN_DUTYCYCLE_RANGE 25
+.br
+PI_MAX_DUTYCYCLE_RANGE 40000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBrawCbs_t\fP" 0
+
+.EX
+typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
+.br
+{
+.br
+ unsigned long info;
+.br
+ unsigned long src;
+.br
+ unsigned long dst;
+.br
+ unsigned long length;
+.br
+ unsigned long stride;
+.br
+ unsigned long next;
+.br
+ unsigned long pad[2];
+.br
+} rawCbs_t;
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBrawSPI_t\fP" 0
+
+.EX
+typedef struct
+.br
+{
+.br
+ int clk; // gpio for clock
+.br
+ int mosi; // gpio for MOSI
+.br
+ int miso; // gpio for MISO
+.br
+ int ss_pol; // slave select off state
+.br
+ int ss_us; // delay after slave select
+.br
+ int clk_pol; // clock off state
+.br
+ int clk_pha; // clock phase
+.br
+ int clk_us; // clock micros
+.br
+} rawSPI_t;
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBrawWave_t\fP" 0
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint32_t gpioOn;
+.br
+ uint32_t gpioOff;
+.br
+ uint32_t usDelay;
+.br
+ uint32_t flags;
+.br
+} rawWave_t;
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fB*rxBuf\fP" 0
+
+.br
+
+.br
+A pointer to a buffer to receive data.
+
+.br
+
+.br
+
+.IP "\fB*script\fP" 0
+
+.br
+
+.br
+A pointer to the text of a script.
+
+.br
+
+.br
+
+.IP "\fBscript_id\fP" 0
+
+.br
+
+.br
+An id of a stored script as returned by \fBgpioStoreScript\fP.
+
+.br
+
+.br
+
+.IP "\fBsecondaryChannel\fP: 0-6" 0
+
+.br
+
+.br
+The DMA channel used to time output waveforms.
+
+.br
+
+.br
+
+.IP "\fB*seconds\fP" 0
+
+.br
+
+.br
+A pointer to a uint32_t to store the second component of
+a returned time.
+
+.br
+
+.br
+
+.IP "\fBseconds\fP" 0
+
+.br
+
+.br
+The number of seconds.
+
+.br
+
+.br
+
+.IP "\fBserBaud\fP" 0
+
+.br
+
+.br
+The baud rate to use on the serial link.
+
+.br
+
+.br
+It must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
+4800, 9600, 19200, 38400, 57600, 115200, 230400.
+
+.br
+
+.br
+
+.IP "\fBserFlags\fP" 0
+
+.br
+
+.br
+Flags which modify a serial open command. None are currently defined.
+
+.br
+
+.br
+
+.IP "\fB*sertty\fP" 0
+
+.br
+
+.br
+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
+
+.br
+
+.br
+
+.IP "\fBsignum\fP: 0-63" 0
+
+.EX
+PI_MIN_SIGNUM 0
+.br
+PI_MAX_SIGNUM 63
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBsize_t\fP" 0
+
+.br
+
+.br
+A standard type used to indicate the size of an object in bytes.
+
+.br
+
+.br
+
+.IP "\fB*spi\fP" 0
+
+.br
+
+.br
+A pointer to a \fBrawSPI_t\fP structure.
+
+.br
+
+.br
+
+.IP "\fBspiBaud\fP" 0
+
+.br
+
+.br
+The speed in bits per second to use for the SPI device.
+
+.br
+
+.br
+
+.IP "\fBspiBitFirst\fP" 0
+
+.br
+
+.br
+Gpio reads are made from spiBitFirst to spiBitLast.
+
+.br
+
+.br
+
+.IP "\fBspiBitLast\fP" 0
+
+.br
+
+.br
+Gpio reads are made from spiBitFirst to spiBitLast.
+
+.br
+
+.br
+
+.IP "\fBspiBits\fP" 0
+
+.br
+
+.br
+The number of bits to transfer in a raw SPI transaction.
+
+.br
+
+.br
+
+.IP "\fBspiChan\fP" 0
+
+.br
+
+.br
+A SPI channel, 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBspiFlags\fP" 0
+
+.br
+
+.br
+Flags which modify a SPI open command. The two least significant bits
+define the SPI mode. The other bits are undefined.
+
+.br
+
+.br
+
+.IP "\fBspiSS\fP" 0
+
+.br
+
+.br
+The SPI slave select gpio in a raw SPI transaction.
+
+.br
+
+.br
+
+.IP "\fBspiTxBits\fP" 0
+
+.br
+
+.br
+The number of bits to transfer dring a raw SPI transaction
+
+.br
+
+.br
+
+.IP "\fB*str\fP" 0
+
+.br
+
+.br
+An array of characters.
+
+.br
+
+.br
+
+.IP "\fBtimeout\fP" 0
+
+.br
+
+.br
+A gpio watchdog timeout in milliseconds.
+
+.EX
+PI_MIN_WDOG_TIMEOUT 0
+.br
+PI_MAX_WDOG_TIMEOUT 60000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBtimer\fP" 0
+
+.EX
+PI_MIN_TIMER 0
+.br
+PI_MAX_TIMER 9
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBtimetype\fP" 0
+
+.EX
+PI_TIME_RELATIVE 0
+.br
+PI_TIME_ABSOLUTE 1
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fB*txBuf\fP" 0
+
+.br
+
+.br
+An array of bytes to transmit.
+
+.br
+
+.br
+
+.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0
+
+.br
+
+.br
+A 32-bit unsigned value.
+
+.br
+
+.br
+
+.IP "\fBuint64_t\fP: 0-(2^64)-1" 0
+
+.br
+
+.br
+A 64-bit unsigned value.
+
+.br
+
+.br
+
+.IP "\fBunsigned\fP" 0
+
+.br
+
+.br
+A whole number >= 0.
+
+.br
+
+.br
+
+.IP "\fBupdateMask\fP" 0
+
+.br
+
+.br
+A 64 bit mask indicating which gpios may be written to by the user.
+
+.br
+
+.br
+If gpio#n may be written then bit (1<<n) is set.
+
+.br
+
+.br
+
+.IP "\fBuser_gpio\fP" 0
+
+.br
+
+.br
+0-31, a Broadcom numbered gpio.
+
+.br
+
+.br
+
+.IP "\fB*userdata\fP" 0
+
+.br
+
+.br
+A pointer to arbitrary user data. This may be used to identify the instance.
+
+.br
+
+.br
+
+.IP "\fBvoid\fP" 0
+
+.br
+
+.br
+Denoting no parameter is required
+
+.br
+
+.br
+
+.IP "\fBwave_id\fP" 0
+
+.br
+
+.br
+A number representing a waveform created by \fBgpioWaveCreate\fP.
+
+.br
+
+.br
+
+.IP "\fBwave_mode\fP" 0
+
+.br
+
+.br
+The mode of waveform transmission, whether it is sent once or cycles
+repeatedly.
+
+.br
+
+.br
+
+.EX
+PI_WAVE_MODE_ONE_SHOT 0
+.br
+PI_WAVE_MODE_REPEAT 1
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0
+
+.br
+
+.br
+A 16-bit word value.
+
+.br
+
+.br
+.SH Socket Command Codes
+
+.EX
+
+.br
+#define PI_CMD_MODES 0
+.br
+#define PI_CMD_MODEG 1
+.br
+#define PI_CMD_PUD 2
+.br
+#define PI_CMD_READ 3
+.br
+#define PI_CMD_WRITE 4
+.br
+#define PI_CMD_PWM 5
+.br
+#define PI_CMD_PRS 6
+.br
+#define PI_CMD_PFS 7
+.br
+#define PI_CMD_SERVO 8
+.br
+#define PI_CMD_WDOG 9
+.br
+#define PI_CMD_BR1 10
+.br
+#define PI_CMD_BR2 11
+.br
+#define PI_CMD_BC1 12
+.br
+#define PI_CMD_BC2 13
+.br
+#define PI_CMD_BS1 14
+.br
+#define PI_CMD_BS2 15
+.br
+#define PI_CMD_TICK 16
+.br
+#define PI_CMD_HWVER 17
+.br
+#define PI_CMD_NO 18
+.br
+#define PI_CMD_NB 19
+.br
+#define PI_CMD_NP 20
+.br
+#define PI_CMD_NC 21
+.br
+#define PI_CMD_PRG 22
+.br
+#define PI_CMD_PFG 23
+.br
+#define PI_CMD_PRRG 24
+.br
+#define PI_CMD_HELP 25
+.br
+#define PI_CMD_PIGPV 26
+.br
+#define PI_CMD_WVCLR 27
+.br
+#define PI_CMD_WVAG 28
+.br
+#define PI_CMD_WVAS 29
+.br
+#define PI_CMD_WVGO 30
+.br
+#define PI_CMD_WVGOR 31
+.br
+#define PI_CMD_WVBSY 32
+.br
+#define PI_CMD_WVHLT 33
+.br
+#define PI_CMD_WVSM 34
+.br
+#define PI_CMD_WVSP 35
+.br
+#define PI_CMD_WVSC 36
+.br
+#define PI_CMD_TRIG 37
+.br
+#define PI_CMD_PROC 38
+.br
+#define PI_CMD_PROCD 39
+.br
+#define PI_CMD_PROCR 40
+.br
+#define PI_CMD_PROCS 41
+.br
+#define PI_CMD_SLRO 42
+.br
+#define PI_CMD_SLR 43
+.br
+#define PI_CMD_SLRC 44
+.br
+#define PI_CMD_PROCP 45
+.br
+#define PI_CMD_MICS 46
+.br
+#define PI_CMD_MILS 47
+.br
+#define PI_CMD_PARSE 48
+.br
+#define PI_CMD_WVCRE 49
+.br
+#define PI_CMD_WVDEL 50
+.br
+#define PI_CMD_WVTX 51
+.br
+#define PI_CMD_WVTXR 52
+.br
+#define PI_CMD_WVNEW 53
+.br
+
+.br
+#define PI_CMD_I2CO 54
+.br
+#define PI_CMD_I2CC 55
+.br
+#define PI_CMD_I2CRD 56
+.br
+#define PI_CMD_I2CWD 57
+.br
+#define PI_CMD_I2CWQ 58
+.br
+#define PI_CMD_I2CRS 59
+.br
+#define PI_CMD_I2CWS 60
+.br
+#define PI_CMD_I2CRB 61
+.br
+#define PI_CMD_I2CWB 62
+.br
+#define PI_CMD_I2CRW 63
+.br
+#define PI_CMD_I2CWW 64
+.br
+#define PI_CMD_I2CRK 65
+.br
+#define PI_CMD_I2CWK 66
+.br
+#define PI_CMD_I2CRI 67
+.br
+#define PI_CMD_I2CWI 68
+.br
+#define PI_CMD_I2CPC 69
+.br
+#define PI_CMD_I2CPK 70
+.br
+
+.br
+#define PI_CMD_SPIO 71
+.br
+#define PI_CMD_SPIC 72
+.br
+#define PI_CMD_SPIR 73
+.br
+#define PI_CMD_SPIW 74
+.br
+#define PI_CMD_SPIX 75
+.br
+
+.br
+#define PI_CMD_SERO 76
+.br
+#define PI_CMD_SERC 77
+.br
+#define PI_CMD_SERRB 78
+.br
+#define PI_CMD_SERWB 79
+.br
+#define PI_CMD_SERR 80
+.br
+#define PI_CMD_SERW 81
+.br
+#define PI_CMD_SERDA 82
+.br
+
+.br
+#define PI_CMD_NOIB 99
+.br
+
+.br
+
+.EE
+.SH Error Codes
+
+.EX
+
+.br
+#define PI_INIT_FAILED -1 // gpioInitialise failed
+.br
+#define PI_BAD_USER_GPIO -2 // gpio not 0-31
+.br
+#define PI_BAD_GPIO -3 // gpio not 0-53
+.br
+#define PI_BAD_MODE -4 // mode not 0-7
+.br
+#define PI_BAD_LEVEL -5 // level not 0-1
+.br
+#define PI_BAD_PUD -6 // pud not 0-2
+.br
+#define PI_BAD_PULSEWIDTH -7 // pulsewidth not 0 or 500-2500
+.br
+#define PI_BAD_DUTYCYCLE -8 // dutycycle outside set range
+.br
+#define PI_BAD_TIMER -9 // timer not 0-9
+.br
+#define PI_BAD_MS -10 // ms not 10-60000
+.br
+#define PI_BAD_TIMETYPE -11 // timetype not 0-1
+.br
+#define PI_BAD_SECONDS -12 // seconds < 0
+.br
+#define PI_BAD_MICROS -13 // micros not 0-999999
+.br
+#define PI_TIMER_FAILED -14 // gpioSetTimerFunc failed
+.br
+#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
+.br
+#define PI_NO_ALERT_FUNC -16 // DEPRECATED
+.br
+#define PI_BAD_CLK_PERIPH -17 // clock peripheral not 0-1
+.br
+#define PI_BAD_CLK_SOURCE -18 // clock source not 0-1
+.br
+#define PI_BAD_CLK_MICROS -19 // clock micros not 1, 2, 4, 5, 8, or 10
+.br
+#define PI_BAD_BUF_MILLIS -20 // buf millis not 100-10000
+.br
+#define PI_BAD_DUTYRANGE -21 // dutycycle range not 25-40000
+.br
+#define PI_BAD_DUTY_RANGE -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
+.br
+#define PI_BAD_SIGNUM -22 // signum not 0-63
+.br
+#define PI_BAD_PATHNAME -23 // can't open pathname
+.br
+#define PI_NO_HANDLE -24 // no handle available
+.br
+#define PI_BAD_HANDLE -25 // unknown handle
+.br
+#define PI_BAD_IF_FLAGS -26 // ifFlags > 3
+.br
+#define PI_BAD_CHANNEL -27 // DMA channel not 0-14
+.br
+#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-14
+.br
+#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000
+.br
+#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
+.br
+#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-6
+.br
+#define PI_NOT_INITIALISED -31 // function called before gpioInitialise
+.br
+#define PI_INITIALISED -32 // function called after gpioInitialise
+.br
+#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-1
+.br
+#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
+.br
+#define PI_BAD_WAVE_BAUD -35 // baud rate not 100-250000
+.br
+#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses
+.br
+#define PI_TOO_MANY_CHARS -37 // waveform has too many chars
+.br
+#define PI_NOT_SERIAL_GPIO -38 // no serial read in progress on gpio
+.br
+#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
+.br
+#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter
+.br
+#define PI_NOT_PERMITTED -41 // gpio operation not permitted
+.br
+#define PI_SOME_PERMITTED -42 // one or more gpios not permitted
+.br
+#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand
+.br
+#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand
+.br
+#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand
+.br
+#define PI_BAD_PULSELEN -46 // trigger pulse length > 50
+.br
+#define PI_BAD_SCRIPT -47 // invalid script
+.br
+#define PI_BAD_SCRIPT_ID -48 // unknown script id
+.br
+#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes
+.br
+#define PI_GPIO_IN_USE -50 // gpio already in use
+.br
+#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
+.br
+#define PI_BAD_PARAM_NUM -52 // script parameter must be 0-9
+.br
+#define PI_DUP_TAG -53 // script has duplicate tag
+.br
+#define PI_TOO_MANY_TAGS -54 // script has too many tags
+.br
+#define PI_BAD_SCRIPT_CMD -55 // illegal script command
+.br
+#define PI_BAD_VAR_NUM -56 // script variable must be 0-149
+.br
+#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts
+.br
+#define PI_NO_MEMORY -58 // can't allocate temporary memory
+.br
+#define PI_SOCK_READ_FAILED -59 // socket read failed
+.br
+#define PI_SOCK_WRIT_FAILED -60 // socket write failed
+.br
+#define PI_TOO_MANY_PARAM -61 // too many script parameters > 10
+.br
+#define PI_NOT_HALTED -62 // script already running or failed
+.br
+#define PI_BAD_TAG -63 // script has unresolved tag
+.br
+#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large)
+.br
+#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large)
+.br
+#define PI_BAD_WAVE_ID -66 // non existent wave id
+.br
+#define PI_TOO_MANY_CBS -67 // No more CBs for waveform
+.br
+#define PI_TOO_MANY_OOL -68 // No more OOL for waveform
+.br
+#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform
+.br
+#define PI_NO_WAVEFORM_ID -70 // no more waveforms
+.br
+#define PI_I2C_OPEN_FAILED -71 // can't open I2C device
+.br
+#define PI_SER_OPEN_FAILED -72 // can't open serial device
+.br
+#define PI_SPI_OPEN_FAILED -73 // can't open SPI device
+.br
+#define PI_BAD_I2C_BUS -74 // bad I2C bus
+.br
+#define PI_BAD_I2C_ADDR -75 // bad I2C address
+.br
+#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel
+.br
+#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags
+.br
+#define PI_BAD_SPI_SPEED -78 // bad SPI speed
+.br
+#define PI_BAD_SER_DEVICE -79 // bad serial device name
+.br
+#define PI_BAD_SER_SPEED -80 // bad serial baud rate
+.br
+#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter
+.br
+#define PI_I2C_WRITE_FAILED -82 // i2c write failed
+.br
+#define PI_I2C_READ_FAILED -83 // i2c read failed
+.br
+#define PI_BAD_SPI_COUNT -84 // bad SPI count
+.br
+#define PI_SER_WRITE_FAILED -85 // ser write failed
+.br
+#define PI_SER_READ_FAILED -86 // ser read failed
+.br
+#define PI_SER_READ_NO_DATA -87 // ser read no data available
+.br
+#define PI_UNKNOWN_COMMAND -88 // unknown command
+.br
+#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed
+.br
+#define PI_BAD_POINTER -90 // bad (NULL) pointer
+.br
+
+.br
+
+.EE
+.SH Defaults
+
+.EX
+
+.br
+#define PI_DEFAULT_BUFFER_MILLIS 120
+.br
+#define PI_DEFAULT_CLK_MICROS 5
+.br
+#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM
+.br
+#define PI_DEFAULT_CLK_SOURCE PI_CLOCK_PLLD
+.br
+#define PI_DEFAULT_IF_FLAGS 0
+.br
+#define PI_DEFAULT_DMA_CHANNEL 14
+.br
+#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14
+.br
+#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 5
+.br
+#define PI_DEFAULT_SOCKET_PORT 8888
+.br
+#define PI_DEFAULT_SOCKET_PORT_STR "8888"
+.br
+#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1"
+.br
+#define PI_DEFAULT_UPDATE_MASK_R0 0xFFFFFFFF
+.br
+#define PI_DEFAULT_UPDATE_MASK_R1 0x03E7CF93
+.br
+#define PI_DEFAULT_UPDATE_MASK_R2 0xFBC7CF9C
+.br
+#define PI_DEFAULT_UPDATE_MASK_R3 0x80400FFFFFFCLL
+.br
+
+.br
+
+.EE
+
+.SH SEE ALSO
+
+pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3)
+.SH AUTHOR
+
+joan@abyz.co.uk
diff --git a/pigpio.c b/pigpio.c
index 68e1451..0bd05f9 100644
--- a/pigpio.c
+++ b/pigpio.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
-/* pigpio version 16 */
+/* pigpio version 17 */
#include <stdio.h>
#include <string.h>
@@ -51,6 +51,7 @@ For more information, please refer to <http://unlicense.org/>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/socket.h>
+#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <linux/spi/spidev.h>
@@ -812,12 +813,6 @@ struct my_smbus_ioctl_data
union my_smbus_data *data;
};
-struct my_rdwr_ioctl_data
-{
- struct i2c_msg *msgs; /* pointers to msgs */
- uint32_t nmsgs; /* number of msgs */
-};
-
/* --------------------------------------------------------------- */
/* initialise once then preserve */
@@ -984,6 +979,28 @@ static int gpioNotifyOpenInBand(int fd);
/* ======================================================================= */
+static char * myTimeStamp()
+{
+ static struct timeval last;
+ static char buf[32];
+ struct timeval now;
+
+ struct tm tmp;
+
+ gettimeofday(&now, NULL);
+
+ if (now.tv_sec != last.tv_sec)
+ {
+ localtime_r(&now.tv_sec, &tmp);
+ strftime(buf, sizeof(buf), "%F %T", &tmp);
+ last.tv_sec = now.tv_sec;
+ }
+
+ return buf;
+}
+
+/* ----------------------------------------------------------------------- */
+
static int my_smbus_access(
int fd, char rw, uint8_t cmd, int size, union my_smbus_data *data)
{
@@ -997,6 +1014,8 @@ static int my_smbus_access(
return ioctl(fd, PI_I2C_SMBUS, &args);
}
+/* ----------------------------------------------------------------------- */
+
static char *myBuf2Str(unsigned count, char *buf)
{
static char str[64];
@@ -1014,6 +1033,8 @@ static char *myBuf2Str(unsigned count, char *buf)
return str;
}
+/* ----------------------------------------------------------------------- */
+
static void myGpioSleep(int seconds, int micros)
{
struct timespec ts, rem;
@@ -1045,28 +1066,6 @@ static uint32_t myGpioDelay(uint32_t micros)
/* ----------------------------------------------------------------------- */
-static char * myTimeStamp()
-{
- static struct timeval last;
- static char buf[32];
- struct timeval now;
-
- struct tm tmp;
-
- gettimeofday(&now, NULL);
-
- if (now.tv_sec != last.tv_sec)
- {
- localtime_r(&now.tv_sec, &tmp);
- strftime(buf, sizeof(buf), "%F %T", &tmp);
- last.tv_sec = now.tv_sec;
- }
-
- return buf;
-}
-
-/* ----------------------------------------------------------------------- */
-
static void myCreatePipe(char * name, int perm)
{
unlink(name);
@@ -1743,12 +1742,12 @@ static void myGpioSetServo(unsigned gpio, int oldVal, int newVal)
/* ======================================================================= */
-rawCbs_t * rawWaveCBAdr(int n)
+rawCbs_t * rawWaveCBAdr(int cbNum)
{
int page, slot;
- page = n/CBS_PER_OPAGE;
- slot = n%CBS_PER_OPAGE;
+ page = cbNum/CBS_PER_OPAGE;
+ slot = cbNum%CBS_PER_OPAGE;
return &dmaOVirt[page]->cb[slot];
}
@@ -1861,7 +1860,7 @@ static int errCBsOOL(int cb, int botOOL, int topOOL)
/* ----------------------------------------------------------------------- */
-static int wave2Cbs(unsigned mode)
+static int wave2Cbs(unsigned wave_mode)
{
int botCB=waveOutBotCB, botOOL=waveOutBotOOL, topOOL=waveOutTopOOL;
@@ -2000,7 +1999,7 @@ static int wave2Cbs(unsigned mode)
if (p != NULL)
{
- if (mode == PI_WAVE_MODE_ONE_SHOT)
+ if (wave_mode == PI_WAVE_MODE_ONE_SHOT)
p->next = 0;
else p->next = waveCbPOadr(repeatCB) | DMA_BUS_ADR;
}
@@ -2485,8 +2484,12 @@ int i2cReadBlockData(unsigned handle, unsigned reg, char *buf)
return PI_I2C_READ_FAILED;
else
{
- for (i=1; i<=data.block[0]; i++) buf[i-1] = data.block[i];
- return data.block[0];
+ if (data.block[0] <= PI_I2C_SMBUS_BLOCK_MAX)
+ {
+ for (i=0; i<data.block[0]; i++) buf[i] = data.block[i+1];
+ return data.block[0];
+ }
+ else return PI_I2C_READ_FAILED;
}
}
@@ -2558,12 +2561,17 @@ int i2cBlockProcessCall(
for (i=1; i<=count; i++) data.block[i] = buf[i-1];
data.block[0] = count;
if (my_smbus_access(
- i2cInfo[handle].fd, PI_I2C_SMBUS_WRITE, reg, PI_I2C_SMBUS_BLOCK_PROC_CALL, &data))
+ i2cInfo[handle].fd, PI_I2C_SMBUS_WRITE, reg,
+ PI_I2C_SMBUS_BLOCK_PROC_CALL, &data))
return PI_I2C_READ_FAILED;
else
{
- for (i=1; i<=data.block[0]; i++) buf[i-1] = data.block[i];
- return data.block[0];
+ if (data.block[0] <= PI_I2C_SMBUS_BLOCK_MAX)
+ {
+ for (i=0; i<data.block[0]; i++) buf[i] = data.block[i+1];
+ return data.block[0];
+ }
+ else return PI_I2C_READ_FAILED;
}
}
@@ -2604,8 +2612,12 @@ int i2cReadI2CBlockData(
return PI_I2C_READ_FAILED;
else
{
- for (i = 1; i <= data.block[0]; i++) buf[i-1] = data.block[i];
- return data.block[0];
+ if (data.block[0] <= PI_I2C_SMBUS_I2C_BLOCK_MAX)
+ {
+ for (i=0; i<data.block[0]; i++) buf[i] = data.block[i+1];
+ return data.block[0];
+ }
+ else return PI_I2C_READ_FAILED;
}
}
@@ -4122,11 +4134,10 @@ static void *pthScript(void *x)
s = x;
- s->run_state = PI_SCRIPT_HALTED;
-
- while (s->request != PI_SCRIPT_DELETE)
+ while ((volatile int)s->request != PI_SCRIPT_DELETE)
{
pthread_mutex_lock(&s->pthMutex);
+ s->run_state = PI_SCRIPT_HALTED;
pthread_cond_wait(&s->pthCond, &s->pthMutex);
pthread_mutex_unlock(&s->pthMutex);
@@ -4137,8 +4148,8 @@ static void *pthScript(void *x)
PC = 0;
SP = 0;
- while ((s->request == PI_SCRIPT_RUN ) &&
- (s->run_state == PI_SCRIPT_RUNNING))
+ while (((volatile int)s->request == PI_SCRIPT_RUN ) &&
+ (s->run_state == PI_SCRIPT_RUNNING))
{
instr = s->script.instr[PC];
@@ -4150,7 +4161,11 @@ static void *pthScript(void *x)
if (instr.opt[2] == CMD_VAR) instr.p[2] = s->script.var[p2o];
else if (instr.opt[2] == CMD_PAR) instr.p[2] = s->script.par[p2o];
-
+/*
+ fprintf(stderr, "PC=%d cmd=%d p1o=%d p1=%d p2o=%d p2=%d\n",
+ PC, instr.p[0], p1o, instr.p[1], p2o, instr.p[2]);
+ fflush(stderr);
+*/
if (instr.p[0] < 100)
{
if (instr.p[3])
@@ -4323,7 +4338,8 @@ static void *pthScript(void *x)
}
- if (s->request == PI_SCRIPT_HALT) s->run_state = PI_SCRIPT_HALTED;
+ if ((volatile int)s->request == PI_SCRIPT_HALT)
+ s->run_state = PI_SCRIPT_HALTED;
}
@@ -4462,11 +4478,15 @@ static void * pthFifoThread(void *x)
break;
case 6:
- if (res < 0) fprintf(outFifo, "%d\n", res);
- else if (res > 0)
+ fprintf(outFifo, "%d", res);
+ if (res > 0)
{
- fwrite(v, 1, res, outFifo);
+ for (i=0; i<res; i++)
+ {
+ fprintf(outFifo, " %d", v[i]);
+ }
}
+ fprintf(outFifo, "\n");
break;
case 7:
@@ -4499,10 +4519,15 @@ static void *pthSocketThreadHandler(void *fdC)
{
int sock = *(int*)fdC;
uint32_t p[10];
+ int opt;
char buf[CMD_MAX_EXTENSION];
free(fdC);
+ /* Disable the Nagle algorithm. */
+ opt = 1;
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(int));
+
while (1)
{
if (recv(sock, p, 16, MSG_WAITALL) != 16) break;
@@ -4544,6 +4569,10 @@ static void *pthSocketThreadHandler(void *fdC)
else
{
p[3] = gpioNotifyOpenInBand(sock);
+
+ /* Enable the Nagle algorithm. */
+ opt = 0;
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(int));
}
write(sock, p, 16);
@@ -5617,7 +5646,8 @@ int gpioInitialise(void)
if (i == 0) gpioMask = PI_DEFAULT_UPDATE_MASK_R0;
else if (i < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_R1;
- else gpioMask = PI_DEFAULT_UPDATE_MASK_R2;
+ else if (i < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_R2;
+ else gpioMask = PI_DEFAULT_UPDATE_MASK_R3;
gpioMaskSet = 1;
}
@@ -6191,11 +6221,12 @@ int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses)
/* ----------------------------------------------------------------------- */
-int gpioWaveAddSerial(unsigned gpio,
- unsigned bbBaud,
- unsigned offset,
- unsigned numChar,
- char *str)
+int gpioWaveAddSerial
+ (unsigned gpio,
+ unsigned bbBaud,
+ unsigned offset,
+ unsigned numChar,
+ char *str)
{
int i, b, p, lev, c, v;
@@ -6489,7 +6520,7 @@ int gpioWaveDelete(unsigned wave_id)
/* ----------------------------------------------------------------------- */
-int gpioWaveTxStart(unsigned mode)
+int gpioWaveTxStart(unsigned wave_mode)
{
/* This function is deprecated and will be removed. */
@@ -6497,12 +6528,12 @@ int gpioWaveTxStart(unsigned mode)
int cb, i;
- DBG(DBG_USER, "mode=%d", mode);
+ DBG(DBG_USER, "wave_mode=%d", wave_mode);
CHECK_INITED;
- if (mode > PI_WAVE_MODE_REPEAT)
- SOFT_ERROR(PI_BAD_WAVE_MODE, "bad wave mode (%d)", mode);
+ if (wave_mode > PI_WAVE_MODE_REPEAT)
+ SOFT_ERROR(PI_BAD_WAVE_MODE, "bad wave mode (%d)", wave_mode);
if (wfc[wfcur] == 0) return 0;
@@ -6523,7 +6554,7 @@ int gpioWaveTxStart(unsigned mode)
waveOutCount = 0;
- cb = wave2Cbs(mode);
+ cb = wave2Cbs(wave_mode);
if (gpioCfg.dbgLevel >= DBG_SLOW_TICK)
{
@@ -6539,21 +6570,21 @@ int gpioWaveTxStart(unsigned mode)
/* ----------------------------------------------------------------------- */
-int gpioWaveTxSend(unsigned wave_id, unsigned mode)
+int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)
{
rawCbs_t *p=NULL;
static int secondaryClockInited = 0;
- DBG(DBG_USER, "wave_id=%d mode=%d", wave_id, mode);
+ DBG(DBG_USER, "wave_id=%d wave_mode=%d", wave_id, wave_mode);
CHECK_INITED;
if (wave_id >= waveOutCount)
SOFT_ERROR(PI_BAD_WAVE_ID, "bad wave id (%d)", wave_id);
- if (mode > PI_WAVE_MODE_REPEAT)
- SOFT_ERROR(PI_BAD_WAVE_MODE, "bad wave mode (%d)", mode);
+ if (wave_mode > PI_WAVE_MODE_REPEAT)
+ SOFT_ERROR(PI_BAD_WAVE_MODE, "bad wave mode (%d)", wave_mode);
if (!secondaryClockInited)
{
@@ -6563,7 +6594,7 @@ int gpioWaveTxSend(unsigned wave_id, unsigned mode)
p = rawWaveCBAdr(waveInfo[wave_id].topCB);
- if (mode == PI_WAVE_MODE_ONE_SHOT) p->next = 0;
+ if (wave_mode == PI_WAVE_MODE_ONE_SHOT) p->next = 0;
else p->next = waveCbPOadr(waveInfo[wave_id].botCB+1) | DMA_BUS_ADR;
dmaOut[DMA_CS] = DMA_CHANNEL_RESET;
@@ -7358,7 +7389,7 @@ int gpioStoreScript(char *script)
if (status == 0)
{
s->request = PI_SCRIPT_HALT;
- s->run_state = PI_SCRIPT_HALTED;
+ s->run_state = PI_SCRIPT_INITING;
pthread_cond_init(&s->pthCond, NULL);
pthread_mutex_init(&s->pthMutex, NULL);
@@ -7519,7 +7550,8 @@ int gpioDeleteScript(unsigned script_id)
gpioStopThread(gpioScript[script_id].pthIdp);
- if (gpioScript[script_id].script.par) free(gpioScript[script_id].script.par);
+ if (gpioScript[script_id].script.par)
+ free(gpioScript[script_id].script.par);
gpioScript[script_id].script.par = NULL;
@@ -7949,8 +7981,6 @@ int gpioCfgInternals(unsigned cfgWhat, int cfgVal)
DBG(DBG_USER, "cfgWhat=%u, cfgVal=%d", cfgWhat, cfgVal);
- CHECK_NOT_INITED;
-
/*
133084774
207081315
diff --git a/pigpio.h b/pigpio.h
index dc62ca9..91ae30a 100644
--- a/pigpio.h
+++ b/pigpio.h
@@ -25,72 +25,83 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
-/*
-This version is for pigpio version 16
-*/
-
#ifndef PIGPIO_H
#define PIGPIO_H
#include <stdint.h>
#include <pthread.h>
-#define PIGPIO_VERSION 16
+#define PIGPIO_VERSION 17
+
+/*TEXT
+
+pigpio is a C library for the Raspberry which allows control of the gpios.
+
+*Features*
+
+o PWM on any of gpios 0-31
+
+o servo pulses on any of gpios 0-31
-/* INTRO
+o callbacks when any of gpios 0-31 change state
-pigpio is a C library for the Raspberry Pi which allows
-control of the gpios.
+o callbacks at timed intervals
-Its main features are:
+o reading/writing all of the gpios in a bank as one operation
+
+o individually setting gpio modes, reading and writing
+
+o notifications when any of gpios 0-31 change state
+
+o the construction of output waveforms with microsecond timing
+
+o rudimentary permission control over gpios
+
+o a simple interface to start and stop new threads
-o PWM on any of gpios 0-31
-o servo pulses on any of gpios 0-31
-o callbacks when any of gpios 0-31 change state
-o callbacks at timed intervals
-o reading/writing all of the gpios in a bank as one operation
-o individually setting gpio modes, reading and writing
-o notifications when any of gpios 0-31 change state
-o the construction of output waveforms with microsecond timing
-o rudimentary permission control over gpios
-o a simple interface to start and stop new threads
o I2C, SPI, and serial link wrappers
+o creating and running scripts
+
+*gpios*
+
ALL gpios are identified by their Broadcom number.
+*Credits*
+
The PWM and servo pulses are timed using the DMA and PWM peripherals.
-This use was inspired by Richard Hirst's servoblaster kernel module.
-See https://github.com/richardghirst/PiBits
-Tag rgh on the Raspberry Pi forums http://www.raspberrypi.org/phpBB3/
+This use was inspired by Richard Hirst's servoblaster kernel module.
-INTRO */
+[https://github.com/richardghirst/PiBits/tree/master/ServoBlaster]
-/* USAGE
-Usage
+*Usage*
Include <pigpio.h> in your source files.
-Assuming your source is in example.c use the following command to build
+Assuming your source is in prog.c use the following command to build and
+run the executable.
. .
-gcc -o example example.c -lpigpio -lpthread -lrt
+gcc -o prog prog.c -lpigpio -lpthread -lrt
+sudo ./prog
. .
-For examples see checklib.c, demolib.c, pigpio.c, pigpiod.c, pig2vcd.c,
-and pigs.c
+For examples of usage see the C programs within the pigpio archive file.
+
+*Notes*
All the functions which return an int return < 0 on error.
-If the library isn't initialised all but the gpioCfg*, gpioVersion,
-and gpioHardwareRevision functions will return error PI_NOT_INITIALISED.
+If the library isn't initialised all but the [*gpioCfg**], [*gpioVersion*],
+and [*gpioHardwareRevision*] functions will return PI_NOT_INITIALISED.
-If the library is initialised the gpioCfg* functions will
-return error PI_INITIALISED.
+If the library is initialised the [*gpioCfg**] functions will
+return PI_INITIALISED.
-USAGE */
+TEXT*/
-/* OVERVIEW
+/*OVERVIEW
ESSENTIAL
@@ -283,7 +294,7 @@ rawWaveSetIn Not intended for general use
rawDumpWave Not intended for general use
rawDumpScript Not intended for general use
-OVERVIEW */
+OVERVIEW*/
#define PI_INPFIFO "/dev/pigpio"
#define PI_OUTFIFO "/dev/pigout"
@@ -393,23 +404,202 @@ typedef void (*gpioGetSamplesFuncEx_t) (const gpioSample_t *samples,
typedef void *(gpioThreadFunc_t) (void *);
-/* FUNC */
+/* gpio: 0-53 */
+
+#define PI_MIN_GPIO 0
+#define PI_MAX_GPIO 53
+
+/* user_gpio: 0-31 */
+
+#define PI_MAX_USER_GPIO 31
+
+/* level: 0-1 */
+
+#define PI_OFF 0
+#define PI_ON 1
+
+#define PI_CLEAR 0
+#define PI_SET 1
+
+#define PI_LOW 0
+#define PI_HIGH 1
+
+/* level: only reported for gpio timeout, see gpioSetWatchdog */
+
+#define PI_TIMEOUT 2
+
+/* mode: 0-7 */
+
+#define PI_INPUT 0
+#define PI_OUTPUT 1
+#define PI_ALT0 4
+#define PI_ALT1 5
+#define PI_ALT2 6
+#define PI_ALT3 7
+#define PI_ALT4 3
+#define PI_ALT5 2
+
+/* pud: 0-2 */
+
+#define PI_PUD_OFF 0
+#define PI_PUD_DOWN 1
+#define PI_PUD_UP 2
+
+/* dutycycle: 0-range */
+
+#define PI_DEFAULT_DUTYCYCLE_RANGE 255
+
+/* range: 25-40000 */
+
+#define PI_MIN_DUTYCYCLE_RANGE 25
+#define PI_MAX_DUTYCYCLE_RANGE 40000
+
+/* pulsewidth: 0, 500-2500 */
+
+#define PI_SERVO_OFF 0
+#define PI_MIN_SERVO_PULSEWIDTH 500
+#define PI_MAX_SERVO_PULSEWIDTH 2500
+
+#define PI_NOTIFY_SLOTS 32
+
+#define PI_NTFY_FLAGS_WDOG (1 <<5)
+#define PI_NTFY_FLAGS_BIT(x) (((x)<<0)&31)
+
+#define PI_WAVE_BLOCKS 4
+#define PI_WAVE_MAX_PULSES (PI_WAVE_BLOCKS * 3000)
+#define PI_WAVE_MAX_CHARS (PI_WAVE_BLOCKS * 256)
+
+#define PI_WAVE_MIN_BAUD 100
+#define PI_WAVE_MAX_BAUD 250000
+
+#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
+
+#define PI_MAX_WAVES 512
+
+/* wave tx mode */
+
+#define PI_WAVE_MODE_ONE_SHOT 0
+#define PI_WAVE_MODE_REPEAT 1
+
+#define PI_I2C_SLOTS 32
+#define PI_SPI_SLOTS 4
+#define PI_SER_SLOTS 4
+
+
+#define PI_NUM_I2C_BUS 2
+#define PI_NUM_SPI_CHANNEL 2
+
+#define PI_MAX_I2C_DEVICE_COUNT 8192
+#define PI_MAX_SPI_DEVICE_COUNT 8192
+
+#define PI_MAX_PULSELEN 50
+
+/* timeout: 0-60000 */
+
+#define PI_MIN_WDOG_TIMEOUT 0
+#define PI_MAX_WDOG_TIMEOUT 60000
+
+/* timer: 0-9 */
+
+#define PI_MIN_TIMER 0
+#define PI_MAX_TIMER 9
+
+/* millis: 10-60000 */
+
+#define PI_MIN_MS 10
+#define PI_MAX_MS 60000
+
+#define PI_MAX_SCRIPTS 32
+
+#define PI_MAX_SCRIPT_TAGS 50
+#define PI_MAX_SCRIPT_VARS 150
+#define PI_MAX_SCRIPT_PARAMS 10
+
+/* script status */
+
+#define PI_SCRIPT_INITING 0
+#define PI_SCRIPT_HALTED 1
+#define PI_SCRIPT_RUNNING 2
+#define PI_SCRIPT_WAITING 3
+#define PI_SCRIPT_FAILED 4
+
+/* signum: 0-63 */
+
+#define PI_MIN_SIGNUM 0
+#define PI_MAX_SIGNUM 63
+
+/* timetype: 0-1 */
+
+#define PI_TIME_RELATIVE 0
+#define PI_TIME_ABSOLUTE 1
+
+#define PI_MAX_MICS_DELAY 1000000 /* 1 second */
+#define PI_MAX_MILS_DELAY 60000 /* 60 seconds */
+
+/* cfgMillis */
+
+#define PI_BUF_MILLIS_MIN 100
+#define PI_BUF_MILLIS_MAX 10000
+
+/* cfgMicros: 1, 2, 4, 5, 8, or 10 */
+
+/* cfgPeripheral: 0-1 */
+
+#define PI_CLOCK_PWM 0
+#define PI_CLOCK_PCM 1
+
+/* cfgSource: 0-1 */
+
+#define PI_CLOCK_OSC 0
+#define PI_CLOCK_PLLD 1
+
+/* DMA channel: 0-14 */
+
+#define PI_MIN_DMA_CHANNEL 0
+#define PI_MAX_DMA_CHANNEL 14
+
+#define PI_MAX_PRIMARY_CHANNEL 14
+#define PI_MAX_SECONDARY_CHANNEL 6
+
+/* port */
+
+#define PI_MIN_SOCKET_PORT 1024
+#define PI_MAX_SOCKET_PORT 32000
+
+
+/* ifFlags: */
+
+#define PI_DISABLE_FIFO_IF 1
+#define PI_DISABLE_SOCK_IF 2
+
+
+/*F*/
int gpioInitialise(void);
-/* DESC
+/*D
Initialises the library.
Call before using the other library functions.
Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
-The only exception is the optional gpioCfg* functions, see later.
-DESC */
+The only exception is the optional [*gpioCfg**] functions, see later.
+...
+if (gpioInitialise() < 0)
+{
+ // pigpio initialisation failed.
+}
+else
+{
+ // pigpio initialised okay.
+}
+...
+D*/
-/* FUNC */
+/*F*/
void gpioTerminate(void);
-/* DESC
+/*D
Terminates the library.
Returns nothing.
@@ -418,49 +608,46 @@ Call before program exit.
This function resets the DMA and PWM peripherals, releases memory, and
terminates any running threads.
-DESC */
+...
+gpioTerminate();
+...
+D*/
-/* FUNC */
+/*F*/
int gpioSetMode(unsigned gpio, unsigned mode);
-/* DESC
+/*D
Sets the gpio mode, typically input or output.
+. .
+gpio: 0-53
+mode: 0-7
+. .
+
Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE.
Arduino style: pinMode.
...
-gpioSetMode(17, PI_INPUT); // set gpio17 as input
-gpioSetMode(18, PI_OUTPUT); // set gpio18 as output
-gpioSetMode(22,PI_ALT0); // set gpio22 to alternative mode 0
-...
-DESC */
-
-/* gpio: 0-53 */
-
-#define PI_MIN_GPIO 0
-#define PI_MAX_GPIO 53
-
-/* mode: 0-7 */
+gpioSetMode(17, PI_INPUT); // Set gpio17 as input.
-#define PI_INPUT 0
-#define PI_OUTPUT 1
-#define PI_ALT0 4
-#define PI_ALT1 5
-#define PI_ALT2 6
-#define PI_ALT3 7
-#define PI_ALT4 3
-#define PI_ALT5 2
+gpioSetMode(18, PI_OUTPUT); // Set gpio18 as output.
+gpioSetMode(22,PI_ALT0); // Set gpio22 to alternative mode 0.
+...
+D*/
-/* FUNC */
+/*F*/
int gpioGetMode(unsigned gpio);
-/* DESC
+/*D
Gets the gpio mode.
+. .
+gpio: 0-53
+. .
+
Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
...
@@ -469,37 +656,40 @@ if (gpioGetMode(17) != PI_ALT0)
gpioSetMode(17, PI_ALT0); // set gpio17 to ALT0
}
...
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioSetPullUpDown(unsigned gpio, unsigned pud);
-/* DESC
+/*D
Sets or clears resistor pull ups or downs on the gpio.
+. .
+gpio: 0-53
+ pud: 0-2
+. .
+
Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD.
...
-gpioSetPullUpDown(17, PI_PUD_UP); // sets a pull-up on gpio17
-gpioSetPullUpDown(18, PI_PUD_DOWN); // sets a pull-down on gpio18
-gpioSetPullUpDown(23, PI_PUD_OFF); // clear pull-ups/downs on gpio23
-...
-DESC */
-
-/* pud: 0-2 */
+gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up.
-#define PI_PUD_OFF 0
-#define PI_PUD_DOWN 1
-#define PI_PUD_UP 2
+gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.
+gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs.
+...
+D*/
-/* FUNC */
+/*F*/
int gpioRead (unsigned gpio);
-/* DESC
+/*D
Reads the gpio level, on or off.
+. .
+gpio: 0-53
+. .
+
Returns the gpio level if OK, otherwise PI_BAD_GPIO.
Arduino style: digitalRead.
@@ -507,30 +697,19 @@ Arduino style: digitalRead.
...
printf("gpio24 is level %d\n", gpioRead(24));
...
-DESC */
-
-/* level: 0-1 */
-
-#define PI_OFF 0
-#define PI_ON 1
-
-#define PI_CLEAR 0
-#define PI_SET 1
-
-#define PI_LOW 0
-#define PI_HIGH 1
+D*/
-/* level: only reported for gpio timeout, see gpioSetWatchdogTimeout */
-#define PI_TIMEOUT 2
-
-
-
-/* FUNC */
+/*F*/
int gpioWrite(unsigned gpio, unsigned level);
-/* DESC
+/*D
Sets the gpio level, on or off.
+. .
+ gpio: 0-53
+level: 0,1
+. .
+
Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL.
If PWM or servo pulses are active on the gpio they are switched off.
@@ -538,18 +717,22 @@ If PWM or servo pulses are active on the gpio they are switched off.
Arduino style: digitalWrite
...
-gpioWrite(24, 1); // sets gpio24 high
+gpioWrite(24, 1); // Set gpio24 high.
...
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioPWM(unsigned user_gpio, unsigned dutycycle);
-/* DESC
+/*D
Starts PWM on the gpio, dutycycle between 0 (off) and range (fully on).
Range defaults to 255.
+. .
+user_gpio: 0-31
+dutycycle: 0-range
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE.
Arduino style: analogWrite
@@ -557,31 +740,30 @@ Arduino style: analogWrite
This and the servo functionality use the DMA and PWM or PCM peripherals
to control and schedule the pulse lengths and duty cycles.
-The gpioSetPWMrange funtion can change the default range of 255.
+The [*gpioSetPWMrange*] function may be used to change the default
+range of 255.
...
-gpioPWM(17, 255); // sets gpio17 full on
-gpioPWM(18, 128); // sets gpio18 half on
-gpioPWM(23, 0); // sets gpio23 full off
-...
-DESC */
-
-/* user_gpio: 0-31 */
-
-#define PI_MAX_USER_GPIO 31
-
-/* dutycycle: 0-range */
+gpioPWM(17, 255); // Sets gpio17 full on.
-#define PI_DEFAULT_DUTYCYCLE_RANGE 255
+gpioPWM(18, 128); // Sets gpio18 half on.
+gpioPWM(23, 0); // Sets gpio23 full off.
+...
+D*/
-/* FUNC */
+/*F*/
int gpioSetPWMrange(unsigned user_gpio, unsigned range);
-/* DESC
+/*D
Selects the dutycycle range to be used for the gpio. Subsequent calls
to gpioPWM will use a dutycycle between 0 (off) and range (fully on).
+. .
+user_gpio: 0-31
+ range: 25-40000
+. .
+
Returns the real range for the given gpio's frequency if OK,
otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE.
@@ -596,45 +778,58 @@ on for each frequency, is given in the following table.
800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000
. .
-The real value set by gpioPWM is
-
-(dutycycle * real range) / range.
+The real value set by [*gpioPWM*] is (dutycycle * real range) / range.
...
-gpioSetPWMrange(24, 2000); // now 2000 is fully on, 1000 is half on etc.
+gpioSetPWMrange(24, 2000); // Now 2000 is fully on
+ // 1000 is half on
+ // 500 is quarter on, etc.
...
-DESC */
-
-/* range: 25-40000 */
-
-#define PI_MIN_DUTYCYCLE_RANGE 25
-#define PI_MAX_DUTYCYCLE_RANGE 40000
+D*/
-
-/* FUNC */
+/*F*/
int gpioGetPWMrange(unsigned user_gpio);
-/* DESC
+/*D
Returns the dutycycle range used for the gpio if OK, otherwise
PI_BAD_USER_GPIO.
-DESC */
+. .
+user_gpio: 0-31
+. .
+
+...
+r = gpioGetPWMrange(23);
+...
+D*/
-/* FUNC */
+/*F*/
int gpioGetPWMrealRange(unsigned user_gpio);
-/* DESC
+/*D
Returns the real range used for the gpio if OK, otherwise
PI_BAD_USER_GPIO.
-DESC */
+. .
+user_gpio: 0-31
+. .
+...
+rr = gpioGetPWMrealRange(17);
+...
+D*/
-/* FUNC */
+
+/*F*/
int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency);
-/* DESC
+/*D
Sets the frequency in hertz to be used for the gpio.
+. .
+user_gpio: 0-31
+frequency: >=0
+. .
+
Returns the numerically closest frequency if OK, otherwise
PI_BAD_USER_GPIO.
@@ -671,25 +866,44 @@ sample
10: 4000 2000 1000 800 500 400 250 200 160
125 100 80 50 40 25 20 10 5
. .
-DESC */
+...
+gpioSetPWMfrequency(23, 0); // Set gpio23 to lowest frequency.
+
+gpioSetPWMfrequency(24, 500); // Set gpio24 to 500Hz.
+gpioSetPWMfrequency(25, 100000); // Set gpio25 to highest frequency.
+...
+D*/
-/* FUNC */
+
+/*F*/
int gpioGetPWMfrequency(unsigned user_gpio);
-/* DESC
+/*D
Returns the frequency (in hertz) used for the gpio if OK, otherwise
PI_BAD_USER_GPIO.
-DESC */
+. .
+user_gpio: 0-31
+. .
+
+...
+f = gpioGetPWMfrequency(23); // Get frequency used for gpio23.
+...
+D*/
-/* FUNC */
+/*F*/
int gpioServo(unsigned user_gpio, unsigned pulsewidth);
-/* DESC
+/*D
Starts servo pulses on the gpio, 0 (off), 500 (most anti-clockwise) to
2500 (most clockwise).
+. .
+ user_gpio: 0-31
+pulsewidth: 0, 500-2500
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH.
The range supported by servos varies and should probably be determined
@@ -699,10 +913,14 @@ to move beyond its limits.
The following causes an on pulse of 1500 microseconds duration to be
transmitted on gpio 17 at a rate of 50 times per second. This will
- command a servo connected to gpio 17 to rotate to its mid-point.
+command a servo connected to gpio 17 to rotate to its mid-point.
...
-gpioServo(17, 1500);
+gpioServo(17, 1000); // Move servo to safe position anti-clockwise.
+
+gpioServo(23, 1500); // Move servo to centre position.
+
+gpioServo(25, 2000); // Move servo to safe position clockwise.
...
OTHER UPDATE RATES:
@@ -715,37 +933,36 @@ PWM Hz 50 100 200 400 500
1E6/Hz 20000 10000 5000 2500 2000
. .
-Firstly set the desired PWM frequency using gpioSetPWMfrequency.
+Firstly set the desired PWM frequency using [*gpioSetPWMfrequency*].
-Then set the PWM range using gpioSetPWMrange to 1E6/frequency.
+Then set the PWM range using [*gpioSetPWMrange*] to 1E6/frequency.
Doing this allows you to use units of microseconds when setting
the servo pulse width.
-E.g. If you want to update a servo connected to gpio 25 at 400Hz
+E.g. If you want to update a servo connected to gpio25 at 400Hz
. .
gpioSetPWMfrequency(25, 400);
+
gpioSetPWMrange(25, 2500);
. .
Thereafter use the PWM command to move the servo,
e.g. gpioPWM(25, 1500) will set a 1500 us pulse.
-
-DESC */
-
-/* pulsewidth: 0, 500-2500 */
-
-#define PI_SERVO_OFF 0
-#define PI_MIN_SERVO_PULSEWIDTH 500
-#define PI_MAX_SERVO_PULSEWIDTH 2500
+D*/
-/* FUNC */
+/*F*/
int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f);
-/* DESC
+/*D
Registers a function to be called (a callback) when the specified
gpio changes state.
+. .
+user_gpio: 0-31
+ f: the callback function
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
One function may be registered per gpio.
@@ -772,7 +989,7 @@ rate 5 200,000
10 100,000
. .
-Level changes of length less than the sample rate may be missed.
+Level changes shorter than the sample rate may be missed.
The thread which calls the alert functions is triggered nominally
1000 times per second. The active alert functions will be called
@@ -781,7 +998,7 @@ i.e. The active alert functions will get all level changes but there
will be a latency.
The tick value is the time stamp of the sample in microseconds, see
-gpioTick for more details.
+[*gpioTick*] for more details.
...
void aFunction(int gpio, int level, uint32_t tick)
@@ -790,18 +1007,25 @@ void aFunction(int gpio, int level, uint32_t tick)
}
// call aFunction whenever gpio 4 changes state
+
gpioSetAlertFunc(4, aFunction);
...
-DESC */
+D*/
-/* FUNC */
+/*F*/
int gpioSetAlertFuncEx(
unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata);
-/* DESC
+/*D
Registers a function to be called (a callback) when the specified
gpio changes state.
+. .
+user_gpio: 0-31
+ f: the callback function
+ userdata: pointer to arbitrary user data
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
One function may be registered per gpio.
@@ -809,17 +1033,16 @@ One function may be registered per gpio.
The function is passed the gpio, the new level, the tick, and
the userdata pointer.
-Only one of gpioSetAlertFunc or gpioSetAlertFuncEx can be
+Only one of [*gpioSetAlertFunc*] or [*gpioSetAlertFuncEx*] can be
registered per gpio.
-See gpioSetAlertFunc for further details.
-DESC */
-
+See [*gpioSetAlertFunc*] for further details.
+D*/
-/* FUNC */
+/*F*/
int gpioNotifyOpen(void);
-/* DESC
+/*D
This function requests a free notification handle.
Returns a handle greater than or equal to zero if OK,
@@ -835,17 +1058,43 @@ from /dev/pigpio15.
Socket notifications are returned to the socket which requested the
handle.
-DESC */
-#define PI_NOTIFY_SLOTS 32
+...
+h = gpioNotifyOpen();
+
+if (h >= 0)
+{
+ sprintf(str, "/dev/pigpio%d", h);
+
+ fd = open(str, "r");
+ if (fd >= 0)
+ {
+ // Okay.
+ }
+ else
+ {
+ // Error.
+ }
+}
+else
+{
+ // Error.
+}
+...
+D*/
-/* FUNC */
+/*F*/
int gpioNotifyBegin(unsigned handle, uint32_t bits);
-/* DESC
+/*D
This function starts notifications on a previously opened handle.
+. .
+handle: >=0, as returned by [*gpioNotifyOpen*]
+ bits: a bit mask indicating the gpios of interest
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
The notification sends state changes for each gpio whose corresponding
@@ -875,69 +1124,95 @@ tick is the number of microseconds since system boot.
level indicates the level of each gpio.
...
-// start notifications for gpios 1, 4, 6, 7, 10
+// Start notifications for gpios 1, 4, 6, 7, 10.
+
+// 1
+// 0 76 4 1
// (1234 = 0x04D2 = 0b0000010011010010)
-gpioNotifyBegin(0, 1234);
+gpioNotifyBegin(h, 1234);
...
-DESC */
+D*/
-#define PI_NTFY_FLAGS_WDOG (1 <<5)
-#define PI_NTFY_FLAGS_BIT(x) (((x)<<0)&31)
-
-
-/* FUNC */
+/*F*/
int gpioNotifyPause(unsigned handle);
-/* DESC
+/*D
This function pauses notifications on a previously opened handle.
+. .
+handle: >=0, as returned by [*gpioNotifyOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
-Notifications for the handle are suspended until gpioNotifyBegin
+Notifications for the handle are suspended until [*gpioNotifyBegin*]
is called again.
-DESC */
+...
+gpioNotifyPause(h);
+...
+D*/
-/* FUNC */
+/*F*/
int gpioNotifyClose(unsigned handle);
-/* DESC
+/*D
This function stops notifications on a previously opened handle
and releases the handle for reuse.
+. .
+handle: >=0, as returned by [*gpioNotifyOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
-DESC */
+...
+gpioNotifyClose(h);
+...
+D*/
-/* FUNC */
+
+/*F*/
int gpioWaveClear(void);
-/* DESC
+/*D
This function clears all waveforms and any data added by calls to the
-gpioWaveAdd* functions.
+[*gpioWaveAdd**] functions.
Returns 0 if OK.
-DESC */
+...
+gpioWaveClear();
+...
+D*/
-/* FUNC */
+/*F*/
int gpioWaveAddNew(void);
-/* DESC
-This function starts a new empty waveform. You wouldn't normally need
-to call this function as it is automatically called after a waveform is
-created with the gpioWaveCreate function.
+/*D
+This function starts a new empty waveform.
+
+You wouldn't normally need to call this function as it is automatically
+called after a waveform is created with the [*gpioWaveCreate*] function.
Returns 0 if OK.
-DESC */
+...
+gpioWaveAddNew();
+...
+D*/
-/* FUNC */
+/*F*/
int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses);
-/* DESC
+/*D
This function adds a number of pulses to the current waveform.
+. .
+numPulses: the number of pulses
+ pulses: an array of pulses
+. .
+
Returns the new total number of pulses in the current waveform if OK,
otherwise PI_TOO_MANY_PULSES.
@@ -949,21 +1224,64 @@ for gpio#1 can be added, and then gpio#2 etc.
If the added waveform is intended to start after or within the existing
waveform then the first pulse should consist of a delay.
-DESC */
+...
+// Construct and send a 30 microsecond square wave.
+
+gpioSetMode(gpio, PI_OUTPUT);
+
+pulse[0].gpioOn = (1<<gpio);
+pulse[0].gpioOff = 0;
+pulse[0].usDelay = 15;
+
+pulse[1].gpioOn = 0;
+pulse[1].gpioOff = (1<<gpio);
+pulse[1].usDelay = 15;
+
+gpioWaveAddNew();
+
+gpioWaveAddGeneric(2, pulse);
+
+wave_id = gpioWaveCreate();
+
+if (wave_id >= 0)
+{
+ gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT);
+
+ // Transmit for 30 seconds.
+
+ sleep(30);
+
+ gpioWaveTxStop();
+}
+else
+{
+ // Wave create failed.
+}
+...
+D*/
-/* FUNC */
-int gpioWaveAddSerial(unsigned user_gpio,
- unsigned bbBaud,
- unsigned offset,
- unsigned numChar,
- char *str);
-/* DESC
+/*F*/
+int gpioWaveAddSerial
+ (unsigned user_gpio,
+ unsigned bbBaud,
+ unsigned offset,
+ unsigned numChar,
+ char *str);
+/*D
This function adds a waveform representing serial data to the
existing waveform (if any). The serial data starts offset microseconds
from the start of the waveform.
+. .
+user_gpio: 0-31
+ bbBaud: 100-250000
+ offset: 0-
+ numChar: 1-
+ str: an array of chars (which may contain nulls)
+. .
+
Returns the new total number of pulses in the current waveform if OK,
otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS,
PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
@@ -973,59 +1291,67 @@ stop bit.
It is legal to add serial data streams with different baud rates to
the same waveform.
-DESC */
-#define PI_WAVE_BLOCKS 4
-#define PI_WAVE_MAX_PULSES (PI_WAVE_BLOCKS * 3000)
-#define PI_WAVE_MAX_CHARS (PI_WAVE_BLOCKS * 256)
+...
+#define MSG_LEN 8
-#define PI_WAVE_MIN_BAUD 100
-#define PI_WAVE_MAX_BAUD 250000
+int i;
+char *str;
+char data[MSG_LEN];
-#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
+str = "Hello world!";
-#define PI_MAX_WAVES 512
+gpioWaveAddSerial(4, 9600, 0, strlen(str), str);
+
+for (i=0; i<MSG_LEN; i++) data[i] = i;
+
+// Data added is offset 1 second from the waveform start.
+gpioWaveAddSerial(4, 9600, 1000000, MSG_LEN, data);
+...
+D*/
-/* FUNC */
+/*F*/
int gpioWaveCreate(void);
-/* DESC
+/*D
This function creates a waveform from the data provided by the prior
-calls to the gpioWaveAdd* functions. Upon success a positive wave id
+calls to the [*gpioWaveAdd**] functions. Upon success a positive wave id
is returned.
-The data provided by the gpioWaveAdd* functions is consumed by this
+The data provided by the [*gpioWaveAdd**] functions is consumed by this
function.
As many waveforms may be created as there is space available. The
-wave id is passed to gpioWaveTxSend to specify the waveform to transmit.
+wave id is passed to [*gpioWaveTxSend*] to specify the waveform to transmit.
Normal usage would be
-Step 1. gpioWaveClear to clear all waveforms and added data.
+Step 1. [*gpioWaveClear*] to clear all waveforms and added data.
-Step 2. gpioWaveAdd* calls to supply the waveform data.
+Step 2. [*gpioWaveAdd**] calls to supply the waveform data.
-Step 3. gpioWaveCreate to create the waveform and get a unique id
+Step 3. [*gpioWaveCreate*] to create the waveform and get a unique id
Repeat steps 2 and 3 as needed.
-Step 4. gpioWaveTxSend with the id of the waveform to transmit.
+Step 4. [*gpioWaveTxSend*] with the id of the waveform to transmit.
A waveform comprises one of more pulses. Each pulse consists of a
-gpioPulse_t structure.
+[*gpioPulse_t*] structure.
+. .
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;
+. .
The fields specify
-1) the gpios to be switched on at the start of the pulse.
-2) the gpios to be switched off at the start of the pulse.
+1) the gpios to be switched on at the start of the pulse.
+2) the gpios to be switched off at the start of the pulse.
3) the delay in microseconds before the next pulse.
Any or all the fields can be zero. It doesn't make any sense to
@@ -1036,349 +1362,464 @@ specified delay between the pulse and the next.
Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int gpioWaveDelete(unsigned wave_id);
-/* DESC
+/*D
This function deletes all created waveforms with ids greater than or
equal to wave_id.
+. .
+wave_id: >=0, as returned by [*gpioWaveCreate*]
+. .
+
Wave ids are allocated in order, 0, 1, 2, etc.
Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
-DESC */
+D*/
-/* FUNC */
-int gpioWaveTxStart(unsigned mode); /* DEPRECATED */
-/* DESC
+/*F*/
+int gpioWaveTxStart(unsigned wave_mode); /* DEPRECATED */
+/*D
This function creates and then transmits a waveform. The mode
determines whether the waveform is sent once or cycles endlessly.
+. .
+wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
+. .
+
This function is deprecated and should no longer be used. Use
-gpioWaveCreate/gpioWaveTxSend instead.
+[*gpioWaveCreate*] and [*gpioWaveTxSend*] instead.
Returns the number of DMA control blocks in the waveform if OK,
otherwise PI_BAD_WAVE_MODE.
-DESC */
+D*/
-/* FUNC */
-int gpioWaveTxSend(unsigned wave_id, unsigned mode);
-/* DESC
+
+/*F*/
+int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode);
+/*D
This function transmits the waveform with id wave_id. The mode
determines whether the waveform is sent once or cycles endlessly.
+. .
+ wave_id: >=0, as returned by [*gpioWaveCreate*]
+wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
+. .
+
Returns the number of DMA control blocks in the waveform if OK,
otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
-DESC */
-
-#define PI_WAVE_MODE_ONE_SHOT 0
-#define PI_WAVE_MODE_REPEAT 1
-
+D*/
-/* FUNC */
+/*F*/
int gpioWaveTxBusy(void);
-/* DESC
+/*D
This function checks to see if a waveform is currently being
transmitted.
Returns 1 if a waveform is currently being transmitted, otherwise 0.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioWaveTxStop(void);
-/* DESC
+/*D
This function aborts the transmission of the current waveform.
Returns 0 if OK.
This function is intended to stop a waveform started in repeat mode.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioWaveGetMicros(void);
-/* DESC
+/*D
This function returns the length in microseconds of the current
waveform.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioWaveGetHighMicros(void);
-/* DESC
+/*D
This function returns the length in microseconds of the longest waveform
-created since gpioInitialise was called.
-DESC */
-
+created since [*gpioInitialise*] was called.
+D*/
-/* FUNC */
+/*F*/
int gpioWaveGetMaxMicros(void);
-/* DESC
+/*D
This function returns the maximum possible size of a waveform in
microseconds.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioWaveGetPulses(void);
-/* DESC
+/*D
This function returns the length in pulses of the current waveform.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioWaveGetHighPulses(void);
-/* DESC
+/*D
This function returns the length in pulses of the longest waveform
-created since gpioInitialise was called.
-DESC */
+created since [*gpioInitialise*] was called.
+D*/
-
-/* FUNC */
+/*F*/
int gpioWaveGetMaxPulses(void);
-/* DESC
+/*D
This function returns the maximum possible size of a waveform in pulses.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioWaveGetCbs(void);
-/* DESC
+/*D
This function returns the length in DMA control blocks of the current
waveform.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioWaveGetHighCbs(void);
-/* DESC
+/*D
This function returns the length in DMA control blocks of the longest
-waveform created since gpioInitialise was called.
-DESC */
+waveform created since [*gpioInitialise*] was called.
+D*/
-
-/* FUNC */
+/*F*/
int gpioWaveGetMaxCbs(void);
-/* DESC
+/*D
This function returns the maximum possible size of a waveform in DMA
control blocks.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud);
-/* DESC
-This function opens a gpio for reading serial data.
+/*D
+This function opens a gpio for bit bang reading of serial data.
+
+. .
+user_gpio: 0-31
+ bbBaud: 100-250000
+. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
or PI_GPIO_IN_USE.
The serial data is returned in a cyclic buffer and is read using
-gpioSerialRead().
+[*gpioSerialRead*].
It is the caller's responsibility to read data from the cyclic buffer
in a timely fashion.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioSerialRead(unsigned user_gpio, void *buf, size_t bufSize);
-/* DESC
+/*D
This function copies up to bufSize bytes of data read from the
-serial cyclic buffer to the buffer starting at buf.
+bit bang serial cyclic buffer to the buffer starting at buf.
+
+. .
+user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*]
+ buf: an array to receive the read bytes
+ bufSize: 0-
+. .
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
int gpioSerialReadClose(unsigned user_gpio);
-/* DESC
-This function closes a gpio for reading serial data.
-
-Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
-DESC */
-
-#define PI_I2C_SLOTS 32
-#define PI_SPI_SLOTS 4
-#define PI_SER_SLOTS 4
-
+/*D
+This function closes a gpio for bit bang reading of serial data.
-#define PI_NUM_I2C_BUS 2
-#define PI_NUM_SPI_CHANNEL 2
+. .
+user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*]
+. .
-#define PI_MAX_I2C_DEVICE_COUNT 1024
-#define PI_MAX_SPI_DEVICE_COUNT 1024
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
+D*/
-/* FUNC */
+/*F*/
int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags);
-/* DESC
+/*D
This returns a handle for the device at the address on the I2C bus.
+. .
+ i2cBus: 0-1
+ i2cAddr: 0x08-0x77
+i2cFlags: 0
+. .
+
No flags are currently defined. This parameter should be set to zero.
Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
-DESC */
+D*/
-/* FUNC */
+
+/*F*/
int i2cClose(unsigned handle);
-/* DESC
+/*D
This closes the I2C device associated with the handle.
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
-DESC */
+D*/
+
-/* FUNC */
+/*F*/
int i2cReadDevice(unsigned handle, char *buf, unsigned count);
-/* DESC
+/*D
This reads count bytes from the raw device into buf.
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+ buf: an array to receive the read data bytes
+ count: >0, the number of bytes to read
+. .
+
Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_READ_FAILED.
-DESC */
+D*/
+
-/* FUNC */
+/*F*/
int i2cWriteDevice(unsigned handle, char *buf, unsigned count);
-/* DESC
+/*D
This writes count bytes from buf to the raw device.
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+ buf: an array containing the data bytes to write
+ count: >0, the number of bytes to write
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
+D*/
+
-/* FUNC */
+/*F*/
int i2cWriteQuick(unsigned handle, unsigned bit);
-/* DESC
-Sends a single bit to the device associated with handle
-(smbus 2.0 5.5.1: Quick command).
+/*D
+This sends a single bit (in the Rd/Wr bit) to the device associated
+with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+ bit: 0-1, the value to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
-/* FUNC */
+Quick command. smbus 2.0 5.5.1
+D*/
+
+
+/*F*/
int i2cWriteByte(unsigned handle, unsigned bVal);
-/* DESC
-Sends a single byte to the device associated with handle
-(smbus 2.0 5.5.2: Send byte).
+/*D
+This sends a single byte to the device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+ bVal: 0-0xFF, the value to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
-/* FUNC */
+Send byte. smbus 2.0 5.5.2
+D*/
+
+
+/*F*/
int i2cReadByte(unsigned handle);
-/* DESC
-Reads a single byte from the device associated with handle
-(smbus 2.0 5.5.3: Receive byte).
+/*D
+This reads a single byte from the device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+. .
Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
or PI_I2C_READ_FAILED.
-DESC */
-/* FUNC */
-int i2cWriteByteData(unsigned handle, unsigned reg, unsigned bVal);
-/* DESC
-Writes a single byte to the specified register of the device
-associated with handle (smbus 2.0 5.5.4: Write byte).
+Receive byte. smbus 2.0 5.5.3
+D*/
+
+
+/*F*/
+int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal);
+/*D
+This writes a single byte to the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write
+ bVal: 0-0xFF, the value to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
-/* FUNC */
-int i2cWriteWordData(unsigned handle, unsigned reg, unsigned wVal);
-/* DESC
-Writes a single 16 bit word to the specified register of the device
-associated with handle (smbus 2.0 5.5.4: Write word).
+Write byte. smbus 2.0 5.5.4
+D*/
+
+
+/*F*/
+int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal);
+/*D
+This writes a single 16 bit word to the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write
+ wVal: 0-0xFFFF, the value to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
-/* FUNC */
-int i2cReadByteData(unsigned handle, unsigned reg);
-/* DESC
-Reads a single byte from the specified register of the device
-associated with handle (smbus 2.0 5.5.5: Read byte).
+Write word. smbus 2.0 5.5.4
+D*/
+
+
+/*F*/
+int i2cReadByteData(unsigned handle, unsigned i2cReg);
+/*D
+This reads a single byte from the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to read
+. .
Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-DESC */
-/* FUNC */
-int i2cReadWordData(unsigned handle, unsigned reg);
-/* DESC
-Reads a single 16 bit word from the specified register of the device
-associated with handle (smbus 2.0 5.5.5: Read word).
+Read byte. smbus 2.0 5.5.5
+D*/
+
+
+/*F*/
+int i2cReadWordData(unsigned handle, unsigned i2cReg);
+/*D
+This reads a single 16 bit word from the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to read
+. .
Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-DESC */
-/* FUNC */
-int i2cProcessCall(unsigned handle, unsigned reg, unsigned wVal);
-/* DESC
-Writes 16 bits of data to the specified register of the device
-associated with handle and and reads 16 bits of data in return
-(smbus 2.0 5.5.6: Process call).
+Read word. smbus 2.0 5.5.5
+D*/
+
+
+/*F*/
+int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal);
+/*D
+This writes 16 bits of data to the specified register of the device
+associated with handle and and reads 16 bits of data in return.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write/read
+ wVal: 0-0xFFFF, the value to write
+. .
Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-DESC */
-/* FUNC */
+Process call. smbus 2.0 5.5.6
+D*/
+
+
+/*F*/
int i2cWriteBlockData(
-unsigned handle, unsigned reg, char *buf, unsigned count);
-/* DESC
-Writes up to 32 bytes to the specified register of the device
-associated with handle (smbus 2.0 5.5.7: Block write).
+unsigned handle, unsigned i2cReg, char *buf, unsigned count);
+/*D
+This writes up to 32 bytes to the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write
+ buf: an array with the data to send
+ count: 1-32, the number of bytes to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
-/* FUNC */
-int i2cReadBlockData(unsigned handle, unsigned reg, char *buf);
-/* DESC
-Reads a block of up to 32 bytes from the specified register of
-the device associated with handle (smbus 2.0 5.5.7: Block read).
+Block write. smbus 2.0 5.5.7
+D*/
+
+
+/*F*/
+int i2cReadBlockData(unsigned handle, unsigned i2cReg, char *buf);
+/*D
+This reads a block of up to 32 bytes from the specified register of
+the device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to read
+ buf: an array to receive the read data
+. .
The amount of returned data is set by the device.
Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-DESC */
-/* FUNC */
+Block read. smbus 2.0 5.5.7
+D*/
+
+
+/*F*/
int i2cBlockProcessCall(
-unsigned handle, unsigned reg, char *buf, unsigned count);
-/* DESC
-Writes data bytes to the specified register of the device
+unsigned handle, unsigned i2cReg, char *buf, unsigned count);
+/*D
+This writes data bytes to the specified register of the device
associated with handle and reads a device specified number
-of bytes of data in return (smbus 2.0 5.5.8:
-Block write-block read).
+of bytes of data in return.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write/read
+ buf: an array with the data to send and to receive the read data
+ count: 1-32, the number of bytes to write
+. .
Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
@@ -1386,38 +1827,64 @@ PI_BAD_PARAM, or PI_I2C_READ_FAILED.
The smbus 2.0 documentation states that a minimum of 1 byte may be
sent and a minimum of 1 byte may be received. The total number of
bytes sent/received must be 32 or less.
-DESC */
+Block write-block read. smbus 2.0 5.5.8
+D*/
-/* FUNC */
+
+/*F*/
int i2cReadI2CBlockData(
-unsigned handle, unsigned reg, char *buf, unsigned count);
-/* DESC
-Reads count bytes from the specified register of the device
+unsigned handle, unsigned i2cReg, char *buf, unsigned count);
+/*D
+This reads count bytes from the specified register of the device
associated with handle . The count may be 1-32.
-Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to read
+ buf: an array to receive the read data
+ count: 1-32, the number of bytes to read
+. .
+
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int i2cWriteI2CBlockData(
-unsigned handle, unsigned reg, char *buf, unsigned count);
-/* DESC
-Writes data bytes to the specified register of the device
-associated with handle . 1-32 bytes may be written.
+unsigned handle, unsigned i2cReg, char *buf, unsigned count);
+/*D
+This writes 1 to 32 bytes to the specified register of the device
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2cOpen*]
+i2cReg: 0-255, the register to write
+ buf: the data to write
+ count: 1-32, the number of bytes to write
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
-DESC */
+D*/
-/* FUNC */
+
+/*F*/
int spiOpen(unsigned spiChan, unsigned spiBaud, unsigned spiFlags);
-/* DESC
+/*D
This function returns a handle for the SPI device on the channel
Data will be transferred at baud bits per second.
+. .
+ spiChan: 0-1
+ spiBaud: >1
+spiFlags: 0-3
+. .
+
+Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
+PI_BAD_SPI_SPEED, PI_BAD_FLAGS, or PI_SPI_OPEN_FAILED.
+
The least significant two bits of flags define the SPI mode.
. .
@@ -1429,138 +1896,206 @@ Mode POL PHA
. .
The other bits in flags should be set to zero.
+D*/
-Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
-PI_BAD_SPI_SPEED, PI_BAD_FLAGS, or PI_SPI_OPEN_FAILED.
-DESC */
-
-/* FUNC */
+/*F*/
int spiClose(unsigned handle);
-/* DESC
+/*D
This functions closes the SPI device identified by the handle.
+. .
+handle: >=0, as returned by a call to [*spiOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
-DESC */
+D*/
+
-/* FUNC */
+/*F*/
int spiRead(unsigned handle, char *buf, unsigned count);
-/* DESC
+/*D
This function reads count bytes of data from the SPI
device associated with the handle.
+. .
+handle: >=0, as returned by a call to [*spiOpen*]
+ buf: an array to receive the read data bytes
+ count: the number of bytes to read
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
PI_SPI_XFER_FAILED.
-DESC */
+D*/
-/* FUNC */
+
+/*F*/
int spiWrite(unsigned handle, char *buf, unsigned count);
-/* DESC
+/*D
This function writes count bytes of data from buf to the SPI
device associated with the handle.
+. .
+handle: >=0, as returned by a call to [*spiOpen*]
+ buf: the data bytes to write
+ count: the number of bytes to write
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
PI_SPI_XFER_FAILED.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int spiXfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count);
-/* DESC
+/*D
This function transfers count bytes of data from txBuf to the SPI
-device associated with the handle.
+device associated with the handle. Simultaneously count bytes of
+data are read from the device and placed in rxBuf.
+
+. .
+handle: >=0, as returned by a call to [*spiOpen*]
+ txBuf: the data bytes to write
+ rxBuf: the received data bytes
+ count: the number of bytes to transfer
+. .
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
PI_SPI_XFER_FAILED.
+D*/
-The data read from the device is written to rxBuf.
-DESC */
-/* FUNC */
-int serOpen(char *tty, unsigned serBaud, unsigned serFlags);
-/* DESC
-This function open the serial device named tty at baud
-bits per second.
+/*F*/
+int serOpen(char *sertty, unsigned serBaud, unsigned serFlags);
+/*D
+This function opens a serial device at a specified baud rate
+with specified flags.
-No flags are currently defined. This parameter should be set to zero.
+. .
+ sertty: the serial device to open, /dev/tty*
+ serBaud: the baud rate to use
+serFlags: 0
+. .
Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
PI_SER_OPEN_FAILED.
-DESC */
-/* FUNC */
+No flags are currently defined. This parameter should be set to zero.
+D*/
+
+
+/*F*/
int serClose(unsigned handle);
-/* DESC
+/*D
This function closes the serial device associated with handle.
+. .
+handle: >=0, as returned by a call to [*serOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int serWriteByte(unsigned handle, unsigned bVal);
-/* DESC
+/*D
This function writes bVal to the serial port associated with handle.
+. .
+handle: >=0, as returned by a call to [*serOpen*]
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_SER_WRITE_FAILED.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int serReadByte(unsigned handle);
-/* DESC
+/*D
This function reads a byte from the serial port associated with handle.
+. .
+handle: >=0, as returned by a call to [*serOpen*]
+. .
+
Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int serWrite(unsigned handle, char *buf, unsigned count);
-/* DESC
+/*D
This function writes count bytes from buf to the the serial port
associated with handle.
+. .
+handle: >=0, as returned by a call to [*serOpen*]
+ buf: the array of bytes to write
+ count: the number of bytes to write
+. .
+
Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_SER_WRITE_FAILED.
-DESC */
+D*/
+
-/* FUNC */
+/*F*/
int serRead(unsigned handle, char *buf, unsigned count);
-/* DESC
-This function reads count bytes from the the serial port
+/*D
+This function reads up count bytes from the the serial port
associated with handle and writes them to buf.
+. .
+handle: >=0, as returned by a call to serial_open
+ buf: an array to receive the read data
+ count: the maximum number of bytes to read
+. .
+
Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
-DESC */
+D*/
-/* FUNC */
+
+/*F*/
int serDataAvailable(unsigned handle);
-/* DESC
-This function returns the number of bytes of serial data available
-to be read from the serial device associated with handle.
+/*D
+This function returns the number of bytes available
+to be read from the device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*serOpen*]
+. .
Returns the number of bytes of data available (>=0) if OK,
otherwise PI_BAD_HANDLE.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level);
-/* DESC
+/*D
This function sends a trigger pulse to a gpio. The gpio is set to
level for pulseLen microseconds and then reset to not level.
+. .
+user_gpio: 0-31
+ pulseLen: 1-50
+ level: 0,1
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
or PI_BAD_PULSELEN.
-DESC */
-
-#define PI_MAX_PULSELEN 50
+D*/
-/* FUNC */
+/*F*/
int gpioSetWatchdog(unsigned user_gpio, unsigned timeout);
-/* DESC
+/*D
Sets a watchdog for a gpio.
+. .
+user_gpio: 0-31
+ timeout: 0-60000
+. .
+
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT.
The watchdog is nominally in milliseconds.
@@ -1587,24 +2122,22 @@ void aFunction(int gpio, int level, uint32_t tick)
gpioSetAlertFunc(4, aFunction);
// or approximately every 5 millis
-gpioSetWatchdogTimeout(4, 5);
+gpioSetWatchdog(4, 5);
...
+D*/
-DESC */
-
-/* timeout: 0-60000 */
-#define PI_MIN_WDOG_TIMEOUT 0
-#define PI_MAX_WDOG_TIMEOUT 60000
-
-
-
-/* FUNC */
+/*F*/
int gpioSetGetSamplesFunc(gpioGetSamplesFunc_t f, uint32_t bits);
-/* DESC
+/*D
Registers a function to be called (a callback) every millisecond
with the latest gpio samples.
+. .
+ f: the function to call
+bits: the gpios of interest
+. .
+
Returns 0 if OK.
The function is passed a pointer to the samples and the number
@@ -1620,35 +2153,45 @@ plus any active notifications.
e.g. if there are alerts for gpios 7, 8, and 9, notifications for gpios
8, 10, 23, 24, and bits is (1<<23)|(1<<17) then samples for gpios
7, 8, 9, 10, 17, 23, and 24 will be reported.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioSetGetSamplesFuncEx(
gpioGetSamplesFuncEx_t f, uint32_t bits, void *userdata);
-/* DESC
+/*D
Registers a function to be called (a callback) every millisecond
with the latest gpio samples.
+. .
+ f: the function to call
+ bits: the gpios of interest
+userdata: a pointer to arbitrary user data
+. .
+
Returns 0 if OK.
The function is passed a pointer to the samples, the number
of samples, and the userdata pointer.
-Only one of gpioGetSamplesFunc or gpioGetSamplesFuncEx can be
+Only one of [*gpioGetSamplesFunc*] or [*gpioGetSamplesFuncEx*] can be
registered.
-See gpioSetGetSamplesFunc for further details.
-DESC */
+See [*gpioSetGetSamplesFunc*] for further details.
+D*/
-
-/* FUNC */
+/*F*/
int gpioSetTimerFunc(unsigned timer, unsigned millis, gpioTimerFunc_t f);
-/* DESC
+/*D
Registers a function to be called (a callback) every millis milliseconds.
+. .
+ timer: 0-9
+millis: 10-60000
+ f: the function to call
+. .
+
Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
10 timers are supported numbered 0 to 9.
@@ -1666,49 +2209,49 @@ void bFunction(void)
// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);
...
-DESC */
-
-/* timer: 0-9 */
-
-#define PI_MIN_TIMER 0
-#define PI_MAX_TIMER 9
+D*/
-/* millis: 10-60000 */
-#define PI_MIN_MS 10
-#define PI_MAX_MS 60000
-
-
-
-/* FUNC */
+/*F*/
int gpioSetTimerFuncEx(
unsigned timer, unsigned millis, gpioTimerFuncEx_t f, void *userdata);
-/* DESC
+/*D
Registers a function to be called (a callback) every millis milliseconds.
+. .
+ timer: 0-9.
+ millis: 10-60000
+ f: the function to call
+userdata: a pointer to arbitrary user data
+. .
+
Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
The function is passed the userdata pointer.
-Only one of gpioSetTimerFunc or gpioSetTimerFuncEx can be
+Only one of [*gpioSetTimerFunc*] or [*gpioSetTimerFuncEx*] can be
registered per timer.
-See gpioSetTimerFunc for further details.
-DESC */
+See [*gpioSetTimerFunc*] for further details.
+D*/
-
-/* FUNC */
+/*F*/
pthread_t *gpioStartThread(gpioThreadFunc_t f, void *arg);
-/* DESC
+/*D
Starts a new thread of execution with f as the main routine.
+. .
+ f: the main function for the new thread
+arg: a pointer to arbitrary user data
+. .
+
Returns a pointer to pthread_t if OK, otherwise NULL.
The function is passed the single argument arg.
The thread can be cancelled by passing the pointer to pthread_t to
-gpioStopThread().
+[*gpioStopThread*].
...
#include <stdio.h>
@@ -1744,104 +2287,121 @@ int main(int argc, char *argv[])
gpioTerminate();
}
...
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
void gpioStopThread(pthread_t *pth);
-/* DESC
+/*D
Cancels the thread pointed at by pth.
+. .
+pth: a thread pointer returned by [*gpioStartThread*]
+. .
+
No value is returned.
-The thread to be stopped should have been started with gpioStartThread().
-DESC */
+The thread to be stopped should have been started with [*gpioStartThread*].
+D*/
-/* FUNC */
+/*F*/
int gpioStoreScript(char *script);
-/* DESC
+/*D
This function stores a null terminated script for later execution.
+. .
+script: the text of the script
+. .
+
The function returns a script id if the script is valid,
otherwise PI_BAD_SCRIPT.
-DESC */
+D*/
-#define PI_MAX_SCRIPTS 32
-#define PI_MAX_SCRIPT_TAGS 50
-#define PI_MAX_SCRIPT_VARS 150
-#define PI_MAX_SCRIPT_PARAMS 10
-
-
-/* FUNC */
-int gpioRunScript(unsigned script_id, unsigned numParam, uint32_t *param);
-/* DESC
+/*F*/
+int gpioRunScript(unsigned script_id, unsigned numPar, uint32_t *param);
+/*D
This function runs a stored script.
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+ numPar: 0-10, the number of parameters
+ param: an array of parameters
+. .
+
The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
PI_TOO_MANY_PARAM.
param is an array of up to 10 parameters which may be referenced in
-the script as param 0 to param 9.
-DESC */
-
+the script as p0 to p9.
+D*/
-/* FUNC */
+/*F*/
int gpioScriptStatus(unsigned script_id, uint32_t *param);
-/* DESC
+/*D
This function returns the run status of a stored script as well as
the current values of parameters 0 to 9.
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+ param: an array to hold the returned 10 parameters
+. .
+
The function returns greater than or equal to 0 if OK,
otherwise PI_BAD_SCRIPT_ID.
The run status may be
+. .
+PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED
+. .
The current value of script parameters 0 to 9 are returned in param.
-DESC */
-
-/* script status */
-
-#define PI_SCRIPT_HALTED 0
-#define PI_SCRIPT_RUNNING 1
-#define PI_SCRIPT_WAITING 2
-#define PI_SCRIPT_FAILED 3
+D*/
-
-/* FUNC */
+/*F*/
int gpioStopScript(unsigned script_id);
-/* DESC
+/*D
This function stops a running script.
-The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
-DESC */
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+. .
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+D*/
-/* FUNC */
+/*F*/
int gpioDeleteScript(unsigned script_id);
-/* DESC
+/*D
This function deletes a stored script.
-The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
-DESC */
+. .
+script_id: >=0, as returned by [*gpioStoreScript*]
+. .
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+D*/
-/* FUNC */
+/*F*/
int gpioSetSignalFunc(unsigned signum, gpioSignalFunc_t f);
-/* DESC
+/*D
Registers a function to be called (a callback) when a signal occurs.
+. .
+signum: 0-63
+ f: the callback function
+. .
+
Returns 0 if OK, otherwise PI_BAD_SIGNUM.
The function is passed the signal number.
@@ -1852,21 +2412,21 @@ The callback may be cancelled by passing NULL.
By default all signals are treated as fatal and cause the library
to call gpioTerminate and then exit.
-DESC */
-
-/* signum: 0-63 */
-
-#define PI_MIN_SIGNUM 0
-#define PI_MAX_SIGNUM 63
+D*/
-
-/* FUNC */
+/*F*/
int gpioSetSignalFuncEx(
unsigned signum, gpioSignalFuncEx_t f, void *userdata);
-/* DESC
+/*D
Registers a function to be called (a callback) when a signal occurs.
+. .
+ signum: 0-63
+ f: the callback function
+userdata: a pointer to arbitrary user data
+. .
+
Returns 0 if OK, otherwise PI_BAD_SIGNUM.
The function is passed the signal number and the userdata pointer.
@@ -1875,80 +2435,96 @@ Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be
registered per signal.
See gpioSetSignalFunc for further details.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
uint32_t gpioRead_Bits_0_31(void);
-/* DESC
+/*D
Returns the current level of gpios 0-31.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
uint32_t gpioRead_Bits_32_53(void);
-/* DESC
+/*D
Returns the current level of gpios 32-53.
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioWrite_Bits_0_31_Clear(uint32_t bits);
-/* DESC
+/*D
Clears gpios 0-31 if the corresponding bit in bits is set.
+. .
+bits: a bit mask of gpios to clear
+. .
+
Returns 0 if OK.
...
// To clear (set to 0) gpios 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );
...
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
int gpioWrite_Bits_32_53_Clear(uint32_t bits);
-/* DESC
+/*D
Clears gpios 32-53 if the corresponding bit (0-21) in bits is set.
-Returns 0 if OK.
-DESC */
+. .
+bits: a bit mask of gpios to clear
+. .
+Returns 0 if OK.
+D*/
-/* FUNC */
+/*F*/
int gpioWrite_Bits_0_31_Set(uint32_t bits);
-/* DESC
+/*D
Sets gpios 0-31 if the corresponding bit in bits is set.
-Returns 0 if OK.
-DESC */
+. .
+bits: a bit mask of gpios to set
+. .
+Returns 0 if OK.
+D*/
-/* FUNC */
+/*F*/
int gpioWrite_Bits_32_53_Set(uint32_t bits);
-/* DESC
+/*D
Sets gpios 32-53 if the corresponding bit (0-21) in bits is set.
+. .
+bits: a bit mask of gpios to set
+. .
+
Returns 0 if OK.
...
// To set (set to 1) gpios 32, 40, and 53
-gpioWrite_Bits_32_53_Set( (1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)) );
+gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));
...
-DESC */
+D*/
-/* FUNC */
+/*F*/
int gpioTime(unsigned timetype, int *seconds, int *micros);
-/* DESC
+/*D
Updates the seconds and micros variables with the current time.
+. .
+timetype: 0 (relative), 1 (absolute)
+ seconds: a pointer to an int to hold seconds
+ micros: a pointer to an int to hold microseconds
+. .
+
Returns 0 if OK, otherwise PI_BAD_TIMETYPE.
If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the
@@ -1964,21 +2540,21 @@ int secs, mics;
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago\n", secs, mics/1000);
...
-DESC */
-
-/* timetype: 0-1 */
-
-#define PI_TIME_RELATIVE 0
-#define PI_TIME_ABSOLUTE 1
+D*/
-
-/* FUNC */
+/*F*/
int gpioSleep(unsigned timetype, int seconds, int micros);
-/* DESC
+/*D
Sleeps for the number of seconds and microseconds specified by seconds
and micros.
+. .
+timetype: 0 (relative), 1 (absolute)
+ seconds: seconds to sleep
+ micros: microseconds to sleep
+. .
+
Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS,
or PI_BAD_MICROS.
@@ -1990,33 +2566,36 @@ If timetype is PI_TIME_RELATIVE the sleep is for the specified number
of seconds and microseconds. System clock changes do not effect the
sleep length.
-For short delays (say, 50 microseonds or less) use gpioDelayMicroseconds.
+For short delays (say, 50 microseonds or less) use [*gpioDelay*].
...
gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds
-gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 1/10th of a second
+gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds
gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute
...
-DESC */
+D*/
-
-/* FUNC */
+/*F*/
uint32_t gpioDelay(uint32_t micros);
-/* DESC
+/*D
Delays for at least the number of microseconds specified by micros.
+. .
+micros: the number of microseconds to sleep
+. .
+
Returns the actual length of the delay in microseconds.
-DESC */
-#define PI_MAX_MICS_DELAY 1000000 /* 1 second */
-#define PI_MAX_MILS_DELAY 60000 /* 60 seconds */
+Delays of 50 microseconds or less use busy waits.
+D*/
-/* FUNC */
+
+/*F*/
uint32_t gpioTick(void);
-/* DESC
+/*D
Returns the current system tick.
Tick is the number of microseconds since system boot.
@@ -2042,13 +2621,12 @@ diffTick = endTick - startTick;
printf("some processing took %d microseconds\n", diffTick);
...
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
unsigned gpioHardwareRevision(void);
-/* DESC
+/*D
Returns the hardware revision.
If the hardware revision can not be found or is not a valid hexadecimal
@@ -2060,36 +2638,43 @@ The hardware revision is the last 4 characters on the Revision line of
The revision number can be used to determine the assignment of gpios
to pins.
-There are at least two types of board.
+There are at least three types of board.
Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
gpios 28-31 on P5.
+Type 3 has a 40 pin connector rather than the 26 pin connector of
+the earlier boards. Gpios 0 to 27 are brought out to the connector.
+
Type 1 boards have hardware revision numbers of 2 and 3.
Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+Type 3 boards have hardware revision number 16.
+
for "Revision : 0002" the function returns 2.
for "Revision : 000f" the function returns 15.
for "Revision : 000g" the function returns 0.
-DESC */
-
+D*/
-/* FUNC */
+/*F*/
unsigned gpioVersion(void);
-/* DESC
+/*D
Returns the pigpio version.
-DESC */
+D*/
+/*F*/
+int gpioCfgBufferSize(unsigned cfgMillis);
+/*D
+Configures pigpio to buffer cfgMillis milliseconds of gpio samples.
-/* FUNC */
-int gpioCfgBufferSize(unsigned millis);
-/* DESC
-Configures pigpio to buffer millis milliseconds of gpio samples.
+. .
+cfgMillis: 100-10000
+. .
The default setting is 120 milliseconds.
@@ -2112,21 +2697,21 @@ sample 4 8 12 18 31 55 107 ---
(us) 8 6 8 12 18 31 55 107
10 6 8 10 14 24 45 87
. .
-DESC */
-
-/* millis */
-
-#define PI_BUF_MILLIS_MIN 100
-#define PI_BUF_MILLIS_MAX 10000
+D*/
-
-/* FUNC */
+/*F*/
int gpioCfgClock(
- unsigned micros, unsigned peripheral, unsigned source);
-/* DESC
-Configures pigpio to use a sample rate of micros microseconds,
-permitted values are 1, 2, 4, 5, 8 and 10.
+ unsigned cfgMicros, unsigned cfgPeripheral, unsigned cfgSource);
+/*D
+Configures pigpio to use a particualar sample rate timed by a specified
+peripheral and clock source.
+
+. .
+ cfgMicros: 1, 2, 4, 5, 8, 10
+cfgPeripheral: 0 (PWM), 1 (PCM)
+ cfgSource: 0 (OSC), 1 (PLLD)
+. .
The timings are provided by the specified peripheral (PWM or PCM)
using the frequency source (OSC or PLLD).
@@ -2149,116 +2734,103 @@ sample cpu
. .
A sample rate of 5 microseconds seeems to be the sweet spot.
-DESC */
-
-/* micros: 1, 2, 4, 5, 8, or 10 */
-
-/* peripheral: 0-1 */
-
-#define PI_CLOCK_PWM 0
-#define PI_CLOCK_PCM 1
+D*/
-/* source: 0-1 */
-#define PI_CLOCK_OSC 0
-#define PI_CLOCK_PLLD 1
-
-
-
-/* FUNC */
+/*F*/
int gpioCfgDMAchannel(unsigned DMAchannel); /* DEPRECATED */
-/* DESC
+/*D
Configures pigpio to use the specified DMA channel.
-The default setting is to use channel 14.
-DESC */
-
-/* DMA channel: 0-14 */
-
-#define PI_MIN_DMA_CHANNEL 0
-#define PI_MAX_DMA_CHANNEL 14
+. .
+DMAchannel: 0-14
+. .
+The default setting is to use channel 14.
+D*/
-/* FUNC */
+/*F*/
int gpioCfgDMAchannels(
unsigned primaryChannel, unsigned secondaryChannel);
-/* DESC
+/*D
Configures pigpio to use the specified DMA channels.
+. .
+ primaryChannel: 0-14
+secondaryChannel: 0-6
+. .
+
The default setting is to use channel 14 for the primary channel and
channel 5 for the secondary channel.
-DESC */
-
-#define PI_MAX_PRIMARY_CHANNEL 14
-#define PI_MAX_SECONDARY_CHANNEL 6
-
+D*/
-/* FUNC */
+/*F*/
int gpioCfgPermissions(uint64_t updateMask);
-/* DESC
+/*D
Configures pigpio to only allow updates (writes or mode changes) for the
gpios specified by the mask.
-The default setting depends upon the board revision (Type 1 or Type 2).
-The user gpios are added to the mask. If the board revision is not
-recognised then the mask is formed by or'ing the bits for the two
-board revisions.
-
-Unknown board
. .
-PI_DEFAULT_UPDATE_MASK_R0 0xFBE6CF9F
+updateMask: bit (1<<n) is set for each gpio n which may be updated
. .
-Type 1 board
-. .
-PI_DEFAULT_UPDATE_MASK_R1 0x03E6CF93
-. .
-Type 2 board
-. .
-PI_DEFAULT_UPDATE_MASK_R2 0xFBC6CF9C
-. .
-DESC */
+The default setting depends upon the board revision (Type 1, 2, or 3).
+The user gpios are added to the mask. If the board revision is not
+recognised then gpios 0-31 are allowed.
+
+Unknown board @ PI_DEFAULT_UPDATE_MASK_R0 @ 0xFFFFFFFF
+Type 1 board @ PI_DEFAULT_UPDATE_MASK_R1 @ 0x03E6CF93
+Type 2 board @ PI_DEFAULT_UPDATE_MASK_R2 @ 0xFBC6CF9C
+Type 3 board @ PI_DEFAULT_UPDATE_MASK_R3 @ 0x0FFFFFFC
+D*/
-/* FUNC */
+/*F*/
int gpioCfgSocketPort(unsigned port);
-/* DESC
+/*D
Configures pigpio to use the specified socket port.
-The default setting is to use port 8888.
-DESC */
-
-/* port: 1024-9999 */
-
-#define PI_MIN_SOCKET_PORT 1024
-#define PI_MAX_SOCKET_PORT 32000
+. .
+port: 1024-32000
+. .
+The default setting is to use port 8888.
+D*/
-/* FUNC */
+/*F*/
int gpioCfgInterfaces(unsigned ifFlags);
-/* DESC
+/*D
Configures pigpio support of the fifo and socket interfaces.
-The default setting is that both interfaces are enabled.
-DESC */
+. .
+ifFlags: 0-3
+. .
+
+The default setting (0) is that both interfaces are enabled.
-/* ifFlags: */
+Or in PI_DISABLE_FIFO_IF to disable the pipe interface.
+Or in PI_DISABLE_SOCK_IF to disable the socket interface.
+D*/
-#define PI_DISABLE_FIFO_IF 1
-#define PI_DISABLE_SOCK_IF 2
-/* FUNC */
+/*F*/
int gpioCfgInternals(unsigned cfgWhat, int cfgVal);
-/* DESC
+/*D
Used to tune internal settings.
+. .
+cfgWhat: see source code
+ cfgVal: see source code
+. .
+
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+
+/*F*/
int rawWaveAddSPI(
rawSPI_t *spi,
unsigned offset,
@@ -2268,28 +2840,37 @@ int rawWaveAddSPI(
unsigned spiBitFirst,
unsigned spiBitLast,
unsigned spiBits);
-/* DESC
+/*D
This function adds a waveform representing SPI data to the
existing waveform (if any).
-The SPI data starts offset microseconds from the start of the
-waveform. spiSS is the slave select gpio. spiBits bits
-are transferred. spiTxBits are transmitted starting at the
-first bit. The bits to transmit are read, most significant bit
-first, from buf. Gpio reads are made from spiBitFirst to
-spiBitLast.
+. .
+ spi: a pointer to a spi object
+ offset: microseconds from the start of the waveform
+ spiSS: the slave select gpio
+ buf: the bits to transmit, most significant bit first
+ spiTxBits: the number of bits to write
+spiBitFirst: the first bit to read
+ spiBitLast: the last bit to read
+ spiBits: the number of bits to transfer
+. .
Returns the new total number of pulses in the current waveform if OK,
otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int rawWaveAddGeneric(unsigned numPulses, rawWave_t *pulses);
-/* DESC
+/*D
This function adds a number of pulses to the current waveform.
+. .
+numPulses: the number of pulses
+ pulses: the array containing the pulses
+. .
+
Returns the new total number of pulses in the current waveform if OK,
otherwise PI_TOO_MANY_PULSES.
@@ -2306,129 +2887,178 @@ If the added waveform is intended to start after or within the existing
waveform then the first pulse should consist of a delay.
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
unsigned rawWaveCB(void);
-/* DESC
+/*D
Returns the number of the cb being currently output.
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
-rawCbs_t *rawWaveCBAdr(int n);
-/* DESC
-Return the Linux address of contol block n.
+/*F*/
+rawCbs_t *rawWaveCBAdr(int cbNum);
+/*D
+Return the Linux address of contol block cbNum.
+
+. .
+cbNum: the cb of interest
+. .
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
uint32_t rawWaveGetOut(int pos);
-/* DESC
+/*D
Gets the wave output parameter stored at pos.
+. .
+pos: the position of interest.
+. .
+
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
-void rawWaveSetOut(int pos, uint32_t value);
-/* DESC
+/*F*/
+void rawWaveSetOut(int pos, uint32_t lVal);
+/*D
Sets the wave output parameter stored at pos to value.
+. .
+ pos: the position of interest
+lVal: the value to write
+. .
+
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
uint32_t rawWaveGetIn(int pos);
-/* DESC
+/*D
Gets the wave input value parameter stored at pos.
+. .
+pos: the position of interest
+. .
+
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
-void rawWaveSetIn(int pos, uint32_t value);
-/* DESC
+/*F*/
+void rawWaveSetIn(int pos, uint32_t lVal);
+/*D
Sets the wave input value stored at pos to value.
+. .
+ pos: the position of interest
+lVal: the value to write
+. .
+
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
int getBitInBytes(int bitPos, char *buf, int numBits);
-/* DESC
+/*D
Returns the value of the bit bitPos bits from the start of buf. Returns
0 if bitPos is greater than or equal to numBits.
-DESC */
-/* FUNC */
+. .
+ bitPos: bit index from the start of buf
+ buf: array of bits
+numBits: number of valid bits in buf
+. .
+
+D*/
+
+/*F*/
void putBitInBytes(int bitPos, char *buf, int bit);
-/* DESC
+/*D
Sets the bit bitPos bits from the start of buf to bit.
-DESC */
-/* FUNC */
+. .
+bitPos: bit index from the start of buf
+ buf: array of bits
+ bit: 0-1, value to set
+. .
+
+D*/
+
+/*F*/
double time_time(void);
-/* DESC
+/*D
Return the current time in seconds since the Epoch.
-DESC */
+D*/
-/* FUNC */
+/*F*/
void time_sleep(double seconds);
-/* DESC
+/*D
Delay execution for a given number of seconds
-DESC */
+
+. .
+seconds: the number of seconds to sleep
+. .
+D*/
-/* FUNC */
+/*F*/
void rawDumpWave(void);
-/* DESC
+/*D
Used to print a readable version of the current waveform to stderr.
Not intended for general use.
-DESC */
+D*/
-/* FUNC */
+/*F*/
void rawDumpScript(unsigned script_id);
-/* DESC
+/*D
Used to print a readable version of a script to stderr.
+. .
+script_id: >=0, a script_id returned by [*gpioStoreScript*]
+. .
+
Not intended for general use.
-DESC */
+D*/
#ifdef __cplusplus
}
#endif
-/* PARAMS
+/*PARAMS
*arg::
+
A pointer to a void object passed to a thread started by gpioStartThread.
-bbBaud::100-250000
+bbBaud::
+
The baud rate used for the transmission and reception of bit banged
serial data.
-...
+. .
PI_WAVE_MIN_BAUD 100
PI_WAVE_MAX_BAUD 250000
-...
+. .
+
+bit::
-bit::0-1
A value of 0 or 1.
bitPos::
+
A bit position within a byte or word. The least significant bit is
position 0.
bits::
+
A value used to select gpios. If bit n of bits is set then gpio n is
selected.
@@ -2437,66 +3067,126 @@ A convenient way to set bit n is to or in (1<<n).
e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23).
*buf::
+
A buffer to hold data being sent or being received.
bufSize::
+
The size in bytes of a buffer.
-bVal::0-255
-A byte value, 0-255.
+bVal::0-255 (Hex 0x0-0xFF, Octal 0-0377)
+
+An 8-bit byte value.
+
+cbNum::
+
+A number identifying a DMA contol block.
+
+cfgMicros::
+
+The gpio sample rate in microseconds. The default is 5us, or 200 thousand
+samples per second.
+
+cfgMillis:: 100-10000
+
+The size of the sample buffer in milliseconds. Gnerally this should be
+left at the default of 120ms. If you expect intense bursts of signals it
+might be necessary to increase the buffer size.
+
+cfgPeripheral::
+
+One of the PWM or PCM peripherals used to pace DMA transfers for timing
+purposes.
+
+cfgSource::
+
+The clock source used for the timing of DMA transfers. May be the 19.2MHz
+crystal or the 500MHz PLL.
+. .
+PI_CLOCK_OSC 0
+PI_CLOCK_PLLD 1
+. .
+
+cfgVal::
+
+A number specifying the value of a configuration item. See [*cfgWhat*].
+
+cfgWhat::
+
+A number specifying a configuration item.
+
+562484977: print enhanced statistics at termination.
+984762879: set the initial debug level.
char::
+
A single character, an 8 bit quantity able to store 0-255.
count::
-The number of bytes to be transferred in aN I2C, SPI, or Serial
+
+The number of bytes to be transferred in an I2C, SPI, or Serial
command.
DMAchannel::0-14
-...
-#define PI_MIN_DMA_CHANNEL 0
-#define PI_MAX_DMA_CHANNEL 14
-...
+. .
+PI_MIN_DMA_CHANNEL 0
+PI_MAX_DMA_CHANNEL 14
+. .
+
double::
+
A floating point number.
dutycycle::0-range
+
A number representing the ratio of on time to off time for PWM.
The number may vary between 0 and range (default 255) where
-0 is off and 255 is fully on.
+0 is off and range is fully on.
f::
+
A function.
frequency::0-
+
The number of times a gpio is swiched on and off per second. This
can be set per gpio and may be as little as 5Hz or as much as
40KHz. The gpio will be on for a proportion of the time as defined
by its dutycycle.
-gpio::0-53
+gpio::
+
A Broadcom numbered gpio, in the range 0-53.
+gpioAlertFunc_t::
+. .
+typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);
+. .
+
gpioAlertFuncEx_t::
. .
typedef void (*gpioAlertFuncEx_t)
(int gpio, int level, uint32_t tick, void *userdata);
. .
-gpioAlertFunc_t::
-. .
-typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);
-. .
+gpioCfg*::
+
+One of
-gpioExtent_t::
+[*gpioCfgBufferSize*]
+[*gpioCfgClock*]
+[*gpioCfgDMAchannel*]
+[*gpioCfgDMAchannels*]
+[*gpioCfgPermissions*]
+[*gpioCfgInterfaces*]
+[*gpioCfgInternals*]
+[*gpioCfgSocketPort*]
+
+gpioGetSamplesFunc_t::
. .
-typedef struct
-{
- size_t size;
- void *ptr;
- uint32_t data;
-} gpioExtent_t;
+typedef void (*gpioGetSamplesFunc_t)
+ (const gpioSample_t *samples, int numSamples);
. .
gpioGetSamplesFuncEx_t::
@@ -2505,12 +3195,6 @@ typedef void (*gpioGetSamplesFuncEx_t)
(const gpioSample_t *samples, int numSamples, void *userdata);
. .
-gpioGetSamplesFunc_t::
-. .
-typedef void (*gpioGetSamplesFunc_t)
- (const gpioSample_t *samples, int numSamples);
-. .
-
gpioPulse_t::
. .
typedef struct
@@ -2521,14 +3205,14 @@ typedef struct
} gpioPulse_t;
. .
-gpioSignalFuncEx_t::
+gpioSignalFunc_t::
. .
-typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);
+typedef void (*gpioSignalFunc_t) (int signum);
. .
-gpioSignalFunc_t::
+gpioSignalFuncEx_t::
. .
-typedef void (*gpioSignalFunc_t) (int signum);
+typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);
. .
gpioThreadFunc_t::
@@ -2536,17 +3220,26 @@ gpioThreadFunc_t::
typedef void *(gpioThreadFunc_t) (void *);
. .
-gpioTimerFuncEx_t::
+gpioTimerFunc_t::
. .
-typedef void (*gpioTimerFuncEx_t) (void *userdata);
+typedef void (*gpioTimerFunc_t) (void);
. .
-gpioTimerFunc_t::
+gpioTimerFuncEx_t::
. .
-typedef void (*gpioTimerFunc_t) (void);
+typedef void (*gpioTimerFuncEx_t) (void *userdata);
. .
+gpioWaveAdd*::
+
+One of
+
+[*gpioWaveAddNew*]
+[*gpioWaveAddGeneric*]
+[*gpioWaveAddSerial*]
+
handle::0-
+
A number referencing an object opened by one of
[*i2cOpen*]
@@ -2555,14 +3248,21 @@ A number referencing an object opened by one of
[*spiOpen*]
i2cAddr::0x08-0x77
+
The address of a device on the I2C bus (0x08 - 0x77)
i2cBus::0-1
+
An I2C bus, 0 or 1.
i2cFlags::0
+
Flags which modify an I2C open command. None are currently defined.
+i2cReg:: 0-255
+
+A register of an I2C device.
+
ifFlags::0-3
. .
PI_DISABLE_FIFO_IF 1
@@ -2570,9 +3270,13 @@ PI_DISABLE_SOCK_IF 2
. .
int::
+
A whole number, negative or positive.
-level::0-1
+level::
+
+The level of a gpio. Low or High.
+
. .
PI_OFF 0
PI_ON 1
@@ -2584,17 +3288,34 @@ PI_LOW 0
PI_HIGH 1
. .
+There is one exception. If a watchdog expires on a gpio the level will be
+reported as PI_TIMEOUT. See [*gpioSetWatchdog*].
+
+. .
+PI_TIMEOUT 2
+. .
+
+
+lVal::0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)
+
+A 32-bit word value.
+
*micros::
+
A value representing microseconds.
micros::
+
A value representing microseconds.
millis::
+
A value representing milliseconds.
mode::0-7
+
The operational mode of a gpio, normally INPUT or OUTPUT.
+
. .
PI_INPUT 0
PI_OUTPUT 1
@@ -2608,40 +3329,69 @@ PI_ALT5 2
numBits::
+The number of bits stored in a buffer.
+
numChar::
-numParam::
+The number of characters in a string (used when the string might contain
+null characters, which would normally terminate the string).
+
+numPar:: 0-10
+
+The number of parameters passed to a script.
numPulses::
-spiTxBits::
+The number of pulses to be added to a waveform.
offset::
+The associated data starts this number of microseconds from the start of
+tghe waveform.
+
*param::
-peripheral::
+An array of script parameters.
-port::
+port:: 1024-32000
+
+The port used to bind to the pigpio socket. Defaults to 8888.
pos::
-primaryChannel::
+The position of an item.
+
+primaryChannel:: 0-14
+
+The DMA channel used to time the sampling of gpios and to time servo and
+PWM pulses.
*pth::
+
+A thread identifier, returned by [*gpioStartThread*].
+
pthread_t::
+A thread identifier.
+
pud::0-2
+
+The setting of the pull up/down resistor for a gpio, which may be off,
+pull-up, or pull-down.
. .
PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2
. .
+
pulseLen::
+
1-50, the length of a trigger pulse in microseconds.
*pulses::
+An array of pulsed to be added to a waveform.
+
pulsewidth::0, 500-2500
. .
PI_SERVO_OFF 0
@@ -2695,20 +3445,21 @@ typedef struct
} rawWave_t;
. .
-reg::
-
*rxBuf::
-spiBitFirst::
-
-spiBitLast::
+A pointer to a buffer to receive data.
*script::
+A pointer to the text of a script.
+
script_id::
-An id of a stored script as returned by gpioStoreScript.
-secondaryChannel::
+An id of a stored script as returned by [*gpioStoreScript*].
+
+secondaryChannel:: 0-6
+
+The DMA channel used to time output waveforms.
*seconds::
@@ -2717,84 +3468,149 @@ a returned time.
seconds::
+The number of seconds.
+
+serBaud::
+
+The baud rate to use on the serial link.
+
+It must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
+4800, 9600, 19200, 38400, 57600, 115200, 230400.
+
serFlags::
+
Flags which modify a serial open command. None are currently defined.
+*sertty::
+
+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
+
signum::0-63
. .
PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63
. .
+
size_t::
-source::
-. .
-PI_CLOCK_OSC 0
-PI_CLOCK_PLLD 1
-. .
-speed::
+A standard type used to indicate the size of an object in bytes.
+
*spi::
-spi_chan::
+A pointer to a [*rawSPI_t*] structure.
+
+spiBaud::
+
+The speed in bits per second to use for the SPI device.
+
+spiBitFirst::
+
+Gpio reads are made from spiBitFirst to spiBitLast.
+
+spiBitLast::
+
+Gpio reads are made from spiBitFirst to spiBitLast.
+
+spiBits::
+
+The number of bits to transfer in a raw SPI transaction.
+
+spiChan::
+
A SPI channel, 0 or 1.
spiFlags::
+
Flags which modify a SPI open command. The two least significant bits
define the SPI mode. The other bits are undefined.
spiSS::
+
+The SPI slave select gpio in a raw SPI transaction.
+
+spiTxBits::
+
+The number of bits to transfer dring a raw SPI transaction
+
*str::
- A pointer to a null terminated ASCII string.
+
+An array of characters.
+
timeout::
+
+A gpio watchdog timeout in milliseconds.
. .
PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000
. .
+
timer::
. .
PI_MIN_TIMER 0
PI_MAX_TIMER 9
. .
+
timetype::
. .
PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1
. .
-*tty::
-A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0
*txBuf::
-uint32_t::
-A whole number in the range 0-4,294,967,295
+An array of bytes to transmit.
+
+uint32_t::0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)
+
+A 32-bit unsigned value.
+
+uint64_t::0-(2^64)-1
-uint64_t::
-A whole number in the range 0-(2^64)-1.
+A 64-bit unsigned value.
unsigned::
+
A whole number >= 0.
updateMask::
+
A 64 bit mask indicating which gpios may be written to by the user.
If gpio#n may be written then bit (1<<n) is set.
user_gpio::
+
0-31, a Broadcom numbered gpio.
*userdata::
-bVal::
-
-value::
+A pointer to arbitrary user data. This may be used to identify the instance.
void::
+Denoting no parameter is required
+
wave_id::
+
A number representing a waveform created by [*gpioWaveCreate*].
-what::
-PARAMS */
+wave_mode::
+
+The mode of waveform transmission, whether it is sent once or cycles
+repeatedly.
+
+. .
+PI_WAVE_MODE_ONE_SHOT 0
+PI_WAVE_MODE_REPEAT 1
+. .
+
+wVal::0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)
+
+A 16-bit word value.
+
+PARAMS*/
+
+/*DEF_S Socket Command Codes*/
#define PI_CMD_MODES 0
#define PI_CMD_MODEG 1
@@ -2883,8 +3699,12 @@ PARAMS */
#define PI_CMD_SERW 81
#define PI_CMD_SERDA 82
+#define PI_CMD_NOIB 99
+
+/*DEF_E*/
+
/*
-The following command only works on the socket interface.
+PI CMD_NOIB only works on the socket interface.
It returns a spare notification handle. Notifications for
that handle will be sent to the socket (rather than a
/dev/pigpiox pipe).
@@ -2893,8 +3713,6 @@ The socket should be dedicated to receiving notifications
after this command is issued.
*/
-#define PI_CMD_NOIB 99
-
/* pseudo commands */
#define PI_CMD_SCRIPT 800
@@ -2942,102 +3760,104 @@ after this command is issued.
#define PI_CMD_XA 840
#define PI_CMD_XOR 841
-/* error numbers reported by functions */
-
-#define PI_INIT_FAILED -1 /* gpioInitialise failed */
-#define PI_BAD_USER_GPIO -2 /* gpio not 0-31 */
-#define PI_BAD_GPIO -3 /* gpio not 0-53 */
-#define PI_BAD_MODE -4 /* mode not 0-7 */
-#define PI_BAD_LEVEL -5 /* level not 0-1 */
-#define PI_BAD_PUD -6 /* pud not 0-2 */
-#define PI_BAD_PULSEWIDTH -7 /* pulsewidth not 0 or 500-2500 */
-#define PI_BAD_DUTYCYCLE -8 /* dutycycle outside set range */
-#define PI_BAD_TIMER -9 /* timer not 0-9 */
-#define PI_BAD_MS -10 /* ms not 10-60000 */
-#define PI_BAD_TIMETYPE -11 /* timetype not 0-1 */
-#define PI_BAD_SECONDS -12 /* seconds < 0 */
-#define PI_BAD_MICROS -13 /* micros not 0-999999 */
-#define PI_TIMER_FAILED -14 /* gpioSetTimerFunc failed */
-#define PI_BAD_WDOG_TIMEOUT -15 /* timeout not 0-60000 */
-#define PI_NO_ALERT_FUNC -16 /* DEPRECATED */
-#define PI_BAD_CLK_PERIPH -17 /* clock peripheral not 0-1 */
-#define PI_BAD_CLK_SOURCE -18 /* clock source not 0-1 */
-#define PI_BAD_CLK_MICROS -19 /* clock micros not 1, 2, 4, 5, 8, or 10 */
-#define PI_BAD_BUF_MILLIS -20 /* buf millis not 100-10000 */
-#define PI_BAD_DUTYRANGE -21 /* dutycycle range not 25-40000 */
-#define PI_BAD_DUTY_RANGE -21 /* DEPRECATED (use PI_BAD_DUTYRANGE) */
-#define PI_BAD_SIGNUM -22 /* signum not 0-63 */
-#define PI_BAD_PATHNAME -23 /* can't open pathname */
-#define PI_NO_HANDLE -24 /* no handle available */
-#define PI_BAD_HANDLE -25 /* unknown notify handle */
-#define PI_BAD_IF_FLAGS -26 /* ifFlags > 3 */
-#define PI_BAD_CHANNEL -27 /* DMA channel not 0-14 */
-#define PI_BAD_PRIM_CHANNEL -27 /* DMA primary channel not 0-14 */
-#define PI_BAD_SOCKET_PORT -28 /* socket port not 1024-32000 */
-#define PI_BAD_FIFO_COMMAND -29 /* unrecognized fifo command */
-#define PI_BAD_SECO_CHANNEL -30 /* DMA secondary channel not 0-6 */
-#define PI_NOT_INITIALISED -31 /* function called before gpioInitialise */
-#define PI_INITIALISED -32 /* function called after gpioInitialise */
-#define PI_BAD_WAVE_MODE -33 /* waveform mode not 0-1 */
-#define PI_BAD_CFG_INTERNAL -34 /* bad parameter in gpioCfgInternals call */
-#define PI_BAD_WAVE_BAUD -35 /* baud rate not 100-250000 */
-#define PI_TOO_MANY_PULSES -36 /* waveform has too many pulses */
-#define PI_TOO_MANY_CHARS -37 /* waveform has too many chars */
-#define PI_NOT_SERIAL_GPIO -38 /* no serial read in progress on gpio */
-#define PI_BAD_SERIAL_STRUC -39 /* bad (null) serial structure parameter */
-#define PI_BAD_SERIAL_BUF -40 /* bad (null) serial buf parameter */
-#define PI_NOT_PERMITTED -41 /* gpio operation not permitted */
-#define PI_SOME_PERMITTED -42 /* one or more gpios not permitted */
-#define PI_BAD_WVSC_COMMND -43 /* bad WVSC subcommand */
-#define PI_BAD_WVSM_COMMND -44 /* bad WVSM subcommand */
-#define PI_BAD_WVSP_COMMND -45 /* bad WVSP subcommand */
-#define PI_BAD_PULSELEN -46 /* trigger pulse length > 50 */
-#define PI_BAD_SCRIPT -47 /* invalid script */
-#define PI_BAD_SCRIPT_ID -48 /* unknown script id */
-#define PI_BAD_SER_OFFSET -49 /* add serial data offset > 30 minutes */
-#define PI_GPIO_IN_USE -50 /* gpio already in use */
-#define PI_BAD_SERIAL_COUNT -51 /* must read at least a byte at a time */
-#define PI_BAD_PARAM_NUM -52 /* script parameter must be 0-9 */
-#define PI_DUP_TAG -53 /* script has duplicate tag */
-#define PI_TOO_MANY_TAGS -54 /* script has too many tags */
-#define PI_BAD_SCRIPT_CMD -55 /* illegal script command */
-#define PI_BAD_VAR_NUM -56 /* script variable must be 0-149 */
-#define PI_NO_SCRIPT_ROOM -57 /* no more room for scripts */
-#define PI_NO_MEMORY -58 /* can't allocate temporary memory */
-#define PI_SOCK_READ_FAILED -59 /* socket read failed */
-#define PI_SOCK_WRIT_FAILED -60 /* socket write failed */
-#define PI_TOO_MANY_PARAM -61 /* too many script parameters > 10 */
-#define PI_NOT_HALTED -62 /* script already running or failed */
-#define PI_BAD_TAG -63 /* script has unresolved tag */
-#define PI_BAD_MICS_DELAY -64 /* bad MICS delay (too large) */
-#define PI_BAD_MILS_DELAY -65 /* bad MILS delay (too large) */
-#define PI_BAD_WAVE_ID -66 /* non existent wave id */
-#define PI_TOO_MANY_CBS -67 /* No more CBs for waveform */
-#define PI_TOO_MANY_OOL -68 /* No more OOL for waveform */
-#define PI_EMPTY_WAVEFORM -69 /* attempt to create an empty waveform */
-#define PI_NO_WAVEFORM_ID -70 /* no more waveforms */
-#define PI_I2C_OPEN_FAILED -71 /* can't open I2C device */
-#define PI_SER_OPEN_FAILED -72 /* can't open serial device */
-#define PI_SPI_OPEN_FAILED -73 /* can't open SPI device */
-#define PI_BAD_I2C_BUS -74 /* bad I2C bus */
-#define PI_BAD_I2C_ADDR -75 /* bad I2C address */
-#define PI_BAD_SPI_CHANNEL -76 /* bad SPI channel */
-#define PI_BAD_FLAGS -77 /* bad i2c/spi/ser open flags */
-#define PI_BAD_SPI_SPEED -78 /* bad SPI speed */
-#define PI_BAD_SER_DEVICE -79 /* bad serial device name */
-#define PI_BAD_SER_SPEED -80 /* bad serial baud rate */
-#define PI_BAD_PARAM -81 /* bad i2c/spi/ser parameter */
-#define PI_I2C_WRITE_FAILED -82 /* i2c write failed */
-#define PI_I2C_READ_FAILED -83 /* i2c read failed */
-#define PI_BAD_SPI_COUNT -84 /* bad SPI count */
-#define PI_SER_WRITE_FAILED -85 /* ser write failed */
-#define PI_SER_READ_FAILED -86 /* ser read failed */
-#define PI_SER_READ_NO_DATA -87 /* ser read no data available */
-#define PI_UNKNOWN_COMMAND -88 /* unknown command */
-#define PI_SPI_XFER_FAILED -89 /* spi xfer/read/write failed */
-#define PI_BAD_POINTER -90 /* bad (NULL) pointer */
-
-
+/*DEF_S Error Codes*/
+
+#define PI_INIT_FAILED -1 // gpioInitialise failed
+#define PI_BAD_USER_GPIO -2 // gpio not 0-31
+#define PI_BAD_GPIO -3 // gpio not 0-53
+#define PI_BAD_MODE -4 // mode not 0-7
+#define PI_BAD_LEVEL -5 // level not 0-1
+#define PI_BAD_PUD -6 // pud not 0-2
+#define PI_BAD_PULSEWIDTH -7 // pulsewidth not 0 or 500-2500
+#define PI_BAD_DUTYCYCLE -8 // dutycycle outside set range
+#define PI_BAD_TIMER -9 // timer not 0-9
+#define PI_BAD_MS -10 // ms not 10-60000
+#define PI_BAD_TIMETYPE -11 // timetype not 0-1
+#define PI_BAD_SECONDS -12 // seconds < 0
+#define PI_BAD_MICROS -13 // micros not 0-999999
+#define PI_TIMER_FAILED -14 // gpioSetTimerFunc failed
+#define PI_BAD_WDOG_TIMEOUT -15 // timeout not 0-60000
+#define PI_NO_ALERT_FUNC -16 // DEPRECATED
+#define PI_BAD_CLK_PERIPH -17 // clock peripheral not 0-1
+#define PI_BAD_CLK_SOURCE -18 // clock source not 0-1
+#define PI_BAD_CLK_MICROS -19 // clock micros not 1, 2, 4, 5, 8, or 10
+#define PI_BAD_BUF_MILLIS -20 // buf millis not 100-10000
+#define PI_BAD_DUTYRANGE -21 // dutycycle range not 25-40000
+#define PI_BAD_DUTY_RANGE -21 // DEPRECATED (use PI_BAD_DUTYRANGE)
+#define PI_BAD_SIGNUM -22 // signum not 0-63
+#define PI_BAD_PATHNAME -23 // can't open pathname
+#define PI_NO_HANDLE -24 // no handle available
+#define PI_BAD_HANDLE -25 // unknown handle
+#define PI_BAD_IF_FLAGS -26 // ifFlags > 3
+#define PI_BAD_CHANNEL -27 // DMA channel not 0-14
+#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-14
+#define PI_BAD_SOCKET_PORT -28 // socket port not 1024-32000
+#define PI_BAD_FIFO_COMMAND -29 // unrecognized fifo command
+#define PI_BAD_SECO_CHANNEL -30 // DMA secondary channel not 0-6
+#define PI_NOT_INITIALISED -31 // function called before gpioInitialise
+#define PI_INITIALISED -32 // function called after gpioInitialise
+#define PI_BAD_WAVE_MODE -33 // waveform mode not 0-1
+#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
+#define PI_BAD_WAVE_BAUD -35 // baud rate not 100-250000
+#define PI_TOO_MANY_PULSES -36 // waveform has too many pulses
+#define PI_TOO_MANY_CHARS -37 // waveform has too many chars
+#define PI_NOT_SERIAL_GPIO -38 // no serial read in progress on gpio
+#define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter
+#define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter
+#define PI_NOT_PERMITTED -41 // gpio operation not permitted
+#define PI_SOME_PERMITTED -42 // one or more gpios not permitted
+#define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand
+#define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand
+#define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand
+#define PI_BAD_PULSELEN -46 // trigger pulse length > 50
+#define PI_BAD_SCRIPT -47 // invalid script
+#define PI_BAD_SCRIPT_ID -48 // unknown script id
+#define PI_BAD_SER_OFFSET -49 // add serial data offset > 30 minutes
+#define PI_GPIO_IN_USE -50 // gpio already in use
+#define PI_BAD_SERIAL_COUNT -51 // must read at least a byte at a time
+#define PI_BAD_PARAM_NUM -52 // script parameter must be 0-9
+#define PI_DUP_TAG -53 // script has duplicate tag
+#define PI_TOO_MANY_TAGS -54 // script has too many tags
+#define PI_BAD_SCRIPT_CMD -55 // illegal script command
+#define PI_BAD_VAR_NUM -56 // script variable must be 0-149
+#define PI_NO_SCRIPT_ROOM -57 // no more room for scripts
+#define PI_NO_MEMORY -58 // can't allocate temporary memory
+#define PI_SOCK_READ_FAILED -59 // socket read failed
+#define PI_SOCK_WRIT_FAILED -60 // socket write failed
+#define PI_TOO_MANY_PARAM -61 // too many script parameters > 10
+#define PI_NOT_HALTED -62 // script already running or failed
+#define PI_BAD_TAG -63 // script has unresolved tag
+#define PI_BAD_MICS_DELAY -64 // bad MICS delay (too large)
+#define PI_BAD_MILS_DELAY -65 // bad MILS delay (too large)
+#define PI_BAD_WAVE_ID -66 // non existent wave id
+#define PI_TOO_MANY_CBS -67 // No more CBs for waveform
+#define PI_TOO_MANY_OOL -68 // No more OOL for waveform
+#define PI_EMPTY_WAVEFORM -69 // attempt to create an empty waveform
+#define PI_NO_WAVEFORM_ID -70 // no more waveforms
+#define PI_I2C_OPEN_FAILED -71 // can't open I2C device
+#define PI_SER_OPEN_FAILED -72 // can't open serial device
+#define PI_SPI_OPEN_FAILED -73 // can't open SPI device
+#define PI_BAD_I2C_BUS -74 // bad I2C bus
+#define PI_BAD_I2C_ADDR -75 // bad I2C address
+#define PI_BAD_SPI_CHANNEL -76 // bad SPI channel
+#define PI_BAD_FLAGS -77 // bad i2c/spi/ser open flags
+#define PI_BAD_SPI_SPEED -78 // bad SPI speed
+#define PI_BAD_SER_DEVICE -79 // bad serial device name
+#define PI_BAD_SER_SPEED -80 // bad serial baud rate
+#define PI_BAD_PARAM -81 // bad i2c/spi/ser parameter
+#define PI_I2C_WRITE_FAILED -82 // i2c write failed
+#define PI_I2C_READ_FAILED -83 // i2c read failed
+#define PI_BAD_SPI_COUNT -84 // bad SPI count
+#define PI_SER_WRITE_FAILED -85 // ser write failed
+#define PI_SER_READ_FAILED -86 // ser read failed
+#define PI_SER_READ_NO_DATA -87 // ser read no data available
+#define PI_UNKNOWN_COMMAND -88 // unknown command
+#define PI_SPI_XFER_FAILED -89 // spi xfer/read/write failed
+#define PI_BAD_POINTER -90 // bad (NULL) pointer
+
+/*DEF_E*/
+
+/*DEF_S Defaults*/
#define PI_DEFAULT_BUFFER_MILLIS 120
#define PI_DEFAULT_CLK_MICROS 5
@@ -3050,9 +3870,12 @@ after this command is issued.
#define PI_DEFAULT_SOCKET_PORT 8888
#define PI_DEFAULT_SOCKET_PORT_STR "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1"
-#define PI_DEFAULT_UPDATE_MASK_R0 0xFBE6CF9F
-#define PI_DEFAULT_UPDATE_MASK_R1 0x03E6CF93
-#define PI_DEFAULT_UPDATE_MASK_R2 0xFBC6CF9C
+#define PI_DEFAULT_UPDATE_MASK_R0 0xFFFFFFFF
+#define PI_DEFAULT_UPDATE_MASK_R1 0x03E7CF93
+#define PI_DEFAULT_UPDATE_MASK_R2 0xFBC7CF9C
+#define PI_DEFAULT_UPDATE_MASK_R3 0x80400FFFFFFCLL
+
+/*DEF_E*/
#endif
diff --git a/pigpio.py b/pigpio.py
index 1bb3b96..a20a4bc 100644
--- a/pigpio.py
+++ b/pigpio.py
@@ -2,57 +2,51 @@
pigpio is a Python module for the Raspberry which allows control
of the general purpose input outputs (gpios).
-http://abyz.co.uk/rpi/pigpio/python.html
+[http://abyz.co.uk/rpi/pigpio/python.html]
-Features
+*Features*
-The pigpio module's main features are:
+o pigpio Python module can be running on Windows, Macs, or Linux
-- controlling the gpios of one or more Pi's
+o controls one or more Pi's
-- PWM on any of gpios 0-31 simultaneously
+o independent PWM on any of gpios 0-31 simultaneously
-- servo pulses on any of gpios 0-31 simultaneously
+o independent servo pulses on any of gpios 0-31 simultaneously
-- callbacks when any of gpios 0-31 change state
+o callbacks when any of gpios 0-31 change state
-- creating and transmitting precisely timed waveforms
+o creating and transmitting precisely timed waveforms
-- reading/writing gpios and setting their modes
+o reading/writing gpios and setting their modes
-- wrappers for I2C, SPI, and serial links
+o wrappers for I2C, SPI, and serial links
-- creating and running scripts on the pigpio daemon
+o creating and running scripts on the pigpio daemon
-Notes
-
-Transmitted waveforms are accurate to a microsecond.
-
-Callback level changes are time-stamped and will be
-accurate to within a few microseconds.
+*gpios*
ALL gpios are identified by their Broadcom number.
-This module uses the services of the C pigpio library. pigpio
-must be running on the Pi whose gpios are to be manipulated.
+*Notes*
-The normal way to start pigpio is as a daemon (during system
-start).
+Transmitted waveforms are accurate to a microsecond.
-sudo pigpiod
+Callback level changes are time-stamped and will be
+accurate to within a few microseconds.
-Settings
+*Settings*
A number of settings are determined when the pigpio daemon is started.
-- the sample rate (1, 2, 4, 5, 8, or 10us, default 5us).
+o the sample rate (1, 2, 4, 5, 8, or 10us, default 5us).
-- the set of gpios which may be updated (generally written to). The
- default set is those listed above for the Rev.1 or Rev.2 boards.
+o the set of gpios which may be updated (generally written to). The
+ default set is those available on the Pi board revision.
-- the available PWM frequencies (see set_PWM_frequency).
+o the available PWM frequencies (see [*set_PWM_frequency*]).
-Exceptions
+*Exceptions*
By default a fatal exception is raised if you pass an invalid
argument to a pigpio function.
@@ -60,7 +54,26 @@ argument to a pigpio function.
If you wish to handle the returned status yourself you should set
pigpio.exceptions to False.
-USAGE
+You may prefer to check the returned status in only a few parts
+of your code. In that case do the following.
+
+...
+pigpio.exceptions = False
+
+# Code where you want to test the error status.
+
+pigpio.exceptions = True
+...
+
+*Usage*
+
+This module uses the services of the C pigpio library. pigpio
+must be running on the Pi(s) whose gpios are to be manipulated.
+
+The normal way to start pigpio is as a daemon (during system
+start).
+
+sudo pigpiod
Your Python program must import pigpio and create one or more
instances of the pigpio.pi class. This class gives access to
@@ -68,12 +81,12 @@ a specified Pi's gpios.
...
pi1 = pigpio.pi() # pi1 accesses the local Pi's gpios
-pi2 = pigpio.pi('hard') # pi2 accesses hard's gpios
-pi3 = pigpio.pi('soft') # pi3 accesses soft's gpios
+pi2 = pigpio.pi('tom') # pi2 accesses tom's gpios
+pi3 = pigpio.pi('dick') # pi3 accesses dick's gpios
pi1.write(4, 0) # set local Pi's gpio 4 low
-pi2.write(4, 1) # set hard's gpio 4 to high
-pi3.read(4) # get level of soft's gpio 4
+pi2.write(4, 1) # set tom's gpio 4 to high
+pi3.read(4) # get level of dick's gpio 4
...
The later example code snippets assume that pi is an instance of
@@ -81,7 +94,6 @@ the pigpio.pi class.
OVERVIEW
-
Essential
pigpio.pi Initialise Pi connection
@@ -234,7 +246,7 @@ import os
import atexit
import codecs
-VERSION = "1.6"
+VERSION = "1.7"
exceptions = True
@@ -275,10 +287,11 @@ PUD_UP = 2
# script run status
-PI_SCRIPT_HALTED =0
-PI_SCRIPT_RUNNING=1
-PI_SCRIPT_WAITING=2
-PI_SCRIPT_FAILED =3
+PI_SCRIPT_INITING=0
+PI_SCRIPT_HALTED =1
+PI_SCRIPT_RUNNING=2
+PI_SCRIPT_WAITING=3
+PI_SCRIPT_FAILED =4
# pigpio command numbers
@@ -483,7 +496,7 @@ _errors=[
[PI_BAD_LEVEL , "level not 0-1"],
[PI_BAD_PUD , "pud not 0-2"],
[PI_BAD_PULSEWIDTH , "pulsewidth not 0 or 500-2500"],
- [PI_BAD_DUTYCYCLE , "dutycycle not 0-255"],
+ [PI_BAD_DUTYCYCLE , "dutycycle not 0-range (default 255)"],
[_PI_BAD_TIMER , "timer not 0-9"],
[_PI_BAD_MS , "ms not 10-60000"],
[_PI_BAD_TIMETYPE , "timetype not 0-1"],
@@ -500,7 +513,7 @@ _errors=[
[_PI_BAD_SIGNUM , "signum not 0-63"],
[_PI_BAD_PATHNAME , "can't open pathname"],
[PI_NO_HANDLE , "no handle available"],
- [PI_BAD_HANDLE , "unknown notify handle"],
+ [PI_BAD_HANDLE , "unknown handle"],
[_PI_BAD_IF_FLAGS , "ifFlags > 3"],
[_PI_BAD_CHANNEL , "DMA channel not 0-14"],
[_PI_BAD_SOCKET_PORT , "socket port not 1024-30000"],
@@ -936,7 +949,7 @@ class pi():
user_gpio:= 0-31.
dutycycle:= 0-range (range defaults to 255).
- The set_PWM_range function can change the default range of 255.
+ The [*set_PWM_range*] function can change the default range of 255.
...
pi.set_PWM_dutycycle(4, 0) # PWM off
@@ -1069,13 +1082,14 @@ class pi():
A notification is a method for being notified of gpio state
changes via a pipe.
- Pipes are only accessible from the local machine so this
+ Pipes are only accessible from the local machine so this
function serves no purpose if you are using Python from a
remote machine. The in-built (socket) notifications
- provided by callback should be used instead.
+ provided by [*callback*] should be used instead.
Notifications for handle x will be available at the pipe
named /dev/pigpiox (where x is the handle number).
+
E.g. if the function returns 15 then the notifications must be
read from /dev/pigpio15.
@@ -1101,7 +1115,7 @@ class pi():
"""
Starts notifications on a handle.
- handle:= >=0 (as returned by a prior call to notify_open)
+ handle:= >=0 (as returned by a prior call to [*notify_open*])
bits:= a 32 bit mask indicating the gpios to be notified.
The notification sends state changes for each gpio whose
@@ -1122,10 +1136,10 @@ class pi():
"""
Pauses notifications on a handle.
- handle:= >=0 (as returned by a prior call to notify_open)
+ handle:= >=0 (as returned by a prior call to [*notify_open*])
Notifications for the handle are suspended until
- notify_begin is called again.
+ [*notify_begin*] is called again.
...
h = pi.notify_open()
@@ -1144,7 +1158,7 @@ class pi():
"""
Stops notifications on a handle and releases the handle for reuse.
- handle:= >=0 (as returned by a prior call to notify_open)
+ handle:= >=0 (as returned by a prior call to [*notify_open*])
...
h = pi.notify_open()
@@ -1303,7 +1317,7 @@ class pi():
The revision number can be used to determine the assignment
of gpios to pins.
- There are at least two types of board.
+ There are at least three types of board.
Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13
(revision numbers 2 and 3).
@@ -1311,6 +1325,10 @@ class pi():
Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13,
and gpios 28-31 on P5 (revision numbers of 4, 5, 6, and 15).
+ Type 3 has a 40 pin connector rather than the 26 pin connector
+ of the earlier boards. Gpios 0 to 27 are brought out to the
+ connector (revision number 16).
+
If the hardware revision can not be found or is not a valid
hexadecimal number the function returns 0.
@@ -1334,7 +1352,7 @@ class pi():
def wave_clear(self):
"""
Clears all waveforms and any data added by calls to the
- wave_add_* functions.
+ [*wave_add_**] functions.
...
pi.wave_clear()
@@ -1348,7 +1366,7 @@ class pi():
You would not normally need to call this function as it is
automatically called after a waveform is created with the
- wave_create function.
+ [*wave_create*] function.
...
pi.wave_add_new()
@@ -1483,28 +1501,28 @@ class pi():
def wave_create(self):
"""
Creates a waveform from the data provided by the prior calls
- to the wave_add_* functions.
+ to the [*wave_add_**] functions.
Returns a wave id (>=0) if OK.
- The data provided by the wave_add_* functions is consumed by
+ The data provided by the [*wave_add_**] functions is consumed by
this function.
As many waveforms may be created as there is space available.
- The wave id is passed to wave_send_* to specify the waveform
+ The wave id is passed to [*wave_send_**] to specify the waveform
to transmit.
Normal usage would be
- Step 1. wave_clear to clear all waveforms and added data.
+ Step 1. [*wave_clear*] to clear all waveforms and added data.
- Step 2. wave_add_* calls to supply the waveform data.
+ Step 2. [*wave_add_**] calls to supply the waveform data.
- Step 3. wave_create to create the waveform and get a unique id
+ Step 3. [*wave_create*] to create the waveform and get a unique id
Repeat steps 2 and 3 as needed.
- Step 4. wave_send_* with the id of the waveform to transmit.
+ Step 4. [*wave_send_**] with the id of the waveform to transmit.
A waveform comprises one or more pulses.
@@ -1531,7 +1549,7 @@ class pi():
Deletes all created waveforms with ids greater than or equal
to wave_id.
- wave_id:= >=0 (as returned by a prior call to wave_create).
+ wave_id:= >=0 (as returned by a prior call to [*wave_create*]).
Wave ids are allocated in order, 0, 1, 2, etc.
@@ -1547,7 +1565,7 @@ class pi():
"""
This function is deprecated and will be removed.
- Use wave_create/wave_send_* instead.
+ Use [*wave_create*]/[*wave_send_**] instead.
"""
return _u2i(_pigpio_command(self._control, _PI_CMD_WVGO, 0, 0))
@@ -1555,7 +1573,7 @@ class pi():
"""
This function is deprecated and will be removed.
- Use wave_create/wave_send_* instead.
+ Use [*wave_create*]/[*wave_send_**] instead.
"""
return _u2i(_pigpio_command(self._control, _PI_CMD_WVGOR, 0, 0))
@@ -1564,7 +1582,7 @@ class pi():
Transmits the waveform with id wave_id. The waveform is sent
once.
- wave_id:= >=0 (as returned by a prior call to wave_create).
+ wave_id:= >=0 (as returned by a prior call to [*wave_create*]).
Returns the number of DMA control blocks used in the waveform.
@@ -1577,10 +1595,10 @@ class pi():
def wave_send_repeat(self, wave_id):
"""
Transmits the waveform with id wave_id. The waveform repeats
- until wave_tx_stop is called or another call to wave_send_*
+ until wave_tx_stop is called or another call to [*wave_send_**]
is made.
- wave_id:= >=0 (as returned by a prior call to wave_create).
+ wave_id:= >=0 (as returned by a prior call to [*wave_create*]).
Returns the number of DMA control blocks used in the waveform.
@@ -1693,6 +1711,11 @@ class pi():
i2c_address:= 0x08-0x77.
i2c_flags:= 0, no flags are currently defined.
+ Normally you would only use the [*i2c_**] functions if
+ you are or will be connecting to the Pi over a network. If
+ you will always run on the local Pi use the standard smbus
+ modules instead.
+
...
h = pi.i2c_open(1, 0x53) # open device at address 0x53 on bus 1
...
@@ -1710,7 +1733,7 @@ class pi():
"""
Closes the I2C device associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
...
pi.i2c_close(h)
@@ -1723,7 +1746,7 @@ class pi():
Returns count bytes read from the raw device associated
with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
count:= >0, the number of bytes to read.
The returned value is a tuple of the number of bytes read and a
@@ -1744,7 +1767,7 @@ class pi():
"""
Writes the data bytes to the raw device associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
data:= the bytes to write.
...
@@ -1770,10 +1793,11 @@ class pi():
def i2c_write_quick(self, handle, bit):
"""
- Sends a single bit to the device associated with handle
- (smbus 2.0 5.5.1 - Quick command).
+ Sends a single bit to the device associated with handle.
+
+ smbus 2.0 5.5.1 - Quick command.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
bit:= 0 or 1, the value to write.
...
@@ -1785,10 +1809,11 @@ class pi():
def i2c_write_byte(self, handle, byte_val):
"""
- Sends a single byte to the device associated with handle
- (smbus 2.0 5.5.2 - Send byte).
+ Sends a single byte to the device associated with handle.
+
+ smbus 2.0 5.5.2 - Send byte.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
byte_val:= 0-255, the value to write.
...
@@ -1801,10 +1826,11 @@ class pi():
def i2c_read_byte(self, handle):
"""
- Reads a single byte from the device associated with handle
- (smbus 2.0 5.5.3 - Receive byte).
+ Reads a single byte from the device associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ smbus 2.0 5.5.3 - Receive byte.
+
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
...
b = pi.i2c_read_byte(2) # read a byte from device 2
@@ -1815,9 +1841,11 @@ class pi():
def i2c_write_byte_data(self, handle, reg, byte_val):
"""
Writes a single byte to the specified register of the device
- associated with handle (smbus 2.0 5.5.4 - Write byte).
+ associated with handle.
+
+ smbus 2.0 5.5.4 - Write byte.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
byte_val:= 0-255, the value to write.
@@ -1841,9 +1869,11 @@ class pi():
def i2c_write_word_data(self, handle, reg, word_val):
"""
Writes a single 16 bit word to the specified register of the
- device associated with handle (smbus 2.0 5.5.4 - Write word).
+ device associated with handle.
+
+ smbus 2.0 5.5.4 - Write word.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
word_val:= 0-65535, the value to write.
@@ -1867,9 +1897,11 @@ class pi():
def i2c_read_byte_data(self, handle, reg):
"""
Reads a single byte from the specified register of the device
- associated with handle (smbus 2.0 5.5.5 - Read byte).
+ associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ smbus 2.0 5.5.5 - Read byte.
+
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
...
@@ -1885,9 +1917,11 @@ class pi():
def i2c_read_word_data(self, handle, reg):
"""
Reads a single 16 bit word from the specified register of the
- device associated with handle (smbus 2.0 5.5.5 - Read word).
+ device associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ smbus 2.0 5.5.5 - Read word.
+
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
...
@@ -1903,10 +1937,11 @@ class pi():
def i2c_process_call(self, handle, reg, word_val):
"""
Writes 16 bits of data to the specified register of the device
- associated with handle and reads 16 bits of data in return
- (smbus 2.0 5.5.6 - Process call).
+ associated with handle and reads 16 bits of data in return.
+
+ smbus 2.0 5.5.6 - Process call.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
word_val:= 0-65535, the value to write.
@@ -1927,9 +1962,11 @@ class pi():
def i2c_write_block_data(self, handle, reg, data):
"""
Writes up to 32 bytes to the specified register of the device
- associated with handle (smbus 2.0 5.5.7 - Block write).
+ associated with handle.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ smbus 2.0 5.5.7 - Block write.
+
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
data:= the bytes to write.
@@ -1957,9 +1994,11 @@ class pi():
def i2c_read_block_data(self, handle, reg):
"""
Reads a block of up to 32 bytes from the specified register of
- the device associated with handle (smbus 2.0 5.5.7 - Block read).
+ the device associated with handle.
+
+ smbus 2.0 5.5.7 - Block read.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
The amount of returned data is set by the device.
@@ -1986,10 +2025,11 @@ class pi():
"""
Writes data bytes to the specified register of the device
associated with handle and reads a device specified number
- of bytes of data in return (smbus 2.0 5.5.8 -
- Block write-block read).
+ of bytes of data in return.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ smbus 2.0 5.5.8 - Block write-block read.
+
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
data:= the bytes to write.
@@ -2028,7 +2068,7 @@ class pi():
Writes data bytes to the specified register of the device
associated with handle . 1-32 bytes may be written.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
data:= the bytes to write.
@@ -2058,7 +2098,7 @@ class pi():
Reads count bytes from the specified register of the device
associated with handle . The count may be 1-32.
- handle:= >=0 (as returned by a prior call to i2c_open).
+ handle:= >=0 (as returned by a prior call to [*i2c_open*]).
reg:= >=0, the device register.
count:= >0, the number of bytes to read.
@@ -2095,6 +2135,11 @@ class pi():
spi_baud:= >0, the transmission rate in bits per second.
spi_flags:= see below.
+ Normally you would only use the [*spi_**] functions if
+ you are or will be connecting to the Pi over a network. If
+ you will always run on the local Pi use the standard SPI
+ modules instead.
+
The bottom two bits of spi_flags define the SPI mode as
follows.
@@ -2129,7 +2174,7 @@ class pi():
"""
Closes the SPI device associated with handle.
- handle:= >=0 (as returned by a prior call to spi_open).
+ handle:= >=0 (as returned by a prior call to [*spi_open*]).
...
pi.spi_close(h)
@@ -2141,7 +2186,7 @@ class pi():
"""
Reads count bytes from the SPI device associated with handle.
- handle:= >=0 (as returned by a prior call to spi_open).
+ handle:= >=0 (as returned by a prior call to [*spi_open*]).
count:= >0, the number of bytes to read.
The returned value is a tuple of the number of bytes read and a
@@ -2167,7 +2212,7 @@ class pi():
"""
Writes the data bytes to the SPI device associated with handle.
- handle:= >=0 (as returned by a prior call to spi_open).
+ handle:= >=0 (as returned by a prior call to [*spi_open*]).
data:= the bytes to write.
...
@@ -2193,7 +2238,7 @@ class pi():
Writes the data bytes to the SPI device associated with handle,
returning the data bytes read from the device.
- handle:= >=0 (as returned by a prior call to spi_open).
+ handle:= >=0 (as returned by a prior call to [*spi_open*]).
data:= the bytes to write.
The returned value is a tuple of the number of bytes read and a
@@ -2231,6 +2276,11 @@ class pi():
ser_baud:= baud rate
ser_flags:= 0, no flags are currently defined.
+ Normally you would only use the [*serial_**] functions if
+ you are or will be connecting to the Pi over a network. If
+ you will always run on the local Pi use the standard serial
+ modules instead.
+
...
h1 = pi.serial_open("/dev/ttyAMA0", 300)
@@ -2249,7 +2299,7 @@ class pi():
"""
Closes the serial device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
...
pi.serial_close(h1)
@@ -2261,7 +2311,7 @@ class pi():
"""
Returns a single byte from the device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
...
b = pi.serial_read_byte(h1)
@@ -2273,7 +2323,7 @@ class pi():
"""
Writes a single byte to the device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
byte_val:= 0-255, the value to write.
...
@@ -2289,7 +2339,7 @@ class pi():
"""
Reads up to count bytes from the device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
count:= >0, the number of bytes to read.
The returned value is a tuple of the number of bytes read and a
@@ -2313,7 +2363,7 @@ class pi():
"""
Writes the data bytes to the device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
data:= the bytes to write.
...
@@ -2340,7 +2390,7 @@ class pi():
Returns the number of bytes available to be read from the
device associated with handle.
- handle:= >=0 (as returned by a prior call to serial_open).
+ handle:= >=0 (as returned by a prior call to [*serial_open*]).
...
rdy = pi.serial_data_available(h1)
@@ -2441,6 +2491,7 @@ class pi():
The run status may be
. .
+ PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
@@ -2510,7 +2561,7 @@ class pi():
"""
Returns data from the bit bang serial cyclic buffer.
- user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
+ user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*])
The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes. If there was an error the
@@ -2531,7 +2582,7 @@ class pi():
"""
Closes a gpio for bit bang reading of serial data.
- user_gpio:= 0-31 (opened in a prior call to bb_serial_read_open)
+ user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*])
...
status = pi.bb_serial_read_close(17)
@@ -2607,11 +2658,11 @@ class pi():
Grants access to a Pi's gpios.
host:= the host name of the Pi on which the pigpio daemon is
- running. The default is localhost unless overwritten by
+ running. The default is localhost unless overridden by
the PIGPIO_ADDR environment variable.
port:= the port number on which the pigpio daemon is listening.
- The default is 8888 unless overwritten by the PIGPIO_PORT
+ The default is 8888 unless overridden by the PIGPIO_PORT
environment variable. The pigpio daemon must have been
started with the same port number.
@@ -2637,9 +2688,13 @@ class pi():
self._control = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ # Disable the Nagle algorithm.
+ self._control.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+
try:
self._control.connect((self._host, self._port))
self._notify = _callback_thread(self._control, self._host, self._port)
+
except socket.error:
self.connected = False
if self._control is not None:
@@ -2648,8 +2703,11 @@ class pi():
h = "localhost"
else:
h = self._host
- errStr = "Can't connect to pigpio on " + str(h) + "(" + str(self._port) + ")"
- print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+
+ errStr = "Can't connect to pigpio on {}({})".format(
+ str(h), str(self._port))
+
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print(errStr)
print("")
print("Did you start the pigpio daemon? E.g. sudo pigpiod")
@@ -2660,7 +2718,7 @@ class pi():
print("")
print("Did you specify the correct Pi host/port in the")
print("pigpio.pi() function? E.g. pigpio.pi('soft', 8888))")
- print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
else:
atexit.register(self.stop)
@@ -2680,7 +2738,7 @@ class pi():
self._control.close()
self._control = None
-def variables():
+def xref():
"""
bb_baud: 100 - 250000
The baud rate used for the transmission of bit bang serial data.
@@ -2710,13 +2768,17 @@ def variables():
The length of a pulse in microseconds.
dutycycle: 0-range_
- A number between 0 and range_. The dutycycle sets the
- proportion of on time versus off time duting each PWM
- cycle.
+ A number between 0 and range_.
- 0 is off.
- range_ / 2 is 50% on.
- range_ is fully on.
+ The dutycycle sets the proportion of time on versus time off during each
+ PWM cycle.
+
+ Dutycycle @ On time
+ 0 @ Off
+ range_ * 0.25 @ 25% On
+ range_ * 0.50 @ 50% On
+ range_ * 0.75 @ 75% On
+ range_ @ Fully On
edge: 0-2
EITHER_EDGE = 2
@@ -2812,16 +2874,15 @@ def variables():
of a pulse.
handle: 0-
- A number referencing an object opened by one of
-
- [*i2c_open*]
- [*notify_open*]
- [*serial_open*]
- [*spi_open*]
+ A number referencing an object opened by one of [*i2c_open*],
+ [*notify_open*], [*serial_open*], [*spi_open*].
host:
The name or IP address of the Pi running the pigpio daemon.
+ i2c_*:
+ One of the i2c_ functions.
+
i2c_address:
The address of a device on the I2C bus (0x08 - 0x77)
@@ -2870,16 +2931,19 @@ def variables():
A whole number.
pulses:
+ A list of class pulse objects defining the characteristics of a
+ waveform.
pulsewidth:
The servo pulsewidth in microseconds. 0 switches pulses off.
range_: 25-40000
Defines the limits for the [*dutycycle*] parameter.
- range_ defaults tpo 255.
+
+ range_ defaults to 255.
reg: 0-255
- An I2C devive register. The usable registers depend on the
+ An I2C device register. The usable registers depend on the
actual device.
script:
@@ -2889,14 +2953,21 @@ def variables():
A number referencing a script created by [*store_script*].
ser_baud:
- The transmission rate in bits per second. The default
- allowable values are 50, 75, 110, 134, 150, 200, 300,
+ The transmission rate in bits per second.
+
+ The allowable values are 50, 75, 110, 134, 150, 200, 300,
600, 1200, 1800, 2400, 4800, 9600, 19200, 38400,
57600, 115200, or 230400.
ser_flags: 32 bit
No serial flags are currently defined.
+ serial_*:
+ One of the serial_ functions.
+
+ spi_*:
+ One of the spi_ functions.
+
spi_baud: 1-
The transmission rate in bits per second.
@@ -2916,16 +2987,25 @@ def variables():
A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0
user_gpio: 0-31
- A Broadcom numbered gpio. All the user gpios are in the range 0-31.
+ A Broadcom numbered gpio.
+
+ All the user gpios are in the range 0-31.
+
Not all the gpios within this range are usable, some are reserved
for system use.
wait_timeout: 0.0 -
The number of seconds to wait in wait_for_edge before timing out.
+ wave_add_*:
+ One of [*wave_add_new*] , [*wave_add_generic*], [*wave_add_serial*].
+
wave_id: 0-
A number referencing a wave created by [*wave_create*].
+ wave_send_*:
+ One of [*wave_send_once*], [*wave_send_repeat*].
+
wdog_timeout: 0-60000
Defines a gpio watchdog timeout in milliseconds. If no level
change is detected on the gpio for timeout millisecond a watchdog
diff --git a/pigpiod.1 b/pigpiod.1
new file mode 100644
index 0000000..72b4c55
--- /dev/null
+++ b/pigpiod.1
@@ -0,0 +1,179 @@
+
+." Process this file with
+." groff -man -Tascii pigpiod.1
+."
+.TH pigpiod 1 2012-2014 Linux "pigpio archive"
+.SH NAME
+pigpiod - A utility to start the pigpio library as a daemon.
+
+.SH SYNOPSIS
+
+sudo pigpiod [OPTION]...
+.SH DESCRIPTION
+
+pigpiod is a utility which launches the pigpio library as a daemon.
+.br
+
+.br
+Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.
+.br
+
+.br
+The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.
+.br
+
+.br
+pigpiod accepts the following configuration options
+.br
+
+.br
+.SH OPTIONS
+
+.IP "\fB-b value\fP"
+gpio sample buffer in milliseconds
+100-10000
+default 120
+
+.IP "\fB-d value\fP"
+primary DMA channel
+0-14
+default 14
+
+.IP "\fB-e value\fP"
+secondary DMA channel
+0-6
+default 5
+
+.IP "\fB-f\fP"
+disable fifo interface
+
+default enabled
+
+.IP "\fB-k\fP"
+disable socket interface
+
+default enabled
+
+.IP "\fB-p value\fP"
+socket port
+1024-32000
+default 8888
+
+.IP "\fB-s value\fP"
+sample rate
+1, 2, 4, 5, 8, 10
+default 5
+
+.IP "\fB-t value\fP"
+clock peripheral
+0=PWM 1=PCM
+default PCM
+
+.IP "\fB-u value\fP"
+clock source
+0=OSC 1=PLLD
+default PLLD
+
+.IP "\fB-x mask\fP"
+gpios which may be updated
+A 54 bit mask with (1<<n) set if the user may update gpio #n.
+default is the set of user gpios for the board revision
+
+.br
+
+.br
+.SS Example
+.br
+
+.br
+
+.EX
+sudo pigpiod -s 2 -b 200 -f
+.br
+
+.EE
+
+.br
+
+.br
+Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface.
+
+.br
+
+.br
+.SS Permissions
+.br
+
+.br
+pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces.
+
+.br
+
+.br
+All gpios may be read.
+
+.br
+
+.br
+Only the default gpios for the board revision or those specified by the -x option may be updated.
+
+.br
+
+.br
+
+.EX
+Revision 1 boards 0x03E6CF93
+.br
+Revision 2 boards 0xFBC6CF9C
+.br
+Revision 3 boards 0x0FFFFFFC
+.br
+
+.EE
+
+.br
+
+.br
+In this context an update includes the following:
+
+.br
+
+.br
+gpio mode set
+.br
+gpio pull/up down
+.br
+gpio write
+.br
+gpio set PWM (including range and frequency)
+.br
+gpio set servo
+
+.br
+
+.br
+In addition the bank clear and set commands, and the wave commands will only
+affect updateable gpios.
+
+.br
+
+.br
+There are two special cases.
+
+.br
+
+.br
+The activity LED may be written (gpio 16 for Rev.1/2
+boards, gpio 47 for Rev.3 boards).
+
+.br
+
+.br
+The high USB power mode gpio may be written (gpio 38 for Rev.3 boards).
+
+.SH SEE ALSO
+
+pig2vcd(1), pigs(1), pigpio(3), pigpiod_if(3)
+.SH AUTHOR
+
+joan@abyz.co.uk
diff --git a/pigpiod.c b/pigpiod.c
index 2a8b9f2..69a5dbf 100644
--- a/pigpiod.c
+++ b/pigpiod.c
@@ -92,7 +92,7 @@ void usage()
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
" -u value, clock source, 0=OSC 1=PLLD, default PLLD\n" \
- " -x mask, gpios which may be updated, default 0xFFFFFFFF\n" \
+ " -x mask, gpios which may be updated, default board user gpios\n" \
"EXAMPLE\n" \
"sudo pigpiod -s 2 -b 200 -f\n" \
" Set a sample rate of 2 microseconds with a 200 millisecond\n" \
@@ -184,7 +184,6 @@ static void initOpts(int argc, char *argv[])
case 'x':
mask = strtoll(optarg, &endptr, 0);
- printf("mask=%llx\n", mask);
if (!*endptr)
{
updateMask = mask;
diff --git a/pigpiod_if.3 b/pigpiod_if.3
new file mode 100644
index 0000000..5fa5c23
--- /dev/null
+++ b/pigpiod_if.3
@@ -0,0 +1,3345 @@
+
+." Process this file with
+." groff -man -Tascii pigpiod_if.3
+."
+.TH pigpiod_if 3 2012-2014 Linux "pigpio archive"
+.SH NAME
+pigpiod_if - A C library to interface to the pigpio daemon.
+
+.SH SYNOPSIS
+
+gcc -o prog prog.c -lpigpiod_if
+
+ ./prog
+.SH DESCRIPTION
+
+
+.br
+
+.br
+pigpiod_if is a C library for the Raspberry which allows control
+of the gpios via the socket interface to the pigpio daemon.
+.br
+
+.br
+
+.br
+.SS Features
+.br
+
+.br
+o PWM on any of gpios 0-31
+
+.br
+
+.br
+o servo pulses on any of gpios 0-31
+
+.br
+
+.br
+o callbacks when any of gpios 0-31 change state
+
+.br
+
+.br
+o callbacks at timed intervals
+
+.br
+
+.br
+o reading/writing all of the gpios in a bank as one operation
+
+.br
+
+.br
+o individually setting gpio modes, reading and writing
+
+.br
+
+.br
+o notifications when any of gpios 0-31 change state
+
+.br
+
+.br
+o the construction of output waveforms with microsecond timing
+
+.br
+
+.br
+o rudimentary permission control over gpios
+
+.br
+
+.br
+o a simple interface to start and stop new threads
+
+.br
+
+.br
+o I2C, SPI, and serial link wrappers
+
+.br
+
+.br
+o creating and running scripts on the pigpio daemon
+
+.br
+
+.br
+.SS gpios
+.br
+
+.br
+ALL gpios are identified by their Broadcom number.
+
+.br
+
+.br
+.SS Notes
+.br
+
+.br
+The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals.
+
+.br
+
+.br
+.SH FUNCTIONS
+
+.IP "\fBdouble time_time(void)\fP"
+.IP "" 4
+Return the current time in seconds since the Epoch.
+
+.IP "\fBvoid time_sleep(double seconds)\fP"
+.IP "" 4
+Delay execution for a given number of seconds.
+
+.br
+
+.br
+
+.EX
+seconds: the number of seconds to delay.
+.br
+
+.EE
+
+.IP "\fBchar *pigpio_error(int errnum)\fP"
+.IP "" 4
+Return a text description for an error code.
+
+.br
+
+.br
+
+.EX
+errnum: the error code.
+.br
+
+.EE
+
+.IP "\fBunsigned pigpiod_if_version(void)\fP"
+.IP "" 4
+Return the pigpiod_if version.
+
+.IP "\fBpthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata)\fP"
+.IP "" 4
+Starts a new thread of execution with thread_func as the main routine.
+
+.br
+
+.br
+
+.EX
+thread_func: the main function for the new thread.
+.br
+ userdata: a pointer to an arbitrary argument.
+.br
+
+.EE
+
+.br
+
+.br
+Returns a pointer to pthread_t if OK, otherwise NULL.
+
+.br
+
+.br
+The function is passed the single argument userdata.
+
+.br
+
+.br
+The thread can be cancelled by passing the pointer to pthread_t to
+\fBstop_thread\fP.
+
+.IP "\fBvoid stop_thread(pthread_t *pth)\fP"
+.IP "" 4
+Cancels the thread pointed at by pth.
+
+.br
+
+.br
+
+.EX
+pth: the thread to be stopped.
+.br
+
+.EE
+
+.br
+
+.br
+No value is returned.
+
+.br
+
+.br
+The thread to be stopped should have been started with \fBstart_thread\fP.
+
+.IP "\fBint pigpio_start(char *addrStr, char *portStr)\fP"
+.IP "" 4
+Connect to the pigpio daemon. Reserving command and
+notification streams.
+
+.br
+
+.br
+
+.EX
+addrStr: specifies the host or IP address of the Pi running the
+.br
+ pigpio daemon. It may be NULL in which case localhost
+.br
+ is used unless overridden by the PIGPIO_ADDR environment
+.br
+ variable.
+.br
+
+.br
+portStr: specifies the port address used by the Pi running the
+.br
+ pigpio daemon. It may be NULL in which case "8888"
+.br
+ is used unless overridden by the PIGPIO_PORT environment
+.br
+ variable.
+.br
+
+.EE
+
+.IP "\fBvoid pigpio_stop(void)\fP"
+.IP "" 4
+Terminates the connection to the pigpio daemon and releases
+resources used by the library.
+
+.IP "\fBint set_mode(unsigned gpio, unsigned mode)\fP"
+.IP "" 4
+Set the gpio mode.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53.
+.br
+mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1,
+.br
+ PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
+or PI_NOT_PERMITTED.
+
+.IP "\fBint get_mode(unsigned gpio)\fP"
+.IP "" 4
+Get the gpio mode.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
+
+.IP "\fBint set_pull_up_down(unsigned gpio, unsigned pud)\fP"
+.IP "" 4
+Set or clear the gpio pull-up/down resistor.
+
+.br
+
+.br
+
+.EX
+gpio: 0-53.
+.br
+ pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
+or PI_NOT_PERMITTED.
+
+.IP "\fBint gpio_read(unsigned gpio)\fP"
+.IP "" 4
+Read the gpio level.
+
+.br
+
+.br
+
+.EX
+gpio:0-53.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the gpio level if OK, otherwise PI_BAD_GPIO.
+
+.IP "\fBint gpio_write(unsigned gpio, unsigned level)\fP"
+.IP "" 4
+Write the gpio level.
+
+.br
+
+.br
+
+.EX
+ gpio: 0-53.
+.br
+level: 0, 1.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
+or PI_NOT_PERMITTED.
+
+.br
+
+.br
+Notes
+
+.br
+
+.br
+If PWM or servo pulses are active on the gpio they are switched off.
+
+.IP "\fBint set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)\fP"
+.IP "" 4
+Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+dutycycle: 0-range (range defaults to 255).
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
+or PI_NOT_PERMITTED.
+Notes
+
+.br
+
+.br
+The \fBset_PWM_range\fP function may be used to change the
+default range of 255.
+
+.IP "\fBint set_PWM_range(unsigned user_gpio, unsigned range)\fP"
+.IP "" 4
+Set the range of PWM values to be used on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ range: 25-40000.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
+or PI_NOT_PERMITTED.
+
+.br
+
+.br
+Notes
+
+.br
+
+.br
+If PWM is currently active on the gpio its dutycycle will be
+scaled to reflect the new range.
+
+.br
+
+.br
+The real range, the number of steps between fully off and fully on
+for each of the 18 available gpio frequencies is
+
+.br
+
+.br
+
+.EX
+ 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6),
+.br
+ 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12),
+.br
+2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
+.br
+
+.EE
+
+.br
+
+.br
+The real value set by set_PWM_range is (dutycycle * real range) / range.
+
+.IP "\fBint get_PWM_range(unsigned user_gpio)\fP"
+.IP "" 4
+Get the range of PWM values being used on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the dutycycle range used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+
+.IP "\fBint get_PWM_real_range(unsigned user_gpio)\fP"
+.IP "" 4
+Get the real underlying range of PWM values being used on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the real range used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+
+.IP "\fBint set_PWM_frequency(unsigned user_gpio, unsigned frequency)\fP"
+.IP "" 4
+Set the frequency (in Hz) of the PWM to be used on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+frequency: 0- (Hz).
+.br
+
+.EE
+
+.br
+
+.br
+Returns the numerically closest frequency if OK, otherwise
+PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
+
+.br
+
+.br
+The selectable frequencies depend upon the sample rate which
+may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
+sample rate is set when the C pigpio library is started.
+
+.br
+
+.br
+Each gpio can be independently set to one of 18 different
+PWM frequencies.
+
+.br
+
+.br
+If PWM is currently active on the gpio it will be switched
+off and then back on at the new frequency.
+
+.br
+
+.br
+
+.EX
+1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600,
+.br
+ 1250, 1000, 800, 500, 400, 250, 200, 100, 50
+.br
+
+.br
+2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800,
+.br
+ 625, 500, 400, 250, 200, 125, 100, 50 , 25
+.br
+
+.br
+4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400,
+.br
+ 313, 250, 200, 125, 100, 63, 50, 25, 13
+.br
+
+.br
+5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320,
+.br
+ 250, 200, 160, 100 , 80, 50, 40, 20, 10
+.br
+
+.br
+8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200,
+.br
+ 156, 125, 100, 63, 50, 31, 25, 13, 6
+.br
+
+.br
+10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160,
+.br
+ 125, 100, 80, 50, 40, 25, 20, 10, 5
+.br
+
+.EE
+
+.IP "\fBint get_PWM_frequency(unsigned user_gpio)\fP"
+.IP "" 4
+Get the frequency of PWM being used on the gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the frequency (in hertz) used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+
+.IP "\fBint set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)\fP"
+.IP "" 4
+Start (500-2500) or stop (0) servo pulses on the gpio.
+
+.br
+
+.br
+
+.EX
+ user_gpio: 0-31.
+.br
+pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
+PI_NOT_PERMITTED.
+
+.br
+
+.br
+The selected pulsewidth will continue to be transmitted until
+changed by a subsequent call to set_servo_pulsewidth.
+
+.br
+
+.br
+The pulsewidths supported by servos varies and should probably be
+determined by experiment. A value of 1500 should always be safe and
+represents the mid-point of rotation.
+
+.br
+
+.br
+You can DAMAGE a servo if you command it to move beyond its limits.
+
+.br
+
+.br
+OTHER UPDATE RATES:
+
+.br
+
+.br
+This function updates servos at 50Hz. If you wish to use a different
+update frequency you will have to use the PWM functions.
+
+.br
+
+.br
+
+.EX
+Update Rate (Hz) 50 100 200 400 500
+.br
+1E6/Hz 20000 10000 5000 2500 2000
+.br
+
+.EE
+
+.br
+
+.br
+Firstly set the desired PWM frequency using \fBset_PWM_frequency\fP.
+
+.br
+
+.br
+Then set the PWM range using \fBset_PWM_range\fP to 1E6/Hz.
+Doing this allows you to use units of microseconds when setting
+the servo pulse width.
+
+.br
+
+.br
+E.g. If you want to update a servo connected to gpio 25 at 400Hz
+
+.br
+
+.br
+
+.EX
+set_PWM_frequency(25, 400);
+.br
+set_PWM_range(25, 2500);
+.br
+
+.EE
+
+.br
+
+.br
+Thereafter use the \fBset_PWM_dutycycle\fP function to move the servo,
+e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+.br
+
+.IP "\fBint notify_open(void)\fP"
+.IP "" 4
+Get a free notification handle.
+
+.br
+
+.br
+Returns a handle greater than or equal to zero if OK,
+otherwise PI_NO_HANDLE.
+
+.br
+
+.br
+A notification is a method for being notified of gpio state
+changes via a pipe.
+
+.br
+
+.br
+Pipes are only accessible from the local machine so this function
+serves no purpose if you are using the library from a remote machine.
+The in-built (socket) notifications provided by \fBcallback\fP
+should be used instead.
+
+.br
+
+.br
+Notifications for handle x will be available at the pipe
+named /dev/pigpiox (where x is the handle number).
+E.g. if the function returns 15 then the notifications must be
+read from /dev/pigpio15.
+
+.IP "\fBint notify_begin(unsigned handle, uint32_t bits)\fP"
+.IP "" 4
+Start notifications on a previously opened handle.
+
+.br
+
+.br
+
+.EX
+handle: 0-31 (as returned by \fBnotify_open\fP)
+.br
+ bits: a mask indicating the gpios to be notified.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.br
+
+.br
+The notification sends state changes for each gpio whose
+corresponding bit in bits is set.
+
+.br
+
+.br
+Notes
+
+.br
+
+.br
+Each notification occupies 12 bytes in the fifo as follows:
+
+.br
+
+.br
+
+.EX
+H (16 bit) seqno
+.br
+H (16 bit) flags
+.br
+I (32 bit) tick
+.br
+I (32 bit) level
+.br
+
+.EE
+
+.IP "\fBint notify_pause(unsigned handle)\fP"
+.IP "" 4
+Pause notifications on a previously opened handle.
+
+.br
+
+.br
+
+.EX
+handle: 0-31 (as returned by \fBnotify_open\fP)
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.br
+
+.br
+Notifications for the handle are suspended until
+\fBnotify_begin\fP is called again.
+
+.IP "\fBint notify_close(unsigned handle)\fP"
+.IP "" 4
+Stop notifications on a previously opened handle and
+release the handle for reuse.
+
+.br
+
+.br
+
+.EX
+handle: 0-31 (as returned by \fBnotify_open\fP)
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint set_watchdog(unsigned user_gpio, unsigned timeout)\fP"
+.IP "" 4
+Sets a watchdog for a gpio.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ timeout: 0-60000.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO
+or PI_BAD_WDOG_TIMEOUT.
+
+.br
+
+.br
+The watchdog is nominally in milliseconds.
+
+.br
+
+.br
+Only one watchdog may be registered per gpio.
+
+.br
+
+.br
+The watchdog may be cancelled by setting timeout to 0.
+
+.br
+
+.br
+If no level change has been detected for the gpio for timeout
+milliseconds any notification for the gpio has a report written
+to the fifo with the flags set to indicate a watchdog timeout.
+
+.br
+
+.br
+The \fBcallback\fP and \fBcallback_ex\fP functions interpret the flags
+and will call registered callbacks for the gpio with level TIMEOUT.
+
+.IP "\fBuint32_t read_bank_1(void)\fP"
+.IP "" 4
+Read the levels of the bank 1 gpios (gpios 0-31).
+
+.br
+
+.br
+The returned 32 bit integer has a bit set if the corresponding
+gpio is logic 1. Gpio n has bit value (1<<n).
+
+.IP "\fBuint32_t read_bank_2(void)\fP"
+.IP "" 4
+Read the levels of the bank 2 gpios (gpios 32-53).
+
+.br
+
+.br
+The returned 32 bit integer has a bit set if the corresponding
+gpio is logic 1. Gpio n has bit value (1<<(n-32)).
+
+.IP "\fBint clear_bank_1(uint32_t bits)\fP"
+.IP "" 4
+Clears gpios 0-31 if the corresponding bit in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask with 1 set if the corresponding gpio is
+.br
+ to be cleared.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+
+.br
+
+.br
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+
+.IP "\fBint clear_bank_2(uint32_t bits)\fP"
+.IP "" 4
+Clears gpios 32-53 if the corresponding bit (0-21) in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask with 1 set if the corresponding gpio is
+.br
+ to be cleared.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+
+.br
+
+.br
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+
+.IP "\fBint set_bank_1(uint32_t bits)\fP"
+.IP "" 4
+Sets gpios 0-31 if the corresponding bit in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask with 1 set if the corresponding gpio is
+.br
+ to be set.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+
+.br
+
+.br
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+
+.IP "\fBint set_bank_2(uint32_t bits)\fP"
+.IP "" 4
+Sets gpios 32-53 if the corresponding bit (0-21) in bits is set.
+
+.br
+
+.br
+
+.EX
+bits: a bit mask with 1 set if the corresponding gpio is
+.br
+ to be set.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+
+.br
+
+.br
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+
+.IP "\fBuint32_t get_current_tick(void)\fP"
+.IP "" 4
+Gets the current system tick.
+
+.br
+
+.br
+Tick is the number of microseconds since system boot.
+
+.br
+
+.br
+As tick is an unsigned 32 bit quantity it wraps around after
+2**32 microseconds, which is approximately 1 hour 12 minutes.
+
+.br
+
+.br
+
+.IP "\fBuint32_t get_hardware_revision(void)\fP"
+.IP "" 4
+Get the Pi's hardware revision number.
+
+.br
+
+.br
+The hardware revision is the last 4 characters on the Revision line
+of /proc/cpuinfo.
+
+.br
+
+.br
+If the hardware revision can not be found or is not a valid
+hexadecimal number the function returns 0.
+
+.br
+
+.br
+The revision number can be used to determine the assignment of gpios
+to pins.
+
+.br
+
+.br
+There are currently three types of board.
+
+.br
+
+.br
+Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
+
+.br
+
+.br
+Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
+gpios 28-31 on P5.
+
+.br
+
+.br
+Type 3 has a 40 pin connector rather than the 26 pin connector of
+the earlier boards. Gpios 0 to 27 are brought out to the connector.
+
+.br
+
+.br
+Type 1 boards have hardware revision numbers of 2 and 3.
+
+.br
+
+.br
+Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+
+.br
+
+.br
+Type 3 boards have hardware revision number 16.
+
+.IP "\fBuint32_t get_pigpio_version(void)\fP"
+.IP "" 4
+Returns the pigpio version.
+
+.IP "\fBint wave_clear(void)\fP"
+.IP "" 4
+This function clears all waveforms and any data added by calls to the
+\fBwave_add_*\fP functions.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.IP "\fBint wave_add_new(void)\fP"
+.IP "" 4
+This function starts a new empty waveform. You wouldn't normally need
+to call this function as it is automatically called after a waveform is
+created with the \fBwave_create\fP function.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.IP "\fBint wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)\fP"
+.IP "" 4
+This function adds a number of pulses to the current waveform.
+
+.br
+
+.br
+
+.EX
+numPulses: the number of pulses.
+.br
+ pulses: an array of pulses.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+The pulses are interleaved in time order within the existing waveform
+(if any).
+
+.br
+
+.br
+Merging allows the waveform to be built in parts, that is the settings
+for gpio#1 can be added, and then gpio#2 etc.
+
+.br
+
+.br
+If the added waveform is intended to start after or within the existing
+waveform then the first pulse should consist solely of a delay.
+
+.IP "\fBint wave_add_serial(unsigned user_gpio, unsigned bbBaud, unsigned offset, unsigned numChar, char *str)\fP"
+.IP "" 4
+This function adds a waveform representing serial data to the
+existing waveform (if any). The serial data starts offset microseconds
+from the start of the waveform.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ bbBaud: 100-250000
+.br
+ offset: 0-
+.br
+ numChar: 1-
+.br
+ str: an array of chars.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS, or
+PI_TOO_MANY_PULSES.
+
+.br
+
+.br
+NOTES:
+
+.br
+
+.br
+The serial data is formatted as one start bit, eight data bits, and one
+stop bit.
+
+.br
+
+.br
+It is legal to add serial data streams with different baud rates to
+the same waveform.
+
+.IP "\fBint wave_create(void)\fP"
+.IP "" 4
+This function creates a waveform from the data provided by the prior
+calls to the \fBwave_add_*\fP functions. Upon success a positive wave id
+is returned.
+
+.br
+
+.br
+The data provided by the \fBwave_add_*\fP functions is consumed by this
+function.
+
+.br
+
+.br
+As many waveforms may be created as there is space available. The
+wave id is passed to \fBwave_send_*\fP to specify the waveform to transmit.
+
+.br
+
+.br
+Normal usage would be
+
+.br
+
+.br
+Step 1. \fBwave_clear\fP to clear all waveforms and added data.
+
+.br
+
+.br
+Step 2. \fBwave_add_*\fP calls to supply the waveform data.
+
+.br
+
+.br
+Step 3. \fBwave_create\fP to create the waveform and get a unique id
+
+.br
+
+.br
+Repeat steps 2 and 3 as needed.
+
+.br
+
+.br
+Step 4. \fBwave_send_*\fP with the id of the waveform to transmit.
+
+.br
+
+.br
+A waveform comprises one or more pulses. Each pulse consists of a
+\fBgpioPulse_t\fP structure.
+
+.br
+
+.br
+
+.EX
+typedef struct
+.br
+{
+.br
+ uint32_t gpioOn;
+.br
+ uint32_t gpioOff;
+.br
+ uint32_t usDelay;
+.br
+} gpioPulse_t;
+.br
+
+.EE
+
+.br
+
+.br
+The fields specify
+
+.br
+
+.br
+1) the gpios to be switched on at the start of the pulse.
+.br
+2) the gpios to be switched off at the start of the pulse.
+.br
+3) the delay in microseconds before the next pulse.
+.br
+
+.br
+
+.br
+Any or all the fields can be zero. It doesn't make any sense to
+set all the fields to zero (the pulse will be ignored).
+
+.br
+
+.br
+When a waveform is started each pulse is executed in order with the
+specified delay between the pulse and the next.
+
+.br
+
+.br
+Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
+PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
+
+.IP "\fBint wave_delete(unsigned wave_id)\fP"
+.IP "" 4
+This function deletes all created waveforms with ids greater than or
+equal to wave_id.
+
+.br
+
+.br
+
+.EX
+wave_id: >=0, as returned by \fBwave_create\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Wave ids are allocated in order, 0, 1, 2, etc.
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
+
+.IP "\fBint wave_tx_start(void)\fP"
+.IP "" 4
+This function is deprecated and should no longer be used. Use
+\fBwave_create\fP/\fBwave_send_*\fP instead.
+
+.IP "\fBint wave_tx_repeat(void)\fP"
+.IP "" 4
+This function is deprecated and should no longer be used. Use
+\fBwave_create\fP/\fBwave_send_*\fP instead.
+
+.IP "\fBint wave_send_once(unsigned wave_id)\fP"
+.IP "" 4
+This function transmits the waveform with id wave_id. The waveform
+is sent once.
+
+.br
+
+.br
+
+.EX
+wave_id: >=0, as returned by \fBwave_create\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
+
+.IP "\fBint wave_send_repeat(unsigned wave_id)\fP"
+.IP "" 4
+This function transmits the waveform with id wave_id. The waveform
+cycles until cancelled (either by the sending of a new waveform or
+by \fBwave_tx_stop\fP).
+
+.br
+
+.br
+
+.EX
+wave_id: >=0, as returned by \fBwave_create\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
+
+.IP "\fBint wave_tx_busy(void)\fP"
+.IP "" 4
+This function checks to see if a waveform is currently being
+transmitted.
+
+.br
+
+.br
+Returns 1 if a waveform is currently being transmitted, otherwise 0.
+
+.IP "\fBint wave_tx_stop(void)\fP"
+.IP "" 4
+This function stops the transmission of the current waveform.
+
+.br
+
+.br
+Returns 0 if OK.
+
+.br
+
+.br
+This function is intended to stop a waveform started with the repeat mode.
+
+.IP "\fBint wave_get_micros(void)\fP"
+.IP "" 4
+This function returns the length in microseconds of the current
+waveform.
+
+.IP "\fBint wave_get_high_micros(void)\fP"
+.IP "" 4
+This function returns the length in microseconds of the longest waveform
+created since the pigpio daemon was started.
+
+.IP "\fBint wave_get_max_micros(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in
+.br
+microseconds.
+
+.IP "\fBint wave_get_pulses(void)\fP"
+.IP "" 4
+This function returns the length in pulses of the current waveform.
+
+.IP "\fBint wave_get_high_pulses(void)\fP"
+.IP "" 4
+This function returns the length in pulses of the longest waveform
+created since the pigpio daemon was started.
+
+.IP "\fBint wave_get_max_pulses(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in pulses.
+
+.IP "\fBint wave_get_cbs(void)\fP"
+.IP "" 4
+This function returns the length in DMA control blocks of the current
+waveform.
+
+.IP "\fBint wave_get_high_cbs(void)\fP"
+.IP "" 4
+This function returns the length in DMA control blocks of the longest
+waveform created since the pigpio daemon was started.
+
+.IP "\fBint wave_get_max_cbs(void)\fP"
+.IP "" 4
+This function returns the maximum possible size of a waveform in DMA
+control blocks.
+
+.IP "\fBint gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP"
+.IP "" 4
+This function sends a trigger pulse to a gpio. The gpio is set to
+level for pulseLen microseconds and then reset to not level.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ pulseLen: 1-50.
+.br
+ level: 0,1.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
+PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
+
+.IP "\fBint store_script(char *script)\fP"
+.IP "" 4
+This function stores a script for later execution.
+
+.br
+
+.br
+
+.EX
+script: the text of the script.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns a script id if the script is valid,
+otherwise PI_BAD_SCRIPT.
+
+.IP "\fBint run_script(unsigned script_id, unsigned numPar, uint32_t *param)\fP"
+.IP "" 4
+This function runs a stored script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBstore_script\fP.
+.br
+ numPar: 0-10, the number of parameters.
+.br
+ param: an array of parameters.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM
+
+.br
+
+.br
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+
+.IP "\fBint script_status(unsigned script_id, uint32_t *param)\fP"
+.IP "" 4
+This function returns the run status of a stored script as well
+as the current values of parameters 0 to 9.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBstore_script\fP.
+.br
+ param: an array to hold the returned 10 parameters.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns greater than or equal to 0 if OK,
+otherwise PI_BAD_SCRIPT_ID.
+
+.br
+
+.br
+The run status may be
+
+.br
+
+.br
+
+.EX
+PI_SCRIPT_INITING
+.br
+PI_SCRIPT_HALTED
+.br
+PI_SCRIPT_RUNNING
+.br
+PI_SCRIPT_WAITING
+.br
+PI_SCRIPT_FAILED
+.br
+
+.EE
+
+.br
+
+.br
+The current value of script parameters 0 to 9 are returned in param.
+
+.IP "\fBint stop_script(unsigned script_id)\fP"
+.IP "" 4
+This function stops a running script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBstore_script\fP.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+
+.IP "\fBint delete_script(unsigned script_id)\fP"
+.IP "" 4
+This function deletes a stored script.
+
+.br
+
+.br
+
+.EX
+script_id: >=0, as returned by \fBstore_script\fP.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+
+.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned bbBaud)\fP"
+.IP "" 4
+This function opens a gpio for bit bang reading of serial data.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ bbBaud: 100-250000
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
+or PI_GPIO_IN_USE.
+
+.br
+
+.br
+The serial data is returned in a cyclic buffer and is read using
+bb_serial_read.
+
+.br
+
+.br
+It is the caller's responsibility to read data from the cyclic buffer
+in a timely fashion.
+
+.IP "\fBint bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)\fP"
+.IP "" 4
+This function copies up to bufSize bytes of data read from the
+bit bang serial cyclic buffer to the buffer starting at buf.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP.
+.br
+ buf: an array to receive the read bytes.
+.br
+ bufSize: 0-
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
+or PI_NOT_SERIAL_GPIO.
+
+.IP "\fBint bb_serial_read_close(unsigned user_gpio)\fP"
+.IP "" 4
+This function closes a gpio for bit bang reading of serial data.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
+
+.IP "\fBint i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)\fP"
+.IP "" 4
+This returns a handle for the device at address i2c_addr on bus i2c_bus.
+
+.br
+
+.br
+
+.EX
+ i2c_bus: 0-1.
+.br
+ i2c_addr: 0x08-0x77.
+.br
+i2c_flags: 0.
+.br
+
+.EE
+
+.br
+
+.br
+No flags are currently defined. This parameter should be set to zero.
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
+PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
+
+.IP "\fBint i2c_close(unsigned handle)\fP"
+.IP "" 4
+This closes the I2C device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint i2c_read_device(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This reads count bytes from the raw device into buf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+ buf: an array to receive the read data bytes.
+.br
+ count: >0, the number of bytes to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_READ_FAILED.
+
+.IP "\fBint i2c_write_device(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes count bytes from buf to the raw device.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+ buf: an array containing the data bytes to write.
+.br
+ count: >0, the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.IP "\fBint i2c_write_quick(unsigned handle, unsigned bit)\fP"
+.IP "" 4
+This sends a single bit (in the Rd/Wr bit) to the device associated
+with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+ bit: 0-1, the value to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Quick command. smbus 2.0 5.5.1
+
+.IP "\fBint i2c_write_byte(unsigned handle, unsigned bVal)\fP"
+.IP "" 4
+This sends a single byte to the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+ bVal: 0-0xFF, the value to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Send byte. smbus 2.0 5.5.2
+
+.IP "\fBint i2c_read_byte(unsigned handle)\fP"
+.IP "" 4
+This reads a single byte from the device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Receive byte. smbus 2.0 5.5.3
+
+.IP "\fBint i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal)\fP"
+.IP "" 4
+This writes a single byte to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write.
+.br
+ bVal: 0-0xFF, the value to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Write byte. smbus 2.0 5.5.4
+
+.IP "\fBint i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP"
+.IP "" 4
+This writes a single 16 bit word to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write.
+.br
+ wVal: 0-0xFFFF, the value to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Write word. smbus 2.0 5.5.4
+
+.IP "\fBint i2c_read_byte_data(unsigned handle, unsigned i2c_reg)\fP"
+.IP "" 4
+This reads a single byte from the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Read byte. smbus 2.0 5.5.5
+
+.IP "\fBint i2c_read_word_data(unsigned handle, unsigned i2c_reg)\fP"
+.IP "" 4
+This reads a single 16 bit word from the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Read word. smbus 2.0 5.5.5
+
+.IP "\fBint i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal)\fP"
+.IP "" 4
+This writes 16 bits of data to the specified register of the device
+associated with handle and and reads 16 bits of data in return.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write/read.
+.br
+ wVal: 0-0xFFFF, the value to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Process call. smbus 2.0 5.5.6
+
+.IP "\fBint i2c_write_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes up to 32 bytes to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write.
+.br
+ buf: an array with the data to send.
+.br
+ count: 1-32, the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.br
+
+.br
+Block write. smbus 2.0 5.5.7
+
+.IP "\fBint i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf)\fP"
+.IP "" 4
+This reads a block of up to 32 bytes from the specified register of
+the device associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to read.
+.br
+ buf: an array to receive the read data.
+.br
+
+.EE
+
+.br
+
+.br
+The amount of returned data is set by the device.
+
+.br
+
+.br
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+Block read. smbus 2.0 5.5.7
+
+.IP "\fBint i2c_block_process_call(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes data bytes to the specified register of the device
+associated with handle and reads a device specified number
+of bytes of data in return.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write/read.
+.br
+ buf: an array with the data to send and to receive the read data.
+.br
+ count: 1-32, the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+
+.br
+
+.br
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.br
+
+.br
+The smbus 2.0 documentation states that a minimum of 1 byte may be
+sent and a minimum of 1 byte may be received. The total number of
+bytes sent/received must be 32 or less.
+
+.br
+
+.br
+Block write-block read. smbus 2.0 5.5.8
+
+.IP "\fBint i2c_read_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP"
+.IP "" 4
+This reads count bytes from the specified register of the device
+associated with handle . The count may be 1-32.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to read.
+.br
+ buf: an array to receive the read data.
+.br
+ count: 1-32, the number of bytes to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+.IP "\fBint i2c_write_i2c_block_data(unsigned handle, unsigned i2c_reg, char *buf, unsigned count)\fP"
+.IP "" 4
+This writes 1 to 32 bytes to the specified register of the device
+associated with handle.
+
+.br
+
+.br
+
+.EX
+ handle: >=0, as returned by a call to \fBi2c_open\fP.
+.br
+i2c_reg: 0-255, the register to write.
+.br
+ buf: the data to write.
+.br
+ count: 1-32, the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+.IP "\fBint spi_open(unsigned spi_channel, unsigned spi_baud, unsigned spi_flags)\fP"
+.IP "" 4
+This function returns a handle for the SPI device on channel.
+Data will be transferred at baud bits per second.
+
+.br
+
+.br
+
+.EX
+spi_channel: 0-1.
+.br
+ spi_baud: >1.
+.br
+ spi_flags: 0-3.
+.br
+
+.EE
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
+PI_BAD_SPI_SPEED, PI_BAD_FLAGS, or PI_SPI_OPEN_FAILED.
+
+.br
+
+.br
+The least significant two bits of flags define the SPI mode as follows.
+
+.br
+
+.br
+
+.EX
+ bit bit
+.br
+ 1 0
+.br
+Mode POL PHA
+.br
+ 0 0 0
+.br
+ 1 0 1
+.br
+ 2 1 0
+.br
+ 3 1 1
+.br
+
+.EE
+
+.br
+
+.br
+The other bits in flags should be set to zero.
+
+.IP "\fBint spi_close(unsigned handle)\fP"
+.IP "" 4
+This functions closes the SPI device identified by the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspi_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint spi_read(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function reads count bytes of data from the SPI
+device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspi_open\fP.
+.br
+ buf: an array to receive the read data bytes.
+.br
+ count: the number of bytes to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint spi_write(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function writes count bytes of data from buf to the SPI
+device associated with the handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspi_open\fP.
+.br
+ buf: the data bytes to write.
+.br
+ count: the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)\fP"
+.IP "" 4
+This function transfers count bytes of data from txBuf to the SPI
+device associated with the handle. Simultaneously count bytes of
+data are read from the device and placed in rxBuf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBspi_open\fP.
+.br
+ txBuf: the data bytes to write.
+.br
+ rxBuf: the received data bytes.
+.br
+ count: the number of bytes to transfer.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+
+.IP "\fBint serial_open(char *ser_tty, unsigned ser_baud, unsigned ser_flags)\fP"
+.IP "" 4
+This function opens a serial device at a specified baud rate
+with specified flags.
+
+.br
+
+.br
+
+.EX
+ ser_tty: the serial device to open, /dev/tty*.
+.br
+ ser_baud: the baud rate to use.
+.br
+ser_flags: 0.
+.br
+
+.EE
+
+.br
+
+.br
+Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
+PI_SER_OPEN_FAILED.
+
+.br
+
+.br
+No flags are currently defined. This parameter should be set to zero.
+
+.IP "\fBint serial_close(unsigned handle)\fP"
+.IP "" 4
+This function closes the serial device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+
+.IP "\fBint serial_write_byte(unsigned handle, unsigned bVal)\fP"
+.IP "" 4
+This function writes bVal to the serial port associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+
+.IP "\fBint serial_read_byte(unsigned handle)\fP"
+.IP "" 4
+This function reads a byte from the serial port associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
+
+.IP "\fBint serial_write(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function writes count bytes from buf to the the serial port
+associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+ buf: the array of bytes to write.
+.br
+ count: the number of bytes to write.
+.br
+
+.EE
+
+.br
+
+.br
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+
+.IP "\fBint serial_read(unsigned handle, char *buf, unsigned count)\fP"
+.IP "" 4
+This function reads up to count bytes from the the serial port
+associated with handle and writes them to buf.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+ buf: an array to receive the read data.
+.br
+ count: the maximum number of bytes to read.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
+
+.IP "\fBint serial_data_available(unsigned handle)\fP"
+.IP "" 4
+Returns the number of bytes available to be read from the
+device associated with handle.
+
+.br
+
+.br
+
+.EX
+handle: >=0, as returned by a call to \fBserial_open\fP.
+.br
+
+.EE
+
+.br
+
+.br
+Returns the number of bytes of data available (>=0) if OK,
+otherwise PI_BAD_HANDLE.
+
+.IP "\fBint callback(unsigned user_gpio, unsigned edge, CBFunc_t f)\fP"
+.IP "" 4
+This function initialises a new callback.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+.br
+ f: the callback function.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns a callback id if OK, otherwise pigif_bad_malloc,
+pigif_duplicate_callback, or pigif_bad_callback.
+
+.br
+
+.br
+The callback is called with the gpio, edge, and tick, whenever the
+gpio has the identified edge.
+
+.IP "\fBint callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP"
+.IP "" 4
+This function initialises a new callback.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+.br
+ f: the callback function.
+.br
+ userdata: a pointer to arbitrary user data.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns a callback id if OK, otherwise pigif_bad_malloc,
+pigif_duplicate_callback, or pigif_bad_callback.
+
+.br
+
+.br
+The callback is called with the gpio, edge, tick, and user, whenever
+the gpio has the identified edge.
+
+.br
+
+.br
+
+.IP "\fBint callback_cancel(unsigned callback_id)\fP"
+.IP "" 4
+This function fim
+cancels a callback identified by its id.
+
+.br
+
+.br
+
+.EX
+callback_id: >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 0 if OK, otherwise pigif_callback_not_found.
+
+.IP "\fBint wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)\fP"
+.IP "" 4
+This function waits for edge on the gpio for up to timeout
+seconds.
+
+.br
+
+.br
+
+.EX
+user_gpio: 0-31.
+.br
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+.br
+ timeout: >=0.
+.br
+
+.EE
+
+.br
+
+.br
+The function returns 1 if the edge occurred, otherwise 0.
+
+.br
+
+.br
+The function returns when the edge occurs or after the timeout.
+.SH PARAMETERS
+
+.br
+
+.br
+
+.IP "\fB*addrStr\fP" 0
+A string specifying the host or IP address of the Pi running
+the pigpio daemon. It may be NULL in which case localhost
+is used unless overridden by the PIGPIO_ADDR environment
+variable.
+
+.br
+
+.br
+
+.IP "\fBbbBaud\fP" 0
+The baud rate used for the transmission and reception of bit banged
+serial data.
+
+.br
+
+.br
+
+.EX
+PI_WAVE_MIN_BAUD 100
+.br
+PI_WAVE_MAX_BAUD 250000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBbit\fP" 0
+A value of 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBbits\fP" 0
+A value used to select gpios. If bit n of bits is set then gpio n is
+selected.
+
+.br
+
+.br
+A convenient way to set bit n is to or in (1<<n).
+
+.br
+
+.br
+e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23).
+
+.br
+
+.br
+
+.IP "\fB*buf\fP" 0
+A buffer to hold data being sent or being received.
+
+.br
+
+.br
+
+.IP "\fBbufSize\fP" 0
+The size in bytes of a buffer.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBbVal\fP: 0-255 (Hex 0x0-0xFF, Octal 0-0377)" 0
+An 8-bit byte value.
+
+.br
+
+.br
+
+.IP "\fBcallback_id\fP" 0
+A >=0, as returned by a call to \fBcallback\fP or \fBcallback_ex\fP. This is
+passed to \fBcallback_cancel\fP to cancel the callback.
+
+.br
+
+.br
+
+.IP "\fBCBFunc_t\fP" 0
+
+.EX
+typedef void (*CBFunc_t)
+.br
+ (unsigned user_gpio, unsigned level, uint32_t tick);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBCBFuncEx_t\fP" 0
+
+.EX
+typedef void (*CBFuncEx_t)
+.br
+ (unsigned user_gpio, unsigned level, uint32_t tick, void * user);
+.br
+
+.EE
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBchar\fP" 0
+A single character, an 8 bit quantity able to store 0-255.
+
+.br
+
+.br
+
+.IP "\fBcount\fP" 0
+The number of bytes to be transferred in an I2C, SPI, or Serial
+command.
+
+.br
+
+.br
+
+.IP "\fBdouble\fP" 0
+A floating point number.
+
+.br
+
+.br
+
+.IP "\fBdutycycle\fP: 0-range" 0
+A number representing the ratio of on time to off time for PWM.
+
+.br
+
+.br
+The number may vary between 0 and range (default 255) where
+0 is off and range is fully on.
+
+.br
+
+.br
+
+.IP "\fBedge\fP" 0
+Used to identify a gpio level transition of interest. A rising edge is
+a level change from 0 to 1. A falling edge is a level change from 1 to 0.
+
+.br
+
+.br
+
+.EX
+RISING_EDGE 0
+.br
+FALLING_EDGE 1
+.br
+EITHER_EDGE. 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBerrnum\fP" 0
+A negative number indicating a function call failed and the nature
+of the error.
+
+.br
+
+.br
+
+.IP "\fBf\fP" 0
+A function.
+
+.br
+
+.br
+
+.IP "\fBfrequency\fP: 0-" 0
+The number of times a gpio is swiched on and off per second. This
+can be set per gpio and may be as little as 5Hz or as much as
+40KHz. The gpio will be on for a proportion of the time as defined
+by its dutycycle.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBgpio\fP" 0
+A Broadcom numbered gpio, in the range 0-53.
+
+.br
+
+.br
+
+.IP "\fBgpioPulse_t\fP" 0
+
+.EX
+typedef struct
+.br
+{
+.br
+uint32_t gpioOn;
+.br
+uint32_t gpioOff;
+.br
+uint32_t usDelay;
+.br
+} gpioPulse_t;
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBgpioThreadFunc_t\fP" 0
+
+.EX
+typedef void *(gpioThreadFunc_t) (void *);
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBhandle\fP: 0-" 0
+A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP,
+\fBserial_open\fP, and \fBspi_open\fP.
+
+.br
+
+.br
+
+.IP "\fBi2c_addr\fP: 0x08-0x77" 0
+The address of a device on the I2C bus (0x08 - 0x77)
+
+.br
+
+.br
+
+.IP "\fBi2c_bus\fP: 0-1" 0
+An I2C bus, 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBi2c_flags\fP: 0" 0
+Flags which modify an I2C open command. None are currently defined.
+
+.br
+
+.br
+
+.IP "\fBi2c_reg\fP: 0-255" 0
+A register of an I2C device.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBint\fP" 0
+A whole number, negative or positive.
+
+.br
+
+.br
+
+.IP "\fBlevel\fP" 0
+The level of a gpio. Low or High.
+
+.br
+
+.br
+
+.EX
+PI_OFF 0
+.br
+PI_ON 1
+.br
+
+.br
+PI_CLEAR 0
+.br
+PI_SET 1
+.br
+
+.br
+PI_LOW 0
+.br
+PI_HIGH 1
+.br
+
+.EE
+
+.br
+
+.br
+There is one exception. If a watchdog expires on a gpio the level will be
+reported as PI_TIMEOUT. See \fBset_watchdog\fP.
+
+.br
+
+.br
+
+.EX
+PI_TIMEOUT 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBmode\fP: 0-7" 0
+The operational mode of a gpio, normally INPUT or OUTPUT.
+
+.br
+
+.br
+
+.EX
+PI_INPUT 0
+.br
+PI_OUTPUT 1
+.br
+PI_ALT0 4
+.br
+PI_ALT1 5
+.br
+PI_ALT2 6
+.br
+PI_ALT3 7
+.br
+PI_ALT4 3
+.br
+PI_ALT5 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBnumChar\fP" 0
+The number of characters in a string (used when the string might contain
+null characters, which would normally terminate the string).
+
+.br
+
+.br
+
+.IP "\fBnumPar\fP: 0-10" 0
+The number of parameters passed to a script.
+
+.br
+
+.br
+
+.IP "\fBnumPulses\fP" 0
+The number of pulses to be added to a waveform.
+
+.br
+
+.br
+
+.IP "\fBoffset\fP" 0
+The associated data starts this number of microseconds from the start of
+the waveform.
+
+.br
+
+.br
+
+.IP "\fB*param\fP" 0
+An array of script parameters.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fB*portStr\fP" 0
+A string specifying the port address used by the Pi running
+the pigpio daemon. It may be NULL in which case "8888"
+is used unless overridden by the PIGPIO_PORT environment
+variable.
+
+.br
+
+.br
+
+.IP "\fB*pth\fP" 0
+A thread identifier, returned by \fBstart_thread\fP.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBpthread_t\fP" 0
+A thread identifier.
+
+.br
+
+.br
+
+.IP "\fBpud\fP: 0-2" 0
+The setting of the pull up/down resistor for a gpio, which may be off,
+pull-up, or pull-down.
+
+.EX
+PI_PUD_OFF 0
+.br
+PI_PUD_DOWN 1
+.br
+PI_PUD_UP 2
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fBpulseLen\fP" 0
+1-50, the length of a trigger pulse in microseconds.
+
+.br
+
+.br
+
+.IP "\fB*pulses\fP" 0
+An array of pulsed to be added to a waveform.
+
+.br
+
+.br
+
+.IP "\fBpulsewidth\fP: 0, 500-2500" 0
+
+.EX
+PI_SERVO_OFF 0
+.br
+PI_MIN_SERVO_PULSEWIDTH 500
+.br
+PI_MAX_SERVO_PULSEWIDTH 2500
+.br
+
+.EE
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBrange\fP: 25-40000" 0
+The permissible dutycycle values are 0-range.
+
+.EX
+PI_MIN_DUTYCYCLE_RANGE 25
+.br
+PI_MAX_DUTYCYCLE_RANGE 40000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fB*rxBuf\fP" 0
+A pointer to a buffer to receive data.
+
+.br
+
+.br
+
+.IP "\fB*script\fP" 0
+A pointer to the text of a script.
+
+.br
+
+.br
+
+.IP "\fBscript_id\fP" 0
+An id of a stored script as returned by \fBstore_script\fP.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBseconds\fP" 0
+The number of seconds.
+
+.br
+
+.br
+
+.IP "\fBser_baud\fP" 0
+The baud rate to use on the serial link.
+
+.br
+
+.br
+It must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
+4800, 9600, 19200, 38400, 57600, 115200, 230400.
+
+.br
+
+.br
+
+.IP "\fBser_flags\fP" 0
+Flags which modify a serial open command. None are currently defined.
+
+.br
+
+.br
+
+.IP "\fB*ser_tty\fP" 0
+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
+
+.br
+
+.br
+
+.IP "\fBsize_t\fP" 0
+A standard type used to indicate the size of an object in bytes.
+
+.br
+
+.br
+
+.IP "\fBspi_baud\fP" 0
+The speed in bits per second to use for the SPI device.
+
+.br
+
+.br
+
+.br
+
+.br
+
+.IP "\fBspi_channel\fP" 0
+A SPI channel, 0 or 1.
+
+.br
+
+.br
+
+.IP "\fBspi_flags\fP" 0
+Flags which modify a SPI open command. The two least significant bits
+define the SPI mode. The other bits are undefined.
+
+.br
+
+.br
+
+.IP "\fB*str\fP" 0
+ An array of characters.
+
+.br
+
+.br
+
+.IP "\fBthread_func\fP" 0
+A function of type gpioThreadFunc_t used as the main function of a
+thread.
+
+.br
+
+.br
+
+.IP "\fBtimeout\fP" 0
+A gpio watchdog timeout in milliseconds.
+
+.EX
+PI_MIN_WDOG_TIMEOUT 0
+.br
+PI_MAX_WDOG_TIMEOUT 60000
+.br
+
+.EE
+
+.br
+
+.br
+
+.IP "\fB*txBuf\fP" 0
+An array of bytes to transmit.
+
+.br
+
+.br
+
+.IP "\fBuint32_t\fP: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)" 0
+A 32-bit unsigned value.
+
+.br
+
+.br
+
+.IP "\fBunsigned\fP" 0
+A whole number >= 0.
+
+.br
+
+.br
+
+.IP "\fBuser_gpio\fP" 0
+0-31, a Broadcom numbered gpio.
+
+.br
+
+.br
+
+.IP "\fB*userdata\fP" 0
+A pointer to arbitrary user data. This may be used to identify the instance.
+
+.br
+
+.br
+
+.IP "\fBvoid\fP" 0
+Denoting no parameter is required
+
+.br
+
+.br
+
+.IP "\fBwave_add_*\fP" 0
+One of \fBwave_add_new\fP, \fBwave_add_generic\fP, \fBwave_add_serial\fP.
+
+.br
+
+.br
+
+.IP "\fBwave_id\fP" 0
+A number representing a waveform created by \fBwave_create\fP.
+
+.br
+
+.br
+
+.IP "\fBwave_send_*\fP" 0
+One of \fBwave_send_once\fP, \fBwave_send_repeat\fP.
+
+.br
+
+.br
+
+.IP "\fBwVal\fP: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)" 0
+A 16-bit word value.
+
+.br
+
+.br
+.SH pigpiod_if Error Codes
+
+.EX
+
+.br
+typedef enum
+.br
+{
+.br
+ pigif_bad_send = -2000,
+.br
+ pigif_bad_recv = -2001,
+.br
+ pigif_bad_getaddrinfo = -2002,
+.br
+ pigif_bad_connect = -2003,
+.br
+ pigif_bad_socket = -2004,
+.br
+ pigif_bad_noib = -2005,
+.br
+ pigif_duplicate_callback = -2006,
+.br
+ pigif_bad_malloc = -2007,
+.br
+ pigif_bad_callback = -2008,
+.br
+ pigif_notify_failed = -2009,
+.br
+ pigif_callback_not_found = -2010,
+.br
+} pigifError_t;
+.br
+
+.br
+
+.EE
+
+.SH SEE ALSO
+
+pigpiod(1), pig2vcd(1), pigs(1), pigpio(3)
+.SH AUTHOR
+
+joan@abyz.co.uk
diff --git a/pigpiod_if.c b/pigpiod_if.c
index ceb57f7..4ac663e 100644
--- a/pigpiod_if.c
+++ b/pigpiod_if.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
-/* PIGPIOD_IF_VERSION 4 */
+/* PIGPIOD_IF_VERSION 6 */
#include <stdio.h>
#include <stdlib.h>
@@ -42,6 +42,7 @@ For more information, please refer to <http://unlicense.org/>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
+#include <netinet/tcp.h>
#include <sys/select.h>
#include <arpa/inet.h>
@@ -133,7 +134,7 @@ static int pigpio_command_ext
static int pigpioOpenSocket(char *addr, char *port)
{
- int sock, err;
+ int sock, err, opt;
struct addrinfo hints, *res, *rp;
const char *addrStr, *portStr;
@@ -175,6 +176,10 @@ static int pigpioOpenSocket(char *addr, char *port)
if (sock == -1) continue;
+ /* Disable the Nagle algorithm. */
+ opt = 1;
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(int));
+
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break;
}
@@ -289,17 +294,17 @@ static void findNotifyBits(void)
}
}
-static void _wfe(unsigned gpio, unsigned level, uint32_t tick, void *user)
+static void _wfe(unsigned user_gpio, unsigned level, uint32_t tick, void *user)
{
*(int *)user = 1;
}
-static int intCallback(unsigned gpio, unsigned edge, void *f, void *user, int ex)
+static int intCallback(unsigned user_gpio, unsigned edge, void *f, void *user, int ex)
{
static int id = 0;
callback_t *p;
- if ((gpio >=0) && (gpio < 32) && (edge >=0) && (edge <= 2) && f)
+ if ((user_gpio >=0) && (user_gpio < 32) && (edge >=0) && (edge <= 2) && f)
{
/* prevent duplicates */
@@ -307,7 +312,7 @@ static int intCallback(unsigned gpio, unsigned edge, void *f, void *user, int ex
while (p)
{
- if ((p->gpio == gpio) && (p->edge == edge) && (p->f == f))
+ if ((p->gpio == user_gpio) && (p->edge == edge) && (p->f == f))
{
return pigif_duplicate_callback;
}
@@ -321,7 +326,7 @@ static int intCallback(unsigned gpio, unsigned edge, void *f, void *user, int ex
if (!gCallBackFirst) gCallBackFirst = p;
p->id = id++;
- p->gpio = gpio;
+ p->gpio = user_gpio;
p->edge = edge;
p->f = f;
p->user = user;
@@ -375,12 +380,12 @@ void time_sleep(double seconds)
}
}
-const char *pigpio_error(int error)
+char *pigpio_error(int errnum)
{
- if (error > -1000) return cmdErrStr(error);
+ if (errnum > -1000) return cmdErrStr(errnum);
else
{
- switch(error)
+ switch(errnum)
{
case pigif_bad_send:
return "failed to send to pigpiod";
@@ -415,7 +420,7 @@ unsigned pigpiod_if_version(void)
return PIGPIOD_IF_VERSION;
}
-pthread_t *start_thread(gpioThreadFunc_t func, void *arg)
+pthread_t *start_thread(gpioThreadFunc_t thread_func, void *arg)
{
pthread_t *pth;
pthread_attr_t pthAttr;
@@ -438,7 +443,7 @@ pthread_t *start_thread(gpioThreadFunc_t func, void *arg)
return NULL;
}
- if (pthread_create(pth, &pthAttr, func, arg))
+ if (pthread_create(pth, &pthAttr, thread_func, arg))
{
perror("pthread_create socket failed");
free(pth);
@@ -543,8 +548,8 @@ int gpio_write(unsigned gpio, unsigned level)
int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)
{return pigpio_command(gPigCommand, PI_CMD_PWM, user_gpio, dutycycle);}
-int set_PWM_range(unsigned user_gpio, unsigned range_)
- {return pigpio_command(gPigCommand, PI_CMD_PRS, user_gpio, range_);}
+int set_PWM_range(unsigned user_gpio, unsigned range)
+ {return pigpio_command(gPigCommand, PI_CMD_PRS, user_gpio, range);}
int get_PWM_range(unsigned user_gpio)
{return pigpio_command(gPigCommand, PI_CMD_PRG, user_gpio, 0);}
@@ -631,12 +636,13 @@ int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)
}
int wave_add_serial(
- unsigned gpio, unsigned baud, unsigned offset, unsigned numChar, char *str)
+ unsigned user_gpio, unsigned baud, unsigned offset,
+ unsigned numChar, char *str)
{
gpioExtent_t ext[3];
/*
- p1=gpio
+ p1=user_gpio
p2=baud
p3=len+4
## extension ##
@@ -653,7 +659,7 @@ int wave_add_serial(
ext[1].ptr = str;
return pigpio_command_ext(
- gPigCommand, PI_CMD_WVAS, gpio, baud, numChar+4, 2, ext);
+ gPigCommand, PI_CMD_WVAS, user_gpio, baud, numChar+4, 2, ext);
}
int wave_create(void)
@@ -707,12 +713,12 @@ int wave_get_high_cbs(void)
int wave_get_max_cbs(void)
{return pigpio_command(gPigCommand, PI_CMD_WVSC, 2, 0);}
-int gpio_trigger(unsigned gpio, unsigned pulseLen, unsigned level)
+int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level)
{
gpioExtent_t ext[1];
/*
- p1=gpio
+ p1=user_gpio
p2=pulseLen
p3=4
## extension ##
@@ -723,7 +729,7 @@ int gpio_trigger(unsigned gpio, unsigned pulseLen, unsigned level)
ext[0].ptr = &level;
return pigpio_command_ext(
- gPigCommand, PI_CMD_TRIG, gpio, pulseLen, 4, 1, ext);
+ gPigCommand, PI_CMD_TRIG, user_gpio, pulseLen, 4, 1, ext);
}
int store_script(char *script)
@@ -792,14 +798,14 @@ int stop_script(unsigned script_id)
int delete_script(unsigned script_id)
{return pigpio_command(gPigCommand, PI_CMD_PROCD, script_id, 0);}
-int bb_serial_read_open(unsigned gpio, unsigned baud)
- {return pigpio_command(gPigCommand, PI_CMD_SLRO, gpio, baud);}
+int bb_serial_read_open(unsigned user_gpio, unsigned baud)
+ {return pigpio_command(gPigCommand, PI_CMD_SLRO, user_gpio, baud);}
-int bb_serial_read(unsigned gpio, void *buf, size_t bufSize)
+int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)
{
int bytes;
- bytes = pigpio_command(gPigCommand, PI_CMD_SLR, gpio, bufSize);
+ bytes = pigpio_command(gPigCommand, PI_CMD_SLR, user_gpio, bufSize);
if (bytes > 0)
{
@@ -809,26 +815,26 @@ int bb_serial_read(unsigned gpio, void *buf, size_t bufSize)
return bytes;
}
-int bb_serial_read_close(unsigned gpio)
- {return pigpio_command(gPigCommand, PI_CMD_SLRC, gpio, 0);}
+int bb_serial_read_close(unsigned user_gpio)
+ {return pigpio_command(gPigCommand, PI_CMD_SLRC, user_gpio, 0);}
-int i2c_open(unsigned bus, unsigned addr, unsigned flags)
+int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags)
{
gpioExtent_t ext[1];
/*
- p1=bus
- p2=addr
+ p1=i2c_bus
+ p2=i2c_addr
p3=4
## extension ##
- uint32_t flags
+ uint32_t i2c_flags
*/
ext[0].size = 4;
- ext[0].ptr = &flags;
+ ext[0].ptr = &i2c_flags;
return pigpio_command_ext
- (gPigCommand, PI_CMD_I2CO, bus, addr, 4, 1, ext);
+ (gPigCommand, PI_CMD_I2CO, i2c_bus, i2c_addr, 4, 1, ext);
}
int i2c_close(unsigned handle)
@@ -857,7 +863,7 @@ int i2c_write_device(unsigned handle, char *buf, unsigned count)
p2=0
p3=count
## extension ##
- char buf[count] flags
+ char buf[count]
*/
ext[0].size = count;
@@ -1201,11 +1207,11 @@ int serial_read(unsigned handle, char *buf, unsigned count)
int serial_data_available(unsigned handle)
{return pigpio_command(gPigCommand, PI_CMD_SERDA, handle, 0);}
-int callback(unsigned gpio, unsigned edge, CBFunc_t f)
- {return intCallback(gpio, edge, f, 0, 0);}
+int callback(unsigned user_gpio, unsigned edge, CBFunc_t f)
+ {return intCallback(user_gpio, edge, f, 0, 0);}
-int callback_ex(unsigned gpio, unsigned edge, CBFuncEx_t f, void *user)
- {return intCallback(gpio, edge, f, user, 1);}
+int callback_ex(unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *user)
+ {return intCallback(user_gpio, edge, f, user, 1);}
int callback_cancel(unsigned id)
{
@@ -1234,7 +1240,7 @@ int callback_cancel(unsigned id)
return pigif_callback_not_found;
}
-int wait_for_edge(unsigned gpio, unsigned edge, double timeout)
+int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout)
{
int triggered = 0;
int id;
@@ -1244,7 +1250,7 @@ int wait_for_edge(unsigned gpio, unsigned edge, double timeout)
due = time_time() + timeout;
- id = callback_ex(gpio, edge, _wfe, &triggered);
+ id = callback_ex(user_gpio, edge, _wfe, &triggered);
while (!triggered && (time_time() < due)) time_sleep(0.1);
diff --git a/pigpiod_if.h b/pigpiod_if.h
index 81b4b79..d99c17d 100644
--- a/pigpiod_if.h
+++ b/pigpiod_if.h
@@ -30,28 +30,241 @@ For more information, please refer to <http://unlicense.org/>
#include "pigpio.h"
-#define PIGPIOD_IF_VERSION 5
+#define PIGPIOD_IF_VERSION 6
-typedef enum
-{
- pigif_bad_send = -2000,
- pigif_bad_recv = -2001,
- pigif_bad_getaddrinfo = -2002,
- pigif_bad_connect = -2003,
- pigif_bad_socket = -2004,
- pigif_bad_noib = -2005,
- pigif_duplicate_callback = -2006,
- pigif_bad_malloc = -2007,
- pigif_bad_callback = -2008,
- pigif_notify_failed = -2009,
- pigif_callback_not_found = -2010,
-} pigifError_t;
+/*TEXT
+
+pigpiod_if is a C library for the Raspberry which allows control
+of the gpios via the socket interface to the pigpio daemon.
+
+*Features*
+
+o PWM on any of gpios 0-31
+
+o servo pulses on any of gpios 0-31
+
+o callbacks when any of gpios 0-31 change state
+
+o callbacks at timed intervals
+
+o reading/writing all of the gpios in a bank as one operation
+
+o individually setting gpio modes, reading and writing
+
+o notifications when any of gpios 0-31 change state
+
+o the construction of output waveforms with microsecond timing
+
+o rudimentary permission control over gpios
+
+o a simple interface to start and stop new threads
+
+o I2C, SPI, and serial link wrappers
+
+o creating and running scripts on the pigpio daemon
+
+*gpios*
+
+ALL gpios are identified by their Broadcom number.
+
+*Notes*
+
+The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals.
+
+TEXT*/
+
+/*USAGE
+
+Usage
+
+Include <pigpiod_if.h> in your source files.
+
+Assuming your source is in example.c use the following command to build
+
+. .
+gcc -o example example.c -lpigpiod_if
+
+to run make sure the pigpio daemon is running
+
+sudo pigpiod
+
+./example # sudo is not required to run programs linked to pigpiod_if
+. .
+
+For examples see checklib.c, demolib.c, pigpio.c, pigpiod.c, pig2vcd.c,
+and pigs.c
+
+All the functions which return an int return < 0 on error.
+
+
+USAGE*/
+
+/*OVERVIEW
+
+ESSENTIAL
+
+pigpio_start Connects to the pigpio daemon
+pigpio_stop Disconnects from the pigpio daemon
+
+BEGINNER
+
+set_mode Set a gpio mode
+get_mode Get a gpio mode
+
+set_pull_up_down Set/clear gpio pull up/down resistor
+
+gpio_read Read a gpio
+gpio_write Write a gpio
+
+set_PWM_dutycycle Start/stop PWM pulses on a gpio
+
+set_servo_pulsewidth Start/stop servo pulses on a gpio
+
+callback Create gpio level change callback
+callback_ex Create gpio level change callback
+callback_cancel Cancel a callback
+wait_for_edge Wait for gpio level change
+
+INTERMEDIATE
+
+gpio_trigger Send a trigger pulse to a gpio.
+
+set_watchdog Set a watchdog on a gpio.
+
+set_PWM_range Configure PWM range for a gpio
+get_PWM_range Get configured PWM range for a gpio
+
+set_PWM_frequency Configure PWM frequency for a gpio
+get_PWM_frequency Get configured PWM frequency for a gpio
+
+read_bank_1 Read all gpios in bank 1
+read_bank_2 Read all gpios in bank 2
+
+clear_bank_1 Clear selected gpios in bank 1
+clear_bank_2 Clear selected gpios in bank 2
+
+set_bank_1 Set selected gpios in bank 1
+set_bank_2 Set selected gpios in bank 2
+
+start_thread Start a new thread
+stop_thread Stop a previously started thread
+
+ADVANCED
+
+get_PWM_real_range Get underlying PWM range for a gpio
+
+notify_open Request a notification handle
+notify_begin Start notifications for selected gpios
+notify_pause Pause notifications
+notify_close Close a notification
+
+bb_serial_read_open Opens a gpio for bit bang serial reads
+bb_serial_read Reads bit bang serial data from a gpio
+bb_serial_read_close Closes a gpio for bit bang serial reads
+
+SCRIPTS
+
+store_script Store a script
+run_script Run a stored script
+script_status Get script status and parameters
+stop_script Stop a running script
+delete_script Delete a stored script
+
+WAVES
+
+wave_clear Deletes all waveforms
+
+wave_add_new Starts a new waveform
+wave_add_generic Adds a series of pulses to the waveform
+wave_add_serial Adds serial data to the waveform
+
+wave_create Creates a waveform from added data
+wave_delete Deletes one or more waveforms
+
+wave_send_once Transmits a waveform once
+wave_send_repeat Transmits a waveform repeatedly
+wave_tx_busy Checks to see if the waveform has ended
+wave_tx_stop Aborts the current waveform
+
+wave_get_micros Length in microseconds of the current waveform
+wave_get_high_micros Length of longest waveform so far
+wave_get_max_micros Absolute maximum allowed micros
+
+wave_get_pulses Length in pulses of the current waveform
+wave_get_high_pulses Length of longest waveform so far
+wave_get_max_pulses Absolute maximum allowed pulses
+
+wave_get_cbs Length in cbs of the current waveform
+wave_get_high_cbs Length of longest waveform so far
+wave_get_max_cbs Absolute maximum allowed cbs
+
+wave_tx_start Creates/transmits a waveform (DEPRECATED)
+wave_tx_repeat Creates/transmits a waveform repeatedly (DEPRECATED)
+
+I2C
+
+i2c_open Opens an I2C device
+i2c_close Closes an I2C device
+
+i2c_read_device Reads the raw I2C device
+i2c_write_device Writes the raw I2C device
+
+i2c_write_quick smbus write quick
+i2c_write_byte smbus write byte
+i2c_read_byte smbus read byte
+i2c_write_byte_data smbus write byte data
+i2c_write_word_data smbus write word data
+i2c_read_byte_data smbus read byte data
+i2c_read_word_data smbus read word data
+i2c_process_call smbus process call
+i2c_write_block_data smbus write block data
+i2c_read_block_data smbus read block data
+i2c_block_process_call smbus block process call
+
+i2c_write_i2c_block_data smbus write I2C block data
+i2c_read_i2c_block_data smbus read I2C block data
+
+SPI
+
+spi_open Opens a SPI device
+spi_close Closes a SPI device
+
+spi_read Reads bytes from a SPI device
+spi_write Writes bytes to a SPI device
+spi_xfer Transfers bytes with a SPI device
+
+SERIAL
+
+serial_open Opens a serial device (/dev/tty*)
+serial_close Closes a serial device
+
+serial_write_byte Writes a byte to a serial device
+serial_read_byte Reads a byte from a serial device
+serial_write Writes bytes to a serial device
+serial_read Reads bytes from a serial device
+
+serial_data_available Returns number of bytes ready to be read
+
+UTILITIES
+
+get_current_tick Get current tick (microseconds)
+
+get_hardware_revision Get hardware revision
+get_pigpio_version Get the pigpio version
+pigpiod_if_version Get the pigpiod_if version
+
+pigpio_error Get a text description of an error code.
+
+time_sleep Sleeps for a float number of seconds
+time_time Float number of seconds since the epoch
+
+OVERVIEW*/
-typedef void (*CBFunc_t) (unsigned gpio, unsigned level, uint32_t tick);
+typedef void (*CBFunc_t) (unsigned user_gpio, unsigned level, uint32_t tick);
typedef void (*CBFuncEx_t)
- (unsigned gpio, unsigned level, uint32_t tick, void * user);
+ (unsigned user_gpio, unsigned level, uint32_t tick, void * user);
typedef struct callback_s callback_t;
@@ -59,962 +272,1888 @@ typedef struct callback_s callback_t;
#define FALLING_EDGE 1
#define EITHER_EDGE 2
+/*F*/
double time_time(void);
-/* Return the current time in seconds since the Epoch.*/
+/*D
+Return the current time in seconds since the Epoch.
+D*/
+/*F*/
void time_sleep(double seconds);
-/* Delay execution for a given number of seconds */
+/*D
+Delay execution for a given number of seconds.
-const char *pigpio_error(int error);
-/* Return a string for a pigpio library error. */
+. .
+seconds: the number of seconds to delay.
+. .
+D*/
+/*F*/
+char *pigpio_error(int errnum);
+/*D
+Return a text description for an error code.
+
+. .
+errnum: the error code.
+. .
+D*/
+
+/*F*/
unsigned pigpiod_if_version(void);
-/* Return the pigpiod_if version. */
+/*D
+Return the pigpiod_if version.
+D*/
-pthread_t *start_thread(gpioThreadFunc_t func, void *arg);
-/* Starts a new thread of execution with func as the main routine.
+/*F*/
+pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata);
+/*D
+Starts a new thread of execution with thread_func as the main routine.
- Returns a pointer to pthread_t if OK, otherwise NULL.
+. .
+thread_func: the main function for the new thread.
+ userdata: a pointer to an arbitrary argument.
+. .
- The function is passed the single argument arg.
+Returns a pointer to pthread_t if OK, otherwise NULL.
- The thread can be cancelled by passing the pointer to pthread_t to
- stop_thread().
-*/
+The function is passed the single argument userdata.
+
+The thread can be cancelled by passing the pointer to pthread_t to
+[*stop_thread*].
+D*/
+/*F*/
void stop_thread(pthread_t *pth);
-/* Cancels the thread pointed at by pth.
+/*D
+Cancels the thread pointed at by pth.
- No value is returned.
+. .
+pth: the thread to be stopped.
+. .
- The thread to be stopped should have been started with start_thread().
-*/
+No value is returned.
-int pigpio_start(char *addrStr, char *portStr);
-/* Connect to the pigpio daemon. Reserving command and
- notification streams.
-
- addrStr specifies the host or IP address of the Pi running
- the pigpio daemon. It may be NULL in which case localhost
- is used unless overriden by the PIGPIO_ADDR environment
- variable.
-
- portStr specifies the port address used by the Pi running
- the pigpio daemon. It may be NULL in which case "8888"
- is used unless overriden by the PIGPIO_PORT environment
- variable.
-*/
+The thread to be stopped should have been started with [*start_thread*].
+D*/
+/*F*/
+int pigpio_start(char *addrStr, char *portStr);
+/*D
+Connect to the pigpio daemon. Reserving command and
+notification streams.
+
+. .
+addrStr: specifies the host or IP address of the Pi running the
+ pigpio daemon. It may be NULL in which case localhost
+ is used unless overridden by the PIGPIO_ADDR environment
+ variable.
+
+portStr: specifies the port address used by the Pi running the
+ pigpio daemon. It may be NULL in which case "8888"
+ is used unless overridden by the PIGPIO_PORT environment
+ variable.
+. .
+D*/
+
+/*F*/
void pigpio_stop(void);
-/*
- Terminates the connection to the pigpio daemon and releases
- resources used by the library.
-*/
+/*D
+Terminates the connection to the pigpio daemon and releases
+resources used by the library.
+D*/
+/*F*/
int set_mode(unsigned gpio, unsigned mode);
-/* Set the gpio mode.
+/*D
+Set the gpio mode.
- gpio: 0-53.
- mode: INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5.
+. .
+gpio: 0-53.
+mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1,
+ PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.
+. .
- Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
- or PI_NOT_PERMITTED.
-*/
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
+or PI_NOT_PERMITTED.
+D*/
+/*F*/
int get_mode(unsigned gpio);
-/* Get the gpio mode.
+/*D
+Get the gpio mode.
- Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
+. .
+gpio: 0-53.
+. .
- gpio: 0-53.
-*/
+Returns the gpio mode if OK, otherwise PI_BAD_GPIO.
+D*/
+/*F*/
int set_pull_up_down(unsigned gpio, unsigned pud);
-/* Set or clear the gpio pull-up/down resistor.
+/*D
+Set or clear the gpio pull-up/down resistor.
- Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
- or PI_NOT_PERMITTED.
+. .
+gpio: 0-53.
+ pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.
+. .
- gpio: 0-53.
- pud: PUD_UP, PUD_DOWN, PUD_OFF.
-*/
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
+or PI_NOT_PERMITTED.
+D*/
+/*F*/
int gpio_read(unsigned gpio);
-/* Read the gpio level.
+/*D
+Read the gpio level.
- Returns the gpio level if OK, otherwise PI_BAD_GPIO.
+. .
+gpio:0-53.
+. .
- gpio:0-53.
-*/
+Returns the gpio level if OK, otherwise PI_BAD_GPIO.
+D*/
+/*F*/
int gpio_write(unsigned gpio, unsigned level);
-/*
- Write the gpio level.
+/*D
+Write the gpio level.
- Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
- or PI_NOT_PERMITTED.
+. .
+ gpio: 0-53.
+level: 0, 1.
+. .
- gpio: 0-53.
- level: 0, 1.
+Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
+or PI_NOT_PERMITTED.
- Notes
+Notes
- If PWM or servo pulses are active on the gpio they are switched off.
-*/
+If PWM or servo pulses are active on the gpio they are switched off.
+D*/
+/*F*/
int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle);
-/* Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio.
+/*D
+Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio.
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
- or PI_NOT_PERMITTED.
+. .
+user_gpio: 0-31.
+dutycycle: 0-range (range defaults to 255).
+. .
- user_gpio: 0-31.
- dutycycle: 0-range (range defaults to 255).
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
+or PI_NOT_PERMITTED.
+Notes
- Notes
+The [*set_PWM_range*] function may be used to change the
+default range of 255.
+D*/
- The set_PWM_range() function can change the default range of 255.
-*/
-
-int set_PWM_range(unsigned user_gpio, unsigned range_);
-/* Set the range of PWM values to be used on the gpio.
+/*F*/
+int set_PWM_range(unsigned user_gpio, unsigned range);
+/*D
+Set the range of PWM values to be used on the gpio.
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
- or PI_NOT_PERMITTED.
+. .
+user_gpio: 0-31.
+ range: 25-40000.
+. .
- user_gpio: 0-31.
- range_: 25-40000.
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
+or PI_NOT_PERMITTED.
- Notes
+Notes
- If PWM is currently active on the gpio its dutycycle will be
- scaled to reflect the new range.
+If PWM is currently active on the gpio its dutycycle will be
+scaled to reflect the new range.
- The real range, the number of steps between fully off and fully on
- for each of the 18 available gpio frequencies is
+The real range, the number of steps between fully off and fully on
+for each of the 18 available gpio frequencies is
- 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), 400(#7),
- 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12), 2000(#13),
- 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
+. .
+ 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6),
+ 400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12),
+2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
+. .
- The real value set by set_PWM_range is
- (dutycycle * real range) / range.
-*/
+The real value set by set_PWM_range is (dutycycle * real range) / range.
+D*/
+/*F*/
int get_PWM_range(unsigned user_gpio);
-/* Get the range of PWM values being used on the gpio.
+/*D
+Get the range of PWM values being used on the gpio.
- Returns the dutycycle range used for the gpio if OK,
- otherwise PI_BAD_USER_GPIO.
+. .
+user_gpio: 0-31.
+. .
- user_gpio: 0-31.
-*/
+Returns the dutycycle range used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+D*/
+/*F*/
int get_PWM_real_range(unsigned user_gpio);
-/* Get the real underlying range of PWM values being used on the gpio.
+/*D
+Get the real underlying range of PWM values being used on the gpio.
- Returns the real range used for the gpio if OK,
- otherwise PI_BAD_USER_GPIO.
+. .
+user_gpio: 0-31.
+. .
- user_gpio: 0-31.
-*/
+Returns the real range used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+D*/
+/*F*/
int set_PWM_frequency(unsigned user_gpio, unsigned frequency);
-/*
- Set the frequency (in Hz) of the PWM to be used on the gpio.
+/*D
+Set the frequency (in Hz) of the PWM to be used on the gpio.
- Returns the numerically closest frequency if OK, otherwise
- PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
+. .
+user_gpio: 0-31.
+frequency: 0- (Hz).
+. .
- user_gpio: 0-31.
- frequency: 0- (Hz).
+Returns the numerically closest frequency if OK, otherwise
+PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
- The selectable frequencies depend upon the sample rate which
- may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
- sample rate is set when the C pigpio library is started.
+The selectable frequencies depend upon the sample rate which
+may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
+sample rate is set when the C pigpio library is started.
- Each gpio can be independently set to one of 18 different
- PWM frequencies.
+Each gpio can be independently set to one of 18 different
+PWM frequencies.
- If PWM is currently active on the gpio it will be switched
- off and then back on at the new frequency.
+If PWM is currently active on the gpio it will be switched
+off and then back on at the new frequency.
- 1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600,
- 1250, 1000, 800, 500, 400, 250, 200, 100, 50
+. .
+1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600,
+ 1250, 1000, 800, 500, 400, 250, 200, 100, 50
- 2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800,
- 625, 500, 400, 250, 200, 125, 100, 50, 25
+2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800,
+ 625, 500, 400, 250, 200, 125, 100, 50 , 25
- 4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400,
- 313, 250, 200, 125, 100, 63, 50, 25, 13
+4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400,
+ 313, 250, 200, 125, 100, 63, 50, 25, 13
- 5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320,
- 250, 200, 160, 100, 80, 50, 40, 20, 10
+5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320,
+ 250, 200, 160, 100 , 80, 50, 40, 20, 10
- 8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200,
- 156, 125, 100, 63, 50, 31, 25, 13, 6
+8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200,
+ 156, 125, 100, 63, 50, 31, 25, 13, 6
- 10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160,
- 125, 100, 80, 50, 40, 25, 20, 10, 5
-*/
+10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160,
+ 125, 100, 80, 50, 40, 25, 20, 10, 5
+. .
+D*/
+/*F*/
int get_PWM_frequency(unsigned user_gpio);
-/*
- Get the frequency of PWM being used on the gpio.
+/*D
+Get the frequency of PWM being used on the gpio.
- Returns the frequency (in hertz) used for the gpio if OK,
- otherwise PI_BAD_USER_GPIO.
+. .
+user_gpio: 0-31.
+. .
- user_gpio: 0-31.
-*/
+Returns the frequency (in hertz) used for the gpio if OK,
+otherwise PI_BAD_USER_GPIO.
+D*/
+/*F*/
int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth);
-/*
- Start (500-2500) or stop (0) servo pulses on the gpio.
+/*D
+Start (500-2500) or stop (0) servo pulses on the gpio.
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
- PI_NOT_PERMITTED.
+. .
+ user_gpio: 0-31.
+pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).
+. .
- user_gpio: 0-31.
- pulsewidth: 0 (off), 500 (most anti-clockwise) - 2500 (most clockwise).
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
+PI_NOT_PERMITTED.
- The selected pulsewidth will continue to be transmitted until
- changed by a subsequent call to set_servo_pulsewidth().
+The selected pulsewidth will continue to be transmitted until
+changed by a subsequent call to set_servo_pulsewidth.
- The pulsewidths supported by servos varies and should probably be
- determined by experiment. A value of 1500 should always be safe and
- represents the mid-point of rotation.
+The pulsewidths supported by servos varies and should probably be
+determined by experiment. A value of 1500 should always be safe and
+represents the mid-point of rotation.
- You can DAMAGE a servo if you command it to move beyond its limits.
+You can DAMAGE a servo if you command it to move beyond its limits.
- OTHER UPDATE RATES:
+OTHER UPDATE RATES:
- This function updates servos at 50Hz. If you wish to use a different
- update frequency you will have to use the PWM functions.
+This function updates servos at 50Hz. If you wish to use a different
+update frequency you will have to use the PWM functions.
- Update Rate (Hz) 50 100 200 400 500
- 1E6/Hz 20000 10000 5000 2500 2000
+. .
+Update Rate (Hz) 50 100 200 400 500
+1E6/Hz 20000 10000 5000 2500 2000
+. .
- Firstly set the desired PWM frequency using set_PWM_frequency().
+Firstly set the desired PWM frequency using [*set_PWM_frequency*].
- Then set the PWM range using set_PWM_range() to 1E6/Hz.
- Doing this allows you to use units of microseconds when setting
- the servo pulse width.
+Then set the PWM range using [*set_PWM_range*] to 1E6/Hz.
+Doing this allows you to use units of microseconds when setting
+the servo pulse width.
- E.g. If you want to update a servo connected to gpio 25 at 400Hz
+E.g. If you want to update a servo connected to gpio 25 at 400Hz
- set_PWM_frequency(25, 400);
- set_PWM_range(25, 2500);
+. .
+set_PWM_frequency(25, 400);
+set_PWM_range(25, 2500);
+. .
- Thereafter use the set_PWM_dutycycle() function to move the servo,
- e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
-*/
+Thereafter use the [*set_PWM_dutycycle*] function to move the servo,
+e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
+D*/
+/*F*/
int notify_open(void);
-/*
- Get a free notification handle.
+/*D
+Get a free notification handle.
- Returns a handle greater than or equal to zero if OK,
- otherwise PI_NO_HANDLE.
+Returns a handle greater than or equal to zero if OK,
+otherwise PI_NO_HANDLE.
- A notification is a method for being notified of gpio state
- changes via a pipe.
+A notification is a method for being notified of gpio state
+changes via a pipe.
- Pipes are only accessible from the local machine so this function
- serves no purpose if you are using the library from a remote machine.
- The in-built (socket) notifications provided by callback()
- should be used instead.
+Pipes are only accessible from the local machine so this function
+serves no purpose if you are using the library from a remote machine.
+The in-built (socket) notifications provided by [*callback*]
+should be used instead.
- Notifications for handle x will be available at the pipe
- named /dev/pigpiox (where x is the handle number).
- E.g. if the function returns 15 then the notifications must be
- read from /dev/pigpio15.
-*/
+Notifications for handle x will be available at the pipe
+named /dev/pigpiox (where x is the handle number).
+E.g. if the function returns 15 then the notifications must be
+read from /dev/pigpio15.
+D*/
+/*F*/
int notify_begin(unsigned handle, uint32_t bits);
-/*
- Start notifications on a previously opened handle.
+/*D
+Start notifications on a previously opened handle.
- Returns 0 if OK, otherwise PI_BAD_HANDLE.
+. .
+handle: 0-31 (as returned by [*notify_open*])
+ bits: a mask indicating the gpios to be notified.
+. .
- handle: 0-31 (as returned by notify_open())
- bits: a mask indicating the gpios to be notified.
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
- The notification sends state changes for each gpio whose
- corresponding bit in bits is set.
+The notification sends state changes for each gpio whose
+corresponding bit in bits is set.
- Notes
+Notes
- Each notification occupies 12 bytes in the fifo as follows:
+Each notification occupies 12 bytes in the fifo as follows:
- H (16 bit) seqno
- H (16 bit) flags
- I (32 bit) tick
- I (32 bit) level
-*/
+. .
+H (16 bit) seqno
+H (16 bit) flags
+I (32 bit) tick
+I (32 bit) level
+. .
+D*/
+/*F*/
int notify_pause(unsigned handle);
-/*
- Pause notifications on a previously opened handle.
+/*D
+Pause notifications on a previously opened handle.
- Returns 0 if OK, otherwise PI_BAD_HANDLE.
+. .
+handle: 0-31 (as returned by [*notify_open*])
+. .
- handle: 0-31 (as returned by notify_open())
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
- Notifications for the handle are suspended until
- notify_begin() is called again.
-*/
+Notifications for the handle are suspended until
+[*notify_begin*] is called again.
+D*/
+/*F*/
int notify_close(unsigned handle);
-/*
- Stop notifications on a previously opened handle and
- release the handle for reuse.
+/*D
+Stop notifications on a previously opened handle and
+release the handle for reuse.
- Returns 0 if OK, otherwise PI_BAD_HANDLE.
+. .
+handle: 0-31 (as returned by [*notify_open*])
+. .
- handle: 0-31 (as returned by notify_open())
-*/
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+D*/
+/*F*/
int set_watchdog(unsigned user_gpio, unsigned timeout);
-/*
- Sets a watchdog for a gpio.
+/*D
+Sets a watchdog for a gpio.
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO
- or PI_BAD_WDOG_TIMEOUT.
+. .
+user_gpio: 0-31.
+ timeout: 0-60000.
+. .
- user_gpio: 0-31.
- timeout: 0-60000.
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO
+or PI_BAD_WDOG_TIMEOUT.
- The watchdog is nominally in milliseconds.
+The watchdog is nominally in milliseconds.
- Only one watchdog may be registered per gpio.
+Only one watchdog may be registered per gpio.
- The watchdog may be cancelled by setting timeout to 0.
+The watchdog may be cancelled by setting timeout to 0.
- If no level change has been detected for the gpio for timeout
- milliseconds any notification for the gpio has a report written
- to the fifo with the flags set to indicate a watchdog timeout.
+If no level change has been detected for the gpio for timeout
+milliseconds any notification for the gpio has a report written
+to the fifo with the flags set to indicate a watchdog timeout.
- The callback() and callback_ex functions interpret the flags and will
- call registered callbacks for the gpio with level TIMEOUT.
-*/
+The [*callback*] and [*callback_ex*] functions interpret the flags
+and will call registered callbacks for the gpio with level TIMEOUT.
+D*/
+/*F*/
uint32_t read_bank_1(void);
-/*
- Read the levels of the bank 1 gpios (gpios 0-31).
+/*D
+Read the levels of the bank 1 gpios (gpios 0-31).
- The returned 32 bit integer has a bit set if the corresponding
- gpio is logic 1. Gpio n has bit value (1<<n).
-*/
+The returned 32 bit integer has a bit set if the corresponding
+gpio is logic 1. Gpio n has bit value (1<<n).
+D*/
+/*F*/
uint32_t read_bank_2(void);
-/*
- Read the levels of the bank 2 gpios (gpios 32-53).
+/*D
+Read the levels of the bank 2 gpios (gpios 32-53).
- The returned 32 bit integer has a bit set if the corresponding
- gpio is logic 1. Gpio n has bit value (1<<(n-32)).
-*/
+The returned 32 bit integer has a bit set if the corresponding
+gpio is logic 1. Gpio n has bit value (1<<(n-32)).
+D*/
-int clear_bank_1(uint32_t levels);
-/*
- Clears gpios 0-31 if the corresponding bit in levels is set.
+/*F*/
+int clear_bank_1(uint32_t bits);
+/*D
+Clears gpios 0-31 if the corresponding bit in bits is set.
- Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+. .
+bits: a bit mask with 1 set if the corresponding gpio is
+ to be cleared.
+. .
- A status of PI_SOME_PERMITTED indicates that the user is not
- allowed to write to one or more of the gpios.
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
- levels: a bit mask with 1 set if the corresponding gpio is
- to be cleared.
-*/
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+D*/
-int clear_bank_2(uint32_t levels);
-/*
- Clears gpios 32-53 if the corresponding bit (0-21) in levels is set.
+/*F*/
+int clear_bank_2(uint32_t bits);
+/*D
+Clears gpios 32-53 if the corresponding bit (0-21) in bits is set.
- Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+. .
+bits: a bit mask with 1 set if the corresponding gpio is
+ to be cleared.
+. .
- A status of PI_SOME_PERMITTED indicates that the user is not
- allowed to write to one or more of the gpios.
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
- levels: a bit mask with 1 set if the corresponding gpio is
- to be cleared.
-*/
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+D*/
-int set_bank_1(uint32_t levels);
-/*
- Sets gpios 0-31 if the corresponding bit in levels is set.
+/*F*/
+int set_bank_1(uint32_t bits);
+/*D
+Sets gpios 0-31 if the corresponding bit in bits is set.
- Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+. .
+bits: a bit mask with 1 set if the corresponding gpio is
+ to be set.
+. .
- A status of PI_SOME_PERMITTED indicates that the user is not
- allowed to write to one or more of the gpios.
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
- levels: a bit mask with 1 set if the corresponding gpio is
- to be set.
-*/
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+D*/
-int set_bank_2(uint32_t levels);
-/*
- Sets gpios 32-53 if the corresponding bit (0-21) in levels is set.
+/*F*/
+int set_bank_2(uint32_t bits);
+/*D
+Sets gpios 32-53 if the corresponding bit (0-21) in bits is set.
- Returns 0 if OK, otherwise PI_SOME_PERMITTED.
+. .
+bits: a bit mask with 1 set if the corresponding gpio is
+ to be set.
+. .
- A status of PI_SOME_PERMITTED indicates that the user is not
- allowed to write to one or more of the gpios.
+Returns 0 if OK, otherwise PI_SOME_PERMITTED.
- levels: a bit mask with 1 set if the corresponding gpio is
- to be set.
-*/
+A status of PI_SOME_PERMITTED indicates that the user is not
+allowed to write to one or more of the gpios.
+D*/
+/*F*/
uint32_t get_current_tick(void);
-/*
-
- Gets the current system tick.
+/*D
+Gets the current system tick.
- Tick is the number of microseconds since system boot.
+Tick is the number of microseconds since system boot.
- As tick is an unsigned 32 bit quantity it wraps around after
- 2**32 microseconds, which is approximately 1 hour 12 minutes.
+As tick is an unsigned 32 bit quantity it wraps around after
+2**32 microseconds, which is approximately 1 hour 12 minutes.
-*/
+D*/
+/*F*/
uint32_t get_hardware_revision(void);
-/*
- Get the Pi's hardware revision number.
+/*D
+Get the Pi's hardware revision number.
- It is unfortunate that Pi boards have been named Revision.1 and
- Revision.2. That use of the word revision is distinct from the
- Pi's hardware revision number.'
+The hardware revision is the last 4 characters on the Revision line
+of /proc/cpuinfo.
- The hardware revision is the last 4 characters on the Revision line
- of /proc/cpuinfo.
+If the hardware revision can not be found or is not a valid
+hexadecimal number the function returns 0.
- The revision number can be used to determine the assignment of gpios
- to pins.
+The revision number can be used to determine the assignment of gpios
+to pins.
- There are at least two types of board.
+There are currently three types of board.
- Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
- Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
- gpios 28-31 on P5.
+Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
- Type 1 boards have hardware revision numbers of 2 and 3.
+Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
+gpios 28-31 on P5.
- Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+Type 3 has a 40 pin connector rather than the 26 pin connector of
+the earlier boards. Gpios 0 to 27 are brought out to the connector.
- If the hardware revision can not be found or is not a valid
- hexadecimal number the function returns 0.
-*/
+Type 1 boards have hardware revision numbers of 2 and 3.
+
+Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+Type 3 boards have hardware revision number 16.
+D*/
+
+/*F*/
uint32_t get_pigpio_version(void);
-/*
- Returns the pigpio version.
-*/
+/*D
+Returns the pigpio version.
+D*/
+/*F*/
int wave_clear(void);
-/* This function clears all waveforms and any data added by calls to the
- wave_add_* functions.
+/*D
+This function clears all waveforms and any data added by calls to the
+[*wave_add_**] functions.
- Returns 0 if OK.
-*/
+Returns 0 if OK.
+D*/
+/*F*/
int wave_add_new(void);
-/* This function starts a new empty waveform. You wouldn't normally need
- to call this function as it is automatically called after a waveform is
- created with the wave_create function.
+/*D
+This function starts a new empty waveform. You wouldn't normally need
+to call this function as it is automatically called after a waveform is
+created with the [*wave_create*] function.
- Returns 0 if OK.
-*/
+Returns 0 if OK.
+D*/
+/*F*/
int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses);
-/* This function adds a number of pulses to the current waveform.
-
- Returns the new total number of pulses in the current waveform if OK,
- otherwise PI_TOO_MANY_PULSES.
+/*D
+This function adds a number of pulses to the current waveform.
- The pulses are interleaved in time order within the existing waveform
- (if any).
+. .
+numPulses: the number of pulses.
+ pulses: an array of pulses.
+. .
- Merging allows the waveform to be built in parts, that is the settings
- for gpio#1 can be added, and then gpio#2 etc.
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_TOO_MANY_PULSES.
- If the added waveform is intended to start after or within the existing
- waveform then the first pulse should consist solely of a delay.
-*/
-
-int wave_add_serial
- (unsigned gpio, unsigned baud, unsigned offset, unsigned numChar, char *str);
-/* This function adds a waveform representing serial data to the
- existing waveform (if any). The serial data starts offset microseconds
- from the start of the waveform.
+The pulses are interleaved in time order within the existing waveform
+(if any).
- Returns the new total number of pulses in the current waveform if OK,
- otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS, or
- PI_TOO_MANY_PULSES.
+Merging allows the waveform to be built in parts, that is the settings
+for gpio#1 can be added, and then gpio#2 etc.
- NOTES:
-
- The serial data is formatted as one start bit, eight data bits, and one
- stop bit.
-
- It is legal to add serial data streams with different baud rates to
- the same waveform.
-*/
+If the added waveform is intended to start after or within the existing
+waveform then the first pulse should consist solely of a delay.
+D*/
+/*F*/
+int wave_add_serial
+ (unsigned user_gpio, unsigned bbBaud, unsigned offset,
+ unsigned numChar, char *str);
+/*D
+This function adds a waveform representing serial data to the
+existing waveform (if any). The serial data starts offset microseconds
+from the start of the waveform.
+
+. .
+user_gpio: 0-31.
+ bbBaud: 100-250000
+ offset: 0-
+ numChar: 1-
+ str: an array of chars.
+. .
+
+Returns the new total number of pulses in the current waveform if OK,
+otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_TOO_MANY_CHARS, or
+PI_TOO_MANY_PULSES.
+
+NOTES:
+
+The serial data is formatted as one start bit, eight data bits, and one
+stop bit.
+
+It is legal to add serial data streams with different baud rates to
+the same waveform.
+D*/
+
+/*F*/
int wave_create(void);
-/* This function creates a waveform from the data provided by the prior
- calls to the wave_add_* functions. Upon success a positive wave id
- is returned.
+/*D
+This function creates a waveform from the data provided by the prior
+calls to the [*wave_add_**] functions. Upon success a positive wave id
+is returned.
- The data provided by the wave_add_* functions is consumed by this
- function.
+The data provided by the [*wave_add_**] functions is consumed by this
+function.
- As many waveforms may be created as there is space available. The
- wave id is passed to wave_send_* to specify the waveform to transmit.
+As many waveforms may be created as there is space available. The
+wave id is passed to [*wave_send_**] to specify the waveform to transmit.
- Normal usage would be
+Normal usage would be
- Step 1. wave_clear to clear all waveforms and added data.
+Step 1. [*wave_clear*] to clear all waveforms and added data.
- Step 2. wave_add_* calls to supply the waveform data.
+Step 2. [*wave_add_**] calls to supply the waveform data.
- Step 3. wave_create to create the waveform and get a unique id
+Step 3. [*wave_create*] to create the waveform and get a unique id
- Repeat steps 2 and 3 as needed.
+Repeat steps 2 and 3 as needed.
- Step 4. wave_send_* with the id of the waveform to transmit.
+Step 4. [*wave_send_**] with the id of the waveform to transmit.
- A waveform comprises one or more pulses. Each pulse consists of a
- gpioPulse_t structure.
+A waveform comprises one or more pulses. Each pulse consists of a
+[*gpioPulse_t*] structure.
- typedef struct
- {
- uint32_t gpioOn;
- uint32_t gpioOff;
- uint32_t usDelay;
- } gpioPulse_t;
+. .
+typedef struct
+{
+ uint32_t gpioOn;
+ uint32_t gpioOff;
+ uint32_t usDelay;
+} gpioPulse_t;
+. .
- The fields specify
+The fields specify
- 1) the gpios to be switched on at the start of the pulse.
- 2) the gpios to be switched off at the start of the pulse.
- 3) the delay in microseconds before the next pulse.
+1) the gpios to be switched on at the start of the pulse.
+2) the gpios to be switched off at the start of the pulse.
+3) the delay in microseconds before the next pulse.
- Any or all the fields can be zero. It doesn't make any sense to
- set all the fields to zero (the pulse will be ignored).
+Any or all the fields can be zero. It doesn't make any sense to
+set all the fields to zero (the pulse will be ignored).
- When a waveform is started each pulse is executed in order with the
- specified delay between the pulse and the next.
+When a waveform is started each pulse is executed in order with the
+specified delay between the pulse and the next.
- Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
- PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
-*/
+Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
+PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
+D*/
+/*F*/
int wave_delete(unsigned wave_id);
-/* This function deletes all created waveforms with ids greater than or
- equal to wave_id.
+/*D
+This function deletes all created waveforms with ids greater than or
+equal to wave_id.
- Wave ids are allocated in order, 0, 1, 2, etc.
+. .
+wave_id: >=0, as returned by [*wave_create*].
+. .
- Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
-*/
+Wave ids are allocated in order, 0, 1, 2, etc.
+
+Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
+D*/
+/*F*/
int wave_tx_start(void);
-/* This function is deprecated and should no longer be used. Use
- wave_create/wave_send_* instead.
-*/
+/*D
+This function is deprecated and should no longer be used. Use
+[*wave_create*]/[*wave_send_**] instead.
+D*/
+/*F*/
int wave_tx_repeat(void);
-/* This function is deprecated and should no longer be used. Use
- wave_create/wave_send_* instead.
-*/
+/*D
+This function is deprecated and should no longer be used. Use
+[*wave_create*]/[*wave_send_**] instead.
+D*/
+/*F*/
int wave_send_once(unsigned wave_id);
-/* This function transmits the waveform with id wave_id. The waveform
- is sent once.
+/*D
+This function transmits the waveform with id wave_id. The waveform
+is sent once.
- Returns the number of DMA control blocks in the waveform if OK,
- otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
-*/
+. .
+wave_id: >=0, as returned by [*wave_create*].
+. .
+
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
+D*/
+/*F*/
int wave_send_repeat(unsigned wave_id);
-/* This function transmits the waveform with id wave_id. The waveform
- cycles until cancelled (either by the sending of a new waveform or
- by wave_tx_stop).
+/*D
+This function transmits the waveform with id wave_id. The waveform
+cycles until cancelled (either by the sending of a new waveform or
+by [*wave_tx_stop*]).
- Returns the number of DMA control blocks in the waveform if OK,
- otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
-*/
+. .
+wave_id: >=0, as returned by [*wave_create*].
+. .
+
+Returns the number of DMA control blocks in the waveform if OK,
+otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
+D*/
+/*F*/
int wave_tx_busy(void);
-/* This function checks to see if a waveform is currently being
- transmitted.
+/*D
+This function checks to see if a waveform is currently being
+transmitted.
- Returns 1 if a waveform is currently being transmitted, otherwise 0.
-*/
+Returns 1 if a waveform is currently being transmitted, otherwise 0.
+D*/
+/*F*/
int wave_tx_stop(void);
-/* This function stops the transmission of the current waveform.
+/*D
+This function stops the transmission of the current waveform.
- Returns 0 if OK.
+Returns 0 if OK.
- This function is intended to stop a waveform started with the repeat mode.
-*/
+This function is intended to stop a waveform started with the repeat mode.
+D*/
+/*F*/
int wave_get_micros(void);
-/* This function returns the length in microseconds of the current
- waveform.
-*/
+/*D
+This function returns the length in microseconds of the current
+waveform.
+D*/
+/*F*/
int wave_get_high_micros(void);
-/* This function returns the length in microseconds of the longest waveform
- created since the pigpio daemon was started..
-*/
+/*D
+This function returns the length in microseconds of the longest waveform
+created since the pigpio daemon was started.
+D*/
+/*F*/
int wave_get_max_micros(void);
-/* This function returns the maximum possible size of a waveform in
- microseconds.
-*/
+/*D
+This function returns the maximum possible size of a waveform in
+microseconds.
+D*/
+/*F*/
int wave_get_pulses(void);
-/* This function returns the length in pulses of the current waveform.
-*/
+/*D
+This function returns the length in pulses of the current waveform.
+D*/
+/*F*/
int wave_get_high_pulses(void);
-/* This function returns the length in pulses of the longest waveform
- created since the pigpio daemon was started..
-*/
+/*D
+This function returns the length in pulses of the longest waveform
+created since the pigpio daemon was started.
+D*/
+/*F*/
int wave_get_max_pulses(void);
-/* This function returns the maximum possible size of a waveform in pulses.
-*/
+/*D
+This function returns the maximum possible size of a waveform in pulses.
+D*/
+/*F*/
int wave_get_cbs(void);
-/* This function returns the length in DMA control blocks of the current
- waveform.
-*/
+/*D
+This function returns the length in DMA control blocks of the current
+waveform.
+D*/
+/*F*/
int wave_get_high_cbs(void);
-/* This function returns the length in DMA control blocks of the longest
- waveform created since the pigpio daemon was started..
-*/
+/*D
+This function returns the length in DMA control blocks of the longest
+waveform created since the pigpio daemon was started.
+D*/
+/*F*/
int wave_get_max_cbs(void);
-/* This function returns the maximum possible size of a waveform in DMA
- control blocks.
-*/
-
-int gpio_trigger(unsigned gpio, unsigned pulseLen, unsigned level);
-/* This function sends a trigger pulse to a gpio. The gpio is set to
- level for pulseLen microseconds and then reset to not level.
-
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
- PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
-*/
-
+/*D
+This function returns the maximum possible size of a waveform in DMA
+control blocks.
+D*/
+
+/*F*/
+int gpio_trigger(unsigned user_gpio, unsigned pulseLen, unsigned level);
+/*D
+This function sends a trigger pulse to a gpio. The gpio is set to
+level for pulseLen microseconds and then reset to not level.
+
+. .
+user_gpio: 0-31.
+ pulseLen: 1-50.
+ level: 0,1.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
+PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
+D*/
+
+/*F*/
int store_script(char *script);
-/* This function stores a script for later execution.
+/*D
+This function stores a script for later execution.
- The function returns a script id if the script is valid,
- otherwise PI_BAD_SCRIPT.
-*/
+. .
+script: the text of the script.
+. .
+The function returns a script id if the script is valid,
+otherwise PI_BAD_SCRIPT.
+D*/
+
+/*F*/
int run_script(unsigned script_id, unsigned numPar, uint32_t *param);
-/* This function runs a stored script.
+/*D
+This function runs a stored script.
- The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
- PI_TOO_MANY_PARAM
+. .
+script_id: >=0, as returned by [*store_script*].
+ numPar: 0-10, the number of parameters.
+ param: an array of parameters.
+. .
- param is an array of up to 10 parameters which may be referenced in
- the script as param 0 to param 9..
-*/
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
+PI_TOO_MANY_PARAM
+
+param is an array of up to 10 parameters which may be referenced in
+the script as p0 to p9.
+D*/
+/*F*/
int script_status(unsigned script_id, uint32_t *param);
-/* This function returns the run status of a stored script as well
- as the current values of parameters 0 to 9.
+/*D
+This function returns the run status of a stored script as well
+as the current values of parameters 0 to 9.
- The function returns greater than or equal to 0 if OK,
- otherwise PI_BAD_SCRIPT_ID.
+. .
+script_id: >=0, as returned by [*store_script*].
+ param: an array to hold the returned 10 parameters.
+. .
- The run status may be
+The function returns greater than or equal to 0 if OK,
+otherwise PI_BAD_SCRIPT_ID.
- PI_SCRIPT_HALTED
- PI_SCRIPT_RUNNING
- PI_SCRIPT_WAITING
- PI_SCRIPT_FAILED
+The run status may be
- The current value of script parameters 0 to 9 are returned in param.
-*/
+. .
+PI_SCRIPT_INITING
+PI_SCRIPT_HALTED
+PI_SCRIPT_RUNNING
+PI_SCRIPT_WAITING
+PI_SCRIPT_FAILED
+. .
+
+The current value of script parameters 0 to 9 are returned in param.
+D*/
+/*F*/
int stop_script(unsigned script_id);
-/* This function stops a running script.
+/*D
+This function stops a running script.
- The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
-*/
+. .
+script_id: >=0, as returned by [*store_script*].
+. .
+
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+D*/
+/*F*/
int delete_script(unsigned script_id);
-/* This function deletes a stored script.
+/*D
+This function deletes a stored script.
- The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
-*/
+. .
+script_id: >=0, as returned by [*store_script*].
+. .
-int bb_serial_read_open(unsigned user_gpio, unsigned baud);
-/* This function opens a gpio for bit-banged reading of serial data.
+The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
+D*/
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
- or PI_GPIO_IN_USE.
+/*F*/
+int bb_serial_read_open(unsigned user_gpio, unsigned bbBaud);
+/*D
+This function opens a gpio for bit bang reading of serial data.
- The serial data is returned in a cyclic buffer and is read using
- bb_serial_read().
+. .
+user_gpio: 0-31.
+ bbBaud: 100-250000
+. .
- It is the caller's responsibility to read data from the cyclic buffer
- in a timely fashion.
-*/
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
+or PI_GPIO_IN_USE.
+
+The serial data is returned in a cyclic buffer and is read using
+bb_serial_read.
+It is the caller's responsibility to read data from the cyclic buffer
+in a timely fashion.
+D*/
+
+/*F*/
int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize);
-/* This function copies up to bufSize bytes of data read from the
- bit-bang serial cyclic buffer to the buffer starting at buf.
+/*D
+This function copies up to bufSize bytes of data read from the
+bit bang serial cyclic buffer to the buffer starting at buf.
- Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
- or PI_NOT_SERIAL_GPIO.
-*/
+. .
+user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
+ buf: an array to receive the read bytes.
+ bufSize: 0-
+. .
+
+Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
+or PI_NOT_SERIAL_GPIO.
+D*/
+/*F*/
int bb_serial_read_close(unsigned user_gpio);
-/* This function closes a gpio for bit-banged reading of serial data.
+/*D
+This function closes a gpio for bit bang reading of serial data.
- Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
-*/
+. .
+user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
+. .
-int i2c_open(unsigned bus, unsigned addr, unsigned flags);
-/* This returns a handle for the device at address addr on I2C bus bus.
+Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
+D*/
- No flags are currently defined. This parameter should be set to zero.
-*/
+/*F*/
+int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags);
+/*D
+This returns a handle for the device at address i2c_addr on bus i2c_bus.
+
+. .
+ i2c_bus: 0-1.
+ i2c_addr: 0x08-0x77.
+i2c_flags: 0.
+. .
+No flags are currently defined. This parameter should be set to zero.
+
+Returns a handle (>=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
+PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
+D*/
+
+/*F*/
int i2c_close(unsigned handle);
-/* This closes the I2C device associated with the handle.
-*/
+/*D
+This closes the I2C device associated with the handle.
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+D*/
+
+/*F*/
int i2c_read_device(unsigned handle, char *buf, unsigned count);
-/* This reads count bytes from the raw device into buf.
-*/
+/*D
+This reads count bytes from the raw device into buf.
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+ buf: an array to receive the read data bytes.
+ count: >0, the number of bytes to read.
+. .
+
+Returns count (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_READ_FAILED.
+D*/
+
+/*F*/
int i2c_write_device(unsigned handle, char *buf, unsigned count);
-/* This writes count bytes from buf to the raw device.
-*/
+/*D
+This writes count bytes from buf to the raw device.
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+ buf: an array containing the data bytes to write.
+ count: >0, the number of bytes to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+D*/
+
+/*F*/
int i2c_write_quick(unsigned handle, unsigned bit);
-/* This sends a single bit to the device (in the Rd/Wr bit).
+/*D
+This sends a single bit (in the Rd/Wr bit) to the device associated
+with handle.
- Quick command. smbus 2.0 5.5.1
-*/
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+ bit: 0-1, the value to write.
+. .
-int i2c_write_byte(unsigned handle, unsigned val);
-/* This operation is the reverse of i2cReadByte: it sends a single byte
- to a device.
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
- Send byte. smbus 2.0 5.5.2
-*/
+Quick command. smbus 2.0 5.5.1
+D*/
-int i2c_read_byte(unsigned handle);
-/* This reads a single byte from a device, without specifying a device
- register. Some devices are so simple that this interface is enough;
- for others, it is a shorthand if you want to read the same register
- as in the previous SMBus command.
+/*F*/
+int i2c_write_byte(unsigned handle, unsigned bVal);
+/*D
+This sends a single byte to the device associated with handle.
- Receive byte. smbus 2.0 5.5.3
-*/
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+ bVal: 0-0xFF, the value to write.
+. .
-int i2c_write_byte_data(unsigned handle, unsigned reg, unsigned val);
-/* This writes a single byte to a device, to a designated register.
- This is the opposite of the i2cReadByte function.
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
- Write byte. smbus 2.0 5.5.4
-*/
+Send byte. smbus 2.0 5.5.2
+D*/
-int i2c_write_word_data(unsigned handle, unsigned reg, unsigned val);
-/* This is the opposite of the i2cReadWordData operation. 16 bits
- of data is written to a device, to the designated register.
+/*F*/
+int i2c_read_byte(unsigned handle);
+/*D
+This reads a single byte from the device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*i2c_open*].
+. .
+
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+or PI_I2C_READ_FAILED.
+
+Receive byte. smbus 2.0 5.5.3
+D*/
+
+/*F*/
+int i2c_write_byte_data(unsigned handle, unsigned i2c_reg, unsigned bVal);
+/*D
+This writes a single byte to the specified register of the device
+associated with handle.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write.
+ bVal: 0-0xFF, the value to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+Write byte. smbus 2.0 5.5.4
+D*/
+
+/*F*/
+int i2c_write_word_data(unsigned handle, unsigned i2c_reg, unsigned wVal);
+/*D
+This writes a single 16 bit word to the specified register of the device
+associated with handle.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write.
+ wVal: 0-0xFFFF, the value to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+
+Write word. smbus 2.0 5.5.4
+D*/
+
+/*F*/
+int i2c_read_byte_data(unsigned handle, unsigned i2c_reg);
+/*D
+This reads a single byte from the specified register of the device
+associated with handle.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to read.
+. .
+
+Returns the byte read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+Read byte. smbus 2.0 5.5.5
+D*/
+
+/*F*/
+int i2c_read_word_data(unsigned handle, unsigned i2c_reg);
+/*D
+This reads a single 16 bit word from the specified register of the device
+associated with handle.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to read.
+. .
+
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+Read word. smbus 2.0 5.5.5
+D*/
+
+/*F*/
+int i2c_process_call(unsigned handle, unsigned i2c_reg, unsigned wVal);
+/*D
+This writes 16 bits of data to the specified register of the device
+associated with handle and and reads 16 bits of data in return.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write/read.
+ wVal: 0-0xFFFF, the value to write.
+. .
+
+Returns the word read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+
+Process call. smbus 2.0 5.5.6
+D*/
+
+/*F*/
+int i2c_write_block_data(
+unsigned handle, unsigned i2c_reg, char *buf, unsigned count);
+/*D
+This writes up to 32 bytes to the specified register of the device
+associated with handle.
- Write word. smbus 2.0 5.5.4
-*/
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write.
+ buf: an array with the data to send.
+ count: 1-32, the number of bytes to write.
+. .
-int i2c_read_byte_data(unsigned handle, unsigned reg);
-/* This reads a single byte from a device, from a designated register.
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
- Read byte. smbus 2.0 5.5.5
-*/
+Block write. smbus 2.0 5.5.7
+D*/
-int i2c_read_word_data(unsigned handle, unsigned reg);
-/* This operation is very like i2cReadByte; again, data is read
- from a device, from a designated register. But this time, the data
- is a complete word (16 bits).
+/*F*/
+int i2c_read_block_data(unsigned handle, unsigned i2c_reg, char *buf);
+/*D
+This reads a block of up to 32 bytes from the specified register of
+the device associated with handle.
- Read word. smbus 2.0 5.5.5
-*/
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to read.
+ buf: an array to receive the read data.
+. .
-int i2c_process_call(unsigned handle, unsigned reg, unsigned val);
-/* This command selects a device register, sends 16 bits of data to it,
- and reads 16 bits of data in return.
+The amount of returned data is set by the device.
- Process call. smbus 2.0 5.5.6
-*/
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
-int i2c_write_block_data(
- unsigned handle, unsigned reg, char *buf, unsigned count);
-/* The opposite of the i2cReadBlockData command, this writes up to
- 32 bytes to a device, to a designated register. The amount of data
- is specified in the count byte.
+Block read. smbus 2.0 5.5.7
+D*/
- Block write. smbus 2.0 5.5.7
-*/
+/*F*/
+int i2c_block_process_call(
+unsigned handle, unsigned i2c_reg, char *buf, unsigned count);
+/*D
+This writes data bytes to the specified register of the device
+associated with handle and reads a device specified number
+of bytes of data in return.
-int i2c_read_block_data(unsigned handle, unsigned reg, char *buf);
-/* This command reads a block of up to 32 bytes from a device, from a
- designated register. The amount of returned data is set by the device.
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write/read.
+ buf: an array with the data to send and to receive the read data.
+ count: 1-32, the number of bytes to write.
+. .
- Block read. smbus 2.0 5.5.7
-*/
-int i2c_block_process_call(
- unsigned handle, unsigned reg, char *buf, unsigned count);
-/* This command selects a device register, sends count bytes of data
- to it, and reads a device specified number of bytes of data in return.
+Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
- The smbus 2.0 documentation states that a minimum of 1 byte may be
- sent and a minimum of 1 byte may be received. The total number of
- bytes sent/received must be 32 or less.
+The smbus 2.0 documentation states that a minimum of 1 byte may be
+sent and a minimum of 1 byte may be received. The total number of
+bytes sent/received must be 32 or less.
- Block write-block read. smbus 2.0 5.5.8
-*/
+Block write-block read. smbus 2.0 5.5.8
+D*/
+/*F*/
int i2c_read_i2c_block_data(
- unsigned handle, unsigned reg, char *buf, unsigned count);
-/* This command reads a block of bytes from a device, from a
- designated register. The count may be 1-32.
-*/
+unsigned handle, unsigned i2c_reg, char *buf, unsigned count);
+/*D
+This reads count bytes from the specified register of the device
+associated with handle . The count may be 1-32.
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to read.
+ buf: an array to receive the read data.
+ count: 1-32, the number of bytes to read.
+. .
-int i2c_write_i2c_block_data(
- unsigned handle, unsigned reg, char *buf, unsigned count);
-/* The opposite of the i2cReadI2CBlockData command, this writes bytes to
- a device, to a designated register.. Note that command lengths of 0, 2,
- or more bytes are supported as they are indistinguishable from data.
- Count may be 1-32.
-*/
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, or PI_I2C_READ_FAILED.
+D*/
-int spi_open(unsigned channel, unsigned speed, unsigned flags);
-/* This function returns a handle for the SPI device on channel.
- Data will be transferred at speed bits per second.
- The bottom two bits of flags define the SPI mode as follows.
- bit bit
- 1 0
- Mode POL PHA
- 0 0 0
- 1 0 1
- 2 1 0
- 3 1 1
+/*F*/
+int i2c_write_i2c_block_data(
+unsigned handle, unsigned i2c_reg, char *buf, unsigned count);
+/*D
+This writes 1 to 32 bytes to the specified register of the device
+associated with handle.
+
+. .
+ handle: >=0, as returned by a call to [*i2c_open*].
+i2c_reg: 0-255, the register to write.
+ buf: the data to write.
+ count: 1-32, the number of bytes to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_I2C_WRITE_FAILED.
+D*/
+
+/*F*/
+int spi_open(unsigned spi_channel, unsigned spi_baud, unsigned spi_flags);
+/*D
+This function returns a handle for the SPI device on channel.
+Data will be transferred at baud bits per second.
+
+. .
+spi_channel: 0-1.
+ spi_baud: >1.
+ spi_flags: 0-3.
+. .
+
+Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
+PI_BAD_SPI_SPEED, PI_BAD_FLAGS, or PI_SPI_OPEN_FAILED.
+
+The least significant two bits of flags define the SPI mode as follows.
+
+. .
+ bit bit
+ 1 0
+Mode POL PHA
+ 0 0 0
+ 1 0 1
+ 2 1 0
+ 3 1 1
+. .
+
+The other bits in flags should be set to zero.
+D*/
+
+/*F*/
+int spi_close(unsigned handle);
+/*D
+This functions closes the SPI device identified by the handle.
- The other bits in flags should be set to zero.
-*/
+. .
+handle: >=0, as returned by a call to [*spi_open*].
+. .
-int spi_close(unsigned handle);
-/* This functions closes the SPI device identified by the handle.
-*/
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+D*/
+/*F*/
int spi_read(unsigned handle, char *buf, unsigned count);
-/* This function reads count bytes of data from the SPI
- device associated with the handle.
-*/
+/*D
+This function reads count bytes of data from the SPI
+device associated with the handle.
+
+. .
+handle: >=0, as returned by a call to [*spi_open*].
+ buf: an array to receive the read data bytes.
+ count: the number of bytes to read.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+D*/
+/*F*/
int spi_write(unsigned handle, char *buf, unsigned count);
-/* This function writes count bytes of data from buf to the SPI
- device associated with the handle.
-*/
+/*D
+This function writes count bytes of data from buf to the SPI
+device associated with the handle.
+
+. .
+handle: >=0, as returned by a call to [*spi_open*].
+ buf: the data bytes to write.
+ count: the number of bytes to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+D*/
+/*F*/
int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count);
-/* This function writes count bytes of data from txBuf to the SPI
- device associated with the handle.
+/*D
+This function transfers count bytes of data from txBuf to the SPI
+device associated with the handle. Simultaneously count bytes of
+data are read from the device and placed in rxBuf.
+
+. .
+handle: >=0, as returned by a call to [*spi_open*].
+ txBuf: the data bytes to write.
+ rxBuf: the received data bytes.
+ count: the number of bytes to transfer.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or
+PI_SPI_XFER_FAILED.
+D*/
+
+/*F*/
+int serial_open(char *ser_tty, unsigned ser_baud, unsigned ser_flags);
+/*D
+This function opens a serial device at a specified baud rate
+with specified flags.
+
+. .
+ ser_tty: the serial device to open, /dev/tty*.
+ ser_baud: the baud rate to use.
+ser_flags: 0.
+. .
+
+Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or
+PI_SER_OPEN_FAILED.
+
+No flags are currently defined. This parameter should be set to zero.
+D*/
+
+/*F*/
+int serial_close(unsigned handle);
+/*D
+This function closes the serial device associated with handle.
- The data read from the device is written to rxBuf.
-*/
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+. .
-int serial_open(char *dev, unsigned baud, unsigned flags);
-/* This function open the serial device named dev at baud bits per second.
+Returns 0 if OK, otherwise PI_BAD_HANDLE.
+D*/
- No flags are currently defined. This parameter should be set to zero.
-*/
+/*F*/
+int serial_write_byte(unsigned handle, unsigned bVal);
+/*D
+This function writes bVal to the serial port associated with handle.
-int serial_close(unsigned handle);
-/* This function closes the serial device associated with handle.
-*/
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+. .
-int serial_write_byte(unsigned handle, unsigned val);
-/* This function writes val to the serial port associated with handle.
-*/
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+D*/
+/*F*/
int serial_read_byte(unsigned handle);
-/* This function reads a byte from the serial port associated with handle.
-*/
+/*D
+This function reads a byte from the serial port associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+. .
+
+Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE,
+PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
+D*/
+/*F*/
int serial_write(unsigned handle, char *buf, unsigned count);
-/* This function writes count bytes from buf to the the serial port
- associated with handle.
-*/
+/*D
+This function writes count bytes from buf to the the serial port
+associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+ buf: the array of bytes to write.
+ count: the number of bytes to write.
+. .
+
+Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
+PI_SER_WRITE_FAILED.
+D*/
+/*F*/
int serial_read(unsigned handle, char *buf, unsigned count);
-/* This function reads count bytes from the the serial port
- associated with handle and writes them to buf.
-*/
+/*D
+This function reads up to count bytes from the the serial port
+associated with handle and writes them to buf.
+
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+ buf: an array to receive the read data.
+ count: the maximum number of bytes to read.
+. .
+
+Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE,
+PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
+D*/
+/*F*/
int serial_data_available(unsigned handle);
-/* Returns the number of bytes available to be read from the
- device associated with handle.
-*/
+/*D
+Returns the number of bytes available to be read from the
+device associated with handle.
+
+. .
+handle: >=0, as returned by a call to [*serial_open*].
+. .
+
+Returns the number of bytes of data available (>=0) if OK,
+otherwise PI_BAD_HANDLE.
+D*/
-int callback(unsigned gpio, unsigned edge, CBFunc_t f);
-/*
- This function initialises a new callback.
+/*F*/
+int callback(unsigned user_gpio, unsigned edge, CBFunc_t f);
+/*D
+This function initialises a new callback.
- The function returns a callback id if OK, otherwise pigif_bad_malloc,
- pigif_duplicate_callback, or pigif_bad_callback.
+. .
+user_gpio: 0-31.
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+ f: the callback function.
+. .
- The callback is called with the gpio, edge, and tick, whenever the
- gpio has the identified edge.
-*/
+The function returns a callback id if OK, otherwise pigif_bad_malloc,
+pigif_duplicate_callback, or pigif_bad_callback.
-int callback_ex(unsigned gpio, unsigned edge, CBFuncEx_t f, void *user);
-/*
- This function initialises a new callback.
+The callback is called with the gpio, edge, and tick, whenever the
+gpio has the identified edge.
+D*/
- The function returns a callback id if OK, otherwise pigif_bad_malloc,
- pigif_duplicate_callback, or pigif_bad_callback.
+/*F*/
+int callback_ex
+ (unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata);
+/*D
+This function initialises a new callback.
- The callback is called with the gpio, edge, tick, and user, whenever
- the gpio has the identified edge.
-*/
+. .
+user_gpio: 0-31.
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+ f: the callback function.
+ userdata: a pointer to arbitrary user data.
+. .
-int callback_cancel(unsigned id);
-/*
- This function cancels a callback identified by its id.
+The function returns a callback id if OK, otherwise pigif_bad_malloc,
+pigif_duplicate_callback, or pigif_bad_callback.
- The function returns 0 if OK, otherwise pigif_callback_not_found.
-*/
+The callback is called with the gpio, edge, tick, and user, whenever
+the gpio has the identified edge.
-int wait_for_edge(unsigned gpio, unsigned edge, double timeout);
-/*
- This function waits for edge on the gpio for up to timeout
- seconds.
+D*/
- The function returns 1 if the edge occurred, otherwise 0.
+/*F*/
+int callback_cancel(unsigned callback_id);
+/*D
+This function fim
+cancels a callback identified by its id.
- The function returns when the edge occurs or after the timeout.
-*/
+. .
+callback_id: >=0, as returned by a call to [*callback*] or [*callback_ex*].
+. .
+
+The function returns 0 if OK, otherwise pigif_callback_not_found.
+D*/
+
+/*F*/
+int wait_for_edge(unsigned user_gpio, unsigned edge, double timeout);
+/*D
+This function waits for edge on the gpio for up to timeout
+seconds.
+
+. .
+user_gpio: 0-31.
+ edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE.
+ timeout: >=0.
+. .
+
+The function returns 1 if the edge occurred, otherwise 0.
+
+The function returns when the edge occurs or after the timeout.
+D*/
+
+/*PARAMS
+
+*addrStr::
+A string specifying the host or IP address of the Pi running
+the pigpio daemon. It may be NULL in which case localhost
+is used unless overridden by the PIGPIO_ADDR environment
+variable.
+
+bbBaud::
+The baud rate used for the transmission and reception of bit banged
+serial data.
+
+. .
+PI_WAVE_MIN_BAUD 100
+PI_WAVE_MAX_BAUD 250000
+. .
+
+bit::
+A value of 0 or 1.
+
+bits::
+A value used to select gpios. If bit n of bits is set then gpio n is
+selected.
+
+A convenient way to set bit n is to or in (1<<n).
+
+e.g. to select bits 5, 9, 23 you could use (1<<5) | (1<<9) | (1<<23).
+
+*buf::
+A buffer to hold data being sent or being received.
+
+bufSize::
+The size in bytes of a buffer.
+
+
+bVal::0-255 (Hex 0x0-0xFF, Octal 0-0377)
+An 8-bit byte value.
+
+callback_id::
+A >=0, as returned by a call to [*callback*] or [*callback_ex*]. This is
+passed to [*callback_cancel*] to cancel the callback.
+
+CBFunc_t::
+. .
+typedef void (*CBFunc_t)
+ (unsigned user_gpio, unsigned level, uint32_t tick);
+. .
+
+CBFuncEx_t::
+. .
+typedef void (*CBFuncEx_t)
+ (unsigned user_gpio, unsigned level, uint32_t tick, void * user);
+. .
+
+
+char::
+A single character, an 8 bit quantity able to store 0-255.
+
+count::
+The number of bytes to be transferred in an I2C, SPI, or Serial
+command.
+
+double::
+A floating point number.
+
+dutycycle::0-range
+A number representing the ratio of on time to off time for PWM.
+
+The number may vary between 0 and range (default 255) where
+0 is off and range is fully on.
+
+edge::
+Used to identify a gpio level transition of interest. A rising edge is
+a level change from 0 to 1. A falling edge is a level change from 1 to 0.
+
+. .
+RISING_EDGE 0
+FALLING_EDGE 1
+EITHER_EDGE. 2
+. .
+
+errnum::
+A negative number indicating a function call failed and the nature
+of the error.
+
+f::
+A function.
+
+frequency::0-
+The number of times a gpio is swiched on and off per second. This
+can be set per gpio and may be as little as 5Hz or as much as
+40KHz. The gpio will be on for a proportion of the time as defined
+by its dutycycle.
+
+
+gpio::
+A Broadcom numbered gpio, in the range 0-53.
+
+gpioPulse_t::
+. .
+typedef struct
+{
+uint32_t gpioOn;
+uint32_t gpioOff;
+uint32_t usDelay;
+} gpioPulse_t;
+. .
+
+gpioThreadFunc_t::
+. .
+typedef void *(gpioThreadFunc_t) (void *);
+. .
+
+handle::0-
+A number referencing an object opened by one of [*i2c_open*], [*notify_open*],
+[*serial_open*], and [*spi_open*].
+
+i2c_addr::0x08-0x77
+The address of a device on the I2C bus (0x08 - 0x77)
+
+i2c_bus::0-1
+An I2C bus, 0 or 1.
+
+i2c_flags::0
+Flags which modify an I2C open command. None are currently defined.
+
+i2c_reg:: 0-255
+A register of an I2C device.
+
+
+
+int::
+A whole number, negative or positive.
+
+level::
+The level of a gpio. Low or High.
+
+. .
+PI_OFF 0
+PI_ON 1
+
+PI_CLEAR 0
+PI_SET 1
+
+PI_LOW 0
+PI_HIGH 1
+. .
+
+There is one exception. If a watchdog expires on a gpio the level will be
+reported as PI_TIMEOUT. See [*set_watchdog*].
+
+. .
+PI_TIMEOUT 2
+. .
+
+mode::0-7
+The operational mode of a gpio, normally INPUT or OUTPUT.
+
+. .
+PI_INPUT 0
+PI_OUTPUT 1
+PI_ALT0 4
+PI_ALT1 5
+PI_ALT2 6
+PI_ALT3 7
+PI_ALT4 3
+PI_ALT5 2
+. .
+
+numChar::
+The number of characters in a string (used when the string might contain
+null characters, which would normally terminate the string).
+
+numPar:: 0-10
+The number of parameters passed to a script.
+
+numPulses::
+The number of pulses to be added to a waveform.
+
+offset::
+The associated data starts this number of microseconds from the start of
+the waveform.
+
+*param::
+An array of script parameters.
+
+
+*portStr::
+A string specifying the port address used by the Pi running
+the pigpio daemon. It may be NULL in which case "8888"
+is used unless overridden by the PIGPIO_PORT environment
+variable.
+
+*pth::
+A thread identifier, returned by [*start_thread*].
+
+
+pthread_t::
+A thread identifier.
+
+pud::0-2
+The setting of the pull up/down resistor for a gpio, which may be off,
+pull-up, or pull-down.
+. .
+PI_PUD_OFF 0
+PI_PUD_DOWN 1
+PI_PUD_UP 2
+. .
+
+pulseLen::
+1-50, the length of a trigger pulse in microseconds.
+
+*pulses::
+An array of pulsed to be added to a waveform.
+
+pulsewidth::0, 500-2500
+. .
+PI_SERVO_OFF 0
+PI_MIN_SERVO_PULSEWIDTH 500
+PI_MAX_SERVO_PULSEWIDTH 2500
+. .
+
+
+range::25-40000
+The permissible dutycycle values are 0-range.
+. .
+PI_MIN_DUTYCYCLE_RANGE 25
+PI_MAX_DUTYCYCLE_RANGE 40000
+. .
+
+*rxBuf::
+A pointer to a buffer to receive data.
+
+*script::
+A pointer to the text of a script.
+
+script_id::
+An id of a stored script as returned by [*store_script*].
+
+
+seconds::
+The number of seconds.
+
+ser_baud::
+The baud rate to use on the serial link.
+
+It must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
+4800, 9600, 19200, 38400, 57600, 115200, 230400.
+
+ser_flags::
+Flags which modify a serial open command. None are currently defined.
+
+*ser_tty::
+The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
+
+size_t::
+A standard type used to indicate the size of an object in bytes.
+
+spi_baud::
+The speed in bits per second to use for the SPI device.
+
+
+spi_channel::
+A SPI channel, 0 or 1.
+
+spi_flags::
+Flags which modify a SPI open command. The two least significant bits
+define the SPI mode. The other bits are undefined.
+
+*str::
+ An array of characters.
+
+thread_func::
+A function of type gpioThreadFunc_t used as the main function of a
+thread.
+
+timeout::
+A gpio watchdog timeout in milliseconds.
+. .
+PI_MIN_WDOG_TIMEOUT 0
+PI_MAX_WDOG_TIMEOUT 60000
+. .
+
+*txBuf::
+An array of bytes to transmit.
+
+uint32_t::0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)
+A 32-bit unsigned value.
+
+unsigned::
+A whole number >= 0.
+
+user_gpio::
+0-31, a Broadcom numbered gpio.
+
+*userdata::
+A pointer to arbitrary user data. This may be used to identify the instance.
+
+void::
+Denoting no parameter is required
+
+wave_add_*::
+One of [*wave_add_new*], [*wave_add_generic*], [*wave_add_serial*].
+
+wave_id::
+A number representing a waveform created by [*wave_create*].
+
+wave_send_*::
+One of [*wave_send_once*], [*wave_send_repeat*].
+
+wVal::0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)
+A 16-bit word value.
+
+PARAMS*/
+
+/*DEF_S pigpiod_if Error Codes*/
+
+typedef enum
+{
+ pigif_bad_send = -2000,
+ pigif_bad_recv = -2001,
+ pigif_bad_getaddrinfo = -2002,
+ pigif_bad_connect = -2003,
+ pigif_bad_socket = -2004,
+ pigif_bad_noib = -2005,
+ pigif_duplicate_callback = -2006,
+ pigif_bad_malloc = -2007,
+ pigif_bad_callback = -2008,
+ pigif_notify_failed = -2009,
+ pigif_callback_not_found = -2010,
+} pigifError_t;
+
+/*DEF_E*/
#endif
diff --git a/pigs.1 b/pigs.1
new file mode 100644
index 0000000..4154690
--- /dev/null
+++ b/pigs.1
@@ -0,0 +1,3486 @@
+
+." Process this file with
+." groff -man -Tascii foo.1
+."
+.TH pigs 1 2012-2014 Linux "pigpio archive"
+.SH NAME
+pigs - command line socket access to the pigpio daemon.
+
+/dev/pigpio - command line pipe access to the pigpio daemon.
+
+.SH SYNOPSIS
+
+.B sudo pigpiod
+
+then
+
+.B pigs {command}+
+
+or
+
+.B "echo {command}+ >/dev/pigpio"
+
+.SH DESCRIPTION
+
+
+.br
+The socket and pipe interfaces allow control of the gpios by passing
+messages to the running pigpio library.
+
+.br
+The normal way to start the pigpio library would be as a daemon during boot.
+
+.br
+
+.EX
+sudo pigpiod
+.br
+
+.EE
+
+.br
+pigs is a program and internally uses the socket interface to pigpio
+whereas /dev/pigpio uses the pipe interface.
+
+.br
+.SS Features
+.br
+o PWM on any of gpios 0-31
+
+.br
+o servo pulses on any of gpios 0-31
+
+.br
+o reading/writing all of the gpios in a bank as one operation
+
+.br
+o individually setting gpio modes, reading and writing
+
+.br
+o notifications when any of gpios 0-31 change state
+
+.br
+o the construction of output waveforms with microsecond timing
+
+.br
+o I2C, SPI, and serial link wrappers
+
+.br
+o creating and running scripts on the pigpio daemon
+
+.br
+.SS gpios
+.br
+ALL gpios are identified by their Broadcom number.
+
+.br
+.SS Usage
+.br
+pigs and the socket interface share the same commands and are invoked in
+a similar fashion from the command line.
+
+.br
+The pigpio library must be running, either by running a program linked
+with the library or starting the pigpio daemon (sudo pigpiod).
+
+.br
+pigs {command}+
+
+.br
+echo "{command}+" >/dev/pigpio
+
+.br
+pigs will show the result of the command on screen.
+
+.br
+The results of /dev/pigpio commands need to be read from /dev/pigout,
+e.g. cat /dev/pigout (try cat /dev/pigout& so that all subsequent
+results are shown on screen).
+
+.br
+In both cases if an error was detected a message will have been written
+to /dev/pigerr (try cat /dev/pigerr&). This is likely to be more
+informative than the message returned by pigs or the error code
+returned by the pipe interface.
+
+.br
+Several commands may be entered on a line. If present PROC and PARSE must
+be the last command on a line.
+
+.br
+E.g.
+
+.br
+
+.EX
+pigs w 22 1 mils 1000 w 22 0
+.br
+
+.EE
+
+.br
+is equivalent to
+
+.br
+
+.EX
+pigs w 22 1
+.br
+pigs mils 1000
+.br
+pigs w 22 0
+.br
+
+.EE
+
+.br
+and
+
+.br
+
+.EX
+echo "m 4 w w 4 0 mils 250 m 4 r r 4" >/dev/pigpio
+.br
+
+.EE
+
+.br
+is equivalent to
+
+.br
+
+.EX
+echo "m 4 w" >/dev/pigpio
+.br
+echo "w 4 0" >/dev/pigpio
+.br
+echo "mils 250" >/dev/pigpio
+.br
+echo "m 4 r" >/dev/pigpio
+.br
+echo "r 4" >/dev/pigpio
+.br
+
+.EE
+
+.br
+.SS Notes
+.br
+The examples from now on will show the pigs interface but the same
+commands will also work on the pipe interface.
+
+.br
+pigs does not show the status of successful commands unless the
+command itself returns data. The status (0) will be returned to
+pigs but will be discarded.
+
+.br
+The status/data of each command sent to the pipe interface should
+be read from /dev/pigout.
+
+.br
+When a command takes a number as a parameter it may be entered as hex
+(precede by 0x), octal (precede by 0), or decimal.
+
+.br
+E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal.
+
+.br
+
+.SH COMMANDS
+
+.br
+
+.IP "\fBBC1 bits\fP - Clear specified gpios in bank 1"
+.IP "" 4
+This command clears (sets low) the gpios specified by \fBbits\fP in bank 1.
+Bank 1 consists of gpios 0-31.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs bc1 0x400010 # clear gpios 4 (1<<4) and 22 (1<<22)
+.br
+
+.br
+$ pigs bc1 32 # clear gpio 5 (1<<5)
+.br
+-42
+.br
+ERROR: no permission to update one or more gpios
+.br
+
+.EE
+
+.br
+
+.IP "\fBBC2 bits\fP - Clear specified gpios in bank 2"
+.IP "" 4
+This command clears (sets low) the gpios specified by \fBbits\fP in bank 2.
+Bank 2 consists of gpios 32-53.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs bc2 0x8000 # clear gpio 47 (activity LED on B+)
+.br
+
+.br
+$ pigs bc2 1 # clear gpio 32 (first in bank 2)
+.br
+-42
+.br
+ERROR: no permission to update one or more gpios
+.br
+
+.EE
+
+.br
+
+.IP "\fBBR1 \fP - Read bank 1 gpios"
+.IP "" 4
+This command read gpios 0-31 (bank 1) and returns the levels as a
+32-bit hexadecimal value.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs br1
+.br
+1001C1CF
+.br
+
+.EE
+
+.br
+
+.IP "\fBBR2 \fP - Read bank 2 gpios"
+.IP "" 4
+This command read gpios 32-53 (bank 2) and returns the levels as a
+32-bit hexadecimal value.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs br2
+.br
+003F0000
+.br
+
+.EE
+
+.br
+
+.IP "\fBBS1 bits\fP - Set specified gpios in bank 1"
+.IP "" 4
+This command sets (sets high) the gpios specified by \fBbits\fP in bank 1.
+Bank 1 consists of gpios 0-31.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs bs1 16 # set gpio 4 (1<<4)
+.br
+
+.br
+$ pigs bs1 1 # set gpio 1 (1<<0)
+.br
+-42
+.br
+ERROR: no permission to update one or more gpios
+.br
+
+.EE
+
+.br
+
+.IP "\fBBS2 bits\fP - Set specified gpios in bank 2"
+.IP "" 4
+This command sets (sets high) the gpios specified by \fBbits\fP in bank 2.
+Bank 2 consists of gpios 32-53.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs bs2 0x40 # set gpio 38 (enable high current mode B+)
+.br
+
+.br
+$ pigs bs2 1 # set gpio 32 (first in bank 2)
+.br
+-42
+.br
+ERROR: no permission to update one or more gpios
+.br
+
+.EE
+
+.br
+
+.IP "\fBH/HELP \fP - Display command help"
+.IP "" 4
+This command displays a brief list of the commands and their parameters.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs h
+.br
+
+.br
+$ pigs help
+.br
+
+.EE
+
+.br
+
+.IP "\fBHWVER \fP - Get hardware version"
+.IP "" 4
+This command returns the hardware revision of the Pi.
+
+.br
+The hardware revision is found in the last 4 characters on the Revision
+line of /proc/cpuinfo.
+
+.br
+If the hardware revision can not be found or is not a valid hexadecimal
+number the command returns 0.
+
+.br
+The revision number can be used to determine the assignment of gpios to pins.
+
+.br
+There are currently three types of board.
+
+.br
+Type 1 has gpio 0 on P1-3, gpio 1 on P1-5, and gpio 21 on P1-13.
+
+.br
+Type 2 has gpio 2 on P1-3, gpio 3 on P1-5, gpio 27 on P1-13, and
+gpios 28-31 on P5.
+
+.br
+Type 3 has a 40 pin connector rather than the 26 pin connector of
+the earlier boards. Gpios 0 to 27 are brought out to the connector
+(although gpios 0 and 1 are reserved).
+
+.br
+Type 1 boards have hardware revision numbers of 2 and 3.
+
+.br
+Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
+
+.br
+Type 3 boards have hardware revision number 16.
+
+.br
+for "Revision : 0002" the command returns 2.
+
+.br
+for "Revision : 000f" the command returns 15.
+
+.br
+for "Revision : 000g" the command returns 0.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs hwver # On a B+
+.br
+16
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CC h\fP - Close I2C handle"
+.IP "" 4
+This command closes an I2C handle \fBh\fP previously opened with \fBI2CO\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cc 0 # First close okay.
+.br
+
+.br
+$ pigs i2cc 0 # Second fails.
+.br
+-25
+.br
+ERROR: unknown handle
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CO ib id if\fP - Open I2C bus and device with flags"
+.IP "" 4
+This command returns a handle to access device \fBid\fP on I2C bus \fBib\fP.
+The device is opened with flags \fBif\fP.
+
+.br
+No flags are currently defined. The parameter \fBif\fP should be 0.
+
+.br
+Upon success the next free handle (>=0) is returned. On error a
+negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2co 1 0x70 0 # Bus 1, device 0x70, flags 0.
+.br
+0
+.br
+
+.br
+$ pigs i2co 1 0x53 0 # Bus 1, device 0x53, flags 0.
+.br
+1
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CPC h r wv\fP - smb Process Call: exchange register with word"
+.IP "" 4
+This command writes \fBwv\fP to register \fBr\fP of the I2C device
+associated with handle \fBh\fP and returns a 16-bit word read from the
+device.
+
+.br
+Upon success a value between 0 and 65535 will be returned. On error
+a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cpc 0 37 43210
+.br
+39933
+.br
+
+.br
+$ pigs i2cpc 0 256 43210
+.br
+ERROR: bad i2c/spi/ser parameter
+.br
+-81
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CPK h r bvs\fP - smb Block Process Call: exchange data bytes with register"
+.IP "" 4
+
+.br
+This command writes the data bytes \fBbvs\fP to register \fBr\fP of the I2C device
+associated with handle \fBh\fP and returns a device specific number of bytes.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cpk 0 0 0x11 0x12
+.br
+6 0 0 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRB h r\fP - smb Read Byte Data: read byte from register"
+.IP "" 4
+
+.br
+This command returns a single byte read from register \fBr\fP of the I2C device
+associated with handle \fBh\fP.
+
+.br
+Upon success a value between 0 and 255 will be returned. On error
+a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2crb 0 0
+.br
+6
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRD h num\fP - i2c Read bytes"
+.IP "" 4
+
+.br
+This command returns \fBnum\fP bytes read from the I2C device associated with
+handle \fBh\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+This command operates on the raw I2C device. The maximum value of the
+parameter \fBnum\fP is dependent on the I2C drivers and the device
+itself. pigs imposes a limit of about 8000 bytes.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2crd 0 16
+.br
+16 6 24 0 0 0 0 0 0 0 0 0 0 0 0 32 78
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRI h r num\fP - smb Read I2C Block Data: read bytes from register"
+.IP "" 4
+
+.br
+This command returns \fBnum\fP bytes from register \fBr\fP of the I2C device
+associated with handle \fBh\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+The parameter \fBnum\fP may be 1-32.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cri 0 0 16
+.br
+16 237 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRK h r\fP - smb Read Block Data: read data from register"
+.IP "" 4
+
+.br
+This command returns between 1 and 32 bytes read from register \fBr\fP of
+the I2C device associated with handle \fBh\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+The number of bytes of returned data is specific to the device and
+register.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2crk 0 0
+.br
+6 0 0 0 0 0 0
+.br
+
+.br
+$ pigs i2crk 0 1
+.br
+24 0 0 0 0 0 0 0 0 0 0 0 0 120 222 105 215 128 87 195 217 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRS h\fP - smb Read Byte: read byte"
+.IP "" 4
+
+.br
+This command returns a single byte read from the I2C device
+associated with handle \fBh\fP.
+
+.br
+Upon success a value between 0 and 255 will be returned. On error
+a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2crs 0
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CRW h r\fP - smb Read Word Data: read word from register"
+.IP "" 4
+
+.br
+This command returns a single 16 bit word read from register \fBr\fP of
+the I2C device associated with handle \fBh\fP.
+
+.br
+Upon success a value between 0 and 65535 will be returned. On error
+a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2crw 0 0
+.br
+6150
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWB h r bv\fP - smb Write Byte Data: write byte to register"
+.IP "" 4
+
+.br
+This command writes a single byte \fBbv\fP to register \fBr\fP of the
+I2C device associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cwb 0 10 0x54
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWD h bvs\fP - i2c Write data"
+.IP "" 4
+
+.br
+This command writes a block of bytes \fBbvs\fP to the I2C device
+associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The number of bytes which may be written in one transaction is
+dependent on the I2C drivers and the device itself. pigs imposes
+a limit of about 500 bytes.
+
+.br
+This command operates on the raw I2C device.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cwd 0 0x01 0x02 0x03 0x04
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWI h r bvs\fP - smb Write I2C Block Data"
+.IP "" 4
+
+.br
+This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of
+the I2C device associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cwi 0 4 0x01 0x04 0xc0
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWK h r bvs\fP - smb Write Block Data: write data to register"
+.IP "" 4
+
+.br
+This command writes between 1 and 32 bytes \fBbvs\fP to register \fBr\fP of
+the I2C device associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+pigs i2cwk 0 4 0x01 0x04 0xc0
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWQ h bit\fP - smb Write Quick: write bit"
+.IP "" 4
+
+.br
+This command writes a single \fBbit\fP to the I2C device associated
+with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cwq 0 1
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWS h bv\fP - smb Write Byte: write byte"
+.IP "" 4
+
+.br
+This command writes a single byte \fBbv\fP to the I2C device associated
+with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cws 0 0x12
+.br
+
+.br
+$ pigs i2cws 0 0xff
+.br
+-82
+.br
+ERROR: I2C write failed
+.br
+
+.EE
+
+.br
+
+.IP "\fBI2CWW h r wv\fP - smb Write Word Data: write word to register"
+.IP "" 4
+
+.br
+This command writes a single 16 bit word \fBwv\fP to register \fBr\fP of
+the I2C device associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs i2cww 0 0 0xffff
+.br
+
+.EE
+
+.br
+
+.IP "\fBM/MODES g m\fP - Set gpio mode"
+.IP "" 4
+
+.br
+This command sets gpio \fBg\fP to mode \fBm\fP, typically input (read)
+or output (write).
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+Each gpio can be configured to be in one of 8 different modes. The modes
+are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5.
+
+.br
+To set the mode use the code for the mode.
+
+.br
+
+.EX
+Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5
+Code R W 0 1 2 3 4 5
+
+.EE
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs m 4 r # Input (read)
+.br
+$ pigs m 4 w # Output (write)
+.br
+$ pigs m 4 0 # ALT 0
+.br
+$ pigs m 4 5 # ALT 5
+.br
+
+.EE
+
+.br
+
+.IP "\fBMG/MODEG g\fP - Get gpio mode"
+.IP "" 4
+
+.br
+This command returns the current mode of gpio \fBg\fP.
+
+.br
+Upon success the value of the gpio mode is returned.
+On error a negative status code will be returned.
+
+.br
+
+.EX
+Value 0 1 2 3 4 5 6 7
+Mode Input Output ALT5 ALT4 ALT0 ALT1 ALT2 ALT3
+
+.EE
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs mg 4
+.br
+1
+.br
+
+.EE
+
+.br
+
+.IP "\fBMICS v\fP - Microseconds delay"
+.IP "" 4
+This command delays execution for \fBv\fP microseconds.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The main use of this command is expected to be within \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs mics 20 # Delay 20 microseconds.
+.br
+$ pigs mics 1000000 # Delay 1 second.
+.br
+
+.br
+$ pigs mics 2000000
+.br
+-64
+.br
+ERROR: bad MICS delay (too large)
+.br
+
+.EE
+
+.br
+
+.IP "\fBMILS v\fP - Milliseconds delay"
+.IP "" 4
+
+.br
+This command delays execution for \fBv\fP milliseconds.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs mils 2000 # Delay 2 seconds.
+.br
+
+.br
+$ pigs mils 61000
+.br
+-65
+.br
+ERROR: bad MILS delay (too large)
+.br
+
+.EE
+
+.br
+
+.IP "\fBNB h bits\fP - Start notification"
+.IP "" 4
+
+.br
+This command starts notifications on handle \fBh\fP returned by
+a prior call to \fBNO\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The notification gets state changes for each gpio specified by \fBbits\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs nb 0 -1 # Shorthand for gpios 0-31.
+.br
+$ pigs nb 0 0xf0 # Get notifications for gpios 4-7.
+.br
+
+.br
+$ pigs nb 1 0xf
+.br
+-25
+.br
+ERROR: unknown handle
+.br
+
+.EE
+
+.br
+
+.IP "\fBNC h\fP - Close notification"
+.IP "" 4
+
+.br
+This command stops notifications on handle \fBh\fP returned by
+a prior call to \fBNO\fP and releases the handle for reuse.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs nc 0 # First call succeeds.
+.br
+
+.br
+$ pigs nc 1 # Second call fails.
+.br
+-25
+.br
+ERROR: unknown handle
+.br
+
+.EE
+
+.br
+
+.IP "\fBNO \fP - Request a notification"
+.IP "" 4
+
+.br
+This command requests a free notification handle.
+
+.br
+A notification is a method for being notified of gpio state changes via a pipe.
+
+.br
+Upon success the command returns a handle greater than or equal to zero.
+On error a negative status code will be returned.
+
+.br
+Notifications for handle x will be available at the pipe named /dev/pigpiox
+(where x is the handle number).
+
+.br
+E.g. if the command returns 15 then the notifications must be read
+from /dev/pigpio15.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs no
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBNP h\fP - Pause notification"
+.IP "" 4
+
+.br
+This command pauses notifications on handle \fBh\fP returned by
+a prior call to \fBNO\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+Notifications for the handle are suspended until a new \fBNB\fP command
+is given for the handle.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs np 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBP/PWM u v\fP - Set gpio PWM value"
+.IP "" 4
+
+.br
+This command starts PWM on gpio \fBu\fP with duty cycle \fBv\fP. The duty cycle
+varies from 0 (off) to range (fully on). The range defaults to 255.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+This and the servo functionality use the DMA and PWM or PCM peripherals
+to control and schedule the pulse lengths and duty cycles.
+
+.br
+The \fBPRS\fP command may be used to change the default range of 255.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs p 4 64 # Start PWM on gpio 4 with 25% dutycycle
+.br
+$ pigs p 4 128 # 50%
+.br
+$ pigs p 4 192 # 75%
+.br
+$ pigs p 4 255 # 100%
+.br
+
+.EE
+
+.br
+
+.IP "\fBPARSE t\fP - Validate script"
+.IP "" 4
+
+.br
+Validates the text \fBt\fP of a script without storing the script.
+
+.br
+Upon success nothing is returned. On error a list of detected
+script errors will be given.
+
+.br
+See \fBScripts\fP.
+
+.br
+This command may be used to find script syntax faults.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs parse tag 100 w 22 1 mils 200 w 22 0 mils 800 jmp 100
+.br
+
+.br
+$ pigs parse tag 0 w 22 1 mills 50 w 22 0 dcr p10 jp 99
+.br
+Unknown command: mills
+.br
+Unknown command: 50
+.br
+Bad parameter to dcr
+.br
+Can't resolve tag 99
+.br
+
+.EE
+
+.br
+
+.IP "\fBPFG u\fP - Get gpio PWM frequency"
+.IP "" 4
+
+.br
+This command returns the PWM frequency in Hz used for gpio \fBu\fP.
+
+.br
+Upon success the PWM frequency is returned. On error a negative
+status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs pfg 4
+.br
+800
+.br
+
+.br
+pigs pfg 34
+.br
+ERROR: gpio not 0-31
+.br
+-2
+.br
+
+.EE
+
+.br
+
+.IP "\fBPFS u v\fP - Set gpio PWM frequency"
+.IP "" 4
+This command sets the PWM frequency \fBv\fP to be used for gpio \fBu\fP.
+
+.br
+The numerically closest frequency to \fBv\fP will be selected.
+
+.br
+Upon success the new frequency is returned. On error a negative status code
+will be returned.
+
+.br
+The selectable frequencies depend upon the sample rate with which the
+pigpiod daemon was started. The sample rate is one of 1, 2, 4, 5, 8,
+or 10 microseconds (default 5).
+
+.br
+Each gpio can be independently set to one of 18 different PWM frequencies.
+
+.br
+If PWM is currently active on the gpio it will be switched off and then
+back on at the new frequency.
+
+.br
+The frequencies for each sample rate are:
+
+.br
+
+.EX
+ #1 #2 #3 #4 #5 #6 #7 #8 #9
+ 1us 40000 20000 10000 8000 5000 4000 2500 2000 1600
+ 2us 20000 10000 5000 4000 2500 2000 1250 1000 800
+ 4us 10000 5000 2500 2000 1250 1000 625 500 400
+ 5us 8000 4000 2000 1600 1000 800 500 400 320
+ 8us 5000 2500 1250 1000 625 500 313 250 200
+10us 4000 2000 1000 800 500 400 250 200 160
+
+.br
+ #10 #11 #12 #13 #14 #15 #16 #17 #18
+ 1us 1250 1000 800 500 400 250 200 100 50
+ 2us 625 500 400 250 200 125 100 50 25
+ 4us 313 250 200 125 100 63 50 25 13
+ 5us 250 200 160 100 80 50 40 20 10
+ 8us 156 125 100 63 50 31 25 13 6
+10us 125 100 80 50 40 25 20 10 5
+
+.EE
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+pigs pfs 4 0 # 0 selects the lowest frequency.
+.br
+10
+.br
+
+.br
+$ pigs pfs 4 1000 # Set 1000Hz PWM.
+.br
+1000
+.br
+
+.br
+$ pigs pfs 4 100000 # Very big number selects the highest frequency.
+.br
+8000
+.br
+
+.EE
+
+.br
+
+.IP "\fBPIGPV \fP - Get pigpio library version"
+.IP "" 4
+
+.br
+This command returns the pigpio library version.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs pigpv
+.br
+17
+.br
+
+.EE
+
+.br
+
+.IP "\fBPRG u\fP - Get gpio PWM range"
+.IP "" 4
+
+.br
+This command returns the dutycycle range for gpio \fBu\fP.
+
+.br
+Upon success the range is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs prg 4
+.br
+255
+.br
+
+.EE
+
+.br
+
+.IP "\fBPROC t\fP - Store script"
+.IP "" 4
+
+.br
+This command stores a script \fBt\fP for later execution.
+
+.br
+If the script is valid a script id (>=0) is returned which is passed
+to the other script commands. On error a negative status code
+will be returned.
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
+.br
+0
+.br
+
+.br
+$ pigs proc tag 123 w 4 0 mils 5 w 4 1 mils 5 jmp 12
+.br
+ERROR: script has unresolved tag
+.br
+-63
+.br
+
+.EE
+
+.br
+
+.IP "\fBPROCD sid\fP - Delete script"
+.IP "" 4
+
+.br
+This command deletes script \fBsid\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs procd 1
+.br
+
+.br
+$ pigs procd 1
+.br
+ERROR: unknown script id
+.br
+-48
+.br
+
+.EE
+
+.br
+
+.IP "\fBPROCP sid\fP - Get script status and parameters"
+.IP "" 4
+
+.br
+This command returns the status of script \fBsid\fP as well as the
+current value of its 10 parameters.
+
+.br
+Upon success the script status and parameters are returned.
+On error a negative status code will be returned.
+
+.br
+The script status may be one of
+
+.br
+
+.EX
+0 being initialised
+1 halted
+2 running
+3 waiting
+4 failed
+
+.EE
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs procp 0
+.br
+1 0 0 0 0 0 0 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBPROCR sid pars\fP - Run script"
+.IP "" 4
+
+.br
+This command runs stored script \fBsid\fP passing it up to 10 optional
+parameters.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs proc tag 123 w 4 0 mils 200 w 4 1 mils 300 dcr p0 jp 123
+.br
+0
+.br
+
+.br
+$ pigs procr 0 50 # Run script 0 with parameter 0 of 50.
+.br
+
+.br
+$ pigs procp 0
+.br
+2 44 0 0 0 0 0 0 0 0 0
+.br
+$ pigs procp 0
+.br
+2 37 0 0 0 0 0 0 0 0 0
+.br
+$ pigs procp 0
+.br
+2 10 0 0 0 0 0 0 0 0 0
+.br
+$ pigs procp 0
+.br
+2 5 0 0 0 0 0 0 0 0 0
+.br
+$ pigs procp 0
+.br
+2 2 0 0 0 0 0 0 0 0 0
+.br
+$ pigs procp 0
+.br
+1 -1 0 0 0 0 0 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBPROCS sid\fP - Stop script"
+.IP "" 4
+
+.br
+This command stops a running script \fBsid\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+See \fBScripts\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs procs 0
+.br
+
+.br
+$ pigs procs 1
+.br
+-48
+.br
+ERROR: unknown script id
+.br
+
+.EE
+
+.br
+
+.IP "\fBPRRG u\fP - Get gpio PWM real range"
+.IP "" 4
+
+.br
+This command returns the real underlying range used by gpio \fBu\fP.
+
+.br
+Upon success the real range is returned. On error a negative status code
+will be returned.
+
+.br
+See \fBPRS\fP.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs prrg 17
+.br
+250
+.br
+
+.br
+$ pigs pfs 17 0
+.br
+10
+.br
+$ pigs prrg 17
+.br
+20000
+.br
+
+.br
+$ pigs pfs 17 100000
+.br
+8000
+.br
+$ pigs prrg 17
+.br
+25
+.br
+
+.EE
+
+.br
+
+.IP "\fBPRS u v\fP - Set gpio PWM range"
+.IP "" 4
+
+.br
+This command sets the dutycycle range \fBv\fP to be used for gpio \fBu\fP.
+Subsequent uses of command \fBP/PWM\fP will use a dutycycle between 0 (off)
+and \fBv\fP (fully on).
+
+.br
+Upon success the real underlying range used by the gpio is returned.
+On error a negative status code will be returned.
+
+.br
+If PWM is currently active on the gpio its dutycycle will be scaled to
+reflect the new range.
+
+.br
+The real range, the number of steps between fully off and fully on
+for each frequency, is given in the following table.
+
+.br
+
+.EX
+ #1 #2 #3 #4 #5 #6 #7 #8 #9
+ 25 50 100 125 200 250 400 500 625
+
+#10 #11 #12 #13 #14 #15 #16 #17 #18
+800 1000 1250 2000 2500 4000 5000 10000 20000
+
+.EE
+
+.br
+The real value set by \fBPRS\fP is (dutycycle * real range) / range.
+
+.br
+See \fBPRRG\fP
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs prs 18 1000
+.br
+250
+.br
+
+.EE
+
+.br
+
+.IP "\fBPUD g p\fP - Set gpio pull up/down"
+.IP "" 4
+
+.br
+This command sets the internal pull/up down for gpio \fBg\fP to mode \fBp\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The mode may be pull-down (D), pull-up (U), or off (O).
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs pud 4 d # Set pull-down on gpio 4.
+.br
+$ pigs pud 4 u # Set pull-up on gpio 4.
+.br
+$ pigs pud 4 o # No pull-up/down on gpio 4.
+.br
+
+.EE
+
+.br
+
+.IP "\fBR/READ g\fP - Read gpio level"
+.IP "" 4
+
+.br
+This reads the current level of gpio \fBg\fP.
+
+.br
+Upon success the current level is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs r 17 # Get level of gpio 17.
+.br
+0
+.br
+
+.br
+$ pigs r 4 # Get level of gpio 4.
+.br
+1
+.br
+
+.EE
+
+.br
+
+.IP "\fBS/SERVO u v\fP - Set gpio servo pulsewidth"
+.IP "" 4
+
+.br
+This command starts servo pulses of \fBv\fP microseconds on gpio \fBu\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The servo pulse width may be 0 (off), 500 (most anti-clockwise)
+to 2500 (most clockwise).
+
+.br
+The range supported by servos varies and should probably be determined
+by experiment. Generally values between 1000-2000 should be safe.
+A value of 1500 should always be safe and represents
+the mid-point of rotation.
+
+.br
+You can DAMAGE a servo if you command it to move beyond its limits.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs SERVO 17 1500
+.br
+
+.EE
+
+.br
+This example causes an on pulse of 1500 microseconds duration to be
+transmitted on gpio 17 at a rate of 50 times per second.
+
+.br
+This will command a servo connected to gpio 17 to rotate to its mid-point.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+pigs s 17 0 # Switch servo pulses off.
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERC h\fP - Close serial handle"
+.IP "" 4
+
+.br
+This command closes a serial handle \fBh\fP previously opened with \fBSERO\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serc 0 # First close okay.
+.br
+
+.br
+$ pigs serc 0 # Second close gives error.
+.br
+-25
+.br
+ERROR: unknown handle
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERDA h\fP - Check for serial data ready to read"
+.IP "" 4
+
+.br
+This command returns the number of bytes of data available
+to be read from the serial device associated with handle \fBh\fP.
+
+.br
+Upon success the count of bytes available to be read is
+returned (which may be 0). On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serda 0
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERO dev b sef\fP - Open serial device dev at baud with flags"
+.IP "" 4
+
+.br
+This command opens the serial \fBdev\fP at \fBb\fP bits per second.
+
+.br
+No flags are currently defined. \fBsef\fP should be set to zero.
+
+.br
+Upon success a handle (>=0) is returned. On error a negative status code
+will be returned.
+
+.br
+The UART is /dev/ttyAMA0. The consoles are /dev/ttyx. The USB
+devices are /dev/ttyUSBx.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs sero /dev/ttyAMA0 9600 0
+.br
+0
+.br
+
+.br
+$ pigs sero /dev/tty1 38400 0
+.br
+1
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERR h num\fP - Read bytes from serial handle"
+.IP "" 4
+
+.br
+This command returns up to \fBnum\fP bytes of data read from the
+serial device associated with handle \fBh\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serr 0 10
+.br
+5 48 49 128 144 255
+.br
+
+.br
+$ pigs serr 0 10
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERRB \fP - Read byte from serial handle"
+.IP "" 4
+
+.br
+This command returns a byte of data read from the serial
+device associated with handle \fBh\fP.
+
+.br
+Upon success a number between 0 and 255 is returned.
+On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serrb 0
+.br
+23
+.br
+$ pigs serrb 0
+.br
+45
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERW h bvs\fP - Write bytes to serial handle"
+.IP "" 4
+
+.br
+This command writes bytes \fBbvs\fP to the serial device
+associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serw 0 23 45 67 89
+.br
+
+.EE
+
+.br
+
+.IP "\fBSERWB h bv\fP - Write byte to serial handle"
+.IP "" 4
+
+.br
+This command writes a single byte \fBbv\fP to the serial device
+associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs serwb 0 23
+.br
+$ pigs serwb 0 0xf0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSLR u num\fP - Read bit bang serial data from gpio"
+.IP "" 4
+
+.br
+This command returns up to \fBnum\fP bytes of bit bang serial data
+read from gpio \fBu\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+The gpio \fBu\fP should have been initialised with the \fBSLRO\fP command.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs slr 15 20
+.br
+6 1 0 23 45 89 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSLRC u\fP - Close gpio for bit bang serial data"
+.IP "" 4
+
+.br
+This command closes gpio \fBu\fP for reading bit bang serial data.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs slrc 23
+.br
+
+.br
+$ pigs slrc 23
+.br
+-38
+.br
+ERROR: no serial read in progress on gpio
+.br
+
+.EE
+
+.br
+
+.IP "\fBSLRO u b\fP - Open gpio for bit bang serial data"
+.IP "" 4
+
+.br
+This command opens gpio \fBu\fP for reading bit bang serial data
+at \fBb\fP baud.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The received data is held in a cyclic buffer.
+
+.br
+It is the user's responsibility to read the data (with \fBSLR\fP)
+in a timely fashion.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs slro 23 19200
+.br
+
+.br
+$ pigs slro 23 19200
+.br
+-50
+.br
+ERROR: gpio already in use
+.br
+
+.EE
+
+.br
+
+.IP "\fBSPIC h\fP - SPI close handle"
+.IP "" 4
+
+.br
+This command closes the SPI handle \fBh\fP returned by a prior
+call to \fBSPIO\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+.IP "\fBSPIO c b spf\fP - SPI open channel at baud with flags"
+.IP "" 4
+
+.br
+This command returns a handle to a SPI device on channel \fBc\fP.
+.br
+
+.br
+Data will be transferred at \fBb\fP bits per second. The least
+significant two bits of the flags \fBspf\fP determine the SPI mode. All
+other bits in \fBspf\fP should be set to zero.
+
+.br
+
+.EX
+Flags Mode
+0 0
+1 1
+2 2
+3 3
+
+.EE
+
+.br
+Upon success a handle (>=0) is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs spio 0 100000 3 # Open channel 0 at 100kbps in mode 3.
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSPIR h num\fP - SPI read bytes from handle"
+.IP "" 4
+
+.br
+This command returns \fBnum\fP bytes read from the SPI device
+associated with handle \fBh\fP.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs spir 0 10 # Read 10 bytes from the SPI device.
+.br
+10 0 0 0 0 0 0 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBSPIW h bvs\fP - SPI write bytes to handle"
+.IP "" 4
+
+.br
+This command writes bytes \fBbvs\fP to the SPI device
+associated with handle \fBh\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs spiw 0 0x22 0x33 0xcc 0xff
+.br
+
+.EE
+
+.br
+
+.IP "\fBSPIX h bvs\fP - SPI transfer bytes to handle"
+.IP "" 4
+
+.br
+This command writes bytes \fBbvs\fP to the SPI device
+associated with handle \fBh\fP. It returns the same
+number of bytes read from the device.
+
+.br
+Upon success the count of returned bytes followed by the bytes themselves
+is returned. On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs spix 0 0x22 0x33 0xcc 0xff
+.br
+4 0 0 0 0
+.br
+
+.EE
+
+.br
+
+.IP "\fBT/TICK \fP - Get current tick"
+.IP "" 4
+
+.br
+This command returns the current system tick.
+
+.br
+Tick is the number of microseconds since system boot.
+
+.br
+As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds,
+which is approximately 1 hour 12 minutes.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs t mils 1000 t
+.br
+3691823946
+.br
+3692833987
+.br
+
+.EE
+
+.br
+
+.IP "\fBTRIG u pl L\fP - Send a trigger pulse"
+.IP "" 4
+
+.br
+This command sends a trigger pulse of \fBpl\fP microseconds at level \fBL\fP
+to gpio \fBu\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The gpio is set to not level at the end of the pulse.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs trig 4 10 1
+.br
+
+.br
+$ pigs trig 4 51 1
+.br
+-46
+.br
+ERROR: trigger pulse > 50 microseconds
+.br
+
+.EE
+
+.br
+
+.IP "\fBW/WRITE g L\fP - Write gpio level"
+.IP "" 4
+
+.br
+This command sets gpio \fBg\fP to level \fBL\fP. The level may be 0
+(low, off, clear) or 1 (high, on, set).
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs w 23 0
+.br
+$ pigs w 23 1
+.br
+
+.br
+$ pigs w 23 2
+.br
+-5
+.br
+ERROR: level not 0-1
+.br
+
+.EE
+
+.br
+
+.IP "\fBWDOG u v\fP - Set gpio watchdog"
+.IP "" 4
+
+.br
+This command sets a watchdog of \fBv\fP milliseconds on gpio \fBu\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+The watchdog is nominally in milliseconds.
+
+.br
+One watchdog may be registered per gpio.
+
+.br
+The watchdog may be cancelled by setting timeout to 0.
+
+.br
+If no level change has been detected for the gpio for timeout milliseconds:-
+
+.br
+any notification for the gpio has a report written to the fifo with
+the flags set to indicate a watchdog timeout.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wdog 23 90000
+.br
+-15
+.br
+ERROR: timeout not 0-60000
+.br
+
+.br
+$ pigs wdog 23 9000
+.br
+
+.EE
+
+.br
+This example causes a report to be written to any notification pipes
+listening on gpio 23 whenever gpio 23 changes state or approximately
+every 9000 ms.
+
+.br
+
+.IP "\fBWVAG trips\fP - Add generic pulses to waveform"
+.IP "" 4
+
+.br
+This command adds 1 one or more triplets \fBtrips\fP of gpios on, gpios off,
+delay to the existing waveform (if any).
+
+.br
+Upon success the total number of pulses in the waveform so far is
+returned. On error a negative status code will be returned.
+
+.br
+The triplets will be added at the start of the existing waveform. If
+they are to start offset from the start then the first triplet should
+consist solely of a delay i.e. 0 0 offset.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvag 0x10 0x80 1000 0x80 0x10 9000
+.br
+2
+.br
+
+.br
+$ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000
+.br
+4
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVAS u b o bvs\fP - Add serial data to waveform"
+.IP "" 4
+
+.br
+This command adds a waveform representing serial data \fBbvs\fP to
+gpio \fBu\fP at \fBb\fP baud to the existing waveform (if any).
+The serial data starts \fBo\fP microseconds from the start of the waveform.
+
+.br
+Upon success the total number of pulses in the waveform so far is
+returned. On error a negative status code will be returned.
+
+.br
+Data with different baud rates may be added to the same wavefrom.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvas 4 9600 0 0x30 0x31 0x32 0x33
+.br
+23
+.br
+
+.br
+$ pigs wvas 7 38400 0 0x41 0x42
+.br
+35
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVBSY \fP - Check if waveform is being transmitted"
+.IP "" 4
+
+.br
+This command checks to see if a waveform is currently being transmitted.
+
+.br
+Returns 1 if a waveform is currently being transmitted, otherwise 0.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvbsy
+.br
+0
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVCLR \fP - Clear all waveforms"
+.IP "" 4
+
+.br
+This command clears all waveforms.
+
+.br
+Nothing is returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvclr
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVCRE \fP - Create a waveform"
+.IP "" 4
+
+.br
+This command creates a waveform from the data provided by the prior
+calls to the \fBWVAG\fP and \fBWVAS\fP commands.
+
+.br
+Upon success a wave id (>=0) is returned. On error a negative status
+code will be returned.
+
+.br
+The data provided by the \fBWVAG\fP and \fBWVAS\fP commands is
+consumed by this command.
+
+.br
+As many waveforms may be created as there is space available.
+The wave id is passed to \fBWVTX\fP or \fBWVTXR\fP to specify the
+waveform to transmit.
+
+.br
+Normal usage would be
+
+.br
+Step 1. \fBWVCLR\fP to clear all waveforms and added data.
+
+.br
+Step 2. \fBWVAG\fP/\fBWVAS\fP calls to supply the waveform data.
+
+.br
+Step 3. \fBWVCRE\fP to create the waveform and get a unique id.
+
+.br
+Repeat steps 2 and 3 as needed.
+
+.br
+Step 4. \fBWVTX\fP or \fBWVTXR\fP with the id of the waveform to transmit.
+
+.br
+A waveform comprises of one or more pulses.
+
+.br
+A pulse specifies
+
+.br
+1) the gpios to be switched on at the start of the pulse.
+.br
+2) the gpios to be switched off at the start of the pulse.
+.br
+3) the delay in microseconds before the next pulse.
+
+.br
+Any or all the fields can be zero. It doesn't make any sense to
+set all the fields to zero (the pulse will be ignored).
+
+.br
+When a waveform is started each pulse is executed in order with
+the specified delay between the pulse and the next.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvas 4 9600 0 23 45 67 89 90
+.br
+37
+.br
+$ pigs wvcre
+.br
+0
+.br
+
+.br
+$ pigs wvcre
+.br
+-69
+.br
+ERROR: attempt to create an empty waveform
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVDEL wid\fP - Delete selected waveforms"
+.IP "" 4
+
+.br
+This command deletes all waveforms with ids greater than or equal to \fBwid\fP.
+
+.br
+Upon success nothing is returned. On error a negative status code
+will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvdel 0
+.br
+
+.br
+$ pigs wvdel 0
+.br
+-66
+.br
+ERROR: non existent wave id
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVGO \fP - Transmit waveform once (DEPRECATED)"
+.IP "" 4
+
+.br
+This command transmits the current waveform. The waveform is sent once.
+
+.br
+Upon success the number of DMA control blocks in the waveform is returned.
+On error a negative status code will be returned.
+
+.br
+
+.IP "\fBWVGOR \fP - Transmit waveform repeatedly (DEPRECATED)"
+.IP "" 4
+
+.br
+This command transmits the current waveform. The waveform is sent repeatedly.
+
+.br
+Upon success the number of DMA control blocks in the waveform is returned.
+On error a negative status code will be returned.
+
+.br
+
+.IP "\fBWVHLT \fP - Stop waveform"
+.IP "" 4
+
+.br
+This command aborts the transmission of the current waveform.
+
+.br
+Nothing is returned.
+
+.br
+This command is intended to stop a waveform started in the repeat mode.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvhlt
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVNEW \fP - Initialise a new waveform"
+.IP "" 4
+
+.br
+This clears any existing waveform data ready for the creation of a new
+waveform.
+
+.br
+Nothing is returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvnew
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVSC ws\fP - Get waveform DMA CB stats"
+.IP "" 4
+
+.br
+The statistic requested by \fBws\fP is returned.
+
+.br
+\fBws\fP identifies the subcommand as follows.
+
+.br
+0 Get Cbs
+.br
+1 Get High Cbs
+.br
+2 Get Max Cbs
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvas 4 9600 0 23 45 67 89 90
+.br
+37
+.br
+
+.br
+$ pigs wvsc 0
+.br
+74
+.br
+$ pigs wvsc 1
+.br
+74
+.br
+$ pigs wvsc 2
+.br
+25016
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVSM ws\fP - Get waveform time stats"
+.IP "" 4
+
+.br
+The statistic requested by \fBws\fP is returned.
+
+.br
+\fBws\fP identifies the subcommand as follows.
+
+.br
+0 Get Micros
+.br
+1 Get High Micros
+.br
+2 Get Max Micros
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvsm 0
+.br
+5314
+.br
+$ pigs wvsm 1
+.br
+5314
+.br
+$ pigs wvsm 2
+.br
+1800000000
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVSP ws\fP - Get waveform pulse stats"
+.IP "" 4
+
+.br
+The statistic requested by \fBws\fP is returned.
+
+.br
+\fBws\fP identifies the subcommand as follows.
+
+.br
+0 Get Pulses
+.br
+1 Get High Pulses
+.br
+2 Get Max Pulses
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvsp 0
+.br
+37
+.br
+$ pigs wvsp 1
+.br
+37
+.br
+$ pigs wvsp 2
+.br
+12000
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVTX wid\fP - Transmit waveform once"
+.IP "" 4
+
+.br
+This command transmits the waveform with id \fBwid\fP once.
+
+.br
+Upon success the number of DMA control blocks in the waveform is returned.
+On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvtx 1
+.br
+75
+.br
+
+.br
+$ pigs wvtx 2
+.br
+-66
+.br
+ERROR: non existent wave id
+.br
+
+.EE
+
+.br
+
+.IP "\fBWVTXR wid\fP - Transmit waveform repeatedly"
+.IP "" 4
+
+.br
+This command transmits the waveform with id \fBwid\fP repeatedly.
+
+.br
+Upon success the number of DMA control blocks in the waveform is returned.
+On error a negative status code will be returned.
+
+.br
+
+\fBExample\fP
+.br
+
+.EX
+$ pigs wvtxr 1
+.br
+75
+.br
+
+.br
+$ pigs wvtxr 2
+.br
+-66
+.br
+ERROR: non existent wave id
+.br
+
+.EE
+
+.br
+
+.SH PARAMETERS
+
+.br
+
+.IP "\fBb\fP - baud (100-250000)" 0
+The command expects a baud rate for serial data.
+
+.br
+
+.IP "\fBbit\fP - bit value (0-1)" 0
+The command expects 0 or 1.
+
+.br
+
+.IP "\fBbits\fP - a bit mask" 0
+A mask is used to select one or more gpios. A gpio is selected
+if bit (1<<gpio) is set in the mask.
+
+.br
+E.g. a mask of 6 (binary 110) select gpios 1 and 2, a mask of
+0x103 (binary 100000011) selects gpios 0, 1, and 8.
+
+.br
+
+.IP "\fBbv\fP - a byte value (0-255)" 0
+The command expects a byte value.
+
+.br
+
+.IP "\fBbvs\fP - byte values (0-255)" 0
+The command expects one or more byte values.
+
+.br
+
+.IP "\fBc\fP - SPI channel (0-1)" 0
+The command expects a SPI channel.
+
+.br
+
+.IP "\fBdev\fP - a tty serial device (/dev/tty*)" 0
+The command expects the name of a tty serial device, e.g.
+
+.br
+
+.EX
+/dev/ttyAMA0
+.br
+/dev/ttyUSB0
+.br
+/dev/tty0
+.br
+
+.EE
+
+.br
+
+.IP "\fBg\fP - gpio (0-53)" 0
+The command expects a gpio.
+
+.br
+There are 54 General Purpose Input Outputs (gpios) named gpio0 through gpio53.
+
+.br
+They are split into two banks. Bank 1 consists of gpio0 through gpio31.
+Bank 2 consists of gpio32 through gpio53.
+
+.br
+All the gpios which are safe for the user to read and write are in bank 1.
+Not all gpios in bank 1 are safe though. Rev.1 boards have 17 safe gpios.
+Rev.2 boards have 21. Rev.3 boards have 26.
+
+.br
+The user gpios are marked with an X in the following table.
+
+.br
+
+.EX
+ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+Rev.1 X X - - X - - X X X X X - - X X
+Rev.2 - - X X X - - X X X X X - - X X
+Rev.3 X X X X X X X X X X X X X X
+
+ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
+Rev.1 - X X - - X X X X X - - - - - -
+Rev.2 - X X - - - X X X X - X X X X X
+Rev.3 X X X X X X X X X X X X - - - -
+
+.EE
+
+.br
+You are not prevented from writing to unsafe gpios. The consequences
+of doing so range from no effect, to a crash, or corrupted data.
+
+.br
+
+.IP "\fBh\fP - handle (>=0)" 0
+The command expects a handle.
+
+.br
+A handle is a number referencing an object opened by one of \fBI2CO\fP, \fBNO\fP,
+\fBSERO\fP, \fBSPIO\fP.
+
+.br
+
+.IP "\fBib\fP - I2C bus (0-1)" 0
+The command expects an I2C bus.
+
+.br
+
+.IP "\fBid\fP - I2C device (0x08-0x77)" 0
+The command expects the address of an I2C device.
+
+.br
+
+.IP "\fBif\fP - I2C flags (0)" 0
+The command expects an I2C flags value. No flags are currently defined.
+
+.br
+
+.IP "\fBL\fP - level (0-1)" 0
+The command expects a gpio level.
+
+.br
+
+.IP "\fBm\fP - mode (RW540123)" 0
+The command expects a mode character.
+
+.br
+Each gpio can be configured to be in one of 8 different modes. The modes
+are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5.
+
+.br
+To set the mode use the code for the mode.
+
+.br
+The value is returned by the mode get command.
+
+.br
+
+.EX
+Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5
+Code R W 0 1 2 3 4 5
+Value 0 1 4 5 6 7 3 2
+
+.EE
+
+.br
+
+.IP "\fBnum\fP - number of bytes to read (1-)" 0
+The command expects the number of bytes to read.
+
+.br
+For the I2C and SPI commands the requested number of bytes will always
+be returned.
+
+.br
+For the serial commands the smaller of the number of bytes available to be
+read (which may be zero) and \fBnum\fP bytes will be returned.
+
+.br
+
+.IP "\fBo\fP - offset (>=0)" 0
+Serial data is stored offset microseconds from the start of the waveform.
+
+.br
+
+.IP "\fBp\fP - PUD (ODU)" 0
+The command expects a PUD character.
+
+.br
+Each gpio can be configured to use or not use an internal pull up or
+pull down resistor. This is useful to provide a default state for inputs.
+
+.br
+A pull up will default the input to 1 (high).
+
+.br
+A pull down will default the input to 0 (low).
+
+.br
+To set the pull up down state use the command character for the state.
+
+.br
+
+.EX
+Pull Up Down Off Pull Down Pull Up
+Command Character O D U
+
+.EE
+
+.br
+There is no mechanism to read the pull up down state.
+
+.br
+
+.IP "\fBpars\fP - script parameters" 0
+The command expects 0 to 10 numbers as parameters to be passed to the script.
+
+.br
+
+.IP "\fBpl\fP - pulse length (1-50)" 0
+The command expects a pulse length in microseconds.
+
+.br
+
+.IP "\fBr\fP - register (0-255)" 0
+The command expects an I2C register number.
+
+.br
+
+.IP "\fBsef\fP - serial flags (32 bits)" 0
+The command expects a flag value. No serial flags are currently defined.
+
+.br
+
+.IP "\fBsid\fP - script id (>= 0)" 0
+The command expects a script id as returned by a call to \fBPROC\fP.
+
+.br
+
+.IP "\fBspf\fP - SPI flags (32 bits)" 0
+The command expects a flag value. The least significant two bits
+define the SPI mode.
+
+.br
+
+.IP "\fBt\fP - text (a string of text)" 0
+The command expects a text string.
+
+.br
+
+.IP "\fBtrips\fP - triplets" 0
+The command expects 1 or more triplets of gpios on, gpios off, delay.
+
+.br
+E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows
+
+.br
+
+.EX
+ gpios on gpios off delay
+0x400000 (gpio 22) 0 (None) 100000 (1/10th s)
+ 0 (None) 0x400000 (gpio 22) 900000 (9/10th s)
+
+.EE
+
+.br
+
+.IP "\fBu\fP - user gpio (0-31)" 0
+The command expects the number of a user gpio.
+
+.br
+A number of commands are restricted to gpios in bank 1,
+in particular the PWM commands, the servo command,
+the watchdog command, and the notification command.
+
+.br
+It is your responsibility to ensure that the PWM and servo commands
+are only used on safe gpios.
+
+.br
+See \fBg\fP
+
+.br
+
+.IP "\fBv\fP - value" 0
+The command expects a number.
+
+.br
+
+.IP "\fBwid\fP - wave id (>=0)" 0
+The command expects a wave id.
+
+.br
+When a waveform is created it is given an id (0, 1, 2, ...).
+
+.br
+
+.IP "\fBws\fP - wave stats sucommand (0-2)" 0
+The command expects a subcommand.
+
+.br
+0 = current value.
+.br
+1 = highest value so far.
+.br
+2 = maximum possible value.
+
+.br
+
+.IP "\fBwv\fP - word value (0-65535)" 0
+The command expects a word value.
+
+.br
+
+.SH SCRIPTS
+
+.br
+Scripts are programs to be stored and executed by the pigpio daemon.
+They are intended to mitigate any performance problems associated with
+the pigpio daemon server/client model.
+
+.br
+.SS Example
+.br
+A trivial example might be useful. Suppose you want to toggle a gpio
+on and off as fast as possible.
+
+.br
+From the command line you could write
+
+.br
+
+.EX
+for ((i=0; i<1000;i++)); do pigs w 22 1 w 22 0; done
+.br
+
+.EE
+
+.br
+Timing that you will see it takes about 14 seconds, or roughly
+70 toggles per second.
+
+.br
+Using the pigpio Python module you could use code such as
+
+.br
+
+.EX
+#!/usr/bin/env python
+.br
+
+.br
+import time
+.br
+
+.br
+import pigpio
+.br
+
+.br
+PIN=4
+.br
+
+.br
+TOGGLE=10000
+.br
+
+.br
+pi = pigpio.pi() # Connect to local Pi.
+.br
+
+.br
+s = time.time()
+.br
+
+.br
+for i in range(TOGGLE):
+.br
+ pi.write(PIN, 1)
+.br
+ pi.write(PIN, 0)
+.br
+
+.br
+e = time.time()
+.br
+
+.br
+print("pigpio did {} toggles per second".format(int(TOGGLE/(e-s))))
+.br
+
+.br
+pi.stop()
+.br
+
+.EE
+
+.br
+Timing that shows a speed improvement to roughly 800 toggles per second.
+
+.br
+Now let's use a script.
+
+.br
+
+.EX
+pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999
+.br
+
+.EE
+
+.br
+Ignore the details for now.
+
+.br
+Let's time the script running.
+
+.br
+Again, ignore the details for now.
+
+.br
+
+.EX
+time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
+.br
+ do sleep 0.2; done)
+.br
+
+.EE
+
+.br
+The script takes roughly 12 seconds to complete, or 800,000 toggles per second.
+
+.br
+That is the advantage of a stored script.
+
+.br
+Some details.
+
+.br
+
+.EX
+pigs proc tag 999 w 22 1 w 22 0 dcr p0 jp 999
+.br
+
+.EE
+
+.br
+proc introduces a script. Everything after proc is part of the script.
+.br
+tag 999 names the current position in the script.
+.br
+w 22 1 writes 1 to gpio 22.
+.br
+w 22 0 writes 0 to gpio 22.
+.br
+dcr p0 decrements parameter 0.
+.br
+jp 999 jumps to tag 999 if the result is positive.
+
+.br
+
+.EX
+time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
+.br
+ do sleep 0.2; done)
+.br
+
+.EE
+
+.br
+pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million.
+
+.br
+The rest is bash apart from
+
+.br
+pigs procp 0 asks for the status and parameters of script 0.
+The status will be 2 while the script is running and 1 when it is complete.
+
+.br
+.SS Virtual machine
+.br
+A script runs within a virtual machine with
+
+.br
+a 32 bit accumulator A.
+.br
+a flags register F.
+.br
+a program counter PC.
+
+.br
+Each script has
+
+.br
+10 parameters named 0 through 9.
+.br
+150 variables named 0 through 149.
+.br
+50 labels which are named by any unique number.
+
+.br
+.SS Commands
+.br
+All the normal pigs commands may be used within a script.
+
+.br
+The following commands are only legal within a script.
+
+.br
+
+.EX
+Command Description Definition
+ADD x Add x to accumulator A+=x; F=A
+AND x And x with accumulator A&=x; F=A
+CALL L Call subroutine at tag L push(PC+1); PC=L
+CMP x Compare x with accumulator F=A-x
+DCR y Decrement register --*y; F=*y
+DCRA Decrement accumulator --A; F=A
+DIV x Divide x into accumulator A/=x; F=A
+HALT Halt Halt
+INR y Increment register ++*y; F=*y
+INRA Increment accumulator ++A; F=A
+JM L Jump if minus to tag L if (F<0) PC=L
+JMP L Jump to tag L PC=L
+JNZ L Jump if non-zero to tag L if (F) PC=L
+JP L Jump if positive to tag L if (F>=0) PC=L
+JZ L Jump if zero to tag L if (!F) PC=L
+LD y x Load register with x *y=x
+LDA x Load accumulator with x A=x
+MLT x Multiply x with accumulator A*=x; F=A
+MOD x Modulus x with accumulator A%=x; F=A
+OR x Or x with accumulator A|=x; F=A
+POP y Pop register y=pop()
+POPA Pop accumulator A=pop()
+PUSH y Push register push(y)
+PUSHA Push accumulator push(A)
+RET Return from subroutine PC=pop()
+RL y x Rotate left register x bits *y<<=x; F=*y
+RLA x Rotate left accumulator x bits A<<=x; F=A
+RR y x Rotate right register x bits *y>>=x; F=*y
+RRA x Rotate right accumulator x bits A>>=x; F=A
+STA y Store accumulator in register y=A
+SUB x Subtract x from accumulator A-=x; F=A
+SYS str Run external script (/opt/pigpio/cgi/str) system(str); F=A
+TAG L Label the current script position N/A
+WAIT x Wait for a gpio in x to change state A=wait(x); F=A
+X y1 y2 Exchange contents of registers y1 and y2 t=*y1;*y1=*y2;*y2=t
+XA y Exchange contents of accumulator and register t=A;A=*y;*y=t
+XOR x Xor x with accumulator A^=x; F=A
+
+.EE
+
+.br
+x may be a constant, a parameter (p0-p9), or a variable (v0-v149).
+
+.br
+y may be a parameter (p0-p9), or a variable (v0-v149). If p or v isn't
+specified y is assumed to be a variable.
+
+.br
+The WAIT command parameter is a bit-mask with 1 set for gpios of interest.
+
+.br
+
+.SH SEE ALSO
+
+pigpiod(1), pig2vcd(1), pigpio(3), pigpiod_if(3)
+.SH AUTHOR
+
+joan@abyz.co.uk
diff --git a/pigs.c b/pigs.c
index 5d9806a..7840420 100644
--- a/pigs.c
+++ b/pigs.c
@@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/
/*
-This version is for pigpio version 16+
+This version is for pigpio version 17+
*/
#include <stdio.h>
@@ -64,8 +64,6 @@ void fatal(char *fmt, ...)
fprintf(stderr, "%s\n", buf);
fflush(stderr);
-
- exit(EXIT_FAILURE);
}
static int openSocket(void)
@@ -118,16 +116,17 @@ void print_result(int sock, int rv, cmdCmd_t cmd)
switch (rv)
{
case 0:
- if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
- break;
-
case 1:
- if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
+ if (r < 0)
+ {
+ printf("%d\n", r);
+ fatal("ERROR: %s", cmdErrStr(r));
+ }
break;
case 2:
+ printf("%d\n", r);
if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
- else printf("%d\n", r);
break;
case 3:
@@ -142,29 +141,32 @@ void print_result(int sock, int rv, cmdCmd_t cmd)
printf(cmdUsage);
break;
- case 6: /* SLR I2CRD */
+ case 6: /* I2CPK I2CRD I2CRI I2CRK SERR SLR SPIX SPIR */
+ printf("%d", r);
if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
- else if (r > 0)
+ if (r > 0)
{
- write(1, response_buf, r);
+ for (i=0; i<r; i++)
+ {
+ printf(" %hhu", response_buf[i]);
+ }
}
+ printf("\n");
break;
case 7: /* PROCP */
+ printf("%d", r);
if (r < 0) fatal("ERROR: %s", cmdErrStr(r));
- else
+ if (r >= 0)
{
- printf("%d", r);
-
p = (uint32_t *)response_buf;
for (i=0; i<PI_MAX_SCRIPT_PARAMS; i++)
{
printf(" %d", p[i]);
}
-
- printf("\n");
}
+ printf("\n");
break;
}
}
diff --git a/setup.py b/setup.py
index 00cd6c7..34b0e30 100644
--- a/setup.py
+++ b/setup.py
@@ -3,14 +3,14 @@
from distutils.core import setup
setup(name='pigpio',
- version='1.6',
+ version='1.7',
author='joan',
author_email='joan@abyz.co.uk',
maintainer='joan',
maintainer_email='joan@abyz.co.uk',
url='http://abyz.co.uk/rpi/pigpio/python.html/',
- description='Raspberry Pi gpio module',
- long_description='Raspberry Pi Python module to access the pigpio daemon',
+ description='Raspberry gpio module',
+ long_description='Raspberry Python module to access the pigpio daemon',
download_url='http://abyz.co.uk/rpi/pigpio/pigpio.zip',
license='unlicense.org',
py_modules=['pigpio']
diff --git a/tarball b/tarball
index aab4ff7..5c80f8f 100755
--- a/tarball
+++ b/tarball
@@ -5,25 +5,35 @@ mkdir PIGPIO
#
cp command.c PIGPIO
cp command.h PIGPIO
-cp Makefile PIGPIO
-cp MakeRemote PIGPIO
cp pig2vcd.c PIGPIO
cp pigpio.c PIGPIO
cp pigpio.h PIGPIO
cp pigpiod.c PIGPIO
cp pigpiod_if.c PIGPIO
cp pigpiod_if.h PIGPIO
-cp pigpio.py PIGPIO
cp pigs.c PIGPIO
-cp README PIGPIO
+#
+cp pigpio.py PIGPIO
cp setup.py PIGPIO
+#
+cp README PIGPIO
cp UNLICENCE PIGPIO
+#
cp x_pigpio.c PIGPIO
cp x_pigpio.py PIGPIO
cp x_pigpiod_if.c PIGPIO
cp x_pigs PIGPIO
cp x_pipe PIGPIO
#
+cp pig2vcd.1 PIGPIO
+cp pigpiod.1 PIGPIO
+cp pigs.1 PIGPIO
+cp pigpio.3 PIGPIO
+cp pigpiod_if.3 PIGPIO
+#
+cp Makefile PIGPIO
+cp MakeRemote PIGPIO
+#
zip -r pigpio-$1.zip PIGPIO
tar cvf pigpio-$1.tar PIGPIO
diff --git a/x_pigpio.c b/x_pigpio.c
index b12092d..0050823 100644
--- a/x_pigpio.c
+++ b/x_pigpio.c
@@ -561,16 +561,13 @@ void t9()
p1 GPIO
*/
char *script="\
- lda p0\
- sta v0\
+ ld p9 p0\
tag 0\
w p1 1\
mils 5\
w p1 0\
mils 5\
- dcr v0\
- lda v0\
- sta p9\
+ dcr p9\
jp 0";
printf("Script store/run/status/stop/delete tests.\n");
@@ -580,7 +577,15 @@ void t9()
gpioSetAlertFunc(GPIO, t9cbf);
s = gpioStoreScript(script);
- time_sleep(0.1);
+
+ while (1)
+ {
+ /* loop until script initialised */
+ time_sleep(0.1);
+ e = gpioScriptStatus(s, p);
+ if (e != PI_SCRIPT_INITING) break;
+ }
+
oc = t9_count;
p[0] = 99;
p[1] = GPIO;
diff --git a/x_pigpio.py b/x_pigpio.py
index bd8e7f9..42c139d 100755
--- a/x_pigpio.py
+++ b/x_pigpio.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
#*** WARNING ************************************************
#* *
@@ -38,6 +38,8 @@ def t0():
print("Hardware revision {}.".format(pi.get_hardware_revision()))
+ print("Python version {}.".format(sys.version.replace("\n", " ")))
+
def t1():
print("Mode/PUD/read/write tests.")
@@ -96,7 +98,7 @@ def t2():
oc = t2_count
time.sleep(2)
f = t2_count - oc
- CHECK(2, 3, f, 40, 5, "set PWM dutycycle, callback")
+ CHECK(2, 3, f, 40, 10, "set PWM dutycycle, callback")
pi.set_PWM_frequency(GPIO,100)
f = pi.get_PWM_frequency(GPIO)
@@ -106,7 +108,7 @@ def t2():
oc = t2_count
time.sleep(2)
f = t2_count - oc
- CHECK(2, 5, f, 400, 1, "callback")
+ CHECK(2, 5, f, 400, 5, "callback")
pi.set_PWM_frequency(GPIO,1000)
f = pi.get_PWM_frequency(GPIO)
@@ -116,7 +118,7 @@ def t2():
oc = t2_count
time.sleep(2)
f = t2_count - oc
- CHECK(2, 7, f, 4000, 1, "callback")
+ CHECK(2, 7, f, 4000, 5, "callback")
r = pi.get_PWM_range(GPIO)
CHECK(2, 8, r, 255, 0, "get PWM range")
@@ -489,7 +491,7 @@ def t7():
oc = t7_count
time.sleep(2)
c = t7_count - oc
- CHECK(7, 1, c, 200, 1, "set watchdog on count")
+ CHECK(7, 1, c, 200, 5, "set watchdog on count")
pi.set_watchdog(GPIO, 0) # 0 switches watchdog off
time.sleep(0.5)
@@ -549,21 +551,26 @@ def t9():
# p0 number of loops
# p1 GPIO
script="""
- lda p0
- sta v0
+ ld p9 p0
tag 0
w p1 1
mils 5
w p1 0
mils 5
- dcr v0
- lda v0
- sta p9
+ dcr p9
jp 0"""
t9cb = pi.callback(GPIO)
s = pi.store_script(script)
+
+ # Ensure the script has finished initing.
+ while True:
+ time.sleep(0.1)
+ e, p = pi.script_status(s)
+ if e != pigpio.PI_SCRIPT_INITING:
+ break
+
oc = t9cb.tally()
pi.run_script(s, [99, GPIO])
time.sleep(2)
diff --git a/x_pigpiod_if.c b/x_pigpiod_if.c
index b125e7d..9b7ca4f 100644
--- a/x_pigpiod_if.c
+++ b/x_pigpiod_if.c
@@ -382,6 +382,7 @@ To the lascivious pleasing of a lute.\n\
CHECK(5, 13, c, 6158704, 0, "wave get micros");
c = wave_get_high_micros();
+ if (c >= 6158704) c = 6158704;
CHECK(5, 14, c, 6158704, 0, "wave get high micros");
c = wave_get_max_micros();
@@ -548,21 +549,27 @@ void t9()
p1 GPIO
*/
char *script="\
- lda p0\
- sta v0\
+ ld p9 p0\
tag 0\
w p1 1\
mils 5\
w p1 0\
mils 5\
- dcr v0\
- lda v0\
- sta p9\
+ dcr p9\
jp 0";
callback(GPIO, RISING_EDGE, t9cbf);
s = store_script(script);
+
+ /* Wait for script to finish initing. */
+ while (1)
+ {
+ time_sleep(0.1);
+ e = script_status(s, p);
+ if (e != PI_SCRIPT_INITING) break;
+ }
+
oc = t9_count;
p[0] = 99;
p[1] = GPIO;
@@ -577,9 +584,9 @@ void t9()
run_script(s, 2, p);
while (1)
{
+ time_sleep(0.1);
e = script_status(s, p);
if (e != PI_SCRIPT_RUNNING) break;
- time_sleep(0.5);
}
c = t9_count - oc;
time_sleep(0.1);
@@ -591,10 +598,10 @@ void t9()
run_script(s, 2, p);
while (1)
{
+ time_sleep(0.1);
e = script_status(s, p);
if (e != PI_SCRIPT_RUNNING) break;
if (p[9] < 1900) stop_script(s);
- time_sleep(0.1);
}
c = t9_count - oc;
time_sleep(0.1);
diff --git a/x_pigs b/x_pigs
index 49e7081..9411d5d 100755
--- a/x_pigs
+++ b/x_pigs
@@ -86,7 +86,7 @@ s=$(pigs pfs $GPIO 800)
if [[ $s = 800 ]]; then echo "PFS-b ok"; else echo "PFS-b fail ($s)"; fi
s=$(pigs pigpv)
-if [[ $s = 16 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
+if [[ $s = 17 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
s=$(pigs prs $GPIO 255)
if [[ $s = 250 ]]; then echo "PRG-a ok"; else echo "PRG-a fail ($s)"; fi
@@ -99,21 +99,23 @@ then echo "PROC($p) ok"
else echo "PROC($p) fail ($s)"
fi
+sleep 0.1 # Make sure script has time to intialise.
+
s=$(pigs procr $p 9876)
-if [[ $s = 0 ]]; then echo "PROCR($p) ok"; else echo "PROCR($p) fail ($s)"; fi
+if [[ $s = "" ]]; then echo "PROCR($p) ok"; else echo "PROCR($p) fail ($s)"; fi
s=$(pigs procp $p)
v=(${s// / })
-if [[ ${v[0]} = 1 && ${v[1]} = 1234 && ${v[2]} = 9876 ]]
+if [[ ${v[0]} = 2 && ${v[1]} = 1234 && ${v[2]} = 9876 ]]
then echo "PROCP($p) ok"
else echo "PROCP($p) fail ($s)"
fi
s=$(pigs procs $p)
-if [[ $s = 0 ]]; then echo "PROCS($p) ok"; else echo "PROCS($p) fail ($s)"; fi
+if [[ $s = "" ]]; then echo "PROCS($p) ok"; else echo "PROCS($p) fail ($s)"; fi
s=$(pigs procd $p)
-if [[ $s = 0 ]]; then echo "PROCD($p) ok"; else echo "PROCD($p) fail ($s)"; fi
+if [[ $s = "" ]]; then echo "PROCD($p) ok"; else echo "PROCD($p) fail ($s)"; fi
s=$(pigs prrg $GPIO)
if [[ $s = 250 ]]; then echo "PRRG ok"; else echo "PRRG fail ($s)"; fi
@@ -170,7 +172,7 @@ if [[ $s = "" ]]; then echo "SERVO-d ok"; else echo "SERVO-d fail ($s)"; fi
s=$(pigs wvclr)
if [[ $s = "" ]]; then echo "SLR-a ok"; else echo "SLR-a fail ($s)"; fi
s=$(pigs slro $GPIO 1200)
-if [[ $s = 0 ]]; then echo "SLR-b ok"; else echo "SLR-b fail ($s)"; fi
+if [[ $s = "" ]]; then echo "SLR-b ok"; else echo "SLR-b fail ($s)"; fi
s=$(pigs wvas $GPIO 1200 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73 0x20 0x6a 0x6f 0x61 0x6e)
if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
s=$(pigs m $GPIO w)
@@ -179,12 +181,13 @@ s=$(pigs wvgo)
if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
sleep 0.1
s=$(pigs slr $GPIO 100)
-if [[ $s = "my name is joan" ]]
+e="15 109 121 32 110 97 109 101 32 105 115 32 106 111 97 110"
+if [[ $s = $e ]]
then echo "SLR-f ok"
else echo "SLR-f fail with [$s]"
fi
s=$(pigs slrc $GPIO)
-if [[ $s = 0 ]]; then echo "SLR-g ok"; else echo "SLR-g fail ($s)"; fi
+if [[ $s = "" ]]; then echo "SLR-g ok"; else echo "SLR-g fail ($s)"; fi
t=$(pigs t tick)
v=(${t// / })
@@ -233,7 +236,7 @@ sleep 1
s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-b ok"; else echo "WVBSY-b fail ($s)"; fi
s=$(pigs wvhlt)
-if [[ $s = 0 ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
+if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
s=$(pigs wvbsy)
if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi
s=$(pigs wvgor)
@@ -241,7 +244,7 @@ if [[ $s = 621 ]]; then echo "WVGOR ok"; else echo "WVGOR fail ($s)"; fi
s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi
s=$(pigs wvhlt)
-if [[ $s = 0 ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
+if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
s=$(pigs wvbsy)
if [[ $s = 0 ]]; then echo "WVBSY-e ok"; else echo "WVBSY-e fail ($s)"; fi
diff --git a/x_pipe b/x_pipe
index cbcb017..1ffb59e 100755
--- a/x_pipe
+++ b/x_pipe
@@ -119,7 +119,7 @@ if [[ $s = 800 ]]; then echo "PFS-b ok"; else echo "PFS-b fail ($s)"; fi
echo "pigpv" >/dev/pigpio
read -t 1 s </dev/pigout
-if [[ $s = 16 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
+if [[ $s = 17 ]]; then echo "PIGPV ok"; else echo "PIGPV fail ($s)"; fi
echo "prs $GPIO 255" >/dev/pigpio
read -t 1 s </dev/pigout
@@ -135,13 +135,15 @@ then echo "PROC($p) ok"
else echo "PROC($p) fail ($s)"
fi
+sleep 0.1 # Make sure script has time to intialise.
+
echo "procr $p 9876" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "PROCR($p) ok"; else echo "PROCR($p) fail ($s)"; fi
echo "procp $p" >/dev/pigpio
read -t 1 -a v </dev/pigout
-if [[ ${v[0]} = 1 && ${v[1]} = 29 && ${v[2]} = 9876 ]]
+if [[ ${v[0]} = 2 && ${v[1]} = 29 && ${v[2]} = 9876 ]]
then echo "PROCP($p) ok"
else echo "PROCP($p) fail ($s)"
fi
@@ -235,19 +237,20 @@ if [[ $s = 0 ]]; then echo "SLR-a ok"; else echo "SLR-a fail ($s)"; fi
echo "slro $GPIO 1200" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "SLR-b ok"; else echo "SLR-b fail ($s)"; fi
-echo "wvas $GPIO 1200 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73 0x20 0x6a 0x6f 0x61 0x6e 0xc2 0xac" >/dev/pigpio
+echo "wvas $GPIO 1200 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73 0x20 0x6a 0x6f 0x61 0x6e" >/dev/pigpio
read -t 1 s </dev/pigout
-if [[ $s = 105 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
+if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
echo "m $GPIO w" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "SLR-d ok"; else echo "SLR-d fail ($s)"; fi
echo "wvgo" >/dev/pigpio
read -t 1 s </dev/pigout
-if [[ $s = 211 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
+if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
sleep 0.2
echo "slr $GPIO 100" >/dev/pigpio
-read -t 1 -d ¬ s </dev/pigout
-if [[ $s = "my name is joan" ]]
+read -t 1 s </dev/pigout
+e="15 109 121 32 110 97 109 101 32 105 115 32 106 111 97 110"
+if [[ $s = $e ]]
then echo "SLR-f ok"
else echo "SLR-f fail with ($s)"
fi