View Source spi (spi v0.5.0)

Link to this section Summary

Functions

Close a previously open SPI device.

Equivalent to open(Path, #{}).

Open an SPI device given its full path. The path should normally look like "/dev/spidevX.Y".

Initiate a simple read transfer.
Initiate an SPI transfer.
Initiate a simple write transfer.

Link to this section Types

-opaque device()
-type transfer() :: binary() | {binary(), transfer_options()}.
-type transfer_options() ::
    #{speed_hz => pos_integer(),
      bits_per_word => 8 | 16,
      delay_usecs => pos_integer(),
      cs_change => boolean()}.

Link to this section Functions

-spec close(device()) -> ok | {error, term()}.
Close a previously open SPI device.
-spec open(Path) -> {ok, device()} | {error, term()} when Path :: file:filename_all().

Equivalent to open(Path, #{}).

-spec open(Path, Options) -> {ok, device()} | {error, term()}
        when
            Path :: file:filename_all(),
            Options ::
                #{mode => 0 | 1 | 2 | 3, speed_hz => pos_integer(), bits_per_word => 8 | 16}.

Open an SPI device given its full path. The path should normally look like "/dev/spidevX.Y".

Once a device is open, transfers can be done using transfer/2. read/2, read/3, write/2 and write/3 are convenience helpers implemented on top of the transfer/2 function that ignore the reveived data in case of write or write a continuous stream of 0s in the case of read.

The handle to the SPI device is automatically closed when the process that opened it terminates, it can also be closed explicitely using close/1.

Returns a handle to communite with the SPI device in case of success.
-spec read(device(), pos_integer()) -> {ok, binary()} | {error, term()}.

Equivalent to read(Device, Size, #{}).

Link to this function

read(Device, Size, Options)

View Source
-spec read(device(), pos_integer(), transfer_options()) -> {ok, binary()} | {error, term()}.
Initiate a simple read transfer.
Link to this function

transfer(Device, Transfers)

View Source
-spec transfer(device(), [transfer()]) -> {ok, [binary()]} | {error, term()}.
Initiate an SPI transfer.
-spec write(device(), binary()) -> ok | {error, term()}.

Equivalent to write(Device, Data, #{}).

Link to this function

write(Device, Data, Options)

View Source
-spec write(device(), binary(), transfer_options()) -> ok | {error, term()}.
Initiate a simple write transfer.