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

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

#include <gpio2.h>

Collaboration diagram for Gpio2::Line:

Public Member Functions

 Line (std::shared_ptr< Chip > dev, uint32_t offset)
 Constructor for the Line class.
 
 Line (std::shared_ptr< Chip > dev, uint32_t num_lines, const uint32_t *offsets)
 Constructor for the Line class with multiple lines.
 
 Line (std::shared_ptr< Chip > dev, const LineRequest &request)
 Constructor for the Line class with a LineRequest object.
 
 ~Line ()
 Destructor for the Line class. Closes the line if it is open.
 
 Line (const Line &)=delete
 
 Line (Line &&)=delete
 
Lineoperator= (const Line &)=delete
 
Lineoperator= (Line &&)=delete
 
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.
 
const LineRequestrequest () const
 Gets the current line request configuration.
 
uint32_t numLines () const
 Gets the number of lines in the request.
 
uint32_t offset (uint32_t line_no=0) const
 Gets the offset of a specific line in the request.
 
const LineConfigconfig () const
 Gets the current line configuration.
 
bool getInfo (LineInfo *info, uint32_t num_lines=1)
 Retrieves information about GPIO lines.
 
bool open (uint64_t flags)
 Opens the GPIO line with the specified flags.
 
bool open (const LineConfig &config)
 Opens the GPIO line with the specified configuration.
 
bool setConfig (const LineConfig &config)
 Sets the configuration for the GPIO line.
 
bool isOpen () const
 Checks if the GPIO line is open.
 
bool close ()
 Closes the GPIO line.
 
bool getValues (LineValues &values) const
 Gets the values of the GPIO line(s).
 
bool getValue (int line_no=0) const
 Gets the value of a specific GPIO line.
 
bool setValue (bool value, int line_no=0)
 Sets the value of a specific GPIO line.
 
bool setValues (const LineValues &values)
 Sets the values of the GPIO line(s).
 
bool setDebounce (uint32_t debounce_ms)
 Sets the debounce period for the GPIO line.
 
uint32_t debounce () const
 Gets the debounce period for the GPIO line.
 
bool waitForEvent (LineEvent &event, int timeout_ms=-1)
 Waits for an event on the GPIO line.
 

Private Attributes

std::shared_ptr< Chipm_chip
 
LineRequest m_req
 
int m_last_error
 
int m_last_result
 

Detailed Description

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

This class encapsulates the functionality to open, close, configure, and manipulate GPIO lines, as well as handle events.

Note
The class is not copyable or movable.

Definition at line 780 of file gpio2.h.

Constructor & Destructor Documentation

◆ Line() [1/5]

Gpio2::Line::Line ( std::shared_ptr< Chip dev,
uint32_t  offset 
)
inline

Constructor for the Line class.

Parameters
devA pointer to the associated Chip object.
offsetThe offset of the GPIO line.

Definition at line 787 of file gpio2.h.

◆ Line() [2/5]

Gpio2::Line::Line ( std::shared_ptr< Chip dev,
uint32_t  num_lines,
const uint32_t *  offsets 
)
inline

Constructor for the Line class with multiple lines.

Parameters
devA pointer to the associated Chip object.
num_linesThe number of lines.
offsetsA pointer to an array of line offsets.

Definition at line 795 of file gpio2.h.

References m_req.

◆ Line() [3/5]

Gpio2::Line::Line ( std::shared_ptr< Chip dev,
const LineRequest request 
)
inline

Constructor for the Line class with a LineRequest object.

Parameters
devA pointer to the associated Chip object.
requestA LineRequest object containing the line configuration.

Definition at line 807 of file gpio2.h.

References m_req.

◆ ~Line()

Gpio2::Line::~Line ( )
inline

Destructor for the Line class. Closes the line if it is open.

Definition at line 815 of file gpio2.h.

References close().

Here is the call graph for this function:

◆ Line() [4/5]

Gpio2::Line::Line ( const Line )
delete

◆ Line() [5/5]

Gpio2::Line::Line ( Line &&  )
delete

Member Function Documentation

◆ close()

bool Gpio2::Line::close ( )
inline

Closes the GPIO line.

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

Definition at line 1018 of file gpio2.h.

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

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

Here is the call graph for this function:

◆ config()

const LineConfig & Gpio2::Line::config ( ) const
inline

Gets the current line configuration.

Returns
A reference to the LineConfig object.

Definition at line 889 of file gpio2.h.

References m_req.

Referenced by open(), and setConfig().

◆ debounce()

