Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
cdcacm.h
00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 00002 00003 This software may be distributed and modified under the terms of the GNU 00004 General Public License version 2 (GPL2) as published by the Free Software 00005 Foundation and appearing in the file GPL2.TXT included in the packaging of 00006 this file. Please note that GPL2 Section 2[b] requires that all works based 00007 on this software must also be made publicly available under the terms of 00008 the GPL2 ("Copyleft"). 00009 00010 Contact information 00011 ------------------- 00012 00013 Circuits At Home, LTD 00014 Web : http://www.circuitsathome.com 00015 e-mail : support@circuitsathome.com 00016 */ 00017 #if !defined(__CDCACM_H__) 00018 #define __CDCACM_H__ 00019 00020 #include "Usb.h" 00021 00022 #define bmREQ_CDCOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE 00023 #define bmREQ_CDCIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE 00024 00025 // CDC Subclass Constants 00026 #define CDC_SUBCLASS_DLCM 0x01 // Direct Line Control Model 00027 #define CDC_SUBCLASS_ACM 0x02 // Abstract Control Model 00028 #define CDC_SUBCLASS_TCM 0x03 // Telephone Control Model 00029 #define CDC_SUBCLASS_MCCM 0x04 // Multi Channel Control Model 00030 #define CDC_SUBCLASS_CAPI 0x05 // CAPI Control Model 00031 #define CDC_SUBCLASS_ETHERNET 0x06 // Ethernet Network Control Model 00032 #define CDC_SUBCLASS_ATM 0x07 // ATM Network Control Model 00033 #define CDC_SUBCLASS_WIRELESS_HANDSET 0x08 // Wireless Handset Control Model 00034 #define CDC_SUBCLASS_DEVICE_MANAGEMENT 0x09 // Device Management 00035 #define CDC_SUBCLASS_MOBILE_DIRECT_LINE 0x0A // Mobile Direct Line Model 00036 #define CDC_SUBCLASS_OBEX 0x0B // OBEX 00037 #define CDC_SUBCLASS_ETHERNET_EMU 0x0C // Ethernet Emulation Model 00038 00039 // Communication Interface Class Control Protocol Codes 00040 #define CDC_PROTOCOL_ITU_T_V_250 0x01 // AT Commands defined by ITU-T V.250 00041 #define CDC_PROTOCOL_PCCA_101 0x02 // AT Commands defined by PCCA-101 00042 #define CDC_PROTOCOL_PCCA_101_O 0x03 // AT Commands defined by PCCA-101 & Annex O 00043 #define CDC_PROTOCOL_GSM_7_07 0x04 // AT Commands defined by GSM 7.07 00044 #define CDC_PROTOCOL_3GPP_27_07 0x05 // AT Commands defined by 3GPP 27.007 00045 #define CDC_PROTOCOL_C_S0017_0 0x06 // AT Commands defined by TIA for CDMA 00046 #define CDC_PROTOCOL_USB_EEM 0x07 // Ethernet Emulation Model 00047 00048 // CDC Commands defined by CDC 1.2 00049 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00 00050 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01 00051 00052 // CDC Commands defined by PSTN 1.2 00053 #define CDC_SET_COMM_FEATURE 0x02 00054 #define CDC_GET_COMM_FEATURE 0x03 00055 #define CDC_CLEAR_COMM_FEATURE 0x04 00056 #define CDC_SET_AUX_LINE_STATE 0x10 00057 #define CDC_SET_HOOK_STATE 0x11 00058 #define CDC_PULSE_SETUP 0x12 00059 #define CDC_SEND_PULSE 0x13 00060 #define CDC_SET_PULSE_TIME 0x14 00061 #define CDC_RING_AUX_JACK 0x15 00062 #define CDC_SET_LINE_CODING 0x20 00063 #define CDC_GET_LINE_CODING 0x21 00064 #define CDC_SET_CONTROL_LINE_STATE 0x22 00065 #define CDC_SEND_BREAK 0x23 00066 #define CDC_SET_RINGER_PARMS 0x30 00067 #define CDC_GET_RINGER_PARMS 0x31 00068 #define CDC_SET_OPERATION_PARMS 0x32 00069 #define CDC_GET_OPERATION_PARMS 0x33 00070 #define CDC_SET_LINE_PARMS 0x34 00071 #define CDC_GET_LINE_PARMS 0x35 00072 #define CDC_DIAL_DIGITS 0x36 00073 00074 //Class-Specific Notification Codes 00075 #define NETWORK_CONNECTION 0x00 00076 #define RESPONSE_AVAILABLE 0x01 00077 #define AUX_JACK_HOOK_STATE 0x08 00078 #define RING_DETECT 0x09 00079 #define SERIAL_STATE 0x20 00080 #define CALL_STATE_CHANGE 0x28 00081 #define LINE_STATE_CHANGE 0x29 00082 #define CONNECTION_SPEED_CHANGE 0x2a 00083 00084 // CDC Functional Descriptor Structures 00085 00086 typedef struct { 00087 uint8_t bFunctionLength; 00088 uint8_t bDescriptorType; 00089 uint8_t bDescriptorSubtype; 00090 uint8_t bmCapabilities; 00091 uint8_t bDataInterface; 00092 } CALL_MGMNT_FUNC_DESCR; 00093 00094 typedef struct { 00095 uint8_t bFunctionLength; 00096 uint8_t bDescriptorType; 00097 uint8_t bDescriptorSubtype; 00098 uint8_t bmCapabilities; 00099 } ACM_FUNC_DESCR, DLM_FUNC_DESCR, TEL_OPER_MODES_FUNC_DESCR, 00100 TEL_CALL_STATE_REP_CPBL_FUNC_DESCR; 00101 00102 typedef struct { 00103 uint8_t bFunctionLength; 00104 uint8_t bDescriptorType; 00105 uint8_t bDescriptorSubtype; 00106 uint8_t bRingerVolSteps; 00107 uint8_t bNumRingerPatterns; 00108 } TEL_RINGER_FUNC_DESCR; 00109 00110 typedef struct { 00111 uint32_t dwDTERate; // Data Terminal Rate in bits per second 00112 uint8_t bCharFormat; // 0 - 1 stop bit, 1 - 1.5 stop bits, 2 - 2 stop bits 00113 uint8_t bParityType; // 0 - None, 1 - Odd, 2 - Even, 3 - Mark, 4 - Space 00114 uint8_t bDataBits; // Data bits (5, 6, 7, 8 or 16) 00115 } LINE_CODING; 00116 00117 typedef struct { 00118 uint8_t bmRequestType; // 0xa1 for class-specific notifications 00119 uint8_t bNotification; 00120 uint16_t wValue; 00121 uint16_t wIndex; 00122 uint16_t wLength; 00123 uint16_t bmState; //UART state bitmap for SERIAL_STATE, other notifications variable length 00124 } CLASS_NOTIFICATION; 00125 00126 class ACM; 00127 00128 class CDCAsyncOper { 00129 public: 00130 00131 virtual uint8_t OnInit(ACM *pacm __attribute__((unused))) { 00132 return 0; 00133 }; 00134 //virtual void OnDataRcvd(ACM *pacm, uint8_t nbytes, uint8_t *dataptr) = 0; 00135 //virtual void OnDisconnected(ACM *pacm) = 0; 00136 }; 00137 00138 /** 00139 * This structure is used to report the extended capabilities of the connected device. 00140 * It is also used to report the current status. 00141 * Regular CDC-ACM reports all as false. 00142 */ 00143 typedef struct { 00144 00145 union { 00146 uint8_t tty; 00147 00148 struct { 00149 bool enhanced : 1; // Do we have the ability to set/clear any features? 00150 // Status and 8th bit in data stream. 00151 // Presence only indicates feature is available, but this isn't used for CDC-ACM. 00152 bool wide : 1; 00153 bool autoflow_RTS : 1; // Has autoflow on RTS/CTS 00154 bool autoflow_DSR : 1; // Has autoflow on DTR/DSR 00155 bool autoflow_XON : 1; // Has autoflow XON/XOFF 00156 bool half_duplex : 1; // Has half-duplex capability. 00157 } __attribute__((packed)); 00158 }; 00159 } tty_features; 00160 00161 #define ACM_MAX_ENDPOINTS 4 00162 00163 class ACM : public USBDeviceConfig, public UsbConfigXtracter { 00164 protected: 00165 USB *pUsb; 00166 CDCAsyncOper *pAsync; 00167 uint8_t bAddress; 00168 uint8_t bConfNum; // configuration number 00169 uint8_t bControlIface; // Control interface value 00170 uint8_t bDataIface; // Data interface value 00171 uint8_t bNumEP; // total number of EP in the configuration 00172 uint32_t qNextPollTime; // next poll time 00173 volatile bool bPollEnable; // poll enable flag 00174 volatile bool ready; //device ready indicator 00175 tty_features _enhanced_status; // current status 00176 00177 void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); 00178 00179 public: 00180 static const uint8_t epDataInIndex; // DataIn endpoint index 00181 static const uint8_t epDataOutIndex; // DataOUT endpoint index 00182 static const uint8_t epInterruptInIndex; // InterruptIN endpoint index 00183 EpInfo epInfo[ACM_MAX_ENDPOINTS]; 00184 00185 ACM(USB *pusb, CDCAsyncOper *pasync); 00186 00187 uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr); 00188 uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr); 00189 uint8_t ClearCommFeature(uint16_t fid); 00190 uint8_t SetLineCoding(const LINE_CODING *dataptr); 00191 uint8_t GetLineCoding(LINE_CODING *dataptr); 00192 uint8_t SetControlLineState(uint8_t state); 00193 uint8_t SendBreak(uint16_t duration); 00194 uint8_t GetNotif(uint16_t *bytes_rcvd, uint8_t *dataptr); 00195 00196 // Methods for receiving and sending data 00197 uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr); 00198 uint8_t SndData(uint16_t nbytes, uint8_t *dataptr); 00199 00200 // USBDeviceConfig implementation 00201 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 00202 uint8_t Release(); 00203 uint8_t Poll(); 00204 00205 bool available(void) { 00206 return false; 00207 }; 00208 00209 virtual uint8_t GetAddress() { 00210 return bAddress; 00211 }; 00212 00213 virtual bool isReady() { 00214 return ready; 00215 }; 00216 00217 virtual tty_features enhanced_status(void) { 00218 return _enhanced_status; 00219 }; 00220 00221 virtual tty_features enhanced_features(void) { 00222 tty_features rv; 00223 rv.enhanced = false; 00224 rv.autoflow_RTS = false; 00225 rv.autoflow_DSR = false; 00226 rv.autoflow_XON = false; 00227 rv.half_duplex = false; 00228 rv.wide = false; 00229 return rv; 00230 }; 00231 00232 virtual void autoflowRTS(bool s __attribute__((unused))) { 00233 }; 00234 00235 virtual void autoflowDSR(bool s __attribute__((unused))) { 00236 }; 00237 00238 virtual void autoflowXON(bool s __attribute__((unused))) { 00239 }; 00240 00241 virtual void half_duplex(bool s __attribute__((unused))) { 00242 }; 00243 00244 virtual void wide(bool s __attribute__((unused))) { 00245 }; 00246 00247 // UsbConfigXtracter implementation 00248 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); 00249 }; 00250 00251 #endif // __CDCACM_H__ 00252
Generated on Thu Jul 14 2022 08:33:41 by
1.7.2