]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blobdiff - sw/app/lx_dad/usb/usb_defs.h
USB CDC ACM target for command processor implemented.
[fpga/lx-cpu1/lx-dad.git] / sw / app / lx_dad / usb / usb_defs.h
index c960fd05920c909ad61cbec12d7f8a350fb034dd..eecc8de88ac5bc8b0e81e2bcea0a37b13b11c41e 100644 (file)
@@ -3,6 +3,7 @@
 #define USB_DEFS_MODULE
 
 #include <usb/usb_spec.h>
+#include <usb/usb_cdc.h>
 #include <usb/lpcusb.h>
 #include <endian.h>
 #include <cpu_def.h>
 #define USB_RELEASE_VER    0x0100
 
 /*** Class codes for device description ***/
-#define USB_CLASS_CODE      0xFF
+#define USB_CLASS_CODE      USB_DEVICE_CLASS_COMMUNICATIONS
 #define USB_SUBCLASS_CODE   0x00
 #define USB_PROTOCOL_CODE   0x00
 
-#define NUM_ENDPOINTS       2
+#define NUM_ENDPOINTS       3
+#define CDC0_EP_NOTIFY      0x81
+#define CDC0_EP_RXD         0x02
+#define CDC0_EP_TXD         0x82
+
+#define CONFIG_DESCRIPTOR_LENGTH \
+  sizeof(USB_CONFIGURATION_DESCRIPTOR) \
+   + sizeof(USB_INTERFACE_DESCRIPTOR) \
+   + sizeof(USBCDC_HEADER_FCN_DESCRIPTOR) \
+   + sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR) \
+   + sizeof(USBCDC_ACM_FCN_DESCRIPTOR) \
+   + sizeof(USBCDC_UNION_FCN_DESCRIPTOR) \
+   + sizeof(USB_INTERFACE_DESCRIPTOR) \
+   + (NUM_ENDPOINTS*sizeof(USB_ENDPOINT_DESCRIPTOR))
 
 /*** Device descriptor ***/
 CODE const USB_DEVICE_DESCRIPTOR DeviceDescription =
 {
   sizeof(USB_DEVICE_DESCRIPTOR),
   USB_DESCRIPTOR_TYPE_DEVICE,
-  SWAP(0x0100),
+  SWAP(0x0120),
   USB_CLASS_CODE,
   USB_SUBCLASS_CODE,
   USB_PROTOCOL_CODE,
@@ -49,60 +63,118 @@ CODE const USB_DEVICE_DESCRIPTOR DeviceDescription =
   1, /* manufacturer string ID */
   2, /* product string ID */
   3, /* serial number string ID */
-  1
+  1  /* bNumConfigs */
 };
 
 /*** All In Configuration 0 ***/
 CODE const struct
 {
   USB_CONFIGURATION_DESCRIPTOR configuration;
-  USB_INTERFACE_DESCRIPTOR interface;
-  USB_ENDPOINT_DESCRIPTOR endpoint_tx;
-  USB_ENDPOINT_DESCRIPTOR endpoint_rx;
-} ConfigDescription =
+  USB_INTERFACE_DESCRIPTOR        iface_comm;
+  USBCDC_HEADER_FCN_DESCRIPTOR    cdcheader;
+  USBCDC_CALLMGMT_FCN_DESCRIPTOR  cdccallmgt;
+  USBCDC_ACM_FCN_DESCRIPTOR       cdcacm;
+  USBCDC_UNION_FCN_DESCRIPTOR     cdcunion;
+  USB_ENDPOINT_DESCRIPTOR         ep_notification;
+  USB_INTERFACE_DESCRIPTOR        iface_data;
+  USB_ENDPOINT_DESCRIPTOR         ep_rxd;
+  USB_ENDPOINT_DESCRIPTOR         ep_txd;
+} PACKED ConfigDescription =
 {
-  /*** Configuration descriptor ***/
   {
+    /*** Configuration descriptor ***/
     sizeof(USB_CONFIGURATION_DESCRIPTOR),
     USB_DESCRIPTOR_TYPE_CONFIGURATION,
-    sizeof(ConfigDescription),
-    1, /* cnt of interfaces */
+    SWAP(CONFIG_DESCRIPTOR_LENGTH),
+    2, /* cnt of interfaces */
     1, /* this configuration ID */
     4, /* config.name string ID */
-    0x80, /* cfg, in spec is, taha bit 7 must be set to one -> 0xe0 , orig 0x60*/
+    USB_CONFIG_BUS_POWERED, /* CbmAttributes (bus powered) */
     250    /* device power current from host 500mA / 2 */
   },
-  /*** Interface Descriptor ***/
   {
+    /*** Interface Descriptor ***/
     sizeof(USB_INTERFACE_DESCRIPTOR),
     USB_DESCRIPTOR_TYPE_INTERFACE,
     0,    /* index of this interface for SetInterface request */
     0,    /* ID alternate interface */
-    NUM_ENDPOINTS,
-    USB_CLASS_CODE,
-    USB_SUBCLASS_CODE,
-    USB_PROTOCOL_CODE,
+    1,    /* number of endpoints in interface */
+    USB_DEVICE_CLASS_COMMUNICATIONS,
+    USBCDC_COM_IFACE_SUBCLS_ACM,
+    0,    /* protocol */
     5
   },
-  /*** Endpoint 1 - Rx,Bulk ***/
   {
+    /*** CDC Header Descriptor ***/
+    sizeof(USBCDC_HEADER_FCN_DESCRIPTOR),
+    USBCDC_COM_FCN_TYPE_CS_INTERFACE,
+    USBCDC_COM_FCN_SUBTYPE_HEADER,    /* bDescriptorSubtype */
+    SWAP(0x0120),                     /* bcdCDC (spec. release 1.2) */
+  },
+  {
+    /*** CDC CALL MANAGEMENT Descriptor ***/
+    sizeof(USBCDC_CALLMGMT_FCN_DESCRIPTOR),
+    USBCDC_COM_FCN_TYPE_CS_INTERFACE,
+    USBCDC_COM_FCN_SUBTYPE_CALLMGMT,
+    0,
+    1,
+  },
+  {
+    /*** CDC ABSTRACT CONTROL MANAGEMENT Descriptor ***/
+    sizeof(USBCDC_ACM_FCN_DESCRIPTOR),
+    USBCDC_COM_FCN_TYPE_CS_INTERFACE,
+    USBCDC_COM_FCN_SUBTYPE_ACMGMT,
+    USBCDC_ACM_FCN_CAP_SUPPORT_LINECTRL,
+  },
+  {
+    /*** CDC UNION Descriptor ***/
+    sizeof(USBCDC_UNION_FCN_DESCRIPTOR),
+    USBCDC_COM_FCN_TYPE_CS_INTERFACE,
+    USBCDC_COM_FCN_SUBTYPE_UNION,
+    0,
+    1,
+  },
+  {
+    /*** Endpoint 1 IN, type interrupt ***/
     sizeof(USB_ENDPOINT_DESCRIPTOR),
     USB_DESCRIPTOR_TYPE_ENDPOINT,
-    0x81,
+    CDC0_EP_NOTIFY,                   /* bEndpointAddress */
+    USB_ENDPOINT_TYPE_INTERRUPT,
+    SWAP(USB_MAX_PACKET),
+    0x80,                             /* bInterval (polling interval: 50ms) */
+  },
+  {
+    /*** Interface Descriptor ***/
+    sizeof(USB_INTERFACE_DESCRIPTOR),
+    USB_DESCRIPTOR_TYPE_INTERFACE,
+    1,                                /* bInterfaceNumber */
+    0,                                /* bAlternateSetting */
+    2,                                /* number of EPs */
+    USB_DEVICE_CLASS_CDC_DATA,        /* bInterfaceClass */
+    0,                                /* bInterfaceSubclass */
+    0,                                /* bDeviceProtocol */
+    0,                                /* iInterface (string, 0=none) */
+  },
+  {
+    /*** Endpoint 2 OUT, type bulk ***/
+    sizeof(USB_ENDPOINT_DESCRIPTOR),
+    USB_DESCRIPTOR_TYPE_ENDPOINT,
+    CDC0_EP_RXD,                      /* bEndpointAddress */
     USB_ENDPOINT_TYPE_BULK,
     SWAP(USB_MAX_PACKET),
-    0
+    0,                                /* bInterval (polling interval: 50ms) */
   },
-  /*** Endpoint 1 - Tx,Bulk ***/
   {
+    /*** Endpoint 2 IN, type bulk ***/
     sizeof(USB_ENDPOINT_DESCRIPTOR),
     USB_DESCRIPTOR_TYPE_ENDPOINT,
-    0x01,
+    CDC0_EP_TXD,                      /* bEndpointAddress */
     USB_ENDPOINT_TYPE_BULK,
     SWAP(USB_MAX_PACKET),
-    0
+    0,                                /* bInterval (polling interval: 50ms) */
   }
 };
+
 /*** Strings - in unicode ***/
 CODE const char Str0Desc[] =    /* supported languages of strings */
 {
@@ -212,7 +284,8 @@ CODE const USB_DEVICE_CONFIGURATION_ENTRY usb_devdes_configurations[] =
 
 CODE const USB_INTERFACE_DESCRIPTOR *usb_devdes_interfaces[] =
 {
-  &ConfigDescription.interface
+  &ConfigDescription.iface_comm,
+  &ConfigDescription.iface_data
 };
 
 CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table =
@@ -224,7 +297,7 @@ CODE const USB_DEVICE_DESCRIPTORS_TABLE usb_devdes_table =
   .iNumStrings = CNT_STRINGS,
   .bNumEndpoints = NUM_ENDPOINTS,
   .bNumConfigurations = 1,
-  .bNumInterfaces = 1
+  .bNumInterfaces = 2
 };
 
 #endif /* USB_DEFS_MODULE */