*/
/*
-This version is for pigpio version 24+
+This version is for pigpio version 25+
*/
#include <stdio.h>
{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
\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\
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.
*/
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.
*/
.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
.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
.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
.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
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.
.br
bbBaud: 100-250000
.br
+ bbBits: 1-32
+.br
.EE
.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
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.
For more information, please refer to <http://unlicense.org/>
*/
-/* pigpio version 24 */
+/* pigpio version 25 */
#include <stdio.h>
#include <string.h>
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
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;
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 */
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 */
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;
/* ----------------------------------------------------------------------- */
-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;
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;
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;
}
}
if (gpioInfo[i].is == GPIO_HW_PWM)
{
switchFunctionOff(i);
+
gpioInfo[i].is = GPIO_UNDEFINED;
}
}
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<<shift)) | (mode<<shift);
}
{
if (gpioInfo[gpio].is != GPIO_WRITE)
{
- if (gpioInfo[gpio].is == GPIO_UNDEFINED)
- {
- /* stop a glitch between setting mode then level */
- if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT;
- else *(gpioReg + GPSET0 + BANK) = BIT;
- }
- else
- {
- switchFunctionOff(gpio);
- }
+ /* stop a glitch between setting mode then level */
+ if (level == PI_OFF) *(gpioReg + GPCLR0 + BANK) = BIT;
+ else *(gpioReg + GPSET0 + BANK) = BIT;
+
+ switchFunctionOff(gpio);
+
gpioSetMode(gpio, PI_OUTPUT);
+
gpioInfo[gpio].is = GPIO_WRITE;
}
}
if (gpioInfo[gpio].is != GPIO_PWM)
{
- if (gpioInfo[gpio].is == GPIO_UNDEFINED)
- {
- }
- else
- {
- switchFunctionOff(gpio);
- }
+ switchFunctionOff(gpio);
+
gpioSetMode(gpio, PI_OUTPUT);
+
gpioInfo[gpio].is = GPIO_PWM;
}
int gpioGetPWMdutycycle(unsigned gpio)
{
+ unsigned pwm;
+
DBG(DBG_USER, "gpio=%d", gpio);
CHECK_INITED;
if (gpio > 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);
+ }
}
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;
+ }
}
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];
+ }
}
int gpioGetPWMfrequency(unsigned gpio)
{
+ unsigned pwm, clock;
+
DBG(DBG_USER, "gpio=%d", gpio);
CHECK_INITED;
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];
+ }
}
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;
}
/*-------------------------------------------------------------------------*/
-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;
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;
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);
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;
{
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);
{
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();
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;
}
}
#include <stdint.h>
#include <pthread.h>
-#define PIGPIO_VERSION 24
+#define PIGPIO_VERSION 25
/*TEXT
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*/
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);
...
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);
...
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.
...
/*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*].
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*/
import os
import atexit
-VERSION = "1.14"
+VERSION = "1.15"
exceptions = True
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))
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))
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))
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))
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.
"""
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*].
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):
"""
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)
...
.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.
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.
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.
.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.
.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.
.br
bbBaud: 100-250000
.br
+ bbBits: 1-32
+.br
.EE
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.
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)
{
#include "pigpio.h"
-#define PIGPIOD_IF_VERSION 12
+#define PIGPIOD_IF_VERSION 13
/*TEXT
. .
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*/
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*/
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*/
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*/
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,
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*/
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
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
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
.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.
.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
.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
.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
from distutils.core import setup
setup(name='pigpio',
- version='1.14',
+ version='1.15',
author='joan',
author_email='joan@abyz.co.uk',
maintainer='joan',
/* gpioSerialReadOpen changes the alert function */
- e = gpioSerialReadOpen(GPIO, BAUD);
+ e = gpioSerialReadOpen(GPIO, BAUD, 8);
CHECK(5, 6, e, 0, 0, "serial read open");
gpioWaveClear();
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();
#!/bin/bash
-VERSION=24
+VERSION=25
GPIO=4
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
#!/bin/bash
-VERSION=24
+VERSION=25
GPIO=4
echo "wvclr" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "SLR-a ok"; else echo "SLR-a fail ($s)"; fi
-echo "slro $GPIO 1200" >/dev/pigpio
+echo "slro $GPIO 1200 8" >/dev/pigpio
read -t 1 s </dev/pigout
if [[ $s = 0 ]]; then echo "SLR-b ok"; else echo "SLR-b fail ($s)"; fi
echo "wvas $GPIO 1200 8 2 0 0x6d 0x79 0x20 0x6e 0x61 0x6d 0x65 0x20 0x69 0x73 0x20 0x6a 0x6f 0x61 0x6e" >/dev/pigpio