CrossGuard
Loading...
Searching...
No Matches
Functions | Variables
pigpio_stub.cpp File Reference

Implementation of the stub functions for the pigpio library. This stub is used for environments not running Linux on ARM hardware. Created by Saleem Hamo on 20/03/2024. More...

#include "pigpio_stub.h"
#include "utils/Logger.h"
#include <map>
#include <functional>
#include <vector>
#include <string>

Functions

int gpioInitialise ()
 Initialize the GPIO simulation.
 
void gpioTerminate ()
 Terminate the GPIO simulation.
 
void gpioSetMode (unsigned pin, unsigned mode)
 Set the mode of a GPIO pin.
 
void gpioWrite (unsigned pin, unsigned level)
 Write a level to a GPIO pin.
 
int gpioRead (unsigned pin)
 Read the level of a GPIO pin.
 
void gpioDelay (unsigned micros)
 Simulate a delay in microseconds.
 
unsigned gpioTick ()
 Get the current value of the simulated tick counter.
 
int gpioSetAlertFuncEx (unsigned pin, void(*func)(int, int, unsigned, void *), void *user)
 Set a callback function for GPIO pin alert events.
 
void simulateCallback (unsigned pin, int level, unsigned tick)
 Simulate a callback function call for a specific GPIO pin.
 

Variables

const int PI_OUTPUT = 1
 Output mode for GPIO pin.
 
const int PI_INPUT = 0
 Input mode for GPIO pin.
 
const int PI_HIGH = 1
 High level for GPIO pin state.
 
const int PI_LOW = 0
 Low level for GPIO pin state.
 
map< unsigned int, unsigned int > pinStates
 Simulate GPIO pin states with a map.
 
map< unsigned int, vector< function< void(int, int, unsigned, void *)> > callbacks )
 Map to store the registered callback functions for each GPIO pin.
 
unsigned int simulatedTick = 0
 Variable to simulate the tick counter.
 

Detailed Description

Implementation of the stub functions for the pigpio library. This stub is used for environments not running Linux on ARM hardware. Created by Saleem Hamo on 20/03/2024.

Function Documentation

◆ gpioDelay()

void gpioDelay ( unsigned micros)

Simulate a delay in microseconds.

Increments the simulatedTick counter by the delay amount.

Parameters
microsThe number of microseconds to delay.

◆ gpioInitialise()

int gpioInitialise ( )

Initialize the GPIO simulation.

Clears the pin states and resets the simulated tick counter.

Returns
Always returns 0 in this stub implementation.

◆ gpioRead()

int gpioRead ( unsigned pin)

Read the level of a GPIO pin.

Returns the stored state if available, otherwise defaults to LOW.

Parameters
pinThe GPIO pin number to read.
Returns
The level of the pin (high or low).

◆ gpioSetAlertFuncEx()

int gpioSetAlertFuncEx ( unsigned pin,
void(*)(int, int, unsigned, void *) func,
void * user )

Set a callback function for GPIO pin alert events.

This function stores the callback function and user data for the specified GPIO pin.

Parameters
pinThe GPIO pin number.
funcThe callback function to set.
userA user-defined pointer passed to the callback function.
Returns
Always returns 0 in this stub implementation.

◆ gpioSetMode()

void gpioSetMode ( unsigned pin,
unsigned mode )

Set the mode of a GPIO pin.

This function logs the mode setting but does not simulate it.

Parameters
pinThe GPIO pin number.
modeThe mode to set for the pin (input or output).

◆ gpioTerminate()

void gpioTerminate ( )

Terminate the GPIO simulation.

Clears the pin states. Optional in this implementation.

◆ gpioTick()

unsigned gpioTick ( )

Get the current value of the simulated tick counter.

Returns
The current simulated tick value.

◆ gpioWrite()

void gpioWrite ( unsigned pin,
unsigned level )

Write a level to a GPIO pin.

Saves the level of the pin in a simulation map.

Parameters
pinThe GPIO pin number.
levelThe level to write to the pin (high or low).

◆ simulateCallback()

void simulateCallback ( unsigned pin,
int level,
unsigned tick )

Simulate a callback function call for a specific GPIO pin.

This function calls all the registered callback functions for the specified GPIO pin with the provided level and tick values.

Parameters
pinThe GPIO pin number for which to simulate the callback.
levelThe level value to pass to the callback function.
tickThe tick value to pass to the callback function.