View Source gpio (gpio v0.6.3)

Link to this section Summary

Functions

Return information about the open GPIO chip. This includes the name, label and number of available lines.
Close a previously open GPIO chip.
Close a previously opened line events.
Close a previously opened lines.

Open a GPIO chip given its full path. The path should normally look like "/dev/gpiochipX".

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 chip_info(chip()) -> {ok, chip_info()} | {error, term()}.
Return information about the open GPIO chip. This includes the name, label and number of available lines.
-spec close_chip(chip()) -> ok | {error, term()}.
Close a previously open GPIO chip.
-spec close_line_events(line_events()) -> ok | {error, term()}.
Close a previously opened line events.
-spec close_lines(lines()) -> ok | {error, term()}.
Close a previously opened lines.
-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.

Returns a handle to use the GPIO chip in case of success.
Link to this function

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.

Returns a handle that can be used for ending the lines monitoring using close_line_events/1.
Link to this function

open_lines(Chip, Offsets, Flags, Defaults, ConsumerLabel)

View Source
-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.

Returns a handle to read from using 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 of 0 and 1 values. The tuple size is equal to the number of lines opened using open_lines/5.
Link to this function

write_lines(Lines, Values)

View Source
-spec write_lines(lines(), tuple()) -> ok | {error, term()}.

Set the current value of a set of opened lines.

The Values tuple must consiste of 0 and 1 values and its size must be equal to the number of lines opened using open_lines/5.