/* * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include #include #include "esp32/rom/lldesc.h" #include "driver/periph_ctrl.h" #include "hal/gpio_hal.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/dport_reg.h" #include "soc/gpio_periph.h" #include "soc/i2s_periph.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; periph_module_enable(PERIPH_I2S0_MODULE); //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 gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO0_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO2_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO5_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO16_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO17_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO18_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO19_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_GPIO20_U, 0); gpio_hal_iomux_func_sel(PERIPHS_IO_MUX_SD_CMD_U, 2); //11 gpio_hal_iomux_func_sel(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<