summaryrefslogtreecommitdiff
path: root/ucoo/hal/usb
diff options
context:
space:
mode:
authorNicolas Schodet2015-06-03 13:46:44 +0200
committerNicolas Schodet2019-10-07 00:44:44 +0200
commit574480980dcffbfa7cd6dbe71e88253eb4c9feba (patch)
tree5f1c1261341a7c2a56de01d8c6d0815b164be8ba /ucoo/hal/usb
parentd415a0646e874848cd06482c5d57916cca5cff4a (diff)
Rename ucoolib modules directory from ucoolib to ucoo
Diffstat (limited to 'ucoo/hal/usb')
-rw-r--r--ucoo/hal/usb/Config12
-rw-r--r--ucoo/hal/usb/Module1
-rw-r--r--ucoo/hal/usb/test/Config2
-rw-r--r--ucoo/hal/usb/test/Makefile9
-rw-r--r--ucoo/hal/usb/test/test_usb.cc73
-rw-r--r--ucoo/hal/usb/usb.hh33
-rw-r--r--ucoo/hal/usb/usb.stm32.cc160
-rw-r--r--ucoo/hal/usb/usb.stm32.hh98
-rw-r--r--ucoo/hal/usb/usb_desc.stm32.c193
-rw-r--r--ucoo/hal/usb/usb_desc.stm32.h33
10 files changed, 614 insertions, 0 deletions
diff --git a/ucoo/hal/usb/Config b/ucoo/hal/usb/Config
new file mode 100644
index 0000000..9adaece
--- /dev/null
+++ b/ucoo/hal/usb/Config
@@ -0,0 +1,12 @@
+[hal/usb]
+# Theses are APBTeam IDs, given by Openmoko!
+vendor_id = 0x1d50
+product_id = 0x6052
+# Number of streams, interfaces, or pair of endpoints.
+stream_nb = 1
+# Set to 0 if powered from USB cable, 1 if device has its own power supply.
+self_powered = 0
+# Maximum power consumed from USB cable (mA).
+max_power = 100
+# End point size, you should use 64.
+ep_size = 64
diff --git a/ucoo/hal/usb/Module b/ucoo/hal/usb/Module
new file mode 100644
index 0000000..433c8b2
--- /dev/null
+++ b/ucoo/hal/usb/Module
@@ -0,0 +1 @@
+hal_usb_SOURCES = usb.stm32.cc usb_desc.stm32.c
diff --git a/ucoo/hal/usb/test/Config b/ucoo/hal/usb/test/Config
new file mode 100644
index 0000000..49b2f0b
--- /dev/null
+++ b/ucoo/hal/usb/test/Config
@@ -0,0 +1,2 @@
+[hal/usb]
+stream_nb = 1
diff --git a/ucoo/hal/usb/test/Makefile b/ucoo/hal/usb/test/Makefile
new file mode 100644
index 0000000..cec9ded
--- /dev/null
+++ b/ucoo/hal/usb/test/Makefile
@@ -0,0 +1,9 @@
+BASE = ../../../..
+
+TARGETS = stm32f4
+stm32f4_PROGS = test_usb
+test_usb_SOURCES = test_usb.cc
+
+MODULES = hal/usb
+
+include $(BASE)/build/top.mk
diff --git a/ucoo/hal/usb/test/test_usb.cc b/ucoo/hal/usb/test/test_usb.cc
new file mode 100644
index 0000000..a1fe362
--- /dev/null
+++ b/ucoo/hal/usb/test/test_usb.cc
@@ -0,0 +1,73 @@
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// }}}
+#include "ucoo/hal/usb/usb.hh"
+#include "ucoo/arch/arch.hh"
+
+int
+main (int argc, const char **argv)
+{
+ ucoo::arch_init (argc, argv);
+ ucoo::UsbStreamControl usc ("APBTeam", "USB test");
+ ucoo::UsbStream us[] = {
+ ucoo::UsbStream (usc, 0),
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+ ucoo::UsbStream (usc, 1),
+#endif
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+ ucoo::UsbStream (usc, 2),
+#endif
+ };
+ if (UCOO_CONFIG_HAL_USB_STREAM_NB > 1)
+ {
+ for (int i = 0; i < UCOO_CONFIG_HAL_USB_STREAM_NB; i++)
+ us[i].block (false);
+ }
+ char buf[6];
+ while (1)
+ {
+ for (int i = 0; i < UCOO_CONFIG_HAL_USB_STREAM_NB; i++)
+ {
+ int len = us[i].read (buf + 2, sizeof (buf) - 2);
+ if (len)
+ {
+ buf[0] = i + '0';
+ buf[1] = '>';
+ len += 2;
+ if (UCOO_CONFIG_HAL_USB_STREAM_NB == 1)
+ us[i].write (buf, len);
+ else
+ {
+ const char *p = buf;
+ while (len)
+ {
+ int r = us[i].write (p, len);
+ p += r;
+ len -= r;
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/ucoo/hal/usb/usb.hh b/ucoo/hal/usb/usb.hh
new file mode 100644
index 0000000..5324058
--- /dev/null
+++ b/ucoo/hal/usb/usb.hh
@@ -0,0 +1,33 @@
+#ifndef ucoo_hal_usb_usb_hh
+#define ucoo_hal_usb_usb_hh
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// }}}
+
+#ifdef TARGET_stm32
+# include "usb.stm32.hh"
+#else
+# error "not implemented for this target"
+#endif
+
+#endif // ucoo_hal_usb_usb_hh
diff --git a/ucoo/hal/usb/usb.stm32.cc b/ucoo/hal/usb/usb.stm32.cc
new file mode 100644
index 0000000..0410df5
--- /dev/null
+++ b/ucoo/hal/usb/usb.stm32.cc
@@ -0,0 +1,160 @@
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// }}}
+#include "usb.stm32.hh"
+#include <algorithm>
+
+#include <libopencm3/stm32/f4/rcc.h>
+#include <libopencm3/stm32/f4/gpio.h>
+#include <libopencm3/cm3/nvic.h>
+
+#include "usb_desc.stm32.h"
+
+static usbd_device *usbdev;
+
+extern "C" {
+
+void
+otg_fs_isr ()
+{
+ usbd_poll (usbdev);
+}
+
+}
+
+namespace ucoo {
+
+UsbStreamControl *UsbStreamControl::instance_;
+
+const char *strings[] = {
+ NULL,
+ NULL
+};
+
+UsbStreamControl::RxBuffer::RxBuffer (void)
+ : size (0), offset (0)
+{
+}
+
+UsbStreamControl::UsbStreamControl (const char *vendor, const char *product)
+ : configured_ (false)
+{
+ assert (!instance_);
+ instance_ = this;
+ strings[0] = vendor;
+ strings[1] = product;
+ rcc_peripheral_enable_clock (&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
+ rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
+ gpio_mode_setup (GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
+ GPIO9 | GPIO11 | GPIO12);
+ gpio_set_af (GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
+ usbdev = usbd_init (&otgfs_usb_driver, &usb_desc_dev, &usb_desc_config,
+ strings, lengthof (strings));
+ usbd_register_set_config_callback (usbdev, set_config);
+ nvic_enable_irq (NVIC_OTG_FS_IRQ);
+}
+
+void
+UsbStreamControl::set_config (usbd_device *usbdev, uint16_t configured)
+{
+ instance_->configured_ = configured;
+ if (configured)
+ {
+ for (int i = 0; i < stream_nb_; i++)
+ {
+ usbd_ep_setup (usbdev, 0x01 + i, USB_ENDPOINT_ATTR_BULK, ep_size_,
+ rx_callback);
+ usbd_ep_setup (usbdev, 0x81 + i, USB_ENDPOINT_ATTR_BULK, ep_size_,
+ NULL);
+ }
+ }
+}
+
+void
+UsbStreamControl::rx_callback (usbd_device *usbdev, uint8_t ep)
+{
+ assert (ep > 0 && ep <= stream_nb_);
+ int num = ep - 1;
+ RxBuffer &rb = instance_->rx_buffer_[num];
+ assert (rb.size == 0 && rb.offset == 0);
+ usbd_ep_nak_set (usbdev, ep, 1);
+ rb.size = usbd_ep_read_packet (usbdev, ep, rb.buf, ep_size_);
+}
+
+UsbStream::UsbStream (UsbStreamControl &control, int num)
+ : control_ (control), num_ (num)
+{
+ assert (num < UsbStreamControl::stream_nb_);
+}
+
+int
+UsbStream::read (char *buf, int count)
+{
+ UsbStreamControl::RxBuffer &rb = control_.rx_buffer_[num_];
+ /* Wait for reception. */
+ if (!rb.size && !block_)
+ return 0;
+ while (!rb.size)
+ barrier ();
+ /* Copy to provided buffer. */
+ int len = std::min (count, rb.size - rb.offset);
+ buf = std::copy (rb.buf + rb.offset, rb.buf + rb.offset + len, buf);
+ rb.offset += len;
+ /* Reload buffer? */
+ if (rb.offset == rb.size)
+ {
+ rb.offset = rb.size = 0;
+ barrier ();
+ usbd_ep_nak_set (usbdev, num_ + 1, 0);
+ }
+ /* Done. */
+ return len;
+}
+
+int
+UsbStream::write (const char *buf, int count)
+{
+ int left = count;
+ while (left)
+ {
+ if (control_.configured_)
+ {
+ int len = std::min (left, UsbStreamControl::ep_size_);
+ len = usbd_ep_write_packet (usbdev, num_ + 0x81, buf, len);
+ buf += len;
+ left -= len;
+ }
+ if (!block_)
+ break;
+ }
+ return count - left;
+}
+
+int
+UsbStream::poll ()
+{
+ UsbStreamControl::RxBuffer &rb = control_.rx_buffer_[num_];
+ return rb.size - rb.offset;
+}
+
+} // namespace ucoo
diff --git a/ucoo/hal/usb/usb.stm32.hh b/ucoo/hal/usb/usb.stm32.hh
new file mode 100644
index 0000000..118e883
--- /dev/null
+++ b/ucoo/hal/usb/usb.stm32.hh
@@ -0,0 +1,98 @@
+#ifndef ucoo_hal_usb_usb_stm32_hh
+#define ucoo_hal_usb_usb_stm32_hh
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// }}}
+#include "ucoo/intf/stream.hh"
+#include "ucoo/common.hh"
+
+#include "config/hal/usb.hh"
+
+#include <libopencm3/usb/usbd.h>
+
+namespace ucoo {
+
+class UsbStream;
+
+/// Top control class for an USB device. This is a limited implementation
+/// which fulfill most of our needs: one or more interfaces, each of them is
+/// handled as a character stream. This should be instantiated only once.
+class UsbStreamControl
+{
+ public:
+ /// Construct a new USB control object, with given VENDOR and PRODUCT
+ /// strings.
+ UsbStreamControl (const char *vendor, const char *product);
+ /// Return true if the device is configured. This means that the
+ /// connection is done with the host and data can be exchanged.
+ bool is_configured () const { return configured_; }
+ private:
+ /// Called by USB stack when device is configured. This is expected to
+ /// setup endpoints.
+ static void set_config (usbd_device *usbdev, uint16_t wValue);
+ /// Called by USB stack when a frame is received on a OUT endpoint.
+ static void rx_callback (usbd_device *usbdev, uint8_t ep);
+ private:
+ /// Size of endpoints.
+ static const int ep_size_ = UCOO_CONFIG_HAL_USB_EP_SIZE;
+ /// Number of streams (also interfaces or pair of endpoints).
+ static const int stream_nb_ = UCOO_CONFIG_HAL_USB_STREAM_NB;
+ /// Pointer to the one and only instance.
+ static UsbStreamControl *instance_;
+ /// Whether device is currently configured.
+ bool configured_;
+ /// Internal RX buffer type.
+ struct RxBuffer
+ {
+ char buf[ep_size_];
+ int size, offset;
+ RxBuffer (void);
+ };
+ /// Internal RX buffer, one per stream.
+ RxBuffer rx_buffer_[stream_nb_];
+ friend class UsbStream;
+};
+
+/// One USB stream, instantiated for each stream, interface, or pair of
+/// endpoints.
+class UsbStream : public Stream
+{
+ public:
+ /// Construct from control object and stream index.
+ UsbStream (UsbStreamControl &control, int num);
+ /// See Stream::read.
+ int read (char *buf, int count);
+ /// See Stream::write.
+ int write (const char *buf, int count);
+ /// See Stream::poll.
+ int poll ();
+ private:
+ /// Reference to control object.
+ UsbStreamControl &control_;
+ /// Stream index.
+ int num_;
+};
+
+} // namespace ucoo
+
+#endif // ucoo_hal_usb_usb_stm32_hh
diff --git a/ucoo/hal/usb/usb_desc.stm32.c b/ucoo/hal/usb/usb_desc.stm32.c
new file mode 100644
index 0000000..8d6fc87
--- /dev/null
+++ b/ucoo/hal/usb/usb_desc.stm32.c
@@ -0,0 +1,193 @@
+/* ucoolib - Microcontroller object oriented library. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * }}} */
+#include "usb_desc.stm32.h"
+
+#include "config/hal/usb.hh"
+
+const struct usb_device_descriptor usb_desc_dev = {
+ .bLength = USB_DT_DEVICE_SIZE,
+ .bDescriptorType = USB_DT_DEVICE,
+ .bcdUSB = 0x0200,
+ .bDeviceClass = 0xff,
+ .bDeviceSubClass = 0,
+ .bDeviceProtocol = 0,
+ .bMaxPacketSize0 = 64,
+ .idVendor = UCOO_CONFIG_HAL_USB_VENDOR_ID,
+ .idProduct = UCOO_CONFIG_HAL_USB_PRODUCT_ID,
+ .bcdDevice = 0x0000,
+ .iManufacturer = 1,
+ .iProduct = 2,
+ .iSerialNumber = 0,
+ .bNumConfigurations = 1,
+};
+
+static const struct usb_endpoint_descriptor usb_desc_endp_1[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x01,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x81,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_1[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 0,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_1,
+ },
+};
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+
+static const struct usb_endpoint_descriptor usb_desc_endp_2[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x02,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x82,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_2[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 1,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_2,
+ },
+};
+
+#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 2 */
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+
+static const struct usb_endpoint_descriptor usb_desc_endp_3[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x03,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x83,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_3[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 2,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_3,
+ },
+};
+
+#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 3 */
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB > 3
+# error "too many streams requested"
+#endif
+
+static const struct usb_interface usb_desc_ifaces[] = {
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_1,
+ },
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_2,
+ },
+#endif
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_3,
+ },
+#endif
+};
+
+const struct usb_config_descriptor usb_desc_config = {
+ .bLength = USB_DT_CONFIGURATION_SIZE,
+ .bDescriptorType = USB_DT_CONFIGURATION,
+ .wTotalLength = 0,
+ .bNumInterfaces = UCOO_CONFIG_HAL_USB_STREAM_NB,
+ .bConfigurationValue = 1,
+ .iConfiguration = 0,
+ .bmAttributes = 0x80 | (UCOO_CONFIG_HAL_USB_SELF_POWERED ? 0x40 : 0),
+ .bMaxPower = UCOO_CONFIG_HAL_USB_MAX_POWER / 2,
+
+ .interface = usb_desc_ifaces,
+};
+
diff --git a/ucoo/hal/usb/usb_desc.stm32.h b/ucoo/hal/usb/usb_desc.stm32.h
new file mode 100644
index 0000000..dca84b7
--- /dev/null
+++ b/ucoo/hal/usb/usb_desc.stm32.h
@@ -0,0 +1,33 @@
+#ifndef ucoo_hal_usb_usb_desc_stm32_h
+#define ucoo_hal_usb_usb_desc_stm32_h
+/* ucoolib - Microcontroller object oriented library. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * }}} */
+#include <libopencm3/usb/usbstd.h>
+
+/** USB device descriptor. */
+extern const struct usb_device_descriptor usb_desc_dev;
+/** USB configuration descriptor. */
+extern const struct usb_config_descriptor usb_desc_config;
+
+#endif /* ucoo_hal_usb_usb_desc_stm32_h */