19 const uint8_t FTDI::epDataInIndex = 1;
20 const uint8_t FTDI::epDataOutIndex = 2;
21 const uint8_t FTDI::epInterruptInIndex = 3;
39 uint8_t
FTDI::Init(uint8_t parent, uint8_t port,
bool lowspeed) {
42 uint8_t buf[constBufSize];
100 rcode = pUsb->
setAddr(0, 0, bAddress);
127 goto FailSetDevTblEntry;
131 for(uint8_t i = 0; i < num_of_conf; i++) {
138 goto FailGetConfDescr;
140 rcode = pUsb->
getConfDescr(bAddress, 0, i, &confDescrParser);
143 goto FailGetConfDescr;
160 rcode = pUsb->
setConf(bAddress, 0, bConfNum);
163 goto FailSetConfDescr;
165 rcode = pAsync->
OnInit(
this);
176 #ifdef DEBUG_USB_HOST
182 #ifdef DEBUG_USB_HOST
188 #ifdef DEBUG_USB_HOST
194 #ifdef DEBUG_USB_HOST
200 #ifdef DEBUG_USB_HOST
211 ErrorMessage<uint8_t > (
PSTR(
"Conf.Val"), conf);
212 ErrorMessage<uint8_t > (
PSTR(
"Iface Num"), iface);
213 ErrorMessage<uint8_t > (
PSTR(
"Alt.Set"), alt);
220 index = epInterruptInIndex;
223 index = ((pep->
bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
234 PrintEndpointDescriptor(pep);
263 uint16_t baud_value, baud_index = 0;
266 divisor3 = 48000000 / 2 / baud;
269 if((divisor3 & 0x7) == 7)
272 baud_value = divisor3 >> 3;
275 if(divisor3 == 1) baud_value |= 0xc000;
277 if(divisor3 >= 4) baud_value |= 0x4000;
279 if(divisor3 != 0) baud_value |= 0x8000;
280 if(baud_value == 1) baud_value = 0;
282 static const unsigned char divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3};
283 static const unsigned char divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1};
285 baud_value = divisor3 >> 3;
286 baud_value |= divfrac [divisor3 & 0x7] << 14;
287 baud_index = divindex[divisor3 & 0x7];
290 if(baud_value == 1) baud_value = 0;
292 if(baud_value == 0x4001) baud_value = 1;
296 return pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL);
300 return pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL);
304 return pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL);
308 return pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL);
312 return pUsb->
inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
316 return pUsb->
outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
322 D_PrintHex<uint8_t > (ep_ptr->
bLength, 0x80);
332 D_PrintHex<uint8_t > (ep_ptr->
bInterval, 0x80);
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
#define USB_ERROR_EPINFO_IS_NULL
uint8_t SetBaudRate(uint32_t baud)
uint8_t SetModemControl(uint16_t control)
#define FTDI_SIO_SET_BAUD_RATE
FTDI(USB *pusb, FTDIAsyncOper *pasync)
#define FTDI_SIO_SET_DATA
uint8_t SetFlowControl(uint8_t protocol, uint8_t xon=0x11, uint8_t xoff=0x13)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
#define NotifyFailGetDevDescr(...)
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
virtual void FreeAddress(uint8_t addr)=0
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
#define NotifyFailGetConfDescr(...)
#define USB_NAK_MAX_POWER
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
#define FTDI_SIO_SET_FLOW_CTRL
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual uint8_t OnInit(FTDI *pftdi)
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
virtual uint8_t OnRelease(FTDI *pftdi)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data)
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
uint8_t bNumConfigurations
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define FTDI_SIO_MODEM_CTRL
AddressPool & GetAddressPool()
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
uint8_t SetData(uint16_t databm)
#define FTDI_MAX_ENDPOINTS
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
#define NotifyFailSetDevTblEntry(...)