USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 <inttypes.h>
21 #include <avr/pgmspace.h>
22 #include "avrpins.h"
23 #include "max3421e.h"
24 #include "usbhost.h"
25 #include "usb_ch9.h"
26 #include "Usb.h"
27 
28 #if defined(ARDUINO) && ARDUINO >=100
29 #include "Arduino.h"
30 #else
31 #include <WProgram.h>
32 #endif
33 
34 #include "printhex.h"
35 #include "hexdump.h"
36 #include "message.h"
37 
38 #include "confdescparser.h"
39 
40 #define bmREQ_CDCOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
41 #define bmREQ_CDCIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
42 
43 // CDC Subclass Constants
44 #define CDC_SUBCLASS_DLCM 0x01 // Direct Line Control Model
45 #define CDC_SUBCLASS_ACM 0x02 // Abstract Control Model
46 #define CDC_SUBCLASS_TCM 0x03 // Telephone Control Model
47 #define CDC_SUBCLASS_MCCM 0x04 // Multi Channel Control Model
48 #define CDC_SUBCLASS_CAPI 0x05 // CAPI Control Model
49 #define CDC_SUBCLASS_ETHERNET 0x06 // Ethernet Network Control Model
50 #define CDC_SUBCLASS_ATM 0x07 // ATM Network Control Model
51 #define CDC_SUBCLASS_WIRELESS_HANDSET 0x08 // Wireless Handset Control Model
52 #define CDC_SUBCLASS_DEVICE_MANAGEMENT 0x09 // Device Management
53 #define CDC_SUBCLASS_MOBILE_DIRECT_LINE 0x0A // Mobile Direct Line Model
54 #define CDC_SUBCLASS_OBEX 0x0B // OBEX
55 #define CDC_SUBCLASS_ETHERNET_EMU 0x0C // Ethernet Emulation Model
56 
57 // Communication Interface Class Control Protocol Codes
58 #define CDC_PROTOCOL_ITU_T_V_250 0x01 // AT Commands defined by ITU-T V.250
59 #define CDC_PROTOCOL_PCCA_101 0x02 // AT Commands defined by PCCA-101
60 #define CDC_PROTOCOL_PCCA_101_O 0x03 // AT Commands defined by PCCA-101 & Annex O
61 #define CDC_PROTOCOL_GSM_7_07 0x04 // AT Commands defined by GSM 7.07
62 #define CDC_PROTOCOL_3GPP_27_07 0x05 // AT Commands defined by 3GPP 27.007
63 #define CDC_PROTOCOL_C_S0017_0 0x06 // AT Commands defined by TIA for CDMA
64 #define CDC_PROTOCOL_USB_EEM 0x07 // Ethernet Emulation Model
65 
66 // CDC Commands defined by CDC 1.2
67 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
68 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
69 
70 // CDC Commands defined by PSTN 1.2
71 #define CDC_SET_COMM_FEATURE 0x02
72 #define CDC_GET_COMM_FEATURE 0x03
73 #define CDC_CLEAR_COMM_FEATURE 0x04
74 #define CDC_SET_AUX_LINE_STATE 0x10
75 #define CDC_SET_HOOK_STATE 0x11
76 #define CDC_PULSE_SETUP 0x12
77 #define CDC_SEND_PULSE 0x13
78 #define CDC_SET_PULSE_TIME 0x14
79 #define CDC_RING_AUX_JACK 0x15
80 #define CDC_SET_LINE_CODING 0x20
81 #define CDC_GET_LINE_CODING 0x21
82 #define CDC_SET_CONTROL_LINE_STATE 0x22
83 #define CDC_SEND_BREAK 0x23
84 #define CDC_SET_RINGER_PARMS 0x30
85 #define CDC_GET_RINGER_PARMS 0x31
86 #define CDC_SET_OPERATION_PARMS 0x32
87 #define CDC_GET_OPERATION_PARMS 0x33
88 #define CDC_SET_LINE_PARMS 0x34
89 #define CDC_GET_LINE_PARMS 0x35
90 #define CDC_DIAL_DIGITS 0x36
91 
92 // CDC Functional Descriptor Structures
93 
94 typedef struct {
95  uint8_t bFunctionLength;
96  uint8_t bDescriptorType;
98  uint8_t bmCapabilities;
99  uint8_t bDataInterface;
101 
102 typedef struct {
106  uint8_t bmCapabilities;
109 
110 typedef struct {
117 
118 typedef struct {
119  uint32_t dwDTERate; // Data Terminal Rate in bits per second
120  uint8_t bCharFormat; // 0 - 1 stop bit, 1 - 1.5 stop bits, 2 - 2 stop bits
121  uint8_t bParityType; // 0 - None, 1 - Odd, 2 - Even, 3 - Mark, 4 - Space
122  uint8_t bDataBits; // Data bits (5, 6, 7, 8 or 16)
123 } LINE_CODING;
124 
125 class ACM;
126 
128 public:
129  virtual uint8_t OnInit(ACM *pacm) = 0;
130  //virtual void OnDataRcvd(ACM *pacm, uint8_t nbytes, uint8_t *dataptr) = 0;
131  //virtual void OnDisconnected(ACM *pacm) = 0;
132 };
133 
134 
135 #define ACM_MAX_ENDPOINTS 4
136 
137 class ACM : public USBDeviceConfig, public UsbConfigXtracter {
138 protected:
139  static const uint8_t epDataInIndex; // DataIn endpoint index
140  static const uint8_t epDataOutIndex; // DataOUT endpoint index
141  static const uint8_t epInterruptInIndex; // InterruptIN endpoint index
142 
145  uint8_t bAddress;
146  uint8_t bConfNum; // configuration number
147  uint8_t bControlIface; // Control interface value
148  uint8_t bDataIface; // Data interface value
149  uint8_t bNumEP; // total number of EP in the configuration
150  uint32_t qNextPollTime; // next poll time
151  bool bPollEnable; // poll enable flag
152 
154 
156 
157 public:
158  ACM(USB *pusb, CDCAsyncOper *pasync);
159 
160  uint8_t SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
161  uint8_t GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr);
162  uint8_t ClearCommFeature(uint16_t fid);
163  uint8_t SetLineCoding(const LINE_CODING *dataptr);
164  uint8_t GetLineCoding(LINE_CODING *dataptr);
165  uint8_t SetControlLineState(uint8_t state);
166  uint8_t SendBreak(uint16_t duration);
167 
168  // Methods for recieving and sending data
169  uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
170  uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
171 
172  // USBDeviceConfig implementation
173  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
174  virtual uint8_t Release();
175  virtual uint8_t Poll();
176 
177  virtual uint8_t GetAddress() {
178  return bAddress;
179  };
180 
181  // UsbConfigXtracter implementation
182  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
183 };
184 
185 #endif // __CDCACM_H__