GPIO chip
-
class chip
Represents a GPIO chip.
Public Functions
-
explicit chip(const ::std::filesystem::path &path)
Instantiates a new chip object by opening the device file indicated by the
pathargument.- Parameters:
path – Path to the device file to open.
-
chip &operator=(chip &&other) noexcept
Move assignment operator.
- Parameters:
other – Object to move.
- Returns:
Reference to self.
-
explicit operator bool() const noexcept
Check if this object is valid.
- Returns:
True if this object’s methods can be used, false otherwise. False usually means the chip was closed. If the user calls any of the methods of this class on an object for which this operator returned false, a logic_error will be thrown.
-
void close()
Close the GPIO chip device file and free associated resources.
Note
The chip object can live after calling this method but any of the chip’s mutators will throw a logic_error exception.
-
::std::filesystem::path path() const
Get the filesystem path that was used to open this GPIO chip.
- Returns:
Path to the underlying character device file.
-
line_info get_line_info(line::offset offset) const
Retrieve the current snapshot of line information for a single line.
- Parameters:
offset – Offset of the line to get the info for.
- Returns:
New gpiod::line_info object.
-
line_info watch_line_info(line::offset offset) const
Wrapper around gpiod::chip::get_line_info that retrieves the line info and starts watching the line for changes.
- Parameters:
offset – Offset of the line to get the info for.
- Returns:
New gpiod::line_info object.
-
void unwatch_line_info(line::offset offset) const
Stop watching the line at given offset for info events.
- Parameters:
offset – Offset of the line to get the info for.
-
int fd() const
Get the file descriptor associated with this chip.
- Returns:
File descriptor number.
-
bool wait_info_event(const ::std::chrono::nanoseconds &timeout) const
Wait for line status events on any of the watched lines exposed by this chip.
- Parameters:
timeout – Wait time limit in nanoseconds. If set to 0, the function returns immediately. If set to a negative number, the function blocks indefinitely until an event becomes available.
- Returns:
True if at least one event is ready to be read. False if the wait timed out.
-
info_event read_info_event() const
Read a single line status change event from this chip.
- Returns:
New info_event object.
-
int get_line_offset_from_name(const ::std::string &name) const
Map a GPIO line’s name to its offset within the chip.
- Parameters:
name – Name of the GPIO line to map.
- Returns:
Offset of the line within the chip or -1 if the line with given name is not exposed by this chip.
-
request_builder prepare_request()
Create a request_builder associated with this chip.
- Returns:
New request_builder object.
-
explicit chip(const ::std::filesystem::path &path)