This commit is contained in:
joan 2016-09-22 14:12:26 +01:00
parent 68ab0a9525
commit abe5f12942
16 changed files with 2403 additions and 658 deletions

View File

@ -94,3 +94,4 @@ Type 3
It is safe to read all the gpios. If you try to write a system gpio or change It is safe to read all the gpios. If you try to write a system gpio or change
its mode you can crash the Pi or corrupt the data on the SD card. its mode you can crash the Pi or corrupt the data on the SD card.

View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/ */
/* /*
This version is for pigpio version 55+ This version is for pigpio version 56+
*/ */
#include <stdio.h> #include <stdio.h>
@ -49,16 +49,16 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_BI2CO, "BI2CO", 131, 0}, // bbI2COpen {PI_CMD_BI2CO, "BI2CO", 131, 0}, // bbI2COpen
{PI_CMD_BI2CZ, "BI2CZ", 193, 6}, // bbI2CZip {PI_CMD_BI2CZ, "BI2CZ", 193, 6}, // bbI2CZip
{PI_CMD_BSPIC, "BSPIC", 112, 0}, // bbSPIClose
{PI_CMD_BSPIO, "BSPIO", 134, 0}, // bbSPIOpen
{PI_CMD_BSPIX, "BSPIX", 193, 6}, // bbSPIXfer
{PI_CMD_BR1, "BR1", 101, 3}, // gpioRead_Bits_0_31 {PI_CMD_BR1, "BR1", 101, 3}, // gpioRead_Bits_0_31
{PI_CMD_BR2, "BR2", 101, 3}, // gpioRead_Bits_32_53 {PI_CMD_BR2, "BR2", 101, 3}, // gpioRead_Bits_32_53
{PI_CMD_BS1, "BS1", 111, 1}, // gpioWrite_Bits_0_31_Set {PI_CMD_BS1, "BS1", 111, 1}, // gpioWrite_Bits_0_31_Set
{PI_CMD_BS2, "BS2", 111, 1}, // gpioWrite_Bits_32_53_Set {PI_CMD_BS2, "BS2", 111, 1}, // gpioWrite_Bits_32_53_Set
{PI_CMD_BSPIC, "BSPIC", 112, 0}, // bbSPIClose
{PI_CMD_BSPIO, "BSPIO", 134, 0}, // bbSPIOpen
{PI_CMD_BSPIX, "BSPIX", 193, 6}, // bbSPIXfer
{PI_CMD_CF1, "CF1", 195, 2}, // gpioCustom1 {PI_CMD_CF1, "CF1", 195, 2}, // gpioCustom1
{PI_CMD_CF2, "CF2", 195, 6}, // gpioCustom2 {PI_CMD_CF2, "CF2", 195, 6}, // gpioCustom2
@ -384,11 +384,18 @@ WVTX wid Transmit wave as one-shot\n\
WVTXM wid wmde Transmit wave using mode\n\ WVTXM wid wmde Transmit wave using mode\n\
WVTXR wid Transmit wave repeatedly\n\ WVTXR wid Transmit wave repeatedly\n\
\n\ \n\
\n\
Numbers may be entered as hex (prefix 0x), octal (prefix 0),\n\ Numbers may be entered as hex (prefix 0x), octal (prefix 0),\n\
otherwise they are assumed to be decimal.\n\ otherwise they are assumed to be decimal.\n\
\n\ \n\
man pigs for full details.\n\n"; Examples\n\
\n\
pigs w 4 1 # set GPIO 4 high\n\
pigs r 5 # read GPIO 5\n\
pigs t # get current tick\n\
pigs i2co 1 0x20 0 # get handle to device 0x20 on I2C bus 1\n\
\n\
man pigs for full details.\n\
\n";
typedef struct typedef struct
{ {
@ -945,11 +952,11 @@ int cmdParse(
(to5 == CMD_NUMERIC)) (to5 == CMD_NUMERIC))
{ {
p[3] = 5 * 4; p[3] = 5 * 4;
memcpy(ext, &tp1, 4); memcpy(ext+ 0, &tp1, 4);
memcpy(ext, &tp2, 4); memcpy(ext+ 4, &tp2, 4);
memcpy(ext, &tp3, 4); memcpy(ext+ 8, &tp3, 4);
memcpy(ext, &tp4, 4); memcpy(ext+12, &tp4, 4);
memcpy(ext, &tp5, 4); memcpy(ext+16, &tp5, 4);
valid = 1; valid = 1;
} }

View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/ */
/* /*
This version is for pigpio version 55+ This version is for pigpio version 56+
*/ */
#ifndef COMMAND_H #ifndef COMMAND_H

448
pigpio.3
View File

@ -1372,7 +1372,7 @@ if (h >= 0)
.br .br
.br .br
fd = open(str, "r"); fd = open(str, O_RDONLY);
.br .br
.br .br
@ -3453,6 +3453,301 @@ End
.EE .EE
.IP "\fBint bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags)\fP"
.IP "" 4
This function selects a set of GPIO for bit banging SPI with
a specified baud rate and mode.
.br
.br
.EX
CS: 0-31
.br
MISO: 0-31
.br
MOSI: 0-31
.br
SCLK: 0-31
.br
baud: 50-250000
.br
spiFlags: see below
.br
.EE
.br
.br
spiFlags consists of the least significant 22 bits.
.br
.br
.EX
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
.br
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
.br
.EE
.br
.br
mm defines the SPI mode, defaults to 0
.br
.br
.EX
Mode CPOL CPHA
.br
0 0 0
.br
1 0 1
.br
2 1 0
.br
3 1 1
.br
.EE
.br
.br
p is 0 if CS is active low (default) and 1 for active high.
.br
.br
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
.br
.br
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
.br
.br
The other bits in flags should be set to zero.
.br
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
.br
.br
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
.br
.br
\fBExample\fP
.br
.EX
bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
.br
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2
.br
.EE
.IP "\fBint bbSPIClose(unsigned CS)\fP"
.IP "" 4
This function stops bit banging SPI on a set of GPIO
opened with \fBbbSPIOpen\fP.
.br
.br
.EX
CS: 0-31, the CS GPIO used in a prior call to \fBbbSPIOpen\fP
.br
.EE
.br
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
.IP "\fBint bbSPIXfer(unsigned CS, char *inBuf, char *outBuf, unsigned count)\fP"
.IP "" 4
This function executes a bit banged SPI transfer.
.br
.br
.EX
CS: 0-31 (as used in a prior call to \fBbbSPIOpen\fP)
.br
inBuf: pointer to buffer to hold data to be sent
.br
outBuf: pointer to buffer to hold returned data
.br
count: size of data transfer
.br
.EE
.br
.br
Returns >= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
.br
.br
\fBExample\fP
.br
.EX
// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
.br
// sudo ./bbSPIx_test
.br
.br
.br
#include <stdio.h>
.br
.br
#include "pigpio.h"
.br
.br
#define CE0 5
.br
#define CE1 6
.br
#define MISO 13
.br
#define MOSI 19
.br
#define SCLK 12
.br
.br
int main(int argc, char *argv[])
.br
{
.br
int i, count, set_val, read_val;
.br
unsigned char inBuf[3];
.br
char cmd1[] = {0, 0};
.br
char cmd2[] = {12, 0};
.br
char cmd3[] = {1, 128, 0};
.br
.br
if (gpioInitialise() < 0)
.br
{
.br
fprintf(stderr, "pigpio initialisation failed.\n");
.br
return 1;
.br
}
.br
.br
bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
.br
bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
.br
.br
for (i=0; i<256; i++)
.br
{
.br
cmd1[1] = i;
.br
.br
count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC
.br
.br
if (count == 2)
.br
{
.br
count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC
.br
.br
if (count == 2)
.br
{
.br
set_val = inBuf[1];
.br
.br
count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC
.br
.br
if (count == 3)
.br
{
.br
read_val = ((inBuf[1]&3)<<8) | inBuf[2];
.br
printf("%d %d\n", set_val, read_val);
.br
}
.br
}
.br
}
.br
}
.br
.br
bbSPIClose(CE0);
.br
bbSPIClose(CE1);
.br
.br
gpioTerminate();
.br
.br
return 0;
.br
}
.br
.EE
.IP "\fBint spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)\fP" .IP "\fBint spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags)\fP"
.IP "" 4 .IP "" 4
This function returns a handle for the SPI device on the channel. This function returns a handle for the SPI device on the channel.
@ -6156,6 +6451,28 @@ method uses the mailbox property interface to allocate bus memory.
Auto will use the mailbox method unless a larger than default buffer Auto will use the mailbox method unless a larger than default buffer
size is requested with \fBgpioCfgBufferSize\fP. size is requested with \fBgpioCfgBufferSize\fP.
.IP "\fBint gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr)\fP"
.IP "" 4
Sets the network addresses which are allowed to talk over the
socket interface.
.br
.br
This function is only effective if called before \fBgpioInitialise\fP.
.br
.br
.EX
numSockAddr: 0-256 (0 means all addresses allowed)
.br
sockAddr: an array of permitted network addresses.
.br
.EE
.IP "\fBint gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)\fP" .IP "\fBint gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal)\fP"
.IP "" 4 .IP "" 4
Used to tune internal settings. Used to tune internal settings.
@ -6363,7 +6680,7 @@ Not intended for general use.
.IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP" .IP "\fBrawCbs_t *rawWaveCBAdr(int cbNum)\fP"
.IP "" 4 .IP "" 4
Return the Linux address of contol block cbNum. Return the (Linux) address of contol block cbNum.
.br .br
@ -6380,12 +6697,57 @@ cbNum: the cb of interest
.br .br
Not intended for general use. Not intended for general use.
.IP "\fBuint32_t rawWaveGetOOL(int pos)\fP"
.IP "" 4
Gets the OOL parameter stored at pos.
.br
.br
.EX
pos: the position of interest.
.br
.EE
.br
.br
Not intended for general use.
.IP "\fBvoid rawWaveSetOOL(int pos, uint32_t lVal)\fP"
.IP "" 4
Sets the OOL parameter stored at pos to value.
.br
.br
.EX
pos: the position of interest
.br
lVal: the value to write
.br
.EE
.br
.br
Not intended for general use.
.IP "\fBuint32_t rawWaveGetOut(int pos)\fP" .IP "\fBuint32_t rawWaveGetOut(int pos)\fP"
.IP "" 4 .IP "" 4
Gets the wave output parameter stored at pos. Gets the wave output parameter stored at pos.
.br .br
.br
DEPRECATED: use rawWaveGetOOL instead.
.br
.br .br
.EX .EX
@ -6405,6 +6767,11 @@ Sets the wave output parameter stored at pos to value.
.br .br
.br
DEPRECATED: use rawWaveSetOOL instead.
.br
.br .br
.EX .EX
@ -6426,6 +6793,11 @@ Gets the wave input value parameter stored at pos.
.br .br
.br
DEPRECATED: use rawWaveGetOOL instead.
.br
.br .br
.EX .EX
@ -6445,6 +6817,11 @@ Sets the wave input value stored at pos to value.
.br .br
.br
DEPRECATED: use rawWaveSetOOL instead.
.br
.br .br
.EX .EX
@ -6831,6 +7208,13 @@ command.
.br .br
.IP "\fBCS\fP" 0
The GPIO used for the slave select signal when bit banging SPI.
.br
.br
.IP "\fBdata_bits\fP: 1-32" 0 .IP "\fBdata_bits\fP: 1-32" 0
.br .br
@ -7481,6 +7865,13 @@ A value representing milliseconds.
.br .br
.IP "\fBMISO\fP" 0
The GPIO used for the MISO signal when bit banging SPI.
.br
.br
.IP "\fBmode\fP" 0 .IP "\fBmode\fP" 0
.br .br
@ -7554,6 +7945,13 @@ PI_FILE_TRUNC 16
.br .br
.IP "\fBMOSI\fP" 0
The GPIO used for the MOSI signal when bit banging SPI.
.br
.br
.IP "\fBnumBits\fP" 0 .IP "\fBnumBits\fP" 0
.br .br
@ -7595,6 +7993,18 @@ The number of segments in a combined I2C transaction.
.br .br
.IP "\fBnumSockAddr\fP" 0
The number of network addresses allowed to use the socket interface.
.br
.br
0 means all addresses allowed.
.br
.br
.IP "\fBoffset\fP" 0 .IP "\fBoffset\fP" 0
The associated data starts this number of microseconds from the start of The associated data starts this number of microseconds from the start of
the waveform. the waveform.
@ -7987,6 +8397,13 @@ The user GPIO to use for the clock when bit banging I2C.
.br .br
.IP "\fBSCLK\fP" 0
The GPIO used for the SCLK signal when bit banging SPI.
.br
.br
.IP "\fB*script\fP" 0 .IP "\fB*script\fP" 0
A pointer to the text of a script. A pointer to the text of a script.
@ -8134,6 +8551,19 @@ A standard type used to indicate the size of an object in bytes.
.br .br
.IP "\fB*sockAddr\fP" 0
An array of network addresses allowed to use the socket interface encoded
as 32 bit numbers.
.br
.br
E.g. address 192.168.1.66 would be encoded as 0x4201a8c0.
.br
.br
.IP "\fB*spi\fP" 0 .IP "\fB*spi\fP" 0
A pointer to a \fBrawSPI_t\fP structure. A pointer to a \fBrawSPI_t\fP structure.
@ -8174,7 +8604,7 @@ A SPI channel, 0-2.
.br .br
.IP "\fBspiFlags\fP" 0 .IP "\fBspiFlags\fP" 0
See \fBspiOpen\fP. See \fBspiOpen\fP and \fBbbSPIOpen\fP.
.br .br
@ -8744,6 +9174,14 @@ A 16-bit word value.
#define PI_CMD_SHELL 110 #define PI_CMD_SHELL 110
.br .br
.br
#define PI_CMD_BSPIC 111
.br
#define PI_CMD_BSPIO 112
.br
#define PI_CMD_BSPIX 113
.br
.br .br
.EE .EE
@ -9038,6 +9476,10 @@ A 16-bit word value.
.br .br
#define PI_BAD_SCRIPT_NAME -140 // bad script name #define PI_BAD_SCRIPT_NAME -140 // bad script name
.br .br
#define PI_BAD_SPI_BAUD -141 // bad SPI baud rate, not 50-500k
.br
#define PI_NOT_SPI_GPIO -142 // no bit bang SPI in progress on GPIO
.br
.br .br
#define PI_PIGIF_ERR_0 -2000 #define PI_PIGIF_ERR_0 -2000

812
pigpio.c

File diff suppressed because it is too large Load Diff

330
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 55 #define PIGPIO_VERSION 56
/*TEXT /*TEXT
@ -320,6 +320,7 @@ gpioCfgPermissions Configure the GPIO access permissions
gpioCfgInterfaces Configure user interfaces gpioCfgInterfaces Configure user interfaces
gpioCfgSocketPort Configure socket port gpioCfgSocketPort Configure socket port
gpioCfgMemAlloc Configure DMA memory allocation mode gpioCfgMemAlloc Configure DMA memory allocation mode
gpioCfgNetAddr Configure allowed network addresses
gpioCfgInternals Configure miscellaneous internals (DEPRECATED) gpioCfgInternals Configure miscellaneous internals (DEPRECATED)
gpioCfgGetInternals Get internal configuration settings gpioCfgGetInternals Get internal configuration settings
@ -352,6 +353,8 @@ rawWaveAddSPI Not intended for general use
rawWaveAddGeneric Not intended for general use rawWaveAddGeneric Not intended for general use
rawWaveCB Not intended for general use rawWaveCB Not intended for general use
rawWaveCBAdr Not intended for general use rawWaveCBAdr Not intended for general use
rawWaveGetOOL Not intended for general use
rawWaveSetOOL Not intended for general use
rawWaveGetOut Not intended for general use rawWaveGetOut Not intended for general use
rawWaveSetOut Not intended for general use rawWaveSetOut Not intended for general use
rawWaveGetIn Not intended for general use rawWaveGetIn Not intended for general use
@ -818,6 +821,10 @@ typedef void *(gpioThreadFunc_t) (void *);
#define PI_FROM_CURRENT 1 #define PI_FROM_CURRENT 1
#define PI_FROM_END 2 #define PI_FROM_END 2
/* Allowed socket connect addresses */
#define MAX_CONNECT_ADDRESSES 256
/*F*/ /*F*/
int gpioInitialise(void); int gpioInitialise(void);
/*D /*D
@ -1456,7 +1463,7 @@ if (h >= 0)
{ {
sprintf(str, "/dev/pigpio%d", h); sprintf(str, "/dev/pigpio%d", h);
fd = open(str, "r"); fd = open(str, O_RDONLY);
if (fd >= 0) if (fd >= 0)
{ {
@ -2626,92 +2633,6 @@ SDA: 0-31, the SDA GPIO used in a prior call to [*bbI2COpen*]
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO. Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
D*/ D*/
/*F*/
int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spiFlags);
/*D
This function selects a set of GPIO for bit banging SPI at a
specified baud rate.
Bit banging SPI allows the use of different GPIO for SPI than
for the hardware SPI ports.
. .
CS: 0-31
MISO: 0-31
MOSI: 0-31
SCLK: 0-31
baud: 50-250000
spiFlags: see below
. .
spiFlags consists of the least significant 22 bits.
. .
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m
. .
mm defines the SPI mode.
. .
Mode POL PHA
0 0 0
1 0 1
2 1 0
3 1 1
. .
p0 is 0 if CEx is active low (default) and 1 for active high.
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
The other bits in flags should be set to zero.
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
D*/
/*F*/
int bbSPIClose(unsigned CS);
/*D
This function stops bit banging SPI on a set of GPIO previously
opened with [*bbSPIOpen*].
. .
CS: 0-31, the CS GPIO used in a prior call to [*bbSPIOpen*]
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
D*/
/*F*/
int bbSPIXfer(
unsigned CS,
char *inBuf,
char *outBuf,
unsigned len);
/*D
This function executes an bit banged SPI transfer. The data
to be sent is specified by the contents of inBuf, received data
is stored into outBuf.
len specifies the amount of bytes to be transferred.
. .
CS: 0-31 (as used in a prior call to [*bbSPIOpen*])
inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
len: size of data transfer
. .
Returns >= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
The returned SPI data is stored in consecutive locations of outBuf.
D*/
/*F*/ /*F*/
int bbI2CZip( int bbI2CZip(
unsigned SDA, unsigned SDA,
@ -2783,6 +2704,161 @@ End
... ...
D*/ D*/
/*F*/
int bbSPIOpen(
unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK,
unsigned baud, unsigned spiFlags);
/*D
This function selects a set of GPIO for bit banging SPI with
a specified baud rate and mode.
. .
CS: 0-31
MISO: 0-31
MOSI: 0-31
SCLK: 0-31
baud: 50-250000
spiFlags: see below
. .
spiFlags consists of the least significant 22 bits.
. .
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
. .
mm defines the SPI mode, defaults to 0
. .
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
. .
p is 0 if CS is active low (default) and 1 for active high.
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
The other bits in flags should be set to zero.
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
...
bbSPIOpen(10, MISO, MOSI, SCLK, 10000, 0); // device 1
bbSPIOpen(11, MISO, MOSI, SCLK, 20000, 3); // device 2
...
D*/
/*F*/
int bbSPIClose(unsigned CS);
/*D
This function stops bit banging SPI on a set of GPIO
opened with [*bbSPIOpen*].
. .
CS: 0-31, the CS GPIO used in a prior call to [*bbSPIOpen*]
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
D*/
/*F*/
int bbSPIXfer(
unsigned CS,
char *inBuf,
char *outBuf,
unsigned count);
/*D
This function executes a bit banged SPI transfer.
. .
CS: 0-31 (as used in a prior call to [*bbSPIOpen*])
inBuf: pointer to buffer to hold data to be sent
outBuf: pointer to buffer to hold returned data
count: size of data transfer
. .
Returns >= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
...
// gcc -Wall -pthread -o bbSPIx_test bbSPIx_test.c -lpigpio
// sudo ./bbSPIx_test
#include <stdio.h>
#include "pigpio.h"
#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12
int main(int argc, char *argv[])
{
int i, count, set_val, read_val;
unsigned char inBuf[3];
char cmd1[] = {0, 0};
char cmd2[] = {12, 0};
char cmd3[] = {1, 128, 0};
if (gpioInitialise() < 0)
{
fprintf(stderr, "pigpio initialisation failed.\n");
return 1;
}
bbSPIOpen(CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
bbSPIOpen(CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
for (i=0; i<256; i++)
{
cmd1[1] = i;
count = bbSPIXfer(CE0, cmd1, (char *)inBuf, 2); // > DAC
if (count == 2)
{
count = bbSPIXfer(CE0, cmd2, (char *)inBuf, 2); // < DAC
if (count == 2)
{
set_val = inBuf[1];
count = bbSPIXfer(CE1, cmd3, (char *)inBuf, 3); // < ADC
if (count == 3)
{
read_val = ((inBuf[1]&3)<<8) | inBuf[2];
printf("%d %d\n", set_val, read_val);
}
}
}
}
bbSPIClose(CE0);
bbSPIClose(CE1);
gpioTerminate();
return 0;
}
...
D*/
/*F*/ /*F*/
int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags); int spiOpen(unsigned spiChan, unsigned baud, unsigned spiFlags);
/*D /*D
@ -4314,6 +4390,22 @@ Auto will use the mailbox method unless a larger than default buffer
size is requested with [*gpioCfgBufferSize*]. size is requested with [*gpioCfgBufferSize*].
D*/ D*/
/*F*/
int gpioCfgNetAddr(int numSockAddr, uint32_t *sockAddr);
/*D
Sets the network addresses which are allowed to talk over the
socket interface.
This function is only effective if called before [*gpioInitialise*].
. .
numSockAddr: 0-256 (0 means all addresses allowed)
sockAddr: an array of permitted network addresses.
. .
D*/
/*F*/ /*F*/
int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal); int gpioCfgInternals(unsigned cfgWhat, unsigned cfgVal);
/*D /*D
@ -4325,6 +4417,7 @@ cfgWhat: see source code
. . . .
D*/ D*/
/*F*/ /*F*/
uint32_t gpioCfgGetInternals(void); uint32_t gpioCfgGetInternals(void);
/*D /*D
@ -4456,7 +4549,7 @@ D*/
/*F*/ /*F*/
rawCbs_t *rawWaveCBAdr(int cbNum); rawCbs_t *rawWaveCBAdr(int cbNum);
/*D /*D
Return the Linux address of contol block cbNum. Return the (Linux) address of contol block cbNum.
. . . .
cbNum: the cb of interest cbNum: the cb of interest
@ -4465,11 +4558,39 @@ cbNum: the cb of interest
Not intended for general use. Not intended for general use.
D*/ D*/
/*F*/
uint32_t rawWaveGetOOL(int pos);
/*D
Gets the OOL parameter stored at pos.
. .
pos: the position of interest.
. .
Not intended for general use.
D*/
/*F*/
void rawWaveSetOOL(int pos, uint32_t lVal);
/*D
Sets the OOL parameter stored at pos to value.
. .
pos: the position of interest
lVal: the value to write
. .
Not intended for general use.
D*/
/*F*/ /*F*/
uint32_t rawWaveGetOut(int pos); uint32_t rawWaveGetOut(int pos);
/*D /*D
Gets the wave output parameter stored at pos. Gets the wave output parameter stored at pos.
DEPRECATED: use rawWaveGetOOL instead.
. . . .
pos: the position of interest. pos: the position of interest.
. . . .
@ -4483,6 +4604,8 @@ void rawWaveSetOut(int pos, uint32_t lVal);
/*D /*D
Sets the wave output parameter stored at pos to value. Sets the wave output parameter stored at pos to value.
DEPRECATED: use rawWaveSetOOL instead.
. . . .
pos: the position of interest pos: the position of interest
lVal: the value to write lVal: the value to write
@ -4496,6 +4619,8 @@ uint32_t rawWaveGetIn(int pos);
/*D /*D
Gets the wave input value parameter stored at pos. Gets the wave input value parameter stored at pos.
DEPRECATED: use rawWaveGetOOL instead.
. . . .
pos: the position of interest pos: the position of interest
. . . .
@ -4509,6 +4634,8 @@ void rawWaveSetIn(int pos, uint32_t lVal);
/*D /*D
Sets the wave input value stored at pos to value. Sets the wave input value stored at pos to value.
DEPRECATED: use rawWaveSetOOL instead.
. . . .
pos: the position of interest pos: the position of interest
lVal: the value to write lVal: the value to write
@ -4708,6 +4835,9 @@ count::
The number of bytes to be transferred in an I2C, SPI, or Serial The number of bytes to be transferred in an I2C, SPI, or Serial
command. command.
CS::
The GPIO used for the slave select signal when bit banging SPI.
data_bits::1-32 data_bits::1-32
The number of data bits to be used when adding serial data to a The number of data bits to be used when adding serial data to a
@ -4983,6 +5113,9 @@ millis::
A value representing milliseconds. A value representing milliseconds.
MISO::
The GPIO used for the MISO signal when bit banging SPI.
mode:: mode::
1. The operational mode of a GPIO, normally INPUT or OUTPUT. 1. The operational mode of a GPIO, normally INPUT or OUTPUT.
@ -5014,6 +5147,9 @@ PI_FILE_CREATE 8
PI_FILE_TRUNC 16 PI_FILE_TRUNC 16
. . . .
MOSI::
The GPIO used for the MOSI signal when bit banging SPI.
numBits:: numBits::
The number of bits stored in a buffer. The number of bits stored in a buffer.
@ -5032,6 +5168,11 @@ The number of pulses to be added to a waveform.
numSegs:: numSegs::
The number of segments in a combined I2C transaction. The number of segments in a combined I2C transaction.
numSockAddr::
The number of network addresses allowed to use the socket interface.
0 means all addresses allowed.
offset:: offset::
The associated data starts this number of microseconds from the start of The associated data starts this number of microseconds from the start of
the waveform. the waveform.
@ -5202,6 +5343,9 @@ A pointer to a buffer to receive data.
SCL:: SCL::
The user GPIO to use for the clock when bit banging I2C. The user GPIO to use for the clock when bit banging I2C.
SCLK::
The GPIO used for the SCLK signal when bit banging SPI.
*script:: *script::
A pointer to the text of a script. A pointer to the text of a script.
@ -5264,6 +5408,12 @@ size_t::
A standard type used to indicate the size of an object in bytes. A standard type used to indicate the size of an object in bytes.
*sockAddr::
An array of network addresses allowed to use the socket interface encoded
as 32 bit numbers.
E.g. address 192.168.1.66 would be encoded as 0x4201a8c0.
*spi:: *spi::
A pointer to a [*rawSPI_t*] structure. A pointer to a [*rawSPI_t*] structure.
@ -5281,7 +5431,7 @@ spiChan::
A SPI channel, 0-2. A SPI channel, 0-2.
spiFlags:: spiFlags::
See [*spiOpen*]. See [*spiOpen*] and [*bbSPIOpen*].
spiSS:: spiSS::
The SPI slave select GPIO in a raw SPI transaction. The SPI slave select GPIO in a raw SPI transaction.

187
pigpio.py
View File

@ -288,7 +288,7 @@ import threading
import os import os
import atexit import atexit
VERSION = "1.32" VERSION = "1.33"
exceptions = True exceptions = True
@ -363,18 +363,18 @@ FROM_START=0
FROM_CURRENT=1 FROM_CURRENT=1
FROM_END=2 FROM_END=2
SPI_CS_HIGH_ACTIVE = 1 << 2
SPI_CS0_HIGH_ACTIVE = 1 << 2
SPI_CS1_HIGH_ACTIVE = 1 << 3
SPI_CS2_HIGH_ACTIVE = 1 << 4
SPI_RX_LSBFIRST = 1 << 15
SPI_TX_LSBFIRST = 1 << 14
SPI_MODE_0 = 0 SPI_MODE_0 = 0
SPI_MODE_1 = 1 SPI_MODE_1 = 1
SPI_MODE_2 = 2 SPI_MODE_2 = 2
SPI_MODE_3 = 3 SPI_MODE_3 = 3
SPI_CPOL = 2
SPI_CPHA = 1 SPI_CPHA = 1 << 0
SPI_CPOL = 1 << 1
SPI_CS_HIGH_ACTIVE = 1 << 2
SPI_TX_LSBFIRST = 1 << 14
SPI_RX_LSBFIRST = 1 << 15
# pigpio command numbers # pigpio command numbers
@ -809,6 +809,24 @@ _errors=[
[PI_NOT_SPI_GPIO , "no bit bang SPI in progress on GPIO"], [PI_NOT_SPI_GPIO , "no bit bang SPI in progress on GPIO"],
] ]
except_a = "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n{}"
except_z = "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
except1 = """
Did you start the pigpio daemon? E.g. sudo pigpiod
Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888
Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888)"""
except2 = """
Do you have permission to access the pigpio daemon?
Perhaps it was started with sudo pigpiod -nlocalhost"""
class _socklock: class _socklock:
""" """
A class to store socket and lock. A class to store socket and lock.
@ -2975,9 +2993,6 @@ class pi():
This function selects a set of GPIO for bit banging SPI at a This function selects a set of GPIO for bit banging SPI at a
specified baud rate. specified baud rate.
Bit banging SPI allows the use of different GPIO for SPI than
for the hardware SPI ports.
CS := 0-31 CS := 0-31
MISO := 0-31 MISO := 0-31
MOSI := 0-31 MOSI := 0-31
@ -2987,49 +3002,55 @@ class pi():
spiFlags consists of the least significant 22 bits. spiFlags consists of the least significant 22 bits.
... . .
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
b b b b b b R T n n n n W A u2 u1 u0 p2 p1 p0 m m 0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
... . .
mm defines the SPI mode, defaults to 0 mm defines the SPI mode, defaults to 0
... . .
Mode CPOL CPHA Mode CPOL CPHA
0 0 0 0 0 0
1 0 1 1 0 1
2 1 0 2 1 0
3 1 1 3 1 1
... . .
Use the following constants to set the Mode: The following constants may be used to set the mode:
pigpio.SPI_MODE_0,
pigpio.SPI_MODE_1, . .
pigpio.SPI_MODE_2 or pigpio.SPI_MODE_0
pigpio.SPI_MODE_1
pigpio.SPI_MODE_2
pigpio.SPI_MODE_3 pigpio.SPI_MODE_3
or use . .
pigpio.SPI_CPOL and/ or
pigpio.SPI_CPHA
p0 is 0 if CS is active low (default) and 1 for active high. Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA
Use pigpio.SPI_CS_HIGH_ACTIVE to set this flag. may be used.
p is 0 if CS is active low (default) and 1 for active high.
pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag.
T is 1 if the least significant bit is transmitted on MOSI first, T is 1 if the least significant bit is transmitted on MOSI first,
the default (0) shifts the most significant bit out first. the default (0) shifts the most significant bit out first.
Use pigpio.SPI_TX_LSBFIRST to set this flag. pigpio.SPI_TX_LSBFIRST may be used to set this flag.
R is 1 if the least significant bit is received on MISO first, R is 1 if the least significant bit is received on MISO first,
the default (0) receives the most significant bit first. the default (0) receives the most significant bit first.
Use pigpio.SPI_RX_LSBFIRST to set this flag. pigpio.SPI_RX_LSBFIRST may be used to set this flag.
The other bits in spiFlags should be set to zero. The other bits in spiFlags should be set to zero.
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE. PI_GPIO_IN_USE.
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
... ...
pi.bb_spi_open(CS, MISO, MOSI, SCLK, bb_spi_open(10, MISO, MOSI, SCLK, 10000, 0); // device 1
baud=100000, bb_spi_open(11, MISO, MOSI, SCLK, 20000, 3); // device 2
spi_flags=pigpio.SPI_MODE_1 | pigpio.SPI_CS_HIGH_ACTIVE)
... ...
""" """
# I p1 CS # I p1 CS
@ -3050,9 +3071,9 @@ class pi():
def bb_spi_close(self, CS): def bb_spi_close(self, CS):
""" """
This function stops bit banging SPI on a set of GPIO This function stops bit banging SPI on a set of GPIO
previously opened with [*bb_spi_open*]. opened with [*bb_spi_open*].
CS:= 0-31, the CS GPIO used in a prior call to [*bb_ispi_open*] CS:= 0-31, the CS GPIO used in a prior call to [*bb_spi_open*]
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO. Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
@ -3065,22 +3086,61 @@ class pi():
def bb_spi_xfer(self, CS, data): def bb_spi_xfer(self, CS, data):
""" """
This function executes an bit banged SPI transfer. The data This function executes a bit banged SPI transfer.
to be sent is specified by the contents of data, received data
is returned as a bytestring.
CS:= 0-31 (as used in a prior call to [*bbSPIOpen*]) CS:= 0-31 (as used in a prior call to [*bb_spi_open*])
data:= data to be sent data:= data to be sent
Returns >= 0 if OK (the number of bytes read), otherwise The returned value is a tuple of the number of bytes read and a
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER. bytearray containing the bytes. If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
The received SPI data returned as ab bytearray
... ...
pi.bb_spi_xfer(CS, data) #!/usr/bin/env python
import pigpio
CE0=5
CE1=6
MISO=13
MOSI=19
SCLK=12
pi = pigpio.pi()
if not pi.connected:
exit()
pi.bb_spi_open(CE0, MISO, MOSI, SCLK, 10000, 0) # MCP4251 DAC
pi.bb_spi_open(CE1, MISO, MOSI, SCLK, 20000, 3) # MCP3008 ADC
for i in range(256):
count, data = pi.bb_spi_xfer(CE0, [0, i]) # Set DAC value
if count == 2:
count, data = pi.bb_spi_xfer(CE0, [12, 0]) # Read back DAC
if count == 2:
set_val = data[1]
count, data = pi.bb_spi_xfer(CE1, [1, 128, 0]) # Read ADC
if count == 3:
read_val = ((data[1]&3)<<8) | data[2]
print("{} {}".format(set_val, read_val))
pi.bb_spi_close(CE0)
pi.bb_spi_close(CE1)
pi.stop()
... ...
""" """
# I p1 SDA # I p1 CS
# I p2 0 # I p2 0
# I p3 len # I p3 len
## extension ## ## extension ##
@ -4428,9 +4488,22 @@ class pi():
self._notify = _callback_thread(self.sl, host, port) self._notify = _callback_thread(self.sl, host, port)
except socket.error: except socket.error:
exception = 1
except struct.error:
exception = 2
else:
exception = 0
atexit.register(self.stop)
if exception != 0:
self.connected = False self.connected = False
if self.sl.s is not None: if self.sl.s is not None:
self.sl.s = None self.sl.s = None
if host == '': if host == '':
h = "localhost" h = "localhost"
else: else:
@ -4438,20 +4511,12 @@ class pi():
s = "Can't connect to pigpio at {}({})".format(str(h), str(port)) s = "Can't connect to pigpio at {}({})".format(str(h), str(port))
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(except_a.format(s))
print(s) if exception == 1:
print("") print(except1)
print("Did you start the pigpio daemon? E.g. sudo pigpiod")
print("")
print("Did you specify the correct Pi host/port in the environment")
print("variables PIGPIO_ADDR/PIGPIO_PORT?")
print("E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888")
print("")
print("Did you specify the correct Pi host/port in the")
print("pigpio.pi() function? E.g. pigpio.pi('soft', 8888))")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
else: else:
atexit.register(self.stop) print(except2)
print(except_z)
def stop(self): def stop(self):
"""Release pigpio resources. """Release pigpio resources.
@ -4527,6 +4592,9 @@ def xref():
count: count:
The number of bytes of data to be transferred. The number of bytes of data to be transferred.
CS:
The GPIO used for the slave select signal when bit banging SPI.
data: data:
Data to be transmitted, a series of bytes. Data to be transmitted, a series of bytes.
@ -4771,6 +4839,9 @@ def xref():
SET = 1 SET = 1
TIMEOUT = 2 # only returned for a watchdog timeout TIMEOUT = 2 # only returned for a watchdog timeout
MISO:
The GPIO used for the MISO signal when bit banging SPI.
mode: mode:
1.The operational mode of a GPIO, normally INPUT or OUTPUT. 1.The operational mode of a GPIO, normally INPUT or OUTPUT.
@ -4791,6 +4862,9 @@ def xref():
WAVE_MODE_ONE_SHOT_SYNC = 2 WAVE_MODE_ONE_SHOT_SYNC = 2
WAVE_MODE_REPEAT_SYNC = 3 WAVE_MODE_REPEAT_SYNC = 3
MOSI:
The GPIO used for the MOSI signal when bit banging SPI.
offset: >=0 offset: >=0
The offset wave data starts from the beginning of the waveform The offset wave data starts from the beginning of the waveform
being currently defined. being currently defined.
@ -4854,6 +4928,9 @@ def xref():
SCL: SCL:
The user GPIO to use for the clock when bit banging I2C. The user GPIO to use for the clock when bit banging I2C.
SCLK::
The GPIO used for the SCLK signal when bit banging SPI.
script: script:
The text of a script to store on the pigpio daemon. The text of a script to store on the pigpio daemon.

105
pigpiod.1
View File

@ -34,70 +34,75 @@ pigpiod accepts the following configuration options
.SH OPTIONS .SH OPTIONS
.IP "\fB-a value\fP" .IP "\fB-a value\fP"
DMA memory allocation mode DMA memory allocation mode.
0=AUTO, 1=PMAP, 2=MBOX 0=AUTO, 1=PMAP, 2=MBOX.
default AUTO Default AUTO
.
.IP "\fB-b value\fP" .IP "\fB-b value\fP"
GPIO sample buffer in milliseconds GPIO sample buffer size in milliseconds.
100-10000 100-10000.
default 120 Default 120
.
.IP "\fB-c value\fP" .IP "\fB-c value\fP"
library internal settings Library internal settings.
.
default 0 Default 0
.
.IP "\fB-d value\fP" .IP "\fB-d value\fP"
primary DMA channel Primary DMA channel.
0-14 0-14.
default 14 Default 14
.
.IP "\fB-e value\fP" .IP "\fB-e value\fP"
secondary DMA channel Secondary DMA channel.
0-14 0-14.
default 6 Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel
.
.IP "\fB-f\fP" .IP "\fB-f\fP"
disable fifo interface Disable fifo interface.
.
default enabled Default enabled
.
.IP "\fB-k\fP" .IP "\fB-k\fP"
disable local and remote socket interface Disable local and remote socket interface.
.
default enabled Default enabled
.
.IP "\fB-l\fP" .IP "\fB-l\fP"
disable remote socket interface Disable remote socket interface.
.
default enabled Default enabled
.
.IP "\fB-n IP address\fP"
Allow IP address to use the socket interface.
Name (e.g. paul) or dotted quad (e.g. 192.168.1.66).
If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect
.
.IP "\fB-p value\fP" .IP "\fB-p value\fP"
socket port Socket port.
1024-32000 1024-32000.
default 8888 Default 8888
.
.IP "\fB-s value\fP" .IP "\fB-s value\fP"
sample rate Sample rate.
1, 2, 4, 5, 8, 10 1, 2, 4, 5, 8, or 10 microseconds.
default 5 Default 5
.
.IP "\fB-t value\fP" .IP "\fB-t value\fP"
clock peripheral Clock peripheral.
0=PWM 1=PCM 0=PWM 1=PCM.
default PCM Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio.
.
.IP "\fB-v -V\fP" .IP "\fB-v -V\fP"
display pigpio version and exit Display pigpio version and exit.
.
.
.IP "\fB-x mask\fP" .IP "\fB-x mask\fP"
GPIO which may be updated GPIO which may be updated.
A 54 bit mask with (1<<n) set if the user may update GPIO #n. A 54 bit mask with (1<<n) set if the user may update GPIO #n.
default is the set of user GPIO for the board revision Default is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO
.
.br .br
.br .br

View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/ */
/* /*
This version is for pigpio version 48+ This version is for pigpio version 56+
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -42,6 +42,8 @@ This version is for pigpio version 48+
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <ctype.h> #include <ctype.h>
#include <sys/socket.h>
#include <netdb.h>
#include "pigpio.h" #include "pigpio.h"
@ -65,6 +67,10 @@ static int updateMaskSet = 0;
static FILE * errFifo; static FILE * errFifo;
static uint32_t sockNetAddr[MAX_CONNECT_ADDRESSES];
static int numSockNetAddr = 0;
void fatal(char *fmt, ...) void fatal(char *fmt, ...)
{ {
char buf[128]; char buf[128];
@ -87,18 +93,19 @@ void usage()
"pigpio V%d\n" \ "pigpio V%d\n" \
"Usage: sudo pigpiod [OPTION] ...\n" \ "Usage: sudo pigpiod [OPTION] ...\n" \
" -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n" \ " -a value, DMA mode, 0=AUTO, 1=PMAP, 2=MBOX, default AUTO\n" \
" -b value, gpio sample buffer in milliseconds, default 120\n" \ " -b value, sample buffer size in ms, default 120\n" \
" -c value, library internal settings, default 0\n" \ " -c value, library internal settings, default 0\n" \
" -d value, primary DMA channel, 0-14, default 14\n" \ " -d value, primary DMA channel, 0-14, default 14\n" \
" -e value, secondary DMA channel, 0-14, default 6\n" \ " -e value, secondary DMA channel, 0-14, default 6\n" \
" -f, disable fifo interface, default enabled\n" \ " -f, disable fifo interface, default enabled\n" \
" -k, disable socket interface, default enabled\n" \ " -k, disable socket interface, default enabled\n" \
" -l, localhost socket only default all interfaces\n" \ " -l, localhost socket only default local+remote\n" \
" -n IP addr, allow address, name or dotted, default allow all\n" \
" -p value, socket port, 1024-32000, default 8888\n" \ " -p value, socket port, 1024-32000, default 8888\n" \
" -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \ " -s value, sample rate, 1, 2, 4, 5, 8, or 10, default 5\n" \
" -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \ " -t value, clock peripheral, 0=PWM 1=PCM, default PCM\n" \
" -v, -V, display pigpio version and exit\n" \ " -v, -V, display pigpio version and exit\n" \
" -x mask, gpios which may be updated, default board user gpios\n" \ " -x mask, GPIO which may be updated, default board GPIO\n" \
"EXAMPLE\n" \ "EXAMPLE\n" \
"sudo pigpiod -s 2 -b 200 -f\n" \ "sudo pigpiod -s 2 -b 200 -f\n" \
" Set a sample rate of 2 microseconds with a 200 millisecond\n" \ " Set a sample rate of 2 microseconds with a 200 millisecond\n" \
@ -117,12 +124,43 @@ static uint64_t getNum(char *str, int *err)
return val; return val;
} }
static uint32_t checkAddr(char *addrStr)
{
int err;
struct addrinfo hints, *res;
struct sockaddr_in *sin;
const char *portStr;
uint32_t addr;
portStr = getenv(PI_ENVPORT);
if (!portStr) portStr = PI_DEFAULT_SOCKET_PORT_STR;
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags |= AI_CANONNAME;
err = getaddrinfo(addrStr, portStr, &hints, &res);
if (err) return 0;
sin = (struct sockaddr_in *)res->ai_addr;
addr = sin->sin_addr.s_addr;
freeaddrinfo(res);
return addr;
}
static void initOpts(int argc, char *argv[]) static void initOpts(int argc, char *argv[])
{ {
int opt, err, i; int opt, err, i;
uint32_t addr;
int64_t mask; int64_t mask;
while ((opt = getopt(argc, argv, "a:b:c:d:e:fklp:s:t:x:vV")) != -1) while ((opt = getopt(argc, argv, "a:b:c:d:e:fkln:p:s:t:x:vV")) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -173,6 +211,13 @@ static void initOpts(int argc, char *argv[])
ifFlags |= PI_LOCALHOST_SOCK_IF; ifFlags |= PI_LOCALHOST_SOCK_IF;
break; break;
case 'n':
addr = checkAddr(optarg);
if (addr && (numSockNetAddr<MAX_CONNECT_ADDRESSES))
sockNetAddr[numSockNetAddr++] = addr;
else fatal("invalid -n option (%s)", optarg);
break;
case 'p': case 'p':
i = getNum(optarg, &err); i = getNum(optarg, &err);
if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT)) if ((i >= PI_MIN_SOCKET_PORT) && (i <= PI_MAX_SOCKET_PORT))
@ -304,6 +349,8 @@ int main(int argc, char **argv)
if (updateMaskSet) gpioCfgPermissions(updateMask); if (updateMaskSet) gpioCfgPermissions(updateMask);
gpioCfgNetAddr(numSockNetAddr, sockNetAddr);
gpioCfgSetInternals(cfgInternals); gpioCfgSetInternals(cfgInternals);
/* start library */ /* start library */

