PIDUINO
Loading...
Searching...
No Matches
Gpio2::Chip

Represents a GPIO chip and provides methods to interact with it. More...

#include <gpio2.h>

Collaboration diagram for Gpio2::Chip:

Public Member Functions

 Chip (const std::string &consumer=std::string())
 Constructor for the Chip class.
 
 ~Chip ()
 Destructor for the Chip class.
 
std::string consumer () const
 Gets the consumer label of the GPIO chip.
 
template<class ParamType >
bool ioCtl (unsigned long cmd, ParamType *param)
 Performs an IOCTL operation on the GPIO chip.
 
int errorCode () const
 Gets the last error code from the IOCTL operation.
 
int result () const
 Gets the result of the last IOCTL operation.
 
const char * errorMessage () const
 Gets the error message corresponding to the last error code.
 
bool open (const char *dev)
 Opens the GPIO chip device.
 
bool open (const std::string &dev)
 Opens the GPIO chip device using a string.
 
bool open (uint32_t chip_no)
 Opens the GPIO chip device using a chip number.
 
bool isOpen () const
 Checks if the GPIO chip device is open.
 
std::string dev () const
 Gets the path to the GPIO chip device.
 
bool close ()
 Closes the GPIO chip device.
 
bool fillInfo ()
 Fills the chip information structure with data from the device.
 
std::string name () const
 Gets the name of the GPIO chip.
 
std::string label () const
 Gets the label of the GPIO chip.
 
uint32_t lines () const
 Gets the number of lines available on the GPIO chip.
 
bool lineInfo (uint32_t offset, LineInfo *info)
 Retrieves information about a specific GPIO line.
 

Static Public Member Functions

static std::string devPath (uint32_t chip_no)
 Gets the path to a GPIO chip device based on its chip number.
 

Private Attributes

std::string m_dev
 
std::string m_consumer
 
ChipInfo m_dev_info
 
int m_fd
 
int m_last_error
 
int m_last_result
 

Detailed Description

Represents a GPIO chip and provides methods to interact with it.

This class encapsulates the functionality to open, close, and query information about a GPIO chip, as well as perform IOCTL operations.

Note
The class is not copyable or movable.

Definition at line 547 of file gpio2.h.

Constructor & Destructor Documentation

◆ Chip()

Gpio2::Chip::Chip ( const std::string &  consumer = std::string())
inline

Constructor for the Chip class.

Parameters
consumerA string representing the consumer label for the chip.

Definition at line 553 of file gpio2.h.

◆ ~Chip()

Gpio2::Chip::~Chip ( )
inline

Destructor for the Chip class.

Note
Ensures that the chip is closed when the object is destroyed.

Definition at line 559 of file gpio2.h.

References close().

Here is the call graph for this function:

Member Function Documentation

◆ close()

bool Gpio2::Chip::close ( )
inline

Closes the GPIO chip device.

Returns
true if the device was successfully closed, false otherwise.

Definition at line 681 of file gpio2.h.

References close(), isOpen(), m_fd, m_last_error, and m_last_result.

Referenced by close(), and ~Chip().

Here is the call graph for this function:

◆ consumer()

std::string Gpio2::Chip::consumer ( ) const
inline

Gets the consumer label of the GPIO chip.

Returns
A string containing the consumer label.

Definition at line 569 of file gpio2.h.

References m_consumer.

◆ dev()

std::string Gpio2::Chip::dev ( ) const
inline

Gets the path to the GPIO chip device.

Returns
A string containing the device path.

Definition at line 672 of file gpio2.h.

References m_dev.

Referenced by open(), and open().

◆ devPath()

static std::string Gpio2::Chip::devPath ( uint32_t  chip_no)
inlinestatic

Gets the path to a GPIO chip device based on its chip number.

Parameters
chip_noThe chip number of the GPIO chip.
Returns
A string representing the path to the GPIO chip device.
Note
The path is constructed as "/dev/gpiochip<chip_no>".

Definition at line 757 of file gpio2.h.

Referenced by open().

◆ errorCode()

int Gpio2::Chip::errorCode ( ) const
inline

Gets the last error code from the IOCTL operation.

Returns
The error code.

Definition at line 597 of file gpio2.h.

References m_last_error.

Referenced by errorMessage().

◆ errorMessage()

const char * Gpio2::Chip::errorMessage ( ) const
inline

Gets the error message corresponding to the last error code.

Returns
A string describing the error.

Definition at line 615 of file gpio2.h.

References errorCode().

Here is the call graph for this function:

◆ fillInfo()

bool Gpio2::Chip::fillInfo ( )
inline

