19 const uint8_t FTDI::epDataInIndex = 1;
20 const uint8_t FTDI::epDataOutIndex = 2;
21 const uint8_t FTDI::epInterruptInIndex = 3;
29 wIdProduct(idProduct) {
41 uint8_t
FTDI::Init(uint8_t parent, uint8_t port,
bool lowspeed) {
44 uint8_t buf[constBufSize];
91 USBTRACE(
"FTDI Init: Product not supported\r\n");
113 rcode = pUsb->
setAddr(0, 0, bAddress);
140 goto FailSetDevTblEntry;
144 for(uint8_t i = 0; i < num_of_conf; i++) {
153 rcode = pUsb->
getConfDescr(bAddress, 0, i, &confDescrParser);
156 goto FailGetConfDescr;
173 rcode = pUsb->
setConf(bAddress, 0, bConfNum);
176 goto FailSetConfDescr;
178 rcode = pAsync->
OnInit(
this);
189 #ifdef DEBUG_USB_HOST
195 #ifdef DEBUG_USB_HOST
201 #ifdef DEBUG_USB_HOST
207 #ifdef DEBUG_USB_HOST
213 #ifdef DEBUG_USB_HOST
224 ErrorMessage<uint8_t > (
PSTR(
"Conf.Val"), conf);
225 ErrorMessage<uint8_t > (
PSTR(
"Iface Num"), iface);
226 ErrorMessage<uint8_t > (
PSTR(
"Alt.Set"), alt);
233 index = epInterruptInIndex;
235 index = ((pep->
bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
247 PrintEndpointDescriptor(pep);
277 uint16_t baud_value, baud_index = 0;
279 divisor3 = 48000000 / 2 / baud;
282 if((divisor3 & 0x7) == 7)
285 baud_value = divisor3 >> 3;
288 if(divisor3 == 1) baud_value |= 0xc000;
290 if(divisor3 >= 4) baud_value |= 0x4000;
292 if(divisor3 != 0) baud_value |= 0x8000;
293 if(baud_value == 1) baud_value = 0;
295 static const uint8_t divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3};
296 static const uint8_t divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1};
298 baud_value = divisor3 >> 3;
299 baud_value |= divfrac [divisor3 & 0x7] << 14;
300 baud_index = divindex[divisor3 & 0x7];
303 if(baud_value == 1) baud_value = 0;
305 if(baud_value == 0x4001) baud_value = 1;
309 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL);
310 if(rv && rv !=
hrNAK) {
317 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL);
318 if(rv && rv !=
hrNAK) {
325 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL);
326 if(rv && rv !=
hrNAK) {
333 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL);
334 if(rv && rv !=
hrNAK) {
341 uint8_t rv = pUsb->
inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
342 if(rv && rv !=
hrNAK) {
349 uint8_t rv = pUsb->
outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
350 if(rv && rv !=
hrNAK) {
359 D_PrintHex<uint8_t > (ep_ptr->
bLength, 0x80);
369 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
#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 USB_TRANSFER_TYPE_INTERRUPT
#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
FTDI(USB *pusb, FTDIAsyncOper *pasync, uint16_t idProduct=FTDI_PID)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
#define bmUSB_TRANSFER_TYPE
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)
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
uint8_t bNumConfigurations
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define FTDI_SIO_MODEM_CTRL
AddressPool & GetAddressPool()
#define USB_TRANSFER_TYPE_BULK
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(...)