WS2812 RMT Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ws2812::RmtTx Class Reference

#include <rmt_wrapper.hpp>

Public Member Functions

 RmtTx (gpio_num_t gpio, uint32_t resolution_hz=10 '000 '000, size_t mem_symbols=kDefaultMemSymbols, bool with_dma=false, uint32_t queue_depth=4, rmt_clock_source_t clk_src=RMT_CLK_SRC_DEFAULT, int channel_id=-1)
 Create a Transmit channel.
 
 RmtTx (const RmtTx &)=delete
 
RmtTx & operator= (const RmtTx &)=delete
 
 RmtTx (RmtTx &&other) noexcept
 
RmtTx & operator= (RmtTx &&other) noexcept
 
 ~RmtTx ()
 
esp_err_t Init ()
 Create and enable the channel if that has not succeeded yet.
 
esp_err_t InitStatus () const
 Result of the last Init(): ESP_OK when the channel is ready.
 
bool IsReady () const
 True when the channel was created and enabled.
 
esp_err_t Transmit (const rmt_symbol_word_t *symbols, size_t count, int32_t timeout_ms=kWaitForever) const
 Transmit raw RMT symbols (blocking until done).
 
template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t Transmit (const rmt_symbol_word_t *symbols, size_t count, Ticks timeout) const
 
esp_err_t TransmitBytes (const uint8_t *data, size_t length, const rmt_symbol_word_t &bit0, const rmt_symbol_word_t &bit1, int32_t timeout_ms=kWaitForever)
 Transmit an arbitrary byte stream with custom bit timing.
 
template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t TransmitBytes (const uint8_t *data, size_t length, const rmt_symbol_word_t &bit0, const rmt_symbol_word_t &bit1, Ticks timeout)
 
esp_err_t TransmitWs2812 (const uint8_t *grb, size_t length, int32_t timeout_ms=kWaitForever)
 Helper dedicated to WS2812/NeoPixel @ 800 kHz. Uses 10 MHz or faster resolution to achieve accurate timings.
 
template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t TransmitWs2812 (const uint8_t *grb, size_t length, Ticks timeout)
 
rmt_channel_handle_t Handle () const
 

Static Public Member Functions

static constexpr int32_t TicksToTimeoutMs (TickType_t ticks, uint32_t tick_rate_hz=configTICK_RATE_HZ)
 Convert a FreeRTOS tick count to the millisecond timeout the transmit calls take.
 

Static Public Attributes

static constexpr size_t kDefaultMemSymbols = WS2812_RMT_MEM_BLOCK_SYMBOLS
 
static constexpr int32_t kWaitForever = -1
 

Constructor & Destructor Documentation

◆ RmtTx() [1/3]

ws2812::RmtTx::RmtTx ( gpio_num_t  gpio,
uint32_t  resolution_hz = 10'000'000,
size_t  mem_symbols = kDefaultMemSymbols,
bool  with_dma = false,
uint32_t  queue_depth = 4,
rmt_clock_source_t  clk_src = RMT_CLK_SRC_DEFAULT,
int  channel_id = -1 
)
inlineexplicit

Create a Transmit channel.

Parameters
gpioOutput GPIO number.
resolution_hzClock resolution in Hz (max 40 MHz on ESP32‑C6).
mem_symbolsSymbol memory per channel (in 32-bit words); the default is one memory block of the target.
with_dmaEnable DMA mode for huge transfers.
queue_depthDepth of internal Transmit queue.
clk_srcClock source (default: RMT_CLK_SRC_DEFAULT).
channel_idUnused: ESP-IDF v5 allocates the channel itself.

◆ RmtTx() [2/3]

ws2812::RmtTx::RmtTx ( const RmtTx &  )
delete

◆ RmtTx() [3/3]

ws2812::RmtTx::RmtTx ( RmtTx &&  other)
inlinenoexcept

◆ ~RmtTx()

ws2812::RmtTx::~RmtTx ( )
inline

Member Function Documentation

◆ Handle()

rmt_channel_handle_t ws2812::RmtTx::Handle ( ) const
inline

◆ Init()

esp_err_t ws2812::RmtTx::Init ( )
inline

Create and enable the channel if that has not succeeded yet.

