1
1
2
2
#pragma once
3
- #include " DriverCommon.h"
4
3
#include " Driver/ac101/ac101.h"
5
4
#include " Driver/ad1938/ad1938.h"
6
5
#include " Driver/cs42448/cs42448.h"
12
11
#include " Driver/es8311/es8311.h"
13
12
#include " Driver/es8374/es8374.h"
14
13
#include " Driver/es8388/es8388.h"
14
+ #include " Driver/pcm3168/pcm3168.h"
15
15
#include " Driver/tas5805m/tas5805m.h"
16
16
#include " Driver/wm8960/mtb_wm8960.h"
17
17
#include " Driver/wm8978/WM8978.h"
18
18
#include " Driver/wm8994/wm8994.h"
19
+ #include " DriverCommon.h"
19
20
#include " DriverPins.h"
20
21
21
22
namespace audio_driver {
@@ -120,7 +121,7 @@ class CodecConfig : public codec_config_t {
120
121
i2s.channels = (channels_t )channels;
121
122
return true ;
122
123
default :
123
- AD_LOGE (" Channels not supported: %d - using %d" , channels,2 );
124
+ AD_LOGE (" Channels not supported: %d - using %d" , channels, 2 );
124
125
i2s.channels = CHANNELS2;
125
126
return false ;
126
127
}
@@ -264,7 +265,7 @@ class AudioDriver {
264
265
}
265
266
266
267
// / Gets the number of I2S Interfaces
267
- virtual int getI2SCount () { return 1 ;}
268
+ virtual int getI2SCount () { return 1 ; }
268
269
269
270
protected:
270
271
CodecConfig codec_cfg;
@@ -674,7 +675,8 @@ class AudioDriverES7243eClass : public AudioDriver {
674
675
}
675
676
bool setVolume (int volume) {
676
677
this ->volume = volume;
677
- return es7243e_adc_set_voice_volume (limitValue (volume, 0 , 100 )) == RESULT_OK;
678
+ return es7243e_adc_set_voice_volume (limitValue (volume, 0 , 100 )) ==
679
+ RESULT_OK;
678
680
}
679
681
int getVolume () {
680
682
int vol;
@@ -710,7 +712,8 @@ class AudioDriverES8156Class : public AudioDriver {
710
712
}
711
713
bool setVolume (int volume) {
712
714
AD_LOGD (" volume %d" , volume);
713
- return es8156_codec_set_voice_volume (limitValue (volume, 0 , 100 )) == RESULT_OK;
715
+ return es8156_codec_set_voice_volume (limitValue (volume, 0 , 100 )) ==
716
+ RESULT_OK;
714
717
}
715
718
int getVolume () {
716
719
int vol;
@@ -742,7 +745,8 @@ class AudioDriverES8311Class : public AudioDriver {
742
745
AudioDriverES8311Class (int i2cAddr = 0 ) { i2c_address = i2cAddr; }
743
746
bool setMute (bool mute) { return es8311_set_voice_mute (mute) == RESULT_OK; }
744
747
bool setVolume (int volume) {
745
- return es8311_codec_set_voice_volume (limitValue (volume, 0 , 100 )) == RESULT_OK;
748
+ return es8311_codec_set_voice_volume (limitValue (volume, 0 , 100 )) ==
749
+ RESULT_OK;
746
750
}
747
751
int getVolume () {
748
752
int vol;
@@ -756,8 +760,10 @@ class AudioDriverES8311Class : public AudioDriver {
756
760
bool init (codec_config_t codec_cfg) {
757
761
int mclk_src = pins ().getPinID (PinFunction::MCLK_SOURCE);
758
762
if (mclk_src == -1 ) {
759
- AD_LOGI (" Pin for PinFunction::MCLK_SOURCE not defined: we assume FROM_MCLK_PIN" );
760
- mclk_src = 0 ; // = FROM_MCLK_PIN;
763
+ AD_LOGI (
764
+ " Pin for PinFunction::MCLK_SOURCE not defined: we assume "
765
+ " FROM_MCLK_PIN" );
766
+ mclk_src = 0 ; // = FROM_MCLK_PIN;
761
767
}
762
768
763
769
// determine address from data
@@ -787,7 +793,8 @@ class AudioDriverES8374Class : public AudioDriver {
787
793
bool setMute (bool mute) { return es8374_set_voice_mute (mute) == RESULT_OK; }
788
794
bool setVolume (int volume) {
789
795
AD_LOGD (" volume %d" , volume);
790
- return es8374_codec_set_voice_volume (limitValue (volume, 0 , 100 )) == RESULT_OK;
796
+ return es8374_codec_set_voice_volume (limitValue (volume, 0 , 100 )) ==
797
+ RESULT_OK;
791
798
}
792
799
int getVolume () {
793
800
int vol;
@@ -860,25 +867,26 @@ class AudioDriverES8388Class : public AudioDriver {
860
867
bool setInputVolume (int volume) {
861
868
// map values from 0 - 100 to 0 to 8
862
869
863
- // es_mic_gain_t: MIC_GAIN_MIN = -1, 0,3,6,9,12,15,18,21,24 MIC_GAIN_MAX = 25
870
+ // es_mic_gain_t: MIC_GAIN_MIN = -1, 0,3,6,9,12,15,18,21,24 MIC_GAIN_MAX =
871
+ // 25
864
872
865
873
// Vol: 0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100
866
874
// idx: 0, 1, 2, 3, 4, 5, 6, 7, 8
867
875
// dB/gain: 0, 3, 6, 9, 12, 15, 18, 21, 24
868
876
// factor: 1, 2, 4, 8, 16, 32, 63, 126, 252
869
877
870
878
// es8388 Register 9 – ADC Control 1
871
- // dB MicL MicR
879
+ // dB MicL MicR
872
880
// 0 0000 0000
873
881
// 3 0001 0001
874
882
// 6 0010 0010
875
883
// 9 0011 0011
876
- // 12 0100 0100
877
- // 15 0101 0101
878
- // 18 0110 0110
879
- // 21 0111 0111
880
- // 24 1000 1000
881
-
884
+ // 12 0100 0100
885
+ // 15 0101 0101
886
+ // 18 0110 0110
887
+ // 21 0111 0111
888
+ // 24 1000 1000
889
+
882
890
es_mic_gain_t gains[] = {MIC_GAIN_0DB, MIC_GAIN_3DB, MIC_GAIN_6DB,
883
891
MIC_GAIN_9DB, MIC_GAIN_12DB, MIC_GAIN_15DB,
884
892
MIC_GAIN_18DB, MIC_GAIN_21DB, MIC_GAIN_24DB};
@@ -887,7 +895,8 @@ class AudioDriverES8388Class : public AudioDriver {
887
895
int idx = map (vol, 0 , 100 , 0 , 8 );
888
896
889
897
es_mic_gain_t gain = gains[idx];
890
- AD_LOGD (" input volume: %d -> gain %d [dB] (idx: %d of 0..8)" , volume, gain, idx);
898
+ AD_LOGD (" input volume: %d -> gain %d [dB] (idx: %d of 0..8)" , volume, gain,
899
+ idx);
891
900
return setMicrophoneGain (gain);
892
901
}
893
902
@@ -1140,7 +1149,7 @@ class AudioDriverWM8978Class : public AudioDriver {
1140
1149
1141
1150
return rc;
1142
1151
}
1143
-
1152
+
1144
1153
bool setConfig (CodecConfig codecCfg) override {
1145
1154
codec_cfg = codecCfg;
1146
1155
bool is_dac = codec_cfg.output_device != DAC_OUTPUT_NONE;
@@ -1326,6 +1335,78 @@ class AudioDriverWM8994Class : public AudioDriver {
1326
1335
}
1327
1336
};
1328
1337
1338
+ /* *
1339
+ * @brief Driver API for the CS43l22 codec chip on 0x94 (0x4A<<1)
1340
+ * @author Phil Schatzmann
1341
+ * @copyright GPLv3
1342
+ */
1343
+ class AudioDriverPCM3168Class : public AudioDriver {
1344
+ public:
1345
+ AudioDriverPCM3168Class () = default ;
1346
+
1347
+ bool setMute (bool mute) { return driver.setMute (mute); }
1348
+
1349
+ bool setMute (bool mute, int line) { return driver.setMute (line, mute); }
1350
+
1351
+ bool setVolume (int vol) {
1352
+ volume = vol;
1353
+ return driver.setVolume (100.0 * vol);
1354
+ }
1355
+ int getVolume () { return volume; }
1356
+
1357
+ protected:
1358
+ int volume;
1359
+ PCM3168 driver;
1360
+
1361
+ bool init (codec_config_t codec_cfg) {
1362
+ driver.setWire (*getI2C ());
1363
+ driver.setAddress (getI2CAddress ());
1364
+ return true ;
1365
+ }
1366
+ bool deinit () { return driver.end (); }
1367
+ bool controlState (codec_mode_t mode) { return true ; }
1368
+ bool configInterface (codec_mode_t mode, I2SDefinition iface) {
1369
+ if (iface.mode == MODE_MASTER) {
1370
+ AD_LOGE (" Only slave is supported: MCU must be master" );
1371
+ return false ;
1372
+ }
1373
+ PCM3168::FMT fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
1374
+ switch (iface.bits ) {
1375
+ case BIT_LENGTH_16BITS:
1376
+ if (iface.fmt != I2S_RIGHT) {
1377
+ AD_LOGW (" Only I2S_RIGHT is supported for 16 bits" );
1378
+ }
1379
+ fmt = PCM3168::FMT::Right16bit;
1380
+ break ;
1381
+ case BIT_LENGTH_32BITS:
1382
+ case BIT_LENGTH_24BITS:
1383
+ switch (iface.fmt ) {
1384
+ case I2S_NORMAL:
1385
+ fmt = PCM3168::FMT::I2S24bit;
1386
+ break ;
1387
+ case I2S_LEFT:
1388
+ fmt = PCM3168::FMT::Left24bit;
1389
+ break ;
1390
+ case I2S_RIGHT:
1391
+ fmt = PCM3168::FMT::Right24bit;
1392
+ break ;
1393
+ case I2S_DSP:
1394
+ fmt = PCM3168::FMT::LeftDSP24bit;
1395
+ break ;
1396
+ case I2S_TDM:
1397
+ fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
1398
+ break ;
1399
+ }
1400
+ break ;
1401
+ default :
1402
+ AD_LOGE (" Unsupported bits" );
1403
+ return false ;
1404
+ }
1405
+
1406
+ return driver.begin (fmt);
1407
+ }
1408
+ };
1409
+
1329
1410
/* *
1330
1411
* @brief Driver API for Lyrat Mini with a ES8311 and a ES7243 codec chip
1331
1412
* @author Phil Schatzmann
@@ -1353,8 +1434,8 @@ class AudioDriverLyratMiniClass : public AudioDriver {
1353
1434
bool setInputVolume (int volume) { return adc.setVolume (volume); }
1354
1435
int getInputVolume () { return adc.getVolume (); }
1355
1436
bool isInputVolumeSupported () { return true ; }
1356
- // Separate ADC and DAC I2S
1357
- int getI2SCount () override { return 2 ;}
1437
+ // Separate ADC and DAC I2S
1438
+ int getI2SCount () override { return 2 ; }
1358
1439
1359
1440
protected:
1360
1441
AudioDriverES8311Class dac;
@@ -1394,5 +1475,6 @@ static NoDriverClass NoDriver;
1394
1475
static AudioDriverAD1938Class AudioDriverAD1938;
1395
1476
// / @ingroup audio_driver
1396
1477
static AudioDriverCS42448Class AudioDriverCS42448;
1397
-
1478
+ // / @ingroup audio_driver
1479
+ static AudioDriverPCM3168Class AudioDriverPCM3168;
1398
1480
} // namespace audio_driver
0 commit comments