TMF882X.Device (tmf882x v0.1.1)

Handles communication around device setup and configuration.

Link to this section Summary

Functions

Applies a subset of configuration

Enables the device via I2C when the enable pin is not connected.

Returns firmware information for the device.

Returns the SPAD currently in the custom page.

Read the contents of the configuration page register and returns them as a TMF882X.Config struct.

Sets the spad in the custom spad page to the provided one.

Returns the status of the device gathered from the 0xE0 register

Waits until the STAT_OK register returns a value less than 0x10 and returns :ok or returns {:error, :wait_timeout} if it does not before the given timeout (in ms).

Waits until the status of the device returns as enabled. Ether returns :ok if the device becomes enabled or {:ok, :enable_timeout} if the device is not enabled before the timeout.

Waits until the STAT_OK register returns a value of 0x00 and returns :ok or returns {:error, :wait_timeout} if it does not before the given timeout (in ms).

Link to this section Functions

Link to this function

apply_config(pid, config)

@spec apply_config(reference(), map()) :: :ok | :error

Applies a subset of configuration

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

Enables the device via I2C when the enable pin is not connected.

@spec firmware(reference()) :: %{app_id: byte(), major: byte(), minor: byte()}

Returns firmware information for the device.

Link to this function

get_custom_spad(pid)

@spec get_custom_spad(reference()) :: TMF882X.SPAD.t()

Returns the SPAD currently in the custom page.

Link to this function

read_config(pid)

Read the contents of the configuration page register and returns them as a TMF882X.Config struct.

Link to this function

set_custom_spad(pid, spad)

@spec set_custom_spad(reference(), TMF882X.SPAD.t()) :: :ok | :error

Sets the spad in the custom spad page to the provided one.

@spec status(reference()) :: %{
  active: boolean(),
  enabled: boolean(),
  set_bits: <<_::2>>,
  status: byte()
}

Returns the status of the device gathered from the 0xE0 register

Link to this function

wait(pid, remain)

@spec wait(reference(), non_neg_integer()) :: :ok | {:error, :wait_timeout}

Waits until the STAT_OK register returns a value less than 0x10 and returns :ok or returns {:error, :wait_timeout} if it does not before the given timeout (in ms).

Link to this function

wait_for_enabled(i2c, timeout)

@spec wait_for_enabled(reference(), non_neg_integer()) ::
  :ok | {:error, :enable_timeout}

Waits until the status of the device returns as enabled. Ether returns :ok if the device becomes enabled or {:ok, :enable_timeout} if the device is not enabled before the timeout.

Link to this function

wait_for_stat_ok(pid, remain)

@spec wait_for_stat_ok(reference(), non_neg_integer()) ::
  :ok | {:error, :wait_timeout}

Waits until the STAT_OK register returns a value of 0x00 and returns :ok or returns {:error, :wait_timeout} if it does not before the given timeout (in ms).