uint32_t Gpio2::Line::debounce ( ) const
inline

Gets the debounce period for the GPIO line.

Returns
The debounce period in milliseconds.

Definition at line 1195 of file gpio2.h.

References m_req.

Referenced by setDebounce().

◆ errorCode()

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

Gets the last error code from the IOCTL operation.

Returns
The error code.

Definition at line 829 of file gpio2.h.

References m_last_error.

Referenced by errorMessage().

◆ errorMessage()

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

Gets the error message corresponding to the last error code.

Returns
A string describing the error.

Definition at line 847 of file gpio2.h.

References errorCode().

Here is the call graph for this function:

◆ getInfo()

bool Gpio2::Line::getInfo ( LineInfo info,
uint32_t  num_lines = 1 
)
inline

Retrieves information about GPIO lines.

This function fetches information about a specified number of GPIO lines and stores it in the provided LineInfo array. The number of lines to retrieve is limited by the number of lines available in the request.

Parameters
[in]infoPointer to an array of LineInfo structures where the line information will be stored.
num_linesThe number of lines to retrieve information for. Defaults to 1. If num_lines exceeds the number of lines available in the request, it will be clamped to the maximum available.
Returns
true if the information for all requested lines was successfully retrieved, false otherwise.

Definition at line 909 of file gpio2.h.

References m_chip, m_last_error, m_last_result, and m_req.

◆ getValue()

bool Gpio2::Line::getValue ( int  line_no = 0) const
inline

Gets the value of a specific GPIO line.

The value returned are logical, indicating if the line is active or inactive. The #GPIO_V2_LINE_FLAG_ACTIVE_LOW flag controls the mapping between physical value (high/low) and logical value (active/inactive). If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is not set then high is active and low is inactive. If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is set then low is active and high is inactive.

If failed to get the value, an std::system_error exception is thrown.

Note
The values of both input and output lines may be read. For output lines, the value returned is driver and configuration dependent and may be either the output buffer (the last requested value set) or the input buffer (the actual level of the line), and depending on the hardware and configuration these may differ.
Parameters
line_noThe line number (default is 0).
Returns
The value of the line (true for high, false for low).

Definition at line 1088 of file gpio2.h.

References getValues(), and isOpen().

Here is the call graph for this function:

◆ getValues()

bool Gpio2::Line::getValues ( LineValues values) const
inline

Gets the values of the GPIO line(s).

The values returned are logical, indicating if the line is active or inactive. The #GPIO_V2_LINE_FLAG_ACTIVE_LOW flag controls the mapping between physical values (high/low) and logical values (active/inactive). If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is not set then high is active and low is inactive. If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is set then low is active and high is inactive.

Note
The values of both input and output lines may be read. For output lines, the value returned is driver and configuration dependent and may be either the output buffer (the last requested value set) or the input buffer (the actual level of the line), and depending on the hardware and configuration these may differ.
Parameters
valuesA reference to a LineValues object to be filled with line values.
Returns
true if the values were successfully retrieved, false otherwise.

Definition at line 1052 of file gpio2.h.

References isOpen(), m_last_error, m_last_result, and m_req.

Referenced by getValue().

Here is the call graph for this function:

◆ isOpen()

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

Checks if the GPIO line is open.

Returns
true if the line is open, false otherwise.

Definition at line 1009 of file gpio2.h.

References m_req.

Referenced by close(), getValue(), getValues(), open(), open(), setConfig(), setValue(), setValues(), and waitForEvent().

◆ numLines()

uint32_t Gpio2::Line::numLines ( ) const
inline

Gets the number of lines in the request.

Returns
The number of lines in the request.

Definition at line 865 of file gpio2.h.

References m_req.

◆ offset()

uint32_t Gpio2::Line::offset ( uint32_t  line_no = 0) const
inline

Gets the offset of a specific line in the request.

Parameters
line_noThe line number (default is 0).
Returns
The offset of the specified line.
Exceptions
std::out_of_rangeif the line number is out of range.

Definition at line 876 of file gpio2.h.

References m_req.

◆ open() [1/2]

bool Gpio2::Line::open ( const LineConfig config)
inline

Opens the GPIO line with the specified configuration.

Parameters
configThe configuration for the line.
Returns
true if the line was successfully opened, false otherwise.

Definition at line 961 of file gpio2.h.

References config(), isOpen(), m_chip, m_last_error, m_last_result, and m_req.

Here is the call graph for this function:

◆ open() [2/2]

bool Gpio2::Line::open ( uint64_t  flags)
inline

