X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Bootloader%2Fdfu.h;h=d4da289eb93b4caf60ba3ccde706dcb7636e8a97;hb=5f262ea4b68a07e9b94ce0a49c0f7196e5f32b3b;hp=1a7340f1b4f439ae0ddfe7c2eed3f1fbe2680dac;hpb=622ea5d85f94be4b1694fdf08e30fa76eeb18fe4;p=kiibohd-controller.git diff --git a/Bootloader/dfu.h b/Bootloader/dfu.h index 1a7340f..d4da289 100644 --- a/Bootloader/dfu.h +++ b/Bootloader/dfu.h @@ -1,5 +1,5 @@ /* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>. - * Modifications by Jacob Alexander 2014 + * Modifications by Jacob Alexander 2014-2015 * * 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 . */ -#ifndef _USB_DFU_H -#define _USB_DFU_H +#pragma once // ----- Compiler Includes ----- @@ -30,7 +29,15 @@ #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 \ @@ -42,39 +49,6 @@ -// ----- 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