." 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 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 is not 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 used DMA channels, 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 dutycycles. .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 gpioGetPWMdutycycle(unsigned user_gpio)\fP" .IP "" 4 Returns the PWM dutycycle setting for the gpio. .br .br .EX user_gpio: 0-31 .br .EE .br .br Returns between 0 (off) and range (fully on) if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. .br .br For normal PWM the dutycycle will be out of the defined range for the gpio (see \fBgpioGetPWMrange\fP). .br .br If a hardware clock is active on the gpio the reported dutycycle will be 500000 (500k) out of 1000000 (1M). .br .br If hardware PWM is active on the gpio the reported dutycycle will be out of a 1000000 (1M). .br .br Normal PWM range defaults to 255. .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 If a hardware clock or hardware PWM is active on the gpio the reported range will be 1000000 (1M). .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 If a hardware clock is active on the gpio the reported real range will be 1000000 (1M). .br .br If hardware PWM is active on the gpio the reported real range will be approximately 250M divided by the set PWM frequency. .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 For normal PWM the frequency will be that defined for the gpio by \fBgpioSetPWMfrequency\fP. .br .br If a hardware clock is active on the gpio the reported frequency will be that set by \fBgpioHardwareClock\fP. .br .br If hardware PWM is active on the gpio the reported frequency will be that set by \fBgpioHardwarePWM\fP. .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 pulsewidth. .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 gpioGetServoPulsewidth(unsigned user_gpio)\fP" .IP "" 4 Returns the servo pulsewidth setting for the gpio. .br .br .EX user_gpio: 0-31 .br .EE .br .br Returns , 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. .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<= 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 bbBits, unsigned bbStop, unsigned offset, unsigned numBytes, 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-1000000 .br bbBits: 1-32 .br bbStop: 2-8 .br offset: 0- .br numBytes: 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_BAD_DATABITS, PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES. .br .br NOTES: .br .br The serial data is formatted as one start bit, bbBits data bits, and bbStop/2 stop bits. .br .br It is legal to add serial data streams with different baud rates to the same waveform. .br .br numBytes is the number of bytes of data in str. .br .br The bytes required for each character depend upon bbBits. .br .br For bbBits 1-8 there will be one byte per character. .br For bbBits 9-16 there will be two bytes per character. .br For bbBits 17-32 there will be four bytes per character. .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, 8, 2, 0, strlen(str), str); .br .br for (i=0; i=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 NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. .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 NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled. .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, unsigned bbBits)\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 bbBits: 1-32 .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, 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. .br .br The bytes returned for each character depend upon the number of data bits \fBbbBits\fP specified in the \fBgpioSerialReadOpen\fP command. .br .br For \fBbbBits\fP 1-8 there will be one byte per character. .br For \fBbbBits\fP 9-16 there will be two bytes per character. .br For \fBbbBits\fP 17-32 there will be four bytes per character. .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. .br .br For the SMBus commands the low level transactions are shown at the end of the function description. The following abbreviations are used. .br .br .EX S (1 bit) : Start bit .br P (1 bit) : Stop bit .br Rd/Wr (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0. .br A, NA (1 bit) : Accept and not accept bit. .br .br .br Addr (7 bits): I2C 7 bit address. .br Comm (8 bits): Command byte, a data byte which often selects a register. .br Data (8 bits): A data byte. .br Count (8 bits): A data byte containing the length of a block operation. .br .br [..]: Data sent by the device. .br .EE .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 .EX S Addr Rd/Wr [A] P .br .EE .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 .EX S Addr Wr [A] Data [A] P .br .EE .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 .EX S Addr Rd [A] [Data] NA P .br .EE .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 .EX S Addr Wr [A] Comm [A] Data [A] P .br .EE .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 .EX S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P .br .EE .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 .EX S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P .br .EE .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 .EX S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P .br .EE .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 .EX S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] .br S Addr Rd [A] [DataLow] A [DataHigh] NA P .br .EE .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 .EX S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P .br .EE .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 .EX S Addr Wr [A] Comm [A] .br S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P .br .EE .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 .EX S Addr Wr [A] Comm [A] Count [A] Data [A] ... .br S Addr Rd [A] [Count] A [Data] ... A P .br .EE .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. .br .br .EX S Addr Wr [A] Comm [A] .br S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P .br .EE .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. .br .br .EX S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P .br .EE .IP "\fBint spiOpen(unsigned spiChan, unsigned spiBaud, unsigned spiFlags)\fP" .IP "" 4 This function returns a handle for the SPI device on the channel. Data will be transferred at baud bits per second. The flags may be used to modify the default behaviour of 4-wire operation, mode 0, active low chip select. .br .br An auxiliary SPI device is available on the A+/B+/Pi2 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 .br .EX spiChan: 0-1 (0-2 for A+/B+/Pi2 auxiliary device) .br spiBaud: 32K-125M (values above 30M are unlikely to work) .br spiFlags: see below .br .EE .br .br Returns a handle (>=0) if OK, otherwise PI_BAD_SPI_CHANNEL, PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED. .br .br spiFlags consists of the least significant 22 bits. .br .br .EX 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 .br b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m .br .EE .br .br mm defines the SPI mode. .br .br Warning: modes 1 and 3 do not appear to work on the auxiliary device. .br .br .EX Mode POL PHA .br 0 0 0 .br 1 0 1 .br 2 1 0 .br 3 1 1 .br .EE .br .br 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 A+/B+/Pi2. .br .br W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard SPI device only. .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 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. .br .br The other bits in flags should be set to zero. .IP "\fBint spiClose(unsigned handle)\fP" .IP "" 4 This functions closes the SPI device identified by the handle. .br .br .EX handle: >=0, as returned by a call to \fBspiOpen\fP .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_HANDLE. .IP "\fBint spiRead(unsigned handle, char *buf, unsigned count)\fP" .IP "" 4 This function reads count bytes of data from the SPI device associated with the handle. .br .br .EX handle: >=0, as returned by a call to \fBspiOpen\fP .br buf: an array to receive the read data bytes .br count: the number of bytes to read .br .EE .br .br Returns the number of bytes transferred 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 the number of bytes transferred 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 the number of bytes transferred if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. .IP "\fBint serOpen(char *sertty, unsigned serBaud, unsigned serFlags)\fP" .IP "" 4 This function opens a serial device at a specified baud rate with specified flags. .br .br .EX sertty: the serial device to open, /dev/tty* .br serBaud: the baud rate to use .br serFlags: 0 .br .EE .br .br Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or PI_SER_OPEN_FAILED. .br .br No flags are currently defined. This parameter should be set to zero. .IP "\fBint serClose(unsigned handle)\fP" .IP "" 4 This function closes the serial device associated with handle. .br .br .EX handle: >=0, as returned by a call to \fBserOpen\fP .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_HANDLE. .IP "\fBint serWriteByte(unsigned handle, unsigned bVal)\fP" .IP "" 4 This function writes bVal to the serial port associated with handle. .br .br .EX handle: >=0, as returned by a call to \fBserOpen\fP .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_SER_WRITE_FAILED. .IP "\fBint serReadByte(unsigned handle)\fP" .IP "" 4 This function reads a byte from the serial port associated with handle. .br .br .EX handle: >=0, as returned by a call to \fBserOpen\fP .br .EE .br .br Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED. .IP "\fBint serWrite(unsigned handle, char *buf, unsigned count)\fP" .IP "" 4 This function writes count bytes from buf to the the serial port associated with handle. .br .br .EX handle: >=0, as returned by a call to \fBserOpen\fP .br buf: the array of bytes to write .br count: the number of bytes to write .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_SER_WRITE_FAILED. .IP "\fBint serRead(unsigned handle, char *buf, unsigned count)\fP" .IP "" 4 This function reads up count bytes from the the serial port associated with handle and writes them to buf. .br .br .EX handle: >=0, as returned by a call to serial_open .br buf: an array to receive the read data .br count: the maximum number of bytes to read .br .EE .br .br Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED. .IP "\fBint serDataAvailable(unsigned handle)\fP" .IP "" 4 This function returns the number of bytes available to be read from the device associated with handle. .br .br .EX handle: >=0, as returned by a call to \fBserOpen\fP .br .EE .br .br Returns the number of bytes of data available (>=0) if OK, otherwise PI_BAD_HANDLE. .IP "\fBint gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level)\fP" .IP "" 4 This function sends a trigger pulse to a gpio. The gpio is set to level for pulseLen microseconds and then reset to not level. .br .br .EX user_gpio: 0-31 .br pulseLen: 1-100 .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 (an array of \fBgpioSample_t\fP), 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 (an array of \fBgpioSample_t\fP), 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 .br #include .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 gpioHardwareClock(unsigned gpio, unsigned clkfreq)\fP" .IP "" 4 Starts a hardware clock on a gpio at the specified frequency. Frequencies above 30MHz are unlikely to work. .br .br .EX gpio: see description .br clkfreq: 0 (off) or 4689-250000000 (250M) .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS. .br .br The same clock is available on multiple gpios. The latest frequency setting will be used by all gpios which share a clock. .br .br The gpio must be one of the following. .br .br .EX 4 clock 0 All models .br 5 clock 1 A+/B+/Pi2 and compute module only (reserved for system use) .br 6 clock 2 A+/B+/Pi2 and compute module only .br 20 clock 0 A+/B+/Pi2 and compute module only .br 21 clock 1 All models but Rev.2 B (reserved for system use) .br .br 32 clock 0 Compute module only .br 34 clock 0 Compute module only .br 42 clock 1 Compute module only (reserved for system use) .br 43 clock 2 Compute module only .br 44 clock 1 Compute module only (reserved for system use) .br .EE .br .br Access to clock 1 is protected by a password as its use will likely crash the Pi. The password is given by or'ing 0x5A000000 with the gpio number. .IP "\fBint gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty)\fP" .IP "" 4 Starts hardware PWM on a gpio at the specified frequency and dutycycle. Frequencies above 30MHz are unlikely to work. .br .br NOTE: Any waveform started by \fBgpioWaveTxSend\fP or \fBgpioWaveTxStart\fP will be cancelled. .br .br This function is only valid if the pigpio main clock is PCM. The main clock defaults to PCM but may be overridden by a call to \fBgpioCfgClock\fP. .br .br .EX gpio: see description .br PWMfreq: 0 (off) or 1-125000000 (125M) .br PWMduty: 0 (off) to 1000000 (1M)(fully on) .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL. .br .br The same PWM channel is available on multiple gpios. The latest frequency and dutycycle setting will be used by all gpios which share a PWM channel. .br .br The gpio must be one of the following. .br .br .EX 12 PWM channel 0 A+/B+/Pi2 and compute module only .br 13 PWM channel 1 A+/B+/Pi2 and compute module only .br 18 PWM channel 0 All models .br 19 PWM channel 1 A+/B+/Pi2 and compute module only .br .br 40 PWM channel 0 Compute module only .br 41 PWM channel 1 Compute module only .br 45 PWM channel 1 Compute module only .br 52 PWM channel 0 Compute module only .br 53 PWM channel 1 Compute module only .br .EE .IP "\fBint gpioTime(unsigned timetype, int *seconds, int *micros)\fP" .IP "" 4 Updates the seconds and micros variables with the current time. .br .br .EX timetype: 0 (relative), 1 (absolute) .br seconds: a pointer to an int to hold seconds .br micros: a pointer to an int to hold microseconds .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_TIMETYPE. .br .br If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the number of seconds and microseconds since the epoch (1st January 1970). .br .br If timetype is PI_TIME_RELATIVE updates seconds and micros with the number of seconds and microseconds since the library was initialised. .br .br \fBExample\fP .br .EX int secs, mics; .br .br // print the number of seconds since the library was started .br gpioTime(PI_TIME_RELATIVE, &secs, &mics); .br printf("library started %d.%03d seconds ago\n", secs, mics/1000); .br .EE .IP "\fBint gpioSleep(unsigned timetype, int seconds, int micros)\fP" .IP "" 4 Sleeps for the number of seconds and microseconds specified by seconds and micros. .br .br .EX timetype: 0 (relative), 1 (absolute) .br seconds: seconds to sleep .br micros: microseconds to sleep .br .EE .br .br Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS, or PI_BAD_MICROS. .br .br If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds and microseconds since the epoch (1st January 1970) has elapsed. System clock changes are taken into account. .br .br If timetype is PI_TIME_RELATIVE the sleep is for the specified number of seconds and microseconds. System clock changes do not effect the sleep length. .br .br For short delays (say, 50 microseonds or less) use \fBgpioDelay\fP. .br .br \fBExample\fP .br .EX gpioSleep(PI_TIME_RELATIVE, 2, 500000); // sleep for 2.5 seconds .br .br gpioSleep(PI_TIME_RELATIVE, 0, 100000); // sleep for 0.1 seconds .br .br gpioSleep(PI_TIME_RELATIVE, 60, 0); // sleep for one minute .br .EE .IP "\fBuint32_t gpioDelay(uint32_t micros)\fP" .IP "" 4 Delays for at least the number of microseconds specified by micros. .br .br .EX micros: the number of microseconds to sleep .br .EE .br .br Returns the actual length of the delay in microseconds. .br .br Delays of 100 microseconds or less use busy waits. .IP "\fBuint32_t gpioTick(void)\fP" .IP "" 4 Returns the current system tick. .br .br Tick is the number of microseconds since system boot. .br .br As tick is an unsigned 32 bit quantity it wraps around after 2^32 microseconds, which is approximately 1 hour 12 minutes. .br .br You don't need to worry about the wrap around as long as you take a tick (uint32_t) from another tick, i.e. the following code will always provide the correct difference. .br .br \fBExample\fP .br .EX uint32_t startTick, endTick; .br int diffTick; .br .br startTick = gpioTick(); .br .br // do some processing .br .br endTick = gpioTick(); .br .br diffTick = endTick - startTick; .br .br printf("some processing took %d microseconds\n", diffTick); .br .EE .IP "\fBunsigned gpioHardwareRevision(void)\fP" .IP "" 4 Returns the hardware revision. .br .br If the hardware revision can not be found or is not a valid hexadecimal number the function returns 0. .br .br The hardware revision is the last few characters on the Revision line of /proc/cpuinfo. .br .br The revision number can be used to determine the assignment of gpios to pins (see \fBgpio\fP). .br .br There are at least three types of board. .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 numbers of 16 or greater. .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 particular sample rate timed by a specified peripheral. .br .br .EX cfgMicros: 1, 2, 4, 5, 8, 10 .br cfgPeripheral: 0 (PWM), 1 (PCM) .br cfgSource: deprecated, value is ignored .br .EE .br .br The timings are provided by the specified peripheral (PWM or PCM). .br .br The default setting is 5 microseconds using the PCM peripheral. .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<=0 .br arg2: >=0 .br argx: extra (byte) arguments .br argc: number of extra arguments .br .EE .br .br Returns >= 0 if OK, less than 0 indicates a user defined error. .IP "\fBint gpioCustom2(unsigned arg1, char *argx, unsigned argc, char *retBuf, unsigned retMax)\fP" .IP "" 4 This function is available for user customisation. .br .br It differs from gpioCustom1 in that it returns an array of bytes rather than just an integer. .br .br The returned value is an integer indicating the number of returned bytes. .EX arg1: >=0 .br argx: extra (byte) arguments .br argc: number of extra arguments .br retBuf: buffer for returned bytes .br retMax: maximum number of bytes to return .br .EE .br .br Returns >= 0 if OK, less than 0 indicates a user defined error. .br .br The number of returned bytes must be retMax or less. .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 "\fBrawWaveInfo_t rawWaveInfo(int wave_id)\fP" .IP "" 4 Gets details about the wave with id wave_id. .br .br .EX wave_id: the wave of interest .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 "\fBarg1\fP" 0 .br .br An unsigned argument passed to a user customised function. Its meaning is defined by the customiser. .br .br .IP "\fBarg2\fP" 0 .br .br An unsigned argument passed to a user customised function. Its meaning is defined by the customiser. .br .br .IP "\fBargc\fP" 0 .br .br The count of bytes passed to a user customised function. .br .br .IP "\fB*argx\fP" 0 .br .br A pointer to an array of bytes passed to a user customised function. Its meaning and content is defined by the customiser. .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_BB_MIN_BAUD 50 .br PI_BB_RX_MAX_BAUD 250000 .br PI_BB_TX_MAX_BAUD 1000000 .br .EE .br .br .IP "\fBbbBits\fP: 1-32" 0 .br .br The number of data bits to be used when adding serial data to a waveform. .br .br .EX #define PI_MIN_WAVE_DATABITS 1 .br #define PI_MAX_WAVE_DATABITS 32 .br .EE .br .br .IP "\fBbbStop\fP: 2-8" 0 .br .br The number of (half) stop bits to be used when adding serial data to a waveform. .br .br .EX #define PI_MIN_WAVE_HALFSTOPBITS 2 .br #define PI_MAX_WAVE_HALFSTOPBITS 8 .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<= 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< 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 50-250K(RX)/50-1M(TX) .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 bit bang serial read in progress on gpio .br #define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter .br #define PI_BAD_SERIAL_BUF -40 // bad (null) serial buf parameter .br #define PI_NOT_PERMITTED -41 // gpio operation not permitted .br #define PI_SOME_PERMITTED -42 // one or more gpios not permitted .br #define PI_BAD_WVSC_COMMND -43 // bad WVSC subcommand .br #define PI_BAD_WVSM_COMMND -44 // bad WVSM subcommand .br #define PI_BAD_WVSP_COMMND -45 // bad WVSP subcommand .br #define PI_BAD_PULSELEN -46 // trigger pulse length not 1-100 .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 id not 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 id not 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 #define PI_NO_AUX_SPI -91 // need a A+/B+/Pi2 for auxiliary SPI .br #define PI_NOT_PWM_GPIO -92 // gpio is not in use for PWM .br #define PI_NOT_SERVO_GPIO -93 // gpio is not in use for servo pulses .br #define PI_NOT_HCLK_GPIO -94 // gpio has no hardware clock .br #define PI_NOT_HPWM_GPIO -95 // gpio has no hardware PWM .br #define PI_BAD_HPWM_FREQ -96 // hardware PWM frequency not 1-125M .br #define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M .br #define PI_BAD_HCLK_FREQ -98 // hardware clock frequency not 4689-250M .br #define PI_BAD_HCLK_PASS -99 // need password to use hardware clock 1 .br #define PI_HPWM_ILLEGAL -100 // illegal, PWM in use for main clock .br #define PI_BAD_DATABITS -101 // serial data bits not 1-32 .br #define PI_BAD_STOPBITS -102 // serial (half) stop bits not 2-8 .br #define PI_MSG_TOOBIG -103 // socket/pipe message too big .br #define PI_BAD_MALLOC_MODE -104 // bad memory allocation mode .br #define PI_TOO_MANY_PARTS -105 // too many I2C transaction parts .br #define PI_BAD_I2C_PART -106 // a combined I2C transaction failed .br #define PI_BAD_SMBUS_CMD -107 // SMBus command not supported by driver .br #define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on gpio .br #define PI_BAD_BB_WLEN -109 // bad BB write length .br #define PI_BAD_BB_RLEN -110 // bad BB read length .br #define PI_BAD_BB_CMD -111 // bad BB command .br .br #define PI_PIGIF_ERR_0 -2000 .br #define PI_PIGIF_ERR_99 -2099 .br .br #define PI_CUSTOM_ERR_0 -3000 .br #define PI_CUSTOM_ERR_999 -3999 .br .br .EE .SH Defaults .EX .br #define PI_DEFAULT_BUFFER_MILLIS 120 .br #define PI_DEFAULT_CLK_MICROS 5 .br #define PI_DEFAULT_CLK_PERIPHERAL PI_CLOCK_PCM .br #define PI_DEFAULT_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 0x0080480FFFFFFCLL .br #define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL .br #define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO .br .br .EE .SH SEE ALSO pigpiod(1), pig2vcd(1), pigs(1), pigpiod_if(3) .SH AUTHOR joan@abyz.co.uk