Skip to content

Commit

Permalink
Fix Break Timing (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Makuna authored Feb 5, 2023
1 parent f863faf commit 7822ea9
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/internal/NeoEsp8266I2sDmx512Method.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class NeoEsp8266I2sDmx512SpeedBase
static const uint32_t I2sClockDivisor = 20; // 0-63
static const uint32_t I2sBaseClockDivisor = 32; // 0-63
static const uint32_t ByteSendTimeUs = 44; // us it takes to send a single pixel element of 11 bits
static const uint32_t MtbpUs = 100; // // Break, min 88
static const uint32_t MtbpBits = 25; // (MtbpUs/4) count of bits needed for the Mtbp timing

static const uint32_t BreakMabUs = 96; // Break min 92, Mab min 12
static const size_t BreakMabSize = 4; // roundupby((BreakMabUs/4us)/8,4) count of bytes needed for the Break+Mab timing
static const uint32_t MtbpUs = 11; // Mtbp, min 0, buy we use at least one byte of space (8*1.35)
static const size_t MtbpSize = 1; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing
// DMX requires the first slot to be zero
static const size_t HeaderSize = 1;
};
Expand All @@ -50,6 +51,7 @@ class NeoEsp8266I2sDmx512Speed : public NeoEsp8266I2sDmx512SpeedBase
static const uint8_t MtbpLevel = 0x1; // high
static const uint8_t StartBit = 0b00000000;
static const uint8_t StopBits = 0b00000011;
static const uint32_t Break = 0x00000000; // Break
static const uint32_t BreakMab = 0x00000007; // Break + Mab

static uint8_t Convert(uint8_t value)
Expand All @@ -65,6 +67,7 @@ class NeoEsp8266I2sDmx512InvertedSpeed : public NeoEsp8266I2sDmx512SpeedBase
static const uint8_t MtbpLevel = 0x00; // low
static const uint8_t StartBit = 0b00000001;
static const uint8_t StopBits = 0b00000000;
static const uint32_t Break = 0xffffffff; // Break
static const uint32_t BreakMab = 0xfffffff8; // Break + Mab

static uint8_t Convert(uint8_t value)
Expand All @@ -82,8 +85,11 @@ class NeoEsp8266I2sWs2821SpeedBase
static const uint32_t I2sClockDivisor = 27; // 0-63
static const uint32_t I2sBaseClockDivisor = 8; // 0-63
static const uint32_t ByteSendTimeUs = 15; // us it takes to send a single pixel element of 11 bits
static const uint32_t MtbpUs = 33; // Break
static const uint32_t MtbpBits = 25; // (MtbpUs/1.35) count of bits needed for the Mtbp timing
static const uint32_t BreakMabUs = 92; // Break min 88, Mab min 4
static const size_t BreakMabSize = 12; // roundupby((BreakMabUs/1.35)/8,4) count of bytes needed for the Break+Mab timing
static const uint32_t MtbpUs = 88; // Mtbp, min 88
static const size_t MtbpSize = 9; // (MtbpUs/1.35)/8 count of bytes needed for the Mtbp timing

// DMX/WS2821 requires the first slot to be zero
static const size_t HeaderSize = 1;
};
Expand All @@ -94,7 +100,8 @@ class NeoEsp8266I2sWs2821Speed : public NeoEsp8266I2sWs2821SpeedBase
static const uint8_t MtbpLevel = 0x1; // high
static const uint8_t StartBit = 0b00000000;
static const uint8_t StopBits = 0b00000011;
static const uint32_t BreakMab = 0x00000007; // Break + Mab
static const uint32_t Break = 0x00000000; // Break
static const uint32_t BreakMab = 0x00000007; // Break + Mab (4~12us/1.35us)

static uint8_t Convert(uint8_t value)
{
Expand All @@ -109,6 +116,7 @@ class NeoEsp8266I2sWs2821InvertedSpeed : public NeoEsp8266I2sWs2821SpeedBase
static const uint8_t MtbpLevel = 0x00; // low
static const uint8_t StartBit = 0b00000001;
static const uint8_t StopBits = 0b00000000;
static const uint32_t Break = 0xffffffff; // Break
static const uint32_t BreakMab = 0xfffffff8; // Break + Mab

static uint8_t Convert(uint8_t value)
Expand All @@ -132,14 +140,14 @@ template<typename T_SPEED> class NeoEsp8266I2sDmx512MethodBase : NeoEsp8266I2sMe
// bits + half rounding byte of bits / bits per byte
size_t i2sBufferSize = (pixelCount * dmaPixelBits + dmaSettingsBits + 4) / 8;

i2sBufferSize = i2sBufferSize + sizeof(T_SPEED::BreakMab);
i2sBufferSize = i2sBufferSize + T_SPEED::BreakMabSize;

// size is rounded up to nearest I2sByteBoundarySize
i2sBufferSize = NeoUtil::RoundUp(i2sBufferSize, I2sByteBoundarySize);

//
size_t i2sZeroesSize = NeoUtil::RoundUp(T_SPEED::MtbpBits, 8) / 8;

// size of a looping silent space rounded up to nearest I2sByteBoundarySize
size_t i2sZeroesSize = NeoUtil::RoundUp(T_SPEED::MtbpSize, I2sByteBoundarySize);

// protocol limits use of full block size to I2sByteBoundarySize
size_t is2BufMaxBlockSize = (c_maxDmaBlockSize / I2sByteBoundarySize) * I2sByteBoundarySize;

Expand Down Expand Up @@ -315,10 +323,14 @@ template<typename T_SPEED> class NeoEsp8266I2sDmx512MethodBase : NeoEsp8266I2sMe
uint32_t* pDma32 = reinterpret_cast<uint32_t*>(_i2sBuffer);
const uint32_t* pDma32End = reinterpret_cast<uint32_t*>(_i2sBuffer + _i2sBufferSize);

// first put Break and MAB at front
//
// BREAK 121.8us @ 4.2us per bit
// MAB 12.6us
// first insert Break space as needed
for (size_t count = 1;
count < (T_SPEED::BreakMabSize/sizeof(T_SPEED::Break));
count++)
{
*(pDma32++) = T_SPEED::Break;
}
// then tail of break with mab
*(pDma32++) = T_SPEED::BreakMab;

Encoder(_data, _data + _sizeData, pDma32, pDma32End);
Expand Down

0 comments on commit 7822ea9

Please sign in to comment.