This commit is contained in:
joan 2016-06-03 16:13:58 +01:00
parent 3b56709a0e
commit 862f445669
3 changed files with 86 additions and 60 deletions

View File

@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/> For more information, please refer to <http://unlicense.org/>
*/ */
/* pigpio version 53 */ /* pigpio version 54 */
/* include ------------------------------------------------------- */ /* include ------------------------------------------------------- */
@ -4238,27 +4238,27 @@ static void spiInit(uint32_t flags)
if (!(resvd&1)) if (!(resvd&1))
{ {
gpioSetMode(PI_ASPI_CE0, PI_OUTPUT); myGpioSetMode(PI_ASPI_CE0, PI_OUTPUT);
myGpioWrite(PI_ASPI_CE0, !(cspols&1)); myGpioWrite(PI_ASPI_CE0, !(cspols&1));
} }
if (!(resvd&2)) if (!(resvd&2))
{ {
gpioSetMode(PI_ASPI_CE1, PI_OUTPUT); myGpioSetMode(PI_ASPI_CE1, PI_OUTPUT);
myGpioWrite(PI_ASPI_CE1, !(cspols&2)); myGpioWrite(PI_ASPI_CE1, !(cspols&2));
} }
if (!(resvd&4)) if (!(resvd&4))
{ {
gpioSetMode(PI_ASPI_CE2, PI_OUTPUT); myGpioSetMode(PI_ASPI_CE2, PI_OUTPUT);
myGpioWrite(PI_ASPI_CE2, !(cspols&4)); myGpioWrite(PI_ASPI_CE2, !(cspols&4));
} }
/* set gpios to SPI mode */ /* set gpios to SPI mode */
gpioSetMode(PI_ASPI_SCLK, PI_ALT4); myGpioSetMode(PI_ASPI_SCLK, PI_ALT4);
gpioSetMode(PI_ASPI_MISO, PI_ALT4); myGpioSetMode(PI_ASPI_MISO, PI_ALT4);
gpioSetMode(PI_ASPI_MOSI, PI_ALT4); myGpioSetMode(PI_ASPI_MOSI, PI_ALT4);
} }
else else
{ {
@ -4275,12 +4275,12 @@ static void spiInit(uint32_t flags)
/* set gpios to SPI mode */ /* set gpios to SPI mode */
if (!(resvd&1)) gpioSetMode(PI_SPI_CE0, PI_ALT0); if (!(resvd&1)) myGpioSetMode(PI_SPI_CE0, PI_ALT0);
if (!(resvd&2)) gpioSetMode(PI_SPI_CE1, PI_ALT0); if (!(resvd&2)) myGpioSetMode(PI_SPI_CE1, PI_ALT0);
gpioSetMode(PI_SPI_SCLK, PI_ALT0); myGpioSetMode(PI_SPI_SCLK, PI_ALT0);
gpioSetMode(PI_SPI_MISO, PI_ALT0); myGpioSetMode(PI_SPI_MISO, PI_ALT0);
gpioSetMode(PI_SPI_MOSI, PI_ALT0); myGpioSetMode(PI_SPI_MOSI, PI_ALT0);
} }
} }
@ -4298,13 +4298,13 @@ static void spiTerm(uint32_t flags)
/* restore original state */ /* restore original state */
if (!(resvd&1)) gpioSetMode(PI_ASPI_CE0, old_mode_ace0); if (!(resvd&1)) myGpioSetMode(PI_ASPI_CE0, old_mode_ace0);
if (!(resvd&2)) gpioSetMode(PI_ASPI_CE1, old_mode_ace1); if (!(resvd&2)) myGpioSetMode(PI_ASPI_CE1, old_mode_ace1);
if (!(resvd&4)) gpioSetMode(PI_ASPI_CE2, old_mode_ace2); if (!(resvd&4)) myGpioSetMode(PI_ASPI_CE2, old_mode_ace2);
gpioSetMode(PI_ASPI_SCLK, old_mode_asclk); myGpioSetMode(PI_ASPI_SCLK, old_mode_asclk);
gpioSetMode(PI_ASPI_MISO, old_mode_amiso); myGpioSetMode(PI_ASPI_MISO, old_mode_amiso);
gpioSetMode(PI_ASPI_MOSI, old_mode_amosi); myGpioSetMode(PI_ASPI_MOSI, old_mode_amosi);
auxReg[AUX_SPI0_CNTL0_REG] = old_spi_cntl0; auxReg[AUX_SPI0_CNTL0_REG] = old_spi_cntl0;
auxReg[AUX_SPI0_CNTL1_REG] = old_spi_cntl1; auxReg[AUX_SPI0_CNTL1_REG] = old_spi_cntl1;
@ -4313,12 +4313,12 @@ static void spiTerm(uint32_t flags)
{ {
/* restore original state */ /* restore original state */
if (!(resvd&1)) gpioSetMode(PI_SPI_CE0, old_mode_ce0); if (!(resvd&1)) myGpioSetMode(PI_SPI_CE0, old_mode_ce0);
if (!(resvd&2)) gpioSetMode(PI_SPI_CE1, old_mode_ce1); if (!(resvd&2)) myGpioSetMode(PI_SPI_CE1, old_mode_ce1);
gpioSetMode(PI_SPI_SCLK, old_mode_sclk); myGpioSetMode(PI_SPI_SCLK, old_mode_sclk);
gpioSetMode(PI_SPI_MISO, old_mode_miso); myGpioSetMode(PI_SPI_MISO, old_mode_miso);
gpioSetMode(PI_SPI_MOSI, old_mode_mosi); myGpioSetMode(PI_SPI_MOSI, old_mode_mosi);
spiReg[SPI_CS] = old_spi_cs; spiReg[SPI_CS] = old_spi_cs;
spiReg[SPI_CLK] = old_spi_clk; spiReg[SPI_CLK] = old_spi_clk;
@ -8049,10 +8049,10 @@ int gpioSetMode(unsigned gpio, unsigned mode)
switchFunctionOff(gpio); switchFunctionOff(gpio);
gpioInfo[gpio].is = GPIO_UNDEFINED; gpioInfo[gpio].is = GPIO_UNDEFINED;
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
} }
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
return 0; return 0;
} }
@ -8147,12 +8147,12 @@ int gpioWrite(unsigned gpio, unsigned level)
switchFunctionOff(gpio); switchFunctionOff(gpio);
gpioSetMode(gpio, PI_OUTPUT);
gpioInfo[gpio].is = GPIO_WRITE; gpioInfo[gpio].is = GPIO_WRITE;
} }
} }
myGpioSetMode(gpio, PI_OUTPUT);
if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT; if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT;
else *(gpioReg + GPSET0 + BANK) = BIT; else *(gpioReg + GPSET0 + BANK) = BIT;
@ -8178,11 +8178,11 @@ int gpioPWM(unsigned gpio, unsigned val)
{ {
switchFunctionOff(gpio); switchFunctionOff(gpio);
gpioSetMode(gpio, PI_OUTPUT);
gpioInfo[gpio].is = GPIO_PWM; gpioInfo[gpio].is = GPIO_PWM;
} }
myGpioSetMode(gpio, PI_OUTPUT);
myGpioSetPwm(gpio, gpioInfo[gpio].width, val); myGpioSetPwm(gpio, gpioInfo[gpio].width, val);
gpioInfo[gpio].width=val; gpioInfo[gpio].width=val;
@ -8415,11 +8415,11 @@ int gpioServo(unsigned gpio, unsigned val)
{ {
switchFunctionOff(gpio); switchFunctionOff(gpio);
gpioSetMode(gpio, PI_OUTPUT);
gpioInfo[gpio].is = GPIO_SERVO; gpioInfo[gpio].is = GPIO_SERVO;
} }
myGpioSetMode(gpio, PI_OUTPUT);
myGpioSetServo(gpio, gpioInfo[gpio].width, val); myGpioSetServo(gpio, gpioInfo[gpio].width, val);
gpioInfo[gpio].width=val; gpioInfo[gpio].width=val;
@ -9795,8 +9795,8 @@ int bbI2CClose(unsigned SDA)
{ {
case PI_WFRX_I2C: case PI_WFRX_I2C:
gpioSetMode(wfRx[SDA].I.SDA, wfRx[SDA].I.SDAMode); myGpioSetMode(wfRx[SDA].I.SDA, wfRx[SDA].I.SDAMode);
gpioSetMode(wfRx[SDA].I.SCL, wfRx[SDA].I.SCLMode); myGpioSetMode(wfRx[SDA].I.SCL, wfRx[SDA].I.SCLMode);
wfRx[wfRx[SDA].I.SDA].mode = PI_WFRX_NONE; wfRx[wfRx[SDA].I.SDA].mode = PI_WFRX_NONE;
wfRx[wfRx[SDA].I.SCL].mode = PI_WFRX_NONE; wfRx[wfRx[SDA].I.SCL].mode = PI_WFRX_NONE;
@ -11324,7 +11324,7 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency)
initHWClk(cctl[clock], cdiv[clock], initHWClk(cctl[clock], cdiv[clock],
csrc[clkInf.clock], clkInf.div, clkInf.frac, mash); csrc[clkInf.clock], clkInf.div, clkInf.frac, mash);
gpioSetMode(gpio, mode); myGpioSetMode(gpio, mode);
gpioInfo[gpio].is = GPIO_HW_CLK; gpioInfo[gpio].is = GPIO_HW_CLK;
@ -11448,7 +11448,7 @@ int gpioHardwarePWM(
{ {
switchFunctionOff(gpio); switchFunctionOff(gpio);
gpioSetMode(gpio, mode); myGpioSetMode(gpio, mode);
gpioInfo[gpio].is = GPIO_HW_PWM; gpioInfo[gpio].is = GPIO_HW_PWM;
} }

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 53 #define PIGPIO_VERSION 54
/*TEXT /*TEXT

72
pigs.1
View File

@ -1808,16 +1808,17 @@ Upon success the new frequency is returned. On error a negative status code
will be returned. will be returned.
.br .br
The selectable frequencies depend upon the sample rate with which the If PWM is currently active on the GPIO it will be
pigpiod daemon was started. The sample rate is one of 1, 2, 4, 5, 8, switched off and then back on at the new frequency.
or 10 microseconds (default 5).
.br .br
Each GPIO can be independently set to one of 18 different PWM frequencies. Each GPIO can be independently set to one of 18 different PWM
frequencies.
.br .br
If PWM is currently active on the GPIO it will be switched off and then The selectable frequencies depend upon the sample rate which
back on at the new frequency. may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
sample rate is set when the pigpio daemon is started.
.br .br
The frequencies for each sample rate are: The frequencies for each sample rate are:
@ -1825,21 +1826,46 @@ The frequencies for each sample rate are:
.br .br
.EX .EX
#1 #2 #3 #4 #5 #6 #7 #8 #9 Hertz
1us 40000 20000 10000 8000 5000 4000 2500 2000 1600 .br
2us 20000 10000 5000 4000 2500 2000 1250 1000 800
4us 10000 5000 2500 2000 1250 1000 625 500 400
5us 8000 4000 2000 1600 1000 800 500 400 320
8us 5000 2500 1250 1000 625 500 313 250 200
10us 4000 2000 1000 800 500 400 250 200 160
#10 #11 #12 #13 #14 #15 #16 #17 #18 .br
1us 1250 1000 800 500 400 250 200 100 50 1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
2us 625 500 400 250 200 125 100 50 25 .br
4us 313 250 200 125 100 63 50 25 13 1250 1000 800 500 400 250 200 100 50
5us 250 200 160 100 80 50 40 20 10 .br
8us 156 125 100 63 50 31 25 13 6
10us 125 100 80 50 40 25 20 10 5 .br
2: 20000 10000 5000 4000 2500 2000 1250 1000 800
.br
625 500 400 250 200 125 100 50 25
.br
.br
4: 10000 5000 2500 2000 1250 1000 625 500 400
.br
313 250 200 125 100 63 50 25 13
.br
sample
.br
rate
.br
(us) 5: 8000 4000 2000 1600 1000 800 500 400 320
.br
250 200 160 100 80 50 40 20 10
.br
.br
8: 5000 2500 1250 1000 625 500 313 250 200
.br
156 125 100 63 50 31 25 13 6
.br
.br
10: 4000 2000 1000 800 500 400 250 200 160
.br
125 100 80 50 40 25 20 10 5
.br
.EE .EE
@ -3393,7 +3419,7 @@ pigs wvcha \
.br .br
.br .br
while \fB $(pigs wvbsy) -eq 1 \fP; do sleep 0.1; done while [[ $(pigs wvbsy) -eq 1 ]]; do sleep 0.1; done
.br .br
.br .br
@ -4314,7 +4340,7 @@ Again, ignore the details for now.
.br .br
.EX .EX
time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
.br .br
do sleep 0.2; done) do sleep 0.2; done)
.br .br
@ -4354,7 +4380,7 @@ jp 999 jumps to tag 999 if the result is positive.
.br .br
.EX .EX
time (pigs procr 0 10000000; while a=$(pigs procp 0); \fB ${a::1} -eq 2 \fP;\ time (pigs procr 0 10000000; while a=$(pigs procp 0); [[ ${a::1} -eq 2 ]];\
.br .br
do sleep 0.2; done) do sleep 0.2; done)
.br .br