Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
2  software/videomixer/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/common.mak
3 3
 
4  
-OBJECTS=crt0.o isr.o time.o dvisampler0.o dvisampler1.o main.o
  4
+OBJECTS=crt0.o isr.o time.o fb.o dvisampler0.o dvisampler1.o main.o
5 5
 
6 6
 all: videomixer.bin videomixer.fbi
7 7
 
5  software/videomixer/dvisamplerX.c
@@ -7,12 +7,13 @@
7 7
 #include <hw/flags.h>
8 8
 
9 9
 #include "time.h"
  10
+#include "fb.h"
10 11
 #include "dvisamplerX.h"
11 12
 
12 13
 #define FRAMEBUFFER_COUNT 4
13 14
 #define FRAMEBUFFER_MASK (FRAMEBUFFER_COUNT - 1)
14 15
 
15  
-static unsigned int dvisamplerX_framebuffers[FRAMEBUFFER_COUNT][640*480] __attribute__((aligned(16)));
  16
+static unsigned int dvisamplerX_framebuffers[FRAMEBUFFER_COUNT][800*600] __attribute__((aligned(16)));
16 17
 static int dvisamplerX_fb_slot_indexes[2];
17 18
 static int dvisamplerX_next_fb_index;
18 19
 
@@ -49,7 +50,7 @@ void dvisamplerX_init_video(void)
49 50
 	mask |= 1 << DVISAMPLERX_INTERRUPT;
50 51
 	irq_setmask(mask);
51 52
 
52  
-	dvisamplerX_dma_frame_size_write(sizeof(dvisamplerX_framebuffers[0]));
  53
+	dvisamplerX_dma_frame_size_write(fb_hres*fb_vres*4);
53 54
 	dvisamplerX_fb_slot_indexes[0] = 0;
54 55
 	dvisamplerX_dma_slot0_address_write((unsigned int)dvisamplerX_framebuffers[0]);
55 56
 	dvisamplerX_dma_slot0_status_write(DVISAMPLER_SLOT_LOADED);
103  software/videomixer/fb.c
... ...
@@ -0,0 +1,103 @@
  1
+#include <stdio.h>
  2
+
  3
+#include <hw/csr.h>
  4
+#include <hw/flags.h>
  5
+
  6
+#include "fb.h"
  7
+
  8
+int fb_hres = 640;
  9
+int fb_vres = 480;
  10
+
  11
+static void fb_clkgen_write(int cmd, int data)
  12
+{
  13
+	int word;
  14
+
  15
+	word = (data << 2) | cmd;
  16
+	crg_cmd_data_write(word);
  17
+	crg_send_cmd_data_write(1);
  18
+	while(crg_status_read() & CLKGEN_STATUS_BUSY);
  19
+}
  20
+
  21
+void fb_set_mode(int mode)
  22
+{
  23
+	int clock_m, clock_d;
  24
+
  25
+	switch(mode) {
  26
+		default:
  27
+		case FB_MODE_640_480: // Pixel clock: 25MHz
  28
+			fb_hres = 640;
  29
+			fb_vres = 480;
  30
+			clock_m = 2;
  31
+			clock_d = 4;
  32
+			fb_fi_hres_write(640);
  33
+			fb_fi_hsync_start_write(656);
  34
+			fb_fi_hsync_end_write(752);
  35
+			fb_fi_hscan_write(800);
  36
+			fb_fi_vres_write(480);
  37
+			fb_fi_vsync_start_write(492);
  38
+			fb_fi_vsync_end_write(494);
  39
+			fb_fi_vscan_write(525);
  40
+			break;
  41
+		case FB_MODE_800_600: // Pixel clock: 50MHz
  42
+			fb_hres = 800;
  43
+			fb_vres = 600;
  44
+			clock_m = 2;
  45
+			clock_d = 2;
  46
+			fb_fi_hres_write(800);
  47
+			fb_fi_hsync_start_write(848);
  48
+			fb_fi_hsync_end_write(976);
  49
+			fb_fi_hscan_write(1040);
  50
+			fb_fi_vres_write(600);
  51
+			fb_fi_vsync_start_write(636);
  52
+			fb_fi_vsync_end_write(642);
  53
+			fb_fi_vscan_write(665);
  54
+			break;
  55
+		case FB_MODE_1024_768: // Pixel clock: 65MHz
  56
+			fb_hres = 1024;
  57
+			fb_vres = 768;
  58
+			clock_m = 13;
  59
+			clock_d = 10;
  60
+			fb_fi_hres_write(1024);
  61
+			fb_fi_hsync_start_write(1048);
  62
+			fb_fi_hsync_end_write(1184);
  63
+			fb_fi_hscan_write(1344);
  64
+			fb_fi_vres_write(768);
  65
+			fb_fi_vsync_start_write(772);
  66
+			fb_fi_vsync_end_write(778);
  67
+			fb_fi_vscan_write(807);
  68
+			break;
  69
+		case FB_MODE_1920_1080: // Pixel clock: 148MHz
  70
+			fb_hres = 1920;
  71
+			fb_vres = 1080;
  72
+			clock_m = 74;
  73
+			clock_d = 25;
  74
+			fb_fi_hres_write(1920);
  75
+			fb_fi_hsync_start_write(2008);
  76
+			fb_fi_hsync_end_write(2052);
  77
+			fb_fi_hscan_write(2200);
  78
+			fb_fi_vres_write(1080);
  79
+			fb_fi_vsync_start_write(1084);
  80
+			fb_fi_vsync_end_write(1089);
  81
+			fb_fi_vscan_write(1125);
  82
+			break;
  83
+	}
  84
+	fb_dma0_length_write(fb_hres*fb_vres*4);
  85
+	fb_dma1_length_write(fb_hres*fb_vres*4);
  86
+
  87
+	fb_clkgen_write(0x1, clock_d-1);
  88
+	fb_clkgen_write(0x3, clock_m-1);
  89
+	crg_send_go_write(1);
  90
+	printf("waiting for PROGDONE...");
  91
+	while(!(crg_status_read() & CLKGEN_STATUS_PROGDONE));
  92
+	printf("ok\n");
  93
+	printf("waiting for LOCKED...");
  94
+	while(!(crg_status_read() & CLKGEN_STATUS_LOCKED));
  95
+	printf("ok\n");
  96
+
  97
+	printf("VGA: mode set to %dx%d\n", fb_hres, fb_vres);
  98
+}
  99
+
  100
+void fb_enable(int en)
  101
+{
  102
+	fb_enable_write(!!en);
  103
+}
16  software/videomixer/fb.h
... ...
@@ -0,0 +1,16 @@
  1
+#ifndef __FB_H
  2
+#define __FB_H
  3
+
  4
+enum {
  5
+    FB_MODE_640_480,
  6
+    FB_MODE_800_600,
  7
+    FB_MODE_1024_768,
  8
+    FB_MODE_1920_1080
  9
+};
  10
+
  11
+extern int fb_hres, fb_vres;
  12
+
  13
+void fb_set_mode(int mode);
  14
+void fb_enable(int en);
  15
+
  16
+#endif /* __FB_H */
8  software/videomixer/main.c
@@ -8,6 +8,7 @@
8 8
 #include <console.h>
9 9
 
10 10
 #include "time.h"
  11
+#include "fb.h"
11 12
 #include "dvisampler0.h"
12 13
 #include "dvisampler1.h"
13 14
 
@@ -80,10 +81,10 @@ static void fb_service(void)
80 81
 	if(readchar_nonblock()) {
81 82
 		c = readchar();
82 83
 		if(c == '1') {
83  
-			fb_enable_write(1);
  84
+			fb_enable(1);
84 85
 			printf("Framebuffer is ON\n");
85 86
 		} else if(c == '0') {
86  
-			fb_enable_write(0);
  87
+			fb_enable(0);
87 88
 			printf("Framebuffer is OFF\n");
88 89
 		}
89 90
 	}
@@ -98,9 +99,10 @@ int main(void)
98 99
 	puts("Minimal video mixer software built "__DATE__" "__TIME__"\n");
99 100
 	
100 101
 	time_init();
  102
+	fb_set_mode(FB_MODE_640_480);
101 103
 	dvisampler0_init_video();
102 104
 	dvisampler1_init_video();
103  
-	fb_enable_write(1);
  105
+	fb_enable(1);
104 106
 
105 107
 	while(1) {
106 108
 		dvisampler0_service();

No commit comments for this range

Something went wrong with that request. Please try again.