GCC Code Coverage Report


Directory: ./
File: channeloutput/BBBMatrix.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 553 680 81.3%
Functions: 17 19 89.5%
Branches: 644 1317 48.9%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the GPL v2 as described in the
10 * included LICENSE.GPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #ifdef __ARM_NEON
16 #include <arm_neon.h>
17 #endif
18
19 #include "fpp-json.h"
20
21 #include "BBBMatrix.h"
22 #include <sys/mman.h>
23 #include <sys/wait.h>
24 #include <cmath>
25 #include <fstream>
26
27 #include "../Warnings.h"
28 #include "ChannelOutputSetup.h"
29 #include "../common.h"
30 #include "../log.h"
31 #include "../settings.h"
32
33 #include "GammaLUT.h"
34 #include "PanelInterleaveHandler.h"
35 #include "overlays/PixelOverlay.h"
36 #include "util/BBBUtils.h"
37
38 #include "Plugin.h"
39 class BBBMatrixPlugin : public FPPPlugins::Plugin, public FPPPlugins::ChannelOutputPlugin {
40 public:
41 57 BBBMatrixPlugin() :
42
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
171 FPPPlugins::Plugin("BBBMatrix") {
43 57 }
44 57 virtual ChannelOutput* createChannelOutput(unsigned int startChannel, unsigned int channelCount) override {
45
2/6
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 return new BBBMatrix(startChannel, channelCount);
46 }
47 };
48
49 extern "C" {
50 57 FPPPlugins::Plugin* createPlugin() {
51
2/6
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
114 return new BBBMatrixPlugin();
52 }
53 }
54
55 // These are the number of clock cycles it takes to clock out a single "row" of bits (1 bit) for 32x16 1/8 P10 scan panels. Other
56 // panel types and scan rates and stuff are proportional to these
57 static const uint32_t v1Timings[8][16] = {
58 { 0xA65, 0x14EA, 0x1F6F, 0x29ED, 0x346E, 0x3EEE, 0x496C, 0x53EB, 0x5E6B, 0x68ED, 0x7374, 0x7DF0, 0x887B, 0x92F4, 0x9D75, 0xA7FB },
59 { 0xA69, 0x14EA, 0x1F6F, 0x29ED, 0x346E, 0x3EEE, 0x496C, 0x53EB, 0x5E6B, 0x68ED, 0x7374, 0x7DF0, 0x887B, 0x92F4, 0x9D75, 0xA7FB },
60 { 0xA6A, 0x14EA, 0x1F6F, 0x29ED, 0x346E, 0x3EEE, 0x496C, 0x53EB, 0x5E6B, 0x68ED, 0x7374, 0x7DF0, 0x887B, 0x92F4, 0x9D75, 0xA7FB },
61 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
62 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
63 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
64 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
65 { 0xC90, 0x190D, 0x2590, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D }
66 };
67 static const uint32_t v2Timings[8][16] = {
68 { 0x347, 0x64F, 0x95F, 0xC70, 0xF80, 0x129E, 0x15B3, 0x18CB, 0x1BE4, 0x1EFB, 0x2211, 0x252C, 0x2786, 0x2A88, 0x2D85, 0x3088 },
69 { 0x864, 0x10ED, 0x196C, 0x21EA, 0x2A6C, 0x32E9, 0x3B6A, 0x43EC, 0x4C6A, 0x54EA, 0x5D6B, 0x65EB, 0x6E6D, 0x76ED, 0x7F6E, 0x87EE },
70 { 0x864, 0x10ED, 0x196C, 0x21EA, 0x2A6C, 0x32E9, 0x3B6A, 0x43EC, 0x4C6A, 0x54EA, 0x5D6B, 0x65EB, 0x6E6D, 0x76ED, 0x7F6E, 0x87EE },
71 { 0xA69, 0x14EA, 0x1F6F, 0x29ED, 0x346E, 0x3EEE, 0x496C, 0x53EB, 0x5E6B, 0x68ED, 0x7374, 0x7DF0, 0x887B, 0x92F4, 0x9D75, 0xA7FB },
72 { 0xA6A, 0x14EA, 0x1F6F, 0x29ED, 0x346E, 0x3EEE, 0x496C, 0x53EB, 0x5E6B, 0x68ED, 0x7374, 0x7DF0, 0x887B, 0x92F4, 0x9D75, 0xA7FB },
73 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
74 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
75 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
76 };
77 static const uint32_t psTimings[8][16] = {
78 { 0x440, 0x820, 0xC30, 0x1000, 0x1400, 0x17F1, 0x1C00, 0x2000, 0x2400, 0x2800, 0x2C00, 0x3000, 0x3400, 0x3800, 0x3C00, 0x4000 },
79 { 0x940, 0x12C0, 0x1C80, 0x25C0, 0x2F40, 0x3900, 0x4240, 0x4C00, 0x5540, 0x5EC0, 0x6850, 0x71C0, 0x7B40, 0x84C0, 0x8E80, 0x97CE },
80 { 0xB70, 0x1700, 0x2280, 0x2E00, 0x3A00, 0x4500, 0x5080, 0x5C00, 0x6780, 0x7320, 0x7E80, 0x8A00, 0x9580, 0xA100, 0xAC80, 0xB7F0 },
81 { 0xB80, 0x1700, 0x2280, 0x2E00, 0x3A00, 0x4500, 0x5080, 0x5C00, 0x6780, 0x7320, 0x7E80, 0x8A00, 0x9580, 0xA100, 0xAC80, 0xB800 },
82 { 0xB90, 0x1700, 0x2280, 0x2E00, 0x3A00, 0x4500, 0x5080, 0x5C00, 0x6780, 0x7320, 0x7E80, 0x8A00, 0x9580, 0xA100, 0xAC80, 0xB800 },
83 { 0xB90, 0x1700, 0x2280, 0x2E00, 0x3A00, 0x4500, 0x5080, 0x5C00, 0x6780, 0x7320, 0x7E80, 0x8A00, 0x9580, 0xA100, 0xAC80, 0xB800 },
84 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
85 { 0xC88, 0x1906, 0x2588, 0x340D, 0x3E8D, 0x4B10, 0x5790, 0x6410, 0x7090, 0x7D10, 0x8990, 0x9610, 0xA291, 0xAF0D, 0xBB90, 0xC80D },
86 };
87
88 static std::map<int, std::vector<int>> BIT_ORDERS = {
89 { 6, { 5, 2, 1, 4, 3, 0 } },
90 { 7, { 6, 2, 1, 4, 5, 3, 0 } },
91 { 8, { 7, 3, 5, 1, 2, 6, 4, 0 } },
92 //{ 8, { 7, 6, 5, 4, 3, 2, 1, 0 } },
93 { 9, { 8, 3, 5, 1, 7, 2, 6, 4, 0 } },
94 { 10, { 9, 4, 1, 6, 3, 8, 2, 7, 5, 0 } },
95 { 11, { 10, 4, 7, 2, 3, 1, 6, 9, 8, 5, 0 } },
96 { 12, { 11, 5, 8, 2, 4, 1, 7, 10, 3, 9, 6, 0 } }
97 };
98 55 static void compilePRUMatrixCode(std::vector<std::string>& sargs) {
99
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 CompilePRUProgram("/opt/fpp/src/pru/compileMatrix.sh", sargs);
100 55 }
101
102 55 void BBBMatrix::calcBrightnessFlags(std::vector<std::string>& sargs) {
103
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 LogDebug(VB_CHANNELOUT, "Calc Brightness: maxPanel: %d maxOutput: %d Brightness: %d rpo: %d ph: %d pw: %d\n", m_longestChain, m_outputs, m_brightness, m_panelScan, m_panelHeight, m_panelWidth);
104
105 // The tables stop at 8 outputs (MAX_OUTPUTS) and 16 panels a chain:
106 // past them this read beyond the tables. Use the nearest entry, the
107 // slowest timing the tables know.
108
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 int to = std::clamp(m_outputs, 1, 8) - 1;
109
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 int tc = std::clamp(m_longestChain, 1, 16) - 1;
110 55 uint32_t max = 0xB00;
111
2/3
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
55 switch (m_timing) {
112 28 case 2:
113 28 max = psTimings[to][tc];
114 28 break;
115 ✗ case 1:
116 ✗ max = v2Timings[to][tc];
117 ✗ break;
118 27 default:
119 27 max = v1Timings[to][tc];
120 27 break;
121 }
122
123 // timings are based on 32 pixel wide panels
124 55 max *= m_panelWidth;
125 55 max /= 32;
126
127 // 1/4 scan we need to double the time since we have twice the number of pixels to clock out
128 55 max *= m_panelHeight;
129 55 max /= (m_panelScan * 2);
130
131 55 uint32_t origMax = max;
132
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 if (m_colorDepth >= 11 && max < 0x9000) {
133 // for depth 10, we'll need a little more on time
134 // or the last bit will be on far too short
135 ✗ max = 0x9000;
136
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 } else if (m_colorDepth >= 10 && max < 0x8000) {
137 // for depth 10, we'll need a little more on time
138 // or the last bit will be on far too short
139 ✗ max = 0x8000;
140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 } else if (m_colorDepth == 9 && max < 0x6800) {
141 // for depth 9, we'll need a little more on time
142 ✗ max = 0x6800;
143
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 4 times.
55 } else if (max < 0x4500) {
144 // if max is too low, the low bit time is too short and
145 // extra ghosting occurs
146 // At this point, framerate will be supper high anyway >100fps
147 51 max = 0x4500;
148 }
149
150 55 uint32_t origMax2 = max;
151
152 55 max *= m_brightness;
153 55 max /= 10;
154
155 55 uint32_t delay = origMax2 - max;
156
3/4
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 51 times.
55 if ((origMax2 > origMax) && (origMax > max)) {
157 ✗ delay = origMax - max;
158 }
159
160 55 int maxBit = 8;
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_colorDepth > 8) {
162 ✗ maxBit = m_colorDepth;
163 }
164 // printf("Delay : %d Max: %d OrigMax: %d OrigMax2: %d\n", delay, max, origMax, origMax2);
165
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 55 times.
495 for (int x = 0; x < maxBit; x++) {
166
1/2
✓ Branch 0 taken 440 times.
✗ Branch 1 not taken.
440 LogDebug(VB_CHANNELOUT, "Brightness %d: %X\n", x, max);
167 440 delayValues[x] = delay;
168 440 brightnessValues[x] = max;
169 440 max >>= 1;
170 440 origMax >>= 1;
171 }
172 // low value cannot be less than 20 or ghosting
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (brightnessValues[maxBit - 1] < 20) {
174 ✗ brightnessValues[maxBit - 1] = 20;
175 }
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (brightnessValues[maxBit - 2] < brightnessValues[maxBit - 1]) {
177 ✗ brightnessValues[maxBit - 2] = brightnessValues[maxBit - 2] + 5;
178 }
179
180
3/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 53 times.
55 if (FileExists("/home/fpp/media/config/ledscape_dimming")) {
181
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 FILE* file = fopen("/home/fpp/media/config/ledscape_dimming", "r");
182
183
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (file != NULL) {
184 // fgets, not getline: getline() was handed a stack buffer as if it
185 // were malloc'd, and a line of 100 characters or more made it
186 // realloc() the stack
187 char line[100];
188 2 int count = 0;
189
190
6/8
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 2 times.
10 while ((count < 10) && fgets(line, sizeof(line), file)) {
191 8 size_t read = strlen(line);
192
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if ((!read) || (read == 1))
193 ✗ continue;
194
195
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 LogDebug(VB_CHANNELOUT, "Line %d: %s\n", count, line);
196
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (count == 0) {
197 2 m_printStats = atoi(line);
198 2 count++;
199 } else {
200 uint32_t d1, d2;
201
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (sscanf(line, "%X %X", &d1, &d2) == 2) {
202 6 brightnessValues[count - 1] = d1;
203 6 delayValues[count - 1] = d2;
204 }
205 6 count++;
206 }
207 }
208
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fclose(file);
209 }
210 }
211
212 char buf[255];
213
214 55 int x = m_colorDepth;
215 55 m_bitOrder.clear();
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_outputByRow) {
217 // if outputing by row, we have to keep in decending order
218 ✗ for (int x = m_colorDepth; x > 0; --x) {
219 ✗ m_bitOrder.push_back(x - 1);
220 }
221 } else {
222
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 m_bitOrder = BIT_ORDERS[m_colorDepth];
223 }
224
225
2/2
✓ Branch 0 taken 436 times.
✓ Branch 1 taken 55 times.
491 for (auto b : m_bitOrder) {
226 436 int idx = m_colorDepth - b - 1;
227 436 snprintf(buf, sizeof(buf), "-DBRIGHTNESS%d=%d", x, brightnessValues[idx]);
228
229
2/4
✓ Branch 0 taken 436 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 436 times.
✗ Branch 3 not taken.
436 sargs.push_back(buf);
230 436 snprintf(buf, sizeof(buf), "-DDELAY%d=%d", x, delayValues[idx]);
231
2/4
✓ Branch 0 taken 436 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 436 times.
✗ Branch 3 not taken.
436 sargs.push_back(buf);
232 436 x--;
233 }
234 55 }
235
236 57 BBBMatrix::BBBMatrix(unsigned int startChannel, unsigned int channelCount) :
237 ChannelOutput(startChannel, channelCount),
238 57 m_pru(nullptr),
239 57 m_pruCopy(nullptr),
240 57 m_matrix(nullptr),
241 57 m_panelMatrix(nullptr),
242 57 m_outputs(0),
243 57 m_gpioFrame(nullptr),
244 57 m_longestChain(0),
245 57 m_panelWidth(32),
246 57 m_panelHeight(16),
247 57 m_invertedData(0),
248 57 m_brightness(10),
249 57 m_colorDepth(8),
250 57 m_panelInterleave(),
251 57 m_panelScan(8),
252 57 m_timing(0),
253 57 m_printStats(false),
254 57 m_handler(nullptr),
255 57 m_outputByRow(false),
256 57 m_outputBlankData(false),
257 57 m_curFrame(0),
258 57 m_numFrames(0) {
259
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 LogDebug(VB_CHANNELOUT, "BBBMatrix::BBBMatrix(%u, %u)\n",
260 startChannel, channelCount);
261 57 }
262
263 228 BBBMatrix::~BBBMatrix() {
264 114 LogDebug(VB_CHANNELOUT, "BBBMatrix::~BBBMatrix()\n");
265
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 if (m_gpioFrame)
266
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 delete[] m_gpioFrame;
267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
114 if (m_pru)
268 ✗ delete m_pru;
269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
114 if (m_pruCopy)
270 ✗ delete m_pruCopy;
271
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 if (m_handler)
272
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 delete m_handler;
273
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 if (m_matrix)
274
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 delete m_matrix;
275
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 if (m_panelMatrix)
276
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 delete m_panelMatrix;
277 228 }
278
279 387 bool BBBMatrix::configureControlPin(const std::string& ctype, Json::Value& root, std::ofstream& outputFile, int pru, int& controlGPIO) {
280
4/8
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 387 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 387 times.
✗ Branch 7 not taken.
387 std::string type = root["controls"][ctype]["type"].asString();
281
2/4
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387 times.
✗ Branch 3 not taken.
387 if (type != "none") {
282
4/8
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 387 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 387 times.
✗ Branch 7 not taken.
387 std::string pinName = root["controls"][ctype]["pin"].asString();
283
1/2
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
387 m_usedGPIOS.push_back(pinName);
284
1/2
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
387 const PinCapabilities& pin = PinCapabilities::getPinByName(pinName);
285
5/8
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 332 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 55 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 387 times.
387 if (ctype == "oe" && pin.pwm >= 99) {
286 ✗ outputFile << "#define oe_pwm_address " << std::to_string(pin.getPWMRegisterAddress()) << "\n";
287 ✗ outputFile << "#define oe_pwm_output " << std::to_string(pin.subPwm) << "\n";
288 ✗ int max = 300 * 255;
289 // FIXME - adjust max for brightness
290 ✗ pin.setupPWM(max);
291 ✗ pin.setPWMValue(0);
292 ✗ return true;
293 } else {
294
3/4
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 214 times.
387 if (type == "pruout") {
295
4/8
✓ Branch 0 taken 173 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 173 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 173 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 173 times.
✗ Branch 7 not taken.
519 pin.configPin("pru" + std::to_string(pru) + "out");
296 173 const BBBPinCapabilities* bp = static_cast<const BBBPinCapabilities*>(&pin);
297
5/10
✓ Branch 0 taken 173 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 173 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 173 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 173 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 173 times.
✗ Branch 9 not taken.
173 outputFile << "#define pru_" << ctype << " " << std::to_string(bp->pruPin(pru)) << "\n";
298 } else {
299
2/4
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 214 times.
✗ Branch 3 not taken.
428 pin.configPin(type);
300
6/12
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 214 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 214 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 214 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 214 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 214 times.
✗ Branch 11 not taken.
214 outputFile << "#define gpio_" << ctype << " " << std::to_string(pin.mappedGPIO()) << "\n";
301
1/2
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
214 controlGPIO = pin.mappedGPIOIdx();
302 }
303 }
304
1/2
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
387 }
305 387 return false;
306 387 }
307
308 402 void BBBMatrix::configurePanelPin(int x, const std::string& color, int row, Json::Value& root, std::ofstream& outputFile, int* minPort) {
309
6/12
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 402 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 402 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 402 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 402 times.
✗ Branch 11 not taken.
402 std::string pinName = root["outputs"][x]["pins"][color + std::to_string(row)].asString();
310
1/2
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
402 const PinCapabilities& pin = PinCapabilities::getPinByName(pinName);
311
3/6
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 402 times.
✗ Branch 5 not taken.
1608 pin.configPin();
312
1/2
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
402 m_usedGPIOS.push_back(pinName);
313
1/2
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
402 int gpioIdx = pin.mappedGPIOIdx();
314
1/2
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
402 minPort[gpioIdx] = std::min(minPort[gpioIdx], (int)pin.mappedGPIO());
315
8/16
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 402 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 402 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 402 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 402 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 402 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 402 times.
✗ Branch 15 not taken.
402 outputFile << "#define " << color << std::to_string(x + 1) << std::to_string(row) << "_gpio " << std::to_string(pin.mappedGPIOIdx()) << "\n";
316
8/16
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 402 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 402 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 402 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 402 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 402 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 402 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 402 times.
✗ Branch 15 not taken.
402 outputFile << "#define " << color << std::to_string(x + 1) << std::to_string(row) << "_pin " << std::to_string(pin.mappedGPIO()) << "\n";
317
318
3/4
✓ Branch 0 taken 402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
✓ Branch 3 taken 268 times.
402 if (color == "r") {
319
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].r_gpio = pin.mappedGPIOIdx();
320
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].r_pin = 1UL << pin.mappedGPIO();
321
3/4
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
✓ Branch 3 taken 134 times.
268 } else if (color == "g") {
322
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].g_gpio = pin.mappedGPIOIdx();
323
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].g_pin = 1UL << pin.mappedGPIO();
324 } else {
325
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].b_gpio = pin.mappedGPIOIdx();
326
1/2
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
134 m_pinInfo[x].row[row - 1].b_pin = 1UL << pin.mappedGPIO();
327 }
328 402 }
329
330 67 void BBBMatrix::configurePanelPins(int x, Json::Value& root, std::ofstream& outputFile, int* minPort) {
331
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
134 configurePanelPin(x, "r", 1, root, outputFile, minPort);
332
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
134 configurePanelPin(x, "g", 1, root, outputFile, minPort);
333
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
67 configurePanelPin(x, "b", 1, root, outputFile, minPort);
334 67 outputFile << "\n";
335
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
134 configurePanelPin(x, "r", 2, root, outputFile, minPort);
336
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
134 configurePanelPin(x, "g", 2, root, outputFile, minPort);
337
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
67 configurePanelPin(x, "b", 2, root, outputFile, minPort);
338 67 outputFile << "\n";
339 67 }
340
341 57 int BBBMatrix::Init(Json::Value config) {
342
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 LogDebug(VB_CHANNELOUT, "BBBMatrix::Init(JSON)\n");
343
344
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_panelWidth = config["panelWidth"].asInt();
345
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_panelHeight = config["panelHeight"].asInt();
346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (!m_panelWidth)
347 ✗ m_panelWidth = 32;
348
349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (!m_panelHeight)
350 ✗ m_panelHeight = 16;
351
352
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 int addressingType = config["panelRowAddressType"].asInt();
353
354
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_invertedData = config["invertedData"].asInt();
355
3/6
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
57 m_colorOrder = ColorOrderFromString(config["colorOrder"].asString());
356
357
3/8
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 57 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
57 m_panelMatrix = new PanelMatrix(m_panelWidth, m_panelHeight, m_invertedData);
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (!m_panelMatrix) {
359 ✗ LogErr(VB_CHANNELOUT, "BBBMatrix: Unable to create PanelMatrix\n");
360 ✗ return 0;
361 }
362 57 bool usesOutput[MAX_OUTPUTS] = {};
363
4/6
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71 times.
✓ Branch 5 taken 57 times.
128 for (int i = 0; i < config["panels"].size(); i++) {
364
3/6
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71 times.
✗ Branch 5 not taken.
71 Json::Value p = config["panels"][i];
365 71 char orientation = 'N';
366
2/4
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
71 std::string o = p["orientation"].asString();
367
368
1/2
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
71 if (!o.empty())
369 71 orientation = o[0];
370
371
4/8
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 71 times.
✗ Branch 7 not taken.
71 if (p["colorOrder"].asString() == "")
372
3/6
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71 times.
✗ Branch 5 not taken.
71 p["colorOrder"] = ColorOrderToString(m_colorOrder);
373
374 // Only the first MAX_OUTPUTS outputs have pins: m_outputs, and every
375 // table indexed by output, stay within them. A panel past them used
376 // to raise m_outputs anyway, and buildPrepTables() then read the pins
377 // of an output that has none and indexed with them.
378
9/14
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 71 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 71 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 71 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 69 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 69 times.
71 if (p["outputNumber"].asInt() < 0 || p["outputNumber"].asInt() >= MAX_OUTPUTS) {
379
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 LogErr(VB_CHANNELOUT, "Invalid panel output number %d, LED panels drive outputs 1-%d\n", p["outputNumber"].asInt() + 1, MAX_OUTPUTS);
380
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 AddOutputConfigWarning(20, "BBBMatrix: a panel is on output " + std::to_string(p["outputNumber"].asInt() + 1) + ", past the " + std::to_string(MAX_OUTPUTS) + " outputs LED panels can drive; it is not shown");
381 2 continue;
382 }
383 // a refused panel (out of range) must not count toward the outputs or chains below
384
4/8
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 69 times.
✗ Branch 7 not taken.
138 if (!m_panelMatrix->AddPanel(p["outputNumber"].asInt(),
385
2/4
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
69 p["panelNumber"].asInt(), orientation,
386
4/8
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 69 times.
✗ Branch 7 not taken.
69 p["xOffset"].asInt(), p["yOffset"].asInt(),
387
3/6
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 69 times.
138 ColorOrderFromString(p["colorOrder"].asString()))) {
388 ✗ continue;
389 }
390
391
4/6
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 57 times.
69 if (p["outputNumber"].asInt() > m_outputs)
392
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 m_outputs = p["outputNumber"].asInt();
393
2/4
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
69 usesOutput[p["outputNumber"].asInt()] = true;
394
395
4/6
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 65 times.
69 if (p["panelNumber"].asInt() > m_longestChain)
396
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 m_longestChain = p["panelNumber"].asInt();
397
4/4
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 2 times.
73 }
398 // Both of these are 0-based, so bump them up by 1 for comparisons
399 57 m_outputs++;
400 57 m_longestChain++;
401
402 // get the dimensions of the matrix
403 57 m_panels = m_panelMatrix->PanelCount();
404 57 m_rows = m_outputs * m_panelHeight;
405 57 m_width = m_panelMatrix->Width();
406 57 m_height = m_panelMatrix->Height();
407
408
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 if (config.isMember("brightness")) {
409
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_brightness = config["brightness"].asInt();
410 }
411
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
57 if (m_brightness < 1 || m_brightness > 10) {
412 ✗ m_brightness = 10;
413 }
414
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 if (config.isMember("panelColorDepth")) {
415
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_colorDepth = config["panelColorDepth"].asInt();
416 }
417
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 if (config.isMember("panelOutputOrder")) {
418
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_outputByRow = config["panelOutputOrder"].asBool();
419 }
420
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
57 if (config.isMember("panelOutputBlankRow")) {
421 ✗ m_outputBlankData = config["panelOutputBlankRow"].asBool();
422 }
423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (m_colorDepth < 0) {
424 ✗ m_colorDepth = -m_colorDepth;
425 ✗ m_outputBlankData = true;
426 }
427
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
57 if (m_colorDepth > 12 || m_colorDepth < 6) {
428 ✗ m_colorDepth = 8;
429 }
430
431
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 if (config.isMember("panelInterleave")) {
432
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_panelInterleave = config["panelInterleave"].asString();
433 }
434
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_panelScan = config["panelScan"].asInt();
435 // printf("Interleave: %d Scan: %d ZZI: %d ZZCI: %d SI: %d\n", m_interleave, m_panelScan, zigZagInterleave, zigZagClusterInterleave, stripeInterleave);
436
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (m_panelScan == 0) {
437 // default scan is 1/2 the height of the panel
438 ✗ m_panelScan = m_panelHeight / 2;
439 }
440
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 m_handler = PanelInterleaveHandler::createHandler(m_panelInterleave, m_panelWidth, m_panelHeight, m_panelScan);
441
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (!m_handler) {
442 // A panel that scans fewer rows than half its height folds the rest
443 // into extra columns, so it needs an interleave that matches; without
444 // one the pixels have nowhere to go.
445 ✗ LogErr(VB_CHANNELOUT, "BBBMatrix: Panel interleave '%s' cannot map a %dx%d 1/%d scan panel\n",
446 m_panelInterleave.c_str(), m_panelWidth, m_panelHeight, m_panelScan);
447 ✗ AddOutputConfigWarning(50, "LED panel output disabled: panel interleave '" + m_panelInterleave +
448 ✗ "' is not valid for a " + std::to_string(m_panelWidth) + "x" + std::to_string(m_panelHeight) +
449 ✗ " 1/" + std::to_string(m_panelScan) + " scan panel. Set the Panel Interleave to match the panel.");
450 ✗ return 0;
451 }
452 57 m_channelCount = m_width * m_height * 3;
453
454
3/8
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 57 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
57 m_matrix = new Matrix(m_startChannel, m_width, m_height);
455
456
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 57 times.
57 if (config.isMember("subMatrices")) {
457 ✗ for (int i = 0; i < config["subMatrices"].size(); i++) {
458 ✗ Json::Value sm = config["subMatrices"][i];
459
460 ✗ m_matrix->AddSubMatrix(
461 ✗ sm["enabled"].asInt(),
462 ✗ sm["startChannel"].asInt() - 1,
463 ✗ sm["width"].asInt(),
464 ✗ sm["height"].asInt(),
465 ✗ sm["xOffset"].asInt(),
466 ✗ sm["yOffset"].asInt());
467 ✗ }
468 }
469
470 57 m_rowSize = m_longestChain * m_panelWidth * 3;
471 57 int maxBits = 8;
472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if (m_colorDepth > 8) {
473 ✗ maxBits = m_colorDepth;
474 }
475 57 int gpioFrameLen = m_longestChain * m_panelWidth * maxBits * (m_panelHeight / 2) * 4;
476
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 m_gpioFrame = new uint32_t[gpioFrameLen];
477 57 memset(m_gpioFrame, 0, gpioFrameLen * 4);
478
479 57 std::vector<std::string> compileArgs;
480
481
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
114 std::string dirname = "bbb";
482
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 std::string name = "Octoscroller";
483
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 28 times.
57 if (getBeagleBoneType() == PocketBeagle) {
484
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 dirname = "pb";
485
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 name = "PocketScroller";
486 }
487
4/8
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 57 times.
57 if (config["wiringPinout"] == "v2") {
488 ✗ name += "-v2";
489 }
490
5/8
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 53 times.
57 if (config["wiringPinout"] == "v3") {
491
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 name += "-v3";
492 }
493
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 Json::Value root;
494 char filename[256];
495 57 int minPort[4] = { 99, 99, 99, 99 };
496 57 int pru = 0;
497 57 snprintf(filename, sizeof(filename), "/home/fpp/media/tmp/panels/%s.json", name.c_str());
498
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 53 times.
57 if (!FileExists(filename)) {
499 4 snprintf(filename, sizeof(filename), "/home/fpp/media/tmp/panels/CapePanels.json", dirname.c_str());
500
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if (FileExists(filename)) {
501
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 name = "CapePanels";
502 }
503 }
504
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 55 times.
57 if (!FileExists(filename)) {
505 2 snprintf(filename, sizeof(filename), "/opt/fpp/capes/%s/panels/%s.json", dirname.c_str(), name.c_str());
506 }
507 57 bool isPWM = false;
508
3/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 55 times.
57 if (!FileExists(filename)) {
509
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_CHANNELOUT, "No output pin configuration for %s - %s\n", name.c_str(), filename);
510
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 AddOutputConfigWarning(50, "LED panel output: no output pin configuration for " + name);
511 2 return 0;
512 } else {
513
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 LogDebug(VB_CHANNELOUT, "Using panel pinout from %s\n", filename);
514
3/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 55 times.
110 if (!LoadJsonFromFile(filename, root, JsonRoot::Object)) {
515 ✗ LogErr(VB_CHANNELOUT, "Could not read pin configuration for %s - %s\n", name.c_str(), filename);
516 ✗ AddOutputConfigWarning(50, "LED panel output: could not read pin configuration for " + name);
517 ✗ return 0;
518 }
519
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 std::string longName = root["longName"].asString();
520
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 LogDebug(VB_CHANNELOUT, "Using pin configuration for %s from %s\n", longName.c_str(), filename);
521
522
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 std::ofstream outputFile;
523
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile.open("/tmp/PanelPinConfiguration.hp", std::ofstream::out | std::ofstream::trunc);
524
525 // kind of a hack, ideally the timing info would go into the json as well
526
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 m_timing = root["timing"].asInt();
527
528
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 pru = root["pru"].asInt();
529
530
3/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 29 times.
55 if (root.isMember("singlePRU")) {
531
2/4
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
26 m_singlePRU = root["singlePRU"].asBool();
532 }
533 // m_singlePRU = true;
534
535
3/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 49 times.
55 if (root.isMember("dataOffset")) {
536
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 m_dataOffset = root["dataOffset"].asInt();
537 6 m_dataOffset *= 1024; // dataOffset is in KB
538 }
539
540
3/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 55 times.
✗ Branch 5 not taken.
55 int controlGpio = root["controls"]["gpio"].asInt();
541
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 configureControlPin("latch", root, outputFile, pru, controlGpio);
542
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
543
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 isPWM = configureControlPin("oe", root, outputFile, pru, controlGpio);
544
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
545
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 configureControlPin("clock", root, outputFile, pru, controlGpio);
546
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
547
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
110 configureControlPin("sel0", root, outputFile, pru, controlGpio);
548
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
110 configureControlPin("sel1", root, outputFile, pru, controlGpio);
549
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
110 configureControlPin("sel2", root, outputFile, pru, controlGpio);
550
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 configureControlPin("sel3", root, outputFile, pru, controlGpio);
551
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 53 times.
55 if (m_panelScan > 16) {
552 // a row address of 16 or more needs the fifth "E" line - 1/32
553 // scan, and 80x40 1/20 scan (rows 16-19)
554
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 configureControlPin("sel4", root, outputFile, pru, controlGpio);
555
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 compileArgs.push_back("-DE_SCAN_LINE");
556 }
557
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
558
3/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 55 times.
✗ Branch 5 not taken.
55 outputFile << "#define CONTROLS_GPIO_BASE GPIO" << std::to_string(controlGpio) << "\n";
559
3/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 55 times.
✗ Branch 5 not taken.
55 outputFile << "#define gpio_controls_led_mask gpio" << std::to_string(controlGpio) << "_led_mask\n";
560
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
561
3/6
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 55 times.
55 if (m_outputs > root["outputs"].size()) {
562 ✗ m_outputs = root["outputs"].size();
563 }
564
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 55 times.
495 for (int x = 0; x < MAX_OUTPUTS; x++) {
565
3/4
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 373 times.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
440 if (usesOutput[x] && x < m_outputs) {
566
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 configurePanelPins(x, root, outputFile, minPort);
567 } else {
568
3/6
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 373 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 373 times.
✗ Branch 5 not taken.
373 outputFile << "#define NO_OUTPUT_" << std::to_string(x + 1) << "\n";
569
1/2
✓ Branch 0 taken 373 times.
✗ Branch 1 not taken.
373 outputFile << "\n";
570 }
571 }
572
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
573 #ifdef PLATFORM_BBB
574 // Dual PRU split output: the copy PRU writes up to two of the data
575 // GPIO banks itself (see FalconMatrixPRUCpy.asm), roughly a 1.35x
576 // higher pixel clock. The controls bank and GPIO0 (which has
577 // multi-microsecond write-landing jitter on the L4_WKUP bus) stay
578 // on the output PRU so their behavior is unchanged. AM335x only.
579 //
580 // Not with a GPIO clock: the clock write is posted, so the copy PRU
581 // can't write the next pixel until a read back proves the edge has
582 // landed (ACK_SPLIT), and that read makes the split slower than one
583 // PRU doing everything (measured 70Hz vs 100Hz). Without it the copy
584 // PRU's data beat ~1 in 5 clock edges and bled into the neighbouring
585 // pixel. A PRU (r30) clock is immediate and needs no read back.
586
5/10
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 54 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 54 times.
✗ Branch 9 not taken.
54 bool gpioClock = root["controls"]["clock"]["type"].asString() != "pruout";
587
16/26
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 22 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
✓ Branch 17 taken 48 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 48 times.
✓ Branch 20 taken 6 times.
✓ Branch 21 taken 48 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
54 if (!m_singlePRU && !gpioClock && !root.get("noSplitOutput", false).asBool() && getSettingInt("BBBMatrixNoSplitOutput", 0) == 0) {
588 6 int cnt = 0;
589
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 for (int x = 3; x > 0; x--) { // never GPIO0
590
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
18 if (minPort[x] != 99 && x != controlGpio && cnt < 2) {
591 6 m_splitCpyBanks[x] = true;
592 6 cnt++;
593 }
594 }
595 6 m_splitOutput = cnt > 0;
596 }
597
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 48 times.
54 if (m_splitOutput) {
598
6/8
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
6 LogDebug(VB_CHANNELOUT, "BBBMatrix: split output, copy PRU owns GPIO banks:%s%s%s\n",
599 m_splitCpyBanks[1] ? " 1" : "", m_splitCpyBanks[2] ? " 2" : "", m_splitCpyBanks[3] ? " 3" : "");
600 }
601 #endif
602
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 55 times.
275 for (int x = 0; x < 4; x++) {
603
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 128 times.
220 if (minPort[x] != 99) {
604
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 90 times.
92 if (x == controlGpio) {
605
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 outputFile << "#define OUTPUT_GPIO_" << std::to_string(x) << "(a, b, c, d) OUTPUT_GPIO_FORCE_CLEAR a, b, c, d\n";
606
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 84 times.
90 } else if (m_splitCpyBanks[x]) {
607 // in split mode the copy PRU owns this bank; the output
608 // PRU compiles the bank's writes out
609
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 outputFile << "#if defined(SPLIT_GPIO) && !defined(IN_CPY_PRU)\n";
610
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 outputFile << "#define OUTPUT_GPIO_" << std::to_string(x) << "(a, b, c, d)\n";
611
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 outputFile << "#else\n";
612
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 outputFile << "#define OUTPUT_GPIO_" << std::to_string(x) << "(a, b, c, d) OUTPUT_GPIO a, b, c, d\n";
613
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 outputFile << "#endif\n";
614
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 outputFile << "#define CPY_OWNS_GPIO" << std::to_string(x) << "\n";
615 } else {
616
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 84 times.
✗ Branch 5 not taken.
84 outputFile << "#define OUTPUT_GPIO_" << std::to_string(x) << "(a, b, c, d) OUTPUT_GPIO a, b, c, d\n";
617 }
618 } else {
619
3/6
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 128 times.
✗ Branch 5 not taken.
128 outputFile << "#define OUTPUT_GPIO_" << std::to_string(x) << "(a, b, c, d)\n";
620 }
621 }
622
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
623
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 2 times.
55 if (minPort[controlGpio] == 99) {
624 // not outputting anything on the GPIO the controls are using
625 // we need to make sure the controls are set/cleared indepentent of the panel data
626
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 outputFile << "#define NO_CONTROLS_WITH_DATA\n";
627 }
628
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile << "\n";
629
630
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 outputFile.close();
631 55 }
632
633 char buf[200];
634
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 29 times.
55 if (m_singlePRU) {
635
2/4
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
52 compileArgs.push_back("-DSINGLEPRU");
636 }
637
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 49 times.
55 if (m_splitOutput) {
638
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 compileArgs.push_back("-DSPLIT_GPIO");
639 }
640 55 snprintf(buf, sizeof(buf), "-DRUNNING_ON_PRU%d", pru);
641
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
642 55 snprintf(buf, sizeof(buf), "-DRUNNING_ON_PRU=%d", pru);
643
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
644 55 snprintf(buf, sizeof(buf), "-DOUTPUTS=%d", m_outputs);
645
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
646 55 snprintf(buf, sizeof(buf), "-DROWS=%d", m_panelScan);
647
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
648 55 snprintf(buf, sizeof(buf), "-DBITS=%d", m_colorDepth);
649
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
650 55 int tmp = m_longestChain * m_panelWidth;
651
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_panelScan * 4 == m_panelHeight) {
652 ✗ tmp *= 2;
653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 } else if (m_panelScan * 8 == m_panelHeight) {
654 ✗ tmp *= 4;
655 }
656 55 snprintf(buf, sizeof(buf), "-DROW_LEN=%d", tmp);
657
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 compileArgs.push_back(buf);
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (isPWM) {
659 ✗ compileArgs.push_back("-DUSING_PWM");
660 }
661
662
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 53 times.
55 if (addressingType == 2) {
663 // 1/2 scan panel that uses 2 bits, bit one for scan row 1 and bit two for row 2
664 // Normal addressing would be 1 bit, 0 for row 1, 1 for row 2
665
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 compileArgs.push_back("-DADDRESSING_AB=1");
666
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 51 times.
53 } else if (addressingType == 3) {
667 // the row drivers are shift registers clocked on A with data on C;
668 // every row change clocks one bit per panel row since panels can
669 // daisy chain a driver per band of scan rows
670
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 compileArgs.push_back("-DADDRESSING_ABC_SHIFT=1");
671 2 snprintf(buf, sizeof(buf), "-DROW_CHAIN=%d", m_panelHeight);
672
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 compileArgs.push_back(buf);
673 }
674
675
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 calcBrightnessFlags(compileArgs);
676 // m_printStats = true;
677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_printStats) {
678 ✗ snprintf(buf, sizeof(buf), "-DENABLESTATS=1", m_outputs);
679 ✗ compileArgs.push_back("-DENABLESTATS=1");
680 }
681
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_outputByRow) {
683 ✗ compileArgs.push_back("-DOUTPUTBYROW");
684 ✗ if (m_outputBlankData) {
685 ✗ compileArgs.push_back("-DOUTPUTBLANKROW");
686 }
687 } else {
688
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
110 compileArgs.push_back("-DOUTPUTBYDEPTH");
689 }
690
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 compilePRUMatrixCode(compileArgs);
691
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 std::string pru_program = "/tmp/FalconMatrix.out";
692
693
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 26 times.
55 if (!m_singlePRU) {
694
3/8
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29 m_pruCopy = new BBBPru(pru ? 0 : 1);
695 }
696
697
3/8
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 55 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
55 m_pru = new BBBPru(pru);
698 55 m_pruData = (BBBPruMatrixData*)m_pru->data_ram;
699
700
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 26 times.
55 if (!m_singlePRU) {
701
3/6
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
87 if (!m_pruCopy->run("/tmp/FalconMatrixPRUCpy.out")) {
702 ✗ LogErr(VB_CHANNELOUT, "BBBMatrix: Unable to start PRU. May require a reboot.\n");
703 ✗ AddOutputConfigWarning(20, "BBBMatrix: Unable to start PRU. May require a reboot.");
704 ✗ return 0;
705 }
706 }
707
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 if (!m_pru->run(pru_program)) {
708 ✗ LogErr(VB_CHANNELOUT, "BBBMatrix: Unable to start PRU. May require a reboot.\n");
709 ✗ AddOutputConfigWarning(20, "BBBMatrix: Unable to start PRU. May require a reboot.");
710 ✗ return 0;
711 }
712
713 // Nothing may touch the PRU memories before run() has started the core.
714 // The PRUSS is only clocked once its firmware is loaded and running, so an
715 // earlier access is dropped at best and aborts the process at worst - and
716 // run() clears the whole data RAM as its last step anyway, so a write made
717 // before it could never have survived. The sibling PRU outputs
718 // (BBB48String, BBBSerial, BBShiftString, BBShiftPanel) all order it this
719 // way; this one did not, which is why a board whose PRUSS was left
720 // unpowered segfaulted here instead of reporting the error above.
721 55 m_pruData->address_dma = m_pru->ddr_addr + m_dataOffset;
722 55 m_pruData->command = 0;
723 55 m_pruData->response = 0;
724
725
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 GammaLUT::BuildForColorDepth(gammaCurve, GammaLUT::ParseConfig(config, 2.2f), m_colorDepth);
726
727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (isPWM) {
728 // need to calculate the clock counts for the PWM subsystem
729 ✗ int i = m_pruData->pwmBrightness[0];
730 ✗ while (i == 0) {
731 ✗ i = m_pruData->pwmBrightness[0];
732 }
733 ✗ printf("PERIOD: %X\n", i);
734
735 ✗ int f = i;
736 // f *= 300;
737 // f /= 500;
738 ✗ i = f;
739 ✗ printf("New PERIOD: %X\n", i);
740
741 ✗ i *= m_brightness;
742 ✗ i /= 10;
743 ✗ for (int x = 0; x < 8; x++) {
744 ✗ printf("%d: %X\n", x, i);
745 ✗ m_pruData->pwmBrightness[7 - x] = i;
746 ✗ i /= 2;
747 }
748 }
749 /*
750 for (int x = 0; x < 8; x++) {
751 printf("%d R1: %d %8X\n",x, m_pinInfo[x].row[0].r_gpio, m_pinInfo[x].row[0].r_pin);
752 printf(" G1: %d %8X\n", m_pinInfo[x].row[0].g_gpio, m_pinInfo[x].row[0].g_pin);
753 printf(" B1: %d %8X\n", m_pinInfo[x].row[0].b_gpio, m_pinInfo[x].row[0].b_pin);
754 printf(" R2: %d %8X\n", m_pinInfo[x].row[1].r_gpio, m_pinInfo[x].row[1].r_pin);
755 printf(" G2: %d %8X\n", m_pinInfo[x].row[1].g_gpio, m_pinInfo[x].row[1].g_pin);
756 printf(" B2: %d %8X\n", m_pinInfo[x].row[1].b_gpio, m_pinInfo[x].row[1].b_pin);
757 }
758 */
759
760
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 buildPrepTables();
761
762 // make sure the PRU starts outputting a blank frame to remove any random noise
763 // from the panels
764 55 m_fullFrameLen = gpioFrameLen * 4;
765 // round up to next page boundary
766 55 int alignedLen = m_fullFrameLen + 8192;
767 55 alignedLen -= (alignedLen & 0xFFF);
768
769 // the frame flipping slots come from the shared DDR region allocator so
770 // string/serial outputs on the same region (e.g. the K8-B-Scroller runs
771 // BBB48String + BBBSerial + panels) cannot overlap us; the cape's
772 // dataOffset is kept as a floor for the historic layout. 4 slots is
773 // plenty (3 is the tear-free flip threshold) and leaving the rest of
774 // the region free lets the other outputs grow on a partial reload.
775 55 m_numFrames = 4;
776 55 uint8_t* framesBase = nullptr;
777 55 uint32_t framesPhys = 0;
778
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 while (m_numFrames > 0) {
779
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
59 framesBase = BBBPru::ddrAlloc("BBBMatrix", (size_t)alignedLen * m_numFrames, framesPhys, m_dataOffset);
780
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 4 times.
59 if (framesBase) {
781 55 break;
782 }
783 4 m_numFrames--;
784 }
785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (!framesBase) {
786 ✗ LogErr(VB_CHANNELOUT, "BBBMatrix: no room in the PRU DDR region for even one frame\n");
787 ✗ AddOutputConfigWarning(20, "BBBMatrix: no room in the PRU DDR region - reduce panel count/color depth or other outputs' buffers");
788 ✗ return 0;
789 }
790
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 55 times.
495 for (int x = 0; x < 8; x++) {
791 440 m_frames[x] = framesBase + (size_t)std::min(x, m_numFrames - 1) * alignedLen;
792 }
793 55 m_pruData->address_dma = framesPhys;
794 55 m_curFrame = 0;
795
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (PixelOverlayManager::INSTANCE.isAutoCreatePixelOverlayModels()) {
796
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 std::string dd = "LED Panels";
797
4/16
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 55 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 55 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
55 if (config.isMember("LEDPanelMatrixName") && !config["LEDPanelMatrixName"].asString().empty()) {
798 ✗ dd = config["LEDPanelMatrixName"].asString();
799 }
800
3/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 53 times.
55 if (config.isMember("description")) {
801
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 dd = config["description"].asString();
802 }
803
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 std::string desc = dd;
804 55 int count = 0;
805
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 while (PixelOverlayManager::INSTANCE.getModel(desc) != nullptr) {
806 ✗ count++;
807 ✗ desc = dd + "-" + std::to_string(count);
808 }
809
4/8
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 55 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 55 times.
✗ Branch 7 not taken.
385 PixelOverlayManager::INSTANCE.addAutoOverlayModel(desc,
810 m_startChannel, m_channelCount, 3,
811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 "H", m_invertedData ? "BL" : "TL",
812 55 m_height, 1);
813
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_autoCreatedModelName = desc;
814 55 }
815 // We need to send the data once to make sure the panels are cleared and "off"
816 // However, this doesn't always work so we'll set everything slightly "on" first
817 // real quick to make sure all the memory changes and is properly mapped into
818 // the process, then we'll reset everything to off
819
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 55 times.
271 for (int x = 0; x < m_numFrames; x++) {
820 216 memset(m_frames[x], 0x1, m_fullFrameLen);
821 }
822
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 SendData(nullptr);
823
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 55 times.
271 for (int x = 0; x < m_numFrames; x++) {
824 216 memset(m_frames[x], 0x0, m_fullFrameLen);
825 }
826
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 SendData(nullptr);
827
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 return ChannelOutput::Init(config);
828 57 }
829
830 55 int BBBMatrix::Close(void) {
831 55 LogDebug(VB_CHANNELOUT, "BBBMatrix::Close()\n");
832
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 BBBPru::ddrRelease("BBBMatrix");
833
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (!m_autoCreatedModelName.empty()) {
834 55 PixelOverlayManager::INSTANCE.removeAutoOverlayModel(m_autoCreatedModelName);
835 }
836
837 // Send the stop command
838 55 m_pruData->command = 0xFF;
839
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (m_pru) {
840 55 m_pru->stop();
841
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 delete m_pru;
842 55 m_pru = nullptr;
843 }
844
845
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 26 times.
55 if (m_pruCopy) {
846 29 m_pruCopy->stop();
847
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 delete m_pruCopy;
848 29 m_pruCopy = nullptr;
849 }
850 55 return ChannelOutput::Close();
851 }
852
853 static int fcount = 0;
854
855 ✗ void BBBMatrix::printStats() {
856 FILE* rfile;
857 ✗ rfile = fopen("/tmp/framerates.txt", "w");
858 ✗ for (int x = 0; x < m_colorDepth; ++x) {
859 ✗ fprintf(rfile, "DV: %d %8X %8X\n", (m_colorDepth - x), brightnessValues[x], delayValues[x]);
860 }
861 ✗ int off = 0;
862 ✗ uint32_t total = 0;
863 ✗ int count = 0;
864 ✗ for (int x = 0; x < m_panelScan; ++x) {
865 ✗ for (int y = m_colorDepth; y > 0; --y) {
866 ✗ fprintf(rfile, "r%2d b%2d: %8X %8X %8X\n", x, y, m_pruData->stats[off], m_pruData->stats[off + 1], m_pruData->stats[off + 2]);
867 ✗ total += m_pruData->stats[off];
868 ✗ count++;
869 ✗ off += 3;
870 }
871 }
872 ✗ fprintf(rfile, "Average Per Row/Bit: %8X\n", (total / count));
873 // printf("0x%X\n", (total / count));
874 ✗ fclose(rfile);
875 ✗ }
876
877 108 void BBBMatrix::GetRequiredChannelRanges(const std::function<void(int, int)>& addRange) {
878 108 addRange(m_startChannel, m_startChannel + m_channelCount - 1);
879 108 }
880
881 ✗ void BBBMatrix::OverlayTestData(unsigned char* channelData, int cycleNum, float percentOfCycle, int testType, const Json::Value& config) {
882 ✗ for (int output = 0; output < m_outputs; output++) {
883 ✗ int panelsOnOutput = m_panelMatrix->m_outputPanels[output].size();
884 ✗ for (int i = 0; i < panelsOnOutput; i++) {
885 ✗ int panel = m_panelMatrix->m_outputPanels[output][i];
886
887 ✗ m_panelMatrix->m_panels[panel].drawTestPattern(channelData + m_startChannel, cycleNum, percentOfCycle, testType);
888 }
889 }
890 ✗ }
891
892 55 void BBBMatrix::buildPrepTables() {
893 // per output: the 4 GPIO bank words for every combination of the 6 pins,
894 // so setting the pins for a pixel/bit is 4 unconditional ORs instead of
895 // 6 data dependent branches
896
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 55 times.
146 for (int o = 0; o < m_outputs; o++) {
897 91 const GPIOPinInfo::Pins& p0 = m_pinInfo[o].row[0];
898 91 const GPIOPinInfo::Pins& p1 = m_pinInfo[o].row[1];
899
2/2
✓ Branch 0 taken 5824 times.
✓ Branch 1 taken 91 times.
5915 for (int idx = 0; idx < 64; idx++) {
900 5824 uint32_t v[4] = { 0, 0, 0, 0 };
901
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 1)
902 2912 v[p0.r_gpio] |= p0.r_pin;
903
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 2)
904 2912 v[p0.g_gpio] |= p0.g_pin;
905
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 4)
906 2912 v[p0.b_gpio] |= p0.b_pin;
907
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 8)
908 2912 v[p1.r_gpio] |= p1.r_pin;
909
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 16)
910 2912 v[p1.g_gpio] |= p1.g_pin;
911
2/2
✓ Branch 0 taken 2912 times.
✓ Branch 1 taken 2912 times.
5824 if (idx & 32)
912 2912 v[p1.b_gpio] |= p1.b_pin;
913
2/2
✓ Branch 0 taken 23296 times.
✓ Branch 1 taken 5824 times.
29120 for (int g = 0; g < 4; g++) {
914 23296 m_pinLUT[o][idx][g] = v[g];
915 }
916 }
917 }
918 // spread the gamma corrected value so bit b lands in byte b; shifting
919 // six spread values together produces the 6 bit pin combination for
920 // every bit plane of a pixel in a couple of operations
921
2/2
✓ Branch 0 taken 14080 times.
✓ Branch 1 taken 55 times.
14135 for (int v = 0; v < 256; v++) {
922 14080 uint16_t g = gammaCurve[v];
923 14080 uint64_t lo = 0;
924 14080 uint32_t hi = 0;
925
2/2
✓ Branch 0 taken 112640 times.
✓ Branch 1 taken 14080 times.
126720 for (int b = 0; b < 8; b++) {
926
2/2
✓ Branch 0 taken 56318 times.
✓ Branch 1 taken 56322 times.
112640 if ((g >> b) & 1)
927 56318 lo |= 1ULL << (8 * b);
928 }
929
2/2
✓ Branch 0 taken 56320 times.
✓ Branch 1 taken 14080 times.
70400 for (int b = 8; b < 12; b++) {
930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56320 times.
56320 if ((g >> b) & 1)
931 ✗ hi |= 1u << (8 * (b - 8));
932 }
933 14080 m_gammaSpreadLo[v] = lo;
934 14080 m_gammaSpreadHi[v] = hi;
935 }
936 // group the panels by chain position; all outputs at the same chain
937 // position write into the same gpio words and can accumulate in registers
938
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_chainPanels.assign(m_longestChain, {});
939
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 55 times.
146 for (int output = 0; output < m_outputs; output++) {
940
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 91 times.
158 for (int i = 0; i < m_panelMatrix->m_outputPanels[output].size(); i++) {
941 67 int panel = m_panelMatrix->m_outputPanels[output][i];
942 67 int chain = m_panelMatrix->m_panels[panel].chain;
943
2/4
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
✗ Branch 3 not taken.
67 if (chain >= 0 && chain < m_longestChain) {
944
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 m_chainPanels[chain].emplace_back(output, panel);
945 }
946 }
947 }
948 // the interleave mapping only depends on the coordinates, not the panel
949 // or output, so it can be precomputed once instead of a virtual call per
950 // pixel per frame
951 55 int h2 = m_panelHeight / 2;
952
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_yOutMap.resize(h2);
953
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_xOutMap.resize(h2 * m_panelWidth);
954
2/2
✓ Branch 0 taken 888 times.
✓ Branch 1 taken 55 times.
943 for (int y = 0; y < h2; y++) {
955 888 int xo = 0;
956 888 int yo = y;
957 888 m_handler->map(xo, yo);
958 888 m_yOutMap[y] = yo;
959
2/2
✓ Branch 0 taken 57472 times.
✓ Branch 1 taken 888 times.
58360 for (int x = 0; x < m_panelWidth; x++) {
960 57472 int xOut = x;
961 57472 int yo2 = y;
962 57472 m_handler->map(xOut, yo2);
963 57472 m_xOutMap[y * m_panelWidth + x] = xOut;
964 }
965 }
966 55 size_t maxPairs = 1;
967
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 55 times.
138 for (auto& c : m_chainPanels) {
968 83 maxPairs = std::max(maxPairs, c.size());
969 }
970
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_stageLo.resize(maxPairs * m_panelWidth * 8);
971
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 m_stageHi.resize(maxPairs * m_panelWidth * 4);
972
973 // PrepData skips the per-frame memset and uses plain stores, which is
974 // only valid if the interleave maps every (y, x) onto a distinct slot of
975 // the chain block (it covers and overwrites everything). If a handler
976 // is not a clean bijection, fall back to memset + OR accumulation which
977 // matches the historical behavior exactly.
978 55 m_prepNeedsMemset = false;
979 55 int blockW = m_panelWidth * m_panelHeight / (m_panelScan * 2);
980
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
110 std::vector<uint8_t> covered(m_panelScan * blockW, 0);
981
2/2
✓ Branch 0 taken 888 times.
✓ Branch 1 taken 55 times.
943 for (int y = 0; y < h2; y++) {
982
2/2
✓ Branch 0 taken 57472 times.
✓ Branch 1 taken 888 times.
58360 for (int x = 0; x < m_panelWidth; x++) {
983 57472 int yOut = m_yOutMap[y];
984 57472 int xOut = m_xOutMap[y * m_panelWidth + x];
985
6/12
✓ Branch 0 taken 57472 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57472 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 57472 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 57472 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 57472 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 57472 times.
57472 if (yOut < 0 || yOut >= m_panelScan || xOut < 0 || xOut >= blockW || covered[yOut * blockW + xOut]) {
986 ✗ m_prepNeedsMemset = true;
987 } else {
988 57472 covered[yOut * blockW + xOut] = 1;
989 }
990 }
991 }
992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (m_prepNeedsMemset) {
993 ✗ LogWarn(VB_CHANNELOUT, "BBBMatrix: interleave map for %s is not a clean bijection, using slower PrepData path\n",
994 m_panelInterleave.c_str());
995 }
996 55 }
997
998 940 void BBBMatrix::PrepData(unsigned char* channelData) {
999 940 m_matrix->OverlaySubMatrices(channelData);
1000
1001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 940 times.
940 if (m_printStats) {
1002 ✗ fcount++;
1003 ✗ if (fcount == 20) {
1004 // every 20 frames or so, save stats
1005 ✗ fcount = 0;
1006 ✗ printStats();
1007 }
1008 }
1009
1010 940 channelData += m_startChannel;
1011
1012 // number of uint32_t per row for each bit
1013 940 size_t rowLen = m_panelWidth * m_longestChain * m_panelHeight / (m_panelScan * 2) * 4; // 4 GPIO's
1014 // number of uint32_t per full row (all bits)
1015 940 size_t fullRowLen = rowLen * m_colorDepth;
1016
1017 940 uint32_t* gpioFrame = m_gpioFrame;
1018 940 int h2 = m_panelHeight / 2;
1019
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 940 times.
940 size_t bitStride = m_outputByRow ? rowLen : (rowLen * m_panelScan);
1020
1021 // For each chain position, the packed bit-plane pin indexes for every
1022 // output are staged for the row, then each bit plane is written with all
1023 // outputs accumulated in a register and stored without a read-modify-
1024 // write. Iterating every chain position and row covers (and thus
1025 // clears) the whole frame, so no memset is needed; bit planes past the
1026 // color depth were zeroed at init and are never touched.
1027 940 const bool rmw = m_prepNeedsMemset;
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 940 times.
940 if (rmw) {
1029 ✗ memset(gpioFrame, 0, m_fullFrameLen);
1030 }
1031
2/2
✓ Branch 0 taken 1031 times.
✓ Branch 1 taken 940 times.
1971 for (int chain = 0; chain < m_longestChain; chain++) {
1032 1031 auto& pairs = m_chainPanels[chain];
1033 1031 int nPairs = (int)pairs.size();
1034 1031 size_t chainOff = (size_t)(m_longestChain - chain - 1) * 4 * m_panelWidth * m_panelHeight / m_panelScan / 2;
1035
2/2
✓ Branch 0 taken 16544 times.
✓ Branch 1 taken 1031 times.
17575 for (int y = 0; y < h2; y++) {
1036 16544 int yw1 = y * m_panelWidth * 3;
1037 16544 int yw2 = (y + h2) * m_panelWidth * 3;
1038 16544 const uint16_t* xMap = &m_xOutMap[y * m_panelWidth];
1039
2/2
✓ Branch 0 taken 15680 times.
✓ Branch 1 taken 16544 times.
32224 for (int p = 0; p < nPairs; p++) {
1040 15680 const int* pixelMap = &m_panelMatrix->m_panels[pairs[p].second].pixelMap[0];
1041 15680 uint8_t* stLo = &m_stageLo[p * m_panelWidth * 8];
1042
2/2
✓ Branch 0 taken 1007360 times.
✓ Branch 1 taken 15680 times.
1023040 for (int x = 0; x < m_panelWidth; ++x) {
1043 1007360 uint64_t pk = m_gammaSpreadLo[channelData[pixelMap[yw1 + x * 3]]] |
1044 1007360 (m_gammaSpreadLo[channelData[pixelMap[yw1 + x * 3 + 1]]] << 1) |
1045 1007360 (m_gammaSpreadLo[channelData[pixelMap[yw1 + x * 3 + 2]]] << 2) |
1046 1007360 (m_gammaSpreadLo[channelData[pixelMap[yw2 + x * 3]]] << 3) |
1047 1007360 (m_gammaSpreadLo[channelData[pixelMap[yw2 + x * 3 + 1]]] << 4) |
1048 1007360 (m_gammaSpreadLo[channelData[pixelMap[yw2 + x * 3 + 2]]] << 5);
1049 1007360 memcpy(&stLo[x * 8], &pk, 8);
1050 }
1051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15680 times.
15680 if (m_colorDepth > 8) {
1052 ✗ uint8_t* stHi = &m_stageHi[p * m_panelWidth * 4];
1053 ✗ for (int x = 0; x < m_panelWidth; ++x) {
1054 ✗ uint32_t pk = m_gammaSpreadHi[channelData[pixelMap[yw1 + x * 3]]] |
1055 ✗ (m_gammaSpreadHi[channelData[pixelMap[yw1 + x * 3 + 1]]] << 1) |
1056 ✗ (m_gammaSpreadHi[channelData[pixelMap[yw1 + x * 3 + 2]]] << 2) |
1057 ✗ (m_gammaSpreadHi[channelData[pixelMap[yw2 + x * 3]]] << 3) |
1058 ✗ (m_gammaSpreadHi[channelData[pixelMap[yw2 + x * 3 + 1]]] << 4) |
1059 ✗ (m_gammaSpreadHi[channelData[pixelMap[yw2 + x * 3 + 2]]] << 5);
1060 ✗ memcpy(&stHi[x * 4], &pk, 4);
1061 }
1062 }
1063 }
1064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16544 times.
16544 size_t offset = (m_outputByRow ? (size_t)m_yOutMap[y] * fullRowLen : (size_t)m_yOutMap[y] * rowLen) + chainOff;
1065 // Depths below 8 take the TOP bits of the 8 bit gamma value: the
1066 // bit order is relative to the depth (0..depth-1, which the
1067 // brightness flags index by), so shift it up past the bits the
1068 // depth drops. Without this 6 and 7 bit showed the low bits and
1069 // wrapped - at 6 bit, 136 came out black.
1070
2/2
✓ Branch 0 taken 5456 times.
✓ Branch 1 taken 11088 times.
16544 const int bitShift = m_colorDepth < 8 ? 8 - m_colorDepth : 0;
1071
2/2
✓ Branch 0 taken 121440 times.
✓ Branch 1 taken 16544 times.
137984 for (int bi = 0; bi < m_colorDepth; bi++) {
1072 121440 int b = m_bitOrder[bi] + bitShift;
1073 121440 uint32_t* out = &gpioFrame[offset + (size_t)bi * bitStride];
1074
1/2
✓ Branch 0 taken 121440 times.
✗ Branch 1 not taken.
121440 const uint8_t* st = (b < 8) ? m_stageLo.data() : m_stageHi.data();
1075
1/2
✓ Branch 0 taken 121440 times.
✗ Branch 1 not taken.
121440 size_t stStride = (b < 8) ? (m_panelWidth * 8) : (m_panelWidth * 4);
1076
1/2
✓ Branch 0 taken 121440 times.
✗ Branch 1 not taken.
121440 int stMult = (b < 8) ? 8 : 4;
1077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 121440 times.
121440 int bb = (b < 8) ? b : (b - 8);
1078 #ifdef __ARM_NEON
1079
2/2
✓ Branch 0 taken 7802880 times.
✓ Branch 1 taken 121440 times.
7924320 for (int x = 0; x < m_panelWidth; ++x) {
1080 7802880 uint32_t* o2 = &out[(size_t)xMap[x] * 4];
1081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7802880 times.
15605760 uint32x4_t acc = rmw ? vld1q_u32(o2) : vdupq_n_u32(0);
1082
2/2
✓ Branch 0 taken 7360512 times.
✓ Branch 1 taken 7802880 times.
15163392 for (int p = 0; p < nPairs; p++) {
1083 22081536 acc = vorrq_u32(acc, vld1q_u32(m_pinLUT[pairs[p].first][st[p * stStride + x * stMult + bb]]));
1084 }
1085 vst1q_u32(o2, acc);
1086 }
1087 #else
1088 for (int x = 0; x < m_panelWidth; ++x) {
1089 uint32_t* o2 = &out[(size_t)xMap[x] * 4];
1090 uint32_t a0 = 0, a1 = 0, a2 = 0, a3 = 0;
1091 if (rmw) {
1092 a0 = o2[0];
1093 a1 = o2[1];
1094 a2 = o2[2];
1095 a3 = o2[3];
1096 }
1097 for (int p = 0; p < nPairs; p++) {
1098 const uint32_t* t = m_pinLUT[pairs[p].first][st[p * stStride + x * stMult + bb]];
1099 a0 |= t[0];
1100 a1 |= t[1];
1101 a2 |= t[2];
1102 a3 |= t[3];
1103 }
1104 o2[0] = a0;
1105 o2[1] = a1;
1106 o2[2] = a2;
1107 o2[3] = a3;
1108 }
1109 #endif
1110 }
1111 }
1112 }
1113
1114
2/4
✓ Branch 0 taken 940 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 940 times.
✗ Branch 3 not taken.
940 if ((m_numFrames >= 3) && (m_frames[m_curFrame] != (uint8_t*)gpioFrame)) {
1115 940 memcpy(m_frames[m_curFrame], m_gpioFrame, m_fullFrameLen);
1116 }
1117 940 }
1118 972 int BBBMatrix::SendData(unsigned char* channelData) {
1119 972 LogExcess(VB_CHANNELOUT, "BBBMatrix::SendData(%p)\n", channelData);
1120
1121 // long long startTime = GetTime();
1122 972 uint32_t addr = m_pru->ddr_addr + (uint32_t)(m_frames[m_curFrame] - m_pru->ddr);
1123 972 uint8_t* ptr = m_frames[m_curFrame];
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 972 times.
972 if (m_numFrames < 3) {
1125 // if we have less than 3 blocks, we cannot copy
1126 // in prep or we'd get potential tearing/flickering
1127 ✗ memcpy(ptr, m_gpioFrame, m_fullFrameLen);
1128 }
1129 // long long cpyTime = GetTime();
1130
2/2
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 701 times.
972 if (m_curFrame == 0) {
1131 271 m_curFrame = m_numFrames - 1;
1132 } else {
1133 701 m_curFrame--;
1134 }
1135
1136 // the frame data must reach DDR before its address reaches the PRU (the
1137 // DDR region is mapped non-cacheable, so ordering is all it needs)
1138 972 BBBPru::frameDataBarrier();
1139 972 m_pruData->address_dma = addr;
1140
1141 972 __asm__ __volatile__("" ::
1142 : "memory");
1143 // long long flshTime = GetTime();
1144 972 m_pruData->command = 1;
1145
1146 /*
1147 if (fcount == 0) {
1148 printf("%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x \n",
1149 m_outputFrame[0], m_outputFrame[1], m_outputFrame[2],
1150 m_outputFrame[3], m_outputFrame[4], m_outputFrame[5],
1151 m_outputFrame[6], m_outputFrame[7], m_outputFrame[8],
1152 m_outputFrame[9], m_outputFrame[10], m_outputFrame[11],
1153 m_outputFrame[12], m_outputFrame[13], m_outputFrame[15]
1154 );
1155
1156 uint32_t *t = (uint32_t *)m_pruCopy->data_ram;
1157 printf(" %d %X %X %X %X %X\n", t[0], t[1], t[2], t[3], t[4], t[5]);
1158 }
1159 */
1160 /*
1161 long long endTime = GetTime();
1162 if ((endTime - startTime) > 100) {
1163 printf("cpy: %d flush: %d cmd: %d Total: %d\n", (int)(cpyTime - startTime), (int)(flshTime - cpyTime), (int)(endTime - flshTime), (int)(endTime - startTime));
1164 }
1165 */
1166 972 return m_channelCount;
1167 }
1168
1169 55 void BBBMatrix::DumpConfig(void) {
1170 55 LogDebug(VB_CHANNELOUT, "BBBMatrix::DumpConfig()\n");
1171 55 LogDebug(VB_CHANNELOUT, " Width : %d\n", m_width);
1172 55 LogDebug(VB_CHANNELOUT, " Height : %d\n", m_height);
1173 55 LogDebug(VB_CHANNELOUT, " Rows : %d\n", m_rows);
1174 55 LogDebug(VB_CHANNELOUT, " Row Size : %d\n", m_rowSize);
1175 55 LogDebug(VB_CHANNELOUT, " Color Depth : %d\n", m_colorDepth);
1176 55 LogDebug(VB_CHANNELOUT, " Outputs : %d\n", m_outputs);
1177 55 LogDebug(VB_CHANNELOUT, " Longest Chain : %d\n", m_longestChain);
1178 55 LogDebug(VB_CHANNELOUT, " Inverted Data : %d\n", m_invertedData);
1179
1180 55 ChannelOutput::DumpConfig();
1181 55 }
1182