This commit is contained in:
joan 2015-07-24 21:17:29 +01:00
parent 927f3544f1
commit 33a222f80b
15 changed files with 1332 additions and 883 deletions

View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/ */
/* /*
This version is for pigpio version 34+ This version is for pigpio version 35+
*/ */
#include <stdio.h> #include <stdio.h>
@ -458,11 +458,14 @@ static errInfo_t errInfo[]=
{PI_BAD_I2C_RLEN , "bad I2C read length"}, {PI_BAD_I2C_RLEN , "bad I2C read length"},
{PI_BAD_I2C_CMD , "bad I2C command"}, {PI_BAD_I2C_CMD , "bad I2C command"},
{PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"}, {PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"},
{PI_BAD_REPEAT_CNT , "bad repeat count, not 2-max"}, {PI_CHAIN_LOOP_CNT , "bad chain loop count"},
{PI_BAD_REPEAT_WID , "bad repeat wave id"}, {PI_BAD_CHAIN_LOOP , "empty chain loop"},
{PI_TOO_MANY_COUNTS , "too many chain counters"}, {PI_CHAIN_COUNTER , "too many chain counters"},
{PI_BAD_CHAIN_CMD , "malformed chain command string"}, {PI_BAD_CHAIN_CMD , "bad chain command"},
{PI_REUSED_WID , "wave already used in chain"}, {PI_BAD_CHAIN_DELAY , "bad chain delay micros"},
{PI_CHAIN_NESTING , "chain counters nested too deeply"},
{PI_CHAIN_TOO_BIG , "chain is too long"},
{PI_DEPRECATED , "deprecated function removed"},
}; };
@ -535,6 +538,7 @@ int cmdParse(
char c; char c;
uint32_t tp1, tp2, tp3; uint32_t tp1, tp2, tp3;
int8_t to1, to2, to3; int8_t to1, to2, to3;
int eaten;
/* Check that ext is big enough for the largest message. */ /* Check that ext is big enough for the largest message. */
if (ext_len < (4 * CMD_MAX_PARAM)) return CMD_EXT_TOO_SMALL; if (ext_len < (4 * CMD_MAX_PARAM)) return CMD_EXT_TOO_SMALL;
@ -865,12 +869,16 @@ int cmdParse(
while (pars < CMD_MAX_PARAM) while (pars < CMD_MAX_PARAM)
{ {
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); eaten = getNum(buf+ctl->eaten, &tp1, &to1);
if ((to1 == CMD_NUMERIC) && if (to1 == CMD_NUMERIC)
((int)tp1>=0) && ((int)tp1<=255)) {
if (((int)tp1>=0) && ((int)tp1<=255))
{ {
pars++; pars++;
*p8++ = tp1; *p8++ = tp1;
ctl->eaten += eaten;
}
else break; /* invalid number, end of command */
} }
else break; else break;
} }
@ -899,13 +907,16 @@ int cmdParse(
while (pars < 32) while (pars < 32)
{ {
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); eaten = getNum(buf+ctl->eaten, &tp1, &to1);
if ((to1 == CMD_NUMERIC) && if (to1 == CMD_NUMERIC)
((int)tp1>=0) && {
((int)tp1<=255)) if (((int)tp1>=0) && ((int)tp1<=255))
{ {
pars++; pars++;
*p8++ = tp1; *p8++ = tp1;
ctl->eaten += eaten;
}
else break; /* invalid number, end of command */
} }
else break; else break;
} }
@ -940,15 +951,16 @@ int cmdParse(
while (pars < CMD_MAX_PARAM) while (pars < CMD_MAX_PARAM)
{ {
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); eaten = getNum(buf+ctl->eaten, &tp1, &to1);
if (to1 == CMD_NUMERIC) if (to1 == CMD_NUMERIC)
{ {
if (((int)tp1>=0) && ((int)tp1<=255)) if (((int)tp1>=0) && ((int)tp1<=255))
{ {
pars++; pars++;
*p8++ = tp1; *p8++ = tp1;
ctl->eaten += eaten;
} }
else valid = 0; else break;
} }
else break; else break;
} }
@ -996,12 +1008,16 @@ int cmdParse(
p8 = ext + 12; p8 = ext + 12;
while (pars < CMD_MAX_PARAM) while (pars < CMD_MAX_PARAM)
{ {
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); eaten = getNum(buf+ctl->eaten, &tp1, &to1);
if ((to1 == CMD_NUMERIC) && if (to1 == CMD_NUMERIC)
((int)tp1>=0) && ((int)tp1<=255)) {
if (((int)tp1>=0) && ((int)tp1<=255))
{ {
*p8++ = tp1; *p8++ = tp1;
pars++; pars++;
ctl->eaten += eaten;
}
else break; /* invalid number, end of command */
} }
else break; else break;
} }
@ -1022,12 +1038,16 @@ int cmdParse(
while (pars < CMD_MAX_PARAM) while (pars < CMD_MAX_PARAM)
{ {
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1); eaten = getNum(buf+ctl->eaten, &tp1, &to1);
if ((to1 == CMD_NUMERIC) && if (to1 == CMD_NUMERIC)
((int)tp1>=0) && ((int)tp1<=255)) {
if (((int)tp1>=0) && ((int)tp1<=255))
{ {
pars++; pars++;
*p8++ = tp1; *p8++ = tp1;
ctl->eaten += eaten;
}
else break; /* invalid number, end of command */
} }
else break; else break;
} }

213
pigpio.3
View File

@ -1683,8 +1683,9 @@ gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);
.IP "\fBint gpioWaveCreate(void)\fP" .IP "\fBint gpioWaveCreate(void)\fP"
.IP "" 4 .IP "" 4
This function creates a waveform from the data provided by the prior This function creates a waveform from the data provided by the prior
calls to the \fBgpioWaveAdd*\fP functions. Upon success a positive wave id calls to the \fBgpioWaveAdd*\fP functions. Upon success a wave id
is returned. 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.
.br .br
@ -1788,8 +1789,7 @@ PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
.IP "\fBint gpioWaveDelete(unsigned wave_id)\fP" .IP "\fBint gpioWaveDelete(unsigned wave_id)\fP"
.IP "" 4 .IP "" 4
This function deletes all created waveforms with ids greater than or This function deletes the waveform with id wave_id.
equal to wave_id.
.br .br
@ -1811,38 +1811,6 @@ Wave ids are allocated in order, 0, 1, 2, etc.
.br .br
Returns 0 if OK, otherwise PI_BAD_WAVE_ID. Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
.IP "\fBint gpioWaveTxStart(unsigned wave_mode)\fP"
.IP "" 4
This function creates and then transmits a waveform. The mode
determines whether the waveform is sent once or cycles endlessly.
.br
.br
NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled.
.br
.br
.EX
wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
.br
.EE
.br
.br
This function is deprecated and should no longer be used. Use
\fBgpioWaveCreate\fP and \fBgpioWaveTxSend\fP instead.
.br
.br
Returns the number of DMA control blocks in the waveform if OK,
otherwise PI_BAD_WAVE_MODE.
.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP" .IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP"
.IP "" 4 .IP "" 4
This function transmits the waveform with id wave_id. The mode This function transmits the waveform with id wave_id. The mode
@ -1884,7 +1852,7 @@ NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled.
.br .br
The waves to be transmitted are specified by the contents of buf The waves to be transmitted are specified by the contents of buf
which contains an ordered list of wave_ids and optional command which contains an ordered list of \fBwave_id\fPs and optional command
codes and related data. codes and related data.
.br .br
@ -1902,24 +1870,26 @@ bufSize: the number of bytes in buf
.br .br
.br .br
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID, Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID. PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
.br .br
.br .br
Each wave is transmitted in the order specified. A wave may only Each wave is transmitted in the order specified. A wave may
occur once per chain. Waves may be transmitted multiple times by occur multiple times per chain.
using the repeat command. The repeat command specifies a wave id
and a count. The wave id must occur earlier in the chain. All the
waves between wave id and the repeat command are transmitted count
times.
.br .br
.br .br
Repeat commands may not be nested. The minimum repeat count is 2. A blocks of waves may be transmitted multiple times by using
A maximum of 5 repeat commands is supported per chain. the loop commands. The block is bracketed by loop start and
end commands. Loops may be nested.
.br
.br
Delays between waves may be added with the delay command.
.br .br
@ -1932,10 +1902,21 @@ The following command codes are supported:
Name Cmd & Data Meaning Name Cmd & Data Meaning
.br .br
Repeat 255 wid C0 C1 C2 Repeat from wid count times Loop Start 255 0 Identify start of a wave block
.br .br
count = C0 + C1*256 + C2*65536 Loop Repeat 255 1 x y loop x + y*256 times
.br
Delay 255 2 x y delay x + y*256 microseconds
.br
.br
.br
The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
.br .br
@ -1944,55 +1925,109 @@ count = C0 + C1*256 + C2*65536
.br .br
.EX .EX
The following examples assume that waves with ids 0 to 12 exist. #include <stdio.h>
.br
#include <pigpio.h>
.br .br
.br .br
// 0 255 0 57 0 0 (repeat 0 57 times) #define WAVES 5
.br .br
status = gpioWaveChain((char []){0, 255, 0, 57, 0, 0}, 6); #define GPIO 4
.br .br
.br .br
// 0 1 255 0 0 2 0 (repeat 0+1 512 times) int main(int argc, char *argv[])
.br .br
status = gpioWaveChain((char []){0, 1, 255, 0, 0, 2, 0}, 7); {
.br
int i, wid[WAVES];
.br .br
.br .br
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) if (gpioInitialise()<0) return -1;
.br
status = gpioWaveChain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
.br .br
.br .br
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) gpioSetMode(GPIO, PI_OUTPUT);
.br
status = gpioWaveChain(
.br
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
.br .br
.br .br
// The following repeats 5 65793 times, transmits 6, printf("start piscope, press return\n"); getchar();
.br
// repeats 7+8 514 times, transmits 12,
.br
// repeats 9+11+10 197121 times.
.br
// 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3
.br
char chain[] = {
.br
5, 255, 5, 1, 1, 1,
.br
6, 7, 8, 255, 7, 2, 2, 0,
.br
12, 9, 11, 10, 255, 9, 1, 2, 3};
.br .br
.br .br
status = gpioWaveChain(chain, sizeof(chain)); for (i=0; i<WAVES; i++)
.br
{
.br
gpioWaveAddGeneric(2, (gpioPulse_t[])
.br
{{1<<GPIO, 0, 20},
.br
{0, 1<<GPIO, (i+1)*200}});
.br
.br
wid[i] = gpioWaveCreate();
.br
}
.br
.br
gpioWaveChain((char []) {
.br
wid[4], wid[3], wid[2], // transmit waves 4+3+2
.br
255, 0, // loop start
.br
wid[0], wid[0], wid[0], // transmit waves 0+0+0
.br
255, 0, // loop start
.br
wid[0], wid[1], // transmit waves 0+1
.br
255, 2, 0x88, 0x13, // delay 5000us
.br
255, 1, 30, 0, // loop end (repeat 30 times)
.br
255, 0, // loop start
.br
wid[2], wid[3], wid[0], // transmit waves 2+3+0
.br
wid[3], wid[1], wid[2], // transmit waves 3+1+2
.br
255, 1, 10, 0, // loop end (repeat 10 times)
.br
255, 1, 5, 0, // loop end (repeat 5 times)
.br
wid[4], wid[4], wid[4], // transmit waves 4+4+4
.br
255, 2, 0x20, 0x4E, // delay 20000us
.br
wid[0], wid[0], wid[0], // transmit waves 0+0+0
.br
.br
}, 46);
.br
.br
while (gpioWaveTxBusy()) time_sleep(0.1);
.br
.br
for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);
.br
.br
printf("stop piscope, press return\n"); getchar();
.br
.br
gpioTerminate();
.br
}
.br .br
.EE .EE
@ -4386,8 +4421,8 @@ Frequencies above 30MHz are unlikely to work.
.br .br
.br .br
NOTE: Any waveform started by \fBgpioWaveTxSend\fP, \fBgpioWaveTxStart\fP, NOTE: Any waveform started by \fBgpioWaveTxSend\fP, or
or \fBgpioWaveChain\fP will be cancelled. \fBgpioWaveChain\fP will be cancelled.
.br .br
@ -7022,7 +7057,7 @@ Denoting no parameter is required
.br .br
.br .br
A number representing a waveform created by \fBgpioWaveCreate\fP. A number identifying a waveform created by \fBgpioWaveCreate\fP.
.br .br
@ -7514,15 +7549,21 @@ A 16-bit word value.
.br .br
#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k #define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k
.br .br
#define PI_BAD_REPEAT_CNT -113 // bad repeat count, not 2-max #define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
.br .br
#define PI_BAD_REPEAT_WID -114 // bad repeat wave id #define PI_BAD_CHAIN_LOOP -114 // empty chain loop
.br .br
#define PI_TOO_MANY_COUNTS -115 // too many chain counters #define PI_CHAIN_COUNTER -115 // too many chain counters
.br .br
#define PI_BAD_CHAIN_CMD -116 // malformed chain command string #define PI_BAD_CHAIN_CMD -116 // bad chain command
.br .br
#define PI_REUSED_WID -117 // wave already used in chain #define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
.br
#define PI_CHAIN_NESTING -118 // chain counters nested too deeply
.br
#define PI_CHAIN_TOO_BIG -119 // chain is too long
.br
#define PI_DEPRECATED -120 // deprecated function removed
.br .br
.br .br

