Wafer.SPI protocol (wafer v0.1.2)
A (very simple) protocol for interacting with SPI connected devices.
This API is a minimal version of the ElixirALE.SPI
and Circuits.SPI
APIs,
except that it takes a Conn
which implements SPI
as an argument. If you
want to use any advanced features, such as bus detection, I advise you to
interact with the underlying driver directly.
Deriving
If you're implementing your own Conn
type that simply delegates to one of
the lower level drivers then you can derive this protocol automatically:
defstruct MySPIDevice do
@derive Wafer.SPI
defstruct [:conn]
end
If your type uses a key other than conn
for the inner connection you can
specify it while deriving:
defstruct MySPIDevice do
@derive {Wafer.SPI, key: :spi_conn}
defstruct [:spi_conn]
end
Link to this section Summary
Functions
Perform an SPI transfer.
Link to this section Types
data()
Specs
data() :: binary()
Specs
t() :: term()
Link to this section Functions
transfer(conn, data)
Specs
transfer(Wafer.Conn.t(), data()) :: {:ok, data(), Wafer.Conn.t()} | {:error, reason :: any()}
Perform an SPI transfer.
SPI transfers are synchronous, so data
should be a binary of bytes to send
to the device, and you will receive back a binary of the same length
containing the data received from the device.