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