826
pigpio.c

File diff suppressed because it is too large Load Diff

178
pigpio.h
View File

@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
#include <stdint.h> #include <stdint.h>
#include <pthread.h> #include <pthread.h>
#define PIGPIO_VERSION 34 #define PIGPIO_VERSION 35
/*TEXT /*TEXT
@ -197,7 +197,7 @@ gpioWaveAddGeneric Adds a series of pulses to the waveform
gpioWaveAddSerial Adds serial data to the waveform gpioWaveAddSerial Adds serial data to the waveform
gpioWaveCreate Creates a waveform from added data gpioWaveCreate Creates a waveform from added data
gpioWaveDelete Deletes one or more waveforms gpioWaveDelete Deletes a waveform
gpioWaveTxSend Transmits a waveform gpioWaveTxSend Transmits a waveform
@ -218,8 +218,6 @@ gpioWaveGetCbs Length in control blocks of the current waveform
gpioWaveGetHighCbs Length of longest waveform so far gpioWaveGetHighCbs Length of longest waveform so far
gpioWaveGetMaxCbs Absolute maximum allowed control blocks gpioWaveGetMaxCbs Absolute maximum allowed control blocks
gpioWaveTxStart Creates/transmits a waveform (DEPRECATED)
I2C I2C
i2cOpen Opens an I2C device i2cOpen Opens an I2C device
@ -383,12 +381,31 @@ typedef struct
uint32_t flags; uint32_t flags;
} rawWave_t; } rawWave_t;
/*
CBs are used in order from the lowest numbered CB up to
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 level and tick read values are stored in descending locations
from the top (topOOL/numTOOL).
*/
typedef struct typedef struct
{ {
uint16_t botCB; /* first CB used by wave */ uint16_t botCB; /* first CB used by wave */
uint16_t topCB; /* last CB used by wave */ uint16_t topCB; /* last CB used by wave */
uint16_t botOOL; /* last OOL used by wave */ uint16_t botOOL; /* first bottom OOL used by wave */
uint16_t topOOL; /* first OOL used by wave */ /* botOOL to botOOL + numBOOL -1 are in use */
uint16_t topOOL; /* last top OOL used by wave */
/* topOOL - numTOOL to topOOL are in use.*/
uint16_t deleted;
uint16_t numCB;
uint16_t numBOOL;
uint16_t numTOOL;
} rawWaveInfo_t; } rawWaveInfo_t;
typedef struct typedef struct
@ -550,9 +567,11 @@ typedef void *(gpioThreadFunc_t) (void *);
#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */ #define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
#define PI_MAX_WAVES 250 #define PI_MAX_WAVES 250
//#define PI_MAX_WAVE_CYCLES 537824
#define PI_MAX_WAVE_CYCLES 16777216 #define PI_MAX_WAVE_CYCLES 65535
#define PI_WAVE_COUNTERS 5 #define PI_MAX_WAVE_DELAY 65535
#define PI_WAVE_COUNT_PAGES 10
/* wave tx mode */ /* wave tx mode */
@ -1511,8 +1530,9 @@ D*/
int gpioWaveCreate(void); int gpioWaveCreate(void);
/*D /*D
This function creates a waveform from the data provided by the prior This function creates a waveform from the data provided by the prior
calls to the [*gpioWaveAdd**] functions. Upon success a positive wave id calls to the [*gpioWaveAdd**] functions. Upon success a wave id
is returned. 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.
The data provided by the [*gpioWaveAdd**] functions is consumed by this The data provided by the [*gpioWaveAdd**] functions is consumed by this
function. function.
@ -1564,8 +1584,7 @@ D*/
/*F*/ /*F*/
int gpioWaveDelete(unsigned wave_id); int gpioWaveDelete(unsigned wave_id);
/*D /*D
This function deletes all created waveforms with ids greater than or This function deletes the waveform with id wave_id.
equal to wave_id.
. . . .
wave_id: >=0, as returned by [*gpioWaveCreate*] wave_id: >=0, as returned by [*gpioWaveCreate*]
@ -1577,26 +1596,6 @@ Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
D*/ D*/
/*F*/
int gpioWaveTxStart(unsigned wave_mode); /* DEPRECATED */
/*D
This function creates and then transmits a waveform. The mode
determines whether the waveform is sent once or cycles endlessly.
NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled.
. .
wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
. .
This function is deprecated and should no longer be used. Use
[*gpioWaveCreate*] and [*gpioWaveTxSend*] instead.
Returns the number of DMA control blocks in the waveform if OK,
otherwise PI_BAD_WAVE_MODE.
D*/
/*F*/ /*F*/
int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode); int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode);
/*D /*D
@ -1623,7 +1622,7 @@ This function transmits a chain of waveforms.
NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled. NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled.
The waves to be transmitted are specified by the contents of buf The waves to be transmitted are specified by the contents of buf
which contains an ordered list of wave_ids and optional command which contains an ordered list of [*wave_id*]s and optional command
codes and related data. codes and related data.
. . . .
@ -1631,51 +1630,81 @@ codes and related data.
bufSize: the number of bytes in buf bufSize: the number of bytes in buf
. . . .
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID, Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID. PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
Each wave is transmitted in the order specified. A wave may only Each wave is transmitted in the order specified. A wave may
occur once per chain. Waves may be transmitted multiple times by occur multiple times per chain.
using the repeat command. The repeat command specifies a wave id
and a count. The wave id must occur earlier in the chain. All the
waves between wave id and the repeat command are transmitted count
times.
Repeat commands may not be nested. The minimum repeat count is 2. A blocks of waves may be transmitted multiple times by using
A maximum of 5 repeat commands is supported per chain. the loop commands. The block is bracketed by loop start and
end commands. Loops may be nested.
Delays between waves may be added with the delay command.
The following command codes are supported: The following command codes are supported:
Name @ Cmd & Data @ Meaning Name @ Cmd & Data @ Meaning
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times Loop Start @ 255 0 @ Identify start of a wave block
count = C0 + C1*256 + C2*65536 Loop Repeat @ 255 1 x y @ loop x + y*256 times
Delay @ 255 2 x y @ delay x + y*256 microseconds
The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
... ...
The following examples assume that waves with ids 0 to 12 exist. #include <stdio.h>
#include <pigpio.h>
// 0 255 0 57 0 0 (repeat 0 57 times) #define WAVES 5
status = gpioWaveChain((char []){0, 255, 0, 57, 0, 0}, 6); #define GPIO 4
// 0 1 255 0 0 2 0 (repeat 0+1 512 times) int main(int argc, char *argv[])
status = gpioWaveChain((char []){0, 1, 255, 0, 0, 2, 0}, 7); {
int i, wid[WAVES];
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) if (gpioInitialise()<0) return -1;
status = gpioWaveChain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) gpioSetMode(GPIO, PI_OUTPUT);
status = gpioWaveChain(
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
// The following repeats 5 65793 times, transmits 6, printf("start piscope, press return\n"); getchar();
// repeats 7+8 514 times, transmits 12,
// repeats 9+11+10 197121 times.
// 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3
char chain[] = {
5, 255, 5, 1, 1, 1,
6, 7, 8, 255, 7, 2, 2, 0,
12, 9, 11, 10, 255, 9, 1, 2, 3};
status = gpioWaveChain(chain, sizeof(chain)); for (i=0; i<WAVES; i++)
{
gpioWaveAddGeneric(2, (gpioPulse_t[])
{{1<<GPIO, 0, 20},
{0, 1<<GPIO, (i+1)*200}});
wid[i] = gpioWaveCreate();
}
gpioWaveChain((char []) {
wid[4], wid[3], wid[2], // transmit waves 4+3+2
255, 0, // loop start
wid[0], wid[0], wid[0], // transmit waves 0+0+0
255, 0, // loop start
wid[0], wid[1], // transmit waves 0+1
255, 2, 0x88, 0x13, // delay 5000us
255, 1, 30, 0, // loop end (repeat 30 times)
255, 0, // loop start
wid[2], wid[3], wid[0], // transmit waves 2+3+0
wid[3], wid[1], wid[2], // transmit waves 3+1+2
255, 1, 10, 0, // loop end (repeat 10 times)
255, 1, 5, 0, // loop end (repeat 5 times)
wid[4], wid[4], wid[4], // transmit waves 4+4+4
255, 2, 0x20, 0x4E, // delay 20000us
wid[0], wid[0], wid[0], // transmit waves 0+0+0
}, 46);
while (gpioWaveTxBusy()) time_sleep(0.1);
for (i=0; i<WAVES; i++) gpioWaveDelete(wid[i]);
printf("stop piscope, press return\n"); getchar();
gpioTerminate();
}
... ...
D*/ D*/
@ -3135,8 +3164,8 @@ int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty);
Starts hardware PWM on a gpio at the specified frequency and dutycycle. Starts hardware PWM on a gpio at the specified frequency and dutycycle.
Frequencies above 30MHz are unlikely to work. Frequencies above 30MHz are unlikely to work.
NOTE: Any waveform started by [*gpioWaveTxSend*], [*gpioWaveTxStart*], NOTE: Any waveform started by [*gpioWaveTxSend*], or
or [*gpioWaveChain*] will be cancelled. [*gpioWaveChain*] will be cancelled.
This function is only valid if the pigpio main clock is PCM. The This function is only valid if the pigpio main clock is PCM. The
main clock defaults to PCM but may be overridden by a call to main clock defaults to PCM but may be overridden by a call to
@ -4428,7 +4457,7 @@ Denoting no parameter is required
wave_id:: wave_id::
A number representing a waveform created by [*gpioWaveCreate*]. A number identifying a waveform created by [*gpioWaveCreate*].
wave_mode:: wave_mode::
@ -4729,11 +4758,14 @@ after this command is issued.
#define PI_BAD_I2C_RLEN -110 // bad I2C read length #define PI_BAD_I2C_RLEN -110 // bad I2C read length
#define PI_BAD_I2C_CMD -111 // bad I2C command #define PI_BAD_I2C_CMD -111 // bad I2C command
#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k #define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k
#define PI_BAD_REPEAT_CNT -113 // bad repeat count, not 2-max #define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
#define PI_BAD_REPEAT_WID -114 // bad repeat wave id #define PI_BAD_CHAIN_LOOP -114 // empty chain loop
#define PI_TOO_MANY_COUNTS -115 // too many chain counters #define PI_CHAIN_COUNTER -115 // too many chain counters
#define PI_BAD_CHAIN_CMD -116 // malformed chain command string #define PI_BAD_CHAIN_CMD -116 // bad chain command
#define PI_REUSED_WID -117 // wave already used in chain #define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
#define PI_CHAIN_NESTING -118 // chain counters nested too deeply
#define PI_CHAIN_TOO_BIG -119 // chain is too long
#define PI_DEPRECATED -120 // deprecated function removed
#define PI_PIGIF_ERR_0 -2000 #define PI_PIGIF_ERR_0 -2000
#define PI_PIGIF_ERR_99 -2099 #define PI_PIGIF_ERR_99 -2099

