|
| 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_H_ |
| 28 | +#define _TUSB_DFU_H_ |
| 29 | + |
| 30 | +#include "common/tusb_common.h" |
| 31 | + |
| 32 | +#ifdef __cplusplus |
| 33 | + extern "C" { |
| 34 | +#endif |
| 35 | + |
| 36 | +//--------------------------------------------------------------------+ |
| 37 | +// Common Definitions |
| 38 | +//--------------------------------------------------------------------+ |
| 39 | +// DFU Protocol |
| 40 | +typedef enum |
| 41 | +{ |
| 42 | + DFU_PROTOCOL_RT = 0x01, |
| 43 | + DFU_PROTOCOL_DFU = 0x02, |
| 44 | +} dfu_protocol_type_t; |
| 45 | + |
| 46 | +// DFU Descriptor Type |
| 47 | +typedef enum |
| 48 | +{ |
| 49 | + DFU_DESC_FUNCTIONAL = 0x21, |
| 50 | +} dfu_descriptor_type_t; |
| 51 | + |
| 52 | +// DFU Requests |
| 53 | +typedef enum { |
| 54 | + DFU_REQUEST_DETACH = 0, |
| 55 | + DFU_REQUEST_DNLOAD = 1, |
| 56 | + DFU_REQUEST_UPLOAD = 2, |
| 57 | + DFU_REQUEST_GETSTATUS = 3, |
| 58 | + DFU_REQUEST_CLRSTATUS = 4, |
| 59 | + DFU_REQUEST_GETSTATE = 5, |
| 60 | + DFU_REQUEST_ABORT = 6, |
| 61 | +} dfu_requests_t; |
| 62 | + |
| 63 | +// DFU States |
| 64 | +typedef enum { |
| 65 | + APP_IDLE = 0, |
| 66 | + APP_DETACH = 1, |
| 67 | + DFU_IDLE = 2, |
| 68 | + DFU_DNLOAD_SYNC = 3, |
| 69 | + DFU_DNBUSY = 4, |
| 70 | + DFU_DNLOAD_IDLE = 5, |
| 71 | + DFU_MANIFEST_SYNC = 6, |
| 72 | + DFU_MANIFEST = 7, |
| 73 | + DFU_MANIFEST_WAIT_RESET = 8, |
| 74 | + DFU_UPLOAD_IDLE = 9, |
| 75 | + DFU_ERROR = 10, |
| 76 | +} dfu_state_t; |
| 77 | + |
| 78 | +// DFU Status |
| 79 | +typedef enum { |
| 80 | + DFU_STATUS_OK = 0x00, |
| 81 | + DFU_STATUS_ERRTARGET = 0x01, |
| 82 | + DFU_STATUS_ERRFILE = 0x02, |
| 83 | + DFU_STATUS_ERRWRITE = 0x03, |
| 84 | + DFU_STATUS_ERRERASE = 0x04, |
| 85 | + DFU_STATUS_ERRCHECK_ERASED = 0x05, |
| 86 | + DFU_STATUS_ERRPROG = 0x06, |
| 87 | + DFU_STATUS_ERRVERIFY = 0x07, |
| 88 | + DFU_STATUS_ERRADDRESS = 0x08, |
| 89 | + DFU_STATUS_ERRNOTDONE = 0x09, |
| 90 | + DFU_STATUS_ERRFIRMWARE = 0x0A, |
| 91 | + DFU_STATUS_ERRVENDOR = 0x0B, |
| 92 | + DFU_STATUS_ERRUSBR = 0x0C, |
| 93 | + DFU_STATUS_ERRPOR = 0x0D, |
| 94 | + DFU_STATUS_ERRUNKNOWN = 0x0E, |
| 95 | + DFU_STATUS_ERRSTALLEDPKT = 0x0F, |
| 96 | +} dfu_device_status_t; |
| 97 | + |
| 98 | +#define DFU_FUNC_ATTR_CAN_DOWNLOAD_BITMASK (1 << 0) |
| 99 | +#define DFU_FUNC_ATTR_CAN_UPLOAD_BITMASK (1 << 1) |
| 100 | +#define DFU_FUNC_ATTR_MANIFESTATION_TOLERANT_BITMASK (1 << 2) |
| 101 | +#define DFU_FUNC_ATTR_WILL_DETACH_BITMASK (1 << 3) |
| 102 | + |
| 103 | +// DFU Status Request Payload |
| 104 | +typedef struct TU_ATTR_PACKED |
| 105 | +{ |
| 106 | + uint8_t bStatus; |
| 107 | + uint8_t bwPollTimeout[3]; |
| 108 | + uint8_t bState; |
| 109 | + uint8_t iString; |
| 110 | +} dfu_status_req_payload_t; |
| 111 | + |
| 112 | +TU_VERIFY_STATIC( sizeof(dfu_status_req_payload_t) == 6, "size is not correct"); |
| 113 | + |
| 114 | +#ifdef __cplusplus |
| 115 | + } |
| 116 | +#endif |
| 117 | + |
| 118 | +#endif /* _TUSB_DFU_H_ */ |
0 commit comments