|
35 | 35 | //--------------------------------------------------------------------+
|
36 | 36 | // MACRO CONSTANT TYPEDEF PROTYPES
|
37 | 37 | //--------------------------------------------------------------------+
|
38 |
| -//#define USE_DFU_BUTTON 1 |
39 | 38 |
|
40 | 39 | // timeout for double tap detection
|
41 | 40 | #define DBL_TAP_DELAY 500
|
42 | 41 |
|
| 42 | +// when sensing the button state, wait this long before sampling the pin |
| 43 | +#define BUTTON_SETTLE_DELAY 20 |
| 44 | + |
43 | 45 | #ifndef DBL_TAP_REG
|
| 46 | + |
44 | 47 | // defined by linker script
|
45 | 48 | extern uint32_t _board_dfu_dbl_tap[];
|
46 | 49 | #define DBL_TAP_REG _board_dfu_dbl_tap[0]
|
@@ -104,6 +107,24 @@ int main(void)
|
104 | 107 | static bool check_dfu_mode(void)
|
105 | 108 | {
|
106 | 109 | // TODO enable for all port instead of one with double tap
|
| 110 | +#if TINYUF2_DFU_BUTTON |
| 111 | + // always stay in dfu mode if the button is pressed. |
| 112 | + // wait for a few milliseconds for the switch pin to reach its pulled value. |
| 113 | + _timer_count = 0; |
| 114 | + board_timer_start(1); |
| 115 | + while(_timer_count < BUTTON_SETTLE_DELAY) {} |
| 116 | + board_timer_stop(); |
| 117 | + if (board_button_read()) { |
| 118 | + // force erase app if forced into bootloader mode. |
| 119 | +#if TINYUF2_DFU_BUTTON_ERASE |
| 120 | + indicator_set(STATE_WRITING_STARTED); |
| 121 | + board_flash_erase_app(); |
| 122 | + indicator_set(STATE_WRITING_FINISHED); |
| 123 | +#endif |
| 124 | + return true; |
| 125 | + } |
| 126 | +#endif |
| 127 | + |
107 | 128 | #if TINYUF2_DFU_DOUBLE_TAP
|
108 | 129 | // TUF2_LOG1_HEX(&DBL_TAP_REG);
|
109 | 130 |
|
|
0 commit comments