ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputSerial.hpp
Go to the documentation of this file.
1#pragma once
2/*
3* OutputSerial.h - Pixel driver code for ESPixelStick
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
25#include "OutputCommon.hpp"
26#if defined(SUPPORT_OutputProtocol_FireGod) || defined(SUPPORT_OutputProtocol_DMX) || defined(SUPPORT_OutputProtocol_Serial) || defined(SUPPORT_OutputProtocol_Renard)
27
28class c_OutputSerial : public c_OutputCommon
29{
30public:
31 // These functions are inherited from c_OutputCommon
32 c_OutputSerial (OM_OutputPortDefinition_t & OutputPortDefinition,
34 virtual ~c_OutputSerial ();
35
36 // functions to be provided by the derived class
37 virtual void Begin ();
38 virtual bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
39 virtual void GetConfig (ArduinoJson::JsonObject & jsonConfig);
40 void GetDriverName (String& sDriverName);
41 virtual void GetStatus (ArduinoJson::JsonObject & jsonStatus);
42 uint32_t GetNumOutputBufferBytesNeeded () { return OutputBufferSize; };
44 void SetOutputBufferSize (uint32_t NumChannelsAvailable);
45 uint32_t Poll = 0;
46 void StartNewFrame();
47
48 bool IRAM_ATTR ISR_GetNextIntensityToSend(uint32_t &DataToSend);
49 bool IRAM_ATTR ISR_MoreDataToSend() { return (SerialFrameState_t::SerialIdle != SerialFrameState); }
50
51protected:
52 void SetFrameDurration();
53
54#define GS_CHANNEL_LIMIT 2048
55
56 enum class BaudRate
57 {
58 BR_MIN = 38400,
59 BR_FIREGOD = 115200,
60 BR_DMX = 250000,
61 BR_MAX = 460800,
62 BR_DEF = 57600,
63 };
64
65 uint32_t CurrentBaudrate = uint32_t(BaudRate::BR_DEF); // current transmit rate
66
67 /* DMX minimum timings per E1.11 */
68 const uint32_t DMX_BREAK_US = uint32_t(((1.0 / float(BaudRate::BR_DMX)) * 23.0) * float(MicroSecondsInASecond)); // 23 bits = 92us
69 const uint32_t DMX_MAB_US = uint32_t(((1.0 / float(BaudRate::BR_DMX)) * 3.0) * float(MicroSecondsInASecond)); // 3 bits = 12us
70 uint32_t InterFrameGapInMicroSec = DMX_BREAK_US + DMX_MAB_US;
71
72private:
73
74 const uint32_t MAX_HDR_SIZE = 10; // Max generic serial header size
75 const uint32_t MAX_FOOTER_SIZE = 10; // max generic serial footer size
76 const uint32_t MAX_CHANNELS = 1024;
77 const uint16_t DEFAULT_NUM_CHANNELS = 64;
78 const uint32_t BUF_SIZE = (MAX_CHANNELS + MAX_HDR_SIZE + MAX_FOOTER_SIZE);
79 const uint32_t DMX_BITS_PER_BYTE = (1.0 + 8.0 + 2.0);
80 const uint32_t DMX_MaxFrameSize = 512;
81
82 uint32_t Num_Channels = DEFAULT_NUM_CHANNELS; // Number of data channels to transmit
83
84 uint8_t* NextIntensityToSend = nullptr;
85 uint32_t intensity_count = 0;
86 uint32_t SentIntensityCount = 0;
87
88 float IntensityBitTimeInUs = 0.0;
89 uint32_t NumBitsPerIntensity = 1 + 8 + 2; // Start. 8 Data, Stop
90
91 char GenericSerialHeader[65];
92 uint32_t SerialHeaderSize = 0;
93 uint32_t SerialHeaderIndex = 0;
94
95 char GenericSerialFooter[65];
96 uint32_t SerialFooterSize = 0;
97 uint32_t SerialFooterIndex = 0;
98
99 uint16_t FireGodCurrentController = 0;
100 uint8_t FireGodBytesInFrameCount = 0;
101 const uint8_t FireGodNumMaxControllers = 4;
102 const uint8_t FireGodNumChanPerController = 32;
103
104#ifdef USE_SERIAL_DEBUG_COUNTERS
105 uint32_t IntensityBytesSent = 0;
106 uint32_t IntensityBytesSentLastFrame = 0;
107 uint32_t FrameStartCounter = 0;
108 uint32_t FrameEndCounter = 0;
109 uint32_t AbortFrameCounter = 0;
110 uint32_t LastDataSent = 0;
111 uint32_t DmxFrameStart = 0;
112 uint32_t DmxSendData = 0;
113 uint32_t Serialidle = 0;
114#define SERIAL_DEBUG_COUNTER(p) p
115
116#else
117
118#define SERIAL_DEBUG_COUNTER(p)
119
120#endif // def USE_SERIAL_DEBUG_COUNTERS
121
122 bool validate ();
123
124 enum RenardFrameDefinitions_t
125 {
126 CMD_DATA_START = 0x80,
127 ESC_CHAR = 0x7F,
128 FRAME_START_CHAR = 0x7E,
129 FRAME_PAD_CHAR = 0x7D,
130 ESCAPED_OFFSET = 0x4E,
131 MIN_VAL_TO_ESC = FRAME_PAD_CHAR,
132 MAX_VAL_TO_ESC = ESC_CHAR
133 };
134
135 enum FireGodFrameDefinitions_t
136 {
137 FRAME_START = 0x55,
138 DATA_BASE = 100,
139 DATA_MAX = 200,
140 };
141
142 enum SerialFrameState_t
143 {
144 RenardFrameStart,
145 RenardDataStart,
146 RenardSendData,
147 RenardSendEscapedData,
148 DMXSendFrameStart,
149 DMXSendData,
150 GenSerSendHeader,
151 GenSerSendData,
152 GenSerSendFooter,
153 FireGodFrameStart,
154 FireGodSendControllerId,
155 FireGodSendData,
156 FireGodSendFill,
157 SerialIdle
158 };
159 SerialFrameState_t SerialFrameState = SerialIdle;
160
161}; // c_OutputSerial
162
163#endif // defined(SUPPORT_OutputProtocol_FireGod) || defined(SUPPORT_OutputProtocol_DMX) || defined(SUPPORT_OutputProtocol_Serial) || defined(SUPPORT_OutputProtocol_Renard)
#define MicroSecondsInASecond
Definition ESPixelStick.h:57
Definition OutputCommon.hpp:32
virtual void GetDriverName(String &sDriverName)=0
get the name for the instantiated driver
virtual void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputCommon.hpp:41
virtual uint32_t GetNumOutputBufferChannelsServiced()=0
uint32_t OutputBufferSize
Definition OutputCommon.hpp:77
virtual void GetStatus(ArduinoJson::JsonObject &jsonStatus)=0
virtual uint32_t GetNumOutputBufferBytesNeeded()=0
virtual bool SetConfig(ArduinoJson::JsonObject &jsonConfig)
Set a new config in the driver.
Definition OutputCommon.cpp:78
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputCommon.cpp:95
virtual void SetOutputBufferSize(uint32_t NewOutputBufferSize)
Definition OutputCommon.hpp:57
e_OutputProtocolType
Definition OutputMgr.hpp:78
Definition OutputMgrPortDefs.hpp:90