Add alt settings support in DFU class.

This commit is contained in:
Mengsk
2021-07-05 17:56:21 +02:00
parent 2ae19ce40d
commit c2d8ed3fd1
5 changed files with 56 additions and 41 deletions

View File

@@ -115,25 +115,20 @@ void tud_resume_cb(void)
blink_interval_ms = BLINK_MOUNTED;
}
// Invoked on DFU_DETACH request to reboot to the bootloader
void tud_dfu_runtime_reboot_to_dfu_cb(void)
{
blink_interval_ms = BLINK_DFU_MODE;
}
//--------------------------------------------------------------------+
// Class callbacks
//--------------------------------------------------------------------+
bool tud_dfu_firmware_valid_check_cb(void)
bool tud_dfu_firmware_valid_check_cb(uint8_t alt)
{
(void) alt;
printf(" Firmware check\r\n");
return true;
}
void tud_dfu_req_dnload_data_cb(uint16_t wBlockNum, uint8_t* data, uint16_t length)
void tud_dfu_req_dnload_data_cb(uint8_t alt, uint16_t wBlockNum, uint8_t* data, uint16_t length)
{
(void) data;
printf(" Received BlockNum %u of length %u\r\n", wBlockNum, length);
printf(" Received Alt %u BlockNum %u of length %u\r\n", alt, wBlockNum, length);
#if DFU_VERBOSE
for(uint16_t i=0; i<length; i++)
@@ -145,8 +140,9 @@ void tud_dfu_req_dnload_data_cb(uint16_t wBlockNum, uint8_t* data, uint16_t leng
tud_dfu_dnload_complete();
}
bool tud_dfu_device_data_done_check_cb(void)
bool tud_dfu_device_data_done_check_cb(uint8_t alt)
{
(void) alt;
printf(" Host said no more data... Returning true\r\n");
return true;
}
@@ -156,15 +152,16 @@ void tud_dfu_abort_cb(void)
printf(" Host aborted transfer\r\n");
}
#define UPLOAD_SIZE (29)
const uint8_t upload_test[UPLOAD_SIZE] = "Hello world from TinyUSB DFU!";
#define UPLOAD_SIZE 43
const uint8_t upload_test[2][UPLOAD_SIZE] = {"Hello world from TinyUSB DFU! - Partition 0",
"Hello world from TinyUSB DFU! - Partition 1"};
uint16_t tud_dfu_req_upload_data_cb(uint16_t block_num, uint8_t* data, uint16_t length)
uint16_t tud_dfu_req_upload_data_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length)
{
(void) block_num;
(void) length;
memcpy(data, upload_test, UPLOAD_SIZE);
memcpy(data, upload_test[alt], UPLOAD_SIZE);
return UPLOAD_SIZE;
}