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.
Dependents: UsbHostMAX3421E_Hello
cdcacm.h@0:84353c479782, 2020-07-12 (annotated)
- Committer:
- hudakz
- Date:
- Sun Jul 12 20:39:26 2020 +0000
- Revision:
- 0:84353c479782
- Child:
- 1:2263e77400e9
MAX3421E-based USB Host Shield Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:84353c479782 | 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. |
hudakz | 0:84353c479782 | 2 | |
hudakz | 0:84353c479782 | 3 | This software may be distributed and modified under the terms of the GNU |
hudakz | 0:84353c479782 | 4 | General Public License version 2 (GPL2) as published by the Free Software |
hudakz | 0:84353c479782 | 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
hudakz | 0:84353c479782 | 6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
hudakz | 0:84353c479782 | 7 | on this software must also be made publicly available under the terms of |
hudakz | 0:84353c479782 | 8 | the GPL2 ("Copyleft"). |
hudakz | 0:84353c479782 | 9 | |
hudakz | 0:84353c479782 | 10 | Contact information |
hudakz | 0:84353c479782 | 11 | ------------------- |
hudakz | 0:84353c479782 | 12 | |
hudakz | 0:84353c479782 | 13 | Circuits At Home, LTD |
hudakz | 0:84353c479782 | 14 | Web : http://www.circuitsathome.com |
hudakz | 0:84353c479782 | 15 | e-mail : support@circuitsathome.com |
hudakz | 0:84353c479782 | 16 | */ |
hudakz | 0:84353c479782 | 17 | #if !defined(__CDCACM_H__) |
hudakz | 0:84353c479782 | 18 | #define __CDCACM_H__ |
hudakz | 0:84353c479782 | 19 | |
hudakz | 0:84353c479782 | 20 | #include "Usb.h" |
hudakz | 0:84353c479782 | 21 | |
hudakz | 0:84353c479782 | 22 | #define bmREQ_CDCOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE |
hudakz | 0:84353c479782 | 23 | #define bmREQ_CDCIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE |
hudakz | 0:84353c479782 | 24 | |
hudakz | 0:84353c479782 | 25 | // CDC Subclass Constants |
hudakz | 0:84353c479782 | 26 | #define CDC_SUBCLASS_DLCM 0x01 // Direct Line Control Model |
hudakz | 0:84353c479782 | 27 | #define CDC_SUBCLASS_ACM 0x02 // Abstract Control Model |
hudakz | 0:84353c479782 | 28 | #define CDC_SUBCLASS_TCM 0x03 // Telephone Control Model |
hudakz | 0:84353c479782 | 29 | #define CDC_SUBCLASS_MCCM 0x04 // Multi Channel Control Model |
hudakz | 0:84353c479782 | 30 | #define CDC_SUBCLASS_CAPI 0x05 // CAPI Control Model |
hudakz | 0:84353c479782 | 31 | #define CDC_SUBCLASS_ETHERNET 0x06 // Ethernet Network Control Model |
hudakz | 0:84353c479782 | 32 | #define CDC_SUBCLASS_ATM 0x07 // ATM Network Control Model |
hudakz | 0:84353c479782 | 33 | #define CDC_SUBCLASS_WIRELESS_HANDSET 0x08 // Wireless Handset Control Model |
hudakz | 0:84353c479782 | 34 | #define CDC_SUBCLASS_DEVICE_MANAGEMENT 0x09 // Device Management |
hudakz | 0:84353c479782 | 35 | #define CDC_SUBCLASS_MOBILE_DIRECT_LINE 0x0A // Mobile Direct Line Model |
hudakz | 0:84353c479782 | 36 | #define CDC_SUBCLASS_OBEX 0x0B // OBEX |
hudakz | 0:84353c479782 | 37 | #define CDC_SUBCLASS_ETHERNET_EMU 0x0C // Ethernet Emulation Model |
hudakz | 0:84353c479782 | 38 | |
hudakz | 0:84353c479782 | 39 | // Communication Interface Class Control Protocol Codes |
hudakz | 0:84353c479782 | 40 | #define CDC_PROTOCOL_ITU_T_V_250 0x01 // AT Commands defined by ITU-T V.250 |
hudakz | 0:84353c479782 | 41 | #define CDC_PROTOCOL_PCCA_101 0x02 // AT Commands defined by PCCA-101 |
hudakz | 0:84353c479782 | 42 | #define CDC_PROTOCOL_PCCA_101_O 0x03 // AT Commands defined by PCCA-101 & Annex O |
hudakz | 0:84353c479782 | 43 | #define CDC_PROTOCOL_GSM_7_07 0x04 // AT Commands defined by GSM 7.07 |
hudakz | 0:84353c479782 | 44 | #define CDC_PROTOCOL_3GPP_27_07 0x05 // AT Commands defined by 3GPP 27.007 |
hudakz | 0:84353c479782 | 45 | #define CDC_PROTOCOL_C_S0017_0 0x06 // AT Commands defined by TIA for CDMA |
hudakz | 0:84353c479782 | 46 | #define CDC_PROTOCOL_USB_EEM 0x07 // Ethernet Emulation Model |
hudakz | 0:84353c479782 | 47 | |
hudakz | 0:84353c479782 | 48 | // CDC Commands defined by CDC 1.2 |
hudakz | 0:84353c479782 | 49 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00 |
hudakz | 0:84353c479782 | 50 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01 |
hudakz | 0:84353c479782 | 51 | |
hudakz | 0:84353c479782 | 52 | // CDC Commands defined by PSTN 1.2 |
hudakz | 0:84353c479782 | 53 | #define CDC_SET_COMM_FEATURE 0x02 |
hudakz | 0:84353c479782 | 54 | #define CDC_GET_COMM_FEATURE 0x03 |
hudakz | 0:84353c479782 | 55 | #define CDC_CLEAR_COMM_FEATURE 0x04 |
hudakz | 0:84353c479782 | 56 | #define CDC_SET_AUX_LINE_STATE 0x10 |
hudakz | 0:84353c479782 | 57 | #define CDC_SET_HOOK_STATE 0x11 |
hudakz | 0:84353c479782 | 58 | #define CDC_PULSE_SETUP 0x12 |
hudakz | 0:84353c479782 | 59 | #define CDC_SEND_PULSE 0x13 |
hudakz | 0:84353c479782 | 60 | #define CDC_SET_PULSE_TIME 0x14 |
hudakz | 0:84353c479782 | 61 | #define CDC_RING_AUX_JACK 0x15 |
hudakz | 0:84353c479782 | 62 | #define CDC_SET_LINE_CODING 0x20 |
hudakz | 0:84353c479782 | 63 | #define CDC_GET_LINE_CODING 0x21 |
hudakz | 0:84353c479782 | 64 | #define CDC_SET_CONTROL_LINE_STATE 0x22 |
hudakz | 0:84353c479782 | 65 | #define CDC_SEND_BREAK 0x23 |
hudakz | 0:84353c479782 | 66 | #define CDC_SET_RINGER_PARMS 0x30 |
hudakz | 0:84353c479782 | 67 | #define CDC_GET_RINGER_PARMS 0x31 |
hudakz | 0:84353c479782 | 68 | #define CDC_SET_OPERATION_PARMS 0x32 |
hudakz | 0:84353c479782 | 69 | #define CDC_GET_OPERATION_PARMS 0x33 |
hudakz | 0:84353c479782 | 70 | #define CDC_SET_LINE_PARMS 0x34 |
hudakz | 0:84353c479782 | 71 | #define CDC_GET_LINE_PARMS 0x35 |
hudakz | 0:84353c479782 | 72 | #define CDC_DIAL_DIGITS 0x36 |
hudakz | 0:84353c479782 | 73 | |
hudakz | 0:84353c479782 | 74 | //Class-Specific Notification Codes |
hudakz | 0:84353c479782 | 75 | #define NETWORK_CONNECTION 0x00 |
hudakz | 0:84353c479782 | 76 | #define RESPONSE_AVAILABLE 0x01 |
hudakz | 0:84353c479782 | 77 | #define AUX_JACK_HOOK_STATE 0x08 |
hudakz | 0:84353c479782 | 78 | #define RING_DETECT 0x09 |
hudakz | 0:84353c479782 | 79 | #define SERIAL_STATE 0x20 |
hudakz | 0:84353c479782 | 80 | #define CALL_STATE_CHANGE 0x28 |
hudakz | 0:84353c479782 | 81 | #define LINE_STATE_CHANGE 0x29 |
hudakz | 0:84353c479782 | 82 | #define CONNECTION_SPEED_CHANGE 0x2a |
hudakz | 0:84353c479782 | 83 | |
hudakz | 0:84353c479782 | 84 | // CDC Functional Descriptor Structures |
hudakz | 0:84353c479782 | 85 | |
hudakz | 0:84353c479782 | 86 | typedef struct { |
hudakz | 0:84353c479782 | 87 | uint8_t bFunctionLength; |
hudakz | 0:84353c479782 | 88 | uint8_t bDescriptorType; |
hudakz | 0:84353c479782 | 89 | uint8_t bDescriptorSubtype; |
hudakz | 0:84353c479782 | 90 | uint8_t bmCapabilities; |
hudakz | 0:84353c479782 | 91 | uint8_t bDataInterface; |
hudakz | 0:84353c479782 | 92 | } CALL_MGMNT_FUNC_DESCR; |
hudakz | 0:84353c479782 | 93 | |
hudakz | 0:84353c479782 | 94 | typedef struct { |
hudakz | 0:84353c479782 | 95 | uint8_t bFunctionLength; |
hudakz | 0:84353c479782 | 96 | uint8_t bDescriptorType; |
hudakz | 0:84353c479782 | 97 | uint8_t bDescriptorSubtype; |
hudakz | 0:84353c479782 | 98 | uint8_t bmCapabilities; |
hudakz | 0:84353c479782 | 99 | } ACM_FUNC_DESCR, DLM_FUNC_DESCR, TEL_OPER_MODES_FUNC_DESCR, |
hudakz | 0:84353c479782 | 100 | TEL_CALL_STATE_REP_CPBL_FUNC_DESCR; |
hudakz | 0:84353c479782 | 101 | |
hudakz | 0:84353c479782 | 102 | typedef struct { |
hudakz | 0:84353c479782 | 103 | uint8_t bFunctionLength; |
hudakz | 0:84353c479782 | 104 | uint8_t bDescriptorType; |
hudakz | 0:84353c479782 | 105 | uint8_t bDescriptorSubtype; |
hudakz | 0:84353c479782 | 106 | uint8_t bRingerVolSteps; |
hudakz | 0:84353c479782 | 107 | uint8_t bNumRingerPatterns; |
hudakz | 0:84353c479782 | 108 | } TEL_RINGER_FUNC_DESCR; |
hudakz | 0:84353c479782 | 109 | |
hudakz | 0:84353c479782 | 110 | typedef struct { |
hudakz | 0:84353c479782 | 111 | uint32_t dwDTERate; // Data Terminal Rate in bits per second |
hudakz | 0:84353c479782 | 112 | uint8_t bCharFormat; // 0 - 1 stop bit, 1 - 1.5 stop bits, 2 - 2 stop bits |
hudakz | 0:84353c479782 | 113 | uint8_t bParityType; // 0 - None, 1 - Odd, 2 - Even, 3 - Mark, 4 - Space |
hudakz | 0:84353c479782 | 114 | uint8_t bDataBits; // Data bits (5, 6, 7, 8 or 16) |
hudakz | 0:84353c479782 | 115 | } LINE_CODING; |
hudakz | 0:84353c479782 | 116 | |
hudakz | 0:84353c479782 | 117 | typedef struct { |
hudakz | 0:84353c479782 | 118 | uint8_t bmRequestType; // 0xa1 for class-specific notifications |
hudakz | 0:84353c479782 | 119 | uint8_t bNotification; |
hudakz | 0:84353c479782 | 120 | uint16_t wValue; |
hudakz | 0:84353c479782 | 121 | uint16_t wIndex; |
hudakz | 0:84353c479782 | 122 | uint16_t wLength; |
hudakz | 0:84353c479782 | 123 | uint16_t bmState; //UART state bitmap for SERIAL_STATE, other notifications variable length |
hudakz | 0:84353c479782 | 124 | } CLASS_NOTIFICATION; |
hudakz | 0:84353c479782 | 125 | |
hudakz | 0:84353c479782 | 126 | class ACM; |
hudakz | 0:84353c479782 | 127 | |
hudakz | 0:84353c479782 | 128 | class CDCAsyncOper { |
hudakz | 0:84353c479782 | 129 | public: |
hudakz | 0:84353c479782 | 130 | |
hudakz | 0:84353c479782 | 131 | virtual uint8_t OnInit(ACM *pacm __attribute__((unused))) { |
hudakz | 0:84353c479782 | 132 | return 0; |
hudakz | 0:84353c479782 | 133 | }; |
hudakz | 0:84353c479782 | 134 | //virtual void OnDataRcvd(ACM *pacm, uint8_t nbytes, uint8_t *dataptr) = 0; |
hudakz | 0:84353c479782 | 135 | //virtual void OnDisconnected(ACM *pacm) = 0; |
hudakz | 0:84353c479782 | 136 | }; |
hudakz | 0:84353c479782 | 137 | |
hudakz | 0:84353c479782 | 138 | /** |
hudakz | 0:84353c479782 | 139 | * This structure is used to report the extended capabilities of the connected device. |
hudakz | 0:84353c479782 | 140 | * It is also used to report the current status. |
hudakz | 0:84353c479782 | 141 | * Regular CDC-ACM reports all as false. |
hudakz | 0:84353c479782 | 142 | */ |
hudakz | 0:84353c479782 | 143 | typedef struct { |
hudakz | 0:84353c479782 | 144 | |
hudakz | 0:84353c479782 | 145 | union { |
hudakz | 0:84353c479782 | 146 | uint8_t tty; |
hudakz | 0:84353c479782 | 147 | |
hudakz | 0:84353c479782 | 148 | struct { |
hudakz | 0:84353c479782 | 149 | bool enhanced : 1; // Do we have the ability to set/clear any features? |
hudakz | 0:84353c479782 | 150 | // Status and 8th bit in data stream. |
hudakz | 0:84353c479782 | 151 | // Presence only indicates feature is available, but this isn't used for CDC-ACM. |
hudakz | 0:84353c479782 | 152 | bool wide : 1; |
hudakz | 0:84353c479782 | 153 | bool autoflow_RTS : 1; // Has autoflow on RTS/CTS |
hudakz | 0:84353c479782 | 154 | bool autoflow_DSR : 1; // Has autoflow on DTR/DSR |
hudakz | 0:84353c479782 | 155 | bool autoflow_XON : 1; // Has autoflow XON/XOFF |
hudakz | 0:84353c479782 | 156 | bool half_duplex : 1; // Has half-duplex capability. |
hudakz | 0:84353c479782 | 157 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 158 | }; |
hudakz | 0:84353c479782 | 159 | } tty_features; |
hudakz | 0:84353c479782 | 160 | |
hudakz | 0:84353c479782 | 161 | #define ACM_MAX_ENDPOINTS 4 |
hudakz | 0:84353c479782 | 162 | |
hudakz | 0:84353c479782 | 163 | class ACM : public USBDeviceConfig, public UsbConfigXtracter { |
hudakz | 0:84353c479782 | 164 | protected: |
hudakz | 0:84353c479782 | 165 | USB *pUsb; |
hudakz | 0:84353c479782 | 166 | CDCAsyncOper *pAsync; |
hudakz | 0:84353c479782 | 167 | uint8_t bAddress; |
hudakz | 0:84353c479782 | 168 | uint8_t bConfNum; // configuration number |
hudakz | 0:84353c479782 | 169 | uint8_t bControlIface; // Control interface value |
hudakz | 0:84353c479782 | 170 | uint8_t bDataIface; // Data interface value |
hudakz | 0:84353c479782 | 171 | uint8_t bNumEP; // total number of EP in the configuration |
hudakz | 0:84353c479782 | 172 | uint32_t qNextPollTime; // next poll time |
hudakz | 0:84353c479782 | 173 | volatile bool bPollEnable; // poll enable flag |
hudakz | 0:84353c479782 | 174 | volatile bool ready; //device ready indicator |
hudakz | 0:84353c479782 | 175 | tty_features _enhanced_status; // current status |
hudakz | 0:84353c479782 | 176 | |
hudakz | 0:84353c479782 | 177 | void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); |
hudakz | 0:84353c479782 | 178 | |
hudakz | 0:84353c479782 | 179 | public: |
hudakz | 0:84353c479782 | 180 | static const uint8_t epDataInIndex; // DataIn endpoint index |
hudakz | 0:84353c479782 | 181 | static const uint8_t epDataOutIndex; // DataOUT endpoint index |
hudakz | 0:84353c479782 | 182 | static const uint8_t epInterruptInIndex; // InterruptIN endpoint index |
hudakz | 0:84353c479782 | 183 | EpInfo epInfo[ACM_MAX_ENDPOINTS]; |
hudakz | 0:84353c479782 | 184 | |
hudakz | 0:84353c479782 | 185 | ACM(USB *pusb, CDCAsyncOper *pasync); |
hudakz | 0:84353c479782 | 186 | |
hudakz | 0:84353c479782 | 187 | uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 188 | uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 189 | uint8_t ClearCommFeature(uint16_t fid); |
hudakz | 0:84353c479782 | 190 | uint8_t SetLineCoding(const LINE_CODING *dataptr); |
hudakz | 0:84353c479782 | 191 | uint8_t GetLineCoding(LINE_CODING *dataptr); |
hudakz | 0:84353c479782 | 192 | uint8_t SetControlLineState(uint8_t state); |
hudakz | 0:84353c479782 | 193 | uint8_t SendBreak(uint16_t duration); |
hudakz | 0:84353c479782 | 194 | uint8_t GetNotif(uint16_t *bytes_rcvd, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 195 | |
hudakz | 0:84353c479782 | 196 | // Methods for receiving and sending data |
hudakz | 0:84353c479782 | 197 | uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 198 | uint8_t SndData(uint16_t nbytes, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 199 | |
hudakz | 0:84353c479782 | 200 | // USBDeviceConfig implementation |
hudakz | 0:84353c479782 | 201 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 202 | uint8_t Release(); |
hudakz | 0:84353c479782 | 203 | uint8_t Poll(); |
hudakz | 0:84353c479782 | 204 | |
hudakz | 0:84353c479782 | 205 | bool available(void) { |
hudakz | 0:84353c479782 | 206 | return false; |
hudakz | 0:84353c479782 | 207 | }; |
hudakz | 0:84353c479782 | 208 | |
hudakz | 0:84353c479782 | 209 | virtual uint8_t GetAddress() { |
hudakz | 0:84353c479782 | 210 | return bAddress; |
hudakz | 0:84353c479782 | 211 | }; |
hudakz | 0:84353c479782 | 212 | |
hudakz | 0:84353c479782 | 213 | virtual bool isReady() { |
hudakz | 0:84353c479782 | 214 | return ready; |
hudakz | 0:84353c479782 | 215 | }; |
hudakz | 0:84353c479782 | 216 | |
hudakz | 0:84353c479782 | 217 | virtual tty_features enhanced_status(void) { |
hudakz | 0:84353c479782 | 218 | return _enhanced_status; |
hudakz | 0:84353c479782 | 219 | }; |
hudakz | 0:84353c479782 | 220 | |
hudakz | 0:84353c479782 | 221 | virtual tty_features enhanced_features(void) { |
hudakz | 0:84353c479782 | 222 | tty_features rv; |
hudakz | 0:84353c479782 | 223 | rv.enhanced = false; |
hudakz | 0:84353c479782 | 224 | rv.autoflow_RTS = false; |
hudakz | 0:84353c479782 | 225 | rv.autoflow_DSR = false; |
hudakz | 0:84353c479782 | 226 | rv.autoflow_XON = false; |
hudakz | 0:84353c479782 | 227 | rv.half_duplex = false; |
hudakz | 0:84353c479782 | 228 | rv.wide = false; |
hudakz | 0:84353c479782 | 229 | return rv; |
hudakz | 0:84353c479782 | 230 | }; |
hudakz | 0:84353c479782 | 231 | |
hudakz | 0:84353c479782 | 232 | virtual void autoflowRTS(bool s __attribute__((unused))) { |
hudakz | 0:84353c479782 | 233 | }; |
hudakz | 0:84353c479782 | 234 | |
hudakz | 0:84353c479782 | 235 | virtual void autoflowDSR(bool s __attribute__((unused))) { |
hudakz | 0:84353c479782 | 236 | }; |
hudakz | 0:84353c479782 | 237 | |
hudakz | 0:84353c479782 | 238 | virtual void autoflowXON(bool s __attribute__((unused))) { |
hudakz | 0:84353c479782 | 239 | }; |
hudakz | 0:84353c479782 | 240 | |
hudakz | 0:84353c479782 | 241 | virtual void half_duplex(bool s __attribute__((unused))) { |
hudakz | 0:84353c479782 | 242 | }; |
hudakz | 0:84353c479782 | 243 | |
hudakz | 0:84353c479782 | 244 | virtual void wide(bool s __attribute__((unused))) { |
hudakz | 0:84353c479782 | 245 | }; |
hudakz | 0:84353c479782 | 246 | |
hudakz | 0:84353c479782 | 247 | // UsbConfigXtracter implementation |
hudakz | 0:84353c479782 | 248 | void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); |
hudakz | 0:84353c479782 | 249 | }; |
hudakz | 0:84353c479782 | 250 | |
hudakz | 0:84353c479782 | 251 | #endif // __CDCACM_H__ |