344
pigpio.py
View File

@ -182,9 +182,6 @@ wave_chain Transmits a chain of waveforms
wave_tx_busy Checks to see if a waveform has ended wave_tx_busy Checks to see if a waveform has ended
wave_tx_stop Aborts the current waveform wave_tx_stop Aborts the current waveform
wave_tx_repeat Creates/transmits a waveform (DEPRECATED)
wave_tx_start Creates/transmits a waveform (DEPRECATED)
wave_get_micros Length in microseconds of the current waveform wave_get_micros Length in microseconds of the current waveform
wave_get_max_micros Absolute maximum allowed micros wave_get_max_micros Absolute maximum allowed micros
wave_get_pulses Length in pulses of the current waveform wave_get_pulses Length in pulses of the current waveform
@ -266,7 +263,7 @@ import threading
import os import os
import atexit import atexit
VERSION = "1.19" VERSION = "1.20"
exceptions = True exceptions = True
@ -550,11 +547,14 @@ PI_BAD_I2C_WLEN =-109
PI_BAD_I2C_RLEN =-110 PI_BAD_I2C_RLEN =-110
PI_BAD_I2C_CMD =-111 PI_BAD_I2C_CMD =-111
PI_BAD_I2C_BAUD =-112 PI_BAD_I2C_BAUD =-112
PI_BAD_REPEAT_CNT =-113 PI_CHAIN_LOOP_CNT =-113
PI_BAD_REPEAT_WID =-114 PI_BAD_CHAIN_LOOP =-114
PI_TOO_MANY_COUNTS =-115 PI_CHAIN_COUNTER =-115
PI_BAD_CHAIN_CMD =-116 PI_BAD_CHAIN_CMD =-116
PI_REUSED_WID =-117 PI_BAD_CHAIN_DELAY =-117
PI_CHAIN_NESTING =-118
PI_CHAIN_TOO_BIG =-119
PI_DEPRECATED =-120
# pigpio error text # pigpio error text
@ -669,11 +669,14 @@ _errors=[
[PI_BAD_I2C_RLEN , "bad I2C read length"], [PI_BAD_I2C_RLEN , "bad I2C read length"],
[PI_BAD_I2C_CMD , "bad I2C command"], [PI_BAD_I2C_CMD , "bad I2C command"],
[PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"], [PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"],
[PI_BAD_REPEAT_CNT , "bad repeat count, not 2-max"], [PI_CHAIN_LOOP_CNT , "bad chain loop count"],
[PI_BAD_REPEAT_WID , "bad repeat wave id"], [PI_BAD_CHAIN_LOOP , "empty chain loop"],
[PI_TOO_MANY_COUNTS , "too many chain counters"], [PI_CHAIN_COUNTER , "too many chain counters"],
[PI_BAD_CHAIN_CMD , "malformed chain command string"], [PI_BAD_CHAIN_CMD , "bad chain command"],
[PI_REUSED_WID , "wave already used in chain"], [PI_BAD_CHAIN_DELAY , "bad chain delay micros"],
[PI_CHAIN_NESTING , "chain counters nested too deeply"],
[PI_CHAIN_TOO_BIG , "chain is too long"],
[PI_DEPRECATED , "deprecated function removed"],
] ]
@ -1551,8 +1554,7 @@ class pi():
and dutycycle. Frequencies above 30MHz are unlikely to work. and dutycycle. Frequencies above 30MHz are unlikely to work.
NOTE: Any waveform started by [*wave_send_once*], NOTE: Any waveform started by [*wave_send_once*],
[*wave_send_repeat*], [*wave_tx_start*], [*wave_tx_repeat*], [*wave_send_repeat*], or [*wave_chain*] will be cancelled.
or [*wave_chain*] will be cancelled.
This function is only valid if the pigpio main clock is PCM. This function is only valid if the pigpio main clock is PCM.
The main clock defaults to PCM but may be overridden when the The main clock defaults to PCM but may be overridden when the
@ -1821,7 +1823,8 @@ class pi():
Creates a waveform from the data provided by the prior calls Creates a waveform from the data provided by the prior calls
to the [*wave_add_**] functions. to the [*wave_add_**] functions.
Returns a wave id (>=0) if OK. Returns a wave id (>=0) if OK, otherwise PI_EMPTY_WAVEFORM,
PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
The data provided by the [*wave_add_**] functions is consumed by The data provided by the [*wave_add_**] functions is consumed by
this function. this function.
@ -1864,40 +1867,33 @@ class pi():
def wave_delete(self, wave_id): def wave_delete(self, wave_id):
""" """
Deletes all created waveforms with ids greater than or equal This function deletes the waveform with id wave_id.
to wave_id.
wave_id:= >=0 (as returned by a prior call to [*wave_create*]). wave_id:= >=0 (as returned by a prior call to [*wave_create*]).
Wave ids are allocated in order, 0, 1, 2, etc. Wave ids are allocated in order, 0, 1, 2, etc.
... ...
pi.wave_delete(6) # delete all waves with id 6 or greater pi.wave_delete(6) # delete waveform with id 6
pi.wave_delete(0) # delete all waves pi.wave_delete(0) # delete waveform with id 0
... ...
""" """
return _u2i(_pigpio_command(self.sl, _PI_CMD_WVDEL, wave_id, 0)) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVDEL, wave_id, 0))
def wave_tx_start(self): # DEPRECATED def wave_tx_start(self): # DEPRECATED
""" """
This function is deprecated and will be removed. This function is deprecated and has been removed.
Use [*wave_create*]/[*wave_send_**] instead. Use [*wave_create*]/[*wave_send_**] instead.
NOTE: Any hardware PWM started by [*hardware_PWM*] will
be cancelled.
""" """
return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0)) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0))
def wave_tx_repeat(self): # DEPRECATED def wave_tx_repeat(self): # DEPRECATED
""" """
This function is deprecated and will be removed. This function is deprecated and has beeen removed.
Use [*wave_create*]/[*wave_send_**] instead. Use [*wave_create*]/[*wave_send_**] instead.
NOTE: Any hardware PWM started by [*hardware_PWM*] will
be cancelled.
""" """
return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0)) return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0))
@ -1975,58 +1971,84 @@ class pi():
""" """
This function transmits a chain of waveforms. This function transmits a chain of waveforms.
NOTE: Any hardware PWM started by [*hardware_PWM*] will NOTE: Any hardware PWM started by [*hardware_PWM*]
be cancelled. will be cancelled.
The waves to be transmitted are specified by the contents of The waves to be transmitted are specified by the contents
data which contains an ordered list of wave_ids and optional of data which contains an ordered list of [*wave_id*]s
command codes and related data. and optional command codes and related data.
data:= contains the wave_ids and optional command codes Returns 0 if OK, otherwise PI_CHAIN_NESTING,
PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD,
PI_CHAIN_COUNTER, PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG,
or PI_BAD_WAVE_ID.
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID, Each wave is transmitted in the order specified. A wave
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID. may occur multiple times per chain.
Each wave is transmitted in the order specified. A wave may A blocks of waves may be transmitted multiple times by
only occur once per chain. Waves may be transmitted multiple using the loop commands. The block is bracketed by loop
times by using the repeat command. The repeat command start and end commands. Loops may be nested.
specifies a wave id and a count. The wave id must occur
earlier in the chain. All the waves between wave id and the
repeat command are transmitted count times.
Repeat commands may not be nested. The minimum repeat Delays between waves may be added with the delay command.
count is 2. A maximum of 5 repeat commands is supported
per chain.
The following command codes are supported: The following command codes are supported:
Name @ Cmd & Data @ Meaning Name @ Cmd & Data @ Meaning
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times Loop Start @ 255 0 @ Identify start of a wave block
count = C0 + C1*256 + C2*65536 Loop Repeat @ 255 1 x y @ loop x + y*256 times
Delay @ 255 2 x y @ delay x + y*256 microseconds
The code is currently dimensioned to support a chain with
roughly 600 entries and 20 loop counters.
... ...
The following examples assume that waves with ids 0 to 12 exist. #!/usr/bin/env python
# 0 255 0 57 0 0 (repeat 0 57 times) import time
pi.wave_chain([0, 255, 0, 57, 0, 0]) import pigpio
# 0 1 255 0 0 2 0 (repeat 0+1 512 times) WAVES=5
pi.wave_chain([0, 1, 255, 0, 0, 2, 0]) GPIO=4
# 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) wid=[0]*WAVES
pi.wave_chain([0, 1, 255, 1, 0, 0, 1])
# 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) pi = pigpio.pi() # Connect to local Pi.
pi.wave_chain([0, 1, 2, 3, 255, 2, 13, 0, 0])
pi.set_mode(GPIO, pigpio.OUTPUT);
for i in range(WAVES):
pi.wave_add_generic([
pigpio.pulse(1<<GPIO, 0, 20),
pigpio.pulse(0, 1<<GPIO, (i+1)*200)]);
wid[i] = pi.wave_create();
# The following repeats 5 65793 times, transmits 6,
# repeats 7+8 514 times, transmits 12,
# repeats 9+11+10 197121 times.
# 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3
pi.wave_chain([ pi.wave_chain([
5, 255, 5, 1, 1, 1, wid[4], wid[3], wid[2], # transmit waves 4+3+2
6, 7, 8, 255, 7, 2, 2, 0, 255, 0, # loop start
12, 9, 11, 10, 255, 9, 1, 2, 3]) wid[0], wid[0], wid[0], # transmit waves 0+0+0
255, 0, # loop start
wid[0], wid[1], # transmit waves 0+1
255, 2, 0x88, 0x13, # delay 5000us
255, 1, 30, 0, # loop end (repeat 30 times)
255, 0, # loop start
wid[2], wid[3], wid[0], # transmit waves 2+3+0
wid[3], wid[1], wid[2], # transmit waves 3+1+2
255, 1, 10, 0, # loop end (repeat 10 times)
255, 1, 5, 0, # loop end (repeat 5 times)
wid[4], wid[4], wid[4], # transmit waves 4+4+4
255, 2, 0x20, 0x4E, # delay 20000us
wid[0], wid[0], wid[0], # transmit waves 0+0+0
])
while pi.wave_tx_busy():
time.sleep(0.1);
for i in range(WAVES):
pi.wave_delete(wid[i])
pi.stop()
... ...
""" """
# I p1 0 # I p1 0
@ -3386,12 +3408,18 @@ class pi():
edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE. edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
func:= user supplied callback function. func:= user supplied callback function.
If a user callback is not specified a default tally callback is
provided which simply counts edges.
The user supplied callback receives three parameters, the gpio, The user supplied callback receives three parameters, the gpio,
the level, and the tick. the level, and the tick.
If a user callback is not specified a default tally callback is
provided which simply counts edges. The count may be retrieved
by calling the tally function.
The callback may be cancelled by calling the cancel function.
A gpio may have multiple callbacks (although I can't think of
a reason to do so).
... ...
def cbf(gpio, level, tick): def cbf(gpio, level, tick):
print(gpio, level, tick) print(gpio, level, tick)
@ -3403,6 +3431,8 @@ class pi():
cb3 = pi.callback(17) cb3 = pi.callback(17)
print(cb3.tally()) print(cb3.tally())
cb1.cancel() # To cancel callback cb1.
... ...
""" """
return _callback(self._notify, user_gpio, edge, func) return _callback(self._notify, user_gpio, edge, func)
@ -3594,96 +3624,100 @@ def xref():
RISING_EDGE = 0 RISING_EDGE = 0
errnum: <0 errnum: <0
. . . .
PI_BAD_USER_GPIO =-2 PI_BAD_USER_GPIO = -2
PI_BAD_GPIO =-3 PI_BAD_GPIO = -3
PI_BAD_MODE =-4 PI_BAD_MODE = -4
PI_BAD_LEVEL =-5 PI_BAD_LEVEL = -5
PI_BAD_PUD =-6 PI_BAD_PUD = -6
PI_BAD_PULSEWIDTH =-7 PI_BAD_PULSEWIDTH = -7
PI_BAD_DUTYCYCLE =-8 PI_BAD_DUTYCYCLE = -8
PI_BAD_WDOG_TIMEOUT =-15 PI_BAD_WDOG_TIMEOUT = -15
PI_BAD_DUTYRANGE =-21 PI_BAD_DUTYRANGE = -21
PI_NO_HANDLE =-24 PI_NO_HANDLE = -24
PI_BAD_HANDLE =-25 PI_BAD_HANDLE = -25
PI_BAD_WAVE_BAUD =-35 PI_BAD_WAVE_BAUD = -35
PI_TOO_MANY_PULSES =-36 PI_TOO_MANY_PULSES = -36
PI_TOO_MANY_CHARS =-37 PI_TOO_MANY_CHARS = -37
PI_NOT_SERIAL_GPIO =-38 PI_NOT_SERIAL_GPIO = -38
PI_NOT_PERMITTED =-41 PI_NOT_PERMITTED = -41
PI_SOME_PERMITTED =-42 PI_SOME_PERMITTED = -42
PI_BAD_WVSC_COMMND =-43 PI_BAD_WVSC_COMMND = -43
PI_BAD_WVSM_COMMND =-44 PI_BAD_WVSM_COMMND = -44
PI_BAD_WVSP_COMMND =-45 PI_BAD_WVSP_COMMND = -45
PI_BAD_PULSELEN =-46 PI_BAD_PULSELEN = -46
PI_BAD_SCRIPT =-47 PI_BAD_SCRIPT = -47
PI_BAD_SCRIPT_ID =-48 PI_BAD_SCRIPT_ID = -48
PI_BAD_SER_OFFSET =-49 PI_BAD_SER_OFFSET = -49
PI_GPIO_IN_USE =-50 PI_GPIO_IN_USE = -50
PI_BAD_SERIAL_COUNT =-51 PI_BAD_SERIAL_COUNT = -51
PI_BAD_PARAM_NUM =-52 PI_BAD_PARAM_NUM = -52
PI_DUP_TAG =-53 PI_DUP_TAG = -53
PI_TOO_MANY_TAGS =-54 PI_TOO_MANY_TAGS = -54
PI_BAD_SCRIPT_CMD =-55 PI_BAD_SCRIPT_CMD = -55
PI_BAD_VAR_NUM =-56 PI_BAD_VAR_NUM = -56
PI_NO_SCRIPT_ROOM =-57 PI_NO_SCRIPT_ROOM = -57
PI_NO_MEMORY =-58 PI_NO_MEMORY = -58
PI_SOCK_READ_FAILED =-59 PI_SOCK_READ_FAILED = -59
PI_SOCK_WRIT_FAILED =-60 PI_SOCK_WRIT_FAILED = -60
PI_TOO_MANY_PARAM =-61 PI_TOO_MANY_PARAM = -61
PI_NOT_HALTED =-62 PI_NOT_HALTED = -62
PI_BAD_TAG =-63 PI_BAD_TAG = -63
PI_BAD_MICS_DELAY =-64 PI_BAD_MICS_DELAY = -64
PI_BAD_MILS_DELAY =-65 PI_BAD_MILS_DELAY = -65
PI_BAD_WAVE_ID =-66 PI_BAD_WAVE_ID = -66
PI_TOO_MANY_CBS =-67 PI_TOO_MANY_CBS = -67
PI_TOO_MANY_OOL =-68 PI_TOO_MANY_OOL = -68
PI_EMPTY_WAVEFORM =-69 PI_EMPTY_WAVEFORM = -69
PI_NO_WAVEFORM_ID =-70 PI_NO_WAVEFORM_ID = -70
PI_I2C_OPEN_FAILED =-71 PI_I2C_OPEN_FAILED = -71
PI_SER_OPEN_FAILED =-72 PI_SER_OPEN_FAILED = -72
PI_SPI_OPEN_FAILED =-73 PI_SPI_OPEN_FAILED = -73
PI_BAD_I2C_BUS =-74 PI_BAD_I2C_BUS = -74
PI_BAD_I2C_ADDR =-75 PI_BAD_I2C_ADDR = -75
PI_BAD_SPI_CHANNEL =-76 PI_BAD_SPI_CHANNEL = -76
PI_BAD_FLAGS =-77 PI_BAD_FLAGS = -77
PI_BAD_SPI_SPEED =-78 PI_BAD_SPI_SPEED = -78
PI_BAD_SER_DEVICE =-79 PI_BAD_SER_DEVICE = -79
PI_BAD_SER_SPEED =-80 PI_BAD_SER_SPEED = -80
PI_BAD_PARAM =-81 PI_BAD_PARAM = -81
PI_I2C_WRITE_FAILED =-82 PI_I2C_WRITE_FAILED = -82
PI_I2C_READ_FAILED =-83 PI_I2C_READ_FAILED = -83
PI_BAD_SPI_COUNT =-84 PI_BAD_SPI_COUNT = -84
PI_SER_WRITE_FAILED =-85 PI_SER_WRITE_FAILED = -85
PI_SER_READ_FAILED =-86 PI_SER_READ_FAILED = -86
PI_SER_READ_NO_DATA =-87 PI_SER_READ_NO_DATA = -87
PI_UNKNOWN_COMMAND =-88 PI_UNKNOWN_COMMAND = -88
PI_SPI_XFER_FAILED =-89 PI_SPI_XFER_FAILED = -89
PI_NO_AUX_SPI =-91 PI_NO_AUX_SPI = -91
PI_NOT_PWM_GPIO =-92 PI_NOT_PWM_GPIO = -92
PI_NOT_SERVO_GPIO =-93 PI_NOT_SERVO_GPIO = -93
PI_NOT_HCLK_GPIO =-94 PI_NOT_HCLK_GPIO = -94
PI_NOT_HPWM_GPIO =-95 PI_NOT_HPWM_GPIO = -95
PI_BAD_HPWM_FREQ =-96 PI_BAD_HPWM_FREQ = -96
PI_BAD_HPWM_DUTY =-97 PI_BAD_HPWM_DUTY = -97
PI_BAD_HCLK_FREQ =-98 PI_BAD_HCLK_FREQ = -98
PI_BAD_HCLK_PASS =-99 PI_BAD_HCLK_PASS = -99
PI_HPWM_ILLEGAL =-100 PI_HPWM_ILLEGAL = -100
PI_BAD_DATABITS =-101 PI_BAD_DATABITS = -101
PI_BAD_STOPBITS =-102 PI_BAD_STOPBITS = -102
PI_MSG_TOOBIG =-103 PI_MSG_TOOBIG = -103
PI_BAD_MALLOC_MODE =-104 PI_BAD_MALLOC_MODE = -104
PI_BAD_SMBUS_CMD =-107 PI_BAD_SMBUS_CMD = -107
PI_NOT_I2C_GPIO =-108 PI_NOT_I2C_GPIO = -108
PI_BAD_I2C_WLEN =-109 PI_BAD_I2C_WLEN = -109
PI_BAD_I2C_RLEN =-110 PI_BAD_I2C_RLEN = -110
PI_BAD_I2C_CMD =-111 PI_BAD_I2C_CMD = -111
PI_BAD_I2C_BAUD =-112 PI_BAD_I2C_BAUD = -112
PI_BAD_REPEAT_CNT =-113 PI_CHAIN_LOOP_CNT = -113
PI_BAD_REPEAT_WID =-114 PI_BAD_CHAIN_LOOP = -114
PI_TOO_MANY_COUNTS =-115 PI_CHAIN_COUNTER = -115
PI_BAD_CHAIN_CMD =-116 PI_BAD_CHAIN_CMD = -116
PI_REUSED_WID =-117 PI_BAD_CHAIN_DELAY = -117
PI_CHAIN_NESTING = -118
PI_CHAIN_TOO_BIG = -119
PI_DEPRECATED = -120
. . . .
frequency: 0-40000 frequency: 0-40000

