/** * The MIT License (MIT) * * Copyright (c) 2016 sheinz (https://github.com/sheinz) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "i2s_dma.h" #include "esp/iomux.h" #include "esp/i2s_regs.h" #include "esp/interrupts.h" #include "esp/iomux.h" #include "common_macros.h" #include // #define I2S_DMA_DEBUG #ifdef I2S_DMA_DEBUG #include #define debug(fmt, ...) printf("%s" fmt "\n", "i2s_dma: ", ## __VA_ARGS__); #else #define debug(fmt, ...) #endif // The following definitions is taken from ESP8266_MP3_DECODER demo // https://github.com/espressif/ESP8266_MP3_DECODER/blob/master/mp3/driver/i2s_freertos.c // It is requred to set clock to I2S subsystem void sdk_rom_i2c_writeReg_Mask(uint32_t block, uint32_t host_id, uint32_t reg_add, uint32_t Msb, uint32_t Lsb, uint32_t indata); #ifndef i2c_bbpll #define i2c_bbpll 0x67 #define i2c_bbpll_en_audio_clock_out 4 #define i2c_bbpll_en_audio_clock_out_msb 7 #define i2c_bbpll_en_audio_clock_out_lsb 7 #define i2c_bbpll_hostid 4 #endif #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) \ sdk_rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) #define i2c_writeReg_Mask_def(block, reg_add, indata) \ i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, \ reg_add##_lsb, indata) void i2s_dma_init(i2s_dma_isr_t isr, void *arg, i2s_clock_div_t clock_div, i2s_pins_t pins) { // reset DMA SET_MASK_BITS(SLC.CONF0, SLC_CONF0_RX_LINK_RESET); CLEAR_MASK_BITS(SLC.CONF0, SLC_CONF0_RX_LINK_RESET); // clear DMA int flags SLC.INT_CLEAR = 0xFFFFFFFF; SLC.INT_CLEAR = 0; // Enable and configure DMA SLC.CONF0 = SET_FIELD(SLC.CONF0, SLC_CONF0_MODE, 0); // does it really needed? SLC.CONF0 = SET_FIELD(SLC.CONF0, SLC_CONF0_MODE, 1); // Do we really need to set and clear? SET_MASK_BITS(SLC.RX_DESCRIPTOR_CONF, SLC_RX_DESCRIPTOR_CONF_INFOR_NO_REPLACE | SLC_RX_DESCRIPTOR_CONF_TOKEN_NO_REPLACE); CLEAR_MASK_BITS(SLC.RX_DESCRIPTOR_CONF, SLC_RX_DESCRIPTOR_CONF_RX_FILL_ENABLE | SLC_RX_DESCRIPTOR_CONF_RX_EOF_MODE | SLC_RX_DESCRIPTOR_CONF_RX_FILL_MODE); if (isr) { _xt_isr_attach(INUM_SLC, isr, arg); SET_MASK_BITS(SLC.INT_ENABLE, SLC_INT_ENABLE_RX_EOF); SLC.INT_CLEAR = 0xFFFFFFFF; _xt_isr_unmask(1<