Opens the GPIO line with the specified flags.

Parameters
flagsThe flags for opening the line.
Returns
true if the line was successfully opened, false otherwise.

Definition at line 937 of file gpio2.h.

References isOpen(), m_chip, m_last_error, m_last_result, and m_req.

Here is the call graph for this function:

◆ operator=() [1/2]

Line & Gpio2::Line::operator= ( const Line )
delete

◆ operator=() [2/2]

Line & Gpio2::Line::operator= ( Line &&  )
delete

◆ request()

const LineRequest & Gpio2::Line::request ( ) const
inline

Gets the current line request configuration.

Returns
A reference to the LineRequest object.

Definition at line 856 of file gpio2.h.

References m_req.

◆ result()

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

Gets the result of the last IOCTL operation.

Returns
The result of the operation.

Definition at line 838 of file gpio2.h.

References m_last_result.

◆ setConfig()

bool Gpio2::Line::setConfig ( const LineConfig config)
inline

Sets the configuration for the GPIO line.

Parameters
configThe new configuration for the line.
Returns
true if the configuration was successfully set, false otherwise.

Definition at line 985 of file gpio2.h.

References config(), isOpen(), m_last_error, m_last_result, and m_req.

Referenced by setDebounce().

Here is the call graph for this function:

◆ setDebounce()

bool Gpio2::Line::setDebounce ( uint32_t  debounce_ms)
inline

Sets the debounce period for the GPIO line.

Parameters
debounce_msThe debounce period in milliseconds.
Returns
true if the debounce period was successfully set or unchanged, false otherwise.

Definition at line 1165 of file gpio2.h.

References debounce(), m_req, and setConfig().

Here is the call graph for this function:

◆ setValue()

bool Gpio2::Line::setValue ( bool  value,
int  line_no = 0 
)
inline

Sets the value of a specific GPIO line.

The value set are logical, indicating if the line is to be active or inactive. The #GPIO_V2_LINE_FLAG_ACTIVE_LOW flag controls the mapping between logical values (active/inactive) and physical values (high/low). If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is not set then active is high and inactive is low. If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is set then active is low and inactive is high.

Only the values of output lines may be set. Attempting to set the value of an input line is an error (EPERM).

Parameters
line_noThe line number.
valueThe value to set (true for high, false for low).
Returns
true if the value was successfully set, false otherwise.

Definition at line 1118 of file gpio2.h.

References isOpen(), and setValues().

Here is the call graph for this function:

◆ setValues()

bool Gpio2::Line::setValues ( const LineValues values)
inline

Sets the values of the GPIO line(s).

The values set are logical, indicating if the line is to be active or inactive. The #GPIO_V2_LINE_FLAG_ACTIVE_LOW flag controls the mapping between logical values (active/inactive) and physical values (high/low). If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is not set then active is high and inactive is low. If #GPIO_V2_LINE_FLAG_ACTIVE_LOW is set then active is low and inactive is high.

Only the values of output lines may be set. Attempting to set the value of an input line is an error (EPERM).

Parameters
valuesA reference to a LineValues object containing the values to set.
Returns
true if the values were successfully set, false otherwise.

Definition at line 1142 of file gpio2.h.

References isOpen(), m_last_error, m_last_result, and m_req.

Referenced by setValue().

Here is the call graph for this function:

◆ waitForEvent()

bool Gpio2::Line::waitForEvent ( LineEvent event,
int  timeout_ms = -1 
)
inline

Waits for an event on the GPIO line.

Parameters
eventA reference to a LineEvent object to be filled with event data.
timeout_msThe timeout in milliseconds. A negative value indicates no timeout.
Returns
true if an event was successfully received, false otherwise.

Definition at line 1207 of file gpio2.h.

References isOpen(), m_last_error, m_last_result, and m_req.

Here is the call graph for this function:

Member Data Documentation

◆ m_chip

std::shared_ptr<Chip> Gpio2::Line::m_chip
private

Definition at line 1231 of file gpio2.h.

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

◆ m_last_error

int Gpio2::Line::m_last_error
mutableprivate

Definition at line 1233 of file gpio2.h.

Referenced by close(), errorCode(), getInfo(), getValues(), open(), open(), setConfig(), setValues(), and waitForEvent().

◆ m_last_result

int Gpio2::Line::m_last_result
mutableprivate

Definition at line 1234 of file gpio2.h.

Referenced by close(), getInfo(), getValues(), open(), open(), result(), setConfig(), setValues(), and waitForEvent().

◆ m_req