View File

@ -1221,8 +1221,8 @@ Frequencies above 30MHz are unlikely to work.
.br .br
.br .br
NOTE: Any waveform started by \fBwave_send_once\fP, \fBwave_send_repeat\fP, \fBwave_tx_start\fP, \fBwave_tx_repeat\fP, or \fBwave_chain\fP NOTE: Any waveform started by \fBwave_send_once\fP, \fBwave_send_repeat\fP,
will be cancelled. or \fBwave_chain\fP will be cancelled.
.br .br
@ -1493,8 +1493,9 @@ For \fBdata_bits\fP 17-32 there will be four bytes per character.
.IP "\fBint wave_create(void)\fP" .IP "\fBint wave_create(void)\fP"
.IP "" 4 .IP "" 4
This function creates a waveform from the data provided by the prior This function creates a waveform from the data provided by the prior
calls to the \fBwave_add_*\fP functions. Upon success a positive wave id calls to the \fBwave_add_*\fP functions. Upon success a wave id
is returned. 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.
.br .br
@ -1599,8 +1600,7 @@ PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
.IP "\fBint wave_delete(unsigned wave_id)\fP" .IP "\fBint wave_delete(unsigned wave_id)\fP"
.IP "" 4 .IP "" 4
This function deletes all created waveforms with ids greater than or This function deletes the waveform with id wave_id.
equal to wave_id.
.br .br
@ -1622,34 +1622,6 @@ Wave ids are allocated in order, 0, 1, 2, etc.
.br .br
Returns 0 if OK, otherwise PI_BAD_WAVE_ID. Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
.IP "\fBint wave_tx_start(void)\fP"
.IP "" 4
This function is deprecated and should no longer be used.
.br
.br
Use \fBwave_create\fP/\fBwave_send_*\fP instead.
.br
.br
NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled.
.IP "\fBint wave_tx_repeat(void)\fP"
.IP "" 4
This function is deprecated and should no longer be used.
.br
.br
Use \fBwave_create\fP/\fBwave_send_*\fP instead.
.br
.br
NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled.
.IP "\fBint wave_send_once(unsigned wave_id)\fP" .IP "\fBint wave_send_once(unsigned wave_id)\fP"
.IP "" 4 .IP "" 4
This function transmits the waveform with id wave_id. The waveform This function transmits the waveform with id wave_id. The waveform
@ -1716,7 +1688,7 @@ NOTE: Any hardware PWM started by \fBhardware_PWM\fP will be cancelled.
.br .br
The waves to be transmitted are specified by the contents of buf The waves to be transmitted are specified by the contents of buf
which contains an ordered list of wave_ids and optional command which contains an ordered list of \fBwave_id\fPs and optional command
codes and related data. codes and related data.
.br .br
@ -1734,24 +1706,26 @@ bufSize: the number of bytes in buf
.br .br
.br .br
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID, Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID. PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
.br .br
.br .br
Each wave is transmitted in the order specified. A wave may only Each wave is transmitted in the order specified. A wave may
occur once per chain. Waves may be transmitted multiple times by occur multiple times per chain.
using the repeat command. The repeat command specifies a wave id
and a count. The wave id must occur earlier in the chain. All the
waves between wave id and the repeat command are transmitted count
times.
.br .br
.br .br
Repeat commands may not be nested. The minimum repeat count is 2. A blocks of waves may be transmitted multiple times by using
A maximum of 5 repeat commands is supported per chain. the loop commands. The block is bracketed by loop start and
end commands. Loops may be nested.
.br
.br
Delays between waves may be added with the delay command.
.br .br
@ -1764,10 +1738,21 @@ The following command codes are supported:
Name Cmd & Data Meaning Name Cmd & Data Meaning
.br .br
Repeat 255 wid C0 C1 C2 Repeat from wid count times Loop Start 255 0 Identify start of a wave block
.br .br
count = C0 + C1*256 + C2*65536 Loop Repeat 255 1 x y loop x + y*256 times
.br
Delay 255 2 x y delay x + y*256 microseconds
.br
.br
.br
The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
.br .br
@ -1776,55 +1761,101 @@ count = C0 + C1*256 + C2*65536
.br .br
.EX .EX
The following examples assume that waves with ids 0 to 12 exist. #include <stdio.h>
.br
#include <pigpiod_if.h>
.br .br
.br .br
// 0 255 0 57 0 0 (repeat 0 57 times) #define WAVES 5
.br .br
status = wave_chain((char []){0, 255, 0, 57, 0, 0}, 6); #define GPIO 4
.br .br
.br .br
// 0 1 255 0 0 2 0 (repeat 0+1 512 times) int main(int argc, char *argv[])
.br .br
status = wave_chain((char []){0, 1, 255, 0, 0, 2, 0}, 7); {
.br
int i, wid[WAVES];
.br .br
.br .br
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) if (pigpio_start(0, 0)<0) return -1;
.br
status = wave_chain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
.br .br
.br .br
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) set_mode(GPIO, PI_OUTPUT);
.br
status = wave_chain(
.br
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
.br .br
.br .br
// The following repeats 5 65793 times, transmits 6, for (i=0; i<WAVES; i++)
.br .br
// repeats 7+8 514 times, transmits 12, {
.br .br
// repeats 9+11+10 197121 times. wave_add_generic(2, (gpioPulse_t[])
.br .br
// 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3 {{1<<GPIO, 0, 20},
.br .br
char chain[] = { {0, 1<<GPIO, (i+1)*200}});
.br
5, 255, 5, 1, 1, 1,
.br
6, 7, 8, 255, 7, 2, 2, 0,
.br
12, 9, 11, 10, 255, 9, 1, 2, 3};
.br .br
.br .br
status = wave_chain(chain, sizeof(chain)); wid[i] = wave_create();
.br
}
.br
.br
wave_chain((char []) {
.br
wid[4], wid[3], wid[2], // transmit waves 4+3+2
.br
255, 0, // loop start
.br
wid[0], wid[0], wid[0], // transmit waves 0+0+0
.br
255, 0, // loop start
.br
wid[0], wid[1], // transmit waves 0+1
.br
255, 2, 0x88, 0x13, // delay 5000us
.br
255, 1, 30, 0, // loop end (repeat 30 times)
.br
255, 0, // loop start
.br
wid[2], wid[3], wid[0], // transmit waves 2+3+0
.br
wid[3], wid[1], wid[2], // transmit waves 3+1+2
.br
255, 1, 10, 0, // loop end (repeat 10 times)
.br
255, 1, 5, 0, // loop end (repeat 5 times)
.br
wid[4], wid[4], wid[4], // transmit waves 4+4+4
.br
255, 2, 0x20, 0x4E, // delay 20000us
.br
wid[0], wid[0], wid[0], // transmit waves 0+0+0
.br
.br
}, 46);
.br
.br
while (wave_tx_busy()) time_sleep(0.1);
.br
.br
for (i=0; i<WAVES; i++) wave_delete(wid[i]);
.br
.br
pigpio_stop();
.br
}
.br .br
.EE .EE