View File

@ -3757,6 +3757,301 @@ End
.EE .EE
.IP "\fBint bb_spi_open(int pi, unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned baud, unsigned spi_flags)\fP"
.IP "" 4
This function selects a set of GPIO for bit banging SPI at a
specified baud rate.
.br
.br
.EX
pi: >=0 (as returned by \fBpigpio_start\fP).
.br
CS: 0-31
.br
MISO: 0-31
.br
MOSI: 0-31
.br
SCLK: 0-31
.br
baud: 50-250000
.br
spi_flags: see below
.br
.EE
.br
.br
spi_flags consists of the least significant 22 bits.
.br
.br
.EX
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
.br
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
.br
.EE
.br
.br
mm defines the SPI mode, defaults to 0
.br
.br
.EX
Mode CPOL CPHA
.br
0 0 0
.br
1 0 1
.br
2 1 0
.br
3 1 1
.br
.EE
.br
.br
p is 0 if CS is active low (default) and 1 for active high.
.br
.br
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
.br
.br
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
.br
.br
The other bits in flags should be set to zero.
.br
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
.br
.br
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
.br
.br
\fBExample\fP
.br
.EX
bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
.br
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2
.br
.EE
.IP "\fBint bb_spi_close(int pi, unsigned CS)\fP"
.IP "" 4
This function stops bit banging SPI on a set of GPIO
opened with \fBbbSPIOpen\fP.
.br
.br
.EX
pi: >=0 (as returned by \fBpigpio_start\fP).
.br
CS: 0-31, the CS GPIO used in a prior call to \fBbb_spi_open\fP
.br
.EE
.br
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
.IP "\fBint bb_spi_xfer(int pi, unsigned CS, char *txBuf, char *rxBuf, unsigned count)\fP"
.IP "" 4
This function executes a bit banged SPI transfer.
.br
.br
.EX
pi: >=0 (as returned by \fBpigpio_start\fP).
.br
CS: 0-31 (as used in a prior call to \fBbb_spi_open\fP)
.br
txBuf: pointer to buffer to hold data to be sent
.br
rxBuf: pointer to buffer to hold returned data
.br
count: size of data transfer
.br
.EE
.br
.br
Returns >= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
.br
.br
\fBExample\fP
.br
.EX
// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
.br
// ./bb_spi_x_test
.br
.br
#include <stdio.h>
.br
.br
#include "pigpiod_if2.h"
.br
.br
#define CE0 5
.br
#define CE1 6
.br
#define MISO 13
.br
#define MOSI 19
.br
#define SCLK 12
.br
.br
int main(int argc, char *argv[])
.br
{
.br
int i, pi, count, set_val, read_val;
.br
unsigned char inBuf[3];
.br
char cmd1[] = {0, 0};
.br
char cmd2[] = {12, 0};
.br
char cmd3[] = {1, 128, 0};
.br
.br
if ((pi = pigpio_start(0, 0)) < 0)
.br
{
.br
fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
.br
return 1;
.br
}
.br
.br
bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
.br
bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
.br
.br
for (i=0; i<256; i++)
.br
{
.br
cmd1[1] = i;
.br
.br
count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC
.br
.br
if (count == 2)
.br
{
.br
count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC
.br
.br
if (count == 2)
.br
{
.br
set_val = inBuf[1];
.br
.br
count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC
.br
.br
if (count == 3)
.br
{
.br
read_val = ((inBuf[1]&3)<<8) | inBuf[2];
.br
printf("%d %d\n", set_val, read_val);
.br
}
.br
}
.br
}
.br
}
.br
.br
bb_spi_close(pi, CE0);
.br
bb_spi_close(pi, CE1);
.br
.br
pigpio_stop(pi);
.br
}
.br
.EE
.IP "\fBint spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP" .IP "\fBint spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags)\fP"
.IP "" 4 .IP "" 4
This function returns a handle for the SPI device on channel. This function returns a handle for the SPI device on channel.
@ -5272,6 +5567,13 @@ command.
.br .br
.IP "\fBCS\fP" 0
The GPIO used for the slave select signal when bit banging SPI.
.br
.br
.IP "\fBdata_bits\fP: 1-32" 0 .IP "\fBdata_bits\fP: 1-32" 0
The number of data bits in each character of serial data. The number of data bits in each character of serial data.
@ -5588,6 +5890,13 @@ PI_TIMEOUT 2
.br .br
.IP "\fBMISO\fP" 0
The GPIO used for the MISO signal when bit banging SPI.
.br
.br
.IP "\fBmode\fP" 0 .IP "\fBmode\fP" 0
1. The operational mode of a GPIO, normally INPUT or OUTPUT. 1. The operational mode of a GPIO, normally INPUT or OUTPUT.
@ -5678,6 +5987,9 @@ PI_FILE_TRUNC 16
.br .br
.IP "\fBMOSI\fP" 0
The GPIO used for the MOSI signal when bit banging SPI.
.br .br
.br .br
@ -5928,6 +6240,13 @@ The user GPIO to use for the clock when bit banging I2C.
.br .br
.IP "\fBSCLK\fP" 0
The GPIO used for the SCLK signal when bit banging SPI.
.br
.br
.IP "\fB*script\fP" 0 .IP "\fB*script\fP" 0
A pointer to the text of a script. A pointer to the text of a script.
@ -6028,7 +6347,7 @@ A SPI channel, 0-2.
.br .br
.IP "\fBspi_flags\fP" 0 .IP "\fBspi_flags\fP" 0
See \fBspi_open\fP. See \fBspi_open\fP and \fBbb_spi_open\fP.
.br .br

