2 * boot/dfu.h - DFU protocol constants and data structures
4 * Written 2008, 2011, 2013-2015 by Werner Almesberger
5 * Copyright 2008, 2011, 2013-2015 Werner Almesberger
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
63 dfuMANIFEST_WAIT_RESET,
69 dfu_proto_runtime = 1, /* Runtime protocol */
70 dfu_proto_dfu = 2, /* DFU mode protocol */
74 #define DFU_DT_FUNCTIONAL 0x21 /* DFU FUNCTIONAL descriptor type */
77 #define DFU_TO_DEV(req) (0x21 | (req) << 8)
78 #define DFU_FROM_DEV(req) (0xa1 | (req) << 8)
82 uint8_t status; /* bStatus */
83 uint8_t toL, toM, toH; /* bwPollTimeout */
84 uint8_t state; /* bState */
89 #define DFU_ITF_DESCR(itf, alt, proto, idx) \
91 USB_DT_INTERFACE, /* bDescriptorType */ \
92 (itf), /* bInterfaceNumber */ \
93 (alt), /* bAlternateSetting */ \
94 0, /* bNumEndpoints */ \
95 0xfe, /* bInterfaceClass (application specific) */ \
96 0x01, /* bInterfaceSubClass (device fw upgrade) */ \
97 (proto), /* bInterfaceProtocol (dfu_proto_*) */ \
98 (idx), /* iInterface */
101 struct dfu_flash_ops {
103 bool (*can_write)(uint16_t size);
104 void (*write)(const uint8_t *buf, uint16_t size);
105 void (*end_write)(void);
106 uint16_t (*read)(uint8_t *buf, uint16_t size);
109 extern struct dfu dfu;
110 extern const struct dfu_flash_ops *dfu_flash_ops;
113 bool dfu_setup_common(const struct setup_request *setup);
114 bool dfu_my_descr(uint8_t type, uint8_t index, const uint8_t **reply,