View File

@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/> For more information, please refer to <http://unlicense.org/>
*/ */
/* PIGPIOD_IF_VERSION 16 */ /* PIGPIOD_IF_VERSION 17 */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
#include "pigpio.h" #include "pigpio.h"
#define PIGPIOD_IF_VERSION 16 #define PIGPIOD_IF_VERSION 17
/*TEXT /*TEXT
@ -204,9 +204,6 @@ wave_get_cbs Length in cbs of the current waveform
wave_get_high_cbs Length of longest waveform so far wave_get_high_cbs Length of longest waveform so far
wave_get_max_cbs Absolute maximum allowed cbs wave_get_max_cbs Absolute maximum allowed cbs
wave_tx_start Creates/transmits a waveform (DEPRECATED)
wave_tx_repeat Creates/transmits a waveform repeatedly (DEPRECATED)
I2C I2C
i2c_open Opens an I2C device i2c_open Opens an I2C device
@ -914,8 +911,8 @@ int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty);
Starts hardware PWM on a gpio at the specified frequency and dutycycle. Starts hardware PWM on a gpio at the specified frequency and dutycycle.
Frequencies above 30MHz are unlikely to work. Frequencies above 30MHz are unlikely to work.
NOTE: Any waveform started by [*wave_send_once*], [*wave_send_repeat*], [*wave_tx_start*], [*wave_tx_repeat*], or [*wave_chain*] NOTE: Any waveform started by [*wave_send_once*], [*wave_send_repeat*],
will be cancelled. or [*wave_chain*] will be cancelled.
This function is only valid if the pigpio main clock is PCM. The This function is only valid if the pigpio main clock is PCM. The
main clock defaults to PCM but may be overridden when the pigpio main clock defaults to PCM but may be overridden when the pigpio
@ -1081,8 +1078,9 @@ D*/
int wave_create(void); int wave_create(void);
/*D /*D
This function creates a waveform from the data provided by the prior This function creates a waveform from the data provided by the prior
calls to the [*wave_add_**] functions. Upon success a positive wave id calls to the [*wave_add_**] functions. Upon success a wave id
is returned. 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.
The data provided by the [*wave_add_**] functions is consumed by this The data provided by the [*wave_add_**] functions is consumed by this
function. function.
@ -1134,8 +1132,7 @@ D*/
/*F*/ /*F*/
int wave_delete(unsigned wave_id); int wave_delete(unsigned wave_id);
/*D /*D
This function deletes all created waveforms with ids greater than or This function deletes the waveform with id wave_id.
equal to wave_id.
. . . .
wave_id: >=0, as returned by [*wave_create*]. wave_id: >=0, as returned by [*wave_create*].
@ -1146,26 +1143,6 @@ Wave ids are allocated in order, 0, 1, 2, etc.
Returns 0 if OK, otherwise PI_BAD_WAVE_ID. Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
D*/ D*/
/*F*/
int wave_tx_start(void);
/*D
This function is deprecated and should no longer be used.
Use [*wave_create*]/[*wave_send_**] instead.
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
D*/
/*F*/
int wave_tx_repeat(void);
/*D
This function is deprecated and should no longer be used.
Use [*wave_create*]/[*wave_send_**] instead.
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
D*/
/*F*/ /*F*/
int wave_send_once(unsigned wave_id); int wave_send_once(unsigned wave_id);
/*D /*D
@ -1207,7 +1184,7 @@ This function transmits a chain of waveforms.
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled. NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
The waves to be transmitted are specified by the contents of buf The waves to be transmitted are specified by the contents of buf
which contains an ordered list of wave_ids and optional command which contains an ordered list of [*wave_id*]s and optional command
codes and related data. codes and related data.
. . . .
@ -1215,51 +1192,77 @@ codes and related data.
bufSize: the number of bytes in buf bufSize: the number of bytes in buf
. . . .
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID, Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID. PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
Each wave is transmitted in the order specified. A wave may only Each wave is transmitted in the order specified. A wave may
occur once per chain. Waves may be transmitted multiple times by occur multiple times per chain.
using the repeat command. The repeat command specifies a wave id
and a count. The wave id must occur earlier in the chain. All the
waves between wave id and the repeat command are transmitted count
times.
Repeat commands may not be nested. The minimum repeat count is 2. A blocks of waves may be transmitted multiple times by using
A maximum of 5 repeat commands is supported per chain. the loop commands. The block is bracketed by loop start and
end commands. Loops may be nested.
Delays between waves may be added with the delay command.
The following command codes are supported: The following command codes are supported:
Name @ Cmd & Data @ Meaning Name @ Cmd & Data @ Meaning
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times Loop Start @ 255 0 @ Identify start of a wave block
count = C0 + C1*256 + C2*65536 Loop Repeat @ 255 1 x y @ loop x + y*256 times
Delay @ 255 2 x y @ delay x + y*256 microseconds
The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
... ...
The following examples assume that waves with ids 0 to 12 exist. #include <stdio.h>
#include <pigpiod_if.h>
// 0 255 0 57 0 0 (repeat 0 57 times) #define WAVES 5
status = wave_chain((char []){0, 255, 0, 57, 0, 0}, 6); #define GPIO 4
// 0 1 255 0 0 2 0 (repeat 0+1 512 times) int main(int argc, char *argv[])
status = wave_chain((char []){0, 1, 255, 0, 0, 2, 0}, 7); {
int i, wid[WAVES];
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) if (pigpio_start(0, 0)<0) return -1;
status = wave_chain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) set_mode(GPIO, PI_OUTPUT);
status = wave_chain(
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
// The following repeats 5 65793 times, transmits 6, for (i=0; i<WAVES; i++)
// repeats 7+8 514 times, transmits 12, {
// repeats 9+11+10 197121 times. wave_add_generic(2, (gpioPulse_t[])
// 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3 {{1<<GPIO, 0, 20},
char chain[] = { {0, 1<<GPIO, (i+1)*200}});
5, 255, 5, 1, 1, 1,
6, 7, 8, 255, 7, 2, 2, 0,
12, 9, 11, 10, 255, 9, 1, 2, 3};
status = wave_chain(chain, sizeof(chain)); wid[i] = wave_create();
}
wave_chain((char []) {
wid[4], wid[3], wid[2], // transmit waves 4+3+2
255, 0, // loop start
wid[0], wid[0], wid[0], // transmit waves 0+0+0
255, 0, // loop start
wid[0], wid[1], // transmit waves 0+1
255, 2, 0x88, 0x13, // delay 5000us
255, 1, 30, 0, // loop end (repeat 30 times)
255, 0, // loop start
wid[2], wid[3], wid[0], // transmit waves 2+3+0
wid[3], wid[1], wid[2], // transmit waves 3+1+2
255, 1, 10, 0, // loop end (repeat 10 times)
255, 1, 5, 0, // loop end (repeat 5 times)
wid[4], wid[4], wid[4], // transmit waves 4+4+4
255, 2, 0x20, 0x4E, // delay 20000us
wid[0], wid[0], wid[0], // transmit waves 0+0+0
}, 46);
while (wave_tx_busy()) time_sleep(0.1);
for (i=0; i<WAVES; i++) wave_delete(wid[i]);
pigpio_stop();
}
... ...
D*/ D*/

