From b063a2da3024a2e3175e1ba9b0a87cb6c7470765 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Aug 2016 14:04:59 +0100 Subject: candlestick --- app/usb.c | 61 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'app/usb.c') diff --git a/app/usb.c b/app/usb.c index 9a84389..2bd6986 100644 --- a/app/usb.c +++ b/app/usb.c @@ -10,7 +10,7 @@ const struct usb_device_descriptor dev = { .bDeviceProtocol = 0, .bMaxPacketSize0 = 64, .idVendor = 0x1d6b, - .idProduct = 0x1932, + .idProduct = 0xcad5, .bcdDevice = 0x0200, .iManufacturer = 1, .iProduct = 2, @@ -20,9 +20,13 @@ const struct usb_device_descriptor dev = { const struct usb_interface ifaces[] = { { - .num_altsetting = 1, - .altsetting = &keyboard_iface, - }, + .num_altsetting = 1, + .altsetting = comm_iface, + }, + { + .num_altsetting = 1, + .altsetting = data_iface, +}, { .num_altsetting = 1, .altsetting = &dfu_iface, @@ -33,23 +37,22 @@ const struct usb_config_descriptor config = { .bLength = USB_DT_CONFIGURATION_SIZE, .bDescriptorType = USB_DT_CONFIGURATION, .wTotalLength = 0, - .bNumInterfaces = 2, + .bNumInterfaces = 3, .bConfigurationValue = 1, .iConfiguration = 4, .bmAttributes = 0xa0, .bMaxPower = 0x31, - .interface = ifaces, }; static const char *usb_strings[] = { - "bootpad", - "bootpad", - "bootpad", + "candlestick", + "candlestick", + "candlestick", "composite", - "bootpad keyboard", - "bootpad control", - "bootpad dfu device", + "usb serial 0", + "usb serial 1", + "candlestick dfu device", }; @@ -127,6 +130,8 @@ usb_control_request (usbd_device * usbd_dev, struct usb_setup_data *req, (void) complete; (void) usbd_dev; + (void) buf; + (void) len; if ((req->bmRequestType != @@ -134,25 +139,32 @@ usb_control_request (usbd_device * usbd_dev, struct usb_setup_data *req, || (req->bRequest != USB_REQ_GET_DESCRIPTOR) || (req->wValue != 0x2200)) return 0; - switch (req->wIndex) - { - case 0: - keyboard_get_descriptor (buf, len); - return 1; - } - *len = 0; return 0; } +int +class_control_request (usbd_device * usbd_dev, struct usb_setup_data *req, + uint8_t ** buf, uint16_t * len, + int (**complete) (usbd_device * usbd_dev, + struct usb_setup_data * req)) +{ + + if (cdcacm_control_request(usbd_dev,req,buf,len,complete)) return 1; + if (dfu_control_request(usbd_dev,req,buf,len,complete)) return 1; + return 0; +} + void usb_set_config (usbd_device * usbd_dev, uint16_t wValue) { (void) wValue; (void) usbd_dev; - usbd_ep_setup (usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL); + usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb); + usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL); + usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); usbd_register_control_callback (usbd_dev, USB_REQ_TYPE_STANDARD | @@ -163,18 +175,14 @@ usb_set_config (usbd_device * usbd_dev, uint16_t wValue) usbd_register_control_callback (usbd_dev, USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - dfu_control_request); + class_control_request); - usbd_register_control_callback (usbd_dev, - USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - vendor_control_request); } /* Buffer to be used for control requests. */ -static uint8_t usbd_control_buffer[128]; +uint8_t usbd_control_buffer[128]; void usb_init (void) @@ -197,6 +205,5 @@ usb_run (void) for (;;) { usbd_poll (usbd_dev); - crypto_poll (); } } -- cgit v1.2.3