Class Setup
Library setup and configuration methods.
Inherited Members
Namespace: Unosquare.PiGpio.NativeMethods
Syntax
public static class Setup
Methods
GpioCfgBufferSize(UInt32)
Configures pigpio to buffer cfgMillis milliseconds of GPIO samples.
This function is only effective if called before GpioInitialise().
The default setting is 120 milliseconds.
The intention is to allow for bursts of data and protection against other processes hogging cpu time.
I haven't seen a process locked out for more than 100 milliseconds.
Making the buffer bigger uses a LOT of memory at the more frequent sampling rates as shown in the following table in MBs.
Declaration
public static ResultCode GpioCfgBufferSize(uint milliSecs)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | milliSecs | 100-10000. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
Remarks
buffer milliseconds
120 250 500 1sec 2sec 4sec 8sec
1 16 31 55 107 --- --- ---
2 10 18 31 55 107 --- ---
sample 4 8 12 18 31 55 107 --- rate 5 8 10 14 24 45 87 --- (us) 8 6 8 12 18 31 55 107 10 6 8 10 14 24 45 87.
GpioCfgClock(UInt32, CpuPeripheral)
Configures pigpio to use a particular sample rate timed by a specified peripheral.
This function is only effective if called before GpioInitialise().
The timings are provided by the specified peripheral (PWM or PCM).
The default setting is 5 microseconds using the PCM peripheral.
The approximate CPU percentage used for each sample rate is:
A sample rate of 5 microseconds seeems to be the sweet spot.
Declaration
public static ResultCode GpioCfgClock(uint microSecs, CpuPeripheral peripheral)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | microSecs | 1, 2, 4, 5, 8, 10. |
CpuPeripheral | peripheral | 0 (PWM), 1 (PCM). |
Returns
Type | Description |
---|---|
ResultCode | The result code. |
Remarks
sample cpu rate %
1 25 2 16 4 11 5 10 8 15 10 14.
GpioCfgDmaChannel(DmaChannel)
Configures pigpio to use the specified DMA channel. This function is only effective if called before GpioInitialise(). The default setting is to use channel 14.
Declaration
[Obsolete]
public static ResultCode GpioCfgDmaChannel(DmaChannel dmaChannel)
Parameters
Type | Name | Description |
---|---|---|
DmaChannel | dmaChannel | The DMA channel. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
Remarks
DMAchannel: 0-14.
GpioCfgDmaChannels(DmaChannel, DmaChannel)
Configures pigpio to use the specified DMA channels.
This function is only effective if called before GpioInitialise().
The default setting is to use channel 14 for the primary channel and channel 6 for the secondary channel.
The secondary channel is only used for the transmission of waves.
If possible use one of channels 0 to 6 for the secondary channel (a full channel).
A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel.
Declaration
public static ResultCode GpioCfgDmaChannels(DmaChannel primaryChannel, DmaChannel secondaryChannel)
Parameters
Type | Name | Description |
---|---|---|
DmaChannel | primaryChannel | Channel 1: 0-14. |
DmaChannel | secondaryChannel | Channel 2: 0-14. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgGetInternals()
This function returns the current library internal configuration settings.
Declaration
public static ConfigFlags GpioCfgGetInternals()
Returns
Type | Description |
---|---|
ConfigFlags | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgInterfaces(InterfaceFlags)
Configures pigpio support of the fifo and socket interfaces.
This function is only effective if called before GpioInitialise().
The default setting (0) is that both interfaces are enabled.
Or in PI_DISABLE_FIFO_IF to disable the pipe interface.
Or in PI_DISABLE_SOCK_IF to disable the socket interface.
Or in PI_LOCALHOST_SOCK_IF to disable remote socket access (this means that the socket interface is only usable from the local Pi).
Declaration
public static ResultCode GpioCfgInterfaces(InterfaceFlags interfaceFlags)
Parameters
Type | Name | Description |
---|---|---|
InterfaceFlags | interfaceFlags | 0-7. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgInternals(UInt32, UInt32)
Used to tune internal settings.
Declaration
[Obsolete]
public static ResultCode GpioCfgInternals(uint key, uint value)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | key | Key: see source code. |
UInt32 | value | Value: see source code. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgMemAlloc(AllocationMode)
Selects the method of DMA memory allocation.
This function is only effective if called before GpioInitialise().
There are two methods of DMA memory allocation. The original method uses the /proc/self/pagemap file to allocate bus memory. The new method uses the mailbox property interface to allocate bus memory.
Auto will use the mailbox method unless a larger than default buffer size is requested with GpioCfgBufferSize(UInt32).
Declaration
public static ResultCode GpioCfgMemAlloc(AllocationMode allocationMode)
Parameters
Type | Name | Description |
---|---|---|
AllocationMode | allocationMode | 0-2. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgNetAddr(UInt32[])
Sets the network addresses which are allowed to talk over the socket interface.
This function is only effective if called before GpioInitialise().
Declaration
public static ResultCode GpioCfgNetAddr(uint[] socketAddresses)
Parameters
Type | Name | Description |
---|---|---|
UInt32[] | socketAddresses | an array of permitted network addresses. An empty array means ALL. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgPermissions(UInt64)
Configures pigpio to restrict GPIO updates via the socket or pipe interfaces to the GPIO specified by the mask. Programs directly calling the pigpio library (i.e. linked with -lpigpio are not affected). A GPIO update is a write to a GPIO or a GPIO mode change or any function which would force such an action.
This function is only effective if called before GpioInitialise().
The default setting depends upon the Pi model. The user GPIO are added to the mask.
If the board revision is not recognised then GPIO 2-27 are allowed.
Unknown board @ PI_DEFAULT_UPDATE_MASK_UNKNOWN @ 0x0FFFFFFC Type 1 board @ PI_DEFAULT_UPDATE_MASK_B1 @ 0x03E6CF93 Type 2 board @ PI_DEFAULT_UPDATE_MASK_A_B2 @ 0xFBC6CF9C Type 3 board @ PI_DEFAULT_UPDATE_MASK_R3 @ 0x0FFFFFFC.
Declaration
public static ResultCode GpioCfgPermissions(ulong updateMask)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | updateMask | bit (1<<n) is set for each GPIO n which may be updated. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgSetInternals(ConfigFlags)
This function sets the current library internal configuration settings.
Declaration
public static ResultCode GpioCfgSetInternals(ConfigFlags configFlags)
Parameters
Type | Name | Description |
---|---|---|
ConfigFlags | configFlags | see source code. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioCfgSocketPort(UInt32)
Configures pigpio to use the specified socket port.
This function is only effective if called before GpioInitialise().
The default setting is to use port 8888.
Declaration
public static ResultCode GpioCfgSocketPort(uint port)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | port | 1024-32000. |
Returns
Type | Description |
---|---|
ResultCode | The result code. 0 for success. See the ResultCode enumeration. |
GpioInitialise()
Initialises the library.
gpioInitialise must be called before using the other library functions with the following exceptions:.
Declaration
public static ResultCode GpioInitialise()
Returns
Type | Description |
---|---|
ResultCode | Returns the pigpio version number if OK, otherwise PI_INIT_FAILED. |
Remarks
GpioCfg methods. GpioVersion() GpioHardwareRevision().
Examples
if (gpioInitialise() < 0)
{
// pigpio initialisation failed.
}
else
{
// pigpio initialised okay.
}
GpioTerminate()
Terminates the library.
Returns nothing.
Call before program exit.
This function resets the used DMA channels, releases memory, and terminates any running threads.
Declaration
public static void GpioTerminate()
Examples
gpioTerminate();