154
pigs.1
View File

@ -674,8 +674,8 @@ frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz
are unlikely to work. are unlikely to work.
.br .br
NOTE: Any waveform started by \fBWVGO\fP, \fBWVGOR\fP, \fBWVTX\fP, NOTE: Any waveform started by \fBWVTX\fP, \fBWVTXR\fP, or \fBWVCHA\fP
\fBWVTXR\fP, or \fBWVCHA\fP will be cancelled. will be cancelled.
.br .br
This function is only valid if the pigpio main clock is PCM. The This function is only valid if the pigpio main clock is PCM. The
@ -3125,16 +3125,15 @@ will be returned.
.br .br
Each wave is transmitted in the order specified. A wave may Each wave is transmitted in the order specified. A wave may
only occur once per chain. Waves may be transmitted multiple occur multiple times per chain.
times by using the repeat command. The repeat command
specifies a wave id and a count. The wave id must occur
earlier in the chain. All the waves between wave id and the
repeat command are transmitted count times.
.br .br
Repeat commands may not be nested. The minimum repeat A blocks of waves may be transmitted multiple times by using
count is 2. A maximum of 5 repeat commands is supported the loop commands. The block is bracketed by loop start and
per chain. end commands. Loops may be nested.
.br
Delays between waves may be added with the delay command.
.br .br
The following command codes are supported: The following command codes are supported:
@ -3143,10 +3142,15 @@ The following command codes are supported:
.EX .EX
Name Cmd & Data Meaning Name Cmd & Data Meaning
Repeat 255 wid C0 C1 C2 Repeat from wid count times Loop Start 255 0 Identify start of a wave block
Loop Repeat 255 1 x y loop x + y*256 times
Delay 255 2 x y delay x + y*256 microseconds
.EE .EE
count = C0 + C1*256 + C2*65536
.br
The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
.br .br
@ -3154,43 +3158,103 @@ count = C0 + C1*256 + C2*65536
.br .br
.EX .EX
The following examples assume that waves with ids 0 to 12 exist. #!/bin/bash
.br .br
.br .br
# 0 255 0 57 0 0 (repeat 0 57 times) GPIO=4
.br .br
$ pigs wvcha 0 255 0 57 0 0 WAVES=5
.br .br
.br .br
# 0 1 255 0 0 2 0 (repeat 0+1 512 times) pigs m $GPIO w
.br
$ pigs wvcha 0 1 255 0 0 2 0
.br .br
.br .br
# 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times) for ((i=0; i<$WAVES; i++))
.br .br
$ pigs wvcha 0 1 255 1 0 0 1 do
.br
pigs wvag $((1<<GPIO)) 0 20 0 $((1<<GPIO)) $(((i+1)*200))
.br
w[i]=$(pigs wvcre)
.br
done
.br .br
.br .br
# 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times) # transmit waves 4+3+2
.br .br
$ pigs wvcha 0 1 2 3 255 2 13 0 0 # loop start
.br
# transmit waves 0+0+0
.br
# loop start
.br
# transmit waves 0+1
.br
# delay 5000us
.br
# loop end (repeat 30 times)
.br
# loop start
.br
# transmit waves 2+3+0
.br
# transmit waves 3+1+2
.br
# loop end (repeat 10 times)
.br
# loop end (repeat 5 times)
.br
# transmit waves 4+4+4
.br
# delay 20000us
.br
# transmit waves 0+0+0
.br .br
.br .br
# The following repeats 5 65793 times, transmits 6, pigs wvcha \\
.br .br
# repeats 7+8 514 times, transmits 12, ${w[4]} ${w[3]} ${w[2]} \\
.br .br
# repeats 9+11+10 197121 times. 255 0 \\
.br .br
# 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3 ${w[0]} ${w[0]} ${w[0]} \\
.br .br
$ pigs wvcha 5 255 5 1 1 1 6 7 8 255 7 2 2 0 12 9 11 10 255 9 1 2 3 255 0 \\
.br
${w[0]} ${w[1]} \\
.br
255 2 0x88 0x13 \\
.br
255 1 30 0 \\
.br
255 0 \\
.br
${w[2]} ${w[3]} ${w[0]} \\
.br
${w[3]} ${w[1]} ${w[2]} \\
.br
255 1 10 0 \\
.br
255 1 5 0 \\
.br
${w[4]} ${w[4]} ${w[4]} \\
.br
255 2 0x20 0x4E \\
.br
${w[0]} ${w[0]} ${w[0]}
.br
.br
while [[ $(pigs wvbsy) -eq 1 ]]; do sleep 0.1; done
.br
.br
for ((i=0; i<$WAVES; i++)); do echo ${w[i]}; pigs wvdel ${w[i]}; done
.br .br
.EE .EE
@ -3309,7 +3373,7 @@ ERROR: attempt to create an empty waveform
.IP "" 4 .IP "" 4
.br .br
This command deletes all waveforms with ids greater than or equal to \fBwid\fP. This command deletes the waveform with id \fBwid\fP.
.br .br
Upon success nothing is returned. On error a negative status code Upon success nothing is returned. On error a negative status code
@ -3336,36 +3400,6 @@ ERROR: non existent wave id
.br .br
.IP "\fBWVGO \fP - Transmit waveform once (DEPRECATED)"
.IP "" 4
.br
This command transmits the current waveform. The waveform is sent once.
.br
NOTE: Any hardware PWM started by \fBHP\fP will be cancelled.
.br
Upon success the number of DMA control blocks in the waveform is returned.
On error a negative status code will be returned.
.br
.IP "\fBWVGOR \fP - Transmit waveform repeatedly (DEPRECATED)"
.IP "" 4
.br
This command transmits the current waveform. The waveform is sent repeatedly.
.br
NOTE: Any hardware PWM started by \fBHP\fP will be cancelled.
.br
Upon success the number of DMA control blocks in the waveform is returned.
On error a negative status code will be returned.
.br
.IP "\fBWVHLT \fP - Stop waveform" .IP "\fBWVHLT \fP - Stop waveform"
.IP "" 4 .IP "" 4
@ -4059,7 +4093,7 @@ Again, ignore the details for now.
.br .br
.EX .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); [[ ${a::1} -eq 2 ]];\\
.br .br
do sleep 0.2; done) do sleep 0.2; done)
.br .br
@ -4099,7 +4133,7 @@ jp 999 jumps to tag 999 if the result is positive.
.br .br
.EX .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); [[ ${a::1} -eq 2 ]];\\
.br .br
do sleep 0.2; done) do sleep 0.2; done)
.br .br

