]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Bootloader/dfu.h
Code cleanup
[kiibohd-controller.git] / Bootloader / dfu.h
index 1a7340f1b4f439ae0ddfe7c2eed3f1fbe2680dac..d4da289eb93b4caf60ba3ccde706dcb7636e8a97 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>.
- * Modifications by Jacob Alexander 2014 <haata@kiibohd.com>
+ * Modifications by Jacob Alexander 2014-2015 <haata@kiibohd.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _USB_DFU_H
-#define _USB_DFU_H
+#pragma once
 
 // ----- Compiler Includes -----
 
 
 
 #ifndef USB_DFU_TRANSFER_SIZE
-#define USB_DFU_TRANSFER_SIZE   FLASH_SECTOR_SIZE
+// Sector size is the same as the program flash size
+#if defined(_mk20dx128vlf5_)
+#define USB_DFU_TRANSFER_SIZE FLASH_SECTOR_SIZE
+
+// Sector size is double the program flash size
+#elif defined(_mk20dx256vlh7_ )
+#define USB_DFU_TRANSFER_SIZE FLASH_SECTOR_SIZE / 2
+
+#endif
 #endif
 
 #define USB_FUNCTION_DESC_DFU_DECL                         \
 
 
 
-// ----- Macros -----
-
-#define USB_FUNCTION_DESC_DFU(state...)                                 \
-       {                                                               \
-               .iface = {                                              \
-                       .bLength = sizeof(struct usb_desc_iface_t),     \
-                       .bDescriptorType = USB_DESC_IFACE,              \
-                       .bInterfaceNumber = USB_FUNCTION_IFACE(0, state), \
-                       .bAlternateSetting = 0,                         \
-                       .bNumEndpoints = 0,                             \
-                       .bInterfaceClass = USB_DEV_CLASS_APP,           \
-                       .bInterfaceSubClass = USB_DEV_SUBCLASS_APP_DFU, \
-                       .bInterfaceProtocol = USB_DEV_PROTO_DFU_DFU,    \
-                       .iInterface = 0,                                \
-               },                                                      \
-                       .dfu = {                                        \
-                       .bLength = sizeof(struct dfu_desc_functional),  \
-                       .bDescriptorType = {                            \
-                               .id = 0x1,                              \
-                               .type_type = USB_DESC_TYPE_CLASS        \
-                       },                                              \
-                       .will_detach = 1,                               \
-                       .manifestation_tolerant = 0,                    \
-                       .can_upload = 0,                                \
-                       .can_download = 1,                              \
-                       .wDetachTimeOut = 0,                            \
-                       .wTransferSize = USB_DFU_TRANSFER_SIZE,         \
-                       .bcdDFUVersion = { .maj = 1, .min = 1 }         \
-               }                                                       \
-       }
-
-
-
 // ----- Enumerations -----
 
 enum dfu_dev_subclass {
@@ -143,6 +117,7 @@ struct dfu_status_t {
 CTASSERT_SIZE_BYTE(struct dfu_status_t, 6);
 
 
+typedef enum dfu_status (*dfu_setup_read_t)(size_t off, size_t *len, void **buf);
 typedef enum dfu_status (*dfu_setup_write_t)(size_t off, size_t len, void **buf);
 typedef enum dfu_status (*dfu_finish_write_t)(void *, size_t off, size_t len);
 typedef void (*dfu_detach_t)(void);
@@ -151,6 +126,7 @@ struct dfu_ctx {
        struct usbd_function_ctx_header header;
        enum dfu_state state;
        enum dfu_status status;
+       dfu_setup_read_t setup_read;
        dfu_setup_write_t setup_write;
        dfu_finish_write_t finish_write;
        size_t off;
@@ -190,8 +166,7 @@ extern const struct usbd_function dfu_app_function;
 
 // ----- Functions -----
 
-void dfu_write_done(enum dfu_status, struct dfu_ctx *ctx);
-void dfu_init(dfu_setup_write_t setup_write, dfu_finish_write_t finish_write, struct dfu_ctx *ctx);
-void dfu_app_init(dfu_detach_t detachcb);
+void dfu_write_done( enum dfu_status, struct dfu_ctx *ctx );
+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 );
+void dfu_app_init( dfu_detach_t detachcb );
 
-#endif