From 1079a58e08a1a22d9421537962288ce7dea387c4 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Tue, 3 Oct 2023 13:38:58 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20doxygen=20from=20@=20pschatzma?= =?UTF-8?q?nn/arduino-audio-tools@8664054d44bfdbc46a75e7101c9dc7b16a267fc4?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _analog_audio_e_s_p32_8h_source.html | 420 ++++++++++++++------------- 1 file changed, 211 insertions(+), 209 deletions(-) diff --git a/_analog_audio_e_s_p32_8h_source.html b/_analog_audio_e_s_p32_8h_source.html index 0eb4dae09b..5b2f48c8ae 100644 --- a/_analog_audio_e_s_p32_8h_source.html +++ b/_analog_audio_e_s_p32_8h_source.html @@ -197,220 +197,222 @@
135 
137  void end() override {
138  LOGI(__func__);
-
139  i2s_zero_dma_buffer(port_no);
-
140 
-
141  // close ADC
-
142  if (adc_config.rx_tx_mode == RX_MODE){
-
143  i2s_adc_disable(port_no);
-
144  }
-
145  if (adc_config.uninstall_driver_on_end){
-
146  i2s_driver_uninstall(port_no);
-
147  is_driver_installed = false;
-
148  } else {
-
149  i2s_stop(port_no);
-
150  }
-
151  active = false;
-
152  }
-
153 
-
154  // /// Overides the sample rate and uses the max value which is around ~13MHz. Call this methd after begin();
-
155  // void setMaxSampleRate() {
-
156  // //this is the hack that enables the highest sampling rate possible ~13MHz, have fun
-
157  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_A_V, 1, I2S_CLKM_DIV_A_S);
-
158  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_B_V, 1, I2S_CLKM_DIV_B_S);
-
159  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_NUM_V, 1, I2S_CLKM_DIV_NUM_S);
-
160  // SET_PERI_REG_BITS(I2S_SAMPLE_RATE_CONF_REG(0), I2S_TX_BCK_DIV_NUM_V, 1, I2S_TX_BCK_DIV_NUM_S);
-
161  // }
-
162 
-
164  size_t write(const uint8_t *src, size_t size_bytes) override {
-
165  TRACED();
-
166 
-
167  size_t result = 0;
-
168  if (size_bytes>0 && src!=nullptr){
-
169  switch(adc_config.channels){
-
170  case 1:
-
171  result = outputMono(src, size_bytes);
-
172  break;
-
173  case 2:
-
174  result = outputStereo(src, size_bytes);
-
175  break;
-
176  default:
-
177  LOGE("Unsupported number of channels: %d", adc_config.channels);
-
178  stop();
-
179  }
-
180  LOGD("converted write size: %d",result);
-
181  }
-
182  return size_bytes;
-
183  }
-
184 
-
185  size_t readBytes(uint8_t *dest, size_t size_bytes) override {
-
186  TRACED();
-
187  size_t result = 0;
-
188  if (i2s_read(port_no, dest, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
-
189  TRACEE();
-
190  }
-
191  // make sure that the center is at 0
-
192  if (adc_config.is_auto_center_read){
-
193  auto_center.convert(dest, result);
-
194  }
-
195  LOGD( "%s - len: %d -> %d", __func__, size_bytes, result);
-
196  return result;
-
197  }
-
198 
-
199  virtual int available() override {
-
200  return active ? adc_config.buffer_size*adc_config.buffer_count : 0;
-
201  }
-
202 
-
203  protected:
-
204  AnalogConfig adc_config;
-
205  ConverterAutoCenter auto_center;
-
206  i2s_port_t port_no;
-
207  bool active = false;
-
208  bool is_driver_installed = false;
-
209  size_t result=0;
-
210 
-
211  // input values
-
212  adc_unit_t adc_unit;
-
213  adc1_channel_t adc_channel;
-
214 
-
216  void setupInputPin(int gpio){
-
217  TRACED();
-
218 
-
219  switch(gpio){
-
220  case 32:
-
221  adc_unit = ADC_UNIT_1;
-
222  adc_channel = ADC1_GPIO32_CHANNEL;
-
223  break;
-
224  case 33:
-
225  adc_unit = ADC_UNIT_1;
-
226  adc_channel = ADC1_GPIO33_CHANNEL;
-
227  break;
-
228  case 34:
-
229  adc_unit = ADC_UNIT_1;
-
230  adc_channel = ADC1_GPIO34_CHANNEL;
-
231  break;
-
232  case 35:
-
233  adc_unit = ADC_UNIT_1;
-
234  adc_channel = ADC1_GPIO35_CHANNEL;
-
235  break;
-
236  case 36:
-
237  adc_unit = ADC_UNIT_1;
-
238  adc_channel = ADC1_GPIO36_CHANNEL;
-
239  break;
-
240  case 37:
-
241  adc_unit = ADC_UNIT_1;
-
242  adc_channel = ADC1_GPIO37_CHANNEL;
-
243  break;
-
244  case 38:
-
245  adc_unit = ADC_UNIT_1;
-
246  adc_channel = ADC1_GPIO38_CHANNEL;
-
247  break;
-
248  case 39:
-
249  adc_unit = ADC_UNIT_1;
-
250  adc_channel = ADC1_GPIO39_CHANNEL;
-
251  break;
-
252 
-
253  default:
-
254  LOGE( "%s - pin GPIO%d is not supported", __func__,gpio);
-
255  }
-
256  }
-
257 
-
258  // The internal DAC only supports 8 bit values - so we need to convert the data
-
259  size_t outputStereo(const void *src, size_t size_bytes) {
-
260  TRACED();
-
261  size_t output_size = 0;
-
262  size_t result;
-
263  uint16_t *dst = (uint16_t *)src;
-
264  switch(adc_config.bits_per_sample){
-
265  case 16: {
-
266  int16_t *data=(int16_t *)src;
-
267  output_size = size_bytes;
-
268  for (int j=0;j<size_bytes/2;j++){
-
269  dst[j] = convert8DAC(data[j], adc_config.bits_per_sample);
-
270  }
-
271  } break;
-
272  case 24: {
-
273  int24_t *data=(int24_t *)src;
-
274  output_size = (size_bytes/3) * 2;
-
275  for (int j=0;j<size_bytes/3;j++){
-
276  dst[j] = (uint32_t)convert8DAC(data[j], adc_config.bits_per_sample);
-
277  }
-
278  } break;
-
279  case 32: {
-
280  int32_t *data=(int32_t *)src;
-
281  output_size = (size_bytes/4) * 2;
-
282  for (int j=0;j<size_bytes/4;j++){
-
283  dst[j] = convert8DAC(data[j], adc_config.bits_per_sample);
-
284  }
-
285  } break;
-
286  }
-
287 
-
288  if (output_size>0){
-
289  if (i2s_write(port_no, src, output_size, &result, portMAX_DELAY)!=ESP_OK){
-
290  LOGE("%s: %d", LOG_METHOD, output_size);
-
291  }
-
292  }
-
293 
-
294  LOGD("i2s_write %d -> %d bytes", size_bytes, result);
-
295  return result;
-
296 
-
297  }
+
139  if (active) {
+
140  i2s_zero_dma_buffer(port_no);
+
141  }
+
142 
+
143  // close ADC
+
144  if (adc_config.rx_tx_mode == RX_MODE){
+
145  i2s_adc_disable(port_no);
+
146  }
+
147  if (adc_config.uninstall_driver_on_end){
+
148  i2s_driver_uninstall(port_no);
+
149  is_driver_installed = false;
+
150  } else {
+
151  i2s_stop(port_no);
+
152  }
+
153  active = false;
+
154  }
+
155 
+
156  // /// Overides the sample rate and uses the max value which is around ~13MHz. Call this methd after begin();
+
157  // void setMaxSampleRate() {
+
158  // //this is the hack that enables the highest sampling rate possible ~13MHz, have fun
+
159  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_A_V, 1, I2S_CLKM_DIV_A_S);
+
160  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_B_V, 1, I2S_CLKM_DIV_B_S);
+
161  // SET_PERI_REG_BITS(I2S_CLKM_CONF_REG(0), I2S_CLKM_DIV_NUM_V, 1, I2S_CLKM_DIV_NUM_S);
+
162  // SET_PERI_REG_BITS(I2S_SAMPLE_RATE_CONF_REG(0), I2S_TX_BCK_DIV_NUM_V, 1, I2S_TX_BCK_DIV_NUM_S);
+
163  // }
+
164 
+
166  size_t write(const uint8_t *src, size_t size_bytes) override {
+
167  TRACED();
+
168 
+
169  size_t result = 0;
+
170  if (size_bytes>0 && src!=nullptr){
+
171  switch(adc_config.channels){
+
172  case 1:
+
173  result = outputMono(src, size_bytes);
+
174  break;
+
175  case 2:
+
176  result = outputStereo(src, size_bytes);
+
177  break;
+
178  default:
+
179  LOGE("Unsupported number of channels: %d", adc_config.channels);
+
180  stop();
+
181  }
+
182  LOGD("converted write size: %d",result);
+
183  }
+
184  return size_bytes;
+
185  }
+
186 
+
187  size_t readBytes(uint8_t *dest, size_t size_bytes) override {
+
188  TRACED();
+
189  size_t result = 0;
+
190  if (i2s_read(port_no, dest, size_bytes, &result, portMAX_DELAY)!=ESP_OK){
+
191  TRACEE();
+
192  }
+
193  // make sure that the center is at 0
+
194  if (adc_config.is_auto_center_read){
+
195  auto_center.convert(dest, result);
+
196  }
+
197  LOGD( "%s - len: %d -> %d", __func__, size_bytes, result);
+
198  return result;
+
199  }
+
200 
+
201  virtual int available() override {
+
202  return active ? adc_config.buffer_size*adc_config.buffer_count : 0;
+
203  }
+
204 
+
205  protected:
+
206  AnalogConfig adc_config;
+
207  ConverterAutoCenter auto_center;
+
208  i2s_port_t port_no;
+
209  bool active = false;
+
210  bool is_driver_installed = false;
+
211  size_t result=0;
+
212 
+
213  // input values
+
214  adc_unit_t adc_unit;
+
215  adc1_channel_t adc_channel;
+
216 
+
218  void setupInputPin(int gpio){
+
219  TRACED();
+
220 
+
221  switch(gpio){
+
222  case 32:
+
223  adc_unit = ADC_UNIT_1;
+
224  adc_channel = ADC1_GPIO32_CHANNEL;
+
225  break;
+
226  case 33:
+
227  adc_unit = ADC_UNIT_1;
+
228  adc_channel = ADC1_GPIO33_CHANNEL;
+
229  break;
+
230  case 34:
+
231  adc_unit = ADC_UNIT_1;
+
232  adc_channel = ADC1_GPIO34_CHANNEL;
+
233  break;
+
234  case 35:
+
235  adc_unit = ADC_UNIT_1;
+
236  adc_channel = ADC1_GPIO35_CHANNEL;
+
237  break;
+
238  case 36:
+
239  adc_unit = ADC_UNIT_1;
+
240  adc_channel = ADC1_GPIO36_CHANNEL;
+
241  break;
+
242  case 37:
+
243  adc_unit = ADC_UNIT_1;
+
244  adc_channel = ADC1_GPIO37_CHANNEL;
+
245  break;
+
246  case 38:
+
247  adc_unit = ADC_UNIT_1;
+
248  adc_channel = ADC1_GPIO38_CHANNEL;
+
249  break;
+
250  case 39:
+
251  adc_unit = ADC_UNIT_1;
+
252  adc_channel = ADC1_GPIO39_CHANNEL;
+
253  break;
+
254 
+
255  default:
+
256  LOGE( "%s - pin GPIO%d is not supported", __func__,gpio);
+
257  }
+
258  }
+
259 
+
260  // The internal DAC only supports 8 bit values - so we need to convert the data
+
261  size_t outputStereo(const void *src, size_t size_bytes) {
+
262  TRACED();
+
263  size_t output_size = 0;
+
264  size_t result;
+
265  uint16_t *dst = (uint16_t *)src;
+
266  switch(adc_config.bits_per_sample){
+
267  case 16: {
+
268  int16_t *data=(int16_t *)src;
+
269  output_size = size_bytes;
+
270  for (int j=0;j<size_bytes/2;j++){
+
271  dst[j] = convert8DAC(data[j], adc_config.bits_per_sample);
+
272  }
+
273  } break;
+
274  case 24: {
+
275  int24_t *data=(int24_t *)src;
+
276  output_size = (size_bytes/3) * 2;
+
277  for (int j=0;j<size_bytes/3;j++){
+
278  dst[j] = (uint32_t)convert8DAC(data[j], adc_config.bits_per_sample);
+
279  }
+
280  } break;
+
281  case 32: {
+
282  int32_t *data=(int32_t *)src;
+
283  output_size = (size_bytes/4) * 2;
+
284  for (int j=0;j<size_bytes/4;j++){
+
285  dst[j] = convert8DAC(data[j], adc_config.bits_per_sample);
+
286  }
+
287  } break;
+
288  }
+
289 
+
290  if (output_size>0){
+
291  if (i2s_write(port_no, src, output_size, &result, portMAX_DELAY)!=ESP_OK){
+
292  LOGE("%s: %d", LOG_METHOD, output_size);
+
293  }
+
294  }
+
295 
+
296  LOGD("i2s_write %d -> %d bytes", size_bytes, result);
+
297  return result;
298 
-
299  // I2S requires stereo so we convert mono to stereo
-
300  size_t outputMono(const void *src, size_t size_bytes) {
-
301  TRACED();
-
302  size_t output_size = 0;
-
303  uint16_t out[2];
-
304  size_t resultTotal = 0;
-
305  switch(adc_config.bits_per_sample){
-
306  case 16: {
-
307  int16_t *data=(int16_t *)src;
-
308  for (int j=0;j<size_bytes/2;j++){
-
309  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
-
310  out[1] = out[0];
-
311  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
-
312  LOGE("%s: %d", LOG_METHOD, output_size);
-
313  }
-
314  resultTotal += result;
-
315  }
-
316  }break;
-
317  case 24: {
-
318  int24_t *data=(int24_t*)src;
-
319  for (int j=0;j<size_bytes/3;j++){
-
320  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
-
321  out[1] = out[0];
-
322  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
-
323  LOGE("%s: %d", LOG_METHOD, output_size);
-
324  }
-
325  resultTotal += result;
-
326  }
-
327  } break;
-
328  case 32: {
-
329  int32_t *data=(int32_t *)src;
-
330  for (int j=0;j<size_bytes/4;j++){
-
331  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
-
332  out[1] = out[0];
-
333  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
-
334  LOGE("%s: %d", LOG_METHOD, output_size);
-
335  }
-
336  resultTotal += result;
-
337  }
-
338  } break;
-
339  }
-
340 
-
341  LOGD("i2s_write %d -> %d bytes", size_bytes, resultTotal);
-
342  return resultTotal;
-
343  }
-
344 };
-
346 using AnalogDriver = AnalogDriverESP32;
-
347 
-
348 } // namespace
+
299  }
+
300 
+
301  // I2S requires stereo so we convert mono to stereo
+
302  size_t outputMono(const void *src, size_t size_bytes) {
+
303  TRACED();
+
304  size_t output_size = 0;
+
305  uint16_t out[2];
+
306  size_t resultTotal = 0;
+
307  switch(adc_config.bits_per_sample){
+
308  case 16: {
+
309  int16_t *data=(int16_t *)src;
+
310  for (int j=0;j<size_bytes/2;j++){
+
311  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
+
312  out[1] = out[0];
+
313  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
+
314  LOGE("%s: %d", LOG_METHOD, output_size);
+
315  }
+
316  resultTotal += result;
+
317  }
+
318  }break;
+
319  case 24: {
+
320  int24_t *data=(int24_t*)src;
+
321  for (int j=0;j<size_bytes/3;j++){
+
322  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
+
323  out[1] = out[0];
+
324  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
+
325  LOGE("%s: %d", LOG_METHOD, output_size);
+
326  }
+
327  resultTotal += result;
+
328  }
+
329  } break;
+
330  case 32: {
+
331  int32_t *data=(int32_t *)src;
+
332  for (int j=0;j<size_bytes/4;j++){
+
333  out[0] = convert8DAC(data[j], adc_config.bits_per_sample);
+
334  out[1] = out[0];
+
335  if (i2s_write(port_no, out, 4, &result, portMAX_DELAY)!=ESP_OK){
+
336  LOGE("%s: %d", LOG_METHOD, output_size);
+
337  }
+
338  resultTotal += result;
+
339  }
+
340  } break;
+
341  }
+
342 
+
343  LOGD("i2s_write %d -> %d bytes", size_bytes, resultTotal);
+
344  return resultTotal;
+
345  }
+
346 };
+
348 using AnalogDriver = AnalogDriverESP32;
349 
-
350 #endif
+
350 } // namespace
+
351 
+
352 #endif
ESP32 specific configuration for i2s input via adc. The default input pin is GPIO34....
Definition: AnalogAudioBase.h:19
Definition: AnalogAudioBase.h:94
Please use AnalogAudioStream: A very fast ADC and DAC using the ESP32 I2S interface.
Definition: AnalogAudioESP32.h:35
-
void setupInputPin(int gpio)
Defines the current ADC pin. The following GPIO pins are supported: GPIO32-GPIO39.
Definition: AnalogAudioESP32.h:216
-
size_t write(const uint8_t *src, size_t size_bytes) override
writes the data to the I2S interface
Definition: AnalogAudioESP32.h:164
+
void setupInputPin(int gpio)
Defines the current ADC pin. The following GPIO pins are supported: GPIO32-GPIO39.
Definition: AnalogAudioESP32.h:218
+
size_t write(const uint8_t *src, size_t size_bytes) override
writes the data to the I2S interface
Definition: AnalogAudioESP32.h:166
AnalogDriverESP32()=default
Default constructor.
bool begin(AnalogConfig cfg)
starts the DAC
Definition: AnalogAudioESP32.h:46
void end() override
stops the I2S and unistalls the driver
Definition: AnalogAudioESP32.h:137