From 2b9dd956cf4b980046c427efb29b6f4227cf3a21 Mon Sep 17 00:00:00 2001 From: jorgenkraghjakobsen Date: Wed, 29 Apr 2020 00:38:15 +0200 Subject: [PATCH] Added i2c config to kprojectmenu --- components/dsp_processor/Kconfig.projbuild | 41 +++++++ components/dsp_processor/dsp_processor.c | 109 +++++++++--------- .../dsp_processor/include/dsp_processor.h | 6 +- main/main.c | 2 +- sdkconfig | 27 +++-- sdkconfig.old | 35 ++++-- 6 files changed, 140 insertions(+), 80 deletions(-) create mode 100644 components/dsp_processor/Kconfig.projbuild diff --git a/components/dsp_processor/Kconfig.projbuild b/components/dsp_processor/Kconfig.projbuild new file mode 100644 index 0000000..94220ed --- /dev/null +++ b/components/dsp_processor/Kconfig.projbuild @@ -0,0 +1,41 @@ +# Config file for ESP32 DSP Processor + +menu "ESP32 audio I2S config" + config MASTER_I2S_BCK_PIN + int "Master i2s bck" + default 23 + help + Master audio interface bit clock. + + config MASTER_I2S_LRCK_PIN + int "Master i2s lrck" + default 13 + help + Master audio interface left/right sync clock. + + config MASTER_I2S_DATAOUT_PIN + int "Master i2s data out" + default 14 + help + Master audio interface data out. + + config SLAVE_I2S_BCK_PIN + int "Slave i2s bck" + default 26 + help + Slave audio interface bit clock. + + config SLAVE_I2S_LRCK_PIN + int "Slave i2s lrck" + default 12 + help + Slave audio interface left/right sync clock. + + config SLAVE_I2S_DATAOUT_PIN + int "Slave i2s data out" + default 5 + help + Slave audio interface data out. + + +endmenu diff --git a/components/dsp_processor/dsp_processor.c b/components/dsp_processor/dsp_processor.c index d596657..17548ff 100644 --- a/components/dsp_processor/dsp_processor.c +++ b/components/dsp_processor/dsp_processor.c @@ -1,3 +1,5 @@ + + #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -15,64 +17,62 @@ static xTaskHandle s_dsp_i2s_task_handle = NULL; static RingbufHandle_t s_ringbuf_i2s = NULL; extern xQueueHandle i2s_queue; -//enum dspFlows { dspfStereo, dspfBiamp, dspf2DOT1, dspfFunkyHonda }; uint dspFlow = dspfStereo; uint8_t muteCH[4]; ptype_t bq[6]; -void setup_dsp_i2s(uint32_t sample_rate) +void setup_dsp_i2s(uint32_t sample_rate, bool slave_i2s) { i2s_config_t i2s_config0 = { .mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX .sample_rate = sample_rate, .bits_per_sample = 32, - .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels + .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels .communication_format = I2S_COMM_FORMAT_I2S_MSB, - .dma_buf_count = 8, // 8 - .dma_buf_len = 480, //512, - //.intr_alloc_flags = 1, //Default interrupt priority + .dma_buf_count = 8, + .dma_buf_len = 480, .use_apll = true, .fixed_mclk = 0, - .tx_desc_auto_clear = true //Auto clear tx descriptor on underflow + .tx_desc_auto_clear = true // Auto clear tx descriptor on underflow }; - i2s_config_t i2s_config1 = { - .mode = I2S_MODE_SLAVE | I2S_MODE_TX, // Only TX - .sample_rate = sample_rate, - .bits_per_sample = 32, - .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //2-channels - .communication_format = I2S_COMM_FORMAT_I2S_MSB, - .dma_buf_count = 8, // 8 - .dma_buf_len = 480, //512, - //.intr_alloc_flags = 1, //Default interrupt priority - .use_apll = true, - .fixed_mclk = 0, - .tx_desc_auto_clear = true //Auto clear tx descriptor on underflow - }; - - i2s_driver_install(0, &i2s_config0, 8, &i2s_queue); - //i2s_driver_install(1, &i2s_config1, 4, &i2s_queue); - - i2s_zero_dma_buffer(0); - //i2s_zero_dma_buffer(1); - i2s_pin_config_t pin_config0 = { - .bck_io_num = 23, // 12, //CONFIG_EXAMPLE_I2S_BCK_PIN, - .ws_io_num = 13, //CONFIG_EXAMPLE_I2S_LRCK_PIN, - .data_out_num = 14, //CONFIG_EXAMPLE_I2S_DATA_PIN, - .data_in_num = -1 //Not used + .bck_io_num = CONFIG_MASTER_I2S_BCK_PIN, + .ws_io_num = CONFIG_MASTER_I2S_LRCK_PIN, + .data_out_num = CONFIG_MASTER_I2S_DATAOUT_PIN, + .data_in_num = -1 //Not used }; + + i2s_driver_install(0, &i2s_config0, 7, &i2s_queue); + i2s_zero_dma_buffer(0); i2s_set_pin(0, &pin_config0); + i2s_config_t i2s_config1 = { + .mode = I2S_MODE_SLAVE | I2S_MODE_TX, // Only TX - Slave channel + .sample_rate = sample_rate, + .bits_per_sample = 32, + .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels + .communication_format = I2S_COMM_FORMAT_I2S_MSB, + .dma_buf_count = 8, + .dma_buf_len = 480, + .use_apll = true, + .fixed_mclk = 0, + .tx_desc_auto_clear = true // Auto clear tx descriptor on underflow + }; + i2s_pin_config_t pin_config1 = { - .bck_io_num = 15, //CONFIG_EXAMPLE_I2S_BCK_PIN, - .ws_io_num = 4, //CONFIG_EXAMPLE_I2S_LRCK_PIN, - .data_out_num = 23, //CONFIG_EXAMPLE_I2S_DATA_PIN, + .bck_io_num = CONFIG_SLAVE_I2S_BCK_PIN, + .ws_io_num = CONFIG_SLAVE_I2S_LRCK_PIN, + .data_out_num = CONFIG_SLAVE_I2S_DATAOUT_PIN, .data_in_num = -1 //Not used }; - //i2s_set_pin(1, &pin_config1); - + + if (slave_i2s) { + i2s_driver_install(1, &i2s_config1, 7, &i2s_queue); + i2s_zero_dma_buffer(1); + i2s_set_pin(1, &pin_config1); + } } @@ -227,15 +227,15 @@ static void dsp_i2s_task_handler(void *arg) if (cnt%100==0) { //ws_server_send_bin_client(0,(char*)audio, 240); - //printf("%d %d \n",byteWritten, i2s_evt.size ); + //printf("%d %d \n",byteWritten, i2s_evt.size ); } vRingbufferReturnItem(s_ringbuf_i2s,(void *)audio); } } } -void dsp_i2s_task_init(uint32_t sample_rate) -{ setup_dsp_i2s(sample_rate); +void dsp_i2s_task_init(uint32_t sample_rate,bool slave) +{ setup_dsp_i2s(sample_rate,slave); s_ringbuf_i2s = xRingbufferCreate(32*1024,RINGBUF_TYPE_BYTEBUF); // 8*1024 if (s_ringbuf_i2s == NULL) { return; } printf("Ringbuffer ok\n"); @@ -260,25 +260,23 @@ size_t write_ringbuf(const uint8_t *data, size_t size) } -// DSP processor +// ESP32 DSP processor //====================================================== // Each time a buffer of audio is passed to the DSP - samples are -// processoed according to a list audio node processings. +// processed according to a dynamic list of audio processing nodes. // Each audio processor node consist of a data struct holding the -// required weights and states for processing a automomous filter +// required weights and states for processing an automomous processing // function. The high level parameters is maintained in the structre -// as well. +// as well // Release - Prove off concept // ---------------------------------------- -// Fixed 2x2 biquad flow high low seperation for each channel -// Interface for cross over and level -// Additional dynamic bass boost -// +// Fixed 2x2 biquad flow Xover for biAmp systems +// Interface for cross over frequency and level -void dsp_setup_flow(double freq ) { - float f = freq/48000/2; +void dsp_setup_flow(double freq, uint32_t samplerate) { + float f = freq/samplerate/2.; bq[0] = (ptype_t) { LPF, f, 0, 0.707, NULL, NULL, {0,0,0,0,0}, {0, 0} } ; bq[1] = (ptype_t) { LPF, f, 0, 0.707, NULL, NULL, {0,0,0,0,0}, {0, 0} } ; @@ -296,9 +294,9 @@ void dsp_setup_flow(double freq ) { for (uint8_t n=0; n<=5; n++) { switch (bq[n].filtertype) { case LPF: dsps_biquad_gen_lpf_f32( bq[n].coeffs, bq[n].freq, bq[n].q ); - break; + break; case HPF: dsps_biquad_gen_hpf_f32( bq[n].coeffs, bq[n].freq, bq[n].q ); - break; + break; default : break; } for (uint8_t i = 0;i <=3 ;i++ ) @@ -308,10 +306,10 @@ void dsp_setup_flow(double freq ) { } } -void dsp_set_xoverfreq(uint8_t freqh, uint8_t freql) { +void dsp_set_xoverfreq(uint8_t freqh, uint8_t freql,uint32_t samplerate) { float freq = freqh*256 + freql; printf("%f\n",freq); - float f = freq/48000.0/2.0; + float f = freq/samplerate/2.; for ( int8_t n=0; n<=5; n++) { bq[n].freq = f ; switch (bq[n].filtertype) { @@ -319,15 +317,14 @@ void dsp_set_xoverfreq(uint8_t freqh, uint8_t freql) { for (uint8_t i = 0;i <=4 ;i++ ) { printf("%.6f ",bq[n].coeffs[i]); } printf("\n"); - dsps_biquad_gen_lpf_f32( bq[n].coeffs, bq[n].freq, bq[n].q ); for (uint8_t i = 0;i <=4 ;i++ ) { printf("%.6f ",bq[n].coeffs[i]); } printf("%f \n",bq[n].freq); break; case HPF: - dsps_biquad_gen_hpf_f32( bq[n].coeffs, bq[n].freq, bq[n].q ); - break; + dsps_biquad_gen_hpf_f32( bq[n].coeffs, bq[n].freq, bq[n].q ); + break; default : break; } } diff --git a/components/dsp_processor/include/dsp_processor.h b/components/dsp_processor/include/dsp_processor.h index 1667267..b119146 100644 --- a/components/dsp_processor/include/dsp_processor.h +++ b/components/dsp_processor/include/dsp_processor.h @@ -5,7 +5,7 @@ enum dspFlows {dspfStereo, dspfBiamp, dspf2DOT1, dspfFunkyHonda }; size_t write_ringbuf(const uint8_t *data, size_t size); -void dsp_i2s_task_init(uint32_t sample_rate); +void dsp_i2s_task_init(uint32_t sample_rate,bool slave); void dsp_i2s_task_deinit(void); @@ -30,7 +30,7 @@ typedef struct pnode { struct pnode *next; } pnode_t; -void dsp_setup_flow(double freq); -void dsp_set_xoverfreq(uint8_t, uint8_t); +void dsp_setup_flow(double freq,uint32_t samplerate); +void dsp_set_xoverfreq(uint8_t, uint8_t, uint32_t ); #endif /* _DSP_PROCESSOR_H_ */ diff --git a/main/main.c b/main/main.c index 035a16e..e7aabfd 100644 --- a/main/main.c +++ b/main/main.c @@ -167,7 +167,7 @@ static void http_get_task(void *pvParameters) int16_t pcm_size = 120; uint16_t channels; - dsp_i2s_task_init(48000); + dsp_i2s_task_init(48000,false); while(1) { /* Wait for the callback to set the CONNECTED_BIT in the diff --git a/sdkconfig b/sdkconfig index 3e695c4..99d8009 100644 --- a/sdkconfig +++ b/sdkconfig @@ -28,13 +28,13 @@ CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y # # Merus MA120x0 interface Configuration # -CONFIG_MA120X0_NENABLE_PIN=32 -CONFIG_MA120X0_NMUTE_PIN=33 -CONFIG_MA120X0_ENABLE_PIN=16 +CONFIG_MA120X0_NENABLE_PIN=5 +CONFIG_MA120X0_NMUTE_PIN=16 +CONFIG_MA120X0_ENABLE_PIN=15 CONFIG_MA120X0_NERR_PIN=34 CONFIG_MA120X0_NCLIP_PIN=35 -CONFIG_MA120X0_SCL_PIN=5 -CONFIG_MA120X0_SDA_PIN=18 +CONFIG_MA120X0_SCL_PIN=32 +CONFIG_MA120X0_SDA_PIN=33 CONFIG_MA120X0_I2C_ADDR=0x20 # end of Merus MA120x0 interface Configuration @@ -78,17 +78,28 @@ CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 # CONFIG_SECURE_FLASH_ENC_ENABLED is not set # end of Security features +# +# ESP32 audio I2S config +# +CONFIG_MASTER_I2S_BCK_PIN=25 +CONFIG_MASTER_I2S_LRCK_PIN=26 +CONFIG_MASTER_I2S_DATAOUT_PIN=27 +CONFIG_SLAVE_I2S_BCK_PIN=26 +CONFIG_SLAVE_I2S_LRCK_PIN=12 +CONFIG_SLAVE_I2S_DATAOUT_PIN=5 +# end of ESP32 audio I2S config + # # Serial flasher config # CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB3" # CONFIG_ESPTOOLPY_BAUD_115200B is not set -CONFIG_ESPTOOLPY_BAUD_230400B=y -# CONFIG_ESPTOOLPY_BAUD_921600B is not set +# CONFIG_ESPTOOLPY_BAUD_230400B is not set +CONFIG_ESPTOOLPY_BAUD_921600B=y # CONFIG_ESPTOOLPY_BAUD_2MB is not set # CONFIG_ESPTOOLPY_BAUD_OTHER is not set CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 -CONFIG_ESPTOOLPY_BAUD=230400 +CONFIG_ESPTOOLPY_BAUD=921600 CONFIG_ESPTOOLPY_COMPRESSED=y # CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set # CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set diff --git a/sdkconfig.old b/sdkconfig.old index 3f25984..9b04251 100644 --- a/sdkconfig.old +++ b/sdkconfig.old @@ -28,13 +28,13 @@ CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y # # Merus MA120x0 interface Configuration # -CONFIG_MA120X0_NENABLE_PIN=32 -CONFIG_MA120X0_NMUTE_PIN=33 -CONFIG_MA120X0_ENABLE_PIN=16 +CONFIG_MA120X0_NENABLE_PIN=5 +CONFIG_MA120X0_NMUTE_PIN=16 +CONFIG_MA120X0_ENABLE_PIN=15 CONFIG_MA120X0_NERR_PIN=34 CONFIG_MA120X0_NCLIP_PIN=35 -CONFIG_MA120X0_SCL_PIN=5 -CONFIG_MA120X0_SDA_PIN=18 +CONFIG_MA120X0_SCL_PIN=33 +CONFIG_MA120X0_SDA_PIN=32 CONFIG_MA120X0_I2C_ADDR=0x20 # end of Merus MA120x0 interface Configuration @@ -78,17 +78,28 @@ CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 # CONFIG_SECURE_FLASH_ENC_ENABLED is not set # end of Security features +# +# ESP32 audio I2S config +# +CONFIG_MASTER_I2S_BCK_PIN=25 +CONFIG_MASTER_I2S_LRCK_PIN=26 +CONFIG_MASTER_I2S_DATAOUT_PIN=27 +CONFIG_SLAVE_I2S_BCK_PIN=26 +CONFIG_SLAVE_I2S_LRCK_PIN=12 +CONFIG_SLAVE_I2S_DATAOUT_PIN=5 +# end of ESP32 audio I2S config + # # Serial flasher config # CONFIG_ESPTOOLPY_PORT="/dev/ttyUSB3" # CONFIG_ESPTOOLPY_BAUD_115200B is not set -CONFIG_ESPTOOLPY_BAUD_230400B=y -# CONFIG_ESPTOOLPY_BAUD_921600B is not set +# CONFIG_ESPTOOLPY_BAUD_230400B is not set +CONFIG_ESPTOOLPY_BAUD_921600B=y # CONFIG_ESPTOOLPY_BAUD_2MB is not set # CONFIG_ESPTOOLPY_BAUD_OTHER is not set CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 -CONFIG_ESPTOOLPY_BAUD=230400 +CONFIG_ESPTOOLPY_BAUD=921600 CONFIG_ESPTOOLPY_COMPRESSED=y # CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set # CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set @@ -279,9 +290,9 @@ CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y # CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set CONFIG_ESP32_BROWNOUT_DET_LVL=0 CONFIG_ESP32_REDUCE_PHY_TX_POWER=y -CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y +# CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 is not set # CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set -# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set +CONFIG_ESP32_TIME_SYSCALL_USE_FRC1=y # CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y # CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set @@ -693,8 +704,8 @@ CONFIG_LWIP_MAX_RAW_PCBS=16 # # SNTP # -CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 -CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 +CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=4 +CONFIG_LWIP_SNTP_UPDATE_DELAY=60000 # end of SNTP # end of LWIP