From b04583a1247332c6009322e46bb426914f172d4a Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 17 May 2015 20:12:29 +0200 Subject: [PATCH] RoCoN: USB CDC ACM target for command processor implemented. The support is based on new USB CDC ACM implementation. Signed-off-by: Pavel Pisa --- sw/app/rocon/Makefile.omk | 2 +- sw/app/rocon/appl_usb.c | 91 ++++++++++++++++---------- sw/app/rocon/usb/usb_defs.h | 123 ++++++++++++++++++++++++++++-------- sw/config.omk | 1 + 4 files changed, 156 insertions(+), 61 deletions(-) diff --git a/sw/app/rocon/Makefile.omk b/sw/app/rocon/Makefile.omk index 201eaab..df5bf0c 100644 --- a/sw/app/rocon/Makefile.omk +++ b/sw/app/rocon/Makefile.omk @@ -143,7 +143,7 @@ rocon_SOURCES += appl_usb.c ifeq ($(CONFIG_LIB_U2U_V2),y) lib_LOADLIBES += u2u_dcnv endif -lib_LOADLIBES += usbbase usbmore +lib_LOADLIBES += usbcdc usbbase usbmore ifeq ($(CONFIG_USB_LPCUSB),y) lib_LOADLIBES += lpcusb endif diff --git a/sw/app/rocon/appl_usb.c b/sw/app/rocon/appl_usb.c index 1bdc8b0..d87fe15 100644 --- a/sw/app/rocon/appl_usb.c +++ b/sw/app/rocon/appl_usb.c @@ -68,15 +68,23 @@ usb_device_t usb_device; usb_ep_t eps[NUM_ENDPOINTS]; -#define MASK_EP1RX 0x01 -#define MASK_EP1TX 0x02 - -unsigned char ep1_rx_buff[USB_MAX_PACKET] __attribute__ ((aligned (8))); -unsigned char ep1_tx_buff[USB_MAX_PACKET] __attribute__ ((aligned (8))); +#define CDC0_EPIDX_NOTIFY 0 +#define CDC0_EPIDX_RXD 1 +#define CDC0_EPIDX_TXD 2 +#define CDC0_MASK_EP_NOTIFY (1<= ep1_tx_chars) + if (cdc0_rx_index >= cdc0_rx_chars) return -1; - return ep1_tx_buff[ep1_tx_index++]; + return cdc0_ep_rx_buff[cdc0_rx_index++]; } int cmd_io_putc_usbcon(struct cmd_io *cmd_io, int ch) { - if (ep1_rx_index >= USB_MAX_PACKET) + if (cdc0_tx_index >= USB_MAX_PACKET) { /* Check EP1 status and return -1 if unavailable */ usb_check_events(&usb_device); - usb_check_ep1(); + cdc0_txd_check_ep(); /* Check again if it wasn't emptied */ - if (ep1_rx_index >= USB_MAX_PACKET) + if (cdc0_tx_index >= USB_MAX_PACKET) return -1; } - ep1_rx_buff[ep1_rx_index++] = (unsigned char)ch; + cdc0_ep_tx_buff[cdc0_tx_index++] = (unsigned char)ch; return ch; } diff --git a/sw/app/rocon/usb/usb_defs.h b/sw/app/rocon/usb/usb_defs.h index 01042c6..0fbf6a3 100644 --- a/sw/app/rocon/usb/usb_defs.h +++ b/sw/app/rocon/usb/usb_defs.h @@ -3,6 +3,7 @@ #define USB_DEFS_MODULE #include +#include #include #include #include @@ -27,18 +28,31 @@ #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 */ { @@ -211,7 +283,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 = @@ -223,7 +296,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 */ diff --git a/sw/config.omk b/sw/config.omk index 75313bf..fa65c81 100644 --- a/sw/config.omk +++ b/sw/config.omk @@ -38,6 +38,7 @@ CONFIG_OC_MTD_DRV_SYSLESS=y CONFIG_USB_BASE=y CONFIG_USB_LPCUSB=y CONFIG_USB_MORE=y +CONFIG_USB_CDC=y CONFIG_APP_ROCON_WITH_USB=y CONFIG_LIB_U2U_V2=n -- 2.39.2