File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -80,11 +80,27 @@ void board_init(void)
80
80
GPIO_PinInit (NEOPIXEL_PORT , NEOPIXEL_PIN , & neopixel_config );
81
81
#endif
82
82
83
+ #ifdef TINYUF2_DFU_BUTTON
84
+ // Button
85
+ IOMUXC_SetPinMux ( BUTTON_PINMUX , 1U );
86
+ IOMUXC_SetPinConfig (BUTTON_PINMUX , 0x01B0A0U );
87
+ gpio_pin_config_t button_config = { kGPIO_DigitalInput , 0 , kGPIO_NoIntmode };
88
+ GPIO_PinInit (BUTTON_PORT , BUTTON_PIN , & button_config );
89
+ #endif
90
+
83
91
#if TUF2_LOG
84
92
board_uart_init (BOARD_UART_BAUDRATE );
85
93
#endif
86
94
}
87
95
96
+ #ifdef TINYUF2_DFU_BUTTON
97
+ int board_button_read (void )
98
+ {
99
+ // active low
100
+ return BUTTON_STATE_ACTIVE == GPIO_PinRead (BUTTON_PORT , BUTTON_PIN );
101
+ }
102
+ #endif
103
+
88
104
void board_teardown (void )
89
105
{
90
106
// no GPIO deinit for GPIO: LED, Neopixel, Button
Original file line number Diff line number Diff line change 49
49
#define TINYUF2_DFU_DOUBLE_TAP 0
50
50
#endif
51
51
52
+ // Force boot to DFU mode when button is pressed
53
+ #ifndef TINYUF2_DFU_BUTTON
54
+ #define TINYUF2_DFU_BUTTON 0
55
+ // Should holding the DFU button perform an erase as well?
56
+ # ifndef TINYUF2_DFU_BUTTON_ERASE
57
+ # define TINYUF2_DFU_BUTTON_ERASE 0
58
+ # endif
59
+ #endif
60
+
61
+
52
62
// Use Display to draw DFU image
53
63
#ifndef TINYUF2_DISPLAY
54
64
#define TINYUF2_DISPLAY 0
@@ -91,6 +101,11 @@ void board_reset(void);
91
101
// Write PWM duty value to LED
92
102
void board_led_write (uint32_t value );
93
103
104
+ #if TINYUF2_DFU_BUTTON
105
+ // Read button. Return true if pressed
106
+ int board_button_read (void );
107
+ #endif
108
+
94
109
// Write color to rgb strip
95
110
void board_rgb_write (uint8_t const rgb []);
96
111
Original file line number Diff line number Diff line change 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
@@ -104,6 +103,18 @@ int main(void)
104
103
static bool check_dfu_mode (void )
105
104
{
106
105
// TODO enable for all port instead of one with double tap
106
+ #if TINYUF2_DFU_BUTTON
107
+ // always stay in dfu mode if the button is pressed.
108
+ if (board_button_read ()) {
109
+ // force erase app if forced into bootloader mode.
110
+ #if TINYUF2_DFU_BUTTON_ERASE
111
+ indicator_set (STATE_WRITING_STARTED );
112
+ board_flash_erase_app ();
113
+ indicator_set (STATE_WRITING_FINISHED );
114
+ #endif
115
+ return true;
116
+ }
117
+ #endif
107
118
#if TINYUF2_DFU_DOUBLE_TAP
108
119
// TUF2_LOG1_HEX(&DBL_TAP_REG);
109
120
You can’t perform that action at this time.
0 commit comments