From 4c1c574507e326c6a8d592cceb1332be85ec99fb Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 22 Feb 2023 11:51:07 -0800 Subject: [PATCH] i2s improvements (#654) --- src/internal/Esp32_i2s.c | 36 ++++++++++++++++++++++++++++++ src/internal/Esp32_i2s.h | 5 +++++ src/internal/NeoEsp8266DmaMethod.h | 24 ++++++++++---------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/internal/Esp32_i2s.c b/src/internal/Esp32_i2s.c index 7e1fbee..5893d19 100644 --- a/src/internal/Esp32_i2s.c +++ b/src/internal/Esp32_i2s.c @@ -340,6 +340,42 @@ void i2sSetPins(uint8_t bus_num, } } +void i2sSetClkWsPins(uint8_t bus_num, + int8_t outClk, + bool invertClk, + int8_t outWs, + bool invertWs) +{ + + if (bus_num >= I2S_NUM_MAX) + { + return; + } + + uint32_t i2sSignalClk = I2S0O_BCK_OUT_IDX; + uint32_t i2sSignalWs = I2S0O_WS_OUT_IDX; + +#if !defined(CONFIG_IDF_TARGET_ESP32S2) + if (bus_num == 1) + { + i2sSignalClk = I2S1O_BCK_OUT_IDX; + i2sSignalWs = I2S1O_WS_OUT_IDX; + } +#endif + + if (outClk >= 0) + { + pinMode(outClk, OUTPUT); + gpio_matrix_out(outClk, i2sSignalClk, invertClk, false); + } + + if (outWs >= 0) + { + pinMode(outWs, OUTPUT); + gpio_matrix_out(outWs, i2sSignalWs, invertWs, false); + } +} + bool i2sWriteDone(uint8_t bus_num) { if (bus_num >= I2S_NUM_MAX) diff --git a/src/internal/Esp32_i2s.h b/src/internal/Esp32_i2s.h index 0c47047..9f961d3 100644 --- a/src/internal/Esp32_i2s.h +++ b/src/internal/Esp32_i2s.h @@ -34,6 +34,11 @@ void i2sSetPins(uint8_t bus_num, int8_t parallel, int8_t busSampleSize, bool invert); +void i2sSetClkWsPins(uint8_t bus_num, + int8_t outClk, + bool invertClk, + int8_t outWs, + bool invertWs); bool i2sWrite(uint8_t bus_num); bool i2sWriteDone(uint8_t bus_num); diff --git a/src/internal/NeoEsp8266DmaMethod.h b/src/internal/NeoEsp8266DmaMethod.h index 5ab7feb..fff7003 100644 --- a/src/internal/NeoEsp8266DmaMethod.h +++ b/src/internal/NeoEsp8266DmaMethod.h @@ -72,8 +72,8 @@ public: class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase { public: - const static uint32_t I2sClockDivisor = 3; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 + const static uint32_t I2sClockDivisor = 5; // 0-63 + const static uint32_t I2sBaseClockDivisor = 10; // 0-63 const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed }; @@ -110,8 +110,8 @@ public: class NeoEsp8266DmaSpeed400Kbps : public NeoEsp8266DmaSpeedBase { public: - const static uint32_t I2sClockDivisor = 6; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 + const static uint32_t I2sClockDivisor = 10; // 0-63 + const static uint32_t I2sBaseClockDivisor = 10; // 0-63 const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed const static uint32_t ResetTimeUs = 50; }; @@ -120,8 +120,8 @@ class NeoEsp8266DmaSpeedApa106 : public NeoEsp8266DmaSpeedBase { public: const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 - const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element + const static uint32_t I2sBaseClockDivisor = 17; // 0-63 + const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element const static uint32_t ResetTimeUs = 50; }; @@ -130,8 +130,8 @@ public: class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase { public: - const static uint32_t I2sClockDivisor = 3; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 + const static uint32_t I2sClockDivisor = 5; // 0-63 + const static uint32_t I2sBaseClockDivisor = 10; // 0-63 const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed }; @@ -168,8 +168,8 @@ public: class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase { public: - const static uint32_t I2sClockDivisor = 6; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 + const static uint32_t I2sClockDivisor = 10; // 0-63 + const static uint32_t I2sBaseClockDivisor = 10; // 0-63 const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed const static uint32_t ResetTimeUs = 50; }; @@ -178,8 +178,8 @@ class NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase { public: const static uint32_t I2sClockDivisor = 4; // 0-63 - const static uint32_t I2sBaseClockDivisor = 16; // 0-63 - const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element + const static uint32_t I2sBaseClockDivisor = 17; // 0-63 + const static uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element const static uint32_t ResetTimeUs = 50; };