mirror of https://github.com/joan2937/pigpio
V35
This commit is contained in:
parent
927f3544f1
commit
33a222f80b
62
command.c
62
command.c
|
@ -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>
|
||||
|
@ -458,11 +458,14 @@ static errInfo_t errInfo[]=
|
|||
{PI_BAD_I2C_RLEN , "bad I2C read length"},
|
||||
{PI_BAD_I2C_CMD , "bad I2C command"},
|
||||
{PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"},
|
||||
{PI_BAD_REPEAT_CNT , "bad repeat count, not 2-max"},
|
||||
{PI_BAD_REPEAT_WID , "bad repeat wave id"},
|
||||
{PI_TOO_MANY_COUNTS , "too many chain counters"},
|
||||
{PI_BAD_CHAIN_CMD , "malformed chain command string"},
|
||||
{PI_REUSED_WID , "wave already used in chain"},
|
||||
{PI_CHAIN_LOOP_CNT , "bad chain loop count"},
|
||||
{PI_BAD_CHAIN_LOOP , "empty chain loop"},
|
||||
{PI_CHAIN_COUNTER , "too many chain counters"},
|
||||
{PI_BAD_CHAIN_CMD , "bad chain command"},
|
||||
{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;
|
||||
uint32_t tp1, tp2, tp3;
|
||||
int8_t to1, to2, to3;
|
||||
int eaten;
|
||||
|
||||
/* Check that ext is big enough for the largest message. */
|
||||
if (ext_len < (4 * CMD_MAX_PARAM)) return CMD_EXT_TOO_SMALL;
|
||||
|
@ -865,12 +869,16 @@ int cmdParse(
|
|||
|
||||
while (pars < CMD_MAX_PARAM)
|
||||
{
|
||||
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if ((to1 == CMD_NUMERIC) &&
|
||||
((int)tp1>=0) && ((int)tp1<=255))
|
||||
eaten = getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if (to1 == CMD_NUMERIC)
|
||||
{
|
||||
if (((int)tp1>=0) && ((int)tp1<=255))
|
||||
{
|
||||
pars++;
|
||||
*p8++ = tp1;
|
||||
ctl->eaten += eaten;
|
||||
}
|
||||
else break; /* invalid number, end of command */
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
@ -899,13 +907,16 @@ int cmdParse(
|
|||
|
||||
while (pars < 32)
|
||||
{
|
||||
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if ((to1 == CMD_NUMERIC) &&
|
||||
((int)tp1>=0) &&
|
||||
((int)tp1<=255))
|
||||
eaten = getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if (to1 == CMD_NUMERIC)
|
||||
{
|
||||
if (((int)tp1>=0) && ((int)tp1<=255))
|
||||
{
|
||||
pars++;
|
||||
*p8++ = tp1;
|
||||
ctl->eaten += eaten;
|
||||
}
|
||||
else break; /* invalid number, end of command */
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
@ -940,15 +951,16 @@ int cmdParse(
|
|||
|
||||
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 (((int)tp1>=0) && ((int)tp1<=255))
|
||||
{
|
||||
pars++;
|
||||
*p8++ = tp1;
|
||||
ctl->eaten += eaten;
|
||||
}
|
||||
else valid = 0;
|
||||
else break;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
@ -996,12 +1008,16 @@ int cmdParse(
|
|||
p8 = ext + 12;
|
||||
while (pars < CMD_MAX_PARAM)
|
||||
{
|
||||
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if ((to1 == CMD_NUMERIC) &&
|
||||
((int)tp1>=0) && ((int)tp1<=255))
|
||||
eaten = getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if (to1 == CMD_NUMERIC)
|
||||
{
|
||||
if (((int)tp1>=0) && ((int)tp1<=255))
|
||||
{
|
||||
*p8++ = tp1;
|
||||
pars++;
|
||||
ctl->eaten += eaten;
|
||||
}
|
||||
else break; /* invalid number, end of command */
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
@ -1022,12 +1038,16 @@ int cmdParse(
|
|||
|
||||
while (pars < CMD_MAX_PARAM)
|
||||
{
|
||||
ctl->eaten += getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if ((to1 == CMD_NUMERIC) &&
|
||||
((int)tp1>=0) && ((int)tp1<=255))
|
||||
eaten = getNum(buf+ctl->eaten, &tp1, &to1);
|
||||
if (to1 == CMD_NUMERIC)
|
||||
{
|
||||
if (((int)tp1>=0) && ((int)tp1<=255))
|
||||
{
|
||||
pars++;
|
||||
*p8++ = tp1;
|
||||
ctl->eaten += eaten;
|
||||
}
|
||||
else break; /* invalid number, end of command */
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
|
213
pigpio.3
213
pigpio.3
|
@ -1683,8 +1683,9 @@ gpioWaveAddSerial(4, 9600, 8, 2, 1000000, MSG_LEN, data);
|
|||
.IP "\fBint gpioWaveCreate(void)\fP"
|
||||
.IP "" 4
|
||||
This function creates a waveform from the data provided by the prior
|
||||
calls to the \fBgpioWaveAdd*\fP functions. Upon success a positive wave id
|
||||
is returned.
|
||||
calls to the \fBgpioWaveAdd*\fP functions. Upon success a wave id
|
||||
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
|
||||
|
||||
|
@ -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 "" 4
|
||||
This function deletes all created waveforms with ids greater than or
|
||||
equal to wave_id.
|
||||
This function deletes the waveform with id wave_id.
|
||||
|
||||
.br
|
||||
|
||||
|
@ -1811,38 +1811,6 @@ Wave ids are allocated in order, 0, 1, 2, etc.
|
|||
.br
|
||||
Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
|
||||
|
||||
.IP "\fBint gpioWaveTxStart(unsigned wave_mode)\fP"
|
||||
.IP "" 4
|
||||
This function creates and then transmits a waveform. The mode
|
||||
determines whether the waveform is sent once or cycles endlessly.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
|
||||
.EX
|
||||
wave_mode: 0 (PI_WAVE_MODE_ONE_SHOT), 1 (PI_WAVE_MODE_REPEAT)
|
||||
.br
|
||||
|
||||
.EE
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
This function is deprecated and should no longer be used. Use
|
||||
\fBgpioWaveCreate\fP and \fBgpioWaveTxSend\fP instead.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
Returns the number of DMA control blocks in the waveform if OK,
|
||||
otherwise PI_BAD_WAVE_MODE.
|
||||
|
||||
.IP "\fBint gpioWaveTxSend(unsigned wave_id, unsigned wave_mode)\fP"
|
||||
.IP "" 4
|
||||
This function transmits the waveform with id wave_id. The mode
|
||||
|
@ -1884,7 +1852,7 @@ NOTE: Any hardware PWM started by \fBgpioHardwarePWM\fP will be cancelled.
|
|||
|
||||
.br
|
||||
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.
|
||||
|
||||
.br
|
||||
|
@ -1902,24 +1870,26 @@ bufSize: the number of bytes in buf
|
|||
.br
|
||||
|
||||
.br
|
||||
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID,
|
||||
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID.
|
||||
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.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
Each wave is transmitted in the order specified. A wave may only
|
||||
occur once per chain. Waves may be transmitted multiple 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.
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
occur multiple times per chain.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
Repeat commands may not be nested. The minimum repeat count is 2.
|
||||
A maximum of 5 repeat commands is supported per chain.
|
||||
A blocks of waves may be transmitted multiple times by using
|
||||
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
|
||||
|
||||
|
@ -1932,10 +1902,21 @@ The following command codes are supported:
|
|||
Name Cmd & Data Meaning
|
||||
|
||||
.br
|
||||
Repeat 255 wid C0 C1 C2 Repeat from wid count times
|
||||
Loop Start 255 0 Identify start of a wave block
|
||||
|
||||
.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
|
||||
|
||||
|
@ -1944,55 +1925,109 @@ count = C0 + C1*256 + C2*65536
|
|||
.br
|
||||
|
||||
.EX
|
||||
The following examples assume that waves with ids 0 to 12 exist.
|
||||
#include <stdio.h>
|
||||
.br
|
||||
#include <pigpio.h>
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 255 0 57 0 0 (repeat 0 57 times)
|
||||
#define WAVES 5
|
||||
.br
|
||||
status = gpioWaveChain((char []){0, 255, 0, 57, 0, 0}, 6);
|
||||
#define GPIO 4
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
int main(int argc, char *argv[])
|
||||
.br
|
||||
status = gpioWaveChain((char []){0, 1, 255, 0, 0, 2, 0}, 7);
|
||||
{
|
||||
.br
|
||||
int i, wid[WAVES];
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
.br
|
||||
status = gpioWaveChain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
|
||||
if (gpioInitialise()<0) return -1;
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
.br
|
||||
status = gpioWaveChain(
|
||||
.br
|
||||
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
|
||||
gpioSetMode(GPIO, PI_OUTPUT);
|
||||
.br
|
||||
|
||||
.br
|
||||
// The following repeats 5 65793 times, transmits 6,
|
||||
.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};
|
||||
printf("start piscope, press return\n"); getchar();
|
||||
.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
|
||||
|
||||
.EE
|
||||
|
@ -4386,8 +4421,8 @@ Frequencies above 30MHz are unlikely to work.
|
|||
.br
|
||||
|
||||
.br
|
||||
NOTE: Any waveform started by \fBgpioWaveTxSend\fP, \fBgpioWaveTxStart\fP,
|
||||
or \fBgpioWaveChain\fP will be cancelled.
|
||||
NOTE: Any waveform started by \fBgpioWaveTxSend\fP, or
|
||||
\fBgpioWaveChain\fP will be cancelled.
|
||||
|
||||
.br
|
||||
|
||||
|
@ -7022,7 +7057,7 @@ Denoting no parameter is required
|
|||
.br
|
||||
|
||||
.br
|
||||
A number representing a waveform created by \fBgpioWaveCreate\fP.
|
||||
A number identifying a waveform created by \fBgpioWaveCreate\fP.
|
||||
|
||||
.br
|
||||
|
||||
|
@ -7514,15 +7549,21 @@ A 16-bit word value.
|
|||
.br
|
||||
#define PI_BAD_I2C_BAUD -112 // bad I2C baud rate, not 50-500k
|
||||
.br
|
||||
#define PI_BAD_REPEAT_CNT -113 // bad repeat count, not 2-max
|
||||
#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
|
||||
.br
|
||||
#define PI_BAD_REPEAT_WID -114 // bad repeat wave id
|
||||
#define PI_BAD_CHAIN_LOOP -114 // empty chain loop
|
||||
.br
|
||||
#define PI_TOO_MANY_COUNTS -115 // too many chain counters
|
||||
#define PI_CHAIN_COUNTER -115 // too many chain counters
|
||||
.br
|
||||
#define PI_BAD_CHAIN_CMD -116 // malformed chain command string
|
||||
#define PI_BAD_CHAIN_CMD -116 // bad chain command
|
||||
.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
|
||||
|
|
178
pigpio.h
178
pigpio.h
|
@ -31,7 +31,7 @@ For more information, please refer to <http://unlicense.org/>
|
|||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define PIGPIO_VERSION 34
|
||||
#define PIGPIO_VERSION 35
|
||||
|
||||
/*TEXT
|
||||
|
||||
|
@ -197,7 +197,7 @@ gpioWaveAddGeneric Adds a series of pulses to the waveform
|
|||
gpioWaveAddSerial Adds serial data to the waveform
|
||||
|
||||
gpioWaveCreate Creates a waveform from added data
|
||||
gpioWaveDelete Deletes one or more waveforms
|
||||
gpioWaveDelete Deletes 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
|
||||
gpioWaveGetMaxCbs Absolute maximum allowed control blocks
|
||||
|
||||
gpioWaveTxStart Creates/transmits a waveform (DEPRECATED)
|
||||
|
||||
I2C
|
||||
|
||||
i2cOpen Opens an I2C device
|
||||
|
@ -383,12 +381,31 @@ typedef struct
|
|||
uint32_t flags;
|
||||
} 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
|
||||
{
|
||||
uint16_t botCB; /* first CB used by wave */
|
||||
uint16_t topCB; /* last CB used by wave */
|
||||
uint16_t botOOL; /* last OOL used by wave */
|
||||
uint16_t topOOL; /* first OOL used by wave */
|
||||
uint16_t botOOL; /* first bottom 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;
|
||||
|
||||
typedef struct
|
||||
|
@ -550,9 +567,11 @@ typedef void *(gpioThreadFunc_t) (void *);
|
|||
#define PI_WAVE_MAX_MICROS (30 * 60 * 1000000) /* half an hour */
|
||||
|
||||
#define PI_MAX_WAVES 250
|
||||
//#define PI_MAX_WAVE_CYCLES 537824
|
||||
#define PI_MAX_WAVE_CYCLES 16777216
|
||||
#define PI_WAVE_COUNTERS 5
|
||||
|
||||
#define PI_MAX_WAVE_CYCLES 65535
|
||||
#define PI_MAX_WAVE_DELAY 65535
|
||||
|
||||
#define PI_WAVE_COUNT_PAGES 10
|
||||
|
||||
/* wave tx mode */
|
||||
|
||||
|
@ -1511,8 +1530,9 @@ D*/
|
|||
int gpioWaveCreate(void);
|
||||
/*D
|
||||
This function creates a waveform from the data provided by the prior
|
||||
calls to the [*gpioWaveAdd**] functions. Upon success a positive wave id
|
||||
is returned.
|
||||
calls to the [*gpioWaveAdd**] functions. Upon success a wave id
|
||||
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
|
||||
function.
|
||||
|
@ -1564,8 +1584,7 @@ D*/
|
|||
/*F*/
|
||||
int gpioWaveDelete(unsigned wave_id);
|
||||
/*D
|
||||
This function deletes all created waveforms with ids greater than or
|
||||
equal to wave_id.
|
||||
This function deletes the waveform with id wave_id.
|
||||
|
||||
. .
|
||||
wave_id: >=0, as returned by [*gpioWaveCreate*]
|
||||
|
@ -1577,26 +1596,6 @@ Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
|
|||
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*/
|
||||
int gpioWaveTxSend(unsigned wave_id, unsigned wave_mode);
|
||||
/*D
|
||||
|
@ -1623,7 +1622,7 @@ This function transmits a chain of waveforms.
|
|||
NOTE: Any hardware PWM started by [*gpioHardwarePWM*] will be cancelled.
|
||||
|
||||
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.
|
||||
|
||||
. .
|
||||
|
@ -1631,51 +1630,81 @@ codes and related data.
|
|||
bufSize: the number of bytes in buf
|
||||
. .
|
||||
|
||||
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID,
|
||||
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID.
|
||||
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.
|
||||
|
||||
Each wave is transmitted in the order specified. A wave may only
|
||||
occur once per chain. Waves may be transmitted multiple 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.
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
occur multiple times per chain.
|
||||
|
||||
Repeat commands may not be nested. The minimum repeat count is 2.
|
||||
A maximum of 5 repeat commands is supported per chain.
|
||||
A blocks of waves may be transmitted multiple times by using
|
||||
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:
|
||||
|
||||
Name @ Cmd & Data @ Meaning
|
||||
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times
|
||||
count = C0 + C1*256 + C2*65536
|
||||
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
|
||||
|
||||
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)
|
||||
status = gpioWaveChain((char []){0, 255, 0, 57, 0, 0}, 6);
|
||||
#define WAVES 5
|
||||
#define GPIO 4
|
||||
|
||||
// 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
status = gpioWaveChain((char []){0, 1, 255, 0, 0, 2, 0}, 7);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, wid[WAVES];
|
||||
|
||||
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
status = gpioWaveChain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
|
||||
if (gpioInitialise()<0) return -1;
|
||||
|
||||
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
status = gpioWaveChain(
|
||||
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
|
||||
gpioSetMode(GPIO, PI_OUTPUT);
|
||||
|
||||
// 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
|
||||
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};
|
||||
printf("start piscope, press return\n"); getchar();
|
||||
|
||||
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*/
|
||||
|
||||
|
@ -3135,8 +3164,8 @@ int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty);
|
|||
Starts hardware PWM on a gpio at the specified frequency and dutycycle.
|
||||
Frequencies above 30MHz are unlikely to work.
|
||||
|
||||
NOTE: Any waveform started by [*gpioWaveTxSend*], [*gpioWaveTxStart*],
|
||||
or [*gpioWaveChain*] will be cancelled.
|
||||
NOTE: Any waveform started by [*gpioWaveTxSend*], or
|
||||
[*gpioWaveChain*] will be cancelled.
|
||||
|
||||
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
|
||||
|
@ -4428,7 +4457,7 @@ Denoting no parameter is required
|
|||
|
||||
wave_id::
|
||||
|
||||
A number representing a waveform created by [*gpioWaveCreate*].
|
||||
A number identifying a waveform created by [*gpioWaveCreate*].
|
||||
|
||||
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_CMD -111 // bad I2C command
|
||||
#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_BAD_REPEAT_WID -114 // bad repeat wave id
|
||||
#define PI_TOO_MANY_COUNTS -115 // too many chain counters
|
||||
#define PI_BAD_CHAIN_CMD -116 // malformed chain command string
|
||||
#define PI_REUSED_WID -117 // wave already used in chain
|
||||
#define PI_CHAIN_LOOP_CNT -113 // bad chain loop count
|
||||
#define PI_BAD_CHAIN_LOOP -114 // empty chain loop
|
||||
#define PI_CHAIN_COUNTER -115 // too many chain counters
|
||||
#define PI_BAD_CHAIN_CMD -116 // bad chain command
|
||||
#define PI_BAD_CHAIN_DELAY -117 // bad chain delay micros
|
||||
#define PI_CHAIN_NESTING -118 // chain counters nested too deeply
|
||||
#define PI_CHAIN_TOO_BIG -119 // chain is too long
|
||||
#define PI_DEPRECATED -120 // deprecated function removed
|
||||
|
||||
#define PI_PIGIF_ERR_0 -2000
|
||||
#define PI_PIGIF_ERR_99 -2099
|
||||
|
|
174
pigpio.py
174
pigpio.py
|
@ -182,9 +182,6 @@ wave_chain Transmits a chain of waveforms
|
|||
wave_tx_busy Checks to see if a waveform has ended
|
||||
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_max_micros Absolute maximum allowed micros
|
||||
wave_get_pulses Length in pulses of the current waveform
|
||||
|
@ -266,7 +263,7 @@ import threading
|
|||
import os
|
||||
import atexit
|
||||
|
||||
VERSION = "1.19"
|
||||
VERSION = "1.20"
|
||||
|
||||
exceptions = True
|
||||
|
||||
|
@ -550,11 +547,14 @@ PI_BAD_I2C_WLEN =-109
|
|||
PI_BAD_I2C_RLEN =-110
|
||||
PI_BAD_I2C_CMD =-111
|
||||
PI_BAD_I2C_BAUD =-112
|
||||
PI_BAD_REPEAT_CNT =-113
|
||||
PI_BAD_REPEAT_WID =-114
|
||||
PI_TOO_MANY_COUNTS =-115
|
||||
PI_CHAIN_LOOP_CNT =-113
|
||||
PI_BAD_CHAIN_LOOP =-114
|
||||
PI_CHAIN_COUNTER =-115
|
||||
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
|
||||
|
||||
|
@ -669,11 +669,14 @@ _errors=[
|
|||
[PI_BAD_I2C_RLEN , "bad I2C read length"],
|
||||
[PI_BAD_I2C_CMD , "bad I2C command"],
|
||||
[PI_BAD_I2C_BAUD , "bad I2C baud rate, not 50-500k"],
|
||||
[PI_BAD_REPEAT_CNT , "bad repeat count, not 2-max"],
|
||||
[PI_BAD_REPEAT_WID , "bad repeat wave id"],
|
||||
[PI_TOO_MANY_COUNTS , "too many chain counters"],
|
||||
[PI_BAD_CHAIN_CMD , "malformed chain command string"],
|
||||
[PI_REUSED_WID , "wave already used in chain"],
|
||||
[PI_CHAIN_LOOP_CNT , "bad chain loop count"],
|
||||
[PI_BAD_CHAIN_LOOP , "empty chain loop"],
|
||||
[PI_CHAIN_COUNTER , "too many chain counters"],
|
||||
[PI_BAD_CHAIN_CMD , "bad chain command"],
|
||||
[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.
|
||||
|
||||
NOTE: Any waveform started by [*wave_send_once*],
|
||||
[*wave_send_repeat*], [*wave_tx_start*], [*wave_tx_repeat*],
|
||||
or [*wave_chain*] will be cancelled.
|
||||
[*wave_send_repeat*], or [*wave_chain*] will be cancelled.
|
||||
|
||||
This function is only valid if the pigpio main clock is PCM.
|
||||
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
|
||||
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
|
||||
this function.
|
||||
|
@ -1864,40 +1867,33 @@ class pi():
|
|||
|
||||
def wave_delete(self, wave_id):
|
||||
"""
|
||||
Deletes all created waveforms with ids greater than or equal
|
||||
to wave_id.
|
||||
This function deletes the waveform with id wave_id.
|
||||
|
||||
wave_id:= >=0 (as returned by a prior call to [*wave_create*]).
|
||||
|
||||
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))
|
||||
|
||||
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.
|
||||
|
||||
NOTE: Any hardware PWM started by [*hardware_PWM*] will
|
||||
be cancelled.
|
||||
"""
|
||||
return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGO, 0, 0))
|
||||
|
||||
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.
|
||||
|
||||
NOTE: Any hardware PWM started by [*hardware_PWM*] will
|
||||
be cancelled.
|
||||
"""
|
||||
return _u2i(_pigpio_command(self.sl, _PI_CMD_WVGOR, 0, 0))
|
||||
|
||||
|
@ -1975,58 +1971,84 @@ class pi():
|
|||
"""
|
||||
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
|
||||
data which contains an ordered list of wave_ids and optional
|
||||
command codes and related data.
|
||||
The waves to be transmitted are specified by the contents
|
||||
of data which contains an ordered list of [*wave_id*]s
|
||||
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,
|
||||
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID.
|
||||
Each wave is transmitted in the order specified. A wave
|
||||
may occur multiple times per chain.
|
||||
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
only occur once per chain. Waves may be transmitted multiple
|
||||
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.
|
||||
A blocks of waves may be transmitted multiple times by
|
||||
using the loop commands. The block is bracketed by loop
|
||||
start and end commands. Loops may be nested.
|
||||
|
||||
Repeat commands may not be nested. The minimum repeat
|
||||
count is 2. A maximum of 5 repeat commands is supported
|
||||
per chain.
|
||||
Delays between waves may be added with the delay command.
|
||||
|
||||
The following command codes are supported:
|
||||
|
||||
Name @ Cmd & Data @ Meaning
|
||||
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times
|
||||
count = C0 + C1*256 + C2*65536
|
||||
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
|
||||
|
||||
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)
|
||||
pi.wave_chain([0, 255, 0, 57, 0, 0])
|
||||
import time
|
||||
import pigpio
|
||||
|
||||
# 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
pi.wave_chain([0, 1, 255, 0, 0, 2, 0])
|
||||
WAVES=5
|
||||
GPIO=4
|
||||
|
||||
# 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
pi.wave_chain([0, 1, 255, 1, 0, 0, 1])
|
||||
wid=[0]*WAVES
|
||||
|
||||
# 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
pi.wave_chain([0, 1, 2, 3, 255, 2, 13, 0, 0])
|
||||
pi = pigpio.pi() # Connect to local Pi.
|
||||
|
||||
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([
|
||||
5, 255, 5, 1, 1, 1,
|
||||
6, 7, 8, 255, 7, 2, 2, 0,
|
||||
12, 9, 11, 10, 255, 9, 1, 2, 3])
|
||||
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
|
||||
])
|
||||
|
||||
while pi.wave_tx_busy():
|
||||
time.sleep(0.1);
|
||||
|
||||
for i in range(WAVES):
|
||||
pi.wave_delete(wid[i])
|
||||
|
||||
pi.stop()
|
||||
...
|
||||
"""
|
||||
# I p1 0
|
||||
|
@ -3386,12 +3408,18 @@ class pi():
|
|||
edge:= EITHER_EDGE, RISING_EDGE (default), or FALLING_EDGE.
|
||||
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 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):
|
||||
print(gpio, level, tick)
|
||||
|
@ -3403,6 +3431,8 @@ class pi():
|
|||
cb3 = pi.callback(17)
|
||||
|
||||
print(cb3.tally())
|
||||
|
||||
cb1.cancel() # To cancel callback cb1.
|
||||
...
|
||||
"""
|
||||
return _callback(self._notify, user_gpio, edge, func)
|
||||
|
@ -3594,6 +3624,7 @@ def xref():
|
|||
RISING_EDGE = 0
|
||||
|
||||
errnum: <0
|
||||
|
||||
. .
|
||||
PI_BAD_USER_GPIO = -2
|
||||
PI_BAD_GPIO = -3
|
||||
|
@ -3679,11 +3710,14 @@ def xref():
|
|||
PI_BAD_I2C_RLEN = -110
|
||||
PI_BAD_I2C_CMD = -111
|
||||
PI_BAD_I2C_BAUD = -112
|
||||
PI_BAD_REPEAT_CNT =-113
|
||||
PI_BAD_REPEAT_WID =-114
|
||||
PI_TOO_MANY_COUNTS =-115
|
||||
PI_CHAIN_LOOP_CNT = -113
|
||||
PI_BAD_CHAIN_LOOP = -114
|
||||
PI_CHAIN_COUNTER = -115
|
||||
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
|
||||
|
|
175
pigpiod_if.3
175
pigpiod_if.3
|
@ -1221,8 +1221,8 @@ Frequencies above 30MHz are unlikely to work.
|
|||
.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
|
||||
will be cancelled.
|
||||
NOTE: Any waveform started by \fBwave_send_once\fP, \fBwave_send_repeat\fP,
|
||||
or \fBwave_chain\fP will be cancelled.
|
||||
|
||||
.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 "" 4
|
||||
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
|
||||
is returned.
|
||||
calls to the \fBwave_add_*\fP functions. Upon success a wave id
|
||||
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
|
||||
|
||||
|
@ -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 "" 4
|
||||
This function deletes all created waveforms with ids greater than or
|
||||
equal to wave_id.
|
||||
This function deletes the waveform with id wave_id.
|
||||
|
||||
.br
|
||||
|
||||
|
@ -1622,34 +1622,6 @@ Wave ids are allocated in order, 0, 1, 2, etc.
|
|||
.br
|
||||
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 "" 4
|
||||
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
|
||||
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.
|
||||
|
||||
.br
|
||||
|
@ -1734,24 +1706,26 @@ bufSize: the number of bytes in buf
|
|||
.br
|
||||
|
||||
.br
|
||||
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID,
|
||||
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID.
|
||||
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.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
Each wave is transmitted in the order specified. A wave may only
|
||||
occur once per chain. Waves may be transmitted multiple 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.
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
occur multiple times per chain.
|
||||
|
||||
.br
|
||||
|
||||
.br
|
||||
Repeat commands may not be nested. The minimum repeat count is 2.
|
||||
A maximum of 5 repeat commands is supported per chain.
|
||||
A blocks of waves may be transmitted multiple times by using
|
||||
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
|
||||
|
||||
|
@ -1764,10 +1738,21 @@ The following command codes are supported:
|
|||
Name Cmd & Data Meaning
|
||||
|
||||
.br
|
||||
Repeat 255 wid C0 C1 C2 Repeat from wid count times
|
||||
Loop Start 255 0 Identify start of a wave block
|
||||
|
||||
.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
|
||||
|
||||
|
@ -1776,55 +1761,101 @@ count = C0 + C1*256 + C2*65536
|
|||
.br
|
||||
|
||||
.EX
|
||||
The following examples assume that waves with ids 0 to 12 exist.
|
||||
#include <stdio.h>
|
||||
.br
|
||||
#include <pigpiod_if.h>
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 255 0 57 0 0 (repeat 0 57 times)
|
||||
#define WAVES 5
|
||||
.br
|
||||
status = wave_chain((char []){0, 255, 0, 57, 0, 0}, 6);
|
||||
#define GPIO 4
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
int main(int argc, char *argv[])
|
||||
.br
|
||||
status = wave_chain((char []){0, 1, 255, 0, 0, 2, 0}, 7);
|
||||
{
|
||||
.br
|
||||
int i, wid[WAVES];
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
.br
|
||||
status = wave_chain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
|
||||
if (pigpio_start(0, 0)<0) return -1;
|
||||
.br
|
||||
|
||||
.br
|
||||
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
.br
|
||||
status = wave_chain(
|
||||
.br
|
||||
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
|
||||
set_mode(GPIO, PI_OUTPUT);
|
||||
.br
|
||||
|
||||
.br
|
||||
// The following repeats 5 65793 times, transmits 6,
|
||||
for (i=0; i<WAVES; i++)
|
||||
.br
|
||||
// repeats 7+8 514 times, transmits 12,
|
||||
{
|
||||
.br
|
||||
// repeats 9+11+10 197121 times.
|
||||
wave_add_generic(2, (gpioPulse_t[])
|
||||
.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
|
||||
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};
|
||||
{0, 1<<GPIO, (i+1)*200}});
|
||||
.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
|
||||
|
||||
.EE
|
||||
|
|
|
@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|||
For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
|
||||
/* PIGPIOD_IF_VERSION 16 */
|
||||
/* PIGPIOD_IF_VERSION 17 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
127
pigpiod_if.h
127
pigpiod_if.h
|
@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
|
|||
|
||||
#include "pigpio.h"
|
||||
|
||||
#define PIGPIOD_IF_VERSION 16
|
||||
#define PIGPIOD_IF_VERSION 17
|
||||
|
||||
/*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_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_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.
|
||||
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*]
|
||||
will be cancelled.
|
||||
NOTE: Any waveform started by [*wave_send_once*], [*wave_send_repeat*],
|
||||
or [*wave_chain*] will be cancelled.
|
||||
|
||||
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
|
||||
|
@ -1081,8 +1078,9 @@ D*/
|
|||
int wave_create(void);
|
||||
/*D
|
||||
This function creates a waveform from the data provided by the prior
|
||||
calls to the [*wave_add_**] functions. Upon success a positive wave id
|
||||
is returned.
|
||||
calls to the [*wave_add_**] functions. Upon success a wave id
|
||||
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
|
||||
function.
|
||||
|
@ -1134,8 +1132,7 @@ D*/
|
|||
/*F*/
|
||||
int wave_delete(unsigned wave_id);
|
||||
/*D
|
||||
This function deletes all created waveforms with ids greater than or
|
||||
equal to wave_id.
|
||||
This function deletes the waveform with id wave_id.
|
||||
|
||||
. .
|
||||
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.
|
||||
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*/
|
||||
int wave_send_once(unsigned wave_id);
|
||||
/*D
|
||||
|
@ -1207,7 +1184,7 @@ This function transmits a chain of waveforms.
|
|||
NOTE: Any hardware PWM started by [*hardware_PWM*] will be cancelled.
|
||||
|
||||
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.
|
||||
|
||||
. .
|
||||
|
@ -1215,51 +1192,77 @@ codes and related data.
|
|||
bufSize: the number of bytes in buf
|
||||
. .
|
||||
|
||||
Returns 0 if OK, otherwise PI_BAD_REPEAT_CNT, PI_BAD_REPEAT_WID,
|
||||
PI_BAD_CHAIN_CMD, PI_TOO_MANY_COUNTS, or PI_BAD_WAVE_ID.
|
||||
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.
|
||||
|
||||
Each wave is transmitted in the order specified. A wave may only
|
||||
occur once per chain. Waves may be transmitted multiple 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.
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
occur multiple times per chain.
|
||||
|
||||
Repeat commands may not be nested. The minimum repeat count is 2.
|
||||
A maximum of 5 repeat commands is supported per chain.
|
||||
A blocks of waves may be transmitted multiple times by using
|
||||
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:
|
||||
|
||||
Name @ Cmd & Data @ Meaning
|
||||
Repeat @ 255 wid C0 C1 C2 @ Repeat from wid count times
|
||||
count = C0 + C1*256 + C2*65536
|
||||
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
|
||||
|
||||
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)
|
||||
status = wave_chain((char []){0, 255, 0, 57, 0, 0}, 6);
|
||||
#define WAVES 5
|
||||
#define GPIO 4
|
||||
|
||||
// 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
status = wave_chain((char []){0, 1, 255, 0, 0, 2, 0}, 7);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, wid[WAVES];
|
||||
|
||||
// 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
status = wave_chain((char []){0, 1, 255, 1, 0, 0, 1}, 7);
|
||||
if (pigpio_start(0, 0)<0) return -1;
|
||||
|
||||
// 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
status = wave_chain(
|
||||
(char []){0, 1, 2, 3, 255, 2, 13, 0, 0}, 9);
|
||||
set_mode(GPIO, PI_OUTPUT);
|
||||
|
||||
// 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
|
||||
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};
|
||||
for (i=0; i<WAVES; i++)
|
||||
{
|
||||
wave_add_generic(2, (gpioPulse_t[])
|
||||
{{1<<GPIO, 0, 20},
|
||||
{0, 1<<GPIO, (i+1)*200}});
|
||||
|
||||
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*/
|
||||
|
||||
|
|
154
pigs.1
154
pigs.1
|
@ -674,8 +674,8 @@ frequency \fBpf\fP with dutycycle \fBpdc\fP. Frequencies above 30MHz
|
|||
are unlikely to work.
|
||||
|
||||
.br
|
||||
NOTE: Any waveform started by \fBWVGO\fP, \fBWVGOR\fP, \fBWVTX\fP,
|
||||
\fBWVTXR\fP, or \fBWVCHA\fP will be cancelled.
|
||||
NOTE: Any waveform started by \fBWVTX\fP, \fBWVTXR\fP, or \fBWVCHA\fP
|
||||
will be cancelled.
|
||||
|
||||
.br
|
||||
This function is only valid if the pigpio main clock is PCM. The
|
||||
|
@ -3125,16 +3125,15 @@ will be returned.
|
|||
|
||||
.br
|
||||
Each wave is transmitted in the order specified. A wave may
|
||||
only occur once per chain. Waves may be transmitted multiple
|
||||
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.
|
||||
occur multiple times per chain.
|
||||
|
||||
.br
|
||||
Repeat commands may not be nested. The minimum repeat
|
||||
count is 2. A maximum of 5 repeat commands is supported
|
||||
per chain.
|
||||
A blocks of waves may be transmitted multiple times by using
|
||||
the loop commands. The block is bracketed by loop start and
|
||||
end commands. Loops may be nested.
|
||||
|
||||
.br
|
||||
Delays between waves may be added with the delay command.
|
||||
|
||||
.br
|
||||
The following command codes are supported:
|
||||
|
@ -3143,10 +3142,15 @@ The following command codes are supported:
|
|||
|
||||
.EX
|
||||
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
|
||||
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
|
||||
|
||||
|
@ -3154,43 +3158,103 @@ count = C0 + C1*256 + C2*65536
|
|||
.br
|
||||
|
||||
.EX
|
||||
The following examples assume that waves with ids 0 to 12 exist.
|
||||
#!/bin/bash
|
||||
.br
|
||||
|
||||
.br
|
||||
# 0 255 0 57 0 0 (repeat 0 57 times)
|
||||
GPIO=4
|
||||
.br
|
||||
$ pigs wvcha 0 255 0 57 0 0
|
||||
WAVES=5
|
||||
.br
|
||||
|
||||
.br
|
||||
# 0 1 255 0 0 2 0 (repeat 0+1 512 times)
|
||||
.br
|
||||
$ pigs wvcha 0 1 255 0 0 2 0
|
||||
pigs m $GPIO w
|
||||
.br
|
||||
|
||||
.br
|
||||
# 0 1 255 1 0 0 1 (transmit 0, repeat 1 65536 times)
|
||||
for ((i=0; i<$WAVES; i++))
|
||||
.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
|
||||
# 0 1 2 3 255 2 13 0 0 (transmit 0+1, repeat 2+3 13 times)
|
||||
# transmit waves 4+3+2
|
||||
.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
|
||||
# The following repeats 5 65793 times, transmits 6,
|
||||
pigs wvcha \\
|
||||
.br
|
||||
# repeats 7+8 514 times, transmits 12,
|
||||
${w[4]} ${w[3]} ${w[2]} \\
|
||||
.br
|
||||
# repeats 9+11+10 197121 times.
|
||||
255 0 \\
|
||||
.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
|
||||
$ 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
|
||||
|
||||
.EE
|
||||
|
@ -3309,7 +3373,7 @@ ERROR: attempt to create an empty waveform
|
|||
.IP "" 4
|
||||
|
||||
.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
|
||||
Upon success nothing is returned. On error a negative status code
|
||||
|
@ -3336,36 +3400,6 @@ ERROR: non existent wave id
|
|||
|
||||
.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 "" 4
|
||||
|
||||
|
@ -4059,7 +4093,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); [[ ${a::1} -eq 2 ]];\\
|
||||
.br
|
||||
do sleep 0.2; done)
|
||||
.br
|
||||
|
@ -4099,7 +4133,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); [[ ${a::1} -eq 2 ]];\\
|
||||
.br
|
||||
do sleep 0.2; done)
|
||||
.br
|
||||
|
|
2
setup.py
2
setup.py
|
@ -3,7 +3,7 @@
|
|||
from distutils.core import setup
|
||||
|
||||
setup(name='pigpio',
|
||||
version='1.19',
|
||||
version='1.20',
|
||||
author='joan',
|
||||
author_email='joan@abyz.co.uk',
|
||||
maintainer='joan',
|
||||
|
|
|
@ -363,7 +363,7 @@ To the lascivious pleasing of a lute.\n\
|
|||
{0, 1<<GPIO, 100000},
|
||||
};
|
||||
|
||||
int e, oc, c;
|
||||
int e, oc, c, wid;
|
||||
|
||||
char text[2048];
|
||||
|
||||
|
@ -379,7 +379,8 @@ To the lascivious pleasing of a lute.\n\
|
|||
e = gpioWaveAddGeneric(4, wf);
|
||||
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");
|
||||
|
||||
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);
|
||||
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, 9, 0, 0, 0, "NOT APPLICABLE");
|
||||
|
|
10
x_pigpio.py
10
x_pigpio.py
|
@ -356,8 +356,9 @@ To the lascivious pleasing of a lute.
|
|||
e = pi.wave_add_generic(wf)
|
||||
CHECK(5, 2, e, 4, 0, "pulse, wave add generic")
|
||||
|
||||
e = pi.wave_tx_repeat()
|
||||
CHECK(5, 3, e, 9, 0, "wave tx repeat")
|
||||
wid = pi.wave_create()
|
||||
e = pi.wave_send_repeat(wid)
|
||||
CHECK(5, 3, e, 9, 0, "wave send repeat")
|
||||
|
||||
oc = t5_count
|
||||
time.sleep(5)
|
||||
|
@ -374,8 +375,9 @@ To the lascivious pleasing of a lute.
|
|||
e = pi.wave_add_serial(GPIO, BAUD, TEXT, 5000000)
|
||||
CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial")
|
||||
|
||||
e = pi.wave_tx_start()
|
||||
CHECK(5, 8, e, 6811, 0, "wave tx start")
|
||||
wid = pi.wave_create()
|
||||
e = pi.wave_send_once(wid)
|
||||
CHECK(5, 8, e, 6811, 0, "wave send once")
|
||||
|
||||
oc = t5_count
|
||||
time.sleep(3)
|
||||
|
|
|
@ -339,7 +339,7 @@ To the lascivious pleasing of a lute.\n\
|
|||
{0, 1<<GPIO, 100000},
|
||||
};
|
||||
|
||||
int e, oc, c;
|
||||
int e, oc, c, wid;
|
||||
|
||||
char text[2048];
|
||||
|
||||
|
@ -355,7 +355,8 @@ To the lascivious pleasing of a lute.\n\
|
|||
e = wave_add_generic(4, wf);
|
||||
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");
|
||||
|
||||
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);
|
||||
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");
|
||||
|
||||
oc = t5_count;
|
||||
|
|
14
x_pigs
14
x_pigs
|
@ -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
|
||||
s=$(pigs m $GPIO w)
|
||||
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
|
||||
sleep 0.2
|
||||
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
|
||||
s=$(pigs wvag 16 0 5000000 0 16 5000000)
|
||||
if [[ $s = 310 ]]; then echo "WVAG ok"; else echo "WVAG fail ($s)"; fi
|
||||
s=$(pigs wvgo)
|
||||
if [[ $s = 621 ]]; then echo "WVGO ok"; else echo "WVGO 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
|
||||
s=$(pigs wvbsy)
|
||||
if [[ $s = 1 ]]; then echo "WVBSY-a ok"; else echo "WVBSY-a fail ($s)"; fi
|
||||
sleep 1
|
||||
|
@ -257,8 +261,8 @@ s=$(pigs wvhlt)
|
|||
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 wvgor)
|
||||
if [[ $s = 621 ]]; then echo "WVGOR ok"; else echo "WVGOR fail ($s)"; fi
|
||||
s=$(pigs wvtxr $w)
|
||||
if [[ $s = 621 ]]; 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)
|
||||
|
|
16
x_pipe
16
x_pipe
|
@ -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
|
||||
read -t 1 s </dev/pigout
|
||||
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
|
||||
if [[ $s = 191 ]]; then echo "SLR-e ok"; else echo "SLR-e fail ($s)"; fi
|
||||
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
|
||||
read -t 1 s </dev/pigout
|
||||
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
|
||||
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
|
||||
read -t 1 s </dev/pigout
|
||||
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
|
||||
read -t 1 s </dev/pigout
|
||||
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
|
||||
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
|
||||
read -t 1 s </dev/pigout
|
||||
if [[ $s = 1 ]]; then echo "WVBSY-d ok"; else echo "WVBSY-d fail ($s)"; fi
|
||||
|
|
Loading…
Reference in New Issue