elixir_ale v0.7.0 ElixirALE.SPI

This module enables Elixir programs to interact with hardware that’s connected via a SPI bus.

Summary

Functions

Return a list of available SPI bus device names. If nothing is returned, it’s possible that the kernel driver for that SPI bus is not enabled or the kernel’s device tree is not configured. On Raspbian, run raspi-config and look in the advanced options

Stop the GenServer and release the SPI resources

Start and link a SPI GenServer

Perform a SPI transfer. The data should be a binary containing the bytes to send. Since SPI transfers simultaneously send and receive, the return value will be a binary of the same length

Types

spi_option()
spi_option ::
  {:mode, 0..3} |
  {:bits_per_word, 0..16} |
  {:speed_hz, pos_integer} |
  {:delay_us, non_neg_integer}

Functions

device_names()
device_names() :: [binary]

Return a list of available SPI bus device names. If nothing is returned, it’s possible that the kernel driver for that SPI bus is not enabled or the kernel’s device tree is not configured. On Raspbian, run raspi-config and look in the advanced options.

iex> ElixirALE.SPI.device_names
["spidev0.0", "spidev0.1"]
release(pid)
release(pid) :: :ok

Stop the GenServer and release the SPI resources.

start_link(devname, spi_opts \\ [], opts \\ [])
start_link(binary, [spi_option], [term]) :: {:ok, pid}

Start and link a SPI GenServer.

SPI bus options include:

  • mode: This specifies the clock polarity and phase to use. (0)
  • bits_per_word: bits per word on the bus (8)
  • speed_hz: bus speed (1000000)
  • delay_us: delay between transaction (10)

Parameters:

  • devname is the Linux device name for the bus (e.g., “spidev0.0”)
  • spi_opts is a keyword list to configure the bus
  • opts are any options to pass to GenServer.start_link
transfer(pid, data)
transfer(pid, binary) :: binary | {:error, term}

Perform a SPI transfer. The data should be a binary containing the bytes to send. Since SPI transfers simultaneously send and receive, the return value will be a binary of the same length.