ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputWS2811Rmt.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputWS2811Rmt.h - WS2811 driver code for ESPixelStick RMT Channel
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2015, 2025 Shelby Merrick
7* http://www.forkineye.com
8*
9* This program is provided free for you to use in any way that you wish,
10* subject to the laws and regulations where you are using it. Due diligence
11* is strongly suggested before using this code. Please give credit where due.
12*
13* The Author makes no warranty of any kind, express or implied, with regard
14* to this program or the documentation contained in this document. The
15* Author shall not be liable in any event for incidental or consequential
16* damages in connection with, or arising out of, the furnishing, performance
17* or use of these programs.
18*
19* This is a derived class that converts data in the output buffer into
20* pixel intensities and then transmits them through the configured serial
21* interface.
22*
23*/
24#include "ESPixelStick.h"
25#if defined(SUPPORT_OutputProtocol_WS2811) && defined(ARDUINO_ARCH_ESP32)
26
27#include "OutputWS2811.hpp"
28#include "OutputRmt.hpp"
29
30class c_OutputWS2811Rmt : public c_OutputWS2811
31{
32public:
33 // These functions are inherited from c_OutputCommon
34 c_OutputWS2811Rmt (OM_OutputPortDefinition_t & OutputPortDefinition,
36 virtual ~c_OutputWS2811Rmt ();
37
38 // functions to be provided by the derived class
39 void Begin ();
40 bool SetConfig (ArduinoJson::JsonObject& jsonConfig);
41 uint32_t Poll ();
42 bool RmtPoll ();
43 void GetStatus (ArduinoJson::JsonObject& jsonStatus);
44 void SetOutputBufferSize (uint32_t NumChannelsAvailable);
45 bool DriverIsSendingIntensityData() {return (Rmt.DriverIsSendingIntensityData() || false == canRefresh());}
46 void PauseOutput(bool State);
47 bool ISR_GetNextBitToSend (rmt_item32_t &DataToSend);
48 void StartNewDataFrame();
49
50private:
51
52#ifdef USE_RMT_DEBUG_COUNTERS
53 uint32_t CanRefresh = 0;
54 uint32_t CannotRefresh = 0;
55#endif // def USE_RMT_DEBUG_COUNTERS
56// The adjustments compensate for rounding errors in the calculations
57#define WS2811_PIXEL_RMT_TICKS_BIT_0_HIGH uint16_t ( (WS2811_PIXEL_NS_BIT_0_HIGH / RMT_TickLengthNS) + 0.0)
58#define WS2811_PIXEL_RMT_TICKS_BIT_0_LOW uint16_t ( (WS2811_PIXEL_NS_BIT_0_LOW / RMT_TickLengthNS) + 0.0)
59#define WS2811_PIXEL_RMT_TICKS_BIT_1_HIGH uint16_t ( (WS2811_PIXEL_NS_BIT_1_HIGH / RMT_TickLengthNS) - 1.0)
60#define WS2811_PIXEL_RMT_TICKS_BIT_1_LOW uint16_t ( (WS2811_PIXEL_NS_BIT_1_LOW / RMT_TickLengthNS) + 1.0)
61#define WS2811_PIXEL_RMT_TICKS_IDLE uint16_t ( (WS2811_PIXEL_IDLE_TIME_NS / RMT_TickLengthNS) + 1.0)
62
63 rmt_item32_t ZeroBit = {WS2811_PIXEL_RMT_TICKS_BIT_0_HIGH, 0, WS2811_PIXEL_RMT_TICKS_BIT_0_LOW, 1};
64 rmt_item32_t OneBit = {WS2811_PIXEL_RMT_TICKS_BIT_1_HIGH, 0, WS2811_PIXEL_RMT_TICKS_BIT_1_LOW, 1};
65 rmt_item32_t IfgBit;
66 uint32_t IfgBitCount;
67 uint32_t IfgBitCurrentCount;
68 uint32_t DataPattern;
69 uint32_t DataPatternMask;
70
71 // #define WS2811_RMT_DEBUG_COUNTERS
72 #ifdef WS2811_RMT_DEBUG_COUNTERS
73 #define INC_WS2811_RMT_DEBUG_COUNTERS(c) (++RmtDebugCounters.c)
74 struct
75 {
76 uint32_t GetNextBit = 0;
77 uint32_t FrameStarts = 0;
78 uint32_t FrameEnds = 0;
79 uint32_t BreakBits = 0;
80 uint32_t MabBits = 0;
81 uint32_t StartBits = 0;
82 uint32_t DataBits = 0;
83 uint32_t StopBits = 0;
84 uint32_t Underrun = 0;
85 } RmtDebugCounters;
86 #else
87 #define INC_WS2811_RMT_DEBUG_COUNTERS(c)
88 #endif // def WS2811_RMT_DEBUG_COUNTERS
89
90 c_OutputRmt Rmt;
91
92}; // c_OutputWS2811Rmt
93
94#endif // defined(SUPPORT_OutputProtocol_WS2811) && defined(ARDUINO_ARCH_ESP32)
e_OutputProtocolType
Definition OutputMgr.hpp:78
void SetConfig(const char *DataString)
Definition main.cpp:329
Definition OutputMgrPortDefs.hpp:90