src/app/host-serial/libftdi/ftdi.c
static unsigned int _ftdi_determine_max_packet_size(struct ftdi_context *ftdi, libusb_device *dev)
{
    struct libusb_device_descriptor desc;
    struct libusb_config_descriptor *config0;
    unsigned int packet_size;

    // Sanity check
    if (ftdi == NULL || dev == NULL)
        return 64;

    // Determine maximum packet size. Init with default value.
    // New hi-speed devices from FTDI use a packet size of 512 bytes
    // but could be connected to a normal speed USB hub -> 64 bytes packet size.
    if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H)
        packet_size = 512;
    else
        packet_size = 64;

    if (libusb_get_device_descriptor(dev, &desc) < 0)
        return packet_size;

    if (libusb_get_config_descriptor(dev, 0, &config0) < 0)
        return packet_size;

    if (desc.bNumConfigurations > 0)
    {
        if (ftdi->interface < config0->bNumInterfaces)
        {
            struct libusb_interface interface = config0->interface[ftdi->interface];
            if (interface.num_altsetting > 0)
            {
                struct libusb_interface_descriptor descriptor = interface.altsetting[0];
                if (descriptor.bNumEndpoints > 0)
                {
                    packet_size = descriptor.endpoint[0].wMaxPacketSize;
                }
            }
        }
    }

    libusb_free_config_descriptor (config0);
    return packet_size;
}
/**
 * Internal function to determine the maximum packet size.
 * \param ftdi pointer to ftdi_context
 * \param dev libusb usb_dev to use
 * \retval Maximum packet size for this device
 */
Internal function to determine the maximum packet size.
\param ftdi pointer to ftdi_context
\param dev libusb usb_dev to use
\retval Maximum packet size for this device
Internal function to determine the maximum packet size . \ param ftdi pointer to ftdi_context \ param dev libusb usb_dev to use \ retval Maximum packet size for this device
static unsigned int _ftdi_determine_max_packet_size(struct ftdi_context *ftdi, libusb_device *dev)
{
    struct libusb_device_descriptor desc;
    struct libusb_config_descriptor *config0;
    unsigned int packet_size;
    if (ftdi == NULL || dev == NULL)
        return 64;
    if (ftdi->type == TYPE_2232H || ftdi->type == TYPE_4232H || ftdi->type == TYPE_232H)
        packet_size = 512;
    else
        packet_size = 64;
    if (libusb_get_device_descriptor(dev, &desc) < 0)
        return packet_size;
    if (libusb_get_config_descriptor(dev, 0, &config0) < 0)
        return packet_size;
    if (desc.bNumConfigurations > 0)
    {
        if (ftdi->interface < config0->bNumInterfaces)
        {
            struct libusb_interface interface = config0->interface[ftdi->interface];
            if (interface.num_altsetting > 0)
            {
                struct libusb_interface_descriptor descriptor = interface.altsetting[0];
                if (descriptor.bNumEndpoints > 0)
                {
                    packet_size = descriptor.endpoint[0].wMaxPacketSize;
                }
            }
        }
    }
    libusb_free_config_descriptor (config0);
    return packet_size;
}
static unsigned int _ftdi_determine_max_packet_size ( struct ftdi_context * ftdi , libusb_device * dev ) { struct libusb_device_descriptor desc ; struct libusb_config_descriptor * config0 ; unsigned int packet_size ; if ( ftdi == NULL || dev == NULL ) return 64 ; if ( ftdi -> type == TYPE_2232H || ftdi -> type == TYPE_4232H || ftdi -> type == TYPE_232H ) packet_size = 512 ; else packet_size = 64 ; if ( libusb_get_device_descriptor ( dev , & desc ) < 0 ) return packet_size ; if ( libusb_get_config_descriptor ( dev , 0 , & config0 ) < 0 ) return packet_size ; if ( desc . bNumConfigurations > 0 ) { if ( ftdi -> interface < config0 -> bNumInterfaces ) { struct libusb_interface interface = config0 -> interface [ ftdi -> interface ] ; if ( interface . num_altsetting > 0 ) { struct libusb_interface_descriptor descriptor = interface . altsetting [ 0 ] ; if ( descriptor . bNumEndpoints > 0 ) { packet_size = descriptor . endpoint [ 0 ] . wMaxPacketSize ; } } } } libusb_free_config_descriptor ( config0 ) ; return packet_size ; }
Internal function to determine the maximum packet size.
Internal function to determine the maximum packet size .
// Sanity check // Determine maximum packet size. Init with default value. // New hi-speed devices from FTDI use a packet size of 512 bytes // but could be connected to a normal speed USB hub -> 64 bytes packet size.