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

Subversion Repositories openrisc

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

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
   in the middle. */
8
 
9
#define CAMERA_BASE     0x88000000
10
#define CRT_BASE        0xc0000000
11
#define VIDEO_RAM_START 0xa8000000      /* till including a83ffffc */
12
 
13
#define SCREEN_X        640
14
#define SCREEN_Y        480
15
 
16
#define CAMERA_X        352
17
#define CAMERA_Y        288
18
 
19
#define CAMERA_BUF(idx) (VIDEO_RAM_START + (idx) * CAMERA_X * CAMERA_Y)
20
#define FRAME_BUF       (CAMERA_BUF(2))
21
 
22
#define CAMERA_POS      (camera_pos_x + ((SCREEN_Y - CAMERA_Y) / 2) * SCREEN_X)
23
 
24
#define MIN(x,y)        ((x) < (y) ? (x) : (y))
25
 
26
#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
 
31
int camera_pos_x;
32
int camera_move_speed = 1;
33
int current_buf;
34
 
35
void camera_int (void)
36
{
37
  /* Change base addresse of camera */
38
  set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf)); /* Set address to store to */
39
 
40
  /* Change base addresse of crt */
41
  set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
42
  printf ("\n %08x\n ", CAMERA_BUF(current_buf));
43
 
44
  current_buf = 1 - current_buf;
45
 
46
  /* move the camera screen around */
47
  camera_pos_x += camera_move_speed;
48
  if (camera_pos_x >= SCREEN_X - CAMERA_X || camera_pos_x <= 0)
49
    camera_move_speed = -camera_move_speed;
50
  mtspr(SPR_PICSR, 0);
51
}
52
 
53
int crt_enable_cmd (int argc, char *argv[])
54
{
55
  int i, x, y;
56
 
57
  if (argc) return -1;
58
  /* Init CRT */
59
  set_mem32 (CRT_BASE + 4, FRAME_BUF); /* Frame buffer start */
60
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 1);          /* Enable CRT only */
61
 
62
  /* Init palette */
63
  for (i = 0; i < 32; i++) {
64
    set_palette (8 * i + 0, 0x00, 0x00, 0x00); /* black */
65
    set_palette (8 * i + 1, 0xff, 0xff, 0xff); /* white */
66
    set_palette (8 * i + 2, 0x7f, 0x7f, 0x7f); /* gray */
67
    set_palette (8 * i + 3, 0xff, 0x00, 0x00); /* red */
68
    set_palette (8 * i + 4, 0x00, 0xff, 0x00); /* green */
69
    set_palette (8 * i + 5, 0x00, 0x00, 0xff); /* blue */
70
    set_palette (8 * i + 6, 0x00, 0xff, 0xff); /* cyan */
71
    set_palette (8 * i + 7, 0xff, 0x00, 0xff); /* purple */
72
  }
73
  for (x = 0; x < SCREEN_X; x++)
74
    for (y = 0; y < SCREEN_Y; y++)
75
      put_pixel(x, y, 3);
76
  return 0;
77
}
78
 
79
int crt_test_cmd (int argc, char *argv[])
80
{
81
  int i, x, y;
82
  if (argc) return -1;
83
  for (x = 0; x < SCREEN_X; x++)
84
    for (y = 0; y < SCREEN_Y; y++)
85
      put_pixel(x, y, 0);
86
 /* Draw gray X */
87
  for (i = 0; i < SCREEN_Y; i++) {
88
    put_pixel (i, i, 2);
89
    put_pixel (SCREEN_X - i - 1, i, 1);
90
  }
91
 
92
  /* Draw color boxes */
93
  for (y = 0; y < 50; y++)
94
    for (x = 0; x < 50; x++)
95
      for (i = 0; i < 8; i++)
96
        put_pixel (i * 50 + x, y, i);
97
  return 0;
98
}
99
 
100
int crt_disable_cmd (int argc, char *argv[])
101
{
102
  if (argc) return -1;
103
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~1);             /* Disable CRT */
104
  return 0;
105
}
106
 
107
int camera_enable_cmd (int argc, char *argv[])
108
{
109
  if (argc) return -1;
110
  /* Init Camera */
111
  set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf = 0)); /* Set address to store to */
112
  set_mem32 (CAMERA_BASE + 4, 1);         /* Enable it */
113
 
114
  /* Init CRT to display camera */
115
  set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
116
  camera_pos_x = 0;
117
  set_mem32 (CRT_BASE + 0xc, CAMERA_POS);
118
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 2);         /* Enable camera overlay */
119
 
120
  /* Enable interrupts */
121
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
122
  mtspr (SPR_PICMR, mfspr(SPR_PICSR) | (1 << 13));
123
  return 0;
124
}
125
 
126
int camera_disable_cmd (int argc, char *argv[])
127
{
128
  if (argc) return -1;
129
  /* Disable interrupts */
130
  mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
131
  mtspr (SPR_PICMR, mfspr(SPR_PICSR) & ~(1 << 13));
132
 
133
  /* Disable Camera */
134
  set_mem32 (CAMERA_BASE + 4, 1);         /* Enable it */
135
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~2);                           /* Disable camera overlay */
136
  return 0;
137
}
138
 
139
void module_camera_init (void)
140
{
141
  register_command ("crt_enable", "", "enables CRT", crt_enable_cmd);
142
  register_command ("crt_disable", "", "disables CRT", crt_disable_cmd);
143
  register_command ("crt_test", "", "enables CRT and displays some test patterns", crt_test_cmd);
144
  register_command ("camera_enable", "", "enables camera", camera_enable_cmd);
145
  register_command ("camera_disable", "", "disables camera", camera_disable_cmd);
146
}

powered by: WebSVN 2.1.0

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