فهرست منبع

projects/boot_stub: Make a lot of things optional / board dependent

Help to re-use the whole project on other boards that lack some features

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Sylvain Munaut 4 سال پیش
والد
کامیت
c22180302c

+ 2 - 2
projects/boot_stub/data/top-bitsy-v0.pcf

@@ -11,5 +11,5 @@ set_io -nowarn rgb[0] 39
 set_io -nowarn rgb[1] 40
 set_io -nowarn rgb[2] 41
 
-set_io -nowarn ledr 11
-set_io -nowarn ledg 37
+set_io -nowarn led[0] 11
+set_io -nowarn led[1] 37

+ 2 - 2
projects/boot_stub/data/top-bitsy-v1.pcf

@@ -11,5 +11,5 @@ set_io -nowarn rgb[0] 39
 set_io -nowarn rgb[1] 40
 set_io -nowarn rgb[2] 41
 
-set_io -nowarn ledr 25
-set_io -nowarn ledg 6
+set_io -nowarn led[0] 25
+set_io -nowarn led[1]  6

+ 2 - 2
projects/boot_stub/data/top-icebreaker.pcf

@@ -11,5 +11,5 @@ set_io -nowarn rgb[0] 39
 set_io -nowarn rgb[1] 40
 set_io -nowarn rgb[2] 41
 
-set_io -nowarn ledr 11
-set_io -nowarn ledg 37
+set_io -nowarn led[0] 11
+set_io -nowarn led[1] 37

+ 81 - 0
projects/boot_stub/rtl/boards.vh

@@ -0,0 +1,81 @@
+/*
+ * boards.vh
+ *
+ * vim: ts=4 sw=4 syntax=verilog
+ *
+ * Copyright (C) 2019  Sylvain Munaut <tnt@246tNt.com>
+ * All rights reserved.
+ *
+ * BSD 3-clause, see LICENSE.bsd
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the <organization> nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+`ifdef BOARD_BITSY_V0
+	// 1bitsquared iCEbreaker bitsy prototypes (v0.x)
+	`define HAS_USB
+	`define HAS_LEDS
+	`define HAS_RGB
+	`define RGB_DIM 3
+	`define RGB_MAP 12'h201		// 41=Blue, 40=Red, 39=Green
+`elsif BOARD_BITSY_V1
+	// 1bitsquared iCEbreaker bitsy prod (v1.x)
+	`define HAS_USB
+	`define HAS_LEDS
+	`define HAS_RGB
+	`define RGB_DIM 3
+	`define RGB_MAP 12'h210		// 41=Blue, 40=Green, 39=Red
+`elsif BOARD_ICEBREAKER
+	// 1bitsquare iCEbreaker
+	`define HAS_USB
+	`define HAS_LEDS
+	`define HAS_RGB
+	`define RGB_DIM 3
+	`define RGB_MAP 12'h012		// 41=Red, 40=Green, 39=Blue
+//	`define RGB_MAP 12'h120		// 41=Green, 40=Blue, 39=Red (Hacked v1.0b)
+`endif
+
+// Defaults
+`ifndef RGB_CURRENT_MODE
+`define RGB_CURRENT_MODE "0b1"
+`endif
+
+`ifndef RGB0_CURRENT
+`define RGB0_CURRENT "0b000001"
+`endif
+
+`ifndef RGB1_CURRENT
+`define RGB1_CURRENT "0b000001"
+`endif
+
+`ifndef RGB2_CURRENT
+`define RGB2_CURRENT "0b000001"
+`endif
+
+`ifndef RGB_MAP
+// [11:8] - Color of RGB2 / pin 41
+// [ 7:0] - Color of RGB1 / pin 40
+// [ 3:0] - Color of RGB0 / pin 39
+//          0=Red 1=Green 2=Blue
+`define RGB_MAP 12'h210		// 41=Blue, 40=Green, 39=Red
+`endif

+ 44 - 23
projects/boot_stub/rtl/top.v

@@ -32,21 +32,27 @@
  */
 
 `default_nettype none
+`include "boards.vh"
 
 module top (
 	// Button
 	input  wire btn,
 
 	// LED
-	output wire ledr,
-	output wire ledg,
+`ifdef HAS_LEDS
+	output wire [1:0] led,
+`endif
 
+`ifdef HAS_RGB
 	output wire [2:0] rgb,
+`endif
 
 	// USB
+`ifdef HAS_USB
 	output wire usb_dp,
 	output wire usb_dn,
 	output wire usb_pu
+`endif
 );
 
 	// FSM
