@@ -656,10 +656,12 @@ class AudioDriverWM8960Class : public AudioDriver {
656
656
}
657
657
// define wire object
658
658
mtb_wm8960_set_wire (i2c.value ().p_wire );
659
+ mtb_wm8960_set_write_retry_count (i2c_retry_count);
659
660
660
661
// 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" );
663
665
return false ;
664
666
}
665
667
setVolume (DRIVER_DEFAULT_VOLUME);
@@ -683,14 +685,17 @@ class AudioDriverWM8960Class : public AudioDriver {
683
685
684
686
// / Defines the Volume (in %) if volume is 0, mute is enabled,range is 0-100.
685
687
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
+
689
693
int getVolume () { return volume_out; }
690
694
691
695
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);
694
699
}
695
700
bool isVolumeSupported () { return true ; }
696
701
@@ -707,27 +712,18 @@ class AudioDriverWM8960Class : public AudioDriver {
707
712
vs1053_mclk_hz = hz;
708
713
}
709
714
715
+ void dumpRegisters () {
716
+ mtb_wm8960_dump ();
717
+ }
718
+
710
719
protected:
711
720
int volume_in = 100 ;
712
721
int volume_out = 100 ;
713
722
int i2c_retry_count = 0 ;
714
723
uint32_t vs1053_mclk_hz = 0 ;
715
724
bool vs1053_enable_pll = true ;
716
725
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) {
731
727
int features = 0 ;
732
728
switch (cfg.dac_output ) {
733
729
case DAC_OUTPUT_LINE1:
@@ -756,8 +752,8 @@ class AudioDriverWM8960Class : public AudioDriver {
756
752
default :
757
753
break ;
758
754
}
759
- AD_LOGW ( " Setup features: %d" , features);
760
- return mtb_wm8960_init ( features) ;
755
+ AD_LOGI ( " features: %d" , features);
756
+ return features;
761
757
}
762
758
763
759
bool configure_clocking () {
@@ -821,11 +817,9 @@ class AudioDriverWM8960Class : public AudioDriver {
821
817
}
822
818
823
819
// / 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 ;
826
822
}
827
-
828
- void volumeError (float vol) { AD_LOGE (" Invalid volume %f" , vol); }
829
823
};
830
824
831
825
/* *
0 commit comments