Mercurial > louis > kiibohd-controller
comparison Bootloader/dfu.h @ 334:9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Mon, 27 Apr 2015 00:57:34 -0700 |
parents | ab4515606277 |
children | 795cc567b018 |
comparison
equal
deleted
inserted
replaced
333:772f9bea482b | 334:9ac304aa1ab5 |
---|---|
1 /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>. | 1 /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>. |
2 * Modifications by Jacob Alexander 2014 <haata@kiibohd.com> | 2 * Modifications by Jacob Alexander 2014-2015 <haata@kiibohd.com> |
3 * | 3 * |
4 * This program is free software: you can redistribute it and/or modify | 4 * This program is free software: you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation, either version 3 of the License, or | 6 * the Free Software Foundation, either version 3 of the License, or |
7 * (at your option) any later version. | 7 * (at your option) any later version. |
37 struct dfu_function_desc | 37 struct dfu_function_desc |
38 | 38 |
39 #define USB_FUNCTION_DFU_IFACE_COUNT 1 | 39 #define USB_FUNCTION_DFU_IFACE_COUNT 1 |
40 #define USB_FUNCTION_DFU_RX_EP_COUNT 0 | 40 #define USB_FUNCTION_DFU_RX_EP_COUNT 0 |
41 #define USB_FUNCTION_DFU_TX_EP_COUNT 0 | 41 #define USB_FUNCTION_DFU_TX_EP_COUNT 0 |
42 | |
43 | |
44 | |
45 // ----- Macros ----- | |
46 | |
47 #define USB_FUNCTION_DESC_DFU(state...) \ | |
48 { \ | |
49 .iface = { \ | |
50 .bLength = sizeof(struct usb_desc_iface_t), \ | |
51 .bDescriptorType = USB_DESC_IFACE, \ | |
52 .bInterfaceNumber = USB_FUNCTION_IFACE(0, state), \ | |
53 .bAlternateSetting = 0, \ | |
54 .bNumEndpoints = 0, \ | |
55 .bInterfaceClass = USB_DEV_CLASS_APP, \ | |
56 .bInterfaceSubClass = USB_DEV_SUBCLASS_APP_DFU, \ | |
57 .bInterfaceProtocol = USB_DEV_PROTO_DFU_DFU, \ | |
58 .iInterface = 0, \ | |
59 }, \ | |
60 .dfu = { \ | |
61 .bLength = sizeof(struct dfu_desc_functional), \ | |
62 .bDescriptorType = { \ | |
63 .id = 0x1, \ | |
64 .type_type = USB_DESC_TYPE_CLASS \ | |
65 }, \ | |
66 .will_detach = 1, \ | |
67 .manifestation_tolerant = 0, \ | |
68 .can_upload = 0, \ | |
69 .can_download = 1, \ | |
70 .wDetachTimeOut = 0, \ | |
71 .wTransferSize = USB_DFU_TRANSFER_SIZE, \ | |
72 .bcdDFUVersion = { .maj = 1, .min = 1 } \ | |
73 } \ | |
74 } | |
75 | 42 |
76 | 43 |
77 | 44 |
78 // ----- Enumerations ----- | 45 // ----- Enumerations ----- |
79 | 46 |
141 uint8_t iString; | 108 uint8_t iString; |
142 } __packed; | 109 } __packed; |
143 CTASSERT_SIZE_BYTE(struct dfu_status_t, 6); | 110 CTASSERT_SIZE_BYTE(struct dfu_status_t, 6); |
144 | 111 |
145 | 112 |
113 typedef enum dfu_status (*dfu_setup_read_t)(size_t off, size_t *len, void **buf); | |
146 typedef enum dfu_status (*dfu_setup_write_t)(size_t off, size_t len, void **buf); | 114 typedef enum dfu_status (*dfu_setup_write_t)(size_t off, size_t len, void **buf); |
147 typedef enum dfu_status (*dfu_finish_write_t)(void *, size_t off, size_t len); | 115 typedef enum dfu_status (*dfu_finish_write_t)(void *, size_t off, size_t len); |
148 typedef void (*dfu_detach_t)(void); | 116 typedef void (*dfu_detach_t)(void); |
149 | 117 |
150 struct dfu_ctx { | 118 struct dfu_ctx { |
151 struct usbd_function_ctx_header header; | 119 struct usbd_function_ctx_header header; |
152 enum dfu_state state; | 120 enum dfu_state state; |
153 enum dfu_status status; | 121 enum dfu_status status; |
122 dfu_setup_read_t setup_read; | |
154 dfu_setup_write_t setup_write; | 123 dfu_setup_write_t setup_write; |
155 dfu_finish_write_t finish_write; | 124 dfu_finish_write_t finish_write; |
156 size_t off; | 125 size_t off; |
157 size_t len; | 126 size_t len; |
158 }; | 127 }; |
188 | 157 |
189 | 158 |
190 | 159 |
191 // ----- Functions ----- | 160 // ----- Functions ----- |
192 | 161 |
193 void dfu_write_done(enum dfu_status, struct dfu_ctx *ctx); | 162 void dfu_write_done( enum dfu_status, struct dfu_ctx *ctx ); |
194 void dfu_init(dfu_setup_write_t setup_write, dfu_finish_write_t finish_write, struct dfu_ctx *ctx); | 163 void dfu_init( dfu_setup_read_t setup_read, dfu_setup_write_t setup_write, dfu_finish_write_t finish_write, struct dfu_ctx *ctx ); |
195 void dfu_app_init(dfu_detach_t detachcb); | 164 void dfu_app_init( dfu_detach_t detachcb ); |
196 | 165 |
197 #endif | 166 #endif |