gcc -Wall -pthread -o prog prog.c -lpigpio -lrt
sudo ./prog
gpioCfg*
gpioVersion
gpioHardwareRevision
ESSENTIAL | |
gpioInitialise | Initialise library |
gpioTerminate | Stop library |
BASIC | |
gpioSetMode | Set a GPIO mode |
gpioGetMode | Get a GPIO mode |
gpioSetPullUpDown | Set/clear GPIO pull up/down resistor |
gpioRead | Read a GPIO |
gpioWrite | Write a GPIO |
PWM (overrides servo commands on same GPIO) | |
gpioPWM | Start/stop PWM pulses on a GPIO |
gpioSetPWMfrequency | Configure PWM frequency for a GPIO |
gpioSetPWMrange | Configure PWM range for a GPIO |
gpioGetPWMdutycycle | Get dutycycle setting on a GPIO |
gpioGetPWMfrequency | Get configured PWM frequency for a GPIO |
gpioGetPWMrange | Get configured PWM range for a GPIO |
gpioGetPWMrealRange | Get underlying PWM range for a GPIO |
Servo (overrides PWM commands on same GPIO) | |
gpioServo | Start/stop servo pulses on a GPIO |
gpioGetServoPulsewidth | Get pulsewidth setting on a GPIO |
INTERMEDIATE | |
gpioTrigger | Send a trigger pulse to a GPIO |
gpioSetWatchdog | Set a watchdog on a GPIO |
gpioRead_Bits_0_31 | Read all GPIO in bank 1 |
gpioRead_Bits_32_53 | Read all GPIO in bank 2 |
gpioWrite_Bits_0_31_Clear | Clear selected GPIO in bank 1 |
gpioWrite_Bits_32_53_Clear | Clear selected GPIO in bank 2 |
gpioWrite_Bits_0_31_Set | Set selected GPIO in bank 1 |
gpioWrite_Bits_32_53_Set | Set selected GPIO in bank 2 |
gpioSetAlertFunc | Request a GPIO level change callback |
gpioSetAlertFuncEx | Request a GPIO change callback, extended |
gpioSetTimerFunc | Request a regular timed callback |
gpioSetTimerFuncEx | Request a regular timed callback, extended |
gpioStartThread | Start a new thread |
gpioStopThread | Stop a previously started thread |
ADVANCED | |
gpioNotifyOpen | Request a notification handle |
gpioNotifyClose | Close a notification |
gpioNotifyOpenWithSize | Request a notification with sized pipe |
gpioNotifyBegin | Start notifications for selected GPIO |
gpioNotifyPause | Pause notifications |
gpioHardwareClock | Start hardware clock on supported GPIO |
gpioHardwarePWM | Start hardware PWM on supported GPIO |
gpioGlitchFilter | Set a glitch filter on a GPIO |
gpioNoiseFilter | Set a noise filter on a GPIO |
gpioSetPad | Sets a pads drive strength |
gpioGetPad | Gets a pads drive strength |
shell | Executes a shell command |
gpioSetISRFunc | Request a GPIO interrupt callback |
gpioSetISRFuncEx | Request a GPIO interrupt callback, extended |
gpioSetSignalFunc | Request a signal callback |
gpioSetSignalFuncEx | Request a signal callback, extended |
gpioSetGetSamplesFunc | Requests a GPIO samples callback |
gpioSetGetSamplesFuncEx | Requests a GPIO samples callback, extended |
Custom | |
gpioCustom1 | User custom function 1 |
gpioCustom2 | User custom function 2 |
Events | |
eventMonitor | Sets the events to monitor |
eventSetFunc | Request an event callback |
eventSetFuncEx | Request an event callback, extended |
eventTrigger | Trigger an event |
Scripts | |
gpioStoreScript | Store a script |
gpioRunScript | Run a stored script |
gpioUpdateScript | Set a scripts parameters |
gpioScriptStatus | Get script status and parameters |
gpioStopScript | Stop a running script |
gpioDeleteScript | Delete a stored script |
I2C | |
i2cOpen | Opens an I2C device |
i2cClose | Closes an I2C device |
i2cWriteQuick | SMBus write quick |
i2cReadByte | SMBus read byte |
i2cWriteByte | SMBus write byte |
i2cReadByteData | SMBus read byte data |
i2cWriteByteData | SMBus write byte data |
i2cReadWordData | SMBus read word data |
i2cWriteWordData | SMBus write word data |
i2cReadBlockData | SMBus read block data |
i2cWriteBlockData | SMBus write block data |
i2cReadI2CBlockData | SMBus read I2C block data |
i2cWriteI2CBlockData | SMBus write I2C block data |
i2cReadDevice | Reads the raw I2C device |
i2cWriteDevice | Writes the raw I2C device |
i2cProcessCall | SMBus process call |
i2cBlockProcessCall | SMBus block process call |
i2cSwitchCombined | Sets or clears the combined flag |
i2cSegments | Performs multiple I2C transactions |
i2cZip | Performs multiple I2C transactions |
I2C BIT BANG | |
bbI2COpen | Opens GPIO for bit banging I2C |
bbI2CClose | Closes GPIO for bit banging I2C |
bbI2CZip | Performs bit banged I2C transactions |
I2C/SPI SLAVE | |
bscXfer | I2C/SPI as slave transfer |
SERIAL | |
serOpen | Opens a serial device |
serClose | Closes a serial device |
serReadByte | Reads a byte from a serial device |
serWriteByte | Writes a byte to a serial device |
serRead | Reads bytes from a serial device |
serWrite | Writes bytes to a serial device |
serDataAvailable | Returns number of bytes ready to be read |
SERIAL BIT BANG (read only) | |
gpioSerialReadOpen | Opens a GPIO for bit bang serial reads |
gpioSerialReadClose | Closes a GPIO for bit bang serial reads |
gpioSerialReadInvert | Configures normal/inverted for serial reads |
gpioSerialRead | Reads bit bang serial data from a GPIO |
SPI | |
spiOpen | Opens a SPI device |
spiClose | Closes a SPI device |
spiRead | Reads bytes from a SPI device |
spiWrite | Writes bytes to a SPI device |
spiXfer | Transfers bytes with a SPI device |
SPI BIT BANG | |
bbSPIOpen | Opens GPIO for bit banging SPI |
bbSPIClose | Closes GPIO for bit banging SPI |
bbSPIXfer | Performs bit banged SPI transactions |
FILES | |
fileOpen | Opens a file |
fileClose | Closes a file |
fileRead | Reads bytes from a file |
fileWrite | Writes bytes to a file |
fileSeek | Seeks to a position within a file |
fileList | List files which match a pattern |
WAVES | |
gpioWaveClear | Deletes all waveforms |
gpioWaveAddNew | Starts a new waveform |
gpioWaveAddGeneric | Adds a series of pulses to the waveform |
gpioWaveAddSerial | Adds serial data to the waveform |
gpioWaveCreate | Creates a waveform from added data |
gpioWaveCreatePad | Creates a waveform of fixed size from added data |
gpioWaveDelete | Deletes a waveform |
gpioWaveTxSend | Transmits a waveform |
gpioWaveChain | Transmits a chain of waveforms |
gpioWaveTxAt | Returns the current transmitting waveform |
gpioWaveTxBusy | Checks to see if the waveform has ended |
gpioWaveTxStop | Aborts the current waveform |
gpioWaveGetCbs | Length in CBs of the current waveform |
gpioWaveGetHighCbs | Length of longest waveform so far |
gpioWaveGetMaxCbs | Absolute maximum allowed CBs |
gpioWaveGetMicros | Length in micros of the current waveform |
gpioWaveGetHighMicros | Length of longest waveform so far |
gpioWaveGetMaxMicros | Absolute maximum allowed micros |
gpioWaveGetPulses | Length in pulses of the current waveform |
gpioWaveGetHighPulses | Length of longest waveform so far |
gpioWaveGetMaxPulses | Absolute maximum allowed pulses |
UTILITIES | |
gpioDelay | Delay for a number of microseconds |
gpioTick | Get current tick (microseconds) |
gpioHardwareRevision | Get hardware revision |
gpioVersion | Get the pigpio version |
getBitInBytes | Get the value of a bit |
putBitInBytes | Set the value of a bit |
gpioTime | Get current time |
gpioSleep | Sleep for specified time |
time_sleep | Sleeps for a float number of seconds |
time_time | Float number of seconds since the epoch |
CONFIGURATION | |
gpioCfgBufferSize | Configure the GPIO sample buffer size |
gpioCfgClock | Configure the GPIO sample rate |
gpioCfgDMAchannel | Configure the DMA channel (DEPRECATED) |
gpioCfgDMAchannels | Configure the DMA channels |
gpioCfgPermissions | Configure the GPIO access permissions |
gpioCfgInterfaces | Configure user interfaces |
gpioCfgSocketPort | Configure socket port |
gpioCfgMemAlloc | Configure DMA memory allocation mode |
gpioCfgNetAddr | Configure allowed network addresses |
gpioCfgInternals | Configure misc. internals (DEPRECATED) |
gpioCfgGetInternals | Get internal configuration settings |
gpioCfgSetInternals | Set internal configuration settings |
EXPERT | |
rawWaveAddSPI | Not intended for general use |
rawWaveAddGeneric | Not intended for general use |
rawWaveCB | Not intended for general use |
rawWaveCBAdr | Not intended for general use |
rawWaveGetOOL | Not intended for general use |
rawWaveSetOOL | Not intended for general use |
rawWaveGetOut | Not intended for general use |
rawWaveSetOut | Not intended for general use |
rawWaveGetIn | Not intended for general use |
rawWaveSetIn | Not intended for general use |
rawWaveInfo | Not intended for general use |
rawDumpWave | Not intended for general use |
rawDumpScript | Not intended for general use |
gpioCfg*
gpioVersion
gpioHardwareRevision
if (gpioInitialise() < 0)
{
// pigpio initialisation failed.
}
else
{
// pigpio initialised okay.
}
gpioTerminate();
gpio: 0-53
mode: 0-7
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.
gpio: 0-53
if (gpioGetMode(17) != PI_ALT0)
{
gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0
}
gpio: 0-53
pud: 0-2
gpioSetPullUpDown(17, PI_PUD_UP); // Sets a pull-up.
gpioSetPullUpDown(18, PI_PUD_DOWN); // Sets a pull-down.
gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs.
gpio: 0-53
printf("GPIO24 is level %d", gpioRead(24));
gpio: 0-53
level: 0-1
gpioWrite(24, 1); // Set GPIO24 high.
user_gpio: 0-31
dutycycle: 0-range
gpioPWM(17, 255); // Sets GPIO17 full on.
gpioPWM(18, 128); // Sets GPIO18 half on.
gpioPWM(23, 0); // Sets GPIO23 full off.
user_gpio: 0-31
user_gpio: 0-31
range: 25-40000
25, 50, 100, 125, 200, 250, 400, 500, 625,
800, 1000, 1250, 2000, 2500, 4000, 5000, 10000, 20000
gpioSetPWMrange(24, 2000); // Now 2000 is fully on
// 1000 is half on
// 500 is quarter on, etc.
user_gpio: 0-31
r = gpioGetPWMrange(23);
user_gpio: 0-31
rr = gpioGetPWMrealRange(17);
user_gpio: 0-31
frequency: >=0
Hertz
1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
1250 1000 800 500 400 250 200 100 50
2: 20000 10000 5000 4000 2500 2000 1250 1000 800
625 500 400 250 200 125 100 50 25
4: 10000 5000 2500 2000 1250 1000 625 500 400
313 250 200 125 100 63 50 25 13
sample
rate
(us) 5: 8000 4000 2000 1600 1000 800 500 400 320
250 200 160 100 80 50 40 20 10
8: 5000 2500 1250 1000 625 500 313 250 200
156 125 100 63 50 31 25 13 6
10: 4000 2000 1000 800 500 400 250 200 160
125 100 80 50 40 25 20 10 5
gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency.
gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz.
gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency.
user_gpio: 0-31
f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23.
user_gpio: 0-31
pulsewidth: 0, 500-2500
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.
PWM Hz 50 100 200 400 500
1E6/Hz 20000 10000 5000 2500 2000
gpioSetPWMfrequency(25, 400);
gpioSetPWMrange(25, 2500);
user_gpio: 0-31
user_gpio: 0-31
f: the callback function
Parameter Value Meaning
GPIO 0-31 The GPIO which has changed state
level 0-2 0 = change to low (a falling edge)
1 = change to high (a rising edge)
2 = no level change (a watchdog timeout)
tick 32 bit The number of microseconds since boot
WARNING: this wraps around from
4294967295 to 0 roughly every 72 minutes
samples
per sec
1 1,000,000
2 500,000
sample 4 250,000
rate 5 200,000
(us) 8 125,000
10 100,000
void aFunction(int gpio, int level, uint32_t tick)
{
printf("GPIO %d became %d at %d", gpio, level, tick);
}
// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);
user_gpio: 0-31
f: the callback function
userdata: pointer to arbitrary user data
Parameter Value Meaning
GPIO 0-31 The GPIO which has changed state
level 0-2 0 = change to low (a falling edge)
1 = change to high (a rising edge)
2 = no level change (a watchdog timeout)
tick 32 bit The number of microseconds since boot
WARNING: this wraps around from
4294967295 to 0 roughly every 72 minutes
userdata pointer Pointer to an arbitrary object
gpio: 0-53
edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
f: the callback function
Parameter Value Meaning
GPIO 0-53 The GPIO which has changed state
level 0-2 0 = change to low (a falling edge)
1 = change to high (a rising edge)
2 = no level change (interrupt timeout)
tick 32 bit The number of microseconds since boot
WARNING: this wraps around from
4294967295 to 0 roughly every 72 minutes
gpio: 0-53
edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE
timeout: interrupt timeout in milliseconds (<=0 to cancel)
f: the callback function
userdata: pointer to arbitrary user data
Parameter Value Meaning
GPIO 0-53 The GPIO which has changed state
level 0-2 0 = change to low (a falling edge)
1 = change to high (a rising edge)
2 = no level change (interrupt timeout)
tick 32 bit The number of microseconds since boot
WARNING: this wraps around from
4294967295 to 0 roughly every 72 minutes
userdata pointer Pointer to an arbitrary object
h = gpioNotifyOpen();
if (h >= 0)
{
sprintf(str, "/dev/pigpio%d", h);
fd = open(str, O_RDONLY);
if (fd >= 0)
{
// Okay.
}
else
{
// Error.
}
}
else
{
// Error.
}
handle: >=0, as returned by gpioNotifyOpen
bits: a bit mask indicating the GPIO of interest
typedef struct
{
uint16_t seqno;
uint16_t flags;
uint32_t tick;
uint32_t level;
} gpioReport_t;
// Start notifications for GPIO 1, 4, 6, 7, 10.
// 1
// 0 76 4 1
// (1234 = 0x04D2 = 0b0000010011010010)
gpioNotifyBegin(h, 1234);
handle: >=0, as returned by gpioNotifyOpen
gpioNotifyPause(h);
handle: >=0, as returned by gpioNotifyOpen
gpioNotifyClose(h);
gpioWaveClear();
gpioWaveAddNew();
numPulses: the number of pulses
pulses: an array of pulses
// 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.
}
user_gpio: 0-31
baud: 50-1000000
data_bits: 1-32
stop_bits: 2-8
offset: >=0
numBytes: >=1
str: an array of chars (which may contain nulls)
#define MSG_LEN 8
int i;
char *str;
char data[MSG_LEN];
str = "Hello world!";
gpioWaveAddSerial(4, 9600, 8, 2, 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, 8, 2, 1000000, MSG_LEN, data);
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;
pctCB: 0-100, the percent of all DMA control blocks to consume.
pctBOOL: 0-100, percent On-Off-Level (OOL) buffer to consume for wave output.
pctTOOL: 0-100, the percent of OOL buffer to consume for wave input (flags).
// get firstWaveChunk, somehow
gpioWaveAddGeneric(firstWaveChunk);
wid = gpioWaveCreatePad(50, 50, 0);
gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
// get nextWaveChunk
while (nextWaveChunk) {
gpioWaveAddGeneric(nextWaveChunk);
nextWid = gpioWaveCreatePad(50, 50, 0);
gpioWaveTxSend(nextWid, PI_WAVE_MODE_ONE_SHOT_SYNC);
while(gpioWaveTxAt() == wid) time_sleep(0.1);
gpioWaveDelete(wid);
wid = nextWid;
// get nextWaveChunk
}
wave_id: >=0, as returned by gpioWaveCreate
wave_id: >=0, as returned by gpioWaveCreate
wave_mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT,
PI_WAVE_MODE_ONE_SHOT_SYNC, PI_WAVE_MODE_REPEAT_SYNC
buf: pointer to the wave_ids and optional command codes
bufSize: the number of bytes in buf
Name | Cmd & Data | Meaning |
Loop Start | 255 0 | Identify start of a wave block |
Loop Repeat | 255 1 x y | loop x + y*256 times |
Delay | 255 2 x y | delay x + y*256 microseconds |
Loop Forever | 255 3 | loop forever |
#include <stdio.h>
#include <pigpio.h>
#define WAVES 5
#define GPIO 4
int main(int argc, char *argv[])
{
int i, wid[WAVES];
if (gpioInitialise()<0) return -1;
gpioSetMode(GPIO, PI_OUTPUT);
printf("start piscope, press return"); getchar();
for (i=0; i<WAVES; i++)
{
gpioWaveAddGeneric(2, (gpioPulse_t[])
{{1<<GPIO, 0, 20},
{0, 1<<GPIO, (i+1)*200}});
wid[i] = gpioWaveCreate();
}
gpioWaveChain((char []) {
wid[4], wid[3], wid[2], // transmit waves 4+3+2
255, 0, // loop start
wid[0], wid[0], wid[0], // transmit waves 0+0+0
255, 0, // loop start
wid[0], wid[1], // transmit waves 0+1
255, 2, 0x88, 0x13, // delay 5000us
255, 1, 30, 0, // loop end (repeat 30 times)
255, 0, // loop start
wid[2], wid[3], wid[0], // transmit waves 2+3+0
wid[3], wid[1], wid[2], // transmit waves 3+1+2
255, 1, 10, 0, // loop end (repeat 10 times)
255, 1, 5, 0, // loop end (repeat 5 times)
wid[4], wid[4], wid[4], // transmit waves 4+4+4
255, 2, 0x20, 0x4E, // delay 20000us
wid[0], wid[0], wid[0], // transmit waves 0+0+0
}, 46);
while (gpioWaveTxBusy()) time_sleep(0.1);
for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);
printf("stop piscope, press return"); getchar();
gpioTerminate();
}
user_gpio: 0-31
baud: 50-250000
data_bits: 1-32
user_gpio: 0-31
invert: 0-1
user_gpio: 0-31, previously opened with gpioSerialReadOpen
buf: an array to receive the read bytes
bufSize: >=0
user_gpio: 0-31, previously opened with gpioSerialReadOpen
i2cBus: >=0
i2cAddr: 0-0x7F
i2cFlags: 0
SDA | SCL | |
I2C 0 | 0 | 1 |
I2C 1 | 2 | 3 |
S (1 bit) : Start bit
P (1 bit) : Stop bit
Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.
A, NA (1 bit) : Accept and not accept bit.
Addr (7 bits): I2C 7 bit address.
i2cReg (8 bits): Command byte, a byte which often selects a register.
Data (8 bits): A data byte.
Count (8 bits): A byte defining the length of a block operation.
[..]: Data sent by the device.
handle: >=0, as returned by a call to i2cOpen
handle: >=0, as returned by a call to i2cOpen
bit: 0-1, the value to write
S Addr bit [A] P
handle: >=0, as returned by a call to i2cOpen
bVal: 0-0xFF, the value to write
S Addr Wr [A] bVal [A] P
handle: >=0, as returned by a call to i2cOpen
S Addr Rd [A] [Data] NA P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
bVal: 0-0xFF, the value to write
S Addr Wr [A] i2cReg [A] bVal [A] P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write
wVal: 0-0xFFFF, the value to write
S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A] P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
S Addr Wr [A] i2cReg [A] S Addr Rd [A] [Data] NA P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
S Addr Wr [A] i2cReg [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to write/read
wVal: 0-0xFFFF, the value to write
S Addr Wr [A] i2cReg [A] wValLow [A] wValHigh [A]
S Addr Rd [A] [DataLow] A [DataHigh] NA P
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
S Addr Wr [A] i2cReg [A] count [A]
buf0 [A] buf1 [A] ... [A] bufn [A] P
handle: >=0, as returned by a call to i2cOpen
i2cReg: 0-255, the register to read
buf: an array to receive the read data
S Addr Wr [A] i2cReg [A]
S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P
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
S Addr Wr [A] i2cReg [A] count [A] buf0 [A] ... bufn [A]
S Addr Rd [A] [Count] A [buf0] A ... [bufn] A P
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
S Addr Wr [A] i2cReg [A]
S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
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
S Addr Wr [A] i2cReg [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
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
S Addr Rd [A] [buf0] A [buf1] A ... A [bufn] NA P
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
S Addr Wr [A] buf0 [A] buf1 [A] ... [A] bufn [A] P
setting: 0 to set the parameter off, non-zero to set it on
handle: >=0, as returned by a call to i2cOpen
segs: an array of I2C segments
numSegs: >0, the number of I2C segments
handle: >=0, as returned by a call to i2cOpen
inBuf: pointer to the concatenated I2C commands, see below
inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer
Name | Cmd & Data | Meaning |
End | 0 | No more commands |
Escape | 1 | Next P is two bytes |
On | 2 | Switch combined flag on |
Off | 3 | Switch combined flag off |
Address | 4 P | Set I2C address to P |
Flags | 5 lsb msb | Set I2C flags to lsb + (msb << 8) |
Read | 6 P | Read P bytes of data |
Write | 7 P ... | Write P bytes of data |
Set address 0x53, write 0x32, read 6 bytes
Set address 0x1E, write 0x03, read 6 bytes
Set address 0x68, write 0x1B, read 8 bytes
End
0x04 0x53 0x07 0x01 0x32 0x06 0x06
0x04 0x1E 0x07 0x01 0x03 0x06 0x06
0x04 0x68 0x07 0x01 0x1B 0x06 0x08
0x00
SDA: 0-31
SCL: 0-31
baud: 50-500000
SDA: 0-31, the SDA GPIO used in a prior call to bbI2COpen
SDA: 0-31 (as used in a prior call to bbI2COpen)
inBuf: pointer to the concatenated I2C commands, see below
inLen: size of command buffer
outBuf: pointer to buffer to hold returned data
outLen: size of output buffer
Name | Cmd & Data | Meaning |
End | 0 | No more commands |
Escape | 1 | Next P is two bytes |
Start | 2 | Start condition |
Stop | 3 | Stop condition |
Address | 4 P | Set I2C address to P |
Flags | 5 lsb msb | Set I2C flags to lsb + (msb << 8) |
Read | 6 P | Read P bytes of data |
Write | 7 P ... | Write P bytes of data |
Set address 0x53
start, write 0x32, (re)start, read 6 bytes, stop
Set address 0x1E
start, write 0x03, (re)start, read 6 bytes, stop
Set address 0x68
start, write 0x1B, (re)start, read 8 bytes, stop
End
0x04 0x53
0x02 0x07 0x01 0x32 0x02 0x06 0x06 0x03
0x04 0x1E
0x02 0x07 0x01 0x03 0x02 0x06 0x06 0x03
0x04 0x68
0x02 0x07 0x01 0x1B 0x02 0x06 0x08 0x03
0x00
bsc_xfer:= a structure defining the transfer
typedef struct
{
uint32_t control; // Write
int rxCnt; // Read only
char rxBuf[BSC_FIFO_SIZE]; // Read only
int txCnt; // Write
char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;
SDA | SCL | MOSI | SCLK | MISO | CE | |
I2C | 18 | 19 | - | - | - | - |
SPI | - | - | 18 | 19 | 20 | 21 |
SDA | SCL | MOSI | SCLK | MISO | CE | |
I2C | 10 | 11 | - | - | - | - |
SPI | - | - | 10 | 11 | 9 | 8 |
22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
a a a a a a a - - IT HC TF IR RE TE BK EC ES PL PH I2 SP EN
aaaaaaa | defines the I2C slave address (only relevant in I2C mode) |
IT | invert transmit status flags |
HC | enable host control |
TF | enable test FIFO |
IR | invert receive status flags |
RE | enable receive |
TE | enable transmit |
BK | abort operation and clear FIFOs |
EC | send control register as first I2C byte |
ES | send status register as first I2C byte |
PL | set SPI polarity high |
PH | set SPI phase high |
I2 | enable I2C mode |
SP | enable SPI mode |
EN | enable BSC peripheral |
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
S S S S S R R R R R T T T T T RB TE RF TF RE TB
SSSSS | number of bytes successfully copied to transmit FIFO |
RRRRR | number of bytes in receieve FIFO |
TTTTT | number of bytes in transmit FIFO |
RB | receive busy |
TE | transmit FIFO empty |
RF | receive FIFO full |
TF | transmit FIFO full |
RE | receive FIFO empty |
TB | transmit busy |
bsc_xfer_t xfer;
xfer.control = (0x13<<16) | 0x305;
memcpy(xfer.txBuf, "ABCD", 4);
xfer.txCnt = 4;
status = bscXfer(&xfer);
if (status >= 0)
{
// process transfer
}
CS: 0-31
MISO: 0-31
MOSI: 0-31
SCLK: 0-31
baud: 50-250000
spiFlags: see below
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2
CS: 0-31, the CS GPIO used in a prior call to bbSPIOpen
CS: 0-31 (as used in a prior call to bbSPIOpen)
inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
count: size of data transfer
// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test
#include <stdio.h>
#include "pigpio.h"
#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12
int main(int argc, char *argv[])
{
int i, count, set_val, read_val;
unsigned char inBuf[3];
char cmd1[] = {0, 0};
char cmd2[] = {12, 0};
char cmd3[] = {1, 128, 0};
if (gpioInitialise() < 0)
{
fprintf(stderr, "pigpio initialisation failed.\n");
return 1;
}
bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
for (i=0; i<256; i++)
{
cmd1[1] = i;
count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC
if (count == 2)
{
count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC
if (count == 2)
{
set_val = inBuf[1];
count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC
if (count == 3)
{
read_val = ((inBuf[1]&3)<<8) | inBuf[2];
printf("%d %d\n", set_val, read_val);
}
}
}
}
bbSPIClose(CE0);
bbSPIClose(CE1);
gpioTerminate();
return 0;
}
MISO | MOSI | SCLK | CE0 | CE1 | CE2 | |
Main SPI | 9 | 10 | 11 | 8 | 7 | - |
Aux SPI | 19 | 20 | 21 | 18 | 17 | 16 |
spiChan: 0-1 (0-2 for the auxiliary SPI)
baud: 32K-125M (values above 30M are unlikely to work)
spiFlags: see below
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m
Mode POL PHA
0 0 0
1 0 1
2 1 0
3 1 1
handle: >=0, as returned by a call to spiOpen
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
handle: >=0, as returned by a call to spiOpen
buf: the data bytes to write
count: the number of bytes to write
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
sertty: the serial device to open
baud: the baud rate in bits per second, see below
serFlags: 0
handle: >=0, as returned by a call to serOpen
handle: >=0, as returned by a call to serOpen
handle: >=0, as returned by a call to serOpen
handle: >=0, as returned by a call to serOpen
buf: the array of bytes to write
count: the number of bytes to write
handle: >=0, as returned by a call to serOpen
buf: an array to receive the read data
count: the maximum number of bytes to read
handle: >=0, as returned by a call to serOpen
user_gpio: 0-31
pulseLen: 1-100
level: 0,1
user_gpio: 0-31
timeout: 0-60000
void aFunction(int gpio, int level, uint32_t tick)
{
printf("GPIO %d became %d at %d", gpio, level, tick);
}
// call aFunction whenever GPIO 4 changes state
gpioSetAlertFunc(4, aFunction);
// or approximately every 5 millis
gpioSetWatchdog(4, 5);
user_gpio: 0-31
steady: 0-300000
active: 0-1000000
user_gpio: 0-31
steady: 0-300000
f: the function to call
bits: the GPIO of interest
f: the function to call
bits: the GPIO of interest
userdata: a pointer to arbitrary user data
timer: 0-9
millis: 10-60000
f: the function to call
void bFunction(void)
{
printf("two seconds have elapsed");
}
// call bFunction every 2000 milliseconds
gpioSetTimerFunc(0, 2000, bFunction);
timer: 0-9.
millis: 10-60000
f: the function to call
userdata: a pointer to arbitrary user data
f: the main function for the new thread
userdata: a pointer to arbitrary user data
#include <stdio.h>
#include <pigpio.h>
void *myfunc(void *arg)
{
while (1)
{
printf("%s", arg);
sleep(1);
}
}
int main(int argc, char *argv[])
{
pthread_t *p1, *p2, *p3;
if (gpioInitialise() < 0) return 1;
p1 = gpioStartThread(myfunc, "thread 1"); sleep(3);
p2 = gpioStartThread(myfunc, "thread 2"); sleep(3);
p3 = gpioStartThread(myfunc, "thread 3"); sleep(3);
gpioStopThread(p3); sleep(3);
gpioStopThread(p2); sleep(3);
gpioStopThread(p1); sleep(3);
gpioTerminate();
}
pth: a thread pointer returned by gpioStartThread
script: the text of the script
script_id: >=0, as returned by gpioStoreScript
numPar: 0-10, the number of parameters
param: an array of parameters
script_id: >=0, as returned by gpioStoreScript
numPar: 0-10, the number of parameters
param: an array of parameters
script_id: >=0, as returned by gpioStoreScript
numPar: 0-10, the number of parameters
param: an array of parameters
script_id: >=0, as returned by gpioStoreScript
param: an array to hold the returned 10 parameters
PI_SCRIPT_INITING
PI_SCRIPT_HALTED
PI_SCRIPT_RUNNING
PI_SCRIPT_WAITING
PI_SCRIPT_FAILED
script_id: >=0, as returned by gpioStoreScript
script_id: >=0, as returned by gpioStoreScript
signum: 0-63
f: the callback function
signum: 0-63
f: the callback function
userdata: a pointer to arbitrary user data
bits: a bit mask of GPIO to clear
// To clear (set to 0) GPIO 4, 7, and 15
gpioWrite_Bits_0_31_Clear( (1<<4) | (1<<7) | (1<<15) );
bits: a bit mask of GPIO to clear
bits: a bit mask of GPIO to set
bits: a bit mask of GPIO to set
// To set (set to 1) GPIO 32, 40, and 53
gpioWrite_Bits_32_53_Set((1<<(32-32)) | (1<<(40-32)) | (1<<(53-32)));
gpio: see description
clkfreq: 0 (off) or 4689-250M (13184-375M for the BCM2711)
4 clock 0 All models
5 clock 1 All models but A and B (reserved for system use)
6 clock 2 All models but A and B
20 clock 0 All models but A and B
21 clock 1 All models but A and Rev.2 B (reserved for system use)
32 clock 0 Compute module only
34 clock 0 Compute module only
42 clock 1 Compute module only (reserved for system use)
43 clock 2 Compute module only
44 clock 1 Compute module only (reserved for system use)
gpio: see description
PWMfreq: 0 (off) or 1-125M (1-187.5M for the BCM2711)
PWMduty: 0 (off) to 1000000 (1M)(fully on)
12 PWM channel 0 All models but A and B
13 PWM channel 1 All models but A and B
18 PWM channel 0 All models
19 PWM channel 1 All models but A and B
40 PWM channel 0 Compute module only
41 PWM channel 1 Compute module only
45 PWM channel 1 Compute module only
52 PWM channel 0 Compute module only
53 PWM channel 1 Compute module only
timetype: 0 (relative), 1 (absolute)
seconds: a pointer to an int to hold seconds
micros: a pointer to an int to hold microseconds
int secs, mics;
// print the number of seconds since the library was started
gpioTime(PI_TIME_RELATIVE, &secs, &mics);
printf("library started %d.%03d seconds ago", secs, mics/1000);
timetype: 0 (relative), 1 (absolute)
seconds: seconds to sleep
micros: microseconds to sleep
gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds
gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds
gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute
micros: the number of microseconds to sleep
uint32_t startTick, endTick;
int diffTick;
startTick = gpioTick();
// do some processing
endTick = gpioTick();
diffTick = endTick - startTick;
printf("some processing took %d microseconds", diffTick);
pad: 0-2, the pad to get
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
strength = gpioGetPad(1); // get pad 1 strength
pad: 0-2, the pad to set
padStrength: 1-16 mA
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
gpioSetPad(0, 16); // set pad 0 strength to 16 mA
handle: >=0, as returned by gpioNotifyOpen
bits: a bit mask indicating the events of interest
// Start reporting events 3, 6, and 7.
// bit 76543210
// (0xC8 = 0b11001000)
eventMonitor(h, 0xC8);
event: 0-31
f: the callback function
event: 0-31
f: the callback function
userdata: pointer to arbitrary user data
event: 0-31, the event
scriptName: the name of the script, only alphanumeric characters,
'-' and '_' are allowed in the name
scriptString: the string to pass to the script
Script exit status | Returned system call status |
1 | 256 |
5 | 1280 |
10 | 2560 |
200 | 51200 |
script not found | 32512 |
// pass two parameters, hello and world
status = shell("scr1", "hello world");
// pass three parameters, hello, string with spaces, and world
status = shell("scr1", "hello 'string with spaces' world");
// pass one parameter, hello string with spaces world
status = shell("scr1", "\"hello string with spaces world\"");
file: the file to open
mode: the file open mode
/home/* n
/home/pi/shared/dir_1/* w
/home/pi/shared/dir_2/* r
/home/pi/shared/dir_3/* u
/home/pi/shared/dir_1/file.txt n
a path containing ..
a path containing only wildcards (*?)
a path containing less than two non-wildcard parts
Macro | Value | Meaning |
PI_FILE_READ | 1 | open file for reading |
PI_FILE_WRITE | 2 | open file for writing |
PI_FILE_RW | 3 | open file for reading and writing |
Macro | Value | Meaning |
PI_FILE_APPEND | 4 | Writes append data to the end of the file |
PI_FILE_CREATE | 8 | The file is created if it doesn't exist |
PI_FILE_TRUNC | 16 | The file is truncated |
#include <stdio.h>
#include <pigpio.h>
int main(int argc, char *argv[])
{
int handle, c;
char buf[60000];
if (gpioInitialise() < 0) return 1;
// assumes /opt/pigpio/access contains the following line
// /ram/*.c r
handle = fileOpen("/ram/pigpio.c", PI_FILE_READ);
if (handle >= 0)
{
while ((c=fileRead(handle, buf, sizeof(buf)-1)))
{
buf[c] = 0;
printf("%s", buf);
}
fileClose(handle);
}
gpioTerminate();
}
handle: >=0, as returned by a call to fileOpen
fileClose(h);
handle: >=0, as returned by a call to fileOpen
buf: the array of bytes to write
count: the number of bytes to write
status = fileWrite(h, buf, count);
if (status == 0)
{
// okay
}
else
{
// error
}
handle: >=0, as returned by a call to fileOpen
buf: an array to receive the read data
count: the maximum number of bytes to read
if (fileRead(h, buf, sizeof(buf)) > 0)
{
// process read data
}
handle: >=0, as returned by a call to fileOpen
seekOffset: the number of bytes to move. Positive offsets
move forward, negative offsets backwards.
seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1),
or PI_FROM_END (2)
fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20
size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size
pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position
fpat: file pattern to match
buf: an array to receive the matching file names
count: the maximum number of bytes to read
#include <stdio.h>
#include <pigpio.h>
int main(int argc, char *argv[])
{
int c;
char buf[1000];
if (gpioInitialise() < 0) return 1;
// assumes /opt/pigpio/access contains the following line
// /ram/*.c r
c = fileList("/ram/p*.c", buf, sizeof(buf));
if (c >= 0)
{
// terminate string
buf[c] = 0;
printf("%s", buf);
}
gpioTerminate();
}
cfgMillis: 100-10000
buffer milliseconds
120 250 500 1sec 2sec 4sec 8sec
1 16 31 55 107 --- --- ---
2 10 18 31 55 107 --- ---
sample 4 8 12 18 31 55 107 ---
rate 5 8 10 14 24 45 87 ---
(us) 8 6 8 12 18 31 55 107
10 6 8 10 14 24 45 87
cfgMicros: 1, 2, 4, 5, 8, 10
cfgPeripheral: 0 (PWM), 1 (PCM)
cfgSource: deprecated, value is ignored
sample cpu
rate %
1 25
2 16
4 11
5 10
8 15
10 14
DMAchannel: 0-14
primaryChannel: 0-14
secondaryChannel: 0-14
updateMask: bit (1<<n) is set for each GPIO n which may be updated
Unknown board | PI_DEFAULT_UPDATE_MASK_UNKNOWN | 0x0FFFFFFC |
Type 1 board | PI_DEFAULT_UPDATE_MASK_B1 | 0x03E6CF93 |
Type 2 board | PI_DEFAULT_UPDATE_MASK_A_B2 | 0xFBC6CF9C |
Type 3 board | PI_DEFAULT_UPDATE_MASK_R3 | 0x0FFFFFFC |
port: 1024-32000
ifFlags: 0-7
memAllocMode: 0-2
numSockAddr: 0-256 (0 means all addresses allowed)
sockAddr: an array of permitted network addresses.
cfgWhat: see source code
cfgVal: see source code
cfgVal: see source code
arg1: >=0
arg2: >=0
argx: extra (byte) arguments
argc: number of extra arguments
arg1: >=0
argx: extra (byte) arguments
argc: number of extra arguments
retBuf: buffer for returned bytes
retMax: maximum number of bytes to return
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
numPulses: the number of pulses
pulses: the array containing the pulses
cbNum: the cb of interest
pos: the position of interest.
pos: the position of interest
lVal: the value to write
pos: the position of interest.
pos: the position of interest
lVal: the value to write
pos: the position of interest
pos: the position of interest
lVal: the value to write
wave_id: the wave of interest
bitPos: bit index from the start of buf
buf: array of bits
numBits: number of valid bits in buf
bitPos: bit index from the start of buf
buf: array of bits
bit: 0-1, value to set
seconds: the number of seconds to sleep
script_id: >=0, a script_id returned by gpioStoreScript
typedef struct
{
uint32_t control; // Write
int rxCnt; // Read only
char rxBuf[BSC_FIFO_SIZE]; // Read only
int txCnt; // Write
char txBuf[BSC_FIFO_SIZE]; // Write
} bsc_xfer_t;
PI_HW_CLK_MIN_FREQ 4689
PI_HW_CLK_MAX_FREQ 250000000
PI_HW_CLK_MAX_FREQ_2711 375000000
PI_MIN_WAVE_DATABITS 1
PI_MAX_WAVE_DATABITS 32
PI_MIN_DMA_CHANNEL 0
PI_MAX_DMA_CHANNEL 15
RISING_EDGE 0
FALLING_EDGE 1
EITHER_EDGE 2
typedef void (*eventFunc_t) (int event, uint32_t tick);
typedef void (*eventFuncEx_t)
(int event, uint32_t tick, void *userdata);
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Type 1 X X - - X - - X X X X X - - X X
Type 2 - - X X X - - X X X X X - - X X
Type 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
Type 1 - X X - - X X X X X - - - - - -
Type 2 - X X - - - X X X X - X X X X X
Type 3 X X X X X X X X X X X X - - - -
typedef void (*gpioAlertFunc_t) (int gpio, int level, uint32_t tick);
typedef void (*eventFuncEx_t)
(int event, int level, uint32_t tick, void *userdata);
typedef void (*gpioGetSamplesFunc_t)
(const gpioSample_t *samples, int numSamples);
typedef void (*gpioGetSamplesFuncEx_t)
(const gpioSample_t *samples, int numSamples, void *userdata);
typedef void (*gpioISRFunc_t)
(int gpio, int level, uint32_t tick);
typedef void (*gpioISRFuncEx_t)
(int gpio, int level, uint32_t tick, void *userdata);
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
} gpioPulse_t;
typedef struct
{
uint32_t tick;
uint32_t level;
} gpioSample_t;
typedef void (*gpioSignalFunc_t) (int signum);
typedef void (*gpioSignalFuncEx_t) (int signum, void *userdata);
typedef void *(gpioThreadFunc_t) (void *);
typedef void (*gpioTimerFunc_t) (void);
typedef void (*gpioTimerFuncEx_t) (void *userdata);
PI_DISABLE_FIFO_IF 1
PI_DISABLE_SOCK_IF 2
PI_OFF 0
PI_ON 1
PI_CLEAR 0
PI_SET 1
PI_LOW 0
PI_HIGH 1
PI_TIMEOUT 2
PI_MEM_ALLOC_AUTO 0
PI_MEM_ALLOC_PAGEMAP 1
PI_MEM_ALLOC_MAILBOX 2
PI_INPUT 0
PI_OUTPUT 1
PI_ALT0 4
PI_ALT1 5
PI_ALT2 6
PI_ALT3 7
PI_ALT4 3
PI_ALT5 2
PI_FILE_READ 1
PI_FILE_WRITE 2
PI_FILE_RW 3
PI_FILE_APPEND 4
PI_FILE_CREATE 8
PI_FILE_TRUNC 16
Pad | GPIO |
0 | 0-27 |
1 | 28-45 |
2 | 46-53 |
typedef struct
{
uint16_t addr; // slave address
uint16_t flags;
uint16_t len; // msg length
uint8_t *buf; // pointer to msg data
} pi_i2c_msg_t;
PI_PUD_OFF 0
PI_PUD_DOWN 1
PI_PUD_UP 2
PI_SERVO_OFF 0
PI_MIN_SERVO_PULSEWIDTH 500
PI_MAX_SERVO_PULSEWIDTH 2500
PI_HW_PWM_RANGE 1000000
PI_HW_PWM_MIN_FREQ 1
PI_HW_PWM_MAX_FREQ 125000000
PI_HW_PWM_MAX_FREQ_2711 187500000
PI_MIN_DUTYCYCLE_RANGE 25
PI_MAX_DUTYCYCLE_RANGE 40000
typedef struct // linux/arch/arm/mach-bcm2708/include/mach/dma.h
{
unsigned long info;
unsigned long src;
unsigned long dst;
unsigned long length;
unsigned long stride;
unsigned long next;
unsigned long pad[2];
} rawCbs_t;
typedef struct
{
int clk; // GPIO for clock
int mosi; // GPIO for MOSI
int miso; // GPIO for MISO
int ss_pol; // slave select off state
int ss_us; // delay after slave select
int clk_pol; // clock off state
int clk_pha; // clock phase
int clk_us; // clock micros
} rawSPI_t;
typedef struct
{
uint32_t gpioOn;
uint32_t gpioOff;
uint32_t usDelay;
uint32_t flags;
} rawWave_t;
typedef struct
{
uint16_t botCB; // first CB used by wave
uint16_t topCB; // last CB used by wave
uint16_t botOOL; // last OOL used by wave
uint16_t topOOL; // first OOL used by wave
uint16_t deleted;
uint16_t numCB;
uint16_t numBOOL;
uint16_t numTOOL;
} rawWaveInfo_t;
PI_FROM_START 0
PI_FROM_CURRENT 1
PI_FROM_END 2
PI_MIN_SIGNUM 0
PI_MAX_SIGNUM 63
PI_MIN_WAVE_HALFSTOPBITS 2
PI_MAX_WAVE_HALFSTOPBITS 8
PI_MIN_WDOG_TIMEOUT 0
PI_MAX_WDOG_TIMEOUT 60000
<=0 cancel timeout
>0 timeout after specified milliseconds
PI_MIN_TIMER 0
PI_MAX_TIMER 9
PI_TIME_RELATIVE 0
PI_TIME_ABSOLUTE 1
user_type *userdata;
user_type my_userdata;
userdata = malloc(sizeof(user_type));
*userdata = my_userdata;
user_type my_userdata = *(user_type*)userdata;
free(userdata);
PI_WAVE_MODE_ONE_SHOT 0
PI_WAVE_MODE_REPEAT 1
PI_WAVE_MODE_ONE_SHOT_SYNC 2
PI_WAVE_MODE_REPEAT_SYNC 3
#define PI_CMD_MODES 0
#define PI_CMD_MODEG 1
#define PI_CMD_PUD 2
#define PI_CMD_READ 3
#define PI_CMD_WRITE 4
#define PI_CMD_PWM 5
#define PI_CMD_PRS 6
#define PI_CMD_PFS 7
#define PI_CMD_SERVO 8
#define PI_CMD_WDOG 9
#define PI_CMD_BR1 10
#define PI_CMD_BR2 11
#define PI_CMD_BC1 12
#define PI_CMD_BC2 13
#define PI_CMD_BS1 14
#define PI_CMD_BS2 15
#define PI_CMD_TICK 16
#define PI_CMD_HWVER 17
#define PI_CMD_NO 18
#define PI_CMD_NB 19
#define PI_CMD_NP 20
#define PI_CMD_NC 21
#define PI_CMD_PRG 22
#define PI_CMD_PFG 23
#define PI_CMD_PRRG 24
#define PI_CMD_HELP 25
#define PI_CMD_PIGPV 26
#define PI_CMD_WVCLR 27
#define PI_CMD_WVAG 28
#define PI_CMD_WVAS 29
#define PI_CMD_WVGO 30
#define PI_CMD_WVGOR 31
#define PI_CMD_WVBSY 32
#define PI_CMD_WVHLT 33
#define PI_CMD_WVSM 34
#define PI_CMD_WVSP 35
#define PI_CMD_WVSC 36
#define PI_CMD_TRIG 37
#define PI_CMD_PROC 38
#define PI_CMD_PROCD 39
#define PI_CMD_PROCR 40
#define PI_CMD_PROCS 41
#define PI_CMD_SLRO 42
#define PI_CMD_SLR 43
#define PI_CMD_SLRC 44
#define PI_CMD_PROCP 45
#define PI_CMD_MICS 46
#define PI_CMD_MILS 47
#define PI_CMD_PARSE 48
#define PI_CMD_WVCRE 49
#define PI_CMD_WVDEL 50
#define PI_CMD_WVTX 51
#define PI_CMD_WVTXR 52
#define PI_CMD_WVNEW 53
#define PI_CMD_I2CO 54
#define PI_CMD_I2CC 55
#define PI_CMD_I2CRD 56
#define PI_CMD_I2CWD 57
#define PI_CMD_I2CWQ 58
#define PI_CMD_I2CRS 59
#define PI_CMD_I2CWS 60
#define PI_CMD_I2CRB 61
#define PI_CMD_I2CWB 62
#define PI_CMD_I2CRW 63
#define PI_CMD_I2CWW 64
#define PI_CMD_I2CRK 65
#define PI_CMD_I2CWK 66
#define PI_CMD_I2CRI 67
#define PI_CMD_I2CWI 68
#define PI_CMD_I2CPC 69
#define PI_CMD_I2CPK 70
#define PI_CMD_SPIO 71
#define PI_CMD_SPIC 72
#define PI_CMD_SPIR 73
#define PI_CMD_SPIW 74
#define PI_CMD_SPIX 75
#define PI_CMD_SERO 76
#define PI_CMD_SERC 77
#define PI_CMD_SERRB 78
#define PI_CMD_SERWB 79
#define PI_CMD_SERR 80
#define PI_CMD_SERW 81
#define PI_CMD_SERDA 82
#define PI_CMD_GDC 83
#define PI_CMD_GPW 84
#define PI_CMD_HC 85
#define PI_CMD_HP 86
#define PI_CMD_CF1 87
#define PI_CMD_CF2 88
#define PI_CMD_BI2CC 89
#define PI_CMD_BI2CO 90
#define PI_CMD_BI2CZ 91
#define PI_CMD_I2CZ 92
#define PI_CMD_WVCHA 93
#define PI_CMD_SLRI 94
#define PI_CMD_CGI 95
#define PI_CMD_CSI 96
#define PI_CMD_FG 97
#define PI_CMD_FN 98
#define PI_CMD_NOIB 99
#define PI_CMD_WVTXM 100
#define PI_CMD_WVTAT 101
#define PI_CMD_PADS 102
#define PI_CMD_PADG 103
#define PI_CMD_FO 104
#define PI_CMD_FC 105
#define PI_CMD_FR 106
#define PI_CMD_FW 107
#define PI_CMD_FS 108
#define PI_CMD_FL 109
#define PI_CMD_SHELL 110
#define PI_CMD_BSPIC 111
#define PI_CMD_BSPIO 112
#define PI_CMD_BSPIX 113
#define PI_CMD_BSCX 114
#define PI_CMD_EVM 115
#define PI_CMD_EVT 116
#define PI_CMD_PROCU 117
#define PI_CMD_WVCAP 118
#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 // DEPRECATED
#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 > 4
#define PI_BAD_CHANNEL -27 // DMA channel not 0-15
#define PI_BAD_PRIM_CHANNEL -27 // DMA primary channel not 0-15
#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-15
#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-3
#define PI_BAD_CFG_INTERNAL -34 // bad parameter in gpioCfgInternals call
#define PI_BAD_WAVE_BAUD -35 // baud rate not 50-250K(RX)/50-1M(TX)
#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 bit bang serial read 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 GPIO 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 not 1-100
#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 id not 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 id not 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 // DEPRECATED
#define PI_SCRIPT_NOT_READY -62 // script initialising
#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
#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B
#define PI_NOT_PWM_GPIO -92 // GPIO is not in use for PWM
#define PI_NOT_SERVO_GPIO -93 // GPIO is not in use for servo pulses
#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock
#define PI_NOT_HPWM_GPIO -95 // GPIO has no hardware PWM
#define PI_BAD_HPWM_FREQ -96 // invalid hardware PWM frequency
#define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M
#define PI_BAD_HCLK_FREQ -98 // invalid hardware clock frequency
#define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1
#define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock
#define PI_BAD_DATABITS -101 // serial data bits not 1-32
#define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8
#define PI_MSG_TOOBIG -103 // socket/pipe message too big
#define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode
#define PI_TOO_MANY_SEGS -105 // too many I2C transaction segments
#define PI_BAD_I2C_SEG -106 // an I2C transaction segment failed
#define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver
#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO
#define PI_BAD_I2C_WLEN -109 // bad I2C write length
#define PI_BAD_I2C_RLEN -110 // bad I2C read length
#define PI_BAD_I2C_CMD -111 // bad I2C command
#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k
#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
#define PI_BAD_CHAIN_LOOP -114 // empty chain loop
#define PI_CHAIN_COUNTER -115 // too many chain counters
#define PI_BAD_CHAIN_CMD -116 // bad chain command
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG -119 // chain is too long
#define PI_DEPRECATED -120 // deprecated function removed
#define PI_BAD_SER_INVERT -121 // bit bang serial invert not 0 or 1
#define PI_BAD_EDGE -122 // bad ISR edge value, not 0-2
#define PI_BAD_ISR_INIT -123 // bad ISR initialisation
#define PI_BAD_FOREVER -124 // loop forever must be last command
#define PI_BAD_FILTER -125 // bad filter parameter
#define PI_BAD_PAD -126 // bad pad number
#define PI_BAD_STRENGTH -127 // bad pad drive strength
#define PI_FIL_OPEN_FAILED -128 // file open failed
#define PI_BAD_FILE_MODE -129 // bad file mode
#define PI_BAD_FILE_FLAG -130 // bad file flag
#define PI_BAD_FILE_READ -131 // bad file read
#define PI_BAD_FILE_WRITE -132 // bad file write
#define PI_FILE_NOT_ROPEN -133 // file not open for read
#define PI_FILE_NOT_WOPEN -134 // file not open for write
#define PI_BAD_FILE_SEEK -135 // bad file seek
#define PI_NO_FILE_MATCH -136 // no files match pattern
#define PI_NO_FILE_ACCESS -137 // no permission to access file
#define PI_FILE_IS_A_DIR -138 // file is a directory
#define PI_BAD_SHELL_STATUS -139 // bad shell return status
#define PI_BAD_SCRIPT_NAME -140 // bad script name
#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k
#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO
#define PI_BAD_EVENT_ID -143 // bad event id
#define PI_CMD_INTERRUPTED -144 // Used by Python
#define PI_NOT_ON_BCM2711 -145 // not available on BCM2711
#define PI_ONLY_ON_BCM2711 -146 // only available on BCM2711
#define PI_PIGIF_ERR_0 -2000
#define PI_PIGIF_ERR_99 -2099
#define PI_CUSTOM_ERR_0 -3000
#define PI_CUSTOM_ERR_999 -3999
#define PI_DEFAULT_BUFFER_MILLIS 120
#define PI_DEFAULT_CLK_MICROS 5
#define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM
#define PI_DEFAULT_IF_FLAGS 0
#define PI_DEFAULT_FOREGROUND 0
#define PI_DEFAULT_DMA_CHANNEL 14
#define PI_DEFAULT_DMA_PRIMARY_CHANNEL 14
#define PI_DEFAULT_DMA_SECONDARY_CHANNEL 6
#define PI_DEFAULT_DMA_PRIMARY_CH_2711 7
#define PI_DEFAULT_DMA_SECONDARY_CH_2711 6
#define PI_DEFAULT_DMA_NOT_SET 15
#define PI_DEFAULT_SOCKET_PORT 8888
#define PI_DEFAULT_SOCKET_PORT_STR "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C
#define PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_ZERO 0x0080000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI2B 0x0080480FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI3B 0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_PI4B 0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL
#define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO
#define PI_DEFAULT_CFG_INTERNALS 0