Skip to content

Commit

Permalink
added adc_builtin support
Browse files Browse the repository at this point in the history
  • Loading branch information
ligantx committed Apr 29, 2020
1 parent e113449 commit 99470c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions esp32_I2S_recorder/I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
void I2S_Init(i2s_mode_t MODE, i2s_bits_per_sample_t BPS)
{
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | MODE),
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = BPS,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0,
.dma_buf_count = 16,
.dma_buf_len = 60};
.dma_buf_len = 60
};
if (MODE == I2S_MODE_RX || MODE == I2S_MODE_TX) {
Serial.println("using I2S_MODE");
i2s_pin_config_t pin_config;
pin_config.bck_io_num = PIN_I2S_BCLK;
pin_config.ws_io_num = PIN_I2S_LRC;
Expand All @@ -29,6 +31,7 @@ void I2S_Init(i2s_mode_t MODE, i2s_bits_per_sample_t BPS)
i2s_set_clk(I2S_NUM_0, SAMPLE_RATE, BPS, I2S_CHANNEL_STEREO);
}
else if (MODE == I2S_MODE_DAC_BUILT_IN || MODE == I2S_MODE_ADC_BUILT_IN) {
Serial.println("using ADC_builtin");
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
// GPIO36, VP
i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_0);
Expand Down
8 changes: 7 additions & 1 deletion esp32_I2S_recorder/esp32_I2S_recorder.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Arduino.h"
#include <FS.h>
#include <SD.h>
#include "Wav.h"
#include "I2S.h"
#include <SD.h>


//comment the first line and uncomment the second if you use MAX9814
//#define I2S_MODE I2S_MODE_RX
Expand All @@ -22,6 +24,10 @@ File file;
void setup() {
Serial.begin(115200);
if (!SD.begin()) Serial.println("SD begin failed");
while(!SD.begin()){
Serial.print(".");
delay(500);
}
CreateWavHeader(header, waveDataSize);
SD.remove(filename);
file = SD.open(filename, FILE_WRITE);
Expand Down

0 comments on commit 99470c5

Please sign in to comment.