mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 14:10:37 +02:00
atusb/fw/: added transition from runtime to DFU mode according to DFU spec
- descr.c (config_descriptor): added DFU interface descriptor - ep0.c (my_dfu_setup, my_set_interface, ep0_init): added DFU interface switching - ep0.c (my_reset, ep0_init): CPU-reset (into boot loader) on USB bus reset when in appDETACH - Makefile (OBJS): added dfu_common.o
This commit is contained in:
parent
5f50611735
commit
2d7ee91430
@ -31,7 +31,8 @@ SIZE = $(AVR_PREFIX)size
|
||||
USB_ID = 20b7:1540
|
||||
|
||||
USB_OBJS = usb.o atu2.o
|
||||
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o $(USB_OBJS)
|
||||
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o dfu_common.o \
|
||||
$(USB_OBJS)
|
||||
BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o dfu_common.o \
|
||||
$(USB_OBJS)
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
|
||||
#include "usb.h"
|
||||
#include "dfu.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
@ -55,9 +56,9 @@ const uint8_t config_descriptor[] = {
|
||||
#if 0
|
||||
LE(9+9+7+7), /* wTotalLength */
|
||||
#else
|
||||
LE(9+9), /* wTotalLength */
|
||||
LE(9+9+9), /* wTotalLength */
|
||||
#endif
|
||||
1, /* bNumInterfaces */
|
||||
2, /* bNumInterfaces */
|
||||
1, /* bConfigurationValue (> 0 !) */
|
||||
0, /* iConfiguration */
|
||||
USB_ATTR_BUS_POWERED, /* bmAttributes */
|
||||
@ -98,4 +99,8 @@ const uint8_t config_descriptor[] = {
|
||||
LE(EP1_SIZE), /* wMaxPacketSize */
|
||||
0, /* bInterval */
|
||||
#endif
|
||||
|
||||
/* Interface #1 */
|
||||
|
||||
DFU_ITF_DESCR(1, dfu_proto_runtime)
|
||||
};
|
||||
|
@ -21,11 +21,13 @@
|
||||
#endif
|
||||
|
||||
#include "usb.h"
|
||||
#include "dfu.h"
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atusb/ep0.h"
|
||||
#include "version.h"
|
||||
#include "board.h"
|
||||
#include "sernum.h"
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
@ -207,7 +209,43 @@ static int my_setup(const struct setup_request *setup)
|
||||
}
|
||||
|
||||
|
||||
static int my_dfu_setup(const struct setup_request *setup)
|
||||
{
|
||||
switch (setup->bmRequestType | setup->bRequest << 8) {
|
||||
case DFU_TO_DEV(DFU_DETACH):
|
||||
/* @@@ should use wTimeout */
|
||||
dfu.state = appDETACH;
|
||||
return 1;
|
||||
default:
|
||||
return dfu_setup_common(setup);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void my_set_interface(int nth)
|
||||
{
|
||||
if (nth) {
|
||||
user_setup = my_dfu_setup;
|
||||
user_get_descriptor = dfu_my_descr;
|
||||
dfu.state = appIDLE;
|
||||
} else {
|
||||
user_setup = my_setup;
|
||||
user_get_descriptor = sernum_get_descr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void my_reset(void)
|
||||
{
|
||||
if (dfu.state == appDETACH)
|
||||
reset_cpu();
|
||||
}
|
||||
|
||||
|
||||
void ep0_init(void)
|
||||
{
|
||||
user_setup = my_setup;
|
||||
user_set_interface = my_set_interface;
|
||||
my_set_interface(0);
|
||||
user_reset = my_reset;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user