forked from Makuna/NeoPixelBus
Esp32 update i2s (#283)
* Update NeoEsp32I2sMethod.h * Esp32i2sFixes * Improve Apa106 RMT timing
This commit is contained in:
1 parent
49c411dbf9
commit
b237440d63
5 files changed
+44
-15
No files matched your search
@@ -45,7 +45,7 @@
|
||||
#define ESP32_REG(addr) (*((volatile uint32_t*)(0x3FF00000+(addr))))
|
||||
|
||||
#define I2S_DMA_QUEUE_SIZE 16
|
||||
#define I2S_DMA_MAX_DATA_LEN 4092// maximum bytes in one dma item
|
||||
|
||||
#define I2S_DMA_SILENCE_LEN 256 // bytes
|
||||
|
||||
typedef struct i2s_dma_item_s {
|
||||
@@ -142,7 +142,7 @@ bool i2sInitDmaItems(uint8_t bus_num) {
|
||||
}
|
||||
}
|
||||
|
||||
I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count - 3, sizeof(i2s_dma_item_t*));
|
||||
I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count, sizeof(i2s_dma_item_t*));
|
||||
if (I2S[bus_num].tx_queue == NULL) {// memory error
|
||||
log_e("MEM ERROR!");
|
||||
free(I2S[bus_num].dma_items);
|
||||
@@ -273,7 +273,7 @@ bool i2sWriteDone(uint8_t bus_num) {
|
||||
if (bus_num > 1) {
|
||||
return false;
|
||||
}
|
||||
return (I2S[bus_num].dma_items[0].data == I2S[bus_num].silence_buf && I2S[bus_num].dma_items[1].data == I2S[bus_num].silence_buf);
|
||||
return (I2S[bus_num].dma_items[I2S[bus_num].dma_count - 1].data == I2S[bus_num].silence_buf);
|
||||
}
|
||||
|
||||
void i2sInit(uint8_t bus_num, uint32_t bits_per_sample, uint32_t sample_rate, i2s_tx_chan_mod_t chan_mod, i2s_tx_fifo_mod_t fifo_mod, size_t dma_count, size_t dma_len) {
|
||||
|
||||
@@ -8,6 +8,8 @@ extern "C" {
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#define I2S_DMA_MAX_DATA_LEN 4092// maximum bytes in one dma item
|
||||
|
||||
typedef enum {
|
||||
I2S_CHAN_STEREO, I2S_CHAN_RIGHT_TO_LEFT, I2S_CHAN_LEFT_TO_RIGHT, I2S_CHAN_RIGHT_ONLY, I2S_CHAN_LEFT_ONLY
|
||||
} i2s_tx_chan_mod_t;
|
||||
|
||||
@@ -35,37 +35,47 @@ extern "C"
|
||||
}
|
||||
|
||||
const uint16_t c_dmaBytesPerPixelBytes = 4;
|
||||
const uint16_t c_dmaBytesPer50us = 20;
|
||||
const uint32_t c_dmaI2sSampleRate = 100000;
|
||||
|
||||
class NeoEsp32I2sSpeedWs2812x
|
||||
{
|
||||
public:
|
||||
const static uint16_t I2sSampleRateDiv = 1;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeedSk6812
|
||||
{
|
||||
public:
|
||||
const static uint16_t I2sSampleRateDiv = 1;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeed800Kbps
|
||||
{
|
||||
public:
|
||||
const static uint16_t I2sSampleRateDiv = 1;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeed400Kbps
|
||||
{
|
||||
public:
|
||||
const static uint16_t I2sSampleRateDiv = 2;
|
||||
const static uint32_t I2sSampleRate = 50000;
|
||||
const static uint16_t ByteSendTimeUs = 20;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeedApa106
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 76000;
|
||||
const static uint16_t ByteSendTimeUs = 14;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sBusZero
|
||||
{
|
||||
public:
|
||||
@@ -85,7 +95,7 @@ public:
|
||||
_pin(pin)
|
||||
{
|
||||
uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize;
|
||||
uint16_t resetSize = (c_dmaBytesPer50us * T_SPEED::ResetTimeUs / 50 / T_SPEED::I2sSampleRateDiv);
|
||||
uint16_t resetSize = c_dmaBytesPerPixelBytes * T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs;
|
||||
|
||||
_pixelsSize = pixelCount * elementSize;
|
||||
_i2sBufferSize = pixelCount * dmaPixelSize + resetSize;
|
||||
@@ -124,7 +134,8 @@ public:
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
i2sInit(T_BUS::I2sBusNumber, 16, c_dmaI2sSampleRate / T_SPEED::I2sSampleRateDiv, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, 4, 0);
|
||||
size_t dmaCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN;
|
||||
i2sInit(T_BUS::I2sBusNumber, 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaCount, 0);
|
||||
i2sSetPins(T_BUS::I2sBusNumber, _pin, -1, -1, -1);
|
||||
}
|
||||
|
||||
@@ -184,13 +195,13 @@ typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedWs2812x, NeoEsp32I2sBusZero> NeoEs
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedSk6812, NeoEsp32I2sBusZero> NeoEsp32I2s0Sk6812Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed800Kbps, NeoEsp32I2sBusZero> NeoEsp32I2s0800KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed400Kbps, NeoEsp32I2sBusZero> NeoEsp32I2s0400KbpsMethod;
|
||||
typedef NeoEsp32I2s0400KbpsMethod NeoEsp32I2s0Apa106Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedApa106, NeoEsp32I2sBusZero> NeoEsp32I2s0Apa106Method;
|
||||
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedWs2812x, NeoEsp32I2sBusOne> NeoEsp32I2s1Ws2812xMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedSk6812, NeoEsp32I2sBusOne> NeoEsp32I2s1Sk6812Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed800Kbps, NeoEsp32I2sBusOne> NeoEsp32I2s1800KbpsMethod;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeed400Kbps, NeoEsp32I2sBusOne> NeoEsp32I2s1400KbpsMethod;
|
||||
typedef NeoEsp32I2s1400KbpsMethod NeoEsp32I2s1Apa106Method;
|
||||
typedef NeoEsp32I2sMethodBase<NeoEsp32I2sSpeedApa106, NeoEsp32I2sBusOne> NeoEsp32I2s1Apa106Method;
|
||||
|
||||
// I2s Bus 1 method is the default method for Esp32
|
||||
typedef NeoEsp32I2s1Ws2812xMethod NeoWs2813Method;
|
||||
|
||||
@@ -106,8 +106,8 @@ public:
|
||||
class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 1400);
|
||||
const static uint32_t RmtBit1 = Item32Val(1400, 400);
|
||||
const static uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user