TB2026-YDS Firmware
Loading...
Searching...
No Matches
volume.h File Reference

Volume service: maps the pot to whichever output is active (DAC, Bluetooth, or none). More...

#include "esp_err.h"
#include <stdint.h>

Go to the source code of this file.

Enumerations

enum  volume_output_t { VOLUME_OUT_NONE = 0 , VOLUME_OUT_DAC , VOLUME_OUT_BT }
 Where volume_poll() sends the knob level. More...

Functions

esp_err_t volume_init (void)
 Bring up the volume pot and push the current knob position to the DAC.
bool volume_poll (int *out_mv, uint8_t *out_level)
 Sample the pot and write the active output only if the mapped level changed.
bool volume_read_mv (int *out_mv)
 Read the pot wiper voltage without touching any output (for diagnostics).
void volume_set_output (volume_output_t out)
 Select which output volume_poll() drives. Default VOLUME_OUT_DAC.
volume_output_t volume_get_output (void)
 The output volume_poll() currently drives (see volume_set_output()).
void volume_set_fixed (int percent)
 Override the pot with a fixed volume (for a deterministic measurement).
void volume_clear_fixed (void)
 Release the fixed-volume override; the pot drives the level again from the next poll.
uint8_t volume_get_level (void)
 The level that would be applied to the active output under the current setting.
void volume_set_bt_handler (esp_err_t(*set_abs_vol)(uint8_t volume))
 Register the Bluetooth absolute-volume setter (e.g. bluetooth_set_absolute_volume).
void volume_set_balance (int8_t steps)
 Trim the L/R balance to compensate the analog imbalance (driver is independent L/R).
int8_t volume_get_balance (void)
 The current L/R balance trim in register steps (see volume_set_balance()).
void volume_save_balance (void)
 Persist the current balance trim to NVS so it survives a reboot.

Detailed Description

Volume service: maps the pot to whichever output is active (DAC, Bluetooth, or none).

Owns the volume potentiometer (ADC1, see ADC / Volume potentiometer) and routes the knob level to the selected output: the PCM5242 digital volume (with an L/R balance trim), the Bluetooth speaker over AVRCP, or nowhere. It only writes when the mapped level changes, so a still knob costs no I2C/AVRCP traffic, and it only ever touches the active output (power: no pointless writes to a silent path). Each output has its own scale: the DAC uses a dB register byte, Bluetooth a linear 0..0x7F (see ADC / Volume potentiometer); switching output re-applies the current knob position.

The Bluetooth setter is registered as a callback (volume_set_bt_handler) so this service does not hard-link the Bluetooth stack when BT is unused.

Not real-time: drive it from a periodic maintenance/UI loop via volume_poll(), not its own task.

Note
Développé avec l'assistance de Claude Opus 4.8 (Anthropic), sous la direction de Y. Dos Santos : spécification, revue et validation sur cible par l'auteur.

Enumeration Type Documentation

◆ volume_output_t

Where volume_poll() sends the knob level.

Enumerator
VOLUME_OUT_NONE 

No active output: sample the pot but send nothing.

VOLUME_OUT_DAC 

Wired jack via the PCM5242 digital volume (default).

VOLUME_OUT_BT 

Bluetooth speaker via AVRCP absolute volume.