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];
90 USBTRACE(
"FTDI Init: Product not supported\r\n");
112 if(epInfo[0].maxPktSize == 0) epInfo[0].
maxPktSize = 64;
115 rcode = pUsb->
setAddr(0, 0, bAddress);
142 goto FailSetDevTblEntry;
146 for(uint8_t i = 0; i < num_of_conf; i++) {
155 rcode = pUsb->
getConfDescr(bAddress, 0, i, &confDescrParser);
158 goto FailGetConfDescr;
175 rcode = pUsb->
setConf(bAddress, 0, bConfNum);
178 goto FailSetConfDescr;
186 rcode = pAsync->
OnInit(
this);
197 #ifdef DEBUG_USB_HOST 203 #ifdef DEBUG_USB_HOST 209 #ifdef DEBUG_USB_HOST 215 #ifdef DEBUG_USB_HOST 221 #ifdef DEBUG_USB_HOST 227 #ifdef DEBUG_USB_HOST 238 ErrorMessage<uint8_t > (
PSTR(
"Conf.Val"), conf);
239 ErrorMessage<uint8_t > (
PSTR(
"Iface Num"), iface);
240 ErrorMessage<uint8_t > (
PSTR(
"Alt.Set"), alt);
247 index = epInterruptInIndex;
249 index = ((pep->
bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
264 PrintEndpointDescriptor(pep);
294 uint16_t baud_value, baud_index = 0;
296 divisor3 = 48000000 / 2 / baud;
299 if((divisor3 & 0x7) == 7)
302 baud_value = divisor3 >> 3;
305 if(divisor3 == 1) baud_value |= 0xc000;
307 if(divisor3 >= 4) baud_value |= 0x4000;
309 if(divisor3 != 0) baud_value |= 0x8000;
310 if(baud_value == 1) baud_value = 0;
312 static const uint8_t divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3};
313 static const uint8_t divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1};
315 baud_value = divisor3 >> 3;
316 baud_value |= divfrac [divisor3 & 0x7] << 14;
317 baud_index = divindex[divisor3 & 0x7];
320 if(baud_value == 1) baud_value = 0;
322 if(baud_value == 0x4001) baud_value = 1;
326 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);
327 if(rv && rv !=
hrNAK) {
336 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_LATENCY_TIMER, l, 0, 0, 0, 0, NULL, NULL);
337 if(rv && rv !=
hrNAK) {
346 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_GET_LATENCY_TIMER, 0, 0, 0, 0, 1, (uint8_t *)l, NULL);
347 if(rv && rv !=
hrNAK) {
354 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL);
355 if(rv && rv !=
hrNAK) {
362 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL);
363 if(rv && rv !=
hrNAK) {
370 uint8_t rv = pUsb->
ctrlReq(bAddress, 0,
bmREQ_FTDI_OUT,
FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL);
371 if(rv && rv !=
hrNAK) {
378 uint8_t rv = pUsb->
inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr);
379 if(rv && rv !=
hrNAK) {
386 uint8_t rv = pUsb->
outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr);
387 if(rv && rv !=
hrNAK) {
396 D_PrintHex<uint8_t > (ep_ptr->
bLength, 0x80);
406 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
uint8_t SetLatency(uint8_t l)
#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 FTDI_SIO_SET_LATENCY_TIMER
#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 FTDI_SIO_GET_LATENCY_TIMER
#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)
uint8_t GetLatency(uint8_t *l)
#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(...)