Skip to content

Commit 7861a54

Browse files
committed
AudioDriverWM8978Class
1 parent 66eb2a0 commit 7861a54

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/Driver.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class CodecConfig : public codec_config_t {
187187
*/
188188
class AudioDriver {
189189
public:
190+
/// Starts the processing
190191
virtual bool begin(CodecConfig codecCfg, DriverPins &pins) {
191192
AD_LOGD("AudioDriver::begin:pins");
192193
p_pins = &pins;
@@ -201,6 +202,7 @@ class AudioDriver {
201202
setVolume(DRIVER_DEFAULT_VOLUME);
202203
return result;
203204
}
205+
/// changes the configuration
204206
virtual bool setConfig(CodecConfig codecCfg) {
205207
codec_cfg = codecCfg;
206208
if (!init(codec_cfg)) {
@@ -225,7 +227,9 @@ class AudioDriver {
225227
}
226228
return result;
227229
}
230+
/// Ends the processing: shut down dac and adc
228231
virtual bool end(void) { return deinit(); }
232+
/// Mutes all output lines
229233
virtual bool setMute(bool enable) = 0;
230234
/// Mute individual lines: only supported for some rare DACs
231235
virtual bool setMute(bool mute, int line) {
@@ -235,11 +239,15 @@ class AudioDriver {
235239

236240
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
237241
virtual bool setVolume(int volume) = 0;
242+
/// Determines the actual volume (range: 0-100)
238243
virtual int getVolume() = 0;
244+
/// Defines the input volume (range: 0-100) if supported
239245
virtual bool setInputVolume(int volume) { return false; }
246+
/// Determines if setVolume() is suppored
240247
virtual bool isVolumeSupported() { return true; }
248+
/// Determines if setInputVolume() is supported
241249
virtual bool isInputVolumeSupported() { return false; }
242-
250+
/// Provides the pin information
243251
DriverPins &pins() { return *p_pins; }
244252

245253
/// Sets the PA Power pin to active or inactive
@@ -1085,14 +1093,24 @@ class AudioDriverWM8978Class : public AudioDriver {
10851093

10861094
bool begin(CodecConfig codecCfg, DriverPins &pins) override {
10871095
bool rc = true;
1088-
codec_cfg = codecCfg;
10891096
auto i2c = pins.getI2CPins(PinFunction::CODEC);
10901097
if (!i2c) {
10911098
rc = wm8078.begin();
10921099
} else {
10931100
auto i2c_pins = i2c.value();
10941101
rc = wm8078.begin(i2c_pins.sda, i2c_pins.scl, i2c_pins.frequency);
10951102
}
1103+
1104+
setConfig(codecCfg);
1105+
1106+
// setup initial default volume
1107+
setVolume(DRIVER_DEFAULT_VOLUME);
1108+
1109+
return rc;
1110+
}
1111+
1112+
bool setConfig(CodecConfig codecCfg) override {
1113+
codec_cfg = codecCfg;
10961114
bool is_dac = codec_cfg.output_device != DAC_OUTPUT_NONE;
10971115
bool is_adc = codec_cfg.input_device != ADC_INPUT_NONE;
10981116
wm8078.cfgADDA(is_dac, is_adc);
@@ -1111,11 +1129,7 @@ class AudioDriverWM8978Class : public AudioDriver {
11111129
int i2s = toI2S(codecCfg.i2s.fmt);
11121130
if (i2s < 0) return false;
11131131
wm8078.cfgI2S(i2s, bits);
1114-
1115-
// setup initial default volume
1116-
setVolume(DRIVER_DEFAULT_VOLUME);
1117-
1118-
return rc;
1132+
return true;
11191133
}
11201134

11211135
bool end() override {

0 commit comments

Comments
 (0)