TLV320DAC3100 (tlv320dac3100 v0.1.0)

Copy Markdown View Source

Hardware driver for the TLV320DAC3100 Stereo DAC with Headphone & Speaker Amplifiers.

Summary

Types

Real-time headset/jack detection status.

t()

Driver state for a TLV320DAC3100 device.

Functions

Configures headset and button press detection.

Reads and returns the real-time headset detection status.

Bang version of get_headset_status/1. Raises on error.

Performs physical hardware reset and initial clock/register setup.

Bang version of initialize/1. Raises on error.

Creates a new, uninitialized %TLV320DAC3100{} struct.

Sets the DAC Left and Right channel digital volume (range: -63.5 to 24.0 dB).

Bang version of set_dac_volume/2. Raises on error.

Sets the Analog Headphone Amplifier gain (range: 0 to 9 dB). It automatically clamps the value to the configured headphone_max_gain safety limit.

Bang version of set_headphone_gain/2. Raises on error.

Mutes or unmutes both left and right headphone driver amplifiers.

Bang version of set_headphone_mute/2. Raises on error.

Powers up/down the headphone drivers and sets output routing.

Sets the headphone output volume as a pragmatic percentage from 0 to 100.

Bang version of set_headphone_volume/2. Raises on error.

Sets the headphone Left and Right analog volume in decibels (range: 0.0 to -78.3 dB).

Sets the Analog Class-D Speaker Amplifier gain (options: 6, 12, 18, 24 dB). It automatically clamps the value to the configured speaker_max_gain safety limit.

Bang version of set_speaker_gain/2. Raises on error.

Mutes or unmutes the speaker driver amplifier.

Bang version of set_speaker_mute/2. Raises on error.

Powers up/down the Class-D speaker amplifier and sets output routing.

Bang version of set_speaker_output/2. Raises on error.

Sets the speaker output volume as a pragmatic percentage from 0 to 100.

Bang version of set_speaker_volume/2. Raises on error.

Sets the Left Analog Volume to SPK in decibels (range: 0.0 to -78.3 dB).

Bang version of set_speaker_volume_db/2. Raises on error.

Types

headset_status()

@type headset_status() :: :none | :headphone | :headset | :reserved

Real-time headset/jack detection status.

t()

@type t() :: %TLV320DAC3100{
  address: Circuits.I2C.address(),
  dac_volume: float(),
  headphone_enabled: boolean(),
  headphone_gain: 0..9,
  headphone_max_gain: 0..9,
  headphone_max_volume: float(),
  headphone_muted: boolean(),
  headphone_volume: float(),
  i2c_bus: Circuits.I2C.bus() | nil,
  reset_pin: String.t(),
  speaker_enabled: boolean(),
  speaker_gain: 6 | 12 | 18 | 24,
  speaker_max_gain: 6 | 12 | 18 | 24,
  speaker_max_volume: float(),
  speaker_muted: boolean(),
  speaker_volume: float()
}

Driver state for a TLV320DAC3100 device.

Functions

configure_headset_detection(dac, enabled?, opts \\ [])

@spec configure_headset_detection(t(), boolean(), keyword()) ::
  {:ok, t()} | {:error, term()}

Configures headset and button press detection.

Options

  • :detect_debounce - Debounce setting for headset detection (0-7, defaults to 0).
  • :button_debounce - Debounce setting for button press detection (0-3, defaults to 0).

configure_headset_detection!(dac, enabled?, opts \\ [])

@spec configure_headset_detection!(t(), boolean(), keyword()) :: t()

Bang version of configure_headset_detection/3. Raises on error.

get_headset_status(dac)

@spec get_headset_status(t()) :: {:ok, headset_status(), t()} | {:error, term()}

Reads and returns the real-time headset detection status.

Returns {:ok, status_atom, dac} where status_atom is one of:

  • :none - No headset is connected.
  • :headphone - Standard headphone (no mic) is connected.
  • :headset - Headset with a microphone is connected.
  • :reserved - Invalid or reserved state.

get_headset_status!(dac)

@spec get_headset_status!(t()) :: {headset_status(), t()}

Bang version of get_headset_status/1. Raises on error.

initialize(dac)

@spec initialize(t()) :: {:ok, t()} | {:error, term()}

Performs physical hardware reset and initial clock/register setup.

initialize!(dac)

@spec initialize!(t()) :: t()

Bang version of initialize/1. Raises on error.

new(i2c_bus, opts \\ [])

@spec new(
  Circuits.I2C.bus(),
  keyword()
) :: t()

Creates a new, uninitialized %TLV320DAC3100{} struct.

Options

  • :address - I2C address of the device (defaults to 0x18).
  • :reset_pin - GPIO pin identifier wired to the chip's reset line (defaults to "GPIO26").
  • :speaker_max_volume - Max analog speaker volume safety limit, 0.0 to -78.3 dB (defaults to 0.0).
  • :speaker_max_gain - Max speaker Class-D PGA gain safety limit, 6, 12, 18, or 24 dB (defaults to 12).
  • :headphone_max_volume - Max analog headphone volume safety limit, 0.0 to -78.3 dB (defaults to 0.0).
  • :headphone_max_gain - Max headphone PGA gain safety limit, 0 to 9 dB (defaults to 9).

