#include #include #include #include #include "rom/ets_sys.h" #include "rom/lldesc.h" #include "rom/gpio.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/queue.h" #include "freertos/xtensa_api.h" #include "unity.h" #include "soc/uart_reg.h" #include "soc/dport_reg.h" #include "soc/io_mux_reg.h" #include "soc/gpio_sig_map.h" #include "soc/gpio_reg.h" #include "soc/i2s_reg.h" #include "esp_dport_access.h" #define DPORT_I2S0_CLK_EN (BIT(4)) #define DPORT_I2S0_RST (BIT(4)) static volatile lldesc_t dmaDesc[2]; //hacked up routine to essentially do a memcpy() using dma. Supports max 4K-1 bytes. static void dmaMemcpy(void *in, void *out, int len) { volatile int i; DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST); //Init pins to i2s functions SET_PERI_REG_MASK(GPIO_ENABLE_W1TS_REG, (1 << 11) | (1 << 3) | (1 << 0) | (1 << 2) | (1 << 5) | (1 << 16) | (1 << 17) | (1 << 18) | (1 << 19) | (1 << 20)); //ENABLE GPIO oe_enable PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO16_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO17_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO18_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO20_U, 0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 2); //11 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO26_U, 0); //RS WRITE_PERI_REG(GPIO_FUNC0_OUT_SEL_CFG_REG, (148 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC2_OUT_SEL_CFG_REG, (149 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC5_OUT_SEL_CFG_REG, (150 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC16_OUT_SEL_CFG_REG, (151 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC17_OUT_SEL_CFG_REG, (152 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC18_OUT_SEL_CFG_REG, (153 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC19_OUT_SEL_CFG_REG, (154 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC20_OUT_SEL_CFG_REG, (155 << GPIO_FUNC0_OUT_SEL_S)); WRITE_PERI_REG(GPIO_FUNC26_OUT_SEL_CFG_REG, (156 << GPIO_FUNC0_OUT_SEL_S)); //RS WRITE_PERI_REG(GPIO_FUNC11_OUT_SEL_CFG_REG, (I2S0O_WS_OUT_IDX << GPIO_FUNC0_OUT_SEL_S)); // WRITE_PERI_REG(GPIO_FUNC11_OUT_SEL_CFG, (I2S0O_BCK_OUT_IDX<