pigpio/pigpio.3

6231 lines
82 KiB
Groff
Raw Normal View History

2014-08-01 10:30:25 +02:00
." 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
2014-08-12 19:47:26 +02:00
This function returns a handle for the SPI device on the channel.
Data will be transferred at baud bits per second. The flags may
be used to modify the default behaviour of 4-wire operation, mode 0,
active low chip select.
2014-08-01 10:30:25 +02:00
.br
2014-09-03 20:52:48 +02:00
.br
An auxiliary SPI device is available on the B+ and may be
selected by setting the A bit in the flags. The auxiliary
device has 3 chip selects and a selectable word size in bits.
.br
2014-08-01 10:30:25 +02:00
.br
.EX
spiChan: 0-1
.br
spiBaud: >1
.br
2014-09-03 20:52:48 +02:00
spiFlags: see below
2014-08-01 10:30:25 +02:00
.br
.EE
.br
.br
Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
2014-09-03 20:52:48 +02:00
PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED.
2014-08-01 10:30:25 +02:00
.br
.br
2014-09-03 20:52:48 +02:00
spiFlags consists of the least significant 22 bits.
2014-08-12 19:47:26 +02:00
.br
.br
.EX
2014-09-03 20:52:48 +02:00
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
2014-08-12 19:47:26 +02:00
.br
2014-09-03 20:52:48 +02:00
b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m
2014-08-12 19:47:26 +02:00
.br
.EE
.br
.br
mm defines the SPI mode.
2014-08-01 10:30:25 +02:00
.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
2014-08-12 19:47:26 +02:00
.br
2014-09-03 20:52:48 +02:00
px is 0 if CEx is active low (default) and 1 for active high.
.br
.br
ux is 0 if the CEx gpio is reserved for SPI (default) and 1 otherwise.
.br
.br
A is 0 for the standard SPI device, 1 for the auxiliary SPI. The
auxiliary device is only present on the B+.
2014-08-12 19:47:26 +02:00
.br
.br
2014-09-03 20:52:48 +02:00
W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard
SPI device only.
2014-08-12 19:47:26 +02:00
.br
.br
nnnn defines the number of bytes (0-15) to write before switching
the MOSI line to MISO to read data. This field is ignored
2014-09-03 20:52:48 +02:00
if W is not set. Standard SPI device only.
.br
.br
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first. Auxiliary SPI
device only.
.br
.br
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first. Auxiliary SPI
device only.
.br
.br
bbbbbb defines the word size in bits (0-32). The default (0)
sets 8 bits per word. Auxiliary SPI device only.
2014-08-12 19:47:26 +02:00
.br
2014-08-01 10:30:25 +02:00
.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
2014-08-17 20:53:43 +02:00
pulseLen: 1-100
2014-08-01 10:30:25 +02:00
.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
2014-09-03 20:52:48 +02:00
Delays of 100 microseconds or less use busy waits.
2014-08-01 10:30:25 +02:00
.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
2014-09-03 20:52:48 +02:00
.IP "\fBgpioSample_t\fP" 0
.EX
typedef struct
.br
{
.br
uint32_t tick;
.br
uint32_t level;
.br
} gpioSample_t;
.br
.EE
.br
.br
2014-08-01 10:30:25 +02:00
.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
2014-08-17 20:53:43 +02:00
1-100, the length of a trigger pulse in microseconds.
2014-08-01 10:30:25 +02:00
.br
.br
.IP "\fB*pulses\fP" 0
.br
.br
2014-09-03 20:52:48 +02:00
An array of pulses to be added to a waveform.
2014-08-01 10:30:25 +02:00
.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
2014-09-03 20:52:48 +02:00
See \fBspiOpen\fP.
2014-08-01 10:30:25 +02:00
.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
2014-08-12 19:47:26 +02:00
#define PI_BAD_PULSELEN -46 // trigger pulse length > 100
2014-08-01 10:30:25 +02:00
.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
2014-09-03 20:52:48 +02:00
#define PI_NO_AUX_SPI -91 // need a B+ for auxiliary SPI
.br
2014-08-01 10:30:25 +02:00
.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