瀏覽代碼

projects/boot_stub: Add a re-arm delay between selection button presses

It's easy to 'double' press the button, not really bounce, but just
mis presses. This small delay makes each press really intentional.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Sylvain Munaut 5 年之前
父節點
當前提交
ab62a9762e
共有 1 個文件被更改,包括 16 次插入6 次删除
  1. 16 6
      projects/boot_stub/rtl/top.v

+ 16 - 6
projects/boot_stub/rtl/top.v

@@ -59,7 +59,8 @@ module top (
 		ST_START	= 0,
 		ST_WAIT		= 1,
 		ST_SEL		= 2,
-		ST_BOOT		= 3;
+		ST_SEL_WAIT = 3,
+		ST_BOOT		= 4;
 
 
 	// Signals
@@ -72,8 +73,8 @@ module top (
 	wire btn_f;
 
 	// FSM
-	reg  [1:0] state_nxt;
-	reg  [1:0] state;
+	reg  [2:0] state_nxt;
+	reg  [2:0] state;
 
 	// Boot selector
 	wire boot_now;
@@ -141,10 +142,19 @@ module top (
 					state_nxt <= ST_SEL;
 
 			ST_SEL:
-				// Wait for timeout
-				if (timer_tick)
+				// If button press, temporarily disable it
+				if (btn_f)
+					state_nxt <= ST_SEL_WAIT;
+
+				// Or wait for timeout
+				else if (timer_tick)
 					state_nxt <= ST_BOOT;
 
+			ST_SEL_WAIT:
+				// Wait for button to re-arm
+				if (timer_tick)
+					state_nxt <= ST_SEL;
+
 			ST_BOOT:
 				// Nothing to do ... will reconfigure shortly
 				state_nxt <= state;
@@ -169,7 +179,7 @@ module top (
 			timer <= timer + 1;
 
 	assign timer_rst  = (btn_v == 1'b0) | timer_tick;
-	assign timer_tick = timer[23];
+	assign timer_tick = (state == ST_SEL_WAIT) ? timer[15] : timer[23];
 
 
 	// Warm Boot