fix: resolve byte-to-byte gap stretching in FCOB driver by introducing zero-gap double-buffered SPI transmission queue

This commit is contained in:
2026-07-08 11:50:20 +08:00
parent 8c7b6b3e22
commit 4a7c6c5b7b

View File

@@ -164,13 +164,23 @@ void WS2812_Write24Bit(u8 g, u8 r, u8 b)
SPCTL = 0xD0; // Enable SPI at SYSCLK/4 (6.0 MHz)
SPSTAT = 0xC0; // Clear flags
for (i = 0; i < 15; i++)
SPDAT = buf[0]; // Goes to shift register immediately
// Wait at least 1 SPI clock cycle (8 system cycles) to avoid WCOL
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
SPDAT = buf[1]; // Goes to transmit buffer
for (i = 2; i < 15; i++)
{
SPDAT = buf[i];
while (!(SPSTAT & 0x80));
while (!(SPSTAT & 0x80)); // Wait for buf[i-2] to finish, buf[i-1] moves to shifter
SPSTAT = 0xC0;
SPDAT = buf[i]; // Write buf[i] to transmit buffer (zero gap!)
}
while (!(SPSTAT & 0x80)); // Wait for buf[13] to finish, buf[14] moves to shifter
SPSTAT = 0xC0;
while (!(SPSTAT & 0x80)); // Wait for buf[14] to finish
SPSTAT = 0xC0;
SPCTL = 0x90; // Disable SPI
WS2812_DI = 0;
MOTOR = 0; // Ensure motor is off