main: add force DFU detection

This commit is contained in:
King Kévin 2023-01-07 06:11:53 +01:00
parent 1312bfbc05
commit 48e0b43255
1 changed files with 15 additions and 1 deletions

View File

@ -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