summaryrefslogtreecommitdiffstats
path: root/app/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/usb.c')
-rw-r--r--app/usb.c63
1 files changed, 48 insertions, 15 deletions
diff --git a/app/usb.c b/app/usb.c
index 053f126..ea432ef 100644
--- a/app/usb.c
+++ b/app/usb.c
@@ -13,12 +13,12 @@ static const struct usb_device_descriptor dev = {
.bLength = USB_DT_DEVICE_SIZE,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0200,
- .bDeviceClass = USB_CLASS_CDC,
- .bDeviceSubClass = 0,
- .bDeviceProtocol = 0,
+ .bDeviceClass = 0xef,
+ .bDeviceSubClass = 0x02,
+ .bDeviceProtocol = 0x01,
.bMaxPacketSize0 = 64,
- .idVendor = ID_VENDOR,
- .idProduct = ID_PRODUCT,
+ .idVendor = 0x0483,
+ .idProduct = 0xff03,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
@@ -30,15 +30,22 @@ static const struct usb_device_descriptor dev = {
static const struct usb_interface ifaces[] = {
{
.num_altsetting = 1,
- .altsetting = &comm_iface,
+ .altsetting = &dummy_kb_iface,
+ .iface_assoc = &dummy_kb_iface_assoc,
},
{
.num_altsetting = 1,
- .altsetting = &data_iface,
+ .altsetting = &dfu_iface,
+ .iface_assoc = &dfu_iface_assoc,
},
{
.num_altsetting = 1,
- .altsetting = &dfu_iface,
+ .altsetting = &comm_iface,
+ .iface_assoc = &cdc_iface_assoc,
+ },
+ {
+ .num_altsetting = 1,
+ .altsetting = &data_iface,
},
};
@@ -46,7 +53,7 @@ static const struct usb_config_descriptor config = {
.bLength = USB_DT_CONFIGURATION_SIZE,
.bDescriptorType = USB_DT_CONFIGURATION,
.wTotalLength = 0,
- .bNumInterfaces = 3,
+ .bNumInterfaces = 4,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0x80,
@@ -55,10 +62,12 @@ static const struct usb_config_descriptor config = {
};
static const char *usb_strings[] = {
- VENDOR_NAME,
- PRODUCT_NAME,
- SERIAL_NUMBER,
- "DFU",
+ VENDOR_NAME, /*1*/
+ PRODUCT_NAME, /*2*/
+ SERIAL_NUMBER, /*3*/
+ "dummy device", /*4*/
+ "Dfu iface", /*5*/
+ "Clock iface", /*6*/
};
void otg_fs_isr (void)
@@ -67,6 +76,30 @@ void otg_fs_isr (void)
}
+static int control_request (usbd_device *usbd_dev,
+ struct usb_setup_data *req,
+ uint8_t **buf,
+ uint16_t *len,
+ usbd_control_complete_callback *complete)
+{
+ if (dfu_control_request (usbd_dev, req, buf, len, complete))
+ return 1;
+
+ return cdcacm_control_request (usbd_dev, req, buf, len, complete);
+}
+
+static void set_config (usbd_device *usbd_dev, uint16_t wValue)
+{
+
+ cdcacm_set_config (usbd_dev, wValue);
+
+ usbd_register_control_callback (usbd_dev,
+ USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
+ USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
+ control_request);
+
+}
+
void usb_init (void)
@@ -79,7 +112,7 @@ void usb_init (void)
&dev,
&config,
usb_strings,
- 4,
+ 6,
usbd_control_buffer,
sizeof (usbd_control_buffer));
@@ -89,7 +122,7 @@ void usb_init (void)
OTG_FS_GCCFG &= ~OTG_GCCFG_VBUSASEN;
OTG_FS_GCCFG &= ~OTG_GCCFG_VBUSBSEN;
- usbd_register_set_config_callback (usb_device, cdcacm_set_config);
+ usbd_register_set_config_callback (usb_device, set_config);
nvic_enable_irq (NVIC_OTG_FS_IRQ);