OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [cmds/] [camera.c] - Blame information for rev 729

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#include "common.h"
2
#include "support.h"
3 246 julius
#include "spr-defs.h"
4 2 marcus.erl
 
5
/* Camera and CRT test.
6
   Draws gray cross across the screen, few color boxes at top left and moves around camera captured screen left/right
7 406 julius
   in the middle. */
8
 
9 2 marcus.erl
#define CAMERA_BASE     0x88000000
10
#define CRT_BASE        0xc0000000
11
#define VIDEO_RAM_START 0xa8000000      /* till including a83ffffc */
12 406 julius
 
13 2 marcus.erl
#define SCREEN_X        640
14
#define SCREEN_Y        480
15 406 julius
 
16 2 marcus.erl
#define CAMERA_X        352
17
#define CAMERA_Y        288
18 406 julius
 
19 2 marcus.erl
#define CAMERA_BUF(idx) (VIDEO_RAM_START + (idx) * CAMERA_X * CAMERA_Y)
20
#define FRAME_BUF       (CAMERA_BUF(2))
21 406 julius
 
22 2 marcus.erl
#define CAMERA_POS      (camera_pos_x + ((SCREEN_Y - CAMERA_Y) / 2) * SCREEN_X)
23 406 julius
 
24 2 marcus.erl
#define MIN(x,y)        ((x) < (y) ? (x) : (y))
25 406 julius
 
26 2 marcus.erl
#define set_mem32(addr,val)  (*((unsigned long *) (addr)) = (val))
27
#define get_mem32(addr)  (*((unsigned long *) (addr)))
28
#define set_palette(idx,r,g,b) set_mem32 (CRT_BASE + 0x400 + (idx) * 4, (((r) >> 3) << 11) | (((g) >> 2) << 5) | (((b) >> 3) << 0))
29
#define put_pixel(xx,yy,idx)   (*(unsigned char *)(FRAME_BUF + (xx) + (yy) * SCREEN_X) = (idx))
30 406 julius
 
31
int camera_pos_x;
32
 
33
int camera_move_speed = 1;
34
 
35
int current_buf;
36
 
37
 
38
void camera_int(void)
39
{
40
 
41
            /* Change base addresse of camera */
42
            set_mem32(CAMERA_BASE, CAMERA_BUF(current_buf));    /* Set address to store to */
43
 
44 2 marcus.erl
 
45 406 julius
            /* Change base addresse of crt */
46
            set_mem32(CRT_BASE + 8, CAMERA_BUF(1 - current_buf));       /* Tell CRT when camera buffer is */
47
 
48
printf("\n %08x\n ", CAMERA_BUF(current_buf));
49
 
50
 
51
current_buf = 1 - current_buf;
52
 
53 2 marcus.erl
 
54 406 julius
            /* move the camera screen around */
55
            camera_pos_x += camera_move_speed;
56
 
57
if (camera_pos_x >= SCREEN_X - CAMERA_X || camera_pos_x <= 0)
58
 
59
camera_move_speed = -camera_move_speed;
60
 
61
mtspr(SPR_PICSR, 0);
62
 
63
}
64
 
65
 
66
 
67
int crt_enable_cmd(int argc, char *argv[])
68
{
69
 
70
int i, x, y;
71
 
72
 
73
if (argc)
74
                return -1;
75
 
76
            /* Init CRT */
77
            set_mem32(CRT_BASE + 4, FRAME_BUF); /* Frame buffer start */
78
 
79
set_mem32(CRT_BASE, get_mem32(CRT_BASE) | 1);   /* Enable CRT only */
80
 
81 2 marcus.erl
 
82 406 julius
            /* Init palette */
83
            for (i = 0; i < 32; i++) {
84
 
85
set_palette(8 * i + 0, 0x00, 0x00, 0x00);        /* black */
86
 
87
set_palette(8 * i + 1, 0xff, 0xff, 0xff);       /* white */
88
 
89
set_palette(8 * i + 2, 0x7f, 0x7f, 0x7f);       /* gray */
90
 
91
set_palette(8 * i + 3, 0xff, 0x00, 0x00);       /* red */
92
 
93
set_palette(8 * i + 4, 0x00, 0xff, 0x00);       /* green */
94
 
95
set_palette(8 * i + 5, 0x00, 0x00, 0xff);       /* blue */
96
 
97
set_palette(8 * i + 6, 0x00, 0xff, 0xff);       /* cyan */
98
 
99
set_palette(8 * i + 7, 0xff, 0x00, 0xff);       /* purple */
100
 
101
}
102
 
103
for (x = 0; x < SCREEN_X; x++)
104
 
105
for (y = 0; y < SCREEN_Y; y++)
106
 
107
put_pixel(x, y, 3);
108
 
109
return 0;
110
 
111
}
112
 
