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
|
/**
* Calculate virtual->real co-ordinate mapping to underlying single chain of panels connected to ESP32.
* Updates the private class member variable 'coords', so no need to use the return value.
* Not thread safe, but not a concern for ESP32 sketch anyway... I think.
*/
// DO NOT CHANGE
inline VirtualCoords VirtualMatrixPanelTest::getCoords_WorkingBaslineMarch2023(int16_t virt_x, int16_t virt_y)
{
coords.x = coords.y = -1; // By defalt use an invalid co-ordinates that will be rejected by updateMatrixDMABuffer
if (virt_x < 0 || virt_x >= virtualResX || virt_y < 0 || virt_y >= virtualResY)
{ // Co-ordinates go from 0 to X-1 remember! otherwise they are out of range!
return coords;
}
// Do we want to rotate?
if (_rotate)
{
int16_t temp_x = virt_x;
virt_x = virt_y;
virt_y = virtualResY - 1 - temp_x;
}
int row = (virt_y / panelResY); // 0 indexed
switch(panel_chain_type)
{
case (CHAIN_TOP_RIGHT_DOWN):
{
if ( (row % 2) == 1 )
{ // upside down panel
//Serial.printf("Condition 1, row %d ", row);
// refersed for the row
coords.x = dmaResX - virt_x - (row*virtualResX);
// y co-ord inverted within the panel
coords.y = panelResY - 1 - (virt_y % panelResY);
}
else
{
//Serial.printf("Condition 2, row %d ", row);
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
coords.y = virt_y % panelResY;
}
}
break;
case (CHAIN_TOP_LEFT_DOWN): // OK -> modulus opposite of CHAIN_TOP_RIGHT_DOWN
{
if ( (row % 2) == 0 )
{ // refersed panel
//Serial.printf("Condition 1, row %d ", row);
coords.x = dmaResX - virt_x - (row*virtualResX);
// y co-ord inverted within the panel
coords.y = panelResY - 1 - (virt_y % panelResY);
}
else
{
//Serial.printf("Condition 2, row %d ", row);
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
coords.y = virt_y % panelResY;
}
}
break;
case (CHAIN_BOTTOM_LEFT_UP): //
{
row = vmodule_rows - row - 1;
if ( (row % 2) == 1 )
{
// Serial.printf("Condition 1, row %d ", row);
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
coords.y = virt_y % panelResY;
}
else
{ // inverted panel
// Serial.printf("Condition 2, row %d ", row);
coords.x = dmaResX - (row*virtualResX) - virt_x;
coords.y = panelResY - 1 - (virt_y % panelResY);
}
}
break;
case (CHAIN_BOTTOM_RIGHT_UP): // OK -> modulus opposite of CHAIN_BOTTOM_LEFT_UP
{
row = vmodule_rows - row - 1;
if ( (row % 2) == 0 )
{ // right side up
// Serial.printf("Condition 1, row %d ", row);
// refersed for the row
coords.x = ((vmodule_rows - (row+1))*virtualResX)+virt_x;
coords.y = virt_y % panelResY;
}
else
{ // inverted panel
// Serial.printf("Condition 2, row %d ", row);
coords.x = dmaResX - (row*virtualResX) - virt_x;
coords.y = panelResY - 1 - (virt_y % panelResY);
}
}
break;
default:
return coords;
break;
} // end switch
/* START: Pixel remapping AGAIN to convert TWO parallel scanline output that the
* the underlying hardware library is designed for (because
* there's only 2 x RGB pins... and convert this to 1/4 or something
*/
if (panel_scan_rate == FOUR_SCAN_32PX_HIGH)
{
/* Convert Real World 'VirtualMatrixPanel' co-ordinates (i.e. Real World pixel you're looking at
on the panel or chain of panels, per the chaining configuration) to a 1/8 panels
double 'stretched' and 'squished' coordinates which is what needs to be sent from the
DMA buffer.
Note: Look at the FourScanPanel example code and you'll see that the DMA buffer is setup
as if the panel is 2 * W and 0.5 * H !
*/
if ((virt_y & 8) == 0)
{
coords.x += ((coords.x / panelResX) + 1) * panelResX; // 1st, 3rd 'block' of 8 rows of pixels, offset by panel width in DMA buffer
}
else
{
coords.x += (coords.x / panelResX) * panelResX; // 2nd, 4th 'block' of 8 rows of pixels, offset by panel width in DMA buffer
}
// http://cpp.sh/4ak5u
// Real number of DMA y rows is half reality
// coords.y = (y / 16)*8 + (y & 0b00000111);
coords.y = (virt_y >> 4) * 8 + (virt_y & 0b00000111);
}
else if (panel_scan_rate == FOUR_SCAN_16PX_HIGH)
{
if ((virt_y & 8) == 0)
{
coords.x += (panelResX >> 2) * (((coords.x & 0xFFF0) >> 4) + 1); // 1st, 3rd 'block' of 8 rows of pixels, offset by panel width in DMA buffer
}
else
{
coords.x += (panelResX >> 2) * (((coords.x & 0xFFF0) >> 4)); // 2nd, 4th 'block' of 8 rows of pixels, offset by panel width in DMA buffer
}
if (virt_y < 32)
coords.y = (virt_y >> 4) * 8 + (virt_y & 0b00000111);
else
{
coords.y = ((virt_y - 32) >> 4) * 8 + (virt_y & 0b00000111);
coords.x += 256;
}
}
return coords;
}
|