Wafer.SPI protocol (wafer v1.1.1)
View SourceA (very simple) protocol for interacting with SPI connected devices.
This API is a minimal version of the 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]
endIf 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
Summary
Functions
Perform an SPI transfer.
Types
Functions
@spec 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.