dfu: fix blinking pattern
This commit is contained in:
parent
95cdbda6e1
commit
59826f0d5b
|
@ -2,6 +2,7 @@
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||||
|
* Copyright (c) 2022 King Kévin <kingkevin@cuvoodoo.info>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -60,14 +61,10 @@ static const char* TAG = "DFU";
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
/* Blink pattern
|
/* Blink pattern (in ms) */
|
||||||
* - 250 ms : device not mounted
|
|
||||||
* - 1000 ms : device mounted
|
|
||||||
* - 2500 ms : device is suspended
|
|
||||||
*/
|
|
||||||
enum {
|
enum {
|
||||||
BLINK_NOT_MOUNTED = 250,
|
BLINK_IDLE = 1000,
|
||||||
BLINK_MOUNTED = 1000,
|
BLINK_DOWNLOAD = 250,
|
||||||
BLINK_SUSPENDED = 2500,
|
BLINK_SUSPENDED = 2500,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,7 +107,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// soft timer for blinky
|
// 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);
|
xTimerStart(blinky_tm, 0);
|
||||||
|
|
||||||
// Create a task for tinyusb device stack
|
// Create a task for tinyusb device stack
|
||||||
|
@ -155,18 +152,6 @@ void usb_device_task(void* param)
|
||||||
// Device callbacks
|
// 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
|
// Invoked when usb bus is suspended
|
||||||
// remote_wakeup_en : if host allow us to perform remote wakeup
|
// 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
|
// 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
|
// Invoked when usb bus is resumed
|
||||||
void tud_resume_cb(void)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_DOWNLOAD), 0);
|
||||||
|
|
||||||
// write data to partition
|
// write data to partition
|
||||||
rc = esp_ota_write_with_offset(ota_handle, data, length, block_num * CFG_TUD_DFU_XFER_BUFSIZE);
|
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;
|
(void) alt;
|
||||||
esp_err_t rc;
|
esp_err_t rc;
|
||||||
ESP_LOGI(TAG, "download completed, enter manifestation");
|
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
|
// finish flashing
|
||||||
if (ota_handle) {
|
if (ota_handle) {
|
||||||
|
@ -320,6 +307,7 @@ void tud_dfu_abort_cb(uint8_t alt)
|
||||||
{
|
{
|
||||||
(void) alt;
|
(void) alt;
|
||||||
ESP_LOGI(TAG, "host aborted transfer");
|
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
|
// Invoked when a DFU_DETACH request is received
|
||||||
|
|
Loading…
Reference in New Issue