X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Bootloader%2Fdfu.c;h=e5509fa00303182775fa7d67838b784e0b0db1ad;hb=6dfeffd9cad508817757d1afaba4ab0901cc9786;hp=8a4aa7d2db6abe0c40df5d723ceacc794a56166b;hpb=96e785b571a231265d64fbe5083371480cd3a549;p=kiibohd-controller.git diff --git a/Bootloader/dfu.c b/Bootloader/dfu.c index 8a4aa7d..e5509fa 100644 --- a/Bootloader/dfu.c +++ b/Bootloader/dfu.c @@ -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 @@ -19,6 +19,7 @@ #include "usb.h" #include "dfu.h" +#include "debug.h" @@ -68,7 +69,8 @@ static int dfu_handle_control( struct usb_ctrl_req_t *req, void *data ) struct dfu_ctx *ctx = data; int fail = 1; - switch ((enum dfu_ctrl_req_code)req->bRequest) { + switch ((enum dfu_ctrl_req_code)req->bRequest) + { case USB_CTRL_REQ_DFU_DNLOAD: { void *buf; @@ -98,12 +100,58 @@ static int dfu_handle_control( struct usb_ctrl_req_t *req, void *data ) dfu_dnload_complete(NULL, 0, ctx); goto out_no_status; } + case USB_CTRL_REQ_DFU_UPLOAD: { + /* + void *buf; + size_t len = 0; + + switch ( ctx->state ) + { + case DFU_STATE_dfuIDLE: + break; + case DFU_STATE_dfuUPLOAD_IDLE: + break; + default: + goto err; + } + + // Find which sector to read + ctx->status = ctx->setup_read(ctx->off, &len, &buf); + print("UPLOAD off:"); + printHex( ctx->off ); + print(" len:"); + printHex( len ); + print(" addr:"); + printHex( (uint32_t)buf ); + print( NL ); + + if ( ctx->status != DFU_STATUS_OK || len > req->wLength ) + { + ctx->state = DFU_STATE_dfuERROR; + goto err_have_status; + } + + // Send bytes to Host + if ( len > 0 ) + { + usb_ep0_rx( buf, len, NULL, NULL ); + } + else + { + ctx->state = DFU_STATE_dfuIDLE; + } + + goto out_no_status; + */ + return 0; + } case USB_CTRL_REQ_DFU_GETSTATUS: { struct dfu_status_t st; st.bState = ctx->state; st.bStatus = ctx->status; st.bwPollTimeout = 1000; /* XXX */ + /** * If we're in DFU_STATE_dfuMANIFEST, we just finished * the download, and we're just about to send our last @@ -131,14 +179,13 @@ static int dfu_handle_control( struct usb_ctrl_req_t *req, void *data ) switch (ctx->state) { case DFU_STATE_dfuIDLE: case DFU_STATE_dfuDNLOAD_IDLE: - /* case DFU_STATE_dfuUPLOAD_IDLE: */ + case DFU_STATE_dfuUPLOAD_IDLE: ctx->state = DFU_STATE_dfuIDLE; break; default: goto err; } break; - /* case USB_CTRL_REQ_DFU_UPLOAD: */ default: return (0); } @@ -156,9 +203,10 @@ out_no_status: return (1); } -void dfu_init( dfu_setup_write_t setup_write, dfu_finish_write_t finish_write, 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 ) { ctx->state = DFU_STATE_dfuIDLE; + ctx->setup_read = setup_read; ctx->setup_write = setup_write; ctx->finish_write = finish_write; usb_attach_function(&dfu_function, &ctx->header);