View Source spi (spi v0.5.0)
Link to this section Summary
Functions
Equivalent to open(Path, #{}).
Open an SPI device given its full path. The path should normally look like "/dev/spidevX.Y".
Equivalent to read(Device, Size, #{}).
Equivalent to write(Device, Data, #{}).
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()}.
-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.
-spec read(device(), pos_integer()) -> {ok, binary()} | {error, term()}.
Equivalent to read(Device, Size, #{}).
-spec read(device(), pos_integer(), transfer_options()) -> {ok, binary()} | {error, term()}.
-spec write(device(), binary()) -> ok | {error, term()}.
Equivalent to write(Device, Data, #{}).
-spec write(device(), binary(), transfer_options()) -> ok | {error, term()}.