-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathMatrixEsp32Hub75Refresh_NT_Impl.h
More file actions
470 lines (382 loc) · 18.7 KB
/
MatrixEsp32Hub75Refresh_NT_Impl.h
File metadata and controls
470 lines (382 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/*
* SmartMatrix Library - ESP32 HUB75 Panel Refresh Class (No Template Version)
*
* Copyright (c) 2020 Louis Beaudoin (Pixelmatix)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "SmartMatrix.h"
#if 0
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "esp_heap_caps.h"
#include "i2s_parallel.h"
#endif
#include "Esp32MemDisplay.h"
#include "rom/lldesc.h"
#define INLINE __attribute__( ( always_inline ) ) inline
// TODO: slower refresh rates require larger timer values - get the min refresh rate from the largest MSB value that will fit in the timer (round up)
#define MIN_REFRESH_RATE 30
template <int dummyvar>
void frameShiftCompleteISR(void);
template <int dummyvar>
bool SmartMatrixHub75Refresh_NT<dummyvar>::isFrameBufferFree(void) {
if(cbIsFull(&dmaBuffer))
return false;
else
return true;
}
template <int dummyvar>
MATRIX_DATA_STORAGE_TYPE * SmartMatrixHub75Refresh_NT<dummyvar>::getNextFrameBufferPtr(void) {
return matrixUpdateFrames[cbGetNextWrite(&dmaBuffer)];
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::writeFrameBuffer(uint8_t currentFrame) {
//SmartMatrixHub75Refresh_NT<dummyvar>::frameStruct * currentFramePtr = SmartMatrixHub75Refresh_NT<dummyvar>::getNextFrameBufferPtr();
i2s_parallel_flip_to_buffer(&I2S1, cbGetNextWrite(&dmaBuffer));
cbWrite(&dmaBuffer);
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::recoverFromDmaUnderrun(void) {
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::setMatrixCalculationsCallback(matrix_calc_callback f) {
setShiftCompleteCallback(f);
matrixCalcCallback = f;
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::setBrightness(uint8_t newBrightness) {
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::setRefreshRate(uint16_t newRefreshRate) {
if(newRefreshRate > MIN_REFRESH_RATE)
minRefreshRate = newRefreshRate;
else
minRefreshRate = MIN_REFRESH_RATE;
}
template <int dummyvar>
uint16_t SmartMatrixHub75Refresh_NT<dummyvar>::getRefreshRate(void) {
return refreshRate;
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::begin(uint32_t dmaRamToKeepFreeBytes) {
cbInit(&dmaBuffer, ESP32_NUM_FRAME_BUFFERS);
printf("Starting SmartMatrix DMA Mallocs\r\n");
printf("sizeof framestruct: %08X\r\n", SIZE_OF_FRAMESTRUCT);
show_esp32_dma_mem("DMA Memory Available before ptr1 alloc");
// TODO: malloc this buffer before other smaller buffers as this is (by far) the largest buffer to allocate?
matrixUpdateFrames[0] = (MATRIX_DATA_STORAGE_TYPE *)heap_caps_malloc(SIZE_OF_FRAMESTRUCT, MALLOC_CAP_DMA);
assert(matrixUpdateFrames[0] != NULL);
printf("matrixUpdateFrames[0] pointer: %08X\r\n", (uint32_t)matrixUpdateFrames[0]);
show_esp32_dma_mem("DMA Memory Available before ptr2 alloc");
matrixUpdateFrames[1] = (MATRIX_DATA_STORAGE_TYPE *)heap_caps_malloc(SIZE_OF_FRAMESTRUCT, MALLOC_CAP_DMA);
assert(matrixUpdateFrames[1] != NULL);
printf("matrixUpdateFrames[1] pointer: %08X\r\n", (uint32_t)matrixUpdateFrames[1]);
printf("Frame Structs Allocated from Heap:\r\n");
show_esp32_all_mem();
printf("Allocating refresh buffer:\r\n");
// setup debug output
#ifdef DEBUG_PINS_ENABLED
gpio_pad_select_gpio(DEBUG_1_GPIO);
gpio_set_direction(DEBUG_1_GPIO, GPIO_MODE_OUTPUT);
gpio_set_level(DEBUG_1_GPIO, 1);
gpio_set_level(DEBUG_1_GPIO, 0);
#endif
#if defined(DEBUG_PINS_ENABLED) && defined(DEBUG_2_GPIO)
gpio_pad_select_gpio(DEBUG_2_GPIO);
gpio_set_direction(DEBUG_2_GPIO, GPIO_MODE_OUTPUT);
gpio_set_level(DEBUG_2_GPIO, 1);
gpio_set_level(DEBUG_2_GPIO, 0);
#endif
// calculate the lowest LSBMSB_TRANSITION_BIT value that will fit in memory
int numDescriptorsPerRow;
lsbMsbTransitionBit = 0;
while(1) {
numDescriptorsPerRow = 1;
for(int i=lsbMsbTransitionBit + 1; i<COLOR_DEPTH_BITS; i++) {
numDescriptorsPerRow += 1<<(i - lsbMsbTransitionBit - 1);
}
int ramrequired = numDescriptorsPerRow * MATRIX_SCAN_MOD * ESP32_NUM_FRAME_BUFFERS * sizeof(lldesc_t);
int largestblockfree = heap_caps_get_largest_free_block(MALLOC_CAP_DMA);
printf("lsbMsbTransitionBit of %d requires %d RAM, %d available, leaving %d free: \r\n", lsbMsbTransitionBit, ramrequired, largestblockfree, largestblockfree - ramrequired);
if(largestblockfree > dmaRamToKeepFreeBytes && ramrequired < (largestblockfree - dmaRamToKeepFreeBytes))
break;
if(lsbMsbTransitionBit < COLOR_DEPTH_BITS - 1)
lsbMsbTransitionBit++;
else
break;
}
if(numDescriptorsPerRow * MATRIX_SCAN_MOD * ESP32_NUM_FRAME_BUFFERS * sizeof(lldesc_t) > heap_caps_get_largest_free_block(MALLOC_CAP_DMA)){
printf("not enough RAM for SmartMatrix descriptors\r\n");
return;
}
printf("Raised lsbMsbTransitionBit to %d/%d to fit in RAM\r\n", lsbMsbTransitionBit, COLOR_DEPTH_BITS - 1);
// calculate the lowest LSBMSB_TRANSITION_BIT value that will fit in memory that will meet or exceed the configured refresh rate
while(1) {
int psPerClock = 1000000000000UL/ESP32_I2S_CLOCK_SPEED;
int nsPerLatch = ((PIXELS_PER_LATCH + CLKS_DURING_LATCH) * psPerClock) / 1000;
//printf("ns per latch: %d: \r\n", nsPerLatch);
// add time to shift out LSBs + LSB-MSB transition bit - this ignores fractions...
int nsPerRow = COLOR_DEPTH_BITS * nsPerLatch;
// add time to shift out MSBs
for(int i=lsbMsbTransitionBit + 1; i<COLOR_DEPTH_BITS; i++)
nsPerRow += (1<<(i - lsbMsbTransitionBit - 1)) * (COLOR_DEPTH_BITS - i) * nsPerLatch;
//printf("nsPerRow: %d: \r\n", nsPerRow);
int nsPerFrame = nsPerRow * MATRIX_SCAN_MOD;
//printf("nsPerFrame: %d: \r\n", nsPerFrame);
int actualRefreshRate = 1000000000UL/(nsPerFrame);
refreshRate = actualRefreshRate;
printf("lsbMsbTransitionBit of %d gives %d Hz refresh, %d requested: \r\n", lsbMsbTransitionBit, actualRefreshRate, minRefreshRate);
if(actualRefreshRate >= minRefreshRate)
break;
if(lsbMsbTransitionBit < COLOR_DEPTH_BITS - 1)
lsbMsbTransitionBit++;
else
break;
}
printf("Raised lsbMsbTransitionBit to %d/%d to meet minimum refresh rate\r\n", lsbMsbTransitionBit, COLOR_DEPTH_BITS - 1);
// TODO: completely fill buffer with data before enabling DMA - can't do this now, lsbMsbTransition bit isn't set in the calc class - also this call will probably have no effect as matrixCalcDivider will skip the first call
//matrixCalcCallback();
// lsbMsbTransition Bit is now finalized - redo descriptor count in case it changed to hit min refresh rate
numDescriptorsPerRow = 1;
for(int i=lsbMsbTransitionBit + 1; i<COLOR_DEPTH_BITS; i++) {
numDescriptorsPerRow += 1<<(i - lsbMsbTransitionBit - 1);
}
printf("Descriptors for lsbMsbTransitionBit %d/%d with %d rows require %d bytes of DMA RAM\r\n", lsbMsbTransitionBit, COLOR_DEPTH_BITS - 1, MATRIX_SCAN_MOD, 2 * numDescriptorsPerRow * MATRIX_SCAN_MOD * sizeof(lldesc_t));
// malloc the DMA linked list descriptors that i2s_parallel will need
int desccount = numDescriptorsPerRow * MATRIX_SCAN_MOD;
lldesc_t * dmadesc_a = (lldesc_t *)heap_caps_malloc(desccount * sizeof(lldesc_t), MALLOC_CAP_DMA);
if(!dmadesc_a) {
printf("can't malloc dmadesc_a");
return;
}
lldesc_t * dmadesc_b = (lldesc_t *)heap_caps_malloc(desccount * sizeof(lldesc_t), MALLOC_CAP_DMA);
if(!dmadesc_b) {
printf("can't malloc dmadesc_b");
return;
}
printf("SmartMatrix Mallocs Complete\r\n");
show_esp32_all_mem();
lldesc_t *prevdmadesca = 0;
lldesc_t *prevdmadescb = 0;
int currentDescOffset = 0;
// fill DMA linked lists for both frames
for(int j=0; j<MATRIX_SCAN_MOD; j++) {
// first set of data is LSB through MSB, single pass - all color bits are displayed once, which takes care of everything below and including LSBMSB_TRANSITION_BIT
// TODO: size must be less than DMA_MAX - worst case for SmartMatrix Library: 16-bpp with 256 pixels per row would exceed this, need to break into two
//link_dma_desc(&dmadesc_a[currentDescOffset], prevdmadesca, matrixUpdateFrames[0]->rowdata[j].rowbits[0].data, sizeof(rowBitStruct) * COLOR_DEPTH_BITS);
link_dma_desc(&dmadesc_a[currentDescOffset], prevdmadesca, &matrixUpdateFrames[0][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, 0)], SIZE_OF_ROWDATASTRUCT);
prevdmadesca = &dmadesc_a[currentDescOffset];
//printf("matrixUpdateFrames[0](%d,0): %08X, size: %04X\r\n", j, (uint32_t)&matrixUpdateFrames[0][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, 0)], SIZE_OF_ROWDATASTRUCT);
//link_dma_desc(&dmadesc_b[currentDescOffset], prevdmadescb, matrixUpdateFrames[1]->rowdata[j].rowbits[0].data, sizeof(rowBitStruct) * COLOR_DEPTH_BITS);
link_dma_desc(&dmadesc_b[currentDescOffset], prevdmadescb, &matrixUpdateFrames[1][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, 0)], SIZE_OF_ROWDATASTRUCT);
prevdmadescb = &dmadesc_b[currentDescOffset];
currentDescOffset++;
//printf("row %d: \r\n", j);
for(int i=lsbMsbTransitionBit + 1; i<COLOR_DEPTH_BITS; i++) {
// binary time division setup: we need 2 of bit (LSBMSB_TRANSITION_BIT + 1) four of (LSBMSB_TRANSITION_BIT + 2), etc
// because we sweep through to MSB each time, it divides the number of times we have to sweep in half (saving linked list RAM)
// we need 2^(i - LSBMSB_TRANSITION_BIT - 1) == 1 << (i - LSBMSB_TRANSITION_BIT - 1) passes from i to MSB
//printf("buffer %d: repeat %d times, size: %d, from %d - %d\r\n", nextBufdescIndex, 1<<(i - LSBMSB_TRANSITION_BIT - 1), (COLOR_DEPTH_BITS - i), i, COLOR_DEPTH_BITS-1);
for(int k=0; k < 1<<(i - lsbMsbTransitionBit - 1); k++) {
//link_dma_desc(&dmadesc_a[currentDescOffset], prevdmadesca, matrixUpdateFrames[0]->rowdata[j].rowbits[i].data, sizeof(rowBitStruct) * (COLOR_DEPTH_BITS - i));
link_dma_desc(&dmadesc_a[currentDescOffset], prevdmadesca, &matrixUpdateFrames[0][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, i)], SIZE_OF_ROWBITSTRUCT * (COLOR_DEPTH_BITS - i));
prevdmadesca = &dmadesc_a[currentDescOffset];
//printf("matrixUpdateFrames[0](%d,%i): %08X, size: %04X\r\n", j, i, (uint32_t)&matrixUpdateFrames[0][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, i)], SIZE_OF_ROWBITSTRUCT * (COLOR_DEPTH_BITS - i));
//link_dma_desc(&dmadesc_b[currentDescOffset], prevdmadescb, matrixUpdateFrames[1]->rowdata[j].rowbits[i].data, sizeof(rowBitStruct) * (COLOR_DEPTH_BITS - i));
link_dma_desc(&dmadesc_b[currentDescOffset], prevdmadescb, &matrixUpdateFrames[1][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, i)], SIZE_OF_ROWBITSTRUCT * (COLOR_DEPTH_BITS - i));
prevdmadescb = &dmadesc_b[currentDescOffset];
//printf("matrixUpdateFrames[1](%d,%i): %08X, size: %04X\r\n", j, i, (uint32_t)&matrixUpdateFrames[1][GET_DATA_OFFSET_FROM_ROW_AND_COLOR_DEPTH_BIT(j, i)], SIZE_OF_ROWBITSTRUCT * (COLOR_DEPTH_BITS - i));
currentDescOffset++;
//printf("i %d, j %d, k %d\r\n", i, j, k);
}
}
}
//End markers
dmadesc_a[desccount-1].eof = 1;
dmadesc_b[desccount-1].eof = 1;
dmadesc_a[desccount-1].qe.stqe_next=(lldesc_t*)&dmadesc_a[0];
dmadesc_b[desccount-1].qe.stqe_next=(lldesc_t*)&dmadesc_b[0];
//printf("\n");
// send FM6126A chipset reset sequence, which is ignored by other chipsets that don't need it
// Thanks to Bob Davis: http://bobdavis321.blogspot.com/2019/02/p3-64x32-hub75e-led-matrix-panels-with.html
if(optionFlags & SMARTMATRIX_OPTIONS_FM6126A_RESET_AT_START) {
int C12[16] = {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int C13[16] = {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0};
gpio_pad_select_gpio(CLK_PIN);
gpio_set_direction(CLK_PIN, GPIO_MODE_OUTPUT);
#ifdef CLK_MANUAL_PIN
gpio_pad_select_gpio(CLK_MANUAL_PIN);
gpio_set_direction(CLK_MANUAL_PIN, GPIO_MODE_OUTPUT);
#endif
gpio_pad_select_gpio(LAT_PIN);
gpio_set_direction(LAT_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(OE_PIN);
gpio_set_direction(OE_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(R1_PIN);
gpio_set_direction(R1_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(G1_PIN);
gpio_set_direction(G1_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(B1_PIN);
gpio_set_direction(B1_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(R2_PIN);
gpio_set_direction(R2_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(G2_PIN);
gpio_set_direction(G2_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(B2_PIN);
gpio_set_direction(B2_PIN, GPIO_MODE_OUTPUT);
#if (A_PIN >= 0)
gpio_pad_select_gpio(A_PIN);
gpio_set_direction(A_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(A_PIN, 1);
#endif
#if (B_PIN >= 0)
gpio_pad_select_gpio(B_PIN);
gpio_set_direction(B_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(B_PIN, 0);
#endif
#if (C_PIN >= 0)
gpio_pad_select_gpio(C_PIN);
gpio_set_direction(C_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(C_PIN, 0);
#endif
#if (D_PIN >= 0)
gpio_pad_select_gpio(D_PIN);
gpio_set_direction(D_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(D_PIN, 0);
#endif
#if (E_PIN >= 0)
gpio_pad_select_gpio(E_PIN);
gpio_set_direction(E_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(E_PIN, 0);
#endif
// keep display off
gpio_set_level(OE_PIN, 1);
// set CLK/LAT to idle state
gpio_set_level(LAT_PIN, 0);
gpio_set_level(CLK_PIN, 0);
#ifdef CLK_MANUAL_PIN
gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
// Send Data to control register 11
for(int i=0; i<PIXELS_PER_LATCH; i++) {
int y=i%16;
gpio_set_level(R1_PIN, 0);
gpio_set_level(G1_PIN, 0);
gpio_set_level(B1_PIN, 0);
gpio_set_level(R2_PIN, 0);
gpio_set_level(G2_PIN, 0);
gpio_set_level(B2_PIN, 0);
if(C12[y] == 1) {
gpio_set_level(R1_PIN, 1);
gpio_set_level(G1_PIN, 1);
gpio_set_level(B1_PIN, 1);
gpio_set_level(R2_PIN, 1);
gpio_set_level(G2_PIN, 1);
gpio_set_level(B2_PIN, 1);
}
delay(1);
if(i > PIXELS_PER_LATCH-12)
gpio_set_level(LAT_PIN, 1);
else
gpio_set_level(LAT_PIN, 0);
delay(1);
#ifdef CLK_MANUAL_PIN
gpio_set_level(CLK_MANUAL_PIN, 1);
gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
gpio_set_level(CLK_PIN, 1);
delay(1);
gpio_set_level(CLK_PIN, 0);
delay(1);
}
gpio_set_level(LAT_PIN, 0);
// Send Data to control register 12
for(int i=0; i<PIXELS_PER_LATCH; i++) {
int y=i%16;
gpio_set_level(R1_PIN, 0);
gpio_set_level(G1_PIN, 0);
gpio_set_level(B1_PIN, 0);
gpio_set_level(R2_PIN, 0);
gpio_set_level(G2_PIN, 0);
gpio_set_level(B2_PIN, 0);
if(C13[y] == 1) {
gpio_set_level(R1_PIN, 1);
gpio_set_level(G1_PIN, 1);
gpio_set_level(B1_PIN, 1);
gpio_set_level(R2_PIN, 1);
gpio_set_level(G2_PIN, 1);
gpio_set_level(B2_PIN, 1);
}
delay(1);
if(i > PIXELS_PER_LATCH-13)
gpio_set_level(LAT_PIN, 1);
else
gpio_set_level(LAT_PIN, 0);
delay(1);
#ifdef CLK_MANUAL_PIN
gpio_set_level(CLK_MANUAL_PIN, 1);
gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
gpio_set_level(CLK_PIN, 1);
delay(1);
gpio_set_level(CLK_PIN, 0);
delay(1);
}
gpio_set_level(LAT_PIN, 0);
// let changes settle before refreshing
delay(1);
}
#ifdef CLK_MANUAL_PIN
// this pin can be manually toggled when the latch pin is high to send CLK pulses to the panel (normally latch blocks the clock signal on the ESP32 circuit). Set idle to low so there's no extra CLK pulse when latch goes high
gpio_pad_select_gpio(CLK_MANUAL_PIN);
gpio_set_direction(CLK_MANUAL_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
i2s_parallel_config_t cfg={
.gpio_bus={R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, LAT_PIN, OE_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, -1, -1, -1},
.gpio_clk=CLK_PIN,
.clk_inversion=(optionFlags & SMARTMATRIX_OPTIONS_ESP32_INVERT_CLK),
.clkspeed_hz=ESP32_I2S_CLOCK_SPEED, // formula used is 80000000L/(cfg->clkspeed_hz + 1), must result in >=2. Acceptable values 26.67MHz, 20MHz, 16MHz, 13.34MHz...
.bits=MATRIX_I2S_MODE,
.bufa=0,
.bufb=0,
.desccount_a=desccount,
.desccount_b=desccount,
.lldesc_a=dmadesc_a,
.lldesc_b=dmadesc_b
};
//Setup I2S
i2s_parallel_setup_without_malloc(&I2S1, &cfg);
//printf("I2S setup done.\n");
}
template <int dummyvar>
void SmartMatrixHub75Refresh_NT<dummyvar>::markRefreshComplete(void) {
if(!cbIsEmpty(&dmaBuffer))
cbRead(&dmaBuffer);
}
template <int dummyvar>
uint8_t SmartMatrixHub75Refresh_NT<dummyvar>::getLsbMsbTransitionBit(void) {
return lsbMsbTransitionBit;
}