wrap up DFU update

This commit is contained in:
hathach
2021-07-15 20:47:50 +07:00
parent b4fde90b55
commit daca9e520b
10 changed files with 367 additions and 254 deletions

View File

@@ -37,53 +37,51 @@
// Class Driver Default Configure & Validation
//--------------------------------------------------------------------+
#if !defined(CFG_TUD_DFU_TRANSFER_BUFFER_SIZE)
#error "CFG_TUD_DFU_TRANSFER_BUFFER_SIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR"
#if !defined(CFG_TUD_DFU_TRANSFER_BUFSIZE)
#error "CFG_TUD_DFU_TRANSFER_BUFSIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR"
#endif
//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+
// Must be called when the application is done with flashing started by
// tud_dfu_download_cb() and tud_dfu_manifest_cb().
// status is DFU_STATUS_OK if successful, any other error status will cause state to enter dfuError
void tud_dfu_finish_flashing(uint8_t status);
//--------------------------------------------------------------------+
// Application Callback API (weak is optional)
//--------------------------------------------------------------------+
// Invoked during DFU_MANIFEST_SYNC get status request to check if firmware is valid
// 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
// 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 uint32_t tud_dfu_get_status_cb(uint8_t alt, uint8_t state);
// Note: alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.
// 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.
// This callback takes the wBlockNum chunk of length length and provides it
// to the application at the data pointer. This data is only valid for this
// call, so the app must use it not or copy it.
void tud_dfu_download_cb(uint8_t alt, uint16_t wBlockNum, uint8_t* data, uint16_t length);
// Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MANIFEST)
// Application return timeout in milliseconds (bwPollTimeout) for the next download/manifest operation.
// During this period, USB host won't try to communicate with us.
uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state);
// Must be called when the application is done using the last block of data
// provided by tud_dfu_download_cb
void tud_dfu_download_complete(void);
// Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests
// This callback could be returned before flashing op is complete (async).
// Once finished flashing, application must call tud_dfu_finish_flashing()
void tud_dfu_download_cb (uint8_t alt, uint16_t block_num, uint8_t const *data, uint16_t length);
// Invoked during the last DFU_DNLOAD request, signifying that the host believes
// it is done transmitting data.
// alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.
// Return true if the application agrees there is no more data
// Return false if the device disagrees, which will stall the pipe, and the Host
// should initiate a recovery procedure
bool tud_dfu_device_data_done_check_cb(uint8_t alt);
// Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS (state=Manifest)
// Application can do checksum, or actual flashing if buffered entire image previously.
// Once finished flashing, application must call tud_dfu_finish_flashing()
void tud_dfu_manifest_cb(uint8_t alt);
// Invoked when the Host has terminated a download or upload transfer
TU_ATTR_WEAK void tud_dfu_abort_cb(uint8_t alt);
// Invoked when a DFU_UPLOAD request is received
// alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.
// This callback must populate data with up to length bytes
// Return the number of bytes to write
// Invoked when received DFU_UPLOAD request
// Application must populate data with up to length bytes and
// Return the number of written bytes
TU_ATTR_WEAK uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length);
// Invoked when a DFU_DETACH request is received
TU_ATTR_WEAK void tud_dfu_detach_cb(void);
// Invoked when the Host has terminated a download or upload transfer
TU_ATTR_WEAK void tud_dfu_abort_cb(uint8_t alt);
//--------------------------------------------------------------------+
// Internal Class Driver API
//--------------------------------------------------------------------+