TB2026-YDS Firmware
Loading...
Searching...
No Matches
ADC / Volume potentiometer

Potentiometer sampling on ADC1 and mapping to PCM5242 digital volume. More...

Collaboration diagram for ADC / Volume potentiometer:

Functions

esp_err_t adc_pot_init (adc_oneshot_unit_handle_t *out_handle)
 Bring up ADC1 for the volume potentiometer (GPIO36) with line-fitting calibration.
esp_err_t adc_pot_read (adc_oneshot_unit_handle_t handle, int *out_mv)
 Read the averaged, calibrated wiper voltage.
uint8_t adc_pot_to_volume (int mv)
 Map a wiper voltage to a PCM5242 digital-volume register byte.
uint8_t adc_pot_to_avrcp_volume (int mv)
 Map a wiper voltage to an AVRCP absolute-volume value (0..0x7F) for a Bluetooth sink.
uint8_t adc_frac_to_volume (float frac)
 Map a 0..1 volume fraction directly to a PCM5242 register byte, bypassing the pot.
uint8_t adc_frac_to_avrcp_volume (float frac)
 Map a 0..1 volume fraction directly to an AVRCP absolute-volume value, bypassing the pot.

Detailed Description

Potentiometer sampling on ADC1 and mapping to PCM5242 digital volume.

Function Documentation

◆ adc_frac_to_avrcp_volume()

uint8_t adc_frac_to_avrcp_volume ( float frac)

Map a 0..1 volume fraction directly to an AVRCP absolute-volume value, bypassing the pot.

Parameters
fracVolume fraction, 0.0 (silent) .. 1.0 (loudest); clamped.
Returns
The AVRCP absolute-volume value, 0..0x7F. Pure function, never fails.

◆ adc_frac_to_volume()

uint8_t adc_frac_to_volume ( float frac)

Map a 0..1 volume fraction directly to a PCM5242 register byte, bypassing the pot.

Same curve as adc_pot_to_volume() (it feeds the fraction through the knob's mv range), so a fixed level matches what the equivalent knob position would produce. For deterministic tests that must not depend on the physical wiper.

Parameters
fracVolume fraction, 0.0 (quietest) .. 1.0 (loudest); clamped.
Returns
The digital-volume register byte. Pure function, never fails.

◆ adc_pot_init()

esp_err_t adc_pot_init ( adc_oneshot_unit_handle_t * out_handle)

Bring up ADC1 for the volume potentiometer (GPIO36) with line-fitting calibration.

Parameters
[out]out_handleReceives the oneshot unit handle; owned by the caller.
Returns
ESP_OK on success, or the underlying ADC unit/channel/calibration error.

◆ adc_pot_read()

esp_err_t adc_pot_read ( adc_oneshot_unit_handle_t handle,
int * out_mv )

Read the averaged, calibrated wiper voltage.

Parameters
handleUnit handle from adc_pot_init().
[out]out_mvReceives the wiper voltage in millivolts.
Returns
ESP_OK on success; propagates the ADC read error.

◆ adc_pot_to_avrcp_volume()

uint8_t adc_pot_to_avrcp_volume ( int mv)

Map a wiper voltage to an AVRCP absolute-volume value (0..0x7F) for a Bluetooth sink.

Linear in the knob position: minimum -> 0 (silent), maximum -> 0x7F (loudest). Unlike adc_pot_to_volume(), there is no PCM5242 dB curve or -60 dB floor — the speaker applies its own curve, and the bottom of the knob reaches true silence.

Parameters
mvWiper voltage in millivolts.
Returns
The AVRCP absolute-volume value, 0..0x7F. Pure function, never fails.

◆ adc_pot_to_volume()

uint8_t adc_pot_to_volume ( int mv)

Map a wiper voltage to a PCM5242 digital-volume register byte.

0x00 = +24 dB (max), 0x30 = 0 dB, 0xFE = -103 dB, 0xFF = mute.

Parameters
mvWiper voltage in millivolts.
Returns
The digital-volume register byte. Pure function, never fails.