-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
233 lines (197 loc) · 5.39 KB
/
main.c
File metadata and controls
233 lines (197 loc) · 5.39 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
/**
* main.c
*/
#include <F28x_Project.h>
#include "inv.h"
#include "inv2.h"
#include "sram.h"
#include "fatfs/src/tff.h"
#include "uart.h"
static FATFS g_sFatFs;
static FIL g_sFileObject;
static FIL g_invader;
FRESULT fresult;
void writeAll(uint16_t color1, uint16_t color2, uint16_t color3);
void writeImage();
void writeSquare(uint32_t x_size, uint32_t y_size, FIL* obj);
void writeX(uint32_t x_size, uint32_t y_size, uint32_t x_pos, uint32_t y_pos, uint16_t factor, FIL* obj);
void writeInvader(uint32_t x_pos, uint32_t y_pos, uint16_t type);
#define INV_BEGIN_X 80
#define INV_END_X 140
#define INV_BEGIN_Y 140
#define INV_ROW 6
#define INV_PER_ROW 11
int main(void)
{
sram_init();
volatile unsigned long time = 0;
InitSysCtrl();
GPIO_SetupPinOptions(32, GPIO_OUTPUT, 0);
GPIO_WritePin(32, 0);
scia_msg("\rOpen SD Card\n");
fresult = f_mount(0, &g_sFatFs);
if(fresult != FR_OK) scia_msg("\rDid not mount\n");
// fresult = f_open(&g_invader, "ismall.txt", FA_READ);
// if(fresult != FR_OK) scia_msg("\rrs.txt did not open\n");
fresult = f_open(&g_sFileObject, "bs.txt", FA_READ);
if(fresult != FR_OK) scia_msg("\rvga.txt did not open\n");
writeImage();
GPIO_WritePin(32, 1);
writeImage();
GPIO_WritePin(32, 0);
f_close(&g_sFileObject);
uint32_t x_start = 120;
uint16_t dir = 1, animation = 0;
while(1)
{
// writeAll(RED, GREEN, BLUE);
// writeX(13, 10, 120, 300, 3, &g_invader);
for(uint32_t rows = 0; rows < INV_ROW; rows++)
{
for(uint32_t enemy = 0; enemy < INV_PER_ROW; enemy++)
{
writeInvader(x_start+(enemy*40), INV_BEGIN_Y+30*rows, animation & 2);
}
}
if(dir)
{
x_start++;
if(x_start == INV_END_X)
dir = 0;
}
else
{
x_start--;
if(x_start == INV_BEGIN_X)
dir = 1;
}
GPIO_WritePin(32, 1);
// writeX(13, 10, 120, 300, 3, &g_invader);
for(uint32_t rows = 0; rows < INV_ROW; rows++)
{
for(uint32_t enemy = 0; enemy < INV_PER_ROW; enemy++)
{
writeInvader(x_start+(enemy*40), INV_BEGIN_Y+30*rows, animation & 2);
}
}
if(dir)
{
x_start++;
if(x_start == INV_END_X)
dir = 0;
}
else
{
x_start--;
if(x_start == INV_BEGIN_X)
dir = 1;
}
GPIO_WritePin(32, 0);
animation++;
}
return 0;
}
void writeInvader(uint32_t x_pos, uint32_t y_pos, uint16_t type)
{
uint32_t addr = 0;
sram_write_multi_start();
for(uint32_t x = 0; x < 33; x++)
{
for(uint32_t y = 0; y < 25; y++)
{
addr = ((x_pos + x) << 9) | (y_pos + y);
if(type)
sram_write_multi(addr, inv[y][x]);
else
sram_write_multi(addr, inv2[y][x]);
}
}
sram_write_multi_end();
}
void writeImage()
{
//SPI-C
//CS - Select GPIO125 (J2 12)
//DO - MISO GPIO123 (J2 18)
//SCK - CLK GPIO124 (J2 13)
//DI - MOSI GPIO122 (J2 17)
//CD - VCC
unsigned short usBytesRead;
uint32_t addr = 0;
uint16_t buf[2] = {0, 0};
sram_write_multi_start();
for(uint32_t x = 0; x < 640; x++)
{
for(uint32_t y = 0; y < 480; y++)
{
addr = (x << 9) | y;
fresult = f_read(&g_sFileObject, buf, 2, &usBytesRead);
sram_write_multi(addr, buf[1] << 8 | buf[0]);
}
}
f_lseek(&g_sFileObject, 0);
sram_write_multi_end();
}
void writeSquare(uint32_t x_size, uint32_t y_size, FIL* obj)
{
unsigned short usBytesRead;
uint32_t addr = 0;
uint16_t buf[2] = {0, 0};
sram_write_multi_start();
for(uint32_t x = 0; x < 33; x++)
{
for(uint32_t y = 0; y < 25; y++)
{
addr = ((120+x) << 9) | (300+y);
fresult = f_read(obj, buf, 2, &usBytesRead);
sram_write_multi(addr, buf[1] << 8 | buf[0]);
}
}
f_lseek(obj, 0);
sram_write_multi_end();
}
void writeX(uint32_t x_size, uint32_t y_size, uint32_t x_pos, uint32_t y_pos, uint16_t factor, FIL* obj)
{
unsigned short usBytesRead;
uint32_t addr = 0;
uint16_t buf[2] = {0, 0};
sram_write_multi_start();
for(uint32_t x = 0; x < factor*x_size; x+=factor)
{
for(uint32_t y = 0; y < factor*y_size; y+=factor)
{
fresult = f_read(obj, buf, 2, &usBytesRead);
for(uint16_t i = 0; i < factor; i++)
{
for(uint16_t j = 0; j < factor; j++)
{
addr = ((x_pos+x+i) << 9) | (y_pos+y+j);
sram_write_multi(addr, buf[1] << 8 | buf[0]);
}
}
}
}
f_lseek(obj, 0);
sram_write_multi_end();
}
void writeAll(uint16_t color1, uint16_t color2, uint16_t color3)
{
uint32_t addr = 0;
uint16_t color = 0;
sram_write_multi_start();
for(uint32_t x = 0; x < 640; x++)
{
if(x < 213)
color = color1;
else if(x < 426)
color = color2;
else
color = color3;
for(uint32_t y = 0; y < 480; y++)
{
addr = (x << 9) | y;
sram_write_multi(addr, color);
}
}
sram_write_multi_end();
}