-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLC698x_LP589x_APIs.c
More file actions
885 lines (803 loc) · 27.9 KB
/
Copy pathTLC698x_LP589x_APIs.c
File metadata and controls
885 lines (803 loc) · 27.9 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
/*
* TLC698x_LP589x_APIs.c
*
* Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/
* ALL RIGHTS RESERVED
*
*/
//
// Included Files
//
#include "TLC698x_LP589x_APIs.h"
#include "led_driver.h"
#include <led_hal.h>
#include <CCSI_Socket.h>
#include "FC_settings.h"
//
// Globals
//
uint16_t vsyncDone;
uint16_t data[CCSI_BUS_NUM][MAX_DATA_LENGTH];
uint32_t sub_period_in_us;
#if MONOCHROMATIC
uint16_t img_mono[SCREEN_SIZE_Y][SCREEN_SIZE_X][CCSI_BUS_NUM];
#else
uint16_t img_R_RGB[SCREEN_SIZE_Y][SCREEN_SIZE_X][CCSI_BUS_NUM];
uint16_t img_G_RGB[SCREEN_SIZE_Y][SCREEN_SIZE_X][CCSI_BUS_NUM];
uint16_t img_B_RGB[SCREEN_SIZE_Y][SCREEN_SIZE_X][CCSI_BUS_NUM];
#endif
/* Function Name: LED_getStackableDevices
*
* Purpose: Get the number of stackable devices.
*
* Parameters:
*
*/
uint16_t LED_getStackableDevices(void)
{
uint16_t stack_dev = 0;
uint16_t modSizeMasked;
#if (LP5890 | TLC6983)
modSizeMasked = _FC0_2 & 0xC000;
if(modSizeMasked == MOD_SIZE__1) {
stack_dev = 1;
}
else {
stack_dev = 2;
}
#else
modSizeMasked = _FC2_0 & 0x3800;
if(modSizeMasked == MOD_SIZE__1) {
stack_dev = 1;
}
else {
if(modSizeMasked == MOD_SIZE__2) {
stack_dev = 2;
}
else {
if((modSizeMasked & MOD_SIZE__4_7) == MOD_SIZE__4_7) {
stack_dev = 4;
}
else {
stack_dev = 3;
}
}
}
#endif
return stack_dev;
}
/* Function Name: LED_setSubPeriodInUS
*
* Purpose: Calculate the sub-period in us.
*
* Parameters:
*
*/
void LED_setSubPeriodInUS(void)
{
uint32_t segment_length = _FC1_0 & SEG_LENGTH__1024;
uint32_t t_sw = (((_FC1_2 & 0x01E0) >> 5) + 1) * 30;
uint32_t freq_mult;
uint32_t one_billion = 1000000000;
uint32_t sclk_period_in_ns;
#if (LP5890 | TLC6983)
freq_mult = ((_FC0_1 & (FREQ_MUL_15 >> 16)) >> 12) + 1;
#else
freq_mult = ((_FC0_1 & 0xE000) >> 13) + (8 * (_FC0_2 & 0x0001)) + 1;
#endif
// Correct T_SW when the setting is 0
if(t_sw < 60) {
t_sw = 45;
}
sclk_period_in_ns = one_billion / LED_HAL_SclkInHz();
sub_period_in_us = (((segment_length + t_sw) * TOTAL_SCAN_LINES * sclk_period_in_ns) / 1000) / freq_mult;
}
/* Function Name: setData
*
* Purpose: Set data send buffer.
*
* Parameters:
* data -> The pointer of data send buffer.
* high, mid, low -> Data bytes, MSB first.
* bias -> Bias in the date send buffer.
*
*/
void setData(uint16_t *data, uint16_t high, uint16_t mid, uint16_t low, uint16_t bias)
{
data[0 + bias] = high;
data[1 + bias] = mid;
data[2 + bias] = low;
}
/* Function Name: LED_Set_Chip_Index
*
* Purpose: Set Chip Index.
*
* Parameters:
* checkResponse -> Perform read of returned data
* bus -> Index of the CCSI bus to be written
*
*/
void LED_Set_Chip_Index(unsigned int checkResponse, unsigned int bus)
{
uint16_t data_int[1] = {0x0000};
CCSI_write(W_CHIP_INDEX, data_int, 0, checkResponse, bus);
}
/* Function Name: LED_sendSRAM
*
* Purpose: Send frame data to LED driver.
*
* Parameters:
* scan_lines -> Number of scan lines to send. A user might only want to send the first few scan lines.
*
*/
void LED_sendSRAM(uint16_t scan_lines)
{
uint16_t line_idx = 0;
uint16_t ch_idx = 0;
uint16_t x_idx = 0;
uint16_t y_idx = 0;
uint16_t bus_idx = 0;
uint16_t chip_idx = 0;
for(line_idx = 0; line_idx < scan_lines; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
for(bus_idx = 0 ; bus_idx < CCSI_BUS_NUM ; bus_idx++){
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++){
x_idx = X_COORDINATE(chip_idx, line_idx, ch_idx);
y_idx = Y_COORDINATE(chip_idx, line_idx, ch_idx);
// Ensure there are different data per bus in case transmission efficiency is fast enough to overwrite before all data is sent
setData(&data[bus_idx][0],
#if MONOCHROMATIC
lookup_table_B[img_mono[y_idx][x_idx + 2][bus_idx]], // B
lookup_table_G[img_mono[y_idx][x_idx + 1][bus_idx]], // G
lookup_table_R[img_mono[y_idx][x_idx][bus_idx]], // R
#else
lookup_table_B[img_B_RGB[y_idx][x_idx][bus_idx]], // B
lookup_table_G[img_G_RGB[y_idx][x_idx][bus_idx]], // G
lookup_table_R[img_R_RGB[y_idx][x_idx][bus_idx]], // R
#endif
(chip_idx << 1) + chip_idx);
}
CCSI_write(W_SRAM, &data[bus_idx][0], (CASCADED_UNITS[bus_idx] << 1) + CASCADED_UNITS[bus_idx], FALSE, bus_idx);
}
}
}
}
void LED_Write_Pos(uint16_t x, uint16_t y){
uint16_t line_idx = 0;
uint16_t ch_idx = 0;
uint16_t bus_idx = 0;
uint16_t chip_idx = 0;
uint16_t val = 0xFFFF;
for(line_idx = 0; line_idx < TOTAL_SCAN_LINES; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
for(bus_idx = 0 ; bus_idx < 1 ; bus_idx++){
for(chip_idx = 0; chip_idx < 1; chip_idx++){
if(line_idx == x && ch_idx == y){
val = 0xFFFF;
}
else{
val = 0x0;
}
if(ch_idx >= 11){
val = 0x0;
}
setData(&data[0][0],
val, // B
val, // G
val, // R
(0 << 1) + 0);
}
CCSI_write(W_SRAM, &data[0][0], (CASCADED_UNITS[0] << 1) + CASCADED_UNITS[0], FALSE, 0);
//DEVICE_DELAY_US(10000); //0.01s
}
}
}
}
void LED_Write_Letter(const unsigned char letter[15][15]){
uint16_t line_idx = 0;
uint16_t ch_idx = 0;
uint16_t val = 0xFFFF;
for(line_idx = 0; line_idx < TOTAL_SCAN_LINES; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
if(ch_idx < 15 && line_idx < 15){
if(letter[line_idx][ch_idx] != 0){
val = 0xFFFF;
}
else{
val = 0x0;
}
}
else{
val = 0x0;
}
setData(&data[0][0],
val, // B
val, // G
val, // R
0);
CCSI_write(W_SRAM, &data[0][0], 3, FALSE, 0);
}
}
}
/* Function Name: LED_Write_RGB_Custom_ALL
*
* Purpose: Send RGB data to all LED drivers.
*
* Parameters:
* r_value -> Brightness for red-channels
* g_value -> Brightness for green-channels
* b_value -> Brightness for blue-channels
*
*/
void LED_Write_RGB_Custom_ALL(uint16_t r_value, uint16_t g_value, uint16_t b_value)
{
uint16_t line_idx = 0;
uint16_t ch_idx = 0;
uint16_t bus_idx = 0;
uint16_t chip_idx = 0;
//uint16_t lineNum = 0; //turn on this line only
//uint16_t channelNum = 0;
for(line_idx = 0; line_idx < TOTAL_SCAN_LINES; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
for(bus_idx = 0 ; bus_idx < CCSI_BUS_NUM ; bus_idx++){
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++){
// Ensure there are different data per bus in case transmission efficiency is fast enough to overwrite before all data is sent
/*if((line_idx == lineNum) && (channelNum == ch_idx)){
// do nothing, we're at the right pixel
}
else{
b_value = 0x0000;
g_value = 0x0000;
r_value = 0x0000;
}*/
setData(&data[bus_idx][0],
b_value, // B
g_value, // G
r_value, // R
(chip_idx << 1) + chip_idx);
}
CCSI_write(W_SRAM, &data[bus_idx][0], (CASCADED_UNITS[bus_idx] << 1) + CASCADED_UNITS[bus_idx], FALSE, bus_idx);
}
}
}
}
/* Function Name: LED_Write_Black_ALL
*
* Purpose: Set all channels to off
*
* Parameters:
*
*/
void LED_Write_Black_ALL(void)
{
LED_Write_RGB_Custom_ALL(0x0000, 0x0000, 0x0000);
}
/* Function Name: LED_Write_White_ALL
*
* Purpose: Set all channels to maximum brightness
*
* Parameters:
*
*/
void LED_Write_White_ALL(void)
{
LED_Write_RGB_Custom_ALL(0xFFFF, 0xFFFF, 0xFFFF); //0xFFFF;
}
/* Function Name: LED_Write_Red_ALL
*
* Purpose: Set all red-channels to maximum brightness
*
* Parameters:
*
*/
void LED_Write_Red_ALL(void)
{
LED_Write_RGB_Custom_ALL(0xFFFF, 0x0000, 0x0000);
}
/* Function Name: LED_Write_Green_ALL
*
* Purpose: Set all green-channels to maximum brightness
*
* Parameters:
*
*/
void LED_Write_Green_ALL(void)
{
LED_Write_RGB_Custom_ALL(0x0000, 0xFFFF, 0x0000);
}
/* Function Name: LED_Write_Blue_ALL
*
* Purpose: Set all blue-channels to maximum brightness
*
* Parameters:
*
*/
void LED_Write_Blue_ALL(void)
{
LED_Write_RGB_Custom_ALL(0x0000, 0x0000, 0xFFFF);
}
/* Function Name: LED_Write_RGB_Diagonal_Custom_ALL
*
* Purpose: Diagonal data to all LED drivers
*
* Parameters:
* r_value -> Brightness for red-channels
* g_value -> Brightness for green-channels
* b_value -> Brightness for blue-channels
*
*/
void LED_Write_RGB_Diagonal_Custom_ALL(uint16_t r_value, uint16_t g_value, uint16_t b_value) {
uint16_t bus_idx = 0;
uint16_t line_idx;
uint16_t ch_idx;
uint16_t chip_idx;
uint16_t r_val;
uint16_t g_val;
uint16_t b_val;
uint16_t stacked_devices = LED_getStackableDevices();
uint16_t offset;
// Only do something when there are more than 1 scan lines
if(TOTAL_SCAN_LINES > 1) {
for(line_idx = 0; line_idx < TOTAL_SCAN_LINES; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
for(bus_idx = 0 ; bus_idx < CCSI_BUS_NUM ; bus_idx++){
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++){
offset = ((chip_idx % stacked_devices) * RGB_CHANNEL_CNT);
if(((ch_idx + line_idx + offset + 1U) % (uint16_t) TOTAL_SCAN_LINES) == 0) {
r_val = r_value;
g_val = g_value;
b_val = b_value;
}
else {
r_val = 0x0000;
g_val = 0x0000;
b_val = 0x0000;
}
// Ensure there are different data per bus in case transmission efficiency is fast enough to overwrite before all data is sent
setData(&data[bus_idx][0],
b_val, // B
g_val, // G
r_val, // R
(chip_idx << 1) + chip_idx);
}
CCSI_write(W_SRAM, &data[bus_idx][0], (CASCADED_UNITS[bus_idx] << 1) + CASCADED_UNITS[bus_idx], FALSE, bus_idx);
}
}
}
}
}
/* Function Name: LED_Write_Red_Diagonal_ALL
*
* Purpose: Write diagonal pattern to red-channels with maximum brightness
*
* Parameters:
*
*/
void LED_Write_Red_Diagonal_ALL(void)
{
LED_Write_RGB_Diagonal_Custom_ALL(0xFFFF, 0x0000, 0x0000);
}
/* Function Name: LED_Write_Green_Diagonal_ALL
*
* Purpose: Write diagonal pattern to green-channels with maximum brightness
*
* Parameters:
*
*/
void LED_Write_Green_Diagonal_ALL(void)
{
LED_Write_RGB_Diagonal_Custom_ALL(0x0000, 0xFFFF, 0x0000);
}
/* Function Name: LED_Write_Blue_Diagonal_ALL
*
* Purpose: Write diagonal pattern to blue-channels with maximum brightness
*
* Parameters:
*
*/
void LED_Write_Blue_Diagonal_ALL(void)
{
LED_Write_RGB_Diagonal_Custom_ALL(0x0000, 0x0000, 0xFFFF);
}
/* Function Name: LED_Write_RGB_Coupling_Custom_ALL
*
* Purpose: Write pattern to check coupling issue
*
* Parameters:
* r_coupling_value -> Brightness for red-channels of coupling value
* g_coupling_value -> Brightness for green-channels of coupling value
* b_coupling_value -> Brightness for blue-channels of coupling value
* r_value -> Brightness for low grayscale of red-channels
* g_value -> Brightness for low grayscale of green-channels
* b_value -> Brightness for low grayscale of blue-channels
*
*/
void LED_Write_RGB_Coupling_Custom_ALL(uint16_t r_coupling_value, uint16_t g_coupling_value, uint16_t b_coupling_value, uint16_t r_lg_value, uint16_t g_lg_value, uint16_t b_lg_value)
{
uint16_t rows_above;
uint16_t rows_middle;
uint16_t rows_below;
uint16_t columns_left;
uint16_t bus_idx = 0;
uint16_t line_idx;
uint16_t ch_idx;
uint16_t chip_idx;
uint16_t r_val;
uint16_t g_val;
uint16_t b_val;
uint16_t stacked_devices = LED_getStackableDevices();
uint16_t offset;
// Only do something when there are more than 1 scan lines
if(TOTAL_SCAN_LINES > 1) {
rows_middle = TOTAL_SCAN_LINES >> 1;
rows_below = (TOTAL_SCAN_LINES - rows_middle) >> 1;
rows_above = TOTAL_SCAN_LINES - rows_middle - rows_below;
columns_left = (stacked_devices * RGB_CHANNEL_CNT) >> 2;
for(line_idx = 0; line_idx < TOTAL_SCAN_LINES; line_idx++){
for(ch_idx = 0 ; ch_idx < RGB_CHANNEL_CNT ; ch_idx++){
for(bus_idx = 0 ; bus_idx < CCSI_BUS_NUM ; bus_idx++){
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++){
offset = ((chip_idx % stacked_devices) * RGB_CHANNEL_CNT);
if((line_idx < rows_above) | (line_idx > (rows_above + rows_middle - 1))) {
// Send low grayscale data
r_val = r_lg_value;
g_val = g_lg_value;
b_val = b_lg_value;
}
else {
// It depends on the column
if((ch_idx + offset) < columns_left) {
// Send low grayscale data
r_val = r_lg_value;
g_val = g_lg_value;
b_val = b_lg_value;
}
else {
// Send coupling grayscale data
r_val = r_coupling_value;
g_val = g_coupling_value;
b_val = b_coupling_value;
}
}
// Ensure there are different data per bus in case transmission efficiency is fast enough to overwrite before all data is sent
setData(&data[bus_idx][0],
b_val, // B
g_val, // G
r_val, // R
(chip_idx << 1) + chip_idx);
}
CCSI_write(W_SRAM, &data[bus_idx][0], (CASCADED_UNITS[bus_idx] << 1) + CASCADED_UNITS[bus_idx], FALSE, bus_idx);
}
}
}
}
}
void LED_Write_White_Dark_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0x0000, 0x0000, 0x0200, 0x0200, 0x0800);
}
void LED_Write_Red_Dark_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0x0000, 0x0000, 0x0200, 0x0000, 0x0000);
}
void LED_Write_Green_Dark_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x0000);
}
void LED_Write_Blue_Dark_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0800);
}
void LED_Write_White_Bright_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0xFFFF, 0xFFFF, 0xFFFF, 0x0200, 0x0200, 0x0800);
}
void LED_Write_Red_Bright_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0xFFFF, 0x0000, 0x0000, 0x0200, 0x0000, 0x0000);
}
void LED_Write_Green_Bright_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0xFFFF, 0x0000, 0x0000, 0x0200, 0x0000);
}
void LED_Write_Blue_Bright_Coupling_ALL(void)
{
LED_Write_RGB_Coupling_Custom_ALL(0x0000, 0x0000, 0xFFFF, 0x0000, 0x0000, 0x0800);
}
/* Function Name: LED_Write_Reg_Broadcast
*
* Purpose: Send same data to all FC register(s) in the chain.
*
* Parameters:
* fc_reg -> First FC register to be written.
* data2 -> Data byte
* data1 -> Data byte
* data0 -> Data byte
* checkResponse -> Perform read of returned data
* bus -> Index of the CCSI bus to be written
*
*/
void LED_Write_Reg_Broadcast(uint16_t fc_reg, uint16_t data2, uint16_t data1, uint16_t data0, unsigned int checkResponse, unsigned int bus)
{
uint16_t data_int[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
setData(data_int, data2, data1, data0, 0);
CCSI_write(fc_reg, data_int, 3, checkResponse, bus);
}
/* Function Name: LED_Read_Reg
*
* Purpose: Read FC register for specified chip index.
*
* Parameters:
* fc_reg -> FC register to be read.
* chip_idx -> Chip index that should be read
* bus -> Index of the CCSI bus to be used
*
*/
void LED_Read_Reg(uint16_t fc_reg, uint16_t chip_idx, unsigned int bus)
{
//CCSI_read(CHIP_REG_READ, ((fc_reg & 0x1F) << 10) + (chip_idx & 0x3FF), bus);
}
/* Function Name: LED_lod_lsd_detection
*
* Purpose: Detect if any line and channel have LED open or short
* LOD and LSD can only work when channel is on. This means that the device needs to be in a
* scan cycle. In addition, when during this scan cycle a channel is not turned on, e.g.
* only Red is displayed and Green and Blue are turned off, the LED open and LED short cannot
* be detected for the channels that are off. Also for low grayscale it might not be possible
* to detect the LSD and LOD.
*
* Parameters:
* LOD -> When 0, LED short detection is executed. All other numbers LED open detection is executed.
*
*/
void LED_lod_lsd_detection(unsigned int LOD)
{
uint16_t data[3] = {0x00, 0x00, 0x00}; // Data send buffer - to send FC registers
uint16_t fc3_0_old = 0;
uint16_t fc3_0 = 0;
uint16_t fc3_1 = 0;
uint16_t fc3_2 = 0;
uint16_t lod_lsd_line_warn[MAX_CASCADED_UNITS][4];
uint16_t line_warn_reg[2];
uint16_t line_warn_reg_cnt = 1;
uint16_t line_cmd_reg = 0;
uint16_t ch_reg = 0;
uint16_t idx = 0;
uint16_t bus_idx = 0;
uint16_t chip_idx;
uint16_t scan_idx;
uint16_t ch_idx;
uint16_t line_warn_reg_idx;
uint16_t found_chip_with_fault;
uint16_t offset;
LED_setSubPeriodInUS();
if(LOD == TRUE){
// LOD detection
#if (LP5890 | TLC6983)
line_warn_reg[0] = R_FC12;
line_cmd_reg = W_FC10;
ch_reg = R_FC14;
#else
line_warn_reg_cnt = 2;
line_warn_reg[0] = R_FC17;
line_warn_reg[1] = R_FC16;
line_cmd_reg = W_FC14;
ch_reg = R_FC20;
#endif
}
else{
// LSD detection
#if (LP5890 | TLC6983)
line_warn_reg[0] = R_FC13;
line_cmd_reg = W_FC11;
ch_reg = R_FC15;
#else
line_warn_reg_cnt = 2;
line_warn_reg[0] = R_FC19;
line_warn_reg[1] = R_FC18;
line_cmd_reg = W_FC15;
ch_reg = R_FC21;
#endif
}
// Clear flags
for(bus_idx = 0; bus_idx < CCSI_BUS_NUM; bus_idx++) {
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++) {
if(LOD == TRUE) {
chip_status[bus_idx][chip_idx].LOD = 0U;
for(scan_idx = 0; scan_idx < TOTAL_SCAN_LINES; scan_idx++) {
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTR.OUTR = 0U;
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTG.OUTG = 0U;
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTB.OUTB = 0U;
}
}
else {
chip_status[bus_idx][chip_idx].LSD = 0U;
for(scan_idx = 0; scan_idx < TOTAL_SCAN_LINES; scan_idx++) {
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTR.OUTR = 0U;
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTG.OUTG = 0U;
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTB.OUTB = 0U;
}
}
}
}
for(bus_idx = 0; bus_idx < CCSI_BUS_NUM; bus_idx++) {
// Read FC3 because we will need to set bit LOD_LSB_RB in this register
CCSI_read(R_FC3, bus_idx);
fc3_0 = ledRcvBuffer[bus_idx][3];
fc3_0_old = ledRcvBuffer[bus_idx][3];
fc3_1 = ledRcvBuffer[bus_idx][2];
fc3_2 = ledRcvBuffer[bus_idx][1];
// Set LOD_LSB_RB
fc3_0 |= LOD_LSD_RB__1;
setData(data, fc3_2, fc3_1, fc3_0, 0);
CCSI_write(W_FC3, data, 3, FALSE, bus_idx);
// Wait at least one sub-period time
DEVICE_DELAY_US (sub_period_in_us);
// Read the failing lines
line_warn_reg_idx = 0;
while(line_warn_reg_idx < line_warn_reg_cnt) {
CCSI_read(line_warn_reg[line_warn_reg_idx], bus_idx);
// Process read data for all devices in the chain
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++) {
if(line_warn_reg_idx == 0) {
// Scan line 0 to 15
lod_lsd_line_warn[chip_idx][0] = ledRcvBuffer[bus_idx][3 + chip_idx*3];
// Scan line 16 to 31
lod_lsd_line_warn[chip_idx][1] = ledRcvBuffer[bus_idx][2 + chip_idx*3];
// Scan line 32 to 47 - For LP5890 and TLC6983 this should be always 0
lod_lsd_line_warn[chip_idx][2] = ledRcvBuffer[bus_idx][1 + chip_idx*3];
}
else {
// Scan line 48 to 63 - For LP5890 and TLC6983 there is no second read
lod_lsd_line_warn[chip_idx][3] = ledRcvBuffer[bus_idx][3 + chip_idx*3];
}
}
// Check and process failing scan lines
for(scan_idx = 0; scan_idx < TOTAL_SCAN_LINES; scan_idx++){
idx = (scan_idx >> 4) & 0x1;
found_chip_with_fault = FALSE;
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++) {
if(lod_lsd_line_warn[chip_idx][idx] & 0x1){
found_chip_with_fault = TRUE;
if(LOD == TRUE) {
chip_status[bus_idx][chip_idx].LOD = 1U;
}
else {
chip_status[bus_idx][chip_idx].LSD = 1U;
}
}
lod_lsd_line_warn[chip_idx][idx] = lod_lsd_line_warn[chip_idx][idx] >> 1;
}
// If chip with fault is found need to find channel
if(found_chip_with_fault == TRUE) {
// Every time read line warning register
CCSI_read(line_warn_reg[line_warn_reg_idx], bus_idx);
// This scan line failed. So need to get the failing channel(s)
setData(data, 0x0000, 0x0000, scan_idx, 0);
CCSI_write(line_cmd_reg, data, 3, FALSE, bus_idx);
// Wait at least one sub-period time
DEVICE_DELAY_US (sub_period_in_us);
CCSI_read(ch_reg, bus_idx);
// Run over channels to see which one in the line has a fault
for(chip_idx = 0; chip_idx < CASCADED_UNITS[bus_idx]; chip_idx++) {
for(ch_idx = 0; ch_idx < CHANNEL_CNT; ch_idx++) {
offset = (ch_idx >> 4);
if(ledRcvBuffer[bus_idx][1 + (2-offset) + chip_idx*3] & (0x1 << (ch_idx & 0xF))) {
if(LOD == TRUE) {
if(offset == 0) {
// LOD is a Red channel
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTR.OUTR |= (1U << (ch_idx & 0x000F));
}
else {
if(offset == 1) {
// LOD is a Green channel
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTG.OUTG |= (1U << (ch_idx & 0x000F));
}
else {
// LOD is a Blue channel
chip_status[bus_idx][chip_idx].LOD_channels[scan_idx].OUTB.OUTB |= (1U << (ch_idx & 0x000F));
}
}
}
else {
if(offset == 0) {
// LSD is a Red channel
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTR.OUTR |= (1U << (ch_idx & 0x000F));
}
else {
if(offset == 1) {
// LSD is a Green channel
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTG.OUTG |= (1U << (ch_idx & 0x000F));
}
else {
// LSD is a Blue channel
chip_status[bus_idx][chip_idx].LSD_channels[scan_idx].OUTB.OUTB |= (1U << (ch_idx & 0x000F));
}
}
}
}
}
}
}
}
line_warn_reg_idx++;
}
// Return FC3 to old setting
setData(data, fc3_2, fc3_1, fc3_0_old, 0);
CCSI_write(W_FC3, data, 3, FALSE, bus_idx);
}
}
void LED_Update_LSD_channels(void)
{
LED_lod_lsd_detection(FALSE);
}
void LED_Update_LOD_channels(void)
{
LED_lod_lsd_detection(TRUE);
}
/* Function Name: LED_Update_Chip_Status
*
* Purpose: Update the chip status struct for all devices in the chain.
*
* Parameters:
*
*/
void LED_Update_Chip_Status(void)
{
// Update LOD and LSD for each channel
LED_Update_LOD_channels();
LED_Update_LSD_channels();
}
/* Function Name: sendSYNCinternal
*
* Purpose: Send VSYNC command to display next frame.
*
* Parameters:
* waitForINT -> When TRUE wait for interrupt before sending VSYNC command
*
*/
void sendSYNCinternal(unsigned int waitForINT)
{
uint16_t data_int[1] = {0x00};
uint16_t bus_idx = 0;
uint16_t vsync_local = 0;
// VSYNC needs to be send before next frame data can be send
if(waitForINT == TRUE) {
while(!vsync_local) {
vsync_local = vsyncDone;
}
}
for(bus_idx = 0 ; bus_idx < CCSI_BUS_NUM ; bus_idx++){
// SYNC display at a fixed FPS
CCSI_write_sync(W_VSYNC, data_int, 0, bus_idx);
}
// Send simultaneous VSYNC
LED_HAL_clbSyncTransferStart();
// Reset VSYNC
vsyncDone = 0;
}
/* Function Name: sendSYNC
*
* Purpose: Send VSYNC command but wait for interrupt to control timing.
*
* Parameters:
*
*/
void sendSYNC()
{
sendSYNCinternal(TRUE);
}
/* Function Name: sendSYNCnoWait
*
* Purpose: Send VSYNC command directly.
*
* Parameters:
*
*/
void sendSYNCnoWait()
{
sendSYNCinternal(FALSE);
}
//
// End of File
//