# `Circuits.I2C.Bus`
[🔗](https://github.com/elixir-circuits/circuits_i2c/blob/v2.1.0/lib/i2c/bus.ex#L5)

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

# `flag`

```elixir
@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.

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `close`

```elixir
@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.

# `flags`

```elixir
@spec flags(t()) :: [flag()]
```

# `read`

```elixir
@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

# `write`

```elixir
@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.

# `write_read`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
