Skip to content

Commit a7ffd76

Browse files
committed
singal_t for TDM
1 parent 0d0fd38 commit a7ffd76

File tree

4 files changed

+99
-57
lines changed

4 files changed

+99
-57
lines changed

src/Driver.h

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,12 @@ class CodecConfig : public codec_config_t {
193193
*/
194194
class AudioDriver {
195195
public:
196-
197196
/// Starts the processing
198197
virtual bool begin(CodecConfig codecCfg, DriverPins &pins) {
199198
AD_LOGI("AudioDriver::begin");
200199
p_pins = &pins;
201200
pins.setSPIActiveForSD(codecCfg.sd_active);
202-
if (!setConfig(codecCfg)){
201+
if (!setConfig(codecCfg)) {
203202
AD_LOGE("setConfig has failed");
204203
return false;
205204
}
@@ -215,17 +214,17 @@ class AudioDriver {
215214
if (!init(codec_cfg)) {
216215
AD_LOGE("AudioDriver init failed");
217216
return false;
218-
}
217+
}
219218
codec_mode_t codec_mode = codec_cfg.get_mode();
220219
if (!controlState(codec_mode)) {
221220
AD_LOGE("AudioDriver controlState failed");
222221
return false;
223-
}
222+
}
224223
bool result = configInterface(codec_mode, codec_cfg.i2s);
225224
if (!result) {
226225
AD_LOGE("AudioDriver configInterface failed");
227226
return false;
228-
}
227+
}
229228
return result;
230229
}
231230
/// Ends the processing: shut down dac and adc
@@ -258,7 +257,7 @@ class AudioDriver {
258257
if (p_pins == nullptr) {
259258
AD_LOGI("pins are null");
260259
return false;
261-
}
260+
}
262261
GpioPin pin = pins().getPinID(PinFunction::PA);
263262
if (pin == -1) {
264263
AD_LOGI("PinFunction::PA not defined");
@@ -269,7 +268,7 @@ class AudioDriver {
269268
return true;
270269
}
271270

272-
operator bool() {return p_pins != nullptr;}
271+
operator bool() { return p_pins != nullptr; }
273272

274273
protected:
275274
CodecConfig codec_cfg;
@@ -282,7 +281,7 @@ class AudioDriver {
282281
if (!i2c) {
283282
return &Wire;
284283
}
285-
TwoWire* result = i2c.value().p_wire;
284+
TwoWire *result = i2c.value().p_wire;
286285
return result != nullptr ? result : &Wire;
287286
}
288287

@@ -321,8 +320,8 @@ class AudioDriver {
321320
class NoDriverClass : public AudioDriver {
322321
public:
323322
virtual bool begin(CodecConfig codecCfg, DriverPins &pins) {
324-
//codec_cfg = codecCfg;
325-
//p_pins = &pins;
323+
// codec_cfg = codecCfg;
324+
// p_pins = &pins;
326325
return true;
327326
}
328327
virtual bool end(void) { return true; }
@@ -331,7 +330,9 @@ class NoDriverClass : public AudioDriver {
331330
virtual int getVolume() { return 100; }
332331
virtual bool setInputVolume(int volume) { return false; }
333332
virtual bool isVolumeSupported() {
334-
{ return false; }
333+
{
334+
return false;
335+
}
335336
}
336337
virtual bool isInputVolumeSupported() { return false; }
337338
};
@@ -774,7 +775,7 @@ class AudioDriverES8311Class : public AudioDriver {
774775
// determine address from data
775776
if (i2c_address <= 0) i2c_address = getI2CAddress();
776777

777-
assert(getI2C()!=nullptr);
778+
assert(getI2C() != nullptr);
778779
return es8311_codec_init(&codec_cfg, getI2C(), mclk_src, i2c_address) ==
779780
RESULT_OK;
780781
}
@@ -1379,29 +1380,43 @@ class AudioDriverPCM3168Class : public AudioDriver {
13791380
PCM3168::FMT fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
13801381
switch (iface.bits) {
13811382
case BIT_LENGTH_16BITS:
1382-
if (iface.fmt!= I2S_RIGHT) {
1383+
if (iface.fmt != I2S_RIGHT) {
13831384
AD_LOGW("Only I2S_RIGHT is supported for 16 bits");
13841385
}
13851386
fmt = PCM3168::FMT::Right16bit;
13861387
break;
13871388
case BIT_LENGTH_32BITS:
13881389
case BIT_LENGTH_24BITS:
1389-
switch (iface.fmt) {
1390-
case I2S_NORMAL:
1391-
fmt = PCM3168::FMT::I2S24bit;
1392-
break;
1393-
case I2S_LEFT:
1394-
fmt = PCM3168::FMT::Left24bit;
1395-
break;
1396-
case I2S_RIGHT:
1397-
fmt = PCM3168::FMT::Right24bit;
1398-
break;
1399-
case I2S_DSP:
1400-
fmt = PCM3168::FMT::LeftDSP24bit;
1401-
break;
1402-
case I2S_TDM:
1403-
fmt = PCM3168::FMT::I2SHighSpeedTDM24bit;
1404-
break;
1390+
if (iface.singal_type == TDM) {
1391+
switch (iface.fmt) {
1392+
case I2S_NORMAL:
1393+
fmt = PCM3168::FMT::I2STDM24bit;
1394+
break;
1395+
case I2S_LEFT:
1396+
fmt = PCM3168::FMT::LeftTDM24bit;
1397+
break;
1398+
default:
1399+
AD_LOGE("Unsupported fmt for tdm");
1400+
return false;
1401+
}
1402+
} else {
1403+
switch (iface.fmt) {
1404+
case I2S_NORMAL:
1405+
fmt = PCM3168::FMT::I2S24bit;
1406+
break;
1407+
case I2S_LEFT:
1408+
fmt = PCM3168::FMT::Left24bit;
1409+
break;
1410+
case I2S_RIGHT:
1411+
fmt = PCM3168::FMT::Right24bit;
1412+
break;
1413+
case I2S_DSP:
1414+
fmt = PCM3168::FMT::LeftDSP24bit;
1415+
break;
1416+
default:
1417+
AD_LOGE("Unsupported fmt");
1418+
return false;
1419+
}
14051420
}
14061421
break;
14071422
default:
@@ -1426,7 +1441,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14261441
codec_cfg = codecCfg;
14271442

14281443
// setup SPI for SD
1429-
//pins.setSPIActiveForSD(codecCfg.sd_active);
1444+
// pins.setSPIActiveForSD(codecCfg.sd_active);
14301445

14311446
bool ok = true;
14321447

@@ -1438,7 +1453,7 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14381453
setVolume(DRIVER_DEFAULT_VOLUME);
14391454

14401455
// Start ES7243
1441-
if (codecCfg.input_device != ADC_INPUT_NONE){
1456+
if (codecCfg.input_device != ADC_INPUT_NONE) {
14421457
AD_LOGI("starting ES7243");
14431458
adc.setPins(this->pins());
14441459
ok = ok && adc.setConfig(codecCfg);
@@ -1455,11 +1470,11 @@ class AudioDriverLyratMiniClass : public AudioDriver {
14551470
rc += adc.end();
14561471
return rc == 2;
14571472
}
1458-
bool setMute(bool enable) override { return dac.setMute(enable); }
1459-
bool setVolume(int volume) override { return dac.setVolume(volume); }
1460-
int getVolume() override { return dac.getVolume(); }
1473+
bool setMute(bool enable) override { return dac.setMute(enable); }
1474+
bool setVolume(int volume) override { return dac.setVolume(volume); }
1475+
int getVolume() override { return dac.getVolume(); }
14611476
bool setInputVolume(int volume) override { return adc.setVolume(volume); }
1462-
int getInputVolume() { return adc.getVolume(); }
1477+
int getInputVolume() { return adc.getVolume(); }
14631478
bool isInputVolumeSupported() override { return true; }
14641479

14651480
protected:

src/Driver/cs42448/cs42448.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
*
2525
*/
2626
#pragma once
27-
#include "DriverCommon.h"
2827
#include "Driver/DriverConstants.h"
28+
#include "DriverCommon.h"
2929
#include "Utils/I2C.h"
3030

3131
/*
@@ -154,7 +154,7 @@ class CS42448 {
154154
this->i2c_address = i2cAddress;
155155
}
156156

157-
if (is_active){
157+
if (is_active) {
158158
setMuteADC(true);
159159
setMuteDAC(true);
160160
}
@@ -556,29 +556,29 @@ class CS42448 {
556556

557557
/// Set I2S format based on codec_config
558558
bool setFormat() {
559-
switch (codec_config.i2s.fmt) {
560-
case I2S_NORMAL:
561-
return setFormat(Format::I2S);
562-
case I2S_LEFT:
563-
return setFormat(Format::LeftJustified24Bit);
564-
case I2S_RIGHT:
565-
Format fmt;
566-
if (codec_config.i2s.bits == BIT_LENGTH_16BITS) {
567-
fmt = Format::RightJustified16Bits;
568-
} else if (codec_config.i2s.bits == BIT_LENGTH_16BITS) {
569-
fmt = Format::RightJustified24Bits;
570-
} else
559+
if (codec_config.i2s.singal_type == singal_t::TDM) {
560+
return setFormat(Format::TDM);
561+
} else {
562+
switch (codec_config.i2s.fmt) {
563+
case I2S_NORMAL:
564+
return setFormat(Format::I2S);
565+
case I2S_LEFT:
566+
return setFormat(Format::LeftJustified24Bit);
567+
case I2S_RIGHT:
568+
Format fmt;
569+
if (codec_config.i2s.bits == BIT_LENGTH_16BITS) {
570+
fmt = Format::RightJustified16Bits;
571+
} else if (codec_config.i2s.bits == BIT_LENGTH_16BITS) {
572+
fmt = Format::RightJustified24Bits;
573+
} else
574+
return false;
575+
return setFormat(fmt);
576+
default:
571577
return false;
572-
return setFormat(fmt);
573-
case I2S_TDM:
574-
return setFormat(Format::TDM);
575-
default:
576-
return false;
578+
}
577579
}
578580
}
579581

580-
581-
582582
bool writeReg(uint8_t reg, uint8_t value) { return writeReg(reg, &value, 1); }
583583

584584
bool writeReg(uint8_t reg, uint8_t* value, int len) {

src/Driver/es7210/es7210.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ error_t es7210_adc_init(codec_config_t *codec_cfg, void* i2c)
323323
ret |= es7210_config_sample(i2s_cfg->rate);
324324
ret |= es7210_mic_select(mic_select);
325325
ret |= es7210_adc_set_gain(ES7210_GAIN_30DB);
326+
327+
// set REG12
328+
uint8_t reg12 = 0;
329+
if (i2s_cfg->singal_type == TDM) {
330+
reg12 = 0x02; // TDM I2S
331+
}
332+
ret |= es7210_write_reg(ES7210_SDP_INTERFACE2_REG12, reg12);
333+
326334
return RESULT_OK;
327335
}
328336

@@ -335,8 +343,10 @@ error_t es7210_config_fmt(i2s_format_t fmt)
335343
{
336344
error_t ret = RESULT_OK;
337345
uint8_t adc_iface = 0;
346+
338347
adc_iface = es7210_read_reg(ES7210_SDP_INTERFACE1_REG11);
339348
adc_iface &= 0xfc;
349+
340350
switch (fmt) {
341351
case I2S_NORMAL:
342352
AD_LOGD( "ES7210 in I2S Format");

src/DriverCommon.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,22 @@ typedef enum {
116116
I2S_LEFT = 1, /*!< set all left format */
117117
I2S_RIGHT = 2, /*!< set all right format */
118118
I2S_DSP = 3, /*!< set dsp/pcm format */
119-
I2S_TDM = 4, /*!< set tdm format */
120119
} i2s_format_t;
121120

121+
/**
122+
* @enum singal_t
123+
* @brief Usually the value is digital for i2s
124+
* @ingroup enumerations
125+
*/
126+
127+
typedef enum {
128+
DIGITAL,
129+
AMALOG,
130+
PDM,
131+
TDM,
132+
} singal_t;
133+
134+
122135
/**
123136
* @enum es_mic_gain_t
124137
* @brief Microphone Gain
@@ -165,6 +178,7 @@ typedef enum {
165178
CHANNELS16 = 16,
166179
} channels_t;
167180

181+
168182
/**
169183
* @brief I2s interface configuration for audio codec chip
170184
* @ingroup audio_driver
@@ -181,6 +195,9 @@ typedef struct {
181195
sample_bits_t bits;
182196
/*!< i2s number of channels */
183197
channels_t channels;
198+
/*!< signal tpye */
199+
singal_t singal_type;
200+
184201
} I2SDefinition;
185202

186203
/**

0 commit comments

Comments
 (0)