mikroSDK Reference Manual
dfu_device.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021 XMOS LIMITED
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_DFU_DEVICE_H_
28#define _TUSB_DFU_DEVICE_H_
29
30#include "dfu.h"
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36//--------------------------------------------------------------------+
37// Class Driver Default Configure & Validation
38//--------------------------------------------------------------------+
39
40#if !defined(CFG_TUD_DFU_XFER_BUFSIZE)
41 #error "CFG_TUD_DFU_XFER_BUFSIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR"
42#endif
43
44//--------------------------------------------------------------------+
45// Application API
46//--------------------------------------------------------------------+
47
48// Must be called when the application is done with flashing started by
49// tud_dfu_download_cb() and tud_dfu_manifest_cb().
50// status is DFU_STATUS_OK if successful, any other error status will cause state to enter dfuError
51void tud_dfu_finish_flashing(uint8_t status);
52
53//--------------------------------------------------------------------+
54// Application Callback API (weak is optional)
55//--------------------------------------------------------------------+
56
57// Note: alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.
58
59// Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MANIFEST)
60// Application return timeout in milliseconds (bwPollTimeout) for the next download/manifest operation.
61// During this period, USB host won't try to communicate with us.
62uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state);
63
64// Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests
65// This callback could be returned before flashing op is complete (async).
66// Once finished flashing, application must call tud_dfu_finish_flashing()
67void tud_dfu_download_cb (uint8_t alt, uint16_t block_num, uint8_t const *data, uint16_t length);
68
69// Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS (state=Manifest)
70// Application can do checksum, or actual flashing if buffered entire image previously.
71// Once finished flashing, application must call tud_dfu_finish_flashing()
72void tud_dfu_manifest_cb(uint8_t alt);
73
74// Invoked when received DFU_UPLOAD request
75// Application must populate data with up to length bytes and
76// Return the number of written bytes
77TU_ATTR_WEAK uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length);
78
79// Invoked when a DFU_DETACH request is received
80TU_ATTR_WEAK void tud_dfu_detach_cb(void);
81
82// Invoked when the Host has terminated a download or upload transfer
83TU_ATTR_WEAK void tud_dfu_abort_cb(uint8_t alt);
84
85//--------------------------------------------------------------------+
86// Internal Class Driver API
87//--------------------------------------------------------------------+
88void dfu_moded_init(void);
89void dfu_moded_reset(uint8_t rhport);
90uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
91bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
92
93
94#ifdef __cplusplus
95 }
96#endif
97
98#endif /* _TUSB_DFU_MODE_DEVICE_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647