View File

@ -1397,6 +1397,76 @@ int bb_i2c_zip(
return bytes; return bytes;
} }
int bb_spi_open(
int pi,
unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK,
unsigned baud, unsigned spiFlags)
{
uint8_t buf[20];
gpioExtent_t ext[1];
/*
p1=CS
p2=0
p3=20
## extension ##
uint32_t MISO
uint32_t MOSI
uint32_t SCLK
uint32_t baud
uint32_t spiFlags
*/
ext[0].size = 20;
ext[0].ptr = &buf;
memcpy(buf + 0, &MISO, 4);
memcpy(buf + 4, &MOSI, 4);
memcpy(buf + 8, &SCLK, 4);
memcpy(buf + 12, &baud, 4);
memcpy(buf + 16, &spiFlags, 4);
return pigpio_command_ext
(pi, PI_CMD_BSPIO, CS, 0, 20, 1, ext, 1);
}
int bb_spi_close(int pi, unsigned CS)
{return pigpio_command(pi, PI_CMD_BSPIC, CS, 0, 1);}
int bb_spi_xfer(
int pi,
unsigned CS,
char *txBuf,
char *rxBuf,
unsigned count)
{
int bytes;
gpioExtent_t ext[1];
/*
p1=CS
p2=0
p3=count
## extension ##
char txBuf[count]
*/
ext[0].size = count;
ext[0].ptr = txBuf;
bytes = pigpio_command_ext
(pi, PI_CMD_BSPIX, CS, 0, count, 1, ext, 0);
if (bytes > 0)
{
bytes = recvMax(pi, rxBuf, count, bytes);
}
_pmu(pi);
return bytes;
}
int spi_open(int pi, unsigned channel, unsigned speed, uint32_t flags) int spi_open(int pi, unsigned channel, unsigned speed, uint32_t flags)
{ {
gpioExtent_t ext[1]; gpioExtent_t ext[1];

View File

@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
#include "pigpio.h" #include "pigpio.h"
#define PIGPIOD_IF2_VERSION 8 #define PIGPIOD_IF2_VERSION 9
/*TEXT /*TEXT
@ -253,6 +253,10 @@ spi_read Reads bytes from a SPI device
spi_write Writes bytes to a SPI device spi_write Writes bytes to a SPI device
spi_xfer Transfers bytes with a SPI device spi_xfer Transfers bytes with a SPI device
bb_spi_open Opens GPIO for bit banging SPI
bb_spi_close Closes GPIO for bit banging SPI
bb_spi_xfer Transfers bytes with bit banging SPI
SERIAL SERIAL
serial_open Opens a serial device serial_open Opens a serial device
@ -2371,6 +2375,163 @@ End
... ...
D*/ D*/
/*F*/
int bb_spi_open(
int pi,
unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK,
unsigned baud, unsigned spi_flags);
/*D
This function selects a set of GPIO for bit banging SPI at a
specified baud rate.
. .
pi: >=0 (as returned by [*pigpio_start*]).
CS: 0-31
MISO: 0-31
MOSI: 0-31
SCLK: 0-31
baud: 50-250000
spi_flags: see below
. .
spi_flags consists of the least significant 22 bits.
. .
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
. .
mm defines the SPI mode, defaults to 0
. .
Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
. .
p is 0 if CS is active low (default) and 1 for active high.
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
The other bits in flags should be set to zero.
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
...
bb_spi_open(pi,10, MISO, MOSI, SCLK, 10000, 0); // device 1
bb_spi_open(pi,11, MISO, MOSI, SCLK, 20000, 3); // device 2
...
D*/
/*F*/
int bb_spi_close(int pi, unsigned CS);
/*D
This function stops bit banging SPI on a set of GPIO
opened with [*bbSPIOpen*].
. .
pi: >=0 (as returned by [*pigpio_start*]).
CS: 0-31, the CS GPIO used in a prior call to [*bb_spi_open*]
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
D*/
/*F*/
int bb_spi_xfer(
int pi,
unsigned CS,
char *txBuf,
char *rxBuf,
unsigned count);
/*D
This function executes a bit banged SPI transfer.
. .
pi: >=0 (as returned by [*pigpio_start*]).
CS: 0-31 (as used in a prior call to [*bb_spi_open*])
txBuf: pointer to buffer to hold data to be sent
rxBuf: pointer to buffer to hold returned data
count: size of data transfer
. .
Returns >= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
...
// gcc -Wall -pthread -o bb_spi_x_test bb_spi_x_test.c -lpigpiod_if2
// ./bb_spi_x_test
#include <stdio.h>
#include "pigpiod_if2.h"
#define CE0 5
#define CE1 6
#define MISO 13
#define MOSI 19
#define SCLK 12
int main(int argc, char *argv[])
{
int i, pi, count, set_val, read_val;
unsigned char inBuf[3];
char cmd1[] = {0, 0};
char cmd2[] = {12, 0};
char cmd3[] = {1, 128, 0};
if ((pi = pigpio_start(0, 0)) < 0)
{
fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
return 1;
}
bb_spi_open(pi, CE0, MISO, MOSI, SCLK, 10000, 0); // MCP4251 DAC
bb_spi_open(pi, CE1, MISO, MOSI, SCLK, 20000, 3); // MCP3008 ADC
for (i=0; i<256; i++)
{
cmd1[1] = i;
count = bb_spi_xfer(pi, CE0, cmd1, (char *)inBuf, 2); // > DAC
if (count == 2)
{
count = bb_spi_xfer(pi, CE0, cmd2, (char *)inBuf, 2); // < DAC
if (count == 2)
{
set_val = inBuf[1];
count = bb_spi_xfer(pi, CE1, cmd3, (char *)inBuf, 3); // < ADC
if (count == 3)
{
read_val = ((inBuf[1]&3)<<8) | inBuf[2];
printf("%d %d\n", set_val, read_val);
}
}
}
}
bb_spi_close(pi, CE0);
bb_spi_close(pi, CE1);
pigpio_stop(pi);
}
...
D*/
/*F*/ /*F*/
int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags); int spi_open(int pi, unsigned spi_channel, unsigned baud, unsigned spi_flags);
/*D /*D
@ -3195,6 +3356,9 @@ count::
The number of bytes to be transferred in a file, I2C, SPI, or serial The number of bytes to be transferred in a file, I2C, SPI, or serial
command. command.
CS::
The GPIO used for the slave select signal when bit banging SPI.
data_bits::1-32 data_bits::1-32
The number of data bits in each character of serial data. The number of data bits in each character of serial data.
@ -3339,6 +3503,9 @@ reported as PI_TIMEOUT. See [*set_watchdog*].
PI_TIMEOUT 2 PI_TIMEOUT 2
. . . .
MISO::
The GPIO used for the MISO signal when bit banging SPI.
mode:: mode::
1. The operational mode of a GPIO, normally INPUT or OUTPUT. 1. The operational mode of a GPIO, normally INPUT or OUTPUT.
@ -3378,6 +3545,8 @@ PI_FILE_CREATE 8
PI_FILE_TRUNC 16 PI_FILE_TRUNC 16
. . . .
MOSI::
The GPIO used for the MOSI signal when bit banging SPI.
numBytes:: numBytes::
The number of bytes used to store characters in a string. Depending The number of bytes used to store characters in a string. Depending
@ -3489,6 +3658,9 @@ A pointer to a buffer to receive data.
SCL:: SCL::
The user GPIO to use for the clock when bit banging I2C. The user GPIO to use for the clock when bit banging I2C.
SCLK::
The GPIO used for the SCLK signal when bit banging SPI.
*script:: *script::
A pointer to the text of a script. A pointer to the text of a script.
@ -3533,7 +3705,7 @@ spi_channel::
A SPI channel, 0-2. A SPI channel, 0-2.
spi_flags:: spi_flags::
See [*spi_open*]. See [*spi_open*] and [*bb_spi_open*].
steady:: 0-300000 steady:: 0-300000

250
pigs.1
View File

@ -484,6 +484,232 @@ ERROR: no permission to update one or more GPIO
.br .br
.IP "\fBBSPIC cs\fP - Close bit bang SPI"
.IP "" 4
.br
This function stops bit banging SPI on a set of GPIO
opened with \fBBSPIO\fP.
.br
The set of GPIO is specifed by \fBcs\fP.
.br
Upon success nothing is returned. On error a negative status code
will be returned.
.br
\fBExample\fP
.br
.EX
$ pigs bspic 10
.br
.br
$ pigs bspic 10
.br
-142
.br
ERROR: no bit bang SPI in progress on GPIO
.br
.EE
.br
.IP "\fBBSPIO cs miso mosi sclk b spf\fP - Open bit bang SPI"
.IP "" 4
.br
This command starts bit banging SPI on a group of GPIO with slave
select \fBcs\fP, MISO \fBmiso\fP, MOSI \fBmosi\fP, and clock \fBsclk\fP.
.br
Data will be transferred at baud \fBb\fP bits per second (which may
be set in the range 50-250000).
.br
The flags \fBspf\fP may be used to modify the default behaviour of
mode 0, active low chip select.
.br
The flags consists of the least significant 22 bits.
.br
.EX
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
.br
0 0 0 0 0 0 R T 0 0 0 0 0 0 0 0 0 0 0 p m m
.br
.EE
.br
mm defines the SPI mode.
.br
.EX
Mode POL PHA
.br
0 0 0
.br
1 0 1
.br
2 1 0
.br
3 1 1
.br
.EE
.br
p is 0 if CS is active low (default) and 1 for active high.
.br
T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
.br
R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
.br
The other bits in flags should be set to zero.
.br
Upon success 0 is returned. On error a negative status code
will be returned.
.br
If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
.br
\fBExample\fP
.br
.EX
$ pigs bspio 9 11 12 13 50000 0
.br
.br
$ pigs bspio 10 11 12 13 50000 0
.br
.br
$ pigs bspio 29 19 20 21 50000 0 # GPIO 29 not avaialble on this Pi
.br
-41
.br
ERROR: no permission to update GPIO
.br
.EE
.br
.IP "\fBBSPIX cs bvs\fP - SPI bit bang transfer"
.IP "" 4
.br
This command writes bytes \fBbvs\fP to the bit bang SPI device
associated with slave select \fBcs\fP. It returns the same
number of bytes read from the device.
.br
Upon success the count of returned bytes followed by the bytes themselves
is returned. On error a negative status code will be returned.
.br
\fBExample\fP
.br
.EX
$ pigs bspio 5 13 19 12 10000 0 # MCP4251 DAC
.br
$ pigs bspio 6 13 19 12 20000 3 # MCP3008 ADC
.br
.br
$ pigs bspix 5 0 16 # set DAC to 16
.br
2 255 255
.br
.br
$ pigs bspix 5 12 0 # read back DAC
.br
2 254 16
.br
.br
$ pigs bspix 6 1 128 0 # read ADC input 0
.br
3 0 3 184 # 952
.br
.br
$ pigs bspix 5 0 240 # set DAC to 240
.br
2 255 255
.br
.br
$ pigs bspix 5 12 0 # read back DAC
.br
2 254 240
.br
.br
$ pigs bspix 6 1 128 0 # read ADC input 0
.br
3 0 0 63 # 63
.br
.br
$ pigs bspix 5 0 128 # set DAC to 128
.br
2 255 255
.br
.br
$ pigs bspix 5 12 0 # read back DAC
.br
2 254 128
.br
.br
$ pigs bspix 6 1 128 0 # read ADC input 0
.br
3 0 1 255 # 511
.br
.br
$ pigs bspic 5 # close SPI CS 5
.br
$ pigs bspic 6 # close SPI CS 6
.br
.br
$ pigs bspic 5 # try to close SPI CS 5 again
.br
-142
.br
ERROR: no bit bang SPI in progress on GPIO
.br
.EE
.br
.br
.IP "\fBCF1 uvs\fP - Custom function 1" .IP "\fBCF1 uvs\fP - Custom function 1"
.IP "" 4 .IP "" 4
@ -906,7 +1132,7 @@ returned. On error a negative status code will be returned.
.br .br
.EX .EX
$ pigs fs 0 0 0 # Seek to start of file plus 200 $ pigs fs 0 200 0 # Seek to start of file plus 200
.br .br
200 200
.br .br
@ -4481,6 +4707,11 @@ The command expects a frequency.
.br .br
.IP "\fBcs\fP - GPIO (0-31)" 0
The GPIO used for the slave select signal when bit banging SPI.
.br
.IP "\fBdb\fP - serial data bits (1-32)" 0 .IP "\fBdb\fP - serial data bits (1-32)" 0
The command expects the number of data bits per serial character. The command expects the number of data bits per serial character.
@ -4620,6 +4851,11 @@ Value 0 1 4 5 6 7 3 2
.br .br
.IP "\fBmiso\fP - GPIO (0-31)" 0
The GPIO used for the MISO signal when bit banging SPI.
.br
.IP "\fBmode\fP - file open mode" 0 .IP "\fBmode\fP - file open mode" 0
One of the following values. One of the following values.
@ -4648,6 +4884,11 @@ TRUNC 16 The file is truncated
.br .br
.IP "\fBmosi\fP - GPIO (0-31)" 0
The GPIO used for the MOSI signal when bit banging SPI.
.br
.IP "\fBname\fP - the name of a script" 0 .IP "\fBname\fP - the name of a script" 0
Only alphanumeric characters, '-' and '_' are allowed in the name. Only alphanumeric characters, '-' and '_' are allowed in the name.
@ -4764,6 +5005,11 @@ when bit banging I2C.
.br .br
.IP "\fBsclk\fP - user GPIO (0-31)" 0
The GPIO used for the SCLK signal when bit banging SPI.
.br
.IP "\fBsda\fP - user GPIO (0-31)" 0 .IP "\fBsda\fP - user GPIO (0-31)" 0
The command expects the number of the GPIO to be used for SDA The command expects the number of the GPIO to be used for SDA
when bit banging I2C. when bit banging I2C.
@ -4781,7 +5027,7 @@ The command expects a script id as returned by a call to \fBPROC\fP.
.br .br
.IP "\fBspf\fP - SPI flags (32 bits)" 0 .IP "\fBspf\fP - SPI flags (32 bits)" 0
See \fBSPIO\fP. See \fBSPIO\fP and \fBBSPIO\fP.
.br .br

3
pigs.c
View File

@ -26,7 +26,7 @@ For more information, please refer to <http://unlicense.org/>
*/ */
/* /*
This version is for pigpio version 55+ This version is for pigpio version 56+
*/ */
#include <stdio.h> #include <stdio.h>
@ -224,6 +224,7 @@ void get_extensions(int sock, int command, int res)
switch (command) switch (command)
{ {
case PI_CMD_BI2CZ: case PI_CMD_BI2CZ:
case PI_CMD_BSPIX:
case PI_CMD_CF2: case PI_CMD_CF2:
case PI_CMD_FL: case PI_CMD_FL:
case PI_CMD_FR: case PI_CMD_FR:

View File

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

2
x_pigs
View File

@ -50,7 +50,7 @@ s=$(pigs bs2 0)
if [[ $s = "" ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi if [[ $s = "" ]]; then echo "BS2 ok"; else echo "BS2 fail ($s)"; fi
s=$(pigs h) s=$(pigs h)
if [[ ${#s} = 4966 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi if [[ ${#s} = 5273 ]]; then echo "HELP ok"; else echo "HELP fail (${#s})"; fi
s=$(pigs hwver) s=$(pigs hwver)
if [[ $s -ne 0 ]]; then echo "HWVER ok"; else echo "HWVER fail ($s)"; fi if [[ $s -ne 0 ]]; then echo "HWVER ok"; else echo "HWVER fail ($s)"; fi