@@ -82,10 +88,6 @@ module top (
 	wire timer_tick;
 	wire timer_rst;
 
-	// LED
-	reg [3:0] dim;
-	wire [2:0] rgb_pwm;
-
 	// Clock / Reset
 	wire clk;
 	wire rst;
@@ -207,42 +209,60 @@ module top (
 	// LED
 	// ---
 
-	assign rgb_pwm[0] = dim[3] & ~boot_now & boot_sel[0];
-	assign rgb_pwm[1] = dim[3] &  boot_now;
-	assign rgb_pwm[2] = dim[3] & ~boot_now & boot_sel[1];
+	// Normal LEDs
+`ifdef HAS_LEDS
+	assign led = ~boot_sel;
+`endif
 
-	assign ledr = ~boot_sel[0];
-	assign ledg = ~boot_sel[1];
+	// RGB LEDs
+`ifdef HAS_RGB
+		// Signals
+	wire [2:0] rgb_pwm;
+	wire       dim;
+		// Dimming
+`ifdef RGB_DIM
+	reg  [`RGB_DIM:0] dim_cnt;
 
-	// Dimming
 	always @(posedge clk)
-		if (rst)
-			dim <= 4'h0;
+		if (dim[`RGB_DIM])
+			dim_cnt <= 0;
 		else
-			dim <= dim[3] ? 4'h0 : (dim + 1);
+			dim_cnt <= dim_cnt + 1;
+
+	assign dim = dim[`RGB_DIM];
+`else
+	assign dim = 1'b1;
+`endif
+
+		// Color
+	assign rgb_pwm[0] = dim & ~boot_now & boot_sel[0];
+	assign rgb_pwm[1] = dim & ~boot_now & boot_sel[1];
+	assign rgb_pwm[2] = dim &  boot_now;
 
-	// Driver
+		// Driver
 	SB_RGBA_DRV #(
-		.CURRENT_MODE("0b1"),
-		.RGB0_CURRENT("0b000001"),
-		.RGB1_CURRENT("0b000001"),
-		.RGB2_CURRENT("0b000001")
+		.CURRENT_MODE(`RGB_CURRENT_MODE),
+		.RGB0_CURRENT(`RGB0_CURRENT),
+		.RGB1_CURRENT(`RGB1_CURRENT),
+		.RGB2_CURRENT(`RGB2_CURRENT)
 	) rgb_drv_I (
 		.RGBLEDEN(1'b1),
-		.RGB0PWM(rgb_pwm[0]),
-		.RGB1PWM(rgb_pwm[1]),
-		.RGB2PWM(rgb_pwm[2]),
+		.RGB0PWM(rgb_pwm[(`RGB_MAP >> 0) & 3]),
+		.RGB1PWM(rgb_pwm[(`RGB_MAP >> 4) & 3]),
+		.RGB2PWM(rgb_pwm[(`RGB_MAP >> 8) & 3]),
 		.CURREN(1'b1),
 		.RGB0(rgb[0]),
 		.RGB1(rgb[1]),
 		.RGB2(rgb[2])
 	);
+`endif
 
 
 	// Dummy USB
 	// ---------
 	// (to avoid pullups triggering detection)
 
+`ifdef HAS_USB
 	SB_IO #(
 		.PIN_TYPE(6'b101000),
 		.PULLUP(1'b0),
@@ -252,6 +272,7 @@ module top (
 		.OUTPUT_ENABLE(1'b0),
 		.D_OUT_0(1'b0)
 	);
+`endif
 
 
 	// Clock / Reset