diff --git a/examples/device/dfu/src/main.c b/examples/device/dfu/src/main.c index ee201c1c5..4ec6d477c 100644 --- a/examples/device/dfu/src/main.c +++ b/examples/device/dfu/src/main.c @@ -125,10 +125,13 @@ bool tud_dfu_firmware_valid_check_cb(uint8_t alt) return true; } -uint16_t tud_dfu_set_timeout_cb(uint8_t alt) +uint32_t tud_dfu_get_status_cb(uint8_t alt, uint8_t state) { // For example Alt1 (EEPROM) is slow, add 2000ms timeout - if (alt == 1) return 2000; + if ( state == DFU_DNBUSY ) + { + if (alt == 1) return 2000; + } return 0; } diff --git a/src/class/dfu/dfu_device.c b/src/class/dfu/dfu_device.c index 51e6179bc..23669b508 100644 --- a/src/class/dfu/dfu_device.c +++ b/src/class/dfu/dfu_device.c @@ -293,18 +293,17 @@ static uint16_t dfu_req_upload(uint8_t rhport, tusb_control_request_t const * re static void dfu_req_getstatus_reply(uint8_t rhport, tusb_control_request_t const * request) { - dfu_status_req_payload_t resp; - - uint16_t timeout = 0; - resp.bStatus = _dfu_state_ctx.status; - if(_dfu_state_ctx.state == DFU_DNBUSY && tud_dfu_set_timeout_cb) + uint32_t timeout = 0; + if ( tud_dfu_get_status_cb ) { - timeout = tud_dfu_set_timeout_cb(_dfu_state_ctx.alt); - + timeout = tud_dfu_get_status_cb(_dfu_state_ctx.alt, _dfu_state_ctx.state); } - resp.bwPollTimeout[0] = TU_U16_LOW(timeout); - resp.bwPollTimeout[1] = TU_U16_HIGH(timeout); - resp.bwPollTimeout[2] = 0; + + dfu_status_req_payload_t resp; + resp.bStatus = _dfu_state_ctx.status; + resp.bwPollTimeout[0] = TU_U32_BYTE0(timeout); + resp.bwPollTimeout[1] = TU_U32_BYTE1(timeout); + resp.bwPollTimeout[2] = TU_U32_BYTE2(timeout); resp.bState = _dfu_state_ctx.state; resp.iString = 0; diff --git a/src/class/dfu/dfu_device.h b/src/class/dfu/dfu_device.h index 8edb2bae3..647fc2c04 100644 --- a/src/class/dfu/dfu_device.h +++ b/src/class/dfu/dfu_device.h @@ -48,10 +48,10 @@ // alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. bool tud_dfu_firmware_valid_check_cb(uint8_t alt); -// Invoked when a DFU_GETSTATUS request is received in DFU_DNBUSY state -// Used to set the bwPollTimeout value, useful for slow Flash in order to make host wait longer +// Invoked when a DFU_GETSTATUS request is received +// Return the bwPollTimeout value for host's response, useful for slow Flash in order to make host wait longer // alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. -TU_ATTR_WEAK uint16_t tud_dfu_set_timeout_cb(uint8_t alt); +TU_ATTR_WEAK uint32_t tud_dfu_get_status_cb(uint8_t alt, uint8_t state); // Invoked when a DFU_DNLOAD request is received // alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.