175 lines
5.9 KiB
C
175 lines
5.9 KiB
C
/*
|
|
* Copyright (c) 2017, Alex Taradov <alex@taradov.com>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
|
|
/*- Includes ----------------------------------------------------------------*/
|
|
#include <stdalign.h>
|
|
#include "usb.h"
|
|
#include "usb_descriptors.h"
|
|
|
|
/*- Variables ---------------------------------------------------------------*/
|
|
const alignas(4) usb_device_descriptor_t usb_device_descriptor =
|
|
{
|
|
.bLength = sizeof(usb_device_descriptor_t),
|
|
.bDescriptorType = USB_DEVICE_DESCRIPTOR,
|
|
.bcdUSB = 0x0110,
|
|
.bDeviceClass = USB_CDC_DEVICE_CLASS,
|
|
.bDeviceSubClass = 0,
|
|
.bDeviceProtocol = 0,
|
|
.bMaxPacketSize0 = 64,
|
|
.idVendor = 0x1d50,
|
|
.idProduct = 0x6142,
|
|
.bcdDevice = 0x0100,
|
|
.iManufacturer = USB_STR_MANUFACTURER,
|
|
.iProduct = USB_STR_PRODUCT,
|
|
.iSerialNumber = USB_STR_SERIAL_NUMBER,
|
|
.bNumConfigurations = 1,
|
|
};
|
|
|
|
const alignas(4) usb_configuration_hierarchy_t usb_configuration_hierarchy =
|
|
{
|
|
.configuration =
|
|
{
|
|
.bLength = sizeof(usb_configuration_descriptor_t),
|
|
.bDescriptorType = USB_CONFIGURATION_DESCRIPTOR,
|
|
.wTotalLength = sizeof(usb_configuration_hierarchy_t),
|
|
.bNumInterfaces = 2,
|
|
.bConfigurationValue = 1,
|
|
.iConfiguration = 0,
|
|
.bmAttributes = 0x80,
|
|
.bMaxPower = 100, // 200 mA
|
|
},
|
|
|
|
.interface_comm =
|
|
{
|
|
.bLength = sizeof(usb_interface_descriptor_t),
|
|
.bDescriptorType = USB_INTERFACE_DESCRIPTOR,
|
|
.bInterfaceNumber = 0,
|
|
.bAlternateSetting = 0,
|
|
.bNumEndpoints = 1,
|
|
.bInterfaceClass = USB_CDC_COMM_CLASS,
|
|
.bInterfaceSubClass = USB_CDC_ACM_SUBCLASS,
|
|
.bInterfaceProtocol = 0,
|
|
.iInterface = 0,
|
|
},
|
|
|
|
.cdc_header =
|
|
{
|
|
.bFunctionalLength = sizeof(usb_cdc_header_functional_descriptor_t),
|
|
.bDescriptorType = USB_CS_INTERFACE_DESCRIPTOR,
|
|
.bDescriptorSubtype = USB_CDC_HEADER_SUBTYPE,
|
|
.bcdCDC = 0x0110,
|
|
},
|
|
|
|
.cdc_acm =
|
|
{
|
|
.bFunctionalLength = sizeof(usb_cdc_abstract_control_managment_descriptor_t),
|
|
.bDescriptorType = USB_CS_INTERFACE_DESCRIPTOR,
|
|
.bDescriptorSubtype = USB_CDC_ACM_SUBTYPE,
|
|
.bmCapabilities = USB_CDC_ACM_SUPPORT_LINE_REQUESTS,
|
|
},
|
|
|
|
.cdc_call_mgmt =
|
|
{
|
|
.bFunctionalLength = sizeof(usb_cdc_call_managment_functional_descriptor_t),
|
|
.bDescriptorType = USB_CS_INTERFACE_DESCRIPTOR,
|
|
.bDescriptorSubtype = USB_CDC_CALL_MGMT_SUBTYPE,
|
|
.bmCapabilities = USB_CDC_CALL_MGMT_OVER_DCI,
|
|
.bDataInterface = 1,
|
|
},
|
|
|
|
.cdc_union =
|
|
{
|
|
.bFunctionalLength = sizeof(usb_cdc_union_functional_descriptor_t),
|
|
.bDescriptorType = USB_CS_INTERFACE_DESCRIPTOR,
|
|
.bDescriptorSubtype = USB_CDC_UNION_SUBTYPE,
|
|
.bMasterInterface = 0,
|
|
.bSlaveInterface0 = 1,
|
|
},
|
|
|
|
.ep_comm =
|
|
{
|
|
.bLength = sizeof(usb_endpoint_descriptor_t),
|
|
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR,
|
|
.bEndpointAddress = USB_IN_ENDPOINT | USB_CDC_EP_COMM,
|
|
.bmAttributes = USB_INTERRUPT_ENDPOINT,
|
|
.wMaxPacketSize = 64,
|
|
.bInterval = 1,
|
|
},
|
|
|
|
.interface_data =
|
|
{
|
|
.bLength = sizeof(usb_interface_descriptor_t),
|
|
.bDescriptorType = USB_INTERFACE_DESCRIPTOR,
|
|
.bInterfaceNumber = 1,
|
|
.bAlternateSetting = 0,
|
|
.bNumEndpoints = 2,
|
|
.bInterfaceClass = USB_CDC_DATA_CLASS,
|
|
.bInterfaceSubClass = 0,
|
|
.bInterfaceProtocol = 0,
|
|
.iInterface = 0,
|
|
},
|
|
|
|
.ep_in =
|
|
{
|
|
.bLength = sizeof(usb_endpoint_descriptor_t),
|
|
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR,
|
|
.bEndpointAddress = USB_IN_ENDPOINT | USB_CDC_EP_SEND,
|
|
.bmAttributes = USB_BULK_ENDPOINT,
|
|
.wMaxPacketSize = 64,
|
|
.bInterval = 0,
|
|
},
|
|
|
|
.ep_out =
|
|
{
|
|
.bLength = sizeof(usb_endpoint_descriptor_t),
|
|
.bDescriptorType = USB_ENDPOINT_DESCRIPTOR,
|
|
.bEndpointAddress = USB_OUT_ENDPOINT | USB_CDC_EP_RECV,
|
|
.bmAttributes = USB_BULK_ENDPOINT,
|
|
.wMaxPacketSize = 64,
|
|
.bInterval = 0,
|
|
},
|
|
};
|
|
|
|
const alignas(4) usb_string_descriptor_zero_t usb_string_descriptor_zero =
|
|
{
|
|
.bLength = sizeof(usb_string_descriptor_zero_t),
|
|
.bDescriptorType = USB_STRING_DESCRIPTOR,
|
|
.wLANGID = 0x0409, // English (United States)
|
|
};
|
|
|
|
char usb_serial_number[16];
|
|
|
|
const char *usb_strings[] =
|
|
{
|
|
[USB_STR_MANUFACTURER] = "sysmocom - s.f.m.c. GmbH",
|
|
[USB_STR_PRODUCT] = "osmo-clock-generator",
|
|
[USB_STR_SERIAL_NUMBER] = usb_serial_number,
|
|
};
|
|
|