![]() |
PIDUINO
|
Represents a GPIO line and provides methods to interact with it. More...
#include <gpio2.h>
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 | |
Line & | operator= (const Line &)=delete |
Line & | operator= (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 LineRequest & | request () 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 LineConfig & | config () 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< Chip > | m_chip |
LineRequest | m_req |
int | m_last_error |
int | m_last_result |
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.
|
inline |
|
inline |
|
inline |
Constructor for the Line class with a LineRequest object.
dev | A pointer to the associated Chip object. |
request | A LineRequest object containing the line configuration. |
Definition at line 807 of file gpio2.h.
References m_req.
|
inline |
|
delete |
|
delete |
|
inline |
Closes the GPIO line.
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().
|
inline |
Gets the current line configuration.
Definition at line 889 of file gpio2.h.
References m_req.
Referenced by open(), and setConfig().
|
inline |
Gets the debounce period for the GPIO line.
Definition at line 1195 of file gpio2.h.
References m_req.
Referenced by setDebounce().
|
inline |
Gets the last error code from the IOCTL operation.
Definition at line 829 of file gpio2.h.
References m_last_error.
Referenced by errorMessage().
|
inline |
Gets the error message corresponding to the last error code.
Definition at line 847 of file gpio2.h.
References errorCode().
|
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.
[in] | info | Pointer to an array of LineInfo structures where the line information will be stored. |
num_lines | The 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. |
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.
|
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.
line_no | The line number (default is 0). |
Definition at line 1088 of file gpio2.h.
References getValues(), and isOpen().
|
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.
values | A reference to a LineValues object to be filled with line values. |
Definition at line 1052 of file gpio2.h.
References isOpen(), m_last_error, m_last_result, and m_req.
Referenced by getValue().
|
inline |
Checks if the GPIO line is open.
Definition at line 1009 of file gpio2.h.
References m_req.
Referenced by close(), getValue(), getValues(), open(), open(), setConfig(), setValue(), setValues(), and waitForEvent().
|
inline |
|
inline |
|
inline |
Opens the GPIO line with the specified configuration.
config | The configuration for the line. |
Definition at line 961 of file gpio2.h.
References config(), isOpen(), m_chip, m_last_error, m_last_result, and m_req.
|
inline |
Opens the GPIO line with the specified flags.
flags | The flags for opening the line. |
Definition at line 937 of file gpio2.h.
References isOpen(), m_chip, m_last_error, m_last_result, and m_req.
|
inline |
Gets the current line request configuration.
Definition at line 856 of file gpio2.h.
References m_req.
|
inline |
Gets the result of the last IOCTL operation.
Definition at line 838 of file gpio2.h.
References m_last_result.
|
inline |
Sets the configuration for the GPIO line.
config | The new configuration for the line. |
Definition at line 985 of file gpio2.h.
References config(), isOpen(), m_last_error, m_last_result, and m_req.
Referenced by setDebounce().
|
inline |
Sets the debounce period for the GPIO line.
debounce_ms | The debounce period in milliseconds. |
Definition at line 1165 of file gpio2.h.
References debounce(), m_req, and setConfig().
|
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).
line_no | The line number. |
value | The value to set (true for high, false for low). |
Definition at line 1118 of file gpio2.h.
References isOpen(), and setValues().
|
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).
values | A reference to a LineValues object containing the values to set. |
Definition at line 1142 of file gpio2.h.
References isOpen(), m_last_error, m_last_result, and m_req.
Referenced by setValue().
|
inline |
Waits for an event on the GPIO line.
event | A reference to a LineEvent object to be filled with event data. |
timeout_ms | The timeout in milliseconds. A negative value indicates no timeout. |
Definition at line 1207 of file gpio2.h.
References isOpen(), m_last_error, m_last_result, and m_req.
|
private |
|
mutableprivate |
Definition at line 1233 of file gpio2.h.
Referenced by close(), errorCode(), getInfo(), getValues(), open(), open(), setConfig(), setValues(), and waitForEvent().
|
mutableprivate |
Definition at line 1234 of file gpio2.h.
Referenced by close(), getInfo(), getValues(), open(), open(), result(), setConfig(), setValues(), and waitForEvent().
|
private |
Definition at line 1232 of file gpio2.h.
Referenced by close(), config(), debounce(), getInfo(), getValues(), isOpen(), Line(), Line(), numLines(), offset(), open(), open(), request(), setConfig(), setDebounce(), setValues(), and waitForEvent().