From 46eb4d6056bbb872467fd4ad3e403ea2c0bc76b1 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 1 Mar 2016 21:41:36 +0000 Subject: [PATCH 01/21] V47 --- command.c | 80 ++++---- pigpio.3 | 429 ++++++++++++++++++++++------------------- pigpio.c | 92 ++++++++- pigpio.h | 515 +++++++++++++++++++++++++++----------------------- pigpio.py | 440 ++++++++++++++++++++++-------------------- pigpiod.1 | 32 ++-- pigpiod_if.3 | 264 +++++++++++++------------- pigpiod_if.h | 336 ++++++++++++++++---------------- pigpiod_if2.3 | 313 +++++++++++++++++------------- pigpiod_if2.c | 5 +- pigpiod_if2.h | 364 +++++++++++++++++++---------------- pigs.1 | 411 ++++++++++++++++++++++------------------ setup.py | 2 +- x_pigs | 2 +- x_pipe | 4 +- 15 files changed, 1803 insertions(+), 1486 deletions(-) diff --git a/command.c b/command.c index 32b59de..32619ba 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 46+ +This version is for pigpio version 47+ */ #include @@ -172,6 +172,7 @@ cmdInfo_t cmdInfo[]= {PI_CMD_WVAG, "WVAG", 192, 2}, // gpioWaveAddGeneric {PI_CMD_WVAS, "WVAS", 196, 2}, // gpioWaveAddSerial + {PI_CMD_WVTAT, "WVTAT", 101, 2}, // gpioWaveTxAt {PI_CMD_WVBSY, "WVBSY", 101, 2}, // gpioWaveTxBusy {PI_CMD_WVCHA, "WVCHA", 197, 0}, // gpioWaveChain {PI_CMD_WVCLR, "WVCLR", 101, 0}, // gpioWaveClear @@ -235,15 +236,15 @@ cmdInfo_t cmdInfo[]= char * cmdUsage = "\n\ -BC1 bits Clear gpios in bank 1\n\ -BC2 bits Clear gpios in bank 2\n\ +BC1 bits Clear GPIO in bank 1\n\ +BC2 bits Clear GPIO in bank 2\n\ BI2CC sda Close bit bang I2C\n\ BI2CO sda scl baud | Open bit bang I2C\n\ BI2CZ sda ... I2C bit bang multiple transactions\n\ -BR1 Read bank 1 gpios\n\ -BR2 Read bank 2 gpios\n\ -BS1 bits Set gpios in bank 2\n\ -BS2 bits Set gpios in bank 2\n\ +BR1 Read bank 1 GPIO\n\ +BR2 Read bank 2 GPIO\n\ +BS1 bits Set GPIO in bank 2\n\ +BS2 bits Set GPIO in bank 2\n\ \n\ CF1 ... Custom function 1\n\ CF2 ... Custom function 2\n\ @@ -251,11 +252,11 @@ CF2 ... Custom function 2\n\ CGI Configuration get internals\n\ CSI v Configuration set internals\n\ \n\ -FG g steady Set glitch filter on gpio\n\ -FN g steady active | Set noise filter on gpio\n\ +FG g steady Set glitch filter on GPIO\n\ +FN g steady active | Set noise filter on GPIO\n\ \n\ -GDC g Get PWM dutycycle for gpio\n\ -GPW g Get servo pulsewidth for gpio\n\ +GDC g Get PWM dutycycle for GPIO\n\ +GPW g Get servo pulsewidth for GPIO\n\ \n\ H/HELP Display command help\n\ HC g f Set hardware clock frequency\n\ @@ -281,8 +282,8 @@ I2CWS h b SMBus Write Byte: write byte\n\ I2CWW h r word SMBus Write Word Data: write word to register\n\ I2CZ h ... I2C multiple transactions\n\ \n\ -M/MODES g mode Set gpio mode\n\ -MG/MODEG g Get gpio mode\n\ +M/MODES g mode Set GPIO mode\n\ +MG/MODEG g Get GPIO mode\n\ MICS n Delay for microseconds\n\ MILS n Delay for milliseconds\n\ \n\ @@ -291,24 +292,24 @@ NC h Close notification\n\ NO Request a notification\n\ NP h Pause notification\n\ \n\ -P/PWM g v Set gpio PWM value\n\ +P/PWM g v Set GPIO PWM value\n\ PARSE text Validate script\n\ -PFG g Get gpio PWM frequency\n\ -PFS g v Set gpio PWM frequency\n\ +PFG g Get GPIO PWM frequency\n\ +PFS g v Set GPIO PWM frequency\n\ PIGPV Get pigpio library version\n\ -PRG g Get gpio PWM range\n\ +PRG g Get GPIO PWM range\n\ PROC text Store script\n\ PROCD sid Delete script\n\ PROCP sid Get script status and parameters\n\ PROCR sid ... Run script\n\ PROCS sid Stop script\n\ -PRRG g Get gpio PWM real range\n\ -PRS g v Set gpio PWM range\n\ -PUD g pud Set gpio pull up/down\n\ +PRRG g Get GPIO PWM real range\n\ +PRS g v Set GPIO PWM range\n\ +PUD g pud Set GPIO pull up/down\n\ \n\ -R/READ g Read gpio level\n\ +R/READ g Read GPIO level\n\ \n\ -S/SERVO g v Set gpio servo pulsewidth\n\ +S/SERVO g v Set GPIO servo pulsewidth\n\ SERC h Close serial handle\n\ SERDA h Check for serial data ready to read\n\ SERO text baud flags | Open serial device at baud with flags\n\ @@ -316,9 +317,9 @@ SERR h n Read bytes from serial handle\n\ SERRB h Read byte from serial handle\n\ SERW h ... Write bytes to serial handle\n\ SERWB h byte Write byte to serial handle\n\ -SLR g v Read bit bang serial data from gpio\n\ -SLRC g Close gpio for bit bang serial data\n\ -SLRO g baud bitlen | Open gpio for bit bang serial data\n\ +SLR g v Read bit bang serial data from GPIO\n\ +SLRC g Close GPIO for bit bang serial data\n\ +SLRO g baud bitlen | Open GPIO for bit bang serial data\n\ SLRI g invert Invert serial logic (1 invert, 0 normal)\n\ SPIC h SPI close handle\n\ SPIO channel baud flags | SPI open channel at baud with flags\n\ @@ -327,10 +328,10 @@ SPIW h ... SPI write bytes to handle\n\ SPIX h ... SPI transfer bytes to handle\n\ \n\ T/TICK Get current tick\n\ -TRIG g micros l Trigger level for micros on gpio\n\ +TRIG g micros l Trigger level for micros on GPIO\n\ \n\ -W/WRITE g l Write level to gpio\n\ -WDOG g millis Set millisecond watchdog on gpio\n\ +W/WRITE g l Write level to GPIO\n\ +WDOG g millis Set millisecond watchdog on GPIO\n\ WVAG triplets Wave add generic pulses\n\ WVAS g baud bitlen stopbits offset ... | Wave add serial data\n\ WVBSY Check if wave busy\n\ @@ -345,6 +346,7 @@ WVNEW Start a new empty wave\n\ WVSC 0,1,2 Wave get DMA control block stats\n\ WVSM 0,1,2 Wave get micros stats\n\ WVSP 0,1,2 Wave get pulses stats\n\ +WVTAT Returns the current transmitting wave\n\ WVTX wid Transmit wave as one-shot\n\ WVTXM wid wmde Transmit wave using mode\n\ WVTXR wid Transmit wave repeatedly\n\ @@ -364,8 +366,8 @@ typedef struct static errInfo_t errInfo[]= { {PI_INIT_FAILED , "pigpio initialisation failed"}, - {PI_BAD_USER_GPIO , "gpio not 0-31"}, - {PI_BAD_GPIO , "gpio not 0-53"}, + {PI_BAD_USER_GPIO , "GPIO not 0-31"}, + {PI_BAD_GPIO , "GPIO not 0-53"}, {PI_BAD_MODE , "mode not 0-7"}, {PI_BAD_LEVEL , "level not 0-1"}, {PI_BAD_PUD , "pud not 0-2"}, @@ -400,11 +402,11 @@ static errInfo_t errInfo[]= {PI_BAD_WAVE_BAUD , "baud rate not 50-250K(RX)/50-1M(TX)"}, {PI_TOO_MANY_PULSES , "waveform has too many pulses"}, {PI_TOO_MANY_CHARS , "waveform has too many chars"}, - {PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on gpio"}, + {PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on GPIO"}, {PI_BAD_SERIAL_STRUC , "bad (null) serial structure parameter"}, {PI_BAD_SERIAL_BUF , "bad (null) serial buf parameter"}, - {PI_NOT_PERMITTED , "no permission to update gpio"}, - {PI_SOME_PERMITTED , "no permission to update one or more gpios"}, + {PI_NOT_PERMITTED , "no permission to update GPIO"}, + {PI_SOME_PERMITTED , "no permission to update one or more GPIO"}, {PI_BAD_WVSC_COMMND , "bad WVSC subcommand"}, {PI_BAD_WVSM_COMMND , "bad WVSM subcommand"}, {PI_BAD_WVSP_COMMND , "bad WVSP subcommand"}, @@ -412,7 +414,7 @@ static errInfo_t errInfo[]= {PI_BAD_SCRIPT , "invalid script"}, {PI_BAD_SCRIPT_ID , "unknown script id"}, {PI_BAD_SER_OFFSET , "add serial data offset > 30 minute"}, - {PI_GPIO_IN_USE , "gpio already in use"}, + {PI_GPIO_IN_USE , "GPIO already in use"}, {PI_BAD_SERIAL_COUNT , "must read at least a byte at a time"}, {PI_BAD_PARAM_NUM , "script parameter id not 0-9"}, {PI_DUP_TAG , "script has duplicate tag"}, @@ -454,10 +456,10 @@ static errInfo_t errInfo[]= {PI_SPI_XFER_FAILED , "spi xfer/read/write failed"}, {PI_BAD_POINTER , "bad (NULL) pointer"}, {PI_NO_AUX_SPI , "need a B+ for auxiliary SPI"}, - {PI_NOT_PWM_GPIO , "gpio is not in use for PWM"}, - {PI_NOT_SERVO_GPIO , "gpio is not in use for servo pulses"}, - {PI_NOT_HCLK_GPIO , "gpio has no hardware clock"}, - {PI_NOT_HPWM_GPIO , "gpio has no hardware PWM"}, + {PI_NOT_PWM_GPIO , "GPIO is not in use for PWM"}, + {PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"}, + {PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"}, + {PI_NOT_HPWM_GPIO , "GPIO has no hardware PWM"}, {PI_BAD_HPWM_FREQ , "hardware PWM frequency not 1-125M"}, {PI_BAD_HPWM_DUTY , "hardware PWM dutycycle not 0-1M"}, {PI_BAD_HCLK_FREQ , "hardware clock frequency not 4689-250M"}, @@ -470,7 +472,7 @@ static errInfo_t errInfo[]= {PI_TOO_MANY_SEGS , "too many I2C transaction segments"}, {PI_BAD_I2C_SEG , "an I2C transaction segment failed"}, {PI_BAD_SMBUS_CMD , "SMBus command not supported by driver"}, - {PI_NOT_I2C_GPIO , "no bit bang I2C in progress on gpio"}, + {PI_NOT_I2C_GPIO , "no bit bang I2C in progress on GPIO"}, {PI_BAD_I2C_WLEN , "bad I2C write length"}, {PI_BAD_I2C_RLEN , "bad I2C read length"}, {PI_BAD_I2C_CMD , "bad I2C command"}, diff --git a/pigpio.3 b/pigpio.3 index c4dd556..cc7264d 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -4,7 +4,7 @@ ." .TH pigpio 3 2012-2015 Linux "pigpio archive" .SH NAME -pigpio - A C library to manipulate the Pi's gpios. +pigpio - A C library to manipulate the Pi's GPIO. .SH SYNOPSIS @@ -20,7 +20,7 @@ sudo ./prog .br .br -pigpio is a C library for the Raspberry which allows control of the gpios. +pigpio is a C library for the Raspberry which allows control of the GPIO. .br @@ -29,17 +29,17 @@ pigpio is a C library for the Raspberry which allows control of the gpios. .br .br -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 .br .br -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 .br .br -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state .br @@ -49,17 +49,17 @@ o callbacks at timed intervals .br .br -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation .br .br -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing .br .br -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state .br @@ -69,7 +69,7 @@ o the construction of output waveforms with microsecond timing .br .br -o rudimentary permission control over gpios +o rudimentary permission control over GPIO .br @@ -89,11 +89,11 @@ o creating and running scripts .br .br -.SS gpios +.SS GPIO .br .br -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. .br @@ -250,7 +250,7 @@ gpioTerminate(); .IP "\fBint gpioSetMode(unsigned gpio, unsigned mode)\fP" .IP "" 4 -Sets the gpio mode, typically input or output. +Sets the GPIO mode, typically input or output. .br @@ -296,7 +296,7 @@ gpioSetMode(22,PI_ALT0); // Set gpio22 to alternative mode 0. .IP "\fBint gpioGetMode(unsigned gpio)\fP" .IP "" 4 -Gets the gpio mode. +Gets the GPIO mode. .br @@ -311,7 +311,7 @@ gpio: 0-53 .br .br -Returns the gpio mode if OK, otherwise PI_BAD_GPIO. +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. .br @@ -333,7 +333,7 @@ if (gpioGetMode(17) != PI_ALT0) .IP "\fBint gpioSetPullUpDown(unsigned gpio, unsigned pud)\fP" .IP "" 4 -Sets or clears resistor pull ups or downs on the gpio. +Sets or clears resistor pull ups or downs on the GPIO. .br @@ -374,7 +374,7 @@ gpioSetPullUpDown(23, PI_PUD_OFF); // Clear any pull-ups/downs. .IP "\fBint gpioRead(unsigned gpio)\fP" .IP "" 4 -Reads the gpio level, on or off. +Reads the GPIO level, on or off. .br @@ -389,7 +389,7 @@ gpio: 0-53 .br .br -Returns the gpio level if OK, otherwise PI_BAD_GPIO. +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. .br @@ -403,14 +403,14 @@ Arduino style: digitalRead. .br .EX -printf("gpio24 is level %d\n", gpioRead(24)); +printf("gpio24 is level %d", gpioRead(24)); .br .EE .IP "\fBint gpioWrite(unsigned gpio, unsigned level)\fP" .IP "" 4 -Sets the gpio level, on or off. +Sets the GPIO level, on or off. .br @@ -432,7 +432,7 @@ 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. +If PWM or servo pulses are active on the GPIO they are switched off. .br @@ -453,7 +453,7 @@ gpioWrite(24, 1); // Set gpio24 high. .IP "\fBint gpioPWM(unsigned user_gpio, unsigned dutycycle)\fP" .IP "" 4 -Starts PWM on the gpio, dutycycle between 0 (off) and range (fully on). +Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). Range defaults to 255. .br @@ -512,7 +512,7 @@ gpioPWM(23, 0); // Sets gpio23 full off. .IP "\fBint gpioGetPWMdutycycle(unsigned user_gpio)\fP" .IP "" 4 -Returns the PWM dutycycle setting for the gpio. +Returns the PWM dutycycle setting for the GPIO. .br @@ -534,18 +534,18 @@ PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. .br For normal PWM the dutycycle will be out of the defined range -for the gpio (see \fBgpioGetPWMrange\fP). +for the GPIO (see \fBgpioGetPWMrange\fP). .br .br -If a hardware clock is active on the gpio the reported dutycycle +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 +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). .br @@ -555,7 +555,7 @@ 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 +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 @@ -573,13 +573,13 @@ user_gpio: 0-31 .br .br -Returns the real range for the given gpio's frequency if OK, +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 +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. .br @@ -623,7 +623,7 @@ gpioSetPWMrange(24, 2000); // Now 2000 is fully on .IP "\fBint gpioGetPWMrange(unsigned user_gpio)\fP" .IP "" 4 -Returns the dutycycle range used for the gpio if OK, otherwise +Returns the dutycycle range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .br @@ -639,7 +639,7 @@ user_gpio: 0-31 .br .br -If a hardware clock or hardware PWM is active on the gpio +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). .br @@ -656,7 +656,7 @@ r = gpioGetPWMrange(23); .IP "\fBint gpioGetPWMrealRange(unsigned user_gpio)\fP" .IP "" 4 -Returns the real range used for the gpio if OK, otherwise +Returns the real range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .br @@ -672,13 +672,13 @@ user_gpio: 0-31 .br .br -If a hardware clock is active on the gpio the reported real +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 +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. .br @@ -695,7 +695,7 @@ rr = gpioGetPWMrealRange(17); .IP "\fBint gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency)\fP" .IP "" 4 -Sets the frequency in hertz to be used for the gpio. +Sets the frequency in hertz to be used for the GPIO. .br @@ -724,13 +724,13 @@ 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 +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 +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. .br @@ -808,7 +808,7 @@ gpioSetPWMfrequency(25, 100000); // Set gpio25 to highest frequency. .IP "\fBint gpioGetPWMfrequency(unsigned user_gpio)\fP" .IP "" 4 -Returns the frequency (in hertz) used for the gpio if OK, otherwise +Returns the frequency (in hertz) used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .br @@ -824,19 +824,19 @@ user_gpio: 0-31 .br .br -For normal PWM the frequency will be that defined for the gpio by +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 +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 +If hardware PWM is active on the GPIO the reported frequency will be that set by \fBgpioHardwarePWM\fP. .br @@ -853,7 +853,7 @@ f = gpioGetPWMfrequency(23); // Get frequency used for gpio23. .IP "\fBint gpioServo(unsigned user_gpio, unsigned pulsewidth)\fP" .IP "" 4 -Starts servo pulses on the gpio, 0 (off), 500 (most anti-clockwise) to +Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise). .br @@ -885,8 +885,8 @@ to move beyond its limits. .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. +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 @@ -970,7 +970,7 @@ 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. +Returns the servo pulsewidth setting for the GPIO. .br @@ -991,7 +991,7 @@ 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. +GPIO changes state. .br @@ -1013,12 +1013,12 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO. .br .br -One function may be registered per gpio. +One function may be registered per GPIO. .br .br -The function is passed the gpio, the new level, and the tick. +The function is passed the GPIO, the new level, and the tick. .br @@ -1028,7 +1028,7 @@ 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. +The GPIO are sampled at a rate set when the library is started. .br @@ -1097,13 +1097,13 @@ void aFunction(int gpio, int level, uint32_t tick) .br { .br - printf("gpio %d became %d at %d\n", gpio, level, tick); + printf("GPIO %d became %d at %d", gpio, level, tick); .br } .br .br -// call aFunction whenever gpio 4 changes state +// call aFunction whenever GPIO 4 changes state .br .br @@ -1115,7 +1115,7 @@ gpioSetAlertFunc(4F, aFunction); .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. +GPIO changes state. .br @@ -1139,19 +1139,19 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO. .br .br -One function may be registered per gpio. +One function may be registered per GPIO. .br .br -The function is passed the gpio, the new level, the tick, and +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. +registered per GPIO. .br @@ -1161,7 +1161,7 @@ See \fBgpioSetAlertFunc\fP for further details. .IP "\fBint gpioSetISRFunc(unsigned user_gpio, unsigned edge, int timeout, gpioISRFunc_t f)\fP" .IP "" 4 Registers a function to be called (a callback) whenever the specified -gpio interrupt occurs. +GPIO interrupt occurs. .br @@ -1188,26 +1188,26 @@ or PI_BAD_ISR_INIT. .br .br -One function may be registered per gpio. +One function may be registered per GPIO. .br .br -The function is passed the gpio, the current level, and the +The function is passed the GPIO, the current level, and the current tick. The level will be PI_TIMEOUT if the optional interrupt timeout expires. .br .br -The underlying Linux sysfs gpio interface is used to provide +The underlying Linux sysfs GPIO interface is used to provide the interrupt services. .br .br The first time the function is called, with a non-NULL f, the -gpio is exported, set to be an input, and set to interrupt +GPIO is exported, set to be an input, and set to interrupt on the given edge and timeout. .br @@ -1220,7 +1220,7 @@ edge, timeout, or function. .br The ISR may be cancelled by passing a NULL f, in which case the -gpio is unexported. +GPIO is unexported. .br @@ -1244,7 +1244,7 @@ interrupts only a few microseconds apart). .IP "\fBint gpioSetISRFuncEx(unsigned user_gpio, unsigned edge, int timeout, gpioISRFuncEx_t f, void *userdata)\fP" .IP "" 4 Registers a function to be called (a callback) whenever the specified -gpio interrupt occurs. +GPIO interrupt occurs. .br @@ -1273,14 +1273,14 @@ or PI_BAD_ISR_INIT. .br .br -The function is passed the gpio, the current level, the +The function is passed the GPIO, the current level, the current tick, and the userdata pointer. .br .br Only one of \fBgpioSetISRFunc\fP or \fBgpioSetISRFuncEx\fP can be -registered per gpio. +registered per GPIO. .br @@ -1300,7 +1300,7 @@ otherwise PI_NO_HANDLE. .br .br -A notification is a method for being notified of gpio state changes +A notification is a method for being notified of GPIO state changes via a pipe or socket. .br @@ -1395,7 +1395,7 @@ This function starts notifications on a previously opened handle. .EX handle: >=0, as returned by \fBgpioNotifyOpen\fP .br - bits: a bit mask indicating the gpios of interest + bits: a bit mask indicating the GPIO of interest .br .EE @@ -1408,7 +1408,7 @@ Returns 0 if OK, otherwise PI_BAD_HANDLE. .br .br -The notification sends state changes for each gpio whose corresponding +The notification sends state changes for each GPIO whose corresponding bit in bits is set. .br @@ -1450,7 +1450,7 @@ by one for each report. .br flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a gpio which has had a watchdog timeout; if bit 6 is set +indicate a GPIO which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. @@ -1464,8 +1464,8 @@ after 1h12m. .br .br -level: indicates the level of each gpio. If bit 1<= 0. .br .br -A 64 bit mask indicating which gpios may be written to by the user. +A 64 bit mask indicating which GPIO may be written to by the user. .br .br -If gpio#n may be written then bit (1< 30 minutes .br -#define PI_GPIO_IN_USE -50 // gpio already in use +#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 @@ -8013,15 +8062,15 @@ A 16-bit word value. .br #define PI_BAD_POINTER -90 // bad (NULL) pointer .br -#define PI_NO_AUX_SPI -91 // need a A+/B+/Pi2/Zero for auxiliary SPI +#define PI_NO_AUX_SPI -91 // no auxiliary SPI on Pi A or B .br -#define PI_NOT_PWM_GPIO -92 // gpio is not in use for PWM +#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 +#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 +#define PI_NOT_HCLK_GPIO -94 // GPIO has no hardware clock .br -#define PI_NOT_HPWM_GPIO -95 // gpio has no hardware PWM +#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 @@ -8047,7 +8096,7 @@ A 16-bit word value. .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 +#define PI_NOT_I2C_GPIO -108 // no bit bang I2C in progress on GPIO .br #define PI_BAD_I2C_WLEN -109 // bad I2C write length .br diff --git a/pigpio.c b/pigpio.c index f8a038f..039ccc5 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 46 */ +/* pigpio version 47 */ /* include ------------------------------------------------------- */ @@ -2181,6 +2181,8 @@ static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf) } break; + case PI_CMD_WVTAT: res = gpioWaveTxAt(); break; + case PI_CMD_WVTX: res = gpioWaveTxSend(p[1], PI_WAVE_MODE_ONE_SHOT); break; @@ -4789,6 +4791,53 @@ static unsigned dmaNowAtICB(void) /* ----------------------------------------------------------------------- */ +static int dmaNowAtOCB(void) +{ + unsigned cb; + unsigned page; + uint32_t cbAddr; + + cbAddr = dmaOut[DMA_CONBLK_AD]; + + if (!cbAddr) return -PI_NO_TX_WAVE; + + page = 0; + + /* which page are we dma'ing? */ + + while (1) + { + cb = (cbAddr - ((int)dmaOBus[page])) / 32; + + if (cb < CBS_PER_OPAGE) return (page*CBS_PER_OPAGE) + cb; + + if (page++ >= DMAO_PAGES) break; + } + + /* Try twice */ + + cbAddr = dmaOut[DMA_CONBLK_AD]; + + if (!cbAddr) return -PI_NO_TX_WAVE; + + page = 0; + + /* which page are we dma'ing? */ + + while (1) + { + cb = (cbAddr - ((int)dmaOBus[page])) / 32; + + if (cb < CBS_PER_OPAGE) return (page*CBS_PER_OPAGE) + cb; + + if (page++ >= DMAO_PAGES) break; + } + + return -PI_WAVE_NOT_FOUND; +} + +/* ----------------------------------------------------------------------- */ + unsigned rawWaveCB(void) { unsigned cb; @@ -8560,7 +8609,7 @@ int rawWaveAddSPI( unsigned spiBitLast, unsigned spiBits) { - int p, dbv, bit, halfbit; + int p, bit, dbv, halfbit; int rising_edge[2], read_cycle[2]; uint32_t on_bits, off_bits; int tx_bit_pos; @@ -8600,27 +8649,32 @@ int rawWaveAddSPI( p++; } - /* preset initial mosi bit in case it's read at leading clock bit */ - on_bits = 0; off_bits = 0; tx_bit_pos = 0; + /* preset initial mosi bit */ + if (getBitInBytes(tx_bit_pos, buf, spiTxBits)) { - dbv = 1; on_bits |= (1<<(spi->mosi)); + dbv = 1; } else { + off_bits |= (1<<(spi->mosi)); dbv = 0; - off_bits |= (1<<(spi->mosi)); } + if (!spi->clk_pha) tx_bit_pos ++; + if (spi->ss_pol) off_bits |= (1<clk_pol) on_bits |= (1<<(spi->clk)); + else off_bits |= (1<<(spi->clk)); + wf[2][p].gpioOn = on_bits; wf[2][p].gpioOff = off_bits; wf[2][p].flags = 0; @@ -8649,7 +8703,7 @@ int rawWaveAddSPI( { if (getBitInBytes(tx_bit_pos, buf, spiTxBits)) { - if (!dbv) on_bits |= (1<<(spi->mosi)); + if (!dbv) on_bits |= (1<<(spi->mosi)); dbv = 1; } else @@ -9345,6 +9399,30 @@ int gpioWaveTxBusy(void) return 0; } +/*-------------------------------------------------------------------------*/ + +int gpioWaveTxAt(void) +{ + int i, cb; + + DBG(DBG_USER, ""); + + CHECK_INITED; + + cb = dmaNowAtOCB(); + + if (cb < 0) return -cb; + + for (i=0; i= waveInfo[i].botCB) && + (cb <= waveInfo[i].topCB) ) return i; + } + + return PI_WAVE_NOT_FOUND; +} + /* ----------------------------------------------------------------------- */ int gpioWaveTxStop(void) diff --git a/pigpio.h b/pigpio.h index 3be23d4..b759488 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,31 +31,31 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 46 +#define PIGPIO_VERSION 47 /*TEXT -pigpio is a C library for the Raspberry which allows control of the gpios. +pigpio is a C library for the Raspberry which allows control of the GPIO. *Features* -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state o callbacks at timed intervals -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state o the construction of output waveforms with microsecond timing -o rudimentary permission control over gpios +o rudimentary permission control over GPIO o a simple interface to start and stop new threads @@ -63,9 +63,9 @@ o I2C, SPI, and serial link wrappers o creating and running scripts -*gpios* +*GPIO* -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. *Credits* @@ -110,83 +110,83 @@ gpioTerminate Stop library BEGINNER -gpioSetMode Set a gpio mode -gpioGetMode Get a gpio mode +gpioSetMode Set a GPIO mode +gpioGetMode Get a GPIO mode -gpioSetPullUpDown Set/clear gpio pull up/down resistor +gpioSetPullUpDown Set/clear GPIO pull up/down resistor -gpioRead Read a gpio -gpioWrite Write a gpio +gpioRead Read a GPIO +gpioWrite Write a GPIO -gpioPWM Start/stop PWM pulses on a gpio -gpioGetPWMdutycycle Get dutycycle setting on a gpio +gpioPWM Start/stop PWM pulses on a GPIO +gpioGetPWMdutycycle Get dutycycle setting on a GPIO -gpioServo Start/stop servo pulses on a gpio -gpioGetServoPulsewidth Get pulsewidth setting on a gpio +gpioServo Start/stop servo pulses on a GPIO +gpioGetServoPulsewidth Get pulsewidth setting on a GPIO gpioDelay Delay for a number of microseconds -gpioSetAlertFunc Request a gpio level change callback +gpioSetAlertFunc Request a GPIO level change callback gpioSetTimerFunc Request a regular timed callback INTERMEDIATE -gpioTrigger Send a trigger pulse to a gpio. +gpioTrigger Send a trigger pulse to a GPIO. -gpioSetWatchdog Set a watchdog on a gpio. +gpioSetWatchdog Set a watchdog on a GPIO. -gpioSetPWMrange Configure PWM range for a gpio -gpioGetPWMrange Get configured PWM range for a gpio +gpioSetPWMrange Configure PWM range for a GPIO +gpioGetPWMrange Get configured PWM range for a GPIO -gpioSetPWMfrequency Configure PWM frequency for a gpio -gpioGetPWMfrequency Get configured PWM frequency for a gpio +gpioSetPWMfrequency Configure PWM frequency for a GPIO +gpioGetPWMfrequency Get configured PWM frequency for a GPIO -gpioRead_Bits_0_31 Read all gpios in bank 1 -gpioRead_Bits_32_53 Read all gpios in bank 2 +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 gpios in bank 1 -gpioWrite_Bits_32_53_Clear Clear selected gpios 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 gpios in bank 1 -gpioWrite_Bits_32_53_Set Set selected gpios 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 gpioStartThread Start a new thread gpioStopThread Stop a previously started thread ADVANCED -gpioGetPWMrealRange Get underlying PWM range for a gpio +gpioGetPWMrealRange Get underlying PWM range for a GPIO -gpioSetAlertFuncEx Request a gpio change callback, extended +gpioSetAlertFuncEx Request a GPIO change callback, extended -gpioSetISRFunc Request a gpio interrupt callback -gpioSetISRFuncEx Request a gpio interrupt callback, extended +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 +gpioSetGetSamplesFunc Requests a GPIO samples callback +gpioSetGetSamplesFuncEx Requests a GPIO samples callback, extended gpioSetTimerFuncEx Request a regular timed callback, extended gpioNotifyOpen Request a notification handle gpioNotifyOpenWithSize Request a notification handle with sized pipe -gpioNotifyBegin Start notifications for selected gpios +gpioNotifyBegin Start notifications for selected GPIO gpioNotifyPause Pause notifications gpioNotifyClose Close a notification -gpioSerialReadOpen Opens a gpio for bit bang serial reads +gpioSerialReadOpen Opens a GPIO for bit bang serial reads gpioSerialReadInvert Configures normal/inverted for serial reads -gpioSerialRead Reads bit bang serial data from a gpio -gpioSerialReadClose Closes a gpio for bit bang serial reads +gpioSerialRead Reads bit bang serial data from a GPIO +gpioSerialReadClose Closes a GPIO for bit bang serial reads -gpioHardwareClock Start hardware clock on supported gpios -gpioHardwarePWM Start hardware PWM on supported gpios +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 +gpioGlitchFilter Set a glitch filter on a GPIO +gpioNoiseFilter Set a noise filter on a GPIO SCRIPTS @@ -211,6 +211,8 @@ 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 @@ -255,8 +257,8 @@ i2cSegments Performs multiple I2C transactions i2cZip Performs multiple I2C transactions -bbI2COpen Opens gpios for bit banging I2C -bbI2CClose Closes gpios for bit banging I2C +bbI2COpen Opens GPIO for bit banging I2C +bbI2CClose Closes GPIO for bit banging I2C bbI2CZip Performs multiple bit banged I2C transactions SPI @@ -282,11 +284,11 @@ serDataAvailable Returns number of bytes ready to be read CONFIGURATION -gpioCfgBufferSize Configure the gpio sample buffer size -gpioCfgClock Configure the gpio sample rate +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 +gpioCfgPermissions Configure the GPIO access permissions gpioCfgInterfaces Configure user interfaces gpioCfgSocketPort Configure socket port gpioCfgMemAlloc Configure DMA memory allocation mode @@ -400,7 +402,7 @@ the maximum NUM_WAVE_CBS. OOLS are used from the bottom climbing up and from the top climbing down. -The gpio on and off settings climb up from the bottom (botOOL/numBOOL). +The GPIO on and off settings climb up from the bottom (botOOL/numBOOL). The level and tick read values are stored in descending locations from the top (topOOL/numTOOL). @@ -422,9 +424,9 @@ typedef struct typedef struct { - int clk; /* gpio for clock */ - int mosi; /* gpio for MOSI */ - int miso; /* gpio for MISO */ + 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 */ @@ -507,7 +509,7 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_LOW 0 #define PI_HIGH 1 -/* level: only reported for gpio time-out, see gpioSetWatchdog */ +/* level: only reported for GPIO time-out, see gpioSetWatchdog */ #define PI_TIMEOUT 2 @@ -576,11 +578,8 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_WAVE_MIN_BAUD 50 #define PI_WAVE_MAX_BAUD 1000000 -//#define PI_SPI_MIN_BAUD 32000 -//#define PI_SPI_MAX_BAUD 125000000 - -#define PI_SPI_MIN_BAUD 1 -#define PI_SPI_MAX_BAUD 500000000 +#define PI_SPI_MIN_BAUD 32000 +#define PI_SPI_MAX_BAUD 125000000 #define PI_MIN_WAVE_DATABITS 1 #define PI_MAX_WAVE_DATABITS 32 @@ -604,6 +603,11 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_WAVE_MODE_ONE_SHOT_SYNC 2 #define PI_WAVE_MODE_REPEAT_SYNC 3 +/* special wave at return values */ + +#define PI_WAVE_NOT_FOUND 9998 /* Transmitted wave not found. */ +#define PI_NO_TX_WAVE 9999 /* No wave being transmitted. */ + /* I2C, SPI, SER */ #define PI_I2C_SLOTS 32 @@ -809,7 +813,7 @@ D*/ /*F*/ int gpioSetMode(unsigned gpio, unsigned mode); /*D -Sets the gpio mode, typically input or output. +Sets the GPIO mode, typically input or output. . . gpio: 0-53 @@ -833,13 +837,13 @@ D*/ /*F*/ int gpioGetMode(unsigned gpio); /*D -Gets the gpio mode. +Gets the GPIO mode. . . gpio: 0-53 . . -Returns the gpio mode if OK, otherwise PI_BAD_GPIO. +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. ... if (gpioGetMode(17) != PI_ALT0) @@ -853,7 +857,7 @@ D*/ /*F*/ int gpioSetPullUpDown(unsigned gpio, unsigned pud); /*D -Sets or clears resistor pull ups or downs on the gpio. +Sets or clears resistor pull ups or downs on the GPIO. . . gpio: 0-53 @@ -875,18 +879,18 @@ D*/ /*F*/ int gpioRead (unsigned gpio); /*D -Reads the gpio level, on or off. +Reads the GPIO level, on or off. . . gpio: 0-53 . . -Returns the gpio level if OK, otherwise PI_BAD_GPIO. +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. Arduino style: digitalRead. ... -printf("gpio24 is level %d\n", gpioRead(24)); +printf("gpio24 is level %d", gpioRead(24)); ... D*/ @@ -894,7 +898,7 @@ D*/ /*F*/ int gpioWrite(unsigned gpio, unsigned level); /*D -Sets the gpio level, on or off. +Sets the GPIO level, on or off. . . gpio: 0-53 @@ -903,7 +907,7 @@ level: 0,1 Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. -If PWM or servo pulses are active on the gpio they are switched off. +If PWM or servo pulses are active on the GPIO they are switched off. Arduino style: digitalWrite @@ -916,7 +920,7 @@ D*/ /*F*/ int gpioPWM(unsigned user_gpio, unsigned dutycycle); /*D -Starts PWM on the gpio, dutycycle between 0 (off) and range (fully on). +Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). Range defaults to 255. . . @@ -947,7 +951,7 @@ D*/ /*F*/ int gpioGetPWMdutycycle(unsigned user_gpio); /*D -Returns the PWM dutycycle setting for the gpio. +Returns the PWM dutycycle setting for the GPIO. . . user_gpio: 0-31 @@ -957,12 +961,12 @@ Returns between 0 (off) and range (fully on) if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. For normal PWM the dutycycle will be out of the defined range -for the gpio (see [*gpioGetPWMrange*]). +for the GPIO (see [*gpioGetPWMrange*]). -If a hardware clock is active on the gpio the reported dutycycle +If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). -If hardware PWM is active on the gpio the reported dutycycle +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). Normal PWM range defaults to 255. @@ -972,7 +976,7 @@ D*/ /*F*/ int gpioSetPWMrange(unsigned user_gpio, unsigned range); /*D -Selects the dutycycle range to be used for the gpio. Subsequent calls +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). . . @@ -980,10 +984,10 @@ user_gpio: 0-31 range: 25-40000 . . -Returns the real range for the given gpio's frequency if OK, +Returns the real range for the given GPIO's frequency if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE. -If PWM is currently active on the gpio its dutycycle will be scaled +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. The real range, the number of steps between fully off and fully @@ -1007,14 +1011,14 @@ D*/ /*F*/ int gpioGetPWMrange(unsigned user_gpio); /*D -Returns the dutycycle range used for the gpio if OK, otherwise +Returns the dutycycle range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. . . user_gpio: 0-31 . . -If a hardware clock or hardware PWM is active on the gpio +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). ... @@ -1026,17 +1030,17 @@ D*/ /*F*/ int gpioGetPWMrealRange(unsigned user_gpio); /*D -Returns the real range used for the gpio if OK, otherwise +Returns the real range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. . . user_gpio: 0-31 . . -If a hardware clock is active on the gpio the reported real +If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). -If hardware PWM is active on the gpio the reported real range +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. ... @@ -1048,7 +1052,7 @@ D*/ /*F*/ int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency); /*D -Sets the frequency in hertz to be used for the gpio. +Sets the frequency in hertz to be used for the GPIO. . . user_gpio: 0-31 @@ -1061,10 +1065,10 @@ PI_BAD_USER_GPIO. The selectable frequencies depend upon the sample rate which may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). -Each gpio can be independently set to one of 18 different PWM +Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the gpio it will be +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. The frequencies for each sample rate are: @@ -1105,20 +1109,20 @@ D*/ /*F*/ int gpioGetPWMfrequency(unsigned user_gpio); /*D -Returns the frequency (in hertz) used for the gpio if OK, otherwise +Returns the frequency (in hertz) used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. . . user_gpio: 0-31 . . -For normal PWM the frequency will be that defined for the gpio by +For normal PWM the frequency will be that defined for the GPIO by [*gpioSetPWMfrequency*]. -If a hardware clock is active on the gpio the reported frequency +If a hardware clock is active on the GPIO the reported frequency will be that set by [*gpioHardwareClock*]. -If hardware PWM is active on the gpio the reported frequency +If hardware PWM is active on the GPIO the reported frequency will be that set by [*gpioHardwarePWM*]. ... @@ -1130,7 +1134,7 @@ D*/ /*F*/ int gpioServo(unsigned user_gpio, unsigned pulsewidth); /*D -Starts servo pulses on the gpio, 0 (off), 500 (most anti-clockwise) to +Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise). . . @@ -1146,8 +1150,8 @@ the mid-point of rotation. You can DAMAGE a servo if you command it to move beyond its limits. The following causes an on pulse of 1500 microseconds duration to be -transmitted on gpio 17 at a rate of 50 times per second. This will -command a servo connected to gpio 17 to rotate to its mid-point. +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. ... gpioServo(17, 1000); // Move servo to safe position anti-clockwise. @@ -1189,7 +1193,7 @@ D*/ /*F*/ int gpioGetServoPulsewidth(unsigned user_gpio); /*D -Returns the servo pulsewidth setting for the gpio. +Returns the servo pulsewidth setting for the GPIO. . . user_gpio: 0-31 @@ -1204,7 +1208,7 @@ D*/ int gpioSetAlertFunc(unsigned user_gpio, gpioAlertFunc_t f); /*D Registers a function to be called (a callback) when the specified -gpio changes state. +GPIO changes state. . . user_gpio: 0-31 @@ -1213,13 +1217,13 @@ user_gpio: 0-31 Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -One function may be registered per gpio. +One function may be registered per GPIO. -The function is passed the gpio, the new level, and the tick. +The function is passed the GPIO, the new level, and the tick. The alert may be cancelled by passing NULL as the function. -The gpios are sampled at a rate set when the library is started. +The GPIO are sampled at a rate set when the library is started. If a value isn't specifically set the default of 5 us is used. @@ -1251,10 +1255,10 @@ The tick value is the time stamp of the sample in microseconds, see ... void aFunction(int gpio, int level, uint32_t tick) { - printf("gpio %d became %d at %d\n", gpio, level, tick); + printf("GPIO %d became %d at %d", gpio, level, tick); } -// call aFunction whenever gpio 4 changes state +// call aFunction whenever GPIO 4 changes state gpioSetAlertFunc(4F, aFunction); ... @@ -1266,7 +1270,7 @@ int gpioSetAlertFuncEx( unsigned user_gpio, gpioAlertFuncEx_t f, void *userdata); /*D Registers a function to be called (a callback) when the specified -gpio changes state. +GPIO changes state. . . user_gpio: 0-31 @@ -1276,13 +1280,13 @@ user_gpio: 0-31 Returns 0 if OK, otherwise PI_BAD_USER_GPIO. -One function may be registered per gpio. +One function may be registered per GPIO. -The function is passed the gpio, the new level, the tick, and +The function is passed the GPIO, the new level, the tick, and the userdata pointer. Only one of [*gpioSetAlertFunc*] or [*gpioSetAlertFuncEx*] can be -registered per gpio. +registered per GPIO. See [*gpioSetAlertFunc*] for further details. D*/ @@ -1293,7 +1297,7 @@ int gpioSetISRFunc( unsigned user_gpio, unsigned edge, int timeout, gpioISRFunc_t f); /*D Registers a function to be called (a callback) whenever the specified -gpio interrupt occurs. +GPIO interrupt occurs. . . user_gpio: 0-31 @@ -1305,24 +1309,24 @@ user_gpio: 0-31 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE, or PI_BAD_ISR_INIT. -One function may be registered per gpio. +One function may be registered per GPIO. -The function is passed the gpio, the current level, and the +The function is passed the GPIO, the current level, and the current tick. The level will be PI_TIMEOUT if the optional interrupt timeout expires. -The underlying Linux sysfs gpio interface is used to provide +The underlying Linux sysfs GPIO interface is used to provide the interrupt services. The first time the function is called, with a non-NULL f, the -gpio is exported, set to be an input, and set to interrupt +GPIO is exported, set to be an input, and set to interrupt on the given edge and timeout. Subsequent calls, with a non-NULL f, can vary one or more of the edge, timeout, or function. The ISR may be cancelled by passing a NULL f, in which case the -gpio is unexported. +GPIO is unexported. The tick is that read at the time the process was informed of the interrupt. This will be a variable number of microseconds @@ -1348,7 +1352,7 @@ int gpioSetISRFuncEx( void *userdata); /*D Registers a function to be called (a callback) whenever the specified -gpio interrupt occurs. +GPIO interrupt occurs. . . user_gpio: 0-31 @@ -1361,11 +1365,11 @@ user_gpio: 0-31 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_EDGE, or PI_BAD_ISR_INIT. -The function is passed the gpio, the current level, the +The function is passed the GPIO, the current level, the current tick, and the userdata pointer. Only one of [*gpioSetISRFunc*] or [*gpioSetISRFuncEx*] can be -registered per gpio. +registered per GPIO. See [*gpioSetISRFunc*] for further details. D*/ @@ -1379,7 +1383,7 @@ This function requests a free notification handle. Returns a handle greater than or equal to zero if OK, otherwise PI_NO_HANDLE. -A notification is a method for being notified of gpio state changes +A notification is a method for being notified of GPIO state changes via a pipe or socket. Pipe notifications for handle x will be available at the pipe @@ -1435,12 +1439,12 @@ This function starts notifications on a previously opened handle. . . handle: >=0, as returned by [*gpioNotifyOpen*] - bits: a bit mask indicating the gpios of interest + bits: a bit mask indicating the GPIO of interest . . Returns 0 if OK, otherwise PI_BAD_HANDLE. -The notification sends state changes for each gpio whose corresponding +The notification sends state changes for each GPIO whose corresponding bit in bits is set. Each notification occupies 12 bytes in the fifo and has the @@ -1461,7 +1465,7 @@ by one for each report. flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a gpio which has had a watchdog timeout; if bit 6 is set +indicate a GPIO which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. @@ -1469,11 +1473,11 @@ notification activity. tick: the number of microseconds since system boot. It wraps around after 1h12m. -level: indicates the level of each gpio. If bit 1<= 0. updateMask:: -A 64 bit mask indicating which gpios may be written to by the user. +A 64 bit mask indicating which GPIO may be written to by the user. -If gpio#n may be written then bit (1< 30 minutes -#define PI_GPIO_IN_USE -50 // gpio already in use +#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 @@ -5077,11 +5110,11 @@ after this command is issued. #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 // need a A+/B+/Pi2/Zero for auxiliary SPI -#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_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 // hardware PWM frequency not 1-125M #define PI_BAD_HPWM_DUTY -97 // hardware PWM dutycycle not 0-1M #define PI_BAD_HCLK_FREQ -98 // hardware clock frequency not 4689-250M @@ -5094,7 +5127,7 @@ after this command is issued. #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_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 diff --git a/pigpio.py b/pigpio.py index b960fdf..b6b41d0 100644 --- a/pigpio.py +++ b/pigpio.py @@ -1,7 +1,7 @@ """ pigpio is a Python module for the Raspberry which talks to the pigpio daemon to allow control of the general purpose -input outputs (gpios). +input outputs (GPIO). [http://abyz.co.uk/rpi/pigpio/python.html] @@ -11,23 +11,23 @@ o the pigpio Python module can run on Windows, Macs, or Linux o controls one or more Pi's -o independent PWM on any of gpios 0-31 simultaneously +o independent PWM on any of GPIO 0-31 simultaneously -o independent servo pulses on any of gpios 0-31 simultaneously +o independent servo pulses on any of GPIO 0-31 simultaneously -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state o creating and transmitting precisely timed waveforms -o reading/writing gpios and setting their modes +o reading/writing GPIO and setting their modes o wrappers for I2C, SPI, and serial links o creating and running scripts on the pigpio daemon -*gpios* +*GPIO* -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. *Notes* @@ -42,7 +42,7 @@ A number of settings are determined when the pigpio daemon is started. o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us). -o the set of gpios which may be updated (generally written to). The +o the set of GPIO which may be updated (generally written to). The default set is those available on the Pi board revision. o the available PWM frequencies (see [*set_PWM_frequency*]). @@ -69,7 +69,7 @@ pigpio.exceptions = True *Usage* This module uses the services of the C pigpio library. pigpio -must be running on the Pi(s) whose gpios are to be manipulated. +must be running on the Pi(s) whose GPIO are to be manipulated. The normal way to start pigpio is as a daemon (during system start). @@ -78,16 +78,16 @@ sudo pigpiod Your Python program must import pigpio and create one or more instances of the pigpio.pi class. This class gives access to -a specified Pi's gpios. +a specified Pi's GPIO. ... -pi1 = pigpio.pi() # pi1 accesses the local Pi's gpios -pi2 = pigpio.pi('tom') # pi2 accesses tom's gpios -pi3 = pigpio.pi('dick') # pi3 accesses dick's gpios +pi1 = pigpio.pi() # pi1 accesses the local Pi's GPIO +pi2 = pigpio.pi('tom') # pi2 accesses tom's GPIO +pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO -pi1.write(4, 0) # set local Pi's gpio 4 low -pi2.write(4, 1) # set tom's gpio 4 to high -pi3.read(4) # get level of dick's gpio 4 +pi1.write(4, 0) # set local Pi's GPIO 4 low +pi2.write(4, 1) # set tom's GPIO 4 to high +pi3.read(4) # get level of dick's GPIO 4 ... The later example code snippets assume that pi is an instance of @@ -102,62 +102,62 @@ stop Stop a Pi connection Beginner -set_mode Set a gpio mode -get_mode Get a gpio mode -set_pull_up_down Set/clear gpio pull up/down resistor +set_mode Set a GPIO mode +get_mode Get a GPIO mode +set_pull_up_down Set/clear GPIO pull up/down resistor -read Read a gpio -write Write a gpio +read Read a GPIO +write Write a GPIO -set_PWM_dutycycle Start/stop PWM pulses on a gpio -get_PWM_dutycycle Get PWM dutycycle set on a gpio +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +get_PWM_dutycycle Get PWM dutycycle set on a GPIO -set_servo_pulsewidth Start/Stop servo pulses on a gpio -get_servo_pulsewidth Get servo pulsewidth set on a gpio +set_servo_pulsewidth Start/Stop servo pulses on a GPIO +get_servo_pulsewidth Get servo pulsewidth set on a GPIO -callback Create gpio level change callback -wait_for_edge Wait for gpio level change +callback Create GPIO level change callback +wait_for_edge Wait for GPIO level change Intermediate -gpio_trigger Send a trigger pulse to a gpio +gpio_trigger Send a trigger pulse to a GPIO -set_watchdog Set a watchdog on a gpio +set_watchdog Set a watchdog on a GPIO -set_PWM_range Configure PWM range of a gpio -get_PWM_range Get configured PWM range of a gpio +set_PWM_range Configure PWM range of a GPIO +get_PWM_range Get configured PWM range of a GPIO -set_PWM_frequency Set PWM frequency of a gpio -get_PWM_frequency Get PWM frequency of a gpio +set_PWM_frequency Set PWM frequency of a GPIO +get_PWM_frequency Get PWM frequency of a GPIO -read_bank_1 Read all bank 1 gpios -read_bank_2 Read all bank 2 gpios +read_bank_1 Read all bank 1 GPIO +read_bank_2 Read all bank 2 GPIO -clear_bank_1 Clear selected gpios in bank 1 -clear_bank_2 Clear selected gpios in bank 2 +clear_bank_1 Clear selected GPIO in bank 1 +clear_bank_2 Clear selected GPIO in bank 2 -set_bank_1 Set selected gpios in bank 1 -set_bank_2 Set selected gpios in bank 2 +set_bank_1 Set selected GPIO in bank 1 +set_bank_2 Set selected GPIO in bank 2 Advanced -get_PWM_real_range Get underlying PWM range for a gpio +get_PWM_real_range Get underlying PWM range for a GPIO notify_open Request a notification handle -notify_begin Start notifications for selected gpios +notify_begin Start notifications for selected GPIO notify_pause Pause notifications notify_close Close a notification -bb_serial_read_open Open a gpio for bit bang serial reads -bb_serial_read Read bit bang serial data from a gpio -bb_serial_read_close Close a gpio for bit bang serial reads +bb_serial_read_open Open a GPIO for bit bang serial reads +bb_serial_read Read bit bang serial data from a GPIO +bb_serial_read_close Close a GPIO for bit bang serial reads bb_serial_invert Invert serial logic (1 invert, 0 normal) -hardware_clock Start hardware clock on supported gpios -hardware_PWM Start hardware PWM on supported gpios +hardware_clock Start hardware clock on supported GPIO +hardware_PWM Start hardware PWM on supported GPIO -set_glitch_filter Set a glitch filter on a gpio -set_noise_filter Set a noise filter on a gpio +set_glitch_filter Set a glitch filter on a GPIO +set_noise_filter Set a noise filter on a GPIO Scripts @@ -184,6 +184,7 @@ wave_send_using_mode Transmits a waveform in the chosen mode wave_chain Transmits a chain of waveforms +wave_tx_at Returns the current transmitting waveform wave_tx_busy Checks to see if a waveform has ended wave_tx_stop Aborts the current waveform @@ -219,8 +220,8 @@ i2c_write_device Writes the raw I2C device i2c_zip Performs multiple I2C transactions -bb_i2c_open Opens gpios for bit banging I2C -bb_i2c_close Closes gpios for bit banging I2C +bb_i2c_open Opens GPIO for bit banging I2C +bb_i2c_close Closes GPIO for bit banging I2C bb_i2c_zip Performs multiple bit banged I2C transactions SPI @@ -269,11 +270,11 @@ import threading import os import atexit -VERSION = "1.27" +VERSION = "1.29" exceptions = True -# gpio levels +# GPIO levels OFF = 0 LOW = 0 @@ -285,13 +286,13 @@ SET = 1 TIMEOUT = 2 -# gpio edges +# GPIO edges RISING_EDGE = 0 FALLING_EDGE = 1 EITHER_EDGE = 2 -# gpio modes +# GPIO modes INPUT = 0 OUTPUT = 1 @@ -302,7 +303,7 @@ ALT3 = 7 ALT4 = 3 ALT5 = 2 -# gpio Pull Up Down +# GPIO Pull Up Down PUD_OFF = 0 PUD_DOWN = 1 @@ -329,6 +330,9 @@ WAVE_MODE_REPEAT =1 WAVE_MODE_ONE_SHOT_SYNC=2 WAVE_MODE_REPEAT_SYNC =3 +WAVE_NOT_FOUND = 9998 # Transmitted wave not found. +NO_TX_WAVE = 9999 # No wave being transmitted. + # pigpio command numbers _PI_CMD_MODES= 0 @@ -454,6 +458,7 @@ _PI_CMD_FG =97 _PI_CMD_FN =98 _PI_CMD_WVTXM=100 +_PI_CMD_WVAT =101 # pigpio error numbers @@ -589,8 +594,8 @@ PI_BAD_FILTER =-125 _errors=[ [_PI_INIT_FAILED , "pigpio initialisation failed"], - [PI_BAD_USER_GPIO , "gpio not 0-31"], - [PI_BAD_GPIO , "gpio not 0-53"], + [PI_BAD_USER_GPIO , "GPIO not 0-31"], + [PI_BAD_GPIO , "GPIO not 0-53"], [PI_BAD_MODE , "mode not 0-7"], [PI_BAD_LEVEL , "level not 0-1"], [PI_BAD_PUD , "pud not 0-2"], @@ -625,9 +630,9 @@ _errors=[ [PI_BAD_WAVE_BAUD , "baud rate not 50-250000(RX)/1000000(TX)"], [PI_TOO_MANY_PULSES , "waveform has too many pulses"], [PI_TOO_MANY_CHARS , "waveform has too many chars"], - [PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on gpio"], - [PI_NOT_PERMITTED , "no permission to update gpio"], - [PI_SOME_PERMITTED , "no permission to update one or more gpios"], + [PI_NOT_SERIAL_GPIO , "no bit bang serial read in progress on GPIO"], + [PI_NOT_PERMITTED , "no permission to update GPIO"], + [PI_SOME_PERMITTED , "no permission to update one or more GPIO"], [PI_BAD_WVSC_COMMND , "bad WVSC subcommand"], [PI_BAD_WVSM_COMMND , "bad WVSM subcommand"], [PI_BAD_WVSP_COMMND , "bad WVSP subcommand"], @@ -635,7 +640,7 @@ _errors=[ [PI_BAD_SCRIPT , "invalid script"], [PI_BAD_SCRIPT_ID , "unknown script id"], [PI_BAD_SER_OFFSET , "add serial data offset > 30 minute"], - [PI_GPIO_IN_USE , "gpio already in use"], + [PI_GPIO_IN_USE , "GPIO already in use"], [PI_BAD_SERIAL_COUNT , "must read at least a byte at a time"], [PI_BAD_PARAM_NUM , "script parameter id not 0-9"], [PI_DUP_TAG , "script has duplicate tag"], @@ -676,11 +681,11 @@ _errors=[ [PI_UNKNOWN_COMMAND , "unknown command"], [PI_SPI_XFER_FAILED , "SPI xfer/read/write failed"], [_PI_BAD_POINTER , "bad (NULL) pointer"], - [PI_NO_AUX_SPI , "need a A+/B+/Pi2/Zero for auxiliary SPI"], - [PI_NOT_PWM_GPIO , "gpio is not in use for PWM"], - [PI_NOT_SERVO_GPIO , "gpio is not in use for servo pulses"], - [PI_NOT_HCLK_GPIO , "gpio has no hardware clock"], - [PI_NOT_HPWM_GPIO , "gpio has no hardware PWM"], + [PI_NO_AUX_SPI , "no auxiliary SPI on Pi A or B"], + [PI_NOT_PWM_GPIO , "GPIO is not in use for PWM"], + [PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"], + [PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"], + [PI_NOT_HPWM_GPIO , "GPIO has no hardware PWM"], [PI_BAD_HPWM_FREQ , "hardware PWM frequency not 1-125M"], [PI_BAD_HPWM_DUTY , "hardware PWM dutycycle not 0-1M"], [PI_BAD_HCLK_FREQ , "hardware clock frequency not 4689-250M"], @@ -693,7 +698,7 @@ _errors=[ [_PI_TOO_MANY_SEGS , "too many I2C transaction segments"], [_PI_BAD_I2C_SEG , "an I2C transaction segment failed"], [PI_BAD_SMBUS_CMD , "SMBus command not supported"], - [PI_NOT_I2C_GPIO , "no bit bang I2C in progress on gpio"], + [PI_NOT_I2C_GPIO , "no bit bang I2C in progress on GPIO"], [PI_BAD_I2C_WLEN , "bad I2C write length"], [PI_BAD_I2C_RLEN , "bad I2C read length"], [PI_BAD_I2C_CMD , "bad I2C command"], @@ -738,8 +743,8 @@ class pulse: """ Initialises a pulse. - gpio_on:= the gpios to switch on at the start of the pulse. - gpio_off:= the gpios to switch off at the start of the pulse. + gpio_on:= the GPIO to switch on at the start of the pulse. + gpio_off:= the GPIO to switch off at the start of the pulse. delay:= the delay in microseconds before the next pulse. """ @@ -875,9 +880,9 @@ class _callback_ADT: """ Initialises a callback ADT. - gpio:= Broadcom gpio number. + gpio:= Broadcom GPIO number. edge:= EITHER_EDGE, RISING_EDGE, or FALLING_EDGE. - func:= a user function taking three arguments (gpio, level, tick). + func:= a user function taking three arguments (GPIO, level, tick). """ self.gpio = gpio self.edge = edge @@ -963,7 +968,7 @@ class _callback_thread(threading.Thread): self.sl.s.close() class _callback: - """A class to provide gpio level change callbacks.""" + """A class to provide GPIO level change callbacks.""" def __init__(self, notify, user_gpio, edge=RISING_EDGE, func=None): """ @@ -1006,7 +1011,7 @@ class _callback: self.count = 0 class _wait_for_edge: - """Encapsulates waiting for gpio edges.""" + """Encapsulates waiting for GPIO edges.""" def __init__(self, notify, gpio, edge, timeout): """Initialises a wait_for_edge.""" @@ -1034,22 +1039,22 @@ class pi(): def set_mode(self, gpio, mode): """ - Sets the gpio mode. + Sets the GPIO mode. gpio:= 0-53. mode:= INPUT, OUTPUT, ALT0, ALT1, ALT2, ALT3, ALT4, ALT5. ... - pi.set_mode( 4, pigpio.INPUT) # gpio 4 as input - pi.set_mode(17, pigpio.OUTPUT) # gpio 17 as output - pi.set_mode(24, pigpio.ALT2) # gpio 24 as ALT2 + pi.set_mode( 4, pigpio.INPUT) # GPIO 4 as input + pi.set_mode(17, pigpio.OUTPUT) # GPIO 17 as output + pi.set_mode(24, pigpio.ALT2) # GPIO 24 as ALT2 ... """ return _u2i(_pigpio_command(self.sl, _PI_CMD_MODES, gpio, mode)) def get_mode(self, gpio): """ - Returns the gpio mode. + Returns the GPIO mode. gpio:= 0-53. @@ -1075,7 +1080,7 @@ class pi(): def set_pull_up_down(self, gpio, pud): """ - Sets or clears the internal gpio pull-up/down resistor. + Sets or clears the internal GPIO pull-up/down resistor. gpio:= 0-53. pud:= PUD_UP, PUD_DOWN, PUD_OFF. @@ -1090,7 +1095,7 @@ class pi(): def read(self, gpio): """ - Returns the gpio level. + Returns the GPIO level. gpio:= 0-53. @@ -1110,12 +1115,12 @@ class pi(): def write(self, gpio, level): """ - Sets the gpio level. + Sets the GPIO level. - gpio:= 0-53. + GPIO:= 0-53. level:= 0, 1. - If PWM or servo pulses are active on the gpio they are + If PWM or servo pulses are active on the GPIO they are switched off. ... @@ -1134,7 +1139,7 @@ class pi(): def set_PWM_dutycycle(self, user_gpio, dutycycle): """ - Starts (non-zero dutycycle) or stops (0) PWM pulses on the gpio. + Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO. user_gpio:= 0-31. dutycycle:= 0-range (range defaults to 255). @@ -1154,7 +1159,7 @@ class pi(): def get_PWM_dutycycle(self, user_gpio): """ - Returns the PWM dutycycle being used on the gpio. + Returns the PWM dutycycle being used on the GPIO. user_gpio:= 0-31. @@ -1162,12 +1167,12 @@ class pi(): For normal PWM the dutycycle will be out of the defined range - for the gpio (see [*get_PWM_range*]). + for the GPIO (see [*get_PWM_range*]). - If a hardware clock is active on the gpio the reported + If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). - If hardware PWM is active on the gpio the reported dutycycle + If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). ... @@ -1184,7 +1189,7 @@ class pi(): def set_PWM_range(self, user_gpio, range_): """ - Sets the range of PWM values to be used on the gpio. + Sets the range of PWM values to be used on the GPIO. user_gpio:= 0-31. range_:= 25-40000. @@ -1199,11 +1204,11 @@ class pi(): def get_PWM_range(self, user_gpio): """ - Returns the range of PWM values being used on the gpio. + Returns the range of PWM values being used on the GPIO. user_gpio:= 0-31. - If a hardware clock or hardware PWM is active on the gpio + If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). ... @@ -1217,14 +1222,14 @@ class pi(): def get_PWM_real_range(self, user_gpio): """ Returns the real (underlying) range of PWM values being - used on the gpio. + used on the GPIO. user_gpio:= 0-31. - If a hardware clock is active on the gpio the reported + If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). - If hardware PWM is active on the gpio the reported real range + If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. ... @@ -1237,7 +1242,7 @@ class pi(): def set_PWM_frequency(self, user_gpio, frequency): """ - Sets the frequency (in Hz) of the PWM to be used on the gpio. + Sets the frequency (in Hz) of the PWM to be used on the GPIO. user_gpio:= 0-31. frequency:= >=0 Hz @@ -1259,19 +1264,19 @@ class pi(): def get_PWM_frequency(self, user_gpio): """ - Returns the frequency of PWM being used on the gpio. + Returns the frequency of PWM being used on the GPIO. user_gpio:= 0-31. - Returns the frequency (in Hz) used for the gpio. + Returns the frequency (in Hz) used for the GPIO. - For normal PWM the frequency will be that defined for the gpio + For normal PWM the frequency will be that defined for the GPIO by [*set_PWM_frequency*]. - If a hardware clock is active on the gpio the reported frequency + If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardware_clock*]. - If hardware PWM is active on the gpio the reported frequency + If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardware_PWM*]. ... @@ -1288,7 +1293,7 @@ class pi(): def set_servo_pulsewidth(self, user_gpio, pulsewidth): """ - Starts (500-2500) or stops (0) servo pulses on the gpio. + Starts (500-2500) or stops (0) servo pulses on the GPIO. user_gpio:= 0-31. pulsewidth:= 0 (off), @@ -1316,7 +1321,7 @@ class pi(): def get_servo_pulsewidth(self, user_gpio): """ - Returns the servo pulsewidth being used on the gpio. + Returns the servo pulsewidth being used on the GPIO. user_gpio:= 0-31. @@ -1338,7 +1343,7 @@ class pi(): """ Returns a notification handle (>=0). - A notification is a method for being notified of gpio state + A notification is a method for being notified of GPIO state changes via a pipe. Pipes are only accessible from the local machine so this @@ -1366,7 +1371,7 @@ class pi(): flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) - then bits 0-4 of the flags indicate a gpio which has had a + then bits 0-4 of the flags indicate a GPIO which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity. @@ -1374,8 +1379,8 @@ class pi(): tick: the number of microseconds since system boot. It wraps around after 1h12m. - level: indicates the level of each gpio. If bit 1<=0 (as returned by a prior call to [*notify_open*]) - bits:= a 32 bit mask indicating the gpios to be notified. + bits:= a 32 bit mask indicating the GPIO to be notified. - The notification sends state changes for each gpio whose + The notification sends state changes for each GPIO whose corresponding bit in bits is set. - The following code starts notifications for gpios 1, 4, + The following code starts notifications for GPIO 1, 4, 6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010). ... @@ -1447,27 +1452,27 @@ class pi(): def set_watchdog(self, user_gpio, wdog_timeout): """ - Sets a watchdog timeout for a gpio. + Sets a watchdog timeout for a GPIO. user_gpio:= 0-31. wdog_timeout:= 0-60000. The watchdog is nominally in milliseconds. - Only one watchdog may be registered per gpio. + Only one watchdog may be registered per GPIO. The watchdog may be cancelled by setting timeout to 0. - If no level change has been detected for the gpio for timeout - milliseconds any notification for the gpio has a report written + If no level change has been detected for the GPIO for timeout + milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout. The callback class interprets the flags and will - call registered callbacks for the gpio with level TIMEOUT. + call registered callbacks for the GPIO with level TIMEOUT. ... - pi.set_watchdog(23, 1000) # 1000 ms watchdog on gpio 23 - pi.set_watchdog(23, 0) # cancel watchdog on gpio 23 + pi.set_watchdog(23, 1000) # 1000 ms watchdog on GPIO 23 + pi.set_watchdog(23, 0) # cancel watchdog on GPIO 23 ... """ return _u2i(_pigpio_command( @@ -1475,10 +1480,10 @@ class pi(): def read_bank_1(self): """ - Returns the levels of the bank 1 gpios (gpios 0-31). + Returns the levels of the bank 1 GPIO (GPIO 0-31). The returned 32 bit integer has a bit set if the corresponding - gpio is high. Gpio n has bit value (1<= 0. .br .IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered gpio. +0-31, a Broadcom numbered GPIO. .br diff --git a/pigpiod_if.h b/pigpiod_if.h index 0d2fbdc..6d4f7f3 100644 --- a/pigpiod_if.h +++ b/pigpiod_if.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF_VERSION 21 +#define PIGPIOD_IF_VERSION 22 /*TEXT @@ -38,27 +38,27 @@ THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO USE THE MORE VERSATILE pigpiod_if2 LIBRARY. pigpiod_if is a C library for the Raspberry which allows control -of the gpios via the socket interface to the pigpio daemon. +of the GPIO via the socket interface to the pigpio daemon. *Features* -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state o callbacks at timed intervals -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state o the construction of output waveforms with microsecond timing -o rudimentary permission control over gpios +o rudimentary permission control over GPIO o a simple interface to start and stop new threads @@ -66,9 +66,9 @@ o I2C, SPI, and serial link wrappers o creating and running scripts on the pigpio daemon -*gpios* +*GPIO* -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. *Notes* @@ -109,68 +109,68 @@ pigpio_stop Disconnects from the pigpio daemon BEGINNER -set_mode Set a gpio mode -get_mode Get a gpio mode +set_mode Set a GPIO mode +get_mode Get a GPIO mode -set_pull_up_down Set/clear gpio pull up/down resistor +set_pull_up_down Set/clear GPIO pull up/down resistor -gpio_read Read a gpio -gpio_write Write a gpio +gpio_read Read a GPIO +gpio_write Write a GPIO -set_PWM_dutycycle Start/stop PWM pulses on a gpio -get_PWM_dutycycle Get the PWM dutycycle in use on a gpio +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -set_servo_pulsewidth Start/stop servo pulses on a gpio -get_servo_pulsewidth Get the servo pulsewidth in use on a gpio +set_servo_pulsewidth Start/stop servo pulses on a GPIO +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -callback Create gpio level change callback -callback_ex Create gpio level change callback +callback Create GPIO level change callback +callback_ex Create GPIO level change callback callback_cancel Cancel a callback -wait_for_edge Wait for gpio level change +wait_for_edge Wait for GPIO level change INTERMEDIATE -gpio_trigger Send a trigger pulse to a gpio. +gpio_trigger Send a trigger pulse to a GPIO. -set_watchdog Set a watchdog on a gpio. +set_watchdog Set a watchdog on a GPIO. -set_PWM_range Configure PWM range for a gpio -get_PWM_range Get configured PWM range for a gpio +set_PWM_range Configure PWM range for a GPIO +get_PWM_range Get configured PWM range for a GPIO -set_PWM_frequency Configure PWM frequency for a gpio -get_PWM_frequency Get configured PWM frequency for a gpio +set_PWM_frequency Configure PWM frequency for a GPIO +get_PWM_frequency Get configured PWM frequency for a GPIO -read_bank_1 Read all gpios in bank 1 -read_bank_2 Read all gpios in bank 2 +read_bank_1 Read all GPIO in bank 1 +read_bank_2 Read all GPIO in bank 2 -clear_bank_1 Clear selected gpios in bank 1 -clear_bank_2 Clear selected gpios in bank 2 +clear_bank_1 Clear selected GPIO in bank 1 +clear_bank_2 Clear selected GPIO in bank 2 -set_bank_1 Set selected gpios in bank 1 -set_bank_2 Set selected gpios in bank 2 +set_bank_1 Set selected GPIO in bank 1 +set_bank_2 Set selected GPIO in bank 2 start_thread Start a new thread stop_thread Stop a previously started thread ADVANCED -get_PWM_real_range Get underlying PWM range for a gpio +get_PWM_real_range Get underlying PWM range for a GPIO notify_open Request a notification handle -notify_begin Start notifications for selected gpios +notify_begin Start notifications for selected GPIO notify_pause Pause notifications notify_close Close a notification -bb_serial_read_open Opens a gpio for bit bang serial reads -bb_serial_read Reads bit bang serial data from a gpio -bb_serial_read_close Closes a gpio for bit bang serial reads +bb_serial_read_open Opens a GPIO for bit bang serial reads +bb_serial_read Reads bit bang serial data from a GPIO +bb_serial_read_close Closes a GPIO for bit bang serial reads bb_serial_invert Invert serial logic (1 invert, 0 normal) -hardware_clock Start hardware clock on supported gpios -hardware_PWM Start hardware PWM on supported gpios +hardware_clock Start hardware clock on supported GPIO +hardware_PWM Start hardware PWM on supported GPIO -set_glitch_filter Set a glitch filter on a gpio -set_noise_filter Set a noise filter on a gpio +set_glitch_filter Set a glitch filter on a GPIO +set_noise_filter Set a noise filter on a GPIO SCRIPTS @@ -236,8 +236,8 @@ i2c_write_device Writes the raw I2C device i2c_zip Performs multiple I2C transactions -bb_i2c_open Opens gpios for bit banging I2C -bb_i2c_close Closes gpios for bit banging I2C +bb_i2c_open Opens GPIO for bit banging I2C +bb_i2c_close Closes GPIO for bit banging I2C bb_i2c_zip Performs multiple bit banged I2C transactions SPI @@ -385,7 +385,7 @@ D*/ /*F*/ int set_mode(unsigned gpio, unsigned mode); /*D -Set the gpio mode. +Set the GPIO mode. . . gpio: 0-53. @@ -400,19 +400,19 @@ D*/ /*F*/ int get_mode(unsigned gpio); /*D -Get the gpio mode. +Get the GPIO mode. . . gpio: 0-53. . . -Returns the gpio mode if OK, otherwise PI_BAD_GPIO. +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. D*/ /*F*/ int set_pull_up_down(unsigned gpio, unsigned pud); /*D -Set or clear the gpio pull-up/down resistor. +Set or clear the GPIO pull-up/down resistor. . . gpio: 0-53. @@ -426,19 +426,19 @@ D*/ /*F*/ int gpio_read(unsigned gpio); /*D -Read the gpio level. +Read the GPIO level. . . gpio:0-53. . . -Returns the gpio level if OK, otherwise PI_BAD_GPIO. +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. D*/ /*F*/ int gpio_write(unsigned gpio, unsigned level); /*D -Write the gpio level. +Write the GPIO level. . . gpio: 0-53. @@ -450,13 +450,13 @@ or PI_NOT_PERMITTED. Notes -If PWM or servo pulses are active on the gpio they are switched off. +If PWM or servo pulses are active on the GPIO they are switched off. D*/ /*F*/ int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle); /*D -Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio. +Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. . . user_gpio: 0-31. @@ -474,7 +474,7 @@ D*/ /*F*/ int get_PWM_dutycycle(unsigned user_gpio); /*D -Return the PWM dutycycle in use on a gpio. +Return the PWM dutycycle in use on a GPIO. . . user_gpio: 0-31. @@ -483,19 +483,19 @@ user_gpio: 0-31. Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. For normal PWM the dutycycle will be out of the defined range -for the gpio (see [*get_PWM_range*]). +for the GPIO (see [*get_PWM_range*]). -If a hardware clock is active on the gpio the reported dutycycle +If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). -If hardware PWM is active on the gpio the reported dutycycle +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). D*/ /*F*/ int set_PWM_range(unsigned user_gpio, unsigned range); /*D -Set the range of PWM values to be used on the gpio. +Set the range of PWM values to be used on the GPIO. . . user_gpio: 0-31. @@ -507,11 +507,11 @@ or PI_NOT_PERMITTED. Notes -If PWM is currently active on the gpio its dutycycle will be +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. The real range, the number of steps between fully off and fully on -for each of the 18 available gpio frequencies is +for each of the 18 available GPIO frequencies is . . 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), @@ -525,35 +525,35 @@ D*/ /*F*/ int get_PWM_range(unsigned user_gpio); /*D -Get the range of PWM values being used on the gpio. +Get the range of PWM values being used on the GPIO. . . user_gpio: 0-31. . . -Returns the dutycycle range used for the gpio if OK, +Returns the dutycycle range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. -If a hardware clock or hardware PWM is active on the gpio the +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). D*/ /*F*/ int get_PWM_real_range(unsigned user_gpio); /*D -Get the real underlying range of PWM values being used on the gpio. +Get the real underlying range of PWM values being used on the GPIO. . . user_gpio: 0-31. . . -Returns the real range used for the gpio if OK, +Returns the real range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. -If a hardware clock is active on the gpio the reported +If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). -If hardware PWM is active on the gpio the reported real range +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. D*/ @@ -561,7 +561,7 @@ D*/ /*F*/ int set_PWM_frequency(unsigned user_gpio, unsigned frequency); /*D -Set the frequency (in Hz) of the PWM to be used on the gpio. +Set the frequency (in Hz) of the PWM to be used on the GPIO. . . user_gpio: 0-31. @@ -575,10 +575,10 @@ The selectable frequencies depend upon the sample rate which may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The sample rate is set when the C pigpio library is started. -Each gpio can be independently set to one of 18 different +Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the gpio it will be switched +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. . . @@ -605,29 +605,29 @@ D*/ /*F*/ int get_PWM_frequency(unsigned user_gpio); /*D -Get the frequency of PWM being used on the gpio. +Get the frequency of PWM being used on the GPIO. . . user_gpio: 0-31. . . -For normal PWM the frequency will be that defined for the gpio by +For normal PWM the frequency will be that defined for the GPIO by [*set_PWM_frequency*]. -If a hardware clock is active on the gpio the reported frequency +If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardware_clock*]. -If hardware PWM is active on the gpio the reported frequency +If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardware_PWM*]. -Returns the frequency (in hertz) used for the gpio if OK, +Returns the frequency (in hertz) used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. D*/ /*F*/ int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth); /*D -Start (500-2500) or stop (0) servo pulses on the gpio. +Start (500-2500) or stop (0) servo pulses on the GPIO. . . user_gpio: 0-31. @@ -662,7 +662,7 @@ Then set the PWM range using [*set_PWM_range*] to 1E6/Hz. Doing this allows you to use units of microseconds when setting the servo pulsewidth. -E.g. If you want to update a servo connected to gpio 25 at 400Hz +E.g. If you want to update a servo connected to GPIO 25 at 400Hz . . set_PWM_frequency(25, 400); @@ -676,7 +676,7 @@ D*/ /*F*/ int get_servo_pulsewidth(unsigned user_gpio); /*D -Return the servo pulsewidth in use on a gpio. +Return the servo pulsewidth in use on a GPIO. . . user_gpio: 0-31. @@ -693,7 +693,7 @@ Get a free notification handle. Returns a handle greater than or equal to zero if OK, otherwise PI_NO_HANDLE. -A notification is a method for being notified of gpio state +A notification is a method for being notified of GPIO state changes via a pipe. Pipes are only accessible from the local machine so this function @@ -714,12 +714,12 @@ Start notifications on a previously opened handle. . . handle: 0-31 (as returned by [*notify_open*]) - bits: a mask indicating the gpios to be notified. + bits: a mask indicating the GPIO to be notified. . . Returns 0 if OK, otherwise PI_BAD_HANDLE. -The notification sends state changes for each gpio whose +The notification sends state changes for each GPIO whose corresponding bit in bits is set. Notes @@ -765,7 +765,7 @@ D*/ /*F*/ int set_watchdog(unsigned user_gpio, unsigned timeout); /*D -Sets a watchdog for a gpio. +Sets a watchdog for a GPIO. . . user_gpio: 0-31. @@ -777,24 +777,24 @@ or PI_BAD_WDOG_TIMEOUT. The watchdog is nominally in milliseconds. -Only one watchdog may be registered per gpio. +Only one watchdog may be registered per GPIO. The watchdog may be cancelled by setting timeout to 0. -If no level change has been detected for the gpio for timeout -milliseconds any notification for the gpio has a report written +If no level change has been detected for the GPIO for timeout +milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout. The [*callback*] and [*callback_ex*] functions interpret the flags -and will call registered callbacks for the gpio with level TIMEOUT. +and will call registered callbacks for the GPIO with level TIMEOUT. D*/ /*F*/ int set_glitch_filter(unsigned user_gpio, unsigned steady); /*D -Sets a glitch filter on a gpio. +Sets a glitch filter on a GPIO. -Level changes on the gpio are not reported unless the level +Level changes on the GPIO are not reported unless the level has been stable for at least [*steady*] microseconds. The level is then reported. Level changes of less than [*steady*] microseconds are ignored. @@ -813,11 +813,11 @@ D*/ /*F*/ int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active); /*D -Sets a noise filter on a gpio. +Sets a noise filter on a GPIO. -Level changes on the gpio are ignored until a level which has +Level changes on the GPIO are ignored until a level which has been stable for [*steady*] microseconds is detected. Level changes -on the gpio are then reported for [*active*] microseconds after +on the GPIO are then reported for [*active*] microseconds after which the process repeats. . . @@ -836,90 +836,90 @@ D*/ /*F*/ uint32_t read_bank_1(void); /*D -Read the levels of the bank 1 gpios (gpios 0-31). +Read the levels of the bank 1 GPIO (GPIO 0-31). The returned 32 bit integer has a bit set if the corresponding -gpio is logic 1. Gpio n has bit value (1<= 0. user_gpio:: -0-31, a Broadcom numbered gpio. +0-31, a Broadcom numbered GPIO. See [*gpio*]. diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index 44fe60e..df2afe7 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -21,7 +21,7 @@ gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 -lrt .br pigpiod_if2 is a C library for the Raspberry which allows control -of the gpios via the socket interface to the pigpio daemon. +of the GPIO via the socket interface to the pigpio daemon. .br .br @@ -31,17 +31,17 @@ of the gpios via the socket interface to the pigpio daemon. .br .br -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 .br .br -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 .br .br -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state .br @@ -51,17 +51,17 @@ o callbacks at timed intervals .br .br -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation .br .br -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing .br .br -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state .br @@ -71,7 +71,7 @@ o the construction of output waveforms with microsecond timing .br .br -o rudimentary permission control over gpios +o rudimentary permission control over GPIO .br @@ -91,11 +91,11 @@ o creating and running scripts on the pigpio daemon .br .br -.SS gpios +.SS GPIO .br .br -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. .br @@ -319,7 +319,7 @@ pi: 0- (as returned by \fBpigpio_start\fP). .IP "\fBint set_mode(int pi, unsigned gpio, unsigned mode)\fP" .IP "" 4 -Set the gpio mode. +Set the GPIO mode. .br @@ -345,7 +345,7 @@ or PI_NOT_PERMITTED. .IP "\fBint get_mode(int pi, unsigned gpio)\fP" .IP "" 4 -Get the gpio mode. +Get the GPIO mode. .br @@ -362,11 +362,11 @@ gpio: 0-53. .br .br -Returns the gpio mode if OK, otherwise PI_BAD_GPIO. +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. .IP "\fBint set_pull_up_down(int pi, unsigned gpio, unsigned pud)\fP" .IP "" 4 -Set or clear the gpio pull-up/down resistor. +Set or clear the GPIO pull-up/down resistor. .br @@ -390,7 +390,7 @@ or PI_NOT_PERMITTED. .IP "\fBint gpio_read(int pi, unsigned gpio)\fP" .IP "" 4 -Read the gpio level. +Read the GPIO level. .br @@ -407,11 +407,11 @@ gpio:0-53. .br .br -Returns the gpio level if OK, otherwise PI_BAD_GPIO. +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. .IP "\fBint gpio_write(int pi, unsigned gpio, unsigned level)\fP" .IP "" 4 -Write the gpio level. +Write the GPIO level. .br @@ -441,11 +441,11 @@ Notes .br .br -If PWM or servo pulses are active on the gpio they are switched off. +If PWM or servo pulses are active on the GPIO they are switched off. .IP "\fBint set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle)\fP" .IP "" 4 -Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio. +Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. .br @@ -476,7 +476,7 @@ default range of 255. .IP "\fBint get_PWM_dutycycle(int pi, unsigned user_gpio)\fP" .IP "" 4 -Return the PWM dutycycle in use on a gpio. +Return the PWM dutycycle in use on a GPIO. .br @@ -499,23 +499,23 @@ Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. .br For normal PWM the dutycycle will be out of the defined range -for the gpio (see \fBget_PWM_range\fP). +for the GPIO (see \fBget_PWM_range\fP). .br .br -If a hardware clock is active on the gpio the reported dutycycle +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 +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). .IP "\fBint set_PWM_range(int pi, unsigned user_gpio, unsigned range)\fP" .IP "" 4 -Set the range of PWM values to be used on the gpio. +Set the range of PWM values to be used on the GPIO. .br @@ -545,14 +545,14 @@ Notes .br .br -If PWM is currently active on the gpio its dutycycle will be +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. .br .br The real range, the number of steps between fully off and fully on -for each of the 18 available gpio frequencies is +for each of the 18 available GPIO frequencies is .br @@ -575,7 +575,7 @@ The real value set by set_PWM_range is (dutycycle * real range) / range. .IP "\fBint get_PWM_range(int pi, unsigned user_gpio)\fP" .IP "" 4 -Get the range of PWM values being used on the gpio. +Get the range of PWM values being used on the GPIO. .br @@ -592,18 +592,18 @@ user_gpio: 0-31. .br .br -Returns the dutycycle range used for the gpio if OK, +Returns the dutycycle range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .br .br -If a hardware clock or hardware PWM is active on the gpio the +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). .IP "\fBint get_PWM_real_range(int pi, unsigned user_gpio)\fP" .IP "" 4 -Get the real underlying range of PWM values being used on the gpio. +Get the real underlying range of PWM values being used on the GPIO. .br @@ -620,19 +620,19 @@ user_gpio: 0-31. .br .br -Returns the real range used for the gpio if OK, +Returns the real range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .br .br -If a hardware clock is active on the gpio the reported +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 +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. .br @@ -641,7 +641,7 @@ will be approximately 250M divided by the set PWM frequency. .IP "\fBint set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency)\fP" .IP "" 4 -Set the frequency (in Hz) of the PWM to be used on the gpio. +Set the frequency (in Hz) of the PWM to be used on the GPIO. .br @@ -673,13 +673,13 @@ sample rate is set when the C pigpio library is started. .br .br -Each gpio can be independently set to one of 18 different +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 +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. .br @@ -726,7 +726,7 @@ off and then back on at the new frequency. .IP "\fBint get_PWM_frequency(int pi, unsigned user_gpio)\fP" .IP "" 4 -Get the frequency of PWM being used on the gpio. +Get the frequency of PWM being used on the GPIO. .br @@ -743,30 +743,30 @@ user_gpio: 0-31. .br .br -For normal PWM the frequency will be that defined for the gpio by +For normal PWM the frequency will be that defined for the GPIO by \fBset_PWM_frequency\fP. .br .br -If a hardware clock is active on the gpio the reported frequency +If a hardware clock is active on the GPIO the reported frequency will be that set by \fBhardware_clock\fP. .br .br -If hardware PWM is active on the gpio the reported frequency +If hardware PWM is active on the GPIO the reported frequency will be that set by \fBhardware_PWM\fP. .br .br -Returns the frequency (in hertz) used for the gpio if OK, +Returns the frequency (in hertz) used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. .IP "\fBint set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth)\fP" .IP "" 4 -Start (500-2500) or stop (0) servo pulses on the gpio. +Start (500-2500) or stop (0) servo pulses on the GPIO. .br @@ -844,7 +844,7 @@ the servo pulsewidth. .br .br -E.g. If you want to update a servo connected to gpio 25 at 400Hz +E.g. If you want to update a servo connected to GPIO 25 at 400Hz .br @@ -867,7 +867,7 @@ e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse. .IP "\fBint get_servo_pulsewidth(int pi, unsigned user_gpio)\fP" .IP "" 4 -Return the servo pulsewidth in use on a gpio. +Return the servo pulsewidth in use on a GPIO. .br @@ -909,7 +909,7 @@ otherwise PI_NO_HANDLE. .br .br -A notification is a method for being notified of gpio state +A notification is a method for being notified of GPIO state changes via a pipe. .br @@ -941,7 +941,7 @@ Start notifications on a previously opened handle. .br handle: 0-31 (as returned by \fBnotify_open\fP) .br - bits: a mask indicating the gpios to be notified. + bits: a mask indicating the GPIO to be notified. .br .EE @@ -954,7 +954,7 @@ Returns 0 if OK, otherwise PI_BAD_HANDLE. .br .br -The notification sends state changes for each gpio whose +The notification sends state changes for each GPIO whose corresponding bit in bits is set. .br @@ -1034,7 +1034,7 @@ Returns 0 if OK, otherwise PI_BAD_HANDLE. .IP "\fBint set_watchdog(int pi, unsigned user_gpio, unsigned timeout)\fP" .IP "" 4 -Sets a watchdog for a gpio. +Sets a watchdog for a GPIO. .br @@ -1064,7 +1064,7 @@ The watchdog is nominally in milliseconds. .br .br -Only one watchdog may be registered per gpio. +Only one watchdog may be registered per GPIO. .br @@ -1074,24 +1074,24 @@ The watchdog may be cancelled by setting timeout to 0. .br .br -If no level change has been detected for the gpio for timeout -milliseconds any notification for the gpio has a report written +If no level change has been detected for the GPIO for timeout +milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout. .br .br The \fBcallback\fP and \fBcallback_ex\fP functions interpret the flags -and will call registered callbacks for the gpio with level TIMEOUT. +and will call registered callbacks for the GPIO with level TIMEOUT. .IP "\fBint set_glitch_filter(int pi, unsigned user_gpio, unsigned steady)\fP" .IP "" 4 -Sets a glitch filter on a gpio. +Sets a glitch filter on a GPIO. .br .br -Level changes on the gpio are not reported unless the level +Level changes on the GPIO are not reported unless the level has been stable for at least \fBsteady\fP microseconds. The level is then reported. Level changes of less than \fBsteady\fP microseconds are ignored. @@ -1123,14 +1123,14 @@ after it was first detected. .IP "\fBint set_noise_filter(int pi, unsigned user_gpio, unsigned steady, unsigned active)\fP" .IP "" 4 -Sets a noise filter on a gpio. +Sets a noise filter on a GPIO. .br .br -Level changes on the gpio are ignored until a level which has +Level changes on the GPIO are ignored until a level which has been stable for \fBsteady\fP microseconds is detected. Level changes -on the gpio are then reported for \fBactive\fP microseconds after +on the GPIO are then reported for \fBactive\fP microseconds after which the process repeats. .br @@ -1163,7 +1163,7 @@ such reports. .IP "\fBuint32_t read_bank_1(int pi)\fP" .IP "" 4 -Read the levels of the bank 1 gpios (gpios 0-31). +Read the levels of the bank 1 GPIO (GPIO 0-31). .br @@ -1179,11 +1179,11 @@ pi: 0- (as returned by \fBpigpio_start\fP). .br The returned 32 bit integer has a bit set if the corresponding -gpio is logic 1. Gpio n has bit value (1<= 0. .br .IP "\fBuser_gpio\fP" 0 -0-31, a Broadcom numbered gpio. +0-31, a Broadcom numbered GPIO. .br diff --git a/pigpiod_if2.c b/pigpiod_if2.c index e5971f2..e478ddd 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 3 */ +/* PIGPIOD_IF2_VERSION 5 */ #include #include @@ -874,6 +874,9 @@ int wave_chain(int pi, char *buf, unsigned bufSize) (pi, PI_CMD_WVCHA, 0, 0, bufSize, 1, ext, 1); } +int wave_tx_at(int pi) + {return pigpio_command(pi, PI_CMD_WVTAT, 0, 0, 1);} + int wave_tx_busy(int pi) {return pigpio_command(pi, PI_CMD_WVBSY, 0, 0, 1);} diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 51846c4..f4be0f5 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,32 +30,32 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 3 +#define PIGPIOD_IF2_VERSION 5 /*TEXT pigpiod_if2 is a C library for the Raspberry which allows control -of the gpios via the socket interface to the pigpio daemon. +of the GPIO via the socket interface to the pigpio daemon. *Features* -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 -o callbacks when any of gpios 0-31 change state +o callbacks when any of GPIO 0-31 change state o callbacks at timed intervals -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state o the construction of output waveforms with microsecond timing -o rudimentary permission control over gpios +o rudimentary permission control over GPIO o a simple interface to start and stop new threads @@ -63,9 +63,9 @@ o I2C, SPI, and serial link wrappers o creating and running scripts on the pigpio daemon -*gpios* +*GPIO* -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. *Notes* @@ -106,68 +106,68 @@ pigpio_stop Disconnects from a pigpio daemon BEGINNER -set_mode Set a gpio mode -get_mode Get a gpio mode +set_mode Set a GPIO mode +get_mode Get a GPIO mode -set_pull_up_down Set/clear gpio pull up/down resistor +set_pull_up_down Set/clear GPIO pull up/down resistor -gpio_read Read a gpio -gpio_write Write a gpio +gpio_read Read a GPIO +gpio_write Write a GPIO -set_PWM_dutycycle Start/stop PWM pulses on a gpio -get_PWM_dutycycle Get the PWM dutycycle in use on a gpio +set_PWM_dutycycle Start/stop PWM pulses on a GPIO +get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO -set_servo_pulsewidth Start/stop servo pulses on a gpio -get_servo_pulsewidth Get the servo pulsewidth in use on a gpio +set_servo_pulsewidth Start/stop servo pulses on a GPIO +get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO -callback Create gpio level change callback -callback_ex Create gpio level change callback +callback Create GPIO level change callback +callback_ex Create GPIO level change callback callback_cancel Cancel a callback -wait_for_edge Wait for gpio level change +wait_for_edge Wait for GPIO level change INTERMEDIATE -gpio_trigger Send a trigger pulse to a gpio. +gpio_trigger Send a trigger pulse to a GPIO. -set_watchdog Set a watchdog on a gpio. +set_watchdog Set a watchdog on a GPIO. -set_PWM_range Configure PWM range for a gpio -get_PWM_range Get configured PWM range for a gpio +set_PWM_range Configure PWM range for a GPIO +get_PWM_range Get configured PWM range for a GPIO -set_PWM_frequency Configure PWM frequency for a gpio -get_PWM_frequency Get configured PWM frequency for a gpio +set_PWM_frequency Configure PWM frequency for a GPIO +get_PWM_frequency Get configured PWM frequency for a GPIO -read_bank_1 Read all gpios in bank 1 -read_bank_2 Read all gpios in bank 2 +read_bank_1 Read all GPIO in bank 1 +read_bank_2 Read all GPIO in bank 2 -clear_bank_1 Clear selected gpios in bank 1 -clear_bank_2 Clear selected gpios in bank 2 +clear_bank_1 Clear selected GPIO in bank 1 +clear_bank_2 Clear selected GPIO in bank 2 -set_bank_1 Set selected gpios in bank 1 -set_bank_2 Set selected gpios in bank 2 +set_bank_1 Set selected GPIO in bank 1 +set_bank_2 Set selected GPIO in bank 2 start_thread Start a new thread stop_thread Stop a previously started thread ADVANCED -get_PWM_real_range Get underlying PWM range for a gpio +get_PWM_real_range Get underlying PWM range for a GPIO notify_open Request a notification handle -notify_begin Start notifications for selected gpios +notify_begin Start notifications for selected GPIO notify_pause Pause notifications notify_close Close a notification -bb_serial_read_open Opens a gpio for bit bang serial reads -bb_serial_read Reads bit bang serial data from a gpio -bb_serial_read_close Closes a gpio for bit bang serial reads +bb_serial_read_open Opens a GPIO for bit bang serial reads +bb_serial_read Reads bit bang serial data from a GPIO +bb_serial_read_close Closes a GPIO for bit bang serial reads bb_serial_invert Invert serial logic (1 invert, 0 normal) -hardware_clock Start hardware clock on supported gpios -hardware_PWM Start hardware PWM on supported gpios +hardware_clock Start hardware clock on supported GPIO +hardware_PWM Start hardware PWM on supported GPIO -set_glitch_filter Set a glitch filter on a gpio -set_noise_filter Set a noise filter on a gpio +set_glitch_filter Set a glitch filter on a GPIO +set_noise_filter Set a noise filter on a GPIO SCRIPTS @@ -194,6 +194,7 @@ wave_send_using_mode Transmits a waveform in the chosen mode wave_chain Transmits a chain of waveforms +wave_tx_at Returns the current transmitting waveform wave_tx_busy Checks to see if the waveform has ended wave_tx_stop Aborts the current waveform @@ -234,8 +235,8 @@ i2c_write_device Writes the raw I2C device i2c_zip Performs multiple I2C transactions -bb_i2c_open Opens gpios for bit banging I2C -bb_i2c_close Closes gpios for bit banging I2C +bb_i2c_open Opens GPIO for bit banging I2C +bb_i2c_close Closes GPIO for bit banging I2C bb_i2c_zip Performs multiple bit banged I2C transactions SPI @@ -393,7 +394,7 @@ D*/ /*F*/ int set_mode(int pi, unsigned gpio, unsigned mode); /*D -Set the gpio mode. +Set the GPIO mode. . . pi: 0- (as returned by [*pigpio_start*]). @@ -409,20 +410,20 @@ D*/ /*F*/ int get_mode(int pi, unsigned gpio); /*D -Get the gpio mode. +Get the GPIO mode. . . pi: 0- (as returned by [*pigpio_start*]). gpio: 0-53. . . -Returns the gpio mode if OK, otherwise PI_BAD_GPIO. +Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. D*/ /*F*/ int set_pull_up_down(int pi, unsigned gpio, unsigned pud); /*D -Set or clear the gpio pull-up/down resistor. +Set or clear the GPIO pull-up/down resistor. . . pi: 0- (as returned by [*pigpio_start*]). @@ -437,20 +438,20 @@ D*/ /*F*/ int gpio_read(int pi, unsigned gpio); /*D -Read the gpio level. +Read the GPIO level. . . pi: 0- (as returned by [*pigpio_start*]). gpio:0-53. . . -Returns the gpio level if OK, otherwise PI_BAD_GPIO. +Returns the GPIO level if OK, otherwise PI_BAD_GPIO. D*/ /*F*/ int gpio_write(int pi, unsigned gpio, unsigned level); /*D -Write the gpio level. +Write the GPIO level. . . pi: 0- (as returned by [*pigpio_start*]). @@ -463,13 +464,13 @@ or PI_NOT_PERMITTED. Notes -If PWM or servo pulses are active on the gpio they are switched off. +If PWM or servo pulses are active on the GPIO they are switched off. D*/ /*F*/ int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle); /*D -Start (non-zero dutycycle) or stop (0) PWM pulses on the gpio. +Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -488,7 +489,7 @@ D*/ /*F*/ int get_PWM_dutycycle(int pi, unsigned user_gpio); /*D -Return the PWM dutycycle in use on a gpio. +Return the PWM dutycycle in use on a GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -498,19 +499,19 @@ user_gpio: 0-31. Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO. For normal PWM the dutycycle will be out of the defined range -for the gpio (see [*get_PWM_range*]). +for the GPIO (see [*get_PWM_range*]). -If a hardware clock is active on the gpio the reported dutycycle +If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). -If hardware PWM is active on the gpio the reported dutycycle +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). D*/ /*F*/ int set_PWM_range(int pi, unsigned user_gpio, unsigned range); /*D -Set the range of PWM values to be used on the gpio. +Set the range of PWM values to be used on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -523,11 +524,11 @@ or PI_NOT_PERMITTED. Notes -If PWM is currently active on the gpio its dutycycle will be +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. The real range, the number of steps between fully off and fully on -for each of the 18 available gpio frequencies is +for each of the 18 available GPIO frequencies is . . 25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6), @@ -541,37 +542,37 @@ D*/ /*F*/ int get_PWM_range(int pi, unsigned user_gpio); /*D -Get the range of PWM values being used on the gpio. +Get the range of PWM values being used on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). user_gpio: 0-31. . . -Returns the dutycycle range used for the gpio if OK, +Returns the dutycycle range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. -If a hardware clock or hardware PWM is active on the gpio the +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). D*/ /*F*/ int get_PWM_real_range(int pi, unsigned user_gpio); /*D -Get the real underlying range of PWM values being used on the gpio. +Get the real underlying range of PWM values being used on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). user_gpio: 0-31. . . -Returns the real range used for the gpio if OK, +Returns the real range used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. -If a hardware clock is active on the gpio the reported +If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). -If hardware PWM is active on the gpio the reported real range +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. D*/ @@ -579,7 +580,7 @@ D*/ /*F*/ int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency); /*D -Set the frequency (in Hz) of the PWM to be used on the gpio. +Set the frequency (in Hz) of the PWM to be used on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -594,10 +595,10 @@ The selectable frequencies depend upon the sample rate which may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The sample rate is set when the C pigpio library is started. -Each gpio can be independently set to one of 18 different +Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the gpio it will be switched +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. . . @@ -624,30 +625,30 @@ D*/ /*F*/ int get_PWM_frequency(int pi, unsigned user_gpio); /*D -Get the frequency of PWM being used on the gpio. +Get the frequency of PWM being used on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). user_gpio: 0-31. . . -For normal PWM the frequency will be that defined for the gpio by +For normal PWM the frequency will be that defined for the GPIO by [*set_PWM_frequency*]. -If a hardware clock is active on the gpio the reported frequency +If a hardware clock is active on the GPIO the reported frequency will be that set by [*hardware_clock*]. -If hardware PWM is active on the gpio the reported frequency +If hardware PWM is active on the GPIO the reported frequency will be that set by [*hardware_PWM*]. -Returns the frequency (in hertz) used for the gpio if OK, +Returns the frequency (in hertz) used for the GPIO if OK, otherwise PI_BAD_USER_GPIO. D*/ /*F*/ int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth); /*D -Start (500-2500) or stop (0) servo pulses on the gpio. +Start (500-2500) or stop (0) servo pulses on the GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -683,7 +684,7 @@ Then set the PWM range using [*set_PWM_range*] to 1E6/Hz. Doing this allows you to use units of microseconds when setting the servo pulsewidth. -E.g. If you want to update a servo connected to gpio 25 at 400Hz +E.g. If you want to update a servo connected to GPIO 25 at 400Hz . . set_PWM_frequency(25, 400); @@ -697,7 +698,7 @@ D*/ /*F*/ int get_servo_pulsewidth(int pi, unsigned user_gpio); /*D -Return the servo pulsewidth in use on a gpio. +Return the servo pulsewidth in use on a GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -719,7 +720,7 @@ pi: 0- (as returned by [*pigpio_start*]). Returns a handle greater than or equal to zero if OK, otherwise PI_NO_HANDLE. -A notification is a method for being notified of gpio state +A notification is a method for being notified of GPIO state changes via a pipe. Pipes are only accessible from the local machine so this function @@ -741,12 +742,12 @@ Start notifications on a previously opened handle. . . pi: 0- (as returned by [*pigpio_start*]). handle: 0-31 (as returned by [*notify_open*]) - bits: a mask indicating the gpios to be notified. + bits: a mask indicating the GPIO to be notified. . . Returns 0 if OK, otherwise PI_BAD_HANDLE. -The notification sends state changes for each gpio whose +The notification sends state changes for each GPIO whose corresponding bit in bits is set. Notes @@ -794,7 +795,7 @@ D*/ /*F*/ int set_watchdog(int pi, unsigned user_gpio, unsigned timeout); /*D -Sets a watchdog for a gpio. +Sets a watchdog for a GPIO. . . pi: 0- (as returned by [*pigpio_start*]). @@ -807,24 +808,24 @@ or PI_BAD_WDOG_TIMEOUT. The watchdog is nominally in milliseconds. -Only one watchdog may be registered per gpio. +Only one watchdog may be registered per GPIO. The watchdog may be cancelled by setting timeout to 0. -If no level change has been detected for the gpio for timeout -milliseconds any notification for the gpio has a report written +If no level change has been detected for the GPIO for timeout +milliseconds any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout. The [*callback*] and [*callback_ex*] functions interpret the flags -and will call registered callbacks for the gpio with level TIMEOUT. +and will call registered callbacks for the GPIO with level TIMEOUT. D*/ /*F*/ int set_glitch_filter(int pi, unsigned user_gpio, unsigned steady); /*D -Sets a glitch filter on a gpio. +Sets a glitch filter on a GPIO. -Level changes on the gpio are not reported unless the level +Level changes on the GPIO are not reported unless the level has been stable for at least [*steady*] microseconds. The level is then reported. Level changes of less than [*steady*] microseconds are ignored. @@ -845,11 +846,11 @@ D*/ int set_noise_filter( int pi, unsigned user_gpio, unsigned steady, unsigned active); /*D -Sets a noise filter on a gpio. +Sets a noise filter on a GPIO. -Level changes on the gpio are ignored until a level which has +Level changes on the GPIO are ignored until a level which has been stable for [*steady*] microseconds is detected. Level changes -on the gpio are then reported for [*active*] microseconds after +on the GPIO are then reported for [*active*] microseconds after which the process repeats. . . @@ -869,102 +870,102 @@ D*/ /*F*/ uint32_t read_bank_1(int pi); /*D -Read the levels of the bank 1 gpios (gpios 0-31). +Read the levels of the bank 1 GPIO (GPIO 0-31). . . pi: 0- (as returned by [*pigpio_start*]). . . The returned 32 bit integer has a bit set if the corresponding -gpio is logic 1. Gpio n has bit value (1<= 0. user_gpio:: -0-31, a Broadcom numbered gpio. +0-31, a Broadcom numbered GPIO. See [*gpio*]. diff --git a/pigs.1 b/pigs.1 index 2340e1c..b42fd40 100644 --- a/pigs.1 +++ b/pigs.1 @@ -24,7 +24,7 @@ or .br -The socket and pipe interfaces allow control of the gpios by passing +The socket and pipe interfaces allow control of the GPIO by passing messages to the running pigpio library. .br @@ -45,19 +45,19 @@ whereas /dev/pigpio uses the pipe interface. .br .SS Features .br -o PWM on any of gpios 0-31 +o PWM on any of GPIO 0-31 .br -o servo pulses on any of gpios 0-31 +o servo pulses on any of GPIO 0-31 .br -o reading/writing all of the gpios in a bank as one operation +o reading/writing all of the GPIO in a bank as one operation .br -o individually setting gpio modes, reading and writing +o individually setting GPIO modes, reading and writing .br -o notifications when any of gpios 0-31 change state +o notifications when any of GPIO 0-31 change state .br o the construction of output waveforms with microsecond timing @@ -69,9 +69,9 @@ o I2C, SPI, and serial link wrappers o creating and running scripts on the pigpio daemon .br -.SS gpios +.SS GPIO .br -ALL gpios are identified by their Broadcom number. +ALL GPIO are identified by their Broadcom number. .br .SS Usage @@ -191,10 +191,10 @@ E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal. .br -.IP "\fBBC1 bits\fP - Clear specified gpios in bank 1" +.IP "\fBBC1 bits\fP - Clear specified GPIO in bank 1" .IP "" 4 -This command clears (sets low) the gpios specified by \fBbits\fP in bank 1. -Bank 1 consists of gpios 0-31. +This command clears (sets low) the GPIO specified by \fBbits\fP in bank 1. +Bank 1 consists of GPIO 0-31. .br Upon success nothing is returned. On error a negative status code @@ -206,25 +206,25 @@ will be returned. .br .EX -$ pigs bc1 0x400010 # clear gpios 4 (1<<4) and 22 (1<<22) +$ pigs bc1 0x400010 # clear GPIO 4 (1<<4) and 22 (1<<22) .br .br -$ pigs bc1 32 # clear gpio 5 (1<<5) +$ pigs bc1 32 # clear GPIO 5 (1<<5) .br -42 .br -ERROR: no permission to update one or more gpios +ERROR: no permission to update one or more GPIO .br .EE .br -.IP "\fBBC2 bits\fP - Clear specified gpios in bank 2" +.IP "\fBBC2 bits\fP - Clear specified GPIO in bank 2" .IP "" 4 -This command clears (sets low) the gpios specified by \fBbits\fP in bank 2. -Bank 2 consists of gpios 32-53. +This command clears (sets low) the GPIO specified by \fBbits\fP in bank 2. +Bank 2 consists of GPIO 32-53. .br Upon success nothing is returned. On error a negative status code @@ -236,15 +236,15 @@ will be returned. .br .EX -$ pigs bc2 0x8000 # clear gpio 47 (activity LED on A+/B+/Pi2) +$ pigs bc2 0x8000 # clear GPIO 47 (activity LED on A+/B+/Pi2/Pi3) .br .br -$ pigs bc2 1 # clear gpio 32 (first in bank 2) +$ pigs bc2 1 # clear GPIO 32 (first in bank 2) .br -42 .br -ERROR: no permission to update one or more gpios +ERROR: no permission to update one or more GPIO .br .EE @@ -271,7 +271,7 @@ $ pigs bi2cc 5 .IP "\fBBI2CO sda scl b\fP - Open bit bang I2C" .IP "" 4 -This command signals that gpios \fBsda\fP and \fBscl\fP are to be used +This command signals that GPIO \fBsda\fP and \fBscl\fP are to be used for bit banging I2C at \fBb\fP baud. .br @@ -285,13 +285,13 @@ o repeated starts .br o clock stretching .br -o I2C on any pair of spare gpios +o I2C on any pair of spare GPIO .br The baud rate may be between 50 and 500000 bits per second. .br -The gpios used for SDA and SCL must have pull-ups to 3V3 connected. As +The GPIO used for SDA and SCL must have pull-ups to 3V3 connected. As a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value. .br @@ -380,9 +380,9 @@ End .br -.IP "\fBBR1 \fP - Read bank 1 gpios" +.IP "\fBBR1 \fP - Read bank 1 GPIO" .IP "" 4 -This command read gpios 0-31 (bank 1) and returns the levels as a +This command read GPIO 0-31 (bank 1) and returns the levels as a 32-bit hexadecimal value. .br @@ -400,9 +400,9 @@ $ pigs br1 .br -.IP "\fBBR2 \fP - Read bank 2 gpios" +.IP "\fBBR2 \fP - Read bank 2 GPIO" .IP "" 4 -This command read gpios 32-53 (bank 2) and returns the levels as a +This command read GPIO 32-53 (bank 2) and returns the levels as a 32-bit hexadecimal value. .br @@ -420,10 +420,10 @@ $ pigs br2 .br -.IP "\fBBS1 bits\fP - Set specified gpios in bank 1" +.IP "\fBBS1 bits\fP - Set specified GPIO in bank 1" .IP "" 4 -This command sets (sets high) the gpios specified by \fBbits\fP in bank 1. -Bank 1 consists of gpios 0-31. +This command sets (sets high) the GPIO specified by \fBbits\fP in bank 1. +Bank 1 consists of GPIO 0-31. .br Upon success nothing is returned. On error a negative status code @@ -435,25 +435,25 @@ will be returned. .br .EX -$ pigs bs1 16 # set gpio 4 (1<<4) +$ pigs bs1 16 # set GPIO 4 (1<<4) .br .br -$ pigs bs1 1 # set gpio 1 (1<<0) +$ pigs bs1 1 # set GPIO 1 (1<<0) .br -42 .br -ERROR: no permission to update one or more gpios +ERROR: no permission to update one or more GPIO .br .EE .br -.IP "\fBBS2 bits\fP - Set specified gpios in bank 2" +.IP "\fBBS2 bits\fP - Set specified GPIO in bank 2" .IP "" 4 -This command sets (sets high) the gpios specified by \fBbits\fP in bank 2. -Bank 2 consists of gpios 32-53. +This command sets (sets high) the GPIO specified by \fBbits\fP in bank 2. +Bank 2 consists of GPIO 32-53. .br Upon success nothing is returned. On error a negative status code @@ -465,15 +465,15 @@ will be returned. .br .EX -$ pigs bs2 0x40 # set gpio 38 (enable high current mode A+/B+/Pi2) +$ pigs bs2 0x40 # set GPIO 38 (enable high current mode A+/B+/Pi2/Pi3) .br .br -$ pigs bs2 1 # set gpio 32 (first in bank 2) +$ pigs bs2 1 # set GPIO 32 (first in bank 2) .br -42 .br -ERROR: no permission to update one or more gpios +ERROR: no permission to update one or more GPIO .br .EE @@ -514,11 +514,11 @@ configuration settings to \fBv\fP. .br -.IP "\fBFG u stdy\fP - Set a glitch filter on a gpio" +.IP "\fBFG u stdy\fP - Set a glitch filter on a GPIO" .IP "" 4 .br -Level changes on the gpio are not reported unless the level +Level changes on the GPIO are not reported unless the level has been stable for at least \fBstdy\fP microseconds. The level is then reported. Level changes of less than \fBstdy\fP microseconds are ignored. @@ -529,13 +529,13 @@ after it was first detected. .br -.IP "\fBFN u stdy actv\fP - Set a noise filter on a gpio" +.IP "\fBFN u stdy actv\fP - Set a noise filter on a GPIO" .IP "" 4 .br -Level changes on the gpio are ignored until a level which has +Level changes on the GPIO are ignored until a level which has been stable for \fBstdy\fP microseconds is detected. Level -changes on the gpio are then reported for \fBactv\fP microseconds +changes on the GPIO are then reported for \fBactv\fP microseconds after which the process repeats. .br @@ -545,11 +545,11 @@ such reports. .br -.IP "\fBGDC u\fP - Get gpio PWM dutycycle" +.IP "\fBGDC u\fP - Get GPIO PWM dutycycle" .IP "" 4 .br -This command returns the PWM dutycycle in use on gpio \fBu\fP. +This command returns the PWM dutycycle in use on GPIO \fBu\fP. .br Upon success the dutycycle is returned. On error a negative @@ -557,14 +557,14 @@ status code will be returned. .br For normal PWM the dutycycle will be out of the defined range -for the gpio (see \fBPRG\fP). +for the GPIO (see \fBPRG\fP). .br -If a hardware clock is active on the gpio the reported +If a hardware clock is active on the GPIO the reported dutycycle will be 500000 (500k) out of 1000000 (1M). .br -If hardware PWM is active on the gpio the reported dutycycle +If hardware PWM is active on the GPIO the reported dutycycle will be out of a 1000000 (1M). .br @@ -585,18 +585,18 @@ pigs gdc 5 .br -92 .br -ERROR: gpio is not in use for PWM +ERROR: GPIO is not in use for PWM .br .EE .br -.IP "\fBGPW u\fP - Get gpio servo pulsewidth" +.IP "\fBGPW u\fP - Get GPIO servo pulsewidth" .IP "" 4 .br -This command returns the servo pulsewidth in use on gpio \fBu\fP. +This command returns the servo pulsewidth in use on GPIO \fBu\fP. .br Upon success the servo pulsewidth is returned. On error a negative @@ -620,7 +620,7 @@ $ pigs gpw 9 .br -93 .br -ERROR: gpio is not in use for servo pulses +ERROR: GPIO is not in use for servo pulses .br .EE @@ -650,7 +650,7 @@ $ pigs help .IP "\fBHC g cf\fP - Set hardware clock frequency" .IP "" 4 -This command sets the hardware clock associated with gpio \fBg\fP to +This command sets the hardware clock associated with GPIO \fBg\fP to frequency \fBcf\fP. Frequencies above 30MHz are unlikely to work. .br @@ -663,11 +663,11 @@ will be returned. .br .EX -$ pigs hc 4 5000 # start a 5 KHz clock on gpio 4 (clock 0) +$ pigs hc 4 5000 # start a 5 KHz clock on GPIO 4 (clock 0) .br .br -$ pigs hc 5 5000000 # start a 5 MHz clcok on gpio 5 (clock 1) +$ pigs hc 5 5000000 # start a 5 MHz clcok on GPIO 5 (clock 1) .br -99 .br @@ -677,20 +677,20 @@ ERROR: need password to use hardware clock 1 .EE .br -The same clock is available on multiple gpios. The latest -frequency setting will be used by all gpios which share a clock. +The same clock is available on multiple GPIO. The latest +frequency setting will be used by all GPIO which share a clock. .br -The gpio must be one of the following. +The GPIO must be one of the following. .br .EX 4 clock 0 All models -5 clock 1 A+/B+/Pi2/Zero and compute module only (reserved for system use) -6 clock 2 A+/B+/Pi2/Zero and compute module only -20 clock 0 A+/B+/Pi2/Zero and compute module only -21 clock 1 All models but Type 2 (reserved for system use) +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 B (Rev. 2) (reserved for system use) .EE @@ -708,13 +708,13 @@ The gpio must be one of the following. .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. +with the GPIO number. .br .IP "\fBHP g pf pdc\fP - Set hardware PWM frequency and dutycycle" .IP "" 4 -This command sets the hardware PWM associated with gpio \fBg\fP to +This command sets the hardware PWM associated with GPIO \fBg\fP to frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz are unlikely to work. @@ -752,20 +752,20 @@ ERROR: hardware PWM frequency not 1-125M .EE .br -The same PWM channel is available on multiple gpios. The latest -frequency and dutycycle setting will be used by all gpios which +The same PWM channel is available on multiple GPIO. The latest +frequency and dutycycle setting will be used by all GPIO which share a PWM channel. .br -The gpio must be one of the following. +The GPIO must be one of the following. .br .EX -12 PWM channel 0 A+/B+/Pi2/Zero and compute module only -13 PWM channel 1 A+/B+/Pi2/Zero and compute module only +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 A+/B+/Pi2/Zero and compute module only +19 PWM channel 1 All models but A and B .EE @@ -808,7 +808,7 @@ If the hardware revision can not be found or is not a valid hexadecimal number the command returns 0. .br -The revision number can be used to determine the assignment of gpios +The revision number can be used to determine the assignment of GPIO to pins (see \fBg\fP). .br @@ -1392,11 +1392,11 @@ End .br -.IP "\fBM/MODES g m\fP - Set gpio mode" +.IP "\fBM/MODES g m\fP - Set GPIO mode" .IP "" 4 .br -This command sets gpio \fBg\fP to mode \fBm\fP, typically input (read) +This command sets GPIO \fBg\fP to mode \fBm\fP, typically input (read) or output (write). .br @@ -1404,7 +1404,7 @@ Upon success nothing is returned. On error a negative status code will be returned. .br -Each gpio can be configured to be in one of 8 different modes. The modes +Each GPIO can be configured to be in one of 8 different modes. The modes are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5. .br @@ -1437,14 +1437,14 @@ $ pigs m 4 5 # ALT 5 .br -.IP "\fBMG/MODEG g\fP - Get gpio mode" +.IP "\fBMG/MODEG g\fP - Get GPIO mode" .IP "" 4 .br -This command returns the current mode of gpio \fBg\fP. +This command returns the current mode of GPIO \fBg\fP. .br -Upon success the value of the gpio mode is returned. +Upon success the value of the GPIO mode is returned. On error a negative status code will be returned. .br @@ -1547,7 +1547,7 @@ Upon success nothing is returned. On error a negative status code will be returned. .br -The notification gets state changes for each gpio specified by \fBbits\fP. +The notification gets state changes for each GPIO specified by \fBbits\fP. .br @@ -1555,9 +1555,9 @@ The notification gets state changes for each gpio specified by \fBbits\fP. .br .EX -$ pigs nb 0 -1 # Shorthand for gpios 0-31. +$ pigs nb 0 -1 # Shorthand for GPIO 0-31. .br -$ pigs nb 0 0xf0 # Get notifications for gpios 4-7. +$ pigs nb 0 0xf0 # Get notifications for GPIO 4-7. .br .br @@ -1611,7 +1611,7 @@ ERROR: unknown handle This command requests a free notification handle. .br -A notification is a method for being notified of gpio state changes via a pipe. +A notification is a method for being notified of GPIO state changes via a pipe. .br Upon success the command returns a handle greater than or equal to zero. @@ -1668,11 +1668,11 @@ $ pigs np 0 .br -.IP "\fBP/PWM u v\fP - Set gpio PWM value" +.IP "\fBP/PWM u v\fP - Set GPIO PWM value" .IP "" 4 .br -This command starts PWM on gpio \fBu\fP with dutycycle \fBv\fP. The dutycycle +This command starts PWM on GPIO \fBu\fP with dutycycle \fBv\fP. The dutycycle varies from 0 (off) to range (fully on). The range defaults to 255. .br @@ -1692,7 +1692,7 @@ The \fBPRS\fP command may be used to change the default range of 255. .br .EX -$ pigs p 4 64 # Start PWM on gpio 4 with 25% dutycycle +$ pigs p 4 64 # Start PWM on GPIO 4 with 25% dutycycle .br $ pigs p 4 128 # 50% .br @@ -1746,26 +1746,26 @@ Can't resolve tag 99 .br -.IP "\fBPFG u\fP - Get gpio PWM frequency" +.IP "\fBPFG u\fP - Get GPIO PWM frequency" .IP "" 4 .br -This command returns the PWM frequency in Hz used for gpio \fBu\fP. +This command returns the PWM frequency in Hz used for GPIO \fBu\fP. .br Upon success the PWM frequency is returned. On error a negative status code will be returned. .br -For normal PWM the frequency will be that defined for the gpio +For normal PWM the frequency will be that defined for the GPIO by \fBPFS\fP. .br -If a hardware clock is active on the gpio the reported frequency +If a hardware clock is active on the GPIO the reported frequency will be that set by \fBHC\fP. .br -If hardware PWM is active on the gpio the reported frequency +If hardware PWM is active on the GPIO the reported frequency will be that set by \fBHP\fP. .br @@ -1782,7 +1782,7 @@ $ pigs pfg 4 .br $ pigs pfg 34 .br -ERROR: gpio not 0-31 +ERROR: GPIO not 0-31 .br -2 .br @@ -1791,9 +1791,9 @@ ERROR: gpio not 0-31 .br -.IP "\fBPFS u v\fP - Set gpio PWM frequency" +.IP "\fBPFS u v\fP - Set GPIO PWM frequency" .IP "" 4 -This command sets the PWM frequency \fBv\fP to be used for gpio \fBu\fP. +This command sets the PWM frequency \fBv\fP to be used for GPIO \fBu\fP. .br The numerically closest frequency to \fBv\fP will be selected. @@ -1808,10 +1808,10 @@ pigpiod daemon was started. The sample rate is one of 1, 2, 4, 5, 8, or 10 microseconds (default 5). .br -Each gpio can be independently set to one of 18 different PWM frequencies. +Each GPIO can be independently set to one of 18 different PWM frequencies. .br -If PWM is currently active on the gpio it will be switched off and then +If PWM is currently active on the GPIO it will be switched off and then back on at the new frequency. .br @@ -1886,18 +1886,18 @@ $ pigs pigpv .br -.IP "\fBPRG u\fP - Get gpio PWM range" +.IP "\fBPRG u\fP - Get GPIO PWM range" .IP "" 4 .br -This command returns the dutycycle range for gpio \fBu\fP. +This command returns the dutycycle range for GPIO \fBu\fP. .br Upon success the range is returned. On error a negative status code will be returned. .br -If a hardware clock or hardware PWM is active on the gpio the reported +If a hardware clock or hardware PWM is active on the GPIO the reported range will be 1000000 (1M). .br @@ -2122,18 +2122,18 @@ ERROR: unknown script id .br -.IP "\fBPRRG u\fP - Get gpio PWM real range" +.IP "\fBPRRG u\fP - Get GPIO PWM real range" .IP "" 4 .br -This command returns the real underlying range used by gpio \fBu\fP. +This command returns the real underlying range used by GPIO \fBu\fP. .br -If a hardware clock is active on the gpio the reported +If a hardware clock is active on the GPIO the reported real range will be 1000000 (1M). .br -If hardware PWM is active on the gpio the reported real range +If hardware PWM is active on the GPIO the reported real range will be approximately 250M divided by the set PWM frequency. .br @@ -2177,20 +2177,20 @@ $ pigs prrg 17 .br -.IP "\fBPRS u v\fP - Set gpio PWM range" +.IP "\fBPRS u v\fP - Set GPIO PWM range" .IP "" 4 .br -This command sets the dutycycle range \fBv\fP to be used for gpio \fBu\fP. +This command sets the dutycycle range \fBv\fP to be used for GPIO \fBu\fP. Subsequent uses of command \fBP/PWM\fP will use a dutycycle between 0 (off) and \fBv\fP (fully on). .br -Upon success the real underlying range used by the gpio is returned. +Upon success the real underlying range used by the GPIO is returned. On error a negative status code will be returned. .br -If PWM is currently active on the gpio its dutycycle will be scaled to +If PWM is currently active on the GPIO its dutycycle will be scaled to reflect the new range. .br @@ -2229,11 +2229,11 @@ $ pigs prs 18 1000 .br -.IP "\fBPUD g p\fP - Set gpio pull up/down" +.IP "\fBPUD g p\fP - Set GPIO pull up/down" .IP "" 4 .br -This command sets the internal pull/up down for gpio \fBg\fP to mode \fBp\fP. +This command sets the internal pull/up down for GPIO \fBg\fP to mode \fBp\fP. .br Upon success nothing is returned. On error a negative status code @@ -2248,22 +2248,22 @@ The mode may be pull-down (D), pull-up (U), or off (O). .br .EX -$ pigs pud 4 d # Set pull-down on gpio 4. +$ pigs pud 4 d # Set pull-down on GPIO 4. .br -$ pigs pud 4 u # Set pull-up on gpio 4. +$ pigs pud 4 u # Set pull-up on GPIO 4. .br -$ pigs pud 4 o # No pull-up/down on gpio 4. +$ pigs pud 4 o # No pull-up/down on GPIO 4. .br .EE .br -.IP "\fBR/READ g\fP - Read gpio level" +.IP "\fBR/READ g\fP - Read GPIO level" .IP "" 4 .br -This reads the current level of gpio \fBg\fP. +This reads the current level of GPIO \fBg\fP. .br Upon success the current level is returned. On error a negative status code @@ -2275,13 +2275,13 @@ will be returned. .br .EX -$ pigs r 17 # Get level of gpio 17. +$ pigs r 17 # Get level of GPIO 17. .br 0 .br .br -$ pigs r 4 # Get level of gpio 4. +$ pigs r 4 # Get level of GPIO 4. .br 1 .br @@ -2290,11 +2290,11 @@ $ pigs r 4 # Get level of gpio 4. .br -.IP "\fBS/SERVO u v\fP - Set gpio servo pulsewidth" +.IP "\fBS/SERVO u v\fP - Set GPIO servo pulsewidth" .IP "" 4 .br -This command starts servo pulses of \fBv\fP microseconds on gpio \fBu\fP. +This command starts servo pulses of \fBv\fP microseconds on GPIO \fBu\fP. .br Upon success nothing is returned. On error a negative status code @@ -2326,10 +2326,10 @@ $ pigs SERVO 17 1500 .br This example causes an on pulse of 1500 microseconds duration to be -transmitted on gpio 17 at a rate of 50 times per second. +transmitted on GPIO 17 at a rate of 50 times per second. .br -This will command a servo connected to gpio 17 to rotate to its mid-point. +This will command a servo connected to GPIO 17 to rotate to its mid-point. .br @@ -2557,19 +2557,19 @@ $ pigs serwb 0 0xf0 .br -.IP "\fBSLR u num\fP - Read bit bang serial data from gpio" +.IP "\fBSLR u num\fP - Read bit bang serial data from GPIO" .IP "" 4 .br This command returns up to \fBnum\fP bytes of bit bang serial data -read from gpio \fBu\fP. +read from GPIO \fBu\fP. .br Upon success the count of returned bytes followed by the bytes themselves is returned. On error a negative status code will be returned. .br -The gpio \fBu\fP should have been initialised with the \fBSLRO\fP command. +The GPIO \fBu\fP should have been initialised with the \fBSLRO\fP command. .br The bytes returned for each character depend upon the number of @@ -2597,11 +2597,11 @@ $ pigs slr 15 20 .br -.IP "\fBSLRC u\fP - Close gpio for bit bang serial data" +.IP "\fBSLRC u\fP - Close GPIO for bit bang serial data" .IP "" 4 .br -This command closes gpio \fBu\fP for reading bit bang serial data. +This command closes GPIO \fBu\fP for reading bit bang serial data. .br Upon success nothing is returned. On error a negative status code @@ -2621,7 +2621,7 @@ $ pigs slrc 23 .br -38 .br -ERROR: no serial read in progress on gpio +ERROR: no serial read in progress on GPIO .br .EE @@ -2633,7 +2633,7 @@ ERROR: no serial read in progress on gpio .br This command sets the logic level for reading bit bang serial data -on gpio \fBu\fP. +on GPIO \fBu\fP. .br Upon success nothing is returned. On error a negative status code @@ -2648,22 +2648,22 @@ The invert parameter \fBv\fP is 1 for inverted signal, 0 for normal. .br .EX -$ pigs slri 17 1 # invert logic on gpio 17 +$ pigs slri 17 1 # invert logic on GPIO 17 .br .br -$ pigs slri 23 0 # use normal logic on gpio 23 +$ pigs slri 23 0 # use normal logic on GPIO 23 .br .EE .br -.IP "\fBSLRO u b db\fP - Open gpio for bit bang serial data" +.IP "\fBSLRO u b db\fP - Open GPIO for bit bang serial data" .IP "" 4 .br -This command opens gpio \fBu\fP for reading bit bang serial data +This command opens GPIO \fBu\fP for reading bit bang serial data at \fBb\fP baud and \fBdb\fP data bits. .br @@ -2694,7 +2694,7 @@ $ pigs slro 23 19200 8 .br -50 .br -ERROR: gpio already in use +ERROR: GPIO already in use .br .EE @@ -2749,9 +2749,10 @@ Speeds between 32kbps and 125Mbps are allowed. Speeds above 30Mbps are unlikely to work. .br -An auxiliary SPI device is available on the A+/B+/Pi2/Zero 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. +An auxiliary SPI device is available on all models but the +A and B and may be selected by setting the A bit in the +flags. The auxiliary device has 3 chip selects and a +selectable word size in bits. .br The flags consists of the least significant 22 bits. @@ -2792,11 +2793,10 @@ Mode POL PHA px is 0 if CEx is active low (default) and 1 for active high. .br -ux is 0 if the CEx gpio is reserved for SPI (default) and 1 otherwise. +ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise. .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/Zero. +A is 0 for the standard SPI device, 1 for the auxiliary SPI. .br W is 0 if the device is not 3-wire, 1 if the device is 3-wire. Standard @@ -2821,6 +2821,20 @@ device only. bbbbbb defines the word size in bits (0-32). The default (0) sets 8 bits per word. Auxiliary SPI device only. +.br +The \fBSPIR\fP, \fBSPIW\fP, and \fBSPIX\fP commands transfer data +packed into 1, 2, or 4 bytes according to the word size in bits. + +.br +For bits 1-8 there will be one byte per character. +.br +For bits 9-16 there will be two bytes per character. +.br +For bits 17-32 there will be four bytes per character. + +.br +E.g. 32 12-bit words will be transferred in 64 bytes. + .br The other bits in flags should be set to zero. @@ -2961,14 +2975,14 @@ $ pigs t mils 1000 t .br This command sends a trigger pulse of \fBpl\fP microseconds at level \fBL\fP -to gpio \fBu\fP. +to GPIO \fBu\fP. .br Upon success nothing is returned. On error a negative status code will be returned. .br -The gpio is set to not level at the end of the pulse. +The GPIO is set to not level at the end of the pulse. .br @@ -2991,11 +3005,11 @@ ERROR: trigger pulse > 50 microseconds .br -.IP "\fBW/WRITE g L\fP - Write gpio level" +.IP "\fBW/WRITE g L\fP - Write GPIO level" .IP "" 4 .br -This command sets gpio \fBg\fP to level \fBL\fP. The level may be 0 +This command sets GPIO \fBg\fP to level \fBL\fP. The level may be 0 (low, off, clear) or 1 (high, on, set). .br @@ -3025,11 +3039,11 @@ ERROR: level not 0-1 .br -.IP "\fBWDOG u v\fP - Set gpio watchdog" +.IP "\fBWDOG u v\fP - Set GPIO watchdog" .IP "" 4 .br -This command sets a watchdog of \fBv\fP milliseconds on gpio \fBu\fP. +This command sets a watchdog of \fBv\fP milliseconds on GPIO \fBu\fP. .br Upon success nothing is returned. On error a negative status code @@ -3039,16 +3053,16 @@ will be returned. The watchdog is nominally in milliseconds. .br -One watchdog may be registered per gpio. +One watchdog may be registered per GPIO. .br The watchdog may be cancelled by setting timeout to 0. .br -If no level change has been detected for the gpio for timeout milliseconds:- +If no level change has been detected for the GPIO for timeout milliseconds:- .br -any notification for the gpio has a report written to the fifo with +any notification for the GPIO has a report written to the fifo with the flags set to indicate a watchdog timeout. .br @@ -3072,7 +3086,7 @@ $ pigs wdog 23 9000 .br This example causes a report to be written to any notification pipes -listening on gpio 23 whenever gpio 23 changes state or approximately +listening on GPIO 23 whenever GPIO 23 changes state or approximately every 9000 ms. .br @@ -3081,7 +3095,7 @@ every 9000 ms. .IP "" 4 .br -This command adds 1 one or more triplets \fBtrips\fP of gpios on, gpios off, +This command adds 1 one or more triplets \fBtrips\fP of GPIO on, GPIO off, delay to the existing waveform (if any). .br @@ -3119,7 +3133,7 @@ $ pigs wvag 0 0 10000 0x10 0x80 1000 0x80 0x10 9000 .br This command adds a waveform representing serial data \fBbvs\fP to -gpio \fBu\fP at \fBb\fP baud to the existing waveform (if any). +GPIO \fBu\fP at \fBb\fP baud to the existing waveform (if any). The serial data starts \fBo\fP microseconds from the start of the waveform. @@ -3169,6 +3183,37 @@ $ pigs wvas 7 38400 8 2 0 0x41 0x42 .br +.IP "\fBWVTAT \fP - Returns the current transmitting waveform" +.IP "" 4 + +.br +This command returns the id of the waveform currently +being transmitted. + +.br +Returns the waveform id or one of the following special +values: + +.br +9998 - transmitted wave not found +.br +9999 - no wave being transmitted + +.br + +\fBExample\fP +.br + +.EX +$ pigs wvtat +.br +9999 +.br + +.EE + +.br + .IP "\fBWVBSY \fP - Check if waveform is being transmitted" .IP "" 4 @@ -3421,9 +3466,9 @@ A waveform comprises of one or more pulses. A pulse specifies .br -1) the gpios to be switched on at the start of the pulse. +1) the GPIO to be switched on at the start of the pulse. .br -2) the gpios to be switched off at the start of the pulse. +2) the GPIO to be switched off at the start of the pulse. .br 3) the delay in microseconds before the next pulse. @@ -3806,12 +3851,12 @@ The command expects 0 or 1. .br .IP "\fBbits\fP - a bit mask" 0 -A mask is used to select one or more gpios. A gpio is selected -if bit (1</dev/pigpio read -t 1 s /dev/pigpio read -t 1 s Date: Tue, 8 Mar 2016 14:28:15 +0000 Subject: [PATCH 02/21] V48 --- command.c | 6 +- pigpio.3 | 78 +++++++++++----- pigpio.c | 231 ++++++++++++++++++++++++++++++++++-------------- pigpio.h | 69 +++++++++------ pigpio.py | 6 +- pigpiod.1 | 75 +++++++++++++--- pigpiod.c | 8 +- setup.py | 2 +- x_pigpio.c | 16 ++-- x_pigpio.py | 31 +++++-- x_pigpiod_if.c | 16 ++-- x_pigpiod_if2.c | 16 ++-- x_pigs | 22 ++++- x_pipe | 24 ++++- 14 files changed, 426 insertions(+), 174 deletions(-) diff --git a/command.c b/command.c index 32619ba..eb7c47e 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 47+ +This version is for pigpio version 48+ */ #include @@ -394,7 +394,7 @@ static errInfo_t errInfo[]= {PI_BAD_CHANNEL , "DMA channel not 0-14"}, {PI_BAD_SOCKET_PORT , "socket port not 1024-30000"}, {PI_BAD_FIFO_COMMAND , "unknown fifo command"}, - {PI_BAD_SECO_CHANNEL , "DMA secondary channel not 0-6"}, + {PI_BAD_SECO_CHANNEL , "DMA secondary channel not 0-14"}, {PI_NOT_INITIALISED , "function called before gpioInitialise"}, {PI_INITIALISED , "function called after gpioInitialise"}, {PI_BAD_WAVE_MODE , "waveform mode not 0-1"}, @@ -455,7 +455,7 @@ static errInfo_t errInfo[]= {PI_UNKNOWN_COMMAND , "unknown command"}, {PI_SPI_XFER_FAILED , "spi xfer/read/write failed"}, {PI_BAD_POINTER , "bad (NULL) pointer"}, - {PI_NO_AUX_SPI , "need a B+ for auxiliary SPI"}, + {PI_NO_AUX_SPI , "no auxiliary SPI on Pi A or B"}, {PI_NOT_PWM_GPIO , "GPIO is not in use for PWM"}, {PI_NOT_SERVO_GPIO , "GPIO is not in use for servo pulses"}, {PI_NOT_HCLK_GPIO , "GPIO has no hardware clock"}, diff --git a/pigpio.3 b/pigpio.3 index cc7264d..7f06865 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -5260,7 +5260,7 @@ Configures pigpio to use the specified DMA channels. .EX primaryChannel: 0-14 .br -secondaryChannel: 0-6 +secondaryChannel: 0-14 .br .EE @@ -5269,7 +5269,27 @@ secondaryChannel: 0-6 .br The default setting is to use channel 14 for the primary channel and -channel 5 for the secondary channel. +channel 6 for the secondary channel. + +.br + +.br +The secondary channel is only used for the transmission of waves. + +.br + +.br +If possible use one of channels 0 to 6 for the secondary channel +(a full channel). + +.br + +.br +A full channel only requires one DMA control block regardless of the +length of a pulse delay. Channels 7 to 14 (lite channels) require +one DMA control block for each 16383 microseconds of delay. I.e. +a 10 second pulse delay requires one control block on a full channel +and 611 control blocks on a lite channel. .IP "\fBint gpioCfgPermissions(uint64_t updateMask)\fP" .IP "" 4 @@ -5289,22 +5309,26 @@ updateMask: bit (1< */ -/* pigpio version 47 */ +/* pigpio version 48 */ /* include ------------------------------------------------------- */ @@ -365,9 +365,11 @@ bit 0 READ_LAST_NOT_SET_ERROR #define DMA_BURST_LENGTH(x) ((x)<<12) #define DMA_SRC_IGNORE (1<<11) #define DMA_SRC_DREQ (1<<10) +#define DMA_SRC_WIDTH (1<< 9) #define DMA_SRC_INC (1<< 8) #define DMA_DEST_IGNORE (1<< 7) #define DMA_DEST_DREQ (1<< 6) +#define DMA_DEST_WIDTH (1<< 5) #define DMA_DEST_INC (1<< 4) #define DMA_WAIT_RESP (1<< 3) @@ -375,6 +377,9 @@ bit 0 READ_LAST_NOT_SET_ERROR #define DMA_DEBUG_FIFO_ERR (1<<1) #define DMA_DEBUG_RD_LST_NOT_SET_ERR (1<<0) +#define DMA_LITE_FIRST 7 +#define DMA_LITE_MAX 0xfffc + #define PWM_CTL 0 #define PWM_STA 1 #define PWM_DMAC 2 @@ -742,6 +747,8 @@ Assumes two counters per block. Each counter 4 * 16 (16^4=65536) #define PI_WF_MICROS 1 +#define BPD 4 + #define MAX_REPORT 120 #define MAX_SAMPLE 4000 @@ -1123,7 +1130,7 @@ typedef struct /* initialise once then preserve */ -static volatile uint32_t piModel = 1; +static volatile uint32_t piCores = 0; static volatile uint32_t pi_peri_phys = 0x20000000; static volatile uint32_t pi_dram_bus = 0x40000000; static volatile uint32_t pi_mem_flag = 0x0C; @@ -1655,7 +1662,7 @@ static void spinWhileStarting(void) { while (runState == PI_STARTING) { - if (piModel == 1) myGpioDelay(1000); + if (piCores == 1) myGpioDelay(1000); else flushMemory(); } } @@ -2603,6 +2610,17 @@ static void waveBitDelay bitDelay[i] = diff; } +static int waveDelayCBs(uint32_t delay) +{ + uint32_t cbs; + + if (!delay) return 0; + if (gpioCfg.DMAsecondaryChannel < DMA_LITE_FIRST) return 1; + cbs = BPD * delay / DMA_LITE_MAX; + if ((BPD * delay) % DMA_LITE_MAX) cbs++; + return cbs; +} + /* ----------------------------------------------------------------------- */ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) @@ -2628,7 +2646,8 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) if (waves[i].gpioOff) {numCB++; numBOOL++;} if (waves[i].flags & WAVE_FLAG_READ) {numCB++; numTOOL++;} if (waves[i].flags & WAVE_FLAG_TICK) {numCB++; numTOOL++;} - if (waves[i].usDelay) {numCB++; } + + numCB += waveDelayCBs(waves[i].usDelay); } *numCBs = numCB; @@ -2646,17 +2665,19 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) rawCbs_t *p=NULL; - unsigned i, half, repeatCB; + unsigned i, repeatCB; unsigned numWaves; + unsigned delayCBs, dcb; + + uint32_t delayLeft; + rawWave_t * waves; numWaves = wfc[wfcur]; waves = wf [wfcur]; - half = PI_WF_MICROS/2; - /* add delay cb at start of DMA */ p = rawWaveCBAdr(botCB++); @@ -2675,7 +2696,7 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) } p->src = (uint32_t) (&dmaOBus[0]->periphData); - p->length = 4 * 20 / PI_WF_MICROS; /* 20 micros delay */ + p->length = BPD * 20 / PI_WF_MICROS; /* 20 micros delay */ p->next = waveCbPOadr(botCB); repeatCB = botCB; @@ -2732,24 +2753,41 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) if (waves[i].usDelay) { - p = rawWaveCBAdr(botCB++); + delayLeft = waves[i].usDelay; - /* use the secondary clock */ + delayCBs = waveDelayCBs(delayLeft); - if (gpioCfg.clockPeriph != PI_CLOCK_PCM) + for (dcb=0; dcbinfo = NORMAL_DMA | TIMED_DMA(2); - p->dst = PCM_TIMER; - } - else - { - p->info = NORMAL_DMA | TIMED_DMA(5); - p->dst = PWM_TIMER; - } + p = rawWaveCBAdr(botCB++); - p->src = (uint32_t) (&dmaOBus[0]->periphData); - p->length = 4 * ((waves[i].usDelay+half)/PI_WF_MICROS); - p->next = waveCbPOadr(botCB); + /* use the secondary clock */ + + if (gpioCfg.clockPeriph != PI_CLOCK_PCM) + { + p->info = NORMAL_DMA | TIMED_DMA(2); + p->dst = PCM_TIMER; + } + else + { + p->info = NORMAL_DMA | TIMED_DMA(5); + p->dst = PWM_TIMER; + } + + p->src = (uint32_t) (&dmaOBus[0]->periphData); + + p->length = BPD * delayLeft / PI_WF_MICROS; + + if ((gpioCfg.DMAsecondaryChannel >= DMA_LITE_FIRST) && + (p->length > DMA_LITE_MAX)) + { + p->length = DMA_LITE_MAX; + } + + delayLeft -= (p->length / BPD); + + p->next = waveCbPOadr(botCB); + } } } @@ -2940,7 +2978,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1) out[outPos].usDelay = tDelay; - cbs++; /* one cb for delay */ + cbs += waveDelayCBs(tDelay); if (out[outPos].gpioOn) cbs++; /* one cb if gpio on */ @@ -4301,7 +4339,7 @@ int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags) if (PI_SPI_FLAGS_GET_AUX_SPI(spiFlags)) { if (gpioHardwareRevision() < 16) - SOFT_ERROR(PI_NO_AUX_SPI, "no auxiliary SPI, need a A+/B+"); + SOFT_ERROR(PI_NO_AUX_SPI, "no auxiliary SPI on Pi A or B"); i = PI_NUM_AUX_SPI_CHANNEL; } @@ -5567,7 +5605,6 @@ static void alertEmit( } else { - gpioCfg.internals |= PI_CFG_STATS; gpioStats.shortPipeWrite++; DBG(DBG_ALWAYS, "emitted %d, asked for %d", err/sizeof(gpioReport_t), max_emits); @@ -5608,7 +5645,6 @@ static void alertEmit( } else { - gpioCfg.internals |= PI_CFG_STATS; gpioStats.shortPipeWrite++; DBG(DBG_ALWAYS, "emitted %d, asked for %d", err/sizeof(gpioReport_t), emit); @@ -7505,7 +7541,7 @@ static void initReleaseResources(void) int initInitialise(void) { - int rev, i; + int rev, i, model; struct sockaddr_in server; char * portStr; unsigned port; @@ -7531,11 +7567,32 @@ int initInitialise(void) if (!gpioMaskSet) { - if (rev == 0) gpioMask = PI_DEFAULT_UPDATE_MASK_R0; + if (rev == 0) gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN; else if (rev == 17) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; - else if (rev < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_R1; - else if (rev < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_R2; - else gpioMask = PI_DEFAULT_UPDATE_MASK_R3; + else if (rev < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_B1; + else if (rev < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; + else + { + model = (rev >> 4) & 0xFF; + + /* model + 0=A 1=B + 2=A+ 3=B+ + 4=Pi2B + 5=Alpha + 6=Compute Module + 7=Unknown + 8=Pi3B + 9=Zero + */ + if (model < 2) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; + else if (model < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; + else if (model == 4) gpioMask = PI_DEFAULT_UPDATE_MASK_PI2B; + else if (model == 6) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; + else if (model == 8) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B; + else if (model == 9) gpioMask = PI_DEFAULT_UPDATE_MASK_ZERO; + else gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN; + } gpioMaskSet = 1; } @@ -9118,7 +9175,7 @@ int gpioWaveChain(char *buf, unsigned bufSize) int cb, chaincb; rawCbs_t *p; int i, wid, cmd, loop, counters; - unsigned cycles; + unsigned cycles, delayCBs, dcb, delayLeft; uint32_t repeat, next, *endPtr; int stk_pos[10], stk_lev=0; @@ -9159,7 +9216,7 @@ int gpioWaveChain(char *buf, unsigned bufSize) } p->src = (uint32_t) (&dmaOBus[0]->periphData); - p->length = 4 * 20 / PI_WF_MICROS; /* 20 micros delay */ + p->length = BPD * 20 / PI_WF_MICROS; /* 20 micros delay */ p->next = waveCbPOadr(chainGetCB(cb)); counters = 0; @@ -9275,29 +9332,45 @@ int gpioWaveChain(char *buf, unsigned bufSize) if (cycles) { - chaincb = chainGetCB(cb++); - - if (chaincb < 0) - SOFT_ERROR(PI_CHAIN_TOO_BIG, "chain is too long (%d)", cb); - - p = rawWaveCBAdr(chaincb); - - /* use the secondary clock */ - - if (gpioCfg.clockPeriph != PI_CLOCK_PCM) + delayLeft = cycles; + delayCBs = waveDelayCBs(delayLeft); + for (dcb=0; dcbinfo = NORMAL_DMA | TIMED_DMA(2); - p->dst = PCM_TIMER; - } - else - { - p->info = NORMAL_DMA | TIMED_DMA(5); - p->dst = PWM_TIMER; - } + chaincb = chainGetCB(cb++); - p->src = (uint32_t) (&dmaOBus[0]->periphData); - p->length = 4 * cycles / PI_WF_MICROS; - p->next = waveCbPOadr(chainGetCB(cb)); + if (chaincb < 0) + SOFT_ERROR( + PI_CHAIN_TOO_BIG, "chain is too long (%d)", cb); + + p = rawWaveCBAdr(chaincb); + + /* use the secondary clock */ + + if (gpioCfg.clockPeriph != PI_CLOCK_PCM) + { + p->info = NORMAL_DMA | TIMED_DMA(2); + p->dst = PCM_TIMER; + } + else + { + p->info = NORMAL_DMA | TIMED_DMA(5); + p->dst = PWM_TIMER; + } + + p->src = (uint32_t) (&dmaOBus[0]->periphData); + + p->length = BPD * delayLeft / PI_WF_MICROS; + + if ((gpioCfg.DMAsecondaryChannel >= DMA_LITE_FIRST) && + (p->length > DMA_LITE_MAX)) + { + p->length = DMA_LITE_MAX; + } + + delayLeft -= (p->length / BPD); + + p->next = waveCbPOadr(chainGetCB(cb)); + } } } else if (cmd == 3) /* repeat loop forever */ @@ -11506,6 +11579,28 @@ unsigned gpioVersion(void) /* ----------------------------------------------------------------------- */ +/* +2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 +5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + +W W S M M M B B B B P P P P T T T T T T T T R R R R + +W warranty void if either bit is set + +S 0=old (bits 0-22 are revision number) 1=new (following fields apply) + +M 0=256 1=512 2=1024 + +B 0=Sony 1=Egoman 2=Embest 3=Unknown 4=Embest + +P 0=2835, 1=2836, 2=2837 + +T 0=A 1=B 2=A+ 3=B+ 4=Pi2B 5=Alpha 6=Compute Module 7=Unknown 8=Pi3B 9=Zero + +R PCB board revision + +*/ + unsigned gpioHardwareRevision(void) { static unsigned rev = 0; @@ -11513,13 +11608,12 @@ unsigned gpioHardwareRevision(void) FILE * filp; char buf[512]; char term; - int chars=4; /* number of chars in revision string */ DBG(DBG_USER, ""); if (rev) return rev; - piModel = 0; + piCores = 0; filp = fopen ("/proc/cpuinfo", "r"); @@ -11527,22 +11621,27 @@ unsigned gpioHardwareRevision(void) { while (fgets(buf, sizeof(buf), filp) != NULL) { - if (piModel == 0) + if (piCores == 0) { if (!strncasecmp("model name", buf, 10)) { if (strstr (buf, "ARMv6") != NULL) { - piModel = 1; - chars = 4; + piCores = 1; pi_peri_phys = 0x20000000; pi_dram_bus = 0x40000000; pi_mem_flag = 0x0C; } else if (strstr (buf, "ARMv7") != NULL) { - piModel = 2; - chars = 6; + piCores = 4; + pi_peri_phys = 0x3F000000; + pi_dram_bus = 0xC0000000; + pi_mem_flag = 0x04; + } + else if (strstr (buf, "ARMv8") != NULL) + { + piCores = 4; pi_peri_phys = 0x3F000000; pi_dram_bus = 0xC0000000; pi_mem_flag = 0x04; @@ -11550,10 +11649,9 @@ unsigned gpioHardwareRevision(void) } } - if (!strncasecmp("revision", buf, 8)) + if (!strncasecmp("revision\t:", buf, 10)) { - if (sscanf(buf+strlen(buf)-(chars+1), - "%x%c", &rev, &term) == 2) + if (sscanf(buf+10, "%x%c", &rev, &term) == 2) { if (term != '\n') rev = 0; } @@ -11633,11 +11731,12 @@ int gpioCfgDMAchannels(unsigned primaryChannel, unsigned secondaryChannel) CHECK_NOT_INITED; - if (primaryChannel > PI_MAX_PRIMARY_CHANNEL) + if (primaryChannel > PI_MAX_DMA_CHANNEL) SOFT_ERROR(PI_BAD_PRIM_CHANNEL, "bad primary channel (%d)", primaryChannel); - if (secondaryChannel > PI_MAX_SECONDARY_CHANNEL) + if ((secondaryChannel > PI_MAX_DMA_CHANNEL) || + (secondaryChannel == primaryChannel)) SOFT_ERROR(PI_BAD_SECO_CHANNEL, "bad secondary channel (%d)", secondaryChannel); diff --git a/pigpio.h b/pigpio.h index b759488..7cbf9b7 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 47 +#define PIGPIO_VERSION 48 /*TEXT @@ -726,9 +726,6 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_MIN_DMA_CHANNEL 0 #define PI_MAX_DMA_CHANNEL 14 -#define PI_MAX_PRIMARY_CHANNEL 14 -#define PI_MAX_SECONDARY_CHANNEL 6 - /* port */ #define PI_MIN_SOCKET_PORT 1024 @@ -3705,11 +3702,22 @@ Configures pigpio to use the specified DMA channels. . . primaryChannel: 0-14 -secondaryChannel: 0-6 +secondaryChannel: 0-14 . . The default setting is to use channel 14 for the primary channel and -channel 5 for the secondary channel. +channel 6 for the secondary channel. + +The secondary channel is only used for the transmission of waves. + +If possible use one of channels 0 to 6 for the secondary channel +(a full channel). + +A full channel only requires one DMA control block regardless of the +length of a pulse delay. Channels 7 to 14 (lite channels) require +one DMA control block for each 16383 microseconds of delay. I.e. +a 10 second pulse delay requires one control block on a full channel +and 611 control blocks on a lite channel. D*/ @@ -3723,13 +3731,14 @@ GPIO specified by the mask. updateMask: bit (1< */ /* -This version is for pigpio version 43+ +This version is for pigpio version 48+ */ #include @@ -90,7 +90,7 @@ void usage() " -b value, gpio sample buffer in milliseconds, default 120\n" \ " -c value, library internal settings, default 0\n" \ " -d value, primary DMA channel, 0-14, default 14\n" \ - " -e value, secondary DMA channel, 0-6, default 5\n" \ + " -e value, secondary DMA channel, 0-14, default 6\n" \ " -f, disable fifo interface, default enabled\n" \ " -k, disable socket interface, default enabled\n" \ " -l, localhost socket only default all interfaces\n" \ @@ -149,14 +149,14 @@ static void initOpts(int argc, char *argv[]) case 'd': i = getNum(optarg, &err); - if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_PRIMARY_CHANNEL)) + if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_DMA_CHANNEL)) DMAprimaryChannel = i; else fatal("invalid -d option (%d)", i); break; case 'e': i = getNum(optarg, &err); - if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_SECONDARY_CHANNEL)) + if ((i >= PI_MIN_DMA_CHANNEL) && (i <= PI_MAX_DMA_CHANNEL)) DMAsecondaryChannel = i; else fatal("invalid -e option (%d)", i); break; diff --git a/setup.py b/setup.py index e7ae279..16a18fa 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.29', + version='1.30', author='joan', author_email='joan@abyz.co.uk', maintainer='joan', diff --git a/x_pigpio.c b/x_pigpio.c index 50212b0..5431301 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -1,5 +1,5 @@ /* -gcc -o x_pigpio x_pigpio.c -lpigpio -lrt -lpthread +gcc -Wall -pthread -o x_pigpio x_pigpio.c -lpigpio sudo ./x_pigpio *** WARNING ************************************************ @@ -45,7 +45,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc) void t0() { - printf("Version.\n"); + printf("\nTesting pigpio C I/F\n"); printf("pigpio version %d.\n", gpioVersion()); @@ -392,7 +392,8 @@ To the lascivious pleasing of a lute.\n\ wid = gpioWaveCreate(); e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT); - CHECK(5, 3, e, 9, 0, "wave tx repeat"); + if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); + else CHECK(5, 3, e, 19, 0, "wave tx repeat"); oc = t5_count; time_sleep(5); @@ -413,7 +414,8 @@ To the lascivious pleasing of a lute.\n\ wid = gpioWaveCreate(); e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT); - CHECK(5, 8, e, 6811, 0, "wave tx start"); + if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); + else CHECK(5, 8, e, 7116, 0, "wave tx start"); CHECK(5, 9, 0, 0, 0, "NOT APPLICABLE"); @@ -447,10 +449,12 @@ To the lascivious pleasing of a lute.\n\ CHECK(5, 18, c, 12000, 0, "wave get max pulses"); c = gpioWaveGetCbs(); - CHECK(5, 19, c, 6810, 0, "wave get cbs"); + if (e < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs"); + else CHECK(5, 19, c, 7115, 0, "wave get cbs"); c = gpioWaveGetHighCbs(); - CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + if (e < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + else CHECK(5, 20, c, 7115, 0, "wave get high cbs"); c = gpioWaveGetMaxCbs(); CHECK(5, 21, c, 25016, 0, "wave get max cbs"); diff --git a/x_pigpio.py b/x_pigpio.py index 9136f48..37459d3 100755 --- a/x_pigpio.py +++ b/x_pigpio.py @@ -45,14 +45,14 @@ def CHECK(t, st, got, expect, pc, desc): def t0(): - print("Version.") + print("\nTesting pigpio Python module {}".format(pigpio.VERSION)) + + print("Python {}".format(sys.version.replace("\n", " "))) print("pigpio version {}.".format(pi.get_pigpio_version())) print("Hardware revision {}.".format(pi.get_hardware_revision())) - print("Python version {}.".format(sys.version.replace("\n", " "))) - def t1(): print("Mode/PUD/read/write tests.") @@ -361,7 +361,10 @@ To the lascivious pleasing of a lute. wid = pi.wave_create() e = pi.wave_send_repeat(wid) - CHECK(5, 3, e, 9, 0, "wave send repeat") + if e < 14: + CHECK(5, 3, e, 9, 0, "wave send repeat") + else: + CHECK(5, 3, e, 19, 0, "wave send repeat") oc = t5_count time.sleep(5) @@ -380,7 +383,10 @@ To the lascivious pleasing of a lute. wid = pi.wave_create() e = pi.wave_send_once(wid) - CHECK(5, 8, e, 6811, 0, "wave send once") + if e < 6964: + CHECK(5, 8, e, 6811, 0, "wave send once") + else: + CHECK(5, 8, e, 7116, 0, "wave send once") oc = t5_count time.sleep(3) @@ -417,7 +423,10 @@ To the lascivious pleasing of a lute. CHECK(5, 18, c, 12000, 0, "wave get max pulses") c = pi.wave_get_cbs() - CHECK(5, 19, c, 6810, 0, "wave get cbs") + if c < 6963: + CHECK(5, 19, c, 6810, 0, "wave get cbs") + else: + CHECK(5, 19, c, 7115, 0, "wave get cbs") CHECK(5, 20, 0, 0, 0, "NOT APPLICABLE") @@ -434,7 +443,10 @@ To the lascivious pleasing of a lute. CHECK(5, 24, w1, 0, 0, "wave create") e = pi.wave_send_repeat(w1) - CHECK(5, 25, e, 9, 0, "wave send repeat") + if e < 14: + CHECK(5, 25, e, 9, 0, "wave send repeat") + else: + CHECK(5, 25, e, 19, 0, "wave send repeat") oc = t5_count time.sleep(5) @@ -451,7 +463,10 @@ To the lascivious pleasing of a lute. CHECK(5, 29, w2, 1, 0, "wave create") e = pi.wave_send_once(w2) - CHECK(5, 30, e, 6811, 0, "wave send once") + if e < 6964: + CHECK(5, 30, e, 6811, 0, "wave send once") + else: + CHECK(5, 30, e, 7116, 0, "wave send once") oc = t5_count time.sleep(3) diff --git a/x_pigpiod_if.c b/x_pigpiod_if.c index df2af4b..cc58d2f 100644 --- a/x_pigpiod_if.c +++ b/x_pigpiod_if.c @@ -1,5 +1,5 @@ /* -gcc -o x_pigpiod_if x_pigpiod_if.c -lpigpiod_if -lrt -lpthread +gcc -Wall -pthread -o x_pigpiod_if x_pigpiod_if.c -lpigpiod_if ./x_pigpiod_if *** WARNING ************************************************ @@ -42,7 +42,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc) void t0() { - printf("Version.\n"); + printf("\nTesting pigpiod C I/F 1\n"); printf("pigpio version %d.\n", get_pigpio_version()); @@ -360,7 +360,8 @@ To the lascivious pleasing of a lute.\n\ wid = wave_create(); e = wave_send_repeat(wid); - CHECK(5, 3, e, 9, 0, "wave tx repeat"); + if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); + else CHECK(5, 3, e, 19, 0, "wave tx repeat"); oc = t5_count; time_sleep(5.05); @@ -379,7 +380,8 @@ To the lascivious pleasing of a lute.\n\ wid = wave_create(); e = wave_send_once(wid); - CHECK(5, 8, e, 6811, 0, "wave tx start"); + if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); + else CHECK(5, 8, e, 7116, 0, "wave tx start"); oc = t5_count; time_sleep(3); @@ -419,10 +421,12 @@ To the lascivious pleasing of a lute.\n\ CHECK(5, 18, c, 12000, 0, "wave get max pulses"); c = wave_get_cbs(); - CHECK(5, 19, c, 6810, 0, "wave get cbs"); + if (c < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs"); + else CHECK(5, 19, c, 7115, 0, "wave get cbs"); c = wave_get_high_cbs(); - CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + if (c < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + else CHECK(5, 20, c, 7115, 0, "wave get high cbs"); c = wave_get_max_cbs(); CHECK(5, 21, c, 25016, 0, "wave get max cbs"); diff --git a/x_pigpiod_if2.c b/x_pigpiod_if2.c index 5e18469..8747c1a 100644 --- a/x_pigpiod_if2.c +++ b/x_pigpiod_if2.c @@ -1,5 +1,5 @@ /* -gcc -o x_pigpiod_if2 x_pigpiod_if2.c -lpigpiod_if2 -lpthread +gcc -Wall -pthread -o x_pigpiod_if2 x_pigpiod_if2.c -lpigpiod_if2 ./x_pigpiod_if2 *** WARNING ************************************************ @@ -42,7 +42,7 @@ void CHECK(int t, int st, int got, int expect, int pc, char *desc) void t0(int pi) { - printf("Version.\n"); + printf("\nTesting pigpiod C I/F 2\n"); printf("pigpio version %d.\n", get_pigpio_version(pi)); @@ -364,7 +364,8 @@ To the lascivious pleasing of a lute.\n\ wid = wave_create(pi); e = wave_send_repeat(pi, wid); - CHECK(5, 3, e, 9, 0, "wave tx repeat"); + if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); + else CHECK(5, 3, e, 19, 0, "wave tx repeat"); oc = t5_count; time_sleep(5.05); @@ -383,7 +384,8 @@ To the lascivious pleasing of a lute.\n\ wid = wave_create(pi); e = wave_send_once(pi, wid); - CHECK(5, 8, e, 6811, 0, "wave tx start"); + if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); + else CHECK(5, 8, e, 7116, 0, "wave tx start"); oc = t5_count; time_sleep(3); @@ -423,10 +425,12 @@ To the lascivious pleasing of a lute.\n\ CHECK(5, 18, c, 12000, 0, "wave get max pulses"); c = wave_get_cbs(pi); - CHECK(5, 19, c, 6810, 0, "wave get cbs"); + if (c < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs"); + else CHECK(5, 19, c, 7115, 0, "wave get cbs"); c = wave_get_high_cbs(pi); - CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + if (c < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs"); + else CHECK(5, 20, c, 7115, 0, "wave get high cbs"); c = wave_get_max_cbs(pi); CHECK(5, 21, c, 25016, 0, "wave get max cbs"); diff --git a/x_pigs b/x_pigs index adaa1eb..1435493 100755 --- a/x_pigs +++ b/x_pigs @@ -19,7 +19,8 @@ GPIO=25 # of tests indicate a problem. # -echo "Testing pigs I/F" +echo +echo "Testing pigpio pigs" s=$(pigs pigpv) echo "pigpio version $s" @@ -250,8 +251,13 @@ s=$(pigs wvag 16 0 5000000 0 16 5000000) if [[ $s = 310 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi w=$(pigs wvcre) if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($s)"; fi + s=$(pigs wvtx $w) -if [[ $s = 621 ]]; then echo "WVTX ok"; else echo "WVTX fail ($s)"; fi +if [[ ($s = 621) || ($s = 1137) ]] +then echo "WVTX ok" +else echo "WVTX fail ($s)" +fi + s=$(pigs wvbsy) if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi sleep 1 @@ -262,7 +268,11 @@ if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi s=$(pigs wvbsy) if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi s=$(pigs wvtxr $w) -if [[ $s = 621 ]]; then echo "WVTXR ok"; else echo "WVTXR fail ($s)"; fi +if [[ ($s = 621) || ($s = 1137) ]] +then echo "WVTXR ok" +else echo "WVTXR fail ($s)" +fi + s=$(pigs wvbsy) if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi s=$(pigs wvhlt) @@ -271,7 +281,11 @@ s=$(pigs wvbsy) if [[ $s = 0 ]]; then echo "WVBSY-e ok"; else echo "WVBSY-e fail ($s)"; fi s=$(pigs wvsc 0) -if [[ $s = 620 ]]; then echo "WVSC-a ok"; else echo "WVSC-a fail ($s)"; fi +if [[ ($s = 620) || ($s = 933) ]] +then echo "WVSC-a ok" +else echo "WVSC-a fail ($s)" +fi + s=$(pigs wvsc 1) if [[ $s -ge 620 ]]; then echo "WVSC-b ok"; else echo "WVSC-b fail ($s)"; fi s=$(pigs wvsc 2) diff --git a/x_pipe b/x_pipe index 4b39afc..b74f523 100755 --- a/x_pipe +++ b/x_pipe @@ -18,7 +18,8 @@ GPIO=25 # of tests indicate a problem. # -echo "Testing pipe I/F" +echo +echo "Testing pigpio pipe I/F" echo "pigpv" >/dev/pigpio read -t 1 s /dev/pigpio read -t 1 s /dev/pigpio read -t 1 s /dev/pigpio read -t 1 s /dev/pigpio read -t 1 s /dev/pigpio read -t 1 s /dev/pigpio read -t 1 s Date: Tue, 8 Mar 2016 23:05:19 +0100 Subject: [PATCH 03/21] Add CMake find script for pigpio. --- cmake/Modules/Findpigpio.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cmake/Modules/Findpigpio.cmake diff --git a/cmake/Modules/Findpigpio.cmake b/cmake/Modules/Findpigpio.cmake new file mode 100644 index 0000000..f832ffa --- /dev/null +++ b/cmake/Modules/Findpigpio.cmake @@ -0,0 +1,25 @@ +################################################################################ +### Find the pigpio shared libraries. +################################################################################ + +# Find the path to the pigpio includes. +find_path(pigpio_INCLUDE_DIR + NAMES pigpio.h pigpiod_if.h pigpiod_if2.h + HINTS /usr/local/include) + +# Find the path to the pigpio libraries. +find_library(pigpio_LIBRARY + NAMES libpigpio.so libpigpiod_if.so libpigpiod_if2.so + HINTS /usr/local/lib) + +# Set the pigpio variables to plural form to make them accessible for +# the paramount cmake modules. +set(pigpio_INCLUDE_DIRS ${pigpio_INCLUDE_DIR}) +set(pigpio_INCLUDES ${pigpio_INCLUDE_DIR}) +set(pigpio_LIBRARIES ${pigpio_LIBRARY}) + +# Handle REQUIRED, QUIET, and version arguments +# and set the _FOUND variable. +find_package_handle_standard_args(pigpio + DEFAULT_MSG + pigpio_INCLUDE_DIR pigpio_LIBRARY) From 2442078b3583365d062f2ff1a12eea9d3c248653 Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Wed, 9 Mar 2016 00:54:03 +0100 Subject: [PATCH 04/21] Changed title. --- cmake/Modules/Findpigpio.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/Findpigpio.cmake b/cmake/Modules/Findpigpio.cmake index f832ffa..717699f 100644 --- a/cmake/Modules/Findpigpio.cmake +++ b/cmake/Modules/Findpigpio.cmake @@ -1,5 +1,5 @@ ################################################################################ -### Find the pigpio shared libraries. +### Find the pigpio includes and shared libraries. ################################################################################ # Find the path to the pigpio includes. From 39856dc7fe590b50b348ad26b3ab8fafee5a9abd Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Thu, 10 Mar 2016 21:44:33 +0100 Subject: [PATCH 05/21] Move CMake find script to util folder. --- {cmake/Modules => util}/Findpigpio.cmake | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {cmake/Modules => util}/Findpigpio.cmake (100%) diff --git a/cmake/Modules/Findpigpio.cmake b/util/Findpigpio.cmake similarity index 100% rename from cmake/Modules/Findpigpio.cmake rename to util/Findpigpio.cmake From 56d28cc80d20b0ca064e54e13ccb81c9d438626f Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Thu, 10 Mar 2016 21:45:20 +0100 Subject: [PATCH 06/21] Add script that allows to start pigpiod as a service. --- util/pigpiod | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 util/pigpiod diff --git a/util/pigpiod b/util/pigpiod new file mode 100755 index 0000000..59ba142 --- /dev/null +++ b/util/pigpiod @@ -0,0 +1,31 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: pigpiod +# Required-Start: +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: pigpio daemon +# Description: pigpio daemon required to control GPIO pins via pigpio $ +### END INIT INFO + +# Actions +case "$1" in + start) + pigpiod + ;; + stop) + pkill pigpiod + ;; + restart) + pkill pigpiod + pigpiod + ;; + *) + echo "Usage: $0 start" >&2 + exit 3 + ;; +esac + +exit 0 + From c28367d2c83d4462ed11ed810c910f25dc7c797e Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Thu, 10 Mar 2016 21:55:01 +0100 Subject: [PATCH 07/21] Add readme --- util/readme.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 util/readme.md diff --git a/util/readme.md b/util/readme.md new file mode 100644 index 0000000..6cd58dd --- /dev/null +++ b/util/readme.md @@ -0,0 +1,31 @@ +This folder provides utility files for the pigpio library. + +### pigpiod + +`pigpiod` is a script that allows to run pigpiod as a Linux service with root privileges. +The advantage of running pigpiod as a service is that pigpiod can be automatically launched on system startup. +To automatically start pigpiod as a service, do the following: + ++ Copy `pigpiod` from this directory to `/etc/init.d/`. + ++ Make it executable: + ``` + sudo chmod +x /etc/init.d/pigpiod + ``` + ++ Tell update-rc.d to automatically start the pigpiod service on system startup: + ``` + sudo update-rc.d skeleton defaults + ``` + ++ Now, you can start, stop, and restart pigpiod using + ``` + sudo service pigpiod start + sudo service pigpiod stop + sudo service pigpiod restart + ``` + + +### Findpigpio.cmake + +`Findpigpio.cmake` is a script used by CMake to find out where the pigpio header and library files are located. From cac54fd86b16aebb1b1f084576350602f0262b89 Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Thu, 10 Mar 2016 21:56:34 +0100 Subject: [PATCH 08/21] Fix copy-and-paste mistake. --- util/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/readme.md b/util/readme.md index 6cd58dd..27c4c3d 100644 --- a/util/readme.md +++ b/util/readme.md @@ -15,7 +15,7 @@ To automatically start pigpiod as a service, do the following: + Tell update-rc.d to automatically start the pigpiod service on system startup: ``` - sudo update-rc.d skeleton defaults + sudo update-rc.d pigpiod defaults ``` + Now, you can start, stop, and restart pigpiod using From e3243d34c1cb25f4cf67b268ce3935d710816486 Mon Sep 17 00:00:00 2001 From: Alexander Schaefer Date: Sat, 12 Mar 2016 21:35:51 +0100 Subject: [PATCH 09/21] Define individual CMake variables for the different pigpio libraries. The user has to specify which library he wants to link against, as all libraries define functions like gpio_write(). --- util/Findpigpio.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/Findpigpio.cmake b/util/Findpigpio.cmake index 717699f..6c94ee0 100644 --- a/util/Findpigpio.cmake +++ b/util/Findpigpio.cmake @@ -1,5 +1,5 @@ ################################################################################ -### Find the pigpio includes and shared libraries. +### Find the pigpio shared libraries. ################################################################################ # Find the path to the pigpio includes. @@ -7,19 +7,24 @@ find_path(pigpio_INCLUDE_DIR NAMES pigpio.h pigpiod_if.h pigpiod_if2.h HINTS /usr/local/include) -# Find the path to the pigpio libraries. +# Find the pigpio libraries. find_library(pigpio_LIBRARY - NAMES libpigpio.so libpigpiod_if.so libpigpiod_if2.so + NAMES libpigpio.so + HINTS /usr/local/lib) +find_library(pigpiod_if_LIBRARY + NAMES libpigpiod_if.so + HINTS /usr/local/lib) +find_library(pigpiod_if2_LIBRARY + NAMES libpigpiod_if2.so HINTS /usr/local/lib) # Set the pigpio variables to plural form to make them accessible for # the paramount cmake modules. set(pigpio_INCLUDE_DIRS ${pigpio_INCLUDE_DIR}) set(pigpio_INCLUDES ${pigpio_INCLUDE_DIR}) -set(pigpio_LIBRARIES ${pigpio_LIBRARY}) # Handle REQUIRED, QUIET, and version arguments # and set the _FOUND variable. find_package_handle_standard_args(pigpio DEFAULT_MSG - pigpio_INCLUDE_DIR pigpio_LIBRARY) + pigpio_INCLUDE_DIR pigpio_LIBRARY pigpiod_if_LIBRARY pigpiod_if2_LIBRARY) From 3f426e699d8483a6cc0288c7a4927645bca51ccc Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 16 Mar 2016 20:08:09 +0000 Subject: [PATCH 10/21] V49 --- pigpio.c | 3 ++- pigpio.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pigpio.c b/pigpio.c index 4676868..169bc41 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 48 */ +/* pigpio version 49 */ /* include ------------------------------------------------------- */ @@ -7568,6 +7568,7 @@ int initInitialise(void) if (!gpioMaskSet) { if (rev == 0) gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN; + else if (rev == 16) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; else if (rev == 17) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; else if (rev < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_B1; else if (rev < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; diff --git a/pigpio.h b/pigpio.h index 7cbf9b7..e5b0e8b 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 48 +#define PIGPIO_VERSION 49 /*TEXT From 399eb5a3a1906603ecafe84ffc62565a7231554d Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 17 Mar 2016 18:01:59 +0000 Subject: [PATCH 11/21] V50 --- pigpio.c | 10 +++++----- pigpio.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pigpio.c b/pigpio.c index 169bc41..ed38416 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 49 */ +/* pigpio version 50 */ /* include ------------------------------------------------------- */ @@ -7568,10 +7568,10 @@ int initInitialise(void) if (!gpioMaskSet) { if (rev == 0) gpioMask = PI_DEFAULT_UPDATE_MASK_UNKNOWN; - else if (rev == 16) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; - else if (rev == 17) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; else if (rev < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_B1; else if (rev < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; + else if (rev == 17) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; + else if (rev < 20) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; else { model = (rev >> 4) & 0xFF; @@ -7586,8 +7586,8 @@ int initInitialise(void) 8=Pi3B 9=Zero */ - if (model < 2) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; - else if (model < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; + if (model < 2) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; + else if (model < 4) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; else if (model == 4) gpioMask = PI_DEFAULT_UPDATE_MASK_PI2B; else if (model == 6) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; else if (model == 8) gpioMask = PI_DEFAULT_UPDATE_MASK_PI3B; diff --git a/pigpio.h b/pigpio.h index e5b0e8b..b06be96 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 49 +#define PIGPIO_VERSION 50 /*TEXT From dc1d244cd806d7b3bf484d06bef386fb28bd2268 Mon Sep 17 00:00:00 2001 From: Stefano Miccoli Date: Sat, 9 Apr 2016 21:03:17 +0200 Subject: [PATCH 12/21] small bug fix for python example --- EXAMPLES/Python/GPIO_STATUS/gpio_status.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/EXAMPLES/Python/GPIO_STATUS/gpio_status.py b/EXAMPLES/Python/GPIO_STATUS/gpio_status.py index 82c022c..9b3bf78 100755 --- a/EXAMPLES/Python/GPIO_STATUS/gpio_status.py +++ b/EXAMPLES/Python/GPIO_STATUS/gpio_status.py @@ -3,6 +3,7 @@ import time import curses import atexit +import sys import pigpio @@ -17,6 +18,8 @@ def cleanup(): pi.stop() pi = pigpio.pi() +if not pi.connected: + sys.exit(1) stdscr = curses.initscr() curses.noecho() @@ -43,7 +46,7 @@ while True: tally = cb[g].tally() mode = pi.get_mode(g) - col = (g / 11) * 25 + col = (g // 11) * 25 row = (g % 11) + 2 stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD) From 2d0bb867f4ad659972fc5f089016dff6ca62d70d Mon Sep 17 00:00:00 2001 From: Stephen Lyons Date: Wed, 6 Apr 2016 13:58:16 +0100 Subject: [PATCH 13/21] BugFix: a typo In the "glossary" part of the command.c file a mention of "GPIO Bank 2" should refer to "GPIO Bank 1". Signed-off-by: Stephen Lyons --- command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command.c b/command.c index eb7c47e..644fc7f 100644 --- a/command.c +++ b/command.c @@ -243,7 +243,7 @@ BI2CO sda scl baud | Open bit bang I2C\n\ BI2CZ sda ... I2C bit bang multiple transactions\n\ BR1 Read bank 1 GPIO\n\ BR2 Read bank 2 GPIO\n\ -BS1 bits Set GPIO in bank 2\n\ +BS1 bits Set GPIO in bank 1\n\ BS2 bits Set GPIO in bank 2\n\ \n\ CF1 ... Custom function 1\n\ From 51cd543d97d9adddbc4ac97ce447e498a7817f4c Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 25 Apr 2016 09:58:51 +0100 Subject: [PATCH 14/21] V51 --- pigpio.3 | 95 ++++++++++++++++++++++++++++++++++++++++++++++++-------- pigpio.c | 5 +-- pigpio.h | 51 +++++++++++++++++++++++------- 3 files changed, 125 insertions(+), 26 deletions(-) diff --git a/pigpio.3 b/pigpio.3 index 7f06865..516125e 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -157,14 +157,35 @@ 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. +\fBgpioInitialise\fP must be called before all other library functions +with the following exceptions: .br .br -If the library is initialised the \fBgpioCfg*\fP functions will -return PI_INITIALISED. + +.EX +\fBgpioCfg*\fP +.br +\fBgpioVersion\fP +.br +\fBgpioHardwareRevision\fP +.br + +.EE + +.br + +.br +If the library is not initialised all but the \fBgpioCfg*\fP, +\fBgpioVersion\fP, and \fBgpioHardwareRevision\fP functions will +return error PI_NOT_INITIALISED. + +.br + +.br +If the library is initialised the \fBgpioCfg*\fP functions will return +error PI_INITIALISED. .br @@ -177,18 +198,28 @@ 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. +gpioInitialise must be called before using the other library functions +with the following exceptions: + +.br + +.br + +.EX +\fBgpioCfg*\fP +.br +\fBgpioVersion\fP +.br +\fBgpioHardwareRevision\fP +.br + +.EE .br @@ -5109,6 +5140,11 @@ Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5172,6 +5208,11 @@ peripheral. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5236,6 +5277,11 @@ Configures pigpio to use the specified DMA channel. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5255,6 +5301,11 @@ Configures pigpio to use the specified DMA channels. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5298,6 +5349,11 @@ GPIO specified by the mask. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5341,6 +5397,11 @@ Configures pigpio to use the specified socket port. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5360,6 +5421,11 @@ Configures pigpio support of the fifo and socket interfaces. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -5396,6 +5462,11 @@ Selects the method of DMA memory allocation. .br +.br +This function is only effective if called before \fBgpioInitialise\fP. + +.br + .br .EX @@ -6306,7 +6377,7 @@ typedef void (*gpioAlertFuncEx_t) .br .br -One of +These functions are only effective if called before \fBgpioInitialise\fP. .br @@ -6323,8 +6394,6 @@ One of .br \fBgpioCfgInterfaces\fP .br -\fBgpioCfgInternals\fP -.br \fBgpioCfgSocketPort\fP .br \fBgpioCfgMemAlloc\fP diff --git a/pigpio.c b/pigpio.c index ed38416..13d7264 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 50 */ +/* pigpio version 51 */ /* include ------------------------------------------------------- */ @@ -7572,6 +7572,8 @@ int initInitialise(void) else if (rev < 16) gpioMask = PI_DEFAULT_UPDATE_MASK_A_B2; else if (rev == 17) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; else if (rev < 20) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; + else if (rev == 20) gpioMask = PI_DEFAULT_UPDATE_MASK_COMPUTE; + else if (rev == 21) gpioMask = PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS; else { model = (rev >> 4) & 0xFF; @@ -11873,4 +11875,3 @@ int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal) #include "custom.cext" - diff --git a/pigpio.h b/pigpio.h index b06be96..cfadacd 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 50 +#define PIGPIO_VERSION 51 /*TEXT @@ -93,11 +93,21 @@ For examples of usage see the C programs within the pigpio archive file. All the functions which return an int return < 0 on error. -If the library is not initialised all but the [*gpioCfg**], [*gpioVersion*], -and [*gpioHardwareRevision*] functions will return PI_NOT_INITIALISED. +[*gpioInitialise*] must be called before all other library functions +with the following exceptions: -If the library is initialised the [*gpioCfg**] functions will -return PI_INITIALISED. +. . +[*gpioCfg**] +[*gpioVersion*] +[*gpioHardwareRevision*] +. . + +If the library is not initialised all but the [*gpioCfg**], +[*gpioVersion*], and [*gpioHardwareRevision*] functions will +return error PI_NOT_INITIALISED. + +If the library is initialised the [*gpioCfg**] functions will return +error PI_INITIALISED. TEXT*/ @@ -294,7 +304,6 @@ gpioCfgSocketPort Configure socket port gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgInternals Configure miscellaneous internals (DEPRECATED) - gpioCfgGetInternals Get internal configuration settings gpioCfgSetInternals Set internal configuration settings @@ -770,11 +779,16 @@ int gpioInitialise(void); /*D Initialises the library. -Call before using the other library functions. - Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. -The only exception is the optional [*gpioCfg**] functions, see later. +gpioInitialise must be called before using the other library functions +with the following exceptions: + +. . +[*gpioCfg**] +[*gpioVersion*] +[*gpioHardwareRevision*] +. . ... if (gpioInitialise() < 0) @@ -3618,6 +3632,8 @@ int gpioCfgBufferSize(unsigned cfgMillis); /*D Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. +This function is only effective if called before [*gpioInitialise*]. + . . cfgMillis: 100-10000 . . @@ -3653,6 +3669,8 @@ int gpioCfgClock( Configures pigpio to use a particular sample rate timed by a specified peripheral. +This function is only effective if called before [*gpioInitialise*]. + . . cfgMicros: 1, 2, 4, 5, 8, 10 cfgPeripheral: 0 (PWM), 1 (PCM) @@ -3686,6 +3704,8 @@ int gpioCfgDMAchannel(unsigned DMAchannel); /* DEPRECATED */ /*D Configures pigpio to use the specified DMA channel. +This function is only effective if called before [*gpioInitialise*]. + . . DMAchannel: 0-14 . . @@ -3700,6 +3720,8 @@ int gpioCfgDMAchannels( /*D Configures pigpio to use the specified DMA channels. +This function is only effective if called before [*gpioInitialise*]. + . . primaryChannel: 0-14 secondaryChannel: 0-14 @@ -3727,6 +3749,8 @@ int gpioCfgPermissions(uint64_t updateMask); Configures pigpio to only allow updates (writes or mode changes) for the GPIO specified by the mask. +This function is only effective if called before [*gpioInitialise*]. + . . updateMask: bit (1< Date: Wed, 27 Apr 2016 11:21:18 +0200 Subject: [PATCH 15/21] pep8:E261 At least two spaces before inline comment --- EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py | 40 ++++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py index 8a10f17..e383498 100755 --- a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py +++ b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py @@ -54,7 +54,7 @@ class sensor: self.power = power if power is not None: - pi.write(power, 1) # Switch sensor on. + pi.write(power, 1) # Switch sensor on. time.sleep(2) self.powered = True @@ -63,10 +63,10 @@ class sensor: atexit.register(self.cancel) - self.bad_CS = 0 # Bad checksum count. - self.bad_SM = 0 # Short message count. - self.bad_MM = 0 # Missing message count. - self.bad_SR = 0 # Sensor reset count. + self.bad_CS = 0 # Bad checksum count. + self.bad_SM = 0 # Short message count. + self.bad_MM = 0 # Missing message count. + self.bad_SR = 0 # Sensor reset count. # Power cycle if timeout > MAX_TIMEOUTS. self.no_response = 0 @@ -82,7 +82,7 @@ class sensor: pi.set_pull_up_down(gpio, pigpio.PUD_OFF) - pi.set_watchdog(gpio, 0) # Kill any watchdogs. + pi.set_watchdog(gpio, 0) # Kill any watchdogs. self.cb = pi.callback(gpio, pigpio.EITHER_EDGE, self._cb) @@ -99,15 +99,15 @@ class sensor: if diff >= 50: val = 1 - if diff >= 200: # Bad bit? - self.CS = 256 # Force bad checksum. + if diff >= 200: # Bad bit? + self.CS = 256 # Force bad checksum. else: val = 0 - if self.bit >= 40: # Message complete. + if self.bit >= 40: # Message complete. self.bit = 40 - elif self.bit >= 32: # In checksum byte. + elif self.bit >= 32: # In checksum byte. self.CS = (self.CS<<1) + val if self.bit == 39: @@ -120,11 +120,11 @@ class sensor: total = self.hH + self.hL + self.tH + self.tL - if (total & 255) == self.CS: # Is checksum ok? + if (total & 255) == self.CS: # Is checksum ok? self.rhum = ((self.hH<<8) + self.hL) * 0.1 - if self.tH & 128: # Negative temperature. + if self.tH & 128: # Negative temperature. mult = -0.1 self.tH = self.tH & 127 else: @@ -141,16 +141,16 @@ class sensor: self.bad_CS += 1 - elif self.bit >=24: # in temp low byte + elif self.bit >=24: # in temp low byte self.tL = (self.tL<<1) + val - elif self.bit >=16: # in temp high byte + elif self.bit >=16: # in temp high byte self.tH = (self.tH<<1) + val - elif self.bit >= 8: # in humidity low byte + elif self.bit >= 8: # in humidity low byte self.hL = (self.hL<<1) + val - elif self.bit >= 0: # in humidity high byte + elif self.bit >= 0: # in humidity high byte self.hH = (self.hH<<1) + val else: # header bits @@ -168,14 +168,14 @@ class sensor: self.tL = 0 self.CS = 0 - else: # level == pigpio.TIMEOUT: + else: # level == pigpio.TIMEOUT: self.pi.set_watchdog(self.gpio, 0) if self.bit < 8: # Too few data bits received. self.bad_MM += 1 # Bump missing message count. self.no_response += 1 if self.no_response > self.MAX_NO_RESPONSE: self.no_response = 0 - self.bad_SR += 1 # Bump sensor reset count. + self.bad_SR += 1 # Bump sensor reset count. if self.power is not None: self.powered = False self.pi.write(self.power, 0) @@ -228,7 +228,7 @@ class sensor: self.pi.write(self.LED, 1) self.pi.write(self.gpio, pigpio.LOW) - time.sleep(0.017) # 17 ms + time.sleep(0.017) # 17 ms self.pi.set_mode(self.gpio, pigpio.INPUT) self.pi.set_watchdog(self.gpio, 200) @@ -275,7 +275,7 @@ if __name__ == "__main__": next_reading += INTERVAL - time.sleep(next_reading-time.time()) # Overall INTERVAL second polling. + time.sleep(next_reading-time.time()) # Overall INTERVAL second polling. s.cancel() From dc3ce64eb48c83f5c14b81dc5d879638102db5f1 Mon Sep 17 00:00:00 2001 From: "Maurice (mausy5043) Hendrix" Date: Wed, 27 Apr 2016 11:27:05 +0200 Subject: [PATCH 16/21] pep8:E225 Whitespace around operators --- EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py index e383498..519585e 100755 --- a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py +++ b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py @@ -108,7 +108,7 @@ class sensor: self.bit = 40 elif self.bit >= 32: # In checksum byte. - self.CS = (self.CS<<1) + val + self.CS = (self.CS << 1) + val if self.bit == 39: @@ -122,7 +122,7 @@ class sensor: if (total & 255) == self.CS: # Is checksum ok? - self.rhum = ((self.hH<<8) + self.hL) * 0.1 + self.rhum = ((self.hH << 8) + self.hL) * 0.1 if self.tH & 128: # Negative temperature. mult = -0.1 @@ -130,7 +130,7 @@ class sensor: else: mult = 0.1 - self.temp = ((self.tH<<8) + self.tL) * mult + self.temp = ((self.tH << 8) + self.tL) * mult self.tov = time.time() @@ -141,17 +141,17 @@ class sensor: self.bad_CS += 1 - elif self.bit >=24: # in temp low byte - self.tL = (self.tL<<1) + val + elif self.bit >= 24: # in temp low byte + self.tL = (self.tL << 1) + val - elif self.bit >=16: # in temp high byte - self.tH = (self.tH<<1) + val + elif self.bit >= 16: # in temp high byte + self.tH = (self.tH << 1) + val elif self.bit >= 8: # in humidity low byte - self.hL = (self.hL<<1) + val + self.hL = (self.hL << 1) + val elif self.bit >= 0: # in humidity high byte - self.hH = (self.hH<<1) + val + self.hH = (self.hH << 1) + val else: # header bits pass @@ -250,7 +250,7 @@ if __name__ == "__main__": import DHT22 # Intervals of about 2 seconds or less will eventually hang the DHT22. - INTERVAL=3 + INTERVAL = 3 pi = pigpio.pi() From 07cbb98dca094d0718c28ab9a0aa7ec51f0a2a3f Mon Sep 17 00:00:00 2001 From: "Maurice (mausy5043) Hendrix" Date: Wed, 27 Apr 2016 11:29:01 +0200 Subject: [PATCH 17/21] pep8:E711 comparison to None should be `if cond is not None:` --- EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py index 519585e..c9ce87e 100755 --- a/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py +++ b/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py @@ -237,7 +237,7 @@ class sensor: self.pi.set_watchdog(self.gpio, 0) - if self.cb != None: + if self.cb is not None: self.cb.cancel() self.cb = None From 09adafce0ce22e383a6c3d33f3e81f39201e29a6 Mon Sep 17 00:00:00 2001 From: joan Date: Sun, 1 May 2016 11:28:56 +0100 Subject: [PATCH 18/21] V52 --- pigpio.c | 18 ++++++++++++++---- pigpio.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pigpio.c b/pigpio.c index 13d7264..8445b86 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 51 */ +/* pigpio version 52 */ /* include ------------------------------------------------------- */ @@ -1144,6 +1144,7 @@ static struct timespec libStarted; static uint32_t reportedLevel = 0; static int waveClockInited = 0; +static int PWMClockInited = 0; static volatile gpioStats_t gpioStats; @@ -7551,6 +7552,7 @@ int initInitialise(void) DBG(DBG_STARTUP, ""); waveClockInited = 0; + PWMClockInited = 0; clock_gettime(CLOCK_REALTIME, &libStarted); @@ -8958,6 +8960,7 @@ int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode) stopHardwarePWM(); initClock(0); /* initialise secondary clock */ waveClockInited = 1; + PWMClockInited = 0; } p = rawWaveCBAdr(waveInfo[wave_id].topCB); @@ -9194,6 +9197,7 @@ int gpioWaveChain(char *buf, unsigned bufSize) stopHardwarePWM(); initClock(0); /* initialise secondary clock */ waveClockInited = 1; + PWMClockInited = 0; } dmaOut[DMA_CS] = DMA_CHANNEL_RESET; @@ -11413,11 +11417,16 @@ int gpioHardwarePWM( old_PWM_CTL = pwmReg[PWM_CTL] & (PWM_CTL_PWEN1 | PWM_CTL_MSEN1 | PWM_CTL_PWEN2 | PWM_CTL_MSEN2); - pwmReg[PWM_CTL] = 0; + if (!PWMClockInited) + { + pwmReg[PWM_CTL] = 0; - myGpioDelay(10); + myGpioDelay(10); - initHWClk(CLK_PWMCTL, CLK_PWMDIV, CLK_CTL_SRC_PLLD, 2, 0, 0); + initHWClk(CLK_PWMCTL, CLK_PWMDIV, CLK_CTL_SRC_PLLD, 2, 0, 0); + + PWMClockInited = 1; + } if (pwm == 0) { @@ -11657,6 +11666,7 @@ unsigned gpioHardwareRevision(void) if (sscanf(buf+10, "%x%c", &rev, &term) == 2) { if (term != '\n') rev = 0; + else rev &= 0xFFFFFF; /* mask out warranty bit */ } } } diff --git a/pigpio.h b/pigpio.h index cfadacd..b855eaa 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 51 +#define PIGPIO_VERSION 52 /*TEXT From 3b56709a0efcc3077b9603ce95d340494dd7c1d1 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 31 May 2016 18:44:12 +0100 Subject: [PATCH 19/21] V53 --- command.c | 4 +- command.h | 2 +- pigpio.3 | 56 ++++++---- pigpio.c | 11 +- pigpio.h | 51 +++++---- pigpio.py | 98 +++++++++++++---- pigpiod_if.3 | 80 +++++++++----- pigpiod_if.c | 2 +- pigpiod_if.h | 68 +++++++----- pigpiod_if2.3 | 286 +++++++++++++++++++++++++++----------------------- pigpiod_if2.c | 2 +- pigpiod_if2.h | 274 ++++++++++++++++++++++++----------------------- pigs.1 | 17 +-- setup.py | 2 +- 14 files changed, 546 insertions(+), 407 deletions(-) diff --git a/command.c b/command.c index 644fc7f..ef15b5d 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 48+ +This version is for pigpio version 53+ */ #include @@ -426,7 +426,7 @@ static errInfo_t errInfo[]= {PI_SOCK_READ_FAILED , "socket read failed"}, {PI_SOCK_WRIT_FAILED , "socket write failed"}, {PI_TOO_MANY_PARAM , "too many script parameters (> 10)"}, - {PI_NOT_HALTED , "script already running or failed"}, + {PI_SCRIPT_NOT_READY , "script initialising"}, {PI_BAD_TAG , "script has unresolved tag"}, {PI_BAD_MICS_DELAY , "bad MICS delay (too large)"}, {PI_BAD_MILS_DELAY , "bad MILS delay (too large)"}, diff --git a/command.h b/command.h index b448f36..3c36bd1 100644 --- a/command.h +++ b/command.h @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 23+ +This version is for pigpio version 53+ */ #ifndef COMMAND_H diff --git a/pigpio.3 b/pigpio.3 index 516125e..8bb1011 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -112,7 +112,8 @@ This use was inspired by Richard Hirst's servoblaster kernel module. .br .br -https://github.com/richardghirst/PiBits/tree/master/ServoBlaster +See \fBhttps://github.com/richardghirst/PiBits/tree/master/ServoBlaster\fP + .br .br @@ -450,7 +451,7 @@ Sets the GPIO level, on or off. .EX gpio: 0-53 .br -level: 0,1 +level: 0-1 .br .EE @@ -749,8 +750,8 @@ 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). +If PWM is currently active on the GPIO it will be +switched off and then back on at the new frequency. .br @@ -761,8 +762,8 @@ frequencies. .br .br -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). .br @@ -1016,7 +1017,7 @@ user_gpio: 0-31 .br .br -Returns , 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) +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" @@ -1138,7 +1139,7 @@ void aFunction(int gpio, int level, uint32_t tick) .br .br -gpioSetAlertFunc(4F, aFunction); +gpioSetAlertFunc(4, aFunction); .br .EE @@ -1773,9 +1774,9 @@ data_bits: 1-32 .br stop_bits: 2-8 .br - offset: 0- + offset: >=0 .br - numBytes: 1- + numBytes: >=1 .br str: an array of chars (which may contain nulls) .br @@ -2371,7 +2372,7 @@ normal logic. Default is PI_BB_SER_NORMAL. .EX user_gpio: 0-31 .br -invert: 0-1 + invert: 0-1 .br .EE @@ -2402,7 +2403,7 @@ user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP .br buf: an array to receive the read bytes .br - bufSize: 0- + bufSize: >=0 .br .EE @@ -2456,9 +2457,9 @@ This returns a handle for the device at the address on the I2C bus. .br .EX - i2cBus: 0-1 + i2cBus: >=0 .br - i2cAddr: 0x00-0x7F + i2cAddr: 0-0x7F .br i2cFlags: 0 .br @@ -2472,6 +2473,12 @@ No flags are currently defined. This parameter should be set to zero. .br +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.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. @@ -4386,6 +4393,11 @@ This function stores a null terminated script for later execution. .br +.br +See \fBhttp://abyz.co.uk/rpi/pigpio/pigs.html#Scripts\fP for details. + +.br + .br .EX @@ -6266,7 +6278,7 @@ A function. .br -.IP "\fBfrequency\fP: 0-" 0 +.IP "\fBfrequency\fP: >=0" 0 .br @@ -6580,7 +6592,7 @@ One of .br -.IP "\fBhandle\fP: 0-" 0 +.IP "\fBhandle\fP: >=0" 0 .br @@ -6602,19 +6614,19 @@ A number referencing an object opened by one of .br -.IP "\fBi2cAddr\fP" 0 +.IP "\fBi2cAddr\fP: 0-0x7F" 0 The address of a device on the I2C bus. .br .br -.IP "\fBi2cBus\fP: 0-1" 0 +.IP "\fBi2cBus\fP: >=0" 0 .br .br -An I2C bus, 0 or 1. +An I2C bus number. .br @@ -8097,7 +8109,9 @@ A 16-bit word value. .br #define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10) .br -#define PI_NOT_HALTED -62 // script already running or failed +#define PI_NOT_HALTED -62 // DEPRECATED +.br +#define PI_SCRIPT_NOT_READY -62 // script initialising .br #define PI_BAD_TAG -63 // script has unresolved tag .br @@ -8286,7 +8300,7 @@ A 16-bit word value. .br .br -#define PI_DEFAULT_CFG_INTERNALS 0 +#define PI_DEFAULT_CFG_INTERNALS 0 .br .br diff --git a/pigpio.c b/pigpio.c index 8445b86..2ca1962 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 52 */ +/* pigpio version 53 */ /* include ------------------------------------------------------- */ @@ -3645,9 +3645,6 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags) CHECK_INITED; - if (i2cBus >= PI_NUM_I2C_BUS) - SOFT_ERROR(PI_BAD_I2C_BUS, "bad I2C bus (%d)", i2cBus); - if (i2cAddr > PI_MAX_I2C_ADDR) SOFT_ERROR(PI_BAD_I2C_ADDR, "bad I2C address (%d)", i2cAddr); @@ -3683,7 +3680,7 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags) if ((fd = open(dev, O_RDWR)) < 0) { i2cInfo[slot].state = PI_I2C_CLOSED; - return PI_I2C_OPEN_FAILED; + return PI_BAD_I2C_BUS; } } @@ -11026,7 +11023,7 @@ int gpioRunScript(unsigned script_id, unsigned numParam, uint32_t *param) { pthread_mutex_lock(&gpioScript[script_id].pthMutex); - if (gpioScript[script_id].run_state == PI_SCRIPT_HALTED) + if (gpioScript[script_id].run_state != PI_SCRIPT_INITING) { if ((numParam > 0) && (param != 0)) { @@ -11040,7 +11037,7 @@ int gpioRunScript(unsigned script_id, unsigned numParam, uint32_t *param) } else { - status = PI_NOT_HALTED; + status = PI_SCRIPT_NOT_READY; } pthread_mutex_unlock(&gpioScript[script_id].pthMutex); diff --git a/pigpio.h b/pigpio.h index b855eaa..9f12087 100644 --- a/pigpio.h +++ b/pigpio.h @@ -31,7 +31,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 52 +#define PIGPIO_VERSION 53 /*TEXT @@ -73,7 +73,7 @@ The PWM and servo pulses are timed using the DMA and PWM peripherals. This use was inspired by Richard Hirst's servoblaster kernel module. -[https://github.com/richardghirst/PiBits/tree/master/ServoBlaster] +See [[https://github.com/richardghirst/PiBits/tree/master/ServoBlaster]] *Usage* @@ -623,7 +623,6 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_SPI_SLOTS 16 #define PI_SER_SLOTS 8 -#define PI_NUM_I2C_BUS 2 #define PI_MAX_I2C_ADDR 0x7F #define PI_NUM_AUX_SPI_CHANNEL 3 @@ -913,7 +912,7 @@ Sets the GPIO level, on or off. . . gpio: 0-53 -level: 0,1 +level: 0-1 . . Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL. @@ -1073,14 +1072,14 @@ frequency: >=0 Returns the numerically closest frequency if OK, otherwise PI_BAD_USER_GPIO. -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). +If PWM is currently active on the GPIO it will be +switched off and then back on at the new frequency. Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the GPIO it will be -switched off and then back on at the new frequency. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The frequencies for each sample rate are: @@ -1210,7 +1209,7 @@ Returns the servo pulsewidth setting for the GPIO. user_gpio: 0-31 . . -Returns , 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) +Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO. D*/ @@ -1271,7 +1270,7 @@ void aFunction(int gpio, int level, uint32_t tick) // call aFunction whenever GPIO 4 changes state -gpioSetAlertFunc(4F, aFunction); +gpioSetAlertFunc(4, aFunction); ... D*/ @@ -1645,8 +1644,8 @@ user_gpio: 0-31 baud: 50-1000000 data_bits: 1-32 stop_bits: 2-8 - offset: 0- - numBytes: 1- + offset: >=0 + numBytes: >=1 str: an array of chars (which may contain nulls) . . @@ -2017,7 +2016,7 @@ normal logic. Default is PI_BB_SER_NORMAL. . . user_gpio: 0-31 -invert: 0-1 + invert: 0-1 . . Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, @@ -2037,7 +2036,7 @@ bit bang serial cyclic buffer to the buffer starting at buf. . . user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*] buf: an array to receive the read bytes - bufSize: 0- + bufSize: >=0 . . Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO @@ -2070,13 +2069,16 @@ int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags); This returns a handle for the device at the address on the I2C bus. . . - i2cBus: 0-1 - i2cAddr: 0x00-0x7F + i2cBus: >=0 + i2cAddr: 0-0x7F i2cFlags: 0 . . No flags are currently defined. This parameter should be set to zero. +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + 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. @@ -3189,6 +3191,8 @@ int gpioStoreScript(char *script); /*D This function stores a null terminated script for later execution. +See [[http://abyz.co.uk/rpi/pigpio/pigs.html#Scripts]] for details. + . . script: the text of the script . . @@ -4260,7 +4264,7 @@ f:: A function. -frequency::0- +frequency::>=0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as @@ -4397,7 +4401,7 @@ One of [*gpioWaveAddGeneric*] [*gpioWaveAddSerial*] -handle::0- +handle::>=0 A number referencing an object opened by one of @@ -4406,12 +4410,12 @@ A number referencing an object opened by one of [*serOpen*] [*spiOpen*] -i2cAddr:: +i2cAddr:: 0-0x7F The address of a device on the I2C bus. -i2cBus::0-1 +i2cBus::>=0 -An I2C bus, 0 or 1. +An I2C bus number. i2cFlags::0 @@ -5119,7 +5123,8 @@ after this command is issued. #define PI_SOCK_READ_FAILED -59 // socket read failed #define PI_SOCK_WRIT_FAILED -60 // socket write failed #define PI_TOO_MANY_PARAM -61 // too many script parameters (> 10) -#define PI_NOT_HALTED -62 // script already running or failed +#define PI_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) @@ -5214,7 +5219,7 @@ after this command is issued. #define PI_DEFAULT_UPDATE_MASK_COMPUTE 0x00FFFFFFFFFFFFLL #define PI_DEFAULT_MEM_ALLOC_MODE PI_MEM_ALLOC_AUTO -#define PI_DEFAULT_CFG_INTERNALS 0 +#define PI_DEFAULT_CFG_INTERNALS 0 /*DEF_E*/ diff --git a/pigpio.py b/pigpio.py index da596eb..55bdc75 100644 --- a/pigpio.py +++ b/pigpio.py @@ -176,7 +176,7 @@ wave_add_generic Adds a series of pulses to the waveform wave_add_serial Adds serial data to the waveform wave_create Creates a waveform from added data -wave_delete Deletes one or more waveforms +wave_delete Deletes a waveform wave_send_once Transmits a waveform once wave_send_repeat Transmits a waveform repeatedly @@ -270,7 +270,7 @@ import threading import os import atexit -VERSION = "1.30" +VERSION = "1.31" exceptions = True @@ -524,7 +524,7 @@ PI_NO_MEMORY =-58 PI_SOCK_READ_FAILED =-59 PI_SOCK_WRIT_FAILED =-60 PI_TOO_MANY_PARAM =-61 -PI_NOT_HALTED =-62 +PI_SCRIPT_NOT_READY =-62 PI_BAD_TAG =-63 PI_BAD_MICS_DELAY =-64 PI_BAD_MILS_DELAY =-65 @@ -652,7 +652,7 @@ _errors=[ [PI_SOCK_READ_FAILED , "socket read failed"], [PI_SOCK_WRIT_FAILED , "socket write failed"], [PI_TOO_MANY_PARAM , "too many script parameters (> 10)"], - [PI_NOT_HALTED , "script already running or failed"], + [PI_SCRIPT_NOT_READY , "script initialising"], [PI_BAD_TAG , "script has unresolved tag"], [PI_BAD_MICS_DELAY , "bad MICS delay (too large)"], [PI_BAD_MILS_DELAY , "bad MILS delay (too large)"], @@ -1247,7 +1247,43 @@ class pi(): user_gpio:= 0-31. frequency:= >=0 Hz - Returns the frequency actually set. + Returns the numerically closest frequency if OK, otherwise + PI_BAD_USER_GPIO or PI_NOT_PERMITTED. + + If PWM is currently active on the GPIO it will be switched + off and then back on at the new frequency. + + Each GPIO can be independently set to one of 18 different + PWM frequencies. + + The selectable frequencies depend upon the sample rate which + may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The + sample rate is set when the pigpio daemon is started. + + The frequencies for each sample rate are: + + . . + 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 + . . ... pi.set_PWM_frequency(4,0) @@ -2256,8 +2292,8 @@ class pi(): """ Returns a handle (>=0) for the device at the I2C bus address. - i2c_bus:= 0-1. - i2c_address:= 0x00-0x7F. + i2c_bus:= >=0. + i2c_address:= 0-0x7F. i2c_flags:= 0, no flags are currently defined. Normally you would only use the [*i2c_**] functions if @@ -2265,6 +2301,10 @@ class pi(): you will always run on the local Pi use the standard SMBus module instead. + Physically buses 0 and 1 are available on the Pi. Higher + numbered buses will be available if a kernel supported bus + multiplexor is being used. + For the SMBus commands the low level transactions are shown at the end of the function description. The following abbreviations are used. @@ -3399,6 +3439,9 @@ class pi(): """ Store a script for later execution. + See [[http://abyz.co.uk/rpi/pigpio/pigs.html#Scripts]] for + details. + script:= the script text as a series of bytes. Returns a >=0 script id if OK. @@ -3595,7 +3638,7 @@ class pi(): Invert serial logic. user_gpio:= 0-31 (opened in a prior call to [*bb_serial_read_open*]) - invert:= 0-1 (1 invert, 0 normal) + invert:= 0-1 (1 invert, 0 normal) ... status = pi.bb_serial_invert(17, 1) @@ -3726,7 +3769,7 @@ class pi(): user_gpio:= 0-31. edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. - wait_timeout:= 0.0- (default 60.0). + wait_timeout:= >=0.0 (default 60.0). The function returns when the edge is detected or after the number of seconds specified by timeout has expired. @@ -3772,10 +3815,18 @@ class pi(): This connects to the pigpio daemon and reserves resources to be used for sending commands and receiving notifications. + An instance attribute [*connected*] may be used to check the + success of the connection. If the connection is established + successfully [*connected*] will be True, otherwise False. + ... pi = pigio.pi() # use defaults pi = pigpio.pi('mypi') # specify host, default port pi = pigpio.pi('mypi', 7777) # specify host and port + + pi = pigpio.pi() # exit script if no connection + if not pi.connected: + exit() ... """ self.connected = True @@ -3892,13 +3943,16 @@ def xref(): clkfreq: 4689-250M The hardware clock frequency. + connected: + True if a connection was established, False otherwise. + count: The number of bytes of data to be transferred. data: Data to be transmitted, a series of bytes. - delay: 1- + delay: >=1 The length of a pulse in microseconds. dutycycle: 0-range_ @@ -3958,7 +4012,7 @@ def xref(): PI_SOCK_READ_FAILED = -59 PI_SOCK_WRIT_FAILED = -60 PI_TOO_MANY_PARAM = -61 - PI_NOT_HALTED = -62 + PI_SCRIPT_NOT_READY = -62 PI_BAD_TAG = -63 PI_BAD_MICS_DELAY = -64 PI_BAD_MILS_DELAY = -65 @@ -4029,11 +4083,11 @@ def xref(): gpio: 0-53 A Broadcom numbered GPIO. All the user GPIO are in the range 0-31. - There are 54 General Purpose Input Outputs (GPIO) named gpio0 - through gpio53. + There are 54 General Purpose Input Outputs (GPIO) named GPIO0 + through GPIO53. - They are split into two banks. Bank 1 consists of gpio0 - through gpio31. Bank 2 consists of gpio32 through gpio53. + They are split into two banks. Bank 1 consists of GPIO0 + through GPIO31. Bank 2 consists of GPIO32 through GPIO53. All the GPIO which are safe for the user to read and write are in bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards @@ -4067,7 +4121,7 @@ def xref(): This mask selects the GPIO to be switched on at the start of a pulse. - handle: 0- + handle: >=0 A number referencing an object opened by one of [*i2c_open*], [*notify_open*], [*serial_open*], [*spi_open*]. @@ -4077,13 +4131,13 @@ def xref(): i2c_*: One of the i2c_ functions. - i2c_address: + i2c_address: 0-0x7F The address of a device on the I2C bus. - i2c_bus: 0-1 + i2c_bus: >=0 An I2C bus number. - i2c_flags: 32 bit + i2c_flags: 0 No I2C flags are currently defined. invert: 0-1 @@ -4119,7 +4173,7 @@ def xref(): WAVE_MODE_ONE_SHOT_SYNC = 2 WAVE_MODE_REPEAT_SYNC = 3 - offset: 0- + offset: >=0 The offset wave data starts from the beginning of the waveform being currently defined. @@ -4170,7 +4224,7 @@ def xref(): script: The text of a script to store on the pigpio daemon. - script_id: 0- + script_id: >=0 A number referencing a script created by [*store_script*]. SDA: @@ -4226,7 +4280,7 @@ def xref(): wave_add_*: One of [*wave_add_new*] , [*wave_add_generic*], [*wave_add_serial*]. - wave_id: 0- + wave_id: >=0 A number referencing a wave created by [*wave_create*]. wave_send_*: diff --git a/pigpiod_if.3 b/pigpiod_if.3 index 3846c75..a5f0782 100644 --- a/pigpiod_if.3 +++ b/pigpiod_if.3 @@ -615,7 +615,7 @@ Set the frequency (in Hz) of the PWM to be used on the GPIO. .EX user_gpio: 0-31. .br -frequency: 0- (Hz). +frequency: >=0 (Hz). .br .EE @@ -629,9 +629,8 @@ PI_BAD_USER_GPIO or PI_NOT_PERMITTED. .br .br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the C pigpio library is started. +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. .br @@ -642,47 +641,59 @@ 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. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +.br + +.br +The frequencies for each sample rate are: .br .br .EX -1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600, -.br - 1250, 1000, 800, 500, 400, 250, 200, 100, 50 + Hertz .br .br -2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800, + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 .br - 625, 500, 400, 250, 200, 125, 100, 50 , 25 + 1250 1000 800 500 400 250 200 100 50 .br .br -4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400, + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 .br - 313, 250, 200, 125, 100, 63, 50, 25, 13 + 625 500 400 250 200 125 100 50 25 .br .br -5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320, + 4: 10000 5000 2500 2000 1250 1000 625 500 400 .br - 250, 200, 160, 100 , 80, 50, 40, 20, 10 + 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 -8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200, + 8: 5000 2500 1250 1000 625 500 313 250 200 .br - 156, 125, 100, 63, 50, 31, 25, 13, 6 + 156 125 100 63 50 31 25 13 6 .br .br -10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160, + 10: 4000 2000 1000 800 500 400 250 200 160 .br - 125, 100, 80, 50, 40, 25, 20, 10, 5 + 125 100 80 50 40 25 20 10 5 .br .EE @@ -1519,9 +1530,9 @@ data_bits: number of data bits (1-32) .br stop_bits: number of stop half bits (2-8) .br - offset: 0- + offset: >=0 .br - numBytes: 1- + numBytes: >=1 .br str: an array of chars. .br @@ -2049,6 +2060,11 @@ This function stores a script for later execution. .br +.br +See \fBhttp://abyz.co.uk/rpi/pigpio/pigs.html#Scripts\fP for details. + +.br + .br .EX @@ -2232,7 +2248,7 @@ user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. .br buf: an array to receive the read bytes. .br - bufSize: 0- + bufSize: >=0 .br .EE @@ -2307,9 +2323,9 @@ This returns a handle for the device at address i2c_addr on bus i2c_bus. .br .EX - i2c_bus: 0-1. + i2c_bus: >=0. .br - i2c_addr: 0x00-0x7F. + i2c_addr: 0-0x7F. .br i2c_flags: 0. .br @@ -2323,6 +2339,12 @@ No flags are currently defined. This parameter should be set to zero. .br +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.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. @@ -4076,7 +4098,7 @@ A function. .br -.IP "\fBfrequency\fP: 0-" 0 +.IP "\fBfrequency\fP: >=0" 0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as 40KHz. The GPIO will be on for a proportion of the time as defined @@ -4186,7 +4208,7 @@ typedef void *(gpioThreadFunc_t) (void *); .br -.IP "\fBhandle\fP: 0-" 0 +.IP "\fBhandle\fP: >=0" 0 A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, \fBserial_open\fP, and \fBspi_open\fP. @@ -4194,15 +4216,15 @@ A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\f .br -.IP "\fBi2c_addr\fP" 0 +.IP "\fBi2c_addr\fP: 0-0x7F" 0 The address of a device on the I2C bus. .br .br -.IP "\fBi2c_bus\fP: 0-1" 0 -An I2C bus, 0 or 1. +.IP "\fBi2c_bus\fP: >=0" 0 +An I2C bus number. .br diff --git a/pigpiod_if.c b/pigpiod_if.c index 4078e12..c2c5c5d 100644 --- a/pigpiod_if.c +++ b/pigpiod_if.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF_VERSION 21 */ +/* PIGPIOD_IF_VERSION 23 */ #include #include diff --git a/pigpiod_if.h b/pigpiod_if.h index 6d4f7f3..0b80183 100644 --- a/pigpiod_if.h +++ b/pigpiod_if.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF_VERSION 22 +#define PIGPIOD_IF_VERSION 23 /*TEXT @@ -565,40 +565,45 @@ Set the frequency (in Hz) of the PWM to be used on the GPIO. . . user_gpio: 0-31. -frequency: 0- (Hz). +frequency: >=0 (Hz). . . Returns the numerically closest frequency if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the C pigpio library is started. +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +The frequencies for each sample rate are: . . -1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600, - 1250, 1000, 800, 500, 400, 250, 200, 100, 50 + Hertz -2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800, - 625, 500, 400, 250, 200, 125, 100, 50 , 25 + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 + 1250 1000 800 500 400 250 200 100 50 -4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400, - 313, 250, 200, 125, 100, 63, 50, 25, 13 + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 + 625 500 400 250 200 125 100 50 25 -5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320, - 250, 200, 160, 100 , 80, 50, 40, 20, 10 + 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 -8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200, - 156, 125, 100, 63, 50, 31, 25, 13, 6 + 8: 5000 2500 1250 1000 625 500 313 250 200 + 156 125 100 63 50 31 25 13 6 -10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160, - 125, 100, 80, 50, 40, 25, 20, 10, 5 + 10: 4000 2000 1000 800 500 400 250 200 160 + 125 100 80 50 40 25 20 10 5 . . D*/ @@ -1097,8 +1102,8 @@ user_gpio: 0-31. baud: 50-1000000 data_bits: number of data bits (1-32) stop_bits: number of stop half bits (2-8) - offset: 0- - numBytes: 1- + offset: >=0 + numBytes: >=1 str: an array of chars. . . @@ -1421,6 +1426,8 @@ int store_script(char *script); /*D This function stores a script for later execution. +See [[http://abyz.co.uk/rpi/pigpio/pigs.html#Scripts]] for details. + . . script: the text of the script. . . @@ -1528,7 +1535,7 @@ bit bang serial cyclic buffer to the buffer starting at buf. . . user_gpio: 0-31, previously opened with [*bb_serial_read_open*]. buf: an array to receive the read bytes. - bufSize: 0- + bufSize: >=0 . . Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO @@ -1573,13 +1580,16 @@ int i2c_open(unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags); This returns a handle for the device at address i2c_addr on bus i2c_bus. . . - i2c_bus: 0-1. - i2c_addr: 0x00-0x7F. + i2c_bus: >=0. + i2c_addr: 0-0x7F. i2c_flags: 0. . . No flags are currently defined. This parameter should be set to zero. +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + 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. @@ -2560,7 +2570,7 @@ of the error. f:: A function. -frequency::0- +frequency::>=0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as 40KHz. The GPIO will be on for a proportion of the time as defined @@ -2611,15 +2621,15 @@ gpioThreadFunc_t:: typedef void *(gpioThreadFunc_t) (void *); . . -handle::0- +handle::>=0 A number referencing an object opened by one of [*i2c_open*], [*notify_open*], [*serial_open*], and [*spi_open*]. -i2c_addr:: +i2c_addr:: 0-0x7F The address of a device on the I2C bus. -i2c_bus::0-1 -An I2C bus, 0 or 1. +i2c_bus::>=0 +An I2C bus number. i2c_flags::0 Flags which modify an I2C open command. None are currently defined. diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index df2afe7..fa88ced 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -312,7 +312,7 @@ resources used by the library. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -326,7 +326,7 @@ Set the GPIO mode. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: 0-53. .br @@ -352,7 +352,7 @@ Get the GPIO mode. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: 0-53. .br @@ -373,7 +373,7 @@ Set or clear the GPIO pull-up/down resistor. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: 0-53. .br @@ -397,7 +397,7 @@ Read the GPIO level. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio:0-53. .br @@ -418,7 +418,7 @@ Write the GPIO level. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: 0-53. .br @@ -452,7 +452,7 @@ Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -483,7 +483,7 @@ Return the PWM dutycycle in use on a GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -522,7 +522,7 @@ Set the range of PWM values to be used on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -582,7 +582,7 @@ Get the range of PWM values being used on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -610,7 +610,7 @@ Get the real underlying range of PWM values being used on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -648,11 +648,11 @@ Set the frequency (in Hz) of the PWM to be used on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br -frequency: 0- (Hz). +frequency: >=0 (Hz). .br .EE @@ -666,9 +666,8 @@ PI_BAD_USER_GPIO or PI_NOT_PERMITTED. .br .br -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the C pigpio library is started. +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. .br @@ -679,47 +678,59 @@ 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. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +.br + +.br +The frequencies for each sample rate are: .br .br .EX -1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600, -.br - 1250, 1000, 800, 500, 400, 250, 200, 100, 50 + Hertz .br .br -2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800, + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 .br - 625, 500, 400, 250, 200, 125, 100, 50 , 25 + 1250 1000 800 500 400 250 200 100 50 .br .br -4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400, + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 .br - 313, 250, 200, 125, 100, 63, 50, 25, 13 + 625 500 400 250 200 125 100 50 25 .br .br -5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320, + 4: 10000 5000 2500 2000 1250 1000 625 500 400 .br - 250, 200, 160, 100 , 80, 50, 40, 20, 10 + 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 -8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200, + 8: 5000 2500 1250 1000 625 500 313 250 200 .br - 156, 125, 100, 63, 50, 31, 25, 13, 6 + 156 125 100 63 50 31 25 13 6 .br .br -10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160, + 10: 4000 2000 1000 800 500 400 250 200 160 .br - 125, 100, 80, 50, 40, 25, 20, 10, 5 + 125 100 80 50 40 25 20 10 5 .br .EE @@ -733,7 +744,7 @@ Get the frequency of PWM being used on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -773,7 +784,7 @@ Start (500-2500) or stop (0) servo pulses on the GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -874,7 +885,7 @@ Return the servo pulsewidth in use on a GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -895,7 +906,7 @@ Get a free notification handle. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -937,7 +948,7 @@ Start notifications on a previously opened handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: 0-31 (as returned by \fBnotify_open\fP) .br @@ -992,7 +1003,7 @@ Pause notifications on a previously opened handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: 0-31 (as returned by \fBnotify_open\fP) .br @@ -1020,7 +1031,7 @@ release the handle for reuse. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: 0-31 (as returned by \fBnotify_open\fP) .br @@ -1041,7 +1052,7 @@ Sets a watchdog for a GPIO. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -1101,7 +1112,7 @@ level is then reported. Level changes of less than .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31 .br @@ -1138,7 +1149,7 @@ which the process repeats. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31 .br @@ -1170,7 +1181,7 @@ Read the levels of the bank 1 GPIO (GPIO 0-31). .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1190,7 +1201,7 @@ Read the levels of the bank 2 GPIO (GPIO 32-53). .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1210,7 +1221,7 @@ Clears GPIO 0-31 if the corresponding bit in bits is set. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br bits: a bit mask with 1 set if the corresponding GPIO is .br @@ -1239,7 +1250,7 @@ Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br bits: a bit mask with 1 set if the corresponding GPIO is .br @@ -1268,7 +1279,7 @@ Sets GPIO 0-31 if the corresponding bit in bits is set. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br bits: a bit mask with 1 set if the corresponding GPIO is .br @@ -1297,7 +1308,7 @@ Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br bits: a bit mask with 1 set if the corresponding GPIO is .br @@ -1327,7 +1338,7 @@ Frequencies above 30MHz are unlikely to work. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: see description .br @@ -1413,7 +1424,7 @@ daemon is started (option -t). .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br gpio: see descripton .br @@ -1499,7 +1510,7 @@ Gets the current system tick. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1528,7 +1539,7 @@ Get the Pi's hardware revision number. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1580,7 +1591,7 @@ Returns the pigpio version. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1595,7 +1606,7 @@ This function clears all waveforms and any data added by calls to the .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1616,7 +1627,7 @@ created with the \fBwave_create\fP function. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1635,7 +1646,7 @@ This function adds a number of pulses to the current waveform. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br numPulses: the number of pulses. .br @@ -1679,7 +1690,7 @@ microseconds from the start of the waveform. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -1689,9 +1700,9 @@ data_bits: number of data bits (1-32) .br stop_bits: number of stop half bits (2-8) .br - offset: 0- + offset: >=0 .br - numBytes: 1- + numBytes: >=1 .br str: an array of chars. .br @@ -1754,7 +1765,7 @@ PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -1869,7 +1880,7 @@ This function deletes the waveform with id wave_id. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br wave_id: >=0, as returned by \fBwave_create\fP. .br @@ -1901,7 +1912,7 @@ NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br wave_id: >=0, as returned by \fBwave_create\fP. .br @@ -1930,7 +1941,7 @@ NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br wave_id: >=0, as returned by \fBwave_create\fP. .br @@ -1952,7 +1963,7 @@ Transmits the waveform with id wave_id using mode mode. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br wave_id: >=0, as returned by \fBwave_create\fP. .br @@ -2023,7 +2034,7 @@ codes and related data. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br buf: pointer to the wave_ids and optional command codes .br @@ -2209,7 +2220,7 @@ transmitted. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2236,7 +2247,7 @@ transmitted. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2255,7 +2266,7 @@ This function stops the transmission of the current waveform. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2280,7 +2291,7 @@ waveform. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2295,7 +2306,7 @@ created since the pigpio daemon was started. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2311,7 +2322,7 @@ microseconds. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2325,7 +2336,7 @@ This function returns the length in pulses of the current waveform. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2340,7 +2351,7 @@ created since the pigpio daemon was started. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2354,7 +2365,7 @@ This function returns the maximum possible size of a waveform in pulses. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2369,7 +2380,7 @@ waveform. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2384,7 +2395,7 @@ waveform created since the pigpio daemon was started. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2399,7 +2410,7 @@ control blocks. .br .EX -pi: 0- (as returned by \fBpigpio_start\fP). +pi: >=0 (as returned by \fBpigpio_start\fP). .br .EE @@ -2414,7 +2425,7 @@ level for pulseLen microseconds and then reset to not level. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -2437,10 +2448,15 @@ This function stores a script for later execution. .br +.br +See \fBhttp://abyz.co.uk/rpi/pigpio/pigs.html#Scripts\fP for details. + +.br + .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br script: the text of the script. .br @@ -2462,7 +2478,7 @@ This function runs a stored script. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br script_id: >=0, as returned by \fBstore_script\fP. .br @@ -2495,7 +2511,7 @@ as the current values of parameters 0 to 9. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br script_id: >=0, as returned by \fBstore_script\fP. .br @@ -2547,7 +2563,7 @@ This function stops a running script. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br script_id: >=0, as returned by \fBstore_script\fP. .br @@ -2568,7 +2584,7 @@ This function deletes a stored script. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br script_id: >=0, as returned by \fBstore_script\fP. .br @@ -2589,7 +2605,7 @@ This function opens a GPIO for bit bang reading of serial data. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -2628,13 +2644,13 @@ bit bang serial cyclic buffer to the buffer starting at buf. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. .br buf: an array to receive the read bytes. .br - bufSize: 0- + bufSize: >=0 .br .EE @@ -2669,7 +2685,7 @@ This function closes a GPIO for bit bang reading of serial data. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. .br @@ -2690,7 +2706,7 @@ This function inverts serial logic for big bang serial reads. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP. .br @@ -2713,11 +2729,11 @@ This returns a handle for the device at address i2c_addr on bus i2c_bus. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br - i2c_bus: 0-1. + i2c_bus: >=0. .br - i2c_addr: 0x00-0x7F. + i2c_addr: 0-0x7F. .br i2c_flags: 0. .br @@ -2731,6 +2747,12 @@ No flags are currently defined. This parameter should be set to zero. .br +.br +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + +.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. @@ -2780,7 +2802,7 @@ This closes the I2C device associated with the handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2802,7 +2824,7 @@ with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2837,7 +2859,7 @@ This sends a single byte to the device associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2872,7 +2894,7 @@ This reads a single byte from the device associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2906,7 +2928,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2944,7 +2966,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -2982,7 +3004,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3018,7 +3040,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3056,7 +3078,7 @@ associated with handle and and reads 16 bits of data in return. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3096,7 +3118,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3138,7 +3160,7 @@ the device associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3184,7 +3206,7 @@ of bytes of data in return. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3237,7 +3259,7 @@ associated with handle . The count may be 1-32. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3278,7 +3300,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3316,7 +3338,7 @@ This reads count bytes from the raw device into buf. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3352,7 +3374,7 @@ This writes count bytes from buf to the raw device. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2c_open\fP. .br @@ -3390,7 +3412,7 @@ which contains the concatenated command codes and associated data. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBi2cOpen\fP .br @@ -3527,7 +3549,7 @@ o I2C on any pair of spare GPIO .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br SDA: 0-31 .br @@ -3565,7 +3587,7 @@ opened with \fBbb_i2c_open\fP. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br SDA: 0-31, the SDA GPIO used in a prior call to \fBbb_i2c_open\fP .br @@ -3588,7 +3610,7 @@ which contains the concatenated command codes and associated data. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br SDA: 0-31 (as used in a prior call to \fBbb_i2c_open\fP) .br @@ -3737,7 +3759,7 @@ selectable word size in bits. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br spi_channel: 0-1 (0-2 for the auxiliary device). .br @@ -3883,7 +3905,7 @@ This functions closes the SPI device identified by the handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBspi_open\fP. .br @@ -3905,7 +3927,7 @@ device associated with the handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBspi_open\fP. .br @@ -3932,7 +3954,7 @@ device associated with the handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBspi_open\fP. .br @@ -3960,7 +3982,7 @@ data are read from the device and placed in rxBuf. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBspi_open\fP. .br @@ -3989,7 +4011,7 @@ with specified flags. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br ser_tty: the serial device to open, /dev/tty*. .br @@ -4027,7 +4049,7 @@ This function closes the serial device associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4048,7 +4070,7 @@ This function writes bVal to the serial port associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4070,7 +4092,7 @@ This function reads a byte from the serial port associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4093,7 +4115,7 @@ associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4120,7 +4142,7 @@ associated with handle and writes them to buf. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4147,7 +4169,7 @@ device associated with handle. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br handle: >=0, as returned by a call to \fBserial_open\fP. .br @@ -4174,7 +4196,7 @@ It returns a single integer value. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br arg1: >=0 .br @@ -4208,7 +4230,7 @@ rather than just an integer. The return value is an integer indicating the number of returned bytes. .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br arg1: >=0 .br @@ -4242,7 +4264,7 @@ This function initialises a new callback. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -4274,7 +4296,7 @@ This function initialises a new callback. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -4328,7 +4350,7 @@ seconds. .br .EX - pi: 0- (as returned by \fBpigpio_start\fP). + pi: >=0 (as returned by \fBpigpio_start\fP). .br user_gpio: 0-31. .br @@ -4608,7 +4630,7 @@ A function. .br -.IP "\fBfrequency\fP: 0-" 0 +.IP "\fBfrequency\fP: >=0" 0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as 40KHz. The GPIO will be on for a proportion of the time as defined @@ -4718,7 +4740,7 @@ typedef void *(gpioThreadFunc_t) (void *); .br -.IP "\fBhandle\fP: 0-" 0 +.IP "\fBhandle\fP: >=0" 0 A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, \fBserial_open\fP, and \fBspi_open\fP. @@ -4726,15 +4748,15 @@ A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\f .br -.IP "\fBi2c_addr\fP" 0 +.IP "\fBi2c_addr\fP: 0-0x7F" 0 The address of a device on the I2C bus. .br .br -.IP "\fBi2c_bus\fP: 0-1" 0 -An I2C bus, 0 or 1. +.IP "\fBi2c_bus\fP: >=0" 0 +An I2C bus number. .br diff --git a/pigpiod_if2.c b/pigpiod_if2.c index e478ddd..ffaab49 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 5 */ +/* PIGPIOD_IF2_VERSION 6 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index f4be0f5..95de307 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 5 +#define PIGPIOD_IF2_VERSION 6 /*TEXT @@ -387,7 +387,7 @@ Terminates the connection to a pigpio daemon and releases resources used by the library. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -397,7 +397,7 @@ int set_mode(int pi, unsigned gpio, unsigned mode); Set the GPIO mode. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: 0-53. mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1, PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. @@ -413,7 +413,7 @@ int get_mode(int pi, unsigned gpio); Get the GPIO mode. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: 0-53. . . @@ -426,7 +426,7 @@ int set_pull_up_down(int pi, unsigned gpio, unsigned pud); Set or clear the GPIO pull-up/down resistor. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: 0-53. pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF. . . @@ -441,7 +441,7 @@ int gpio_read(int pi, unsigned gpio); Read the GPIO level. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio:0-53. . . @@ -454,7 +454,7 @@ int gpio_write(int pi, unsigned gpio, unsigned level); Write the GPIO level. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: 0-53. level: 0, 1. . . @@ -473,7 +473,7 @@ int set_PWM_dutycycle(int pi, unsigned user_gpio, unsigned dutycycle); Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. dutycycle: 0-range (range defaults to 255). . . @@ -492,7 +492,7 @@ int get_PWM_dutycycle(int pi, unsigned user_gpio); Return the PWM dutycycle in use on a GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. . . @@ -514,7 +514,7 @@ int set_PWM_range(int pi, unsigned user_gpio, unsigned range); Set the range of PWM values to be used on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. range: 25-40000. . . @@ -545,7 +545,7 @@ int get_PWM_range(int pi, unsigned user_gpio); Get the range of PWM values being used on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. . . @@ -562,7 +562,7 @@ int get_PWM_real_range(int pi, unsigned user_gpio); Get the real underlying range of PWM values being used on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. . . @@ -583,42 +583,47 @@ int set_PWM_frequency(int pi, unsigned user_gpio, unsigned frequency); Set the frequency (in Hz) of the PWM to be used on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. -frequency: 0- (Hz). +frequency: >=0 (Hz). . . Returns the numerically closest frequency if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PERMITTED. -The selectable frequencies depend upon the sample rate which -may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The -sample rate is set when the C pigpio library is started. +If PWM is currently active on the GPIO it will be switched +off and then back on at the new frequency. Each GPIO can be independently set to one of 18 different PWM frequencies. -If PWM is currently active on the GPIO it will be switched -off and then back on at the new frequency. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. + +The frequencies for each sample rate are: . . -1us 40000, 20000, 10000, 8000, 5000, 4000, 2500, 2000, 1600, - 1250, 1000, 800, 500, 400, 250, 200, 100, 50 + Hertz -2us 20000, 10000, 5000, 4000, 2500, 2000, 1250, 1000, 800, - 625, 500, 400, 250, 200, 125, 100, 50 , 25 + 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600 + 1250 1000 800 500 400 250 200 100 50 -4us 10000, 5000, 2500, 2000, 1250, 1000, 625, 500, 400, - 313, 250, 200, 125, 100, 63, 50, 25, 13 + 2: 20000 10000 5000 4000 2500 2000 1250 1000 800 + 625 500 400 250 200 125 100 50 25 -5us 8000, 4000, 2000, 1600, 1000, 800, 500, 400, 320, - 250, 200, 160, 100 , 80, 50, 40, 20, 10 + 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 -8us 5000, 2500, 1250, 1000, 625, 500, 313, 250, 200, - 156, 125, 100, 63, 50, 31, 25, 13, 6 + 8: 5000 2500 1250 1000 625 500 313 250 200 + 156 125 100 63 50 31 25 13 6 -10us 4000, 2000, 1000, 800, 500, 400, 250, 200, 160, - 125, 100, 80, 50, 40, 25, 20, 10, 5 + 10: 4000 2000 1000 800 500 400 250 200 160 + 125 100 80 50 40 25 20 10 5 . . D*/ @@ -628,7 +633,7 @@ int get_PWM_frequency(int pi, unsigned user_gpio); Get the frequency of PWM being used on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. . . @@ -651,7 +656,7 @@ int set_servo_pulsewidth(int pi, unsigned user_gpio, unsigned pulsewidth); Start (500-2500) or stop (0) servo pulses on the GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise). . . @@ -701,7 +706,7 @@ int get_servo_pulsewidth(int pi, unsigned user_gpio); Return the servo pulsewidth in use on a GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. . . @@ -714,7 +719,7 @@ int notify_open(int pi); Get a free notification handle. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns a handle greater than or equal to zero if OK, @@ -740,7 +745,7 @@ int notify_begin(int pi, unsigned handle, uint32_t bits); Start notifications on a previously opened handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: 0-31 (as returned by [*notify_open*]) bits: a mask indicating the GPIO to be notified. . . @@ -768,7 +773,7 @@ int notify_pause(int pi, unsigned handle); Pause notifications on a previously opened handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: 0-31 (as returned by [*notify_open*]) . . @@ -785,7 +790,7 @@ Stop notifications on a previously opened handle and release the handle for reuse. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: 0-31 (as returned by [*notify_open*]) . . @@ -798,7 +803,7 @@ int set_watchdog(int pi, unsigned user_gpio, unsigned timeout); Sets a watchdog for a GPIO. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. timeout: 0-60000. . . @@ -831,7 +836,7 @@ level is then reported. Level changes of less than [*steady*] microseconds are ignored. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31 steady: 0-300000 . . @@ -854,7 +859,7 @@ on the GPIO are then reported for [*active*] microseconds after which the process repeats. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31 steady: 0-300000 active: 0-1000000 @@ -873,7 +878,7 @@ uint32_t read_bank_1(int pi); Read the levels of the bank 1 GPIO (GPIO 0-31). . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . The returned 32 bit integer has a bit set if the corresponding @@ -886,7 +891,7 @@ uint32_t read_bank_2(int pi); Read the levels of the bank 2 GPIO (GPIO 32-53). . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . The returned 32 bit integer has a bit set if the corresponding @@ -899,7 +904,7 @@ int clear_bank_1(int pi, uint32_t bits); Clears GPIO 0-31 if the corresponding bit in bits is set. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). bits: a bit mask with 1 set if the corresponding GPIO is to be cleared. . . @@ -916,7 +921,7 @@ int clear_bank_2(int pi, uint32_t bits); Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). bits: a bit mask with 1 set if the corresponding GPIO is to be cleared. . . @@ -933,7 +938,7 @@ int set_bank_1(int pi, uint32_t bits); Sets GPIO 0-31 if the corresponding bit in bits is set. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). bits: a bit mask with 1 set if the corresponding GPIO is to be set. . . @@ -950,7 +955,7 @@ int set_bank_2(int pi, uint32_t bits); Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). bits: a bit mask with 1 set if the corresponding GPIO is to be set. . . @@ -969,7 +974,7 @@ Starts a hardware clock on a GPIO at the specified frequency. Frequencies above 30MHz are unlikely to work. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: see description frequency: 0 (off) or 4689-250000000 (250M) . . @@ -1016,7 +1021,7 @@ main clock defaults to PCM but may be overridden when the pigpio daemon is started (option -t). . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). gpio: see descripton PWMfreq: 0 (off) or 1-125000000 (125M) PWMduty: 0 (off) to 1000000 (1M)(fully on) @@ -1063,7 +1068,7 @@ uint32_t get_current_tick(int pi); Gets the current system tick. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Tick is the number of microseconds since system boot. @@ -1079,7 +1084,7 @@ uint32_t get_hardware_revision(int pi); Get the Pi's hardware revision number. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . The hardware revision is the last few characters on the Revision line @@ -1106,7 +1111,7 @@ uint32_t get_pigpio_version(int pi); Returns the pigpio version. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1118,7 +1123,7 @@ This function clears all waveforms and any data added by calls to the [*wave_add_**] functions. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns 0 if OK. @@ -1132,7 +1137,7 @@ to call this function as it is automatically called after a waveform is created with the [*wave_create*] function. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns 0 if OK. @@ -1144,7 +1149,7 @@ int wave_add_generic(int pi, unsigned numPulses, gpioPulse_t *pulses); This function adds a number of pulses to the current waveform. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). numPulses: the number of pulses. pulses: an array of pulses. . . @@ -1172,13 +1177,13 @@ existing waveform (if any). The serial data starts offset microseconds from the start of the waveform. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. baud: 50-1000000 data_bits: number of data bits (1-32) stop_bits: number of stop half bits (2-8) - offset: 0- - numBytes: 1- + offset: >=0 + numBytes: >=1 str: an array of chars. . . @@ -1213,7 +1218,7 @@ greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . The data provided by the [*wave_add_**] functions is consumed by this @@ -1269,7 +1274,7 @@ int wave_delete(int pi, unsigned wave_id); This function deletes the waveform with id wave_id. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). wave_id: >=0, as returned by [*wave_create*]. . . @@ -1288,7 +1293,7 @@ is sent once. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). wave_id: >=0, as returned by [*wave_create*]. . . @@ -1307,7 +1312,7 @@ by [*wave_tx_stop*]). NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). wave_id: >=0, as returned by [*wave_create*]. . . @@ -1322,7 +1327,7 @@ int wave_send_using_mode(int pi, unsigned wave_id, unsigned mode); Transmits the waveform with id wave_id using mode mode. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). wave_id: >=0, as returned by [*wave_create*]. mode: PI_WAVE_MODE_ONE_SHOT, PI_WAVE_MODE_REPEAT, PI_WAVE_MODE_ONE_SHOT_SYNC, or PI_WAVE_MODE_REPEAT_SYNC. @@ -1359,7 +1364,7 @@ which contains an ordered list of [*wave_id*]s and optional command codes and related data. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). buf: pointer to the wave_ids and optional command codes bufSize: the number of bytes in buf . . @@ -1450,7 +1455,7 @@ This function returns the id of the waveform currently being transmitted. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns the waveform id or one of the following special values: @@ -1466,7 +1471,7 @@ This function checks to see if a waveform is currently being transmitted. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns 1 if a waveform is currently being transmitted, otherwise 0. @@ -1478,7 +1483,7 @@ int wave_tx_stop(int pi); This function stops the transmission of the current waveform. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . Returns 0 if OK. @@ -1493,7 +1498,7 @@ This function returns the length in microseconds of the current waveform. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1504,7 +1509,7 @@ This function returns the length in microseconds of the longest waveform created since the pigpio daemon was started. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1515,7 +1520,7 @@ This function returns the maximum possible size of a waveform in microseconds. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1525,7 +1530,7 @@ int wave_get_pulses(int pi); This function returns the length in pulses of the current waveform. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1536,7 +1541,7 @@ This function returns the length in pulses of the longest waveform created since the pigpio daemon was started. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1546,7 +1551,7 @@ int wave_get_max_pulses(int pi); This function returns the maximum possible size of a waveform in pulses. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1557,7 +1562,7 @@ This function returns the length in DMA control blocks of the current waveform. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1568,7 +1573,7 @@ This function returns the length in DMA control blocks of the longest waveform created since the pigpio daemon was started. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1579,7 +1584,7 @@ This function returns the maximum possible size of a waveform in DMA control blocks. . . -pi: 0- (as returned by [*pigpio_start*]). +pi: >=0 (as returned by [*pigpio_start*]). . . D*/ @@ -1590,7 +1595,7 @@ This function sends a trigger pulse to a GPIO. The GPIO is set to level for pulseLen microseconds and then reset to not level. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. pulseLen: 1-100. level: 0,1. @@ -1605,8 +1610,10 @@ int store_script(int pi, char *script); /*D This function stores a script for later execution. +See [[http://abyz.co.uk/rpi/pigpio/pigs.html#Scripts]] for details. + . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). script: the text of the script. . . @@ -1620,7 +1627,7 @@ int run_script(int pi, unsigned script_id, unsigned numPar, uint32_t *param); This function runs a stored script. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). script_id: >=0, as returned by [*store_script*]. numPar: 0-10, the number of parameters. param: an array of parameters. @@ -1640,7 +1647,7 @@ This function returns the run status of a stored script as well as the current values of parameters 0 to 9. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). script_id: >=0, as returned by [*store_script*]. param: an array to hold the returned 10 parameters. . . @@ -1667,7 +1674,7 @@ int stop_script(int pi, unsigned script_id); This function stops a running script. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). script_id: >=0, as returned by [*store_script*]. . . @@ -1680,7 +1687,7 @@ int delete_script(int pi, unsigned script_id); This function deletes a stored script. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). script_id: >=0, as returned by [*store_script*]. . . @@ -1693,7 +1700,7 @@ int bb_serial_read_open(int pi, unsigned user_gpio, unsigned baud, unsigned data This function opens a GPIO for bit bang reading of serial data. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. baud: 50-250000 data_bits: 1-32 @@ -1716,10 +1723,10 @@ This function copies up to bufSize bytes of data read from the bit bang serial cyclic buffer to the buffer starting at buf. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31, previously opened with [*bb_serial_read_open*]. buf: an array to receive the read bytes. - bufSize: 0- + bufSize: >=0 . . Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO @@ -1739,7 +1746,7 @@ int bb_serial_read_close(int pi, unsigned user_gpio); This function closes a GPIO for bit bang reading of serial data. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31, previously opened with [*bb_serial_read_open*]. . . @@ -1752,7 +1759,7 @@ int bb_serial_invert(int pi, unsigned user_gpio, unsigned invert); This function inverts serial logic for big bang serial reads. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31, previously opened with [*bb_serial_read_open*]. invert: 0-1, 1 invert, 0 normal. . . @@ -1766,14 +1773,17 @@ int i2c_open(int pi, unsigned i2c_bus, unsigned i2c_addr, unsigned i2c_flags); This returns a handle for the device at address i2c_addr on bus i2c_bus. . . - pi: 0- (as returned by [*pigpio_start*]). - i2c_bus: 0-1. - i2c_addr: 0x00-0x7F. + pi: >=0 (as returned by [*pigpio_start*]). + i2c_bus: >=0. + i2c_addr: 0-0x7F. i2c_flags: 0. . . No flags are currently defined. This parameter should be set to zero. +Physically buses 0 and 1 are available on the Pi. Higher numbered buses +will be available if a kernel supported bus multiplexor is being used. + 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. @@ -1800,7 +1810,7 @@ int i2c_close(int pi, unsigned handle); This closes the I2C device associated with the handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. . . @@ -1814,7 +1824,7 @@ This sends a single bit (in the Rd/Wr bit) to the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. bit: 0-1, the value to write. . . @@ -1834,7 +1844,7 @@ int i2c_write_byte(int pi, unsigned handle, unsigned bVal); This sends a single byte to the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. bVal: 0-0xFF, the value to write. . . @@ -1854,7 +1864,7 @@ int i2c_read_byte(int pi, unsigned handle); This reads a single byte from the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. . . @@ -1875,7 +1885,7 @@ This writes a single byte to the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write. bVal: 0-0xFF, the value to write. @@ -1898,7 +1908,7 @@ This writes a single 16 bit word to the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write. wVal: 0-0xFFFF, the value to write. @@ -1920,7 +1930,7 @@ This reads a single byte from the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to read. . . @@ -1941,7 +1951,7 @@ This reads a single 16 bit word from the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to read. . . @@ -1963,7 +1973,7 @@ 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. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write/read. wVal: 0-0xFFFF, the value to write. @@ -1987,7 +1997,7 @@ This writes up to 32 bytes to the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write. buf: an array with the data to send. @@ -2011,7 +2021,7 @@ This reads a block of up to 32 bytes from the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to read. buf: an array to receive the read data. @@ -2038,7 +2048,7 @@ associated with handle and reads a device specified number of bytes of data in return. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write/read. buf: an array with the data to send and to receive the read data. @@ -2068,7 +2078,7 @@ This reads count bytes from the specified register of the device associated with handle . The count may be 1-32. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to read. buf: an array to receive the read data. @@ -2093,7 +2103,7 @@ This writes 1 to 32 bytes to the specified register of the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. i2c_reg: 0-255, the register to write. buf: the data to write. @@ -2114,7 +2124,7 @@ int i2c_read_device(int pi, unsigned handle, char *buf, unsigned count); This reads count bytes from the raw device into buf. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. buf: an array to receive the read data bytes. count: >0, the number of bytes to read. @@ -2134,7 +2144,7 @@ int i2c_write_device(int pi, unsigned handle, char *buf, unsigned count); This writes count bytes from buf to the raw device. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2c_open*]. buf: an array containing the data bytes to write. count: >0, the number of bytes to write. @@ -2162,7 +2172,7 @@ operations to be performed are specified by the contents of inBuf which contains the concatenated command codes and associated data. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*i2cOpen*] inBuf: pointer to the concatenated I2C commands, see below inLen: size of command buffer @@ -2226,7 +2236,7 @@ o clock stretching o I2C on any pair of spare GPIO . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). SDA: 0-31 SCL: 0-31 baud: 50-500000 @@ -2248,7 +2258,7 @@ This function stops bit banging I2C on a pair of GPIO previously opened with [*bb_i2c_open*]. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). SDA: 0-31, the SDA GPIO used in a prior call to [*bb_i2c_open*] . . @@ -2269,7 +2279,7 @@ operations to be performed are specified by the contents of inBuf which contains the concatenated command codes and associated data. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). SDA: 0-31 (as used in a prior call to [*bb_i2c_open*]) inBuf: pointer to the concatenated I2C commands, see below inLen: size of command buffer @@ -2342,7 +2352,7 @@ flags. The auxiliary device has 3 chip selects and a selectable word size in bits. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). spi_channel: 0-1 (0-2 for the auxiliary device). baud: 32K-125M (values above 30M are unlikely to work). spi_flags: see below. @@ -2414,7 +2424,7 @@ int spi_close(int pi, unsigned handle); This functions closes the SPI device identified by the handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*spi_open*]. . . @@ -2428,7 +2438,7 @@ This function reads count bytes of data from the SPI device associated with the handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*spi_open*]. buf: an array to receive the read data bytes. count: the number of bytes to read. @@ -2445,7 +2455,7 @@ This function writes count bytes of data from buf to the SPI device associated with the handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*spi_open*]. buf: the data bytes to write. count: the number of bytes to write. @@ -2464,7 +2474,7 @@ device associated with the handle. Simultaneously count bytes of data are read from the device and placed in rxBuf. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*spi_open*]. txBuf: the data bytes to write. rxBuf: the received data bytes. @@ -2482,7 +2492,7 @@ This function opens a serial device at a specified baud rate with specified flags. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). ser_tty: the serial device to open, /dev/tty*. baud: the baud rate in bits per second, see below. ser_flags: 0. @@ -2504,7 +2514,7 @@ int serial_close(int pi, unsigned handle); This function closes the serial device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. . . @@ -2517,7 +2527,7 @@ int serial_write_byte(int pi, unsigned handle, unsigned bVal); This function writes bVal to the serial port associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. . . @@ -2531,7 +2541,7 @@ int serial_read_byte(int pi, unsigned handle); This function reads a byte from the serial port associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. . . @@ -2546,7 +2556,7 @@ This function writes count bytes from buf to the the serial port associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. buf: the array of bytes to write. count: the number of bytes to write. @@ -2563,7 +2573,7 @@ This function reads up to count bytes from the the serial port associated with handle and writes them to buf. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. buf: an array to receive the read data. count: the maximum number of bytes to read. @@ -2580,7 +2590,7 @@ Returns the number of bytes available to be read from the device associated with handle. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). handle: >=0, as returned by a call to [*serial_open*]. . . @@ -2596,7 +2606,7 @@ This function is available for user customisation. It returns a single integer value. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). arg1: >=0 arg2: >=0 argx: extra (byte) arguments @@ -2618,7 +2628,7 @@ rather than just an integer. The return value is an integer indicating the number of returned bytes. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). arg1: >=0 argc: extra (byte) arguments count: number of extra arguments @@ -2638,7 +2648,7 @@ int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f); This function initialises a new callback. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. f: the callback function. @@ -2658,7 +2668,7 @@ int callback_ex This function initialises a new callback. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. f: the callback function. @@ -2691,7 +2701,7 @@ This function waits for edge on the GPIO for up to timeout seconds. . . - pi: 0- (as returned by [*pigpio_start*]). + pi: >=0 (as returned by [*pigpio_start*]). user_gpio: 0-31. edge: RISING_EDGE, FALLING_EDGE, or EITHER_EDGE. timeout: >=0. @@ -2821,7 +2831,7 @@ of the error. f:: A function. -frequency::0- +frequency::>=0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as 40KHz. The GPIO will be on for a proportion of the time as defined @@ -2872,15 +2882,15 @@ gpioThreadFunc_t:: typedef void *(gpioThreadFunc_t) (void *); . . -handle::0- +handle::>=0 A number referencing an object opened by one of [*i2c_open*], [*notify_open*], [*serial_open*], and [*spi_open*]. -i2c_addr:: +i2c_addr::0-0x7F The address of a device on the I2C bus. -i2c_bus::0-1 -An I2C bus, 0 or 1. +i2c_bus::>=0 +An I2C bus number. i2c_flags::0 Flags which modify an I2C open command. None are currently defined. diff --git a/pigs.1 b/pigs.1 index b42fd40..31aec3c 100644 --- a/pigs.1 +++ b/pigs.1 @@ -881,6 +881,11 @@ ERROR: unknown handle This command returns a handle to access device \fBid\fP on I2C bus \fBib\fP. The device is opened with flags \fBif\fP. +.br +Physically buses 0 and 1 are available on the Pi. Higher +numbered buses will be available if a kernel supported bus +multiplexor is being used. + .br No flags are currently defined. The parameter \fBif\fP should be 0. @@ -3388,7 +3393,7 @@ pigs wvcha \ .br .br -while [[ $(pigs wvbsy) -eq 1 ]]; do sleep 0.1; done +while \fB $(pigs wvbsy) -eq 1 \fP; do sleep 0.1; done .br .br @@ -3953,12 +3958,12 @@ A handle is a number referencing an object opened by one of \fBI2CO\fP, \fBNO\fP .br -.IP "\fBib\fP - I2C bus (0-1)" 0 -The command expects an I2C bus. +.IP "\fBib\fP - I2C bus (>=0)" 0 +The command expects an I2C bus number. .br -.IP "\fBid\fP - I2C device (0x08-0x77)" 0 +.IP "\fBid\fP - I2C device (0-0x7F)" 0 The command expects the address of an I2C device. .br @@ -4309,7 +4314,7 @@ Again, ignore the details for now. .br .EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ +time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ .br do sleep 0.2; done) .br @@ -4349,7 +4354,7 @@ jp 999 jumps to tag 999 if the result is positive. .br .EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ +time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ .br do sleep 0.2; done) .br diff --git a/setup.py b/setup.py index 16a18fa..3e0a76d 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.30', + version='1.31', author='joan', author_email='joan@abyz.co.uk', maintainer='joan', From 862f445669a7ba95eeafdc6b7920ac2090750a99 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 3 Jun 2016 16:13:58 +0100 Subject: [PATCH 20/21] V54 --- pigpio.c | 70 ++++++++++++++++++++++++++--------------------------- pigpio.h | 2 +- pigs.1 | 74 ++++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 86 insertions(+), 60 deletions(-) diff --git a/pigpio.c b/pigpio.c index 2ca1962..4588b38 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 53 */ +/* pigpio version 54 */ /* include ------------------------------------------------------- */ @@ -4238,27 +4238,27 @@ static void spiInit(uint32_t flags) if (!(resvd&1)) { - gpioSetMode(PI_ASPI_CE0, PI_OUTPUT); + myGpioSetMode(PI_ASPI_CE0, PI_OUTPUT); myGpioWrite(PI_ASPI_CE0, !(cspols&1)); } if (!(resvd&2)) { - gpioSetMode(PI_ASPI_CE1, PI_OUTPUT); + myGpioSetMode(PI_ASPI_CE1, PI_OUTPUT); myGpioWrite(PI_ASPI_CE1, !(cspols&2)); } if (!(resvd&4)) { - gpioSetMode(PI_ASPI_CE2, PI_OUTPUT); + myGpioSetMode(PI_ASPI_CE2, PI_OUTPUT); myGpioWrite(PI_ASPI_CE2, !(cspols&4)); } /* set gpios to SPI mode */ - gpioSetMode(PI_ASPI_SCLK, PI_ALT4); - gpioSetMode(PI_ASPI_MISO, PI_ALT4); - gpioSetMode(PI_ASPI_MOSI, PI_ALT4); + myGpioSetMode(PI_ASPI_SCLK, PI_ALT4); + myGpioSetMode(PI_ASPI_MISO, PI_ALT4); + myGpioSetMode(PI_ASPI_MOSI, PI_ALT4); } else { @@ -4275,12 +4275,12 @@ static void spiInit(uint32_t flags) /* set gpios to SPI mode */ - if (!(resvd&1)) gpioSetMode(PI_SPI_CE0, PI_ALT0); - if (!(resvd&2)) gpioSetMode(PI_SPI_CE1, PI_ALT0); + if (!(resvd&1)) myGpioSetMode(PI_SPI_CE0, PI_ALT0); + if (!(resvd&2)) myGpioSetMode(PI_SPI_CE1, PI_ALT0); - gpioSetMode(PI_SPI_SCLK, PI_ALT0); - gpioSetMode(PI_SPI_MISO, PI_ALT0); - gpioSetMode(PI_SPI_MOSI, PI_ALT0); + myGpioSetMode(PI_SPI_SCLK, PI_ALT0); + myGpioSetMode(PI_SPI_MISO, PI_ALT0); + myGpioSetMode(PI_SPI_MOSI, PI_ALT0); } } @@ -4298,13 +4298,13 @@ static void spiTerm(uint32_t flags) /* restore original state */ - if (!(resvd&1)) gpioSetMode(PI_ASPI_CE0, old_mode_ace0); - if (!(resvd&2)) gpioSetMode(PI_ASPI_CE1, old_mode_ace1); - if (!(resvd&4)) gpioSetMode(PI_ASPI_CE2, old_mode_ace2); + if (!(resvd&1)) myGpioSetMode(PI_ASPI_CE0, old_mode_ace0); + if (!(resvd&2)) myGpioSetMode(PI_ASPI_CE1, old_mode_ace1); + if (!(resvd&4)) myGpioSetMode(PI_ASPI_CE2, old_mode_ace2); - gpioSetMode(PI_ASPI_SCLK, old_mode_asclk); - gpioSetMode(PI_ASPI_MISO, old_mode_amiso); - gpioSetMode(PI_ASPI_MOSI, old_mode_amosi); + myGpioSetMode(PI_ASPI_SCLK, old_mode_asclk); + myGpioSetMode(PI_ASPI_MISO, old_mode_amiso); + myGpioSetMode(PI_ASPI_MOSI, old_mode_amosi); auxReg[AUX_SPI0_CNTL0_REG] = old_spi_cntl0; auxReg[AUX_SPI0_CNTL1_REG] = old_spi_cntl1; @@ -4313,12 +4313,12 @@ static void spiTerm(uint32_t flags) { /* restore original state */ - if (!(resvd&1)) gpioSetMode(PI_SPI_CE0, old_mode_ce0); - if (!(resvd&2)) gpioSetMode(PI_SPI_CE1, old_mode_ce1); + if (!(resvd&1)) myGpioSetMode(PI_SPI_CE0, old_mode_ce0); + if (!(resvd&2)) myGpioSetMode(PI_SPI_CE1, old_mode_ce1); - gpioSetMode(PI_SPI_SCLK, old_mode_sclk); - gpioSetMode(PI_SPI_MISO, old_mode_miso); - gpioSetMode(PI_SPI_MOSI, old_mode_mosi); + myGpioSetMode(PI_SPI_SCLK, old_mode_sclk); + myGpioSetMode(PI_SPI_MISO, old_mode_miso); + myGpioSetMode(PI_SPI_MOSI, old_mode_mosi); spiReg[SPI_CS] = old_spi_cs; spiReg[SPI_CLK] = old_spi_clk; @@ -8049,10 +8049,10 @@ int gpioSetMode(unsigned gpio, unsigned mode) switchFunctionOff(gpio); gpioInfo[gpio].is = GPIO_UNDEFINED; - - gpioReg[reg] = (gpioReg[reg] & ~(7< #include #include -#define PIGPIO_VERSION 53 +#define PIGPIO_VERSION 54 /*TEXT diff --git a/pigs.1 b/pigs.1 index 31aec3c..e55c554 100644 --- a/pigs.1 +++ b/pigs.1 @@ -1808,16 +1808,17 @@ Upon success the new frequency is returned. On error a negative status code will be returned. .br -The selectable frequencies depend upon the sample rate with which the -pigpiod daemon was started. The sample rate is one of 1, 2, 4, 5, 8, -or 10 microseconds (default 5). +If PWM is currently active on the GPIO it will be +switched off and then back on at the new frequency. .br -Each GPIO can be independently set to one of 18 different PWM frequencies. +Each GPIO can be independently set to one of 18 different PWM +frequencies. .br -If PWM is currently active on the GPIO it will be switched off and then -back on at the new frequency. +The selectable frequencies depend upon the sample rate which +may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The +sample rate is set when the pigpio daemon is started. .br The frequencies for each sample rate are: @@ -1825,21 +1826,46 @@ The frequencies for each sample rate are: .br .EX - #1 #2 #3 #4 #5 #6 #7 #8 #9 - 1us 40000 20000 10000 8000 5000 4000 2500 2000 1600 - 2us 20000 10000 5000 4000 2500 2000 1250 1000 800 - 4us 10000 5000 2500 2000 1250 1000 625 500 400 - 5us 8000 4000 2000 1600 1000 800 500 400 320 - 8us 5000 2500 1250 1000 625 500 313 250 200 -10us 4000 2000 1000 800 500 400 250 200 160 - - #10 #11 #12 #13 #14 #15 #16 #17 #18 - 1us 1250 1000 800 500 400 250 200 100 50 - 2us 625 500 400 250 200 125 100 50 25 - 4us 313 250 200 125 100 63 50 25 13 - 5us 250 200 160 100 80 50 40 20 10 - 8us 156 125 100 63 50 31 25 13 6 -10us 125 100 80 50 40 25 20 10 5 + 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 @@ -3393,7 +3419,7 @@ pigs wvcha \ .br .br -while \fB $(pigs wvbsy) -eq 1 \fP; do sleep 0.1; done +while [[ $(pigs wvbsy) -eq 1 ]]; do sleep 0.1; done .br .br @@ -4314,7 +4340,7 @@ Again, ignore the details for now. .br .EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ +time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ .br do sleep 0.2; done) .br @@ -4354,7 +4380,7 @@ jp 999 jumps to tag 999 if the result is positive. .br .EX -time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ +time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\ .br do sleep 0.2; done) .br From f9e24d568bab974bd353d8bfa7453de2acd66fa0 Mon Sep 17 00:00:00 2001 From: joan Date: Sun, 10 Jul 2016 21:29:14 +0100 Subject: [PATCH 21/21] V55 --- command.c | 160 ++++++-- command.h | 2 +- pig2vcd.1 | 4 + pigpio.3 | 1011 +++++++++++++++++++++++++++++++++++++++++++------ pigpio.c | 552 ++++++++++++++++++++++++++- pigpio.h | 574 +++++++++++++++++++++++++--- pigpio.py | 529 +++++++++++++++++++++++++- pigpiod.1 | 4 + pigpiod_if.3 | 93 +++-- pigpiod_if.c | 2 +- pigpiod_if.h | 46 ++- pigpiod_if2.3 | 945 ++++++++++++++++++++++++++++++++++++++++++--- pigpiod_if2.c | 144 ++++++- pigpiod_if2.h | 502 ++++++++++++++++++++++-- pigs.1 | 694 ++++++++++++++++++++++++++++++++- pigs.c | 16 +- setup.py | 2 +- x_pigs | 2 +- 18 files changed, 4906 insertions(+), 376 deletions(-) diff --git a/command.c b/command.c index ef15b5d..239ec2e 100644 --- a/command.c +++ b/command.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 53+ +This version is for pigpio version 55+ */ #include @@ -61,9 +61,19 @@ cmdInfo_t cmdInfo[]= {PI_CMD_CGI, "CGI", 101, 4}, // gpioCfgGetInternals {PI_CMD_CSI, "CSI", 111, 1}, // gpioCfgSetInternals + {PI_CMD_FC, "FC", 112, 0}, // fileClose + {PI_CMD_FG, "FG", 121, 0}, // gpioGlitchFilter + + {PI_CMD_FL, "FL", 127, 6}, // fileList + {PI_CMD_FN, "FN", 131, 0}, // gpioNoiseFilter + {PI_CMD_FO, "FO", 127, 2}, // fileOpen + {PI_CMD_FR, "FR", 121, 6}, // fileRead + {PI_CMD_FS, "FS", 133, 2}, // fileSeek + {PI_CMD_FW, "FW", 193, 0}, // fileWrite + {PI_CMD_GDC, "GDC", 112, 2}, // gpioGetPWMdutycycle {PI_CMD_GPW, "GPW", 112, 2}, // gpioGetServoPulsewidth @@ -112,6 +122,9 @@ cmdInfo_t cmdInfo[]= {PI_CMD_NO, "NO", 101, 2}, // gpioNotifyOpen {PI_CMD_NP, "NP", 112, 0}, // gpioNotifyPause + {PI_CMD_PADG, "PADG", 112, 2}, // gpioGetPad + {PI_CMD_PADS, "PADS", 121, 0}, // gpioSetPad + {PI_CMD_PARSE, "PARSE", 115, 0}, // cmdParseScript {PI_CMD_PFG, "PFG", 112, 2}, // gpioGetPWMfrequency @@ -149,6 +162,8 @@ cmdInfo_t cmdInfo[]= {PI_CMD_SERVO, "S", 121, 0}, // gpioServo {PI_CMD_SERVO, "SERVO", 121, 0}, // gpioServo + {PI_CMD_SHELL, "SHELL", 128, 2}, // shell + {PI_CMD_SLR, "SLR", 121, 6}, // gpioSerialRead {PI_CMD_SLRC, "SLRC", 112, 0}, // gpioSerialReadClose {PI_CMD_SLRO, "SLRO", 131, 0}, // gpioSerialReadOpen @@ -252,8 +267,14 @@ CF2 ... Custom function 2\n\ CGI Configuration get internals\n\ CSI v Configuration set internals\n\ \n\ +FC h Close file handle\n\ FG g steady Set glitch filter on GPIO\n\ +FL pat n List files which match pattern\n\ FN g steady active | Set noise filter on GPIO\n\ +FO file mode Open a file in mode\n\ +FR h n Read bytes from file handle\n\ +FS h n from Seek to file handle position\n\ +FW h ... Write bytes to file handle\n\ \n\ GDC g Get PWM dutycycle for GPIO\n\ GPW g Get servo pulsewidth for GPIO\n\ @@ -293,6 +314,8 @@ NO Request a notification\n\ NP h Pause notification\n\ \n\ P/PWM g v Set GPIO PWM value\n\ +PADG pad Get pad drive strength\n\ +PADS pad v Set pad drive strength\n\ PARSE text Validate script\n\ PFG g Get GPIO PWM frequency\n\ PFS g v Set GPIO PWM frequency\n\ @@ -316,7 +339,8 @@ SERO text baud flags | Open serial device at baud with flags\n\ SERR h n Read bytes from serial handle\n\ SERRB h Read byte from serial handle\n\ SERW h ... Write bytes to serial handle\n\ -SERWB h byte Write byte to serial handle\n\ +SERWB h byte Write byte to serial handle\n\ +SHELL name str Execute a shell command\n\ SLR g v Read bit bang serial data from GPIO\n\ SLRC g Close GPIO for bit bang serial data\n\ SLRO g baud bitlen | Open GPIO for bit bang serial data\n\ @@ -490,6 +514,21 @@ static errInfo_t errInfo[]= {PI_BAD_ISR_INIT , "bad ISR initialisation"}, {PI_BAD_FOREVER , "loop forever must be last chain command"}, {PI_BAD_FILTER , "bad filter parameter"}, + {PI_BAD_PAD , "bad pad number"}, + {PI_BAD_STRENGTH , "bad pad drive strength"}, + {PI_FIL_OPEN_FAILED , "file open failed"}, + {PI_BAD_FILE_MODE , "bad file mode"}, + {PI_BAD_FILE_FLAG , "bad file flag"}, + {PI_BAD_FILE_READ , "bad file read"}, + {PI_BAD_FILE_WRITE , "bad file write"}, + {PI_FILE_NOT_ROPEN , "file not open for read"}, + {PI_FILE_NOT_WOPEN , "file not open for write"}, + {PI_BAD_FILE_SEEK , "bad file seek"}, + {PI_NO_FILE_MATCH , "no files match pattern"}, + {PI_NO_FILE_ACCESS , "no permission to access file"}, + {PI_FILE_IS_A_DIR , "file is a directory"}, + {PI_BAD_SHELL_STATUS , "bad shell return status"}, + {PI_BAD_SCRIPT_NAME , "bad script name"}, }; @@ -507,14 +546,14 @@ static int cmdMatch(char *str) return CMD_UNKNOWN_CMD; } -static int getNum(char *str, unsigned *val, int8_t *opt) +static int getNum(char *str, uint32_t *val, int8_t *opt) { int f, n; - unsigned v; + intmax_t v; *opt = 0; - f = sscanf(str, " %i %n", &v, &n); + f = sscanf(str, " %ji %n", &v, &n); if (f == 1) { @@ -523,7 +562,7 @@ static int getNum(char *str, unsigned *val, int8_t *opt) return n; } - f = sscanf(str, " v%i %n", &v, &n); + f = sscanf(str, " v%ji %n", &v, &n); if (f == 1) { @@ -533,7 +572,7 @@ static int getNum(char *str, unsigned *val, int8_t *opt) return n; } - f = sscanf(str, " p%i %n", &v, &n); + f = sscanf(str, " p%ji %n", &v, &n); if (f == 1) { @@ -556,7 +595,7 @@ char *cmdStr(void) int cmdParse( char *buf, uint32_t *p, unsigned ext_len, char *ext, cmdCtlParse_t *ctl) { - int f, valid, idx, val, pp, pars, n, n2, i; + int f, valid, idx, val, pp, pars, n, n2; char *p8; int32_t *p32; char c; @@ -611,8 +650,8 @@ int cmdParse( break; - case 112: /* BI2CC GDC GPW I2CC - I2CRB MG MICS MILS MODEG NC NP PFG PRG + case 112: /* BI2CC FC GDC GPW I2CC I2CRB + MG MICS MILS MODEG NC NP PADG PFG PRG PROCD PROCP PROCS PRRG R READ SLRC SPIC WVDEL WVSC WVSM WVSP WVTX WVTXR @@ -656,37 +695,23 @@ int cmdParse( case 116: /* SYS - One parameter, a string of letters, digits, '-' and '_'. + One parameter, a string. */ f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2); if ((f >= 0) && n) { + p[3] = n; + ctl->opt[3] = CMD_NUMERIC; + memcpy(ext, buf+ctl->eaten, n); + ctl->eaten += n2; valid = 1; - - for (i=0; ieaten+i]; - - if ((!isalnum(c)) && (c != '_') && (c != '-')) - { - valid = 0; - break; - } - } - - if (valid) - { - p[3] = n; - ctl->opt[3] = CMD_NUMERIC; - memcpy(ext, buf+ctl->eaten, n); - ctl->eaten += n2; - } } break; - case 121: /* HC I2CRD I2CRR I2CRW I2CWB I2CWQ P PFS PRS - PWM S SERVO SLR SLRI W WDOG WRITE WVTXM + case 121: /* HC FR I2CRD I2CRR I2CRW I2CWB I2CWQ P + PADS PFS PRS PWM S SERVO SLR SLRI W + WDOG WRITE WVTXM Two positive parameters. */ @@ -782,8 +807,53 @@ int cmdParse( break; - case 131: /* BI2CO HP I2CO I2CPC I2CRI I2CWB I2CWW SLRO - SPIO TRIG + case 127: /* FL FO + + Two parameters, first a string, other positive. + */ + f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2); + if ((f >= 0) && n) + { + p[3] = n; + ctl->opt[2] = CMD_NUMERIC; + memcpy(ext, buf+ctl->eaten, n); + ctl->eaten += n2; + + ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]); + + if ((ctl->opt[1] > 0) && ((int)p[1] >= 0)) + valid = 1; + } + + break; + + case 128: /* SHELL + + Two string parameters, the first space teminated. + The second arbitrary. + */ + f = sscanf(buf+ctl->eaten, " %*s%n %n", &n, &n2); + + if ((f >= 0) && n) + { + valid = 1; + + p[1] = n; + memcpy(ext, buf+ctl->eaten, n); + ctl->eaten += n; + ext[n] = 0; /* terminate first string */ + + n2 = strlen(buf+ctl->eaten+1); + memcpy(ext+n+1, buf+ctl->eaten+1, n2); + ctl->eaten += n2; + ctl->eaten ++; + p[3] = p[1] + n2 + 1; + } + + break; + + case 131: /* BI2CO HP I2CO I2CPC I2CRI I2CWB I2CWW + SLRO SPIO TRIG Three positive parameters. */ @@ -824,6 +894,26 @@ int cmdParse( break; + case 133: /* FS + + Three parameters. First and third positive. + Second may be negative when interpreted as an int. + */ + ctl->eaten += getNum(buf+ctl->eaten, &p[1], &ctl->opt[1]); + ctl->eaten += getNum(buf+ctl->eaten, &p[2], &ctl->opt[2]); + ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); + + if ((ctl->opt[1] > 0) && ((int)p[1] >= 0) && + (ctl->opt[2] > 0) && + (to1 == CMD_NUMERIC) && ((int)tp1 >= 0)) + { + p[3] = 4; + memcpy(ext, &tp1, 4); + valid = 1; + } + + break; + case 191: /* PROCR One to 11 parameters, first positive, @@ -880,7 +970,7 @@ int cmdParse( break; - case 193: /* BI2CZ I2CWD I2CZ SERW SPIW SPIX + case 193: /* BI2CZ FW I2CWD I2CZ SERW SPIW SPIX Two or more parameters, first >=0, rest 0-255. */ diff --git a/command.h b/command.h index 3c36bd1..7c6efcd 100644 --- a/command.h +++ b/command.h @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 53+ +This version is for pigpio version 55+ */ #ifndef COMMAND_H diff --git a/pig2vcd.1 b/pig2vcd.1 index 492ec68..24b5a6c 100644 --- a/pig2vcd.1 +++ b/pig2vcd.1 @@ -11,6 +11,10 @@ pig2vd - A utility to convert pigpio notifications to VCD. pig2vcd file.VCD .SH DESCRIPTION + +.ad l + +.nh pig2vcd is a utility which reads notifications on stdin and writes the output as a Value Change Dump (VCD) file on stdout. diff --git a/pigpio.3 b/pigpio.3 index 8bb1011..16b0ddf 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -17,6 +17,10 @@ sudo ./prog .SH DESCRIPTION +.ad l + +.nh + .br .br @@ -29,12 +33,12 @@ pigpio is a C library for the Raspberry which allows control of the GPIO. .br .br -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 .br .br -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 .br @@ -313,15 +317,15 @@ Arduino style: pinMode. .br .EX -gpioSetMode(17, PI_INPUT); // Set gpio17 as input. +gpioSetMode(17, PI_INPUT); // Set GPIO17 as input. .br .br -gpioSetMode(18, PI_OUTPUT); // Set gpio18 as output. +gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output. .br .br -gpioSetMode(22,PI_ALT0); // Set gpio22 to alternative mode 0. +gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0. .br .EE @@ -356,7 +360,7 @@ if (gpioGetMode(17) != PI_ALT0) .br { .br - gpioSetMode(17, PI_ALT0); // set gpio17 to ALT0 + gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0 .br } .br @@ -435,7 +439,7 @@ Arduino style: digitalRead. .br .EX -printf("gpio24 is level %d", gpioRead(24)); +printf("GPIO24 is level %d", gpioRead(24)); .br .EE @@ -478,7 +482,7 @@ Arduino style: digitalWrite .br .EX -gpioWrite(24, 1); // Set gpio24 high. +gpioWrite(24, 1); // Set GPIO24 high. .br .EE @@ -529,15 +533,15 @@ range of 255. .br .EX -gpioPWM(17, 255); // Sets gpio17 full on. +gpioPWM(17, 255); // Sets GPIO17 full on. .br .br -gpioPWM(18, 128); // Sets gpio18 half on. +gpioPWM(18, 128); // Sets GPIO18 half on. .br .br -gpioPWM(23, 0); // Sets gpio23 full off. +gpioPWM(23, 0); // Sets GPIO23 full off. .br .EE @@ -825,15 +829,15 @@ sample .br .EX -gpioSetPWMfrequency(23, 0); // Set gpio23 to lowest frequency. +gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency. .br .br -gpioSetPWMfrequency(24, 500); // Set gpio24 to 500Hz. +gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz. .br .br -gpioSetPWMfrequency(25, 100000); // Set gpio25 to highest frequency. +gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency. .br .EE @@ -878,7 +882,7 @@ will be that set by \fBgpioHardwarePWM\fP. .br .EX -f = gpioGetPWMfrequency(23); // Get frequency used for gpio23. +f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23. .br .EE @@ -978,7 +982,7 @@ the servo pulsewidth. .br .br -E.g. If you want to update a servo connected to gpio25 at 400Hz +E.g. If you want to update a servo connected to GPIO25 at 400Hz .br @@ -1481,11 +1485,19 @@ by one for each report. .br flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout; if bit 6 is set -(PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the -pipe/socket and is sent once a minute in the absence of other -notification activity. + +.br + +.br +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +.br + +.br +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. .br @@ -2095,19 +2107,14 @@ The following command codes are supported: .br Name Cmd & Data Meaning - .br Loop Start 255 0 Identify start of a wave block - .br Loop Repeat 255 1 x y loop x + y*256 times - .br Delay 255 2 x y delay x + y*256 microseconds - .br Loop Forever 255 3 loop forever - .br .br @@ -2362,7 +2369,7 @@ This function configures the level logic for bit bang serial reads. .br .br -Pass PI_BB_SER_INVERT to invert the serial logic. Pass PI_BB_SER_NORMAL for +Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for normal logic. Default is PI_BB_SER_NORMAL. .br @@ -3178,31 +3185,22 @@ The following command codes are supported: .br Name Cmd & Data Meaning - .br End 0 No more commands - .br Escape 1 Next P is two bytes - .br On 2 Switch combined flag on - .br Off 3 Switch combined flag off - .br Address 4 P Set I2C address to P - .br Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) - .br Read 6 P Read P bytes of data - .br Write 7 P ... Write P bytes of data - .br .br @@ -3367,31 +3365,22 @@ The following command codes are supported: .br Name Cmd & Data Meaning - .br End 0 No more commands - .br Escape 1 Next P is two bytes - .br Start 2 Start condition - .br Stop 3 Stop condition - .br Address 4 P Set I2C address to P - .br Flags 5 lsb msb Set I2C flags to lsb + (msb << 8) - .br Read 6 P Read P bytes of data - .br Write 7 P ... Write P bytes of data - .br .br @@ -3719,14 +3708,15 @@ PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED. .IP "\fBint serOpen(char *sertty, unsigned baud, unsigned serFlags)\fP" .IP "" 4 This function opens a serial device at a specified baud rate -with specified flags. +and with specified flags. The device name must start with +/dev/tty or /dev/serial. .br .br .EX - sertty: the serial device to open, /dev/tty* + sertty: the serial device to open .br baud: the baud rate in bits per second, see below .br @@ -3847,7 +3837,7 @@ associated with handle and writes them to buf. .br .EX -handle: >=0, as returned by a call to serial_open +handle: >=0, as returned by a call to \fBserOpen\fP .br buf: an array to receive the read data .br @@ -3860,7 +3850,7 @@ handle: >=0, as returned by a call to serial_open .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. +PI_BAD_PARAM, or PI_SER_READ_NO_DATA. .IP "\fBint serDataAvailable(unsigned handle)\fP" .IP "" 4 @@ -5146,6 +5136,676 @@ for "Revision : 000g" the function returns 0. .IP "" 4 Returns the pigpio version. +.IP "\fBint gpioGetPad(unsigned pad)\fP" +.IP "" 4 +This function returns the pad drive strength in mA. + +.br + +.br + +.EX +pad: 0-2, the pad to get +.br + +.EE + +.br + +.br +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +strength = gpioGetPad(1); // get pad 1 strength +.br + +.EE + +.IP "\fBint gpioSetPad(unsigned pad, unsigned padStrength)\fP" +.IP "" 4 +This function sets the pad drive strength in mA. + +.br + +.br + +.EX + pad: 0-2, the pad to set +.br +padStrength: 1-16 mA +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +gpioSetPad(0, 16); // set pad 0 strength to 16 mA +.br + +.EE + +.IP "\fBint shell(char *scriptName, char *scriptString)\fP" +.IP "" 4 +This function uses the system call to execute a shell script +with the given string as its parameter. + +.br + +.br + +.EX + scriptName: the name of the script, only alphanumeric characters, +.br + '-' and '_' are allowed in the name +.br +scriptString: the string to pass to the script +.br + +.EE + +.br + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br + +.br +scriptName must exist in /opt/pigpio/cgi and must be executable. + +.br + +.br +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +.br + +.br +The following table gives some example returned statuses. + +.br + +.br +Script exit status Returned system call status +.br +1 256 +.br +5 1280 +.br +10 2560 +.br +200 51200 +.br +script not found 32512 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +// pass two parameters, hello and world +.br +status = shell("scr1", "hello world"); +.br + +.br +// pass three parameters, hello, string with spaces, and world +.br +status = shell("scr1", "hello 'string with spaces' world"); +.br + +.br +// pass one parameter, hello string with spaces world +.br +status = shell("scr1", "\"hello string with spaces world\""); +.br + +.EE + +.IP "\fBint fileOpen(char *file, unsigned mode)\fP" +.IP "" 4 +This function returns a handle to a file opened in a specified mode. + +.br + +.br + +.EX +file: the file to open +.br +mode: the file open mode +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +.br + +.br +File + +.br + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br + +.br +Files may be read in directory dir_2. + +.br + +.br +Files may be read and written in directory dir_3. + +.br + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br + +.br +Mode + +.br + +.br +The mode may have the following values. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_READ 1 open file for reading +.br +PI_FILE_WRITE 2 open file for writing +.br +PI_FILE_RW 3 open file for reading and writing +.br + +.br + +.br +The following values may be or'd into the mode. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_APPEND 4 Writes append data to the end of the file +.br +PI_FILE_CREATE 8 The file is created if it doesn't exist +.br +PI_FILE_TRUNC 16 The file is truncated +.br + +.br + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int handle, c; +.br + char buf[60000]; +.br + +.br + if (gpioInitialise() < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + handle = fileOpen("/ram/pigpio.c", PI_FILE_READ); +.br + +.br + if (handle >= 0) +.br + { +.br + while ((c=fileRead(handle, buf, sizeof(buf)-1))) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + fileClose(handle); +.br + } +.br + +.br + gpioTerminate(); +.br +} +.br + +.EE + +.IP "\fBint fileClose(unsigned handle)\fP" +.IP "" 4 +This function closes the file associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\fP +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +\fBExample\fP +.br + +.EX +fileClose(h); +.br + +.EE + +.IP "\fBint fileWrite(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the file +associated with handle. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\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, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +status = fileWrite(h, buf, count); +.br +if (status == 0) +.br +{ +.br + // okay +.br +} +.br +else +.br +{ +.br + // error +.br +} +.br + +.EE + +.IP "\fBint fileRead(unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +.br + +.br + +.EX +handle: >=0, as returned by a call to \fBfileOpen\fP +.br + buf: an array to receive the read data +.br + count: the maximum number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +if (fileRead(h, buf, sizeof(buf)) > 0) +.br +{ +.br + // process read data +.br +} +.br + +.EE + +.IP "\fBint fileSeek(unsigned handle, int32_t seekOffset, int seekFrom)\fP" +.IP "" 4 +This function seeks to a position within the file associated +with handle. + +.br + +.br + +.EX + handle: >=0, as returned by a call to \fBfileOpen\fP +.br +seekOffset: the number of bytes to move. Positive offsets +.br + move forward, negative offsets backwards. +.br + seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), +.br + or PI_FROM_END (2) +.br + +.EE + +.br + +.br +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +.br + +.br +\fBExample\fP +.br + +.EX +fileSeek(0, 20, PI_FROM_START); // Seek to start plus 20 +.br + +.br +size = fileSeek(0, 0, PI_FROM_END); // Seek to end, return size +.br + +.br +pos = fileSeek(0, 0, PI_FROM_CURRENT); // Return current position +.br + +.EE + +.IP "\fBint fileList(char *fpat, char *buf, unsigned count)\fP" +.IP "" 4 +This function returns a list of files which match a pattern. The +pattern may contain wildcards. + +.br + +.br + +.EX + fpat: file pattern to match +.br + buf: an array to receive the matching file names +.br +count: the maximum number of bytes to read +.br + +.EE + +.br + +.br +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +.br + +.br +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See \fBfileOpen\fP. + +.br + +.br +NOTE + +.br + +.br +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int c; +.br + char buf[1000]; +.br + +.br + if (gpioInitialise() < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + c = fileList("/ram/p*.c", buf, sizeof(buf)); +.br + +.br + if (c >= 0) +.br + { +.br + // terminate string +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + gpioTerminate(); +.br +} +.br + +.EE + .IP "\fBint gpioCfgBufferSize(unsigned cfgMillis)\fP" .IP "" 4 Configures pigpio to buffer cfgMillis milliseconds of GPIO samples. @@ -5390,17 +6050,13 @@ If the board revision is not recognised then GPIO 0-31 are allowed. .br Unknown board PI_DEFAULT_UPDATE_MASK_UNKNOWN 0xFFFFFFFF .br - .br Type 1 board PI_DEFAULT_UPDATE_MASK_B1 0x03E6CF93 .br - .br Type 2 board PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC6CF9C - .br Type 3 board PI_DEFAULT_UPDATE_MASK_R3 0x0FFFFFFC - .br .IP "\fBint gpioCfgSocketPort(unsigned port)\fP" @@ -6168,10 +6824,6 @@ PI_HW_CLK_MAX_FREQ 250000000 .br .IP "\fBcount\fP" 0 - -.br - -.br The number of bytes to be transferred in an I2C, SPI, or Serial command. @@ -6246,7 +6898,7 @@ The number may vary between 0 and range (default 255) where .br .IP "\fBedge\fP: 0-2" 0 -The type of GPIO edge to generate an intrrupt. See\fBgpioSetISRFunc\fP, +The type of GPIO edge to generate an intrrupt. See \fBgpioSetISRFunc\fP, and \fBgpioSetISRFuncEx\fP. .br @@ -6278,6 +6930,22 @@ A function. .br +.IP "\fB*file\fP" 0 +A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. + +.br + +.br + +.IP "\fB*fpat\fP" 0 +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + +.br + +.br + .IP "\fBfrequency\fP: >=0" 0 .br @@ -6302,14 +6970,14 @@ A Broadcom numbered GPIO, in the range 0-53. .br .br -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. .br .br -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. .br @@ -6597,18 +7265,8 @@ One of .br .br -A number referencing an object opened by one of - -.br - -.br -\fBi2cOpen\fP -.br -\fBgpioNotifyOpen\fP -.br -\fBserOpen\fP -.br -\fBspiOpen\fP +A number referencing an object opened by one of \fBfileOpen\fP, +\fBgpioNotifyOpen\fP, \fBi2cOpen\fP, \fBserOpen\fP, \fBspiOpen\fP. .br @@ -6689,6 +7347,13 @@ A whole number, negative or positive. .br +.IP "\fBint32_t\fP" 0 +A 32-bit signed value. + +.br + +.br + .IP "\fBinvert\fP" 0 A flag used to set normal or inverted bit bang serial data level logic. @@ -6816,12 +7481,12 @@ A value representing milliseconds. .br -.IP "\fBmode\fP: 0-7" 0 +.IP "\fBmode\fP" 0 .br .br -The operational mode of a GPIO, normally INPUT or OUTPUT. +1. The operational mode of a GPIO, normally INPUT or OUTPUT. .br @@ -6849,6 +7514,44 @@ PI_ALT5 2 .br +.br +2. A file open mode. + +.br + +.br + +.EX +PI_FILE_READ 1 +.br +PI_FILE_WRITE 2 +.br +PI_FILE_RW 3 +.br + +.EE + +.br + +.br +The following values can be or'd into the mode. + +.br + +.br + +.EX +PI_FILE_APPEND 4 +.br +PI_FILE_CREATE 8 +.br +PI_FILE_TRUNC 16 +.br + +.EE + +.br + .br .IP "\fBnumBits\fP" 0 @@ -6914,6 +7617,33 @@ The size in bytes of an output buffer. .br +.IP "\fBpad\fP: 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br + +.IP "\fBpadStrength\fP: 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + +.br + .IP "\fB*param\fP" 0 An array of script parameters. @@ -7251,10 +7981,6 @@ A pointer to a buffer to receive data. .br .IP "\fBSCL\fP" 0 - -.br - -.br The user GPIO to use for the clock when bit banging I2C. .br @@ -7262,10 +7988,6 @@ The user GPIO to use for the clock when bit banging I2C. .br .IP "\fB*script\fP" 0 - -.br - -.br A pointer to the text of a script. .br @@ -7273,21 +7995,28 @@ A pointer to the text of a script. .br .IP "\fBscript_id\fP" 0 - -.br - -.br An id of a stored script as returned by \fBgpioStoreScript\fP. .br .br +.IP "\fB*scriptName\fP" 0 +The name of a \fBshell\fP script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. + +.br + +.br + +.IP "\fB*scriptString\fP" 0 +The string to be passed to a \fBshell\fP script to be executed. + +.br + +.br + .IP "\fBSDA\fP" 0 - -.br - -.br The user GPIO to use for data when bit banging I2C. .br @@ -7318,21 +8047,41 @@ a returned time. .br .IP "\fBseconds\fP" 0 - -.br - -.br The number of seconds. .br .br +.IP "\fBseekFrom\fP" 0 + +.br + +.br + +.EX +PI_FROM_START 0 +.br +PI_FROM_CURRENT 1 +.br +PI_FROM_END 2 +.br + +.EE + +.br + +.br + +.IP "\fBseekOffset\fP" 0 +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + +.br + +.br + .IP "\fB*segs\fP" 0 - -.br - -.br An array of segments which make up a combined I2C transaction. .br @@ -7623,10 +8372,6 @@ See \fBgpio\fP. .br .IP "\fB*userdata\fP" 0 - -.br - -.br A pointer to arbitrary user data. This may be used to identify the instance. .br @@ -7975,6 +8720,30 @@ A 16-bit word value. #define PI_CMD_WVTAT 101 .br +.br +#define PI_CMD_PADS 102 +.br +#define PI_CMD_PADG 103 +.br + +.br +#define PI_CMD_FO 104 +.br +#define PI_CMD_FC 105 +.br +#define PI_CMD_FR 106 +.br +#define PI_CMD_FW 107 +.br +#define PI_CMD_FS 108 +.br +#define PI_CMD_FL 109 +.br + +.br +#define PI_CMD_SHELL 110 +.br + .br .EE @@ -8061,7 +8830,7 @@ A 16-bit word value. .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 +#define PI_NOT_SERIAL_GPIO -38 // no bit bang serial read on GPIO .br #define PI_BAD_SERIAL_STRUC -39 // bad (null) serial structure parameter .br @@ -8235,10 +9004,40 @@ A 16-bit word value. .br #define PI_BAD_ISR_INIT -123 // bad ISR initialisation .br -#define PI_BAD_FOREVER -124 // loop forever must be last chain command +#define PI_BAD_FOREVER -124 // loop forever must be last command .br #define PI_BAD_FILTER -125 // bad filter parameter .br +#define PI_BAD_PAD -126 // bad pad number +.br +#define PI_BAD_STRENGTH -127 // bad pad drive strength +.br +#define PI_FIL_OPEN_FAILED -128 // file open failed +.br +#define PI_BAD_FILE_MODE -129 // bad file mode +.br +#define PI_BAD_FILE_FLAG -130 // bad file flag +.br +#define PI_BAD_FILE_READ -131 // bad file read +.br +#define PI_BAD_FILE_WRITE -132 // bad file write +.br +#define PI_FILE_NOT_ROPEN -133 // file not open for read +.br +#define PI_FILE_NOT_WOPEN -134 // file not open for write +.br +#define PI_BAD_FILE_SEEK -135 // bad file seek +.br +#define PI_NO_FILE_MATCH -136 // no files match pattern +.br +#define PI_NO_FILE_ACCESS -137 // no permission to access file +.br +#define PI_FILE_IS_A_DIR -138 // file is a directory +.br +#define PI_BAD_SHELL_STATUS -139 // bad shell return status +.br +#define PI_BAD_SCRIPT_NAME -140 // bad script name +.br .br #define PI_PIGIF_ERR_0 -2000 diff --git a/pigpio.c b/pigpio.c index 4588b38..3f0b2f8 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 54 */ +/* pigpio version 55 */ /* include ------------------------------------------------------- */ @@ -58,11 +58,14 @@ For more information, please refer to #include #include #include +#include +#include #include "pigpio.h" #include "command.h" + /* --------------------------------------------------------------- */ /* @@ -299,6 +302,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define DMA_BASE (pi_peri_phys + 0x00007000) #define DMA15_BASE (pi_peri_phys + 0x00E05000) #define GPIO_BASE (pi_peri_phys + 0x00200000) +#define PADS_BASE (pi_peri_phys + 0x00100000) #define PCM_BASE (pi_peri_phys + 0x00203000) #define PWM_BASE (pi_peri_phys + 0x0020C000) #define SPI_BASE (pi_peri_phys + 0x00204000) @@ -308,6 +312,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define CLK_LEN 0xA8 #define DMA_LEN 0x1000 /* allow access to all channels */ #define GPIO_LEN 0xB4 +#define PADS_LEN 0x38 #define PCM_LEN 0x24 #define PWM_LEN 0x28 #define SPI_LEN 0x18 @@ -474,7 +479,7 @@ bit 0 READ_LAST_NOT_SET_ERROR #define PCM_GRAY_CLR (1<<1) #define PCM_GRAY_EN (1<<0) -#define CLK_PASSWD (0x5A<<24) +#define BCM_PASSWD (0x5A<<24) #define CLK_CTL_MASH(x)((x)<<9) #define CLK_CTL_BUSY (1 <<7) @@ -734,6 +739,9 @@ Assumes two counters per block. Each counter 4 * 16 (16^4=65536) #define PI_SER_CLOSED 0 #define PI_SER_OPENED 1 +#define PI_FILE_CLOSED 0 +#define PI_FILE_OPENED 1 + #define PI_NOTIFY_CLOSED 0 #define PI_NOTIFY_CLOSING 1 #define PI_NOTIFY_OPENED 2 @@ -843,6 +851,8 @@ Assumes two counters per block. Each counter 4 * 16 (16^4=65536) #define PI_RUNNING 1 #define PI_ENDING 2 +#define PI_MAX_PATH 512 + /* typedef ------------------------------------------------------- */ typedef void (*callbk_t) (); @@ -975,6 +985,13 @@ typedef struct int max_emits; } gpioNotify_t; +typedef struct +{ + uint16_t state; + int16_t fd; + uint32_t mode; +} fileInfo_t; + typedef struct { uint16_t state; @@ -1202,6 +1219,7 @@ static gpioInfo_t gpioInfo [PI_MAX_GPIO+1]; static gpioNotify_t gpioNotify [PI_NOTIFY_SLOTS]; +static fileInfo_t fileInfo [PI_FILE_SLOTS]; static i2cInfo_t i2cInfo [PI_I2C_SLOTS]; static serInfo_t serInfo [PI_SER_SLOTS]; static spiInfo_t spiInfo [PI_SPI_SLOTS]; @@ -1242,6 +1260,7 @@ static volatile uint32_t * auxReg = MAP_FAILED; static volatile uint32_t * clkReg = MAP_FAILED; static volatile uint32_t * dmaReg = MAP_FAILED; static volatile uint32_t * gpioReg = MAP_FAILED; +static volatile uint32_t * padsReg = MAP_FAILED; static volatile uint32_t * pcmReg = MAP_FAILED; static volatile uint32_t * pwmReg = MAP_FAILED; static volatile uint32_t * spiReg = MAP_FAILED; @@ -1408,6 +1427,29 @@ static void closeOrphanedNotifications(int slot, int fd); /* ======================================================================= */ +int myScriptNameValid(char *name) +{ + int i, c, len, valid; + + len = strlen(name); + + valid = 1; + + for (i=0; i bufSize) p[1] = bufSize; + res = fileList(buf, buf, p[1]); + break; + case PI_CMD_FN: memcpy(&p[4], buf, 4); res = gpioNoiseFilter(p[1], p[2], p[4]); break; + case PI_CMD_FO: res = fileOpen(buf, p[1]); break; + + case PI_CMD_FR: + if (p[2] > bufSize) p[2] = bufSize; + res = fileRead(p[1], buf, p[2]); + break; + + case PI_CMD_FS: + memcpy(&p[4], buf, 4); + res = fileSeek(p[1], p[2], p[4]); + break; + + case PI_CMD_FW: res = fileWrite(p[1], buf, p[3]); break; + case PI_CMD_GDC: res = gpioGetPWMdutycycle(p[1]); break; case PI_CMD_GPW: res = gpioGetServoPulsewidth(p[1]); break; @@ -1923,6 +2027,10 @@ static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf) case PI_CMD_NP: res = gpioNotifyPause(p[1]); break; + case PI_CMD_PADG: res = gpioGetPad(p[1]); break; + + case PI_CMD_PADS: res = gpioSetPad(p[1], p[2]); break; + case PI_CMD_PFG: res = gpioGetPWMfrequency(p[1]); break; case PI_CMD_PFS: @@ -2018,6 +2126,10 @@ static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf) case PI_CMD_SERW: res = serWrite(p[1], buf, p[3]); break; + case PI_CMD_SHELL: + res = shell(buf, buf+p[1]+1); + break; + case PI_CMD_SLR: if (p[2] > bufSize) p[2] = bufSize; @@ -4477,7 +4589,7 @@ int serOpen(char *tty, unsigned serBaud, unsigned serFlags) SER_CHECK_INITED; - if (strncmp("/dev/tty", tty, 8)) + if (strncmp("/dev/tty", tty, 8) && strncmp("/dev/serial", tty, 11)) SOFT_ERROR(PI_BAD_SER_DEVICE, "bad device (%s)", tty); switch (serBaud) @@ -6022,17 +6134,21 @@ static int scrWait(gpioScript_t *s, uint32_t bits) static int scrSys(char *cmd, uint32_t p1, uint32_t p2) { - char buf[256]; - char pars[40]; + char buf[1024]; + int status; - sprintf(pars, " %u %u", p1, p2); - strcpy(buf, "/opt/pigpio/cgi/"); - strncat(buf, cmd, 200); - strcat(buf, pars); + if (!myScriptNameValid(cmd)) + SOFT_ERROR(PI_BAD_SCRIPT_NAME, "bad script name (%s)", cmd); - DBG(DBG_USER, "sys %s", buf); + snprintf(buf, sizeof(buf), "/opt/pigpio/cgi/%s %u %u", cmd, p1, p2); - return system(buf); + DBG(DBG_USER, "%s", buf); + + status = system(buf); + + if (status < 0) status = PI_BAD_SHELL_STATUS; + + return status; } /* ----------------------------------------------------------------------- */ @@ -6523,6 +6639,8 @@ static void *pthSocketThreadHandler(void *fdC) case PI_CMD_BI2CZ: case PI_CMD_CF2: + case PI_CMD_FL: + case PI_CMD_FR: case PI_CMD_I2CPK: case PI_CMD_I2CRD: case PI_CMD_I2CRI: @@ -6769,6 +6887,11 @@ static int initPeripherals(void) if (auxReg == MAP_FAILED) SOFT_ERROR(PI_INIT_FAILED, "mmap aux failed (%m)"); + padsReg = initMapMem(fdMem, PADS_BASE, PADS_LEN); + + if (padsReg == MAP_FAILED) + SOFT_ERROR(PI_INIT_FAILED, "mmap pads failed (%m)"); + return 0; } @@ -7170,20 +7293,20 @@ static void initHWClk { do { - clkReg[clkCtl] = CLK_PASSWD | CLK_CTL_KILL; + clkReg[clkCtl] = BCM_PASSWD | CLK_CTL_KILL; } while (clkReg[clkCtl] & CLK_CTL_BUSY); } - clkReg[clkDiv] = (CLK_PASSWD | CLK_DIV_DIVI(divI) | CLK_DIV_DIVF(divF)); + clkReg[clkDiv] = (BCM_PASSWD | CLK_DIV_DIVI(divI) | CLK_DIV_DIVF(divF)); usleep(10); - clkReg[clkCtl] = (CLK_PASSWD | CLK_CTL_MASH(MASH) | CLK_CTL_SRC(clkSrc)); + clkReg[clkCtl] = (BCM_PASSWD | CLK_CTL_MASH(MASH) | CLK_CTL_SRC(clkSrc)); usleep(10); - clkReg[clkCtl] |= (CLK_PASSWD | CLK_CTL_ENAB); + clkReg[clkCtl] |= (BCM_PASSWD | CLK_CTL_ENAB); } static void initClock(int mainClock) @@ -11345,7 +11468,7 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency) else { /* frequency 0, stop clock */ - clkReg[cctl[clock]] = CLK_PASSWD | CLK_CTL_KILL; + clkReg[cctl[clock]] = BCM_PASSWD | CLK_CTL_KILL; if (gpioInfo[gpio].is == GPIO_HW_CLK) gpioInfo[gpio].is = GPIO_UNDEFINED; @@ -11470,6 +11593,403 @@ int gpioHardwarePWM( } +int gpioSetPad(unsigned pad, unsigned padStrength) +{ + DBG(DBG_USER, "pad=%d padStrength=%d", pad, padStrength); + + CHECK_INITED; + + if (pad > PI_MAX_PAD) + SOFT_ERROR(PI_BAD_PAD, "bad pad number (%d)", pad); + + if ((padStrength < PI_MIN_PAD_STRENGTH) || + (padStrength > PI_MAX_PAD_STRENGTH)) + SOFT_ERROR(PI_BAD_STRENGTH, "bad pad drive strength (%d)", pad); + + /* 1-16 -> 0-7 */ + + padStrength += 1; + padStrength /= 2; + padStrength -= 1; + + padsReg[11+pad] = BCM_PASSWD | 0x18 | (padStrength & 7) ; + + return 0; +} + +int gpioGetPad(unsigned pad) +{ + int strength; + + DBG(DBG_USER, "pad=%d", pad); + + CHECK_INITED; + + if (pad > PI_MAX_PAD) + SOFT_ERROR(PI_BAD_PAD, "bad pad (%d)", pad); + + strength = padsReg[11+pad] & 7; + + strength *= 2; + strength += 2; + + return strength; +} + +int shell(char *scriptName, char *scriptString) +{ + int status; + char buf[4096]; + + DBG(DBG_USER, "name=%s string=%s", scriptName, scriptString); + + CHECK_INITED; + + if (!myScriptNameValid(scriptName)) + SOFT_ERROR(PI_BAD_SCRIPT_NAME, "bad script name (%s)", scriptName); + + snprintf(buf, sizeof(buf), + "/opt/pigpio/cgi/%s %s", scriptName, scriptString); + + DBG(DBG_USER, "%s", buf); + + status = system(buf); + + if (status < 0) status = PI_BAD_SHELL_STATUS; + + return status; +} + + +int fileApprove(char *filename) +{ + char match[PI_MAX_PATH]; + char buffer[PI_MAX_PATH]; + char line[PI_MAX_PATH]; + char mperm; + char perm; + char term; + FILE *f; + + buffer[0] = 0; + match[0] = 0; + + f = fopen("/opt/pigpio/access", "r"); + + if (!f) return PI_FILE_NONE; + + while (!feof(f)) + { + buffer[0] = 0; + perm = 0; + term = 0; + if (fgets(line, sizeof(line), f)) + { + sscanf(line, " %511s %c%c", buffer, &perm, &term); + if (term == 10) + { + if (myPathBad(buffer)) continue; /* disallow risky lines */ + + if (fnmatch(buffer, filename, 0) == 0) + { + if (match[0]) + { + if (fnmatch(match, buffer, 0) == 0) + { + strcpy(match, buffer); + mperm = perm; + } + } + else + { + strcpy(match, buffer); + mperm = perm; + } + } + } + } + } + + fclose(f); + + if (match[0]) + { + switch (toupper(mperm)) + { + case 'R': return PI_FILE_READ; + case 'W': return PI_FILE_WRITE; + case 'U': return PI_FILE_RW; + default : return PI_FILE_NONE; + } + } + + return PI_FILE_NONE; +} + +int fileOpen(char *file, unsigned mode) +{ + int fd=-1; + int i, slot, oflag, omode; + struct stat statbuf; + + DBG(DBG_USER, "file=%s mode=%d", file, mode); + + CHECK_INITED; + + if ( (mode < PI_FILE_MIN) || + (mode > PI_FILE_MAX) || + ((mode & PI_FILE_RW) == 0) ) + SOFT_ERROR(PI_BAD_FILE_MODE, "bad mode (%d)", mode); + + if ((fileApprove(file) & mode) == PI_FILE_NONE) + SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", file); + + slot = -1; + + for (i=0; i= PI_FILE_SLOTS) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (fileInfo[handle].state != PI_FILE_OPENED) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (fileInfo[handle].fd >= 0) close(fileInfo[handle].fd); + + fileInfo[handle].fd = -1; + fileInfo[handle].state = PI_FILE_CLOSED; + + return 0; +} + +int fileWrite(unsigned handle, char *buf, unsigned count) +{ + int w; + + DBG(DBG_USER, "handle=%d count=%d [%s]", + handle, count, myBuf2Str(count, buf)); + + CHECK_INITED; + + if (handle >= PI_FILE_SLOTS) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (fileInfo[handle].state != PI_FILE_OPENED) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (!count) + SOFT_ERROR(PI_BAD_PARAM, "bad count (%d)", count); + + if (!(fileInfo[handle].mode & PI_FILE_WRITE)) + SOFT_ERROR(PI_FILE_NOT_WOPEN, "file not opened for write"); + + w = write(fileInfo[handle].fd, buf, count); + + if (w != count) + { + if (w == -1) DBG(DBG_USER, "write failed with errno %d", errno); + + return PI_BAD_FILE_WRITE; + } + return 0; +} + +int fileRead(unsigned handle, char *buf, unsigned count) +{ + int r; + + DBG(DBG_USER, "handle=%d count=%d buf=0x%X", handle, count, (unsigned)buf); + + CHECK_INITED; + + if (handle >= PI_FILE_SLOTS) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (fileInfo[handle].state != PI_FILE_OPENED) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (!count) + SOFT_ERROR(PI_BAD_PARAM, "bad count (%d)", count); + + if (!(fileInfo[handle].mode & PI_FILE_READ)) + SOFT_ERROR(PI_FILE_NOT_ROPEN, "file not opened for read"); + + r = read(fileInfo[handle].fd, buf, count); + + if (r == -1) + { + DBG(DBG_USER, "read failed with errno %d", errno); + return PI_BAD_FILE_READ; + } + else + { + buf[r] = 0; + return r; + } +} + + +int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom) +{ + int whence, s; + + DBG(DBG_USER, "handle=%d offset=%d from=%d", + handle, seekOffset, seekFrom); + + CHECK_INITED; + + if (handle >= PI_FILE_SLOTS) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + if (fileInfo[handle].state != PI_FILE_OPENED) + SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); + + switch (seekFrom) + { + case PI_FROM_START: + whence = SEEK_SET; + break; + + case PI_FROM_CURRENT: + whence = SEEK_CUR; + break; + + case PI_FROM_END: + whence = SEEK_END; + break; + + default: + SOFT_ERROR(PI_BAD_FILE_SEEK, "bad seek from (%d)", seekFrom); + } + + s = lseek(fileInfo[handle].fd, seekOffset, whence); + + if (s == -1) + { + DBG(DBG_USER, "seek failed with errno %d", errno); + return PI_BAD_FILE_SEEK; + } + + return s; +} + +int fileList(char *fpat, char *buf, unsigned count) +{ + int len, bufpos; + glob_t pglob; + int i; + + DBG(DBG_USER, "fpat=%s count=%d buf=%x", fpat, count, (unsigned)buf); + + CHECK_INITED; + + if (fileApprove(fpat) == PI_FILE_NONE) + SOFT_ERROR(PI_NO_FILE_ACCESS, "no permission to access file (%s)", fpat); + + bufpos = 0; + + if (glob(fpat, GLOB_MARK, NULL, &pglob) == 0) + { + for (i=0; i #include #include -#define PIGPIO_VERSION 54 +#define PIGPIO_VERSION 55 /*TEXT @@ -39,9 +39,9 @@ pigpio is a C library for the Raspberry which allows control of the GPIO. *Features* -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 o callbacks when any of GPIO 0-31 change state @@ -198,6 +198,11 @@ gpioHardwarePWM Start hardware PWM on supported GPIO gpioGlitchFilter Set a glitch filter on a GPIO gpioNoiseFilter Set a noise filter on a GPIO +gpioGetPad Gets a pads drive strength +gpioSetPad Sets a pads drive strength + +shell Executes a shell command + SCRIPTS gpioStoreScript Store a script @@ -282,16 +287,25 @@ spiXfer Transfers bytes with a SPI device SERIAL -serOpen Opens a serial device (/dev/tty*) +serOpen Opens a serial device serClose Closes a serial device -serWriteByte Writes a byte to a serial device serReadByte Reads a byte from a serial device -serWrite Writes bytes to 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 +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 + CONFIGURATION gpioCfgBufferSize Configure the GPIO sample buffer size @@ -617,8 +631,9 @@ typedef void *(gpioThreadFunc_t) (void *); #define PI_WAVE_NOT_FOUND 9998 /* Transmitted wave not found. */ #define PI_NO_TX_WAVE 9999 /* No wave being transmitted. */ -/* I2C, SPI, SER */ +/* Files, I2C, SPI, SER */ +#define PI_FILE_SLOTS 8 #define PI_I2C_SLOTS 32 #define PI_SPI_SLOTS 16 #define PI_SER_SLOTS 8 @@ -773,6 +788,29 @@ typedef void *(gpioThreadFunc_t) (void *); #define EITHER_EDGE 2 +/* pads */ + +#define PI_MAX_PAD 2 + +#define PI_MIN_PAD_STRENGTH 1 +#define PI_MAX_PAD_STRENGTH 16 + +/* files */ + +#define PI_FILE_NONE 0 +#define PI_FILE_MIN 1 +#define PI_FILE_READ 1 +#define PI_FILE_WRITE 2 +#define PI_FILE_RW 3 +#define PI_FILE_APPEND 4 +#define PI_FILE_CREATE 8 +#define PI_FILE_TRUNC 16 +#define PI_FILE_MAX 31 + +#define PI_FROM_START 0 +#define PI_FROM_CURRENT 1 +#define PI_FROM_END 2 + /*F*/ int gpioInitialise(void); /*D @@ -835,11 +873,11 @@ Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE. Arduino style: pinMode. ... -gpioSetMode(17, PI_INPUT); // Set gpio17 as input. +gpioSetMode(17, PI_INPUT); // Set GPIO17 as input. -gpioSetMode(18, PI_OUTPUT); // Set gpio18 as output. +gpioSetMode(18, PI_OUTPUT); // Set GPIO18 as output. -gpioSetMode(22,PI_ALT0); // Set gpio22 to alternative mode 0. +gpioSetMode(22,PI_ALT0); // Set GPIO22 to alternative mode 0. ... D*/ @@ -858,7 +896,7 @@ Returns the GPIO mode if OK, otherwise PI_BAD_GPIO. ... if (gpioGetMode(17) != PI_ALT0) { - gpioSetMode(17, PI_ALT0); // set gpio17 to ALT0 + gpioSetMode(17, PI_ALT0); // set GPIO17 to ALT0 } ... D*/ @@ -900,7 +938,7 @@ Returns the GPIO level if OK, otherwise PI_BAD_GPIO. Arduino style: digitalRead. ... -printf("gpio24 is level %d", gpioRead(24)); +printf("GPIO24 is level %d", gpioRead(24)); ... D*/ @@ -922,7 +960,7 @@ If PWM or servo pulses are active on the GPIO they are switched off. Arduino style: digitalWrite ... -gpioWrite(24, 1); // Set gpio24 high. +gpioWrite(24, 1); // Set GPIO24 high. ... D*/ @@ -949,11 +987,11 @@ The [*gpioSetPWMrange*] function may be used to change the default range of 255. ... -gpioPWM(17, 255); // Sets gpio17 full on. +gpioPWM(17, 255); // Sets GPIO17 full on. -gpioPWM(18, 128); // Sets gpio18 half on. +gpioPWM(18, 128); // Sets GPIO18 half on. -gpioPWM(23, 0); // Sets gpio23 full off. +gpioPWM(23, 0); // Sets GPIO23 full off. ... D*/ @@ -1107,11 +1145,11 @@ sample . . ... -gpioSetPWMfrequency(23, 0); // Set gpio23 to lowest frequency. +gpioSetPWMfrequency(23, 0); // Set GPIO23 to lowest frequency. -gpioSetPWMfrequency(24, 500); // Set gpio24 to 500Hz. +gpioSetPWMfrequency(24, 500); // Set GPIO24 to 500Hz. -gpioSetPWMfrequency(25, 100000); // Set gpio25 to highest frequency. +gpioSetPWMfrequency(25, 100000); // Set GPIO25 to highest frequency. ... D*/ @@ -1136,7 +1174,7 @@ If hardware PWM is active on the GPIO the reported frequency will be that set by [*gpioHardwarePWM*]. ... -f = gpioGetPWMfrequency(23); // Get frequency used for gpio23. +f = gpioGetPWMfrequency(23); // Get frequency used for GPIO23. ... D*/ @@ -1187,7 +1225,7 @@ Then set the PWM range using [*gpioSetPWMrange*] to 1E6/frequency. Doing this allows you to use units of microseconds when setting the servo pulsewidth. -E.g. If you want to update a servo connected to gpio25 at 400Hz +E.g. If you want to update a servo connected to GPIO25 at 400Hz . . gpioSetPWMfrequency(25, 400); @@ -1474,11 +1512,13 @@ seqno: starts at 0 each time the handle is opened and then increments by one for each report. flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. -If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags -indicate a GPIO which has had a watchdog timeout; if bit 6 is set -(PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the -pipe/socket and is sent once a minute in the absence of other -notification activity. + +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. tick: the number of microseconds since system boot. It wraps around after 1h12m. @@ -2011,7 +2051,7 @@ int gpioSerialReadInvert(unsigned user_gpio, unsigned invert); /*D This function configures the level logic for bit bang serial reads. -Pass PI_BB_SER_INVERT to invert the serial logic. Pass PI_BB_SER_NORMAL for +Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for normal logic. Default is PI_BB_SER_NORMAL. . . @@ -2798,10 +2838,11 @@ D*/ int serOpen(char *sertty, unsigned baud, unsigned serFlags); /*D This function opens a serial device at a specified baud rate -with specified flags. +and with specified flags. The device name must start with +/dev/tty or /dev/serial. . . - sertty: the serial device to open, /dev/tty* + sertty: the serial device to open baud: the baud rate in bits per second, see below serFlags: 0 . . @@ -2879,13 +2920,13 @@ This function reads up count bytes from the the serial port associated with handle and writes them to buf. . . -handle: >=0, as returned by a call to serial_open +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 . . 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. +PI_BAD_PARAM, or PI_SER_READ_NO_DATA. D*/ @@ -3631,6 +3672,358 @@ Returns the pigpio version. D*/ +/*F*/ +int gpioGetPad(unsigned pad); +/*D +This function returns the pad drive strength in mA. + +. . +pad: 0-2, the pad to get +. . + +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +... +strength = gpioGetPad(1); // get pad 1 strength +... +D*/ + + +/*F*/ +int gpioSetPad(unsigned pad, unsigned padStrength); +/*D +This function sets the pad drive strength in mA. + +. . + pad: 0-2, the pad to set +padStrength: 1-16 mA +. . + +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +... +gpioSetPad(0, 16); // set pad 0 strength to 16 mA +... +D*/ + + +/*F*/ +int shell(char *scriptName, char *scriptString); +/*D +This function uses the system call to execute a shell script +with the given string as its parameter. + +. . + scriptName: the name of the script, only alphanumeric characters, + '-' and '_' are allowed in the name +scriptString: the string to pass to the script +. . + +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +scriptName must exist in /opt/pigpio/cgi and must be executable. + +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +The following table gives some example returned statuses. + +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\""); +... +D*/ + +#pragma GCC diagnostic push + +#pragma GCC diagnostic ignored "-Wcomment" + +/*F*/ +int fileOpen(char *file, unsigned mode); +/*D +This function returns a handle to a file opened in a specified mode. + +. . +file: the file to open +mode: the file open mode +. . + +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +File + +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +Suppose /opt/pigpio/access contains the following entries + +. . +/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 +. . + +Files may be written in directory dir_1 with the exception +of file.txt. + +Files may be read in directory dir_2. + +Files may be read and written in directory dir_3. + +If a directory allows read, write, or read/write access then files may +be created in that directory. + +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +. . +a path containing .. +a path containing only wildcards (*?) +a path containing less than two non-wildcard parts +. . + +Mode + +The mode may have the following values. + +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 + +The following values may be or'd into the mode. + +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 + +Newly created files are owned by root with permissions owner read and write. + +... +#include +#include + +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(); +} +... +D*/ + +#pragma GCC diagnostic pop + +/*F*/ +int fileClose(unsigned handle); +/*D +This function closes the file associated with handle. + +. . +handle: >=0, as returned by a call to [*fileOpen*] +. . + +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +... +fileClose(h); +... +D*/ + + +/*F*/ +int fileWrite(unsigned handle, char *buf, unsigned count); +/*D +This function writes count bytes from buf to the the file +associated with handle. + +. . +handle: >=0, as returned by a call to [*fileOpen*] + buf: the array of bytes to write + count: the number of bytes to write +. . + +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +... +status = fileWrite(h, buf, count); +if (status == 0) +{ + // okay +} +else +{ + // error +} +... +D*/ + + +/*F*/ +int fileRead(unsigned handle, char *buf, unsigned count); +/*D +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +. . +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 +. . + +Returns the number of bytes read (>=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +... +if (fileRead(h, buf, sizeof(buf)) > 0) +{ + // process read data +} +... +D*/ + + +/*F*/ +int fileSeek(unsigned handle, int32_t seekOffset, int seekFrom); +/*D +This function seeks to a position within the file associated +with handle. + +. . + 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) +. . + +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +... +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 +... +D*/ + +#pragma GCC diagnostic push + +#pragma GCC diagnostic ignored "-Wcomment" + +/*F*/ +int fileList(char *fpat, char *buf, unsigned count); +/*D +This function returns a list of files which match a pattern. The +pattern may contain wildcards. + +. . + fpat: file pattern to match + buf: an array to receive the matching file names +count: the maximum number of bytes to read +. . + +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See [*fileOpen*]. + +NOTE + +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +... +#include +#include + +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(); +} +... +D*/ + +#pragma GCC diagnostic pop + + /*F*/ int gpioCfgBufferSize(unsigned cfgMillis); /*D @@ -4219,7 +4612,6 @@ PI_HW_CLK_MAX_FREQ 250000000 . . count:: - The number of bytes to be transferred in an I2C, SPI, or Serial command. @@ -4251,7 +4643,7 @@ The number may vary between 0 and range (default 255) where 0 is off and range is fully on. edge::0-2 -The type of GPIO edge to generate an intrrupt. See[*gpioSetISRFunc*], +The type of GPIO edge to generate an intrrupt. See [*gpioSetISRFunc*], and [*gpioSetISRFuncEx*]. . . @@ -4264,6 +4656,14 @@ f:: A function. +*file:: +A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. + +*fpat:: +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + frequency::>=0 The number of times a GPIO is swiched on and off per second. This @@ -4275,11 +4675,11 @@ gpio:: A Broadcom numbered GPIO, in the range 0-53. -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. All the GPIO which are safe for the user to read and write are in bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards @@ -4403,12 +4803,8 @@ One of handle::>=0 -A number referencing an object opened by one of - -[*i2cOpen*] -[*gpioNotifyOpen*] -[*serOpen*] -[*spiOpen*] +A number referencing an object opened by one of [*fileOpen*], +[*gpioNotifyOpen*], [*i2cOpen*], [*serOpen*], [*spiOpen*]. i2cAddr:: 0-0x7F The address of a device on the I2C bus. @@ -4440,6 +4836,9 @@ The number of bytes of data in a buffer. int:: A whole number, negative or positive. +int32_t:: +A 32-bit signed value. + invert:: A flag used to set normal or inverted bit bang serial data level logic. @@ -4491,9 +4890,9 @@ millis:: A value representing milliseconds. -mode::0-7 +mode:: -The operational mode of a GPIO, normally INPUT or OUTPUT. +1. The operational mode of a GPIO, normally INPUT or OUTPUT. . . PI_INPUT 0 @@ -4506,6 +4905,22 @@ PI_ALT4 3 PI_ALT5 2 . . +2. A file open mode. + +. . +PI_FILE_READ 1 +PI_FILE_WRITE 2 +PI_FILE_RW 3 +. . + +The following values can be or'd into the mode. + +. . +PI_FILE_APPEND 4 +PI_FILE_CREATE 8 +PI_FILE_TRUNC 16 +. . + numBits:: The number of bits stored in a buffer. @@ -4534,6 +4949,18 @@ A buffer used to return data from a function. outLen:: The size in bytes of an output buffer. +pad:: 0-2 +A set of GPIO which share common drivers. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +padStrength:: 1-16 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + *param:: An array of script parameters. @@ -4680,19 +5107,22 @@ The maximum number of bytes a user customised function should return. A pointer to a buffer to receive data. SCL:: - The user GPIO to use for the clock when bit banging I2C. *script:: - A pointer to the text of a script. script_id:: - An id of a stored script as returned by [*gpioStoreScript*]. -SDA:: +*scriptName:: +The name of a [*shell*] script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. +*scriptString:: +The string to be passed to a [*shell*] script to be executed. + +SDA:: The user GPIO to use for data when bit banging I2C. secondaryChannel:: 0-6 @@ -4705,11 +5135,21 @@ A pointer to a uint32_t to store the second component of a returned time. seconds:: - The number of seconds. -*segs:: +seekFrom:: +. . +PI_FROM_START 0 +PI_FROM_CURRENT 1 +PI_FROM_END 2 +. . + +seekOffset:: +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + +*segs:: An array of segments which make up a combined I2C transaction. serFlags:: @@ -4830,7 +5270,6 @@ user_gpio:: See [*gpio*]. *userdata:: - A pointer to arbitrary user data. This may be used to identify the instance. You must ensure that the pointer is in scope at the time it is processed. If @@ -4999,6 +5438,18 @@ PARAMS*/ #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 + /*DEF_E*/ /* @@ -5099,7 +5550,7 @@ after this command is issued. #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 in progress on GPIO +#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 @@ -5186,8 +5637,23 @@ after this command is issued. #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 chain command +#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_PIGIF_ERR_0 -2000 #define PI_PIGIF_ERR_99 -2099 diff --git a/pigpio.py b/pigpio.py index 55bdc75..0fdddba 100644 --- a/pigpio.py +++ b/pigpio.py @@ -11,9 +11,9 @@ o the pigpio Python module can run on Windows, Macs, or Linux o controls one or more Pi's -o independent PWM on any of GPIO 0-31 simultaneously +o hardware timed PWM on any of GPIO 0-31 -o independent servo pulses on any of GPIO 0-31 simultaneously +o hardware timed servo pulses on any of GPIO 0-31 o callbacks when any of GPIO 0-31 change state @@ -159,6 +159,11 @@ hardware_PWM Start hardware PWM on supported GPIO set_glitch_filter Set a glitch filter on a GPIO set_noise_filter Set a noise filter on a GPIO +get_pad_strength Gets a pads drive strength +set_pad_strength Sets a pads drive strength + +shell Executes a shell command + Scripts store_script Store a script @@ -235,7 +240,7 @@ spi_xfer Transfers bytes with a SPI device Serial -serial_open Opens a serial device (/dev/tty*) +serial_open Opens a serial device serial_close Closes a serial device serial_read Reads bytes from a serial device @@ -246,7 +251,16 @@ serial_write_byte Writes a byte to a serial device serial_data_available Returns number of bytes ready to be read -CUSTOM +Files + +file_open Opens a file +file_close Closes a file +file_read Reads bytes from a file +file_write Writes bytes to a file +file_seek Seeks to a position within a file +file_list List files which match a pattern + +Custom custom_1 User custom function 1 custom_2 User custom function 2 @@ -270,7 +284,7 @@ import threading import os import atexit -VERSION = "1.31" +VERSION = "1.32" exceptions = True @@ -333,6 +347,18 @@ WAVE_MODE_REPEAT_SYNC =3 WAVE_NOT_FOUND = 9998 # Transmitted wave not found. NO_TX_WAVE = 9999 # No wave being transmitted. +FILE_READ=1 +FILE_WRITE=2 +FILE_RW=3 + +FILE_APPEND=4 +FILE_CREATE=8 +FILE_TRUNC=16 + +FROM_START=0 +FROM_CURRENT=1 +FROM_END=2 + # pigpio command numbers _PI_CMD_MODES= 0 @@ -460,6 +486,17 @@ _PI_CMD_FN =98 _PI_CMD_WVTXM=100 _PI_CMD_WVTAT=101 +_PI_CMD_PADS =102 +_PI_CMD_PADG =103 + +_PI_CMD_FO =104 +_PI_CMD_FC =105 +_PI_CMD_FR =106 +_PI_CMD_FW =107 +_PI_CMD_FS =108 +_PI_CMD_FL =109 +_PI_CMD_SHELL=110 + # pigpio error numbers _PI_INIT_FAILED =-1 @@ -588,7 +625,21 @@ _PI_BAD_EDGE =-122 _PI_BAD_ISR_INIT =-123 PI_BAD_FOREVER =-124 PI_BAD_FILTER =-125 - +PI_BAD_PAD =-126 +PI_BAD_STRENGTH =-127 +PI_FIL_OPEN_FAILED =-128 +PI_BAD_FILE_MODE =-129 +PI_BAD_FILE_FLAG =-130 +PI_BAD_FILE_READ =-131 +PI_BAD_FILE_WRITE =-132 +PI_FILE_NOT_ROPEN =-133 +PI_FILE_NOT_WOPEN =-134 +PI_BAD_FILE_SEEK =-135 +PI_NO_FILE_MATCH =-136 +PI_NO_FILE_ACCESS =-137 +PI_FILE_IS_A_DIR =-138 +PI_BAD_SHELL_STATUS =-139 +PI_BAD_SCRIPT_NAME =-140 # pigpio error text @@ -716,6 +767,21 @@ _errors=[ [_PI_BAD_ISR_INIT , "bad ISR initialisation"], [PI_BAD_FOREVER , "loop forever must be last chain command"], [PI_BAD_FILTER , "bad filter parameter"], + [PI_BAD_PAD , "bad pad number"], + [PI_BAD_STRENGTH , "bad pad drive strength"], + [PI_FIL_OPEN_FAILED , "file open failed"], + [PI_BAD_FILE_MODE , "bad file mode"], + [PI_BAD_FILE_FLAG , "bad file flag"], + [PI_BAD_FILE_READ , "bad file read"], + [PI_BAD_FILE_WRITE , "bad file write"], + [PI_FILE_NOT_ROPEN , "file not open for read"], + [PI_FILE_NOT_WOPEN , "file not open for write"], + [PI_BAD_FILE_SEEK , "bad file seek"], + [PI_NO_FILE_MATCH , "no files match pattern"], + [PI_NO_FILE_ACCESS , "no permission to access file"], + [PI_FILE_IS_A_DIR , "file is a directory"], + [PI_BAD_SHELL_STATUS , "bad shell return status"], + [PI_BAD_SCRIPT_NAME , "bad script name"], ] @@ -1396,8 +1462,8 @@ class pi(): Notifications have the following structure. . . - I seqno - I flags + H seqno + H flags I tick I level . . @@ -1406,11 +1472,14 @@ class pi(): increments by one for each report. flags: two flags are defined, PI_NTFY_FLAGS_WDOG and - PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) - then bits 0-4 of the flags indicate a GPIO which has had a - watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this - indicates a keep alive signal on the pipe/socket and is sent - once a minute in the absence of other notification activity. + PI_NTFY_FLAGS_ALIVE. + + PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the + flags indicate a GPIO which has had a watchdog timeout. + + PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep + alive signal on the pipe/socket and is sent once a minute + in the absence of other notification activity. tick: the number of microseconds since system boot. It wraps around after 1h12m. @@ -3215,7 +3284,8 @@ class pi(): def serial_open(self, tty, baud, ser_flags=0): """ Returns a handle for the serial tty device opened - at baud bits per second. + at baud bits per second. The device name must start + with /dev/tty or /dev/serial. tty:= the serial device to open. baud:= baud rate in bits per second, see below. @@ -3234,6 +3304,8 @@ class pi(): h1 = pi.serial_open("/dev/ttyAMA0", 300) h2 = pi.serial_open("/dev/ttyUSB1", 19200, 0) + + h3 = pi.serial_open("/dev/serial0", 9600) ... """ # I p1 baud @@ -3646,6 +3718,7 @@ class pi(): """ return _u2i(_pigpio_command(self.sl, _PI_CMD_SLRI, user_gpio, invert)) + def custom_1(self, arg1=0, arg2=0, argx=[]): """ Calls a pigpio function customised by the user. @@ -3721,6 +3794,360 @@ class pi(): self.sl.l.release() return bytes, data + def get_pad_strength(self, pad): + """ + This function returns the pad drive strength in mA. + + pad:= 0-2, the pad to get. + + Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + + Pad @ GPIO + 0 @ 0-27 + 1 @ 28-45 + 2 @ 46-53 + + ... + strength = pi.get_pad_strength(0) # Get pad 0 strength. + ... + """ + return _u2i(_pigpio_command(self.sl, _PI_CMD_PADG, pad, 0)) + + def set_pad_strength(self, pad, pad_strength): + """ + This function sets the pad drive strength in mA. + + + pad:= 0-2, the pad to set. + pad_strength:= 1-16 mA. + + Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + + Pad @ GPIO + 0 @ 0-27 + 1 @ 28-45 + 2 @ 46-53 + + ... + pi.set_pad_strength(2, 14) # Set pad 2 to 14 mA. + ... + """ + return _u2i(_pigpio_command(self.sl, _PI_CMD_PADS, pad, pad_strength)) + + + def file_open(self, file_name, file_mode): + """ + This function returns a handle to a file opened in a specified mode. + + file_name:= the file to open. + file_mode:= the file open mode. + + Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, + PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + + ... + h = pi.file_open("/home/pi/shared/dir_3/file.txt", + pigpio.FILE_WRITE | pigpio.FILE_CREATE) + + pi.file_write(h, "Hello world") + + pi.file_close(h) + ... + + File + + A file may only be opened if permission is granted by an entry in + /opt/pigpio/access. This is intended to allow remote access to files + in a more or less controlled manner. + + Each entry in /opt/pigpio/access takes the form of a file path + which may contain wildcards followed by a single letter permission. + The permission may be R for read, W for write, U for read/write, + and N for no access. + + Where more than one entry matches a file the most specific rule + applies. If no entry matches a file then access is denied. + + Suppose /opt/pigpio/access contains the following entries + + . . + /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 + . . + + Files may be written in directory dir_1 with the exception + of file.txt. + + Files may be read in directory dir_2. + + Files may be read and written in directory dir_3. + + If a directory allows read, write, or read/write access then files + may be created in that directory. + + In an attempt to prevent risky permissions the following paths are + ignored in /opt/pigpio/access. + + . . + a path containing .. + a path containing only wildcards (*?) + a path containing less than two non-wildcard parts + . . + + Mode + + The mode may have the following values. + + Constant @ Value @ Meaning + FILE_READ @ 1 @ open file for reading + FILE_WRITE @ 2 @ open file for writing + FILE_RW @ 3 @ open file for reading and writing + + The following values may be or'd into the mode. + + Name @ Value @ Meaning + FILE_APPEND @ 4 @ All writes append data to the end of the file + FILE_CREATE @ 8 @ The file is created if it doesn't exist + FILE_TRUNC @ 16 @ The file is truncated + + Newly created files are owned by root with permissions owner + read and write. + + ... + #!/usr/bin/env python + + import pigpio + + pi = pigpio.pi() + + if not pi.connected: + exit() + + # Assumes /opt/pigpio/access contains the following line. + # /ram/*.c r + + handle = pi.file_open("/ram/pigpio.c", pigpio.FILE_READ) + + done = False + + while not done: + c, d = pi.file_read(handle, 60000) + if c > 0: + print(d) + else: + done = True + + pi.file_close(handle) + + pi.stop() + ... + """ + # I p1 file_mode + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_FO, file_mode, 0, len(file_name), [file_name])) + + def file_close(self, handle): + """ + Closes the file associated with handle. + + handle:= >=0 (as returned by a prior call to [*file_open*]). + + ... + pi.file_close(handle) + ... + """ + return _u2i(_pigpio_command(self.sl, _PI_CMD_FC, handle, 0)) + + def file_read(self, handle, count): + """ + Reads up to count bytes from the file associated with handle. + + handle:= >=0 (as returned by a prior call to [*file_open*]). + count:= >0, the number of bytes to read. + + The returned value is a tuple of the number of bytes read and a + bytearray containing the bytes. If there was an error the + number of bytes read will be less than zero (and will contain + the error code). + + ... + (b, d) = pi.file_read(h2, 100) + if b > 0: + # process read data + ... + """ + # Don't raise exception. Must release lock. + bytes = u2i( + _pigpio_command(self.sl, _PI_CMD_FR, handle, count, False)) + if bytes > 0: + data = self._rxbuf(bytes) + else: + data = "" + self.sl.l.release() + return bytes, data + + def file_write(self, handle, data): + """ + Writes the data bytes to the file associated with handle. + + handle:= >=0 (as returned by a prior call to [*file_open*]). + data:= the bytes to write. + + ... + pi.file_write(h1, b'\\x02\\x03\\x04') + + pi.file_write(h2, b'help') + + pi.file_write(h2, "hello") + + pi.file_write(h1, [2, 3, 4]) + ... + """ + # I p1 handle + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_FW, handle, 0, len(data), [data])) + + def file_seek(self, handle, seek_offset, seek_from): + """ + Seeks to a position relative to the start, current position, + or end of the file. Returns the new position. + + handle:= >=0 (as returned by a prior call to [*file_open*]). + seek_offset:= byte offset. + seek_from:= FROM_START, FROM_CURRENT, or FROM_END. + + ... + new_pos = pi.file_seek(h, 100, pigpio.FROM_START) + + cur_pos = pi.file_seek(h, 0, pigpio.FROM_CURRENT) + + file_size = pi.file_seek(h, 0, pigpio.FROM_END) + ... + """ + # I p1 handle + # I p2 seek_offset + # I p3 4 + ## extension ## + # I seek_from + extents = [struct.pack("I", seek_from)] + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_FS, handle, seek_offset, 4, extents)) + + def file_list(self, fpattern): + """ + Returns a list of files which match a pattern. + + fpattern:= file pattern to match. + + Returns the number of returned bytes if OK, otherwise + PI_NO_FILE_ACCESS, or PI_NO_FILE_MATCH. + + The pattern must match an entry in /opt/pigpio/access. The + pattern may contain wildcards. See [*file_open*]. + + NOTE + + The returned value is not the number of files, it is the number + of bytes in the buffer. The file names are separated by newline + characters. + + ... + #!/usr/bin/env python + + import pigpio + + pi = pigpio.pi() + + if not pi.connected: + exit() + + # Assumes /opt/pigpio/access contains the following line. + # /ram/*.c r + + c, d = pi.file_list("/ram/p*.c") + if c > 0: + print(d) + + pi.stop() + ... + """ + # I p1 60000 + # I p2 0 + # I p3 len + ## extension ## + # s len data bytes + + # Don't raise exception. Must release lock. + bytes = u2i(_pigpio_command_ext( + self.sl, _PI_CMD_FL, 60000, 0, len(fpattern), [fpattern], False)) + if bytes > 0: + data = self._rxbuf(bytes) + else: + data = "" + self.sl.l.release() + return bytes, data + + def shell(self, shellscr, pstring=""): + """ + This function uses the system call to execute a shell script + with the given string as its parameter. + + shellscr:= the name of the script, only alphanumerics, + '-' and '_' are allowed in the name + pstring := the parameter string to pass to the script + + The exit status of the system call is returned if OK, + otherwise PI_BAD_SHELL_STATUS. + + [*shellscr*] must exist in /opt/pigpio/cgi and must be executable. + + The returned exit status is normally 256 times that set by + the shell script exit function. If the script can't be + found 32512 will be returned. + + The following table gives some example returned statuses. + + 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 = pi.shell("scr1", "hello world"); + + // pass three parameters, hello, string with spaces, and world + status = pi.shell("scr1", "hello 'string with spaces' world"); + + // pass one parameter, hello string with spaces world + status = pi.shell("scr1", "\\"hello string with spaces world\\""); + ... + """ + # I p1 len(shellscr) + # I p2 0 + # I p3 len(shellscr)+len(pstring)+1 + ## extension ## + # s len data bytes + + ls = len(shellscr) + lp = len(pstring) + return _u2i(_pigpio_command_ext( + self.sl, _PI_CMD_SHELL, ls, 0, ls+lp+1, [shellscr+'\x00'+pstring])) + def callback(self, user_gpio, edge=RISING_EDGE, func=None): """ Calls a user supplied function (a callback) whenever the @@ -4071,8 +4498,48 @@ def xref(): PI_BAD_SER_INVERT = -121 PI_BAD_FOREVER = -124 PI_BAD_FILTER = -125 + PI_BAD_PAD = -126 + PI_BAD_STRENGTH = -127 + PI_FIL_OPEN_FAILED = -128 + PI_BAD_FILE_MODE = -129 + PI_BAD_FILE_FLAG = -130 + PI_BAD_FILE_READ = -131 + PI_BAD_FILE_WRITE = -132 + PI_FILE_NOT_ROPEN = -133 + PI_FILE_NOT_WOPEN = -134 + PI_BAD_FILE_SEEK = -135 + PI_NO_FILE_MATCH = -136 + PI_NO_FILE_ACCESS = -137 + PI_FILE_IS_A_DIR = -138 + PI_BAD_SHELL_STATUS = -139 + PI_BAD_SCRIPT_NAME = -140 . . + file_mode: + The mode may have the following values. + + . . + FILE_READ 1 + FILE_WRITE 2 + FILE_RW 3 + . . + + The following values can be or'd into the file open mode. + + . . + FILE_APPEND 4 + FILE_CREATE 8 + FILE_TRUNC 16 + . . + + file_name: + A full file path. To be accessible the path must match + an entry in /opt/pigpio/access. + + fpattern: + A file path which may contain wildcards. To be accessible the path + must match an entry in /opt/pigpio/access. + frequency: 0-40000 Defines the frequency to be used for PWM on a GPIO. The closest permitted frequency will be used. @@ -4122,8 +4589,8 @@ def xref(): of a pulse. handle: >=0 - A number referencing an object opened by one of [*i2c_open*], - [*notify_open*], [*serial_open*], [*spi_open*]. + A number referencing an object opened by one of [*file_open*], + [*i2c_open*], [*notify_open*], [*serial_open*], [*spi_open*]. host: The name or IP address of the Pi running the pigpio daemon. @@ -4177,6 +4644,18 @@ def xref(): The offset wave data starts from the beginning of the waveform being currently defined. + pad: 0-2 + A set of GPIO which share common drivers. + + Pad @ GPIO + 0 @ 0-27 + 1 @ 28-45 + 2 @ 46-53 + + pad_strength: 1-16 + The mA which may be drawn from each GPIO whilst still guaranteeing the + high and low levels. + params: 32 bit number When scripts are started they can receive up to 10 parameters to define their operation. @@ -4184,6 +4663,9 @@ def xref(): port: The port used by the pigpio daemon, defaults to 8888. + pstring: + The string to be passed to a [*shell*] script to be executed. + pud: 0-2 PUD_DOWN = 1 PUD_OFF = 0 @@ -4230,12 +4712,27 @@ def xref(): SDA: The user GPIO to use for data when bit banging I2C. + seek_from: 0-2 + Direction to seek for [*file_seek*]. + + FROM_START=0 + FROM_CURRENT=1 + FROM_END=2 + + seek_offset: + The number of bytes to move forward (positive) or backwards + (negative) from the seek position (start, current, or end of file). + ser_flags: 32 bit No serial flags are currently defined. serial_*: One of the serial_ functions. + shellscr: + The name of a shell script. The script must exist + in /opt/pigpio/cgi and must be executable. + spi_*: One of the spi_ functions. diff --git a/pigpiod.1 b/pigpiod.1 index 2ce59b1..c32a4bb 100644 --- a/pigpiod.1 +++ b/pigpiod.1 @@ -11,6 +11,10 @@ pigpiod - A utility to start the pigpio library as a daemon. sudo pigpiod [OPTION]... .SH DESCRIPTION + +.ad l + +.nh pigpiod is a utility which launches the pigpio library as a daemon. .br diff --git a/pigpiod_if.3 b/pigpiod_if.3 index a5f0782..284a3ae 100644 --- a/pigpiod_if.3 +++ b/pigpiod_if.3 @@ -17,6 +17,10 @@ gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt .SH DESCRIPTION +.ad l + +.nh + .br .br @@ -37,12 +41,12 @@ of the GPIO via the socket interface to the pigpio daemon. .br .br -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 .br .br -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 .br @@ -313,7 +317,7 @@ Set the GPIO mode. .EX gpio: 0-53. .br -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1, +mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, .br PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. .br @@ -915,11 +919,6 @@ corresponding bit in bits is set. .br -.br -Notes - -.br - .br Each notification occupies 12 bytes in the fifo as follows: @@ -928,17 +927,59 @@ Each notification occupies 12 bytes in the fifo as follows: .br .EX -H (16 bit) seqno +typedef struct .br -H (16 bit) flags +{ .br -I (32 bit) tick + uint16_t seqno; .br -I (32 bit) level + 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: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. + +.br + +.br +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +.br + +.br +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +.br + +.br +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +.br + +.br +level: indicates the level of each GPIO. If bit 1< */ -/* PIGPIOD_IF_VERSION 23 */ +/* PIGPIOD_IF_VERSION 25 */ #include #include diff --git a/pigpiod_if.h b/pigpiod_if.h index 0b80183..6706b9d 100644 --- a/pigpiod_if.h +++ b/pigpiod_if.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF_VERSION 23 +#define PIGPIOD_IF_VERSION 25 /*TEXT @@ -42,9 +42,9 @@ of the GPIO via the socket interface to the pigpio daemon. *Features* -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 o callbacks when any of GPIO 0-31 change state @@ -251,7 +251,7 @@ spi_xfer Transfers bytes with a SPI device SERIAL -serial_open Opens a serial device (/dev/tty*) +serial_open Opens a serial device serial_close Closes a serial device serial_write_byte Writes a byte to a serial device @@ -389,7 +389,7 @@ Set the GPIO mode. . . gpio: 0-53. -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1, +mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. . . @@ -727,16 +727,35 @@ Returns 0 if OK, otherwise PI_BAD_HANDLE. The notification sends state changes for each GPIO whose corresponding bit in bits is set. -Notes - Each notification occupies 12 bytes in the fifo as follows: . . -H (16 bit) seqno -H (16 bit) flags -I (32 bit) tick -I (32 bit) level +typedef struct +{ + uint16_t seqno; + uint16_t flags; + uint32_t tick; + uint32_t level; +} gpioReport_t; . . + +seqno: starts at 0 each time the handle is opened and then increments +by one for each report. + +flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. + +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +level: indicates the level of each GPIO. If bit 1<=0 (as returned by \fBpigpio_start\fP). .br - ser_tty: the serial device to open, /dev/tty*. + ser_tty: the serial device to open. .br baud: the baud rate in bits per second, see below. .br @@ -4255,6 +4278,701 @@ Returns >= 0 if OK, less than 0 indicates a user defined error. .br Note, the number of returned bytes will be retMax or less. +.IP "\fBint get_pad_strength(int pi, unsigned pad)\fP" +.IP "" 4 +This function returns the pad drive strength in mA. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +pad: 0-2, the pad to get. +.br + +.EE + +.br + +.br +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +strength = get_pad_strength(pi, 0); // get pad 0 strength +.br + +.EE + +.IP "\fBint set_pad_strength(int pi, unsigned pad, unsigned padStrength)\fP" +.IP "" 4 +This function sets the pad drive strength in mA. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + pad: 0-2, the pad to set. +.br +padStrength: 1-16 mA. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA +.br + +.EE + +.IP "\fBint shell_(int pi, char *scriptName, char *scriptString)\fP" +.IP "" 4 +This function uses the system call to execute a shell script +with the given string as its parameter. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + scriptName: the name of the script, only alphanumeric characters, +.br + '-' and '_' are allowed in the name. +.br +scriptString: the string to pass to the script. +.br + +.EE + +.br + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br + +.br +scriptName must exist in /opt/pigpio/cgi and must be executable. + +.br + +.br +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +.br + +.br +The following table gives some example returned statuses. + +.br + +.br +Script exit status Returned system call status +.br +1 256 +.br +5 1280 +.br +10 2560 +.br +200 51200 +.br +script not found 32512 +.br + +.br + +.br +\fBExample\fP +.br + +.EX +// pass two parameters, hello and world +.br +status = shell_(pi, "scr1", "hello world"); +.br + +.br +// pass three parameters, hello, string with spaces, and world +.br +status = shell_(pi, "scr1", "hello 'string with spaces' world"); +.br + +.br +// pass one parameter, hello string with spaces world +.br +status = shell_(pi, "scr1", "\"hello string with spaces world\""); +.br + +.EE + +.IP "\fBint file_open(int pi, char *file, unsigned mode)\fP" +.IP "" 4 +This function returns a handle to a file opened in a specified mode. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +file: the file to open. +.br +mode: the file open mode. +.br + +.EE + +.br + +.br +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +.br + +.br +File + +.br + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br + +.br +Files may be read in directory dir_2. + +.br + +.br +Files may be read and written in directory dir_3. + +.br + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br + +.br +Mode + +.br + +.br +The mode may have the following values. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_READ 1 open file for reading +.br +PI_FILE_WRITE 2 open file for writing +.br +PI_FILE_RW 3 open file for reading and writing +.br + +.br + +.br +The following values may be or'd into the mode. + +.br + +.br +Macro Value Meaning +.br +PI_FILE_APPEND 4 Writes append data to the end of the file +.br +PI_FILE_CREATE 8 The file is created if it doesn't exist +.br +PI_FILE_TRUNC 16 The file is truncated +.br + +.br + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int pi, handle, c; +.br + char buf[60000]; +.br + +.br + pi = pigpio_start(NULL, NULL); +.br + +.br + if (pi < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ); +.br + +.br + if (handle >= 0) +.br + { +.br + while ((c=file_read(pi, handle, buf, sizeof(buf)-1))) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + file_close(pi, handle); +.br + } +.br + +.br + pigpio_stop(pi); +.br +} +.br + +.EE + +.IP "\fBint file_close(int pi, unsigned handle)\fP" +.IP "" 4 +This function closes the file associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +.br + +.br +\fBExample\fP +.br + +.EX +file_close(pi, handle); +.br + +.EE + +.IP "\fBint file_write(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function writes count bytes from buf to the the file +associated with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + buf: the array of bytes to write. +.br + count: the number of bytes to write. +.br + +.EE + +.br + +.br +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX +if (file_write(pi, handle, buf, 100) == 0) +.br +{ +.br + // file written okay +.br +} +.br +else +.br +{ +.br + // error +.br +} +.br + +.EE + +.IP "\fBint file_read(int pi, unsigned handle, char *buf, unsigned count)\fP" +.IP "" 4 +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br +handle: >=0 (as returned by \fBfile_open\fP). +.br + buf: an array to receive the read data. +.br + count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +.br + +.br +\fBExample\fP +.br + +.EX + bytes = file_read(pi, handle, buf, sizeof(buf)); +.br + +.br + if (bytes >= 0) +.br + { +.br + // process read data +.br + } +.br + +.EE + +.IP "\fBint file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom)\fP" +.IP "" 4 +This function seeks to a position within the file associated +with handle. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + handle: >=0 (as returned by \fBfile_open\fP). +.br +seekOffset: the number of bytes to move. Positive offsets +.br + move forward, negative offsets backwards. +.br + seekFrom: one of PI_FROM_START (0), PI_FROM_CURRENT (1), +.br + or PI_FROM_END (2). +.br + +.EE + +.br + +.br +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +.br + +.br +\fBExample\fP +.br + +.EX +file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123 +.br + +.br +size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size +.br + +.br +pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position +.br + +.EE + +.IP "\fBint file_list(int pi, char *fpat, char *buf, unsigned count)\fP" +.IP "" 4 +This function returns a list of files which match a pattern. + +.br + +.br + +.EX + pi: >=0 (as returned by \fBpigpio_start\fP). +.br + fpat: file pattern to match. +.br + buf: an array to receive the matching file names. +.br +count: the maximum number of bytes to read. +.br + +.EE + +.br + +.br +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +.br + +.br +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See \fBfile_open\fP. + +.br + +.br +NOTE + +.br + +.br +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +.br + +.br +\fBExample\fP +.br + +.EX +#include +.br +#include +.br + +.br +int main(int argc, char *argv[]) +.br +{ +.br + int pi, handle, c; +.br + char buf[60000]; +.br + +.br + pi = pigpio_start(NULL, NULL); +.br + +.br + if (pi < 0) return 1; +.br + +.br + // assumes /opt/pigpio/access contains the following line +.br + // /ram/*.c r +.br + +.br + c = file_list(pi, "/ram/p*.c", buf, sizeof(buf)); +.br + +.br + if (c >= 0) +.br + { +.br + buf[c] = 0; +.br + printf("%s", buf); +.br + } +.br + +.br + pigpio_stop(pi); +.br +} +.br + +.EE + .IP "\fBint callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f)\fP" .IP "" 4 This function initialises a new callback. @@ -4547,7 +5265,7 @@ The hardware clock frequency. .br .IP "\fBcount\fP" 0 -The number of bytes to be transferred in an I2C, SPI, or Serial +The number of bytes to be transferred in a file, I2C, SPI, or serial command. .br @@ -4630,6 +5348,22 @@ A function. .br +.IP "\fB*file\fP" 0 +A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. + +.br + +.br + +.IP "\fB*fpat\fP" 0 +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + +.br + +.br + .IP "\fBfrequency\fP: >=0" 0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as @@ -4640,24 +5374,20 @@ by its dutycycle. .br -.br - -.br - .IP "\fBgpio\fP" 0 A Broadcom numbered GPIO, in the range 0-53. .br .br -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. .br .br -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. .br @@ -4741,8 +5471,8 @@ typedef void *(gpioThreadFunc_t) (void *); .br .IP "\fBhandle\fP: >=0" 0 -A number referencing an object opened by one of \fBi2c_open\fP, \fBnotify_open\fP, -\fBserial_open\fP, and \fBspi_open\fP. +A number referencing an object opened by one of \fBfile_open\fP, +\fBi2c_open\fP, \fBnotify_open\fP, \fBserial_open\fP, and \fBspi_open\fP. .br @@ -4797,6 +5527,13 @@ A whole number, negative or positive. .br +.IP "\fBint32_t\fP" 0 +A 32-bit signed value. + +.br + +.br + .IP "\fBinvert\fP" 0 A flag used to set normal or inverted bit bang serial data level logic. @@ -4901,6 +5638,48 @@ PI_WAVE_MODE_REPEAT_SYNC 3 .br +.br +3. A file open mode. + +.br + +.br + +.EX +PI_FILE_READ 1 +.br +PI_FILE_WRITE 2 +.br +PI_FILE_RW 3 +.br + +.EE + +.br + +.br +The following values can be or'd into the mode. + +.br + +.br + +.EX +PI_FILE_APPEND 4 +.br +PI_FILE_CREATE 8 +.br +PI_FILE_TRUNC 16 +.br + +.EE + +.br + +.br + +.br + .br .IP "\fBnumBytes\fP" 0 @@ -4948,6 +5727,33 @@ The size in bytes of an output buffer. .br +.IP "\fBpad\fP: 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.br +Pad GPIO +.br +0 0-27 +.br +1 28-45 +.br +2 46-53 +.br + +.br + +.br + +.IP "\fBpadStrength\fP: 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + +.br + .IP "\fB*param\fP" 0 An array of script parameters. @@ -5136,6 +5942,21 @@ An id of a stored script as returned by \fBstore_script\fP. .br +.IP "\fB*scriptName\fP" 0 +The name of a \fBshell_\fP script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. + +.br + +.br + +.IP "\fB*scriptString\fP" 0 +The string to be passed to a \fBshell_\fP script to be executed. + +.br + +.br + .IP "\fBSDA\fP" 0 The user GPIO to use for data when bit banging I2C. @@ -5150,6 +5971,34 @@ The number of seconds. .br +.IP "\fBseekFrom\fP" 0 + +.br + +.br + +.EX +PI_FROM_START 0 +.br +PI_FROM_CURRENT 1 +.br +PI_FROM_END 2 +.br + +.EE + +.br + +.br + +.IP "\fBseekOffset\fP" 0 +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + +.br + +.br + .IP "\fBser_flags\fP" 0 Flags which modify a serial open command. None are currently defined. diff --git a/pigpiod_if2.c b/pigpiod_if2.c index ffaab49..bc3d496 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 6 */ +/* PIGPIOD_IF2_VERSION 8 */ #include #include @@ -1604,6 +1604,148 @@ int custom_2(int pi, unsigned arg1, char *argx, unsigned count, return bytes; } +int get_pad_strength(int pi, unsigned pad) + {return pigpio_command(pi, PI_CMD_PADG, pad, 0, 1);} + +int set_pad_strength(int pi, unsigned pad, unsigned padStrength) + {return pigpio_command(pi, PI_CMD_PADS, pad, padStrength, 1);} + +int shell_(int pi, char *scriptName, char *scriptString) +{ + int ln, ls; + gpioExtent_t ext[2]; + + ln = strlen(scriptName); + ls = strlen(scriptString); + /* + p1=len(scriptName) + p2=0 + p3=len(scriptName) + len(scriptString) + 1 + ## extension ## + char[] + */ + + ext[0].size = ln + 1; /* include null byte */ + ext[0].ptr = scriptName; + + ext[1].size = ls; + ext[1].ptr = scriptString; + + return pigpio_command_ext + (pi, PI_CMD_SHELL, ln, 0, ln+ls+1, 2, ext, 1); +} + +int file_open(int pi, char *file, unsigned mode) +{ + int len; + gpioExtent_t ext[1]; + + len = strlen(file); + + /* + p1=mode + p2=0 + p3=len + ## extension ## + char file[len] + */ + + ext[0].size = len; + ext[0].ptr = file; + + return pigpio_command_ext + (pi, PI_CMD_FO, mode, 0, len, 1, ext, 1); +} + +int file_close(int pi, unsigned handle) + {return pigpio_command(pi, PI_CMD_FC, handle, 0, 1);} + +int file_write(int pi, unsigned handle, char *buf, unsigned count) +{ + gpioExtent_t ext[1]; + + /* + p1=handle + p2=0 + p3=count + ## extension ## + char buf[count] + */ + + ext[0].size = count; + ext[0].ptr = buf; + + return pigpio_command_ext + (pi, PI_CMD_FW, handle, 0, count, 1, ext, 1); +} + +int file_read(int pi, unsigned handle, char *buf, unsigned count) +{ + int bytes; + + bytes = pigpio_command + (pi, PI_CMD_FR, handle, count, 0); + + if (bytes > 0) + { + bytes = recvMax(pi, buf, count, bytes); + } + + _pmu(pi); + + return bytes; +} + +int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom) +{ + gpioExtent_t ext[1]; + + /* + p1=handle + p2=seekOffset + p3=4 + ## extension ## + uint32_t seekFrom + */ + + ext[0].size = sizeof(uint32_t); + ext[0].ptr = &seekFrom; + + return pigpio_command_ext + (pi, PI_CMD_FS, handle, seekOffset, 4, 1, ext, 1); +} + +int file_list(int pi, char *fpat, char *buf, unsigned count) +{ + int len; + int bytes; + gpioExtent_t ext[1]; + + len = strlen(fpat); + + /* + p1=60000 + p2=0 + p3=len + ## extension ## + char fpat[len] + */ + + ext[0].size = len; + ext[0].ptr = fpat; + + bytes = pigpio_command_ext(pi, PI_CMD_FL, 60000, 0, len, 1, ext, 0); + + if (bytes > 0) + { + bytes = recvMax(pi, buf, count, bytes); + } + + _pmu(pi); + + return bytes; +} + int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f) {return intCallback(pi, user_gpio, edge, f, 0, 0);} diff --git a/pigpiod_if2.h b/pigpiod_if2.h index 95de307..c41d5a1 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 6 +#define PIGPIOD_IF2_VERSION 8 /*TEXT @@ -39,9 +39,9 @@ of the GPIO via the socket interface to the pigpio daemon. *Features* -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 o callbacks when any of GPIO 0-31 change state @@ -166,8 +166,13 @@ bb_serial_invert Invert serial logic (1 invert, 0 normal) hardware_clock Start hardware clock on supported GPIO hardware_PWM Start hardware PWM on supported GPIO -set_glitch_filter Set a glitch filter on a GPIO -set_noise_filter Set a noise filter on a GPIO +set_glitch_filter Set a glitch filter on a GPIO +set_noise_filter Set a noise filter on a GPIO + +get_pad_strength Gets a pads drive strength +set_pad_strength Sets a pads drive strength + +shell_ Executes a shell command SCRIPTS @@ -250,7 +255,7 @@ spi_xfer Transfers bytes with a SPI device SERIAL -serial_open Opens a serial device (/dev/tty*) +serial_open Opens a serial device serial_close Closes a serial device serial_write_byte Writes a byte to a serial device @@ -260,6 +265,15 @@ serial_read Reads bytes from a serial device serial_data_available Returns number of bytes ready to be read +FILES + +file_open Opens a file +file_close Closes a file +file_read Reads bytes from a file +file_write Writes bytes to a file +file_seek Seeks to a position within a file +file_list List files which match a pattern + CUSTOM custom_1 User custom function 1 @@ -399,7 +413,7 @@ Set the GPIO mode. . . pi: >=0 (as returned by [*pigpio_start*]). gpio: 0-53. -mode: PI_INPUT, PI_OUTPUT, PI_ALT0, _ALT1, +mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1, PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5. . . @@ -755,16 +769,35 @@ Returns 0 if OK, otherwise PI_BAD_HANDLE. The notification sends state changes for each GPIO whose corresponding bit in bits is set. -Notes - Each notification occupies 12 bytes in the fifo as follows: . . -H (16 bit) seqno -H (16 bit) flags -I (32 bit) tick -I (32 bit) level +typedef struct +{ + uint16_t seqno; + uint16_t flags; + uint32_t tick; + uint32_t level; +} gpioReport_t; . . + +seqno: starts at 0 each time the handle is opened and then increments +by one for each report. + +flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. + +PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags +indicate a GPIO which has had a watchdog timeout. + +PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive +signal on the pipe/socket and is sent once a minute in the absence +of other notification activity. + +tick: the number of microseconds since system boot. It wraps around +after 1h12m. + +level: indicates the level of each GPIO. If bit 1<=0 (as returned by [*pigpio_start*]). - ser_tty: the serial device to open, /dev/tty*. + ser_tty: the serial device to open. baud: the baud rate in bits per second, see below. ser_flags: 0. . . @@ -2641,6 +2676,369 @@ Returns >= 0 if OK, less than 0 indicates a user defined error. Note, the number of returned bytes will be retMax or less. D*/ +/*F*/ +int get_pad_strength(int pi, unsigned pad); +/*D +This function returns the pad drive strength in mA. + +. . + pi: >=0 (as returned by [*pigpio_start*]). +pad: 0-2, the pad to get. +. . + +Returns the pad drive strength if OK, otherwise PI_BAD_PAD. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +... +strength = get_pad_strength(pi, 0); // get pad 0 strength +... +D*/ + + +/*F*/ +int set_pad_strength(int pi, unsigned pad, unsigned padStrength); +/*D +This function sets the pad drive strength in mA. + +. . + pi: >=0 (as returned by [*pigpio_start*]). + pad: 0-2, the pad to set. +padStrength: 1-16 mA. +. . + +Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +... +set_pad_strength(pi, 0, 10); // set pad 0 strength to 10 mA +... +D*/ + + +/*F*/ +int shell_(int pi, char *scriptName, char *scriptString); +/*D +This function uses the system call to execute a shell script +with the given string as its parameter. + +. . + pi: >=0 (as returned by [*pigpio_start*]). + scriptName: the name of the script, only alphanumeric characters, + '-' and '_' are allowed in the name. +scriptString: the string to pass to the script. +. . + +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +scriptName must exist in /opt/pigpio/cgi and must be executable. + +The returned exit status is normally 256 times that set by the +shell script exit function. If the script can't be found 32512 will +be returned. + +The following table gives some example returned statuses. + +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_(pi, "scr1", "hello world"); + +// pass three parameters, hello, string with spaces, and world +status = shell_(pi, "scr1", "hello 'string with spaces' world"); + +// pass one parameter, hello string with spaces world +status = shell_(pi, "scr1", "\"hello string with spaces world\""); +... +D*/ + +#pragma GCC diagnostic push + +#pragma GCC diagnostic ignored "-Wcomment" + +/*F*/ +int file_open(int pi, char *file, unsigned mode); +/*D +This function returns a handle to a file opened in a specified mode. + +. . + pi: >=0 (as returned by [*pigpio_start*]). +file: the file to open. +mode: the file open mode. +. . + +Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS, +PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR. + +File + +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +Suppose /opt/pigpio/access contains the following entries + +. . +/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 +. . + +Files may be written in directory dir_1 with the exception +of file.txt. + +Files may be read in directory dir_2. + +Files may be read and written in directory dir_3. + +If a directory allows read, write, or read/write access then files may +be created in that directory. + +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +. . +a path containing .. +a path containing only wildcards (*?) +a path containing less than two non-wildcard parts +. . + +Mode + +The mode may have the following values. + +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 + +The following values may be or'd into the mode. + +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 + +Newly created files are owned by root with permissions owner read and write. + +... +#include +#include + +int main(int argc, char *argv[]) +{ + int pi, handle, c; + char buf[60000]; + + pi = pigpio_start(NULL, NULL); + + if (pi < 0) return 1; + + // assumes /opt/pigpio/access contains the following line + // /ram/*.c r + + handle = file_open(pi, "/ram/pigpio.c", PI_FILE_READ); + + if (handle >= 0) + { + while ((c=file_read(pi, handle, buf, sizeof(buf)-1))) + { + buf[c] = 0; + printf("%s", buf); + } + + file_close(pi, handle); + } + + pigpio_stop(pi); +} +... +D*/ + +#pragma GCC diagnostic pop + +/*F*/ +int file_close(int pi, unsigned handle); +/*D +This function closes the file associated with handle. + +. . + pi: >=0 (as returned by [*pigpio_start*]). +handle: >=0 (as returned by [*file_open*]). +. . + +Returns 0 if OK, otherwise PI_BAD_HANDLE. + +... +file_close(pi, handle); +... +D*/ + + +/*F*/ +int file_write(int pi, unsigned handle, char *buf, unsigned count); +/*D +This function writes count bytes from buf to the the file +associated with handle. + +. . + pi: >=0 (as returned by [*pigpio_start*]). +handle: >=0 (as returned by [*file_open*]). + buf: the array of bytes to write. + count: the number of bytes to write. +. . + +Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, +PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE. + +... +if (file_write(pi, handle, buf, 100) == 0) +{ + // file written okay +} +else +{ + // error +} +... +D*/ + + +/*F*/ +int file_read(int pi, unsigned handle, char *buf, unsigned count); +/*D +This function reads up to count bytes from the the file +associated with handle and writes them to buf. + +. . + pi: >=0 (as returned by [*pigpio_start*]). +handle: >=0 (as returned by [*file_open*]). + buf: an array to receive the read data. + count: the maximum number of bytes to read. +. . + +Returns the number of bytes read (>0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE. + +... + bytes = file_read(pi, handle, buf, sizeof(buf)); + + if (bytes >= 0) + { + // process read data + } +... +D*/ + + +/*F*/ +int file_seek(int pi, unsigned handle, int32_t seekOffset, int seekFrom); +/*D +This function seeks to a position within the file associated +with handle. + +. . + pi: >=0 (as returned by [*pigpio_start*]). + handle: >=0 (as returned by [*file_open*]). +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). +. . + +Returns the new byte position within the file (>=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK. + +... +file_seek(pi, handle, 123, PI_FROM_START); // Start plus 123 + +size = file_seek(pi, handle, 0, PI_FROM_END); // End, return size + +pos = file_seek(pi, handle, 0, PI_FROM_CURRENT); // Current position +... +D*/ + +#pragma GCC diagnostic push + +#pragma GCC diagnostic ignored "-Wcomment" + +/*F*/ +int file_list(int pi, char *fpat, char *buf, unsigned count); +/*D +This function returns a list of files which match a pattern. + +. . + pi: >=0 (as returned by [*pigpio_start*]). + fpat: file pattern to match. + buf: an array to receive the matching file names. +count: the maximum number of bytes to read. +. . + +Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS, +or PI_NO_FILE_MATCH. + +The pattern must match an entry in /opt/pigpio/access. The pattern +may contain wildcards. See [*file_open*]. + +NOTE + +The returned value is not the number of files, it is the number +of bytes in the buffer. The file names are separated by newline +characters. + +... +#include +#include + +int main(int argc, char *argv[]) +{ + int pi, handle, c; + char buf[60000]; + + pi = pigpio_start(NULL, NULL); + + if (pi < 0) return 1; + + // assumes /opt/pigpio/access contains the following line + // /ram/*.c r + + c = file_list(pi, "/ram/p*.c", buf, sizeof(buf)); + + if (c >= 0) + { + buf[c] = 0; + printf("%s", buf); + } + + pigpio_stop(pi); +} +... +D*/ + +#pragma GCC diagnostic pop + /*F*/ int callback(int pi, unsigned user_gpio, unsigned edge, CBFunc_t f); @@ -2794,7 +3192,7 @@ clkfreq::4689-250000000 (250M) The hardware clock frequency. count:: -The number of bytes to be transferred in an I2C, SPI, or Serial +The number of bytes to be transferred in a file, I2C, SPI, or serial command. data_bits::1-32 @@ -2831,21 +3229,28 @@ of the error. f:: A function. +*file:: +A full file path. To be accessible the path must match an entry in +/opt/pigpio/access. + +*fpat:: +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + frequency::>=0 The number of times a GPIO is swiched on and off per second. This can be set per GPIO and may be as little as 5Hz or as much as 40KHz. The GPIO will be on for a proportion of the time as defined by its dutycycle. - gpio:: A Broadcom numbered GPIO, in the range 0-53. -There are 54 General Purpose Input Outputs (GPIO) named gpio0 through -gpio53. +There are 54 General Purpose Input Outputs (GPIO) named GPIO0 through +GPIO53. -They are split into two banks. Bank 1 consists of gpio0 through -gpio31. Bank 2 consists of gpio32 through gpio53. +They are split into two banks. Bank 1 consists of GPIO0 through +GPIO31. Bank 2 consists of GPIO32 through GPIO53. All the GPIO which are safe for the user to read and write are in bank 1. Not all GPIO in bank 1 are safe though. Type 1 boards @@ -2883,8 +3288,8 @@ typedef void *(gpioThreadFunc_t) (void *); . . handle::>=0 -A number referencing an object opened by one of [*i2c_open*], [*notify_open*], -[*serial_open*], and [*spi_open*]. +A number referencing an object opened by one of [*file_open*], +[*i2c_open*], [*notify_open*], [*serial_open*], and [*spi_open*]. i2c_addr::0-0x7F The address of a device on the I2C bus. @@ -2907,6 +3312,9 @@ The number of bytes of data in a buffer. int:: A whole number, negative or positive. +int32_t:: +A 32-bit signed value. + invert:: A flag used to set normal or inverted bit bang serial data level logic. @@ -2954,6 +3362,23 @@ PI_WAVE_MODE_ONE_SHOT_SYNC 2 PI_WAVE_MODE_REPEAT_SYNC 3 . . +3. A file open mode. + +. . +PI_FILE_READ 1 +PI_FILE_WRITE 2 +PI_FILE_RW 3 +. . + +The following values can be or'd into the mode. + +. . +PI_FILE_APPEND 4 +PI_FILE_CREATE 8 +PI_FILE_TRUNC 16 +. . + + numBytes:: The number of bytes used to store characters in a string. Depending on the number of bits per character there may be 1, 2, or 4 bytes @@ -2975,6 +3400,18 @@ A buffer used to return data from a function. outLen:: The size in bytes of an output buffer. +pad:: 0-2 +A set of GPIO which share common drivers. + +Pad @ GPIO +0 @ 0-27 +1 @ 28-45 +2 @ 46-53 + +padStrength:: 1-16 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + *param:: An array of script parameters. @@ -3058,12 +3495,31 @@ A pointer to the text of a script. script_id:: An id of a stored script as returned by [*store_script*]. +*scriptName:: +The name of a [*shell_*] script to be executed. The script must be present in +/opt/pigpio/cgi and must have execute permission. + +*scriptString:: +The string to be passed to a [*shell_*] script to be executed. + SDA:: The user GPIO to use for data when bit banging I2C. seconds:: The number of seconds. +seekFrom:: + +. . +PI_FROM_START 0 +PI_FROM_CURRENT 1 +PI_FROM_END 2 +. . + +seekOffset:: +The number of bytes to move forward (positive) or backwards (negative) +from the seek position (start, current, or end of file). + ser_flags:: Flags which modify a serial open command. None are currently defined. diff --git a/pigs.1 b/pigs.1 index e55c554..28af561 100644 --- a/pigs.1 +++ b/pigs.1 @@ -22,6 +22,10 @@ or .SH DESCRIPTION +.ad l + +.nh + .br The socket and pipe interfaces allow control of the GPIO by passing @@ -45,10 +49,10 @@ whereas /dev/pigpio uses the pipe interface. .br .SS Features .br -o PWM on any of GPIO 0-31 +o hardware timed PWM on any of GPIO 0-31 .br -o servo pulses on any of GPIO 0-31 +o hardware timed servo pulses on any of GPIO 0-31 .br o reading/writing all of the GPIO in a bank as one operation @@ -514,11 +518,40 @@ configuration settings to \fBv\fP. .br +.IP "\fBFC h\fP - Close file handle" +.IP "" 4 +This command closes a file handle \fBh\fP previously opened with \fBFO\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fc 0 # First close okay. +.br + +.br +$ pigs fc 0 # Second fails. +.br +-25 +.br +ERROR: unknown handle +.br + +.EE + +.br + .IP "\fBFG u stdy\fP - Set a glitch filter on a GPIO" .IP "" 4 .br -Level changes on the GPIO are not reported unless the level +Level changes on the GPIO \fBu\fP are not reported unless the level has been stable for at least \fBstdy\fP microseconds. The level is then reported. Level changes of less than \fBstdy\fP microseconds are ignored. @@ -529,11 +562,77 @@ after it was first detected. .br +\fBExample\fP +.br + +.EX +$ pigs fg 4 250 +.br + +.br +$ pigs fg 4 1000000 +.br +-125 +.br +ERROR: bad filter parameter +.br + +.EE + +.br + +.IP "\fBFL pat num\fP - List files which match pattern" +.IP "" 4 +This command returns a list of the files matching \fBpat\fP. Up +to \fBnum\fP bytes may be returned. + +.br +Upon success the count of returned bytes followed by the matching +files is returned. On error a negative status code will be returned. + +.br +A newline (0x0a) character separates each file name. + +.br +Only files which have a matching entry in /opt/pigpio/access may +be listed. + +.br +Suppose /opt/pigpio/access contains + +.br +/sys/bus/w1/devices/28*/w1_slave r + +.br + +\fBExample\fP +.br + +.EX +$ pigs -a fl "/sys/bus/w1/devices/28*/w1_slave" 5000 +.br +90 /sys/bus/w1/devices/28-000005d34cd2/w1_slave +.br +/sys/bus/w1/devices/28-001414abbeff/w1_slave +.br + +.br +$ pigs -a fl "/sys/bus/*" 5000 +.br +ERROR: no permission to access file +.br +-137 +.br + +.EE + +.br + .IP "\fBFN u stdy actv\fP - Set a noise filter on a GPIO" .IP "" 4 .br -Level changes on the GPIO are ignored until a level which has +Level changes on the GPIO \fBu\fP are ignored until a level which has been stable for \fBstdy\fP microseconds is detected. Level changes on the GPIO are then reported for \fBactv\fP microseconds after which the process repeats. @@ -545,6 +644,311 @@ such reports. .br +\fBExample\fP +.br + +.EX +$ pigs fn 7 250 1000 +.br + +.br +$ pigs fn 7 2500000 1000 +.br +-125 +.br +ERROR: bad filter parameter +.br + +.EE + +.br + +.IP "\fBFO file mode\fP - Open a file in mode" +.IP "" 4 +This function returns a handle to a file \fBfile\fP opened +in a specified mode \fBmode\fP. + +.br +Upon success a handle (>=0) is returned. On error a negative status code +will be returned. + +.br +File + +.br +A file may only be opened if permission is granted by an entry in +/opt/pigpio/access. This is intended to allow remote access to files +in a more or less controlled manner. + +.br +Each entry in /opt/pigpio/access takes the form of a file path +which may contain wildcards followed by a single letter permission. +The permission may be R for read, W for write, U for read/write, +and N for no access. + +.br +Where more than one entry matches a file the most specific rule +applies. If no entry matches a file then access is denied. + +.br +Suppose /opt/pigpio/access contains the following entries + +.br + +.EX +/home/* n +.br +/home/pi/shared/dir_1/* w +.br +/home/pi/shared/dir_2/* r +.br +/home/pi/shared/dir_3/* u +.br +/home/pi/shared/dir_1/file.txt n +.br + +.EE + +.br +Files may be written in directory dir_1 with the exception +of file.txt. + +.br +Files may be read in directory dir_2. + +.br +Files may be read and written in directory dir_3. + +.br +If a directory allows read, write, or read/write access then files may +be created in that directory. + +.br +In an attempt to prevent risky permissions the following paths are +ignored in /opt/pigpio/access. + +.br + +.EX +a path containing .. +.br +a path containing only wildcards (*?) +.br +a path containing less than two non-wildcard parts +.br + +.EE + +.br +Mode + +.br +The mode may have the following values. + +.br + +.EX + Value Meaning +READ 1 open file for reading +WRITE 2 open file for writing +RW 3 open file for reading and writing + +.EE + +.br +The following values may be or'd into the mode. + +.br + +.EX + Value Meaning +APPEND 4 All writes append data to the end of the file +CREATE 8 The file is created if it doesn't exist +TRUNC 16 The file is truncated + +.EE + +.br +Newly created files are owned by root with permissions owner read and write. + +.br + +\fBExample\fP +.br + +.EX +$ ls /ram/*.c +.br +/ram/command.c /ram/pigpiod.c /ram/pigs.c +.br +/ram/x_pigpiod_if.c /ram/pig2vcd.c /ram/pigpiod_if2.c +.br +/ram/x_pigpio.c /ram/x_repeat.c /ram/pigpio.c +.br +/ram/pigpiod_if.c /ram/x_pigpiod_if2.c +.br + +.br +# assumes /opt/pigpio/access contains the following line +.br +# /ram/*.c r +.br + +.br +$ pigs fo /ram/pigpio.c 1 +.br +0 +.br + +.br +$ pigs fo /ram/new.c 1 +.br +-128 +.br +ERROR: file open failed +.br + +.br +$ pigs fo /ram/new.c 9 +.br +1 +.br + +.br +$ ls /ram/*.c -l +.br +-rw-r--r-- 1 joan joan 42923 Jul 10 11:22 /ram/command.c +.br +-rw------- 1 root root 0 Jul 10 16:54 /ram/new.c +.br +-rw-r--r-- 1 joan joan 2971 Jul 10 11:22 /ram/pig2vcd.c +.br +-rw------- 1 joan joan 296235 Jul 10 11:22 /ram/pigpio.c +.br +-rw-r--r-- 1 joan joan 9266 Jul 10 11:22 /ram/pigpiod.c +.br +-rw-r--r-- 1 joan joan 37331 Jul 10 11:22 /ram/pigpiod_if2.c +.br +-rw-r--r-- 1 joan joan 33088 Jul 10 11:22 /ram/pigpiod_if.c +.br +-rw-r--r-- 1 joan joan 7990 Jul 10 11:22 /ram/pigs.c +.br +-rw-r--r-- 1 joan joan 19970 Jul 10 11:22 /ram/x_pigpio.c +.br +-rw-r--r-- 1 joan joan 20804 Jul 10 11:22 /ram/x_pigpiod_if2.c +.br +-rw-r--r-- 1 joan joan 19844 Jul 10 11:22 /ram/x_pigpiod_if.c +.br +-rw-r--r-- 1 joan joan 19907 Jul 10 11:22 /ram/x_repeat.c +.br + +.EE + +.br + +.IP "\fBFR h num\fP - Read bytes from file handle" +.IP "" 4 +This command returns up to \fBnum\fP bytes of data read from the +file associated with handle \fBh\fP. + +.br +Upon success the count of returned bytes followed by the bytes themselves +is returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fr 0 10 +.br +5 48 49 128 144 255 +.br + +.br +$ pigs fr 0 10 +.br +0 +.br + +.EE + +.br + +.IP "\fBFS h num from\fP - Seek to file handle position" +.IP "" 4 +This command seeks to a position within the file associated +with handle \fBh\fP. + +.br +The number of bytes to move is \fBnum\fP. Positive offsets +move forward, negative offsets backwards. The move start +position is determined by \fBfrom\fP as follows. + +.br + +.EX + From +0 start +1 current position +2 end + +.EE + +.br +Upon success the new byte position within the file (>=0) is +returned. On error a negative status code will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fs 0 0 0 # Seek to start of file plus 200 +.br +200 +.br + +.br +$ pigs fs 0 0 1 # Return current position +.br +200 +.br + +.br +$ pigs fs 0 0 2 # Seek to end of file, return size +.br +296235 +.br + +.EE + +.br + +.IP "\fBFW h bvs\fP - Write bytes to file handle" +.IP "" 4 +This command writes bytes \fBbvs\fP to the file +associated with handle \fBh\fP. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +\fBExample\fP +.br + +.EX +$ pigs fw 0 23 45 67 89 +.br + +.EE + +.br + .IP "\fBGDC u\fP - Get GPIO PWM dutycycle" .IP "" 4 @@ -1710,6 +2114,96 @@ $ pigs p 4 255 # 100% .br +.IP "\fBPADG pad\fP - Get pad drive strength" +.IP "" 4 + +.br +This command gets the \fBpad\fP drive strength \fBpadma\fP in mA. + +.br +Returns the pad drive strength if OK. On error a negative status code +will be returned. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs padg 0 +.br +8 +.br +$ pigs pads 0 16 +.br +$ pigs padg 0 +.br +16 +.br +pigs padg 3 +.br +-126 +.br +ERROR: bad pad number +.br + +.EE + +.br + +.IP "\fBPADS pad padma\fP - Set pad drive strength" +.IP "" 4 + +.br +This command sets the \fBpad\fP drive strength \fBpadma\fP in mA. + +.br +Upon success nothing is returned. On error a negative status code +will be returned. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +\fBExample\fP +.br + +.EX +$ pigs pads 0 16 +.br +$ pigs padg 0 +.br +16 +.br +$ pigs pads 0 17 +.br +-127 +.br +ERROR: bad pad drive strength +.br + +.EE + +.br + .IP "\fBPARSE t\fP - Validate script" .IP "" 4 @@ -2447,8 +2941,9 @@ Upon success a handle (>=0) is returned. On error a negative status code will be returned. .br -The UART is /dev/ttyAMA0. The consoles are /dev/ttyx. The USB -devices are /dev/ttyUSBx. +The device name must start with /dev/tty or /dev/serial. + +.br .br The baud rate must be one of 50, 75, 110, 134, 150, @@ -2588,6 +3083,81 @@ $ pigs serwb 0 0xf0 .br +.IP "\fBSHELL name str\fP - Execute a shell command" +.IP "" 4 + +.br +This command uses the system call to execute a shell script \fBname\fP +with the given string \fBstr\fP as its parameter. + +.br +The exit status of the system call is returned if OK, otherwise +PI_BAD_SHELL_STATUS. + +.br +\fBname\fP must exist in /opt/pigpio/cgi and must be executable. + +.br +The returned exit status is normally 256 times that set +by the shell script exit function. If the script can't +be found 32512 will be returned. + +.br +The following table gives some example returned statuses. + +.br + +.EX +Script exit status Returned system call status +1 256 +5 1280 +10 2560 +200 51200 +script not found 32512 + +.EE + +.br + +\fBExample\fP +.br + +.EX +# pass two parameters, hello and world +.br +$ pigs shell scr1 hello world +.br +256 +.br + +.br +# pass three parameters, hello, string with spaces, and world +.br +$ pigs shell scr1 "hello 'string with spaces' world" +.br +256 +.br + +.br +# pass one parameter, hello string with spaces world +.br +$ pigs shell scr1 "\"hello string with spaces world\"" +.br +256 +.br + +.br +# non-existent script +.br +$ pigs shell scr78 par1 +.br +32512 +.br + +.EE + +.br + .IP "\fBSLR u num\fP - Read bit bang serial data from GPIO" .IP "" 4 @@ -3916,7 +4486,7 @@ The command expects the number of data bits per serial character. .br -.IP "\fBdev\fP - a tty serial device (/dev/tty*)" 0 +.IP "\fBdev\fP - a tty serial device (/dev/tty* or /dev/serial*)" 0 The command expects the name of a tty serial device, e.g. .br @@ -3928,6 +4498,28 @@ The command expects the name of a tty serial device, e.g. .br /dev/tty0 .br +/dev/serial0 +.br + +.EE + +.br + +.IP "\fBfile\fP - a file name" 0 +The file name must match an entry in /opt/pigpio/access. + +.br + +.IP "\fBfrom\fP - 0-2" 0 +Position to seek from \fBFS\fP. + +.br + +.EX + From +0 start +1 current position +2 end .EE @@ -3979,8 +4571,8 @@ of doing so range from no effect, to a crash, or corrupted data. The command expects a handle. .br -A handle is a number referencing an object opened by one of \fBI2CO\fP, \fBNO\fP, -\fBSERO\fP, \fBSPIO\fP. +A handle is a number referencing an object opened by one of \fBFO\fP, +\fBI2CO\fP, \fBNO\fP, \fBSERO\fP, \fBSPIO\fP. .br @@ -4020,24 +4612,58 @@ The value is returned by the mode get command. .br .EX -Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 -Code R W 0 1 2 3 4 5 -Value 0 1 4 5 6 7 3 2 +Mode Input Output ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 +Code R W 0 1 2 3 4 5 +Value 0 1 4 5 6 7 3 2 .EE .br -.IP "\fBnum\fP - number of bytes to read (1-)" 0 -The command expects the number of bytes to read. +.IP "\fBmode\fP - file open mode" 0 +One of the following values. + +.br + +.EX + Value Meaning +READ 1 open file for reading +WRITE 2 open file for writing +RW 3 open file for reading and writing + +.EE + +.br +The following values can be or'd into the mode. + +.br + +.EX + Value Meaning +APPEND 4 All writes append data to the end of the file +CREATE 8 The file is created if it doesn't exist +TRUNC 16 The file is truncated + +.EE + +.br + +.IP "\fBname\fP - the name of a script" 0 +Only alphanumeric characters, '-' and '_' are allowed in the name. + +.br + +.IP "\fBnum\fP - maximum number of bytes to return (1-)" 0 +The command expects the maximum number of bytes to return. .br For the I2C and SPI commands the requested number of bytes will always be returned. .br -For the serial commands the smaller of the number of bytes available to be -read (which may be zero) and \fBnum\fP bytes will be returned. +For the serial and file commands the smaller of the number of +bytes available to be read (which may be zero) and \fBnum\fP bytes +will be returned. .br @@ -4075,11 +4701,38 @@ There is no mechanism to read the pull up down state. .br +.IP "\fBpad\fP - 0-2" 0 +A set of GPIO which share common drivers. + +.br + +.EX +Pad GPIO +0 0-27 +1 28-45 +2 46-53 + +.EE + +.br + +.IP "\fBpadma\fP - 1-16" 0 +The mA which may be drawn from each GPIO whilst still guaranteeing the +high and low levels. + +.br + .IP "\fBpars\fP - script parameters" 0 The command expects 0 to 10 numbers as parameters to be passed to the script. .br +.IP "\fBpat\fP - a file name pattern" 0 +A file path which may contain wildcards. To be accessible the path +must match an entry in /opt/pigpio/access. + +.br + .IP "\fBpdc\fP - hardware PWM dutycycle (0-1000000)" 0 The command expects a dutycycle. @@ -4141,8 +4794,13 @@ the active part of a noise filter (\fBFN\fP). .br -.IP "\fBt\fP - text (a string of text)" 0 -The command expects a text string. +.IP "\fBstr\fP - a string" 0 +The command expects a string. + +.br + +.IP "\fBt\fP - a string" 0 +The command expects a string. .br diff --git a/pigs.c b/pigs.c index 1e87d3c..d4c91d0 100644 --- a/pigs.c +++ b/pigs.c @@ -26,7 +26,7 @@ For more information, please refer to */ /* -This version is for pigpio version 34+ +This version is for pigpio version 55+ */ #include @@ -48,8 +48,8 @@ This program provides a socket interface to some of the commands available from pigpio. */ -char command_buf[8192]; -char response_buf[8192]; +char command_buf[CMD_MAX_EXTENSION]; +char response_buf[CMD_MAX_EXTENSION]; int printFlags = 0; @@ -171,7 +171,10 @@ void print_result(int sock, int rv, cmdCmd_t cmd) printf("%s", cmdUsage); break; - case 6: /* BI2CZ CF2 I2CPK I2CRD I2CRI I2CRK I2CZ SERR SLR SPIX SPIR */ + case 6: /* + BI2CZ CF2 FL FR I2CPK I2CRD I2CRI I2CRK I2CZ + SERR SLR SPIX SPIR + */ printf("%d", r); if (r < 0) fatal("ERROR: %s", cmdErrStr(r)); if (r > 0) @@ -186,7 +189,8 @@ void print_result(int sock, int rv, cmdCmd_t cmd) else if (printFlags & PRINT_ASCII) { - if ((ch > 31) && (ch < 127)) printf("%c", ch); + if (isprint(ch) || (ch == '\n') || (ch == '\r')) + printf("%c", ch); else printf("\\x%02hhx", ch); } else printf(" %hhu", response_buf[i]); @@ -221,6 +225,8 @@ void get_extensions(int sock, int command, int res) { case PI_CMD_BI2CZ: case PI_CMD_CF2: + case PI_CMD_FL: + case PI_CMD_FR: case PI_CMD_I2CPK: case PI_CMD_I2CRD: case PI_CMD_I2CRI: diff --git a/setup.py b/setup.py index 3e0a76d..a10af60 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.31', + version='1.32', author='joan', author_email='joan@abyz.co.uk', maintainer='joan', diff --git a/x_pigs b/x_pigs index 1435493..38fe120 100755 --- a/x_pigs +++ b/x_pigs @@ -50,7 +50,7 @@ s=$(pigs bs2 0) if [[ $s = "" ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi s=$(pigs h) -if [[ ${#s} = 4593 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi +if [[ ${#s} = 4966 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi s=$(pigs hwver) if [[ $s -ne 0 ]]; then echo "HWVER ok"; else echo "HWVER fail ($s)"; fi