HF-WS2812 Driver 0.1.0-dev
HF-WS2812 ESP32 RMT Driver
Loading...
Searching...
No Matches
ws2812_cpp.hpp
Go to the documentation of this file.
1
7#pragma once
8#include "rmt_wrapper.hpp"
9#include "ws2812_control.h"
10#include "ws2812_version.h"
11#include <cstdint>
12#include <vector>
13
14#ifdef __cplusplus
15
17enum class LedType { RGB, RGBW };
18
26class WS2812Strip {
27public:
34 explicit WS2812Strip(gpio_num_t gpio = (gpio_num_t)CONFIG_WS2812_LED_RMT_TX_GPIO,
35 int channel = CONFIG_WS2812_LED_RMT_TX_CHANNEL, uint32_t num_leds = NUM_LEDS,
36#if CONFIG_WS2812_LED_TYPE_RGBW
37 LedType type = LedType::RGBW,
38#else
39 LedType type = LedType::RGB,
40#endif
41 uint16_t t0h = WS2812_T0H, uint16_t t1h = WS2812_T1H,
42 uint16_t t0l = WS2812_T0L, uint16_t t1l = WS2812_T1L,
43 uint8_t brightness = WS2812_DEFAULT_BRIGHTNESS);
44
50 esp_err_t Begin();
51
58 void SetPixel(uint32_t index, uint32_t rgbw);
59
61 uint32_t Length() const;
62
66 esp_err_t Show();
67
73 void SetBrightness(uint8_t value);
74
83 void SetNumLeds(uint32_t num_leds);
84
90 void SetTimings(uint16_t t0h, uint16_t t1h, uint16_t t0l, uint16_t t1l);
91
98 static uint32_t ColorWheel(uint8_t pos);
99
100 // ===========================================================================
101 // Driver Version
102 // ===========================================================================
103
105 static constexpr const char* GetDriverVersion() noexcept {
106 return HF_WS2812_RMT_VERSION_STRING;
107 }
108
110 static constexpr uint8_t GetDriverVersionMajor() noexcept {
111 return HF_WS2812_RMT_VERSION_MAJOR;
112 }
113
115 static constexpr uint8_t GetDriverVersionMinor() noexcept {
116 return HF_WS2812_RMT_VERSION_MINOR;
117 }
118
120 static constexpr uint8_t GetDriverVersionPatch() noexcept {
121 return HF_WS2812_RMT_VERSION_PATCH;
122 }
123
124private:
125 std::vector<uint32_t> pixels_;
126 std::vector<rmt_symbol_word_t> buffer_;
127 ws2812::RmtTx rmt_;
128 gpio_num_t gpio_;
129 int channel_;
130 LedType type_;
131 uint16_t t0h_;
132 uint16_t t1h_;
133 uint16_t t0l_;
134 uint16_t t1l_;
135 uint8_t brightness_;
136 uint32_t num_leds_;
137};
138
140inline const char* GetWS2812DriverVersion() noexcept {
141 return HF_WS2812_RMT_VERSION_STRING;
142}
143
144#endif // __cplusplus
Definition rmt_wrapper.hpp:50
A modern C++17 header‑only wrapper around the ESP‑IDF v5.3 “new” RMT.
ESP-IDF RMT based driver for WS2812 / NeoPixel LED chains.
#define WS2812_T1L
Definition ws2812_control.h:37
#define WS2812_T0L
Definition ws2812_control.h:36
#define NUM_LEDS
Definition ws2812_control.h:20
#define WS2812_T0H
Definition ws2812_control.h:32
#define WS2812_DEFAULT_BRIGHTNESS
Definition ws2812_control.h:40
#define WS2812_T1H
Definition ws2812_control.h:34