3232#endif
3333#endif
3434
35- #if defined(__GNUC__) && !defined(__clang__)
3635#pragma GCC push_options
3736#pragma GCC optimize("O3")
3837#pragma GCC optimize("no-tree-loop-distribute-patterns")
39- #endif
4038
4139#include < cstdint>
4240#include < algorithm>
5149#endif
5250#include " firmware/debug/debug_debug.h"
5351
54- namespace pixeldmxmulti
55- {
52+ namespace pixeldmxmulti {
5653#if !defined(CONFIG_DMXNODE_PIXEL_MAX_PORTS)
5754#error
5855#endif
5956static constexpr auto kMaxPorts = CONFIG_DMXNODE_PIXEL_MAX_PORTS ;
6057} // namespace pixeldmxmulti
6158
62- class PixelDmxMulti final : public PixelDmxConfiguration
63- {
59+ class PixelDmxMulti final : public PixelDmxConfiguration {
6460 public:
65- PixelDmxMulti ()
66- {
61+ PixelDmxMulti () {
6762 DEBUG_ENTRY ();
6863
6964 assert (s_this == nullptr );
@@ -79,15 +74,13 @@ class PixelDmxMulti final : public PixelDmxConfiguration
7974 DEBUG_EXIT ();
8075 }
8176
82- ~PixelDmxMulti ()
83- {
77+ ~PixelDmxMulti () {
8478 DEBUG_ENTRY ();
8579
8680 DEBUG_EXIT ();
8781 }
8882
89- void ApplyConfiguration ()
90- {
83+ void ApplyConfiguration () {
9184 started_[0 ] = 0 ;
9285 started_[1 ] = 0 ;
9386
@@ -101,72 +94,57 @@ class PixelDmxMulti final : public PixelDmxConfiguration
10194 output_type_.Blackout ();
10295 }
10396
104- void Start (uint32_t port_index)
105- {
97+ void Start (uint32_t port_index) {
10698 const auto kIndex = (port_index <= 31 ) ? 0 : 1 ;
10799 DEBUG_PRINTF (" %u [%u]" , port_index, kIndex );
108100
109- if (kIndex == 0 )
110- {
101+ if (kIndex == 0 ) {
111102 started_[0 ] |= (1U << port_index);
112- }
113- else
114- {
103+ } else {
115104 started_[1 ] |= (1U << (port_index - 32 ));
116105 }
117106
118107#if defined(PIXELDMXSTARTSTOP_GPIO)
119- if ((started_[0 ] != 0 ) || (started_[1 ] != 0 ))
120- {
108+ if ((started_[0 ] != 0 ) || (started_[1 ] != 0 )) {
121109 gpio::Set (PIXELDMXSTARTSTOP_GPIO );
122110 }
123111#endif
124112 }
125113
126- void Stop (uint32_t port_index)
127- {
114+ void Stop (uint32_t port_index) {
128115 const auto kIndex = (port_index <= 31 ) ? 0 : 1 ;
129116 DEBUG_PRINTF (" %u [%u]" , port_index, kIndex );
130117
131- if (kIndex == 0 )
132- {
133- if (started_[0 ] & (1U << port_index))
134- {
118+ if (kIndex == 0 ) {
119+ if (started_[0 ] & (1U << port_index)) {
135120 started_[0 ] &= ~(1U << port_index);
136121 }
137- }
138- else
139- {
140- if (started_[1 ] & (1U << (port_index - 32 )))
141- {
122+ } else {
123+ if (started_[1 ] & (1U << (port_index - 32 ))) {
142124 started_[1 ] &= ~(1U << (port_index - 32 ));
143125 }
144126 }
145127
146128#if defined(PIXELDMXSTARTSTOP_GPIO)
147- if ((started_[0 ] == 0 ) && (started_[1 ] == 0 ))
148- {
129+ if ((started_[0 ] == 0 ) && (started_[1 ] == 0 )) {
149130 gpio::Clr (PIXELDMXSTARTSTOP_GPIO );
150131 }
151132#endif
152133 }
153134
154- template <bool doUpdate> void SetData ( uint32_t port_index, const uint8_t * data, uint32_t length)
155- {
135+ template <bool doUpdate>
136+ void SetData ( uint32_t port_index, const uint8_t * data, uint32_t length) {
156137 logic_analyzer::Ch0Set ();
157138
158139 SetData (port_index, data, length);
159140
160141 auto & port_info = PixelDmxConfiguration::GetPortInfo ();
161142
162- if constexpr (doUpdate)
163- {
164- if (port_index == port_info.protocol_port_index_last )
165- {
143+ if constexpr (doUpdate) {
144+ if (port_index == port_info.protocol_port_index_last ) {
166145 logic_analyzer::Ch1Set ();
167146
168- for (uint32_t index = 0 ; index <= port_info.protocol_port_index_last ; index++)
169- {
147+ for (uint32_t index = 0 ; index <= port_info.protocol_port_index_last ; index++) {
170148 logic_analyzer::Ch2Set ();
171149 SetData (index, dmxnode::Data::Backup (index), dmxnode::Data::GetLength (index));
172150 logic_analyzer::Ch2Clear ();
@@ -181,19 +159,16 @@ class PixelDmxMulti final : public PixelDmxConfiguration
181159 logic_analyzer::Ch0Clear ();
182160 }
183161
184- void Sync ([[maybe_unused]] uint32_t port_index)
185- {
162+ void Sync ([[maybe_unused]] uint32_t port_index) {
186163 logic_analyzer::Ch2Set ();
187164
188165 need_sync_ = true ;
189166
190167 logic_analyzer::Ch2Clear ();
191168 }
192169
193- void Sync ()
194- {
195- if (!need_sync_)
196- {
170+ void Sync () {
171+ if (!need_sync_) {
197172 return ;
198173 }
199174
@@ -211,29 +186,22 @@ class PixelDmxMulti final : public PixelDmxConfiguration
211186 dmxnode::OutputStyle GetOutputStyle ([[maybe_unused]] uint32_t port_index) const { return dmxnode::OutputStyle::kDelta ; }
212187#endif
213188
214- void Blackout (bool blackout = true )
215- {
189+ void Blackout (bool blackout = true ) {
216190 blackout_ = blackout;
217191
218- while (output_type_.IsUpdating ())
219- {
192+ while (output_type_.IsUpdating ()) {
220193 // wait for completion
221194 }
222195
223- if (blackout)
224- {
196+ if (blackout) {
225197 output_type_.Blackout ();
226- }
227- else
228- {
198+ } else {
229199 output_type_.Update ();
230200 }
231201 }
232202
233- void FullOn ()
234- {
235- while (output_type_.IsUpdating ())
236- {
203+ void FullOn () {
204+ while (output_type_.IsUpdating ()) {
237205 // wait for completion
238206 }
239207
@@ -253,22 +221,19 @@ class PixelDmxMulti final : public PixelDmxConfiguration
253221
254222 uint16_t GetDmxFootprint () { return 0 ; }
255223
256- bool GetSlotInfo ([[maybe_unused]] uint16_t slot_offset, dmxnode::SlotInfo& slot_info)
257- {
224+ bool GetSlotInfo ([[maybe_unused]] uint16_t slot_offset, dmxnode::SlotInfo& slot_info) {
258225 slot_info.type = 0x00 ; // ST_PRIMARY
259226 slot_info.category = 0x0001 ; // SD_INTENSITY
260227 return true ;
261228 }
262229
263- static PixelDmxMulti& Get ()
264- {
230+ static PixelDmxMulti& Get () {
265231 assert (s_this != nullptr ); // Ensure that s_this is valid
266232 return *s_this;
267233 }
268234
269235 private:
270- void SetData (uint32_t port_index, const uint8_t * data, uint32_t length)
271- {
236+ void SetData (uint32_t port_index, const uint8_t * data, uint32_t length) {
272237 assert (data != nullptr );
273238 assert (length <= dmxnode::kUniverseSize );
274239
@@ -292,11 +257,9 @@ class PixelDmxMulti final : public PixelDmxConfiguration
292257
293258 uint32_t d = 0 ;
294259
295- if (kChannelsPerPixel == 3 )
296- {
260+ if (kChannelsPerPixel == 3 ) {
297261 // Define a lambda to handle pixel setting based on color order
298- auto set_pixels_colour_rtz = [&](uint32_t portindex, uint32_t pixelindex, uint32_t r, uint32_t g, uint32_t b)
299- {
262+ auto set_pixels_colour_rtz = [&](uint32_t portindex, uint32_t pixelindex, uint8_t r, uint8_t g, uint8_t b) {
300263#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
301264 const auto kGammaTable = PixelDmxConfiguration::GetGammaTable ();
302265 r = kGammaTable [r];
@@ -307,30 +270,26 @@ class PixelDmxMulti final : public PixelDmxConfiguration
307270 };
308271
309272 // Define a lambda to handle pixel setting based on color order
310- auto set_pixels_colour3 = [&](uint32_t portindex, uint32_t pixelindex, uint32_t r, uint32_t g, uint32_t b)
311- {
273+ auto set_pixels_colour3 = [&](uint32_t portindex, uint32_t pixelindex, uint8_t r, uint8_t g, uint8_t b) {
312274#if defined(CONFIG_PIXELDMX_ENABLE_GAMMATABLE)
313275 const auto kGammaTable = PixelDmxConfiguration::GetGammaTable ();
314276 r = kGammaTable [r];
315277 g = kGammaTable [g];
316278 b = kGammaTable [b];
317279#endif
318280
319- switch (kPixelType )
320- {
281+ switch (kPixelType ) {
321282 case pixel::LedType::kWS2801 :
322283 output_type_.SetColourWS2801 (portindex, pixelindex, r, g, b);
323284 break ;
324285 case pixel::LedType::kAPA102 :
325286 case pixel::LedType::kSK9822 :
326287 output_type_.SetPixel4Bytes (portindex, 1 + pixelindex, PixelDmxConfiguration::GetGlobalBrightness (), b, g, r);
327288 break ;
328- case pixel::LedType::kP9813 :
329- {
289+ case pixel::LedType::kP9813 : {
330290 const auto kFlag = static_cast <uint8_t >(0xC0 | ((~b & 0xC0 ) >> 2 ) | ((~r & 0xC0 ) >> 4 ) | ((~r & 0xC0 ) >> 6 ));
331291 output_type_.SetPixel4Bytes (portindex, 1 + pixelindex, kFlag , b, g, r);
332- }
333- break ;
292+ } break ;
334293 default :
335294 assert (0 );
336295 __builtin_unreachable ();
@@ -352,40 +311,29 @@ class PixelDmxMulti final : public PixelDmxConfiguration
352311 assert (kMapIndex < sizeof (kChannelMap ) / sizeof (kChannelMap [0 ])); // Runtime check
353312 auto const & map = kChannelMap [kMapIndex ];
354313
355- if (kIsRtzProtocol )
356- {
357- for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++)
358- {
314+ if (kIsRtzProtocol ) {
315+ for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++) {
359316 auto const kPixelIndexStart = j * kGroupingCount ;
360- for (uint32_t k = 0 ; k < kGroupingCount ; k++)
361- {
317+ for (uint32_t k = 0 ; k < kGroupingCount ; k++) {
362318 set_pixels_colour_rtz (kOutIndex , kPixelIndexStart + k, data[d + map[0 ]], data[d + map[1 ]], data[d + map[2 ]]);
363319 }
364320 d += 3 ; // Increment by 3 since we're processing 3 channels per pixel
365321 }
366- }
367- else
368- {
369- for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++)
370- {
322+ } else {
323+ for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++) {
371324 auto const kPixelIndexStart = j * kGroupingCount ;
372- for (uint32_t k = 0 ; k < kGroupingCount ; k++)
373- {
325+ for (uint32_t k = 0 ; k < kGroupingCount ; k++) {
374326 set_pixels_colour3 (kOutIndex , kPixelIndexStart + k, data[d + map[0 ]], data[d + map[1 ]], data[d + map[2 ]]);
375327 }
376328 d += 3 ; // Increment by 3 since we're processing 3 channels per pixel
377329 }
378330 }
379- }
380- else
381- {
331+ } else {
382332 assert (kChannelsPerPixel == 4 );
383333 assert (kIsRtzProtocol );
384- for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++)
385- {
334+ for (uint32_t j = kBeginIndex ; (j < kEndIndex ) && (d < length); j++) {
386335 auto const kPixelIndexStart = (j * kGroupingCount );
387- for (uint32_t k = 0 ; k < kGroupingCount ; k++)
388- {
336+ for (uint32_t k = 0 ; k < kGroupingCount ; k++) {
389337 output_type_.SetColourRTZ (kOutIndex , kPixelIndexStart + k, data[d], data[d + 1 ], data[d + 2 ], data[d + 3 ]);
390338 }
391339 d = d + 4 ; // Increment by 4 since we're processing 4 channels per pixel
@@ -403,9 +351,7 @@ class PixelDmxMulti final : public PixelDmxConfiguration
403351 static inline PixelDmxMulti* s_this;
404352};
405353
406- #if defined(__GNUC__) && !defined(__clang__)
407354#pragma GCC pop_options
408- #endif
409355#if defined(_NDEBUG)
410356#undef _NDEBUG
411357#define NDEBUG
0 commit comments