diff --git a/command.c b/command.c
index d35e337..e5a94a5 100644
--- a/command.c
+++ b/command.c
@@ -26,7 +26,7 @@ For more information, please refer to
*/
/*
-This version is for pigpio version 24+
+This version is for pigpio version 25+
*/
#include
@@ -136,7 +136,7 @@ cmdInfo_t cmdInfo[]=
{PI_CMD_SLR, "SLR", 121, 6}, // gpioSerialRead
{PI_CMD_SLRC, "SLRC", 112, 0}, // gpioSerialReadClose
- {PI_CMD_SLRO, "SLRO", 121, 0}, // gpioSerialReadOpen
+ {PI_CMD_SLRO, "SLRO", 131, 0}, // gpioSerialReadOpen
{PI_CMD_SPIC, "SPIC", 112, 0}, // spiClose
{PI_CMD_SPIO, "SPIO", 131, 2}, // spiOpen
@@ -303,7 +303,7 @@ SERWB h bv Write byte to serial handle.\n\
\n\
SLR u num Read bit bang serial data from gpio.\n\
SLRC u Close gpio for bit bang serial data.\n\
-SLRO u b Open gpio for bit bang serial data.\n\
+SLRO u b db Open gpio for bit bang serial data.\n\
\n\
SPIC h SPI close handle.\n\
SPIO sc sb sf SPI open channel at baud with flags.\n\
@@ -682,7 +682,7 @@ int cmdParse(
break;
case 121: /* HC I2CRD I2CRR I2CRW I2CWB I2CWQ P PFS PRS
- PWM S SERVO SLR SLRO W WDOG WRITE
+ PWM S SERVO SLR W WDOG WRITE
Two positive parameters.
*/
@@ -778,7 +778,7 @@ int cmdParse(
break;
- case 131: /* HP I2CO I2CPC I2CRI I2CWB I2CWW SPIO TRIG
+ case 131: /* HP I2CO I2CPC I2CRI I2CWB I2CWW SLRO SPIO TRIG
Three positive parameters.
*/
diff --git a/pigpio.3 b/pigpio.3
index 6abef88..25af5c9 100644
--- a/pigpio.3
+++ b/pigpio.3
@@ -530,7 +530,16 @@ PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
.br
.br
-Range defaults to 255.
+For normal PWM the dutycycle will be out of the defined range
+for the gpio (see \fBgpioGetPWMrange\fP). If a hardware clock is
+active on the gpio the reported dutycycle will be 500 (out of 1000).
+If hardware PWM is active on the gpio the reported dutycycle
+will be out of a 1000.
+
+.br
+
+.br
+Normal PWM range defaults to 255.
.IP "\fBint gpioSetPWMrange(unsigned user_gpio, unsigned range)\fP"
.IP "" 4
@@ -617,6 +626,12 @@ user_gpio: 0-31
.br
+.br
+If a hardware clock or hardware PWM is active on the gpio
+the reported range will be 1000.
+
+.br
+
.br
\fBExample\fP
.br
@@ -644,6 +659,12 @@ user_gpio: 0-31
.br
+.br
+If a hardware clock or hardware PWM is active on the gpio
+the reported real range will be 1000.
+
+.br
+
.br
\fBExample\fP
.br
@@ -784,6 +805,15 @@ user_gpio: 0-31
.br
+.br
+For normal PWM the frequency will be that defined for the gpio by
+\fBgpioSetPWMfrequency\fP. If a hardware clock is active on the gpio
+the reported frequency will be that set by \fBgpioHardwareClock\fP.
+If hardware PWM is active on the gpio the reported frequency
+will be that set by \fBgpioHardwarePWM\fP.
+
+.br
+
.br
\fBExample\fP
.br
@@ -1884,7 +1914,7 @@ waveform created since \fBgpioInitialise\fP was called.
This function returns the maximum possible size of a waveform in DMA
control blocks.
-.IP "\fBint gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud)\fP"
+.IP "\fBint gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud, unsigned bbBits)\fP"
.IP "" 4
This function opens a gpio for bit bang reading of serial data.
@@ -1897,6 +1927,8 @@ user_gpio: 0-31
.br
bbBaud: 100-250000
.br
+ bbBits: 1-32
+.br
.EE
@@ -1904,7 +1936,7 @@ user_gpio: 0-31
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
-or PI_GPIO_IN_USE.
+PI_BAD_DATABITS, or PI_GPIO_IN_USE.
.br
@@ -1943,6 +1975,19 @@ user_gpio: 0-31, previously opened with \fBgpioSerialReadOpen\fP
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
+.br
+
+.br
+The bytes returned for each character depend upon the number of
+data bits \fBbbBits\fP specified in the \fBgpioSerialReadOpen\fP command.
+
+.br
+
+.br
+For \fBbbBits\fP 1-8 there will be one byte per character.
+For \fBbbBits\fP 9-16 there will be two bytes per character.
+For \fBbbBits\fP 17-32 there will be four bytes per character.
+
.IP "\fBint gpioSerialReadClose(unsigned user_gpio)\fP"
.IP "" 4
This function closes a gpio for bit bang reading of serial data.
diff --git a/pigpio.c b/pigpio.c
index 6ed7db5..d15fe2f 100644
--- a/pigpio.c
+++ b/pigpio.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to
*/
-/* pigpio version 24 */
+/* pigpio version 25 */
#include
#include
@@ -924,20 +924,22 @@ typedef struct
typedef struct
{
int gpio;
- char * buf;
+ char *buf;
uint32_t bufSize;
int readPos;
int writePos;
- uint32_t baud;
- uint32_t fullBit;
- uint32_t halfBit;
- int timeout;
- uint32_t startBitTick;
- uint32_t nextBitDiff;
+ uint32_t baud; /* 50-250000 */
+ uint32_t fullBit; /* nanoseconds */
+ uint32_t halfBit; /* nanoseconds */
+ int timeout; /* millisconds */
+ uint32_t startBitTick; /* microseconds */
+ uint32_t nextBitDiff; /* nanoseconds */
int bit;
- int byte;
+ uint32_t data;
+ int bytes; /* 1, 2, 4 */
int level;
int mode;
+ int dataBits; /* 1-32 */
} wfRx_t;
union my_smbus_data
@@ -1007,7 +1009,7 @@ static wfStats_t wfStats=
static rawWaveInfo_t waveInfo[PI_MAX_WAVES];
-static volatile wfRx_t wfRx[PI_MAX_USER_GPIO+1];
+static wfRx_t wfRx[PI_MAX_USER_GPIO+1];
static int waveOutBotCB = 0;
static int waveOutTopCB = NUM_WAVE_CBS;
@@ -1116,6 +1118,8 @@ CC: 00 CLK0, 01 CLK1, 10 CLK2
gpio44 GPCLK1 ALT0 Compute module only (reserved for system use)
*/
+uint32_t hw_clk_freq[3];
+
uint8_t clkDef[PI_MAX_GPIO + 1] =
{
/* 0 1 2 3 4 5 6 7 8 9 */
@@ -1146,6 +1150,9 @@ uint8_t clkDef[PI_MAX_GPIO + 1] =
gpio53 pwm1 ALT1
*/
+uint32_t hw_pwm_freq[2];
+uint32_t hw_pwm_duty[2];
+
uint8_t PWMDef[PI_MAX_GPIO + 1] =
{
/* 0 1 2 3 4 5 6 7 8 9 */
@@ -1666,7 +1673,9 @@ static int myDoCommand(uint32_t *p, unsigned bufSize, char *buf)
case PI_CMD_SLRC: res = gpioSerialReadClose(p[1]); break;
- case PI_CMD_SLRO: res = gpioSerialReadOpen(p[1], p[2]); break;
+ case PI_CMD_SLRO:
+ memcpy(&p[4], buf, 4);
+ res = gpioSerialReadOpen(p[1], p[2], p[4]); break;
@@ -2262,44 +2271,48 @@ static int wave2Cbs(unsigned wave_mode)
/* ----------------------------------------------------------------------- */
-static void waveRxSerial(volatile wfRx_t *s, int level, uint32_t tick)
+static void waveRxSerial(wfRx_t *s, int level, uint32_t tick)
{
- int diffTicks;
+ int diffTicks, lastLevel;
int newWritePos;
if (s->bit >= 0)
{
diffTicks = tick - s->startBitTick;
- if (level != PI_TIMEOUT) s->level = level;
+ if (level != PI_TIMEOUT)
+ {
+ s->level = level;
+ lastLevel = !level;
+ }
+ else lastLevel = s->level;
- while ((s->bit < 9) && (diffTicks > s->nextBitDiff))
+ while ((s->bit <= s->dataBits) && (diffTicks > (s->nextBitDiff/1000)))
{
if (s->bit)
{
- if (!(s->level)) s->byte |= (1<<(s->bit-1));
+ if (lastLevel) s->data |= (1<<(s->bit-1));
}
- else s->byte = 0;
+ else s->data = 0;
++(s->bit);
s->nextBitDiff += s->fullBit;
}
- if (s->bit == 9)
+ if (s->bit > s->dataBits)
{
- s->buf[s->writePos] = s->byte;
+ memcpy(s->buf + s->writePos, &s->data, s->bytes);
/* don't let writePos catch readPos */
- newWritePos = s->writePos;
-
- if (++newWritePos >= s->bufSize) newWritePos = 0;
+ newWritePos = (s->writePos + s->bytes) % (s->bufSize);
if (newWritePos != s->readPos) s->writePos = newWritePos;
- if (level == 0) /* true transition high->low, not a timeout */
+ if (level == 0)
{
+ gpioSetWatchdog(s->gpio, s->timeout);
s->bit = 0;
s->startBitTick = tick;
s->nextBitDiff = s->halfBit;
@@ -5741,6 +5754,7 @@ static void initClock(int mainClock)
clkSrc = CLK_CTL_SRC_PLLD;
clkDivI = 50 * micros; /* 10 MHz - 1 MHz */
+ //if (!mainClock) clkDivI = 40 * micros;
clkBits = BITS; /* 10/BITS MHz - 1/BITS MHz */
clkDivF = 0;
clkMash = 0;
@@ -6387,35 +6401,34 @@ static void switchFunctionOff(unsigned gpio)
unsigned clock, pwm;
int cctl[] = {CLK_GP0_CTL, CLK_GP1_CTL, CLK_GP2_CTL};
- if (gpio <= PI_MAX_GPIO)
+ switch (gpioInfo[gpio].is)
{
- switch (gpioInfo[gpio].is)
- {
- case GPIO_SERVO:
- /* switch servo off */
- myGpioSetServo(gpio, gpioInfo[gpio].width, 0);
- gpioInfo[gpio].width = 0;
- break;
+ case GPIO_SERVO:
+ /* switch servo off */
+ myGpioSetServo(gpio, gpioInfo[gpio].width, 0);
+ gpioInfo[gpio].width = 0;
+ break;
- case GPIO_PWM:
- /* switch pwm off */
- myGpioSetPwm(gpio, gpioInfo[gpio].width, 0);
- gpioInfo[gpio].width = 0;
- break;
+ case GPIO_PWM:
+ /* switch pwm off */
+ myGpioSetPwm(gpio, gpioInfo[gpio].width, 0);
+ gpioInfo[gpio].width = 0;
+ break;
- case GPIO_HW_CLK:
- /* switch hardware clock off */
- clock = (clkDef[gpio] >> 4) & 3;
- clkReg[cctl[clock]] = CLK_PASSWD | CLK_CTL_KILL;
- break;
+ case GPIO_HW_CLK:
+ /* switch hardware clock off */
+ clock = (clkDef[gpio] >> 4) & 3;
+ clkReg[cctl[clock]] = CLK_PASSWD | CLK_CTL_KILL;
+ gpioInfo[gpio].width = 0;
+ break;
- case GPIO_HW_PWM:
- /* switch hardware PWM off */
- pwm = (PWMDef[gpio] >> 4) & 3;
- if (pwm == 0) pwmReg[PWM_CTL] &= (~PWM_CTL_PWEN1);
- else pwmReg[PWM_CTL] &= (~PWM_CTL_PWEN2);
- break;
- }
+ case GPIO_HW_PWM:
+ /* switch hardware PWM off */
+ pwm = (PWMDef[gpio] >> 4) & 3;
+ if (pwm == 0) pwmReg[PWM_CTL] &= (~PWM_CTL_PWEN1);
+ else pwmReg[PWM_CTL] &= (~PWM_CTL_PWEN2);
+ gpioInfo[gpio].width = 0;
+ break;
}
}
@@ -6428,6 +6441,7 @@ static void stopHardwarePWM(void)
if (gpioInfo[i].is == GPIO_HW_PWM)
{
switchFunctionOff(i);
+
gpioInfo[i].is = GPIO_UNDEFINED;
}
}
@@ -6456,11 +6470,10 @@ int gpioSetMode(unsigned gpio, unsigned mode)
if (mode != old_mode)
{
- if (gpio <= PI_MAX_USER_GPIO)
- {
- switchFunctionOff(gpio);
- gpioInfo[gpio].is = GPIO_UNDEFINED;
- }
+ switchFunctionOff(gpio);
+
+ gpioInfo[gpio].is = GPIO_UNDEFINED;
+
gpioReg[reg] = (gpioReg[reg] & ~(7< PI_MAX_USER_GPIO)
SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
- if (gpioInfo[gpio].is != GPIO_PWM)
- SOFT_ERROR(PI_NOT_PWM_GPIO, "not a PWM gpio (%d)", gpio);
+ switch (gpioInfo[gpio].is)
+ {
+ case GPIO_PWM:
+ return gpioInfo[gpio].width;
- return gpioInfo[gpio].width;
+ case GPIO_HW_PWM:
+ pwm = (PWMDef[gpio] >> 4) & 3;
+ return hw_pwm_duty[pwm];
+
+ case GPIO_HW_CLK:
+ return PI_HW_PWM_RANGE/2;
+
+ default:
+ SOFT_ERROR(PI_NOT_PWM_GPIO, "not a PWM gpio (%d)", gpio);
+ }
}
@@ -6676,7 +6695,15 @@ int gpioGetPWMrange(unsigned gpio)
if (gpio > PI_MAX_USER_GPIO)
SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
- return gpioInfo[gpio].range;
+ switch (gpioInfo[gpio].is)
+ {
+ case GPIO_HW_PWM:
+ case GPIO_HW_CLK:
+ return PI_HW_PWM_RANGE;
+
+ default:
+ return gpioInfo[gpio].range;
+ }
}
@@ -6691,7 +6718,15 @@ int gpioGetPWMrealRange(unsigned gpio)
if (gpio > PI_MAX_USER_GPIO)
SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
- return pwmRealRange[gpioInfo[gpio].freqIdx];
+ switch (gpioInfo[gpio].is)
+ {
+ case GPIO_HW_PWM:
+ case GPIO_HW_CLK:
+ return PI_HW_PWM_RANGE;
+
+ default:
+ return pwmRealRange[gpioInfo[gpio].freqIdx];
+ }
}
@@ -6751,6 +6786,8 @@ int gpioSetPWMfrequency(unsigned gpio, unsigned frequency)
int gpioGetPWMfrequency(unsigned gpio)
{
+ unsigned pwm, clock;
+
DBG(DBG_USER, "gpio=%d", gpio);
CHECK_INITED;
@@ -6758,7 +6795,19 @@ int gpioGetPWMfrequency(unsigned gpio)
if (gpio > PI_MAX_USER_GPIO)
SOFT_ERROR(PI_BAD_USER_GPIO, "bad gpio (%d)", gpio);
- return pwmFreq[gpioInfo[gpio].freqIdx];
+ switch (gpioInfo[gpio].is)
+ {
+ case GPIO_HW_PWM:
+ pwm = (PWMDef[gpio] >> 4) & 3;
+ return hw_pwm_freq[pwm];
+
+ case GPIO_HW_CLK:
+ clock = (clkDef[gpio] >> 4) & 3;
+ return hw_clk_freq[clock];
+
+ default:
+ return pwmFreq[gpioInfo[gpio].freqIdx];
+ }
}
@@ -6783,14 +6832,10 @@ int gpioServo(unsigned gpio, unsigned val)
if (gpioInfo[gpio].is != GPIO_SERVO)
{
- if (gpioInfo[gpio].is == GPIO_UNDEFINED)
- {
- }
- else
- {
- switchFunctionOff(gpio);
- }
+ switchFunctionOff(gpio);
+
gpioSetMode(gpio, PI_OUTPUT);
+
gpioInfo[gpio].is = GPIO_SERVO;
}
@@ -7435,11 +7480,11 @@ int gpioWaveGetMaxCbs(void)
/*-------------------------------------------------------------------------*/
-int gpioSerialReadOpen(unsigned gpio, unsigned bbBaud)
+int gpioSerialReadOpen(unsigned gpio, unsigned bbBaud, unsigned bbBits)
{
int bitTime, timeout;
- DBG(DBG_USER, "gpio=%d bbBaud=%d", gpio, bbBaud);
+ DBG(DBG_USER, "gpio=%d bbBaud=%d bbBits=%d", gpio, bbBaud, bbBits);
CHECK_INITED;
@@ -7450,12 +7495,17 @@ int gpioSerialReadOpen(unsigned gpio, unsigned bbBaud)
SOFT_ERROR(PI_BAD_WAVE_BAUD,
"gpio %d, bad baud rate (%d)", gpio, bbBaud);
+ if ((bbBits < PI_MIN_WAVE_DATABITS) || (bbBits > PI_MAX_WAVE_DATABITS))
+ SOFT_ERROR(PI_BAD_DATABITS,
+ "gpio %d, bad data bits (%d)", gpio, bbBits);
+
if (wfRx[gpio].mode != PI_WFRX_NONE)
SOFT_ERROR(PI_GPIO_IN_USE, "gpio %d is already being used", gpio);
- bitTime = MILLION / bbBaud;
+ bitTime = (1000 * MILLION) / bbBaud; /* nanoseconds */
+
+ timeout = ((bbBits+2) * bitTime)/MILLION; /* milliseconds */
- timeout = (10 * bitTime)/1000;
if (timeout < 1) timeout = 1;
wfRx[gpio].gpio = gpio;
@@ -7464,11 +7514,16 @@ int gpioSerialReadOpen(unsigned gpio, unsigned bbBaud)
wfRx[gpio].mode = PI_WFRX_SERIAL;
wfRx[gpio].baud = bbBaud;
wfRx[gpio].timeout = timeout;
- wfRx[gpio].fullBit = bitTime;
- wfRx[gpio].halfBit = bitTime/2;
+ wfRx[gpio].fullBit = bitTime; /* nanoseconds */
+ wfRx[gpio].halfBit = (bitTime/2)+500; /* nanoseconds (500 for rounding) */
wfRx[gpio].readPos = 0;
wfRx[gpio].writePos = 0;
wfRx[gpio].bit = -1;
+ wfRx[gpio].dataBits = bbBits;
+
+ if (bbBits < 9) wfRx[gpio].bytes = 1;
+ else if (bbBits < 17) wfRx[gpio].bytes = 2;
+ else wfRx[gpio].bytes = 4;
gpioSetAlertFunc(gpio, waveRxBit);
@@ -7506,6 +7561,10 @@ int gpioSerialRead(unsigned gpio, void *buf, size_t bufSize)
if (bytes > bufSize) bytes = bufSize;
+ /* copy in multiples of the data size in bytes */
+
+ bytes = (bytes / p->bytes) * p->bytes;
+
if (buf) memcpy(buf, p->buf+p->readPos, bytes);
p->readPos += bytes;
@@ -8426,6 +8485,10 @@ int gpioHardwareClock(unsigned gpio, unsigned frequency)
{
if (chooseBestClock(&clkInf, frequency, CLK_SRCS, cfreq))
{
+ /* record the clock frequency */
+
+ hw_clk_freq[clock] = frequency;
+
initHWClk(cctl[clock], cdiv[clock],
csrc[clkInf.clock], clkInf.div, clkInf.frac, mash);
@@ -8496,6 +8559,11 @@ int gpioHardwarePWM(
{
if (chooseBestClock(&clkInf, frequency, CLK_SRCS, cfreq))
{
+ /* record the PWM frequency and dutycycle */
+
+ hw_pwm_freq[pwm] = frequency / PI_HW_PWM_RANGE;
+ hw_pwm_duty[pwm] = dutycycle;
+
/* Abort any waveform transmission in progress */
if (gpioWaveTxBusy()) gpioWaveTxStop();
@@ -8535,14 +8603,10 @@ int gpioHardwarePWM(
if (gpioInfo[gpio].is != GPIO_HW_PWM)
{
- if (gpioInfo[gpio].is == GPIO_UNDEFINED)
- {
- }
- else
- {
- switchFunctionOff(gpio);
- }
+ switchFunctionOff(gpio);
+
gpioSetMode(gpio, mode);
+
gpioInfo[gpio].is = GPIO_HW_PWM;
}
}
diff --git a/pigpio.h b/pigpio.h
index 6bc2e26..3f8edb8 100644
--- a/pigpio.h
+++ b/pigpio.h
@@ -31,7 +31,7 @@ For more information, please refer to
#include
#include
-#define PIGPIO_VERSION 24
+#define PIGPIO_VERSION 25
/*TEXT
@@ -812,7 +812,13 @@ user_gpio: 0-31
Returns between 0 (off) and range (fully on) if OK, otherwise
PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
-Range defaults to 255.
+For normal PWM the dutycycle will be out of the defined range
+for the gpio (see [*gpioGetPWMrange*]). If a hardware clock is
+active on the gpio the reported dutycycle will be 500 (out of 1000).
+If hardware PWM is active on the gpio the reported dutycycle
+will be out of a 1000.
+
+Normal PWM range defaults to 255.
D*/
@@ -861,6 +867,9 @@ PI_BAD_USER_GPIO.
user_gpio: 0-31
. .
+If a hardware clock or hardware PWM is active on the gpio
+the reported range will be 1000.
+
...
r = gpioGetPWMrange(23);
...
@@ -877,6 +886,9 @@ PI_BAD_USER_GPIO.
user_gpio: 0-31
. .
+If a hardware clock or hardware PWM is active on the gpio
+the reported real range will be 1000.
+
...
rr = gpioGetPWMrealRange(17);
...
@@ -950,6 +962,12 @@ PI_BAD_USER_GPIO.
user_gpio: 0-31
. .
+For normal PWM the frequency will be that defined for the gpio by
+[*gpioSetPWMfrequency*]. If a hardware clock is active on the gpio
+the reported frequency will be that set by [*gpioHardwareClock*].
+If hardware PWM is active on the gpio the reported frequency
+will be that set by [*gpioHardwarePWM*].
+
...
f = gpioGetPWMfrequency(23); // Get frequency used for gpio23.
...
@@ -1603,17 +1621,18 @@ D*/
/*F*/
-int gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud);
+int gpioSerialReadOpen(unsigned user_gpio, unsigned bbBaud, unsigned bbBits);
/*D
This function opens a gpio for bit bang reading of serial data.
. .
user_gpio: 0-31
bbBaud: 100-250000
+ bbBits: 1-32
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
-or PI_GPIO_IN_USE.
+PI_BAD_DATABITS, or PI_GPIO_IN_USE.
The serial data is returned in a cyclic buffer and is read using
[*gpioSerialRead*].
@@ -1637,6 +1656,13 @@ user_gpio: 0-31, previously opened with [*gpioSerialReadOpen*]
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
+
+The bytes returned for each character depend upon the number of
+data bits [*bbBits*] specified in the [*gpioSerialReadOpen*] command.
+
+For [*bbBits*] 1-8 there will be one byte per character.
+For [*bbBits*] 9-16 there will be two bytes per character.
+For [*bbBits*] 17-32 there will be four bytes per character.
D*/
diff --git a/pigpio.py b/pigpio.py
index 44c41e1..5ca345f 100644
--- a/pigpio.py
+++ b/pigpio.py
@@ -252,7 +252,7 @@ import threading
import os
import atexit
-VERSION = "1.14"
+VERSION = "1.15"
exceptions = True
@@ -1049,6 +1049,13 @@ class pi():
Returns the PWM dutycycle.
+
+ For normal PWM the dutycycle will be out of the defined range
+ for the gpio (see [*get_PWM_range*]). If a hardware clock is
+ active on the gpio the reported dutycycle will be 500
+ (out of 1000). If hardware PWM is active on the gpio the
+ reported dutycycle will be out of a 1000.
+
...
pi.set_PWM_dutycycle(4, 25)
print(pi.get_PWM_dutycycle(4))
@@ -1082,6 +1089,9 @@ class pi():
user_gpio:= 0-31.
+ If a hardware clock or hardware PWM is active on the gpio
+ the reported range will be 1000.
+
...
pi.set_PWM_range(9, 500)
print(pi.get_PWM_range(9))
@@ -1097,6 +1107,9 @@ class pi():
user_gpio:= 0-31.
+ If a hardware clock or hardware PWM is active on the gpio
+ the reported real range will be 1000.
+
...
pi.set_PWM_frequency(4, 800)
print(pi.get_PWM_real_range(4))
@@ -1135,6 +1148,12 @@ class pi():
Returns the frequency (in Hz) used for the gpio.
+ For normal PWM the frequency will be that defined for the gpio
+ by [*set_PWM_frequency*]. If a hardware clock is active on the
+ gpio the reported frequency will be that set by [*hardware_clock*].
+ If hardware PWM is active on the gpio the reported frequency
+ will be that set by [*hardware_PWM*].
+
...
pi.set_PWM_frequency(4,0)
print(pi.get_PWM_frequency(4))
@@ -1684,7 +1703,7 @@ class pi():
to output.
bb_baud:= baud rate to use.
data:= the bytes to write.
- offset:= number of microseconds from the starts of the
+ offset:= number of microseconds from the start of the
waveform, default 0.
bb_bits:= number of data bits, default 8.
bb_stop:= number of stop half bits, default 2.
@@ -2858,12 +2877,13 @@ class pi():
"""
return _u2i(_pigpio_command(self.sl, _PI_CMD_PROCD, script_id, 0))
- def bb_serial_read_open(self, user_gpio, bb_baud):
+ def bb_serial_read_open(self, user_gpio, bb_baud, bb_bits=8):
"""
Opens a gpio for bit bang reading of serial data.
user_gpio:= 0-31, the gpio to use.
bb_baud:= 300-250000, the baud rate.
+ bb_bits:= 1-32, the number of bits per word, default 8.
The serial data is held in a cyclic buffer and is read using
[*bb_serial_read*].
@@ -2876,8 +2896,16 @@ class pi():
status = pi.bb_serial_read_open(17, 9600)
...
"""
- return _u2i(_pigpio_command(
- self.sl, _PI_CMD_SLRO, user_gpio, bb_baud))
+ # pigpio message format
+
+ # I p1 user_gpio
+ # I p2 bb_baud
+ # I p3 4
+ ## extension ##
+ # I bb_bits
+ extents = [struct.pack("I", bb_bits)]
+ return _u2i(_pigpio_command_ext(
+ self.sl, _PI_CMD_SLRO, user_gpio, bb_baud, 4, extents))
def bb_serial_read(self, user_gpio):
"""
@@ -2890,6 +2918,14 @@ class pi():
number of bytes read will be less than zero (and will contain
the error code).
+ The bytes returned for each character depend upon the number of
+ data bits [*bb_bits*] specified in the [*bb_serial_read_open*]
+ command.
+
+ For [*bb_bits*] 1-8 there will be one byte per character.
+ For [*bb_bits*] 9-16 there will be two bytes per character.
+ For [*bb_bits*] 17-32 there will be four bytes per character.
+
...
(count, data) = pi.bb_serial_read(4)
...
diff --git a/pigpiod_if.3 b/pigpiod_if.3
index 576b2c3..0af3b82 100644
--- a/pigpiod_if.3
+++ b/pigpiod_if.3
@@ -457,6 +457,15 @@ user_gpio: 0-31.
.br
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
+.br
+
+.br
+For normal PWM the dutycycle will be out of the defined range
+for the gpio (see \fBget_PWM_range\fP). If a hardware clock is
+active on the gpio the reported dutycycle will be 500 (out of 1000).
+If hardware PWM is active on the gpio the reported dutycycle
+will be out of a 1000.
+
.IP "\fBint set_PWM_range(unsigned user_gpio, unsigned range)\fP"
.IP "" 4
Set the range of PWM values to be used on the gpio.
@@ -535,6 +544,12 @@ user_gpio: 0-31.
Returns the dutycycle range used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
+.br
+
+.br
+If a hardware clock or hardware PWM is active on the gpio the
+reported range will be 1000.
+
.IP "\fBint get_PWM_real_range(unsigned user_gpio)\fP"
.IP "" 4
Get the real underlying range of PWM values being used on the gpio.
@@ -555,6 +570,12 @@ user_gpio: 0-31.
Returns the real range used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
+.br
+
+.br
+If a hardware clock or hardware PWM is active on the gpio the
+reported real range will be 1000.
+
.IP "\fBint set_PWM_frequency(unsigned user_gpio, unsigned frequency)\fP"
.IP "" 4
Set the frequency (in Hz) of the PWM to be used on the gpio.
@@ -654,6 +675,15 @@ user_gpio: 0-31.
.br
+.br
+For normal PWM the frequency will be that defined for the gpio by
+\fBset_PWM_frequency\fP. If a hardware clock is active on the gpio the
+reported frequency will be that set by \fBhardware_clock\fP. If hardware
+PWM is active on the gpio the reported frequency will be that set by
+\fBhardware_PWM\fP.
+
+.br
+
.br
Returns the frequency (in hertz) used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
@@ -1892,7 +1922,7 @@ script_id: >=0, as returned by \fBstore_script\fP.
.br
The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
-.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned bbBaud)\fP"
+.IP "\fBint bb_serial_read_open(unsigned user_gpio, unsigned bbBaud, unsigned bbBits)\fP"
.IP "" 4
This function opens a gpio for bit bang reading of serial data.
@@ -1905,6 +1935,8 @@ user_gpio: 0-31.
.br
bbBaud: 100-250000
.br
+ bbBits: 1-32
+.br
.EE
@@ -1951,6 +1983,19 @@ user_gpio: 0-31, previously opened with \fBbb_serial_read_open\fP.
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
+.br
+
+.br
+The bytes returned for each character depend upon the number of
+data bits \fBbbBits\fP specified in the \fBbb_serial_read_open\fP command.
+
+.br
+
+.br
+For \fBbbBits\fP 1-8 there will be one byte per character.
+For \fBbbBits\fP 9-16 there will be two bytes per character.
+For \fBbbBits\fP 17-32 there will be four bytes per character.
+
.IP "\fBint bb_serial_read_close(unsigned user_gpio)\fP"
.IP "" 4
This function closes a gpio for bit bang reading of serial data.
diff --git a/pigpiod_if.c b/pigpiod_if.c
index 488e72a..c51e6a5 100644
--- a/pigpiod_if.c
+++ b/pigpiod_if.c
@@ -864,8 +864,24 @@ int stop_script(unsigned script_id)
int delete_script(unsigned script_id)
{return pigpio_command(gPigCommand, PI_CMD_PROCD, script_id, 0, 1);}
-int bb_serial_read_open(unsigned user_gpio, unsigned baud)
- {return pigpio_command(gPigCommand, PI_CMD_SLRO, user_gpio, baud, 1);}
+int bb_serial_read_open(unsigned user_gpio, unsigned baud, uint32_t bbBits)
+{
+ gpioExtent_t ext[1];
+
+ /*
+ p1=user_gpio
+ p2=baud
+ p3=4
+ ## extension ##
+ unsigned bbBits
+ */
+
+ ext[0].size = sizeof(uint32_t);
+ ext[0].ptr = &bbBits;
+
+ return pigpio_command_ext(
+ gPigCommand, PI_CMD_SLRO, user_gpio, baud, 4, 1, ext, 1);
+}
int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)
{
diff --git a/pigpiod_if.h b/pigpiod_if.h
index 4fc199e..61596fa 100644
--- a/pigpiod_if.h
+++ b/pigpiod_if.h
@@ -30,7 +30,7 @@ For more information, please refer to
#include "pigpio.h"
-#define PIGPIOD_IF_VERSION 12
+#define PIGPIOD_IF_VERSION 13
/*TEXT
@@ -464,6 +464,12 @@ user_gpio: 0-31.
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
+
+For normal PWM the dutycycle will be out of the defined range
+for the gpio (see [*get_PWM_range*]). If a hardware clock is
+active on the gpio the reported dutycycle will be 500 (out of 1000).
+If hardware PWM is active on the gpio the reported dutycycle
+will be out of a 1000.
D*/
/*F*/
@@ -507,6 +513,9 @@ user_gpio: 0-31.
Returns the dutycycle range used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
+
+If a hardware clock or hardware PWM is active on the gpio the
+reported range will be 1000.
D*/
/*F*/
@@ -520,6 +529,9 @@ user_gpio: 0-31.
Returns the real range used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
+
+If a hardware clock or hardware PWM is active on the gpio the
+reported real range will be 1000.
D*/
/*F*/
@@ -575,6 +587,12 @@ Get the frequency of PWM being used on the gpio.
user_gpio: 0-31.
. .
+For normal PWM the frequency will be that defined for the gpio by
+[*set_PWM_frequency*]. If a hardware clock is active on the gpio the
+reported frequency will be that set by [*hardware_clock*]. If hardware
+PWM is active on the gpio the reported frequency will be that set by
+[*hardware_PWM*].
+
Returns the frequency (in hertz) used for the gpio if OK,
otherwise PI_BAD_USER_GPIO.
D*/
@@ -1343,13 +1361,14 @@ The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
D*/
/*F*/
-int bb_serial_read_open(unsigned user_gpio, unsigned bbBaud);
+int bb_serial_read_open(unsigned user_gpio, unsigned bbBaud, unsigned bbBits);
/*D
This function opens a gpio for bit bang reading of serial data.
. .
user_gpio: 0-31.
bbBaud: 100-250000
+ bbBits: 1-32
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
@@ -1376,6 +1395,13 @@ user_gpio: 0-31, previously opened with [*bb_serial_read_open*].
Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
+
+The bytes returned for each character depend upon the number of
+data bits [*bbBits*] specified in the [*bb_serial_read_open*] command.
+
+For [*bbBits*] 1-8 there will be one byte per character.
+For [*bbBits*] 9-16 there will be two bytes per character.
+For [*bbBits*] 17-32 there will be four bytes per character.
D*/
/*F*/
diff --git a/pigs.1 b/pigs.1
index 5449176..6235830 100644
--- a/pigs.1
+++ b/pigs.1
@@ -361,6 +361,13 @@ This command returns the PWM dutycycle in use on gpio \fBu\fP.
Upon success the dutycycle is returned. On error a negative
status code will be returned.
+.br
+For normal PWM the dutycycle will be out of the defined range
+for the gpio (see \fBPRG\fP). If a hardware clock is active on
+the gpio the reported dutycycle will be 500 (out of 1000).
+If hardware PWM is active on the gpio the reported dutycycle
+will be out of a 1000.
+
.br
\fBExample\fP
@@ -1482,6 +1489,13 @@ This command returns the PWM frequency in Hz used for gpio \fBu\fP.
Upon success the PWM frequency is returned. On error a negative
status code will be returned.
+.br
+For normal PWM the frequency will be that defined for the gpio
+by \fBPFS\fP. If a hardware clock is active on the gpio
+the reported frequency will be that set by \fBHC\fP.
+If hardware PWM is active on the gpio the reported frequency
+will be that set by \fBHP\fP.
+
.br
\fBExample\fP
@@ -1610,6 +1624,10 @@ This command returns the dutycycle range for gpio \fBu\fP.
Upon success the range is returned. On error a negative status code
will be returned.
+.br
+If a hardware clock or hardware PWM is active on the gpio the reported
+range will be 1000.
+
.br
\fBExample\fP
@@ -1838,6 +1856,10 @@ ERROR: unknown script id
.br
This command returns the real underlying range used by gpio \fBu\fP.
+.br
+If a hardware clock or hardware PWM is active on the gpio the
+reported range will be 1000.
+
.br
Upon success the real range is returned. On error a negative status code
will be returned.
@@ -2269,6 +2291,17 @@ is returned. On error a negative status code will be returned.
.br
The gpio \fBu\fP should have been initialised with the \fBSLRO\fP command.
+.br
+The bytes returned for each character depend upon the number of
+data bits \fBdb\fP specified in the \fBSLRO\fP command.
+
+.br
+For \fBdb\fP 1-8 there will be one byte per character.
+.br
+For \fBdb\fP 9-16 there will be two bytes per character.
+.br
+For \fBdb\fP 17-32 there will be four bytes per character.
+
.br
\fBExample\fP
@@ -2315,12 +2348,12 @@ ERROR: no serial read in progress on gpio
.br
-.IP "\fBSLRO u b\fP - Open gpio for bit bang serial data"
+.IP "\fBSLRO u b db\fP - Open gpio for bit bang serial data"
.IP "" 4
.br
This command opens gpio \fBu\fP for reading bit bang serial data
-at \fBb\fP baud.
+at \fBb\fP baud and \fBdb\fP data bits.
.br
Upon success nothing is returned. On error a negative status code
@@ -2339,11 +2372,11 @@ in a timely fashion.
.br
.EX
-$ pigs slro 23 19200
+$ pigs slro 23 19200 8
.br
.br
-$ pigs slro 23 19200
+$ pigs slro 23 19200 8
.br
-50
.br
diff --git a/setup.py b/setup.py
index 2791a4f..6e6be8a 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
from distutils.core import setup
setup(name='pigpio',
- version='1.14',
+ version='1.15',
author='joan',
author_email='joan@abyz.co.uk',
maintainer='joan',
diff --git a/x_pigpio.c b/x_pigpio.c
index 5c42ad8..e3270f9 100644
--- a/x_pigpio.c
+++ b/x_pigpio.c
@@ -392,7 +392,7 @@ To the lascivious pleasing of a lute.\n\
/* gpioSerialReadOpen changes the alert function */
- e = gpioSerialReadOpen(GPIO, BAUD);
+ e = gpioSerialReadOpen(GPIO, BAUD, 8);
CHECK(5, 6, e, 0, 0, "serial read open");
gpioWaveClear();
diff --git a/x_pigpiod_if.c b/x_pigpiod_if.c
index a0d7a30..c1ff6c3 100644
--- a/x_pigpiod_if.c
+++ b/x_pigpiod_if.c
@@ -366,7 +366,7 @@ To the lascivious pleasing of a lute.\n\
e = wave_tx_stop();
CHECK(5, 5, e, 0, 0, "wave tx stop");
- e = bb_serial_read_open(GPIO, BAUD);
+ e = bb_serial_read_open(GPIO, BAUD, 8);
CHECK(5, 6, e, 0, 0, "serial read open");
wave_clear();
diff --git a/x_pigs b/x_pigs
index db1b82d..34c0642 100755
--- a/x_pigs
+++ b/x_pigs
@@ -1,6 +1,6 @@
#!/bin/bash
-VERSION=24
+VERSION=25
GPIO=4
@@ -189,7 +189,7 @@ if [[ $s = "" ]]; then echo "SERVO-d ok"; else echo "SERVO-d fail ($s)"; fi
s=$(pigs wvclr)
if [[ $s = "" ]]; then echo "SLR-a ok"; else echo "SLR-a fail ($s)"; fi
-s=$(pigs slro $GPIO 1200)
+s=$(pigs slro $GPIO 1200 8)
if [[ $s = "" ]]; then echo "SLR-b ok"; else echo "SLR-b fail ($s)"; fi
s=$(pigs wvas $GPIO 1200 8 2 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73 0x20 0x6a 0x6f 0x61 0x6e)
if [[ $s = 95 ]]; then echo "SLR-c ok"; else echo "SLR-c fail ($s)"; fi
diff --git a/x_pipe b/x_pipe
index 6d9dafc..744dee5 100755
--- a/x_pipe
+++ b/x_pipe
@@ -1,6 +1,6 @@
#!/bin/bash
-VERSION=24
+VERSION=25
GPIO=4
@@ -258,7 +258,7 @@ if [[ $s = 0 ]]; then echo "SERVO-d ok"; else echo "SERVO-d fail ($s)"; fi
echo "wvclr" >/dev/pigpio
read -t 1 s /dev/pigpio
+echo "slro $GPIO 1200 8" >/dev/pigpio
read -t 1 s /dev/pigpio