libgpiod  1.6.2
Public Types | Public Member Functions
gpiod::line Class Reference

Represents a single GPIO line. More...

#include <gpiod.hpp>

Public Types

enum  : int { DIRECTION_INPUT = 1, DIRECTION_OUTPUT }
 Possible direction settings. More...
 
enum  : int { ACTIVE_LOW = 1, ACTIVE_HIGH }
 Possible active state settings. More...
 
enum  : int { BIAS_AS_IS = 1, BIAS_DISABLE, BIAS_PULL_UP, BIAS_PULL_DOWN }
 Possible bias settings. More...
 

Public Member Functions

GPIOD_API line (void)
 Default constructor. More...
 
GPIOD_API line (const line &other)=default
 Copy constructor. More...
 
GPIOD_API line (line &&other)=default
 Move constructor. More...
 
GPIOD_API lineoperator= (const line &other)=default
 Assignment operator. More...
 
GPIOD_API lineoperator= (line &&other)=default
 Move assignment operator. More...
 
GPIOD_API ~line (void)=default
 Destructor.
 
GPIOD_API unsigned int offset (void) const
 Get the offset of this line. More...
 
GPIOD_API ::std::string name (void) const
 Get the name of this line (if any). More...
 
GPIOD_API ::std::string consumer (void) const
 Get the consumer of this line (if any). More...
 
GPIOD_API int direction (void) const
 Get current direction of this line. More...
 
GPIOD_API int active_state (void) const
 Get current active state of this line. More...
 
GPIOD_API int bias (void) const
 Get current bias of this line. More...
 
GPIOD_API bool is_used (void) const
 Check if this line is used by the kernel or other user space process. More...
 
GPIOD_API bool is_open_drain (void) const
 Check if this line represents an open-drain GPIO. More...
 
GPIOD_API bool is_open_source (void) const
 Check if this line represents an open-source GPIO. More...
 
GPIOD_API void request (const line_request &config, int default_val=0) const
 Request this line. More...
 
GPIOD_API void release (void) const
 Release the line if it was previously requested.
 
GPIOD_API bool is_requested (void) const
 Check if this user has ownership of this line. More...
 
GPIOD_API int get_value (void) const
 Read the line value. More...
 
GPIOD_API void set_value (int val) const
 Set the value of this line. More...
 
GPIOD_API void set_config (int direction, ::std::bitset< 32 > flags, int value=0) const
 Set configuration of this line. More...
 
GPIOD_API void set_flags (::std::bitset< 32 > flags) const
 Set configuration flags of this line. More...
 
GPIOD_API void set_direction_input () const
 Change the direction this line to input.
 
GPIOD_API void set_direction_output (int value=0) const
 Change the direction this lines to output. More...
 
GPIOD_API bool event_wait (const ::std::chrono::nanoseconds &timeout) const
 Wait for an event on this line. More...
 
GPIOD_API line_event event_read (void) const
 Read a line event. More...
 
GPIOD_API ::std::vector< line_eventevent_read_multiple (void) const
 Read multiple line events. More...
 
GPIOD_API int event_get_fd (void) const
 Get the event file descriptor associated with this line. More...
 
GPIOD_API const chipget_chip (void) const
 Get the reference to the parent chip. More...
 
GPIOD_API void update (void) const
 Re-read the line info from the kernel.
 
GPIOD_API void reset (void)
 Reset the state of this object. More...
 
GPIOD_API bool operator== (const line &rhs) const noexcept
 Check if two line objects reference the same GPIO line. More...
 
GPIOD_API bool operator!= (const line &rhs) const noexcept
 Check if two line objects reference different GPIO lines. More...
 
GPIOD_API operator bool (void) const noexcept
 Check if this object holds a reference to any GPIO line. More...
 
GPIOD_API bool operator! (void) const noexcept
 Check if this object doesn't reference any GPIO line. More...
 

Detailed Description

Represents a single GPIO line.

Internally this class holds a raw pointer to a GPIO line descriptor and a reference to the parent chip. All line resources are freed when the last reference to the parent chip is dropped.

Definition at line 262 of file gpiod.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : int

Possible direction settings.

Enumerator
DIRECTION_INPUT 

Line's direction setting is input.

DIRECTION_OUTPUT 

Line's direction setting is output.

Definition at line 490 of file gpiod.hpp.

◆ anonymous enum

anonymous enum : int

Possible active state settings.

Enumerator
ACTIVE_LOW 

Line's active state is low.

ACTIVE_HIGH 

Line's active state is high.

Definition at line 500 of file gpiod.hpp.

◆ anonymous enum

anonymous enum : int

Possible bias settings.

Enumerator
BIAS_AS_IS 

Line's bias state is unknown.

BIAS_DISABLE 

Line's internal bias is disabled.

BIAS_PULL_UP 

Line's internal pull-up bias is enabled.

BIAS_PULL_DOWN 

Line's internal pull-down bias is enabled.

Definition at line 510 of file gpiod.hpp.

Constructor & Destructor Documentation

◆ line() [1/3]

GPIOD_API gpiod::line::line ( void  )

Default constructor.

Creates an empty line object.

◆ line() [2/3]

GPIOD_API gpiod::line::line ( const line other)
default

Copy constructor.

Parameters
otherOther line object.

◆ line() [3/3]

GPIOD_API gpiod::line::line ( line &&  other)
default

Move constructor.

Parameters
otherOther line object.

Member Function Documentation

◆ active_state()

GPIOD_API int gpiod::line::active_state ( void  ) const

