@@ -16,7 +16,7 @@ const char* ADC_TAG = "ADC";
16
16
static int16_t convert8DAC (int value, int value_bits_per_sample){
17
17
// -> convert to positive
18
18
int16_t result = (value * maxValue (8 ) / maxValue (value_bits_per_sample)) + maxValue (8 ) / 2 ;
19
- return result;
19
+ return result;
20
20
}
21
21
22
22
@@ -43,17 +43,20 @@ class AnalogConfig {
43
43
int mode_internal;
44
44
int bits_per_sample = 16 ;
45
45
int channels = 2 ;
46
+ bool auto_scale = true ;
46
47
47
- AnalogConfig () {
48
+ AnalogConfig (bool auto_scale = true ) {
48
49
this ->mode = RX_MODE;
50
+ this ->auto_scale = auto_scale;
49
51
setPin (DEFAUT_ADC_PIN);
50
52
mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
51
53
}
52
54
53
55
54
56
// / Default constructor
55
- AnalogConfig (RxTxMode mode) {
57
+ AnalogConfig (RxTxMode mode, bool auto_scale = true ) {
56
58
this ->mode = mode;
59
+ this ->auto_scale = auto_scale;
57
60
if (mode == RX_MODE) {
58
61
setPin (DEFAUT_ADC_PIN);
59
62
mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
@@ -216,7 +219,13 @@ class AnalogAudio {
216
219
// / writes the data to the I2S interface
217
220
size_t writeBytes (const void *src, size_t size_bytes){
218
221
size_t result = 0 ;
219
- result = AnalogAudio::writeExpandChannel (i2s_num, adc_config.channels , adc_config.bits_per_sample , src, size_bytes);
222
+ if (!adc_config.auto_scale ){
223
+ if (i2s_write (i2s_num, src, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
224
+ LOGE (" %s" , __func__);
225
+ }
226
+ } else {
227
+ result = AnalogAudio::writeExpandChannel (i2s_num, adc_config.channels , adc_config.bits_per_sample , src, size_bytes);
228
+ }
220
229
return result;
221
230
}
222
231
0 commit comments