Skip to content

Commit

Permalink
Minimize the time drift between RMT channels.
Browse files Browse the repository at this point in the history
Place all RMT channels in a group to minimize the time drift between
the signals. Please note that this feature is not available on all
platforms.
  • Loading branch information
docbacardi committed Feb 4, 2024
1 parent f31bb9a commit 96a6410
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions components/platform/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "soc/periph_defs.h"
#include "rom/gpio.h" // for gpio_matrix_out()
#include "soc/gpio_periph.h"
#include "soc/rmt_reg.h"

#undef WS2812_DEBUG

Expand Down Expand Up @@ -277,6 +278,19 @@ int platform_ws2812_send( void )
}
}

// Try to add all channels to a group. This moves the start of all RMT sequences closer
// together.
#if SOC_RMT_SUPPORT_TX_SYNCHRO
for (rmt_channel_t channel = 0; channel < RMT_CHANNEL_MAX && res == PLATFORM_OK; channel++) {
if (ws2812_chains[channel].valid) {
if (rmt_add_channel_to_group( channel ) != ESP_OK) {
res = PLATFORM_ERR;
break;
}
}
}
#endif

// start selected channels one by one
for (rmt_channel_t channel = 0; channel < RMT_CHANNEL_MAX && res == PLATFORM_OK; channel++) {
if (ws2812_chains[channel].valid) {
Expand All @@ -296,6 +310,17 @@ int platform_ws2812_send( void )
}
}

#if SOC_RMT_SUPPORT_TX_SYNCHRO
for (rmt_channel_t channel = 0; channel < RMT_CHANNEL_MAX; channel++) {
if (ws2812_chains[channel].valid) {
if (rmt_remove_channel_from_group( channel ) != ESP_OK) {
res = PLATFORM_ERR;
break;
}
}
}
#endif

return res;
}

Expand Down

0 comments on commit 96a6410

Please sign in to comment.