aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2017-11-17 11:27:40 +0000
committerDavid Shah <davey1576@gmail.com>2017-11-17 15:09:58 +0000
commitc71db50a27600885ea4e84d9744a4a4417af02c6 (patch)
tree8304c84ecc3c1f704a5813bbc25c86d1a5310415 /examples
parente7d22f22777227df18ff9c34e3b663aef04a075b (diff)
downloadicestorm-c71db50a27600885ea4e84d9744a4a4417af02c6.tar.gz
icestorm-c71db50a27600885ea4e84d9744a4a4417af02c6.tar.bz2
icestorm-c71db50a27600885ea4e84d9744a4a4417af02c6.zip
Add UltraPlus LED driver support and demo
Diffstat (limited to 'examples')
-rw-r--r--examples/up5k_rgb/.gitignore12
-rw-r--r--examples/up5k_rgb/Makefile36
-rw-r--r--examples/up5k_rgb/rgb.pcf3
-rw-r--r--examples/up5k_rgb/rgb.v81
4 files changed, 132 insertions, 0 deletions
diff --git a/examples/up5k_rgb/.gitignore b/examples/up5k_rgb/.gitignore
new file mode 100644
index 0000000..dd32bfb
--- /dev/null
+++ b/examples/up5k_rgb/.gitignore
@@ -0,0 +1,12 @@
+*.bin
+*.blif
+*.asc
+*.rpt
+*.glb
+*.psb
+*.sdf
+*.vsb
+*.bin
+*.tmp/
+*.exp
+*.vlog
diff --git a/examples/up5k_rgb/Makefile b/examples/up5k_rgb/Makefile
new file mode 100644
index 0000000..711ce5a
--- /dev/null
+++ b/examples/up5k_rgb/Makefile
@@ -0,0 +1,36 @@
+PROJ = rgb
+PIN_DEF = rgb.pcf
+DEVICE = up5k
+# Relative paths for easier development without messing with installed version
+ARACHNE = ../../../arachne-pnr/bin/arachne-pnr
+ARACHNE_ARGS = -c ../../icebox/chipdb-5k.txt
+ICEPACK = ../../icepack/icepack
+ICETIME = ../../icetime/icetime
+ICEPROG = ../../iceprog/iceprog
+
+all: $(PROJ).bin
+
+%.blif: %.v
+ yosys -p 'synth_ice40 -top top -blif $@' $<
+
+%.asc: $(PIN_DEF) %.blif
+ $(ARACHNE) $(ARACHNE_ARGS) -d $(subst up,,$(subst hx,,$(subst lp,,$(DEVICE)))) -o $@ -p $^
+
+%.bin: %.asc
+ $(ICEPACK) $< $@
+
+%.rpt: %.asc
+ $(ICETIME) -d $(DEVICE) -mtr $@ $<
+
+prog: $(PROJ).bin
+ $(ICEPROG) -S $<
+
+sudo-prog: $(PROJ).bin
+ @echo 'Executing prog as root!!!'
+ sudo $(ICEPROG) -S $<
+
+clean:
+ rm -f $(PROJ).blif $(PROJ).asc $(PROJ).rpt $(PROJ).bin
+
+.SECONDARY:
+.PHONY: all prog clean
diff --git a/examples/up5k_rgb/rgb.pcf b/examples/up5k_rgb/rgb.pcf
new file mode 100644
index 0000000..cfdb874
--- /dev/null
+++ b/examples/up5k_rgb/rgb.pcf
@@ -0,0 +1,3 @@
+set_io RGB0 39
+set_io RGB1 40
+set_io RGB2 41 \ No newline at end of file
diff --git a/examples/up5k_rgb/rgb.v b/examples/up5k_rgb/rgb.v
new file mode 100644
index 0000000..c83b943
--- /dev/null
+++ b/examples/up5k_rgb/rgb.v
@@ -0,0 +1,81 @@
+module top(
+ output RGB0, RGB1, RGB2
+);
+
+wire clk;
+
+SB_HFOSC inthosc (
+ .CLKHFPU(1'b1),
+ .CLKHFEN(1'b1),
+ .CLKHF(clk)
+);
+
+localparam counter_width = 30;
+
+reg [counter_width-1:0] ctr;
+
+always@(posedge clk)
+begin
+ ctr <= ctr + 1;
+end
+
+localparam pwm_width = 12;
+
+localparam pwm_max = (2**pwm_width) - 1;
+localparam pwm_max_div4 = (2**(pwm_width-2)) - 1;
+
+
+wire [1:0] phase = ctr[counter_width - 1 : counter_width - 2];
+wire [pwm_width-1:0] fade = ctr[counter_width - 3 : counter_width - (2 + pwm_width)];
+wire [pwm_width-1:0] fade_div4 = ctr[counter_width - 3 : counter_width - (pwm_width)];
+
+wire [pwm_width-1:0] r_val, g_val, b_val;
+
+// Fade R->G->B->W->
+assign r_val = (phase == 0) ? pwm_max_div4 + (3 * fade_div4) :
+ (phase == 1) ? pwm_max - fade :
+ (phase == 3) ? fade_div4 :
+ 0;
+
+assign g_val = (phase == 0) ? pwm_max_div4 - fade_div4:
+ (phase == 1) ? fade :
+ (phase == 2) ? pwm_max - fade :
+ (phase == 3) ? fade_div4 :
+ 0;
+
+assign b_val = (phase == 0) ? pwm_max_div4 - fade_div4:
+ (phase == 2) ? fade :
+ (phase == 3) ? pwm_max - (3 * fade_div4) :
+ 0;
+
+reg [pwm_width-1:0] pwm_ctr;
+
+reg pwm_r, pwm_g, pwm_b;
+
+always@(posedge clk)
+begin
+ pwm_ctr <= pwm_ctr + 1;
+ pwm_r <= (pwm_ctr < r_val) ? 1'b1 : 1'b0;
+ pwm_g <= (pwm_ctr < g_val) ? 1'b1 : 1'b0;
+ pwm_b <= (pwm_ctr < b_val) ? 1'b1 : 1'b0;
+end
+
+SB_RGBA_DRV RGBA_DRIVER (
+ .CURREN(1'b1),
+ .RGBLEDEN(1'b1),
+ .RGB0PWM(pwm_g),
+ .RGB1PWM(pwm_b),
+ .RGB2PWM(pwm_r),
+ .RGB0(RGB0),
+ .RGB1(RGB1),
+ .RGB2(RGB2)
+);
+
+
+defparam RGBA_DRIVER.CURRENT_MODE = "0b1";
+defparam RGBA_DRIVER.RGB0_CURRENT = "0b000001";
+defparam RGBA_DRIVER.RGB1_CURRENT = "0b000011";
+defparam RGBA_DRIVER.RGB2_CURRENT = "0b000011";
+
+
+endmodule \ No newline at end of file