From 48e0b432551ac9e077f938044a6648a1b253dfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 7 Jan 2023 06:11:53 +0100 Subject: [PATCH] main: add force DFU detection --- main/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 4f413d8..fabf62b 100644 --- a/main/main.c +++ b/main/main.c @@ -16,6 +16,8 @@ #include "driver/gpio.h" +// GPIO to force DFU mode (on high) +#define DFU_PIN 14 // GPIO for on-board LED (WEMOS S2 mini, source on) #define LED_BOARD 15 @@ -36,8 +38,20 @@ static const char* usb_str_desc[USB_STRING_DESCRIPTOR_ARRAY_SIZE] = { void app_main(void) { - // configure LEDs + // check DFU force gpio_config_t io_conf = {}; // to configure GPIO + io_conf.pin_bit_mask = (1ULL << DFU_PIN); // GPIO to configure + io_conf.intr_type = GPIO_INTR_DISABLE; // disable interrupt + io_conf.mode = GPIO_MODE_INPUT; // set as input + io_conf.pull_down_en = 1; // enable pull-down mode + io_conf.pull_up_en = 0; // disable pull-up mode + ESP_ERROR_CHECK( gpio_config(&io_conf) ); // configure GPIO + if (gpio_get_level(DFU_PIN)) { // DFU mode asserted + tud_dfu_runtime_reboot_to_dfu_cb(); // reboot to DFU mode + } + + + // configure LEDs io_conf.pin_bit_mask = (1ULL << LED_BOARD); // GPIO to configure io_conf.intr_type = GPIO_INTR_DISABLE; // disable interrupt io_conf.mode = GPIO_MODE_INPUT_OUTPUT; // set as output (push-pull), and input to read state