Fills the chip information structure with data from the device.

Returns
true if the operation was successful, false otherwise.

Definition at line 702 of file gpio2.h.

References ioCtl(), isOpen(), and m_dev_info.

Here is the call graph for this function:

◆ ioCtl()

template<class ParamType >
bool Gpio2::Chip::ioCtl ( unsigned long  cmd,
ParamType *  param 
)
inline

Performs an IOCTL operation on the GPIO chip.

Template Parameters
ParamTypeThe type of the parameter for the IOCTL operation.
Parameters
cmdThe IOCTL command.
paramA pointer to the parameter for the IOCTL operation.
Returns
true if the operation was successful, false otherwise.

Definition at line 581 of file gpio2.h.

References m_fd, m_last_error, and m_last_result.

Referenced by fillInfo(), and lineInfo().

◆ isOpen()

bool Gpio2::Chip::isOpen ( ) const
inline

Checks if the GPIO chip device is open.

Returns
true if the device is open, false otherwise.

Definition at line 663 of file gpio2.h.

References m_fd.

Referenced by close(), fillInfo(), and open().

◆ label()

std::string Gpio2::Chip::label ( ) const
inline

Gets the label of the GPIO chip.

Returns
A string containing the label of the chip.

Definition at line 724 of file gpio2.h.

References m_dev_info.

◆ lineInfo()

bool Gpio2::Chip::lineInfo ( uint32_t  offset,
LineInfo info 
)
inline

Retrieves information about a specific GPIO line.

Parameters
offsetThe offset of the GPIO line.
infoA pointer to a LineInfo structure to be filled with line information.
Returns
true if the operation was successful, false otherwise.

Definition at line 744 of file gpio2.h.

References ioCtl().

Here is the call graph for this function:

◆ lines()

uint32_t Gpio2::Chip::lines ( ) const
inline

Gets the number of lines available on the GPIO chip.

Returns
The number of lines.

Definition at line 733 of file gpio2.h.

References m_dev_info.

◆ name()

std::string Gpio2::Chip::name ( ) const
inline

Gets the name of the GPIO chip.

Returns
A string containing the name of the chip.

Definition at line 715 of file gpio2.h.

References m_dev_info.

◆ open() [1/3]

bool Gpio2::Chip::open ( const char *  dev)
inline

Opens the GPIO chip device.

Parameters
devThe path to the GPIO chip device.
Returns
true if the device was successfully opened, false otherwise.

Definition at line 625 of file gpio2.h.

References dev(), isOpen(), m_dev, m_fd, m_last_error, and open().

Referenced by open(), open(), and open().

Here is the call graph for this function:

◆ open() [2/3]

bool Gpio2::Chip::open ( const std::string &  dev)
inline

Opens the GPIO chip device using a string.

Parameters
devThe path to the GPIO chip device as a string.
Returns
true if the device was successfully opened, false otherwise.

Definition at line 643 of file gpio2.h.

References dev(), and open().

Here is the call graph for this function:

◆ open() [3/3]

bool Gpio2::Chip::open ( uint32_t  chip_no)
inline

Opens the GPIO chip device using a chip number.

Parameters
chip_noThe chip number of the GPIO chip.
Returns
true if the device was successfully opened, false otherwise.

Definition at line 653 of file gpio2.h.

References devPath(), and open().

Here is the call graph for this function:

◆ result()

int Gpio2::Chip::result ( ) const
inline

Gets the result of the last IOCTL operation.

Returns
The result of the operation.

Definition at line 606 of file gpio2.h.

References m_last_result.

Member Data Documentation

◆ m_consumer

std::string Gpio2::Chip::m_consumer
private

Definition at line 764 of file gpio2.h.

Referenced by consumer().

◆ m_dev

std::string Gpio2::Chip::m_dev
private

Definition at line 763 of file gpio2.h.

Referenced by dev(), and open().

◆ m_dev_info

ChipInfo Gpio2::Chip::m_dev_info
private

Definition at line 765 of file gpio2.h.

Referenced by fillInfo(), label(), lines(), and name().

◆ m_fd

int Gpio2::Chip::m_fd
private

Definition at line 766 of file gpio2.h.

Referenced by close(), ioCtl(), isOpen(), and open().

◆ m_last_error

int Gpio2::Chip::m_last_error
private

Definition at line 767 of file gpio2.h.

Referenced by close(), errorCode(), ioCtl(), and open().

◆ m_last_result

int Gpio2::Chip::m_last_result
private

Definition at line 768 of file gpio2.h.

Referenced by close(), ioCtl(), and result().