View Source gpio (gpio v0.6.2)
Link to this section Summary
Functions
Open a GPIO chip given its full path. The path should normally look like "/dev/gpiochipX".
Open a set of lines for montoring.
Open a set of lines for reading/writing.
Read the current value of a set of opened lines.
Set the current value of a set of opened lines.
Link to this section Types
-opaque chip()
-type chip_info() :: #{name := string(), label := string(), lines := non_neg_integer()}.
-opaque line_events()
-opaque lines()
Link to this section Functions
-spec close_chip(chip()) -> ok | {error, term()}.
-spec close_line_events(line_events()) -> ok | {error, term()}.
-spec close_lines(lines()) -> ok | {error, term()}.
-spec open_chip(Path) -> {ok, chip()} | {error, term()} when Path :: file:filename_all().
Open a GPIO chip given its full path. The path should normally look like "/dev/gpiochipX".
Once a chip is open, it can be used to query its info using chip_info/1
, open lines for reading/writing using open_lines/5
or monitor lines for input events using open_line_events/5
.
The handle to the GPIO chip is automatically closed when the process that opened it terminates, it can also be closed explicitely using close_chip/1
.
open_line_events(Chip, Offset, HandleFlags, EventFlags, ConsumerLabel)
View Source-spec open_line_events(chip(), Offset, [Flag], [EventFlag], ConsumerLabel) -> {ok, line_events()} | {error, term()} when Offset :: non_neg_integer(), Flag :: active_low | open_drain | open_source, EventFlag :: rising_edge | falling_edge, ConsumerLabel :: string() | binary().
Open a set of lines for montoring.
The lines to be opened are specified through the Offsets
parameter, for example to open the 16th, 20th and 21st lines Offsets would be [16, 20, 21]
. these offsets are board and system specific.
The Flags
allow specifying the active state as well as the drive mode.
The EventFlags
allow specifying how events are detected.
The ConsumerLabel
should be an ASCII string of the application name. This string will be truncated to 31 characters.
Upon opening the lines for monitoring, the owning process will start receiving messages in the form of:
{gpio, LineEventsHandle, {event, Timestamp, Type}}
Where LineEventsHandle
is the handle returned by this function, Timestamp
is best estimate of time of event occurrence, in nanoseconds and Type
is one of rising_edge
or falling_edge
.
close_line_events/1
.
-spec open_lines(chip(), [Offset], [Flag], [Default], ConsumerLabel) -> {ok, lines()} | {error, term()} when Offset :: non_neg_integer(), Flag :: input | output | active_low | open_drain | open_source, Default :: 0 | 1, ConsumerLabel :: string() | binary().
Open a set of lines for reading/writing.
The lines to be opened are specified through the Offsets
parameter, for example to open the 16th, 20th and 21st lines Offsets would be [16, 20, 21]
. these offsets are board and system specific, make sure to consult the documentation of the system to avoid damages.
The Flags
allow specifying the pin direction, the active state as well as the drive mode.
The Defaults
parameter specifies the default pin values. The length of this list must be equal to the length of the Offsets` list. The `ConsumerLabel
should be an ASCII string of the application name. This string will be truncated to 31 characters.
read_lines/1
; or write to using write_lines/2
; the opened lines in case of success.
-spec read_lines(lines()) -> {ok, tuple()} | {error, term()}.
Read the current value of a set of opened lines.
Returns a tuple of0
and 1
values. The tuple size is equal to the number of lines opened using open_lines/5
.
-spec write_lines(lines(), tuple()) -> ok | {error, term()}.
Set the current value of a set of opened lines.
TheValues
tuple must consiste of 0
and 1
values and its size must be equal to the number of lines opened using open_lines/5
.