Wafer.I2C protocol (wafer v1.0.2)
A protocol for interacting with I2C devices directly. Most of the time you'll
want to use the Chip protocol for working with registers, but this is
provided for consistency's sake.
This API is extremely similar to the ElixirALE.I2C and Circuits.I2C APIs,
except that it takes a Conn which implements I2C as an argument.
deriving
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 MyI2CDevice do
@derive Wafer.I2C
defstruct [:conn]
endIf your type uses a key other than conn for the inner connection you can
specify it while deriving:
defstruct MyI2CDevice do
@derive {Wafer.I2C, key: :i2c_conn}
defstruct [:i2c_conn]
end
Link to this section Summary
Functions
Detect the devices adjacent to the connection's device on the same I2C bus.
Initiate a read transaction to the connection's I2C device.
Write data to the connection's I2C device.
Write data to an I2C device and then immediately issue a read.
Link to this section Types
address()
Specs
address() :: 0..127
data()
Specs
data() :: binary()
option()
Specs
option() :: any()
options()
Specs
options() :: [option()]
Specs
t() :: term()
All the types that implement this protocol.
Link to this section Functions
detect_devices(conn)
Specs
detect_devices(Wafer.Conn.t()) :: {:ok, [address()]}
Detect the devices adjacent to the connection's device on the same I2C bus.
read(conn, bytes_to_read, options \\ [])
Specs
read(Wafer.Conn.t(), non_neg_integer(), options()) :: {:ok, data()} | {:error, reason :: any()}
Initiate a read transaction to the connection's I2C device.
write(conn, data, options \\ [])
Specs
write(Wafer.Conn.t(), data(), options()) :: {:ok, Wafer.Conn.t()} | {:error, reason :: any()}
Write data to the connection's I2C device.
write_read(conn, data, bytes_to_read, options \\ [])
Specs
write_read(Wafer.Conn.t(), data(), non_neg_integer(), options()) :: {:ok, data(), Wafer.Conn.t()} | {:error, reason :: any()}
Write data to an I2C device and then immediately issue a read.