View File

@ -3,7 +3,7 @@
from distutils.core import setup from distutils.core import setup
setup(name='pigpio', setup(name='pigpio',
version='1.19', version='1.20',
author='joan', author='joan',
author_email='joan@abyz.co.uk', author_email='joan@abyz.co.uk',
maintainer='joan', maintainer='joan',

View File

@ -363,7 +363,7 @@ To the lascivious pleasing of a lute.\n\
{0, 1<<GPIO, 100000}, {0, 1<<GPIO, 100000},
}; };
int e, oc, c; int e, oc, c, wid;
char text[2048]; char text[2048];
@ -379,7 +379,8 @@ To the lascivious pleasing of a lute.\n\
e = gpioWaveAddGeneric(4, wf); e = gpioWaveAddGeneric(4, wf);
CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); CHECK(5, 2, e, 4, 0, "pulse, wave add generic");
e = gpioWaveTxStart(PI_WAVE_MODE_REPEAT); wid = gpioWaveCreate();
e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT);
CHECK(5, 3, e, 9, 0, "wave tx repeat"); CHECK(5, 3, e, 9, 0, "wave tx repeat");
oc = t5_count; oc = t5_count;
@ -399,7 +400,8 @@ To the lascivious pleasing of a lute.\n\
e = gpioWaveAddSerial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); e = gpioWaveAddSerial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT);
CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial");
e = gpioWaveTxStart(PI_WAVE_MODE_ONE_SHOT); wid = gpioWaveCreate();
e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT);
CHECK(5, 8, e, 6811, 0, "wave tx start"); CHECK(5, 8, e, 6811, 0, "wave tx start");
CHECK(5, 9, 0, 0, 0, "NOT APPLICABLE"); CHECK(5, 9, 0, 0, 0, "NOT APPLICABLE");

