nerves_config_pin v0.0.1 ConfigPin

A wrapper for the BeagleBone config-pin utility.

Link to this section Summary

Types

Potential errors that can be returned by config-pin. Since new versions of config-pin may be released, any unknown errors are passed through with the message and exit code returned by config-pin.

Functions

Send a command to the config-pin utility.

Print the information about a pin to the console.

Returns a list of valid modes for a pin.

Query the pin configuration details.

Set the mode for a pin.

Set a list of pin configurations defined in a file.

Link to this section Types

Link to this type

config_pin_error()

Specs

config_pin_error() ::
  {:error, :invalid_mode}
  | {:error, :invalid_pin}
  | {:error, :pinmux_file_not_found}
  | {:error, :pin_not_exported}
  | {:error, {:pin_not_modifiable, function :: String.t()}}
  | {:error,
     {:file_unreadable,
      file_path :: String.t() | {:pinmux, file_path :: String.t()}}}
  | {:error,
     {:file_unwritable, {:gpio_direction | :pinmux, file_path :: String.t()}}}
  | {:error, {:unknown, message :: String.t(), exit_code :: non_neg_integer()}}

Potential errors that can be returned by config-pin. Since new versions of config-pin may be released, any unknown errors are passed through with the message and exit code returned by config-pin.

If you encounter an :unknown error, please file an issue or PR with this repository, as we would like to support all config-pin errors idiomatically.

Link to this section Functions

Specs

cmd(args :: [String.t()]) ::
  {response :: String.t(), exit_status :: non_neg_integer()}

Send a command to the config-pin utility.

This is a low-level function and is designed to be used by higher level functions with a more idiomatic interface, or for troubleshooting.

args - See the config-pin docs or print the config-pin help from the console for the list of arguments.

Returns a tuple containing the response from stdout and the command's exit status. stderr is redirected to stdout, so failure messages will show up in the response.

Link to this function

info(header, pin)

Specs

info(header :: non_neg_integer(), pin :: non_neg_integer()) :: :ok

Print the information about a pin to the console.

header - The number of the header the pin belongs to. For example, the BeagleBone Black header P9 would be 9.

pin - The physical number of the pin to configure. For example, BBB GPIO_30 is on pin 11.

Link to this function

list_modes(header, pin)

Specs

list_modes(header :: non_neg_integer(), pin :: non_neg_integer()) ::
  :ok | config_pin_error()

Returns a list of valid modes for a pin.

header - The number of the header the pin belongs to. For example, the BeagleBone Black header P9 would be 9.

pin - The physical number of the pin to configure. For example, BBB GPIO_30 is on pin 11.

Link to this function

query(header, pin)

Specs

query(header :: non_neg_integer(), pin :: non_neg_integer()) ::
  {:ok, map()} | config_pin_error()

Query the pin configuration details.

header - The number of the header the pin belongs to. For example, the BeagleBone Black header P9 would be 9.

pin - The physical number of the pin to configure. For example, BBB GPIO_30 is on pin 11.

Returns a map of the configuration on success.

Link to this function

set(header, pin, mode)

Specs

set(header :: non_neg_integer(), pin :: non_neg_integer(), mode :: term()) ::
  :ok | config_pin_error()

Set the mode for a pin.

header - The number of the header the pin belongs to. For example, the BeagleBone Black header P9 would be 9.

pin - The physical number of the pin to configure. For example, BBB GPIO_30 is on pin 11.

mode - The mode to set the pin to. Valid modes can be discovered with valid_modes/2, or by viewing the config-pin source.

Returns :ok on success.

Link to this function

set_from_file(file_path)

Specs

set_from_file(file_path :: String.t()) :: :ok | config_pin_error()

Set a list of pin configurations defined in a file.

The file is passed directly to config-pin and is not processed by this library.

The format is <header>_<pin> <mode>\n. Comments and white-space are allowed. Each configuration must end with a line terminator.

Example file:

# <header>_<pin> <mode>
P9_11 gpio_pu
P9_12 gpio_pd