View Source Circuits.I2C.Bus protocol (circuits_i2c v2.0.6)

A bus is the connection to a real or virtual I2C controller

Summary

Types

I2C controller flags

t()

All the types that implement this protocol.

Functions

Free up resources associated with the bus

Write data and read a result in one I2C transaction

Types

@type flag() :: :supports_empty_write

I2C controller flags

  • :supports_empty_write - the controller supports sending empty binaries to devices. These can be used for device detection.
@type t() :: term()

All the types that implement this protocol.

Functions

@spec close(t()) :: :ok

Free up resources associated with the bus

Well behaved backends free up their resources with the help of the Erlang garbage collector. However, it is good practice for users to call Circuits.I2C.close/1 (and hence this function) so that limited resources are freed before they're needed again.

@spec flags(t()) :: [flag()]
Link to this function

read(bus, address, count, options)

View Source
@spec read(t(), Circuits.I2C.address(), non_neg_integer(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Read data over I2C

The controller should try to read the specified number of bytes over I2C. If the retry option is passed and non-zero, the transaction only needs to be retried if there's an error. This means that fewer that the requested number of bytes may be returned.

See the implementation for options

Link to this function

write(bus, address, data, options)

View Source
@spec write(t(), Circuits.I2C.address(), iodata(), keyword()) ::
  :ok | {:error, term()}

Write data over I2C

The controller should write the passed in data to the specified I2C address.

Link to this function

write_read(bus, address, write_data, read_count, options)

View Source
@spec write_read(t(), Circuits.I2C.address(), iodata(), non_neg_integer(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Write data and read a result in one I2C transaction

This function handles the common task of writing a register number to a device and then reading its contents. The controller should perform it as one transaction without a stop condition between the write and read.