TMF882X.Bus (tmf882x v0.1.1)

Module for interfacing with the TMF882X over I2C. This module handles the lower-level communication with the device.

Link to this section Summary

Functions

Reads a number of bytes from the bus

Waits for the device to be present on the I2C bus and returns :ok when it is found, or {:error, :i2c_device_timeout} if the device is not found before the given timeout (in ms).

Waits for the i2c bus to become available and connects to it. Returns {:ok, pid} when successful or {:error, :i2c_timeout} if not bus connection was made before the given timeout

Writes data to the bus.

Writes the given data to the bus then immediately reads the given number of bytes off of the bus.

Link to this section Functions

Link to this function

read(pid, size)

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

Reads a number of bytes from the bus

Link to this function

wait_for_device(i2c, timeout)

@spec wait_for_device(reference(), non_neg_integer()) ::
  :ok | {:error, :i2c_device_timeout}

Waits for the device to be present on the I2C bus and returns :ok when it is found, or {:error, :i2c_device_timeout} if the device is not found before the given timeout (in ms).

Link to this function

wait_for_i2c_and_connect(bus, timeout)

@spec wait_for_i2c_and_connect(String.t(), non_neg_integer()) ::
  {:ok, reference()} | {:error, :i2c_timeout}

Waits for the i2c bus to become available and connects to it. Returns {:ok, pid} when successful or {:error, :i2c_timeout} if not bus connection was made before the given timeout

Link to this function

write(pid, data)

@spec write(reference(), binary()) :: :ok | {:error, any()}

Writes data to the bus.

Link to this function

write_read(pid, data, size)

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

Writes the given data to the bus then immediately reads the given number of bytes off of the bus.