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)
8080 GPIO_PinInit (NEOPIXEL_PORT , NEOPIXEL_PIN , & neopixel_config );
8181#endif
8282
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+
8391#if TUF2_LOG
8492 board_uart_init (BOARD_UART_BAUDRATE );
8593#endif
8694}
8795
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+
88104void board_teardown (void )
89105{
90106 // no GPIO deinit for GPIO: LED, Neopixel, Button
Original file line number Diff line number Diff line change 4949#define TINYUF2_DFU_DOUBLE_TAP 0
5050#endif
5151
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+
5262// Use Display to draw DFU image
5363#ifndef TINYUF2_DISPLAY
5464#define TINYUF2_DISPLAY 0
@@ -91,6 +101,11 @@ void board_reset(void);
91101// Write PWM duty value to LED
92102void board_led_write (uint32_t value );
93103
104+ #if TINYUF2_DFU_BUTTON
105+ // Read button. Return true if pressed
106+ int board_button_read (void );
107+ #endif
108+
94109// Write color to rgb strip
95110void board_rgb_write (uint8_t const rgb []);
96111
Original file line number Diff line number Diff line change 3535//--------------------------------------------------------------------+
3636// MACRO CONSTANT TYPEDEF PROTYPES
3737//--------------------------------------------------------------------+
38- //#define USE_DFU_BUTTON 1
3938
4039// timeout for double tap detection
4140#define DBL_TAP_DELAY 500
@@ -104,6 +103,18 @@ int main(void)
104103static bool check_dfu_mode (void )
105104{
106105 // 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
107118#if TINYUF2_DFU_DOUBLE_TAP
108119 // TUF2_LOG1_HEX(&DBL_TAP_REG);
109120
You can’t perform that action at this time.
0 commit comments