Get current active state of this line.

Returns
Current active state setting.

◆ bias()

GPIOD_API int gpiod::line::bias ( void  ) const

Get current bias of this line.

Returns
Current bias setting.

◆ consumer()

GPIOD_API ::std::string gpiod::line::consumer ( void  ) const

Get the consumer of this line (if any).

Returns
Name of the consumer of this line or an empty string if it is unused.

◆ direction()

GPIOD_API int gpiod::line::direction ( void  ) const

Get current direction of this line.

Returns
Current direction setting.

◆ event_get_fd()

GPIOD_API int gpiod::line::event_get_fd ( void  ) const

Get the event file descriptor associated with this line.

Returns
File descriptor number.

◆ event_read()

GPIOD_API line_event gpiod::line::event_read ( void  ) const

Read a line event.

Returns
Line event object.

◆ event_read_multiple()

GPIOD_API ::std::vector<line_event> gpiod::line::event_read_multiple ( void  ) const

Read multiple line events.

Returns
Vector of line event objects.

◆ event_wait()

GPIOD_API bool gpiod::line::event_wait ( const ::std::chrono::nanoseconds &  timeout) const

Wait for an event on this line.

Parameters
timeoutTime to wait before returning if no event occurred.
Returns
True if an event occurred and can be read, false if the wait timed out.

◆ get_chip()

GPIOD_API const chip& gpiod::line::get_chip ( void  ) const

Get the reference to the parent chip.

Returns
Reference to the parent chip object.

◆ get_value()

GPIOD_API int gpiod::line::get_value ( void  ) const

Read the line value.

Returns
Current value (0 or 1).

◆ is_open_drain()

GPIOD_API bool gpiod::line::is_open_drain ( void  ) const

Check if this line represents an open-drain GPIO.

Returns
True if the line is an open-drain GPIO, false otherwise.

◆ is_open_source()

GPIOD_API bool gpiod::line::is_open_source ( void  ) const

Check if this line represents an open-source GPIO.

Returns
True if the line is an open-source GPIO, false otherwise.

◆ is_requested()

GPIOD_API bool gpiod::line::is_requested ( void  ) const

Check if this user has ownership of this line.

Returns
True if the user has ownership of this line, false otherwise.

◆ is_used()

GPIOD_API bool gpiod::line::is_used ( void  ) const

Check if this line is used by the kernel or other user space process.

Returns
True if this line is in use, false otherwise.

◆ name()

GPIOD_API ::std::string gpiod::line::name ( void  ) const

Get the name of this line (if any).

Returns
Name of this line or an empty string if it is unnamed.

◆ offset()

GPIOD_API unsigned int gpiod::line::offset ( void  ) const

Get the offset of this line.

Returns
Offet of this line.

◆ operator bool()

GPIOD_API gpiod::line::operator bool ( void  ) const
explicitnoexcept

Check if this object holds a reference to any GPIO line.

Returns
True if this object references a GPIO line, false otherwise.

◆ operator!()

GPIOD_API bool gpiod::line::operator! ( void  ) const
noexcept

Check if this object doesn't reference any GPIO line.

Returns
True if this object doesn't reference any GPIO line, true otherwise.

References DIRECTION_INPUT, and DIRECTION_OUTPUT.

◆ operator!=()

GPIOD_API bool gpiod::line::operator!= ( const line rhs) const
noexcept

Check if two line objects reference different GPIO lines.

Parameters
rhsRight-hand side of the equation.
Returns
False if both objects reference the same line, true otherwise.

◆ operator=() [1/2]

GPIOD_API line& gpiod::line::operator= ( const line other)
default

Assignment operator.

Parameters
otherOther line object.
Returns
Reference to this object.

◆ operator=() [2/2]

GPIOD_API line& gpiod::line::operator= ( line &&  other)
default

Move assignment operator.

Parameters
otherOther line object.
Returns
Reference to this object.

◆ operator==()

GPIOD_API bool gpiod::line::operator== ( const line rhs) const
noexcept

Check if two line objects reference the same GPIO line.

Parameters
rhsRight-hand side of the equation.
Returns
True if both objects reference the same line, fale otherwise.

◆ request()

GPIOD_API void gpiod::line::request ( const line_request config,
int  default_val = 0 
) const

Request this line.

Parameters
configRequest config (see gpiod::line_request).
default_valDefault value - only matters for OUTPUT direction.

◆ reset()

GPIOD_API void gpiod::line::reset ( void  )

Reset the state of this object.

This is useful when the user needs to e.g. keep the line_event object but wants to drop the reference to the GPIO chip indirectly held by the line being the source of the event.

◆ set_config()

GPIOD_API void gpiod::line::set_config ( int  direction,
::std::bitset< 32 >  flags,
int  value = 0 
) const

Set configuration of this line.

Parameters
directionNew direction.
flagsReplacement flags.
valueNew value (0 or 1) - only matters for OUTPUT direction.

◆ set_direction_output()

GPIOD_API void gpiod::line::set_direction_output ( int  value = 0) const

Change the direction this lines to output.

Parameters
valueNew value (0 or 1).

◆ set_flags()

GPIOD_API void gpiod::line::set_flags ( ::std::bitset< 32 >  flags) const

Set configuration flags of this line.

Parameters
flagsReplacement flags.

◆ set_value()

GPIOD_API void gpiod::line::set_value ( int  val) const

Set the value of this line.

Parameters
valNew value (0 or 1).

The documentation for this class was generated from the following file: