Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
0  milkymist/adc/__init__.py → milkymist/counteradc/__init__.py
File renamed without changes
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 dvisampler0.o dvisampler1.o main.o
  4
+OBJECTS=crt0.o isr.o time.o dvisampler0.o dvisampler1.o main.o
5 5
 
6 6
 all: videomixer.bin
7 7
 
24  software/videomixer/dvisamplerX.c
@@ -6,6 +6,7 @@
6 6
 #include <hw/csr.h>
7 7
 #include <hw/flags.h>
8 8
 
  9
+#include "time.h"
9 10
 #include "dvisamplerX.h"
10 11
 
11 12
 #define FRAMEBUFFER_COUNT 4
@@ -152,22 +153,7 @@ int dvisamplerX_init_phase(void)
152 153
 }
153 154
 
154 155
 static int dvisamplerX_locked;
155  
-
156  
-static int elapsed(int period)
157  
-{
158  
-	static int last_event;
159  
-	int t, dt;
160  
-
161  
-	t = timer0_reload_read() - timer0_value_read(); // TODO: atomic read
162  
-	dt = t - last_event;
163  
-	if(dt < 0)
164  
-		dt += timer0_reload_read();
165  
-	if((dt > period) || (dt < 0)) {
166  
-		last_event = t;
167  
-		return 1;
168  
-	} else
169  
-		return 0;
170  
-}
  156
+static int dvisamplerX_last_event;
171 157
 
172 158
 void dvisamplerX_service(void)
173 159
 {
@@ -175,7 +161,7 @@ void dvisamplerX_service(void)
175 161
 
176 162
 	if(dvisamplerX_locked) {
177 163
 		if(dvisamplerX_clocking_locked_read()) {
178  
-			if(elapsed(identifier_frequency_read())) {
  164
+			if(elapsed(&dvisamplerX_last_event, identifier_frequency_read())) {
179 165
 				dvisamplerX_adjust_phase();
180 166
 				dvisamplerX_print_status();
181 167
 			}
@@ -196,9 +182,9 @@ void dvisamplerX_service(void)
196 182
 			dvisamplerX_print_status();
197 183
 			dvisamplerX_locked = 1;
198 184
 		} else {
199  
-			if(elapsed(identifier_frequency_read()/4)) {
  185
+			if(elapsed(&dvisamplerX_last_event, identifier_frequency_read()/4)) {
200 186
 				dvisamplerX_clocking_pll_reset_write(1);
201  
-				while(!elapsed(identifier_frequency_read()/16));
  187
+				while(!elapsed(&dvisamplerX_last_event, identifier_frequency_read()/16));
202 188
 				dvisamplerX_clocking_pll_reset_write(0);
203 189
 			}
204 190
 		}
67  software/videomixer/main.c
@@ -7,40 +7,75 @@
7 7
 #include <hw/flags.h>
8 8
 #include <console.h>
9 9
 
  10
+#include "time.h"
10 11
 #include "dvisampler0.h"
11 12
 #include "dvisampler1.h"
12 13
 
13  
-int main(void)
  14
+static int scale_pot(int raw, int range)
  15
+{
  16
+	int pot_min = 54000;
  17
+	int pot_max = 105400;
  18
+	int scaled;
  19
+
  20
+	scaled = range*(raw - pot_min)/(pot_max - pot_min);
  21
+	if(scaled < 0)
  22
+		scaled = 0;
  23
+	if(scaled > range)
  24
+		scaled = range;
  25
+	return scaled;
  26
+}
  27
+
  28
+static void pots_service(void)
  29
+{
  30
+	static int last_event;
  31
+	int blackout;
  32
+	int crossfade;
  33
+
  34
+	if(elapsed(&last_event, identifier_frequency_read()/32)) {
  35
+		pots_start_busy_write(1);
  36
+		while(pots_start_busy_read());
  37
+		blackout = scale_pot(pots_res0_read(), 256);
  38
+		crossfade = scale_pot(pots_res1_read(), 255);
  39
+
  40
+		fb_blender_f0_write(crossfade*blackout >> 8);
  41
+		fb_blender_f1_write((255-crossfade)*blackout >> 8);	
  42
+	}
  43
+}
  44
+
  45
+static void fb_service(void)
14 46
 {
15 47
 	int c;
16 48
 
  49
+	if(readchar_nonblock()) {
  50
+		c = readchar();
  51
+		if(c == '1') {
  52
+			fb_enable_write(1);
  53
+			printf("Framebuffer is ON\n");
  54
+		} else if(c == '0') {
  55
+			fb_enable_write(0);
  56
+			printf("Framebuffer is OFF\n");
  57
+		}
  58
+	}
  59
+}
  60
+
  61
+int main(void)
  62
+{
17 63
 	irq_setmask(0);
18 64
 	irq_setie(1);
19 65
 	uart_init();
20 66
 	
21 67
 	puts("Minimal video mixer software built "__DATE__" "__TIME__"\n");
22 68
 	
23  
-	timer0_reload_write(2*identifier_frequency_read());
24  
-	timer0_en_write(1);
25  
-
  69
+	time_init();
26 70
 	dvisampler0_init_video();
27 71
 	dvisampler1_init_video();
28 72
 	fb_enable_write(1);
29  
-	fb_blender_f0_write(127);
30  
-	fb_blender_f1_write(127);
  73
+
31 74
 	while(1) {
32 75
 		dvisampler0_service();
33 76
 		dvisampler1_service();
34  
-		if(readchar_nonblock()) {
35  
-			c = readchar();
36  
-			if(c == '1') {
37  
-				fb_enable_write(1);
38  
-				printf("Framebuffer is ON\n");
39  
-			} else if(c == '0') {
40  
-				fb_enable_write(0);
41  
-				printf("Framebuffer is OFF\n");
42  
-			}
43  
-		}
  77
+		pots_service();
  78
+		fb_service();
44 79
 	}
45 80
 	
46 81
 	return 0;
24  software/videomixer/time.c
... ...
@@ -0,0 +1,24 @@
  1
+#include <hw/csr.h>
  2
+
  3
+#include "time.h"
  4
+
  5
+void time_init(void)
  6
+{
  7
+	timer0_reload_write(2*identifier_frequency_read());
  8
+	timer0_en_write(1);
  9
+}
  10
+
  11
+int elapsed(int *last_event, int period)
  12
+{
  13
+	int t, dt;
  14
+
  15
+	t = timer0_reload_read() - timer0_value_read(); // TODO: atomic read
  16
+	dt = t - *last_event;
  17
+	if(dt < 0)
  18
+		dt += timer0_reload_read();
  19
+	if((dt > period) || (dt < 0)) {
  20
+		*last_event = t;
  21
+		return 1;
  22
+	} else
  23
+		return 0;
  24
+}
7  software/videomixer/time.h
... ...
@@ -0,0 +1,7 @@
  1
+#ifndef __TIME_H
  2
+#define __TIME_H
  3
+
  4
+void time_init(void);
  5
+int elapsed(int *last_event, int period);
  6
+
  7
+#endif /* __TIME_H */
6  top.py
@@ -8,7 +8,7 @@
8 8
 from migen.bank import csrgen
9 9
 
10 10
 from milkymist import m1crg, lm32, norflash, uart, s6ddrphy, dfii, asmicon, \
11  
-	identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler
  11
+	identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler, counteradc
12 12
 from cif import get_macros
13 13
 
14 14
 version = get_macros("common/version.h")["VERSION"][1:-1]
@@ -77,6 +77,7 @@ class SoC(Module):
77 77
 		"dvisampler0_edid_mem":	9,
78 78
 		"dvisampler1":			10,
79 79
 		"dvisampler1_edid_mem":	11,
  80
+		"pots":					12,
80 81
 	}
81 82
 
82 83
 	interrupt_map = {
@@ -148,6 +149,9 @@ def __init__(self, platform):
148 149
 		self.submodules.asmiprobe = asmiprobe.ASMIprobe(self.asmicon.hub)
149 150
 		self.submodules.dvisampler0 = dvisampler.DVISampler(platform.request("dvi_in", 0), asmiport_dvi0)
150 151
 		self.submodules.dvisampler1 = dvisampler.DVISampler(platform.request("dvi_in", 1), asmiport_dvi1)
  152
+		pots_pads = platform.request("dvi_pots")
  153
+		self.submodules.pots = counteradc.CounterADC(pots_pads.charge,
  154
+			[pots_pads.blackout, pots_pads.crossfade])
151 155
 
152 156
 		self.submodules.csrbankarray = csrgen.BankArray(self,
153 157
 			lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override])

No commit comments for this range

Something went wrong with that request. Please try again.