USB Host Shield 2.0
Loading...
Searching...
No Matches
cdcprolific.cpp
Go to the documentation of this file.
1/* Copyright (C) 2011 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 "cdcprolific.h"
18
20ACM(p, pasync),
21wPLType(0) {
22}
23
26
28 USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
30 UsbDevice *p = NULL;
32 uint8_t num_of_conf; // number of configurations
33#ifdef PL2303_COMPAT
35#endif
36
37 AddressPool &addrPool = pUsb->GetAddressPool();
38
39 USBTRACE("PL Init\r\n");
40
41 if(bAddress)
43
44 // Get pointer to pseudo device with address 0 assigned
45 p = addrPool.GetUsbDevicePtr(0);
46
47 if(!p)
49
50 if(!p->epinfo) {
51 USBTRACE("epinfo\r\n");
53 }
54
55 // Save old pointer to EP_RECORD of address 0
56 oldep_ptr = p->epinfo;
57
58 // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
59 p->epinfo = epInfo;
60
61 p->lowspeed = lowspeed;
62
63 // Get device descriptor
65
66 // Restore p->epinfo
67 p->epinfo = oldep_ptr;
68
69 if(rcode)
70 goto FailGetDevDescr;
71
72 if(udd->idVendor != PL_VID && CHECK_PID(udd->idProduct))
74
75 /* determine chip variant */
76#ifdef PL2303_COMPAT
77 if(udd->bDeviceClass == 0x02 )
78 pltype = type_0;
79 else if(udd->bMaxPacketSize0 == 0x40 )
80 pltype = rev_HX;
81 else if(udd->bDeviceClass == 0x00)
82 pltype = type_1;
83 else if(udd->bDeviceClass == 0xff)
84 pltype = type_1;
85#endif
86
87 // Save type of PL chip
88 wPLType = udd->bcdDevice;
89
90 // Allocate new address according to device class
91 bAddress = addrPool.AllocAddress(parent, false, port);
92
93 if(!bAddress)
95
96 // Extract Max Packet Size from the device descriptor
97 epInfo[0].maxPktSize = udd->bMaxPacketSize0;
98
99 // Assign new address to the device
100 rcode = pUsb->setAddr(0, 0, bAddress);
101
102 if(rcode) {
103 p->lowspeed = false;
104 addrPool.FreeAddress(bAddress);
105 bAddress = 0;
106 USBTRACE2("setAddr:", rcode);
107 return rcode;
108 }
109
110 USBTRACE2("Addr:", bAddress);
111
112 p->lowspeed = false;
113
114 p = addrPool.GetUsbDevicePtr(bAddress);
115
116 if(!p)
118
119 p->lowspeed = lowspeed;
120
121 num_of_conf = udd->bNumConfigurations;
122
123 // Assign epInfo to epinfo pointer
125
126 if(rcode)
128
129 USBTRACE2("NC:", num_of_conf);
130
131 for(uint8_t i = 0; i < num_of_conf; i++) {
134
136
137 if(rcode)
138 goto FailGetConfDescr;
139
141
142 if(rcode)
143 goto FailGetConfDescr;
144
145 if(bNumEP > 1)
146 break;
147 } // for
148
149 if(bNumEP < 2)
151
152 // Assign epInfo to epinfo pointer
154
155 USBTRACE2("Conf:", bConfNum);
156
157 // Set Configuration Value
159
160 if(rcode)
161 goto FailSetConfDescr;
162
163#ifdef PL2303_COMPAT
164 /* Shamanic dance - sending Prolific init data as-is */
165 vendorRead( 0x84, 0x84, 0, buf );
166 vendorWrite( 0x04, 0x04, 0 );
167 vendorRead( 0x84, 0x84, 0, buf );
168 vendorRead( 0x83, 0x83, 0, buf );
169 vendorRead( 0x84, 0x84, 0, buf );
170 vendorWrite( 0x04, 0x04, 1 );
171 vendorRead( 0x84, 0x84, 0, buf);
172 vendorRead( 0x83, 0x83, 0, buf);
173 vendorWrite( 0, 0, 1 );
174 vendorWrite( 1, 0, 0 );
175 if( pltype == rev_HX ) {
176 vendorWrite( 2, 0, 0x44 );
177 vendorWrite( 0x06, 0x06, 0 ); // From W7 init
178 }
179 else {
180 vendorWrite( 2, 0, 0x24 );
181 }
182 /* Shamanic dance end */
183#endif
184 /* Calling post-init callback */
185 rcode = pAsync->OnInit(this);
186
187 if(rcode)
188 goto FailOnInit;
189
190 USBTRACE("PL configured\r\n");
191
192 //bPollEnable = true;
193 ready = true;
194 return 0;
195
197#ifdef DEBUG_USB_HOST
199 goto Fail;
200#endif
201
203#ifdef DEBUG_USB_HOST
205 goto Fail;
206#endif
207
209#ifdef DEBUG_USB_HOST
211 goto Fail;
212#endif
213
215#ifdef DEBUG_USB_HOST
217 goto Fail;
218#endif
219
221#ifdef DEBUG_USB_HOST
222 USBTRACE("OnInit:");
223#endif
224
225#ifdef DEBUG_USB_HOST
226Fail:
228#endif
229 Release();
230 return rcode;
231}
232
233//uint8_t PL::Poll()
234//{
235// uint8_t rcode = 0;
236//
237// //if (!bPollEnable)
238// // return 0;
239//
240// //if (qNextPollTime <= (uint32_t)millis())
241// //{
242// // USB_HOST_SERIAL.println(bAddress, HEX);
243//
244// // qNextPollTime = (uint32_t)millis() + 100;
245// //}
246// return rcode;
247//}
#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_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
pl2303_type
@ unknown
@ rev_HX
@ type_1
@ type_0
#define PL_VID
Definition cdcprolific.h:24
#define CHECK_PID(pid)
Definition cdcprolific.h:25
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
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
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
PL2303(USB *pusb, CDCAsyncOper *pasync)
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
#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