diff options
author | root <root@lab.ourano.james.local> | 2021-02-26 12:12:38 +0000 |
---|---|---|
committer | root <root@lab.ourano.james.local> | 2021-02-26 12:12:38 +0000 |
commit | 3d48137c00511b3f2d35511482d1a76f8d06382d (patch) | |
tree | d75c88220cc847007869b0795a240c5077948262 /app/dfu.c | |
parent | 6d3a824e1cdae6e28146b7de380724b49488f3c2 (diff) | |
download | clock-3d48137c00511b3f2d35511482d1a76f8d06382d.tar.gz clock-3d48137c00511b3f2d35511482d1a76f8d06382d.tar.bz2 clock-3d48137c00511b3f2d35511482d1a76f8d06382d.zip |
works
Diffstat (limited to 'app/dfu.c')
-rw-r--r-- | app/dfu.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/app/dfu.c b/app/dfu.c new file mode 100644 index 0000000..c505585 --- /dev/null +++ b/app/dfu.c @@ -0,0 +1,81 @@ +#include "project.h" + +const struct usb_dfu_descriptor dfu_function = { + .bLength = sizeof (struct usb_dfu_descriptor), + .bDescriptorType = DFU_FUNCTIONAL, + .bmAttributes = USB_DFU_CAN_DOWNLOAD, + .wDetachTimeout = 255, + .wTransferSize = 1024, + .bcdDFUVersion = 0x011A, +}; + +const struct usb_interface_descriptor dfu_iface = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 2, + .bAlternateSetting = 0, + .bNumEndpoints = 0, + .bInterfaceClass = 0xFE, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 1, + .iInterface = 4, + + .extra = &dfu_function, + .extralen = sizeof (dfu_function), +}; + + +static int +dfu_detach_complete (usbd_device *usbd_dev, struct usb_setup_data *req) +{ + (void) req; + (void) usbd_dev; + dfu_flag = 0xfee1dead; + //SCB_VTOR=0; + + //SCB_AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_VECTRESET; + //SCB_AIRCR= SCB_AIRCR_SYSRESETREQ; + + scb_reset_core(); + return 1; +} + +int +dfu_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, + uint8_t **buf, uint16_t *len, + usbd_control_complete_callback *complete) +{ + (void) buf; + (void) len; + (void) usbd_dev; + + if ((req->bmRequestType & 0x7F) != 0x21) { + return 0; /* Only accept class request. */ + } + + switch (req->bRequest) { + case DFU_GETSTATUS: { + (*buf) [0] = DFU_STATUS_OK; + (*buf) [1] = 0; + (*buf) [2] = 0; + (*buf) [3] = 0; + (*buf) [4] = STATE_APP_IDLE; + (*buf) [5] = 0; /* iString not used here */ + *len = 6; + return 1; + } + + case DFU_GETSTATE: + /* Return state with no state transision. */ + *buf[0] = STATE_APP_IDLE; + *len = 1; + return 1; + + case DFU_DETACH: + *complete = dfu_detach_complete; + return 1; + } + + return 0; +} + |