set_dac_volume(dac, db)

@spec set_dac_volume(t(), number()) :: {:ok, t()} | {:error, term()}

Sets the DAC Left and Right channel digital volume (range: -63.5 to 24.0 dB).

set_dac_volume!(dac, db)

@spec set_dac_volume!(t(), number()) :: t()

Bang version of set_dac_volume/2. Raises on error.

set_headphone_gain(dac, gain_db)

@spec set_headphone_gain(t(), 0..9) :: {:ok, t()} | {:error, term()}

Sets the Analog Headphone Amplifier gain (range: 0 to 9 dB). It automatically clamps the value to the configured headphone_max_gain safety limit.

set_headphone_gain!(dac, gain_db)

@spec set_headphone_gain!(t(), 0..9) :: t()

Bang version of set_headphone_gain/2. Raises on error.

set_headphone_mute(dac, muted?)

@spec set_headphone_mute(t(), boolean()) :: {:ok, t()} | {:error, term()}

Mutes or unmutes both left and right headphone driver amplifiers.

set_headphone_mute!(dac, muted?)

@spec set_headphone_mute!(t(), boolean()) :: t()

Bang version of set_headphone_mute/2. Raises on error.

set_headphone_output(dac, enabled?)

@spec set_headphone_output(t(), boolean()) :: {:ok, t()} | {:error, term()}

Powers up/down the headphone drivers and sets output routing.

set_headphone_output!(dac, enabled?)

@spec set_headphone_output!(t(), boolean()) :: t()

Bang version of set_headphone_output/2. Raises on error.

set_headphone_volume(dac, pct)

@spec set_headphone_volume(t(), 0..100) :: {:ok, t()} | {:error, term()}

Sets the headphone output volume as a pragmatic percentage from 0 to 100.

  • 0% will automatically mute the headphone drivers.
  • 1% to 100% scales the volume dynamically across all allowable options of gain and volume configured in the struct. It prefers the lowest possible gain when overlapping.

set_headphone_volume!(dac, pct)

@spec set_headphone_volume!(t(), 0..100) :: t()

Bang version of set_headphone_volume/2. Raises on error.

set_headphone_volume_db(dac, db)

@spec set_headphone_volume_db(t(), number()) :: {:ok, t()} | {:error, term()}

Sets the headphone Left and Right analog volume in decibels (range: 0.0 to -78.3 dB).

set_headphone_volume_db!(dac, db)

@spec set_headphone_volume_db!(t(), number()) :: t()

Bang version of set_headphone_volume_db/2. Raises on error.

set_speaker_gain(dac, gain_db)

@spec set_speaker_gain(t(), 6 | 12 | 18 | 24) :: {:ok, t()} | {:error, term()}

Sets the Analog Class-D Speaker Amplifier gain (options: 6, 12, 18, 24 dB). It automatically clamps the value to the configured speaker_max_gain safety limit.

set_speaker_gain!(dac, gain_db)

@spec set_speaker_gain!(t(), 6 | 12 | 18 | 24) :: t()

Bang version of set_speaker_gain/2. Raises on error.

set_speaker_mute(dac, muted?)

@spec set_speaker_mute(t(), boolean()) :: {:ok, t()} | {:error, term()}

Mutes or unmutes the speaker driver amplifier.

set_speaker_mute!(dac, muted?)

@spec set_speaker_mute!(t(), boolean()) :: t()

Bang version of set_speaker_mute/2. Raises on error.

set_speaker_output(dac, enabled?)

@spec set_speaker_output(t(), boolean()) :: {:ok, t()} | {:error, term()}

Powers up/down the Class-D speaker amplifier and sets output routing.

set_speaker_output!(dac, enabled?)

@spec set_speaker_output!(t(), boolean()) :: t()

Bang version of set_speaker_output/2. Raises on error.

set_speaker_volume(dac, pct)

@spec set_speaker_volume(t(), 0..100) :: {:ok, t()} | {:error, term()}

Sets the speaker output volume as a pragmatic percentage from 0 to 100.

  • 0% will automatically mute the speaker driver.
  • 1% to 100% scales the volume dynamically across all allowable options of gain and volume configured in the struct. It prefers the lowest possible gain when overlapping.

set_speaker_volume!(dac, pct)

@spec set_speaker_volume!(t(), 0..100) :: t()

Bang version of set_speaker_volume/2. Raises on error.

set_speaker_volume_db(dac, db)

@spec set_speaker_volume_db(t(), number()) :: {:ok, t()} | {:error, term()}

Sets the Left Analog Volume to SPK in decibels (range: 0.0 to -78.3 dB).

set_speaker_volume_db!(dac, db)

@spec set_speaker_volume_db!(t(), number()) :: t()

Bang version of set_speaker_volume_db/2. Raises on error.