From f7aaad842b6200d79ce769f74a4d8c3957190582 Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Sat, 20 Feb 2021 22:29:22 +0000 Subject: [PATCH] Add stopDMAtransfer function --- ESP32-HUB75-MatrixPanel-I2S-DMA.h | 11 ++++++++++- esp32_i2s_parallel_v2.c | 16 ++++++++++++++++ esp32_i2s_parallel_v2.h | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ESP32-HUB75-MatrixPanel-I2S-DMA.h b/ESP32-HUB75-MatrixPanel-I2S-DMA.h index 8075051..dce549e 100644 --- a/ESP32-HUB75-MatrixPanel-I2S-DMA.h +++ b/ESP32-HUB75-MatrixPanel-I2S-DMA.h @@ -538,6 +538,16 @@ class MatrixPanel_I2S_DMA { * */ const HUB75_I2S_CFG& getCfg() const {return m_cfg;}; + + + /** + * Stop the ESP32 DMA Engine. Screen will forever be black until next ESP reboot. + */ + void stopDMAoutput() { + clearScreen(); + i2s_parallel_stop_dma(I2S_NUM_1); + } + // ------- PROTECTED ------- @@ -592,7 +602,6 @@ class MatrixPanel_I2S_DMA { void fillRectDMA(int16_t x_coord, int16_t y_coord, int16_t w, int16_t h, uint8_t r, uint8_t g, uint8_t b); #endif - // ------- PRIVATE ------- private: diff --git a/esp32_i2s_parallel_v2.c b/esp32_i2s_parallel_v2.c index 966aaee..cb298bf 100644 --- a/esp32_i2s_parallel_v2.c +++ b/esp32_i2s_parallel_v2.c @@ -299,6 +299,22 @@ esp_err_t i2s_parallel_driver_install(i2s_port_t port, i2s_parallel_config_t* co return ESP_OK; } + esp_err_t i2s_parallel_stop_dma(i2s_port_t port) { + if(port < I2S_NUM_0 || port >= I2S_NUM_MAX) { + return ESP_ERR_INVALID_ARG; + } + + i2s_dev_t* dev = I2S[port]; + + // Stop all ongoing DMA operations + dev->out_link.stop = 1; + dev->out_link.start = 0; + dev->conf.tx_start = 0; + + return ESP_OK; +} + + esp_err_t i2s_parallel_send_dma(i2s_port_t port, lldesc_t* dma_descriptor) { if(port < I2S_NUM_0 || port >= I2S_NUM_MAX) { return ESP_ERR_INVALID_ARG; diff --git a/esp32_i2s_parallel_v2.h b/esp32_i2s_parallel_v2.h index d0c6749..e344b9a 100644 --- a/esp32_i2s_parallel_v2.h +++ b/esp32_i2s_parallel_v2.h @@ -66,6 +66,7 @@ void link_dma_desc(volatile lldesc_t *dmadesc, volatile lldesc_t *prevdmadesc, v // I2S DMA Peripheral Setup Functions esp_err_t i2s_parallel_driver_install(i2s_port_t port, i2s_parallel_config_t* conf); esp_err_t i2s_parallel_send_dma(i2s_port_t port, lldesc_t* dma_descriptor); +esp_err_t i2s_parallel_stop_dma(i2s_port_t port); i2s_dev_t* i2s_parallel_get_dev(i2s_port_t port); // For frame buffer flipping / double buffering