diff --git a/atusb/fw/boot.c b/atusb/fw/boot.c index 539d2eb..9bf74d5 100644 --- a/atusb/fw/boot.c +++ b/atusb/fw/boot.c @@ -57,6 +57,7 @@ int main(void) led(0); + usb_reset(); run_payload(); while (1); /* not reached */ diff --git a/atusb/fw/usb/atu2.c b/atusb/fw/usb/atu2.c index 68461b3..917b680 100644 --- a/atusb/fw/usb/atu2.c +++ b/atusb/fw/usb/atu2.c @@ -171,6 +171,12 @@ void usb_poll(void) { uint8_t flags, i; + flags = UDINT; + if (flags & EORSTI) { + UDINT &= ~(1 << EORSTI); + if (user_reset) + user_reset(); + } flags = UEINT; for (i = 0; i != NUM_EPS; i++) if (1 || flags & (1 << i)) @@ -194,6 +200,13 @@ static void ep_init(void) } +void usb_reset(void) +{ + UDCON |= 1 << DETACH; /* detach the pull-up */ + _delay_ms(1); +} + + void usb_init(void) { USBCON |= 1 << FRZCLK; /* freeze the clock */ diff --git a/atusb/fw/usb/dfu.c b/atusb/fw/usb/dfu.c index 18eb98c..2435b5c 100644 --- a/atusb/fw/usb/dfu.c +++ b/atusb/fw/usb/dfu.c @@ -264,21 +264,21 @@ static int my_descr(uint8_t type, uint8_t index, const uint8_t **reply, } -#if 0 static void my_reset(void) { +#if 0 /* @@@ not nice -- think about where this should go */ extern void run_payload(void); if (did_download) run_payload(); -} #endif +} void dfu_init(void) { user_setup = my_setup; user_get_descriptor = my_descr; -// user_reset = my_reset; + user_reset = my_reset; } diff --git a/atusb/fw/usb/usb.h b/atusb/fw/usb/usb.h index 8868ffd..87d0f2e 100644 --- a/atusb/fw/usb/usb.h +++ b/atusb/fw/usb/usb.h @@ -141,6 +141,7 @@ void usb_io(struct ep_descr *ep, enum ep_state state, uint8_t *buf, int handle_setup(const struct setup_request *setup); int set_addr(uint8_t addr); +void usb_reset(void); void usb_init(void); void usb_poll(void);