Skip to content

Commit 03c8ded

Browse files
committed
AudioDriverWM8960Class cleanup
1 parent 20fe361 commit 03c8ded

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/Driver.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,12 @@ class AudioDriverWM8960Class : public AudioDriver {
656656
}
657657
// define wire object
658658
mtb_wm8960_set_wire(i2c.value().p_wire);
659+
mtb_wm8960_set_write_retry_count(i2c_retry_count);
659660

660661
// setup wm8960
661-
if (!init(codecCfg)) {
662-
AD_LOGE("init");
662+
int features = getFeatures(codecCfg);
663+
if (!mtb_wm8960_init(features)) {
664+
AD_LOGE("mtb_wm8960_init");
663665
return false;
664666
}
665667
setVolume(DRIVER_DEFAULT_VOLUME);
@@ -683,14 +685,17 @@ class AudioDriverWM8960Class : public AudioDriver {
683685

684686
/// Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
685687
bool setVolume(int volume) {
686-
setOutputVolume(volume);
687-
return true;
688-
};
688+
volume_out = limitValue(volume, 0, 100);
689+
int vol_int = volume_out == 0.0 ? 0 : map(volume_out, 0, 100, 30, 0x7F);
690+
return mtb_wm8960_set_output_volume(vol_int);
691+
}
692+
689693
int getVolume() { return volume_out; }
690694

691695
bool setInputVolume(int volume) {
692-
adjustInputVolume(volume);
693-
return true;
696+
volume_in = limitValue(volume, 0, 100);
697+
int vol_int = map(volume_in, 0, 100, 0, 30);
698+
return mtb_wm8960_adjust_input_volume(vol_int);
694699
}
695700
bool isVolumeSupported() { return true; }
696701

@@ -707,27 +712,18 @@ class AudioDriverWM8960Class : public AudioDriver {
707712
vs1053_mclk_hz = hz;
708713
}
709714

715+
void dumpRegisters() {
716+
mtb_wm8960_dump();
717+
}
718+
710719
protected:
711720
int volume_in = 100;
712721
int volume_out = 100;
713722
int i2c_retry_count = 0;
714723
uint32_t vs1053_mclk_hz = 0;
715724
bool vs1053_enable_pll = true;
716725

717-
void adjustInputVolume(int vol) {
718-
volume_in = limitValue(vol, 0, 100);
719-
int vol_int = map(volume_in, 0, 100, 0, 30);
720-
mtb_wm8960_adjust_input_volume(vol_int);
721-
}
722-
723-
void setOutputVolume(int vol) {
724-
volume_out = limitValue(vol, 0, 100);
725-
int vol_int = volume_out == 0.0 ? 0 : map(volume_out, 0, 100, 30, 0x7F);
726-
mtb_wm8960_set_output_volume(vol_int);
727-
}
728-
729-
bool init(CodecConfig cfg) {
730-
mtb_wm8960_set_write_retry_count(i2c_retry_count);
726+
int getFeatures(CodecConfig cfg) {
731727
int features = 0;
732728
switch (cfg.dac_output) {
733729
case DAC_OUTPUT_LINE1:
@@ -756,8 +752,8 @@ class AudioDriverWM8960Class : public AudioDriver {
756752
default:
757753
break;
758754
}
759-
AD_LOGW("Setup features: %d", features);
760-
return mtb_wm8960_init(features);
755+
AD_LOGI("features: %d", features);
756+
return features;
761757
}
762758

763759
bool configure_clocking() {
@@ -821,11 +817,9 @@ class AudioDriverWM8960Class : public AudioDriver {
821817
}
822818

823819
/// if microcontroller is master then module is slave
824-
mtb_wm8960_mode_t modeMasterSlave(bool microcontroller_is_master) {
825-
return microcontroller_is_master ? WM8960_MODE_SLAVE : WM8960_MODE_MASTER;
820+
mtb_wm8960_mode_t modeMasterSlave(bool is_master) {
821+
return is_master ? WM8960_MODE_MASTER : WM8960_MODE_SLAVE;
826822
}
827-
828-
void volumeError(float vol) { AD_LOGE("Invalid volume %f", vol); }
829823
};
830824

831825
/**

0 commit comments

Comments
 (0)