Browse Source

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 years ago
parent
commit
ab62a9762e
1 changed files with 16 additions and 6 deletions
  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_START	= 0,
 		ST_WAIT		= 1,
 		ST_WAIT		= 1,
 		ST_SEL		= 2,
 		ST_SEL		= 2,
-		ST_BOOT		= 3;
+		ST_SEL_WAIT = 3,
+		ST_BOOT		= 4;
 
 
 
 
 	// Signals
 	// Signals
@@ -72,8 +73,8 @@ module top (
 	wire btn_f;
 	wire btn_f;
 
 
 	// FSM
 	// FSM
-	reg  [1:0] state_nxt;
+	reg  [2:0] state_nxt;
-	reg  [1:0] state;
+	reg  [2:0] state;
 
 
 	// Boot selector
 	// Boot selector
 	wire boot_now;
 	wire boot_now;
@@ -141,10 +142,19 @@ module top (
 					state_nxt <= ST_SEL;
 					state_nxt <= ST_SEL;
 
 
 			ST_SEL:
 			ST_SEL:
-				// Wait for timeout
+				// If button press, temporarily disable it
-				if (timer_tick)
+				if (btn_f)
+					state_nxt <= ST_SEL_WAIT;
+
+				// Or wait for timeout
+				else if (timer_tick)
 					state_nxt <= ST_BOOT;
 					state_nxt <= ST_BOOT;
 
 
+			ST_SEL_WAIT:
+				// Wait for button to re-arm
+				if (timer_tick)
+					state_nxt <= ST_SEL;
+
 			ST_BOOT:
 			ST_BOOT:
 				// Nothing to do ... will reconfigure shortly
 				// Nothing to do ... will reconfigure shortly
 				state_nxt <= state;
 				state_nxt <= state;
@@ -169,7 +179,7 @@ module top (
 			timer <= timer + 1;
 			timer <= timer + 1;
 
 
 	assign timer_rst  = (btn_v == 1'b0) | timer_tick;
 	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
 	// Warm Boot