-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform.c
124 lines (111 loc) · 3.5 KB
/
transform.c
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
/*
,--- OUT
|
+-^---------------+
7- | 63 <--- 56 |
6- | 55 <--- 48 |
5- | 47 <--- 40 |
4- | 39 <--- 32 |
3- | 31 <--- 24 |
2- | 23 <--- 16 |
1- | 15 <--- 8 |
0- | 7 6 5 4 3 2 1 0 |
| +---------------^-+
| `----- IN
+-----|-|-|-|-|-|-|-|--
0 1 2 3 4 5 6 7
| Location of LED #0 |
LED |'Top-Lft | Btm-Rgt.|.Btm-Lft | Top-Rgt'| Pixel Index = (y * 8) + x
-----+---------+---------+---------+---------| ^ ^
{x} | x | 7 - x | y | 7 - y | ---------------}--------'
{y} | 7 - y | y | x | 7 - x | ---------------'
|---Even Rotation---|----Odd Rotation---|
*/
//----------------------------------------------------------------------------- ---------------------------------------
#include <stdlib.h>
#include "banner.h"
//----------------------------------------------------------------------------- ---------------------------------------
// Curent display configuration
//
grid_t grid = {0} ;
//----------------------------------------------------------------------------- ---------------------------------------
// List of available transform functions
//
transFn_t trans[] = {
[T_2X3_A] = t_2x3_a,
[T_3X2_A] = t_3x2_a,
[T_EOT] = NULL // T_EOT // End of Table - MUST be LAST!
};
// Length of lookup table
const uint transCnt = (sizeof(trans) / sizeof(*trans)) -1;
//+============================================================================ =======================================
// 0-7 8-15
// +v--+---+
// | 3 | 2 | 16-23
// +v--+--^+
// | 4 | 1 | 8-15
// +v--+--^+
// | 5 | 0 | 0- 7
// +---+--^+
// ^----------LED #1
//
int t_2x3_a (int x, int y)
{
// Transformation
if ((y >= 0) && (y <= 23)) { // *EVEN ROTATION*
// ( board *64 ) + ( y *8 ) + ( x )
if ((x >= 0) && (x <= 7)) return ( (5-(y/8)) *64 ) + ( (7-(y&7)) *8 ) + ( x ) ; // left
else if ((x >= 8) && (x <= 15)) return ( (y/8) *64 ) + ( (y&7) *8 ) + ( 7-(x&7) ) ; // right
}
// Setup request
if ((x == 0xDEBB1E) && (y == 0xDA11A5)) {
grid = (grid_t) {
.w = 16,
.h = 24,
.bcnt = 6,
.pcnt = 6*64,
.id = T_2X3_A,
.fn = t_2x3_a
};
return -2;
}
return -1;
}
//+============================================================================ =======================================
//
// ! 0-7 ! 8-15!16-23|
//
// +-----+-----+-----+ ---
// | o< o< o< 15
// | 5 v| 4 v| 3 v| :
// | | | | 8 8-15
// +-----+-----+-----+ ---
// | | | | 7
// |^ 0 |^ 1 |^ 2 | : 0-7
// >o >o >o | 0
// +-----+-----+-----+ ---
// ^
// `-------------------------LED #1
//
int t_3x2_a (int x, int y)
{
// Transformation
if ((x >= 0) && (x <=23)) { // *ODD ROTATION*
// ( board *64 ) + ( y *8 ) + ( x )
if ((y >= 0) && (y <= 7)) return ( (x/8) *64 ) + ( (x&7) *8 ) + ( y );
else if ((y >= 8) && (y <= 15)) return ( (5-(x/8)) *64 ) + ( (7-(x&7)) *8 ) + ( 7-(y&7) );
}
// Setup request
if ((x == 0xDEBB1E) && (y == 0xDA11A5)) {
grid = (grid_t) {
.w = 24,
.h = 16,
.bcnt = 6,
.pcnt = 6*64,
.id = T_3X2_A,
.fn = t_3x2_a
};
return -2;
}
return -1;
}