View File

@ -356,8 +356,9 @@ To the lascivious pleasing of a lute.
e = pi.wave_add_generic(wf) e = pi.wave_add_generic(wf)
CHECK(5, 2, e, 4, 0, "pulse, wave add generic") CHECK(5, 2, e, 4, 0, "pulse, wave add generic")
e = pi.wave_tx_repeat() wid = pi.wave_create()
CHECK(5, 3, e, 9, 0, "wave tx repeat") e = pi.wave_send_repeat(wid)
CHECK(5, 3, e, 9, 0, "wave send repeat")
oc = t5_count oc = t5_count
time.sleep(5) time.sleep(5)
@ -374,8 +375,9 @@ To the lascivious pleasing of a lute.
e = pi.wave_add_serial(GPIO, BAUD, TEXT, 5000000) e = pi.wave_add_serial(GPIO, BAUD, TEXT, 5000000)
CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial") CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial")
e = pi.wave_tx_start() wid = pi.wave_create()
CHECK(5, 8, e, 6811, 0, "wave tx start") e = pi.wave_send_once(wid)
CHECK(5, 8, e, 6811, 0, "wave send once")
oc = t5_count oc = t5_count
time.sleep(3) time.sleep(3)

View File

@ -339,7 +339,7 @@ To the lascivious pleasing of a lute.\n\
{0, 1<<GPIO, 100000}, {0, 1<<GPIO, 100000},
}; };
int e, oc, c; int e, oc, c, wid;
char text[2048]; char text[2048];
@ -355,7 +355,8 @@ To the lascivious pleasing of a lute.\n\
e = wave_add_generic(4, wf); e = wave_add_generic(4, wf);
CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); CHECK(5, 2, e, 4, 0, "pulse, wave add generic");
e = wave_tx_repeat(); wid = wave_create();
e = wave_send_repeat(wid);
CHECK(5, 3, e, 9, 0, "wave tx repeat"); CHECK(5, 3, e, 9, 0, "wave tx repeat");
oc = t5_count; oc = t5_count;
@ -373,7 +374,8 @@ To the lascivious pleasing of a lute.\n\
e = wave_add_serial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); e = wave_add_serial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT);
CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial");
e = wave_tx_start(); wid = wave_create();
e = wave_send_once(wid);
CHECK(5, 8, e, 6811, 0, "wave tx start"); CHECK(5, 8, e, 6811, 0, "wave tx start");
oc = t5_count; oc = t5_count;

14
x_pigs
View File

@ -195,7 +195,9 @@ s=$(pigs wvas $GPIO 1200 8 2 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73
if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
s=$(pigs m $GPIO w) s=$(pigs m $GPIO w)
if [[ $s = "" ]]; then echo "SLR-d ok"; else echo "SLR-d fail ($s)"; fi if [[ $s = "" ]]; then echo "SLR-d ok"; else echo "SLR-d fail ($s)"; fi
s=$(pigs wvgo) w=$(pigs wvcre)
if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($s)"; fi
s=$(pigs wvtx $w)
if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
sleep 0.2 sleep 0.2
s=$(pigs slr $GPIO 100) s=$(pigs slr $GPIO 100)
@ -246,8 +248,10 @@ s=$(pigs wvas $GPIO 300 8 2 0 0x74 0x68 0x69 0x73 0x20 0x69 0x73 0x20 0x74 0x68
if [[ $s = 309 ]]; then echo "WVAS ok"; else echo "WVAS fail ($s)"; fi if [[ $s = 309 ]]; then echo "WVAS ok"; else echo "WVAS fail ($s)"; fi
s=$(pigs wvag 16 0 5000000 0 16 5000000) s=$(pigs wvag 16 0 5000000 0 16 5000000)
if [[ $s = 310 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi if [[ $s = 310 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi
s=$(pigs wvgo) w=$(pigs wvcre)
if [[ $s = 621 ]]; then echo "WVGO ok"; else echo "WVGO fail ($s)"; fi 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
s=$(pigs wvbsy) s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi
sleep 1 sleep 1
@ -257,8 +261,8 @@ s=$(pigs wvhlt)
if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi if [[ $s = "" ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
s=$(pigs wvbsy) s=$(pigs wvbsy)
if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi
s=$(pigs wvgor) s=$(pigs wvtxr $w)
if [[ $s = 621 ]]; then echo "WVGOR ok"; else echo "WVGOR fail ($s)"; fi if [[ $s = 621 ]]; then echo "WVTXR ok"; else echo "WVTXR fail ($s)"; fi
s=$(pigs wvbsy) s=$(pigs wvbsy)
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi
s=$(pigs wvhlt) s=$(pigs wvhlt)

16
x_pipe
View File

@ -270,7 +270,10 @@ if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
echo "m $GPIO w" >/dev/pigpio echo "m $GPIO w" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "SLR-d ok"; else echo "SLR-d fail ($s)"; fi if [[ $s = 0 ]]; then echo "SLR-d ok"; else echo "SLR-d fail ($s)"; fi
echo "wvgo" >/dev/pigpio echo "wvcre" >/dev/pigpio
read -t 1 w </dev/pigout
if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($w)"; fi
echo "wvtx $w" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
sleep 0.2 sleep 0.2
@ -339,9 +342,12 @@ if [[ $s = 215 ]]; then echo "WVAS ok"; else echo "WVAS fail ($s)"; fi
echo "wvag 16 0 5000000 0 16 5000000" >/dev/pigpio echo "wvag 16 0 5000000 0 16 5000000" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 216 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi if [[ $s = 216 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi
echo "wvgo" >/dev/pigpio echo "wvcre" >/dev/pigpio
read -t 1 w </dev/pigout
if [[ $w -ge 0 ]]; then echo "WVCRE ok"; else echo "WVCRE fail ($s)"; fi
echo "wvtx $w" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 433 ]]; then echo "WVGO ok"; else echo "WVGO fail ($s)"; fi if [[ $s = 433 ]]; then echo "WVTX ok"; else echo "WVTX fail ($s)"; fi
echo "wvbsy" >/dev/pigpio echo "wvbsy" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi
@ -355,9 +361,9 @@ if [[ $s = 0 ]]; then echo "WVHLT ok"; else echo "WVHLT fail ($s)"; fi
echo "wvbsy" >/dev/pigpio echo "wvbsy" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi if [[ $s = 0 ]]; then echo "WVBSY-c ok"; else echo "WVBSY-c fail ($s)"; fi
echo "wvgor" >/dev/pigpio echo "wvtxr $w" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 433 ]]; then echo "WVGOR ok"; else echo "WVGOR fail ($s)"; fi if [[ $s = 433 ]]; then echo "WVTXR ok"; else echo "WVTXR fail ($s)"; fi
echo "wvbsy" >/dev/pigpio echo "wvbsy" >/dev/pigpio
read -t 1 s </dev/pigout read -t 1 s </dev/pigout
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi