ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
tas58xx.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
8#include "esphome/core/hal.h"
9#include "esphome/core/log.h"
10
11#ifdef USE_BINARY_SENSOR
13#endif
14
15namespace esphome::tas58xx {
16
17enum DacMode : uint8_t {
18 DAC_MODE_BTL = 0, // Bridge tied load, two speakers
19 DAC_MODE_PBTL = 1, // Parallel bridge tied load, one speaker
20};
21
29
56
57// compile time check
58static_assert(
60 "enum FaultSensor altered: Update FAULT_SENSORS in binary_sensor.py and fault_sensor_bits in each model's cpp");
61
63static constexpr uint8_t NO_BIT = 0xFF;
64
70struct ModelInfo {
71 const LogString *(*name)();
73 const uint8_t (*startup_sequence)[2];
77 uint8_t mixer_book;
78 uint8_t mixer_page;
88 const LogString *(*fault_name)(uint8_t index);
91};
92
93#ifdef USE_TAS58XX_TAS5805M
94extern const ModelInfo TAS5805M_MODEL;
95#endif
96#ifdef USE_TAS58XX_TAS5825M
97extern const ModelInfo TAS5825M_MODEL;
98#endif
99
101 public:
102 explicit TAS58xx(const ModelInfo *model) : model_(model) {}
103
104 void setup() override;
105 void dump_config() override;
106 float get_setup_priority() const override { return setup_priority::IO; }
107 void update() override;
108
111 void activate();
113 void deactivate();
114
115 bool set_mute_off() override { return this->set_mute_(false); }
116 bool set_mute_on() override { return this->set_mute_(true); }
117 bool set_volume(float volume) override;
118
119 bool is_muted() override { return this->is_muted_; }
120 float volume() override { return this->volume_; }
121
122 void on_audio_started() override;
123
124 void set_enable_pin(GPIOPin *enable_pin) { this->enable_pin_ = enable_pin; }
125 void set_analog_gain(float analog_gain_db) { this->analog_gain_db_ = analog_gain_db; }
126 void set_dac_mode(DacMode dac_mode) { this->dac_mode_ = dac_mode; }
127 void set_mixer_mode(MixerMode mixer_mode) { this->mixer_mode_ = mixer_mode; }
128 void set_volume_min_db(float volume_min_db) { this->volume_min_db_ = volume_min_db; }
129 void set_volume_max_db(float volume_max_db) { this->volume_max_db_ = volume_max_db; }
130
131#ifdef USE_BINARY_SENSOR
133 void set_fault_binary_sensor(FaultSensor fault, binary_sensor::BinarySensor *sensor) {
134 this->fault_binary_sensors_[fault] = sensor;
135 }
136#endif
137
138 protected:
139 bool select_book_page_(uint8_t book, uint8_t page);
140 bool init_();
141 bool write_ctrl_state_(uint8_t state, bool muted);
142 bool set_mute_(bool muted);
143 bool write_volume_();
144 bool write_mixer_();
145 bool read_faults_();
146
149#ifdef USE_BINARY_SENSOR
150 std::array<binary_sensor::BinarySensor *, FAULT_SENSOR_COUNT> fault_binary_sensors_{};
151#endif
152 float volume_{0};
153 float analog_gain_db_{-15.5f};
154 float volume_min_db_{-103.0f};
155 float volume_max_db_{24.0f};
156 uint32_t logged_faults_{0}; // Fault bits as last logged, packed like the fault masks
159 uint8_t ctrl_state_{0};
160 uint8_t power_state_{0xFF}; // Last POWER_STATE seen by update(), 0xFF until the first read
161 bool mixer_written_{false}; // Mixer written since the last reset
162};
163
164} // namespace esphome::tas58xx
This class simplifies creating components that periodically check a state.
Definition component.h:514
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
binary_sensor::BinarySensor * sensor
Definition tas58xx.h:133
void set_analog_gain(float analog_gain_db)
Definition tas58xx.h:125
SUB_BINARY_SENSOR(have_fault) void set_fault_binary_sensor(FaultSensor fault
void set_dac_mode(DacMode dac_mode)
Definition tas58xx.h:126
bool set_mute_(bool muted)
Definition tas58xx.cpp:280
void set_volume_min_db(float volume_min_db)
Definition tas58xx.h:128
void set_mixer_mode(MixerMode mixer_mode)
Definition tas58xx.h:127
float get_setup_priority() const override
Definition tas58xx.h:106
bool set_mute_off() override
Definition tas58xx.h:115
void set_enable_pin(GPIOPin *enable_pin)
Definition tas58xx.h:124
const ModelInfo * model_
Definition tas58xx.h:147
std::array< binary_sensor::BinarySensor *, FAULT_SENSOR_COUNT > fault_binary_sensors_
Definition tas58xx.h:150
void setup() override
Definition tas58xx.cpp:63
void update() override
Definition tas58xx.cpp:224
TAS58xx(const ModelInfo *model)
Definition tas58xx.h:102
bool is_muted() override
Definition tas58xx.h:119
void dump_config() override
Definition tas58xx.cpp:244
void set_volume_max_db(float volume_max_db)
Definition tas58xx.h:129
bool set_volume(float volume) override
Definition tas58xx.cpp:287
bool write_ctrl_state_(uint8_t state, bool muted)
Definition tas58xx.cpp:154
void activate()
Clear faults, leave deep sleep and switch to play; the device waits in Hi-Z until an I2S clock is pre...
Definition tas58xx.cpp:118
void deactivate()
Switch to deep sleep, the lowest power state that keeps I2C and the DSP running.
Definition tas58xx.cpp:142
float volume() override
Definition tas58xx.h:120
void on_audio_started() override
Definition tas58xx.cpp:215
bool set_mute_on() override
Definition tas58xx.h:116
bool select_book_page_(uint8_t book, uint8_t page)
Definition tas58xx.cpp:76
bool state
Definition fan.h:2
constexpr float IO
For components that represent GPIO pins like PCF8573.
Definition component.h:41
const ModelInfo TAS5805M_MODEL
const ModelInfo TAS5825M_MODEL
FaultSensor
Fault binary sensors that map to a single fault bit.
Definition tas58xx.h:32
@ FAULT_SENSOR_RIGHT_CHANNEL_OVER_CURRENT
Definition tas58xx.h:37
@ FAULT_SENSOR_LEFT_CHANNEL_CBC_OVER_CURRENT
Definition tas58xx.h:48
@ FAULT_SENSOR_BQ_WRITE_FAILED
Definition tas58xx.h:39
@ FAULT_SENSOR_RIGHT_CHANNEL_CBC_OVER_CURRENT_WARNING
Definition tas58xx.h:50
@ FAULT_SENSOR_OVER_TEMP_SHUTDOWN
Definition tas58xx.h:43
@ FAULT_SENSOR_LEFT_CHANNEL_DC_FAULT
Definition tas58xx.h:34
@ FAULT_SENSOR_RIGHT_CHANNEL_DC_FAULT
Definition tas58xx.h:35
@ FAULT_SENSOR_RIGHT_CHANNEL_CBC_OVER_CURRENT
Definition tas58xx.h:47
@ FAULT_SENSOR_OTP_CRC_CHECK
Definition tas58xx.h:38
@ FAULT_SENSOR_OVER_TEMP_WARNING
Definition tas58xx.h:44
@ FAULT_SENSOR_LEFT_CHANNEL_OVER_CURRENT
Definition tas58xx.h:36
@ FAULT_SENSOR_OVER_TEMP_146C_WARNING
Definition tas58xx.h:51
@ FAULT_SENSOR_PVDD_OVER_VOLTAGE
Definition tas58xx.h:41
@ FAULT_SENSOR_PVDD_UNDER_VOLTAGE
Definition tas58xx.h:42
@ FAULT_SENSOR_LOAD_EEPROM_ERROR
Definition tas58xx.h:46
@ FAULT_SENSOR_LEFT_CHANNEL_CBC_OVER_CURRENT_WARNING
Definition tas58xx.h:49
@ FAULT_SENSOR_CLOCK_FAULT
Definition tas58xx.h:40
@ MIXER_MODE_STEREO_INVERSE
Definition tas58xx.h:24
static void uint32_t
Everything that differs between models of the family.
Definition tas58xx.h:70
uint8_t fault_sensor_bits[FAULT_SENSOR_COUNT]
Bit index for each FaultSensor, NO_BIT used where the model does not have that fault bit.
Definition tas58xx.h:90
uint32_t fault_output_off_mask
Faults that keep the output off until cleared by activate()
Definition tas58xx.h:85
uint32_t fault_warning_mask
Faults logged as warnings.
Definition tas58xx.h:83
uint8_t mixer_book
Location of the four 9.23 fixed point input mixer coefficients: LEFT_TO_LEFT, RIGHT_TO_LEFT,...
Definition tas58xx.h:77
uint32_t fault_latched_mask
Faults that stay set after the condition is gone and are cleared after each read.
Definition tas58xx.h:87
const uint8_t(* startup_sequence)[2]
Remainder of the startup sequence, run after the reset, as {register, value} pairs in PROGMEM.
Definition tas58xx.h:73
uint32_t fault_error_mask
Faults logged as errors and reported by have_fault.
Definition tas58xx.h:81