113
 
114
 
115
int crt_test_cmd(int argc, char *argv[])
116
{
117
 
118
int i, x, y;
119
 
120
if (argc)
121
                return -1;
122
 
123
for (x = 0; x < SCREEN_X; x++)
124
 
125
for (y = 0; y < SCREEN_Y; y++)
126
 
127
put_pixel(x, y, 0);
128
 
129
            /* Draw gray X */
130
            for (i = 0; i < SCREEN_Y; i++) {
131
 
132
put_pixel(i, i, 2);
133
 
134
put_pixel(SCREEN_X - i - 1, i, 1);
135
 
136
}
137
 
138 2 marcus.erl
 
139 406 julius
            /* Draw color boxes */
140
            for (y = 0; y < 50; y++)
141
 
142
for (x = 0; x < 50; x++)
143
 
144
for (i = 0; i < 8; i++)
145
 
146
put_pixel(i * 50 + x, y, i);
147
 
148
return 0;
149
 
150
}
151
 
152
 
153
 
154
int crt_disable_cmd(int argc, char *argv[])
155
{
156
 
157
if (argc)
158
                return -1;
159
 
160
set_mem32(CRT_BASE, get_mem32(CRT_BASE) & ~1);  /* Disable CRT */
161
 
162
return 0;
163
 
164
}
165
 
166
 
167
 
168
int camera_enable_cmd(int argc, char *argv[])
169
{
170
 
171
if (argc)
172
                return -1;
173
 
174
            /* Init Camera */
175
            set_mem32(CAMERA_BASE, CAMERA_BUF(current_buf = 0)); /* Set address to store to */
176
 
177
set_mem32(CAMERA_BASE + 4, 1);  /* Enable it */
178
 
179 2 marcus.erl
 
180 406 julius
            /* Init CRT to display camera */
181
            set_mem32(CRT_BASE + 8, CAMERA_BUF(1 - current_buf));       /* Tell CRT when camera buffer is */
182
 
183
camera_pos_x = 0;
184
 
185
set_mem32(CRT_BASE + 0xc, CAMERA_POS);
186
 
187
set_mem32(CRT_BASE, get_mem32(CRT_BASE) | 2);   /* Enable camera overlay */
188
 
189 2 marcus.erl
 
190 406 julius
            /* Enable interrupts */
191
            mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
192
 
193
mtspr(SPR_PICMR, mfspr(SPR_PICSR) | (1 << 13));
194
 
195
return 0;
196
 
197
}
198
 
199
 
200
 
201
int camera_disable_cmd(int argc, char *argv[])
202
{
203
 
204
if (argc)
205
                return -1;
206
 
207
            /* Disable interrupts */
208
            mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
209
 
210
mtspr(SPR_PICMR, mfspr(SPR_PICSR) & ~(1 << 13));
211
 
212 2 marcus.erl
 
213 406 julius
            /* Disable Camera */
214
            set_mem32(CAMERA_BASE + 4, 1);      /* Enable it */
215
 
216
set_mem32(CRT_BASE, get_mem32(CRT_BASE) & ~2);  /* Disable camera overlay */
217
 
218
return 0;
219
 
220
}
221
 
222
 
223
 
224
void module_camera_init(void)
225
{
226
 
227
register_command("crt_enable", "", "enables CRT", crt_enable_cmd);
228
 
229
register_command("crt_disable", "", "disables CRT", crt_disable_cmd);
230
 
231
register_command("crt_test", "",
232
                          "enables CRT and displays some test patterns",
233
                          crt_test_cmd);
234
 
235
register_command("camera_enable", "", "enables camera",
236
                          camera_enable_cmd);
237
 
238
register_command("camera_disable", "", "disables camera",
239
                          camera_disable_cmd);
240
 
241
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.