The constructor calls this once. A failure (no free channel, invalid GPIO, no memory) no longer aborts: it is returned here and by InitStatus(), the object stays unusable (every transmit returns ESP_ERR_INVALID_STATE), and a later Init() retries.

Returns
ESP_OK when the channel is ready, otherwise the ESP-IDF error.

◆ InitStatus()

esp_err_t ws2812::RmtTx::InitStatus ( ) const
inline

Result of the last Init(): ESP_OK when the channel is ready.

◆ IsReady()

bool ws2812::RmtTx::IsReady ( ) const
inline

True when the channel was created and enabled.

◆ operator=() [1/2]

RmtTx & ws2812::RmtTx::operator= ( const RmtTx &  )
delete

◆ operator=() [2/2]

RmtTx & ws2812::RmtTx::operator= ( RmtTx &&  other)
inlinenoexcept

◆ TicksToTimeoutMs()

static constexpr int32_t ws2812::RmtTx::TicksToTimeoutMs ( TickType_t  ticks,
uint32_t  tick_rate_hz = configTICK_RATE_HZ 
)
inlinestaticconstexpr

Convert a FreeRTOS tick count to the millisecond timeout the transmit calls take.

portMAX_DELAY becomes kWaitForever; other counts round down and saturate at INT32_MAX. Only the deprecated tick overloads use it.

◆ Transmit() [1/2]

esp_err_t ws2812::RmtTx::Transmit ( const rmt_symbol_word_t *  symbols,
size_t  count,
int32_t  timeout_ms = kWaitForever 
) const
inline

Transmit raw RMT symbols (blocking until done).

Parameters
timeout_msHow long to wait for the frame to go out, in milliseconds; kWaitForever (-1) waits until it is done. Passed to rmt_tx_wait_all_done() as it is.

◆ Transmit() [2/2]

template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t ws2812::RmtTx::Transmit ( const rmt_symbol_word_t *  symbols,
size_t  count,
Ticks  timeout 
) const
inline
Deprecated:
The timeout is in milliseconds now: pass an int32_t, or kWaitForever.

◆ TransmitBytes() [1/2]

esp_err_t ws2812::RmtTx::TransmitBytes ( const uint8_t *  data,
size_t  length,
const rmt_symbol_word_t &  bit0,
const rmt_symbol_word_t &  bit1,
int32_t  timeout_ms = kWaitForever 
)
inline

Transmit an arbitrary byte stream with custom bit timing.

Parameters
bit0Symbol encoding logic‑0 (LSB first by default).
bit1Symbol encoding logic‑1.
timeout_msWait for the frame in milliseconds; kWaitForever (-1) waits until done.

◆ TransmitBytes() [2/2]

template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t ws2812::RmtTx::TransmitBytes ( const uint8_t *  data,
size_t  length,
const rmt_symbol_word_t &  bit0,
const rmt_symbol_word_t &  bit1,
Ticks  timeout 
)
inline
Deprecated:
The timeout is in milliseconds now: pass an int32_t, or kWaitForever.

◆ TransmitWs2812() [1/2]

esp_err_t ws2812::RmtTx::TransmitWs2812 ( const uint8_t *  grb,
size_t  length,
int32_t  timeout_ms = kWaitForever 
)
inline

Helper dedicated to WS2812/NeoPixel @ 800 kHz. Uses 10 MHz or faster resolution to achieve accurate timings.

Parameters
timeout_msWait for the frame in milliseconds; kWaitForever (-1) waits until done.

◆ TransmitWs2812() [2/2]

template<typename Ticks , std::enable_if_t< std::is_same_v< Ticks, TickType_t >, int > = 0>
esp_err_t ws2812::RmtTx::TransmitWs2812 ( const uint8_t *  grb,
size_t  length,
Ticks  timeout 
)
inline
Deprecated:
The timeout is in milliseconds now: pass an int32_t, or kWaitForever.

Member Data Documentation

◆ kDefaultMemSymbols

constexpr size_t ws2812::RmtTx::kDefaultMemSymbols = WS2812_RMT_MEM_BLOCK_SYMBOLS
staticconstexpr

Channel memory requested by default, in symbols.

◆ kWaitForever

constexpr int32_t ws2812::RmtTx::kWaitForever = -1
staticconstexpr

Transmit timeout that waits until the frame is out, as rmt_tx_wait_all_done() takes it.


The documentation for this class was generated from the following file: