Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
I am really surprised by the new version, and have just installed the PI version to test it.
One thing I absolutely need is access to the serial port.
There is an example included which opens a serial port, but of course it doesn't work directly, surely access problems.
(It's just a Linux).
Can anyone direct me to the right lane how it works ?
and anyone have some more test codes for the serial port?
Besides, a hobbyist computer like the Pi stands or falls on its
the access to the outside via the IO ports and for example the I2C bus.
I don't know if the development team already has something in the pipeline,
but I would like to see it happen.
A certainly good start would be to use the PIGPIO library,
http://abyz.me.uk/rpi/pigpio/index.html.
It is already installed with the OS, so it should be possible to use it via import.
But of course I don't know how.....
One thing I absolutely need is access to the serial port.
There is an example included which opens a serial port, but of course it doesn't work directly, surely access problems.
(It's just a Linux).
Can anyone direct me to the right lane how it works ?
and anyone have some more test codes for the serial port?
Besides, a hobbyist computer like the Pi stands or falls on its
the access to the outside via the IO ports and for example the I2C bus.
I don't know if the development team already has something in the pipeline,
but I would like to see it happen.
A certainly good start would be to use the PIGPIO library,
http://abyz.me.uk/rpi/pigpio/index.html.
It is already installed with the OS, so it should be possible to use it via import.
But of course I don't know how.....
SPAMINATOR NR.1
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
I usually use this to connect to the serial port. It works flawlessly.
But of course you need the correct permissions to use the port. Usually you need to add your user to the group "dialout". If you serial devices has another owner or group you need that group. Mine look like this:
And now the code.
But of course you need the correct permissions to use the port. Usually you need to add your user to the group "dialout". If you serial devices has another owner or group you need that group. Mine look like this:
Code: Select all
nicolas@Rocky:~$ ls -l /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Okt 11 08:06 /dev/ttyS0
Code: Select all
DeclareModule Serial
Interface Serial
open.i(device.s, baudrate.i, parity.i = #PB_SerialPort_NoParity, dataBits.i = 8, stopBit.i = 1, handShake.i = #PB_SerialPort_NoHandshake)
close.i()
sendData(*buffer, length.i)
sendChar(char.a)
sendFloat(float.f)
receiveData(*buffer, length.i)
receiveChar.a()
receiveLong.l()
sendUnicode(unicode.u)
receiveUnicode.u()
receiveFloat.f()
sendString(string.s) ; Sendet den String ohne Nullbyte am Schluss
receiveString.s(length.i = -1, eol.c = 0)
availableData.i()
waitFor.i(*buffer, length.i)
isOpen.i()
lock()
unlock()
tryLock.i()
free()
bps.f()
availableOutput.i()
EndInterface
Declare.i new()
EndDeclareModule
Module Serial
Structure SerialS
vTable.i
device.s
baudrate.i
handle.i
hMutex.i
lastTime.i
bytesSent.i
EndStructure
Procedure.i new()
Protected *this.SerialS
*this = AllocateMemory(SizeOf(SerialS))
If Not *this : ProcedureReturn #False : EndIf
*this\vTable = ?vTable_Serial
*this\hMutex = CreateMutex()
*this\bytesSent = 0
ProcedureReturn *this
EndProcedure
Procedure.i Serial_open(*this.SerialS, device.s, baudrate.i, parity.i = #PB_SerialPort_NoParity, dataBits.i = 8, stopBit.i = 1, handShake.i = #PB_SerialPort_NoHandshake)
If IsSerialPort(*this\handle)
CloseSerialPort(*this\handle)
EndIf
*this\handle = OpenSerialPort(#PB_Any, device, baudrate, parity, dataBits, stopBit, handShake, 4096, 4096)
If Not *this\handle : ProcedureReturn #False : EndIf
*this\device = device
*this\baudrate = baudrate
ProcedureReturn *this\handle
EndProcedure
Procedure Serial_close(*this.SerialS)
If IsSerialPort(*this\handle)
CloseSerialPort(*this\handle)
EndIf
EndProcedure
Procedure Serial_sendData(*this.SerialS, *buffer, length.i)
Protected pos.i = 0
If IsSerialPort(*this\handle)
While pos < length
pos + WriteSerialPortData(*this\handle, *buffer + pos, length - pos)
Wend
*this\bytesSent + length
EndIf
EndProcedure
Procedure Serial_sendChar(*this.SerialS, char.a)
Protected pos.i = 0
If IsSerialPort(*this\handle)
While pos < 1
pos + WriteSerialPortData(*this\handle, @char, 1)
Wend
*this\bytesSent + 1
EndIf
EndProcedure
Procedure Serial_sendFloat(*this.Serial, float.f)
*this\sendData(@float, SizeOf(Float))
EndProcedure
Procedure Serial_receiveData(*this.SerialS, *buffer, length.i)
Protected pos.i = 0
If IsSerialPort(*this\handle)
While pos < length
pos + ReadSerialPortData(*this\handle, *buffer + pos, length - pos)
Wend
ProcedureReturn length
EndIf
ProcedureReturn #False
EndProcedure
Macro Serial_receiveTYPE(__name, __t, __s, __return)
Procedure.__s Serial_receive#__name(*this.Serial)
Protected result.__s
If (*this\receiveData(@result, SizeOf(__t)))
ProcedureReturn result
EndIf
ProcedureReturn __return
EndProcedure
EndMacro
Serial_receiveTYPE(Char, Character, c, 0)
Serial_receiveTYPE(Long, Long, l, 0)
Serial_receiveTYPE(Unicode, Unicode, u, 0)
Serial_receiveTYPE(Float, Float, f, 0.0)
Procedure Serial_sendUnicode(*this.SerialS, unicode.u)
Protected pos.i = 0
If IsSerialPort(*this\handle)
While pos < 2
pos + WriteSerialPortData(*this\handle, @unicode + 1 - pos, 2 - pos)
Wend
*this\bytesSent + 2
EndIf
EndProcedure
Procedure Serial_sendString(*this.SerialS, string.s)
Protected pos.i, length.i = Len(string)
If IsSerialPort(*this\handle)
While pos < length
pos + WriteSerialPortData(*this\handle, @string + pos, length - pos)
Wend
*this\bytesSent + length
EndIf
EndProcedure
Procedure.s Serial_receiveString(*this.SerialS, length.i = -1, eol.c = 0)
Protected pos.i = 0, *mem, result.s = "", c.a
If IsSerialPort(*this\handle)
If length = 0 : ProcedureReturn "" : EndIf
While length
While Not ReadSerialPortData(*this\handle, @c, 1) : Wend
If (Not c) Or (c = eol) : Break : EndIf
result + Chr(c)
length - 1
Wend
EndIf
ProcedureReturn result
EndProcedure
Procedure.i Serial_availableData(*this.SerialS)
If IsSerialPort(*this\handle)
ProcedureReturn AvailableSerialPortInput(*this\handle)
EndIf
ProcedureReturn 0
EndProcedure
Procedure.i Serial_waitFor(*this.SerialS, *buffer.Ascii, length.i)
Protected try.i = 0
If IsSerialPort(*this\handle)
Protected i.i = 0, Dim copyBuffer.a(length - 1), j.i = 0, full.i = 1
Repeat
While Not ReadSerialPortData(*this\handle, @copyBuffer(j), 1) : Wend
j = (j + 1) % length
If (full < length)
full + 1
Else
For i = 0 To length - 1
If (*buffer\a <> copyBuffer((j + i) % length))
*buffer - i
try + 1
Break
EndIf
*buffer + 1
Next
If (i = length)
Break
EndIf
EndIf
ForEver
EndIf
ProcedureReturn #True
EndProcedure
Procedure.i Serial_isOpen(*this.SerialS)
ProcedureReturn IsSerialPort(*this\handle)
EndProcedure
Procedure Serial_lock(*this.SerialS)
LockMutex(*this\hMutex)
EndProcedure
Procedure Serial_unlock(*this.SerialS)
UnlockMutex(*this\hMutex)
EndProcedure
Procedure.i Serial_tryLock(*this.SerialS)
ProcedureReturn TryLockMutex(*this\hMutex)
EndProcedure
Procedure Serial_free(*this.SerialS)
FreeMutex(*this\hMutex)
FreeMemory(*this)
EndProcedure
Procedure.f Serial_bps(*this.SerialS)
Protected newTime.i = ElapsedMilliseconds()
Protected bps.f = *this\bytesSent / ((newTime - *this\lastTime) / 1000.0)
*this\lastTime = newTime
*this\bytesSent = 0
ProcedureReturn bps
EndProcedure
Procedure.i Serial_availableOutput(*this.SerialS)
If IsSerialPort(*this\handle)
ProcedureReturn AvailableSerialPortOutput(*this\handle)
EndIf
ProcedureReturn -1
EndProcedure
DataSection
vTable_Serial:
Data.i @Serial_open(), @Serial_close(), @Serial_sendData(), @Serial_sendChar(), @Serial_sendFloat()
Data.i @Serial_receiveData(), @Serial_receiveChar(), @Serial_receiveLong()
Data.i @Serial_sendUnicode(), @Serial_receiveUniCode()
Data.i @Serial_receiveFloat()
Data.i @Serial_sendString(), @Serial_receiveString(), @Serial_availableData(), @Serial_waitFor()
Data.i @Serial_isOpen(), @Serial_lock(), @Serial_unlock(), @Serial_tryLock(), @Serial_free()
Data.i @Serial_bps(), @Serial_availableOutput()
EndDataSection
EndModule
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
And btw: On your raspberry there is /dev/ttyAMA0 which should be the bluetooth interface and /dev/ttyS0 which should be the usual serial interface. At least if you have a Raspberry Pi 3 or higher and an up-to-date raspbian os.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
The i2c bus should also be available in /dev/i2c-*. If it is not you problaby have to enable its drivers in /boot/config.txt. Read more here: https://forums.raspberrypi.com/viewtopic.php?t=97639
Then you can use i2c very easily: https://raspberry-projects.com/pi/progr ... -interface
Then you can use i2c very easily: https://raspberry-projects.com/pi/progr ... -interface
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
first version to use the pigpio as dll (.so) .
i would prefer as import lib, but do not know how.
Note, you have to run the code with root rights,
else you got only the version nr.
use sudo !
i would prefer as import lib, but do not know how.
Note, you have to run the code with root rights,
else you got only the version nr.
use sudo !
Code: Select all
If OpenConsole()
If OpenLibrary(0, "libpigpio.so")
result=CallFunction(0, "gpioVersion")
PrintN( "pigpio version:" + Str(result))
result=CallFunction(0, "gpioHardwareRevision")
PrintN( "hardwareversion " + Str(result))
;init the gpios
result=CallFunction(0, "gpioInitialise")
PrintN( "gpio init returns " + Str(result))
If result>0
result=CallFunction(0, "gpioTick")
PrintN("gpio Tick returns " + Str(result))
s$=""
For pin=0 To 31
result=CallFunction(0, "gpioRead",Pin)
s$ + Str(RESULT)
Next
PrintN("io read for 0-31 = " + s$ )
;result=CallFunction(0, "gpioTerminate")
;Debug "gpio terminate returns " + result
Else
PrintN("can't init gpio")
EndIf
PrintN("closing lib")
CloseLibrary(0)
Else
PrintN("error loading lib")
EndIf
EndIf
SPAMINATOR NR.1
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
Try this:
Code: Select all
;
; https://abyz.me.uk/rpi/pigpio/cif.html
;
; https://github.com/joan2937/pigpio/blob/master/pigpio.h
;
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
CompilerEndIf
Macro int
l
EndMacro
Macro unsigned
l
EndMacro
Macro uint32_t
l
EndMacro
#PI_OFF = 0
#PI_ON = 1
#PI_CLEAR = 0
#PI_SET = 1
#PI_LOW = 0
#PI_HIGH = 1
#PI_INPUT = 0
#PI_OUTPUT = 1
#PI_ALT0 = 4
#PI_ALT1 = 5
#PI_ALT2 = 6
#PI_ALT3 = 7
#PI_ALT4 = 3
#PI_ALT5 = 2
#PI_PUD_OFF = 0
#PI_PUD_DOWN = 1
#PI_PUD_UP = 2
#PI_TIME_RELATIVE = 0
#PI_TIME_ABSOLUTE = 1
#PI_FILE_READ = 1
#PI_FILE_WRITE = 2
#PI_FILE_RW = 3
#PI_FILE_APPEND = 4
#PI_FILE_CREATE = 8
#PI_FILE_TRUNC = 16
#PI_INIT_FAILED = -1 ; gpioInitialise failed
#PI_BAD_USER_GPIO = -2 ; GPIO Not 0-31
#PI_BAD_GPIO = -3 ; GPIO Not 0-53
#PI_BAD_MODE = -4 ; mode Not 0-7
#PI_BAD_LEVEL = -5 ; level Not 0-1
#PI_BAD_PUD = -6 ; pud Not 0-2
#PI_BAD_PULSEWIDTH = -7 ; pulsewidth Not 0 Or 500-2500
#PI_BAD_DUTYCYCLE = -8 ; dutycycle outside set range
#PI_BAD_TIMER = -9 ; timer Not 0-9
#PI_BAD_MS = -10 ; ms Not 10-60000
#PI_BAD_TIMETYPE = -11 ; timetype Not 0-1
#PI_BAD_SECONDS = -12 ; seconds < 0
#PI_BAD_MICROS = -13 ; micros Not 0-999999
#PI_TIMER_FAILED = -14 ; gpioSetTimerFunc failed
#PI_BAD_WDOG_TIMEOUT= -15 ; timeout Not 0-60000
#PI_NO_ALERT_FUNC = -16 ; DEPRECATED
#PI_BAD_CLK_PERIPH = -17 ; clock peripheral Not 0-1
#PI_BAD_CLK_SOURCE = -18 ; DEPRECATED
#PI_BAD_CLK_MICROS = -19 ; clock micros Not 1, 2, 4, 5, 8, Or 10
#PI_BAD_BUF_MILLIS = -20 ; buf millis Not 100-10000
#PI_BAD_DUTYRANGE = -21 ; dutycycle range Not 25-40000
#PI_BAD_DUTY_RANGE = -21 ; DEPRECATED (use PI_BAD_DUTYRANGE)
#PI_BAD_SIGNUM = -22 ; signum Not 0-63
#PI_BAD_PATHNAME = -23 ; can't open pathname
#PI_NO_HANDLE = -24 ; no handle available
#PI_BAD_HANDLE = -25 ; unknown handle
#PI_BAD_IF_FLAGS = -26 ; ifFlags > 4
#PI_BAD_CHANNEL = -27 ; DMA channel Not 0-15
#PI_BAD_PRIM_CHANNEL= -27 ; DMA primary channel Not 0-15
#PI_BAD_SOCKET_PORT = -28 ; socket port Not 1024-32000
#PI_BAD_FIFO_COMMAND= -29 ; unrecognized fifo command
#PI_BAD_SECO_CHANNEL= -30 ; DMA secondary channel Not 0-15
#PI_NOT_INITIALISED = -31 ; function called before gpioInitialise
#PI_INITIALISED = -32 ; function called after gpioInitialise
#PI_BAD_WAVE_MODE = -33 ; waveform mode Not 0-3
#PI_BAD_CFG_INTERNAL= -34 ; bad parameter in gpioCfgInternals call
#PI_BAD_WAVE_BAUD = -35 ; baud rate Not 50-250K(RX)/50-1M(TX)
#PI_TOO_MANY_PULSES = -36 ; waveform has too many pulses
#PI_TOO_MANY_CHARS = -37 ; waveform has too many chars
#PI_NOT_SERIAL_GPIO = -38 ; no bit bang serial Read on GPIO
#PI_BAD_SERIAL_STRUC= -39 ; bad (null) serial Structure parameter
#PI_BAD_SERIAL_BUF = -40 ; bad (null) serial buf parameter
#PI_NOT_PERMITTED = -41 ; GPIO operation Not permitted
#PI_SOME_PERMITTED = -42 ; one Or more GPIO Not permitted
#PI_BAD_WVSC_COMMND = -43 ; bad WVSC subcommand
#PI_BAD_WVSM_COMMND = -44 ; bad WVSM subcommand
#PI_BAD_WVSP_COMMND = -45 ; bad WVSP subcommand
#PI_BAD_PULSELEN = -46 ; trigger pulse length Not 1-100
#PI_BAD_SCRIPT = -47 ; invalid script
#PI_BAD_SCRIPT_ID = -48 ; unknown script id
#PI_BAD_SER_OFFSET = -49 ; add serial Data offset > 30 minutes
#PI_GPIO_IN_USE = -50 ; GPIO already in use
#PI_BAD_SERIAL_COUNT= -51 ; must Read at least a byte at a time
#PI_BAD_PARAM_NUM = -52 ; script parameter id Not 0-9
#PI_DUP_TAG = -53 ; script has duplicate tag
#PI_TOO_MANY_TAGS = -54 ; script has too many tags
#PI_BAD_SCRIPT_CMD = -55 ; illegal script command
#PI_BAD_VAR_NUM = -56 ; script variable id Not 0-149
#PI_NO_SCRIPT_ROOM = -57 ; no more room For scripts
#PI_NO_MEMORY = -58 ; can't allocate temporary memory
#PI_SOCK_READ_FAILED= -59 ; socket Read failed
#PI_SOCK_WRIT_FAILED= -60 ; socket write failed
#PI_TOO_MANY_PARAM = -61 ; too many script parameters (> 10)
#PI_NOT_HALTED = -62 ; DEPRECATED
#PI_SCRIPT_NOT_READY= -62 ; script initialising
#PI_BAD_TAG = -63 ; script has unresolved tag
#PI_BAD_MICS_DELAY = -64 ; bad MICS Delay (too large)
#PI_BAD_MILS_DELAY = -65 ; bad MILS Delay (too large)
#PI_BAD_WAVE_ID = -66 ; non existent wave id
#PI_TOO_MANY_CBS = -67 ; No more CBs For waveform
#PI_TOO_MANY_OOL = -68 ; No more OOL For waveform
#PI_EMPTY_WAVEFORM = -69 ; attempt To create an empty waveform
#PI_NO_WAVEFORM_ID = -70 ; no more waveforms
#PI_I2C_OPEN_FAILED = -71 ; can't open I2C device
#PI_SER_OPEN_FAILED = -72 ; can't open serial device
#PI_SPI_OPEN_FAILED = -73 ; can't open SPI device
#PI_BAD_I2C_BUS = -74 ; bad I2C bus
#PI_BAD_I2C_ADDR = -75 ; bad I2C address
#PI_BAD_SPI_CHANNEL = -76 ; bad SPI channel
#PI_BAD_FLAGS = -77 ; bad i2c/spi/ser open flags
#PI_BAD_SPI_SPEED = -78 ; bad SPI speed
#PI_BAD_SER_DEVICE = -79 ; bad serial device name
#PI_BAD_SER_SPEED = -80 ; bad serial baud rate
#PI_BAD_PARAM = -81 ; bad i2c/spi/ser parameter
#PI_I2C_WRITE_FAILED= -82 ; i2c write failed
#PI_I2C_READ_FAILED = -83 ; i2c Read failed
#PI_BAD_SPI_COUNT = -84 ; bad SPI count
#PI_SER_WRITE_FAILED= -85 ; ser write failed
#PI_SER_READ_FAILED = -86 ; ser Read failed
#PI_SER_READ_NO_DATA= -87 ; ser Read no Data available
#PI_UNKNOWN_COMMAND = -88 ; unknown command
#PI_SPI_XFER_FAILED = -89 ; spi xfer/Read/write failed
#PI_BAD_POINTER = -90 ; bad (NULL) pointer
#PI_NO_AUX_SPI = -91 ; no auxiliary SPI on Pi A Or B
#PI_NOT_PWM_GPIO = -92 ; GPIO is Not in use For PWM
#PI_NOT_SERVO_GPIO = -93 ; GPIO is Not in use For servo pulses
#PI_NOT_HCLK_GPIO = -94 ; GPIO has no hardware clock
#PI_NOT_HPWM_GPIO = -95 ; GPIO has no hardware PWM
#PI_BAD_HPWM_FREQ = -96 ; invalid hardware PWM frequency
#PI_BAD_HPWM_DUTY = -97 ; hardware PWM dutycycle Not 0-1M
#PI_BAD_HCLK_FREQ = -98 ; invalid hardware clock frequency
#PI_BAD_HCLK_PASS = -99 ; need password To use hardware clock 1
#PI_HPWM_ILLEGAL = -100 ; illegal, PWM in use For main clock
#PI_BAD_DATABITS = -101 ; serial Data bits Not 1-32
#PI_BAD_STOPBITS = -102 ; serial (half) stop bits Not 2-8
#PI_MSG_TOOBIG = -103 ; socket/pipe message too big
#PI_BAD_MALLOC_MODE = -104 ; bad memory allocation mode
#PI_TOO_MANY_SEGS = -105 ; too many I2C transaction segments
#PI_BAD_I2C_SEG = -106 ; an I2C transaction segment failed
#PI_BAD_SMBUS_CMD = -107 ; SMBus command Not supported by driver
#PI_NOT_I2C_GPIO = -108 ; no bit bang I2C in progress on GPIO
#PI_BAD_I2C_WLEN = -109 ; bad I2C write length
#PI_BAD_I2C_RLEN = -110 ; bad I2C Read length
#PI_BAD_I2C_CMD = -111 ; bad I2C command
#PI_BAD_I2C_BAUD = -112 ; bad I2C baud rate, Not 50-500k
#PI_CHAIN_LOOP_CNT = -113 ; bad chain loop count
#PI_BAD_CHAIN_LOOP = -114 ; empty chain loop
#PI_CHAIN_COUNTER = -115 ; too many chain counters
#PI_BAD_CHAIN_CMD = -116 ; bad chain command
#PI_BAD_CHAIN_DELAY = -117 ; bad chain delay micros
#PI_CHAIN_NESTING = -118 ; chain counters nested too deeply
#PI_CHAIN_TOO_BIG = -119 ; chain is too long
#PI_DEPRECATED = -120 ; deprecated function removed
#PI_BAD_SER_INVERT = -121 ; bit bang serial invert Not 0 Or 1
#PI_BAD_EDGE = -122 ; bad ISR edge value, Not 0-2
#PI_BAD_ISR_INIT = -123 ; bad ISR initialisation
#PI_BAD_FOREVER = -124 ; loop ForEver must be last command
#PI_BAD_FILTER = -125 ; bad filter parameter
#PI_BAD_PAD = -126 ; bad pad number
#PI_BAD_STRENGTH = -127 ; bad pad drive strength
#PI_FIL_OPEN_FAILED = -128 ; file open failed
#PI_BAD_FILE_MODE = -129 ; bad file mode
#PI_BAD_FILE_FLAG = -130 ; bad file flag
#PI_BAD_FILE_READ = -131 ; bad file Read
#PI_BAD_FILE_WRITE = -132 ; bad file write
#PI_FILE_NOT_ROPEN = -133 ; file Not open For Read
#PI_FILE_NOT_WOPEN = -134 ; file Not open For write
#PI_BAD_FILE_SEEK = -135 ; bad file seek
#PI_NO_FILE_MATCH = -136 ; no files match pattern
#PI_NO_FILE_ACCESS = -137 ; no permission To access file
#PI_FILE_IS_A_DIR = -138 ; file is a directory
#PI_BAD_SHELL_STATUS= -139 ; bad shell Return status
#PI_BAD_SCRIPT_NAME = -140 ; bad script name
#PI_BAD_SPI_BAUD = -141 ; bad SPI baud rate, Not 50-500k
#PI_NOT_SPI_GPIO = -142 ; no bit bang SPI in progress on GPIO
#PI_BAD_EVENT_ID = -143 ; bad event id
#PI_CMD_INTERRUPTED = -144 ; Used by Python
#PI_NOT_ON_BCM2711 = -145 ; Not available on BCM2711
#PI_ONLY_ON_BCM2711 = -146 ; only available on BCM2711
#PI_PIGIF_ERR_0 = -2000
#PI_PIGIF_ERR_99 = -2099
#PI_CUSTOM_ERR_0 = -3000
#PI_CUSTOM_ERR_999 = -3999
PrototypeC.int Prototype_gpioInitialise()
PrototypeC Prototype_gpioTerminate()
PrototypeC.int Prototype_gpioSetMode(gpio.unsigned, mode.unsigned)
PrototypeC.int Prototype_gpioGetMode(gpio.unsigned)
PrototypeC.int Prototype_gpioSetPullUpDown(gpio.unsigned, pud.unsigned)
PrototypeC.int Prototype_gpioRead(gpio.unsigned)
PrototypeC.int Prototype_gpioWrite(gpio.unsigned, level.unsigned)
PrototypeC.uint32_t Prototype_gpioRead_Bits_0_31()
PrototypeC.uint32_t Prototype_gpioRead_Bits_32_53()
PrototypeC.int Prototype_gpioWrite_Bits_0_31_Clear(bits.uint32_t)
PrototypeC.int Prototype_gpioWrite_Bits_32_53_Clear(bits.uint32_t)
PrototypeC.int Prototype_gpioWrite_Bits_0_31_Set(bits.uint32_t)
PrototypeC.int Prototype_gpioWrite_Bits_32_53_Set(bits.uint32_t)
PrototypeC.int Prototype_gpioTime(timetype.unsigned, *seconds, *micros)
PrototypeC.int Prototype_gpioSleep(timetype.unsigned, seconds.int, micros.int)
PrototypeC.uint32_t Prototype_gpioDelay(micros.uint32_t)
PrototypeC.uint32_t Prototype_gpioTick()
PrototypeC.unsigned Prototype_gpioHardwareRevision()
PrototypeC.unsigned Prototype_gpioVersion()
Global LibPigPio.i
Global gpioInitialise.Prototype_gpioInitialise
Global gpioTerminate.Prototype_gpioTerminate
Global gpioSetMode.Prototype_gpioSetMode
Global gpioGetMode.Prototype_gpioGetMode
Global gpioSetPullUpDown.Prototype_gpioSetPullUpDown
Global gpioRead.Prototype_gpioRead
Global gpioWrite.Prototype_gpioWrite
Global gpioRead_Bits_0_31.Prototype_gpioRead_Bits_0_31
Global gpioRead_Bits_32_53.Prototype_gpioRead_Bits_32_53
Global gpioWrite_Bits_0_31_Clear.Prototype_gpioWrite_Bits_0_31_Clear
Global gpioWrite_Bits_32_53_Clear.Prototype_gpioWrite_Bits_32_53_Clear
Global gpioWrite_Bits_0_31_Set.Prototype_gpioWrite_Bits_0_31_Set
Global gpioWrite_Bits_32_53_Set.Prototype_gpioWrite_Bits_32_53_Set
Global gpioTime.Prototype_gpioTime
Global gpioSleep.Prototype_gpioSleep
Global gpioDelay.Prototype_gpioDelay
Global gpioTick.Prototype_gpioTick
Global gpioHardwareRevision.Prototype_gpioHardwareRevision
Global gpioVersion.Prototype_gpioVersion
Procedure.i OpenPigPio()
LibPigPio = OpenLibrary(#PB_Any, "libpigpio.so")
If LibPigPio
gpioInitialise = GetFunction(LibPigPio, "gpioInitialise")
gpioTerminate = GetFunction(LibPigPio, "gpioTerminate")
gpioSetMode = GetFunction(LibPigPio, "gpioSetMode")
gpioGetMode = GetFunction(LibPigPio, "gpioGetMode")
gpioSetPullUpDown = GetFunction(LibPigPio, "gpioSetPullUpDown")
gpioRead = GetFunction(LibPigPio, "gpioRead")
gpioWrite = GetFunction(LibPigPio, "gpioWrite")
gpioRead_Bits_0_31 = GetFunction(LibPigPio, "gpioRead_Bits_0_31")
gpioRead_Bits_32_53 = GetFunction(LibPigPio, "gpioRead_Bits_32_53")
gpioWrite_Bits_0_31_Clear = GetFunction(LibPigPio, "gpioWrite_Bits_0_31_Clear")
gpioWrite_Bits_32_53_Clear = GetFunction(LibPigPio, "gpioWrite_Bits_32_53_Clear")
gpioWrite_Bits_0_31_Set = GetFunction(LibPigPio, "gpioWrite_Bits_0_31_Set")
gpioWrite_Bits_32_53_Set = GetFunction(LibPigPio, "gpioWrite_Bits_32_53_Set")
gpioTime = GetFunction(LibPigPio, "gpioTime")
gpioSleep = GetFunction(LibPigPio, "gpioSleep")
gpioDelay = GetFunction(LibPigPio, "gpioDelay")
gpioTick = GetFunction(LibPigPio, "gpioTick")
gpioHardwareRevision = GetFunction(LibPigPio, "gpioHardwareRevision")
gpioVersion = GetFunction(LibPigPio, "gpioVersion")
EndIf
ProcedureReturn LibPigPio
EndProcedure
Procedure ClosePigPio()
If IsLibrary(LibPigPio)
CloseLibrary(LibPigPio)
LibPigPio = 0
EndIf
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
Define i.i, s$, pin.i
If OpenConsole()
If OpenPigPio()
PrintN("pigpio version: " + Str(gpioVersion()))
PrintN("pigpio version: " + Str(gpioHardwareRevision()))
If gpioInitialise() <> #PI_INIT_FAILED
PrintN("gpio Tick returns " + Str(gpioTick()))
s$=""
For pin=0 To 31
s$ + Str(gpioRead(pin))
Next
PrintN("io read for 0-31 = " + s$)
PrintN("io read for 0-31 = " + RSet(Bin(gpioRead_Bits_0_31()), 32, "0"))
gpioTerminate()
Else
PrintN("can't init gpio")
EndIf
ClosePigPio()
Else
PrintN("error loading lib")
EndIf
EndIf
CompilerEndIf
-
- Addict
- Posts: 1443
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
Maybe it is more 'direct' to use the following:
https://iwer.info/article/Elektrotechni ... index.html
It's in german, so you may need a translator.
https://iwer.info/article/Elektrotechni ... index.html
It's in german, so you may need a translator.
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
very very very deep in the hardware,infratec wrote: ↑Thu Dec 16, 2021 7:58 am Maybe it is more 'direct' to use the following:
https://iwer.info/article/Elektrotechni ... index.html
It's in german, so you may need a translator.
thx for th article.....
SPAMINATOR NR.1
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
thx, exactly i was looking forinfratec wrote: ↑Wed Dec 15, 2021 7:39 pm Try this:
Code: Select all
; ; https://abyz.me.uk/rpi/pigpio/cif.html ; ; https://github.com/joan2937/pigpio/blob/master/pigpio.h ; .... ....
SPAMINATOR NR.1
-
- Addict
- Posts: 1443
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
thx, seems to work also
SPAMINATOR NR.1
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
imported pigpoid_if2 mighn't be complete as tool I was working on prepossessed and got rid of the enums
you need to start pigpoi manually with
sudo pigpiod
Code: Select all
;;#427 "/usr/incude/pigpio.h"
;-structures
Structure gpioHeader_t
func.u;
size.u;
EndStructure;
Structure gpioExtent_t;
size.l;
*ptr;
uData.l;
EndStructure;
Structure gpioSample_t;
tick.l;
level.l;
EndStructure;
Structure gpioReport_t;
seqno.u;
fags.u;
tick.l
level.l
EndStructure;
Structure gpioPulse_t;
gpioOn.l
gpioOff.l
usDelay.l
EndStructure;
Structure rawWave_t
qpioOn.l
gpioOff.l
usDelay.l
flags.l
EndStructure;
;;#485 "/usr/incude/pigpio.h"
Structure rawWaveInfo_t;
botCB.u;
topCB.u;
botOO.u;
topOO.u;
deleted.u;
numCB.u;
numBOO.u;
numTOO.u;
EndStructure;
Structure rawSPI_t
clk.l
mosi.l
miso.l
ss_po.l
ss_us.l
clk_po.l
clk_pha.l
clk_us.l
EndStructure;
Structure rawCbs_t;
info.l
src.l
dst.l
length.l
stride.l
nNext.l
pad.l[2]
EndStructure;
Structure pi_i2c_msg_t;
addr.w;
fags.w;
len.w;
*buf;
EndStructure;
Structure bsc_xfer_t;
control.l
rxCnt.l
rxBuf.a[512];
txCnt.l
txBuf.a[512];
EndStructure;
;-gpio prototypes
PrototypeC gpioAlertFunc_t(gpio,level,tick);
PrototypeC gpioAlertFuncEx_t(gpio,level,tick, *userdata);
PrototypeC eventFunc_t(event,tick);
PrototypeC eventFuncEx_t(event,tick, *userdata);
PrototypeC gpioISRFunc_t(gpio,level,tick);
PrototypeC gpioISRFuncEx_t(gpio,level,tick, *userdata);
PrototypeC gpioTimerFunc_t();
PrototypeC gpioTimerFuncEx_t( *userdata);
PrototypeC gpioSignalFunc_t(signum);
PrototypeC gpioSignalFuncEx_t(signum, *userdata);
PrototypeC gpioGetSamplesFunc_t(*samples.gpioSample_t,numSamples);
PrototypeC gpioGetSamplesFuncEx_t(*samples.gpioSample_t,numSamples, *userdata);
PrototypeC gpioThreadFunc_t();
;-Import pigpio
ImportC "-lpigpio"
;#959 "/usr/incude/pigpio.h"
gpioInitialise();
;#988 "/usr/incude/pigpio.h"
gpioTerminate();
;#1006 "/usr/incude/pigpio.h"
gpioSetMode(gpio,mode);
;#1032 "/usr/incude/pigpio.h"
gpioGetMode(gpio);
;#1052 "/usr/incude/pigpio.h"
gpioSetPullUpDown(gpio,pud);
;#1074 "/usr/incude/pigpio.h"
gpioRead(gpio);
;#1093 "/usr/incude/pigpio.h"
gpioWrite(gpio,level);
;#1115 "/usr/incude/pigpio.h"
gpioPWM(user_gpio,dutycycle);
;#1146 "/usr/incude/pigpio.h"
gpioGetPWMdutycycle(user_gpio);
;#1171 "/usr/incude/pigpio.h"
gpioSetPWMrange(user_gpio,range);
;#1206 "/usr/incude/pigpio.h"
gpioGetPWMrange(user_gpio);
;#1225 "/usr/incude/pigpio.h"
gpioGetPWMrealRange(user_gpio);
;#1247 "/usr/incude/pigpio.h"
gpioSetPWMfrequency(user_gpio,frequency);
;#1304 "/usr/incude/pigpio.h"
gpioGetPWMfrequency(user_gpio);
;#1329 "/usr/incude/pigpio.h"
gpioServo(user_gpio, pulsewidth);
;#1388 "/usr/incude/pigpio.h"
gpioGetServoPulsewidth(user_gpio);
;#1402 "/usr/incude/pigpio.h"
gpioSetAlertFunc(user_gpio,*f.gpioAlertFunc_t);
;#1483 "/usr/incude/pigpio.h"
gpioSetAlertFuncEx(user_gpio,*f.gpioAlertFuncEx_t,*userdata=0);
;#1526 "/usr/incude/pigpio.h"
gpioSetISRFunc(gpio,edge,timeout,*f.gpioISRFunc_t);
;#1591 "/usr/incude/pigpio.h"
gpioSetISRFuncEx(gpio,edge,timeout,*f.gpioISRFuncEx_t,*userdata=0);
;#1639 "/usr/incude/pigpio.h"
gpioNotifyOpen();
;#1684 "/usr/incude/pigpio.h"
gpioNotifyOpenWithSize(bufSize);
;#1696 "/usr/incude/pigpio.h"
gpioNotifyBegin(handle,bits);
;#1758 "/usr/incude/pigpio.h"
gpioNotifyPause(handle);
;#1778 "/usr/incude/pigpio.h"
gpioNotifyClose(handle);
;#1796 "/usr/incude/pigpio.h"
gpioWaveClear();
;#1810 "/usr/incude/pigpio.h"
gpioWaveAddNew();
;#1826 "/usr/incude/pigpio.h"
gpioWaveAddGeneric(numPulses,*pulses.gpioPulse_t);
;#1885 "/usr/incude/pigpio.h"
gpioWaveAddSerial(user_gpio,baud,data_bits,stop_bits,offset,numBytes,*buf);
;#1949 "/usr/incude/pigpio.h"
gpioWaveCreate();
;#2004 "/usr/incude/pigpio.h"
gpioWaveCreatePad(pctCB,pctBOOl,pctTOOl);
;#2047 "/usr/incude/pigpio.h"
gpioWaveDelete(wave_id);
;#2071 "/usr/incude/pigpio.h"
gpioWaveTxSend(wave_id, wave_mode);
;#2095 "/usr/incude/pigpio.h"
gpioWaveChain(*buf,bufSize);
;#2193 "/usr/incude/pigpio.h"
gpioWaveTxAt();
;#2206 "/usr/incude/pigpio.h"
gpioWaveTxBusy();
;#2216 "/usr/incude/pigpio.h"
gpioWaveTxStop();
;#2227 "/usr/incude/pigpio.h"
gpioWaveGetMicros();
gpioWaveGetHighMicros();
gpioWaveGetMaxMicros();
gpioWaveGetPulses();
gpioWaveGetHighPulses();
gpioWaveGetMaxPulses();
gpioWaveGetCbs();
gpioWaveGetHighCbs();
gpioWaveGetMaxCbs();
gpioSerialReadOpen(user_gpio, baud, data_bits);
;#2318 "/usr/incude/pigpio.h"
gpioSerialReadInvert(user_gpio, invert);
;#2339 "/usr/incude/pigpio.h"
gpioSerialRead(user_gpio,*buf,bufSize.i);
;#2363 "/usr/incude/pigpio.h"
gpioSerialReadClose(user_gpio);
;#2375 "/usr/incude/pigpio.h"
i2cOpen(i2cBus, i2cAddr, i2cFags);
;#2418 "/usr/incude/pigpio.h"
i2cCose(handle);
;#2431 "/usr/incude/pigpio.h"
i2cWriteQuick(handle, bit);
;#2452 "/usr/incude/pigpio.h"
i2cWriteByte(handle, bVal);
;#2472 "/usr/incude/pigpio.h"
i2cReadByte(handle);
;#2491 "/usr/incude/pigpio.h"
i2cWriteByteData(handle, i2cReg, bVal);
;#2513 "/usr/incude/pigpio.h"
i2cWriteWordData(handle, i2cReg, wVal);
;#2535 "/usr/incude/pigpio.h"
i2cReadByteData(handle, i2cReg);
;#2556 "/usr/incude/pigpio.h"
i2cReadWordData(handle, i2cReg);
;#2577 "/usr/incude/pigpio.h"
i2cProcessCall(handle, i2cReg, wVal);
;#2600 "/usr/incude/pigpio.h"
i2cWriteBlockData(handle, i2cReg,*buf, count);
;#2625 "/usr/incude/pigpio.h"
i2cReadBockData(handle, i2cReg,*buf);
;#2650 "/usr/incude/pigpio.h"
i2cBockProcessCall(handle, i2cReg,*buf, count);
;#2680 "/usr/incude/pigpio.h"
i2cReadI2CBlockData(handle, i2cReg,*buf, count);
;#2704 "/usr/incude/pigpio.h"
i2cWriteI2CBlockData(handle, i2cReg,*buf, count);
;#2726 "/usr/incude/pigpio.h"
i2cReadDevice(handle,*buf, count);
;#2746 "/usr/incude/pigpio.h"
i2cWriteDevice(handle,*buf, count);
;#2765 "/usr/incude/pigpio.h"
i2cSwitchCombined(setting);
;#2780 "/usr/incude/pigpio.h"
i2cSegments(handle,*seg.pi_i2c_msg_t,numSegs);
;#2795 "/usr/incude/pigpio.h"
i2cZip(handle,*inBuf,inlen,*outBuf,outlen);
;#2855 "/usr/incude/pigpio.h"
bbI2COpen(SDA, SC, baud);
;#2884 "/usr/incude/pigpio.h"
bbI2CCose(SDA);
;#2897 "/usr/incude/pigpio.h"
bbI2CZip(SDA,*inBuf,inlen,*outBuf,outlen);
;#2968 "/usr/incude/pigpio.h"
bscXfer(*bsc_xfer);
;#3115 "/usr/incude/pigpio.h"
bbSPIOpen(CS, MISO, MOSI, SCK,baud, spiFags);
;#3171 "/usr/incude/pigpio.h"
bbSPICose(CS);
;#3184 "/usr/incude/pigpio.h"
bbSPIXfer(CS,*inBuf,*outBuf,count);
;#3270 "/usr/incude/pigpio.h"
spiOpen(spiChan, baud, spiFags);
;#3362 "/usr/incude/pigpio.h"
spiCose(handle);
;#3375 "/usr/incude/pigpio.h"
spiRead(handle,*buf, count);
;#3392 "/usr/incude/pigpio.h"
spiWrite(handle,*buf, count);
;#3408 "/usr/incude/pigpio.h"
spiXfer(handle,*txBuf,*rxBuf, count);
;#3427 "/usr/incude/pigpio.h"
serOpen(*sertty, baud, serFags);
;#3451 "/usr/incude/pigpio.h"
serClose(handle);
;#3463 "/usr/incude/pigpio.h"
serWriteByte(handle, bVal);
;#3476 "/usr/incude/pigpio.h"
serReadByte(handle);
;#3491 "/usr/incude/pigpio.h"
serWrite(handle,*buf, count);
;#3508 "/usr/incude/pigpio.h"
serRead(handle,*buf, count);
;#3527 "/usr/incude/pigpio.h"
serDataAvaiabe(handle);
;#3542 "/usr/incude/pigpio.h"
gpioTrigger(user_gpio, pulselen,level);
;#3559 "/usr/incude/pigpio.h"
gpioSetWatchdog(user_gpio, timeout);
;#3603 "/usr/incude/pigpio.h"
gpioNoiseFilter(user_gpio, steady, active);
;#3635 "/usr/incude/pigpio.h"
gpioGitchFilter(user_gpio, steady);
;#3665 "/usr/incude/pigpio.h"
gpioSetGetSamplesFunc(*f.gpioGetSamplesFunc_t,bits);
;#3694 "/usr/incude/pigpio.h"
gpioSetGetSamplesFuncEx(*f.gpioGetSamplesFuncEx_t,bits,*userdata);
;#3719 "/usr/incude/pigpio.h"
gpioSetTimerFunc(timer, millis,*f.gpioTimerFunc_t);
;#3750 "/usr/incude/pigpio.h"
gpioSetTimerFuncEx(timer,millis,*f.gpioTimerFuncEx_t,*userdata);
;#3774 "/usr/incude/pigpio.h"
gpioStartThread(*f.gpioThreadFunc_t,*userdata);
;#3828 "/usr/incude/pigpio.h"
gpioStopThread(*pth);
;#3843 "/usr/incude/pigpio.h"
gpioStoreScript(*script);
;#3859 "/usr/incude/pigpio.h"
gpioRunScript(script_id, numPar,*param);
;#3879 "/usr/incude/pigpio.h"
gpioUpdateScript(script_id, numPar,*param);
;#3900 "/usr/incude/pigpio.h"
gpioScriptStatus(script_id,*param);
;#3928 "/usr/incude/pigpio.h"
gpioStopScript(script_id);
;#3941 "/usr/incude/pigpio.h"
gpioDeleteScript(script_id);
;#3954 "/usr/incude/pigpio.h"
gpioSetSignalFunc(signum,*f.gpioSignalFunc_t);
;#3977 "/usr/incude/pigpio.h"
gpioSetSignalFuncEx(signum,*f.gpioSignalFuncEx_t,*userdata);
;#4000 "/usr/incude/pigpio.h"
gpioRead_Bits_0_31();
gpioRead_Bits_32_53();
gpioWrite_Bits_0_31_Cear(bits);
;#4032 "/usr/incude/pigpio.h"
gpioWrite_Bits_32_53_Cear(bits);
;#4045 "/usr/incude/pigpio.h"
gpioWrite_Bits_0_31_Set(bits);
;#4058 "/usr/incude/pigpio.h"
gpioWrite_Bits_32_53_Set(bits);
;#4075 "/usr/incude/pigpio.h"
gpioHardwareCock(gpio, ckfreq);
;#4113 "/usr/incude/pigpio.h"
gpioHardwarePWM(gpio, PWMfreq, PWMduty);
;#4165 "/usr/incude/pigpio.h"
gpioTime(timetype, *seconds, *micros);
;#4194 "/usr/incude/pigpio.h"
gpioSleep(timetype, seconds, micros);
;#4229 "/usr/incude/pigpio.h"
gpioDelay(micros);
;#4244 "/usr/incude/pigpio.h"
gpioTick();
;#4275 "/usr/incude/pigpio.h"
gpioHardwareRevision();
;#4303 "/usr/incude/pigpio.h"
gpioVersion();
gpioGetPad(pad);
;#4332 "/usr/incude/pigpio.h"
gpioSetPad(pad, padStrength);
;#4354 "/usr/incude/pigpio.h"
eventMonitor(handle, bits);
;#4383 "/usr/incude/pigpio.h"
eventSetFunc(event, *f.eventFunc_t);
;#4403 "/usr/incude/pigpio.h"
eventSetFuncEx(event,*f.eventFuncEx_t,*userdata);
;#4427 "/usr/incude/pigpio.h"
eventTrigger(event);
;#4453 "/usr/incude/pigpio.h"
shell(*scriptName,*scriptString);
;#4494 "/usr/incude/pigpio.h"
;-pragma GCC diagnostic push
;-pragma GCC diagnostic ignored "-Wcomment"
fileOpen(*file.p-UTF8, mode);
;#4604 "/usr/incude/pigpio.h"
;-pragma GCC diagnostic pop
fileCose(handle);
;#4624 "/usr/incude/pigpio.h"
fileWrite(handle,*buf, count);
;#4653 "/usr/incude/pigpio.h"
fileRead(handle,*buf, count);
;#4676 "/usr/incude/pigpio.h"
_FileSeek(handle,seekOffset, seekFrom); as "FileSeek"
;#4700 "/usr/incude/pigpio.h"
;-pragma GCC diagnostic push
;-pragma GCC diagnostic ignored "-Wcomment"
filelist(*fpat.p-UTF8,*buf, count);
;#4756 "/usr/incude/pigpio.h"
;-pragma GCC diagnostic pop
gpioCfgBufferSize(cfgMillis);
;#4795 "/usr/incude/pigpio.h"
gpioCfgClock(cfgMicros, cfgPeripheral, cfgSource);
;#4832 "/usr/incude/pigpio.h"
gpioCfgDMAchannel(DMAchannel);
;#4847 "/usr/incude/pigpio.h"
gpioCfgDMAchannels(primaryChannel, secondaryChannel);
;#4881 "/usr/incude/pigpio.h"
gpioCfgPermissions(updateMask.q);
;#4908 "/usr/incude/pigpio.h"
gpioCfgSocketPort(port);
;#4923 "/usr/incude/pigpio.h"
gpioCfgInterfaces(ifFlags);
;#4946 "/usr/incude/pigpio.h"
gpioCfgMemAlloc(memAllocMode);
;#4966 "/usr/incude/pigpio.h"
gpioCfgNetAddr(numSockAddr, *sockAddr);
;#4981 "/usr/incude/pigpio.h"
gpioCfgGetInternals();
gpioCfgSetInternals(cfgVal);
;#5001 "/usr/incude/pigpio.h"
gpioCustom1(arg1, arg2,*argx, argc);
;#5019 "/usr/incude/pigpio.h"
gpioCustom2(arg1,*argx, argc,*retBuf,retMax);
;#5043 "/usr/incude/pigpio.h"
rawWaveAddSPI(*spi,offset,spiSS,*buf,spiTxBits,spiBitFirst,spiBitast,spiBits);
;#5074 "/usr/incude/pigpio.h"
rawWaveAddGeneric(numPuses,*pulses);
;#5102 "/usr/incude/pigpio.h"
rawWaveCB();
rawWaveCBAdr(cbNum);
;#5122 "/usr/incude/pigpio.h"
rawWaveGetOO(pos);
;#5135 "/usr/incude/pigpio.h"
rawWaveSetOO(pos, Val);
;#5148 "/usr/incude/pigpio.h"
rawWaveGetOut(pos);
;#5163 "/usr/incude/pigpio.h"
rawWaveSetOut(pos, Val);
;#5178 "/usr/incude/pigpio.h"
rawWaveGetIn(pos);
;#5193 "/usr/incude/pigpio.h"
rawWaveSetIn(pos, Val);
;#5208 "/usr/incude/pigpio.h"
rawWaveInfo(wave_id);
;#5220 "/usr/incude/pigpio.h"
getBitInBytes(bitPos,*buf,numBits);
;#5234 "/usr/incude/pigpio.h"
putBitInBytes(bitPos,*buf,bit);
;#5247 "/usr/incude/pigpio.h"
time_time.d();
time_seep(seconds.d);
;#5265 "/usr/incude/pigpio.h"
rawDumpWave();
;#5274 "/usr/incude/pigpio.h"
rawDumpScript(script_id);
EndImport
;#32 "/usr/incude/pigpiod_if2.h" 2
;#351 "/usr/incude/pigpiod_if2.h"
;-if2 prototypes
PrototypeC CBFunc_t(pi,user_gpio,level,tick);
PrototypeC CBFuncEx_t(pi,user_gpio, level,tick,*userdata);
PrototypeC evtCBFunc_t(pi,event,tick);
PrototypeC evtCBFuncEx_t(pi,event,tick,*userdata);
;-Import pigpiod_if2
ImportC "-lpigpiod_if2"
;#384 "/usr/incude/pigpiod_if2.h"
pigpio_error(errnum);
;#394 "/usr/incude/pigpiod_if2.h"
pigpiod_if_version();
start_thread(*thread_func.gpioThreadFunc_t,*userdata);
;#418 "/usr/incude/pigpiod_if2.h"
stop_thread(*pth);
;#432 "/usr/incude/pigpiod_if2.h"
pigpio_start(*addrStr,*portStr);
;#456 "/usr/incude/pigpiod_if2.h"
pigpio_stop(pi);
;#467 "/usr/incude/pigpiod_if2.h"
set_mode(pi,gpio,mode);
;#483 "/usr/incude/pigpiod_if2.h"
get_mode(pi,gpio);
;#496 "/usr/incude/pigpiod_if2.h"
set_pull_up_down(pi, gpio,pud);
;#511 "/usr/incude/pigpiod_if2.h"
gpio_read(pi,gpio);
;#524 "/usr/incude/pigpiod_if2.h"
gpio_write(pi,gpio,level);
;#543 "/usr/incude/pigpiod_if2.h"
set_PWM_dutycyce(pi,user_gpio,dutycyce);
;#562 "/usr/incude/pigpiod_if2.h"
get_PWM_dutycyce(pi,user_gpio);
;#585 "/usr/incude/pigpiod_if2.h"
set_PWM_range(pi,user_gpio,range);
;#616 "/usr/incude/pigpiod_if2.h"
get_PWM_range(pi,user_gpio);
;#633 "/usr/incude/pigpiod_if2.h"
get_PWM_real_range(pi, user_gpio);
;#654 "/usr/incude/pigpiod_if2.h"
set_PWM_frequency(pi, user_gpio, frequency);
;#704 "/usr/incude/pigpiod_if2.h"
get_PWM_frequency(pi, user_gpio);
;#727 "/usr/incude/pigpiod_if2.h"
set_servo_pusewidth(pi, user_gpio, pusewidth);
;#777 "/usr/incude/pigpiod_if2.h"
get_servo_pusewidth(pi, user_gpio);
;#790 "/usr/incude/pigpiod_if2.h"
notify_open(pi);
;#816 "/usr/incude/pigpiod_if2.h"
notify_begin(pi, handel, bits);
;#867 "/usr/incude/pigpiod_if2.h"
notify_pause(pi, handel);
;#883 "/usr/incude/pigpiod_if2.h"
notify_close(pi, handel);
;#897 "/usr/incude/pigpiod_if2.h"
set_watchdog(pi, user_gpio, timeout);
;#923 "/usr/incude/pigpiod_if2.h"
set_gitch_fiter(pi, user_gpio, steady);
;#951 "/usr/incude/pigpiod_if2.h"
set_noise_fiter(pi, user_gpio, steady, active);
;#982 "/usr/incude/pigpiod_if2.h"
read_bank_1(pi);
;#995 "/usr/incude/pigpiod_if2.h"
read_bank_2(pi);
;#1008 "/usr/incude/pigpiod_if2.h"
cear_bank_1(pi, bits);
;#1025 "/usr/incude/pigpiod_if2.h"
cear_bank_2(pi, bits);
;#1042 "/usr/incude/pigpiod_if2.h"
set_bank_1(pi, bits);
;#1059 "/usr/incude/pigpiod_if2.h"
set_bank_2(pi, bits);
;#1077 "/usr/incude/pigpiod_if2.h"
hardware_clock(pi, gpio, clkfreq);
;#1117 "/usr/incude/pigpiod_if2.h"
hardware_PWM(pi, gpio, PWMfreq, PWMduty);
;#1172 "/usr/incude/pigpiod_if2.h"
get_current_tick(pi);
;#1188 "/usr/incude/pigpiod_if2.h"
get_hardware_revision(pi);
;#1215 "/usr/incude/pigpiod_if2.h"
get_pigpio_version(pi);
;#1226 "/usr/incude/pigpiod_if2.h"
wave_cear(pi);
;#1239 "/usr/incude/pigpiod_if2.h"
wave_add_new(pi);
;#1253 "/usr/incude/pigpiod_if2.h"
wave_add_generic(pi, numPuses, *pulses.gpioPulse_t);
;#1277 "/usr/incude/pigpiod_if2.h"
wave_add_serial(pi, user_gpio, baud, data_bits,stop_bits, offset, numBytes,*str);
;#1319 "/usr/incude/pigpiod_if2.h"
wave_create(pi);
;#1378 "/usr/incude/pigpiod_if2.h"
wave_create_and_pad(pi, percent);
;#1421 "/usr/incude/pigpiod_if2.h"
wave_deete(pi, wave_id);
;#1446 "/usr/incude/pigpiod_if2.h"
wave_send_once(pi, wave_id);
;#1464 "/usr/incude/pigpiod_if2.h"
wave_send_repeat(pi, wave_id);
;#1483 "/usr/incude/pigpiod_if2.h"
wave_send_using_mode(pi, wave_id, mode);
;#1514 "/usr/incude/pigpiod_if2.h"
wave_chain(pi,*buf, bufSize);
;#1610 "/usr/incude/pigpiod_if2.h"
wave_tx_at(pi);
;#1626 "/usr/incude/pigpiod_if2.h"
wave_tx_busy(pi);
;#1639 "/usr/incude/pigpiod_if2.h"
wave_tx_stop(pi);
;#1653 "/usr/incude/pigpiod_if2.h"
wave_get_micros(pi);
;#1664 "/usr/incude/pigpiod_if2.h"
wave_get_high_micros(pi);
;#1675 "/usr/incude/pigpiod_if2.h"
wave_get_max_micros(pi);
;#1686 "/usr/incude/pigpiod_if2.h"
wave_get_puses(pi);
;#1696 "/usr/incude/pigpiod_if2.h"
wave_get_high_pulses(pi);
;#1707 "/usr/incude/pigpiod_if2.h"
wave_get_max_pulses(pi);
;#1717 "/usr/incude/pigpiod_if2.h"
wave_get_cbs(pi);
;#1728 "/usr/incude/pigpiod_if2.h"
wave_get_high_cbs(pi);
;#1739 "/usr/incude/pigpiod_if2.h"
wave_get_max_cbs(pi);
;#1750 "/usr/incude/pigpiod_if2.h"
gpio_trigger(pi, user_gpio, pulseen, level);
;#1767 "/usr/incude/pigpiod_if2.h"
store_script(pi,*script);
;#1783 "/usr/incude/pigpiod_if2.h"
run_script(pi, script_id, numPar, *param);
;#1802 "/usr/incude/pigpiod_if2.h"
update_script(pi, script_id, numPar, *param);
;#1823 "/usr/incude/pigpiod_if2.h"
script_status(pi, script_id, *param);
;#1851 "/usr/incude/pigpiod_if2.h"
stop_script(pi, script_id);
;#1864 "/usr/incude/pigpiod_if2.h"
delete_script(pi, script_id);
;#1877 "/usr/incude/pigpiod_if2.h"
bb_serial_read_open(pi, user_gpio, baud, data_bits);
;#1899 "/usr/incude/pigpiod_if2.h"
bb_serial_read(pi, user_gpio, *buf,bufSize.i);
;#1923 "/usr/incude/pigpiod_if2.h"
bb_serial_read_cose(pi, user_gpio);
;#1936 "/usr/incude/pigpiod_if2.h"
bb_serial_invert(pi, user_gpio, invert);
;#1950 "/usr/incude/pigpiod_if2.h"
i2c_open(pi, i2c_bus, i2c_addr, i2c_flags);
;#1993 "/usr/incude/pigpiod_if2.h"
i2c_cose(pi, hande);
;#2006 "/usr/incude/pigpiod_if2.h"
i2c_write_quick(pi, handle, bit);
;#2027 "/usr/incude/pigpiod_if2.h"
i2c_write_byte(pi, handle, bVal);
;#2047 "/usr/incude/pigpiod_if2.h"
i2c_read_byte(pi, handle);
;#2066 "/usr/incude/pigpiod_if2.h"
i2c_write_byte_data(pi, handle, i2c_reg, bVal);
;#2089 "/usr/incude/pigpiod_if2.h"
i2c_write_word_data(pi, handle, i2c_reg, wVal);
;#2112 "/usr/incude/pigpiod_if2.h"
i2c_read_byte_data(pi, handle, i2c_reg);
;#2133 "/usr/incude/pigpiod_if2.h"
i2c_read_word_data(pi, handle, i2c_reg);
;#2155 "/usr/incude/pigpiod_if2.h"
i2c_process_call(pi, handle, i2c_reg, wVal);
;#2178 "/usr/incude/pigpiod_if2.h"
i2c_write_block_data(pi, handle, i2c_reg,*buf, count);
;#2203 "/usr/incude/pigpiod_if2.h"
i2c_read_block_data(pi, handle, i2c_reg,*buf);
;#2228 "/usr/incude/pigpiod_if2.h"
i2c_block_process_call(pi, handle, i2c_reg,*buf, count);
;#2259 "/usr/incude/pigpiod_if2.h"
i2c_read_i2c_block_data(pi, handle, i2c_reg,*buf, count);
;#2284 "/usr/incude/pigpiod_if2.h"
i2c_write_i2c_block_data(pi, handle, i2c_reg,*buf, count);
;#2307 "/usr/incude/pigpiod_if2.h"
i2c_read_device(pi, handle,*buf, count);
;#2327 "/usr/incude/pigpiod_if2.h"
i2c_write_device(pi, hanlde,*buf, count);
;#2347 "/usr/incude/pigpiod_if2.h"
i2c_zip(pi,handle,*inBuf,inlen,*outBuf,outlen);
;#2410 "/usr/incude/pigpiod_if2.h"
bb_i2c_open(pi, SDA, SC, baud);
;#2440 "/usr/incude/pigpiod_if2.h"
bb_i2c_cose(pi, SDA);
;#2454 "/usr/incude/pigpiod_if2.h"
bb_i2c_zip(pi,SDA,*inBuf,inlen,*outBuf,outlen);
;#2527 "/usr/incude/pigpiod_if2.h"
bb_spi_open(pi,CS, MISO, MOSI, SCK,baud, spi_fags);
;#2585 "/usr/incude/pigpiod_if2.h"
bb_spi_cose(pi, CS);
;#2599 "/usr/incude/pigpiod_if2.h"
bb_spi_xfer(pi,CS,*txBuf,*rxBuf,count);
;#2684 "/usr/incude/pigpiod_if2.h"
spi_open(pi, spi_channel, baud, spi_fags);
;#2777 "/usr/incude/pigpiod_if2.h"
spi_close(pi, handle);
;#2790 "/usr/incude/pigpiod_if2.h"
spi_read(pi, handle,*buf, count);
;#2807 "/usr/incude/pigpiod_if2.h"
spi_write(pi, handle,*buf, count);
;#2824 "/usr/incude/pigpiod_if2.h"
spi_xfer(pi, handle,*txBuf,*rxBuf, count);
;#2844 "/usr/incude/pigpiod_if2.h"
serial_open(pi,*ser_tty, baud, ser_fags);
;#2869 "/usr/incude/pigpiod_if2.h"
serial_close(pi, handle);
;#2882 "/usr/incude/pigpiod_if2.h"
serial_write_byte(pi, handle, bVal);
;#2896 "/usr/incude/pigpiod_if2.h"
serial_read_byte(pi, handle);
;#2912 "/usr/incude/pigpiod_if2.h"
serial_write(pi, handle,*buf, count);
;#2929 "/usr/incude/pigpiod_if2.h"
serial_read(pi, handle,*buf, count);
;#2948 "/usr/incude/pigpiod_if2.h"
serial_data_avaiabe(pi, handle);
;#2963 "/usr/incude/pigpiod_if2.h"
custom_1(pi, arg1, arg2,*argx, argc);
;#2982 "/usr/incude/pigpiod_if2.h"
custom_2(pi,arg1,*argx,argc,*retBuf,retMax);
;#3006 "/usr/incude/pigpiod_if2.h"
get_pad_strength(pi, pad);
;#3029 "/usr/incude/pigpiod_if2.h"
set_pad_strength(pi, pad, padStrength);
;#3053 "/usr/incude/pigpiod_if2.h"
shell_(pi,*scriptName,*scriptString);
;#3095 "/usr/incude/pigpiod_if2.h"
;-pragma GCC diagnostic push
;-pragma GCC diagnostic ignored "-Wcomment"
file_open(pi,*file, mode);
;#3208 "/usr/incude/pigpiod_if2.h"
;-pragma GCC diagnostic pop
file_close(pi, handle);
;#3229 "/usr/incude/pigpiod_if2.h"
file_write(pi, handle,*buf, count);
;#3258 "/usr/incude/pigpiod_if2.h"
file_read(pi, handle,*buf, count);
;#3284 "/usr/incude/pigpiod_if2.h"
file_seek(pi, hande,seekOffset,seekFrom);
;#3309 "/usr/incude/pigpiod_if2.h"
;-pragma GCC diagnostic push
;-pragma GCC diagnostic ignored "-Wcomment"
file_list(pi,*fpat,*buf, count);
;#3366 "/usr/incude/pigpiod_if2.h"
;-pragma GCC diagnostic pop
callback(pi, user_gpio, edge,*f.CBFunc_t);
;#3434 "/usr/incude/pigpiod_if2.h"
callback_ex(pi, user_gpio, edge, *f.CBFuncEx_t,*userdata);
;#3471 "/usr/incude/pigpiod_if2.h"
callback_cancel(callback_id);
;#3483 "/usr/incude/pigpiod_if2.h"
wait_for_edge(pi, user_gpio, edge,timeout.d);
;#3506 "/usr/incude/pigpiod_if2.h"
bsc_xfer(pi,*bscxfer);
;#3654 "/usr/incude/pigpiod_if2.h"
bsc_i2c(pi, i2c_addr,*bscxfer);
;#3694 "/usr/incude/pigpiod_if2.h"
event_callback(pi, event,*f.evtCBFunc_t);
;#3712 "/usr/incude/pigpiod_if2.h"
event_callback_ex(pi, event, *f.evtCBFuncEx_t,*userdata);
;#3731 "/usr/incude/pigpiod_if2.h"
event_callback_cancel(callback_id);
;#3744 "/usr/incude/pigpiod_if2.h"
wait_for_event(pi,event,timeout.d);
;#3760 "/usr/incude/pigpiod_if2.h"
event_trigger(pi,event);
;#4364 "/usr/incude/pigpiod_if2.h"
EndImport
;-enums
#pigif_bad_send = -2000
#pigif_bad_recv = -2001
#pigif_bad_getaddrinfo = -2002
#pigif_bad_connect = -2003
#pigif_bad_socket = -2004
#pigif_bad_noib = -2005
#pigif_dupicate_caback = -2006
#pigif_bad_maoc = -2007
#pigif_bad_caback = -2008
#pigif_notify_faied = -2009
#pigif_caback_not_found = -2010
#pigif_unconnected_pi = -2011
#pigif_too_many_pis = -2012
;/* gpio: 0-53 */
#PI_MIN_GPIO= 0
#PI_MAX_GPIO= 53
;/* user_gpio: 0-31 */
#PI_MAX_USER_GPIO =31
;/* level: 0-1 */
#PI_OFF= 0
#PI_ON= 1
#PI_CLEAR= 0
#PI_SET= 1
#PI_LOW= 0
#PI_HIGH= 1
;/* level: only reported For GPIO time-out, see gpioSetWatchdog */
#PI_TIMEOUT= 2
;/* mode: 0-7 */
#PI_INPUT= 0
#PI_OUTPUT= 1
#PI_ALT0= 4
#PI_ALT1= 5
#PI_ALT2= 6
#PI_ALT3= 7
#PI_ALT4= 3
#PI_ALT5= 2
;/* pud: 0-2 */
#PI_PUD_OFF= 0
#PI_PUD_DOWN= 1
#PI_PUD_UP= 2
;/* dutycycle: 0-range */
#PI_DEFAULT_DUTYCYCLE_RANGE= 255
;/* range: 25-40000 */
#PI_MIN_DUTYCYCLE_RANGE= 25
#PI_MAX_DUTYCYCLE_RANGE= 40000
;/* pulsewidth: 0, 500-2500 */
#PI_SERVO_OFF= 0
#PI_MIN_SERVO_PULSEWIDTH= 500
#PI_MAX_SERVO_PULSEWIDTH= 2500
;/* hardware PWM */
#PI_HW_PWM_MIN_FREQ= 1
#PI_HW_PWM_MAX_FREQ= 125000000
#PI_HW_PWM_MAX_FREQ_2711= 187500000
#PI_HW_PWM_RANGE= 1000000
;/* hardware clock */
#PI_HW_CLK_MIN_FREQ= 4689
#PI_HW_CLK_MIN_FREQ_2711= 13184
#PI_HW_CLK_MAX_FREQ= 250000000
#PI_HW_CLK_MAX_FREQ_2711= 375000000
#PI_NOTIFY_SLOTS= 32
#PI_NTFY_FLAGS_EVENT= (1 <<7)
#PI_NTFY_FLAGS_ALIVE= (1 <<6)
#PI_NTFY_FLAGS_WDOG= (1 <<5)
Macro PI_NTFY_FLAGS_BIT(x)
(((x)<<0)&31)
EndMacro
#PI_WAVE_BLOCKS= 4
#PI_WAVE_MAX_PULSES = #PI_WAVE_BLOCKS * 3000
#PI_WAVE_MAX_CHARS = #PI_WAVE_BLOCKS * 300
#PI_BB_I2C_MIN_BAUD = 50
#PI_BB_I2C_MAX_BAUD = 500000
#PI_BB_SPI_MIN_BAUD = 50
#PI_BB_SPI_MAX_BAUD =250000
#PI_BB_SER_MIN_BAUD = 50
#PI_BB_SER_MAX_BAUD =250000
#PI_BB_SER_NORMAL =0
#PI_BB_SER_INVERT =1
#PI_WAVE_MIN_BAUD = 50
#PI_WAVE_MAX_BAUD =1000000
#PI_SPI_MIN_BAUD = 32000
#PI_SPI_MAX_BAUD =125000000
#PI_MIN_WAVE_DATABITS =1
#PI_MAX_WAVE_DATABITS =32
#PI_MIN_WAVE_HALFSTOPBITS =2
#PI_MAX_WAVE_HALFSTOPBITS =8
#PI_WAVE_MAX_MICROS = 30 * 60 * 1000000;) /* half an hour */
#PI_MAX_WAVES =250
#PI_MAX_WAVE_CYCLES =65535
#PI_MAX_WAVE_DELAY = 65535
#PI_WAVE_COUNT_PAGES =10
;/* wave tx mode */
#PI_WAVE_MODE_ONE_SHOT = 0
#PI_WAVE_MODE_REPEAT = 1
#PI_WAVE_MODE_ONE_SHOT_SYNC =2
#PI_WAVE_MODE_REPEAT_SYNC = 3
;/* special wave at Return values */
#PI_WAVE_NOT_FOUND = 9998; /* Transmitted wave Not found. */
#PI_NO_TX_WAVE = 9999 ;/* No wave being transmitted. */
;/* Files, I2C, SPI, SER */
#PI_FILE_SLOTS =16
#PI_I2C_SLOTS =512
#PI_SPI_SLOTS =32
#PI_SER_SLOTS =16
#PI_MAX_I2C_ADDR = $7F
#PI_NUM_AUX_SPI_CHANNEL = 3
#PI_NUM_STD_SPI_CHANNEL =2
#PI_MAX_I2C_DEVICE_COUNT =(1<<16)
#PI_MAX_SPI_DEVICE_COUNT =(1<<16)
;/* max pi_i2c_msg_t per transaction */
#PI_I2C_RDRW_IOCTL_MAX_MSGS = 42
;/* flags For i2cTransaction, pi_i2c_msg_t */
#PI_I2C_M_WR = $0000 ;/* write Data */
#PI_I2C_M_RD = $0001 ;/* Read Data */
#PI_I2C_M_TEN = $0010 ;/* ten bit chip address */
#PI_I2C_M_RECV_LEN = $0400 ;/* length will be first received byte */
#PI_I2C_M_NO_RD_ACK = $0800 ;/* If I2C_FUNC_PROTOCOL_MANGLING */
#PI_I2C_M_IGNORE_NAK = $1000 ;/* If I2C_FUNC_PROTOCOL_MANGLING */
#PI_I2C_M_REV_DIR_ADDR= $2000 ;/* If I2C_FUNC_PROTOCOL_MANGLING */
#PI_I2C_M_NOSTART = $4000 ;/* If I2C_FUNC_PROTOCOL_MANGLING */
;/* bbI2CZip And i2cZip commands */
#PI_I2C_END = 0
#PI_I2C_ESC = 1
#PI_I2C_START = 2
#PI_I2C_COMBINED_ON = 2
#PI_I2C_STOP = 3
#PI_I2C_COMBINED_OFF =3
#PI_I2C_ADDR = 4
#PI_I2C_FLAGS = 5
#PI_I2C_READ = 6
#PI_I2C_WRITE = 7
;/* SPI */
Macro PI_SPI_FLAGS_BITLEN(x)
((x&63)<<16)
EndMacro
Macro PI_SPI_FLAGS_RX_LSB(x)
((x&1)<<15)
EndMacro
Macro PI_SPI_FLAGS_TX_LSB(x)
((x&1)<<14)
EndMacro
Macro PI_SPI_FLAGS_3WREN(x)
((x&15)<<10)
EndMacro
Macro PI_SPI_FLAGS_3WIRE(x)
((x&1)<<9)
EndMacro
Macro PI_SPI_FLAGS_AUX_SPI(x)
((x&1)<<8)
EndMacro
Macro PI_SPI_FLAGS_RESVD(x)
((x&7)<<5)
EndMacro
Macro PI_SPI_FLAGS_CSPOLS(x)
((x&7)<<2)
EndMacro
Macro PI_SPI_FLAGS_MODE(x)
((x&3))
EndMacro
;/* BSC registers */
#BSC_DR = 0
#BSC_RSR = 1
#BSC_SLV = 2
#BSC_CR = 3
#BSC_FR = 4
#BSC_IFLS = 5
#BSC_IMSC = 6
#BSC_RIS = 7
#BSC_MIS = 8
#BSC_ICR = 9
#BSC_DMACR = 10
#BSC_TDR = 11
#BSC_GPUSTAT = 12
#BSC_HCTRL = 13
#BSC_DEBUG_I2C =14
#BSC_DEBUG_SPI= 15
#BSC_CR_TESTFIFO =2048
#BSC_CR_RXE =512
#BSC_CR_TXE =256
#BSC_CR_BRK =128
#BSC_CR_CPOL = 16
#BSC_CR_CPHA = 8
#BSC_CR_I2C = 4
#BSC_CR_SPI = 2
#BSC_CR_EN = 1
#BSC_FR_RXBUSY =32
#BSC_FR_TXFE = 16
#BSC_FR_RXFF = 8
#BSC_FR_TXFF = 4
#BSC_FR_RXFE = 2
#BSC_FR_TXBUSY = 1
;/* BSC GPIO */
#BSC_SDA = 18
#BSC_MOSI = 20
#BSC_SCL_SCLK =19
#BSC_MISO = 18
#BSC_CE_N = 21
#BSC_SDA_2711 = 10
#BSC_MOSI_2711 = 9
#BSC_SCL_SCLK_2711 =11
#BSC_MISO_2711 = 10
#BSC_CE_N_2711 = 8
;/* Longest busy delay */
#PI_MAX_BUSY_DELAY =100
;/* timeout: 0-60000 */
#PI_MIN_WDOG_TIMEOUT =0
#PI_MAX_WDOG_TIMEOUT =60000
;/* timer: 0-9 */
#PI_MIN_TIMER =0
#PI_MAX_TIMER =9
;/* millis: 10-60000 */
#PI_MIN_MS =10
#PI_MAX_MS =60000
#PI_MAX_SCRIPTS = 32
#PI_MAX_SCRIPT_TAGS = 50
#PI_MAX_SCRIPT_VARS = 150
#PI_MAX_SCRIPT_PARAMS =10
;/* script status */
#PI_SCRIPT_INITING =0
#PI_SCRIPT_HALTED = 1
#PI_SCRIPT_RUNNING= 2
#PI_SCRIPT_WAITING= 3
#PI_SCRIPT_FAILED = 4
;/* signum: 0-63 */
#PI_MIN_SIGNUM =0
#PI_MAX_SIGNUM =63
;/* timetype: 0-1 */
#PI_TIME_RELATIVE =0
#PI_TIME_ABSOLUTE =1
#PI_MAX_MICS_DELAY =1000000 ;/* 1 second */
#PI_MAX_MILS_DELAY =60000 ;/* 60 seconds */
;/* cfgMillis */
#PI_BUF_MILLIS_MIN =100
#PI_BUF_MILLIS_MAX =10000
;/* cfgMicros: 1, 2, 4, 5, 8, Or 10 */
;/* cfgPeripheral: 0-1 */
#PI_CLOCK_PWM =0
#PI_CLOCK_PCM =1
;/* DMA channel: 0-15, 15 is unset */
#PI_MIN_DMA_CHANNEL =0
#PI_MAX_DMA_CHANNEL =15
;/* port */
#PI_MIN_SOCKET_PORT =1024
#PI_MAX_SOCKET_PORT =32000
;/* ifFlags: */
#PI_DISABLE_FIFO_IF = 1
#PI_DISABLE_SOCK_IF = 2
#PI_LOCALHOST_SOCK_IF= 4
#PI_DISABLE_ALERT = 8
;/* memAllocMode */
#PI_MEM_ALLOC_AUTO = 0
#PI_MEM_ALLOC_PAGEMAP= 1
#PI_MEM_ALLOC_MAILBOX= 2
;/* filters */
#PI_MAX_STEADY = 300000
#PI_MAX_ACTIVE =1000000
;/* gpioCfgInternals */
#PI_CFG_DBG_LEVEL=0; 0 /* bits 0-3 */
#PI_CFG_ALERT_FREQ =4; 4 /* bits 4-7 */
#PI_CFG_RT_PRIORITY = (1<<8)
#PI_CFG_STATS = (1<<9)
#PI_CFG_NOSIGHANDLER = (1<<10)
#PI_CFG_ILLEGAL_VAL = (1<<11)
;/* gpioISR */
#RISING_EDGE = 0
#FALLING_EDGE= 1
#EITHER_EDGE = 2
;/* pads */
#PI_MAX_PAD =2
#PI_MIN_PAD_STRENGTH =1
#PI_MAX_PAD_STRENGTH =16
;/* files */
#PI_FILE_NONE = 0
#PI_FILE_MIN = 1
#PI_FILE_READ = 1
#PI_FILE_WRITE= 2
#PI_FILE_RW = 3
#PI_FILE_APPEND= 4
#PI_FILE_CREATE= 8
#PI_FILE_TRUNC = 16
#PI_FILE_MAX = 31
#PI_FROM_START = 0
#PI_FROM_CURRENT= 1
#PI_FROM_END = 2
;/* Allowed socket connect addresses */
#MAX_CONNECT_ADDRESSES =256
;/* events */
#PI_MAX_EVENT =31
;/* Event auto generated on BSC slave activity */
#PI_EVENT_BSC= 31
;/*DEF_S Socket Command Codes*/
#PI_CMD_MODES = 0
#PI_CMD_MODEG = 1
#PI_CMD_PUD = 2
#PI_CMD_READ = 3
#PI_CMD_WRITE= 4
#PI_CMD_PWM = 5
#PI_CMD_PRS = 6
#PI_CMD_PFS = 7
#PI_CMD_SERVO= 8
#PI_CMD_WDOG = 9
#PI_CMD_BR1 = 10
#PI_CMD_BR2 = 11
#PI_CMD_BC1 = 12
#PI_CMD_BC2 = 13
#PI_CMD_BS1 = 14
#PI_CMD_BS2 = 15
#PI_CMD_TICK = 16
#PI_CMD_HWVER =17
#PI_CMD_NO = 18
#PI_CMD_NB = 19
#PI_CMD_NP = 20
#PI_CMD_NC = 21
#PI_CMD_PRG = 22
#PI_CMD_PFG = 23
#PI_CMD_PRRG = 24
#PI_CMD_HELP = 25
#PI_CMD_PIGPV= 26
#PI_CMD_WVCLR= 27
#PI_CMD_WVAG = 28
#PI_CMD_WVAS = 29
#PI_CMD_WVGO = 30
#PI_CMD_WVGOR= 31
#PI_CMD_WVBSY= 32
#PI_CMD_WVHLT= 33
#PI_CMD_WVSM = 34
#PI_CMD_WVSP = 35
#PI_CMD_WVSC = 36
#PI_CMD_TRIG = 37
#PI_CMD_PROC = 38
#PI_CMD_PROCD= 39
#PI_CMD_PROCR= 40
#PI_CMD_PROCS= 41
#PI_CMD_SLRO = 42
#PI_CMD_SLR = 43
#PI_CMD_SLRC = 44
#PI_CMD_PROCP= 45
#PI_CMD_MICS = 46
#PI_CMD_MILS = 47
#PI_CMD_PARSE= 48
#PI_CMD_WVCRE= 49
#PI_CMD_WVDEL= 50
#PI_CMD_WVTX = 51
#PI_CMD_WVTXR= 52
#PI_CMD_WVNEW= 53
#PI_CMD_I2CO= 54
#PI_CMD_I2CC= 55
#PI_CMD_I2CRD= 56
#PI_CMD_I2CWD= 57
#PI_CMD_I2CWQ= 58
#PI_CMD_I2CRS= 59
#PI_CMD_I2CWS= 60
#PI_CMD_I2CRB= 61
#PI_CMD_I2CWB= 62
#PI_CMD_I2CRW= 63
#PI_CMD_I2CWW= 64
#PI_CMD_I2CRK= 65
#PI_CMD_I2CWK= 66
#PI_CMD_I2CRI= 67
#PI_CMD_I2CWI= 68
#PI_CMD_I2CPC= 69
#PI_CMD_I2CPK= 70
#PI_CMD_SPIO = 71
#PI_CMD_SPIC = 72
#PI_CMD_SPIR = 73
#PI_CMD_SPIW = 74
#PI_CMD_SPIX = 75
#PI_CMD_SERO = 76
#PI_CMD_SERC = 77
#PI_CMD_SERRB= 78
#PI_CMD_SERWB= 79
#PI_CMD_SERR = 80
#PI_CMD_SERW = 81
#PI_CMD_SERDA= 82
#PI_CMD_GDC = 83
#PI_CMD_GPW = 84
#PI_CMD_HC = 85
#PI_CMD_HP = 86
#PI_CMD_CF1 = 87
#PI_CMD_CF2 = 88
#PI_CMD_BI2CC =89
#PI_CMD_BI2CO =90
#PI_CMD_BI2CZ =91
#PI_CMD_I2CZ = 92
#PI_CMD_WVCHA =93
#PI_CMD_SLRI = 94
#PI_CMD_CGI = 95
#PI_CMD_CSI = 96
#PI_CMD_FG = 97
#PI_CMD_FN = 98
#PI_CMD_NOIB = 99
#PI_CMD_WVTXM =100
#PI_CMD_WVTAT =101
#PI_CMD_PADS = 102
#PI_CMD_PADG = 103
#PI_CMD_FO = 104
#PI_CMD_FC = 105
#PI_CMD_FR = 106
#PI_CMD_FW = 107
#PI_CMD_FS = 108
#PI_CMD_FL = 109
#PI_CMD_SHELL =110
#PI_CMD_BSPIC =111
#PI_CMD_BSPIO =112
#PI_CMD_BSPIX =113
#PI_CMD_BSCX =114
#PI_CMD_EVM =115
#PI_CMD_EVT = 116
#PI_CMD_PROCU =117
#PI_CMD_WVCAP =118
;/*DEF_E*/
;/* pseudo commands */
#PI_CMD_SCRIPT =800
#PI_CMD_ADD = 800
#PI_CMD_AND = 801
#PI_CMD_CALL = 802
#PI_CMD_CMDR = 803
#PI_CMD_CMDW = 804
#PI_CMD_CMP = 805
#PI_CMD_DCR = 806
#PI_CMD_DCRA = 807
#PI_CMD_DIV = 808
#PI_CMD_HALT = 809
#PI_CMD_INR = 810
#PI_CMD_INRA = 811
#PI_CMD_JM = 812
#PI_CMD_JMP = 813
#PI_CMD_JNZ = 814
#PI_CMD_JP = 815
#PI_CMD_JZ = 816
#PI_CMD_TAG = 817
#PI_CMD_LD = 818
#PI_CMD_LDA = 819
#PI_CMD_LDAB = 820
#PI_CMD_MLT = 821
#PI_CMD_MOD = 822
#PI_CMD_NOP = 823
#PI_CMD_OR = 824
#PI_CMD_POP = 825
#PI_CMD_POPA = 826
#PI_CMD_PUSH = 827
#PI_CMD_PUSHA= 828
#PI_CMD_RET = 829
#PI_CMD_RL = 830
#PI_CMD_RLA = 831
#PI_CMD_RR = 832
#PI_CMD_RRA = 833
#PI_CMD_STA = 834
#PI_CMD_STAB = 835
#PI_CMD_SUB = 836
#PI_CMD_SYS = 837
#PI_CMD_WAIT = 838
#PI_CMD_X = 839
#PI_CMD_XA = 840
#PI_CMD_XOR = 841
#PI_CMD_EVTWT= 842
;/*DEF_S Error Codes*/
#PI_INIT_FAILED = -1 ; gpioInitialise failed
#PI_BAD_USER_GPIO = -2 ; GPIO Not 0-31
#PI_BAD_GPIO = -3 ; GPIO Not 0-53
#PI_BAD_MODE = -4 ; mode Not 0-7
#PI_BAD_LEVEL = -5 ; level Not 0-1
#PI_BAD_PUD = -6 ; pud Not 0-2
#PI_BAD_PULSEWIDTH = -7 ; pulsewidth Not 0 Or 500-2500
#PI_BAD_DUTYCYCLE = -8 ; dutycycle outside set range
#PI_BAD_TIMER = -9 ; timer Not 0-9
#PI_BAD_MS = -10 ; ms Not 10-60000
#PI_BAD_TIMETYPE = -11 ; timetype Not 0-1
#PI_BAD_SECONDS = -12 ; seconds < 0
#PI_BAD_MICROS = -13 ; micros Not 0-999999
#PI_TIMER_FAILED = -14 ; gpioSetTimerFunc failed
#PI_BAD_WDOG_TIMEOUT= -15 ; timeout Not 0-60000
#PI_NO_ALERT_FUNC = -16 ; DEPRECATED
#PI_BAD_CLK_PERIPH= -17 ; clock peripheral Not 0-1
#PI_BAD_CLK_SOURCE= -18 ; DEPRECATED
#PI_BAD_CLK_MICROS= -19 ; clock micros Not 1, 2, 4, 5, 8, Or 10
#PI_BAD_BUF_MILLIS= -20 ; buf millis Not 100-10000
#PI_BAD_DUTYRANGE = -21 ; dutycycle range Not 25-40000
#PI_BAD_DUTY_RANGE= -21 ; DEPRECATED (use PI_BAD_DUTYRANGE)
#PI_BAD_SIGNUM = -22 ; signum Not 0-63
#PI_BAD_PATHNAME= -23 ; can't open pathname
#PI_NO_HANDLE = -24 ; no handle available
#PI_BAD_HANDLE = -25 ; unknown handle
#PI_BAD_IF_FLAGS = -26 ; ifFlags > 4
#PI_BAD_CHANNEL = -27 ; DMA channel Not 0-15
#PI_BAD_PRIM_CHANNEL =-27 ; DMA primary channel Not 0-15
#PI_BAD_SOCKET_PORT = -28 ; socket port Not 1024-32000
#PI_BAD_FIFO_COMMAND =-29 ; unrecognized fifo command
#PI_BAD_SECO_CHANNEL= -30 ; DMA secondary channel Not 0-15
#PI_NOT_INITIALISED = -31 ; function called before gpioInitialise
#PI_INITIALISED = -32 ; function called after gpioInitialise
#PI_BAD_WAVE_MODE = -33 ; waveform mode Not 0-3
#PI_BAD_CFG_INTERNAL =-34 ; bad parameter in gpioCfgInternals call
#PI_BAD_WAVE_BAUD = -35 ; baud rate Not 50-250K(RX)/50-1M(TX)
#PI_TOO_MANY_PULSES = -36 ; waveform has too many pulses
#PI_TOO_MANY_CHARS = -37 ; waveform has too many chars
#PI_NOT_SERIAL_GPIO = -38 ; no bit bang serial Read on GPIO
#PI_BAD_SERIAL_STRUC= -39 ; bad (null) serial Structure parameter
#PI_BAD_SERIAL_BUF = -40 ; bad (null) serial buf parameter
#PI_NOT_PERMITTED = -41 ; GPIO operation Not permitted
#PI_SOME_PERMITTED = -42 ; one Or more GPIO Not permitted
#PI_BAD_WVSC_COMMND = -43 ; bad WVSC subcommand
#PI_BAD_WVSM_COMMND = -44 ; bad WVSM subcommand
#PI_BAD_WVSP_COMMND = -45 ; bad WVSP subcommand
#PI_BAD_PULSELEN = -46 ; trigger pulse length Not 1-100
#PI_BAD_SCRIPT = -47 ; invalid script
#PI_BAD_SCRIPT_ID = -48 ; unknown script id
#PI_BAD_SER_OFFSET = -49 ; add serial Data offset > 30 minutes
#PI_GPIO_IN_USE = -50 ; GPIO already in use
#PI_BAD_SERIAL_COUNT= -51 ; must Read at least a byte at a time
#PI_BAD_PARAM_NUM = -52 ; script parameter id Not 0-9
#PI_DUP_TAG = -53 ; script has duplicate tag
#PI_TOO_MANY_TAGS = -54 ; script has too many tags
#PI_BAD_SCRIPT_CMD = -55 ; illegal script command
#PI_BAD_VAR_NUM = -56 ; script variable id Not 0-149
#PI_NO_SCRIPT_ROOM = -57 ; no more room For scripts
#PI_NO_MEMORY = -58 ; can't allocate temporary memory
#PI_SOCK_READ_FAILED= -59 ; socket Read failed
#PI_SOCK_WRIT_FAILED= -60 ; socket write failed
#PI_TOO_MANY_PARAM = -61 ; too many script parameters (> 10)
#PI_NOT_HALTED = -62 ; DEPRECATED
#PI_SCRIPT_NOT_READY= -62 ; script initialising
#PI_BAD_TAG = -63 ; script has unresolved tag
#PI_BAD_MICS_DELAY = -64 ; bad MICS Delay (too large)
#PI_BAD_MILS_DELAY = -65 ; bad MILS Delay (too large)
#PI_BAD_WAVE_ID = -66 ; non existent wave id
#PI_TOO_MANY_CBS = -67 ; No more CBs For waveform
#PI_TOO_MANY_OOL = -68 ; No more OOL For waveform
#PI_EMPTY_WAVEFORM = -69 ; attempt To create an empty waveform
#PI_NO_WAVEFORM_ID = -70 ; no more waveforms
#PI_I2C_OPEN_FAILED = -71 ; can't open I2C device
#PI_SER_OPEN_FAILED = -72 ; can't open serial device
#PI_SPI_OPEN_FAILED = -73 ; can't open SPI device
#PI_BAD_I2C_BUS = -74 ; bad I2C bus
#PI_BAD_I2C_ADDR = -75 ; bad I2C address
#PI_BAD_SPI_CHANNEL = -76 ; bad SPI channel
#PI_BAD_FLAGS = -77 ; bad i2c/spi/ser open flags
#PI_BAD_SPI_SPEED = -78 ; bad SPI speed
#PI_BAD_SER_DEVICE = -79 ; bad serial device name
#PI_BAD_SER_SPEED = -80 ; bad serial baud rate
#PI_BAD_PARAM = -81 ; bad i2c/spi/ser parameter
#PI_I2C_WRITE_FAILED= -82 ; i2c write failed
#PI_I2C_READ_FAILED = -83 ; i2c Read failed
#PI_BAD_SPI_COUNT = -84 ; bad SPI count
#PI_SER_WRITE_FAILED= -85 ; ser write failed
#PI_SER_READ_FAILED = -86 ; ser Read failed
#PI_SER_READ_NO_DATA= -87 ; ser Read no Data available
#PI_UNKNOWN_COMMAND = -88 ; unknown command
#PI_SPI_XFER_FAILED = -89 ; spi xfer/Read/write failed
#PI_BAD_POINTER = -90 ; bad (NULL) pointer
#PI_NO_AUX_SPI = -91 ; no auxiliary SPI on Pi A Or B
#PI_NOT_PWM_GPIO = -92 ; GPIO is Not in use For PWM
#PI_NOT_SERVO_GPIO = -93 ; GPIO is Not in use For servo pulses
#PI_NOT_HCLK_GPIO = -94 ; GPIO has no hardware clock
#PI_NOT_HPWM_GPIO = -95 ; GPIO has no hardware PWM
#PI_BAD_HPWM_FREQ = -96 ; invalid hardware PWM frequency
#PI_BAD_HPWM_DUTY = -97 ; hardware PWM dutycycle Not 0-1M
#PI_BAD_HCLK_FREQ = -98 ; invalid hardware clock frequency
#PI_BAD_HCLK_PASS = -99 ; need password To use hardware clock 1
#PI_HPWM_ILLEGAL =-100 ; illegal, PWM in use For main clock
#PI_BAD_DATABITS =-101 ; serial Data bits Not 1-32
#PI_BAD_STOPBITS =-102 ; serial (half) stop bits Not 2-8
#PI_MSG_TOOBIG =-103 ; socket/pipe message too big
#PI_BAD_MALLOC_MODE =-104 ; bad memory allocation mode
#PI_TOO_MANY_SEGS =-105 ; too many I2C transaction segments
#PI_BAD_I2C_SEG =-106 ; an I2C transaction segment failed
#PI_BAD_SMBUS_CMD =-107 ; SMBus command Not supported by driver
#PI_NOT_I2C_GPIO =-108 ; no bit bang I2C in progress on GPIO
#PI_BAD_I2C_WLEN =-109 ; bad I2C write length
#PI_BAD_I2C_RLEN =-110 ; bad I2C Read length
#PI_BAD_I2C_CMD =-111 ; bad I2C command
#PI_BAD_I2C_BAUD =-112 ; bad I2C baud rate, Not 50-500k
#PI_CHAIN_LOOP_CNT =-113 ; bad chain loop count
#PI_BAD_CHAIN_LOOP =-114 ; empty chain loop
#PI_CHAIN_COUNTER =-115 ; too many chain counters
#PI_BAD_CHAIN_CMD =-116 ; bad chain command
#PI_BAD_CHAIN_DELAY =-117 ; bad chain delay micros
#PI_CHAIN_NESTING =-118 ; chain counters nested too deeply
#PI_CHAIN_TOO_BIG =-119 ; chain is too long
#PI_DEPRECATED =-120 ; deprecated function removed
#PI_BAD_SER_INVERT =-121 ; bit bang serial invert Not 0 Or 1
#PI_BAD_EDGE =-122 ; bad ISR edge value, Not 0-2
#PI_BAD_ISR_INIT =-123 ; bad ISR initialisation
#PI_BAD_FOREVER =-124 ; loop ForEver must be last command
#PI_BAD_FILTER =-125 ; bad filter parameter
#PI_BAD_PAD =-126 ; bad pad number
#PI_BAD_STRENGTH =-127 ; bad pad drive strength
#PI_FIL_OPEN_FAILED =-128 ; file open failed
#PI_BAD_FILE_MODE =-129 ; bad file mode
#PI_BAD_FILE_FLAG =-130 ; bad file flag
#PI_BAD_FILE_READ =-131 ; bad file Read
#PI_BAD_FILE_WRITE =-132 ; bad file write
#PI_FILE_NOT_ROPEN =-133 ; file Not open For Read
#PI_FILE_NOT_WOPEN =-134 ; file Not open For write
#PI_BAD_FILE_SEEK =-135 ; bad file seek
#PI_NO_FILE_MATCH =-136 ; no files match pattern
#PI_NO_FILE_ACCESS =-137 ; no permission To access file
#PI_FILE_IS_A_DIR =-138 ; file is a directory
#PI_BAD_SHELL_STATUS= -139 ; bad shell Return status
#PI_BAD_SCRIPT_NAME =-140 ; bad script name
#PI_BAD_SPI_BAUD =-141 ; bad SPI baud rate, Not 50-500k
#PI_NOT_SPI_GPIO =-142 ; no bit bang SPI in progress on GPIO
#PI_BAD_EVENT_ID =-143 ; bad event id
#PI_CMD_INTERRUPTED =-144 ; Used by Python
#PI_NOT_ON_BCM2711 =-145 ; Not available on BCM2711
#PI_ONLY_ON_BCM2711 =-146 ; only available on BCM2711
#PI_PIGIF_ERR_0 = -2000
#PI_PIGIF_ERR_99 = -2099
#PI_CUSTOM_ERR_0 = -3000
#PI_CUSTOM_ERR_999= -3999
;/*DEF_E*/
;/*DEF_S Defaults*/
#PI_DEFAULT_BUFFER_MILLIS = 120
#PI_DEFAULT_CLK_MICROS = 5
#PI_DEFAULT_CLK_PERIPHERAL = #PI_CLOCK_PCM
#PI_DEFAULT_IF_FLAGS = 0
#PI_DEFAULT_FOREGROUND = 0
#PI_DEFAULT_DMA_CHANNEL = 14
#PI_DEFAULT_DMA_PRIMARY_CHANNEL = 14
#PI_DEFAULT_DMA_SECONDARY_CHANNEL= 6
#PI_DEFAULT_DMA_PRIMARY_CH_2711 = 7
#PI_DEFAULT_DMA_SECONDARY_CH_2711= 6
#PI_DEFAULT_DMA_NOT_SET = 15
#PI_DEFAULT_SOCKET_PORT = 8888
*PI_DEFAULT_SOCKET_PORT_STR = UTF8("8888")
*PI_DEFAULT_SOCKET_ADDR_STR = UTF8("localhost")
#PI_DEFAULT_UPDATE_MASK_UNKNOWN = $0000000FFFFFF
#PI_DEFAULT_UPDATE_MASK_B1 = $03E7CF93
#PI_DEFAULT_UPDATE_MASK_A_B2 = $FBC7CF9C
#PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS= $0080480FFFFFF
#PI_DEFAULT_UPDATE_MASK_ZERO = $80000FFFFFF
#PI_DEFAULT_UPDATE_MASK_PI2B = $0080480FFFFFF
#PI_DEFAULT_UPDATE_MASK_PI3B = $0000000FFFFFF
#PI_DEFAULT_UPDATE_MASK_PI4B = $0000000FFFFFF
#PI_DEFAULT_UPDATE_MASK_COMPUTE = $00FFFFFFFFFFFF
#PI_DEFAULT_MEM_ALLOC_MODE = #PI_MEM_ALLOC_AUTO
#PI_DEFAULT_CFG_INTERNALS = 0
CompilerIf #PB_Compiler_IsMainFile
#GPIO = 25
Procedure CHECK(t,st,got,expect,pc,*desc)
If got = expect
PrintN("TEST " + Str(t) + ":" + Str(st) + " " + PeekS(*desc) + " expect " + Str(expect));
Else
PrintN("TEST " + Str(t) + ":" + Str(st) + " FAILED got " + Str(got) + " " + PeekS(*desc) + " " + Str(expect));
EndIf
EndProcedure
Procedure t0(pi)
PrintN("Testing pigpiod");
PrintN("pigpio version :" + Str(get_pigpio_version(pi)));
PrintN("Hardware revision :" + Str(get_hardware_revision(pi)));
EndProcedure
Procedure t1(pi)
Protected v;
PrintN("Mode/PUD/read/write tests");
set_mode(pi, GPIO, #PI_INPUT);
v = get_mode(pi, GPIO) ;
CHECK(1, 1, v, 0, 0, @"set mode, get mode");
set_pull_up_down(pi, GPIO, #PI_PUD_UP);
v = gpio_read(pi, GPIO) ;
CHECK(1, 2, v, 1, 0, @"set pull up down, read");
set_pull_up_down(pi, GPIO, #PI_PUD_DOWN);
v = gpio_read(pi, GPIO) ;
CHECK(1, 3, v, 0, 0, @"set pull up down, read");
gpio_write(pi, GPIO, #PI_LOW);
v = get_mode(pi, GPIO) ;
CHECK(1, 4, v, 1, 0, @"write, get mode");
v = gpio_read(pi, GPIO);
CHECK(1, 5, v, 0, 0, @"read");
gpio_write(pi, GPIO, #PI_HIGH);
v = gpio_read(pi, GPIO) ;
CHECK(1, 6, v, 1, 0, @"write, read");
pigpio_stop(v)
v = pigpio_start(*PI_DEFAULT_SOCKET_ADDR_STR,*PI_DEFAULT_SOCKET_PORT_STR);
CHECK(1, 7, v, 31, 100, @"pigpio_start with non-default arguments") ;
;
EndProcedure
pi = pigpio_start(0, 0)
If pi = 0
t0(pi)
t1(pi)
pigpio_stop(pi)
EndIf
CompilerEndIf
sudo pigpiod
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
hey guys, loving all the info - its been really helpful so far. I've been able to build console exes that run on a cut down dietpi.
I originally used @User_Russian's example of writing to the GPIO pins, but have found this to be far too slow for my needs and started to look at hitting the memory IO space but have come back today to see @infrantec's pigpio method. Basically I am trying to create a parallel coms with GPIO to talk to the Spectrum Next pi0 - its working so far just slow (like maybe twice as fast a regular loading from tape )
How would I start to move this very simple example to use the pigpio lib?
Ok, venturing forward very carefully (as we cant have GPIO pins active both ways of kaboom), now just to adapt I think.
I originally used @User_Russian's example of writing to the GPIO pins, but have found this to be far too slow for my needs and started to look at hitting the memory IO space but have come back today to see @infrantec's pigpio method. Basically I am trying to create a parallel coms with GPIO to talk to the Spectrum Next pi0 - its working so far just slow (like maybe twice as fast a regular loading from tape )
How would I start to move this very simple example to use the pigpio lib?
Ok, venturing forward very carefully (as we cant have GPIO pins active both ways of kaboom), now just to adapt I think.
Code: Select all
;
; original GPIO module from User_Russian
; [url=http://purebasic.mybb.ru/viewtopic.php?id=885]Модуль GPIO для Raspberry PI[/url]
DeclareModule GPIO
Enumeration
#DirIN
#DirOUT
EndEnumeration
Declare Export(Pin)
Declare Unexport(Pin)
Declare Direction(Pin, Dir)
Declare ReadPin(Pin)
Declare WritePin(Pin, Value)
EndDeclareModule
Module GPIO
EnableExplicit
Procedure Export(Pin)
Protected Res = #False, id
id = OpenFile(#PB_Any, "/sys/class/gpio/export")
If id
Res = Bool(WriteString(id, Str(Pin), #PB_Ascii))
CloseFile(id)
EndIf
ProcedureReturn Res
EndProcedure
Procedure Unexport(Pin)
Protected Res = #False, id
id = OpenFile(#PB_Any, "/sys/class/gpio/unexport")
If id
Res = Bool(WriteString(id, Str(Pin), #PB_Ascii))
CloseFile(id)
EndIf
ProcedureReturn Res
EndProcedure
Procedure Direction(Pin, Dir)
Protected Res = #False, id
id = OpenFile(#PB_Any, "/sys/class/gpio/gpio"+Pin+"/direction")
If id
If Dir = #DirIN
Res = Bool(WriteString(id, "in", #PB_Ascii))
ElseIf Dir = #DirOUT
Res = Bool(WriteString(id, "out", #PB_Ascii))
EndIf
CloseFile(id)
EndIf
ProcedureReturn Res
EndProcedure
Procedure ReadPin(Pin)
Protected Res = -1, id, x.l=0
id = ReadFile(#PB_Any, "/sys/class/gpio/gpio"+Pin+"/value")
If id
If ReadData(id, @x, 3)>0
Res = Val(PeekS(@x, -1, #PB_Ascii))
EndIf
CloseFile(id)
EndIf
ProcedureReturn Res
EndProcedure
Procedure WritePin(Pin, Value)
Protected Res = #False, id
id = OpenFile(#PB_Any, "/sys/class/gpio/gpio"+Pin+"/value")
If id
Res = Bool(WriteString(id, Str(Bool(Value)), #PB_Ascii))
CloseFile(id)
EndIf
ProcedureReturn Res
EndProcedure
EndModule
UseModule GPIO
; this GPIO will be for 8 bits of data
Export(4)
Export(5)
Export(6)
Export(7)
Export(8)
Export(9)
Export(10)
Export(11)
;
Export(24) ; next ready (RTS)
#PinReady = 24
Export(25) ; all sent pi (CTS)
#PinDone = 25
;
Direction(4, #DirOUT)
Direction(5, #DirOUT)
Direction(6, #DirOUT)
Direction(7, #DirOUT)
Direction(8, #DirOUT)
Direction(9, #DirOUT)
Direction(10, #DirOUT)
Direction(11, #DirOUT)
;
Direction(24, #DirIn)
Direction(25, #DirOut)
;
OpenConsole("")
Delay(800) ; Wait a small amount of time before kicking in
WritePin(25,0)
; load a spectrum screenshot to memory
If ReadFile(0,"AticAtac.scr")
*buffer = AllocateMemory(6912)
ReadData(0,*buffer,6912)
CloseFile(0)
Else
PrintN("Error opening file")
End
EndIf
;
; early test
; a$ = "HELLO WORLD ++ "
; tot = Len(a$)
; o = 1
mlen = 6912
offset = 0
time = ElapsedMilliseconds()
Repeat
If ReadPin(#PinReady) = 1 ; is the next ready to receive?
WritePin(#PinDone,0) ; reset done pin
c = 0
; get a byte from memory
a = PeekB(*buffer+offset)
; walk through bits and sent to relevant GPIO
For i=4 To 11
t = a>>c & 1
; PrintN("Write on GPIO "+ Str(i) + " "+ Str(t)+ " ")
; Remove to try and gain more speed
WritePin(i, t)
c+1
Next
offset + 1
WritePin(#PinDone,1) ; write done pin
While ReadPin(#PinReady) = 0
; WritePin(#PinDone,1) ; write done pin
Delay(1)
PrintN("waiting for next OK")
Wend
If offset = mlen
e = (ElapsedMilliseconds()-time) / 60
PrintN("Time " + Str(e) )
FreeMemory(*buffer)
End
; o=1
EndIf
Else
PrintN("waiting for next ready pin")
EndIf
Delay(1)
ForEver
----
R Tape loading error, 0:1
R Tape loading error, 0:1
Re: Serial Ports, IO-Ports, I2C and the use of PIGPIO Library
with pigpoid you can just read the whole bank
Code: Select all
;makes sure pigpoid is started with
;sudo pigpiod
;Read the levels of the bank 1 GPIO (GPIO 0-31).
;pi: >=0 (As returned by [*pigpio_start*]).
;The returned 32 bit integer has a bit set If the corresponding
;GPIO is logic 1. GPIO n has bit value (1<<n).
XIncludeFile "pigpoidf2.pbi"
pi = pigpio_start(0, 0)
If pi >= 0
int32 = read_bank_1(pi);
endif
pigpio_stop(pi)