From 59826f0d5b5b25ea5f50adddb46f0b2871041218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 23 Jul 2022 13:56:18 +0200 Subject: [PATCH] dfu: fix blinking pattern --- examples/device/dfu_freertos/src/main.c | 30 ++++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/examples/device/dfu_freertos/src/main.c b/examples/device/dfu_freertos/src/main.c index 78d760f69..733c447f3 100644 --- a/examples/device/dfu_freertos/src/main.c +++ b/examples/device/dfu_freertos/src/main.c @@ -2,6 +2,7 @@ * The MIT License (MIT) * * Copyright (c) 2019 Ha Thach (tinyusb.org) + * Copyright (c) 2022 King Kévin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -60,14 +61,10 @@ static const char* TAG = "DFU"; //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ -/* Blink pattern - * - 250 ms : device not mounted - * - 1000 ms : device mounted - * - 2500 ms : device is suspended - */ +/* Blink pattern (in ms) */ enum { - BLINK_NOT_MOUNTED = 250, - BLINK_MOUNTED = 1000, + BLINK_IDLE = 1000, + BLINK_DOWNLOAD = 250, BLINK_SUSPENDED = 2500, }; @@ -110,7 +107,7 @@ int main(void) } // soft timer for blinky - blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), true, NULL, led_blinky_cb, &blinky_tmdef); + blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_IDLE), true, NULL, led_blinky_cb, &blinky_tmdef); xTimerStart(blinky_tm, 0); // Create a task for tinyusb device stack @@ -155,18 +152,6 @@ void usb_device_task(void* param) // Device callbacks //--------------------------------------------------------------------+ -// Invoked when device is mounted -void tud_mount_cb(void) -{ - xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0); -} - -// Invoked when device is unmounted -void tud_umount_cb(void) -{ - xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0); -} - // Invoked when usb bus is suspended // remote_wakeup_en : if host allow us to perform remote wakeup // Within 7ms, device must draw an average of current less than 2.5 mA from bus @@ -179,7 +164,7 @@ void tud_suspend_cb(bool remote_wakeup_en) // Invoked when usb bus is resumed void tud_resume_cb(void) { - xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0); + xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_IDLE), 0); } //--------------------------------------------------------------------+ @@ -237,6 +222,7 @@ void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const* data, u return; } } + xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_DOWNLOAD), 0); // write data to partition rc = esp_ota_write_with_offset(ota_handle, data, length, block_num * CFG_TUD_DFU_XFER_BUFSIZE); @@ -260,6 +246,7 @@ void tud_dfu_manifest_cb(uint8_t alt) (void) alt; esp_err_t rc; ESP_LOGI(TAG, "download completed, enter manifestation"); + blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_IDLE), true, NULL, led_blinky_cb, &blinky_tmdef); // finish flashing if (ota_handle) { @@ -320,6 +307,7 @@ void tud_dfu_abort_cb(uint8_t alt) { (void) alt; ESP_LOGI(TAG, "host aborted transfer"); + blinky_tm = xTimerCreateStatic(NULL, pdMS_TO_TICKS(BLINK_IDLE), true, NULL, led_blinky_cb, &blinky_tmdef); } // Invoked when a DFU_DETACH request is received