USB Host Shield 2.0
Loading...
Searching...
No Matches
cdc_XR21B1411.cpp
Go to the documentation of this file.
1/* Copyright (C) 2015 Circuits At Home, LTD. All rights reserved.
2
3This software may be distributed and modified under the terms of the GNU
4General Public License version 2 (GPL2) as published by the Free Software
5Foundation and appearing in the file GPL2.TXT included in the packaging of
6this file. Please note that GPL2 Section 2[b] requires that all works based
7on this software must also be made publicly available under the terms of
8the GPL2 ("Copyleft").
9
10Contact information
11-------------------
12
13Circuits At Home, LTD
14Web : http://www.circuitsathome.com
15e-mail : support@circuitsathome.com
16 */
17#include "cdc_XR21B1411.h"
18
20ACM(p, pasync) {
21 // Is this needed??
22 _enhanced_status = enhanced_features(); // Set up features
23}
24
27
29 USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
30
32 UsbDevice *p = NULL;
34 uint8_t num_of_conf; // number of configurations
35
36 AddressPool &addrPool = pUsb->GetAddressPool();
37
38 USBTRACE("XR Init\r\n");
39
40 if(bAddress)
42
43 // Get pointer to pseudo device with address 0 assigned
44 p = addrPool.GetUsbDevicePtr(0);
45
46 if(!p)
48
49 if(!p->epinfo) {
50 USBTRACE("epinfo\r\n");
52 }
53
54 // Save old pointer to EP_RECORD of address 0
55 oldep_ptr = p->epinfo;
56
57 // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
58 p->epinfo = epInfo;
59
60 p->lowspeed = lowspeed;
61
62 // Get device descriptor
64
65 // Restore p->epinfo
66 p->epinfo = oldep_ptr;
67
68 if(rcode)
69 goto FailGetDevDescr;
70
71 // Allocate new address according to device class
72 bAddress = addrPool.AllocAddress(parent, false, port);
73
74 if(!bAddress)
76
77 // Extract Max Packet Size from the device descriptor
78 epInfo[0].maxPktSize = udd->bMaxPacketSize0;
79
80 // Assign new address to the device
81 rcode = pUsb->setAddr(0, 0, bAddress);
82
83 if(rcode) {
84 p->lowspeed = false;
85 addrPool.FreeAddress(bAddress);
86 bAddress = 0;
87 USBTRACE2("setAddr:", rcode);
88 return rcode;
89 }
90
91 USBTRACE2("Addr:", bAddress);
92
93 p->lowspeed = false;
94
95 p = addrPool.GetUsbDevicePtr(bAddress);
96
97 if(!p)
99
100 p->lowspeed = lowspeed;
101
102 num_of_conf = udd->bNumConfigurations;
103
104 if((((udd->idVendor != 0x2890U) || (udd->idProduct != 0x0201U)) && ((udd->idVendor != 0x04e2U) || (udd->idProduct != 0x1411U))))
106
107 // Assign epInfo to epinfo pointer
109
110 if(rcode)
112
113 USBTRACE2("NC:", num_of_conf);
114
115 for(uint8_t i = 0; i < num_of_conf; i++) {
122
125
127
128 if(rcode)
129 goto FailGetConfDescr;
130
132
133 if(rcode)
134 goto FailGetConfDescr;
135
136 if(bNumEP > 1)
137 break;
138 } // for
139
140 if(bNumEP < 4)
142
143 // Assign epInfo to epinfo pointer
145
146 USBTRACE2("Conf:", bConfNum);
147
148 // Set Configuration Value
150
151 if(rcode)
152 goto FailSetConfDescr;
153
154 // Set up features status
156 half_duplex(false);
157 autoflowRTS(false);
158 autoflowDSR(false);
159 autoflowXON(false);
160 wide(false); // Always false, because this is only available in custom mode.
161
162 rcode = pAsync->OnInit(this);
163
164 if(rcode)
165 goto FailOnInit;
166
167 USBTRACE("XR configured\r\n");
168
169 ready = true;
170
171 //bPollEnable = true;
172
173 //USBTRACE("Poll enabled\r\n");
174 return 0;
175
177#ifdef DEBUG_USB_HOST
179 goto Fail;
180#endif
181
183#ifdef DEBUG_USB_HOST
185 goto Fail;
186#endif
187
189#ifdef DEBUG_USB_HOST
191 goto Fail;
192#endif
193
195#ifdef DEBUG_USB_HOST
197 goto Fail;
198#endif
199
201#ifdef DEBUG_USB_HOST
202 USBTRACE("OnInit:");
203#endif
204
205#ifdef DEBUG_USB_HOST
206Fail:
208#endif
209 Release();
210 return rcode;
211}
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition UsbCore.h:103
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition UsbCore.h:108
#define USB_CLASS_CDC_DATA
Definition UsbCore.h:88
#define USB_CLASS_COM_AND_CDC_CTRL
Definition UsbCore.h:81
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition UsbCore.h:100
#define USB_ERROR_EPINFO_IS_NULL
Definition UsbCore.h:106
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition UsbCore.h:105
#define CDC_PROTOCOL_ITU_T_V_250
Definition cdcacm.h:40
#define CDC_SUBCLASS_ACM
Definition cdcacm.h:27
Definition cdcacm.h:163
uint8_t bNumEP
Definition cdcacm.h:171
CDCAsyncOper * pAsync
Definition cdcacm.h:166
EpInfo epInfo[ACM_MAX_ENDPOINTS]
Definition cdcacm.h:183
uint8_t Release()
Definition cdcacm.cpp:257
tty_features _enhanced_status
Definition cdcacm.h:175
virtual void wide(bool s)
Definition cdcacm.h:244
uint8_t bAddress
Definition cdcacm.h:167
USB * pUsb
Definition cdcacm.h:165
volatile bool ready
Definition cdcacm.h:174
uint8_t bConfNum
Definition cdcacm.h:168
virtual void FreeAddress(uint8_t addr)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual uint8_t OnInit(ACM *pacm)
Definition cdcacm.h:131
Definition UsbCore.h:220
AddressPool & GetAddressPool()
Definition UsbCore.h:236
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition Usb.cpp:801
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition Usb.cpp:850
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition Usb.cpp:841
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
Definition Usb.cpp:806
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition Usb.cpp:64
virtual tty_features enhanced_features(void)
virtual void autoflowXON(bool s)
virtual void autoflowDSR(bool s)
virtual void autoflowRTS(bool s)
XR21B1411(USB *pusb, CDCAsyncOper *pasync)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
virtual void half_duplex(bool s)
#define CP_MASK_COMPARE_PROTOCOL
#define CP_MASK_COMPARE_SUBCLASS
#define CP_MASK_COMPARE_CLASS
#define USBTRACE2(s, r)
Definition macros.h:84
#define USBTRACE(s)
Definition macros.h:82
#define NotifyFailSetConfDescr(...)
Definition message.h:60
#define NotifyFail(...)
Definition message.h:62
#define NotifyFailGetConfDescr(...)
Definition message.h:56
#define NotifyFailSetDevTblEntry(...)
Definition message.h:55
#define NotifyFailGetDevDescr(...)
Definition message.h:54
uint8_t maxPktSize
Definition address.h:41