1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
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
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
17 #include "cdc_XR21B1411.h"
19 XR21B1411::XR21B1411(USB
*p
, CDCAsyncOper
*pasync
) :
22 _enhanced_status
= enhanced_features(); // Set up features
25 uint8_t XR21B1411::Init(uint8_t parent
, uint8_t port
, bool lowspeed
) {
26 const uint8_t constBufSize
= sizeof (USB_DEVICE_DESCRIPTOR
);
28 uint8_t buf
[constBufSize
];
29 USB_DEVICE_DESCRIPTOR
* udd
= reinterpret_cast<USB_DEVICE_DESCRIPTOR
*>(buf
);
33 EpInfo
*oldep_ptr
= NULL
;
34 uint8_t num_of_conf
; // number of configurations
36 AddressPool
&addrPool
= pUsb
->GetAddressPool();
38 USBTRACE("XR Init\r\n");
41 return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
;
43 // Get pointer to pseudo device with address 0 assigned
44 p
= addrPool
.GetUsbDevicePtr(0);
47 return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
;
50 USBTRACE("epinfo\r\n");
51 return USB_ERROR_EPINFO_IS_NULL
;
54 // Save old pointer to EP_RECORD of address 0
55 oldep_ptr
= p
->epinfo
;
57 // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
60 p
->lowspeed
= lowspeed
;
62 // Get device descriptor
63 rcode
= pUsb
->getDevDescr(0, 0, constBufSize
, (uint8_t*)buf
);
66 p
->epinfo
= oldep_ptr
;
71 // Allocate new address according to device class
72 bAddress
= addrPool
.AllocAddress(parent
, false, port
);
75 return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
;
77 // Extract Max Packet Size from the device descriptor
78 epInfo
[0].maxPktSize
= udd
->bMaxPacketSize0
;
80 // Assign new address to the device
81 rcode
= pUsb
->setAddr(0, 0, bAddress
);
85 addrPool
.FreeAddress(bAddress
);
87 USBTRACE2("setAddr:", rcode
);
91 USBTRACE2("Addr:", bAddress
);
95 p
= addrPool
.GetUsbDevicePtr(bAddress
);
98 return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
;
100 p
->lowspeed
= lowspeed
;
102 num_of_conf
= udd
->bNumConfigurations
;
104 if((((udd
->idVendor
!= 0x2890U
) || (udd
->idProduct
!= 0x0201U
)) && ((udd
->idVendor
!= 0x04e2U
) || (udd
->idProduct
!= 0x1411U
))))
105 return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
;
107 // Assign epInfo to epinfo pointer
108 rcode
= pUsb
->setEpInfoEntry(bAddress
, 1, epInfo
);
111 goto FailSetDevTblEntry
;
113 USBTRACE2("NC:", num_of_conf
);
115 for(uint8_t i
= 0; i
< num_of_conf
; i
++) {
116 ConfigDescParser
< USB_CLASS_COM_AND_CDC_CTRL
,
118 CDC_PROTOCOL_ITU_T_V_250
,
119 CP_MASK_COMPARE_CLASS
|
120 CP_MASK_COMPARE_SUBCLASS
|
121 CP_MASK_COMPARE_PROTOCOL
> CdcControlParser(this);
123 ConfigDescParser
<USB_CLASS_CDC_DATA
, 0, 0,
124 CP_MASK_COMPARE_CLASS
> CdcDataParser(this);
126 rcode
= pUsb
->getConfDescr(bAddress
, 0, i
, &CdcControlParser
);
129 goto FailGetConfDescr
;
131 rcode
= pUsb
->getConfDescr(bAddress
, 0, i
, &CdcDataParser
);
134 goto FailGetConfDescr
;
141 return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
;
143 // Assign epInfo to epinfo pointer
144 rcode
= pUsb
->setEpInfoEntry(bAddress
, bNumEP
, epInfo
);
146 USBTRACE2("Conf:", bConfNum
);
148 // Set Configuration Value
149 rcode
= pUsb
->setConf(bAddress
, 0, bConfNum
);
152 goto FailSetConfDescr
;
154 // Set up features status
155 _enhanced_status
= enhanced_features();
160 wide(false); // Always false, because this is only available in custom mode.
162 rcode
= pAsync
->OnInit(this);
167 USBTRACE("XR configured\r\n");
171 //bPollEnable = true;
173 //USBTRACE("Poll enabled\r\n");
177 #ifdef DEBUG_USB_HOST
178 NotifyFailGetDevDescr();
183 #ifdef DEBUG_USB_HOST
184 NotifyFailSetDevTblEntry();
189 #ifdef DEBUG_USB_HOST
190 NotifyFailGetConfDescr();
195 #ifdef DEBUG_USB_HOST
196 NotifyFailSetConfDescr();
201 #ifdef DEBUG_USB_HOST
205 #ifdef DEBUG_USB_HOST