CircuitsSim.I2C.I2CDevice protocol (circuits_sim v0.1.2)

View Source

A protocol for I2C devices

See Circuits.I2C.SimpleI2CDevice if you have a simple register-based I2C device.

Summary

Types

t()

All the types that implement this protocol.

Functions

Handle an user message

Read count bytes

Return the internal state as ASCII art

Write data to the device

Write data to the device and immediately follow it with a read

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

handle_message(dev, message)

@spec handle_message(t(), any()) :: {any(), t()}

Handle an user message

User messages are used to modify the state of the simulated device outside of I2C. This can be used to simulate real world changes like temperature changes affecting a simulated temperature sensor. Another use is as a hook for getting internal state.

read(dev, count)

@spec read(t(), non_neg_integer()) :: {{:ok, binary()} | {:error, any()}, t()}

Read count bytes

The first item in the returned tuple is what's returned from the original call to Circuits.I2C.read/2. Try to make the errors consistent with that function if possible.

render(dev)

@spec render(t()) :: IO.ANSI.ansidata()

Return the internal state as ASCII art

write(dev, data)

@spec write(t(), binary()) :: t()

Write data to the device

write_read(dev, data, read_count)

@spec write_read(t(), binary(), non_neg_integer()) ::
  {{:ok, binary()} | {:error, any()}, t()}

Write data to the device and immediately follow it with a read