16#ifndef WS2812_RMT_TYPES_HPP
17#define WS2812_RMT_TYPES_HPP
24#include "ws2812_rmt_version.h"
42enum class [[nodiscard]]
Error : uint8_t {
70 return "NotInitialized";
72 return "InvalidArgument";
78 return "DeviceIdMismatch";
88 return "TimingUnreachable";
107 [[nodiscard]]
constexpr bool ok() const noexcept {
108 return error == Error::Ok;
111 constexpr explicit operator bool() const noexcept {
120 return {v, Error::Ok};
138 [[nodiscard]]
constexpr bool ok() const noexcept {
139 return error == Error::Ok;
142 constexpr explicit operator bool() const noexcept {
223struct EnumLast<
Gamma> {
244 return Colour{.
r =
static_cast<uint8_t
>((rgb >> 16U) & 0xFFU),
245 .g =
static_cast<uint8_t
>((rgb >> 8U) & 0xFFU),
246 .b =
static_cast<uint8_t
>(rgb & 0xFFU),
255 return Colour{.
r =
static_cast<uint8_t
>((wrgb >> 16U) & 0xFFU),
256 .g =
static_cast<uint8_t
>((wrgb >> 8U) & 0xFFU),
257 .b =
static_cast<uint8_t
>(wrgb & 0xFFU),
258 .
w =
static_cast<uint8_t
>((wrgb >> 24U) & 0xFFU)};
261 [[nodiscard]]
constexpr uint32_t
Packed() const noexcept {
262 return (
static_cast<uint32_t
>(
r) << 16U) | (
static_cast<uint32_t
>(
g) << 8U) |
263 static_cast<uint32_t
>(
b);
375 uint32_t nominal_ns)
noexcept {
376 return Range{.
min_ns = min_ns, .max_ns = max_ns, .nominal_ns = nominal_ns};
396 uint32_t reset_min_ns, uint32_t max_low_ns)
noexcept {
398 .period_max_ns = period_max_ns,
399 .reset_min_ns = reset_min_ns,
400 .max_low_ns = max_low_ns};
418 .period_min_ns = limits.period_min_ns,
419 .period_max_ns = limits.period_max_ns,
420 .reset_min_ns = limits.reset_min_ns,
421 .max_low_ns = limits.max_low_ns};
529 return WS2812_RMT_VERSION_STRING;
533 return WS2812_RMT_VERSION_MAJOR;
537 return WS2812_RMT_VERSION_MINOR;
541 return WS2812_RMT_VERSION_PATCH;
LogLevel
Severity passed to the optional Log() hook.
Definition ws2812_rmt_types.hpp:160
constexpr uint32_t kResetMarginUs
Added to the datasheet reset minimum when Config::reset_us is 0, in microseconds (A-3).
Definition ws2812_rmt_types.hpp:331
constexpr Range MakeRange(uint32_t min_ns, uint32_t max_ns, uint32_t nominal_ns) noexcept
A timing window from its three numbers.
Definition ws2812_rmt_types.hpp:374
constexpr ColourOrder DefaultOrder(Variant variant) noexcept
The colour order a named variant uses unless Config overrides it.
Definition ws2812_rmt_types.hpp:488
constexpr const char * GetDriverVersion() noexcept
Definition ws2812_rmt_types.hpp:528
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition ws2812_rmt_types.hpp:536
constexpr uint32_t kMaxResolutionHz
The highest tick rate the driver accepts from a port, in Hz.
Definition ws2812_rmt_types.hpp:339
constexpr uint32_t kMaxSettleUs
Longest power-on settle Config may ask for, in microseconds.
Definition ws2812_rmt_types.hpp:335
constexpr ColourOrder kOrderRgb
Red, green, blue.
Definition ws2812_rmt_types.hpp:282
constexpr uint32_t kMaxDurationNs
Longest single high or low duration a Custom timing may name, in ns (covers 400 kbit/s).
Definition ws2812_rmt_types.hpp:324
constexpr uint32_t kV5MinHighMv
The fixed floor of VIH of the V5 family, in millivolts (V5.0, datasheet p.2); later revisions print a...
Definition ws2812_rmt_types.hpp:346
constexpr uint32_t kMaxResetUs
Longest reset a timing or Config::reset_us may name, in microseconds.
Definition ws2812_rmt_types.hpp:328
constexpr uint32_t kMaxSlackMs
Longest transmit slack Config may ask for, in milliseconds.
Definition ws2812_rmt_types.hpp:337
constexpr uint32_t kMaxSupplyMv
Supplies above this count as 6 V in MinLogicHighMv() (the absolute maximum is 5.3 V).
Definition ws2812_rmt_types.hpp:343
Channel
A colour channel of a pixel.
Definition ws2812_rmt_types.hpp:199
constexpr ColourOrder kOrderRgbw
Red, green, blue, white: SK6812RGBW Rev 01 and Rev 03.
Definition ws2812_rmt_types.hpp:288
constexpr Limits MakeLimits(uint32_t period_min_ns, uint32_t period_max_ns, uint32_t reset_min_ns, uint32_t max_low_ns) noexcept
The limits of a timing from their four numbers.
Definition ws2812_rmt_types.hpp:395
Gamma
The transfer curve applied before brightness (convenience, not a chip feature).
Definition ws2812_rmt_types.hpp:215
constexpr uint32_t kSk6812MinHighMv
The 3.4 V input high level of the SK6812 family at 5 V, in millivolts: the minimum of SK6812RGBW Rev ...
Definition ws2812_rmt_types.hpp:351
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition ws2812_rmt_types.hpp:65
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition ws2812_rmt_types.hpp:540
constexpr Timing ProfileTiming(Variant variant) noexcept
The window set of a named variant, as nanoseconds. Values are the intersection of the windows of ever...
Definition ws2812_rmt_types.hpp:430
Variant
The timing generation (window set) of the part, chosen by what is printed on or known about it.
Definition ws2812_rmt_types.hpp:176
Error
Why a call failed. Values 0 to 9 are the shared base set; chip-specific values start at 16.
Definition ws2812_rmt_types.hpp:42
constexpr ColourOrder kOrderGrb
Green, red, blue: the wire order of every WS2812 and SK6812 RGB part.
Definition ws2812_rmt_types.hpp:279
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition ws2812_rmt_types.hpp:532
constexpr size_t kMaxPixels
Largest strip the driver accepts, in pixels.
Definition ws2812_rmt_types.hpp:333
constexpr uint32_t kMaxPeriodNs
Longest period a Custom timing may name, in ns.
Definition ws2812_rmt_types.hpp:326
constexpr Timing MakeTiming(const Range &t0h, const Range &t0l, const Range &t1h, const Range &t1l, const Limits &limits) noexcept
A timing from its four windows and its limits.
Definition ws2812_rmt_types.hpp:412
constexpr ColourOrder kOrderGrbw
Green, red, blue, white: SK6812RGBW Rev 07 (the default for Variant::Sk6812Rgbw).
Definition ws2812_rmt_types.hpp:285
@ Warning
Something unexpected that the driver recovered from.
@ Debug
Detail for bring-up.
@ W
White (RGBW parts only).
@ Gamma22
round(255 * (v / 255) ^ 2.2) from a committed table.
@ Ws2812
WS2812 (6 pin): 0.35/0.8/0.7/0.6 us +-150 ns, reset above 50 us.
@ Ws2812bV5
WS2812B V5 and V6, WS2812B-2020, WS2812B-1313, WS2812C-2020: reset above 280 us.
@ Ws2812c
WS2812C (5050) and WS2812-2020: T1L window 220 to 420 ns.
@ Ws2812d
WS2812D-F8: 750 to 1000 ns on T0L and T1H.
@ Custom
Any other part with the same frame: the whole timing is Config::custom.
@ Ws2812bPreV5
WS2812B and WS2812S of 2013 to 2017: reset above 300 us.
@ Sk6812
SK6812 RGB (Rev 01): 0.3/0.9/0.6/0.6 us +-150 ns, reset 80 us.
@ Sk6812Rgbw
SK6812RGBW: 32 bit frame, low inside a frame below 20 us.
@ InvalidArgument
Validate() failed, or a pixel index is out of range.
@ NotPowered
Show() or TraceWire() between PowerOff() and PowerOn(): nothing is sent.
@ DeviceIdMismatch
Not returned by this driver: the pixels are write-only.
@ Crc
Not returned by this driver: the frame has no checksum.
@ DeviceFault
Not returned by this driver: no pixel reports a fault.
@ NotInitialized
EnsureInitialized() has not succeeded.
@ TimingUnreachable
The port's tick rate cannot place any tick count inside a timing window.
@ Unsupported
PowerOn() or PowerOff() on a port without a GpioSet() hook.
@ Timeout
Not returned by this driver: the port reports a timeout as false.
@ Busy
Not returned by this driver: Show() blocks until the frame is out.
The WS2812_RMT driver: everything it declares lives here; internals in detail.
Definition ws2812_rmt.hpp:29
The order of the channels on the wire, first sent first.
Definition ws2812_rmt_types.hpp:268
friend constexpr bool operator==(const ColourOrder &lhs, const ColourOrder &rhs) noexcept=default
Hidden friend: exact member comparison.
std::array< Channel, 4 > ch
Channels in wire order.
Definition ws2812_rmt_types.hpp:269
uint8_t count
3 or 4 channels used.
Definition ws2812_rmt_types.hpp:271
A pixel colour, 8 bit per channel; w is used only by four-channel orders.
Definition ws2812_rmt_types.hpp:229
uint8_t g
Green.
Definition ws2812_rmt_types.hpp:231
friend constexpr bool operator==(const Colour &lhs, const Colour &rhs) noexcept=default
Hidden friend: exact member comparison.
uint8_t r
Red.
Definition ws2812_rmt_types.hpp:230
uint8_t w
White.
Definition ws2812_rmt_types.hpp:233
static constexpr Colour FromPacked(uint32_t rgb) noexcept
A colour from 0xRRGGBB.
Definition ws2812_rmt_types.hpp:243
static constexpr Colour FromPackedW(uint32_t wrgb) noexcept
A colour from 0xWWRRGGBB.
Definition ws2812_rmt_types.hpp:254
uint8_t b
Blue.
Definition ws2812_rmt_types.hpp:232
constexpr uint32_t Packed() const noexcept
Definition ws2812_rmt_types.hpp:261
Everything EnsureInitialized() uses. The defaults suit a current WS2812B (V5, V6).
Definition ws2812_rmt_types.hpp:509
uint32_t pixel_count
Pixels in the strip; 0 means the whole capacity.
Definition ws2812_rmt_types.hpp:515
ColourOrder order
Wire order when use_default_order is false.
Definition ws2812_rmt_types.hpp:512
uint8_t brightness
Linear dimming at start, 0 to 255.
Definition ws2812_rmt_types.hpp:513
uint32_t transmit_slack_ms
Added to the frame time to form the port timeout.
Definition ws2812_rmt_types.hpp:518
Variant variant
The timing generation; no profile fits every part.
Definition ws2812_rmt_types.hpp:510
Gamma gamma
Transfer curve at start.
Definition ws2812_rmt_types.hpp:514
Timing custom
Used only with Variant::Custom; all zero otherwise.
Definition ws2812_rmt_types.hpp:519
uint32_t reset_us
Reset low time; 0 = datasheet minimum plus kResetMarginUs.
Definition ws2812_rmt_types.hpp:516
static constexpr Config Default() noexcept
Definition ws2812_rmt_types.hpp:522
bool use_default_order
False: order is used. Always false for Custom.
Definition ws2812_rmt_types.hpp:511
uint32_t power_on_settle_us
Wait after PowerOn() (no datasheet value, A-16).
Definition ws2812_rmt_types.hpp:517
The four limits of a Timing (a parameter group of MakeTiming()).
Definition ws2812_rmt_types.hpp:380
uint32_t period_max_ns
Longest bit period, 0 none.
Definition ws2812_rmt_types.hpp:382
uint32_t reset_min_ns
The low time that must be exceeded to latch.
Definition ws2812_rmt_types.hpp:383
uint32_t max_low_ns
The low time that must stay below inside a frame, 0 for reset_min_ns.
Definition ws2812_rmt_types.hpp:384
uint32_t period_min_ns
Shortest bit period, 0 none.
Definition ws2812_rmt_types.hpp:381
A timing window in nanoseconds, with the value the driver aims for.
Definition ws2812_rmt_types.hpp:292
uint32_t nominal_ns
The target inside the window.
Definition ws2812_rmt_types.hpp:295
uint32_t max_ns
Inclusive upper bound; 0 means the document gives none.
Definition ws2812_rmt_types.hpp:294
friend constexpr bool operator==(const Range &lhs, const Range &rhs) noexcept=default
Hidden friend: exact member comparison.
uint32_t min_ns
Inclusive lower bound.
Definition ws2812_rmt_types.hpp:293
constexpr bool ok() const noexcept
Definition ws2812_rmt_types.hpp:138
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition ws2812_rmt_types.hpp:154
static constexpr Result Success() noexcept
Definition ws2812_rmt_types.hpp:146
The value of a call, or why there is none.
Definition ws2812_rmt_types.hpp:102
constexpr bool ok() const noexcept
Definition ws2812_rmt_types.hpp:107
static constexpr Result Success(T v) noexcept
A successful result.
Definition ws2812_rmt_types.hpp:119
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition ws2812_rmt_types.hpp:127
The wire timing of one window set.
Definition ws2812_rmt_types.hpp:308
Range t1h
1 code, high time.
Definition ws2812_rmt_types.hpp:311
uint32_t max_low_ns
The low time that must stay below inside a frame; 0 = reset_min_ns.
Definition ws2812_rmt_types.hpp:316
uint32_t period_max_ns
Longest bit period; 0 none.
Definition ws2812_rmt_types.hpp:314
uint32_t period_min_ns
Shortest bit period (high plus low); 0 none.
Definition ws2812_rmt_types.hpp:313
Range t0l
0 code, low time.
Definition ws2812_rmt_types.hpp:310
uint32_t reset_min_ns
The low time that must be exceeded to latch.
Definition ws2812_rmt_types.hpp:315
friend constexpr bool operator==(const Timing &lhs, const Timing &rhs) noexcept=default
Hidden friend: exact member comparison.
Range t1l
1 code, low time.
Definition ws2812_rmt_types.hpp:312
Range t0h
0 code, high time.
Definition ws2812_rmt_types.hpp:309
Compile-time helpers of the WS2812_RMT driver: exact hook matching and enumeration checks.